>From 9490a26be3b2dfd807ac7d8070eb3d0d1716c93a Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Wed, 16 Sep 2015 15:28:54 +0200 Subject: [PATCH 3/4] LDAP: Move sdap_create_search_base from ldap to sdap code The function shouldn't be placed in the LDAP tree, but in the SDAP tree to make it usable from tests without linking to libraries that are normally linked from LDAP provider (such as confdb) --- src/providers/ldap/ldap_common.h | 7 ----- src/providers/ldap/ldap_options.c | 63 --------------------------------------- src/providers/ldap/sdap.c | 61 +++++++++++++++++++++++++++++++++++++ src/providers/ldap/sdap.h | 7 +++++ 4 files changed, 68 insertions(+), 70 deletions(-) diff --git a/src/providers/ldap/ldap_common.h b/src/providers/ldap/ldap_common.h index 716aaa08ef83b8fca3779b830fdef20bbdb14937..f552520a0503908f82b845f8e813cf67306ec954 100644 --- a/src/providers/ldap/ldap_common.h +++ b/src/providers/ldap/ldap_common.h @@ -294,13 +294,6 @@ struct sdap_domain *sdap_domain_get(struct sdap_options *opts, struct sdap_domain *sdap_domain_get_by_dn(struct sdap_options *opts, const char *dn); -errno_t -sdap_create_search_base(TALLOC_CTX *mem_ctx, - const char *unparsed_base, - int scope, - const char *filter, - struct sdap_search_base **_base); - errno_t sdap_parse_search_base(TALLOC_CTX *mem_ctx, struct dp_option *opts, int class, struct sdap_search_base ***_search_bases); diff --git a/src/providers/ldap/ldap_options.c b/src/providers/ldap/ldap_options.c index eb00aab32a55c6841ebbf32d30f3a48722e8b165..7ad6071508d0abbb33984c697b833cf12f9e4df9 100644 --- a/src/providers/ldap/ldap_options.c +++ b/src/providers/ldap/ldap_options.c @@ -532,69 +532,6 @@ errno_t sdap_parse_search_base(TALLOC_CTX *mem_ctx, _search_bases); } -errno_t -sdap_create_search_base(TALLOC_CTX *mem_ctx, - const char *unparsed_base, - int scope, - const char *filter, - struct sdap_search_base **_base) -{ - struct sdap_search_base *base; - TALLOC_CTX *tmp_ctx; - errno_t ret; - struct ldb_dn *ldn; - struct ldb_context *ldb; - - tmp_ctx = talloc_new(NULL); - if (!tmp_ctx) { - ret = ENOMEM; - goto done; - } - - /* Create a throwaway LDB context for validating the DN */ - ldb = ldb_init(tmp_ctx, NULL); - if (!ldb) { - ret = ENOMEM; - goto done; - } - - base = talloc_zero(tmp_ctx, struct sdap_search_base); - if (base == NULL) { - ret = ENOMEM; - goto done; - } - - base->basedn = talloc_strdup(base, unparsed_base); - if (base->basedn == NULL) { - ret = ENOMEM; - goto done; - } - - /* Validate the basedn */ - ldn = ldb_dn_new(tmp_ctx, ldb, unparsed_base); - if (!ldn) { - ret = ENOMEM; - goto done; - } - - if (!ldb_dn_validate(ldn)) { - DEBUG(SSSDBG_CRIT_FAILURE, - "Invalid base DN [%s]\n", - unparsed_base); - ret = EINVAL; - goto done; - } - - base->scope = scope; - base->filter = filter; - - *_base = talloc_steal(mem_ctx, base); - ret = EOK; -done: - talloc_free(tmp_ctx); - return ret; -} - errno_t common_parse_search_base(TALLOC_CTX *mem_ctx, const char *unparsed_base, const char *class_name, diff --git a/src/providers/ldap/sdap.c b/src/providers/ldap/sdap.c index 97bc14b8730565b6d0d2c41e51f910f042357bc3..5aa7ff7cae8b52eb358c806f7500e1386c2bc948 100644 --- a/src/providers/ldap/sdap.c +++ b/src/providers/ldap/sdap.c @@ -1031,6 +1031,67 @@ static char *get_naming_context(TALLOC_CTX *mem_ctx, return naming_context; } +errno_t +sdap_create_search_base(TALLOC_CTX *mem_ctx, + const char *unparsed_base, + int scope, + const char *filter, + struct sdap_search_base **_base) +{ + struct sdap_search_base *base; + TALLOC_CTX *tmp_ctx; + errno_t ret; + struct ldb_dn *ldn; + struct ldb_context *ldb; + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { + ret = ENOMEM; + goto done; + } + + /* Create a throwaway LDB context for validating the DN */ + ldb = ldb_init(tmp_ctx, NULL); + if (!ldb) { + ret = ENOMEM; + goto done; + } + + base = talloc_zero(tmp_ctx, struct sdap_search_base); + if (base == NULL) { + ret = ENOMEM; + goto done; + } + + base->basedn = talloc_strdup(base, unparsed_base); + if (base->basedn == NULL) { + ret = ENOMEM; + goto done; + } + + /* Validate the basedn */ + ldn = ldb_dn_new(tmp_ctx, ldb, unparsed_base); + if (!ldn) { + ret = ENOMEM; + goto done; + } + + if (!ldb_dn_validate(ldn)) { + DEBUG(SSSDBG_CRIT_FAILURE, "Invalid base DN [%s]\n", unparsed_base); + ret = EINVAL; + goto done; + } + + base->scope = scope; + base->filter = filter; + + *_base = talloc_steal(mem_ctx, base); + ret = EOK; +done: + talloc_free(tmp_ctx); + return ret; +} + static errno_t sdap_set_search_base(struct sdap_options *opts, struct sdap_domain *sdom, enum sdap_basic_opt class, diff --git a/src/providers/ldap/sdap.h b/src/providers/ldap/sdap.h index b3321be48e1b24124d59fbfe88096a2109c920a6..0dc6f751a116f4e32579646e4d9a85470cb9d686 100644 --- a/src/providers/ldap/sdap.h +++ b/src/providers/ldap/sdap.h @@ -373,6 +373,13 @@ struct sdap_search_base { const char *filter; }; +errno_t +sdap_create_search_base(TALLOC_CTX *mem_ctx, + const char *unparsed_base, + int scope, + const char *filter, + struct sdap_search_base **_base); + /* Values from * http://msdn.microsoft.com/en-us/library/cc223272%28v=prot.13%29.aspx */ -- 2.4.3