From: Volker Lendecke Date: Mon, 22 Feb 2016 16:03:43 +0000 (+0100) Subject: idmap: Factor out lp_scan_idmap_domains() X-Git-Tag: tdb-1.3.9~78 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=16dc16e904d75143fa8d89faa4c6fdbeab234763;p=thirdparty%2Fsamba.git idmap: Factor out lp_scan_idmap_domains() This simplifies idmap_found_domain_backend() by moving the regex magic somewhere else. Also, this routine will be useful soon somewhere else, thus make it non-static to idmap.c. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/winbindd/idmap.c b/source3/winbindd/idmap.c index 7eb7e589029..7b4ed4f05d1 100644 --- a/source3/winbindd/idmap.c +++ b/source3/winbindd/idmap.c @@ -70,13 +70,71 @@ static struct idmap_domain *idmap_init_domain(TALLOC_CTX *mem_ctx, const char *domainname, const char *modulename, bool check_range); -static bool idmap_found_domain_backend( + +struct lp_scan_idmap_domains_state { + bool (*fn)(const char *domname, void *private_data); + void *private_data; +}; + +static bool lp_scan_idmap_found_domain( const char *string, regmatch_t matches[], void *private_data); +bool lp_scan_idmap_domains(bool (*fn)(const char *domname, + void *private_data), + void *private_data) +{ + struct lp_scan_idmap_domains_state state = { + .fn = fn, .private_data = private_data }; + int ret; + + ret = lp_wi_scan_global_parametrics( + "idmapconfig\\(.*\\):backend", 2, + lp_scan_idmap_found_domain, &state); + if (ret != 0) { + DBG_WARNING("wi_scan_global_parametrics returned %d\n", ret); + return false; + } + + return true; +} + +static bool lp_scan_idmap_found_domain( + const char *string, regmatch_t matches[], void *private_data) +{ + bool ok; + + if (matches[1].rm_so == -1) { + DBG_WARNING("Found match, but no name??\n"); + return false; + } + if (matches[1].rm_eo <= matches[1].rm_so) { + DBG_WARNING("Invalid match\n"); + return false; + } + + { + struct lp_scan_idmap_domains_state *state = private_data; + regoff_t len = matches[1].rm_eo - matches[1].rm_so; + char domname[len+1]; + + memcpy(domname, string + matches[1].rm_so, len); + domname[len] = '\0'; + + DBG_DEBUG("Found idmap domain \"%s\"\n", domname); + + ok = state->fn(domname, state->private_data); + } + + return ok; +} + +static bool idmap_found_domain_backend(const char *domname, + void *private_data); + static bool idmap_init(void) { static bool initialized; - int ret; + bool ok; if (initialized) { return true; @@ -109,11 +167,9 @@ static bool idmap_init(void) return false; } - ret = lp_wi_scan_global_parametrics( - "idmapconfig\\(.*\\):backend", 2, - idmap_found_domain_backend, NULL); - if (ret != 0) { - DBG_WARNING("wi_scan_global_parametrics returned %d\n", ret); + ok = lp_scan_idmap_domains(idmap_found_domain_backend, NULL); + if (!ok) { + DBG_WARNING("lp_scan_idmap_domains failed\n"); return false; } @@ -161,46 +217,33 @@ bool domain_has_idmap_config(const char *domname) return false; } -static bool idmap_found_domain_backend( - const char *string, regmatch_t matches[], void *private_data) +static bool idmap_found_domain_backend(const char *domname, + void *private_data) { - if (matches[1].rm_so == -1) { - DBG_WARNING("Found match, but no name??\n"); - return false; - } - - { - struct idmap_domain *dom, **tmp; - regoff_t len = matches[1].rm_eo - matches[1].rm_so; - char domname[len+1]; + struct idmap_domain *dom, **tmp; - memcpy(domname, string + matches[1].rm_so, len); - domname[len] = '\0'; + DBG_DEBUG("Found idmap domain \"%s\"\n", domname); - DBG_DEBUG("Found idmap domain \"%s\"\n", domname); - - if (strcmp(domname, "*") == 0) { - return false; - } + if (strcmp(domname, "*") == 0) { + return false; + } - dom = idmap_init_named_domain(idmap_domains, domname); - if (dom == NULL) { - DBG_NOTICE("Could not init idmap domain %s\n", - domname); - return false; - } + dom = idmap_init_named_domain(idmap_domains, domname); + if (dom == NULL) { + DBG_NOTICE("Could not init idmap domain %s\n", domname); + return false; + } - tmp = talloc_realloc(idmap_domains, idmap_domains, - struct idmap_domain *, num_domains + 1); - if (tmp == NULL) { - DBG_WARNING("talloc_realloc failed\n"); - TALLOC_FREE(dom); - return false; - } - idmap_domains = tmp; - idmap_domains[num_domains] = dom; - num_domains += 1; + tmp = talloc_realloc(idmap_domains, idmap_domains, + struct idmap_domain *, num_domains + 1); + if (tmp == NULL) { + DBG_WARNING("talloc_realloc failed\n"); + TALLOC_FREE(dom); + return false; } + idmap_domains = tmp; + idmap_domains[num_domains] = dom; + num_domains += 1; return false; } diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h index 12629ffd05a..7c9a9243bea 100644 --- a/source3/winbindd/winbindd_proto.h +++ b/source3/winbindd/winbindd_proto.h @@ -331,6 +331,9 @@ struct winbindd_child *idmap_child(void); struct idmap_domain *idmap_find_domain_with_sid(const char *domname, const struct dom_sid *sid); bool domain_has_idmap_config(const char *domname); +bool lp_scan_idmap_domains(bool (*fn)(const char *domname, + void *private_data), + void *private_data); /* The following definitions come from winbindd/winbindd_locator.c */