dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone
Blob Blame History Raw
From 0e16ec74c380b35fc201ded15434184d88413dc7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Thu, 30 May 2019 12:14:58 +0200
Subject: [PATCH 39/44] sysdb: add sysdb_domain_set_enabled()

This will be used in subsequent patches to disable subdomains.

Resolves:
https://pagure.io/SSSD/sssd/issue/4009

Reviewed-by: Sumit Bose <sbose@redhat.com>
(cherry picked from commit 7a03e99890806257df1ed8a126673d6a032fee6a)
---
 src/db/sysdb.c            |  7 ++++++-
 src/db/sysdb.h            |  6 ++++++
 src/db/sysdb_subdomains.c | 31 +++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index 06d7f2796..279bd5839 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -1135,7 +1135,7 @@ errno_t sysdb_set_bool(struct sysdb_ctx *sysdb,
     errno_t ret;
     int lret;
 
-    if (dn == NULL || cn_value == NULL || attr_name == NULL) {
+    if (dn == NULL || attr_name == NULL) {
         return EINVAL;
     }
 
@@ -1159,6 +1159,11 @@ errno_t sysdb_set_bool(struct sysdb_ctx *sysdb,
     msg->dn = dn;
 
     if (res->count == 0) {
+        if (cn_value == NULL) {
+            ret = ENOENT;
+            goto done;
+        }
+
         lret = ldb_msg_add_string(msg, "cn", cn_value);
         if (lret != LDB_SUCCESS) {
             ret = sysdb_error_to_errno(lret);
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index 01e7554bb..574f4b120 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -155,6 +155,7 @@
 #define SYSDB_SUBDOMAIN_TRUST_DIRECTION "trustDirection"
 #define SYSDB_UPN_SUFFIXES "upnSuffixes"
 #define SYSDB_SITE "site"
+#define SYSDB_ENABLED "enabled"
 
 #define SYSDB_BASE_ID "baseID"
 #define SYSDB_ID_RANGE_SIZE "idRangeSize"
@@ -523,6 +524,11 @@ errno_t
 sysdb_set_site(struct sss_domain_info *dom,
                const char *site);
 
+errno_t
+sysdb_domain_set_enabled(struct sysdb_ctx *sysdb,
+                         const char *name,
+                         bool enabled);
+
 errno_t sysdb_subdomain_store(struct sysdb_ctx *sysdb,
                               const char *name, const char *realm,
                               const char *flat_name, const char *domain_id,
diff --git a/src/db/sysdb_subdomains.c b/src/db/sysdb_subdomains.c
index 34d052fdd..d467dfce5 100644
--- a/src/db/sysdb_subdomains.c
+++ b/src/db/sysdb_subdomains.c
@@ -1200,6 +1200,18 @@ errno_t sysdb_subdomain_store(struct sysdb_ctx *sysdb,
         }
     }
 
+    ret = ldb_msg_add_empty(msg, SYSDB_ENABLED, LDB_FLAG_MOD_REPLACE, NULL);
+    if (ret != LDB_SUCCESS) {
+        ret = sysdb_error_to_errno(ret);
+        goto done;
+    }
+
+    ret = ldb_msg_add_string(msg, SYSDB_ENABLED, "TRUE");
+    if (ret != LDB_SUCCESS) {
+        ret = sysdb_error_to_errno(ret);
+        goto done;
+    }
+
     ret = ldb_modify(sysdb->ldb, msg);
     if (ret != LDB_SUCCESS) {
         DEBUG(SSSDBG_FATAL_FAILURE, "Failed to add subdomain attributes to "
@@ -1420,3 +1432,22 @@ done:
     talloc_free(tmp_ctx);
     return ret;
 }
+
+errno_t
+sysdb_domain_set_enabled(struct sysdb_ctx *sysdb,
+                         const char *name,
+                         bool enabled)
+{
+    struct ldb_dn *dn;
+    errno_t ret;
+
+    dn = ldb_dn_new_fmt(NULL, sysdb->ldb, SYSDB_DOM_BASE, name);
+    if (dn == NULL) {
+        return ENOMEM;
+    }
+
+    ret = sysdb_set_bool(sysdb, dn, NULL, SYSDB_ENABLED, enabled);
+    talloc_free(dn);
+
+    return ret;
+}
-- 
2.20.1