r3579: with the gcc warning flag from abartlet we don't need sys_strftime()
[bbaumbach/samba-autobuild/.git] / source4 / utils / net / net_time.c
1 /* 
2    Samba Unix/Linux SMB client library 
3    Distributed SMB/CIFS Server Management Utility 
4
5    Copyright (C) 2004 Stefan Metzmacher (metze@samba.org)
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "libnet/libnet.h"
24 #include "utils/net/net.h"
25 #include "system/time.h"
26
27 /*
28  * Code for getting the remote time
29  */
30
31
32 int net_time(struct net_context *ctx, int argc, const char **argv)
33 {
34         NTSTATUS status;
35         struct libnet_context *libnetctx;
36         union libnet_RemoteTOD r;
37         const char *server_name;
38         struct tm *tm;
39         char timestr[64];
40
41         if (argc > 0 && argv[0]) {
42                 server_name = argv[0];
43         } else {
44                 DEBUG(0,("net_time: server name needed!\n"));
45                 return -1;
46         }
47
48         libnetctx = libnet_context_init();
49         if (!libnetctx) {
50                 return -1;      
51         }
52         libnetctx->user.account_name    = ctx->user.account_name;
53         libnetctx->user.domain_name     = ctx->user.domain_name;
54         libnetctx->user.password        = ctx->user.password;
55
56         /* prepare to get the time */
57         r.generic.level                 = LIBNET_REMOTE_TOD_GENERIC;
58         r.generic.in.server_name        = server_name;
59
60         /* get the time */
61         status = libnet_RemoteTOD(libnetctx, ctx->mem_ctx, &r);
62         if (!NT_STATUS_IS_OK(status)) {
63                 DEBUG(0,("net_time: %s\n",r.generic.out.error_string));
64                 return -1;
65         }
66
67         ZERO_ARRAY(timestr);
68         tm = localtime(&r.generic.out.time);
69         strftime(timestr, sizeof(timestr)-1, "%c %Z",tm);
70
71         printf("%s\n",timestr);
72
73         libnet_context_destroy(&libnetctx);
74
75         return 0;
76 }
77
78 int net_time_usage(struct net_context *ctx, int argc, const char **argv)
79 {
80         d_printf("net_time_usage: TODO\n");
81         return 0;       
82 }
83
84 int net_time_help(struct net_context *ctx, int argc, const char **argv)
85 {
86         d_printf("net_time_help: TODO\n");
87         return 0;       
88 }