diff options
author | Pavel Březina <pbrezina@redhat.com> | 2012-01-17 15:32:41 +0100 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2012-01-17 11:38:16 -0500 |
commit | 6961025be43141b1d1ca4a6a046ce8f3ac94f508 (patch) | |
tree | 7fdff645c4add239b5b6d5e4ae6f03011978dbb1 /src | |
parent | efe918d7cb27a6ac5901748fc1f5879e3296c012 (diff) | |
download | sssd-6961025be43141b1d1ca4a6a046ce8f3ac94f508.tar.gz sssd-6961025be43141b1d1ca4a6a046ce8f3ac94f508.tar.bz2 sssd-6961025be43141b1d1ca4a6a046ce8f3ac94f508.zip |
sysdb_get_bool() and sysdb_get_bool() functions
Diffstat (limited to 'src')
-rw-r--r-- | src/db/sysdb.c | 148 | ||||
-rw-r--r-- | src/db/sysdb.h | 11 |
2 files changed, 108 insertions, 51 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c index 9fcb7ae5..f36eadea 100644 --- a/src/db/sysdb.c +++ b/src/db/sysdb.c @@ -1337,34 +1337,29 @@ errno_t sysdb_attrs_to_list(TALLOC_CTX *mem_ctx, return EOK; } -errno_t sysdb_has_enumerated(struct sysdb_ctx *sysdb, - bool *has_enumerated) +errno_t sysdb_get_bool(struct sysdb_ctx *sysdb, + struct ldb_dn *dn, + const char *attr_name, + bool *value) { + TALLOC_CTX *tmp_ctx; + struct ldb_result *res; errno_t ret; int lret; - struct ldb_dn *base_dn; - struct ldb_result *res; - const char *attributes[2] = {SYSDB_HAS_ENUMERATED, - NULL}; - TALLOC_CTX *tmp_ctx; - + const char *attrs[2] = {attr_name, NULL}; tmp_ctx = talloc_new(NULL); - if (!tmp_ctx) { - ret = ENOMEM; - goto done; + if (tmp_ctx == NULL) { + return ENOMEM; } - base_dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, - SYSDB_DOM_BASE, - sysdb->domain->name); - if (!base_dn) { - ret = ENOMEM; + lret = ldb_search(sysdb->ldb, tmp_ctx, &res, dn, LDB_SCOPE_BASE, + attrs, NULL); + if (lret != LDB_SUCCESS) { + ret = sysdb_error_to_errno(lret); goto done; } - lret = ldb_search(sysdb->ldb, tmp_ctx, &res, base_dn, - LDB_SCOPE_BASE, attributes, NULL); if (lret != LDB_SUCCESS) { ret = sysdb_error_to_errno(lret); goto done; @@ -1378,20 +1373,17 @@ errno_t sysdb_has_enumerated(struct sysdb_ctx *sysdb, * This object in the sysdb exists mostly just * to contain this attribute. */ - *has_enumerated = false; + *value = false; ret = EOK; goto done; } else if (res->count != 1) { - DEBUG(0, ("Corrupted database. " - "More than one entry for base search.\n")); + DEBUG(SSSDBG_CRIT_FAILURE, + ("Got more than one reply for base search!\n")); ret = EIO; goto done; } - /* Object existed. Return the stored value */ - *has_enumerated = ldb_msg_find_attr_as_bool(res->msgs[0], - SYSDB_HAS_ENUMERATED, - false); + *value = ldb_msg_find_attr_as_bool(res->msgs[0], attr_name, false); ret = EOK; @@ -1400,65 +1392,61 @@ done: return ret; } -errno_t sysdb_set_enumerated(struct sysdb_ctx *sysdb, - bool enumerated) +errno_t sysdb_set_bool(struct sysdb_ctx *sysdb, + struct ldb_dn *dn, + const char *cn_value, + const char *attr_name, + bool value) { + TALLOC_CTX *tmp_ctx = NULL; + struct ldb_message *msg = NULL; + struct ldb_result *res = NULL; errno_t ret; int lret; - TALLOC_CTX *tmp_ctx; - struct ldb_message *msg; - struct ldb_result *res; - struct ldb_dn *dn; - tmp_ctx = talloc_new(NULL); - if (!tmp_ctx) { - ret = ENOMEM; - goto done; + if (dn == NULL || cn_value == NULL || attr_name == NULL) { + return EINVAL; } - dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, - SYSDB_DOM_BASE, - sysdb->domain->name); - if (!dn) { - ret = ENOMEM; - goto done; + tmp_ctx = talloc_new(NULL); + if (tmp_ctx == NULL) { + return ENOMEM; } - lret = ldb_search(sysdb->ldb, tmp_ctx, &res, - dn, LDB_SCOPE_BASE, + lret = ldb_search(sysdb->ldb, tmp_ctx, &res, dn, LDB_SCOPE_BASE, NULL, NULL); if (lret != LDB_SUCCESS) { - ret = EIO; + ret = sysdb_error_to_errno(lret); goto done; } msg = ldb_msg_new(tmp_ctx); - if (!msg) { + if (msg == NULL) { ret = ENOMEM; goto done; } msg->dn = dn; if (res->count == 0) { - lret = ldb_msg_add_string(msg, "cn", sysdb->domain->name); + lret = ldb_msg_add_string(msg, "cn", cn_value); if (lret != LDB_SUCCESS) { ret = sysdb_error_to_errno(lret); goto done; } } else if (res->count != 1) { - DEBUG(0, ("Got more than one reply for base search!\n")); + DEBUG(SSSDBG_CRIT_FAILURE, + ("Got more than one reply for base search!\n")); ret = EIO; goto done; } else { - lret = ldb_msg_add_empty(msg, SYSDB_HAS_ENUMERATED, - LDB_FLAG_MOD_REPLACE, NULL); + lret = ldb_msg_add_empty(msg, attr_name, LDB_FLAG_MOD_REPLACE, NULL); if (lret != LDB_SUCCESS) { ret = sysdb_error_to_errno(lret); goto done; } } - lret = ldb_msg_add_fmt(msg, SYSDB_HAS_ENUMERATED, "%s", - enumerated?"TRUE":"FALSE"); + + lret = ldb_msg_add_fmt(msg, attr_name, "%s", value ? "TRUE" : "FALSE"); if (lret != LDB_SUCCESS) { ret = sysdb_error_to_errno(lret); goto done; @@ -1477,6 +1465,64 @@ done: return ret; } +errno_t sysdb_has_enumerated(struct sysdb_ctx *sysdb, + bool *has_enumerated) +{ + errno_t ret; + struct ldb_dn *dn; + TALLOC_CTX *tmp_ctx; + + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { + ret = ENOMEM; + goto done; + } + + dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, + SYSDB_DOM_BASE, + sysdb->domain->name); + if (!dn) { + ret = ENOMEM; + goto done; + } + + ret = sysdb_get_bool(sysdb, dn, SYSDB_HAS_ENUMERATED, has_enumerated); + +done: + talloc_free(tmp_ctx); + return ret; +} + +errno_t sysdb_set_enumerated(struct sysdb_ctx *sysdb, + bool enumerated) +{ + errno_t ret; + TALLOC_CTX *tmp_ctx; + struct ldb_dn *dn; + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { + ret = ENOMEM; + goto done; + } + + dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, + SYSDB_DOM_BASE, + sysdb->domain->name); + if (!dn) { + ret = ENOMEM; + goto done; + } + + ret = sysdb_set_bool(sysdb, dn, sysdb->domain->name, + SYSDB_HAS_ENUMERATED, enumerated); + +done: + talloc_free(tmp_ctx); + return ret; +} + errno_t sysdb_attrs_primary_name(struct sysdb_ctx *sysdb, struct sysdb_attrs *attrs, const char *ldap_attr, diff --git a/src/db/sysdb.h b/src/db/sysdb.h index 3d2a7682..c4d64be1 100644 --- a/src/db/sysdb.h +++ b/src/db/sysdb.h @@ -703,6 +703,17 @@ errno_t sysdb_netgr_to_entries(TALLOC_CTX *mem_ctx, errno_t sysdb_dn_sanitize(void *mem_ctx, const char *input, char **sanitized); +errno_t sysdb_get_bool(struct sysdb_ctx *sysdb, + struct ldb_dn *dn, + const char *attr_name, + bool *value); + +errno_t sysdb_set_bool(struct sysdb_ctx *sysdb, + struct ldb_dn *dn, + const char *cn_value, + const char *attr_name, + bool value); + errno_t sysdb_has_enumerated(struct sysdb_ctx *sysdb, bool *has_enumerated); |