diff options
author | Simo Sorce <simo@redhat.com> | 2013-01-14 17:04:00 -0500 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2013-02-10 22:08:47 +0100 |
commit | 0232747f04b650796db56fd7b487aee8a96fab03 (patch) | |
tree | 0c0329a59cbb66b1e4ea4983cd034dc9015245dc /src/responder/nss | |
parent | 95e94691178297f2b8225a83d43ae388cab04b45 (diff) | |
download | sssd-0232747f04b650796db56fd7b487aee8a96fab03.tar.gz sssd-0232747f04b650796db56fd7b487aee8a96fab03.tar.bz2 sssd-0232747f04b650796db56fd7b487aee8a96fab03.zip |
Add function get_next_domain()
Use this function instead of explicitly calling domain->next
This function allows to get the next primary domain or to descend into the
subdomains and replaces also get_next_dom_or_subdom()
Diffstat (limited to 'src/responder/nss')
-rw-r--r-- | src/responder/nss/nsssrv_cmd.c | 94 | ||||
-rw-r--r-- | src/responder/nss/nsssrv_netgroup.c | 10 | ||||
-rw-r--r-- | src/responder/nss/nsssrv_services.c | 26 |
3 files changed, 55 insertions, 75 deletions
diff --git a/src/responder/nss/nsssrv_cmd.c b/src/responder/nss/nsssrv_cmd.c index 5ac1bacc..76b79ceb 100644 --- a/src/responder/nss/nsssrv_cmd.c +++ b/src/responder/nss/nsssrv_cmd.c @@ -120,7 +120,7 @@ void nss_update_pw_memcache(struct nss_ctx *nctx) now = time(NULL); - for (dom = nctx->rctx->domains; dom != NULL; dom = dom->next) { + for (dom = nctx->rctx->domains; dom; dom = get_next_domain(dom, false)) { ret = sysdb_enumpwent(nctx, dom->sysdb, dom, &res); if (ret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, @@ -714,7 +714,7 @@ static int nss_cmd_getpwnam_search(struct nss_dom_ctx *dctx) /* if it is a domainless search, skip domains that require fully * qualified names instead */ while (dom && cmdctx->check_next && dom->fqnames) { - dom = dom->next; + dom = get_next_domain(dom, false); } if (!dom) break; @@ -743,7 +743,7 @@ static int nss_cmd_getpwnam_search(struct nss_dom_ctx *dctx) name, dom->name)); /* if a multidomain search, try with next */ if (cmdctx->check_next) { - dom = dom->next; + dom = get_next_domain(dom, false); continue; } /* There are no further domains or this was a @@ -780,7 +780,7 @@ static int nss_cmd_getpwnam_search(struct nss_dom_ctx *dctx) /* if a multidomain search, try with next */ if (cmdctx->check_next) { - dom = dom->next; + dom = get_next_domain(dom, false); if (dom) continue; } @@ -843,8 +843,8 @@ static void nss_cmd_getpwnam_dp_callback(uint16_t err_maj, uint32_t err_min, } /* no previous results, just loop to next domain if possible */ - if (dctx->domain->next && cmdctx->check_next) { - dctx->domain = dctx->domain->next; + if (cmdctx->check_next && get_next_domain(dctx->domain, false)) { + dctx->domain = get_next_domain(dctx->domain, false); dctx->check_provider = NEED_CHECK_PROVIDER(dctx->domain->provider); } else { /* nothing available */ @@ -1031,28 +1031,6 @@ static void nss_cmd_getpwuid_dp_callback(uint16_t err_maj, uint32_t err_min, * anything else on a fatal error */ -struct sss_domain_info *get_next_dom_or_subdom(struct sss_domain_info *dom) -{ - /* Note that we don't know if the dom is a domain or a subdomain, - * therefore: - * - * If it is a subdomain and it doesn't have any siblings (subdomains - * of the same primary domain), return next primary domain - */ - if (dom->next == NULL && dom->parent != NULL) { - return dom->parent->next; - } - - /* If it's primary domain, the next returned should be its first - * subdomain */ - if (dom->subdomains != NULL) { - return dom->subdomains[0]; - } - - /* Any other scenario */ - return dom->next; -} - static int nss_cmd_getpwuid_search(struct nss_dom_ctx *dctx) { struct nss_cmd_ctx *cmdctx = dctx->cmdctx; @@ -1073,7 +1051,7 @@ static int nss_cmd_getpwuid_search(struct nss_dom_ctx *dctx) "(id out of range)\n", (unsigned long)cmdctx->id, dom->name)); if (cmdctx->check_next) { - dom = get_next_dom_or_subdom(dom); + dom = get_next_domain(dom, true); continue; } return ENOENT; @@ -1110,7 +1088,7 @@ static int nss_cmd_getpwuid_search(struct nss_dom_ctx *dctx) if (dctx->res->count == 0 && !dctx->check_provider) { /* if a multidomain search, try with next */ if (cmdctx->check_next) { - dom = get_next_dom_or_subdom(dom); + dom = get_next_domain(dom, true); continue; } @@ -1170,8 +1148,8 @@ static void nss_cmd_getpwuid_dp_callback(uint16_t err_maj, uint32_t err_min, } /* no previous results, just loop to next domain if possible */ - if (dctx->domain->next && cmdctx->check_next) { - dctx->domain = dctx->domain->next; + if (cmdctx->check_next && get_next_domain(dctx->domain, false)) { + dctx->domain = get_next_domain(dctx->domain, false); dctx->check_provider = NEED_CHECK_PROVIDER(dctx->domain->provider); } else { /* nothing available */ @@ -1367,7 +1345,7 @@ struct tevent_req *nss_cmd_setpwent_send(TALLOC_CTX *mem_ctx, } /* check if enumeration is enabled in any domain */ - for (dom = client->rctx->domains; dom; dom = dom->next) { + for (dom = client->rctx->domains; dom; dom = get_next_domain(dom, false)) { if (dom->enumerate != 0) break; } state->dctx->domain = dom; @@ -1480,7 +1458,7 @@ static errno_t nss_cmd_setpwent_step(struct setent_step_ctx *step_ctx) while (dom) { while (dom && dom->enumerate == 0) { - dom = dom->next; + dom = get_next_domain(dom, false); } if (!dom) break; @@ -1538,13 +1516,13 @@ static errno_t nss_cmd_setpwent_step(struct setent_step_ctx *step_ctx) if (ret != EOK) { DEBUG(1, ("Enum from cache failed, skipping domain [%s]\n", dom->name)); - dom = dom->next; + dom = get_next_domain(dom, false); continue; } if (res->count == 0) { DEBUG(4, ("Domain [%s] has no users, skipping.\n", dom->name)); - dom = dom->next; + dom = get_next_domain(dom, false); continue; } @@ -1562,7 +1540,7 @@ static errno_t nss_cmd_setpwent_step(struct setent_step_ctx *step_ctx) nctx->pctx->num++; /* do not reply until all domain searches are done */ - dom = dom->next; + dom = get_next_domain(dom, false); } /* We've finished all our lookups @@ -1859,7 +1837,7 @@ void nss_update_gr_memcache(struct nss_ctx *nctx) now = time(NULL); - for (dom = nctx->rctx->domains; dom != NULL; dom = dom->next) { + for (dom = nctx->rctx->domains; dom; dom = get_next_domain(dom, false)) { ret = sysdb_enumgrent(nctx, dom->sysdb, dom, &res); if (ret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, @@ -2311,7 +2289,7 @@ static int nss_cmd_getgrnam_search(struct nss_dom_ctx *dctx) /* if it is a domainless search, skip domains that require fully * qualified names instead */ while (dom && cmdctx->check_next && dom->fqnames) { - dom = dom->next; + dom = get_next_domain(dom, false); } if (!dom) break; @@ -2340,7 +2318,7 @@ static int nss_cmd_getgrnam_search(struct nss_dom_ctx *dctx) name, dom->name)); /* if a multidomain search, try with next */ if (cmdctx->check_next) { - dom = dom->next; + dom = get_next_domain(dom, false); continue; } /* There are no further domains or this was a @@ -2377,7 +2355,7 @@ static int nss_cmd_getgrnam_search(struct nss_dom_ctx *dctx) /* if a multidomain search, try with next */ if (cmdctx->check_next) { - dom = dom->next; + dom = get_next_domain(dom, false); if (dom) continue; } @@ -2441,8 +2419,8 @@ static void nss_cmd_getgrnam_dp_callback(uint16_t err_maj, uint32_t err_min, } /* no previous results, just loop to next domain if possible */ - if (dctx->domain->next && cmdctx->check_next) { - dctx->domain = dctx->domain->next; + if (cmdctx->check_next && get_next_domain(dctx->domain, false)) { + dctx->domain = get_next_domain(dctx->domain, false); dctx->check_provider = NEED_CHECK_PROVIDER(dctx->domain->provider); } else { /* nothing available */ @@ -2648,7 +2626,7 @@ static int nss_cmd_getgrgid_search(struct nss_dom_ctx *dctx) "(id out of range)\n", (unsigned long)cmdctx->id, dom->name)); if (cmdctx->check_next) { - dom = get_next_dom_or_subdom(dom); + dom = get_next_domain(dom, true); continue; } return ENOENT; @@ -2685,7 +2663,7 @@ static int nss_cmd_getgrgid_search(struct nss_dom_ctx *dctx) if (dctx->res->count == 0 && !dctx->check_provider) { /* if a multidomain search, try with next */ if (cmdctx->check_next) { - dom = get_next_dom_or_subdom(dom); + dom = get_next_domain(dom, true); continue; } @@ -2745,8 +2723,8 @@ static void nss_cmd_getgrgid_dp_callback(uint16_t err_maj, uint32_t err_min, } /* no previous results, just loop to next domain if possible */ - if (dctx->domain->next && cmdctx->check_next) { - dctx->domain = dctx->domain->next; + if (cmdctx->check_next && get_next_domain(dctx->domain, false)) { + dctx->domain = get_next_domain(dctx->domain, false); dctx->check_provider = NEED_CHECK_PROVIDER(dctx->domain->provider); } else { /* nothing available */ @@ -2935,7 +2913,7 @@ struct tevent_req *nss_cmd_setgrent_send(TALLOC_CTX *mem_ctx, } /* check if enumeration is enabled in any domain */ - for (dom = client->rctx->domains; dom; dom = dom->next) { + for (dom = client->rctx->domains; dom; dom = get_next_domain(dom, false)) { if (dom->enumerate != 0) break; } state->dctx->domain = dom; @@ -3048,7 +3026,7 @@ static errno_t nss_cmd_setgrent_step(struct setent_step_ctx *step_ctx) while (dom) { while (dom && dom->enumerate == 0) { - dom = dom->next; + dom = get_next_domain(dom, false); } if (!dom) break; @@ -3106,13 +3084,13 @@ static errno_t nss_cmd_setgrent_step(struct setent_step_ctx *step_ctx) if (ret != EOK) { DEBUG(1, ("Enum from cache failed, skipping domain [%s]\n", dom->name)); - dom = dom->next; + dom = get_next_domain(dom, false); continue; } if (res->count == 0) { DEBUG(4, ("Domain [%s] has no groups, skipping.\n", dom->name)); - dom = dom->next; + dom = get_next_domain(dom, false); continue; } @@ -3130,7 +3108,7 @@ static errno_t nss_cmd_setgrent_step(struct setent_step_ctx *step_ctx) nctx->gctx->num++; /* do not reply until all domain searches are done */ - dom = dom->next; + dom = get_next_domain(dom, false); } /* We've finished all our lookups @@ -3418,7 +3396,7 @@ void nss_update_initgr_memcache(struct nss_ctx *nctx, int ret; int i, j; - for (dom = nctx->rctx->domains; dom != NULL; dom = dom->next) { + for (dom = nctx->rctx->domains; dom; dom = get_next_domain(dom, false)) { if (strcasecmp(dom->name, domain) == 0) { break; } @@ -3596,7 +3574,7 @@ static int nss_cmd_initgroups_search(struct nss_dom_ctx *dctx) /* if it is a domainless search, skip domains that require fully * qualified names instead */ while (dom && cmdctx->check_next && dom->fqnames) { - dom = dom->next; + dom = get_next_domain(dom, false); } if (!dom) break; @@ -3625,7 +3603,7 @@ static int nss_cmd_initgroups_search(struct nss_dom_ctx *dctx) name, dom->name)); /* if a multidomain search, try with next */ if (cmdctx->check_next) { - dom = dom->next; + dom = get_next_domain(dom, false); continue; } /* There are no further domains or this was a @@ -3658,7 +3636,7 @@ static int nss_cmd_initgroups_search(struct nss_dom_ctx *dctx) /* if a multidomain search, try with next */ if (cmdctx->check_next) { - dom = dom->next; + dom = get_next_domain(dom, false); if (dom) continue; } @@ -3711,8 +3689,8 @@ static void nss_cmd_initgroups_dp_callback(uint16_t err_maj, uint32_t err_min, } /* no previous results, just loop to next domain if possible */ - if (dctx->domain->next && cmdctx->check_next) { - dctx->domain = dctx->domain->next; + if (cmdctx->check_next && get_next_domain(dctx->domain, false)) { + dctx->domain = get_next_domain(dctx->domain, false); dctx->check_provider = NEED_CHECK_PROVIDER(dctx->domain->provider); } else { /* nothing available */ diff --git a/src/responder/nss/nsssrv_netgroup.c b/src/responder/nss/nsssrv_netgroup.c index e6debffa..30459bea 100644 --- a/src/responder/nss/nsssrv_netgroup.c +++ b/src/responder/nss/nsssrv_netgroup.c @@ -424,7 +424,7 @@ static errno_t lookup_netgr_step(struct setent_step_ctx *step_ctx) /* if it is a domainless search, skip domains that require fully * qualified names instead */ while (dom && step_ctx->check_next && dom->fqnames) { - dom = dom->next; + dom = get_next_domain(dom, false); } /* No domains left to search */ @@ -463,7 +463,7 @@ static errno_t lookup_netgr_step(struct setent_step_ctx *step_ctx) /* This netgroup was not found in this domain */ if (!step_ctx->dctx->check_provider) { if (step_ctx->check_next) { - dom = dom->next; + dom = get_next_domain(dom, false); continue; } else break; @@ -494,7 +494,7 @@ static errno_t lookup_netgr_step(struct setent_step_ctx *step_ctx) if (!step_ctx->dctx->check_provider) { if (step_ctx->check_next) { - dom = dom->next; + dom = get_next_domain(dom, false); continue; } else break; @@ -588,8 +588,8 @@ static void lookup_netgr_dp_callback(uint16_t err_maj, uint32_t err_min, "Will try to return what we have in cache\n", (unsigned int)err_maj, (unsigned int)err_min, err_msg)); /* Loop to the next domain if possible */ - if (dctx->domain->next && cmdctx->check_next) { - dctx->domain = dctx->domain->next; + if (cmdctx->check_next && get_next_domain(dctx->domain, false)) { + dctx->domain = get_next_domain(dctx->domain, false); dctx->check_provider = NEED_CHECK_PROVIDER(dctx->domain->provider); } } diff --git a/src/responder/nss/nsssrv_services.c b/src/responder/nss/nsssrv_services.c index dd12fa41..7b76cad8 100644 --- a/src/responder/nss/nsssrv_services.c +++ b/src/responder/nss/nsssrv_services.c @@ -99,7 +99,9 @@ getserv_send(TALLOC_CTX *mem_ctx, if (!req) return NULL; state->dctx = dctx; - for (dom = cctx->rctx->domains; dom; dom = dom->next) num_domains++; + for (dom = cctx->rctx->domains; dom; dom = get_next_domain(dom, false)) { + num_domains++; + } /* Create an array of domains to check. To save resizes, we'll * assume that all will be checked @@ -160,7 +162,7 @@ getserv_send(TALLOC_CTX *mem_ctx, /* if it is a domainless search, skip domains that require fully * qualified names instead */ while (dom && cmdctx->check_next && dom->fqnames) { - dom = dom->next; + dom = get_next_domain(dom, false); } if (!dom) break; @@ -191,7 +193,7 @@ getserv_send(TALLOC_CTX *mem_ctx, /* If this is a multi-domain search, try the next one */ if (cmdctx->check_next) { - dom = dom->next; + dom = get_next_domain(dom, false); } else { /* This was a single-domain search. * exit the loop. Since it was negatively- @@ -232,7 +234,7 @@ getserv_send(TALLOC_CTX *mem_ctx, /* If this is a multi-domain search, try the next one */ if (cmdctx->check_next) { - dom = dom->next; + dom = get_next_domain(dom, false); } else { /* This was a single-domain search. * exit the loop. Since it was negatively- @@ -298,7 +300,7 @@ getserv_send(TALLOC_CTX *mem_ctx, /* If this is a multi-domain search, try the next one */ if (cmdctx->check_next) { - dom = dom->next; + dom = get_next_domain(dom, false); } else { /* This was a single-domain search. * exit the loop. @@ -380,7 +382,7 @@ getserv_send(TALLOC_CTX *mem_ctx, /* If this is a multi-domain search, try the next one */ if (cmdctx->check_next) { - dom = dom->next; + dom = get_next_domain(dom, false); } else { /* This was a single-domain search. * exit the loop. @@ -1257,10 +1259,10 @@ setservent_send(TALLOC_CTX *mem_ctx, struct cli_ctx *cctx) * to reallocate later */ num_domains = 0; - dom = state->cctx->rctx->domains; - while (dom) { + for (dom = state->cctx->rctx->domains; + dom; + dom = get_next_domain(dom, false)) { num_domains++; - dom = dom->next; } state->nctx->svcctx->doms = talloc_zero_array(state->nctx->svcctx, @@ -1306,7 +1308,7 @@ setservent_send(TALLOC_CTX *mem_ctx, struct cli_ctx *cctx) ("Error [%s] requesting info from domain [%s]. Skipping.\n", strerror(ret), step_ctx->dctx->domain->name)); - step_ctx->dctx->domain = step_ctx->dctx->domain->next; + step_ctx->dctx->domain = get_next_domain(step_ctx->dctx->domain, false); } /* All domains failed */ @@ -1501,7 +1503,7 @@ setservent_step_done(struct tevent_req *req) svcctx->num++; } - step_ctx->dctx->domain = step_ctx->dctx->domain->next; + step_ctx->dctx->domain = get_next_domain(step_ctx->dctx->domain, false); while (step_ctx->dctx->domain) { /* There are more domains to check */ @@ -1515,7 +1517,7 @@ setservent_step_done(struct tevent_req *req) ("Error [%s] requesting info from domain [%s]. Skipping.\n", strerror(ret), step_ctx->dctx->domain->name)); - step_ctx->dctx->domain = step_ctx->dctx->domain->next; + step_ctx->dctx->domain = get_next_domain(step_ctx->dctx->domain, false); } /* All domains have been checked */ |