s3-winbind: Implemented samr backend function sam_trusted_domains.
authorAndreas Schneider <asn@samba.org>
Mon, 7 Jun 2010 19:46:02 +0000 (21:46 +0200)
committerAndreas Schneider <asn@samba.org>
Mon, 5 Jul 2010 13:59:06 +0000 (15:59 +0200)
source3/winbindd/winbindd_samr.c

index 57a9d5829251e6fad6c010fadf282960afd2b6bc..2cf3b649bf6e2dad93fd078c014fbf03c4e53a9d 100644 (file)
@@ -474,8 +474,87 @@ static NTSTATUS sam_trusted_domains(struct winbindd_domain *domain,
                                    TALLOC_CTX *mem_ctx,
                                    struct netr_DomainTrustList *trusts)
 {
-       /* TODO FIXME */
-       return NT_STATUS_NOT_IMPLEMENTED;
+       struct rpc_pipe_client *lsa_pipe;
+       struct netr_DomainTrust *array = NULL;
+       struct policy_handle lsa_policy;
+       uint32_t enum_ctx = 0;
+       uint32_t count = 0;
+       TALLOC_CTX *tmp_ctx;
+       NTSTATUS status;
+
+       DEBUG(3,("samr: trusted domains\n"));
+
+       tmp_ctx = talloc_stackframe();
+       if (tmp_ctx == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       status = open_internal_lsa_conn(tmp_ctx, &lsa_pipe, &lsa_policy);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto error;
+       }
+
+       do {
+               struct lsa_DomainList dom_list;
+               uint32_t start_idx;
+               uint32_t i;
+
+               /*
+                * We don't run into deadlocks here, cause winbind_off() is
+                * called in the main function.
+                */
+               status = rpccli_lsa_EnumTrustDom(lsa_pipe,
+                                                tmp_ctx,
+                                                &lsa_policy,
+                                                &enum_ctx,
+                                                &dom_list,
+                                                (uint32_t) -1);
+               if (!NT_STATUS_IS_OK(status)) {
+                       if (!NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
+                               goto error;
+                       }
+               }
+
+               start_idx = trusts->count;
+               count += dom_list.count;
+
+               array = talloc_realloc(tmp_ctx,
+                                      array,
+                                      struct netr_DomainTrust,
+                                      count);
+               if (array == NULL) {
+                       status = NT_STATUS_NO_MEMORY;
+                       goto error;
+               }
+
+               for (i = 0; i < dom_list.count; i++) {
+                       struct netr_DomainTrust *trust = &array[i];
+                       struct dom_sid *sid;
+
+                       ZERO_STRUCTP(trust);
+
+                       trust->netbios_name = talloc_move(array,
+                                                         &dom_list.domains[i].name.string);
+                       trust->dns_name = NULL;
+
+                       sid = talloc(array, struct dom_sid);
+                       if (sid == NULL) {
+                               status = NT_STATUS_NO_MEMORY;
+                               goto error;
+                       }
+                       sid_copy(sid, dom_list.domains[i].sid);
+                       trust->sid = sid;
+               }
+       } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
+
+       if (trusts) {
+               trusts->count = count;
+               trusts->array = talloc_move(mem_ctx, &array);
+       }
+
+error:
+       TALLOC_FREE(tmp_ctx);
+       return status;
 }
 
 /* Lookup group membership given a rid.   */