diff options
-rw-r--r-- | server/confdb/confdb.c | 42 | ||||
-rw-r--r-- | server/confdb/confdb.h | 4 |
2 files changed, 46 insertions, 0 deletions
diff --git a/server/confdb/confdb.c b/server/confdb/confdb.c index 1dd79982..bab94b3f 100644 --- a/server/confdb/confdb.c +++ b/server/confdb/confdb.c @@ -316,6 +316,48 @@ int confdb_get_string(struct confdb_ctx *cdb, TALLOC_CTX *ctx, return EOK; } +int confdb_get_int(struct confdb_ctx *cdb, TALLOC_CTX *ctx, + const char *section, const char *attribute, + int defval, int *result) +{ + char **values; + long int val; + int ret; + + ret = confdb_get_param(cdb, ctx, section, attribute, &values); + if (ret != EOK) { + return ret; + } + + if (values[0]) { + if (values[1] != NULL) { + /* too many values */ + talloc_free(values); + return EINVAL; + } + + errno = 0; + val = strtol(values[0], NULL, 0); + if (errno) { + talloc_free(values); + return errno; + } + + if (val < INT_MIN || val > INT_MAX) { + talloc_free(values); + return ERANGE; + } + + } else { + val = defval; + } + + talloc_free(values); + + *result = (int)val; + return EOK; +} + static int confdb_test(struct confdb_ctx *cdb) { char **values; diff --git a/server/confdb/confdb.h b/server/confdb/confdb.h index b8b68531..7841d4c1 100644 --- a/server/confdb/confdb.h +++ b/server/confdb/confdb.h @@ -38,6 +38,10 @@ int confdb_get_string(struct confdb_ctx *cdb, TALLOC_CTX *ctx, const char *section, const char *attribute, const char *defstr, char **result); +int confdb_get_int(struct confdb_ctx *cdb, TALLOC_CTX *ctx, + const char *section, const char *attribute, + int defval, int *result); + int confdb_init(TALLOC_CTX *mem_ctx, struct event_context *ev, struct confdb_ctx **cdb_ctx); |