summaryrefslogtreecommitdiff
path: root/source3/nsswitch/winbindd_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/nsswitch/winbindd_util.c')
-rw-r--r--source3/nsswitch/winbindd_util.c61
1 files changed, 29 insertions, 32 deletions
diff --git a/source3/nsswitch/winbindd_util.c b/source3/nsswitch/winbindd_util.c
index a810e503a0..79588477ba 100644
--- a/source3/nsswitch/winbindd_util.c
+++ b/source3/nsswitch/winbindd_util.c
@@ -80,6 +80,7 @@ static struct winbindd_domain *add_trusted_domain(const char *domain_name, const
DOM_SID *sid)
{
struct winbindd_domain *domain;
+ char *contact_name;
/* We can't call domain_list() as this function is called from
init_domain_list() and we'll get stuck in a loop. */
@@ -125,10 +126,12 @@ static struct winbindd_domain *add_trusted_domain(const char *domain_name, const
sid_copy(&domain->sid, sid);
}
- /* see if this is a native mode win2k domain */
+ /* see if this is a native mode win2k domain (use realm name if possible) */
- domain->native_mode = cm_check_for_native_mode_win2k( domain_name );
- DEBUG(3,("add_trusted_domain: %s is a %s mode domain\n", domain_name,
+ contact_name = *domain->alt_name ? domain->alt_name : domain->name;
+ domain->native_mode = cm_check_for_native_mode_win2k( contact_name );
+
+ DEBUG(3,("add_trusted_domain: %s is a %s mode domain\n", contact_name,
domain->native_mode ? "native" : "mixed (or NT4)" ));
/* Link to domain list */
@@ -145,53 +148,45 @@ static struct winbindd_domain *add_trusted_domain(const char *domain_name, const
/*
rescan our domains looking for new trusted domains
*/
-void rescan_trusted_domains(BOOL force)
+void add_trusted_domains( struct winbindd_domain *domain )
{
- struct winbindd_domain *domain;
TALLOC_CTX *mem_ctx;
- static time_t last_scan;
- time_t t = time(NULL);
+ NTSTATUS result;
+ time_t t;
+ char **names;
+ char **alt_names;
+ int num_domains = 0;
+ DOM_SID *dom_sids, null_sid;
+ int i;
+ struct winbindd_domain *new_domain;
/* trusted domains might be disabled */
if (!lp_allow_trusted_domains()) {
return;
}
- /* Only rescan every few minutes but force if necessary */
-
- if (((unsigned)(t - last_scan) < WINBINDD_RESCAN_FREQ) && !force)
- return;
-
- last_scan = t;
-
DEBUG(1, ("scanning trusted domain list\n"));
if (!(mem_ctx = talloc_init("init_domain_list")))
return;
+
+ ZERO_STRUCTP(&null_sid);
- for (domain = _domain_list; domain; domain = domain->next) {
- NTSTATUS result;
- char **names;
- char **alt_names;
- int num_domains = 0;
- DOM_SID *dom_sids, null_sid;
- int i;
- struct winbindd_domain *new_domain;
+ t = time(NULL);
+
+ /* ask the DC what domains it trusts */
+
+ result = domain->methods->trusted_domains(domain, mem_ctx, &num_domains,
+ &names, &alt_names, &dom_sids);
- ZERO_STRUCTP(&null_sid);
-
- result = domain->methods->trusted_domains(domain, mem_ctx, &num_domains,
- &names, &alt_names, &dom_sids);
- if (!NT_STATUS_IS_OK(result)) {
- continue;
- }
+ if ( NT_STATUS_IS_OK(result) ) {
/* Add each domain to the trusted domain list */
for(i = 0; i < num_domains; i++) {
DEBUG(10,("Found domain %s\n", names[i]));
add_trusted_domain(names[i], alt_names?alt_names[i]:NULL,
- domain->methods, &dom_sids[i]);
+ domain->methods, &dom_sids[i]);
/* if the SID was empty, we better set it now */
@@ -212,7 +207,7 @@ void rescan_trusted_domains(BOOL force)
result = domain->methods->domain_sid( new_domain, &new_domain->sid );
if ( NT_STATUS_IS_OK(result) )
- sid_copy( &dom_sids[i], &domain->sid );
+ sid_copy( &dom_sids[i], &new_domain->sid );
}
/* store trusted domain in the cache */
@@ -234,7 +229,9 @@ BOOL init_domain_list(void)
free_domain_list();
/* Add ourselves as the first entry */
+
domain = add_trusted_domain( lp_workgroup(), NULL, &cache_methods, NULL);
+
if (!secrets_fetch_domain_sid(domain->name, &domain->sid)) {
DEBUG(1, ("Could not fetch sid for our domain %s\n",
domain->name));
@@ -245,7 +242,7 @@ BOOL init_domain_list(void)
cache_methods.alternate_name(domain);
/* do an initial scan for trusted domains */
- rescan_trusted_domains(True);
+ add_trusted_domains(domain);
return True;
}