summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/confdb/confdb.c75
-rw-r--r--src/confdb/confdb.h5
2 files changed, 80 insertions, 0 deletions
diff --git a/src/confdb/confdb.c b/src/confdb/confdb.c
index 5915f2f36..ab0d00480 100644
--- a/src/confdb/confdb.c
+++ b/src/confdb/confdb.c
@@ -288,6 +288,81 @@ done:
return ret;
}
+int confdb_set_bool(struct confdb_ctx *cdb,
+ const char *section,
+ const char *attribute,
+ bool 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;
+ }
+
+ if (val) {
+ lret = ldb_msg_add_string(msg, attribute, "True");
+ } else {
+ lret = ldb_msg_add_string(msg, attribute, "False");
+ }
+ 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 cdbd1ff12..8ed23565b 100644
--- a/src/confdb/confdb.h
+++ b/src/confdb/confdb.h
@@ -414,6 +414,11 @@ int confdb_get_bool(struct confdb_ctx *cdb,
const char *section, const char *attribute,
bool defval, bool *result);
+int confdb_set_bool(struct confdb_ctx *cdb,
+ const char *section,
+ const char *attribute,
+ bool val);
+
/**
* @brief Convenience function to retrieve a single-valued attribute as a
* null-terminated array of strings