From 6713f3d945f09a732e620641771d9ff403aca9ef Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Thu, 27 May 2010 02:40:59 -0400 Subject: [PATCH] s3:auth add function to copy a netr_SamInfo3 structure MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Günther Deschner --- source3/auth/server_info.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++ source3/include/proto.h | 2 ++ 2 files changed, 63 insertions(+) diff --git a/source3/auth/server_info.c b/source3/auth/server_info.c index 16dbfb3e962..d7ab19c58b4 100644 --- a/source3/auth/server_info.c +++ b/source3/auth/server_info.c @@ -507,3 +507,64 @@ NTSTATUS samu_to_SamInfo3(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } +#undef RET_NOMEM + +#define RET_NOMEM(ptr) do { \ + if (!ptr) { \ + TALLOC_FREE(info3); \ + return NULL; \ + } } while(0) + +struct netr_SamInfo3 *copy_netr_SamInfo3(TALLOC_CTX *mem_ctx, + struct netr_SamInfo3 *orig) +{ + struct netr_SamInfo3 *info3; + + info3 = talloc(mem_ctx, struct netr_SamInfo3); + if (!info3) return NULL; + + /* first copy all, then realloc pointers */ + info3->base = orig->base; + + info3->base.account_name.string = + talloc_strdup(info3, orig->base.account_name.string); + RET_NOMEM(info3->base.account_name.string); + info3->base.full_name.string = + talloc_strdup(info3, orig->base.full_name.string); + RET_NOMEM(info3->base.full_name.string); + info3->base.logon_script.string = + talloc_strdup(info3, orig->base.logon_script.string); + RET_NOMEM(info3->base.logon_script.string); + info3->base.profile_path.string = + talloc_strdup(info3, orig->base.profile_path.string); + RET_NOMEM(info3->base.profile_path.string); + info3->base.home_directory.string = + talloc_strdup(info3, orig->base.home_directory.string); + RET_NOMEM(info3->base.home_directory.string); + info3->base.home_drive.string = + talloc_strdup(info3, orig->base.home_drive.string); + RET_NOMEM(info3->base.home_drive.string); + + info3->base.groups.rids = + talloc_memdup(info3, orig->base.groups.rids, + (sizeof(struct samr_RidWithAttribute) * + orig->base.groups.count)); + RET_NOMEM(info3->base.groups.rids); + + info3->base.logon_server.string = + talloc_strdup(info3, orig->base.logon_server.string); + RET_NOMEM(info3->base.logon_server.string); + info3->base.domain.string = + talloc_strdup(info3, orig->base.domain.string); + RET_NOMEM(info3->base.domain.string); + + info3->base.domain_sid = sid_dup_talloc(info3, orig->base.domain_sid); + RET_NOMEM(info3->base.domain_sid); + + info3->sids = talloc_memdup(info3, orig->sids, + (sizeof(struct netr_SidAttr) * + orig->sidcount)); + RET_NOMEM(info3->sids); + + return info3; +} diff --git a/source3/include/proto.h b/source3/include/proto.h index 9a19fbe9b5e..ff7eb9383e2 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -182,6 +182,8 @@ NTSTATUS samu_to_SamInfo3(TALLOC_CTX *mem_ctx, struct samu *samu, const char *login_server, struct netr_SamInfo3 **_info3); +struct netr_SamInfo3 *copy_netr_SamInfo3(TALLOC_CTX *mem_ctx, + struct netr_SamInfo3 *orig); /* The following definitions come from auth/auth_wbc.c */ -- 2.11.4.GIT