From 3257f91e0f39601f36057bec2e0e6c8b5e061cc8 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 4 Mar 2009 10:28:09 -0500 Subject: Improve sysdb Add comments in header files to better explain interfaces and intended usage. Expose function to convert from ldb errors to errnos. Add sysdb_attrs helper to add a long integer as a value. --- server/db/sysdb.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'server/db/sysdb.c') diff --git a/server/db/sysdb.c b/server/db/sysdb.c index 022e33e4..b6558499 100644 --- a/server/db/sysdb.c +++ b/server/db/sysdb.c @@ -116,6 +116,42 @@ int sysdb_attrs_add_string(struct sysdb_attrs *attrs, return sysdb_attrs_add_val(attrs, name, &v); } +int sysdb_attrs_add_long(struct sysdb_attrs *attrs, + const char *name, long value) +{ + struct ldb_val v; + char *str; + int ret; + + str = talloc_asprintf(attrs, "%ld", value); + if (!str) return ENOMEM; + + v.data = (uint8_t *)str; + v.length = strlen(str); + + ret = sysdb_attrs_add_val(attrs, name, &v); + talloc_free(str); + + return ret; +} + +/* TODO: make a more complete and precise mapping */ +int sysdb_error_to_errno(int ldberr) +{ + switch (ldberr) { + case LDB_SUCCESS: + return EOK; + case LDB_ERR_OPERATIONS_ERROR: + return EIO; + case LDB_ERR_NO_SUCH_OBJECT: + return ENOENT; + case LDB_ERR_BUSY: + return EBUSY; + default: + return EFAULT; + } +} + /************************************************ * Initialiazation stuff */ -- cgit