Line data Source code
1 : /*
2 : Authors:
3 : Pavel Březina <pbrezina@redhat.com>
4 :
5 : Copyright (C) 2015 Red Hat
6 :
7 : This program is free software; you can redistribute it and/or modify
8 : it under the terms of the GNU General Public License as published by
9 : the Free Software Foundation; either version 3 of the License, or
10 : (at your option) any later version.
11 :
12 : This program is distributed in the hope that it will be useful,
13 : but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : GNU General Public License for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with this program. If not, see <http://www.gnu.org/licenses/>.
19 : */
20 :
21 : #include "sbus/sssd_dbus.h"
22 : #include "responder/ifp/ifp_iface_generated.h"
23 : #include "responder/ifp/ifp_users.h"
24 : #include "responder/ifp/ifp_groups.h"
25 : #include "responder/ifp/ifp_cache.h"
26 :
27 : static const char **
28 0 : nodes_ifp(TALLOC_CTX *mem_ctx, const char *path, void *data)
29 : {
30 : static const char *nodes[] = {"Users", "Groups", NULL};
31 :
32 0 : return nodes;
33 : }
34 :
35 : static const char **
36 0 : nodes_cached_objects(TALLOC_CTX *mem_ctx,
37 : void *data,
38 : enum ifp_cache_type type,
39 : const char *prefix)
40 : {
41 : TALLOC_CTX *tmp_ctx;
42 : struct ifp_ctx *ifp_ctx;
43 : const char **paths;
44 : const char **nodes;
45 : const char *node;
46 : int num_paths;
47 : errno_t ret;
48 : int i;
49 :
50 0 : tmp_ctx = talloc_new(NULL);
51 0 : if (tmp_ctx == NULL) {
52 0 : DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
53 0 : return NULL;
54 : }
55 :
56 0 : ifp_ctx = talloc_get_type(data, struct ifp_ctx);
57 0 : if (ifp_ctx == NULL) {
58 0 : DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
59 0 : goto fail;
60 : }
61 :
62 0 : ret = ifp_cache_list_domains(tmp_ctx, ifp_ctx->rctx->domains,
63 : type, &paths, &num_paths);
64 0 : if (ret != EOK) {
65 0 : DEBUG(SSSDBG_CRIT_FAILURE, "Unable to obtain cache objects list "
66 : "[%d]: %s\n", ret, sss_strerror(ret));
67 0 : goto fail;
68 : }
69 :
70 0 : nodes = talloc_zero_array(tmp_ctx, const char *, num_paths + 1);
71 0 : if (nodes == NULL) {
72 0 : DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero_array() failed\n");
73 0 : goto fail;
74 : }
75 :
76 0 : for (i = 0; i < num_paths; i++) {
77 0 : node = sbus_opath_strip_prefix(paths[i], prefix);
78 0 : nodes[i] = talloc_strdup(nodes, node);
79 0 : if (nodes[i] == NULL) {
80 0 : DEBUG(SSSDBG_CRIT_FAILURE, "talloc_strdup() failed\n");
81 0 : goto fail;
82 : }
83 : }
84 :
85 0 : talloc_steal(mem_ctx, nodes);
86 0 : talloc_free(tmp_ctx);
87 :
88 0 : return nodes;
89 :
90 : fail:
91 0 : talloc_free(tmp_ctx);
92 0 : return NULL;
93 : }
94 :
95 : static const char **
96 0 : nodes_users(TALLOC_CTX *mem_ctx, const char *path, void *data)
97 : {
98 0 : return nodes_cached_objects(mem_ctx, data, IFP_CACHE_USER,
99 : IFP_PATH_USERS "/");
100 : }
101 :
102 : static const char **
103 0 : nodes_groups(TALLOC_CTX *mem_ctx, const char *path, void *data)
104 : {
105 0 : return nodes_cached_objects(mem_ctx, data, IFP_CACHE_GROUP,
106 : IFP_PATH_GROUPS "/");
107 : }
108 :
109 : struct nodes_map {
110 : const char *path;
111 : sbus_nodes_fn fn;
112 : };
113 :
114 : static struct nodes_map nodes_map[] = {
115 : { IFP_PATH, nodes_ifp },
116 : { IFP_PATH_USERS, nodes_users },
117 : { IFP_PATH_GROUPS, nodes_groups },
118 : { NULL, NULL}
119 : };
120 :
121 0 : void ifp_register_nodes(struct ifp_ctx *ctx, struct sbus_connection *conn)
122 : {
123 : int i;
124 :
125 0 : for (i = 0; nodes_map[i].path != NULL; i++) {
126 0 : sbus_conn_register_nodes(conn, nodes_map[i].path,
127 : nodes_map[i].fn, ctx);
128 : }
129 0 : }
|