winbindd: return trust parameters when listing trusts
authorUri Simchoni <uri@samba.org>
Tue, 9 Feb 2016 22:38:11 +0000 (00:38 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 23 Feb 2016 21:02:16 +0000 (22:02 +0100)
When asking a child domain process to list trusts on that domain,
return (along with trust domain names and SID) the trust properties -
flags, type, and attributes.

Use those attributes to initialize domain object.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=11691

Signed-off-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Tue Feb 23 22:02:16 CET 2016 on sn-devel-144

source3/winbindd/winbindd_misc.c
source3/winbindd/winbindd_util.c

index 3e024c9e2feea5ca30051cffbdd50c99290f647d..560f197ec6646aec6a607244e326437ab6416664 100644 (file)
@@ -181,11 +181,12 @@ enum winbindd_result winbindd_dual_list_trusted_domains(struct winbindd_domain *
                }
 
                extra_data = talloc_asprintf_append_buffer(
-                       extra_data, "%s\\%s\\%s\n",
-                       trusts.array[i].netbios_name,
-                       trusts.array[i].dns_name,
-                       sid_string_talloc(state->mem_ctx,
-                                         trusts.array[i].sid));
+                   extra_data, "%s\\%s\\%s\\%u\\%u\\%u\n",
+                   trusts.array[i].netbios_name, trusts.array[i].dns_name,
+                   sid_string_talloc(state->mem_ctx, trusts.array[i].sid),
+                   trusts.array[i].trust_flags,
+                   (uint32_t)trusts.array[i].trust_type,
+                   trusts.array[i].trust_attributes);
        }
 
        /* add our primary domain */
index 020f45b8419509927153d7170c966274676ea3e5..c32352081e1b58f056f779d790e82a9a393b2099 100644 (file)
@@ -343,24 +343,37 @@ static void trustdom_list_done(struct tevent_req *req)
        struct winbindd_response *response;
        int res, err;
        char *p;
+       struct winbindd_tdc_domain trust_params = {0};
+       ptrdiff_t extra_len;
 
        res = wb_domain_request_recv(req, state, &response, &err);
        if ((res == -1) || (response->result != WINBINDD_OK)) {
-               DEBUG(1, ("Could not receive trustdoms\n"));
+               DBG_WARNING("Could not receive trustdoms\n");
                TALLOC_FREE(state);
                return;
        }
 
+       if (response->length < sizeof(struct winbindd_response)) {
+               DBG_ERR("ill-formed trustdom response - short length\n");
+               TALLOC_FREE(state);
+               return;
+       }
+
+       extra_len = response->length - sizeof(struct winbindd_response);
+
        p = (char *)response->extra_data.data;
 
-       while ((p != NULL) && (*p != '\0')) {
+       while ((p - (char *)response->extra_data.data) < extra_len) {
                char *q, *sidstr, *alt_name;
-               struct dom_sid sid;
-               char *alternate_name = NULL;
+
+               DBG_DEBUG("parsing response line '%s'\n", p);
+
+               ZERO_STRUCT(trust_params);
+               trust_params.domain_name = p;
 
                alt_name = strchr(p, '\\');
                if (alt_name == NULL) {
-                       DEBUG(0, ("Got invalid trustdom response\n"));
+                       DBG_ERR("Got invalid trustdom response\n");
                        break;
                }
 
@@ -369,26 +382,52 @@ static void trustdom_list_done(struct tevent_req *req)
 
                sidstr = strchr(alt_name, '\\');
                if (sidstr == NULL) {
-                       DEBUG(0, ("Got invalid trustdom response\n"));
+                       DBG_ERR("Got invalid trustdom response\n");
                        break;
                }
 
                *sidstr = '\0';
                sidstr += 1;
 
-               q = strchr(sidstr, '\n');
-               if (q != NULL)
-                       *q = '\0';
+               /* use the real alt_name if we have one, else pass in NULL */
+               if (!strequal(alt_name, "(null)")) {
+                       trust_params.dns_name = alt_name;
+               }
+
+               q = strtok(sidstr, "\\");
+               if (q == NULL) {
+                       DBG_ERR("Got invalid trustdom response\n");
+                       break;
+               }
 
-               if (!string_to_sid(&sid, sidstr)) {
+               if (!string_to_sid(&trust_params.sid, sidstr)) {
                        DEBUG(0, ("Got invalid trustdom response\n"));
                        break;
                }
 
-               /* use the real alt_name if we have one, else pass in NULL */
+               q = strtok(NULL, "\\");
+               if (q == NULL) {
+                       DBG_ERR("Got invalid trustdom response\n");
+                       break;
+               }
+
+               trust_params.trust_flags = (uint32_t)strtoul(q, NULL, 10);
+
+               q = strtok(NULL, "\\");
+               if (q == NULL) {
+                       DBG_ERR("Got invalid trustdom response\n");
+                       break;
+               }
+
+               trust_params.trust_type = (uint32_t)strtoul(q, NULL, 10);
+
+               q = strtok(NULL, "\n");
+               if (q == NULL) {
+                       DBG_ERR("Got invalid trustdom response\n");
+                       break;
+               }
 
-               if ( !strequal( alt_name, "(null)" ) )
-                       alternate_name = alt_name;
+               trust_params.trust_attribs = (uint32_t)strtoul(q, NULL, 10);
 
                /*
                 * We always call add_trusted_domain() cause on an existing
@@ -396,13 +435,10 @@ static void trustdom_list_done(struct tevent_req *req)
                 * This is important because we need the SID for sibling
                 * domains.
                 */
-               (void)add_trusted_domain(p, alternate_name,
-                                           &cache_methods,
-                                           &sid);
+               (void)add_trusted_domain_from_tdc(&trust_params,
+                                                 &cache_methods);
 
-               p=q;
-               if (p != NULL)
-                       p += 1;
+               p = q + strlen(q) + 1;
        }
 
        /*