idmap_autorid: move the checks from idmap_autorid_initialize to idmap_autorid_savecon...
authorAtul Kulkarni <atul.kulkarni@in.ibm.com>
Wed, 28 Aug 2013 15:19:30 +0000 (17:19 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 1 Oct 2013 08:49:12 +0000 (10:49 +0200)
Pair-Programmed-With: Michael Adam <obnox@samba.org>

Signed-off-by: Atul Kulkarni <atul.kulkarni@in.ibm.com>
Signed-off-by: Michael Adam <obnox@samba.org>
source3/winbindd/idmap_autorid.c
source3/winbindd/idmap_autorid_tdb.c

index 928d8c84c19593085707a2aae0fa8b15209f199d..46463c8d8e3407df51b022e53eaafee2dc5e7cf5 100644 (file)
@@ -595,9 +595,7 @@ static NTSTATUS idmap_autorid_initialize(struct idmap_domain *dom)
 {
        struct idmap_tdb_common_context *commonconfig;
        struct autorid_global_config *config;
-       struct autorid_global_config *storedconfig = NULL;
        NTSTATUS status;
-       uint32_t hwm;
 
        if (!strequal(dom->name, "*")) {
                DEBUG(0, ("idmap_autorid_initialize: Error: autorid configured "
@@ -635,12 +633,6 @@ static NTSTATUS idmap_autorid_initialize(struct idmap_domain *dom)
        config->rangesize = lp_parm_int(-1, "idmap config *",
                                        "rangesize", 100000);
 
-       if (config->rangesize < 2000) {
-               DEBUG(1, ("autorid rangesize must be at least 2000\n"));
-               status = NT_STATUS_INVALID_PARAMETER;
-               goto error;
-       }
-
        config->maxranges = (dom->high_id - dom->low_id + 1) /
            config->rangesize;
 
@@ -660,50 +652,6 @@ static NTSTATUS idmap_autorid_initialize(struct idmap_domain *dom)
                          config->maxranges));
        }
 
-       DEBUG(10, ("Current configuration in config is "
-                  "minvalue:%d rangesize:%d maxranges:%d\n",
-                  config->minvalue, config->rangesize, config->maxranges));
-
-       /* read previously stored config and current HWM */
-       status = idmap_autorid_loadconfig(autorid_db, talloc_tos(),
-                                         &storedconfig);
-       if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
-               DEBUG(5, ("No configuration found. Storing initial "
-                         "configuration.\n"));
-       } else if (!NT_STATUS_IS_OK(status)) {
-               goto error;
-       }
-
-       status = dbwrap_fetch_uint32_bystring(autorid_db, HWM, &hwm);
-       if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(1, ("Fatal error while fetching current "
-                         "HWM value: %s\n", nt_errstr(status)));
-               status = NT_STATUS_INTERNAL_ERROR;
-               goto error;
-       }
-
-       /* did the minimum value or rangesize change? */
-       if (storedconfig &&
-           ((storedconfig->minvalue != config->minvalue) ||
-            (storedconfig->rangesize != config->rangesize))) {
-               DEBUG(1, ("New configuration values for rangesize or "
-                         "minimum uid value conflict with previously "
-                         "used values! Aborting initialization\n"));
-               status = NT_STATUS_INVALID_PARAMETER;
-               goto error;
-       }
-
-       /*
-        * has the highest uid value been reduced to setting that is not
-        * sufficient any more for already existing ranges?
-        */
-       if (hwm > config->maxranges) {
-               DEBUG(1, ("New upper uid limit is too low to cover "
-                         "existing mappings! Aborting initialization\n"));
-               status = NT_STATUS_INVALID_PARAMETER;
-               goto error;
-       }
-
        status = idmap_autorid_saveconfig(autorid_db, config);
 
        if (!NT_STATUS_IS_OK(status)) {
@@ -738,8 +686,6 @@ error:
        talloc_free(config);
 
 done:
-       talloc_free(storedconfig);
-
        return status;
 }
 
index 825e8fcd632038e1f63f8dd01d47e5a1520d478b..4e50ee6526d68be8ce0153f1eca03ad797fbdf3e 100644 (file)
@@ -414,14 +414,73 @@ NTSTATUS idmap_autorid_saveconfig(struct db_context *db,
                                  struct autorid_global_config *cfg)
 {
 
+       struct autorid_global_config *storedconfig = NULL;
        NTSTATUS status = NT_STATUS_INVALID_PARAMETER;
        TDB_DATA data;
        char *cfgstr;
+       uint32_t hwm;
 
        if (db == NULL || cfg == NULL) {
                goto done;
        }
 
+       DEBUG(10, ("New configuration provided for storing is "
+                  "minvalue:%d rangesize:%d maxranges:%d\n",
+                  cfg->minvalue, cfg->rangesize, cfg->maxranges));
+
+       if (cfg->rangesize < 2000) {
+               DEBUG(1, ("autorid rangesize must be at least 2000\n"));
+               goto done;
+       }
+
+       if (cfg->maxranges == 0) {
+               DEBUG(1, ("An autorid maxranges value of 0 is invalid. "
+                         "Must have at least one range available.\n"));
+               goto done;
+       }
+
+       status = idmap_autorid_loadconfig(db, talloc_tos(), &storedconfig);
+       if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
+               DEBUG(5, ("No configuration found. Storing initial "
+                         "configuration.\n"));
+       } else if (!NT_STATUS_IS_OK(status)) {
+               goto done;
+       }
+
+       /* did the minimum value or rangesize change? */
+       if (storedconfig &&
+           ((storedconfig->minvalue != cfg->minvalue) ||
+            (storedconfig->rangesize != cfg->rangesize)))
+       {
+               DEBUG(1, ("New configuration values for rangesize or "
+                         "minimum uid value conflict with previously "
+                         "used values! Not storing new config.\n"));
+               talloc_free(storedconfig);
+               status = NT_STATUS_INVALID_PARAMETER;
+               goto done;
+       }
+
+       talloc_free(storedconfig);
+
+       status = dbwrap_fetch_uint32_bystring(db, HWM, &hwm);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(1, ("Fatal error while fetching current "
+                         "HWM value: %s\n", nt_errstr(status)));
+               status = NT_STATUS_INTERNAL_ERROR;
+               goto done;
+       }
+
+       /*
+        * has the highest uid value been reduced to setting that is not
+        * sufficient any more for already existing ranges?
+        */
+       if (hwm > cfg->maxranges) {
+               DEBUG(1, ("New upper uid limit is too low to cover "
+                         "existing mappings! Not storing new config."));
+               status = NT_STATUS_INVALID_PARAMETER;
+               goto done;
+       }
+
        cfgstr =
            talloc_asprintf(talloc_tos(),
                            "minvalue:%u rangesize:%u maxranges:%u",