diff options
author | Pavel Březina <pbrezina@redhat.com> | 2015-05-20 14:45:25 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2015-06-18 16:46:10 +0200 |
commit | 2b7ef850846029641cc59560c2d8d4ab7254dda5 (patch) | |
tree | c42a7dfa9cb8e553710e23205ef5813e7b84b3f3 | |
parent | f7adbb15dbdcb79e291f7cf361a400ce25f7b382 (diff) | |
download | sssd-2b7ef850846029641cc59560c2d8d4ab7254dda5.tar.gz sssd-2b7ef850846029641cc59560c2d8d4ab7254dda5.tar.xz sssd-2b7ef850846029641cc59560c2d8d4ab7254dda5.zip |
IFP: Export nodes
IFP now exports cached users and groups in introspection.
After a user is cached with:
dbus-send --print-reply --system \
--dest=org.freedesktop.sssd.infopipe \
/org/freedesktop/sssd/infopipe/Users/ipaldap/397400000 \
org.freedesktop.sssd.infopipe.Cache.Object.Store
And Introspection called with:
dbus-send --print-reply --system \
--dest=org.freedesktop.sssd.infopipe \
/org/freedesktop/sssd/infopipe/Users \
org.freedesktop.DBus.Introspectable.Introspect
The cached users would be visible in the Introspection XML as:
<node name="ipaldap/397400000" />
</node>
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | src/responder/ifp/ifp_cache.c | 78 | ||||
-rw-r--r-- | src/responder/ifp/ifp_cache.h | 10 | ||||
-rw-r--r-- | src/responder/ifp/ifp_iface_nodes.c | 129 | ||||
-rw-r--r-- | src/responder/ifp/ifp_private.h | 2 | ||||
-rw-r--r-- | src/responder/ifp/ifpsrv.c | 2 |
6 files changed, 200 insertions, 22 deletions
diff --git a/Makefile.am b/Makefile.am index bad92e060..73de2db94 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1102,6 +1102,7 @@ sssd_ifp_SOURCES = \ src/responder/ifp/ifp_iface_generated.c \ src/responder/ifp/ifp_iface_generated.h \ src/responder/ifp/ifp_iface.c \ + src/responder/ifp/ifp_iface_nodes.c \ src/responder/ifp/ifpsrv_util.c \ src/responder/ifp/ifp_domains.c \ src/responder/ifp/ifp_components.c \ diff --git a/src/responder/ifp/ifp_cache.c b/src/responder/ifp/ifp_cache.c index 35d51ab2c..9bf7ed7e7 100644 --- a/src/responder/ifp/ifp_cache.c +++ b/src/responder/ifp/ifp_cache.c @@ -149,45 +149,43 @@ done: return ret; } -int ifp_cache_list(struct sbus_request *sbus_req, - void *data, - enum ifp_cache_type type) +errno_t ifp_cache_list_domains(TALLOC_CTX *mem_ctx, + struct sss_domain_info *domains, + enum ifp_cache_type type, + const char ***_paths, + int *_num_paths) { - DBusError *error; + TALLOC_CTX *tmp_ctx; struct sss_domain_info *domain; - struct ifp_ctx *ifp_ctx; const char **tmp_paths; int num_tmp_paths; const char **paths; int num_paths; errno_t ret; - ifp_ctx = talloc_get_type(data, struct ifp_ctx); - if (ifp_ctx == NULL) { - DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n"); - return ERR_INTERNAL; + tmp_ctx = talloc_new(NULL); + if (tmp_ctx == NULL) { + return ENOMEM; } - domain = ifp_ctx->rctx->domains; + domain = domains; num_paths = 0; paths = NULL; while (domain != NULL) { - ret = ifp_cache_get_cached_objects(sbus_req, type, domain, + ret = ifp_cache_get_cached_objects(tmp_ctx, type, domain, &tmp_paths, &num_tmp_paths); if (ret != EOK) { - error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED, - "Unable to build object list [%d]: %s\n", - ret, sss_strerror(ret)); - return sbus_request_fail_and_finish(sbus_req, error); + DEBUG(SSSDBG_CRIT_FAILURE, "Unable to build object list " + "[%d]: %s\n", ret, sss_strerror(ret)); + goto done; } - ret = add_strings_lists(sbus_req, paths, tmp_paths, false, + ret = add_strings_lists(tmp_ctx, paths, tmp_paths, true, discard_const(&paths)); if (ret != EOK) { - error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED, - "Unable to build object list [%d]: %s\n", - ret, sss_strerror(ret)); - return sbus_request_fail_and_finish(sbus_req, error); + DEBUG(SSSDBG_CRIT_FAILURE, "Unable to build object list " + "[%d]: %s\n", ret, sss_strerror(ret)); + goto done; } num_paths += num_tmp_paths; @@ -195,6 +193,46 @@ int ifp_cache_list(struct sbus_request *sbus_req, domain = get_next_domain(domain, true); } + if (_paths != NULL) { + *_paths = talloc_steal(mem_ctx, paths); + } + + if (_num_paths != NULL) { + *_num_paths = num_paths; + } + + ret = EOK; + +done: + talloc_free(tmp_ctx); + return ret; +} + +int ifp_cache_list(struct sbus_request *sbus_req, + void *data, + enum ifp_cache_type type) +{ + DBusError *error; + struct ifp_ctx *ifp_ctx; + const char **paths; + int num_paths; + errno_t ret; + + ifp_ctx = talloc_get_type(data, struct ifp_ctx); + if (ifp_ctx == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n"); + return ERR_INTERNAL; + } + + ret = ifp_cache_list_domains(sbus_req, ifp_ctx->rctx->domains, type, + &paths, &num_paths); + if (ret != EOK) { + error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED, + "Unable to build object list [%d]: %s\n", + ret, sss_strerror(ret)); + return sbus_request_fail_and_finish(sbus_req, error); + } + iface_ifp_cache_List_finish(sbus_req, paths, num_paths); return EOK; diff --git a/src/responder/ifp/ifp_cache.h b/src/responder/ifp/ifp_cache.h index 56e90bb9c..eb1630954 100644 --- a/src/responder/ifp/ifp_cache.h +++ b/src/responder/ifp/ifp_cache.h @@ -24,13 +24,19 @@ #include "responder/common/responder.h" #include "responder/ifp/ifp_iface_generated.h" -/* org.freedesktop-sssd-infopipe.Cache */ - enum ifp_cache_type { IFP_CACHE_USER, IFP_CACHE_GROUP }; +errno_t ifp_cache_list_domains(TALLOC_CTX *mem_ctx, + struct sss_domain_info *domains, + enum ifp_cache_type type, + const char ***_paths, + int *_num_paths); + +/* org.freedesktop-sssd-infopipe.Cache */ + int ifp_cache_list(struct sbus_request *sbus_req, void *data, enum ifp_cache_type type); diff --git a/src/responder/ifp/ifp_iface_nodes.c b/src/responder/ifp/ifp_iface_nodes.c new file mode 100644 index 000000000..ecb9ba324 --- /dev/null +++ b/src/responder/ifp/ifp_iface_nodes.c @@ -0,0 +1,129 @@ +/* + 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 "sbus/sssd_dbus.h" +#include "responder/ifp/ifp_iface_generated.h" +#include "responder/ifp/ifp_users.h" +#include "responder/ifp/ifp_groups.h" +#include "responder/ifp/ifp_cache.h" + +static const char ** +nodes_ifp(TALLOC_CTX *mem_ctx, const char *path, void *data) +{ + static const char *nodes[] = {"Users", "Groups", NULL}; + + return nodes; +} + +static const char ** +nodes_cached_objects(TALLOC_CTX *mem_ctx, + void *data, + enum ifp_cache_type type, + const char *prefix) +{ + TALLOC_CTX *tmp_ctx; + struct ifp_ctx *ifp_ctx; + const char **paths; + const char **nodes; + const char *node; + int num_paths; + errno_t ret; + int i; + + tmp_ctx = talloc_new(NULL); + if (tmp_ctx == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n"); + return NULL; + } + + ifp_ctx = talloc_get_type(data, struct ifp_ctx); + if (ifp_ctx == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n"); + goto fail; + } + + ret = ifp_cache_list_domains(tmp_ctx, ifp_ctx->rctx->domains, + type, &paths, &num_paths); + if (ret != EOK) { + DEBUG(SSSDBG_CRIT_FAILURE, "Unable to obtain cache objects list " + "[%d]: %s\n", ret, sss_strerror(ret)); + goto fail; + } + + nodes = talloc_zero_array(tmp_ctx, const char *, num_paths + 1); + if (nodes == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero_array() failed\n"); + goto fail; + } + + for (i = 0; i < num_paths; i++) { + node = sbus_opath_strip_prefix(paths[i], prefix); + nodes[i] = talloc_strdup(nodes, node); + if (nodes[i] == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, "talloc_strdup() failed\n"); + goto fail; + } + } + + talloc_steal(mem_ctx, nodes); + talloc_free(tmp_ctx); + + return nodes; + +fail: + talloc_free(tmp_ctx); + return NULL; +} + +static const char ** +nodes_users(TALLOC_CTX *mem_ctx, const char *path, void *data) +{ + return nodes_cached_objects(mem_ctx, data, IFP_CACHE_USER, + IFP_PATH_USERS "/"); +} + +static const char ** +nodes_groups(TALLOC_CTX *mem_ctx, const char *path, void *data) +{ + return nodes_cached_objects(mem_ctx, data, IFP_CACHE_GROUP, + IFP_PATH_GROUPS "/"); +} + +struct nodes_map { + const char *path; + sbus_nodes_fn fn; +}; + +static struct nodes_map nodes_map[] = { + { IFP_PATH, nodes_ifp }, + { IFP_PATH_USERS, nodes_users }, + { IFP_PATH_GROUPS, nodes_groups }, + { NULL, NULL} +}; + +void ifp_register_nodes(struct ifp_ctx *ctx, struct sbus_connection *conn) +{ + int i; + + for (i = 0; nodes_map[i].path != NULL; i++) { + sbus_conn_register_nodes(conn, nodes_map[i].path, + nodes_map[i].fn, ctx); + } +} diff --git a/src/responder/ifp/ifp_private.h b/src/responder/ifp/ifp_private.h index 94c9a4b85..304e4dc53 100644 --- a/src/responder/ifp/ifp_private.h +++ b/src/responder/ifp/ifp_private.h @@ -49,6 +49,8 @@ struct ifp_ctx { errno_t ifp_register_sbus_interface(struct sbus_connection *conn, void *handler_data); +void ifp_register_nodes(struct ifp_ctx *ctx, struct sbus_connection *conn); + /* This is a throwaway method to ease the review of the patch. * It will be removed later */ int ifp_ping(struct sbus_request *dbus_req, void *data); diff --git a/src/responder/ifp/ifpsrv.c b/src/responder/ifp/ifpsrv.c index f804ea197..631bcd266 100644 --- a/src/responder/ifp/ifpsrv.c +++ b/src/responder/ifp/ifpsrv.c @@ -165,6 +165,8 @@ sysbus_init(TALLOC_CTX *mem_ctx, goto fail; } + ifp_register_nodes(pvt, system_bus->conn); + *sysbus = system_bus; return EOK; |