s3: winbind: Remove fstring from wb_acct_info struct
authorSamuel Cabrero <scabrero@suse.de>
Tue, 30 Oct 2018 17:47:16 +0000 (18:47 +0100)
committerJeremy Allison <jra@samba.org>
Thu, 1 Nov 2018 00:59:10 +0000 (01:59 +0100)
The group enumeration backend functions try to allocate an array of
wb_acct_info structs with a number of elements equal to the number of
groups. In domains with a large number of groups this allocation may
fail due to the size of the chunk.

Found while trying to enumerate the groups in a domain with more than
700k groups.

Signed-off-by: Samuel Cabrero <scabrero@suse.de>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/winbindd/winbindd.h
source3/winbindd/winbindd_ads.c
source3/winbindd/winbindd_cache.c
source3/winbindd/winbindd_rpc.c

index 57371765484e5be60c515df2c76ec46fa82dfb1c..6d4b92f27cfe70539da22db6aa0640de4a01bff0 100644 (file)
@@ -189,8 +189,8 @@ struct winbindd_domain {
 };
 
 struct wb_acct_info {
-       fstring acct_name; /* account name */
-       fstring acct_desc; /* account name */
+       const char *acct_name; /* account name */
+       const char *acct_desc; /* account name */
        uint32_t rid; /* domain-relative RID */
 };
 
index 76d6a304366c871bb2190e4e448646dccf585a62..abc044d54aca1a00296d9fce2f4aa46bc3c58f7c 100644 (file)
@@ -500,8 +500,8 @@ static NTSTATUS enum_dom_groups(struct winbindd_domain *domain,
                struct dom_sid sid;
                uint32_t rid;
 
-               name = ads_pull_username(ads, mem_ctx, msg);
-               gecos = ads_pull_string(ads, mem_ctx, msg, "name");
+               name = ads_pull_username(ads, (*info), msg);
+               gecos = ads_pull_string(ads, (*info), msg, "name");
                if (!ads_pull_sid(ads, msg, "objectSid", &sid)) {
                        DEBUG(1,("No sid for %s !?\n", name));
                        continue;
@@ -512,8 +512,8 @@ static NTSTATUS enum_dom_groups(struct winbindd_domain *domain,
                        continue;
                }
 
-               fstrcpy((*info)[i].acct_name, name);
-               fstrcpy((*info)[i].acct_desc, gecos);
+               (*info)[i].acct_name = name;
+               (*info)[i].acct_desc = gecos;
                (*info)[i].rid = rid;
                i++;
        }
index 7d98d613ac447194b4a9ac32ea861c3d30ac3da1..2e2a04d09d8ec8542d46906abb097e241edb8333 100644 (file)
@@ -1565,8 +1565,8 @@ do_fetch_cache:
                smb_panic_fn("enum_dom_groups out of memory");
        }
        for (i=0; i<(*num_entries); i++) {
-               fstrcpy((*info)[i].acct_name, centry_string(centry, mem_ctx));
-               fstrcpy((*info)[i].acct_desc, centry_string(centry, mem_ctx));
+               (*info)[i].acct_name = centry_string(centry, (*info));
+               (*info)[i].acct_desc = centry_string(centry, (*info));
                (*info)[i].rid = centry_uint32(centry);
        }
 
@@ -1660,8 +1660,8 @@ do_fetch_cache:
                smb_panic_fn("enum_dom_groups out of memory");
        }
        for (i=0; i<(*num_entries); i++) {
-               fstrcpy((*info)[i].acct_name, centry_string(centry, mem_ctx));
-               fstrcpy((*info)[i].acct_desc, centry_string(centry, mem_ctx));
+               (*info)[i].acct_name = centry_string(centry, (*info));
+               (*info)[i].acct_desc = centry_string(centry, (*info));
                (*info)[i].rid = centry_uint32(centry);
        }
 
index f50fb8fa5dba23bcc50bdfca05baa9ae17df6606..6f7cb07f4e38f8c3ae5290e353c4867b76f70708 100644 (file)
@@ -155,9 +155,13 @@ NTSTATUS rpc_enum_dom_groups(TALLOC_CTX *mem_ctx,
                for (g = 0; g < count; g++) {
                        struct wb_acct_info *i = &info[num_info + g];
 
-                       fstrcpy(i->acct_name,
+                       i->acct_name = talloc_strdup(info,
                                sam_array->entries[g].name.string);
-                       fstrcpy(i->acct_desc, "");
+                       if (i->acct_name == NULL) {
+                               TALLOC_FREE(info);
+                               return NT_STATUS_NO_MEMORY;
+                       }
+                       i->acct_desc = NULL;
                        i->rid = sam_array->entries[g].idx;
                }
 
@@ -217,9 +221,13 @@ NTSTATUS rpc_enum_local_groups(TALLOC_CTX *mem_ctx,
                for (g = 0; g < count; g++) {
                        struct wb_acct_info *i = &info[num_info + g];
 
-                       fstrcpy(i->acct_name,
+                       i->acct_name = talloc_strdup(info,
                                sam_array->entries[g].name.string);
-                       fstrcpy(i->acct_desc, "");
+                       if (i->acct_name == NULL) {
+                               TALLOC_FREE(info);
+                               return NT_STATUS_NO_MEMORY;
+                       }
+                       i->acct_desc = NULL;
                        i->rid = sam_array->entries[g].idx;
                }