diff options
author | Michal Zidek <mzidek@redhat.com> | 2014-07-15 12:00:36 -0400 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2014-07-29 14:51:52 +0200 |
commit | 5328aaeea84268b6d4e26cd33a2b3e8ea89bc349 (patch) | |
tree | 791be8f41958c2b5d1f20613be72b338abb5016a /src/confdb | |
parent | 1b72f6377e997bbadabad9e5e43998dddfe38156 (diff) | |
download | sssd-5328aaeea84268b6d4e26cd33a2b3e8ea89bc349.tar.gz sssd-5328aaeea84268b6d4e26cd33a2b3e8ea89bc349.tar.xz sssd-5328aaeea84268b6d4e26cd33a2b3e8ea89bc349.zip |
Add function confdb_set_string.
Part of fix for:
https://fedorahosted.org/sssd/ticket/2367
Reviewed-by: Pavel Reichl <preichl@redhat.com>
Diffstat (limited to 'src/confdb')
-rw-r--r-- | src/confdb/confdb.c | 71 | ||||
-rw-r--r-- | src/confdb/confdb.h | 22 |
2 files changed, 93 insertions, 0 deletions
diff --git a/src/confdb/confdb.c b/src/confdb/confdb.c index 15de9616f..ae7abd73f 100644 --- a/src/confdb/confdb.c +++ b/src/confdb/confdb.c @@ -369,6 +369,77 @@ done: return ret; } +int confdb_set_string(struct confdb_ctx *cdb, + const char *section, + const char *attribute, + char *val) +{ + TALLOC_CTX *tmp_ctx; + struct ldb_dn *dn; + char *secdn; + struct ldb_message *msg; + int ret, lret; + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { + return ENOMEM; + } + + ret = parse_section(tmp_ctx, section, &secdn, NULL); + if (ret != EOK) { + goto done; + } + + dn = ldb_dn_new(tmp_ctx, cdb->ldb, secdn); + if (!dn) { + ret = EIO; + goto done; + } + + msg = ldb_msg_new(tmp_ctx); + if (!msg) { + ret = ENOMEM; + goto done; + } + + msg->dn = dn; + + lret = ldb_msg_add_empty(msg, attribute, LDB_FLAG_MOD_REPLACE, NULL); + if (lret != LDB_SUCCESS) { + DEBUG(SSSDBG_MINOR_FAILURE, + "ldb_msg_add_empty failed: [%s]\n", ldb_strerror(lret)); + ret = EIO; + goto done; + } + + lret = ldb_msg_add_string(msg, attribute, val); + if (lret != LDB_SUCCESS) { + DEBUG(SSSDBG_MINOR_FAILURE, + "ldb_msg_add_string failed: [%s]\n", ldb_strerror(lret)); + ret = EIO; + goto done; + } + + lret = ldb_modify(cdb->ldb, msg); + if (lret != LDB_SUCCESS) { + DEBUG(SSSDBG_MINOR_FAILURE, + "ldb_modify failed: [%s]\n", ldb_strerror(lret)); + ret = EIO; + goto done; + } + + ret = EOK; + +done: + talloc_free(tmp_ctx); + if (ret != EOK) { + DEBUG(SSSDBG_CRIT_FAILURE, + "Failed to set [%s] from [%s], error [%d] (%s)\n", + attribute, section, ret, strerror(ret)); + } + return ret; +} + int confdb_get_string(struct confdb_ctx *cdb, TALLOC_CTX *ctx, const char *section, const char *attribute, const char *defstr, char **result) diff --git a/src/confdb/confdb.h b/src/confdb/confdb.h index 4ac69ebef..014903c4b 100644 --- a/src/confdb/confdb.h +++ b/src/confdb/confdb.h @@ -461,6 +461,28 @@ int confdb_set_bool(struct confdb_ctx *cdb, bool val); /** + * @brief Convenience function to set a single-valued attribute as a string + * + * @param[in] cdb The connection object to the confdb + * @param[in] section The ConfDB section to update. This is constructed from + * the format of the sssd.conf file. All sections start + * with 'config/'. Subsections are separated by slashes. + * e.g. [domain/LDAP] in sssd.conf would translate to + * config/domain/LDAP + * @param[in] attribute The name of the attribute to update + * @param[in] val New value of the attribute. + * + * @return 0 - Successfully retrieved the entry (or used the default) + * @return ENOMEM - There was insufficient memory to complete the operation + * @return EINVAL - The section could not be parsed + * @return EIO - An I/O error occurred while communicating with the ConfDB + */ +int confdb_set_string(struct confdb_ctx *cdb, + const char *section, + const char *attribute, + char *val); + +/** * @brief Convenience function to retrieve a single-valued attribute as a * null-terminated array of strings * |