[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Wed Apr 2 18:42:03 MDT 2014


The branch, master has been updated
       via  5cf6e9c autorid: make the whole initialization atomic with one transaction.
       via  fc987cf autorid: initialize: fix typo in and further improve a debug message.
       via  e9796ed autorid: initialize: use the split db_open and init_hwms function instead of db_init
       via  90d8e0f autorid: initialize: open the autorid db as late as possible.
       via  3aaaef4 autorid: initialize: link config to commonconfig as soon as it is allocated.
       via  20a2e7f autorid: initialize: link commonconfig to dom as soon as it is allocated
       via  963a05b autorid: initialize: store config directly before allocating well knowns.
       via  9e519d9 autorid: split idmap_autorid_db_open and idmap_autorid_init_hwms out of idmap_autorid_db_init
       via  801556f autorid: in idmap_autorid_saveconfig, add a debug msg when loading gives error
       via  d9c2163 autorid: improve the precision of the DEBUG at the end of add_range
       via  fd56a63 autorid: add a DEBUG upon talloc fail in the add_range function.
       via  38157a0 autorid: when storing a new range, always check it does not exist.
       via  0bfb078 autorid: fix a potential for data corruption.
       via  758308c autorid: print debug message when a HWM key has been created
       via  6ec437c autorid: reverse logic flow in idmap_autorid_init_hwm(), decreasing indentation.
       via  70cfe22 autorid: store hwm as uint32_t in idmap_autorid_init_hwm()
       via  c3719a6 dfs_server: get_dcs: fix pointer list termination
      from  32b35b8 script to generate content for libcli/util/nterr.c & libcli/util/ntstatus.h

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 5cf6e9c8520be49aa57436bf725521cdc5d160f8
Author: Michael Adam <obnox at samba.org>
Date:   Fri Mar 21 00:18:36 2014 +0100

    autorid: make the whole initialization atomic with one transaction.
    
    Originally, there were several writing operations:
    
    - store the range HWM
    - store the alloc uid HWM
    - store the alloc gid HWM
    - store the config
    - create mappings for a whole list of wellknown sids
    
    Each of these consisted of its own transaction,
    the wellknown preallocation even of one transaction per sid.
    
    This change wrapps all of these in one big transaction.
    Thereby making the whole initialization atomic, and
    with respect to the creation of the wellknown mappings
    also more deterministic.
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Thu Apr  3 02:41:25 CEST 2014 on sn-devel-104

commit fc987cf289e620358db945b8372aba16cdc0ea8a
Author: Michael Adam <obnox at samba.org>
Date:   Thu Mar 20 09:20:04 2014 +0100

    autorid: initialize: fix typo in and further improve a debug message.
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit e9796edaa8c67c88b30b4e5e937fd7279674403b
Author: Michael Adam <obnox at samba.org>
Date:   Fri Mar 21 00:07:07 2014 +0100

    autorid: initialize: use the split db_open and init_hwms function instead of db_init
    
    This way, we can later put all of the storing functions inside one transaction.
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 90d8e0f8bc6498fea7845a66280cdd0909dc3b81
Author: Michael Adam <obnox at samba.org>
Date:   Fri Mar 21 00:04:15 2014 +0100

    autorid: initialize: open the autorid db as late as possible.
    
    But make sure to link the db context to commonconfig afterwards.
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 3aaaef40d570913c2bd156c91e1ef450d840a26b
Author: Michael Adam <obnox at samba.org>
Date:   Fri Mar 21 00:03:02 2014 +0100

    autorid: initialize: link config to commonconfig as soon as it is allocated.
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 20a2e7f0a942184f04459b0915dec5d21515175f
Author: Michael Adam <obnox at samba.org>
Date:   Fri Mar 21 00:02:31 2014 +0100

    autorid: initialize: link commonconfig to dom as soon as it is allocated
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 963a05b7e8072ddbc310fb9b1e610356b5c8228e
Author: Michael Adam <obnox at samba.org>
Date:   Wed Mar 19 23:50:20 2014 +0100

    autorid: initialize: store config directly before allocating well knowns.
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 9e519d97c36c951c47f41648529b7d5502b898a0
Author: Michael Adam <obnox at samba.org>
Date:   Thu Mar 20 23:41:03 2014 +0100

    autorid: split idmap_autorid_db_open and idmap_autorid_init_hwms out of idmap_autorid_db_init
    
    These will be used separately in the full initialization function.
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 801556fbfdc8ff3ea3845348bf29826e5ccbc71e
Author: Michael Adam <obnox at samba.org>
Date:   Thu Mar 20 12:38:31 2014 +0100

    autorid: in idmap_autorid_saveconfig, add a debug msg when loading gives error
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit d9c216343b787502c91e88ed19b43810db8352f1
Author: Michael Adam <obnox at samba.org>
Date:   Thu Mar 20 15:26:33 2014 +0100

    autorid: improve the precision of the DEBUG at the end of add_range
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit fd56a63a871be01822f47bdb123413f1541fd68b
Author: Michael Adam <obnox at samba.org>
Date:   Thu Mar 20 15:26:06 2014 +0100

    autorid: add a DEBUG upon talloc fail in the add_range function.
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 38157a093bc782ea2f1493229727ff1ecae753dd
Author: Michael Adam <obnox at samba.org>
Date:   Thu Mar 20 15:22:40 2014 +0100

    autorid: when storing a new range, always check it does not exist.
    
    Also check for existence when the range is >= the HWM,
    typically the "acquire" case where we bump the HWM.
    In case of external modification, we would previously
    simply overwrite an an existing range mapping. Now we
    check and throw INTERNAL_DB_CORRUPTION in this case.
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 0bfb0787194184ac154e4d5c9d16cc0b9e84e007
Author: Michael Adam <obnox at samba.org>
Date:   Thu Mar 20 12:07:19 2014 +0100

    autorid: fix a potential for data corruption.
    
    The initialization of the HWM values in autorid.tdb was racy:
    
    It did:
    
    1. fetch the HWM value
    2. if it did not exist, store 0 in a transaction.
    
    This can be racy if two processes at the same time try to
    run the initialization code, especially in a cluster, when
    winbindd and smbd are started simultaneously on all nodes.
    The race is that the HWM is not re-fetched inside the transaction.
    
    Assume both processes see that the HWM does not exist.
    Both try to start a transaction. Process 1 gets the lock
    and process 2 blocks. After Process 1 has stored the
    HWM, it proceeds and manages to start subsequent transactions
    which also bump the HWM value (e.g. a range allocation,
    which is also triggered from allocation code). When
    process 2 finally manages to start the transaction, the
    HWM value is aready > 0. But process 2 does not look again
    and simply overwrites the HWM with 0.
    
    So the next allocation will overwrite an existing mapping,
    at least partially.
    
    This patch changes the mechanism to:
    
    1. fetch the hwm value
    2. if it does not exist start a transaction
    3.   fetch the hwm value
    4.   if it does not exist, store 0
    5. commit the transaction.
    
    Note: this is not theoretical. Corruptions have been
    seen in cluster environments.
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 758308c25a70da3591ce62e377f1ff449a357dd9
Author: Michael Adam <obnox at samba.org>
Date:   Wed Mar 19 23:43:35 2014 +0100

    autorid: print debug message when a HWM key has been created
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 6ec437ccb5f96871589180d976e9ff44a764b11d
Author: Michael Adam <obnox at samba.org>
Date:   Thu Mar 20 11:23:05 2014 +0100

    autorid: reverse logic flow in idmap_autorid_init_hwm(), decreasing indentation.
    
    I.e. move writing case to the end.
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 70cfe221b05a79f890c0e1758c265335f08bb3e6
Author: Michael Adam <obnox at samba.org>
Date:   Thu Mar 20 12:40:31 2014 +0100

    autorid: store hwm as uint32_t in idmap_autorid_init_hwm()
    
    The HWM is treated as uint32_t all the times.
    This was just a leftover from old code.
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit c3719a6feef87dabfaf698cac89513b421fe1952
Author: Arvid Requate <requate at univention.de>
Date:   Mon Mar 31 18:45:07 2014 +0200

    dfs_server: get_dcs: fix pointer list termination
    
    Should fix a potential SEGV e.g. in case searched_site == NULL and no
    objects with objectClass=site are found.
    
    Signed-off-by: Arvid Requate <requate at univention.de>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 dfs_server/dfs_server_ad.c           |   11 ++-
 source3/include/idmap_autorid_tdb.h  |   12 +++
 source3/winbindd/idmap_autorid.c     |   74 ++++++++++++-----
 source3/winbindd/idmap_autorid_tdb.c |  150 ++++++++++++++++++++++++++--------
 4 files changed, 188 insertions(+), 59 deletions(-)


Changeset truncated at 500 lines:

diff --git a/dfs_server/dfs_server_ad.c b/dfs_server/dfs_server_ad.c
index 5e2634f..3d93e19 100644
--- a/dfs_server/dfs_server_ad.c
+++ b/dfs_server/dfs_server_ad.c
@@ -366,7 +366,11 @@ static NTSTATUS get_dcs(TALLOC_CTX *ctx, struct ldb_context *ldb,
 		/* All of this was to get the DN of the searched_site */
 		sitedn = r->msgs[0]->dn;
 
-		set_list = talloc_realloc(subctx, set_list, struct dc_set *, current_pos+1);
+		/*
+		 * We will realloc + 2 because we will need one additional place
+		 * for element at current_pos + 1 for the NULL element
+		 */
+		set_list = talloc_realloc(subctx, set_list, struct dc_set *, current_pos+2);
 		if (set_list == NULL) {
 			TALLOC_FREE(subctx);
 			return NT_STATUS_NO_MEMORY;
@@ -380,6 +384,9 @@ static NTSTATUS get_dcs(TALLOC_CTX *ctx, struct ldb_context *ldb,
 
 		set_list[current_pos]->names = NULL;
 		set_list[current_pos]->count = 0;
+
+		set_list[current_pos+1] = NULL;
+
 		status = get_dcs_insite(subctx, ldb, sitedn,
 					set_list[current_pos], need_fqdn);
 		if (!NT_STATUS_IS_OK(status)) {
@@ -468,8 +475,6 @@ static NTSTATUS get_dcs(TALLOC_CTX *ctx, struct ldb_context *ldb,
 			}
 		}
 	}
-	current_pos++;
-	set_list[current_pos] = NULL;
 
 	*pset_list = talloc_move(ctx, &set_list);
 	talloc_free(subctx);
diff --git a/source3/include/idmap_autorid_tdb.h b/source3/include/idmap_autorid_tdb.h
index acf4026..2d2d01a 100644
--- a/source3/include/idmap_autorid_tdb.h
+++ b/source3/include/idmap_autorid_tdb.h
@@ -109,6 +109,18 @@ NTSTATUS idmap_autorid_delete_range_by_num(struct db_context *db,
 NTSTATUS idmap_autorid_init_hwm(struct db_context *db, const char *hwm);
 
 /**
+ * Open and possibly create the autorid database.
+ */
+NTSTATUS idmap_autorid_db_open(const char *path,
+			       TALLOC_CTX *mem_ctx,
+			       struct db_context **db);
+
+/**
+ * Initialize the high watermark records in the database.
+ */
+NTSTATUS idmap_autorid_init_hwms(struct db_context *db);
+
+/**
  * Initialize an idmap_autorid database.
  * After this function has successfully completed, the following are true:
  * - the database exists
diff --git a/source3/winbindd/idmap_autorid.c b/source3/winbindd/idmap_autorid.c
index 35b4b68..7e17b66 100644
--- a/source3/winbindd/idmap_autorid.c
+++ b/source3/winbindd/idmap_autorid.c
@@ -580,6 +580,39 @@ static NTSTATUS idmap_autorid_preallocate_wellknown(struct idmap_domain *dom)
 	return NT_STATUS_IS_OK(status)?NT_STATUS_OK:NT_STATUS_UNSUCCESSFUL;
 }
 
+static NTSTATUS idmap_autorid_initialize_action(struct db_context *db,
+						void *private_data)
+{
+	struct idmap_domain *dom;
+	struct idmap_tdb_common_context *common;
+	struct autorid_global_config *config;
+	NTSTATUS status;
+
+	dom = (struct idmap_domain *)private_data;
+	common = (struct idmap_tdb_common_context *)dom->private_data;
+	config = (struct autorid_global_config *)common->private_data;
+
+	status = idmap_autorid_init_hwms(autorid_db);
+	if (!NT_STATUS_IS_OK(status)) {
+		return status;
+	}
+
+	status = idmap_autorid_saveconfig(autorid_db, config);
+	if (!NT_STATUS_IS_OK(status)) {
+		DEBUG(1, ("Failed to store configuration data!\n"));
+		return status;
+	}
+
+	status = idmap_autorid_preallocate_wellknown(dom);
+	if (!NT_STATUS_IS_OK(status)) {
+		DEBUG(1, ("Failed to preallocate wellknown sids: %s\n",
+			  nt_errstr(status)));
+		return status;
+	}
+
+	return NT_STATUS_OK;
+}
+
 static NTSTATUS idmap_autorid_initialize(struct idmap_domain *dom)
 {
 	struct idmap_tdb_common_context *commonconfig;
@@ -598,6 +631,7 @@ static NTSTATUS idmap_autorid_initialize(struct idmap_domain *dom)
 		DEBUG(0, ("Out of memory!\n"));
 		return NT_STATUS_NO_MEMORY;
 	}
+	dom->private_data = commonconfig;
 
 	commonconfig->rw_ops = talloc_zero(commonconfig, struct idmap_rw_ops);
 	if (commonconfig->rw_ops == NULL) {
@@ -610,13 +644,7 @@ static NTSTATUS idmap_autorid_initialize(struct idmap_domain *dom)
 		DEBUG(0, ("Out of memory!\n"));
 		return NT_STATUS_NO_MEMORY;
 	}
-
-	status = idmap_autorid_db_init(state_path("autorid.tdb"),
-				       NULL, /* TALLOC_CTX */
-				       &autorid_db);
-	if (!NT_STATUS_IS_OK(status)) {
-		goto error;
-	}
+	commonconfig->private_data = config;
 
 	config->minvalue = dom->low_id;
 	config->rangesize = lp_parm_int(-1, "idmap config *",
@@ -626,8 +654,8 @@ static NTSTATUS idmap_autorid_initialize(struct idmap_domain *dom)
 	    config->rangesize;
 
 	if (config->maxranges == 0) {
-		DEBUG(1, ("allowed uid range is smaller then rangesize, "
-			  "increase uid range or decrease rangesize\n"));
+		DEBUG(1, ("Allowed uid range is smaller than rangesize. "
+			  "Increase uid range or decrease rangesize.\n"));
 		status = NT_STATUS_INVALID_PARAMETER;
 		goto error;
 	}
@@ -641,13 +669,6 @@ static NTSTATUS idmap_autorid_initialize(struct idmap_domain *dom)
 			  config->maxranges));
 	}
 
-	status = idmap_autorid_saveconfig(autorid_db, config);
-
-	if (!NT_STATUS_IS_OK(status)) {
-		DEBUG(1, ("Failed to store configuration data!\n"));
-		goto error;
-	}
-
 	DEBUG(5, ("%d domain ranges with a size of %d are available\n",
 		  config->maxranges, config->rangesize));
 
@@ -655,19 +676,30 @@ static NTSTATUS idmap_autorid_initialize(struct idmap_domain *dom)
 				      "ignore builtin", false);
 
 	/* fill the TDB common configuration */
-	commonconfig->private_data = config;
 
-	commonconfig->db = autorid_db;
 	commonconfig->max_id = config->rangesize -1;
 	commonconfig->hwmkey_uid = ALLOC_HWM_UID;
 	commonconfig->hwmkey_gid = ALLOC_HWM_GID;
 	commonconfig->rw_ops->get_new_id = idmap_autorid_allocate_id;
 	commonconfig->rw_ops->set_mapping = idmap_tdb_common_set_mapping;
 
-	dom->private_data = commonconfig;
+	status = idmap_autorid_db_open(state_path("autorid.tdb"),
+				       NULL, /* TALLOC_CTX */
+				       &autorid_db);
+	if (!NT_STATUS_IS_OK(status)) {
+		goto error;
+	}
 
-	/* preallocate well-known SIDs in the pool */
-	status = idmap_autorid_preallocate_wellknown(dom);
+	commonconfig->db = autorid_db;
+
+	status = dbwrap_trans_do(autorid_db,
+				 idmap_autorid_initialize_action,
+				 dom);
+	if (!NT_STATUS_IS_OK(status)) {
+		DEBUG(1, ("Failed to init the idmap database: %s\n",
+			  nt_errstr(status)));
+		goto error;
+	}
 
 	goto done;
 
diff --git a/source3/winbindd/idmap_autorid_tdb.c b/source3/winbindd/idmap_autorid_tdb.c
index dd99767..21e1508 100644
--- a/source3/winbindd/idmap_autorid_tdb.c
+++ b/source3/winbindd/idmap_autorid_tdb.c
@@ -175,26 +175,34 @@ static NTSTATUS idmap_autorid_addrange_action(struct db_context *db,
 		goto error;
 	}
 
-	if (requested_rangenum < hwm) {
-		/*
-		 * Set a specified range below the HWM:
-		 * We need to check that it is not yet taken.
-		 */
+	/*
+	 * Check that it is not yet taken.
+	 * If the range is requested and < HWM, we need
+	 * to check anyways, and otherwise, we also better
+	 * check in order to prevent further corruption
+	 * in case the db has been externally modified.
+	 */
 
-		numstr = talloc_asprintf(mem_ctx, "%u", requested_rangenum);
-		if (!numstr) {
-			ret = NT_STATUS_NO_MEMORY;
-			goto error;
-		}
+	numstr = talloc_asprintf(mem_ctx, "%u", requested_rangenum);
+	if (!numstr) {
+		DEBUG(1, ("Talloc failed!\n"));
+		ret = NT_STATUS_NO_MEMORY;
+		goto error;
+	}
+
+	if (dbwrap_exists(db, string_term_tdb_data(numstr))) {
+		DEBUG(1, ("Requested range '%s' is already in use.\n", numstr));
 
-		if (dbwrap_exists(db, string_term_tdb_data(numstr))) {
-			DEBUG(1, ("Requested range already in use.\n"));
+		if (requested_rangenum < hwm) {
 			ret = NT_STATUS_INVALID_PARAMETER;
-			goto error;
+		} else {
+			ret = NT_STATUS_INTERNAL_DB_CORRUPTION;
 		}
 
-		TALLOC_FREE(numstr);
-	} else {
+		goto error;
+	}
+
+	if (requested_rangenum >= hwm) {
 		/*
 		 * requested or automatic range >= HWM:
 		 * increment the HWM.
@@ -239,8 +247,11 @@ static NTSTATUS idmap_autorid_addrange_action(struct db_context *db,
 			  "domain->range assignment: %s\n", nt_errstr(ret)));
 		goto error;
 	}
-	DEBUG(5, ("Acquired new range #%d for domain %s "
-		  "(domain_range_index=%"PRIu32")\n", requested_rangenum, keystr,
+
+	DEBUG(5, ("%s new range #%d for domain %s "
+		  "(domain_range_index=%"PRIu32")\n",
+		  (acquire?"Acquired":"Stored"),
+		  requested_rangenum, keystr,
 		  range->domain_range_index));
 
 	range->rangenum = requested_rangenum;
@@ -389,26 +400,64 @@ NTSTATUS idmap_autorid_get_domainrange(struct db_context *db,
 }
 
 /* initialize the given HWM to 0 if it does not exist yet */
+static NTSTATUS idmap_autorid_init_hwm_action(struct db_context *db,
+					      void *private_data)
+{
+	NTSTATUS status;
+	uint32_t hwmval;
+	const char *hwm;
+
+	hwm = (char *)private_data;
+
+	status = dbwrap_fetch_uint32_bystring(db, hwm, &hwmval);
+	if (NT_STATUS_IS_OK(status)) {
+		DEBUG(1, ("HWM (%s) already initialized in autorid database "
+			  "(value %"PRIu32").\n", hwm, hwmval));
+		return NT_STATUS_OK;
+	}
+	if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
+		DEBUG(0, ("Error fetching HWM (%s) from autorid "
+			  "database: %s\n", hwm, nt_errstr(status)));
+		return status;
+	}
+
+	status = dbwrap_trans_store_uint32_bystring(db, hwm, 0);
+	if (!NT_STATUS_IS_OK(status)) {
+		DEBUG(0, ("Error storing HWM (%s) in autorid database: %s\n",
+			  hwm, nt_errstr(status)));
+		return status;
+	}
+
+	return NT_STATUS_OK;
+}
+
 NTSTATUS idmap_autorid_init_hwm(struct db_context *db, const char *hwm)
 {
 	NTSTATUS status;
 	uint32_t hwmval;
 
 	status = dbwrap_fetch_uint32_bystring(db, hwm, &hwmval);
-	if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND))  {
-		status = dbwrap_trans_store_int32_bystring(db, hwm, 0);
-		if (!NT_STATUS_IS_OK(status)) {
-			DEBUG(0,
-			      ("Unable to initialise HWM (%s) in autorid "
-			       "database: %s\n", hwm, nt_errstr(status)));
-			return NT_STATUS_INTERNAL_DB_ERROR;
-		}
-	} else if (!NT_STATUS_IS_OK(status)) {
+	if (NT_STATUS_IS_OK(status)) {
+		DEBUG(1, ("HWM (%s) already initialized in autorid database "
+			  "(value %"PRIu32").\n", hwm, hwmval));
+		return NT_STATUS_OK;
+	}
+	if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
 		DEBUG(0, ("unable to fetch HWM (%s) from autorid "
 			  "database: %s\n", hwm,  nt_errstr(status)));
 		return status;
 	}
 
+	status = dbwrap_trans_do(db, idmap_autorid_init_hwm_action,
+				 (void *)hwm);
+	if (!NT_STATUS_IS_OK(status)) {
+		DEBUG(0, ("Error initializing HWM (%s) in autorid database: "
+			  "%s\n", hwm, nt_errstr(status)));
+		return NT_STATUS_INTERNAL_DB_ERROR;
+	}
+
+	DEBUG(1, ("Initialized HWM (%s) in autorid database.\n", hwm));
+
 	return NT_STATUS_OK;
 }
 
@@ -650,10 +699,10 @@ NTSTATUS idmap_autorid_delete_range_by_num(struct db_context *db,
 	return status;
 }
 
-/*
- * open and initialize the database which stores the ranges for the domains
+/**
+ * Open and possibly create the database.
  */
-NTSTATUS idmap_autorid_db_init(const char *path,
+NTSTATUS idmap_autorid_db_open(const char *path,
 			       TALLOC_CTX *mem_ctx,
 			       struct db_context **db)
 {
@@ -673,19 +722,48 @@ NTSTATUS idmap_autorid_db_init(const char *path,
 		return NT_STATUS_UNSUCCESSFUL;
 	}
 
-	/* Initialize high water mark for the currently used range to 0 */
+	return status;
+}
+
+/**
+ * Initialize the high watermark records in the database.
+ */
+NTSTATUS idmap_autorid_init_hwms(struct db_context *db)
+{
+	NTSTATUS status;
+
+	status = idmap_autorid_init_hwm(db, HWM);
+	if (!NT_STATUS_IS_OK(status)) {
+		return status;
+	}
+
+	status = idmap_autorid_init_hwm(db, ALLOC_HWM_UID);
+	if (!NT_STATUS_IS_OK(status)) {
+		return status;
+	}
 
-	status = idmap_autorid_init_hwm(*db, HWM);
-	NT_STATUS_NOT_OK_RETURN(status);
+	status = idmap_autorid_init_hwm(db, ALLOC_HWM_GID);
 
-	status = idmap_autorid_init_hwm(*db, ALLOC_HWM_UID);
-	NT_STATUS_NOT_OK_RETURN(status);
+	return status;
+}
 
-	status = idmap_autorid_init_hwm(*db, ALLOC_HWM_GID);
+NTSTATUS idmap_autorid_db_init(const char *path,
+			       TALLOC_CTX *mem_ctx,
+			       struct db_context **db)
+{
+	NTSTATUS status;
 
+	status = idmap_autorid_db_open(path, mem_ctx, db);
+	if (!NT_STATUS_IS_OK(status)) {
+		return status;
+	}
+
+	status = idmap_autorid_init_hwms(*db);
 	return status;
 }
 
+
+
 struct idmap_autorid_fetch_config_state {
 	TALLOC_CTX *mem_ctx;
 	char *configstr;
@@ -830,6 +908,8 @@ NTSTATUS idmap_autorid_saveconfig(struct db_context *db,
 		DEBUG(5, ("No configuration found. Storing initial "
 			  "configuration.\n"));
 	} else if (!NT_STATUS_IS_OK(status)) {
+		DEBUG(1, ("Error loading configuration: %s\n",
+			  nt_errstr(status)));
 		goto done;
 	}
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list