r2065: add libnet_RemoteTOD() call with levels GENERIC and SRVSVC
authorStefan Metzmacher <metze@samba.org>
Wed, 25 Aug 2004 12:11:28 +0000 (12:11 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:58:23 +0000 (12:58 -0500)
metze
(This used to be commit 72e3b351d0169366aa88c5445ffa555da6efd1d0)

source4/libnet/config.mk
source4/libnet/libnet.h
source4/libnet/libnet_time.c [new file with mode: 0644]
source4/libnet/libnet_time.h [new file with mode: 0644]

index c35d18fefed89edf079b16c44fdf103534b0b899..36d369117d076cd9c09355fb6ad2f89900c1d0c6 100644 (file)
@@ -5,6 +5,7 @@ INIT_OBJ_FILES = \
                libnet/libnet.o
 ADD_OBJ_FILES = \
                libnet/libnet_passwd.o \
+               libnet/libnet_time.o \
                libnet/libnet_rpc.o
 # End SUBSYSTEM LIBNET
 #################################
index 20779f0c3f179f5e706c3d81f60b1b02bfbc1897..55681137475e123bd2a80c4e08dbbed49e519903 100644 (file)
@@ -33,4 +33,5 @@ struct libnet_context {
 };
 
 #include "libnet/libnet_passwd.h"
+#include "libnet/libnet_time.h"
 #include "libnet/libnet_rpc.h"
diff --git a/source4/libnet/libnet_time.c b/source4/libnet/libnet_time.c
new file mode 100644 (file)
index 0000000..f56e648
--- /dev/null
@@ -0,0 +1,121 @@
+/* 
+   Unix SMB/CIFS implementation.
+   
+   Copyright (C) Stefan Metzmacher     2004
+   
+   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 02139, USA.
+*/
+
+#include "includes.h"
+
+/*
+ * get the remote time of a server via srvsvc_NetRemoteTOD
+ */
+static NTSTATUS libnet_RemoteTOD_srvsvc(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, union libnet_RemoteTOD *r)
+{
+        NTSTATUS status;
+       union libnet_rpc_connect c;
+       struct srvsvc_NetRemoteTOD tod;
+       struct tm tm;
+
+       /* prepare connect to the SRVSVC pipe of a timeserver */
+       c.standard.level                        = LIBNET_RPC_CONNECT_STANDARD;
+       c.standard.in.server_name               = r->srvsvc.in.server_name;
+       c.standard.in.dcerpc_iface_name         = DCERPC_SRVSVC_NAME;
+       c.standard.in.dcerpc_iface_uuid         = DCERPC_SRVSVC_UUID;
+       c.standard.in.dcerpc_iface_version      = DCERPC_SRVSVC_VERSION;
+
+       /* 1. connect to the SRVSVC pipe of a timeserver */
+       status = libnet_rpc_connect(ctx, mem_ctx, &c);
+       if (!NT_STATUS_IS_OK(status)) {
+               r->srvsvc.out.error_string = talloc_asprintf(mem_ctx,
+                                               "Connection to SRVSVC pipe of server '%s' failed: %s\n",
+                                               r->srvsvc.in.server_name, nt_errstr(status));
+               return status;
+       }
+
+       /* prepare srvsvc_NetrRemoteTOD */
+       tod.in.server_unc = talloc_asprintf(mem_ctx, "\\%s", c.standard.in.server_name);
+
+       /* 2. try srvsvc_NetRemoteTOD */
+       status = dcerpc_srvsvc_NetRemoteTOD(c.pdc.out.dcerpc_pipe, mem_ctx, &tod);
+       if (!NT_STATUS_IS_OK(status)) {
+               r->srvsvc.out.error_string = talloc_asprintf(mem_ctx,
+                                               "srvsvc_NetrRemoteTOD on server '%s' failed: %s\n",
+                                               r->srvsvc.in.server_name, nt_errstr(status));
+               goto disconnect;
+       }
+
+       /* check result of srvsvc_NetrRemoteTOD */
+       if (!W_ERROR_IS_OK(tod.out.result)) {
+               r->srvsvc.out.error_string = talloc_asprintf(mem_ctx,
+                                               "srvsvc_NetrRemoteTOD on server '%s' failed: %s\n",
+                                               r->srvsvc.in.server_name, win_errstr(tod.out.result));
+               status = werror_to_ntstatus(tod.out.result);
+               goto disconnect;
+       }
+
+       /* need to set the out parameters */
+       tm.tm_sec = (int)tod.out.info->secs;
+       tm.tm_min = (int)tod.out.info->mins;
+       tm.tm_hour = (int)tod.out.info->hours;
+       tm.tm_mday = (int)tod.out.info->day;
+       tm.tm_mon = (int)tod.out.info->month -1;
+       tm.tm_year = (int)tod.out.info->year - 1900;
+       tm.tm_wday = -1;
+       tm.tm_yday = -1;
+       tm.tm_isdst = -1;
+
+       r->srvsvc.out.time = timegm(&tm);
+       r->srvsvc.out.time_zone = ((int32_t)tod.out.info->timezone) * 60;
+
+       goto disconnect;
+
+disconnect:
+       /* close connection */
+       dcerpc_pipe_close(c.standard.out.dcerpc_pipe);
+
+       return status;
+}
+
+static NTSTATUS libnet_RemoteTOD_generic(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, union libnet_RemoteTOD *r)
+{
+       NTSTATUS status;
+       union libnet_RemoteTOD r2;
+
+       r2.srvsvc.level                 = LIBNET_REMOTE_TOD_SRVSVC;
+       r2.srvsvc.in.server_name        = r->generic.in.server_name;
+
+       status = libnet_RemoteTOD(ctx, mem_ctx, &r2);
+
+       r->generic.out.time             = r2.srvsvc.out.time;
+       r->generic.out.time_zone        = r2.srvsvc.out.time_zone;
+
+       r->generic.out.error_string     = r2.srvsvc.out.error_string;
+
+       return status;
+}
+
+NTSTATUS libnet_RemoteTOD(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, union libnet_RemoteTOD *r)
+{
+       switch (r->generic.level) {
+               case LIBNET_REMOTE_TOD_GENERIC:
+                       return libnet_RemoteTOD_generic(ctx, mem_ctx, r);
+               case LIBNET_REMOTE_TOD_SRVSVC:
+                       return libnet_RemoteTOD_srvsvc(ctx, mem_ctx, r);
+       }
+
+       return NT_STATUS_INVALID_LEVEL;
+}
diff --git a/source4/libnet/libnet_time.h b/source4/libnet/libnet_time.h
new file mode 100644 (file)
index 0000000..d8f9c16
--- /dev/null
@@ -0,0 +1,47 @@
+/* 
+   Unix SMB/CIFS implementation.
+   
+   Copyright (C) Stefan Metzmacher     2004
+   
+   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 02139, USA.
+*/
+
+/* struct and enum for getting the time of a remote system */
+enum libnet_RemoteTOD_level {
+       LIBNET_REMOTE_TOD_GENERIC,
+       LIBNET_REMOTE_TOD_SRVSVC
+};
+
+union libnet_RemoteTOD {
+       struct {
+               enum libnet_RemoteTOD_level level;
+
+               struct _libnet_RemoteTOD_in {
+                       const char *server_name;
+               } in;
+
+               struct _libnet_RemoteTOD_out {
+                       time_t time;
+                       int time_zone;
+                       const char *error_string;
+               } out;
+       } generic;
+
+       struct {
+               enum libnet_RemoteTOD_level level;
+               struct _libnet_RemoteTOD_in in;
+               struct _libnet_RemoteTOD_out out;
+       } srvsvc;
+};