c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina/*
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina Authors:
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina Pavel Březina <pbrezina@redhat.com>
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina Copyright (C) 2015 Red Hat
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina This program is free software; you can redistribute it and/or modify
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina it under the terms of the GNU General Public License as published by
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina the Free Software Foundation; either version 3 of the License, or
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina (at your option) any later version.
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina This program is distributed in the hope that it will be useful,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina GNU General Public License for more details.
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina You should have received a copy of the GNU General Public License
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina*/
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina#include <talloc.h>
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina#include <tevent.h>
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina#include <string.h>
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina#include "db/sysdb.h"
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina#include "util/util.h"
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina#include "util/strtonum.h"
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose#include "util/cert.h"
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina#include "sbus/sssd_dbus_errors.h"
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina#include "responder/common/responder.h"
4169fb26ea2ff93c19ecdad6e09382732ea5deebPavel Březina#include "responder/common/cache_req/cache_req.h"
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina#include "responder/ifp/ifp_users.h"
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina#include "responder/ifp/ifp_groups.h"
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina#include "responder/ifp/ifp_cache.h"
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březinachar * ifp_users_build_path_from_msg(TALLOC_CTX *mem_ctx,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina struct sss_domain_info *domain,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina struct ldb_message *msg)
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina{
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek const char *key = NULL;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek switch (domain->type) {
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek case DOM_TYPE_APPLICATION:
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek key = ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek break;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek case DOM_TYPE_POSIX:
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek key = ldb_msg_find_attr_as_string(msg, SYSDB_UIDNUM, NULL);
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek break;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek }
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek if (key == NULL) {
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina return NULL;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina }
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek return sbus_opath_compose(mem_ctx, IFP_PATH_USERS, domain->name, key);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina}
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozekstatic errno_t ifp_users_decompose_path(TALLOC_CTX *mem_ctx,
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek struct sss_domain_info *domains,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char *path,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct sss_domain_info **_domain,
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek char **_key)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina{
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina char **parts = NULL;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct sss_domain_info *domain;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina errno_t ret;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina ret = sbus_opath_decompose_exact(NULL, path, IFP_PATH_USERS, 2, &parts);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (ret != EOK) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return ret;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina domain = find_domain_by_name(domains, parts[0], false);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (domain == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina ret = ERR_DOMAIN_NOT_FOUND;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina goto done;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina *_domain = domain;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek *_key = talloc_steal(mem_ctx, parts[1]);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinadone:
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina talloc_free(parts);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return ret;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina}
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březinastatic void ifp_users_find_by_name_done(struct tevent_req *req);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březinaint ifp_users_find_by_name(struct sbus_request *sbus_req,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina void *data,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina const char *name)
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina{
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina struct ifp_ctx *ctx;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina struct tevent_req *req;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina ctx = talloc_get_type(data, struct ifp_ctx);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina if (ctx == NULL) {
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina return ERR_INTERNAL;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina }
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina req = cache_req_user_by_name_send(sbus_req, ctx->rctx->ev, ctx->rctx,
cee85e8fb9534ec997e5388fce59f392cf029573Jakub Hrozek ctx->rctx->ncache, 0,
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek CACHE_REQ_ANY_DOM,
cee85e8fb9534ec997e5388fce59f392cf029573Jakub Hrozek NULL, name);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina if (req == NULL) {
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina return ENOMEM;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina }
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina tevent_req_set_callback(req, ifp_users_find_by_name_done, sbus_req);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina return EOK;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina}
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březinastatic void
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březinaifp_users_find_by_name_done(struct tevent_req *req)
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina{
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina DBusError *error;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina struct sbus_request *sbus_req;
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina struct cache_req_result *result;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina char *object_path;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina errno_t ret;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina sbus_req = tevent_req_callback_data(req, struct sbus_request);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina ret = cache_req_user_by_name_recv(sbus_req, req, &result);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina talloc_zfree(req);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina if (ret == ENOENT) {
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina error = sbus_error_new(sbus_req, SBUS_ERROR_NOT_FOUND,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina "User not found");
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina goto done;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina } else if (ret != EOK) {
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED, "Failed to fetch "
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina "user [%d]: %s\n", ret, sss_strerror(ret));
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina goto done;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina }
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina object_path = ifp_users_build_path_from_msg(sbus_req, result->domain,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina result->msgs[0]);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina if (object_path == NULL) {
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina error = sbus_error_new(sbus_req, SBUS_ERROR_INTERNAL,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina "Failed to compose object path");
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina goto done;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina }
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina ret = EOK;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březinadone:
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina if (ret != EOK) {
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina sbus_request_fail_and_finish(sbus_req, error);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina return;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina }
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina iface_ifp_users_FindByName_finish(sbus_req, object_path);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina return;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina}
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březinastatic void ifp_users_find_by_id_done(struct tevent_req *req);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březinaint ifp_users_find_by_id(struct sbus_request *sbus_req,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina void *data,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina uint32_t id)
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina{
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina struct ifp_ctx *ctx;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina struct tevent_req *req;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina ctx = talloc_get_type(data, struct ifp_ctx);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina if (ctx == NULL) {
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina return ERR_INTERNAL;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina }
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina req = cache_req_user_by_id_send(sbus_req, ctx->rctx->ev, ctx->rctx,
11a87c5f091d6c092b5dadd3d67f900213e280daPetr Cech ctx->rctx->ncache, 0, NULL, id);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina if (req == NULL) {
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina return ENOMEM;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina }
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina tevent_req_set_callback(req, ifp_users_find_by_id_done, sbus_req);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina return EOK;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina}
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březinastatic void
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březinaifp_users_find_by_id_done(struct tevent_req *req)
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina{
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina DBusError *error;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina struct sbus_request *sbus_req;
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina struct cache_req_result *result;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina char *object_path;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina errno_t ret;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina sbus_req = tevent_req_callback_data(req, struct sbus_request);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina ret = cache_req_user_by_id_recv(sbus_req, req, &result);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina talloc_zfree(req);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina if (ret == ENOENT) {
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina error = sbus_error_new(sbus_req, SBUS_ERROR_NOT_FOUND,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina "User not found");
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina goto done;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina } else if (ret != EOK) {
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED, "Failed to fetch "
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina "user [%d]: %s\n", ret, sss_strerror(ret));
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina goto done;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina }
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina object_path = ifp_users_build_path_from_msg(sbus_req, result->domain,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina result->msgs[0]);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina if (object_path == NULL) {
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina error = sbus_error_new(sbus_req, SBUS_ERROR_INTERNAL,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina "Failed to compose object path");
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina goto done;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina }
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březinadone:
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina if (ret != EOK) {
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina sbus_request_fail_and_finish(sbus_req, error);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina return;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina }
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina iface_ifp_users_FindByID_finish(sbus_req, object_path);
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina return;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina}
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bosestatic void ifp_users_find_by_cert_done(struct tevent_req *req);
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose
827a016a07d5f911cc4195be89896a376fd71f59Sumit Boseint ifp_users_find_by_cert(struct sbus_request *sbus_req, void *data,
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose const char *pem_cert)
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose{
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose struct ifp_ctx *ctx;
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose struct tevent_req *req;
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose int ret;
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose char *derb64;
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose DBusError *error;
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose ctx = talloc_get_type(data, struct ifp_ctx);
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose if (ctx == NULL) {
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose return ERR_INTERNAL;
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose }
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose ret = sss_cert_pem_to_derb64(sbus_req, pem_cert, &derb64);
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose if (ret != EOK) {
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sss_cert_pem_to_derb64 failed.\n");
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose if (ret == ENOMEM) {
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose return ret;
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose }
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose error = sbus_error_new(sbus_req, DBUS_ERROR_INVALID_ARGS,
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose "Invalid certificate format");
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose sbus_request_fail_and_finish(sbus_req, error);
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose /* the connection is already terminated with an error message, hence
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose * we have to return EOK to not terminate the connection twice. */
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose return EOK;
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose }
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose req = cache_req_user_by_cert_send(sbus_req, ctx->rctx->ev, ctx->rctx,
cee85e8fb9534ec997e5388fce59f392cf029573Jakub Hrozek ctx->rctx->ncache, 0,
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek CACHE_REQ_ANY_DOM, NULL,
cee85e8fb9534ec997e5388fce59f392cf029573Jakub Hrozek derb64);
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose if (req == NULL) {
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose return ENOMEM;
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose }
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose tevent_req_set_callback(req, ifp_users_find_by_cert_done, sbus_req);
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose return EOK;
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose}
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose#define SBUS_ERROR_MORE_THAN_ONE "org.freedesktop.sssd.Error.MoreThanOne"
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bosestatic void ifp_users_find_by_cert_done(struct tevent_req *req)
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose{
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose DBusError *error;
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose struct sbus_request *sbus_req;
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina struct cache_req_result *result;
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose char *object_path;
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose errno_t ret;
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose sbus_req = tevent_req_callback_data(req, struct sbus_request);
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina ret = cache_req_user_by_cert_recv(sbus_req, req, &result);
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose talloc_zfree(req);
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose if (ret == ENOENT) {
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose error = sbus_error_new(sbus_req, SBUS_ERROR_NOT_FOUND,
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose "User not found");
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose goto done;
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose } else if (ret != EOK) {
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED, "Failed to fetch "
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose "user [%d]: %s\n", ret, sss_strerror(ret));
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose goto done;
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose }
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose if (result->count > 1) {
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose ret = EINVAL;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose error = sbus_error_new(sbus_req, SBUS_ERROR_MORE_THAN_ONE,
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose "More than one user found. "
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose "Use ListByCertificate to get all.");
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose goto done;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose }
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina object_path = ifp_users_build_path_from_msg(sbus_req, result->domain,
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose result->msgs[0]);
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose if (object_path == NULL) {
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose error = sbus_error_new(sbus_req, SBUS_ERROR_INTERNAL,
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose "Failed to compose object path");
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose goto done;
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose }
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bosedone:
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose if (ret != EOK) {
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose sbus_request_fail_and_finish(sbus_req, error);
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose return;
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose }
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose iface_ifp_users_FindByCertificate_finish(sbus_req, object_path);
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose return;
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose}
827a016a07d5f911cc4195be89896a376fd71f59Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bosestatic int ifp_users_list_by_cert_step(struct ifp_list_ctx *list_ctx);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bosestatic void ifp_users_list_by_cert_done(struct tevent_req *req);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bosestatic void ifp_users_list_by_name_reply(struct ifp_list_ctx *list_ctx);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bosestatic int ifp_users_list_copy(struct ifp_list_ctx *list_ctx,
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose struct ldb_result *result);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Boseint ifp_users_list_by_cert(struct sbus_request *sbus_req, void *data,
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose const char *pem_cert, uint32_t limit)
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose{
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose struct ifp_ctx *ctx;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose struct ifp_list_ctx *list_ctx;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose char *derb64;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose int ret;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose DBusError *error;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose ret = sss_cert_pem_to_derb64(sbus_req, pem_cert, &derb64);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose if (ret != EOK) {
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sss_cert_pem_to_derb64 failed.\n");
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose if (ret == ENOMEM) {
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose return ret;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose }
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose error = sbus_error_new(sbus_req, DBUS_ERROR_INVALID_ARGS,
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose "Invalid certificate format");
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose sbus_request_fail_and_finish(sbus_req, error);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose /* the connection is already terminated with an error message, hence
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose * we have to return EOK to not terminate the connection twice. */
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose return EOK;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose }
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose ctx = talloc_get_type(data, struct ifp_ctx);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose if (ctx == NULL) {
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose return ERR_INTERNAL;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose }
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose list_ctx = ifp_list_ctx_new(sbus_req, ctx, derb64, limit);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose if (list_ctx == NULL) {
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose return ENOMEM;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose }
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose return ifp_users_list_by_cert_step(list_ctx);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose}
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bosestatic int ifp_users_list_by_cert_step(struct ifp_list_ctx *list_ctx)
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose{
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose struct tevent_req *req;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose req = cache_req_user_by_cert_send(list_ctx,
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose list_ctx->ctx->rctx->ev,
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose list_ctx->ctx->rctx,
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose list_ctx->ctx->rctx->ncache,
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose 0,
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek CACHE_REQ_ANY_DOM,
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose list_ctx->dom->name,
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose list_ctx->filter);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose if (req == NULL) {
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose return ENOMEM;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose }
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose tevent_req_set_callback(req, ifp_users_list_by_cert_done, list_ctx);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose return EOK;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose}
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bosestatic void ifp_users_list_by_cert_done(struct tevent_req *req)
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose{
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose DBusError *error;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose struct ifp_list_ctx *list_ctx;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose struct sbus_request *sbus_req;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose struct cache_req_result *result;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose errno_t ret;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose list_ctx = tevent_req_callback_data(req, struct ifp_list_ctx);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose sbus_req = list_ctx->sbus_req;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose ret = cache_req_user_by_cert_recv(sbus_req, req, &result);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose talloc_zfree(req);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose if (ret != EOK && ret != ENOENT) {
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED,
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose "Failed to fetch user [%d]: %s\n",
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose ret, sss_strerror(ret));
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose sbus_request_fail_and_finish(sbus_req, error);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose return;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose }
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose if (ret == EOK) {
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose ret = ifp_users_list_copy(list_ctx, result->ldb_result);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose if (ret != EOK) {
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose error = sbus_error_new(sbus_req, SBUS_ERROR_INTERNAL,
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose "Failed to copy domain result");
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose sbus_request_fail_and_finish(sbus_req, error);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose return;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose }
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose }
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose list_ctx->dom = get_next_domain(list_ctx->dom, SSS_GND_DESCEND);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose if (list_ctx->dom == NULL) {
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose return ifp_users_list_by_name_reply(list_ctx);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose }
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose ret = ifp_users_list_by_cert_step(list_ctx);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose if (ret != EOK) {
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose error = sbus_error_new(sbus_req, SBUS_ERROR_INTERNAL,
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose "Failed to start next-domain search");
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose sbus_request_fail_and_finish(sbus_req, error);
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose return;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose }
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose return;
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose}
861dbe0794739a1c93a5bed00913c7442a2bdac9Sumit Bose
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozekstatic int ifp_users_list_copy(struct ifp_list_ctx *list_ctx,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek struct ldb_result *result)
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek{
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek size_t copy_count, i;
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio errno_t ret;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio ret = ifp_list_ctx_remaining_capacity(list_ctx, result->count, &copy_count);
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio if (ret != EOK) {
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio goto done;
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek for (i = 0; i < copy_count; i++) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx->paths[list_ctx->path_count + i] = \
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek ifp_users_build_path_from_msg(list_ctx->paths,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx->dom,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek result->msgs[i]);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek if (list_ctx->paths[list_ctx->path_count + i] == NULL) {
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio ret = ENOMEM;
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio goto done;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx->path_count += copy_count;
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio ret = EOK;
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidênciodone:
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio return ret;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek}
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bosestruct name_and_cert_ctx {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose const char *name;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose char *derb64;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct sbus_request *sbus_req;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose char *user_opath;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct ifp_list_ctx *list_ctx;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose};
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bosestatic void ifp_users_find_by_name_and_cert_name_done(struct tevent_req *req);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bosestatic int ifp_users_find_by_name_and_cert_step(
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct name_and_cert_ctx *name_and_cert_ctx);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bosestatic void ifp_users_find_by_name_and_cert_done(struct tevent_req *req);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bosestatic void ifp_users_find_by_name_and_cert_reply(
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct name_and_cert_ctx *name_and_cert_ctx);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Boseint ifp_users_find_by_name_and_cert(struct sbus_request *sbus_req, void *data,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose const char *name, const char *pem_cert)
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose{
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct ifp_ctx *ctx;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct tevent_req *req;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose int ret;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct name_and_cert_ctx *name_and_cert_ctx = NULL;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose DBusError *error;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose ctx = talloc_get_type(data, struct ifp_ctx);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (ctx == NULL) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return ERR_INTERNAL;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if ((name == NULL || *name == '\0')
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose && (pem_cert == NULL || *pem_cert == '\0')) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose error = sbus_error_new(sbus_req, DBUS_ERROR_INVALID_ARGS,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose "Missing input");
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose sbus_request_fail_and_finish(sbus_req, error);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose /* the connection is already terminated with an error message, hence
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose * we have to return EOK to not terminate the connection twice. */
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return EOK;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose name_and_cert_ctx = talloc_zero(sbus_req, struct name_and_cert_ctx);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (name_and_cert_ctx == NULL) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc failed.\n");
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return ENOMEM;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose name_and_cert_ctx->sbus_req = sbus_req;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (name != NULL && *name != '\0') {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose name_and_cert_ctx->name = talloc_strdup(name_and_cert_ctx, name);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (name_and_cert_ctx->name == NULL) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return ENOMEM;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (pem_cert != NULL && *pem_cert != '\0') {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose ret = sss_cert_pem_to_derb64(name_and_cert_ctx, pem_cert,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose &(name_and_cert_ctx->derb64));
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (ret != EOK) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sss_cert_pem_to_derb64 failed.\n");
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (ret == ENOMEM) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return ret;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose error = sbus_error_new(sbus_req, DBUS_ERROR_INVALID_ARGS,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose "Invalid certificate format");
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose sbus_request_fail_and_finish(sbus_req, error);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose /* the connection is already terminated with an error message, hence
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose * we have to return EOK to not terminate the connection twice. */
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return EOK;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose /* FIXME: if unlimted searches with limit=0 will work please replace
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose * 100 with 0. */
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose name_and_cert_ctx->list_ctx = ifp_list_ctx_new(sbus_req, ctx,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose name_and_cert_ctx->derb64,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose 100);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (name_and_cert_ctx->list_ctx == NULL) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return ENOMEM;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (name_and_cert_ctx->name != NULL) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose req = cache_req_user_by_name_send(sbus_req, ctx->rctx->ev, ctx->rctx,
cee85e8fb9534ec997e5388fce59f392cf029573Jakub Hrozek ctx->rctx->ncache, 0,
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek CACHE_REQ_ANY_DOM,
cee85e8fb9534ec997e5388fce59f392cf029573Jakub Hrozek NULL,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose name_and_cert_ctx->name);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (req == NULL) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return ENOMEM;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose tevent_req_set_callback(req, ifp_users_find_by_name_and_cert_name_done,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose name_and_cert_ctx);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose } else {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose ret = ifp_users_find_by_name_and_cert_step(name_and_cert_ctx);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (ret != EOK) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return ret;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return EOK;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose}
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bosestatic void ifp_users_find_by_name_and_cert_name_done(struct tevent_req *req)
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose{
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose DBusError *error;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct name_and_cert_ctx *name_and_cert_ctx = NULL;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct sbus_request *sbus_req;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct cache_req_result *result;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose errno_t ret;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose name_and_cert_ctx = tevent_req_callback_data(req, struct name_and_cert_ctx);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose sbus_req = name_and_cert_ctx->sbus_req;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose ret = cache_req_user_by_name_recv(name_and_cert_ctx, req, &result);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose talloc_zfree(req);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (ret == ENOENT) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose error = sbus_error_new(sbus_req, SBUS_ERROR_NOT_FOUND,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose "User not found");
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose goto fail;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose } else if (ret != EOK) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose "Failed to fetch user [%d]: %s\n",
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose ret, sss_strerror(ret));
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose goto fail;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose name_and_cert_ctx->user_opath = ifp_users_build_path_from_msg(
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose name_and_cert_ctx,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose result->domain,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose result->msgs[0]);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (name_and_cert_ctx->user_opath == NULL) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose error = sbus_error_new(sbus_req, SBUS_ERROR_INTERNAL,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose "Failed to compose object path");
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose goto fail;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (name_and_cert_ctx->list_ctx != NULL) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose ret = ifp_users_find_by_name_and_cert_step(name_and_cert_ctx);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (ret != EOK) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose "Failed to fetch certificate [%d]: %s\n",
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose ret, sss_strerror(ret));
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose goto fail;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose } else {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose ifp_users_find_by_name_and_cert_reply(name_and_cert_ctx);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bosefail:
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose sbus_request_fail_and_finish(sbus_req, error);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose}
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bosestatic int ifp_users_find_by_name_and_cert_step(
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct name_and_cert_ctx *name_and_cert_ctx)
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose{
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct tevent_req *req;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct ifp_list_ctx *list_ctx = name_and_cert_ctx->list_ctx;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose req = cache_req_user_by_cert_send(list_ctx,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose list_ctx->ctx->rctx->ev,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose list_ctx->ctx->rctx,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose list_ctx->ctx->rctx->ncache,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose 0,
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek CACHE_REQ_ANY_DOM,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose list_ctx->dom->name,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose list_ctx->filter);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (req == NULL) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return ENOMEM;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose tevent_req_set_callback(req, ifp_users_find_by_name_and_cert_done,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose name_and_cert_ctx);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return EOK;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose}
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bosestatic void ifp_users_find_by_name_and_cert_done(struct tevent_req *req)
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose{
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose DBusError *error;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct name_and_cert_ctx *name_and_cert_ctx;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct ifp_list_ctx *list_ctx;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct sbus_request *sbus_req;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct cache_req_result *result;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose errno_t ret;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose name_and_cert_ctx = tevent_req_callback_data(req, struct name_and_cert_ctx);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose list_ctx = name_and_cert_ctx->list_ctx;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose sbus_req = list_ctx->sbus_req;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose ret = cache_req_user_by_cert_recv(name_and_cert_ctx, req, &result);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose talloc_zfree(req);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (ret != EOK && ret != ENOENT) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose "Failed to fetch user [%d]: %s\n",
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose ret, sss_strerror(ret));
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose sbus_request_fail_and_finish(sbus_req, error);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (ret == EOK) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose ret = ifp_users_list_copy(list_ctx, result->ldb_result);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (ret != EOK) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose error = sbus_error_new(sbus_req, SBUS_ERROR_INTERNAL,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose "Failed to copy domain result");
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose sbus_request_fail_and_finish(sbus_req, error);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose list_ctx->dom = get_next_domain(list_ctx->dom, SSS_GND_DESCEND);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (list_ctx->dom == NULL) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return ifp_users_find_by_name_and_cert_reply(name_and_cert_ctx);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose ret = ifp_users_find_by_name_and_cert_step(name_and_cert_ctx);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (ret != EOK) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose error = sbus_error_new(sbus_req, SBUS_ERROR_INTERNAL,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose "Failed to start next-domain search");
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose sbus_request_fail_and_finish(sbus_req, error);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose}
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bosestatic void ifp_users_find_by_name_and_cert_reply(
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct name_and_cert_ctx *name_and_cert_ctx)
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose{
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct sbus_request *sbus_req = name_and_cert_ctx->sbus_req;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose struct ifp_list_ctx *list_ctx = name_and_cert_ctx->list_ctx;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose DBusError *error;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose size_t c;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose /* If no name was given check if there is only one user mapped to the
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose * certificate and return its object path. Either no or more than one
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose * mapped users are errors in this case.
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose * The case where a given name could not be found is already handled in
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose * ifp_users_find_by_name_and_cert_name_done(). */
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (name_and_cert_ctx->user_opath == NULL) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (list_ctx == NULL || list_ctx->path_count == 0) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose error = sbus_error_new(sbus_req, SBUS_ERROR_NOT_FOUND,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose "User not found");
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose sbus_request_fail_and_finish(sbus_req, error);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose } else if (list_ctx->path_count == 1) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose iface_ifp_users_FindByNameAndCertificate_finish(sbus_req,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose list_ctx->paths[0]);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose } else {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose error = sbus_error_new(sbus_req, SBUS_ERROR_MORE_THAN_ONE,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose "More than one user found. "
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose "Use ListByCertificate to get all.");
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose sbus_request_fail_and_finish(sbus_req, error);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose /* If there was no certficate given just return the object path of the
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose * user found by name. If a certificate was given an no mapped user was
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose * found return an error. */
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (list_ctx == NULL || list_ctx->path_count == 0) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (name_and_cert_ctx->derb64 == NULL) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose iface_ifp_users_FindByNameAndCertificate_finish(sbus_req,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose name_and_cert_ctx->user_opath);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose } else {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose error = sbus_error_new(sbus_req, SBUS_ERROR_NOT_FOUND,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose "No user matching name and certificate "
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose "found");
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose sbus_request_fail_and_finish(sbus_req, error);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose /* Check if the user found by name is one of the users mapped to the
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose * certificate. */
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose for (c = 0; c < list_ctx->path_count; c++) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose if (strcmp(name_and_cert_ctx->user_opath, list_ctx->paths[c]) == 0) {
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose iface_ifp_users_FindByNameAndCertificate_finish(sbus_req,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose name_and_cert_ctx->user_opath);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose }
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose /* A user was found by name but the certificate is mapped to one or more
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose * different users. */
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose error = sbus_error_new(sbus_req, SBUS_ERROR_NOT_FOUND,
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose "No user matching name and certificate found");
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose sbus_request_fail_and_finish(sbus_req, error);
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose /* name_and_cert_ctx is already freed because sbus_req (the parent) is
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose * already freed by the DBus finish calls */
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose return;
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose}
ef55b0e470a8fbcf6e6d0a55883145e02a907842Sumit Bose
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozekstatic int ifp_users_list_by_name_step(struct ifp_list_ctx *list_ctx);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozekstatic void ifp_users_list_by_name_done(struct tevent_req *req);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozekstatic void ifp_users_list_by_name_reply(struct ifp_list_ctx *list_ctx);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březinaint ifp_users_list_by_name(struct sbus_request *sbus_req,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina void *data,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina const char *filter,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina uint32_t limit)
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina{
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek struct ifp_ctx *ctx;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek struct ifp_list_ctx *list_ctx;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek ctx = talloc_get_type(data, struct ifp_ctx);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek if (ctx == NULL) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek return ERR_INTERNAL;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx = ifp_list_ctx_new(sbus_req, ctx, filter, limit);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek if (list_ctx == NULL) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek return ENOMEM;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek return ifp_users_list_by_name_step(list_ctx);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek}
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozekstatic int ifp_users_list_by_name_step(struct ifp_list_ctx *list_ctx)
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek{
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek struct tevent_req *req;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek req = cache_req_user_by_filter_send(list_ctx,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx->ctx->rctx->ev,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx->ctx->rctx,
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek CACHE_REQ_ANY_DOM,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx->dom->name,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx->filter);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek if (req == NULL) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek return ENOMEM;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek tevent_req_set_callback(req,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek ifp_users_list_by_name_done, list_ctx);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina return EOK;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina}
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozekstatic void ifp_users_list_by_name_done(struct tevent_req *req)
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek{
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek DBusError *error;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek struct ifp_list_ctx *list_ctx;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek struct sbus_request *sbus_req;
b010f24f4d96d15c5c85021bb4aa83db25cd3df5Jakub Hrozek struct cache_req_result *result = NULL;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek errno_t ret;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx = tevent_req_callback_data(req, struct ifp_list_ctx);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek sbus_req = list_ctx->sbus_req;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina ret = cache_req_user_by_name_recv(sbus_req, req, &result);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek talloc_zfree(req);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek if (ret != EOK && ret != ENOENT) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED, "Failed to fetch "
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek "users by filter [%d]: %s\n", ret, sss_strerror(ret));
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek sbus_request_fail_and_finish(sbus_req, error);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek return;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
b010f24f4d96d15c5c85021bb4aa83db25cd3df5Jakub Hrozek if (ret == EOK) {
b010f24f4d96d15c5c85021bb4aa83db25cd3df5Jakub Hrozek ret = ifp_users_list_copy(list_ctx, result->ldb_result);
b010f24f4d96d15c5c85021bb4aa83db25cd3df5Jakub Hrozek if (ret != EOK) {
b010f24f4d96d15c5c85021bb4aa83db25cd3df5Jakub Hrozek error = sbus_error_new(sbus_req, SBUS_ERROR_INTERNAL,
b010f24f4d96d15c5c85021bb4aa83db25cd3df5Jakub Hrozek "Failed to copy domain result");
b010f24f4d96d15c5c85021bb4aa83db25cd3df5Jakub Hrozek sbus_request_fail_and_finish(sbus_req, error);
b010f24f4d96d15c5c85021bb4aa83db25cd3df5Jakub Hrozek return;
b010f24f4d96d15c5c85021bb4aa83db25cd3df5Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek list_ctx->dom = get_next_domain(list_ctx->dom, SSS_GND_DESCEND);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek if (list_ctx->dom == NULL) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek return ifp_users_list_by_name_reply(list_ctx);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek ret = ifp_users_list_by_name_step(list_ctx);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek if (ret != EOK) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek error = sbus_error_new(sbus_req, SBUS_ERROR_INTERNAL,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek "Failed to start next-domain search");
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek sbus_request_fail_and_finish(sbus_req, error);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek return;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek}
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozekstatic void ifp_users_list_by_name_reply(struct ifp_list_ctx *list_ctx)
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek{
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek iface_ifp_users_ListByName_finish(list_ctx->sbus_req,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx->paths,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx->path_count);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek}
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozekstatic void ifp_users_list_by_domain_and_name_done(struct tevent_req *req);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březinaint ifp_users_list_by_domain_and_name(struct sbus_request *sbus_req,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina void *data,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina const char *domain,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina const char *filter,
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina uint32_t limit)
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina{
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek struct tevent_req *req;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek struct ifp_ctx *ctx;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek struct ifp_list_ctx *list_ctx;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek ctx = talloc_get_type(data, struct ifp_ctx);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek if (ctx == NULL) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek return ERR_INTERNAL;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx = ifp_list_ctx_new(sbus_req, ctx, filter, limit);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek if (list_ctx == NULL) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek return ENOMEM;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek req = cache_req_user_by_filter_send(list_ctx, ctx->rctx->ev, ctx->rctx,
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek CACHE_REQ_ANY_DOM,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek domain, filter);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek if (req == NULL) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek return ENOMEM;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek tevent_req_set_callback(req,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek ifp_users_list_by_domain_and_name_done, list_ctx);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina return EOK;
c747b0c875785ce693f70b50bdda0237c4b04e35Pavel Březina}
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozekstatic void ifp_users_list_by_domain_and_name_done(struct tevent_req *req)
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek{
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek DBusError *error;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek struct ifp_list_ctx *list_ctx;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek struct sbus_request *sbus_req;
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina struct cache_req_result *result;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek errno_t ret;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek size_t copy_count, i;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx = tevent_req_callback_data(req, struct ifp_list_ctx);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek sbus_req = list_ctx->sbus_req;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina ret = cache_req_user_by_name_recv(sbus_req, req, &result);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek talloc_zfree(req);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek if (ret == ENOENT) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek error = sbus_error_new(sbus_req, SBUS_ERROR_NOT_FOUND,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek "User not found by filter");
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek goto done;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek } else if (ret != EOK) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED, "Failed to fetch "
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek "users by filter [%d]: %s\n", ret, sss_strerror(ret));
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek goto done;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio ret = ifp_list_ctx_remaining_capacity(list_ctx, result->count, &copy_count);
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio if (ret != EOK) {
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio error = sbus_error_new(sbus_req, SBUS_ERROR_INTERNAL,
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio "Failed to get the list remaining capacity\n");
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio goto done;
5d855b5d546eb995023d80d61433bbe91888dbdfFabiano Fidêncio }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek for (i = 0; i < copy_count; i++) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx->paths[i] = ifp_users_build_path_from_msg(list_ctx->paths,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx->dom,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek result->msgs[i]);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek if (list_ctx->paths[i] == NULL) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek error = sbus_error_new(sbus_req, SBUS_ERROR_INTERNAL,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek "Failed to compose object path");
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek goto done;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx->path_count += copy_count;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozekdone:
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek if (ret != EOK) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek sbus_request_fail_and_finish(sbus_req, error);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek return;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek iface_ifp_users_ListByDomainAndName_finish(sbus_req,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx->paths,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek list_ctx->path_count);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek return;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek}
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozekstatic errno_t
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozekifp_users_get_from_cache(struct sbus_request *sbus_req,
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek struct sss_domain_info *domain,
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek const char *key,
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek struct ldb_message **_user)
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek{
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek struct ldb_result *user_res;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek errno_t ret;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek uid_t uid;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek switch (domain->type) {
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek case DOM_TYPE_POSIX:
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek uid = strtouint32(key, NULL, 10);
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek ret = errno;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek if (ret != EOK) {
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Invalid UID value\n");
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek return ret;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek }
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek ret = sysdb_getpwuid_with_views(sbus_req, domain, uid, &user_res);
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek if (ret == EOK && user_res->count == 0) {
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek *_user = NULL;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek return ENOENT;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek } else if (ret != EOK) {
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Unable to lookup user %u@%s [%d]: %s\n",
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek uid, domain->name, ret, sss_strerror(ret));
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek return ret;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek }
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek break;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek case DOM_TYPE_APPLICATION:
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek ret = sysdb_getpwnam_with_views(sbus_req, domain, key, &user_res);
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek if (ret == EOK && user_res->count == 0) {
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek *_user = NULL;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek return ENOENT;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek } else if (ret != EOK) {
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Unable to lookup user %s@%s [%d]: %s\n",
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek key, domain->name, ret, sss_strerror(ret));
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek return ret;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek }
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek break;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek }
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek if (user_res->count > 1) {
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "More users matched by the single key\n");
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek return EIO;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek }
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek *_user = user_res->msgs[0];
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek return EOK;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek}
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinastatic errno_t
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinaifp_users_user_get(struct sbus_request *sbus_req,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct ifp_ctx *ifp_ctx,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct sss_domain_info **_domain,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct ldb_message **_user)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina{
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct sss_domain_info *domain;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek char *key;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina errno_t ret;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek ret = ifp_users_decompose_path(sbus_req,
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek ifp_ctx->rctx->domains, sbus_req->path,
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek &domain, &key);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (ret != EOK) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to decompose object path"
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina "[%s] [%d]: %s\n", sbus_req->path, ret, sss_strerror(ret));
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return ret;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (_user != NULL) {
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek ret = ifp_users_get_from_cache(sbus_req, domain, key, _user);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (ret == EOK || ret == ENOENT) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (_domain != NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina *_domain = domain;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek } else if (ret != EOK) {
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Unable to retrieve user from cache\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return ret;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina}
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinastatic void ifp_users_get_as_string(struct sbus_request *sbus_req,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina void *data,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char *attr,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char **_out)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina{
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct ifp_ctx *ifp_ctx;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct ldb_message *msg;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct sss_domain_info *domain;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina errno_t ret;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina *_out = NULL;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina ifp_ctx = talloc_get_type(data, struct ifp_ctx);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (ifp_ctx == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (!ifp_is_user_attr_allowed(ifp_ctx, attr)) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_TRACE_ALL, "Attribute %s is not allowed\n", attr);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek ret = ifp_users_user_get(sbus_req, ifp_ctx, &domain, &msg);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (ret != EOK) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina *_out = sss_view_ldb_msg_find_attr_as_string(domain, msg, attr, NULL);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina}
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozekstatic void ifp_users_get_name(struct sbus_request *sbus_req,
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek void *data,
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek const char *attr,
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek const char **_out)
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek{
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek struct ifp_ctx *ifp_ctx;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek struct ldb_message *msg;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek struct sss_domain_info *domain;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek const char *in_name;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek errno_t ret;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek *_out = NULL;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek ifp_ctx = talloc_get_type(data, struct ifp_ctx);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek if (ifp_ctx == NULL) {
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek return;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek }
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek if (!ifp_is_user_attr_allowed(ifp_ctx, attr)) {
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek DEBUG(SSSDBG_TRACE_ALL, "Attribute %s is not allowed\n", attr);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek return;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek }
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek ret = ifp_users_user_get(sbus_req, ifp_ctx, &domain, &msg);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek if (ret != EOK) {
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek return;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek }
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek in_name = sss_view_ldb_msg_find_attr_as_string(domain, msg, attr, NULL);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek if (in_name == NULL) {
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "No name?\n");
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek return;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek }
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek *_out = ifp_format_name_attr(sbus_req, ifp_ctx, in_name, domain);
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek return;
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek}
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinastatic void ifp_users_get_as_uint32(struct sbus_request *sbus_req,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina void *data,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char *attr,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina uint32_t *_out)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina{
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct ifp_ctx *ifp_ctx;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct ldb_message *msg;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct sss_domain_info *domain;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina errno_t ret;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina *_out = 0;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina ifp_ctx = talloc_get_type(data, struct ifp_ctx);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (ifp_ctx == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (!ifp_is_user_attr_allowed(ifp_ctx, attr)) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_TRACE_ALL, "Attribute %s is not allowed\n", attr);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek ret = ifp_users_user_get(sbus_req, ifp_ctx, &domain, &msg);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (ret != EOK) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina *_out = sss_view_ldb_msg_find_attr_as_uint64(domain, msg, attr, 0);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina}
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinastatic void ifp_users_user_update_groups_list_done(struct tevent_req *req);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinaint ifp_users_user_update_groups_list(struct sbus_request *sbus_req,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina void *data)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina{
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct tevent_req *req;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct ifp_ctx *ctx;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct sss_domain_info *domain;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char *username;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct ldb_message *user;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina errno_t ret;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina ctx = talloc_get_type(data, struct ifp_ctx);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (ctx == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return ERR_INTERNAL;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek ret = ifp_users_user_get(sbus_req, data, &domain, &user);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (ret != EOK) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return ret;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina username = ldb_msg_find_attr_as_string(user, SYSDB_NAME, NULL);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (username == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "User name is empty!\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return ERR_INTERNAL;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina req = cache_req_initgr_by_name_send(sbus_req, ctx->rctx->ev, ctx->rctx,
cee85e8fb9534ec997e5388fce59f392cf029573Jakub Hrozek ctx->rctx->ncache, 0,
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek CACHE_REQ_ANY_DOM, domain->name,
11a87c5f091d6c092b5dadd3d67f900213e280daPetr Cech username);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (req == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return ENOMEM;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina tevent_req_set_callback(req, ifp_users_user_update_groups_list_done,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina sbus_req);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return EOK;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina}
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinastatic void ifp_users_user_update_groups_list_done(struct tevent_req *req)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina{
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DBusError *error;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct sbus_request *sbus_req;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina errno_t ret;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina sbus_req = tevent_req_callback_data(req, struct sbus_request);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina ret = cache_req_initgr_by_name_recv(sbus_req, req, NULL);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina talloc_zfree(req);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (ret == ENOENT) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina error = sbus_error_new(sbus_req, SBUS_ERROR_NOT_FOUND,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina "User not found");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina goto done;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina } else if (ret != EOK) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED, "Failed to fetch "
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina "user [%d]: %s\n", ret, sss_strerror(ret));
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina goto done;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinadone:
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (ret != EOK) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina sbus_request_fail_and_finish(sbus_req, error);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina iface_ifp_users_user_UpdateGroupsList_finish(sbus_req);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina}
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinavoid ifp_users_user_get_name(struct sbus_request *sbus_req,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina void *data,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char **_out)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina{
d0faaf01fd24a935d9779032886d228b3861fa48Jakub Hrozek ifp_users_get_name(sbus_req, data, SYSDB_NAME, _out);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina}
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinavoid ifp_users_user_get_uid_number(struct sbus_request *sbus_req,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina void *data,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina uint32_t *_out)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina{
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina ifp_users_get_as_uint32(sbus_req, data, SYSDB_UIDNUM, _out);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina}
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinavoid ifp_users_user_get_gid_number(struct sbus_request *sbus_req,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina void *data,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina uint32_t *_out)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina{
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina ifp_users_get_as_uint32(sbus_req, data, SYSDB_GIDNUM, _out);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina}
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinavoid ifp_users_user_get_gecos(struct sbus_request *sbus_req,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina void *data,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char **_out)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina{
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina ifp_users_get_as_string(sbus_req, data, SYSDB_GECOS, _out);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina}
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinavoid ifp_users_user_get_home_directory(struct sbus_request *sbus_req,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina void *data,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char **_out)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina{
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina ifp_users_get_as_string(sbus_req, data, SYSDB_HOMEDIR, _out);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina}
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinavoid ifp_users_user_get_login_shell(struct sbus_request *sbus_req,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina void *data,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char **_out)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina{
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina ifp_users_get_as_string(sbus_req, data, SYSDB_SHELL, _out);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina}
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
e9a2e7afbd09c23dd8748246e09831ed7b17d7c5Thomas Equetervoid ifp_users_user_get_unique_id(struct sbus_request *sbus_req,
e9a2e7afbd09c23dd8748246e09831ed7b17d7c5Thomas Equeter void *data,
e9a2e7afbd09c23dd8748246e09831ed7b17d7c5Thomas Equeter const char **_out)
e9a2e7afbd09c23dd8748246e09831ed7b17d7c5Thomas Equeter{
e9a2e7afbd09c23dd8748246e09831ed7b17d7c5Thomas Equeter ifp_users_get_as_string(sbus_req, data, SYSDB_UUID, _out);
e9a2e7afbd09c23dd8748246e09831ed7b17d7c5Thomas Equeter}
e9a2e7afbd09c23dd8748246e09831ed7b17d7c5Thomas Equeter
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinavoid ifp_users_user_get_groups(struct sbus_request *sbus_req,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina void *data,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char ***_out,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina int *_size)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina{
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct ifp_ctx *ifp_ctx;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct sss_domain_info *domain;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char *username;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct ldb_message *user;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct ldb_result *res;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char **out;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina int num_groups;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina gid_t gid;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina errno_t ret;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina int i;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina *_out = NULL;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina *_size = 0;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina ifp_ctx = talloc_get_type(data, struct ifp_ctx);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (ifp_ctx == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (!ifp_is_user_attr_allowed(ifp_ctx, "groups")) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_TRACE_ALL, "Attribute %s is not allowed\n",
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina SYSDB_MEMBEROF);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek ret = ifp_users_user_get(sbus_req, ifp_ctx, &domain, &user);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (ret != EOK) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina username = ldb_msg_find_attr_as_string(user, SYSDB_NAME, NULL);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (username == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "User name is empty!\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina /* Run initgroups. */
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina ret = sysdb_initgroups_with_views(sbus_req, domain, username, &res);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (ret != EOK) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get groups for %s@%s [%d]: %s\n",
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina username, domain->name, ret, sss_strerror(ret));
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (res->count == 0) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina out = talloc_zero_array(sbus_req, const char *, res->count);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (out == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero_array() failed\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina num_groups = 0;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina for (i = 0; i < res->count; i++) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina gid = sss_view_ldb_msg_find_attr_as_uint64(domain, res->msgs[i],
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina SYSDB_GIDNUM, 0);
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek if (gid == 0 && domain->type == DOM_TYPE_POSIX) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina continue;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
788146c3e3a564f333f39a2fcffccf3012cc2679Jakub Hrozek out[num_groups] = ifp_groups_build_path_from_msg(out,
788146c3e3a564f333f39a2fcffccf3012cc2679Jakub Hrozek domain,
788146c3e3a564f333f39a2fcffccf3012cc2679Jakub Hrozek res->msgs[i]);
788146c3e3a564f333f39a2fcffccf3012cc2679Jakub Hrozek if (out[num_groups] == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "ifp_groups_build_path() failed\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina num_groups++;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina *_out = out;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina *_size = num_groups;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina}
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březinavoid ifp_users_user_get_domain(struct sbus_request *sbus_req,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina void *data,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina const char **_out)
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina{
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina const char *domainname;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina *_out = NULL;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina ifp_users_user_get_domainname(sbus_req, data, &domainname);
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina if (domainname == NULL) {
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina return;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina }
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina *_out = sbus_opath_compose(sbus_req, IFP_PATH_DOMAINS,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina domainname);
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina}
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březinavoid ifp_users_user_get_domainname(struct sbus_request *sbus_req,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina void *data,
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina const char **_out)
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina{
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina struct ifp_ctx *ifp_ctx;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina struct sss_domain_info *domain;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina errno_t ret;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina *_out = NULL;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina ifp_ctx = talloc_get_type(data, struct ifp_ctx);
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina if (ifp_ctx == NULL) {
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina return;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina }
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina if (!ifp_is_user_attr_allowed(ifp_ctx, "domainname")) {
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina DEBUG(SSSDBG_TRACE_ALL, "Attribute domainname is not allowed\n");
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina return;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina }
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina ret = ifp_users_user_get(sbus_req, ifp_ctx, &domain, NULL);
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina if (ret != EOK) {
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina return;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina }
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina *_out = domain->name;
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina}
37d2194cc9ea4d0254c88a3419e2376572562babPavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březinavoid ifp_users_user_get_extra_attributes(struct sbus_request *sbus_req,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina void *data,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina hash_table_t **_out)
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina{
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct ifp_ctx *ifp_ctx;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct sss_domain_info *domain;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek struct ldb_message *base_user;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek const char *name;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct ldb_message **user;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct ldb_message_element *el;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina struct ldb_dn *basedn;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina size_t count;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char *filter;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char **extra;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina hash_table_t *table;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina hash_key_t key;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina hash_value_t value;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina const char **values;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina errno_t ret;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina int hret;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina int i;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina *_out = NULL;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina ifp_ctx = talloc_get_type(data, struct ifp_ctx);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (ifp_ctx == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina extra = ifp_get_user_extra_attributes(sbus_req, ifp_ctx);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (extra == NULL || extra[0] == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_TRACE_ALL, "No extra attributes to return\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek ret = ifp_users_user_get(sbus_req, data, &domain, &base_user);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (ret != EOK) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina basedn = sysdb_user_base_dn(sbus_req, domain);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (basedn == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_user_base_dn() failed\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek name = ldb_msg_find_attr_as_string(base_user, SYSDB_NAME, NULL);
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek if (name == NULL) {
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "A user with no name\n");
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek return;
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek }
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek filter = talloc_asprintf(sbus_req, "(&(%s=%s)(%s=%s))",
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose SYSDB_OBJECTCATEGORY, SYSDB_USER_CLASS,
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek SYSDB_NAME, name);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (filter == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_asprintf() failed\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina ret = sysdb_search_entry(sbus_req, domain->sysdb, basedn,
98195e591c4d97caa6125e8214879660b740973fSumit Bose LDB_SCOPE_SUBTREE, filter,
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina extra, &count, &user);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (ret != EOK) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to lookup user [%d]: %s\n",
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina ret, sss_strerror(ret));
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (count == 0) {
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "User %s not found!\n", name);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina } else if (count > 1) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "More than one entry found!\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina ret = sss_hash_create(sbus_req, 10, &table);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (ret != EOK) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create hash table!\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina /* Read each extra attribute. */
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina for (i = 0; extra[i] != NULL; i++) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina el = ldb_msg_find_element(user[0], extra[i]);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (el == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_TRACE_ALL, "Attribute %s not found, skipping...\n",
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina extra[i]);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina continue;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina values = sss_ldb_el_to_string_list(table, el);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (values == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "sss_ldb_el_to_string_list() failed\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina key.type = HASH_KEY_STRING;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina key.str = talloc_strdup(table, extra[i]);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (key.str == NULL) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_strdup() failed\n");
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina value.type = HASH_VALUE_PTR;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina value.ptr = values;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina hret = hash_enter(table, &key, &value);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina if (hret != HASH_SUCCESS) {
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to insert entry "
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina "into hash table: %d\n", hret);
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina return;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina }
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina *_out = table;
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina}
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březinaint ifp_cache_list_user(struct sbus_request *sbus_req,
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina void *data)
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina{
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina return ifp_cache_list(sbus_req, data, IFP_CACHE_USER);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina}
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březinaint ifp_cache_list_by_domain_user(struct sbus_request *sbus_req,
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina void *data,
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina const char *domain)
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina{
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina return ifp_cache_list_by_domain(sbus_req, data, domain, IFP_CACHE_USER);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina}
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březinaint ifp_cache_object_store_user(struct sbus_request *sbus_req,
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina void *data)
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina{
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina DBusError *error;
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina struct sss_domain_info *domain;
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina struct ldb_message *user;
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina errno_t ret;
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek ret = ifp_users_user_get(sbus_req, data, &domain, &user);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina if (ret != EOK) {
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED, "Failed to fetch "
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina "user [%d]: %s\n", ret, sss_strerror(ret));
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina return sbus_request_fail_and_finish(sbus_req, error);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina }
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina /* The request is finished inside. */
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina return ifp_cache_object_store(sbus_req, domain, user->dn);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina}
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březinaint ifp_cache_object_remove_user(struct sbus_request *sbus_req,
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina void *data)
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina{
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina DBusError *error;
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina struct sss_domain_info *domain;
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina struct ldb_message *user;
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina errno_t ret;
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina
35f0f5ff9dac790f6c947190fcdc00d01ae9077cJakub Hrozek ret = ifp_users_user_get(sbus_req, data, &domain, &user);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina if (ret != EOK) {
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina error = sbus_error_new(sbus_req, DBUS_ERROR_FAILED, "Failed to fetch "
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina "user [%d]: %s\n", ret, sss_strerror(ret));
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina return sbus_request_fail_and_finish(sbus_req, error);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina }
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina /* The request is finished inside. */
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina return ifp_cache_object_remove(sbus_req, domain, user->dn);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina}