root/source4/utils/net/net_time.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. net_time
  2. net_time_usage

   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 3 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, see <http://www.gnu.org/licenses/>.
  19 */
  20 
  21 #include "includes.h"
  22 #include "libnet/libnet.h"
  23 #include "utils/net/net.h"
  24 #include "system/time.h"
  25 #include "lib/events/events.h"
  26 
  27 /*
  28  * Code for getting the remote time
  29  */
  30 
  31 int net_time(struct net_context *ctx, int argc, const char **argv)
     /* [<][>][^][v][top][bottom][index][help] */
  32 {
  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];
  39 
  40         if (argc > 0 && argv[0]) {
  41                 server_name = argv[0];
  42         } else {
  43                 return net_time_usage(ctx, argc, argv);
  44         }
  45 
  46         libnetctx = libnet_context_init(ctx->event_ctx, ctx->lp_ctx);
  47         if (!libnetctx) {
  48                 return -1;      
  49         }
  50         libnetctx->cred = ctx->credentials;
  51 
  52         /* prepare to get the time */
  53         r.generic.level                 = LIBNET_REMOTE_TOD_GENERIC;
  54         r.generic.in.server_name        = server_name;
  55 
  56         /* get the time */
  57         status = libnet_RemoteTOD(libnetctx, ctx, &r);
  58         if (!NT_STATUS_IS_OK(status)) {
  59                 DEBUG(0,("net_time: %s\n",r.generic.out.error_string));
  60                 return -1;
  61         }
  62 
  63         ZERO_STRUCT(timestr);
  64         tm = localtime(&r.generic.out.time);
  65         strftime(timestr, sizeof(timestr)-1, "%c %Z",tm);
  66 
  67         printf("%s\n",timestr);
  68 
  69         talloc_free(libnetctx);
  70 
  71         return 0;
  72 }
  73 
  74 int net_time_usage(struct net_context *ctx, int argc, const char **argv)
     /* [<][>][^][v][top][bottom][index][help] */
  75 {
  76         d_printf("net time <server> [options]\n");
  77         return 0;       
  78 }

/* [<][>][^][v][top][bottom][index][help] */