summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2013-08-28 15:29:37 +0200
committerVolker Lendecke <vl@samba.org>2013-10-01 12:03:29 +0000
commitf6c34b1e236aab275d6cfbc12e57af7d692b8c19 (patch)
treec007015127358b2a3f6d37514ba72560e5f12fee /source3
parent42a6bb722884de1ba2d876fcb62343aad7594bb7 (diff)
downloadsamba-f6c34b1e236aab275d6cfbc12e57af7d692b8c19.tar.gz
samba-f6c34b1e236aab275d6cfbc12e57af7d692b8c19.tar.bz2
samba-f6c34b1e236aab275d6cfbc12e57af7d692b8c19.zip
idmap_autorid: refactor idmap_autorid_parse_configstr() out of idmap_autorid_loadconfig()
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> Reviewed-by: Volker Lendecke <vl@samba.org>
Diffstat (limited to 'source3')
-rw-r--r--source3/include/idmap_autorid_tdb.h7
-rw-r--r--source3/winbindd/idmap_autorid_tdb.c36
2 files changed, 32 insertions, 11 deletions
diff --git a/source3/include/idmap_autorid_tdb.h b/source3/include/idmap_autorid_tdb.h
index 21e4ddbdc3..2702f4cf09 100644
--- a/source3/include/idmap_autorid_tdb.h
+++ b/source3/include/idmap_autorid_tdb.h
@@ -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_ */
diff --git a/source3/winbindd/idmap_autorid_tdb.c b/source3/winbindd/idmap_autorid_tdb.c
index 64c108520c..29d3a4dc01 100644
--- a/source3/winbindd/idmap_autorid_tdb.c
+++ b/source3/winbindd/idmap_autorid_tdb.c
@@ -261,12 +261,33 @@ NTSTATUS idmap_autorid_getconfigstr(struct db_context *db, TALLOC_CTX *mem_ctx,
return NT_STATUS_OK;
}
+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);
@@ -279,19 +300,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));