r5917: First step in using the new cli_credentials structure. This patch
[Samba/gebeck_regimport.git] / source4 / utils / net / net_time.c
blobdf3b52a4abf9aa2a67db862de5043f6afc78aa18
1 /*
2 Samba Unix/Linux SMB client library
3 Distributed SMB/CIFS Server Management Utility
5 Copyright (C) 2004 Stefan Metzmacher (metze@samba.org)
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.
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.
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.
22 #include "includes.h"
23 #include "libnet/libnet.h"
24 #include "utils/net/net.h"
25 #include "system/time.h"
28 * Code for getting the remote time
31 int net_time(struct net_context *ctx, int argc, const char **argv)
33 NTSTATUS status;
34 struct libnet_context *libnetctx;
35 union libnet_RemoteTOD r;
36 const char *server_name;
37 struct tm *tm;
38 char timestr[64];
40 if (argc > 0 && argv[0]) {
41 server_name = argv[0];
42 } else {
43 return net_time_usage(ctx, argc, argv);
46 libnetctx = libnet_context_init();
47 if (!libnetctx) {
48 return -1;
50 libnetctx->user.account_name= cli_credentials_get_username(ctx->credentials);
51 libnetctx->user.domain_name = cli_credentials_get_domain(ctx->credentials);
52 libnetctx->user.password = cli_credentials_get_password(ctx->credentials);
54 /* prepare to get the time */
55 r.generic.level = LIBNET_REMOTE_TOD_GENERIC;
56 r.generic.in.server_name = server_name;
58 /* get the time */
59 status = libnet_RemoteTOD(libnetctx, ctx->mem_ctx, &r);
60 if (!NT_STATUS_IS_OK(status)) {
61 DEBUG(0,("net_time: %s\n",r.generic.out.error_string));
62 return -1;
65 ZERO_STRUCT(timestr);
66 tm = localtime(&r.generic.out.time);
67 strftime(timestr, sizeof(timestr)-1, "%c %Z",tm);
69 printf("%s\n",timestr);
71 libnet_context_destroy(&libnetctx);
73 return 0;
76 int net_time_usage(struct net_context *ctx, int argc, const char **argv)
78 d_printf("net time <server> [options]\n");
79 return 0;