e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens Elkner Jakub Hrozek <jhrozek@redhat.com>
521045d36343cd17dd217a81d4b9422ad6ab6a07Christian Maeder Copyright (C) 2013 Red Hat
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer InfoPipe responder: the responder commands
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.
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 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/>.
cb6d5bbb36150e28e40794320773e779e0c25d7bChristian Maeder#include "responder/common/cache_req/cache_req.h"
b941a1f8b2ef8b4dacf7238f4adc1957afb0e1c4Christian Maederifp_user_get_attr_send(TALLOC_CTX *mem_ctx, struct resp_ctx *rctx,
1e3aca4178372af672efb237d16087c603fe5564Christian Maederstatic errno_t ifp_user_get_attr_recv(TALLOC_CTX *mem_ctx,
28ca54b0d63d1d26a991711c8c7e85c474994715Christian Maederstatic void ifp_user_get_attr_process(struct tevent_req *req);
28ca54b0d63d1d26a991711c8c7e85c474994715Christian Maederifp_user_get_attr_handle_reply(struct sss_domain_info *domain,
71654489020a03cf6ce9f2947f3da26a996f9c32Razvan Pascanu const char **attrs,
15a50ae940b17c65d2b3c68918a26de29e565370Thiemo Wiedemeyerifp_user_get_attr_unpack_msg(struct ifp_attr_req *attr_req);
21424a364eb3ce5523298579d57155f35342d3ccChristian Maederint ifp_user_get_attr(struct sbus_request *dbus_req, void *data)
39a2520d13a7d43f0c0fa71b94255c3f7c500005Christian Maeder DEBUG(SSSDBG_IMPORTANT_INFO, "GetUserAttr is deprecated, please consider "
39a2520d13a7d43f0c0fa71b94255c3f7c500005Christian Maeder "switching to org.freedesktop.sssd.infopipe.Users.User interface\n");
15a50ae940b17c65d2b3c68918a26de29e565370Thiemo Wiedemeyer ifp_ctx = talloc_get_type(data, struct ifp_ctx);
15a50ae940b17c65d2b3c68918a26de29e565370Thiemo Wiedemeyer DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
15a50ae940b17c65d2b3c68918a26de29e565370Thiemo Wiedemeyer return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer ret = ifp_req_create(dbus_req, ifp_ctx, &ireq);
21424a364eb3ce5523298579d57155f35342d3ccChristian Maeder return ifp_req_create_handle_failure(dbus_req, ret);
503d96bb6e0daa80f464e45d1b17e57909a2f428Christian Maeder attr_req = talloc_zero(ireq, struct ifp_attr_req);
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer return sbus_request_finish(dbus_req, NULL);
503d96bb6e0daa80f464e45d1b17e57909a2f428Christian Maeder ret = ifp_user_get_attr_unpack_msg(attr_req);
5c9d9c85e0aac314175d6804a994993aabbd1a89Simon Ulbricht "Looking up attributes of user [%s] on behalf of %"PRIi64"\n",
fb5b958b07a002f7f6daa0ac032976979c63b7c3Christian Maeder req = ifp_user_get_attr_send(ireq, ifp_ctx->rctx,
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer return sbus_request_finish(dbus_req, NULL);
fb5b958b07a002f7f6daa0ac032976979c63b7c3Christian Maeder tevent_req_set_callback(req, ifp_user_get_attr_process, attr_req);
fb5b958b07a002f7f6daa0ac032976979c63b7c3Christian Maederifp_user_get_attr_unpack_msg(struct ifp_attr_req *attr_req)
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder const char **whitelist = attr_req->ireq->ifp_ctx->user_whitelist;
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder parsed = sbus_request_parse_or_finish(attr_req->ireq->dbus_req,
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer if (parsed == false) {
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer DEBUG(SSSDBG_OP_FAILURE, "Could not parse arguments\n");
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);
1ac36418f204bbe56f4cd951a979180721758999Christian Maeder for (i = 0; i < nattrs; i++) {
503d96bb6e0daa80f464e45d1b17e57909a2f428Christian Maeder if (ifp_attr_allowed(whitelist, attrs[i]) == false) {
6b26240dca29e026900a83d51c75ca230a072a16Thiemo Wiedemeyer "Attribute %s not present in the whitelist, skipping\n",
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer attr_req->attrs[ai] = talloc_strdup(attr_req->attrs, attrs[i]);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maederstatic void ifp_user_get_attr_process(struct tevent_req *req)
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder attr_req = tevent_req_callback_data(req, struct ifp_attr_req);
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer ret = ifp_user_get_attr_recv(attr_req, req, &res, &dom);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer sbus_request_fail_and_finish(attr_req->ireq->dbus_req,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder "No such user\n"));
d1066b8fb69179973dcab47154858d77e72760a7Thiemo Wiedemeyer sbus_request_fail_and_finish(attr_req->ireq->dbus_req,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder "Failed to read user attribute\n"));
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ifp_user_get_attr_handle_reply(dom, attr_req->ireq,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder sbus_request_fail_and_finish(attr_req->ireq->dbus_req,
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer "Failed to build a reply\n"));
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maederifp_user_get_attr_replace_space(TALLOC_CTX *mem_ctx,
40673b95e958603e990266baef936c28cdbb6e5eChristian Maeder el->values[i].data = (uint8_t *) sss_replace_space(mem_ctx,
71654489020a03cf6ce9f2947f3da26a996f9c32Razvan Pascanu DEBUG(SSSDBG_CRIT_FAILURE, "sss_replace_space failed, skipping\n");
44c1fff98bd6c54db237bef5030657d3f47058a5Thiemo Wiedemeyerifp_user_get_attr_handle_reply(struct sss_domain_info *domain,
ea76e25262c3325f293fbdd6560f180ca18f9be4Thiemo Wiedemeyer /* Construct a reply */
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder reply = dbus_message_new_method_return(ireq->dbus_req->message);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder return sbus_request_finish(ireq->dbus_req, NULL);
6c59ae2c44a1fe22ef1712a57afe129e9dbd3368Thiemo Wiedemeyer dbus_message_iter_init_append(reply, &iter);
28ca54b0d63d1d26a991711c8c7e85c474994715Christian Maeder return sbus_request_finish(ireq->dbus_req, NULL);
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder el = sss_view_ldb_msg_find_element(domain, res->msgs[0], attrs[ai]);
51dc99030b1cce6a795a6d9e3d430264d5949c99Christian Maeder "Attribute %s not present or has no values\n",
d923f0b3f5f075f1d9bfc3018d0e06b561f58deeMihai Codescu /* Normalize white space in user names */
d923f0b3f5f075f1d9bfc3018d0e06b561f58deeMihai Codescu if (ireq->ifp_ctx->rctx->override_space != '\0' &&
d923f0b3f5f075f1d9bfc3018d0e06b561f58deeMihai Codescu ret = ifp_user_get_attr_replace_space(ireq, el,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder DEBUG(SSSDBG_MINOR_FAILURE, "Cannot normalize %s\n",
71654489020a03cf6ce9f2947f3da26a996f9c32Razvan Pascanu ret = ifp_add_ldb_el_to_dict(&iter_dict, el);
66fd8f017efdb8a6c862c3f1856dfaef90865dd5Thiemo Wiedemeyer "Cannot add attribute %s to message\n",
5b00a9d748d5bea461601ed7ed5198dfd30cf2d2Thiemo Wiedemeyer dbret = dbus_message_iter_close_container(&iter, &iter_dict);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder return sbus_request_finish(ireq->dbus_req, NULL);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer return sbus_request_finish(ireq->dbus_req, reply);
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,
521045d36343cd17dd217a81d4b9422ad6ab6a07Christian Maederint ifp_user_get_groups(struct sbus_request *dbus_req,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder ifp_ctx = talloc_get_type(data, struct ifp_ctx);
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maeder return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ifp_req_create(dbus_req, ifp_ctx, &ireq);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer return ifp_req_create_handle_failure(dbus_req, ret);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder group_req = talloc_zero(ireq, struct ifp_attr_req);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder return sbus_request_finish(dbus_req, NULL);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer group_req->attrs = talloc_zero_array(group_req, const char *, 2);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer return sbus_request_finish(dbus_req, NULL);
cb6d5bbb36150e28e40794320773e779e0c25d7bChristian Maeder group_req->attrs[0] = talloc_strdup(group_req->attrs, SYSDB_MEMBEROF);
239991d3955da0cfb760af4d506069446e1676b7Christian Maeder return sbus_request_finish(dbus_req, NULL);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer "Looking up groups of user [%s] on behalf of %"PRIi64"\n",
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer group_req->name, group_req->ireq->dbus_req->client);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer req = ifp_user_get_attr_send(ireq, ifp_ctx->rctx,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder return sbus_request_finish(dbus_req, NULL);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer tevent_req_set_callback(req, ifp_user_get_groups_process, group_req);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maederstatic void ifp_user_get_groups_process(struct tevent_req *req)
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer group_req = tevent_req_callback_data(req, struct ifp_attr_req);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer ret = ifp_user_get_attr_recv(group_req, req, &res, &dom);
66fd8f017efdb8a6c862c3f1856dfaef90865dd5Thiemo Wiedemeyer sbus_request_fail_and_finish(group_req->ireq->dbus_req,
1ac36418f204bbe56f4cd951a979180721758999Christian Maeder "No such user\n"));
1ac36418f204bbe56f4cd951a979180721758999Christian Maeder sbus_request_fail_and_finish(group_req->ireq->dbus_req,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder "Failed to read attribute\n"));
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer ret = ifp_user_get_groups_reply(dom, group_req->ireq, res);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder sbus_request_fail_and_finish(group_req->ireq->dbus_req,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder "Failed to build a reply\n"));
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyerifp_user_get_groups_reply(struct sss_domain_info *domain,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder /* one less, the first one is the user entry */
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyer groupnames = talloc_zero_array(ireq, const char *, num);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder return sbus_request_finish(ireq->dbus_req, NULL);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer for (i = 0; i < num; i++) {
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder name = sss_view_ldb_msg_find_attr_as_string(domain,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder DEBUG(SSSDBG_MINOR_FAILURE, "Skipping a group with no name\n");
1e3aca4178372af672efb237d16087c603fe5564Christian Maeder out_name = sss_output_name(ireq, name, domain->case_preserve,
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder groupnames[i] = sss_tc_fqname(groupnames, domain->names,
239991d3955da0cfb760af4d506069446e1676b7Christian Maeder DEBUG(SSSDBG_CRIT_FAILURE, "sss_tc_fqname failed\n");
cb6d5bbb36150e28e40794320773e779e0c25d7bChristian Maeder groupnames[i] = talloc_steal(groupnames, out_name);
239991d3955da0cfb760af4d506069446e1676b7Christian Maeder DEBUG(SSSDBG_TRACE_FUNC, "Adding group %s\n", groupnames[i]);
8bdd8707c8e341f1fc57fcbf884520bfe06a5028Christian Maeder return iface_ifp_GetUserGroups_finish(ireq->dbus_req, groupnames, num);
53e76316f409f6b1b57ed3d2e5cb9cfe1cb511e5Thiemo Wiedemeyerstatic void ifp_user_get_attr_lookup(struct tevent_req *subreq);
4f8a6dee8333cac3769f6952d64965867e017f4dChristian Maederstatic void ifp_user_get_attr_done(struct tevent_req *subreq);
20b4fd534e69163ae5992d93ebd1782a9661e623Christian Maederifp_user_get_attr_send(TALLOC_CTX *mem_ctx, struct resp_ctx *rctx,
8f5219469b89a15dc6d4c2c30463775975f5841cRazvan Pascanu req = tevent_req_create(mem_ctx, &state, struct ifp_user_get_attr_state);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer subreq = sss_parse_inp_send(req, rctx, inp);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer tevent_req_set_callback(subreq, ifp_user_get_attr_lookup, req);
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyerifp_user_get_attr_lookup(struct tevent_req *subreq)
b72d30bc42015e1ed92fa8b152ddaa062b642ed2Thiemo Wiedemeyer struct ifp_user_get_attr_state *state = NULL;
case SSS_DP_USER:
case SSS_DP_INITGROUPS:
static errno_t
struct ifp_user_get_attr_state);
return ENOENT;
if (_res) {
if (_domain) {
return EOK;
return ssh_cli_protocol_version;