summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2013-09-12 07:37:17 +0200
committerMichael Adam <obnox@samba.org>2013-10-02 00:50:09 +0200
commit6d8cc470396a03b937f1c532946dfaf916ad454c (patch)
tree69b270af0eec8f204abe689f161cbb69579fdcee
parent350916c11d879d2289f7518625547b88e8dd5705 (diff)
downloadsamba-6d8cc470396a03b937f1c532946dfaf916ad454c.tar.gz
samba-6d8cc470396a03b937f1c532946dfaf916ad454c.tar.bz2
samba-6d8cc470396a03b937f1c532946dfaf916ad454c.zip
idmap_autorid: extend idmap_autorid_addrange to allow to set mappings below the HWM
Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
-rw-r--r--source3/winbindd/idmap_autorid_tdb.c61
1 files changed, 40 insertions, 21 deletions
diff --git a/source3/winbindd/idmap_autorid_tdb.c b/source3/winbindd/idmap_autorid_tdb.c
index 9c77f24448..597d9b6194 100644
--- a/source3/winbindd/idmap_autorid_tdb.c
+++ b/source3/winbindd/idmap_autorid_tdb.c
@@ -147,18 +147,6 @@ static NTSTATUS idmap_autorid_addrange_action(struct db_context *db,
* automatically acquire the next range
*/
requested_rangenum = hwm;
- } else {
- /*
- * set a specified range
- */
-
- if (requested_rangenum < hwm) {
- DEBUG(3, ("Invalid range %u requested: Range may not "
- "be smaller than %u (current HWM)\n",
- requested_rangenum, hwm));
- ret = NT_STATUS_INVALID_PARAMETER;
- goto error;
- }
}
if (requested_rangenum >= globalcfg->maxranges) {
@@ -170,18 +158,49 @@ static NTSTATUS idmap_autorid_addrange_action(struct db_context *db,
goto error;
}
- /* HWM always contains current max range + 1 */
- increment = requested_rangenum + 1 - hwm;
+ if (requested_rangenum < hwm) {
+ /*
+ * Set a specified range below the HWM:
+ * We need to check that it is not yet taken.
+ */
- /* increase the HWM */
- ret = dbwrap_change_uint32_atomic_bystring(db, HWM, &hwm, increment);
- if (!NT_STATUS_IS_OK(ret)) {
- DEBUG(1, ("Fatal error while incrementing the HWM value "
- "in the database: %s\n", nt_errstr(ret)));
- goto error;
+ numstr = talloc_asprintf(mem_ctx, "%u", requested_rangenum);
+ if (!numstr) {
+ ret = NT_STATUS_NO_MEMORY;
+ goto error;
+ }
+
+ if (dbwrap_exists(db, string_term_tdb_data(numstr))) {
+ DEBUG(1, ("Requested range already in use.\n"));
+ ret = NT_STATUS_INVALID_PARAMETER;
+ goto error;
+ }
+
+ TALLOC_FREE(numstr);
+ } else {
+ /*
+ * requested or automatic range >= HWM:
+ * increment the HWM.
+ */
+
+ /* HWM always contains current max range + 1 */
+ increment = requested_rangenum + 1 - hwm;
+
+ /* increase the HWM */
+ ret = dbwrap_change_uint32_atomic_bystring(db, HWM, &hwm,
+ increment);
+ if (!NT_STATUS_IS_OK(ret)) {
+ DEBUG(1, ("Fatal error while incrementing the HWM "
+ "value in the database: %s\n",
+ nt_errstr(ret)));
+ goto error;
+ }
}
- /* store away the new mapping in both directions */
+ /*
+ * store away the new mapping in both directions
+ */
+
ret = dbwrap_store_uint32_bystring(db, keystr, requested_rangenum);
if (!NT_STATUS_IS_OK(ret)) {
DEBUG(1, ("Fatal error while storing new "