summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2008-11-04 17:31:40 -0500
committerSimo Sorce <idra@samba.org>2008-11-04 17:39:27 -0500
commit4f49323af05f718d21b61f9763d73280430beaf2 (patch)
tree47ad2f9ae5a79020c810f3b99383f381161c7864
parenta2c6e0e0beb75e0a8fa7e3e07e9443d97ea2b731 (diff)
downloadsssd-4f49323af05f718d21b61f9763d73280430beaf2.tar.gz
sssd-4f49323af05f718d21b61f9763d73280430beaf2.tar.bz2
sssd-4f49323af05f718d21b61f9763d73280430beaf2.zip
Add some more service functions
-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 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);