From 132e477d69e07e02fe6e4d668c0bb6226206474a Mon Sep 17 00:00:00 2001 From: Pavel Březina Date: Mon, 9 Feb 2015 12:17:37 +0100 Subject: IFP: add org.freedesktop.sssd.infopipe.Groups Example calls: dbus-send --print-reply --system --dest=org.freedesktop.sssd.infopipe /org/freedesktop/sssd/infopipe/Groups org.freedesktop.sssd.infopipe.Groups.FindByName string:group-1method return sender=:1.159 -> dest=:1.166 reply_serial=2 object path "/org/freedesktop/sssd/infopipe/Groups/LDAP_2ePB/30001" dbus-send --print-reply --system --dest=org.freedesktop.sssd.infopipe /org/freedesktop/sssd/infopipe/Groups org.freedesktop.sssd.infopipe.Groups.FindByID uint32:30001 method return sender=:1.159 -> dest=:1.167 reply_serial=2 object path "/org/freedesktop/sssd/infopipe/Groups/LDAP_2ePB/30001" Resolves: https://fedorahosted.org/sssd/ticket/2150 Reviewed-by: Jakub Hrozek --- src/responder/ifp/ifp_groups.c | 162 +++++++++++++++++++++ src/responder/ifp/ifp_groups.h | 20 +++ src/responder/ifp/ifp_iface.c | 10 ++ src/responder/ifp/ifp_iface.xml | 24 +++ src/responder/ifp/ifp_iface_generated.c | 121 +++++++++++++++ src/responder/ifp/ifp_iface_generated.h | 31 ++++ .../ifp/org.freedesktop.sssd.infopipe.conf | 1 + 7 files changed, 369 insertions(+) (limited to 'src/responder') diff --git a/src/responder/ifp/ifp_groups.c b/src/responder/ifp/ifp_groups.c index 533e6806d..e362002d3 100644 --- a/src/responder/ifp/ifp_groups.c +++ b/src/responder/ifp/ifp_groups.c @@ -19,8 +19,13 @@ */ #include +#include +#include "util/util.h" #include "db/sysdb.h" +#include "sbus/sssd_dbus_errors.h" +#include "responder/common/responder.h" +#include "responder/common/responder_cache_req.h" #include "responder/ifp/ifp_groups.h" char * ifp_groups_build_path_from_msg(TALLOC_CTX *mem_ctx, @@ -37,3 +42,160 @@ char * ifp_groups_build_path_from_msg(TALLOC_CTX *mem_ctx, return sbus_opath_compose(mem_ctx, IFP_PATH_GROUPS, domain->name, gid); } + +static void ifp_groups_find_by_name_done(struct tevent_req *req); + +int ifp_groups_find_by_name(struct sbus_request *sbus_req, + void *data, + const char *name) +{ + struct ifp_ctx *ctx; + struct tevent_req *req; + + ctx = talloc_get_type(data, struct ifp_ctx); + if (ctx == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n"); + return ERR_INTERNAL; + } + + req = cache_req_group_by_name_send(sbus_req, ctx->rctx->ev, ctx->rctx, + ctx->ncache, ctx->neg_timeout, 0, + NULL, name); + if (req == NULL) { + return ENOMEM; + } + + tevent_req_set_callback(req, ifp_groups_find_by_name_done, sbus_req); + + return EOK; +} + +static void +ifp_groups_find_by_name_done(struct tevent_req *req) +{ + DBusError *error; + struct sbus_request *sbus_req; + struct sss_domain_info *domain; + struct ldb_result *result; + char *object_path; + errno_t ret; + + sbus_req = tevent_req_callback_data(req, struct sbus_request); + + ret = cache_req_group_by_name_recv(sbus_req, req, &result, &domain, NULL); + talloc_zfree(req); + if (ret == ENOENT) { + error = sbus_error_new(sbus_req, SBUS_ERROR_NOT_FOUND, + "Group not found"); + goto done; + } else if (ret != EOK) { + error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED, "Failed to fetch " + "group [%d]: %s\n", ret, sss_strerror(ret)); + goto done; + } + + object_path = ifp_groups_build_path_from_msg(sbus_req, domain, + result->msgs[0]); + if (object_path == NULL) { + error = sbus_error_new(sbus_req, SBUS_ERROR_INTERNAL, + "Failed to compose object path"); + goto done; + } + + ret = EOK; + +done: + if (ret != EOK) { + sbus_request_fail_and_finish(sbus_req, error); + return; + } + + iface_ifp_groups_FindByName_finish(sbus_req, object_path); + return; +} + +static void ifp_groups_find_by_id_done(struct tevent_req *req); + +int ifp_groups_find_by_id(struct sbus_request *sbus_req, + void *data, + uint32_t id) +{ + struct ifp_ctx *ctx; + struct tevent_req *req; + + ctx = talloc_get_type(data, struct ifp_ctx); + if (ctx == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n"); + return ERR_INTERNAL; + } + + req = cache_req_group_by_id_send(sbus_req, ctx->rctx->ev, ctx->rctx, + ctx->ncache, ctx->neg_timeout, 0, + NULL, id); + if (req == NULL) { + return ENOMEM; + } + + tevent_req_set_callback(req, ifp_groups_find_by_id_done, sbus_req); + + return EOK; +} + +static void +ifp_groups_find_by_id_done(struct tevent_req *req) +{ + DBusError *error; + struct sbus_request *sbus_req; + struct sss_domain_info *domain; + struct ldb_result *result; + char *object_path; + errno_t ret; + + sbus_req = tevent_req_callback_data(req, struct sbus_request); + + ret = cache_req_group_by_id_recv(sbus_req, req, &result, &domain); + talloc_zfree(req); + if (ret == ENOENT) { + error = sbus_error_new(sbus_req, SBUS_ERROR_NOT_FOUND, + "Group not found"); + goto done; + } else if (ret != EOK) { + error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED, "Failed to fetch " + "group [%d]: %s\n", ret, sss_strerror(ret)); + goto done; + } + + object_path = ifp_groups_build_path_from_msg(sbus_req, domain, + result->msgs[0]); + if (object_path == NULL) { + error = sbus_error_new(sbus_req, SBUS_ERROR_INTERNAL, + "Failed to compose object path"); + goto done; + } + +done: + if (ret != EOK) { + sbus_request_fail_and_finish(sbus_req, error); + return; + } + + iface_ifp_groups_FindByID_finish(sbus_req, object_path); + return; +} + +int ifp_groups_list_by_name(struct sbus_request *sbus_req, + void *data, + const char *filter, + uint32_t limit) +{ + return EOK; +} + +int ifp_groups_list_by_domain_and_name(struct sbus_request *sbus_req, + void *data, + const char *domain, + const char *filter, + uint32_t limit) +{ + return EOK; +} diff --git a/src/responder/ifp/ifp_groups.h b/src/responder/ifp/ifp_groups.h index 1bdaf3e0c..b93757326 100644 --- a/src/responder/ifp/ifp_groups.h +++ b/src/responder/ifp/ifp_groups.h @@ -33,5 +33,25 @@ char * ifp_groups_build_path_from_msg(TALLOC_CTX *mem_ctx, struct sss_domain_info *domain, struct ldb_message *msg); +/* org.freedesktop.sssd.infopipe.Groups */ + +int ifp_groups_find_by_name(struct sbus_request *sbus_req, + void *data, + const char *name); + +int ifp_groups_find_by_id(struct sbus_request *sbus_req, + void *data, + uint32_t id); + +int ifp_groups_list_by_name(struct sbus_request *sbus_req, + void *data, + const char *filter, + uint32_t limit); + +int ifp_groups_list_by_domain_and_name(struct sbus_request *sbus_req, + void *data, + const char *domain, + const char *filter, + uint32_t limit); #endif /* IFP_GROUPS_H_ */ diff --git a/src/responder/ifp/ifp_iface.c b/src/responder/ifp/ifp_iface.c index 1878263c2..e762ffa28 100644 --- a/src/responder/ifp/ifp_iface.c +++ b/src/responder/ifp/ifp_iface.c @@ -25,6 +25,7 @@ #include "responder/ifp/ifp_domains.h" #include "responder/ifp/ifp_components.h" #include "responder/ifp/ifp_users.h" +#include "responder/ifp/ifp_groups.h" struct iface_ifp iface_ifp = { { &iface_ifp_meta, 0 }, @@ -98,6 +99,14 @@ struct iface_ifp_users_user iface_ifp_users_user = { .get_extraAttributes = ifp_users_user_get_extra_attributes }; +struct iface_ifp_groups iface_ifp_groups = { + { &iface_ifp_groups_meta, 0 }, + .FindByName = ifp_groups_find_by_name, + .FindByID = ifp_groups_find_by_id, + .ListByName = ifp_groups_list_by_name, + .ListByDomainAndName = ifp_groups_list_by_domain_and_name +}; + struct iface_map { const char *path; struct sbus_vtable *vtable; @@ -109,6 +118,7 @@ static struct iface_map iface_map[] = { { IFP_PATH_COMPONENTS_TREE, &iface_ifp_components.vtable }, { IFP_PATH_USERS, &iface_ifp_users.vtable }, { IFP_PATH_USERS_TREE, &iface_ifp_users_user.vtable }, + { IFP_PATH_GROUPS, &iface_ifp_groups.vtable }, { NULL, NULL }, }; diff --git a/src/responder/ifp/ifp_iface.xml b/src/responder/ifp/ifp_iface.xml index 2c15fddea..31fb529fe 100644 --- a/src/responder/ifp/ifp_iface.xml +++ b/src/responder/ifp/ifp_iface.xml @@ -140,4 +140,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/responder/ifp/ifp_iface_generated.c b/src/responder/ifp/ifp_iface_generated.c index 1f6c7ba1d..355db6e84 100644 --- a/src/responder/ifp/ifp_iface_generated.c +++ b/src/responder/ifp/ifp_iface_generated.c @@ -756,6 +756,127 @@ const struct sbus_interface_meta iface_ifp_users_user_meta = { sbus_invoke_get_all, /* GetAll invoker */ }; +/* arguments for org.freedesktop.sssd.infopipe.Groups.FindByName */ +const struct sbus_arg_meta iface_ifp_groups_FindByName__in[] = { + { "name", "s" }, + { NULL, } +}; + +/* arguments for org.freedesktop.sssd.infopipe.Groups.FindByName */ +const struct sbus_arg_meta iface_ifp_groups_FindByName__out[] = { + { "result", "o" }, + { NULL, } +}; + +int iface_ifp_groups_FindByName_finish(struct sbus_request *req, const char *arg_result) +{ + return sbus_request_return_and_finish(req, + DBUS_TYPE_OBJECT_PATH, &arg_result, + DBUS_TYPE_INVALID); +} + +/* arguments for org.freedesktop.sssd.infopipe.Groups.FindByID */ +const struct sbus_arg_meta iface_ifp_groups_FindByID__in[] = { + { "id", "u" }, + { NULL, } +}; + +/* arguments for org.freedesktop.sssd.infopipe.Groups.FindByID */ +const struct sbus_arg_meta iface_ifp_groups_FindByID__out[] = { + { "result", "o" }, + { NULL, } +}; + +int iface_ifp_groups_FindByID_finish(struct sbus_request *req, const char *arg_result) +{ + return sbus_request_return_and_finish(req, + DBUS_TYPE_OBJECT_PATH, &arg_result, + DBUS_TYPE_INVALID); +} + +/* arguments for org.freedesktop.sssd.infopipe.Groups.ListByName */ +const struct sbus_arg_meta iface_ifp_groups_ListByName__in[] = { + { "name_filter", "s" }, + { "limit", "u" }, + { NULL, } +}; + +/* arguments for org.freedesktop.sssd.infopipe.Groups.ListByName */ +const struct sbus_arg_meta iface_ifp_groups_ListByName__out[] = { + { "result", "ao" }, + { NULL, } +}; + +int iface_ifp_groups_ListByName_finish(struct sbus_request *req, const char *arg_result[], int len_result) +{ + return sbus_request_return_and_finish(req, + DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &arg_result, len_result, + DBUS_TYPE_INVALID); +} + +/* arguments for org.freedesktop.sssd.infopipe.Groups.ListByDomainAndName */ +const struct sbus_arg_meta iface_ifp_groups_ListByDomainAndName__in[] = { + { "domain_name", "s" }, + { "name_filter", "s" }, + { "limit", "u" }, + { NULL, } +}; + +/* arguments for org.freedesktop.sssd.infopipe.Groups.ListByDomainAndName */ +const struct sbus_arg_meta iface_ifp_groups_ListByDomainAndName__out[] = { + { "result", "ao" }, + { NULL, } +}; + +int iface_ifp_groups_ListByDomainAndName_finish(struct sbus_request *req, const char *arg_result[], int len_result) +{ + return sbus_request_return_and_finish(req, + DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &arg_result, len_result, + DBUS_TYPE_INVALID); +} + +/* methods for org.freedesktop.sssd.infopipe.Groups */ +const struct sbus_method_meta iface_ifp_groups__methods[] = { + { + "FindByName", /* name */ + iface_ifp_groups_FindByName__in, + iface_ifp_groups_FindByName__out, + offsetof(struct iface_ifp_groups, FindByName), + invoke_s_method, + }, + { + "FindByID", /* name */ + iface_ifp_groups_FindByID__in, + iface_ifp_groups_FindByID__out, + offsetof(struct iface_ifp_groups, FindByID), + invoke_u_method, + }, + { + "ListByName", /* name */ + iface_ifp_groups_ListByName__in, + iface_ifp_groups_ListByName__out, + offsetof(struct iface_ifp_groups, ListByName), + invoke_su_method, + }, + { + "ListByDomainAndName", /* name */ + iface_ifp_groups_ListByDomainAndName__in, + iface_ifp_groups_ListByDomainAndName__out, + offsetof(struct iface_ifp_groups, ListByDomainAndName), + invoke_ssu_method, + }, + { NULL, } +}; + +/* interface info for org.freedesktop.sssd.infopipe.Groups */ +const struct sbus_interface_meta iface_ifp_groups_meta = { + "org.freedesktop.sssd.infopipe.Groups", /* name */ + iface_ifp_groups__methods, + NULL, /* no signals */ + NULL, /* no properties */ + sbus_invoke_get_all, /* GetAll invoker */ +}; + /* invokes a handler with a 'ssu' DBus signature */ static int invoke_ssu_method(struct sbus_request *dbus_req, void *function_ptr) { diff --git a/src/responder/ifp/ifp_iface_generated.h b/src/responder/ifp/ifp_iface_generated.h index 609bd40e6..09db24b73 100644 --- a/src/responder/ifp/ifp_iface_generated.h +++ b/src/responder/ifp/ifp_iface_generated.h @@ -73,6 +73,13 @@ #define IFACE_IFP_USERS_USER_GROUPS "groups" #define IFACE_IFP_USERS_USER_EXTRAATTRIBUTES "extraAttributes" +/* constants for org.freedesktop.sssd.infopipe.Groups */ +#define IFACE_IFP_GROUPS "org.freedesktop.sssd.infopipe.Groups" +#define IFACE_IFP_GROUPS_FINDBYNAME "FindByName" +#define IFACE_IFP_GROUPS_FINDBYID "FindByID" +#define IFACE_IFP_GROUPS_LISTBYNAME "ListByName" +#define IFACE_IFP_GROUPS_LISTBYDOMAINANDNAME "ListByDomainAndName" + /* ------------------------------------------------------------------------ * DBus handlers * @@ -217,6 +224,27 @@ struct iface_ifp_users_user { /* finish function for UpdateGroupsList */ int iface_ifp_users_user_UpdateGroupsList_finish(struct sbus_request *req); +/* vtable for org.freedesktop.sssd.infopipe.Groups */ +struct iface_ifp_groups { + struct sbus_vtable vtable; /* derive from sbus_vtable */ + int (*FindByName)(struct sbus_request *req, void *data, const char *arg_name); + int (*FindByID)(struct sbus_request *req, void *data, uint32_t arg_id); + int (*ListByName)(struct sbus_request *req, void *data, const char *arg_name_filter, uint32_t arg_limit); + int (*ListByDomainAndName)(struct sbus_request *req, void *data, const char *arg_domain_name, const char *arg_name_filter, uint32_t arg_limit); +}; + +/* finish function for FindByName */ +int iface_ifp_groups_FindByName_finish(struct sbus_request *req, const char *arg_result); + +/* finish function for FindByID */ +int iface_ifp_groups_FindByID_finish(struct sbus_request *req, const char *arg_result); + +/* finish function for ListByName */ +int iface_ifp_groups_ListByName_finish(struct sbus_request *req, const char *arg_result[], int len_result); + +/* finish function for ListByDomainAndName */ +int iface_ifp_groups_ListByDomainAndName_finish(struct sbus_request *req, const char *arg_result[], int len_result); + /* ------------------------------------------------------------------------ * DBus Interface Metadata * @@ -242,4 +270,7 @@ extern const struct sbus_interface_meta iface_ifp_users_meta; /* interface info for org.freedesktop.sssd.infopipe.Users.User */ extern const struct sbus_interface_meta iface_ifp_users_user_meta; +/* interface info for org.freedesktop.sssd.infopipe.Groups */ +extern const struct sbus_interface_meta iface_ifp_groups_meta; + #endif /* __IFP_IFACE_XML__ */ diff --git a/src/responder/ifp/org.freedesktop.sssd.infopipe.conf b/src/responder/ifp/org.freedesktop.sssd.infopipe.conf index 79160bbcc..916218c8b 100644 --- a/src/responder/ifp/org.freedesktop.sssd.infopipe.conf +++ b/src/responder/ifp/org.freedesktop.sssd.infopipe.conf @@ -32,6 +32,7 @@ + -- cgit