s3-auth: add copy_netr_SamBaseInfo().
authorGünther Deschner <gd@samba.org>
Tue, 11 Jan 2011 14:08:41 +0000 (15:08 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 4 Feb 2011 15:57:32 +0000 (16:57 +0100)
Guenther

Signed-off-by: Stefan Metzmacher <metze@samba.org>
source3/Makefile.in
source3/auth/server_info.c
source3/rpc_client/util_netlogon.c [new file with mode: 0644]
source3/rpc_client/util_netlogon.h [new file with mode: 0644]
source3/wscript_build

index 09cd71315b96e6fea770fdbb3dbad526ed2ad628..ebfee9fbc9b2ab14b09d67a6a3669b1bb77d0449 100644 (file)
@@ -375,7 +375,8 @@ LIBCLI_SAMR_OBJ = librpc/gen_ndr/ndr_samr_c.o \
                  rpc_client/cli_samr.o
 
 LIBCLI_NETLOGON_OBJ = librpc/gen_ndr/ndr_netlogon_c.o \
-                     rpc_client/cli_netlogon.o
+                     rpc_client/cli_netlogon.o \
+                     rpc_client/util_netlogon.o
 
 LIBCLI_EPMAPPER_OBJ = librpc/gen_ndr/ndr_epmapper_c.o
 
index 01c7a96cdc44c2402b9d986d357754159c60348a..0f62983560a3aa1d1bd52ec20ffbcfa452715dee 100644 (file)
@@ -21,6 +21,7 @@
 #include "../lib/crypto/arcfour.h"
 #include "../librpc/gen_ndr/netlogon.h"
 #include "../libcli/security/security.h"
+#include "rpc_client/util_netlogon.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_AUTH
@@ -490,66 +491,15 @@ struct netr_SamInfo3 *copy_netr_SamInfo3(TALLOC_CTX *mem_ctx,
 {
        struct netr_SamInfo3 *info3;
        unsigned int i;
+       NTSTATUS status;
 
        info3 = talloc_zero(mem_ctx, struct netr_SamInfo3);
        if (!info3) return NULL;
 
-       /* first copy all, then realloc pointers */
-       info3->base = orig->base;
-
-       if (orig->base.account_name.string) {
-               info3->base.account_name.string =
-                       talloc_strdup(info3, orig->base.account_name.string);
-               RET_NOMEM(info3->base.account_name.string);
-       }
-       if (orig->base.full_name.string) {
-               info3->base.full_name.string =
-                       talloc_strdup(info3, orig->base.full_name.string);
-               RET_NOMEM(info3->base.full_name.string);
-       }
-       if (orig->base.logon_script.string) {
-               info3->base.logon_script.string =
-                       talloc_strdup(info3, orig->base.logon_script.string);
-               RET_NOMEM(info3->base.logon_script.string);
-       }
-       if (orig->base.profile_path.string) {
-               info3->base.profile_path.string =
-                       talloc_strdup(info3, orig->base.profile_path.string);
-               RET_NOMEM(info3->base.profile_path.string);
-       }
-       if (orig->base.home_directory.string) {
-               info3->base.home_directory.string =
-                       talloc_strdup(info3, orig->base.home_directory.string);
-               RET_NOMEM(info3->base.home_directory.string);
-       }
-       if (orig->base.home_drive.string) {
-               info3->base.home_drive.string =
-                       talloc_strdup(info3, orig->base.home_drive.string);
-               RET_NOMEM(info3->base.home_drive.string);
-       }
-
-       if (orig->base.groups.count) {
-               info3->base.groups.rids = (struct samr_RidWithAttribute *)
-                       talloc_memdup(info3, orig->base.groups.rids,
-                               (sizeof(struct samr_RidWithAttribute) *
-                                       orig->base.groups.count));
-               RET_NOMEM(info3->base.groups.rids);
-       }
-
-       if (orig->base.logon_server.string) {
-               info3->base.logon_server.string =
-                       talloc_strdup(info3, orig->base.logon_server.string);
-               RET_NOMEM(info3->base.logon_server.string);
-       }
-       if (orig->base.domain.string) {
-               info3->base.domain.string =
-                       talloc_strdup(info3, orig->base.domain.string);
-               RET_NOMEM(info3->base.domain.string);
-       }
-
-       if (orig->base.domain_sid) {
-               info3->base.domain_sid = dom_sid_dup(info3, orig->base.domain_sid);
-               RET_NOMEM(info3->base.domain_sid);
+       status = copy_netr_SamBaseInfo(info3, &orig->base, &info3->base);
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(info3);
+               return NULL;
        }
 
        if (orig->sidcount) {
diff --git a/source3/rpc_client/util_netlogon.c b/source3/rpc_client/util_netlogon.c
new file mode 100644 (file)
index 0000000..558a4da
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+   Unix SMB/CIFS implementation.
+   Authentication utility functions
+   Copyright (C) Volker Lendecke 2010
+
+   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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "../librpc/gen_ndr/netlogon.h"
+#include "../libcli/security/security.h"
+#include "rpc_client/util_netlogon.h"
+
+#define COPY_LSA_STRING(mem_ctx, in, out, name) do { \
+       if (in->name.string) { \
+               out->name.string = talloc_strdup(mem_ctx, in->name.string); \
+               NT_STATUS_HAVE_NO_MEMORY(out->name.string); \
+       } \
+} while (0)
+
+NTSTATUS copy_netr_SamBaseInfo(TALLOC_CTX *mem_ctx,
+                              const struct netr_SamBaseInfo *in,
+                              struct netr_SamBaseInfo *out)
+{
+       /* first copy all, then realloc pointers */
+       *out = *in;
+
+       COPY_LSA_STRING(mem_ctx, in, out, account_name);
+       COPY_LSA_STRING(mem_ctx, in, out, full_name);
+       COPY_LSA_STRING(mem_ctx, in, out, logon_script);
+       COPY_LSA_STRING(mem_ctx, in, out, profile_path);
+       COPY_LSA_STRING(mem_ctx, in, out, home_directory);
+       COPY_LSA_STRING(mem_ctx, in, out, home_drive);
+
+       if (in->groups.count) {
+               out->groups.rids = (struct samr_RidWithAttribute *)
+                       talloc_memdup(mem_ctx, in->groups.rids,
+                               (sizeof(struct samr_RidWithAttribute) *
+                                       in->groups.count));
+               NT_STATUS_HAVE_NO_MEMORY(out->groups.rids);
+       }
+
+       COPY_LSA_STRING(mem_ctx, in, out, logon_server);
+       COPY_LSA_STRING(mem_ctx, in, out, domain);
+
+       if (in->domain_sid) {
+               out->domain_sid = dom_sid_dup(mem_ctx, in->domain_sid);
+               NT_STATUS_HAVE_NO_MEMORY(out->domain_sid);
+       }
+
+       return NT_STATUS_OK;
+}
diff --git a/source3/rpc_client/util_netlogon.h b/source3/rpc_client/util_netlogon.h
new file mode 100644 (file)
index 0000000..42e4326
--- /dev/null
@@ -0,0 +1,5 @@
+/* The following definitions come from rpc_client/util_netlogon.c  */
+
+NTSTATUS copy_netr_SamBaseInfo(TALLOC_CTX *mem_ctx,
+                              const struct netr_SamBaseInfo *in,
+                              struct netr_SamBaseInfo *out);
index 611e28d5ce842c6ad8208e3a831302a88ffd3067..91af04863ca77be2e94f353117f8e57729a83b46 100644 (file)
@@ -43,7 +43,7 @@ LIBCLI_LSA_SRC = '''rpc_client/cli_lsarpc.c'''
 
 LIBCLI_SAMR_SRC = 'rpc_client/cli_samr.c'
 
-LIBRPCCLI_NETLOGON_SRC = 'rpc_client/cli_netlogon.c'
+LIBRPCCLI_NETLOGON_SRC = 'rpc_client/cli_netlogon.c rpc_client/util_netlogon.c'
 
 # this includes only the low level parse code, not stuff
 # that requires knowledge of security contexts