]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
netapi: make map_alias_info_to_buffer suitable for arrays in the buffer.
authorGünther Deschner <gd@samba.org>
Fri, 18 Jul 2008 13:10:43 +0000 (15:10 +0200)
committerGünther Deschner <gd@samba.org>
Fri, 18 Jul 2008 15:23:20 +0000 (17:23 +0200)
Guenther

source/lib/netapi/localgroup.c

index 9237c2bdf4b69c7cc7babb122d5ee54dbac9ebf3..d91045bab34c3b7ab03f8af0653feb9d7cc91281 100644 (file)
@@ -393,8 +393,10 @@ WERROR NetLocalGroupDel_l(struct libnetapi_ctx *ctx,
 ****************************************************************/
 
 static WERROR map_alias_info_to_buffer(TALLOC_CTX *mem_ctx,
+                                      const char *alias_name,
                                       struct samr_AliasInfoAll *info,
                                       uint32_t level,
+                                      uint32_t *entries_read,
                                       uint8_t **buffer)
 {
        struct LOCALGROUP_INFO_0 g0;
@@ -403,30 +405,33 @@ static WERROR map_alias_info_to_buffer(TALLOC_CTX *mem_ctx,
 
        switch (level) {
                case 0:
-                       g0.lgrpi0_name          = info->name.string;
+                       g0.lgrpi0_name          = talloc_strdup(mem_ctx, alias_name);
+                       W_ERROR_HAVE_NO_MEMORY(g0.lgrpi0_name);
 
-                       *buffer = (uint8_t *)talloc_memdup(mem_ctx, &g0, sizeof(g0));
+                       ADD_TO_ARRAY(mem_ctx, struct LOCALGROUP_INFO_0, g0,
+                                    (struct LOCALGROUP_INFO_0 **)buffer, entries_read);
 
                        break;
                case 1:
-                       g1.lgrpi1_name          = info->name.string;
-                       g1.lgrpi1_comment       = info->description.string;
+                       g1.lgrpi1_name          = talloc_strdup(mem_ctx, alias_name);
+                       g1.lgrpi1_comment       = talloc_strdup(mem_ctx, info->description.string);
+                       W_ERROR_HAVE_NO_MEMORY(g1.lgrpi1_name);
 
-                       *buffer = (uint8_t *)talloc_memdup(mem_ctx, &g1, sizeof(g1));
+                       ADD_TO_ARRAY(mem_ctx, struct LOCALGROUP_INFO_1, g1,
+                                    (struct LOCALGROUP_INFO_1 **)buffer, entries_read);
 
                        break;
                case 1002:
-                       g1002.lgrpi1002_comment = info->description.string;
+                       g1002.lgrpi1002_comment = talloc_strdup(mem_ctx, info->description.string);
 
-                       *buffer = (uint8_t *)talloc_memdup(mem_ctx, &g1002, sizeof(g1002));
+                       ADD_TO_ARRAY(mem_ctx, struct LOCALGROUP_INFO_1002, g1002,
+                                    (struct LOCALGROUP_INFO_1002 **)buffer, entries_read);
 
                        break;
                default:
                        return WERR_UNKNOWN_LEVEL;
        }
 
-       W_ERROR_HAVE_NO_MEMORY(*buffer);
-
        return WERR_OK;
 }
 
@@ -444,6 +449,7 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx,
        struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle;
        struct dom_sid2 *domain_sid = NULL;
        union samr_AliasInfo *alias_info = NULL;
+       uint32_t entries_read = 0;
 
        if (!r->in.group_name) {
                return WERR_INVALID_PARAM;
@@ -531,8 +537,11 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx,
                goto done;
        }
 
-       werr = map_alias_info_to_buffer(ctx, &alias_info->all,
-                                       r->in.level, r->out.buf);
+       werr = map_alias_info_to_buffer(ctx,
+                                       r->in.group_name,
+                                       &alias_info->all,
+                                       r->in.level, &entries_read,
+                                       r->out.buf);
 
  done:
        if (!cli) {