2 Unix SMB/CIFS implementation.
3 Authentication utility functions
4 Copyright (C) Volker Lendecke 2010
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "../librpc/gen_ndr/netlogon.h"
22 #include "../libcli/security/security.h"
23 #include "rpc_client/util_netlogon.h"
25 #define COPY_LSA_STRING(mem_ctx, in, out, name) do { \
26 if (in->name.string) { \
27 out->name.string = talloc_strdup(mem_ctx, in->name.string); \
28 NT_STATUS_HAVE_NO_MEMORY(out->name.string); \
32 NTSTATUS copy_netr_SamBaseInfo(TALLOC_CTX *mem_ctx,
33 const struct netr_SamBaseInfo *in,
34 struct netr_SamBaseInfo *out)
36 /* first copy all, then realloc pointers */
39 COPY_LSA_STRING(mem_ctx, in, out, account_name);
40 COPY_LSA_STRING(mem_ctx, in, out, full_name);
41 COPY_LSA_STRING(mem_ctx, in, out, logon_script);
42 COPY_LSA_STRING(mem_ctx, in, out, profile_path);
43 COPY_LSA_STRING(mem_ctx, in, out, home_directory);
44 COPY_LSA_STRING(mem_ctx, in, out, home_drive);
46 if (in->groups.count) {
47 out->groups.rids = (struct samr_RidWithAttribute *)
48 talloc_memdup(mem_ctx, in->groups.rids,
49 (sizeof(struct samr_RidWithAttribute) *
51 NT_STATUS_HAVE_NO_MEMORY(out->groups.rids);
54 COPY_LSA_STRING(mem_ctx, in, out, logon_server);
55 COPY_LSA_STRING(mem_ctx, in, out, logon_domain);
58 out->domain_sid = dom_sid_dup(mem_ctx, in->domain_sid);
59 NT_STATUS_HAVE_NO_MEMORY(out->domain_sid);
67 #define RET_NOMEM(ptr) do { \
73 struct netr_SamInfo3 *copy_netr_SamInfo3(TALLOC_CTX *mem_ctx,
74 const struct netr_SamInfo3 *orig)
76 struct netr_SamInfo3 *info3;
80 info3 = talloc_zero(mem_ctx, struct netr_SamInfo3);
81 if (!info3) return NULL;
83 status = copy_netr_SamBaseInfo(info3, &orig->base, &info3->base);
84 if (!NT_STATUS_IS_OK(status)) {
90 info3->sidcount = orig->sidcount;
91 info3->sids = talloc_array(info3, struct netr_SidAttr,
93 RET_NOMEM(info3->sids);
94 for (i = 0; i < orig->sidcount; i++) {
95 info3->sids[i].sid = dom_sid_dup(info3->sids,
97 RET_NOMEM(info3->sids[i].sid);
98 info3->sids[i].attributes =
99 orig->sids[i].attributes;