32d98ca5e560cf6c1062a0463be4c350af32bed5Thiemo Wiedemeyer/*
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer Authors:
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens Elkner Jakub Hrozek <jhrozek@redhat.com>
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
521045d36343cd17dd217a81d4b9422ad6ab6a07Christian Maeder Copyright (C) 2013 Red Hat
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer InfoPipe responder: the responder commands
521045d36343cd17dd217a81d4b9422ad6ab6a07Christian Maeder
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer This program is free software; you can redistribute it and/or modify
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer it under the terms of the GNU General Public License as published by
521045d36343cd17dd217a81d4b9422ad6ab6a07Christian Maeder the Free Software Foundation; either version 3 of the License, or
521045d36343cd17dd217a81d4b9422ad6ab6a07Christian Maeder (at your option) any later version.
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
521045d36343cd17dd217a81d4b9422ad6ab6a07Christian Maeder This program is distributed in the hope that it will be useful,
83263d411f611d9902ef4d98c93be6ad9361c833Christian Maeder but WITHOUT ANY WARRANTY; without even the implied warranty of
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66fd8f017efdb8a6c862c3f1856dfaef90865dd5Thiemo Wiedemeyer GNU General Public License for more details.
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer You should have received a copy of the GNU General Public License
d1066b8fb69179973dcab47154858d77e72760a7Thiemo Wiedemeyer along with this program. If not, see <http://www.gnu.org/licenses/>.
b941a1f8b2ef8b4dacf7238f4adc1957afb0e1c4Christian Maeder*/
7809fb14d290d257ed6d46a2dd563227e227fcf3Christian Maeder
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder#include "db/sysdb.h"
eeae57399bf0e5d2bac38097748dfc74e0393528Thiemo Wiedemeyer
0425e5ed787f937a67a33d20c263fa72409bfe73Simon Ulbricht#include "responder/ifp/ifp_private.h"
cb6d5bbb36150e28e40794320773e779e0c25d7bChristian Maeder#include "responder/common/cache_req/cache_req.h"
7809fb14d290d257ed6d46a2dd563227e227fcf3Christian Maeder
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyerstruct ifp_attr_req {
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer const char *name;
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer const char **attrs;
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder int nattrs;
8f5219469b89a15dc6d4c2c30463775975f5841cRazvan Pascanu
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder struct ifp_req *ireq;
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer};
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
c208973c890b8f993297720fd0247bc7481d4304Christian Maederstatic struct tevent_req *
b941a1f8b2ef8b4dacf7238f4adc1957afb0e1c4Christian Maederifp_user_get_attr_send(TALLOC_CTX *mem_ctx, struct resp_ctx *rctx,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct sss_nc_ctx *ncache,
ec25781c1180ea07f66b48c34f93cf5634e9277cChristian Maeder enum sss_dp_acct_type search_type,
d923f0b3f5f075f1d9bfc3018d0e06b561f58deeMihai Codescu const char *inp, const char **attrs);
1e3aca4178372af672efb237d16087c603fe5564Christian Maederstatic errno_t ifp_user_get_attr_recv(TALLOC_CTX *mem_ctx,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct tevent_req *req,
b941a1f8b2ef8b4dacf7238f4adc1957afb0e1c4Christian Maeder struct ldb_result **_res,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct sss_domain_info **_domain);
28ca54b0d63d1d26a991711c8c7e85c474994715Christian Maeder
28ca54b0d63d1d26a991711c8c7e85c474994715Christian Maederstatic void ifp_user_get_attr_process(struct tevent_req *req);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
71654489020a03cf6ce9f2947f3da26a996f9c32Razvan Pascanustatic errno_t
28ca54b0d63d1d26a991711c8c7e85c474994715Christian Maederifp_user_get_attr_handle_reply(struct sss_domain_info *domain,
28ca54b0d63d1d26a991711c8c7e85c474994715Christian Maeder struct ifp_req *ireq,
71654489020a03cf6ce9f2947f3da26a996f9c32Razvan Pascanu const char **attrs,
28cbeb7eb61216d3b5a27dca176333d1ff8d3357Mihai Codescu struct ldb_result *res);
28cbeb7eb61216d3b5a27dca176333d1ff8d3357Mihai Codescustatic errno_t
15a50ae940b17c65d2b3c68918a26de29e565370Thiemo Wiedemeyerifp_user_get_attr_unpack_msg(struct ifp_attr_req *attr_req);
15a50ae940b17c65d2b3c68918a26de29e565370Thiemo Wiedemeyer
21424a364eb3ce5523298579d57155f35342d3ccChristian Maederint ifp_user_get_attr(struct sbus_request *dbus_req, void *data)
21424a364eb3ce5523298579d57155f35342d3ccChristian Maeder{
21424a364eb3ce5523298579d57155f35342d3ccChristian Maeder errno_t ret;
15a50ae940b17c65d2b3c68918a26de29e565370Thiemo Wiedemeyer struct ifp_req *ireq;
15a50ae940b17c65d2b3c68918a26de29e565370Thiemo Wiedemeyer struct ifp_ctx *ifp_ctx;
39a2520d13a7d43f0c0fa71b94255c3f7c500005Christian Maeder struct ifp_attr_req *attr_req;
39a2520d13a7d43f0c0fa71b94255c3f7c500005Christian Maeder struct tevent_req *req;
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder
39a2520d13a7d43f0c0fa71b94255c3f7c500005Christian Maeder DEBUG(SSSDBG_IMPORTANT_INFO, "GetUserAttr is deprecated, please consider "
39a2520d13a7d43f0c0fa71b94255c3f7c500005Christian Maeder "switching to org.freedesktop.sssd.infopipe.Users.User interface\n");
39a2520d13a7d43f0c0fa71b94255c3f7c500005Christian Maeder
15a50ae940b17c65d2b3c68918a26de29e565370Thiemo Wiedemeyer ifp_ctx = talloc_get_type(data, struct ifp_ctx);
15a50ae940b17c65d2b3c68918a26de29e565370Thiemo Wiedemeyer if (ifp_ctx == NULL) {
15a50ae940b17c65d2b3c68918a26de29e565370Thiemo Wiedemeyer DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
15a50ae940b17c65d2b3c68918a26de29e565370Thiemo Wiedemeyer return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
1ac36418f204bbe56f4cd951a979180721758999Christian Maeder }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer ret = ifp_req_create(dbus_req, ifp_ctx, &ireq);
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer if (ret != EOK) {
21424a364eb3ce5523298579d57155f35342d3ccChristian Maeder return ifp_req_create_handle_failure(dbus_req, ret);
21424a364eb3ce5523298579d57155f35342d3ccChristian Maeder }
21424a364eb3ce5523298579d57155f35342d3ccChristian Maeder
503d96bb6e0daa80f464e45d1b17e57909a2f428Christian Maeder attr_req = talloc_zero(ireq, struct ifp_attr_req);
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer if (attr_req == NULL) {
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer return sbus_request_finish(dbus_req, NULL);
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer }
503d96bb6e0daa80f464e45d1b17e57909a2f428Christian Maeder attr_req->ireq = ireq;
503d96bb6e0daa80f464e45d1b17e57909a2f428Christian Maeder
503d96bb6e0daa80f464e45d1b17e57909a2f428Christian Maeder ret = ifp_user_get_attr_unpack_msg(attr_req);
503d96bb6e0daa80f464e45d1b17e57909a2f428Christian Maeder if (ret != EOK) {
503d96bb6e0daa80f464e45d1b17e57909a2f428Christian Maeder return ret; /* internal error */
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer }
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder DEBUG(SSSDBG_FUNC_DATA,
5c9d9c85e0aac314175d6804a994993aabbd1a89Simon Ulbricht "Looking up attributes of user [%s] on behalf of %"PRIi64"\n",
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer attr_req->name, ireq->dbus_req->client);
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer
fb5b958b07a002f7f6daa0ac032976979c63b7c3Christian Maeder req = ifp_user_get_attr_send(ireq, ifp_ctx->rctx,
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder ifp_ctx->rctx->ncache, SSS_DP_USER,
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder attr_req->name, attr_req->attrs);
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder if (req == NULL) {
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer return sbus_request_finish(dbus_req, NULL);
fa1bf658051ac503f27ff1b59edb093398eed6edThiemo Wiedemeyer }
fb5b958b07a002f7f6daa0ac032976979c63b7c3Christian Maeder tevent_req_set_callback(req, ifp_user_get_attr_process, attr_req);
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder return EOK;
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder}
fa1bf658051ac503f27ff1b59edb093398eed6edThiemo Wiedemeyer
8e7df4df486c21d40207c537b7d9a82b17e3916cThiemo Wiedemeyerstatic errno_t
fb5b958b07a002f7f6daa0ac032976979c63b7c3Christian Maederifp_user_get_attr_unpack_msg(struct ifp_attr_req *attr_req)
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder{
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder bool parsed;
8e7df4df486c21d40207c537b7d9a82b17e3916cThiemo Wiedemeyer char **attrs;
fb5b958b07a002f7f6daa0ac032976979c63b7c3Christian Maeder int nattrs;
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder int i, ai;
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder const char **whitelist = attr_req->ireq->ifp_ctx->user_whitelist;
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder parsed = sbus_request_parse_or_finish(attr_req->ireq->dbus_req,
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer DBUS_TYPE_STRING, &attr_req->name,
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
fb5b958b07a002f7f6daa0ac032976979c63b7c3Christian Maeder &attrs, &nattrs,
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer DBUS_TYPE_INVALID);
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer if (parsed == false) {
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer DEBUG(SSSDBG_OP_FAILURE, "Could not parse arguments\n");
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer return ERR_SBUS_REQUEST_HANDLED;
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder }
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder /* Copy the attributes to maintain memory hierarchy with talloc */
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer attr_req->attrs = talloc_zero_array(attr_req, const char *, nattrs+1);
15a50ae940b17c65d2b3c68918a26de29e565370Thiemo Wiedemeyer if (attr_req->attrs == NULL) {
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer return ENOMEM;
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer }
1ac36418f204bbe56f4cd951a979180721758999Christian Maeder
1ac36418f204bbe56f4cd951a979180721758999Christian Maeder ai = 0;
1ac36418f204bbe56f4cd951a979180721758999Christian Maeder for (i = 0; i < nattrs; i++) {
503d96bb6e0daa80f464e45d1b17e57909a2f428Christian Maeder if (ifp_attr_allowed(whitelist, attrs[i]) == false) {
7ae38566aaf40710cd83ffa3ba25655c4ad22741Thiemo Wiedemeyer DEBUG(SSSDBG_MINOR_FAILURE,
6b26240dca29e026900a83d51c75ca230a072a16Thiemo Wiedemeyer "Attribute %s not present in the whitelist, skipping\n",
66fd8f017efdb8a6c862c3f1856dfaef90865dd5Thiemo Wiedemeyer attrs[i]);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder continue;
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder }
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer attr_req->attrs[ai] = talloc_strdup(attr_req->attrs, attrs[i]);
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer if (attr_req->attrs[ai] == NULL) {
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder return ENOMEM;
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder }
a79266feb130561fa1a95ae0429d0574f625f6ceChristian Maeder ai++;
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer }
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder return EOK;
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer}
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maederstatic void ifp_user_get_attr_process(struct tevent_req *req)
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder{
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder struct ifp_attr_req *attr_req;
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder errno_t ret;
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer struct ldb_result *res = NULL;
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder struct sss_domain_info *dom = NULL;
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder attr_req = tevent_req_callback_data(req, struct ifp_attr_req);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer ret = ifp_user_get_attr_recv(attr_req, req, &res, &dom);
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer talloc_zfree(req);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder if (ret == ENOENT) {
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer sbus_request_fail_and_finish(attr_req->ireq->dbus_req,
6b26240dca29e026900a83d51c75ca230a072a16Thiemo Wiedemeyer sbus_error_new(attr_req->ireq->dbus_req,
109b67ffce2bad83667e2f4a319d2d7f380f91afThiemo Wiedemeyer DBUS_ERROR_FAILED,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder "No such user\n"));
da955132262baab309a50fdffe228c9efe68251dCui Jian return;
d1066b8fb69179973dcab47154858d77e72760a7Thiemo Wiedemeyer } else if (ret != EOK) {
d1066b8fb69179973dcab47154858d77e72760a7Thiemo Wiedemeyer sbus_request_fail_and_finish(attr_req->ireq->dbus_req,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer sbus_error_new(attr_req->ireq->dbus_req,
8f5219469b89a15dc6d4c2c30463775975f5841cRazvan Pascanu DBUS_ERROR_FAILED,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder "Failed to read user attribute\n"));
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer return;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ifp_user_get_attr_handle_reply(dom, attr_req->ireq,
6b26240dca29e026900a83d51c75ca230a072a16Thiemo Wiedemeyer attr_req->attrs, res);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (ret != EOK) {
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder sbus_request_fail_and_finish(attr_req->ireq->dbus_req,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer sbus_error_new(attr_req->ireq->dbus_req,
6b26240dca29e026900a83d51c75ca230a072a16Thiemo Wiedemeyer DBUS_ERROR_FAILED,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer "Failed to build a reply\n"));
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder return;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
d1066b8fb69179973dcab47154858d77e72760a7Thiemo Wiedemeyer}
d1066b8fb69179973dcab47154858d77e72760a7Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyerstatic errno_t
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maederifp_user_get_attr_replace_space(TALLOC_CTX *mem_ctx,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct ldb_message_element *el,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer const char sub)
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer{
c745add71930134bc085a544783213179bd3e734Thiemo Wiedemeyer int i;
4d3b50fc78a0c99ff2914fb23f3c7fba6e38d790Thiemo Wiedemeyer
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder for (i = 0; i < el->num_values; i++) {
40673b95e958603e990266baef936c28cdbb6e5eChristian Maeder el->values[i].data = (uint8_t *) sss_replace_space(mem_ctx,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder (const char *) el->values[i].data,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder sub);
40673b95e958603e990266baef936c28cdbb6e5eChristian Maeder if (el->values[i].data == NULL) {
71654489020a03cf6ce9f2947f3da26a996f9c32Razvan Pascanu DEBUG(SSSDBG_CRIT_FAILURE, "sss_replace_space failed, skipping\n");
4d3b50fc78a0c99ff2914fb23f3c7fba6e38d790Thiemo Wiedemeyer return ENOMEM;
6b26240dca29e026900a83d51c75ca230a072a16Thiemo Wiedemeyer }
b021998bf955c87c7cdcc69f0667dc2880b3ce1fThiemo Wiedemeyer }
71654489020a03cf6ce9f2947f3da26a996f9c32Razvan Pascanu
c69b7fb3c049796f139641d0f7d6b78a9556bcd1Christian Maeder return EOK;
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder}
a4e6fb26100f53e3b1e9f5b97c2e0a0c129294e5Christian Maeder
71654489020a03cf6ce9f2947f3da26a996f9c32Razvan Pascanustatic errno_t
44c1fff98bd6c54db237bef5030657d3f47058a5Thiemo Wiedemeyerifp_user_get_attr_handle_reply(struct sss_domain_info *domain,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder struct ifp_req *ireq,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder const char **attrs,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder struct ldb_result *res)
28ca54b0d63d1d26a991711c8c7e85c474994715Christian Maeder{
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder errno_t ret;
28ca54b0d63d1d26a991711c8c7e85c474994715Christian Maeder dbus_bool_t dbret;
28ca54b0d63d1d26a991711c8c7e85c474994715Christian Maeder DBusMessage *reply;
a4e6fb26100f53e3b1e9f5b97c2e0a0c129294e5Christian Maeder DBusMessageIter iter;
71654489020a03cf6ce9f2947f3da26a996f9c32Razvan Pascanu DBusMessageIter iter_dict;
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder struct ldb_message_element *el;
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder int ai;
aa21e7aa42fef563dea0cc77edbde76f66cdbe88Thiemo Wiedemeyer
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer /* Construct a reply */
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder reply = dbus_message_new_method_return(ireq->dbus_req->message);
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer if (!reply) {
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder return sbus_request_finish(ireq->dbus_req, NULL);
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer }
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder
6c59ae2c44a1fe22ef1712a57afe129e9dbd3368Thiemo Wiedemeyer dbus_message_iter_init_append(reply, &iter);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder
7809fb14d290d257ed6d46a2dd563227e227fcf3Christian Maeder dbret = dbus_message_iter_open_container(
92487d2ec0c4f9fa81e0213311e214861d232f42Thiemo Wiedemeyer &iter, DBUS_TYPE_ARRAY,
239991d3955da0cfb760af4d506069446e1676b7Christian Maeder DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder DBUS_TYPE_STRING_AS_STRING
0a41b683491798147362fffb0bd3da01178ee708Simon Ulbricht DBUS_TYPE_VARIANT_AS_STRING
17da1f3afd29e72f9dda75c094521e9972fae540Till Mossakowski DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder &iter_dict);
7809fb14d290d257ed6d46a2dd563227e227fcf3Christian Maeder if (!dbret) {
28ca54b0d63d1d26a991711c8c7e85c474994715Christian Maeder return sbus_request_finish(ireq->dbus_req, NULL);
28ca54b0d63d1d26a991711c8c7e85c474994715Christian Maeder }
28ca54b0d63d1d26a991711c8c7e85c474994715Christian Maeder
28ca54b0d63d1d26a991711c8c7e85c474994715Christian Maeder if (res->count > 0) {
28ca54b0d63d1d26a991711c8c7e85c474994715Christian Maeder for (ai = 0; attrs[ai]; ai++) {
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder el = sss_view_ldb_msg_find_element(domain, res->msgs[0], attrs[ai]);
b941a1f8b2ef8b4dacf7238f4adc1957afb0e1c4Christian Maeder if (el == NULL || el->num_values == 0) {
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder DEBUG(SSSDBG_MINOR_FAILURE,
51dc99030b1cce6a795a6d9e3d430264d5949c99Christian Maeder "Attribute %s not present or has no values\n",
51dc99030b1cce6a795a6d9e3d430264d5949c99Christian Maeder attrs[ai]);
b941a1f8b2ef8b4dacf7238f4adc1957afb0e1c4Christian Maeder continue;
b941a1f8b2ef8b4dacf7238f4adc1957afb0e1c4Christian Maeder }
d923f0b3f5f075f1d9bfc3018d0e06b561f58deeMihai Codescu
d923f0b3f5f075f1d9bfc3018d0e06b561f58deeMihai Codescu /* Normalize white space in user names */
d923f0b3f5f075f1d9bfc3018d0e06b561f58deeMihai Codescu if (ireq->ifp_ctx->rctx->override_space != '\0' &&
d923f0b3f5f075f1d9bfc3018d0e06b561f58deeMihai Codescu strcmp(attrs[ai], SYSDB_NAME) == 0) {
d923f0b3f5f075f1d9bfc3018d0e06b561f58deeMihai Codescu ret = ifp_user_get_attr_replace_space(ireq, el,
d923f0b3f5f075f1d9bfc3018d0e06b561f58deeMihai Codescu ireq->ifp_ctx->rctx->override_space);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder if (ret != EOK) {
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder DEBUG(SSSDBG_MINOR_FAILURE, "Cannot normalize %s\n",
71654489020a03cf6ce9f2947f3da26a996f9c32Razvan Pascanu attrs[ai]);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder continue;
8f5219469b89a15dc6d4c2c30463775975f5841cRazvan Pascanu }
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder }
71654489020a03cf6ce9f2947f3da26a996f9c32Razvan Pascanu
71654489020a03cf6ce9f2947f3da26a996f9c32Razvan Pascanu ret = ifp_add_ldb_el_to_dict(&iter_dict, el);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (ret != EOK) {
6b26240dca29e026900a83d51c75ca230a072a16Thiemo Wiedemeyer DEBUG(SSSDBG_MINOR_FAILURE,
66fd8f017efdb8a6c862c3f1856dfaef90865dd5Thiemo Wiedemeyer "Cannot add attribute %s to message\n",
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder attrs[ai]);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder continue;
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer }
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder }
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder }
da955132262baab309a50fdffe228c9efe68251dCui Jian
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer dbret = dbus_message_iter_close_container(&iter, &iter_dict);
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder if (!dbret) {
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder return sbus_request_finish(ireq->dbus_req, NULL);
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer return sbus_request_finish(ireq->dbus_req, reply);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder}
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyerstatic void ifp_user_get_groups_process(struct tevent_req *req);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyerstatic errno_t ifp_user_get_groups_reply(struct sss_domain_info *domain,
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer struct ifp_req *ireq,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder struct ldb_result *res);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
521045d36343cd17dd217a81d4b9422ad6ab6a07Christian Maederint ifp_user_get_groups(struct sbus_request *dbus_req,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer void *data, const char *arg_user)
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder{
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder struct ifp_req *ireq;
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer struct ifp_ctx *ifp_ctx;
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder struct ifp_attr_req *group_req;
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder struct tevent_req *req;
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder errno_t ret;
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder ifp_ctx = talloc_get_type(data, struct ifp_ctx);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer if (ifp_ctx == NULL) {
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer }
38122cbf09ad3dcc31a826cc4093f630515a5cfcChristian Maeder
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ifp_req_create(dbus_req, ifp_ctx, &ireq);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer if (ret != EOK) {
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer return ifp_req_create_handle_failure(dbus_req, ret);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder }
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder group_req = talloc_zero(ireq, struct ifp_attr_req);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer if (group_req == NULL) {
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder return sbus_request_finish(dbus_req, NULL);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer }
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer group_req->ireq = ireq;
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer group_req->name = arg_user;
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer group_req->attrs = talloc_zero_array(group_req, const char *, 2);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer if (group_req->attrs == NULL) {
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer return sbus_request_finish(dbus_req, NULL);
239991d3955da0cfb760af4d506069446e1676b7Christian Maeder }
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon Ulbricht
cb6d5bbb36150e28e40794320773e779e0c25d7bChristian Maeder group_req->attrs[0] = talloc_strdup(group_req->attrs, SYSDB_MEMBEROF);
239991d3955da0cfb760af4d506069446e1676b7Christian Maeder if (group_req->attrs[0] == NULL) {
239991d3955da0cfb760af4d506069446e1676b7Christian Maeder return sbus_request_finish(dbus_req, NULL);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer }
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer DEBUG(SSSDBG_FUNC_DATA,
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer "Looking up groups of user [%s] on behalf of %"PRIi64"\n",
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer group_req->name, group_req->ireq->dbus_req->client);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer req = ifp_user_get_attr_send(ireq, ifp_ctx->rctx,
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer ifp_ctx->rctx->ncache, SSS_DP_INITGROUPS,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder group_req->name, group_req->attrs);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer if (req == NULL) {
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder return sbus_request_finish(dbus_req, NULL);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer }
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer tevent_req_set_callback(req, ifp_user_get_groups_process, group_req);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder return EOK;
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder}
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maederstatic void ifp_user_get_groups_process(struct tevent_req *req)
00962bbc8b21c9a4af3b08983bdf82591cb8067bSimon Ulbricht{
00962bbc8b21c9a4af3b08983bdf82591cb8067bSimon Ulbricht struct ifp_attr_req *group_req;
00962bbc8b21c9a4af3b08983bdf82591cb8067bSimon Ulbricht errno_t ret;
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer struct ldb_result *res;
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder struct sss_domain_info *dom;
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer group_req = tevent_req_callback_data(req, struct ifp_attr_req);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ifp_user_get_attr_recv(group_req, req, &res, &dom);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer talloc_zfree(req);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer if (ret == ENOENT) {
66fd8f017efdb8a6c862c3f1856dfaef90865dd5Thiemo Wiedemeyer sbus_request_fail_and_finish(group_req->ireq->dbus_req,
66fd8f017efdb8a6c862c3f1856dfaef90865dd5Thiemo Wiedemeyer sbus_error_new(group_req->ireq->dbus_req,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder DBUS_ERROR_FAILED,
1ac36418f204bbe56f4cd951a979180721758999Christian Maeder "No such user\n"));
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder return;
1ac36418f204bbe56f4cd951a979180721758999Christian Maeder } else if (ret != EOK) {
1ac36418f204bbe56f4cd951a979180721758999Christian Maeder sbus_request_fail_and_finish(group_req->ireq->dbus_req,
1ac36418f204bbe56f4cd951a979180721758999Christian Maeder sbus_error_new(group_req->ireq->dbus_req,
1ac36418f204bbe56f4cd951a979180721758999Christian Maeder DBUS_ERROR_FAILED,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder "Failed to read attribute\n"));
d7aa4e1cbe00f7f3add4da911673b3b176b140c3Thiemo Wiedemeyer return;
1ac36418f204bbe56f4cd951a979180721758999Christian Maeder }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer ret = ifp_user_get_groups_reply(dom, group_req->ireq, res);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder if (ret != EOK) {
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder sbus_request_fail_and_finish(group_req->ireq->dbus_req,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer sbus_error_new(group_req->ireq->dbus_req,
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer DBUS_ERROR_FAILED,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder "Failed to build a reply\n"));
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder return;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer }
83263d411f611d9902ef4d98c93be6ad9361c833Christian Maeder}
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maederstatic errno_t
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyerifp_user_get_groups_reply(struct sss_domain_info *domain,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder struct ifp_req *ireq,
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer struct ldb_result *res)
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer{
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder int i, num;
1937dccb04b363364f7a7de17fdaae1d70583af9Christian Maeder const char *name;
1937dccb04b363364f7a7de17fdaae1d70583af9Christian Maeder const char **groupnames;
1937dccb04b363364f7a7de17fdaae1d70583af9Christian Maeder char *out_name;
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder /* one less, the first one is the user entry */
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder num = res->count - 1;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer groupnames = talloc_zero_array(ireq, const char *, num);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer if (groupnames == NULL) {
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder return sbus_request_finish(ireq->dbus_req, NULL);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder }
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer for (i = 0; i < num; i++) {
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder name = sss_view_ldb_msg_find_attr_as_string(domain,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder res->msgs[i + 1],
1ac36418f204bbe56f4cd951a979180721758999Christian Maeder SYSDB_NAME, NULL);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer if (name == NULL) {
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder DEBUG(SSSDBG_MINOR_FAILURE, "Skipping a group with no name\n");
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer continue;
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder }
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder
1e3aca4178372af672efb237d16087c603fe5564Christian Maeder out_name = sss_output_name(ireq, name, domain->case_preserve,
239991d3955da0cfb760af4d506069446e1676b7Christian Maeder ireq->ifp_ctx->rctx->override_space);
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder if (out_name == NULL) {
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder continue;
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder }
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder
239991d3955da0cfb760af4d506069446e1676b7Christian Maeder if (domain->fqnames) {
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder groupnames[i] = sss_tc_fqname(groupnames, domain->names,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder domain, out_name);
239991d3955da0cfb760af4d506069446e1676b7Christian Maeder if (out_name == NULL) {
239991d3955da0cfb760af4d506069446e1676b7Christian Maeder DEBUG(SSSDBG_CRIT_FAILURE, "sss_tc_fqname failed\n");
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder continue;
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder }
cb6d5bbb36150e28e40794320773e779e0c25d7bChristian Maeder } else {
cb6d5bbb36150e28e40794320773e779e0c25d7bChristian Maeder groupnames[i] = talloc_steal(groupnames, out_name);
cb6d5bbb36150e28e40794320773e779e0c25d7bChristian Maeder }
cb6d5bbb36150e28e40794320773e779e0c25d7bChristian Maeder
239991d3955da0cfb760af4d506069446e1676b7Christian Maeder DEBUG(SSSDBG_TRACE_FUNC, "Adding group %s\n", groupnames[i]);
239991d3955da0cfb760af4d506069446e1676b7Christian Maeder }
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder return iface_ifp_GetUserGroups_finish(ireq->dbus_req, groupnames, num);
6c83d2b44b0451d099f97c57274684f1a92fe850Thiemo Wiedemeyer}
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder
9a9860760c6f30558e5e60049692b6fc63904590Markus Grossstruct ifp_user_get_attr_state {
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer const char *inp;
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer const char **attrs;
1ac36418f204bbe56f4cd951a979180721758999Christian Maeder struct ldb_result *res;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
521045d36343cd17dd217a81d4b9422ad6ab6a07Christian Maeder enum sss_dp_acct_type search_type;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer char *inp_name;
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer char *domname;
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer struct sss_domain_info *dom;
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder bool check_next;
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder bool check_provider;
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer struct resp_ctx *rctx;
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer struct sss_nc_ctx *ncache;
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer};
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyerstatic void ifp_user_get_attr_lookup(struct tevent_req *subreq);
4f8a6dee8333cac3769f6952d64965867e017f4dChristian Maederstatic void ifp_user_get_attr_done(struct tevent_req *subreq);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder
fe1771bb2ad4ad758a5654b277c1bb145d46701cTill Mossakowskistatic struct tevent_req *
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maederifp_user_get_attr_send(TALLOC_CTX *mem_ctx, struct resp_ctx *rctx,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder struct sss_nc_ctx *ncache,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer enum sss_dp_acct_type search_type,
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer const char *inp, const char **attrs)
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer{
4f8a6dee8333cac3769f6952d64965867e017f4dChristian Maeder errno_t ret;
4f8a6dee8333cac3769f6952d64965867e017f4dChristian Maeder struct tevent_req *req;
4f8a6dee8333cac3769f6952d64965867e017f4dChristian Maeder struct tevent_req *subreq;
8f5219469b89a15dc6d4c2c30463775975f5841cRazvan Pascanu struct ifp_user_get_attr_state *state;
8f5219469b89a15dc6d4c2c30463775975f5841cRazvan Pascanu
8f5219469b89a15dc6d4c2c30463775975f5841cRazvan Pascanu req = tevent_req_create(mem_ctx, &state, struct ifp_user_get_attr_state);
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder if (req == NULL) {
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder return NULL;
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder }
8f5219469b89a15dc6d4c2c30463775975f5841cRazvan Pascanu state->inp = inp;
8f5219469b89a15dc6d4c2c30463775975f5841cRazvan Pascanu state->attrs = attrs;
8f5219469b89a15dc6d4c2c30463775975f5841cRazvan Pascanu state->rctx = rctx;
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer state->ncache = ncache;
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer state->search_type = search_type;
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer subreq = sss_parse_inp_send(req, rctx, inp);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer if (subreq == NULL) {
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer ret = ENOMEM;
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder goto done;
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer }
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer tevent_req_set_callback(subreq, ifp_user_get_attr_lookup, req);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer ret = EOK;
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyerdone:
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer if (ret != EOK) {
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer tevent_req_error(req, ret);
8f5219469b89a15dc6d4c2c30463775975f5841cRazvan Pascanu }
8f5219469b89a15dc6d4c2c30463775975f5841cRazvan Pascanu return req;
8f5219469b89a15dc6d4c2c30463775975f5841cRazvan Pascanu}
28ca54b0d63d1d26a991711c8c7e85c474994715Christian Maeder
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyerstatic void
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyerifp_user_get_attr_lookup(struct tevent_req *subreq)
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer{
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer struct ifp_user_get_attr_state *state = NULL;
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer struct tevent_req *req = NULL;
struct cache_req_data *data;
errno_t ret;
req = tevent_req_callback_data(subreq, struct tevent_req);
state = tevent_req_data(req, struct ifp_user_get_attr_state);
ret = sss_parse_inp_recv(subreq, state,
&state->inp_name, &state->domname);
talloc_zfree(subreq);
if (ret != EOK) {
tevent_req_error(req, ret);
return;
}
switch (state->search_type) {
case SSS_DP_USER:
data = cache_req_data_name(state, CACHE_REQ_USER_BY_NAME,
state->inp_name);
break;
case SSS_DP_INITGROUPS:
data = cache_req_data_name(state, CACHE_REQ_INITGROUPS,
state->inp_name);
break;
default:
DEBUG(SSSDBG_CRIT_FAILURE, "Unsupported search type [%d]!\n",
state->search_type);
tevent_req_error(req, ERR_INTERNAL);
return;
}
if (data == NULL) {
tevent_req_error(req, ENOMEM);
return;
}
subreq = cache_req_send(state, state->rctx->ev, state->rctx,
state->ncache, 0, state->domname, data);
if (subreq == NULL) {
tevent_req_error(req, ENOMEM);
return;
}
tevent_req_set_callback(subreq, ifp_user_get_attr_done, req);
}
static void ifp_user_get_attr_done(struct tevent_req *subreq)
{
struct ifp_user_get_attr_state *state = NULL;
struct tevent_req *req = NULL;
errno_t ret;
char *fqdn;
req = tevent_req_callback_data(subreq, struct tevent_req);
state = tevent_req_data(req, struct ifp_user_get_attr_state);
ret = cache_req_recv(state, subreq, &state->res, &state->dom, NULL);
talloc_zfree(subreq);
if (ret != EOK) {
tevent_req_error(req, ret);
return;
}
fqdn = sss_create_internal_fqname(state, state->inp_name,
state->dom->name);
if (fqdn == NULL) {
tevent_req_error(req, ENOMEM);
return;
}
if (state->search_type == SSS_DP_USER) {
/* throw away the result and perform attr search */
talloc_zfree(state->res);
ret = sysdb_get_user_attr_with_views(state, state->dom, fqdn,
state->attrs, &state->res);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_get_user_attr_with_views() "
"failed [%d]: %s\n", ret, sss_strerror(ret));
tevent_req_error(req, ret);
return;
} else if (state->res->count == 0) {
tevent_req_error(req, ENOENT);
return;
} else if (state->res->count != 1) {
DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_get_user_attr_with_views() "
"returned more than one result!\n");
tevent_req_error(req, ENOENT);
return;
}
}
ret = ifp_ldb_el_output_name(state->rctx, state->res->msgs[0],
SYSDB_NAME, state->dom);
if (ret != EOK) {
tevent_req_error(req, ret);
return;
}
ret = ifp_ldb_el_output_name(state->rctx, state->res->msgs[0],
SYSDB_NAME_ALIAS, state->dom);
if (ret != EOK) {
tevent_req_error(req, ret);
return;
}
tevent_req_done(req);
}
static errno_t
ifp_user_get_attr_recv(TALLOC_CTX *mem_ctx,
struct tevent_req *req,
struct ldb_result **_res,
struct sss_domain_info **_domain)
{
struct ifp_user_get_attr_state *state = tevent_req_data(req,
struct ifp_user_get_attr_state);
TEVENT_REQ_RETURN_ON_ERROR(req);
if (state->res == NULL) {
/* Did the request end with success but with no data? */
return ENOENT;
}
if (_res) {
*_res = talloc_steal(mem_ctx, state->res);
}
if (_domain) {
*_domain = state->dom;
}
return EOK;
}
struct cli_protocol_version *register_cli_protocol_version(void)
{
static struct cli_protocol_version ssh_cli_protocol_version[] = {
{0, NULL, NULL}
};
return ssh_cli_protocol_version;
}
/* 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)
{
struct ifp_ctx *ifp_ctx = talloc_get_type(data, struct ifp_ctx);
static const char *pong = "PONG";
const char *request;
DBusError dberr;
errno_t ret;
struct ifp_req *ifp_req;
if (ifp_ctx == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
}
ret = ifp_req_create(dbus_req, ifp_ctx, &ifp_req);
if (ret != EOK) {
return ifp_req_create_handle_failure(dbus_req, ret);
}
if (!sbus_request_parse_or_finish(dbus_req,
DBUS_TYPE_STRING, &request,
DBUS_TYPE_INVALID)) {
return EOK; /* handled */
}
DEBUG(SSSDBG_CONF_SETTINGS, "Got request for [%s]\n", request);
if (strcasecmp(request, "ping") != 0) {
dbus_error_init(&dberr);
dbus_set_error_const(&dberr,
DBUS_ERROR_INVALID_ARGS,
"Ping() only accepts ping as a param\n");
return sbus_request_fail_and_finish(dbus_req, &dberr);
}
return sbus_request_return_and_finish(dbus_req,
DBUS_TYPE_STRING, &pong,
DBUS_TYPE_INVALID);
}