dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0039-sysdb-add-sysdb_domain_set_enabled.patch

8d3578
From 0e16ec74c380b35fc201ded15434184d88413dc7 Mon Sep 17 00:00:00 2001
8d3578
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
8d3578
Date: Thu, 30 May 2019 12:14:58 +0200
8d3578
Subject: [PATCH 39/44] sysdb: add sysdb_domain_set_enabled()
8d3578
8d3578
This will be used in subsequent patches to disable subdomains.
8d3578
8d3578
Resolves:
8d3578
https://pagure.io/SSSD/sssd/issue/4009
8d3578
8d3578
Reviewed-by: Sumit Bose <sbose@redhat.com>
8d3578
(cherry picked from commit 7a03e99890806257df1ed8a126673d6a032fee6a)
8d3578
---
8d3578
 src/db/sysdb.c            |  7 ++++++-
8d3578
 src/db/sysdb.h            |  6 ++++++
8d3578
 src/db/sysdb_subdomains.c | 31 +++++++++++++++++++++++++++++++
8d3578
 3 files changed, 43 insertions(+), 1 deletion(-)
8d3578
8d3578
diff --git a/src/db/sysdb.c b/src/db/sysdb.c
8d3578
index 06d7f2796..279bd5839 100644
8d3578
--- a/src/db/sysdb.c
8d3578
+++ b/src/db/sysdb.c
8d3578
@@ -1135,7 +1135,7 @@ errno_t sysdb_set_bool(struct sysdb_ctx *sysdb,
8d3578
     errno_t ret;
8d3578
     int lret;
8d3578
 
8d3578
-    if (dn == NULL || cn_value == NULL || attr_name == NULL) {
8d3578
+    if (dn == NULL || attr_name == NULL) {
8d3578
         return EINVAL;
8d3578
     }
8d3578
 
8d3578
@@ -1159,6 +1159,11 @@ errno_t sysdb_set_bool(struct sysdb_ctx *sysdb,
8d3578
     msg->dn = dn;
8d3578
 
8d3578
     if (res->count == 0) {
8d3578
+        if (cn_value == NULL) {
8d3578
+            ret = ENOENT;
8d3578
+            goto done;
8d3578
+        }
8d3578
+
8d3578
         lret = ldb_msg_add_string(msg, "cn", cn_value);
8d3578
         if (lret != LDB_SUCCESS) {
8d3578
             ret = sysdb_error_to_errno(lret);
8d3578
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
8d3578
index 01e7554bb..574f4b120 100644
8d3578
--- a/src/db/sysdb.h
8d3578
+++ b/src/db/sysdb.h
8d3578
@@ -155,6 +155,7 @@
8d3578
 #define SYSDB_SUBDOMAIN_TRUST_DIRECTION "trustDirection"
8d3578
 #define SYSDB_UPN_SUFFIXES "upnSuffixes"
8d3578
 #define SYSDB_SITE "site"
8d3578
+#define SYSDB_ENABLED "enabled"
8d3578
 
8d3578
 #define SYSDB_BASE_ID "baseID"
8d3578
 #define SYSDB_ID_RANGE_SIZE "idRangeSize"
8d3578
@@ -523,6 +524,11 @@ errno_t
8d3578
 sysdb_set_site(struct sss_domain_info *dom,
8d3578
                const char *site);
8d3578
 
8d3578
+errno_t
8d3578
+sysdb_domain_set_enabled(struct sysdb_ctx *sysdb,
8d3578
+                         const char *name,
8d3578
+                         bool enabled);
8d3578
+
8d3578
 errno_t sysdb_subdomain_store(struct sysdb_ctx *sysdb,
8d3578
                               const char *name, const char *realm,
8d3578
                               const char *flat_name, const char *domain_id,
8d3578
diff --git a/src/db/sysdb_subdomains.c b/src/db/sysdb_subdomains.c
8d3578
index 34d052fdd..d467dfce5 100644
8d3578
--- a/src/db/sysdb_subdomains.c
8d3578
+++ b/src/db/sysdb_subdomains.c
8d3578
@@ -1200,6 +1200,18 @@ errno_t sysdb_subdomain_store(struct sysdb_ctx *sysdb,
8d3578
         }
8d3578
     }
8d3578
 
8d3578
+    ret = ldb_msg_add_empty(msg, SYSDB_ENABLED, LDB_FLAG_MOD_REPLACE, NULL);
8d3578
+    if (ret != LDB_SUCCESS) {
8d3578
+        ret = sysdb_error_to_errno(ret);
8d3578
+        goto done;
8d3578
+    }
8d3578
+
8d3578
+    ret = ldb_msg_add_string(msg, SYSDB_ENABLED, "TRUE");
8d3578
+    if (ret != LDB_SUCCESS) {
8d3578
+        ret = sysdb_error_to_errno(ret);
8d3578
+        goto done;
8d3578
+    }
8d3578
+
8d3578
     ret = ldb_modify(sysdb->ldb, msg);
8d3578
     if (ret != LDB_SUCCESS) {
8d3578
         DEBUG(SSSDBG_FATAL_FAILURE, "Failed to add subdomain attributes to "
8d3578
@@ -1420,3 +1432,22 @@ done:
8d3578
     talloc_free(tmp_ctx);
8d3578
     return ret;
8d3578
 }
8d3578
+
8d3578
+errno_t
8d3578
+sysdb_domain_set_enabled(struct sysdb_ctx *sysdb,
8d3578
+                         const char *name,
8d3578
+                         bool enabled)
8d3578
+{
8d3578
+    struct ldb_dn *dn;
8d3578
+    errno_t ret;
8d3578
+
8d3578
+    dn = ldb_dn_new_fmt(NULL, sysdb->ldb, SYSDB_DOM_BASE, name);
8d3578
+    if (dn == NULL) {
8d3578
+        return ENOMEM;
8d3578
+    }
8d3578
+
8d3578
+    ret = sysdb_set_bool(sysdb, dn, NULL, SYSDB_ENABLED, enabled);
8d3578
+    talloc_free(dn);
8d3578
+
8d3578
+    return ret;
8d3578
+}
8d3578
-- 
8d3578
2.20.1
8d3578