1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-22 22:04:08 +03:00

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>
This commit is contained in:
Michael Adam 2013-08-28 15:29:37 +02:00 committed by Volker Lendecke
parent 42a6bb7228
commit f6c34b1e23
2 changed files with 32 additions and 11 deletions

View 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_ */

View File

@ -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));