TODO TEST s3:winbindd: avoid connecting our primary domain from each child
authorStefan Metzmacher <metze@samba.org>
Wed, 31 Mar 2010 19:35:29 +0000 (21:35 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 29 Apr 2010 13:53:15 +0000 (15:53 +0200)
We can lookup the trust details in the trusted domain cache
instead of doinf network roundtrips and have multiple
open connections to our primary domain (without mutex
on the schannel state)

ADASDASD

source3/winbindd/winbindd_cm.c

index 8a1456f407879af4f93cf1c6729c4c5ef1f38995..54abce301274e459ca5ea35b7585f0046bd9733b 100644 (file)
@@ -1700,102 +1700,52 @@ static NTSTATUS init_dc_connection_rpc(struct winbindd_domain *domain)
 
 static bool set_dc_type_and_flags_trustinfo( struct winbindd_domain *domain )
 {
-       struct winbindd_domain *our_domain;
-       NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-       struct netr_DomainTrustList trusts;
-       int i;
-       uint32 flags = (NETR_TRUST_FLAG_IN_FOREST |
-                       NETR_TRUST_FLAG_OUTBOUND |
-                       NETR_TRUST_FLAG_INBOUND);
-       struct rpc_pipe_client *cli;
-       TALLOC_CTX *mem_ctx = NULL;
+       struct winbindd_tdc_domain *cached_domain;
 
        DEBUG(5, ("set_dc_type_and_flags_trustinfo: domain %s\n", domain->name ));
 
-       /* Our primary domain doesn't need to worry about trust flags.
-          Force it to go through the network setup */
-       if ( domain->primary ) {                
-               return False;           
-       }
-
-       our_domain = find_our_domain();
-
-       if ( !connection_ok(our_domain) ) {
-               DEBUG(3,("set_dc_type_and_flags_trustinfo: No connection to our domain!\n"));           
-               return False;
+       /*
+        * Our primary domain doesn't need to worry about trust flags.
+        * Force it to go through the network setup
+        */
+       if (domain->primary) {
+               return false;
        }
 
-       /* This won't work unless our domain is AD */
-
-       if ( !our_domain->active_directory ) {
-               return False;
+       cached_domain = wcache_tdc_fetch_domain(talloc_tos(), domain->name);
+       if (cached_domain == NULL) {
+               return domain->initialized;
        }
 
-       /* Use DsEnumerateDomainTrusts to get us the trust direction
-          and type */
-
-       result = cm_connect_netlogon(our_domain, &cli);
-
-       if (!NT_STATUS_IS_OK(result)) {
-               DEBUG(5, ("set_dc_type_and_flags_trustinfo: Could not open "
-                         "a connection to %s for PIPE_NETLOGON (%s)\n", 
-                         domain->name, nt_errstr(result)));
-               return False;
-       }
+       domain->domain_flags          = cached_domain->trust_flags;
+       domain->domain_type           = cached_domain->trust_type;
+       domain->domain_trust_attribs  = cached_domain->trust_attribs;
 
-       if ( (mem_ctx = talloc_init("set_dc_type_and_flags_trustinfo")) == NULL ) {
-               DEBUG(0,("set_dc_type_and_flags_trustinfo: talloc_init() failed!\n"));
-               return False;
-       }       
+       TALLOC_FREE(cached_domain);
 
-       result = rpccli_netr_DsrEnumerateDomainTrusts(cli, mem_ctx,
-                                                     cli->desthost,
-                                                     flags,
-                                                     &trusts,
-                                                     NULL);
-       if (!NT_STATUS_IS_OK(result)) {
-               DEBUG(0,("set_dc_type_and_flags_trustinfo: "
-                       "failed to query trusted domain list: %s\n",
-                       nt_errstr(result)));
-               talloc_destroy(mem_ctx);
-               return false;
+       if (domain->domain_type == NETR_TRUST_TYPE_UPLEVEL) {
+               domain->active_directory = true;
        }
 
-       /* Now find the domain name and get the flags */
-
-       for ( i=0; i<trusts.count; i++ ) {
-               if ( strequal( domain->name, trusts.array[i].netbios_name) ) {
-                       domain->domain_flags          = trusts.array[i].trust_flags;
-                       domain->domain_type           = trusts.array[i].trust_type;
-                       domain->domain_trust_attribs  = trusts.array[i].trust_attributes;
-
-                       if ( domain->domain_type == NETR_TRUST_TYPE_UPLEVEL )
-                               domain->active_directory = True;
-
-                       /* This flag is only set if the domain is *our* 
-                          primary domain and the primary domain is in
-                          native mode */
-
-                       domain->native_mode = (domain->domain_flags & NETR_TRUST_FLAG_NATIVE);
-
-                       DEBUG(5, ("set_dc_type_and_flags_trustinfo: domain %s is %sin "
-                                 "native mode.\n", domain->name, 
-                                 domain->native_mode ? "" : "NOT "));
-
-                       DEBUG(5,("set_dc_type_and_flags_trustinfo: domain %s is %s"
-                                "running active directory.\n", domain->name, 
-                                domain->active_directory ? "" : "NOT "));
+       /*
+        * This flag is only set if the domain is *our*
+        * primary domain and the primary domain is in
+        * native mode
+        */
 
+       domain->native_mode = (domain->domain_flags & NETR_TRUST_FLAG_NATIVE);
 
-                       domain->initialized = True;
+       DEBUG(5, ("set_dc_type_and_flags_trustinfo: domain %s is %sin "
+                 "native mode.\n", domain->name,
+                 domain->native_mode ? "" : "NOT "));
 
-                       break;
-               }               
-       }
+       DEBUG(5,("set_dc_type_and_flags_trustinfo: domain %s is %s"
+                "running active directory.\n", domain->name,
+                domain->active_directory ? "" : "NOT "));
 
-       talloc_destroy( mem_ctx );
+       domain->initialized = true;
 
-       return domain->initialized;     
+       return domain->initialized;
 }
 
 /******************************************************************************