summaryrefslogtreecommitdiffstats
path: root/src/sbus/sssd_dbus_common_signals.c
blob: 2950c3554257a48ddafed7c8b3b4461382fb2fd0 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
    Authors:
        Pavel Březina <pbrezina@redhat.com>

    Copyright (C) 2015 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 <dbus/dbus.h>
#include <dhash.h>

#include "util/util.h"
#include "sbus/sssd_dbus.h"
#include "sbus/sssd_dbus_private.h"

static void
sbus_signal_name_owner_changed(struct sbus_incoming_signal *signal,
                               void *handler_data)
{
    hash_table_t *table = signal->conn->clients;
    hash_key_t *keys;
    unsigned long count;
    unsigned long i;
    int hret;

    DEBUG(SSSDBG_TRACE_FUNC, "Clearing UIDs cache\n");

    hret = hash_keys(table, &count, &keys);
    if (hret != HASH_SUCCESS) {
        DEBUG(SSSDBG_OP_FAILURE, "Unable to get hash keys\n");
        return;
    }

    for (i = 0; i < count; i++) {
        hret = hash_delete(table, &keys[i]);
        if (hret != HASH_SUCCESS) {
            DEBUG(SSSDBG_MINOR_FAILURE, "Could not delete key from hash\n");
            return;
        }
    }

    return;
}

struct signals_map {
    const char *iface;
    const char *signal;
    sbus_incoming_signal_fn handler_fn;
    int conn_type;
};

static struct signals_map signals_map[] = {
    { "org.freedesktop.DBus", "NameOwnerChanged",
      sbus_signal_name_owner_changed, SBUS_CONN_TYPE_SYSBUS },
    { NULL, NULL, NULL, 0 },
};

void sbus_register_common_signals(struct sbus_connection *conn, void *pvt)
{
    errno_t ret;
    int i;

    for (i = 0; signals_map[i].iface != NULL; i++) {
        if (signals_map[i].conn_type != conn->connection_type) {
            /* Skip this signal. */
            continue;
        }

        ret = sbus_signal_listen(conn, signals_map[i].iface,
                                 signals_map[i].signal,
                                 signals_map[i].handler_fn, conn);
        if (ret != EOK) {
            DEBUG(SSSDBG_MINOR_FAILURE, "Unable to register signal %s.%s\n",
                  signals_map[i].iface, signals_map[i].signal);
            continue;
        }
    }
}