s3:ldb Modify Samba3 to use and build with the common LDB ldb-common
authorAndrew Bartlett <abartlet@samba.org>
Mon, 20 Apr 2009 13:16:59 +0000 (15:16 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 20 Apr 2009 13:16:59 +0000 (15:16 +0200)
Andrew Bartlett

source3/Makefile.in
source3/groupdb/mapping_ldb.c
source3/libads/ldap.c

index ec7c04b2c6b37460b1c5ac70873dd08fdd3dee11..6f35cb1e4a6e96e22863f1b1c124678fa52df967 100644 (file)
@@ -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
index a162c194d6e353264d1cd53effed393f7442c941..b7f8c49b1c617864e5c3119c9dab4b0c948d4e79 100644 (file)
@@ -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;
        }
 
index 841ea8caae46c741284dfa89a81f043f503c393a..6842e286b6a7ab51f074014a3602d839a4cd320b 100644 (file)
@@ -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;
 }