summaryrefslogtreecommitdiffstats
path: root/src/responder/common/iface/responder_domain.c
blob: 2e7f788550b3cd0dcec20fc5b91fe8a4cb366875 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
    Copyright (C) 2016 Red Hat

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <string.h>
#include <errno.h>

#include "util/util.h"
#include "sbus/sssd_dbus.h"
#include "responder/common/responder.h"
#include "responder/common/iface/responder_iface.h"

static void set_domain_state_by_name(struct resp_ctx *rctx,
                                     const char *domain_name,
                                     enum sss_domain_state state)
{
    struct sss_domain_info *dom;

    if (domain_name == NULL) {
        DEBUG(SSSDBG_MINOR_FAILURE, "BUG: NULL domain name\n");
        return;
    }

    DEBUG(SSSDBG_TRACE_LIBS, "Setting state of domain %s\n", domain_name);

    for (dom = rctx->domains;
         dom != NULL;
         dom = get_next_domain(dom, SSS_GND_ALL_DOMAINS)) {

        if (strcasecmp(dom->name, domain_name) == 0) {
            break;
        }
    }

    if (dom != NULL) {
        sss_domain_set_state(dom, state);
    }
}

int sss_resp_domain_active(struct sbus_request *req,
                           void *data,
                           const char *domain_name)
{
    struct resp_ctx *rctx = talloc_get_type(data, struct resp_ctx);

    DEBUG(SSSDBG_TRACE_LIBS, "Enabling domain %s\n", domain_name);
    set_domain_state_by_name(rctx, domain_name, DOM_ACTIVE);
    return iface_responder_domain_SetActive_finish(req);
}

int sss_resp_domain_inconsistent(struct sbus_request *req,
                                 void *data,
                                 const char *domain_name)
{
    struct resp_ctx *rctx = talloc_get_type(data, struct resp_ctx);

    DEBUG(SSSDBG_TRACE_LIBS, "Disabling domain %s\n", domain_name);
    set_domain_state_by_name(rctx, domain_name, DOM_INCONSISTENT);
    return iface_responder_domain_SetInconsistent_finish(req);
}