ifpsrv_cmd.c revision faae3d55e5cf416f16158d3b9f8c8fd475ac6acf
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina/*
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina Authors:
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina Jakub Hrozek <jhrozek@redhat.com>
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina Copyright (C) 2013 Red Hat
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina InfoPipe responder: the responder commands
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina This program is free software; you can redistribute it and/or modify
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina it under the terms of the GNU General Public License as published by
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina the Free Software Foundation; either version 3 of the License, or
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina (at your option) any later version.
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina This program is distributed in the hope that it will be useful,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina GNU General Public License for more details.
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina You should have received a copy of the GNU General Public License
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina*/
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina#include "db/sysdb.h"
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina#include "responder/ifp/ifp_private.h"
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina#include "responder/common/responder_cache_req.h"
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinastruct ifp_attr_req {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina const char *name;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina const char **attrs;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina int nattrs;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ifp_req *ireq;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina};
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinastatic struct tevent_req *
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinaifp_user_get_attr_send(TALLOC_CTX *mem_ctx, struct resp_ctx *rctx,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct sss_nc_ctx *ncache, int neg_timeout,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina enum sss_dp_acct_type search_type,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina const char *inp, const char **attrs);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinastatic errno_t ifp_user_get_attr_recv(TALLOC_CTX *mem_ctx,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct tevent_req *req,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ldb_result **_res,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct sss_domain_info **_domain);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinastatic void ifp_user_get_attr_process(struct tevent_req *req);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinastatic errno_t
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinaifp_user_get_attr_handle_reply(struct sss_domain_info *domain,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ifp_req *ireq,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina const char **attrs,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ldb_result *res);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinastatic errno_t
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinaifp_user_get_attr_unpack_msg(struct ifp_attr_req *attr_req);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinaint ifp_user_get_attr(struct sbus_request *dbus_req, void *data)
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina{
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina errno_t ret;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ifp_req *ireq;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ifp_ctx *ifp_ctx;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ifp_attr_req *attr_req;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct tevent_req *req;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina ifp_ctx = talloc_get_type(data, struct ifp_ctx);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (ifp_ctx == NULL) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina ret = ifp_req_create(dbus_req, ifp_ctx, &ireq);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (ret != EOK) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return ifp_req_create_handle_failure(dbus_req, ret);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina attr_req = talloc_zero(ireq, struct ifp_attr_req);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (attr_req == NULL) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return sbus_request_finish(dbus_req, NULL);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina attr_req->ireq = ireq;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina ret = ifp_user_get_attr_unpack_msg(attr_req);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (ret != EOK) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return ret; /* handled internally */
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DEBUG(SSSDBG_FUNC_DATA,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina "Looking up attributes of user [%s] on behalf of %"PRIi64"\n",
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina attr_req->name, ireq->dbus_req->client);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina req = ifp_user_get_attr_send(ireq, ifp_ctx->rctx,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina ifp_ctx->ncache, ifp_ctx->neg_timeout,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina SSS_DP_USER,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina attr_req->name, attr_req->attrs);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (req == NULL) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return sbus_request_finish(dbus_req, NULL);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina tevent_req_set_callback(req, ifp_user_get_attr_process, attr_req);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return EOK;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina}
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinastatic errno_t
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinaifp_user_get_attr_unpack_msg(struct ifp_attr_req *attr_req)
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina{
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina bool parsed;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina char **attrs;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina int nattrs;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina int i, ai;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina const char **whitelist = attr_req->ireq->ifp_ctx->user_whitelist;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina parsed = sbus_request_parse_or_finish(attr_req->ireq->dbus_req,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBUS_TYPE_STRING, &attr_req->name,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina &attrs, &nattrs,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBUS_TYPE_INVALID);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (parsed == false) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DEBUG(SSSDBG_OP_FAILURE, "Could not parse arguments\n");
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return EOK; /* handled */
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina /* Copy the attributes to maintain memory hierarchy with talloc */
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina attr_req->attrs = talloc_zero_array(attr_req, const char *, nattrs+1);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (attr_req->attrs == NULL) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return ENOMEM;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina ai = 0;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina for (i = 0; i < nattrs; i++) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (ifp_attr_allowed(whitelist, attrs[i]) == false) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DEBUG(SSSDBG_MINOR_FAILURE,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina "Attribute %s not present in the whitelist, skipping\n",
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina attrs[i]);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina continue;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina attr_req->attrs[ai] = talloc_strdup(attr_req->attrs, attrs[i]);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (attr_req->attrs[ai] == NULL) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return ENOMEM;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina ai++;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return EOK;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina}
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinastatic void ifp_user_get_attr_process(struct tevent_req *req)
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina{
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ifp_attr_req *attr_req;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina errno_t ret;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ldb_result *res = NULL;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct sss_domain_info *dom = NULL;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina attr_req = tevent_req_callback_data(req, struct ifp_attr_req);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina ret = ifp_user_get_attr_recv(attr_req, req, &res, &dom);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina talloc_zfree(req);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (ret == ENOENT) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina sbus_request_fail_and_finish(attr_req->ireq->dbus_req,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina sbus_error_new(attr_req->ireq->dbus_req,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBUS_ERROR_FAILED,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina "No such user\n"));
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina } else if (ret != EOK) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina sbus_request_fail_and_finish(attr_req->ireq->dbus_req,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina sbus_error_new(attr_req->ireq->dbus_req,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBUS_ERROR_FAILED,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina "Failed to read user attribute\n"));
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina ret = ifp_user_get_attr_handle_reply(dom, attr_req->ireq,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina attr_req->attrs, res);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (ret != EOK) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina sbus_request_fail_and_finish(attr_req->ireq->dbus_req,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina sbus_error_new(attr_req->ireq->dbus_req,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBUS_ERROR_FAILED,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina "Failed to build a reply\n"));
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina}
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinastatic errno_t
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinaifp_user_get_attr_replace_space(TALLOC_CTX *mem_ctx,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ldb_message_element *el,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina const char sub)
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina{
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina int i;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina for (i = 0; i < el->num_values; i++) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina el->values[i].data = (uint8_t *) sss_replace_space(mem_ctx,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina (const char *) el->values[i].data,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina sub);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (el->values[i].data == NULL) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "sss_replace_space failed, skipping\n");
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return ENOMEM;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return EOK;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina}
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinastatic errno_t
383840c0c9c440710352076f844a64745121d251Pavel Březinaifp_user_get_attr_handle_reply(struct sss_domain_info *domain,
383840c0c9c440710352076f844a64745121d251Pavel Březina struct ifp_req *ireq,
383840c0c9c440710352076f844a64745121d251Pavel Březina const char **attrs,
383840c0c9c440710352076f844a64745121d251Pavel Březina struct ldb_result *res)
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina{
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina errno_t ret;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina dbus_bool_t dbret;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBusMessage *reply;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBusMessageIter iter;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBusMessageIter iter_dict;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ldb_message_element *el;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina int ai;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina /* Construct a reply */
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina reply = dbus_message_new_method_return(ireq->dbus_req->message);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (!reply) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return sbus_request_finish(ireq->dbus_req, NULL);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina dbus_message_iter_init_append(reply, &iter);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina dbret = dbus_message_iter_open_container(
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina &iter, DBUS_TYPE_ARRAY,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBUS_TYPE_STRING_AS_STRING
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBUS_TYPE_VARIANT_AS_STRING
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina &iter_dict);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (!dbret) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return sbus_request_finish(ireq->dbus_req, NULL);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (res->count > 0) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina for (ai = 0; attrs[ai]; ai++) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina el = sss_view_ldb_msg_find_element(domain, res->msgs[0], attrs[ai]);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (el == NULL || el->num_values == 0) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DEBUG(SSSDBG_MINOR_FAILURE,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina "Attribute %s not present or has no values\n",
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina attrs[ai]);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina continue;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina /* Normalize white space in user names */
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (ireq->ifp_ctx->rctx->override_space != '\0' &&
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina strcmp(attrs[ai], SYSDB_NAME) == 0) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina ret = ifp_user_get_attr_replace_space(ireq, el,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina ireq->ifp_ctx->rctx->override_space);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (ret != EOK) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DEBUG(SSSDBG_MINOR_FAILURE, "Cannot normalize %s\n",
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina attrs[ai]);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina continue;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina ret = ifp_add_ldb_el_to_dict(&iter_dict, el);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (ret != EOK) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DEBUG(SSSDBG_MINOR_FAILURE,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina "Cannot add attribute %s to message\n",
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina attrs[ai]);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina continue;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek }
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek dbret = dbus_message_iter_close_container(&iter, &iter_dict);
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek if (!dbret) {
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek return sbus_request_finish(ireq->dbus_req, NULL);
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek }
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return sbus_request_finish(ireq->dbus_req, reply);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina}
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinastatic void ifp_user_get_groups_process(struct tevent_req *req);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinastatic errno_t ifp_user_get_groups_reply(struct sss_domain_info *domain,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ifp_req *ireq,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ldb_result *res);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinaint ifp_user_get_groups(struct sbus_request *dbus_req,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina void *data, const char *arg_user)
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina{
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ifp_req *ireq;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ifp_ctx *ifp_ctx;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ifp_attr_req *group_req;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct tevent_req *req;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina errno_t ret;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina ifp_ctx = talloc_get_type(data, struct ifp_ctx);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (ifp_ctx == NULL) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina ret = ifp_req_create(dbus_req, ifp_ctx, &ireq);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (ret != EOK) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return ifp_req_create_handle_failure(dbus_req, ret);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina group_req = talloc_zero(ireq, struct ifp_attr_req);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (group_req == NULL) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return sbus_request_finish(dbus_req, NULL);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina group_req->ireq = ireq;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina group_req->name = arg_user;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina group_req->attrs = talloc_zero_array(group_req, const char *, 2);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (group_req->attrs == NULL) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return sbus_request_finish(dbus_req, NULL);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina group_req->attrs[0] = talloc_strdup(group_req->attrs, SYSDB_MEMBEROF);
383840c0c9c440710352076f844a64745121d251Pavel Březina if (group_req->attrs[0] == NULL) {
383840c0c9c440710352076f844a64745121d251Pavel Březina return sbus_request_finish(dbus_req, NULL);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DEBUG(SSSDBG_FUNC_DATA,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina "Looking up groups of user [%s] on behalf of %"PRIi64"\n",
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina group_req->name, group_req->ireq->dbus_req->client);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina req = ifp_user_get_attr_send(ireq, ifp_ctx->rctx,
383840c0c9c440710352076f844a64745121d251Pavel Březina ifp_ctx->ncache, ifp_ctx->neg_timeout,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina SSS_DP_INITGROUPS,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina group_req->name, group_req->attrs);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (req == NULL) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return sbus_request_finish(dbus_req, NULL);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina tevent_req_set_callback(req, ifp_user_get_groups_process, group_req);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return EOK;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina}
383840c0c9c440710352076f844a64745121d251Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinastatic void ifp_user_get_groups_process(struct tevent_req *req)
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina{
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ifp_attr_req *group_req;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina errno_t ret;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ldb_result *res;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct sss_domain_info *dom;
383840c0c9c440710352076f844a64745121d251Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina group_req = tevent_req_callback_data(req, struct ifp_attr_req);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina ret = ifp_user_get_attr_recv(group_req, req, &res, &dom);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina talloc_zfree(req);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (ret == ENOENT) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina sbus_request_fail_and_finish(group_req->ireq->dbus_req,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina sbus_error_new(group_req->ireq->dbus_req,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBUS_ERROR_FAILED,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina "No such user\n"));
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina } else if (ret != EOK) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina sbus_request_fail_and_finish(group_req->ireq->dbus_req,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina sbus_error_new(group_req->ireq->dbus_req,
8835ecb2ff5126629993a6b6d3fb0bb7baa3b765Pavel Reichl DBUS_ERROR_FAILED,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina "Failed to read attribute\n"));
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina ret = ifp_user_get_groups_reply(dom, group_req->ireq, res);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (ret != EOK) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina sbus_request_fail_and_finish(group_req->ireq->dbus_req,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina sbus_error_new(group_req->ireq->dbus_req,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBUS_ERROR_FAILED,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina "Failed to build a reply\n"));
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina}
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinastatic errno_t
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinaifp_user_get_groups_reply(struct sss_domain_info *domain,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ifp_req *ireq,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ldb_result *res)
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina{
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina int i, num;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina const char *name;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina const char **groupnames;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina const char *tmpstr;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina /* one less, the first one is the user entry */
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina num = res->count - 1;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina groupnames = talloc_zero_array(ireq, const char *, num);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (groupnames == NULL) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return sbus_request_finish(ireq->dbus_req, NULL);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina for (i = 0; i < num; i++) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina name = sss_view_ldb_msg_find_attr_as_string(domain,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina res->msgs[i + 1],
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina SYSDB_NAME, NULL);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (name == NULL) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DEBUG(SSSDBG_MINOR_FAILURE, "Skipping a group with no name\n");
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina continue;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (ireq->ifp_ctx->rctx->override_space != '\0') {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina tmpstr = sss_replace_space(ireq, name,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina ireq->ifp_ctx->rctx->override_space);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (tmpstr == NULL) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DEBUG(SSSDBG_MINOR_FAILURE, "Cannot normalize %s\n", name);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina continue;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina } else {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina tmpstr = name;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina groupnames[i] = sss_get_cased_name(groupnames, tmpstr,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina domain->case_preserve);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (groupnames[i] == NULL) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina "sss_get_cased_name failed, skipping\n");
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina continue;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek }
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "Adding group %s\n", groupnames[i]);
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek }
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek return infopipe_iface_GetUserGroups_finish(ireq->dbus_req,
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek groupnames, num);
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek}
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozekstruct ifp_user_get_attr_state {
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek const char *inp;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek const char **attrs;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek struct ldb_result *res;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek enum sss_dp_acct_type search_type;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek char *name;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek char *domname;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek struct sss_domain_info *dom;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek bool check_next;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek bool check_provider;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek struct resp_ctx *rctx;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek struct sss_nc_ctx *ncache;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek int neg_timeout;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek};
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozekstatic void ifp_user_get_attr_lookup(struct tevent_req *subreq);
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozekstatic void ifp_user_get_attr_done(struct tevent_req *subreq);
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozekstatic struct tevent_req *
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozekifp_user_get_attr_send(TALLOC_CTX *mem_ctx, struct resp_ctx *rctx,
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek struct sss_nc_ctx *ncache, int neg_timeout,
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek enum sss_dp_acct_type search_type,
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek const char *inp, const char **attrs)
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek{
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek errno_t ret;
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnik struct tevent_req *req;
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnik struct tevent_req *subreq;
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnik struct ifp_user_get_attr_state *state;
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnik
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek req = tevent_req_create(mem_ctx, &state, struct ifp_user_get_attr_state);
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek if (req == NULL) {
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek return NULL;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek }
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek state->inp = inp;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek state->attrs = attrs;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek state->rctx = rctx;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek state->ncache = ncache;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek state->neg_timeout = neg_timeout;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek state->search_type = search_type;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnik subreq = sss_parse_inp_send(req, rctx, inp);
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnik if (subreq == NULL) {
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnik ret = ENOMEM;
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnik goto done;
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnik }
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnik tevent_req_set_callback(subreq, ifp_user_get_attr_lookup, req);
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnik
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnik ret = EOK;
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnikdone:
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnik if (ret != EOK) {
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnik tevent_req_error(req, ret);
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnik }
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnik return req;
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnik}
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnik
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnikstatic void
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnikifp_user_get_attr_lookup(struct tevent_req *subreq)
d9065da2a103fe88b548904bb215c9bb1f21afa2Lukas Slebodnik{
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek struct ifp_user_get_attr_state *state = NULL;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek struct tevent_req *req = NULL;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina errno_t ret;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina state = tevent_req_data(req, struct ifp_user_get_attr_state);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina ret = sss_parse_inp_recv(subreq, state, &state->name, &state->domname);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina talloc_zfree(subreq);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (ret != EOK) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina tevent_req_error(req, ret);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina subreq = cache_req_send(state, state->rctx->ev, state->rctx,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina state->ncache, state->neg_timeout, 0,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina state->search_type, state->domname, state->name);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (subreq == NULL) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina tevent_req_error(req, ENOMEM);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina tevent_req_set_callback(subreq, ifp_user_get_attr_done, req);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina}
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinastatic void ifp_user_get_attr_done(struct tevent_req *subreq)
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina{
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ifp_user_get_attr_state *state = NULL;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct tevent_req *req = NULL;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina errno_t ret;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina state = tevent_req_data(req, struct ifp_user_get_attr_state);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek ret = cache_req_recv(state, subreq, &state->res, &state->dom);
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek talloc_zfree(subreq);
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek if (ret != EOK) {
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek tevent_req_error(req, ret);
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek return;
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek }
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek if (state->search_type == SSS_DP_USER) {
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek /* throw away the result and perform attr search */
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek talloc_zfree(state->res);
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek ret = sysdb_get_user_attr_with_views(state, state->dom, state->name,
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek state->attrs, &state->res);
999d6066c7a96f102b692d31435d76114478e874Jakub Hrozek if (ret != EOK) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_get_user_attr_with_views() "
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina "failed [%d]: %s\n", ret, sss_strerror(ret));
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina tevent_req_error(req, ret);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina } else if (state->res->count == 0) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina tevent_req_error(req, ENOENT);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina } else if (state->res->count != 1) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_get_user_attr_with_views() "
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina "returned more than one result!\n");
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina tevent_req_error(req, ENOENT);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina tevent_req_done(req);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina}
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinastatic errno_t
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinaifp_user_get_attr_recv(TALLOC_CTX *mem_ctx,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct tevent_req *req,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ldb_result **_res,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct sss_domain_info **_domain)
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina{
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ifp_user_get_attr_state *state = tevent_req_data(req,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ifp_user_get_attr_state);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina TEVENT_REQ_RETURN_ON_ERROR(req);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (state->res == NULL) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina /* Did the request end with success but with no data? */
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return ENOENT;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (_res) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina *_res = talloc_steal(mem_ctx, state->res);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (_domain) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina *_domain = state->dom;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return EOK;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina}
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinastruct cli_protocol_version *register_cli_protocol_version(void)
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina{
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina static struct cli_protocol_version ssh_cli_protocol_version[] = {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina {0, NULL, NULL}
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina };
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return ssh_cli_protocol_version;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina}
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina/* This is a throwaway method to ease the review of the patch.
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina * It will be removed later */
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březinaint ifp_ping(struct sbus_request *dbus_req, void *data)
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina{
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ifp_ctx *ifp_ctx = talloc_get_type(data, struct ifp_ctx);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina static const char *pong = "PONG";
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina const char *request;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBusError dberr;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina errno_t ret;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina struct ifp_req *ifp_req;
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (ifp_ctx == NULL) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina ret = ifp_req_create(dbus_req, ifp_ctx, &ifp_req);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (ret != EOK) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return ifp_req_create_handle_failure(dbus_req, ret);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (!sbus_request_parse_or_finish(dbus_req,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBUS_TYPE_STRING, &request,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBUS_TYPE_INVALID)) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return EOK; /* handled */
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DEBUG(SSSDBG_CONF_SETTINGS, "Got request for [%s]\n", request);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina if (strcasecmp(request, "ping") != 0) {
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina dbus_error_init(&dberr);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina dbus_set_error_const(&dberr,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBUS_ERROR_INVALID_ARGS,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina "Ping() only accepts ping as a param\n");
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return sbus_request_fail_and_finish(dbus_req, &dberr);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina }
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina return sbus_request_return_and_finish(dbus_req,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBUS_TYPE_STRING, &pong,
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina DBUS_TYPE_INVALID);
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina}
ce35bb272d25926b8fa0f9450c8b74064f25c816Pavel Březina