From: Andrew Bartlett Date: Mon, 20 Apr 2009 13:16:59 +0000 (+0200) Subject: s3:ldb Modify Samba3 to use and build with the common LDB X-Git-Url: http://git.samba.org/?p=abartlet%2Fsamba.git%2F.git;a=commitdiff_plain;h=refs%2Fheads%2Fldb-common s3:ldb Modify Samba3 to use and build with the common LDB Andrew Bartlett --- diff --git a/source3/Makefile.in b/source3/Makefile.in index ec7c04b2c6b..6f35cb1e4a6 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -170,6 +170,7 @@ FLAGS = -I. \ -I$(srcdir)/lib \ -I$(srcdir)/lib \ -I.. \ + -I../lib/ldb \ -I../lib/ldb/include \ -I../source4 \ -D_SAMBA_BUILD_=3 diff --git a/source3/groupdb/mapping_ldb.c b/source3/groupdb/mapping_ldb.c index a162c194d6e..b7f8c49b1c6 100644 --- a/source3/groupdb/mapping_ldb.c +++ b/source3/groupdb/mapping_ldb.c @@ -23,7 +23,7 @@ #include "includes.h" #include "groupdb/mapping.h" -#include "lib/ldb/include/includes.h" +#include "lib/ldb/include/ldb.h" #include "lib/ldb/include/ldb_errors.h" static struct ldb_context *ldb; @@ -52,12 +52,9 @@ static bool init_group_mapping(void) return True; } - /* this is needed as Samba3 doesn't have this globally yet */ - ldb_global_init(); - db_path = state_path("group_mapping.ldb"); - ldb = ldb_init(NULL); + ldb = ldb_init(NULL, NULL); if (ldb == NULL) goto failed; /* Ensure this db is created read/write for root only. */ @@ -118,7 +115,8 @@ failed: /* form the DN for a mapping entry from a SID */ -static struct ldb_dn *mapping_dn(TALLOC_CTX *mem_ctx, const DOM_SID *sid) +static struct ldb_dn *mapping_dn(TALLOC_CTX *mem_ctx, + const DOM_SID *sid) { fstring string_sid; uint32_t rid; @@ -133,8 +131,8 @@ static struct ldb_dn *mapping_dn(TALLOC_CTX *mem_ctx, const DOM_SID *sid) } /* we split by domain and rid so we can do a subtree search when we only want one domain */ - return ldb_dn_string_compose(mem_ctx, NULL, "rid=%u,domain=%s", - rid, string_sid); + return ldb_dn_new_fmt(mem_ctx, ldb, "rid=%u,domain=%s", + rid, string_sid); } /* @@ -328,7 +326,7 @@ static bool enum_group_mapping(const DOM_SID *domsid, enum lsa_SidType sid_name_ /* we do a subtree search on the domain */ if (domsid != NULL) { sid_to_fstring(name, domsid); - basedn = ldb_dn_string_compose(tmp_ctx, NULL, "domain=%s", name); + basedn = ldb_dn_new_fmt(tmp_ctx, ldb, "domain=%s", name); if (basedn == NULL) goto failed; } diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index 841ea8caae4..6842e286b6a 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -22,7 +22,7 @@ */ #include "includes.h" -#include "lib/ldb/include/includes.h" +#include "lib/ldb/include/ldb.h" #ifdef HAVE_LDAP @@ -3848,34 +3848,36 @@ ADS_STATUS ads_check_ou_dn(TALLOC_CTX *mem_ctx, struct ldb_dn *name_dn = NULL; const char *name = NULL; char *ou_string = NULL; + struct ldb_context *ldb = ldb_init(mem_ctx, NULL); - name_dn = ldb_dn_explode(mem_ctx, *account_ou); - if (name_dn) { + name_dn = ldb_dn_new(mem_ctx, ldb, *account_ou); + if (name_dn && ldb_dn_validate(name_dn)) { + talloc_free(ldb); return ADS_SUCCESS; } ou_string = ads_ou_string(ads, *account_ou); if (!ou_string) { + talloc_free(ldb); return ADS_ERROR_LDAP(LDAP_INVALID_DN_SYNTAX); } - name = talloc_asprintf(mem_ctx, "%s,%s", ou_string, - ads->config.bind_path); + name_dn = ldb_dn_new_fmt(mem_ctx, ldb, "%s,%s", ou_string, + ads->config.bind_path); SAFE_FREE(ou_string); - if (!name) { - return ADS_ERROR_LDAP(LDAP_NO_MEMORY); - } - name_dn = ldb_dn_explode(mem_ctx, name); - if (!name_dn) { + if (!name_dn || !ldb_dn_validate(name_dn)) { + talloc_free(ldb); return ADS_ERROR_LDAP(LDAP_INVALID_DN_SYNTAX); } *account_ou = talloc_strdup(mem_ctx, name); if (!*account_ou) { + talloc_free(ldb); return ADS_ERROR_LDAP(LDAP_NO_MEMORY); } + talloc_free(ldb); return ADS_SUCCESS; }