2004-08-25 12:14:06 +00:00
/*
Samba Unix / Linux SMB client library
Distributed SMB / CIFS Server Management Utility
Copyright ( C ) 2004 Stefan Metzmacher ( metze @ samba . org )
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
2004-11-02 11:42:35 +00:00
# include "libnet/libnet.h"
# include "utils/net/net.h"
2004-11-02 00:24:21 +00:00
# include "system/time.h"
2004-08-25 12:14:06 +00:00
/*
* Code for getting the remote time
*/
int net_time ( struct net_context * ctx , int argc , const char * * argv )
{
NTSTATUS status ;
struct libnet_context * libnetctx ;
union libnet_RemoteTOD r ;
const char * server_name ;
struct tm * tm ;
char timestr [ 64 ] ;
if ( argc > 0 & & argv [ 0 ] ) {
server_name = argv [ 0 ] ;
} else {
2005-02-15 01:11:20 +00:00
return net_time_usage ( ctx , argc , argv ) ;
2004-08-25 12:14:06 +00:00
}
2005-06-16 11:36:09 +00:00
libnetctx = libnet_context_init ( NULL ) ;
2004-08-25 12:14:06 +00:00
if ( ! libnetctx ) {
return - 1 ;
}
2005-06-03 21:30:07 +00:00
libnetctx - > cred = ctx - > credentials ;
2004-08-25 12:14:06 +00:00
/* prepare to get the time */
r . generic . level = LIBNET_REMOTE_TOD_GENERIC ;
r . generic . in . server_name = server_name ;
/* get the time */
status = libnet_RemoteTOD ( libnetctx , ctx - > mem_ctx , & r ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2004-08-25 23:10:30 +00:00
DEBUG ( 0 , ( " net_time: %s \n " , r . generic . out . error_string ) ) ;
2004-08-25 12:14:06 +00:00
return - 1 ;
}
2005-02-10 07:39:14 +00:00
ZERO_STRUCT ( timestr ) ;
2004-08-25 12:14:06 +00:00
tm = localtime ( & r . generic . out . time ) ;
2004-11-06 12:14:14 +00:00
strftime ( timestr , sizeof ( timestr ) - 1 , " %c %Z " , tm ) ;
2004-08-25 12:14:06 +00:00
printf ( " %s \n " , timestr ) ;
2005-06-16 11:36:09 +00:00
talloc_free ( libnetctx ) ;
2004-08-25 12:14:06 +00:00
return 0 ;
}
int net_time_usage ( struct net_context * ctx , int argc , const char * * argv )
{
2005-02-15 01:11:20 +00:00
d_printf ( " net time <server> [options] \n " ) ;
2004-08-25 12:14:06 +00:00
return 0 ;
}