summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/confdb/confdb.c42
-rw-r--r--server/confdb/confdb.h4
2 files changed, 46 insertions, 0 deletions
diff --git a/server/confdb/confdb.c b/server/confdb/confdb.c
index 1dd799827..bab94b3f9 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 b8b685311..7841d4c12 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);