Blob Blame History Raw
From 5605fa5f8adf79fa60286f5427aa2f989e663de0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Tue, 11 Jun 2019 12:18:34 +0200
Subject: [PATCH 43/44] ad: remove all subdomains if only master domain is
 enabled

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

Reviewed-by: Sumit Bose <sbose@redhat.com>
(cherry picked from commit d0bdaabbc95bc9ee3253e1376d849e6a8bd6c6f0)
---
 src/providers/ad/ad_subdomains.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c
index 57438fdd5..0f6d781ae 100644
--- a/src/providers/ad/ad_subdomains.c
+++ b/src/providers/ad/ad_subdomains.c
@@ -1804,9 +1804,11 @@ static void ad_subdomains_refresh_gc_check_done(struct tevent_req *subreq)
 {
     struct ad_subdomains_refresh_state *state;
     struct tevent_req *req;
+    const char **subdoms;
     const char *ad_domain;
     bool is_gc_usable;
     errno_t ret;
+    int i;
 
     req = tevent_req_callback_data(subreq, struct tevent_req);
     state = tevent_req_data(req, struct ad_subdomains_refresh_state);
@@ -1832,6 +1834,27 @@ static void ad_subdomains_refresh_gc_check_done(struct tevent_req *subreq)
                            state->be_ctx->domain->name) == 0) {
                 DEBUG(SSSDBG_TRACE_FUNC,
                       "No other enabled domain than master.\n");
+
+                ret = sysdb_list_subdomains(state, state->be_ctx->domain->sysdb,
+                                            &subdoms);
+                if (ret != EOK) {
+                    DEBUG(SSSDBG_OP_FAILURE, "Unable to list subdomains "
+                          "[%d]: %s\n", ret, sss_strerror(ret));
+                    tevent_req_error(req, ret);
+                    return;
+                }
+
+                for (i = 0; subdoms[i] != NULL; i++) {
+                    ret = sysdb_subdomain_delete(state->be_ctx->domain->sysdb,
+                                                 subdoms[i]);
+                    if (ret != EOK) {
+                        DEBUG(SSSDBG_OP_FAILURE, "Unable to remove subdomain "
+                              "[%d]: %s\n", ret, sss_strerror(ret));
+                        tevent_req_error(req, ret);
+                        return;
+                    }
+                }
+
                 tevent_req_done(req);
                 return;
             }
-- 
2.20.1