s3:auth add function to copy a netr_SamInfo3 structure
authorSimo Sorce <ssorce@redhat.com>
Thu, 27 May 2010 06:40:59 +0000 (02:40 -0400)
committerGünther Deschner <gd@samba.org>
Thu, 27 May 2010 22:55:27 +0000 (00:55 +0200)
Signed-off-by: Günther Deschner <gd@samba.org>
source3/auth/server_info.c
source3/include/proto.h

index 16dbfb3e962ae5047110b89659665c6d64c16597..d7ab19c58b44e60abcdfdf6e34570a8f1f59a17b 100644 (file)
@@ -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;
+}
index 9a19fbe9b5e85bb7d98888b5f9405b13aea54be9..ff7eb9383e227154470154d1a42262ef10af38fa 100644 (file)
@@ -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  */