s3-winbindd: use fill_domain_username_talloc() in winbind.
authorGünther Deschner <gd@samba.org>
Tue, 8 May 2018 09:18:56 +0000 (11:18 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 17 May 2018 15:30:08 +0000 (17:30 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13437

Guenther

Signed-off-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/winbindd/wb_getpwsid.c
source3/winbindd/wb_query_user_list.c
source3/winbindd/winbindd_group.c
source3/winbindd/winbindd_list_groups.c
source3/winbindd/winbindd_pam.c

index 01c2f9cebfbaf119f73207da63b1d020753f56ce..a8f32f2fc94187b886bc306ea81c3b6088626a78 100644 (file)
@@ -69,7 +69,8 @@ static void wb_getpwsid_queryuser_done(struct tevent_req *subreq)
                req, struct wb_getpwsid_state);
        struct winbindd_pw *pw = state->pw;
        struct wbint_userinfo *info;
-       fstring acct_name, output_username;
+       fstring acct_name;
+       const char *output_username;
        char *mapped_name = NULL;
        char *tmp;
        NTSTATUS status;
@@ -101,16 +102,24 @@ static void wb_getpwsid_queryuser_done(struct tevent_req *subreq)
                                    acct_name,
                                    &mapped_name);
        if (NT_STATUS_IS_OK(status)) {
-               fill_domain_username(output_username,
+               output_username = fill_domain_username_talloc(state,
                                     info->domain_name,
                                     mapped_name, true);
+               if (output_username == NULL) {
+                       tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
+                       return;
+               }
                fstrcpy(acct_name, mapped_name);
        } else if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_RENAMED)) {
                fstrcpy(acct_name, mapped_name);
        } else {
-               fill_domain_username(output_username,
+               output_username = fill_domain_username_talloc(state,
                                     info->domain_name,
                                     acct_name, true);
+               if (output_username == NULL) {
+                       tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
+                       return;
+               }
        }
 
        strlcpy(pw->pw_name, output_username, sizeof(pw->pw_name));
index 3c18080e8475c539ad9764f805f9424c2aa2d26e..6d699875e9b145eeef6db1fc48746e81304acb66 100644 (file)
@@ -104,11 +104,14 @@ static void wb_query_user_list_done(struct tevent_req *subreq)
 
        for (i=0; i<state->names.num_principals; i++) {
                struct wbint_Principal *p = &state->names.principals[i];
-               fstring name;
+               const char *name;
                int ret;
 
-               fill_domain_username(name, state->domain_name, p->name, true);
-
+               name = fill_domain_username_talloc(state, state->domain_name, p->name, true);
+               if (name == NULL) {
+                       tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
+                       return;
+               }
                ret = strv_add(state, &state->users, name);
                if (ret != 0) {
                        tevent_req_nterror(req, map_nt_error_from_unix(ret));
index 417565ecbf0ce91aa61cda45bf78bb0f0c58799d..76ba14afb3bfa5c8f3f91664ce134b0229601d83 100644 (file)
@@ -34,7 +34,7 @@
 bool fill_grent(TALLOC_CTX *mem_ctx, struct winbindd_gr *gr,
                const char *dom_name, const char *gr_name, gid_t unix_gid)
 {
-       fstring full_group_name;
+       const char *full_group_name;
        char *mapped_name = NULL;
        NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
 
@@ -43,19 +43,23 @@ bool fill_grent(TALLOC_CTX *mem_ctx, struct winbindd_gr *gr,
 
        /* Basic whitespace replacement */
        if (NT_STATUS_IS_OK(nt_status)) {
-               fill_domain_username(full_group_name, dom_name,
+               full_group_name = fill_domain_username_talloc(mem_ctx, dom_name,
                                     mapped_name, true);
        }
        /* Mapped to an aliase */
        else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_FILE_RENAMED)) {
-               fstrcpy(full_group_name, mapped_name);
+               full_group_name = mapped_name;
        }
        /* no change */
        else {
-               fill_domain_username( full_group_name, dom_name,
+               full_group_name = fill_domain_username_talloc(mem_ctx, dom_name,
                                      gr_name, True );
        }
 
+       if (full_group_name == NULL) {
+               return false;
+       }
+
        gr->gr_gid = unix_gid;
 
        /* Group name and password */
index f593ba26f2ac18c68841ac50de90eec43cef8466..36800ae54ec30336bd71e2c202cc024db59c0a33 100644 (file)
@@ -171,10 +171,13 @@ NTSTATUS winbindd_list_groups_recv(struct tevent_req *req,
                struct winbindd_list_groups_domstate *d = &state->domains[i];
 
                for (j=0; j<d->groups.num_principals; j++) {
-                       fstring name;
-                       fill_domain_username(name, d->domain->name,
+                       const char *name;
+                       name = fill_domain_username_talloc(response, d->domain->name,
                                             d->groups.principals[j].name,
                                             True);
+                       if (name == NULL) {
+                               return NT_STATUS_NO_MEMORY;
+                       }
                        len += strlen(name)+1;
                }
                response->data.num_entries += d->groups.num_principals;
@@ -190,11 +193,14 @@ NTSTATUS winbindd_list_groups_recv(struct tevent_req *req,
                struct winbindd_list_groups_domstate *d = &state->domains[i];
 
                for (j=0; j<d->groups.num_principals; j++) {
-                       fstring name;
+                       const char *name;
                        size_t this_len;
-                       fill_domain_username(name, d->domain->name,
+                       name = fill_domain_username_talloc(response, d->domain->name,
                                             d->groups.principals[j].name,
                                             True);
+                       if (name == NULL) {
+                               return NT_STATUS_NO_MEMORY;
+                       }
                        this_len = strlen(name);
                        memcpy(result+len, name, this_len);
                        len += this_len;
index 25564277f0a10f5a201cc939e589bf767f9c4a47..bed5a940282157801729384ed288020911554e02 100644 (file)
@@ -194,7 +194,7 @@ static NTSTATUS append_unix_username(TALLOC_CTX *mem_ctx,
        /* We've been asked to return the unix username, per
           'winbind use default domain' settings and the like */
 
-       const char *nt_username, *nt_domain;
+       const char *nt_username, *nt_domain, *unix_username;
 
        nt_domain = talloc_strdup(mem_ctx, info3->base.logon_domain.string);
        if (!nt_domain) {
@@ -210,8 +210,15 @@ static NTSTATUS append_unix_username(TALLOC_CTX *mem_ctx,
                nt_username = name_user;
        }
 
-       fill_domain_username(resp->data.auth.unix_username,
-                            nt_domain, nt_username, true);
+       unix_username = fill_domain_username_talloc(mem_ctx,
+                                                   nt_domain,
+                                                   nt_username,
+                                                   true);
+       if (unix_username == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       fstrcpy(resp->data.auth.unix_username, unix_username);
 
        DEBUG(5, ("Setting unix username to [%s]\n",
                  resp->data.auth.unix_username));