diff options
-rw-r--r-- | source3/include/idmap_autorid_tdb.h | 7 | ||||
-rw-r--r-- | source3/winbindd/idmap_autorid_tdb.c | 36 |
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)); |