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/util | |
parent | 95e94691178297f2b8225a83d43ae388cab04b45 (diff) | |
download | sssd-0232747f04b650796db56fd7b487aee8a96fab03.tar.gz sssd-0232747f04b650796db56fd7b487aee8a96fab03.tar.xz 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/util')
-rw-r--r-- | src/util/domain_info_utils.c | 18 | ||||
-rw-r--r-- | src/util/usertools.c | 4 | ||||
-rw-r--r-- | src/util/util.h | 2 |
3 files changed, 22 insertions, 2 deletions
diff --git a/src/util/domain_info_utils.c b/src/util/domain_info_utils.c index 1ff7c0c6d..8cba7dca7 100644 --- a/src/util/domain_info_utils.c +++ b/src/util/domain_info_utils.c @@ -22,6 +22,24 @@ #include "db/sysdb.h" #include "util/util.h" +struct sss_domain_info *get_next_domain(struct sss_domain_info *domain, + bool descend) +{ + struct sss_domain_info *dom; + + dom = domain; + if (descend && dom->subdomain_count > 0) { + dom = dom->subdomains[0]; + } else if (dom->next) { + dom = dom->next; + } else if (descend && dom->parent) { + dom = dom->parent->next; + } else { + dom = NULL; + } + return dom; +} + struct sss_domain_info *new_subdomain(TALLOC_CTX *mem_ctx, struct sss_domain_info *parent, const char *name, diff --git a/src/util/usertools.c b/src/util/usertools.c index 0a657a182..33a2a7bd5 100644 --- a/src/util/usertools.c +++ b/src/util/usertools.c @@ -339,7 +339,7 @@ int sss_parse_name_for_domains(TALLOC_CTX *memctx, rname = NULL; rdomain = NULL; - for (dom = domains; dom != NULL; dom = dom->next) { + for (dom = domains; dom != NULL; dom = get_next_domain(dom, false)) { ret = sss_parse_name(tmp_ctx, dom->names, orig, &dmatch, &nmatch); if (ret == EOK) { /* @@ -397,7 +397,7 @@ int sss_parse_name_for_domains(TALLOC_CTX *memctx, goto done; } - for (dom = domains; dom != NULL; dom = dom->next) { + for (dom = domains; dom != NULL; dom = get_next_domain(dom, false)) { match = match_any_domain_or_subdomain_name(dom, rdomain); if (match != NULL) { break; diff --git a/src/util/util.h b/src/util/util.h index a2b2a2d3e..de212811f 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -566,6 +566,8 @@ struct sized_string { void to_sized_string(struct sized_string *out, const char *in); /* form domain_info.c */ +struct sss_domain_info *get_next_domain(struct sss_domain_info *domain, + bool descend); struct sss_domain_info *new_subdomain(TALLOC_CTX *mem_ctx, struct sss_domain_info *parent, const char *name, |