summaryrefslogtreecommitdiffstats
path: root/src/providers/data_provider/dp_iface_backend.c
blob: f4af35ed6ec3858b7fff80cf2933926a653ba6f5 (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
/*
    Authors:
        Pavel Březina <pbrezina@redhat.com>

    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 <talloc.h>
#include <tevent.h>

#include "sbus/sssd_dbus.h"
#include "sbus/sssd_dbus_errors.h"
#include "providers/data_provider/dp_private.h"
#include "providers/data_provider/dp_iface.h"
#include "providers/backend.h"
#include "util/util.h"

errno_t dp_backend_is_online(struct sbus_request *sbus_req,
                             void *dp_cli,
                             const char *domname)
{
    struct be_ctx *be_ctx;
    struct sss_domain_info *domain;
    DBusError *error;
    bool online;

    be_ctx = dp_client_be(dp_cli);

    if (SBUS_IS_STRING_EMPTY(domname)) {
        domain = be_ctx->domain;
    } else {
        domain = find_domain_by_name(be_ctx->domain, domname, false);
        if (domain == NULL) {
            error = sbus_error_new(sbus_req, SBUS_ERROR_UNKNOWN_DOMAIN,
                                   "Unknown domain %s", domname);
            if (error == NULL) {
                return ENOMEM;
            }

            return sbus_request_fail_and_finish(sbus_req, error);
        }
    }

    if (domain == be_ctx->domain) {
        online = be_is_offline(be_ctx) == false;
    } else {
        online = domain->state == DOM_ACTIVE;
    }

    iface_dp_backend_IsOnline_finish(sbus_req, online);
    return EOK;
}