idmap_autorid: refactor idmap_autorid_parse_configstr() out of idmap_autorid_loadconfig()
authorMichael Adam <obnox@samba.org>
Wed, 28 Aug 2013 13:29:37 +0000 (15:29 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 1 Oct 2013 08:49:11 +0000 (10:49 +0200)
This will be used for other purposes as well.

Pair-Programmed-with: Atul Kulkarni <atul.kulkarni@in.ibm.com>

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

index 21e4ddbdc3748510ab046a01e1795c5b6b5e70ca..2702f4cf0967682f4bd1c9f5b18be691ebe36264 100644 (file)
@@ -75,4 +75,11 @@ NTSTATUS idmap_autorid_saveconfig(struct db_context *db,
 NTSTATUS idmap_autorid_getconfigstr(struct db_context *db, TALLOC_CTX *mem_ctx,
                                    char **result);
 
+/**
+ * parse the handed in config string and fill the provided config structure.
+ * return false if the string could not be parsed.
+ */
+bool idmap_autorid_parse_configstr(const char *configstr,
+                                  struct autorid_global_config *cfg);
+
 #endif /* _IDMAP_AUTORID_H_ */
index d78bcd1ea3d4ece27e7b73bccc91cb9a6073d2f1..e57934900612e676d925a91bc9814422184ce562 100644 (file)
@@ -272,12 +272,33 @@ NTSTATUS idmap_autorid_getconfigstr(struct db_context *db, TALLOC_CTX *mem_ctx,
        return status;
 }
 
+bool idmap_autorid_parse_configstr(const char *configstr,
+                                  struct autorid_global_config *cfg)
+{
+       unsigned long minvalue, rangesize, maxranges;
+
+       if (sscanf(configstr,
+                  "minvalue:%lu rangesize:%lu maxranges:%lu",
+                  &minvalue, &rangesize, &maxranges) != 3) {
+               DEBUG(1,
+                     ("Found invalid configuration data"
+                      "creating new config\n"));
+               return false;
+       }
+
+       cfg->minvalue = minvalue;
+       cfg->rangesize = rangesize;
+       cfg->maxranges = maxranges;
+
+       return true;
+}
+
 struct autorid_global_config *idmap_autorid_loadconfig(struct db_context *db,
                                                       TALLOC_CTX *mem_ctx)
 {
        struct autorid_global_config *cfg;
-       unsigned long minvalue, rangesize, maxranges;
        NTSTATUS status;
+       bool ok;
        char *configstr = NULL;
 
        status = idmap_autorid_getconfigstr(db, mem_ctx, &configstr);
@@ -290,19 +311,12 @@ struct autorid_global_config *idmap_autorid_loadconfig(struct db_context *db,
                return NULL;
        }
 
-       if (sscanf(configstr,
-                  "minvalue:%lu rangesize:%lu maxranges:%lu",
-                  &minvalue, &rangesize, &maxranges) != 3) {
-               DEBUG(1,
-                     ("Found invalid configuration data"
-                      "creating new config\n"));
+       ok = idmap_autorid_parse_configstr(configstr, cfg);
+       if (!ok) {
+               talloc_free(cfg);
                return NULL;
        }
 
-       cfg->minvalue = minvalue;
-       cfg->rangesize = rangesize;
-       cfg->maxranges = maxranges;
-
        DEBUG(10, ("Loaded previously stored configuration "
                   "minvalue:%d rangesize:%d\n",
                   cfg->minvalue, cfg->rangesize));