- /* 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;
+ }