8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny/*
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny SSSD
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny IPA Identity Backend Module
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny Authors:
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny Jan Zeleny <jzeleny@redhat.com>
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny Copyright (C) 2011 Red Hat
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny This program is free software; you can redistribute it and/or modify
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny it under the terms of the GNU General Public License as published by
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny the Free Software Foundation; either version 3 of the License, or
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny (at your option) any later version.
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny This program is distributed in the hope that it will be useful,
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny but WITHOUT ANY WARRANTY; without even the implied warranty of
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny GNU General Public License for more details.
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny You should have received a copy of the GNU General Public License
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny along with this program. If not, see <http://www.gnu.org/licenses/>.
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny*/
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny#include <errno.h>
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny#include "util/util.h"
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny#include "db/sysdb.h"
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny#include "providers/ldap/ldap_common.h"
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny#include "providers/ldap/sdap_async.h"
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny#include "providers/ipa/ipa_id.h"
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic struct tevent_req *
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaipa_id_get_account_info_send(TALLOC_CTX *memctx, struct tevent_context *ev,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct ipa_id_ctx *ipa_ctx,
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *ar);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic int ipa_id_get_account_info_recv(struct tevent_req *req, int *dp_error);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
3d29430867cf92b2d71afa95abb679711231117cPavel Březinastatic bool is_object_overridable(struct dp_id_data *ar)
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech{
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech bool ret = false;
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech switch (ar->entry_type & BE_REQ_TYPE_MASK) {
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech case BE_REQ_USER:
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech case BE_REQ_GROUP:
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech case BE_REQ_INITGROUPS:
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech case BE_REQ_BY_SECID:
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech case BE_REQ_USER_AND_GROUP:
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech case BE_REQ_BY_UUID:
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech case BE_REQ_BY_CERT:
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech ret = true;
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech break;
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech default:
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech break;
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech }
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech return ret;
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech}
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bosestruct ipa_resolve_user_list_state {
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct tevent_context *ev;
eab17959df71341073f946c533f59fc5e593b35cSumit Bose struct ipa_id_ctx *ipa_ctx;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct ldb_message_element *users;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose const char *domain_name;
7988988aab5bd0249476671b850eb3909aa753f8Sumit Bose struct sss_domain_info *domain;
7988988aab5bd0249476671b850eb3909aa753f8Sumit Bose struct sss_domain_info *user_domain;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose size_t user_idx;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose int dp_error;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose};
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bosestatic errno_t ipa_resolve_user_list_get_user_step(struct tevent_req *req);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bosestatic void ipa_resolve_user_list_get_user_done(struct tevent_req *subreq);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
f2e8a7c3230fac11175c0bd17c14c66a8e9b25adSumit Bosestruct tevent_req *
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Boseipa_resolve_user_list_send(TALLOC_CTX *memctx, struct tevent_context *ev,
eab17959df71341073f946c533f59fc5e593b35cSumit Bose struct ipa_id_ctx *ipa_ctx,
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose const char *domain_name,
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct ldb_message_element *users)
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose{
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose int ret;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct tevent_req *req;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct ipa_resolve_user_list_state *state;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose req = tevent_req_create(memctx, &state,
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct ipa_resolve_user_list_state);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose if (req == NULL) {
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "tevent_req_create failed.\n");
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose return NULL;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose state->ev = ev;
eab17959df71341073f946c533f59fc5e593b35cSumit Bose state->ipa_ctx = ipa_ctx;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose state->domain_name = domain_name;
7988988aab5bd0249476671b850eb3909aa753f8Sumit Bose state->domain = find_domain_by_name(state->ipa_ctx->sdap_id_ctx->be->domain,
7988988aab5bd0249476671b850eb3909aa753f8Sumit Bose state->domain_name, true);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose state->users = users;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose state->user_idx = 0;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose state->dp_error = DP_ERR_FATAL;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose ret = ipa_resolve_user_list_get_user_step(req);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose if (ret == EAGAIN) {
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose return req;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose } else if (ret == EOK) {
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose state->dp_error = DP_ERR_OK;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose tevent_req_done(req);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose } else {
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose "ipa_resolve_user_list_get_user_step failed.\n");
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose tevent_req_error(req, ret);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose tevent_req_post(req, ev);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose return req;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose}
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bosestatic errno_t ipa_resolve_user_list_get_user_step(struct tevent_req *req)
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose{
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose int ret;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct tevent_req *subreq;
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *ar;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct ipa_resolve_user_list_state *state = tevent_req_data(req,
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct ipa_resolve_user_list_state);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose if (state->user_idx >= state->users->num_values) {
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose return EOK;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
3d29430867cf92b2d71afa95abb679711231117cPavel Březina ret = get_dp_id_data_for_user_name(state,
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose (char *) state->users->values[state->user_idx].data,
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose state->domain_name, &ar);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose if (ret != EOK) {
3d29430867cf92b2d71afa95abb679711231117cPavel Březina DEBUG(SSSDBG_OP_FAILURE, "get_dp_id_data_for_user_name failed.\n");
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose return ret;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose DEBUG(SSSDBG_TRACE_ALL, "Trying to resolve user [%s].\n", ar->filter_value);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
7988988aab5bd0249476671b850eb3909aa753f8Sumit Bose state->user_domain = find_domain_by_object_name_ex(
7988988aab5bd0249476671b850eb3909aa753f8Sumit Bose state->ipa_ctx->sdap_id_ctx->be->domain,
7988988aab5bd0249476671b850eb3909aa753f8Sumit Bose ar->filter_value, true);
4a9c1047354dbe5a4ed41e5951ae623e3772e113René Genz /* Use provided domain as fallback because no known domain was found in the
7988988aab5bd0249476671b850eb3909aa753f8Sumit Bose * user name. */
7988988aab5bd0249476671b850eb3909aa753f8Sumit Bose if (state->user_domain == NULL) {
7988988aab5bd0249476671b850eb3909aa753f8Sumit Bose state->user_domain = state->domain;
7988988aab5bd0249476671b850eb3909aa753f8Sumit Bose }
7988988aab5bd0249476671b850eb3909aa753f8Sumit Bose ar->domain = state->user_domain->name;
7988988aab5bd0249476671b850eb3909aa753f8Sumit Bose
7988988aab5bd0249476671b850eb3909aa753f8Sumit Bose if (state->user_domain != state->ipa_ctx->sdap_id_ctx->be->domain) {
f2e8a7c3230fac11175c0bd17c14c66a8e9b25adSumit Bose subreq = ipa_subdomain_account_send(state, state->ev, state->ipa_ctx,
f2e8a7c3230fac11175c0bd17c14c66a8e9b25adSumit Bose ar);
f2e8a7c3230fac11175c0bd17c14c66a8e9b25adSumit Bose } else {
f2e8a7c3230fac11175c0bd17c14c66a8e9b25adSumit Bose subreq = ipa_id_get_account_info_send(state, state->ev, state->ipa_ctx,
f2e8a7c3230fac11175c0bd17c14c66a8e9b25adSumit Bose ar);
f2e8a7c3230fac11175c0bd17c14c66a8e9b25adSumit Bose }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose if (subreq == NULL) {
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sdap_handle_acct_req_send failed.\n");
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose return ENOMEM;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose tevent_req_set_callback(subreq, ipa_resolve_user_list_get_user_done, req);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose return EAGAIN;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose}
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bosestatic void ipa_resolve_user_list_get_user_done(struct tevent_req *subreq)
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose{
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct tevent_req *req = tevent_req_callback_data(subreq,
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct tevent_req);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct ipa_resolve_user_list_state *state = tevent_req_data(req,
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct ipa_resolve_user_list_state);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose int ret;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
7988988aab5bd0249476671b850eb3909aa753f8Sumit Bose if (state->user_domain != state->ipa_ctx->sdap_id_ctx->be->domain) {
f2e8a7c3230fac11175c0bd17c14c66a8e9b25adSumit Bose ret = ipa_subdomain_account_recv(subreq, &state->dp_error);
f2e8a7c3230fac11175c0bd17c14c66a8e9b25adSumit Bose } else {
f2e8a7c3230fac11175c0bd17c14c66a8e9b25adSumit Bose ret = ipa_id_get_account_info_recv(subreq, &state->dp_error);
f2e8a7c3230fac11175c0bd17c14c66a8e9b25adSumit Bose }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose talloc_zfree(subreq);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose if (ret != EOK) {
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sdap_handle_acct request failed: %d\n", ret);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose goto done;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose state->user_idx++;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose ret = ipa_resolve_user_list_get_user_step(req);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose if (ret == EAGAIN) {
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose return;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose if (ret != EOK) {
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose "ipa_resolve_user_list_get_user_step failed.\n");
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bosedone:
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose if (ret == EOK) {
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose state->dp_error = DP_ERR_OK;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose tevent_req_done(req);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose } else {
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose if (state->dp_error == DP_ERR_OK) {
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose state->dp_error = DP_ERR_FATAL;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose tevent_req_error(req, ret);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose return;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose}
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
f2e8a7c3230fac11175c0bd17c14c66a8e9b25adSumit Boseint ipa_resolve_user_list_recv(struct tevent_req *req, int *dp_error)
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose{
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct ipa_resolve_user_list_state *state = tevent_req_data(req,
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct ipa_resolve_user_list_state);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose if (dp_error) {
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose *dp_error = state->dp_error;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose TEVENT_REQ_RETURN_ON_ERROR(req);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose return EOK;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose}
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozekstruct ipa_initgr_get_overrides_state {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct tevent_context *ev;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct ipa_id_ctx *ipa_ctx;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct sss_domain_info *user_dom;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek const char *realm;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct ldb_message **groups;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek size_t group_count;
145578006684481434ced78461ab8d1c3570f478Sumit Bose const char *groups_id_attr;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek size_t group_idx;
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *ar;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek int dp_error;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek};
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozekstatic int ipa_initgr_get_overrides_step(struct tevent_req *req);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
145578006684481434ced78461ab8d1c3570f478Sumit Bosestruct tevent_req *
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozekipa_initgr_get_overrides_send(TALLOC_CTX *memctx,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct tevent_context *ev,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct ipa_id_ctx *ipa_ctx,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct sss_domain_info *user_dom,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek size_t groups_count,
145578006684481434ced78461ab8d1c3570f478Sumit Bose struct ldb_message **groups,
145578006684481434ced78461ab8d1c3570f478Sumit Bose const char *groups_id_attr)
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek{
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek int ret;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct tevent_req *req;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct ipa_initgr_get_overrides_state *state;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek req = tevent_req_create(memctx, &state,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct ipa_initgr_get_overrides_state);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (req == NULL) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "tevent_req_create failed.\n");
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek return NULL;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek state->ev = ev;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek state->ipa_ctx = ipa_ctx;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek state->user_dom = user_dom;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek state->groups = groups;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek state->group_count = groups_count;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek state->group_idx = 0;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek state->ar = NULL;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek state->realm = dp_opt_get_string(state->ipa_ctx->ipa_options->basic,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek IPA_KRB5_REALM);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (state->realm == NULL) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "No Kerberos realm for IPA?\n");
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek ret = EINVAL;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek goto done;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
145578006684481434ced78461ab8d1c3570f478Sumit Bose state->groups_id_attr = talloc_strdup(state, groups_id_attr);
145578006684481434ced78461ab8d1c3570f478Sumit Bose if (state->groups_id_attr == NULL) {
145578006684481434ced78461ab8d1c3570f478Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
145578006684481434ced78461ab8d1c3570f478Sumit Bose ret = ENOMEM;
145578006684481434ced78461ab8d1c3570f478Sumit Bose goto done;
145578006684481434ced78461ab8d1c3570f478Sumit Bose }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek ret = ipa_initgr_get_overrides_step(req);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozekdone:
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (ret == EOK) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek tevent_req_done(req);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek tevent_req_post(req, ev);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek } else if (ret != EAGAIN) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek tevent_req_error(req, ret);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek tevent_req_post(req, ev);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek return req;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek}
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozekstatic void ipa_initgr_get_overrides_override_done(struct tevent_req *subreq);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozekstatic int ipa_initgr_get_overrides_step(struct tevent_req *req)
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek{
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek int ret;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct tevent_req *subreq;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek const char *ipa_uuid;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct ipa_initgr_get_overrides_state *state = tevent_req_data(req,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct ipa_initgr_get_overrides_state);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek "Processing group %zu/%zu\n", state->group_idx, state->group_count);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (state->group_idx >= state->group_count) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek return EOK;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek ipa_uuid = ldb_msg_find_attr_as_string(state->groups[state->group_idx],
145578006684481434ced78461ab8d1c3570f478Sumit Bose state->groups_id_attr, NULL);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (ipa_uuid == NULL) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek /* This should never happen, the search filter used to get the list
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek * of groups includes "uuid=*"
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek */
e2d96566aeb881bd89e5c9236d663f6a9a88019aJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
e2d96566aeb881bd89e5c9236d663f6a9a88019aJakub Hrozek "The group %s has no UUID attribute %s, error!\n",
e2d96566aeb881bd89e5c9236d663f6a9a88019aJakub Hrozek ldb_dn_get_linearized(state->groups[state->group_idx]->dn),
e2d96566aeb881bd89e5c9236d663f6a9a88019aJakub Hrozek state->groups_id_attr);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek return EINVAL;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek talloc_free(state->ar); /* Avoid spiking memory with many groups */
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
145578006684481434ced78461ab8d1c3570f478Sumit Bose if (strcmp(state->groups_id_attr, SYSDB_UUID) == 0) {
3d29430867cf92b2d71afa95abb679711231117cPavel Březina ret = get_dp_id_data_for_uuid(state, ipa_uuid,
145578006684481434ced78461ab8d1c3570f478Sumit Bose state->user_dom->name, &state->ar);
145578006684481434ced78461ab8d1c3570f478Sumit Bose if (ret != EOK) {
3d29430867cf92b2d71afa95abb679711231117cPavel Březina DEBUG(SSSDBG_OP_FAILURE, "get_dp_id_data_for_sid failed.\n");
145578006684481434ced78461ab8d1c3570f478Sumit Bose return ret;
145578006684481434ced78461ab8d1c3570f478Sumit Bose }
145578006684481434ced78461ab8d1c3570f478Sumit Bose } else if (strcmp(state->groups_id_attr, SYSDB_SID_STR) == 0) {
3d29430867cf92b2d71afa95abb679711231117cPavel Březina ret = get_dp_id_data_for_sid(state, ipa_uuid,
145578006684481434ced78461ab8d1c3570f478Sumit Bose state->user_dom->name, &state->ar);
145578006684481434ced78461ab8d1c3570f478Sumit Bose if (ret != EOK) {
3d29430867cf92b2d71afa95abb679711231117cPavel Březina DEBUG(SSSDBG_OP_FAILURE, "get_dp_id_data_for_sid failed.\n");
145578006684481434ced78461ab8d1c3570f478Sumit Bose return ret;
145578006684481434ced78461ab8d1c3570f478Sumit Bose }
145578006684481434ced78461ab8d1c3570f478Sumit Bose } else {
145578006684481434ced78461ab8d1c3570f478Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Unsupported groups ID type [%s].\n",
145578006684481434ced78461ab8d1c3570f478Sumit Bose state->groups_id_attr);
145578006684481434ced78461ab8d1c3570f478Sumit Bose return EINVAL;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "Fetching group %s\n", ipa_uuid);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek subreq = ipa_get_ad_override_send(state, state->ev,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek state->ipa_ctx->sdap_id_ctx,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek state->ipa_ctx->ipa_options,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek state->realm,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek state->ipa_ctx->view_name,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek state->ar);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (subreq == NULL) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "ipa_get_ad_override_send failed.\n");
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek return ENOMEM;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek tevent_req_set_callback(subreq,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek ipa_initgr_get_overrides_override_done, req);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek return EAGAIN;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek}
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozekstatic void ipa_initgr_get_overrides_override_done(struct tevent_req *subreq)
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek{
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct tevent_req);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct ipa_initgr_get_overrides_state *state = tevent_req_data(req,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct ipa_initgr_get_overrides_state);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek int ret;
145578006684481434ced78461ab8d1c3570f478Sumit Bose struct sysdb_attrs *override_attrs = NULL;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek ret = ipa_get_ad_override_recv(subreq, &state->dp_error, state,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek &override_attrs);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek talloc_zfree(subreq);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (ret != EOK) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "IPA override lookup failed: %d\n", ret);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek tevent_req_error(req, ret);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek return;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
9ac2a33f4cdc4941fa63118dcffe8058854f33c4Michal Židek if (is_default_view(state->ipa_ctx->view_name)) {
145578006684481434ced78461ab8d1c3570f478Sumit Bose ret = sysdb_apply_default_override(state->user_dom, override_attrs,
145578006684481434ced78461ab8d1c3570f478Sumit Bose state->groups[state->group_idx]->dn);
145578006684481434ced78461ab8d1c3570f478Sumit Bose } else {
145578006684481434ced78461ab8d1c3570f478Sumit Bose ret = sysdb_store_override(state->user_dom,
145578006684481434ced78461ab8d1c3570f478Sumit Bose state->ipa_ctx->view_name,
145578006684481434ced78461ab8d1c3570f478Sumit Bose SYSDB_MEMBER_GROUP,
145578006684481434ced78461ab8d1c3570f478Sumit Bose override_attrs,
145578006684481434ced78461ab8d1c3570f478Sumit Bose state->groups[state->group_idx]->dn);
145578006684481434ced78461ab8d1c3570f478Sumit Bose }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek talloc_free(override_attrs);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (ret != EOK) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "sysdb_store_override failed.\n");
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek tevent_req_error(req, ret);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek return;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek state->group_idx++;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek ret = ipa_initgr_get_overrides_step(req);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (ret == EAGAIN) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek return;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek } else if (ret != EOK) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek tevent_req_error(req, ret);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek return;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek tevent_req_done(req);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek}
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
145578006684481434ced78461ab8d1c3570f478Sumit Boseint ipa_initgr_get_overrides_recv(struct tevent_req *req, int *dp_error)
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek{
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct ipa_initgr_get_overrides_state *state = tevent_req_data(req,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct ipa_initgr_get_overrides_state);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (dp_error) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek *dp_error = state->dp_error;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek return EOK;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek}
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek/* Given a user name, retrieve an array of group UUIDs of groups that have
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek * no overrideDN attribute but do have an UUID attribute.
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek */
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozekstatic errno_t ipa_id_get_group_uuids(TALLOC_CTX *mem_ctx,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct sysdb_ctx *sysdb,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek size_t *_msgs_count,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct ldb_message ***_msgs)
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek{
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek const char *filter;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek TALLOC_CTX *tmp_ctx;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek char **uuid_list = NULL;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek errno_t ret;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct ldb_dn *base_dn;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek const char *attrs[] = { SYSDB_UUID, NULL };
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek size_t msgs_count;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct ldb_message **msgs;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek tmp_ctx = talloc_new(mem_ctx);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (tmp_ctx == NULL) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek return ENOMEM;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek filter = talloc_asprintf(tmp_ctx,
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose "(&(%s=%s)(!(%s=*))(%s=*))",
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose SYSDB_OBJECTCATEGORY,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek SYSDB_GROUP_CLASS, SYSDB_OVERRIDE_DN,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek SYSDB_UUID);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (filter == NULL) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek ret = ENOMEM;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek goto done;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek base_dn = sysdb_base_dn(sysdb, tmp_ctx);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (base_dn == NULL) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek ret = ENOMEM;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek goto done;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek ret = sysdb_search_entry(tmp_ctx, sysdb, base_dn,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek LDB_SCOPE_SUBTREE, filter, attrs,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek &msgs_count, &msgs);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (ret == ENOENT) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek "No groups without %s in sysdb\n", SYSDB_OVERRIDE_DN);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek ret = EOK;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek goto done;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek } else if (ret != EOK) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek goto done;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek uuid_list = talloc_zero_array(tmp_ctx, char *, msgs_count);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (uuid_list == NULL) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek goto done;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek *_msgs_count = msgs_count;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek *_msgs = talloc_steal(mem_ctx, msgs);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek ret = EOK;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozekdone:
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek talloc_free(tmp_ctx);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek return ret;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek}
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bosestruct ipa_id_get_account_info_state {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct tevent_context *ev;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct ipa_id_ctx *ipa_ctx;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct sdap_id_ctx *ctx;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct sdap_id_op *op;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct sysdb_ctx *sysdb;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct sss_domain_info *domain;
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *ar;
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *orig_ar;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose const char *realm;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct sysdb_attrs *override_attrs;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct ldb_message *obj_msg;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct ldb_message_element *ghosts;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct ldb_message **user_groups;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek size_t group_cnt;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek size_t group_idx;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose struct ldb_result *res;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose size_t res_index;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose int dp_error;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose};
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bosestatic void ipa_id_get_account_info_connected(struct tevent_req *subreq);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bosestatic void ipa_id_get_account_info_got_override(struct tevent_req *subreq);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bosestatic errno_t ipa_id_get_account_info_get_original_step(struct tevent_req *req,
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *ar);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bosestatic void ipa_id_get_account_info_orig_done(struct tevent_req *subreq);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bosestatic void ipa_id_get_account_info_done(struct tevent_req *subreq);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bosestatic void ipa_id_get_user_list_done(struct tevent_req *subreq);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bosestatic struct tevent_req *
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Boseipa_id_get_account_info_send(TALLOC_CTX *memctx, struct tevent_context *ev,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct ipa_id_ctx *ipa_ctx,
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *ar)
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose{
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose int ret;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct tevent_req *req;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct tevent_req *subreq;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct ipa_id_get_account_info_state *state;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose req = tevent_req_create(memctx, &state,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct ipa_id_get_account_info_state);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (req == NULL) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "tevent_req_create failed.\n");
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose return NULL;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->ev = ev;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->ipa_ctx = ipa_ctx;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->ctx = ipa_ctx->sdap_id_ctx;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->dp_error = DP_ERR_FATAL;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->op = sdap_id_op_create(state, state->ctx->conn->conn_cache);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (state->op == NULL) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sdap_id_op_create failed.\n");
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ret = ENOMEM;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose goto fail;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->domain = find_domain_by_name(state->ctx->be->domain,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ar->domain, true);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (state->domain == NULL) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "find_domain_by_name failed.\n");
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ret = ENOMEM;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose goto fail;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->sysdb = state->domain->sysdb;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->ar = ar;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->realm = dp_opt_get_string(state->ipa_ctx->ipa_options->basic,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose IPA_KRB5_REALM);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (state->realm == NULL) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "No Kerberos realm for IPA?\n");
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ret = EINVAL;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose goto fail;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose /* We can skip the override lookup and go directly to the original object
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose * if
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose * - the lookup is by SID
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose * - there is no view set of it is the default view
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose * - if the EXTRA_INPUT_MAYBE_WITH_VIEW flag is not set
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose */
9ac2a33f4cdc4941fa63118dcffe8058854f33c4Michal Židek if (is_default_view(state->ipa_ctx->view_name)
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose || state->ar->filter_type == BE_FILTER_SECID
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose || state->ar->extra_value == NULL
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose || strcmp(state->ar->extra_value,
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech EXTRA_INPUT_MAYBE_WITH_VIEW) != 0
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech || ! is_object_overridable(state->ar)) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ret = ipa_id_get_account_info_get_original_step(req, ar);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (ret != EOK) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose "ipa_subdomain_account_get_original_step failed.\n");
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose goto fail;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose } else {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose subreq = sdap_id_op_connect_send(state->op, state, &ret);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (subreq == NULL) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sdap_id_op_connect_send failed.\n");
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose goto fail;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose tevent_req_set_callback(subreq, ipa_id_get_account_info_connected, req);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose return req;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bosefail:
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose tevent_req_error(req, ret);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose tevent_req_post(req, ev);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose return req;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose}
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bosestatic void ipa_id_get_account_info_connected(struct tevent_req *subreq)
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose{
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct tevent_req *req = tevent_req_callback_data(subreq,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct tevent_req);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct ipa_id_get_account_info_state *state = tevent_req_data(req,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct ipa_id_get_account_info_state);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose int dp_error = DP_ERR_FATAL;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose int ret;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ret = sdap_id_op_connect_recv(subreq, &dp_error);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose talloc_zfree(subreq);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (ret != EOK) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sdap_id_op_connect request failed.\n");
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose goto fail;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose subreq = ipa_get_ad_override_send(state, state->ev, state->ctx,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->ipa_ctx->ipa_options, state->realm,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->ipa_ctx->view_name, state->ar);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (subreq == NULL) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_get_ad_override_send failed.\n");
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ret = ENOMEM;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose goto fail;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose tevent_req_set_callback(subreq, ipa_id_get_account_info_got_override, req);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose return;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bosefail:
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->dp_error = dp_error;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose tevent_req_error(req, ret);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose return;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose}
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bosestatic void ipa_id_get_account_info_got_override(struct tevent_req *subreq)
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose{
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct tevent_req *req = tevent_req_callback_data(subreq,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct tevent_req);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct ipa_id_get_account_info_state *state = tevent_req_data(req,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct ipa_id_get_account_info_state);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose int dp_error = DP_ERR_FATAL;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose int ret;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose const char *anchor = NULL;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose char *anchor_domain;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose char *ipa_uuid;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ret = ipa_get_ad_override_recv(subreq, &dp_error, state,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose &state->override_attrs);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose talloc_zfree(subreq);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (ret != EOK) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "IPA override lookup failed: %d\n", ret);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose goto fail;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (state->override_attrs != NULL) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ret = sysdb_attrs_get_string(state->override_attrs,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose SYSDB_OVERRIDE_ANCHOR_UUID,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose &anchor);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (ret != EOK) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_attrs_get_string failed.\n");
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose goto fail;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ret = split_ipa_anchor(state, anchor, &anchor_domain, &ipa_uuid);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (ret != EOK) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose "Unsupported override anchor [%s].\n", anchor);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ret = EINVAL;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose goto fail;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (strcmp(state->ar->domain, anchor_domain) == 0) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
0f9c28eb52d2b45c8a97f709308dc11377831b8cSumit Bose state->orig_ar = state->ar;
0f9c28eb52d2b45c8a97f709308dc11377831b8cSumit Bose
3d29430867cf92b2d71afa95abb679711231117cPavel Březina ret = get_dp_id_data_for_uuid(state, ipa_uuid,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->ar->domain,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose &state->ar);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (ret != EOK) {
3d29430867cf92b2d71afa95abb679711231117cPavel Březina DEBUG(SSSDBG_OP_FAILURE, "get_dp_id_data_for_uuid failed.\n");
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose goto fail;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
0f9c28eb52d2b45c8a97f709308dc11377831b8cSumit Bose
0f9c28eb52d2b45c8a97f709308dc11377831b8cSumit Bose if ((state->orig_ar->entry_type & BE_REQ_TYPE_MASK)
0f9c28eb52d2b45c8a97f709308dc11377831b8cSumit Bose == BE_REQ_INITGROUPS) {
0f9c28eb52d2b45c8a97f709308dc11377831b8cSumit Bose DEBUG(SSSDBG_TRACE_ALL,
0f9c28eb52d2b45c8a97f709308dc11377831b8cSumit Bose "Switching back to BE_REQ_INITGROUPS.\n");
0f9c28eb52d2b45c8a97f709308dc11377831b8cSumit Bose state->ar->entry_type = BE_REQ_INITGROUPS;
0f9c28eb52d2b45c8a97f709308dc11377831b8cSumit Bose state->ar->filter_type = BE_FILTER_UUID;
0f9c28eb52d2b45c8a97f709308dc11377831b8cSumit Bose }
0f9c28eb52d2b45c8a97f709308dc11377831b8cSumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose } else {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_MINOR_FAILURE,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose "Anchor from a different domain [%s], expected [%s]. " \
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose "This is currently not supported, continue lookup in " \
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose "local IPA domain.\n",
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose anchor_domain, state->ar->domain);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ret = ipa_id_get_account_info_get_original_step(req, state->ar);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (ret != EOK) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose "ipa_subdomain_account_get_original_step failed.\n");
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose goto fail;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose return;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bosefail:
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->dp_error = dp_error;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose tevent_req_error(req, ret);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose return;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose}
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bosestatic errno_t ipa_id_get_account_info_get_original_step(struct tevent_req *req,
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *ar)
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose{
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct ipa_id_get_account_info_state *state = tevent_req_data(req,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct ipa_id_get_account_info_state);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct tevent_req *subreq;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
a849d848d53f305a90613a74c1767a42b250dedaPavel Březina subreq = sdap_handle_acct_req_send(state, state->ctx->be, ar,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->ipa_ctx->sdap_id_ctx,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->ipa_ctx->sdap_id_ctx->opts->sdom,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->ipa_ctx->sdap_id_ctx->conn, true);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (subreq == NULL) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sdap_handle_acct_req_send failed.\n");
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose return ENOMEM;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose tevent_req_set_callback(subreq, ipa_id_get_account_info_orig_done, req);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose return EOK;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose}
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bosestatic int ipa_id_get_account_info_post_proc_step(struct tevent_req *req);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozekstatic void ipa_id_get_user_groups_done(struct tevent_req *subreq);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bosestatic void ipa_id_get_account_info_orig_done(struct tevent_req *subreq)
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose{
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct tevent_req *req = tevent_req_callback_data(subreq,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct tevent_req);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct ipa_id_get_account_info_state *state = tevent_req_data(req,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct ipa_id_get_account_info_state);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose int dp_error = DP_ERR_FATAL;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose int ret;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose const char *attrs[] = { SYSDB_NAME,
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose SYSDB_UIDNUM,
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose SYSDB_SID_STR,
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose SYSDB_OBJECTCATEGORY,
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose SYSDB_UUID,
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose SYSDB_GHOST,
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose SYSDB_HOMEDIR,
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose NULL };
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ret = sdap_handle_acct_req_recv(subreq, &dp_error, NULL, NULL);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose talloc_zfree(subreq);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (ret != EOK) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sdap_handle_acct request failed: %d\n", ret);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose goto fail;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech if (! is_object_overridable(state->ar)) {
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech state->dp_error = DP_ERR_OK;
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech tevent_req_done(req);
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech return;
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech }
565e6d91814884054ec0dc4d770804d7bf472d3fPetr Cech
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose /* Lookups by certificate can return muliple results and need special
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose * handling because get_object_from_cache() expects a unique match */
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose state->res = NULL;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose state->res_index = 0;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose if (state->ar->filter_type == BE_FILTER_CERT) {
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose ret = sysdb_search_object_by_cert(state, state->domain,
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose state->ar->filter_value, attrs,
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose &(state->res));
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose if (ret != EOK) {
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose DEBUG(SSSDBG_OP_FAILURE,
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose "Failed to make request to our cache: [%d]: [%s]\n",
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose ret, sss_strerror(ret));
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose goto fail;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose }
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose if (state->res->count == 0) {
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "Object not found in our cache.\n");
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose ret = ENOENT;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose goto fail;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose }
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose state->obj_msg = state->res->msgs[0];
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose if (state->res->count == 1) {
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose /* Just process the unique result, no need to iterate */
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose state->res = NULL;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose }
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose } else {
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose ret = get_object_from_cache(state, state->domain, state->ar,
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose &state->obj_msg);
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose if (ret == ENOENT) {
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose DEBUG(SSSDBG_MINOR_FAILURE, "Object not found, ending request\n");
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose state->dp_error = DP_ERR_OK;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose tevent_req_done(req);
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose return;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose } else if (ret != EOK) {
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "get_object_from_cache failed.\n");
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose goto fail;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose }
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose }
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose ret = ipa_id_get_account_info_post_proc_step(req);
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose if (ret == EAGAIN) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose return;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose } else if (ret != EOK) {
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_id_get_account_info_post_proc_step failed.\n");
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose goto fail;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose state->dp_error = DP_ERR_OK;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose tevent_req_done(req);
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose return;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bosefail:
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose state->dp_error = dp_error;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose tevent_req_error(req, ret);
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose return;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose}
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bosestatic int ipa_id_get_account_info_post_proc_step(struct tevent_req *req)
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose{
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose int ret;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose const char *uuid;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose const char *class;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose enum sysdb_member_type type;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose struct tevent_req *subreq;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose struct ipa_id_get_account_info_state *state = tevent_req_data(req,
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose struct ipa_id_get_account_info_state);
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose class = ldb_msg_find_attr_as_string(state->obj_msg, SYSDB_OBJECTCATEGORY,
605dc7fcc848dffb7c9d270c864c70e6dff1242eSumit Bose NULL);
605dc7fcc848dffb7c9d270c864c70e6dff1242eSumit Bose if (class == NULL) {
605dc7fcc848dffb7c9d270c864c70e6dff1242eSumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Cannot find an objectclass.\n");
605dc7fcc848dffb7c9d270c864c70e6dff1242eSumit Bose ret = EINVAL;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose goto done;
605dc7fcc848dffb7c9d270c864c70e6dff1242eSumit Bose }
605dc7fcc848dffb7c9d270c864c70e6dff1242eSumit Bose
605dc7fcc848dffb7c9d270c864c70e6dff1242eSumit Bose
9ac2a33f4cdc4941fa63118dcffe8058854f33c4Michal Židek if (!is_default_view(state->ipa_ctx->view_name)) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
605dc7fcc848dffb7c9d270c864c70e6dff1242eSumit Bose if ((state->ar->entry_type & BE_REQ_TYPE_MASK) == BE_REQ_GROUP
605dc7fcc848dffb7c9d270c864c70e6dff1242eSumit Bose || ((state->ar->entry_type & BE_REQ_TYPE_MASK) == BE_REQ_BY_UUID
605dc7fcc848dffb7c9d270c864c70e6dff1242eSumit Bose && strcmp(class, SYSDB_GROUP_CLASS) == 0)) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek /* check for ghost members because ghost members are not allowed
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek * if a view other than the default view is applied.*/
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek state->ghosts = ldb_msg_find_element(state->obj_msg, SYSDB_GHOST);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek } else if ((state->ar->entry_type & BE_REQ_TYPE_MASK) == \
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek BE_REQ_INITGROUPS) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek /* Get UUID list of groups that have no overrideDN set. */
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek ret = ipa_id_get_group_uuids(state, state->sysdb,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek &state->group_cnt,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek &state->user_groups);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (ret != EOK) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Cannot get UUID list: %d\n", ret);
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose goto done;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (state->override_attrs == NULL) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose uuid = ldb_msg_find_attr_as_string(state->obj_msg, SYSDB_UUID, NULL);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (uuid == NULL) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Cannot find a UUID.\n");
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ret = EINVAL;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose goto done;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
3d29430867cf92b2d71afa95abb679711231117cPavel Březina ret = get_dp_id_data_for_uuid(state, uuid, state->domain->name,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose &state->ar);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (ret != EOK) {
3d29430867cf92b2d71afa95abb679711231117cPavel Březina DEBUG(SSSDBG_OP_FAILURE, "get_dp_id_data_for_sid failed.\n");
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose goto done;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose subreq = ipa_get_ad_override_send(state, state->ev,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->ipa_ctx->sdap_id_ctx,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->ipa_ctx->ipa_options,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->realm,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->ipa_ctx->view_name,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->ar);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (subreq == NULL) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_get_ad_override_send failed.\n");
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ret = ENOMEM;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose goto done;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose tevent_req_set_callback(subreq, ipa_id_get_account_info_done, req);
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose ret = EAGAIN;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose goto done;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose } else {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (strcmp(class, SYSDB_USER_CLASS) == 0) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose type = SYSDB_MEMBER_USER;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose } else {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose type = SYSDB_MEMBER_GROUP;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ret = sysdb_store_override(state->domain, state->ipa_ctx->view_name,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose type,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->override_attrs, state->obj_msg->dn);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (ret != EOK) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_store_override failed.\n");
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose goto done;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose if (state->ghosts != NULL) {
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose /* Resolve ghost members */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina subreq = ipa_resolve_user_list_send(state, state->ev,
eab17959df71341073f946c533f59fc5e593b35cSumit Bose state->ipa_ctx,
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose state->domain->name,
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose state->ghosts);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose if (subreq == NULL) {
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_resolve_user_list_send failed.\n");
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose ret = ENOMEM;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose goto done;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose tevent_req_set_callback(subreq, ipa_id_get_user_list_done, req);
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose ret = EAGAIN;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose goto done;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (state->user_groups != NULL) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek subreq = ipa_initgr_get_overrides_send(state, state->ev, state->ipa_ctx,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek state->domain, state->group_cnt,
145578006684481434ced78461ab8d1c3570f478Sumit Bose state->user_groups,
145578006684481434ced78461ab8d1c3570f478Sumit Bose SYSDB_UUID);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (subreq == NULL) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "ipa_resolve_user_list_send failed.\n");
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek ret = ENOMEM;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose goto done;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek tevent_req_set_callback(subreq, ipa_id_get_user_groups_done, req);
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose ret = EAGAIN;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose goto done;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose ret = EOK;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bosedone:
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose if (ret == EOK && state->res != NULL
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose && ++state->res_index < state->res->count) {
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose state->obj_msg = state->res->msgs[state->res_index];
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose ret = ipa_id_get_account_info_post_proc_step(req);
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose }
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose return ret;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose}
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bosestatic void ipa_id_get_account_info_done(struct tevent_req *subreq)
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose{
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct tevent_req *req = tevent_req_callback_data(subreq,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct tevent_req);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct ipa_id_get_account_info_state *state = tevent_req_data(req,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct ipa_id_get_account_info_state);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose int dp_error = DP_ERR_FATAL;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose int ret;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose const char *class;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose enum sysdb_member_type type;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ret = ipa_get_ad_override_recv(subreq, &dp_error, state,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose &state->override_attrs);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose talloc_zfree(subreq);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (ret != EOK) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "IPA override lookup failed: %d\n", ret);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose goto fail;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose class = ldb_msg_find_attr_as_string(state->obj_msg, SYSDB_OBJECTCATEGORY,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose NULL);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (class == NULL) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Cannot find an objectclass.\n");
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ret = EINVAL;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose goto fail;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (strcmp(class, SYSDB_USER_CLASS) == 0) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose type = SYSDB_MEMBER_USER;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose } else {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose type = SYSDB_MEMBER_GROUP;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ret = sysdb_store_override(state->domain, state->ipa_ctx->view_name,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose type,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->override_attrs, state->obj_msg->dn);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (ret != EOK) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_store_override failed.\n");
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose goto fail;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose if (state->ghosts != NULL) {
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose /* Resolve ghost members */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina subreq = ipa_resolve_user_list_send(state, state->ev,
eab17959df71341073f946c533f59fc5e593b35cSumit Bose state->ipa_ctx,
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose state->domain->name,
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose state->ghosts);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose if (subreq == NULL) {
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_resolve_user_list_send failed.\n");
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose ret = ENOMEM;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose goto fail;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose tevent_req_set_callback(subreq, ipa_id_get_user_list_done, req);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose return;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (state->user_groups != NULL) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek subreq = ipa_initgr_get_overrides_send(state, state->ev, state->ipa_ctx,
145578006684481434ced78461ab8d1c3570f478Sumit Bose state->domain, state->group_cnt,
145578006684481434ced78461ab8d1c3570f478Sumit Bose state->user_groups,
145578006684481434ced78461ab8d1c3570f478Sumit Bose SYSDB_UUID);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (subreq == NULL) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "ipa_resolve_user_list_send failed.\n");
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek ret = ENOMEM;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek goto fail;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek tevent_req_set_callback(subreq, ipa_id_get_user_groups_done, req);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek return;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose if (state->res != NULL && ++state->res_index < state->res->count) {
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose state->obj_msg = state->res->msgs[state->res_index];
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose ret = ipa_id_get_account_info_post_proc_step(req);
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose if (ret == EAGAIN) {
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose return;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose } else if (ret != EOK) {
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose DEBUG(SSSDBG_OP_FAILURE,
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose "ipa_id_get_account_info_post_proc_step failed.\n");
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose goto fail;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose }
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose }
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose state->dp_error = DP_ERR_OK;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose tevent_req_done(req);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose return;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bosefail:
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose state->dp_error = dp_error;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose tevent_req_error(req, ret);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose return;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose}
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bosestatic void ipa_id_get_user_list_done(struct tevent_req *subreq)
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose{
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct tevent_req *req = tevent_req_callback_data(subreq,
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct tevent_req);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct ipa_id_get_account_info_state *state = tevent_req_data(req,
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose struct ipa_id_get_account_info_state);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose int dp_error = DP_ERR_FATAL;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose int ret;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose ret = ipa_resolve_user_list_recv(subreq, &dp_error);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose talloc_zfree(subreq);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose if (ret != EOK) {
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "IPA resolve user list %d\n", ret);
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose goto fail;
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose }
765d9075bb1e10ae0f09b6c2701bfd50aeb423d4Sumit Bose
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose if (state->res != NULL && ++state->res_index < state->res->count) {
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose state->obj_msg = state->res->msgs[state->res_index];
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose ret = ipa_id_get_account_info_post_proc_step(req);
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose if (ret == EAGAIN) {
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose return;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose } else if (ret != EOK) {
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose DEBUG(SSSDBG_OP_FAILURE,
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose "ipa_id_get_account_info_post_proc_step failed.\n");
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose goto fail;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose }
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose }
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->dp_error = DP_ERR_OK;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose tevent_req_done(req);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose return;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bosefail:
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose state->dp_error = dp_error;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose tevent_req_error(req, ret);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose return;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose}
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozekstatic void ipa_id_get_user_groups_done(struct tevent_req *subreq)
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek{
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct tevent_req);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct ipa_id_get_account_info_state *state = tevent_req_data(req,
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek struct ipa_id_get_account_info_state);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek int dp_error = DP_ERR_FATAL;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek int ret;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek ret = ipa_initgr_get_overrides_recv(subreq, &dp_error);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek talloc_zfree(subreq);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek if (ret != EOK) {
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "IPA resolve user groups %d\n", ret);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek goto fail;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek }
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose if (state->res != NULL && ++state->res_index < state->res->count) {
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose state->obj_msg = state->res->msgs[state->res_index];
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose ret = ipa_id_get_account_info_post_proc_step(req);
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose if (ret == EAGAIN) {
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose return;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose } else if (ret != EOK) {
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose DEBUG(SSSDBG_OP_FAILURE,
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose "ipa_id_get_account_info_post_proc_step failed.\n");
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose goto fail;
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose }
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose }
3fd8ea55d59f29725ab32bdaf5b98ffaae7fbf9dSumit Bose
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek state->dp_error = DP_ERR_OK;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek tevent_req_done(req);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek return;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozekfail:
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek state->dp_error = dp_error;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek tevent_req_error(req, ret);
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek return;
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek}
b2c3722b9a1eaf265f6b102043958f6d4378788cJakub Hrozek
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bosestatic int ipa_id_get_account_info_recv(struct tevent_req *req, int *dp_error)
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose{
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct ipa_id_get_account_info_state *state = tevent_req_data(req,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose struct ipa_id_get_account_info_state);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if (dp_error) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose *dp_error = state->dp_error;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose TEVENT_REQ_RETURN_ON_ERROR(req);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose return EOK;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose}
6ff0d2242fe93d694b81b29ab12289db4859e1dcSimo Sorce
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny/* Request for netgroups
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny * - first start here and then go to ipa_netgroups.c
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny */
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorcestruct ipa_id_get_netgroup_state {
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce struct tevent_context *ev;
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce struct ipa_id_ctx *ctx;
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce struct sdap_id_op *op;
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce struct sysdb_ctx *sysdb;
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce struct sss_domain_info *domain;
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce const char *name;
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce int timeout;
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce char *filter;
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce const char **attrs;
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce size_t count;
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce struct sysdb_attrs **netgroups;
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce int dp_error;
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce};
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorcestatic void ipa_id_get_netgroup_connected(struct tevent_req *subreq);
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorcestatic void ipa_id_get_netgroup_done(struct tevent_req *subreq);
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorcestatic struct tevent_req *ipa_id_get_netgroup_send(TALLOC_CTX *memctx,
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce struct tevent_context *ev,
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce struct ipa_id_ctx *ipa_ctx,
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce const char *name)
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny{
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny struct tevent_req *req;
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce struct ipa_id_get_netgroup_state *state;
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce struct tevent_req *subreq;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny struct sdap_id_ctx *ctx;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny char *clean_name;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny int ret;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny ctx = ipa_ctx->sdap_id_ctx;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce req = tevent_req_create(memctx, &state, struct ipa_id_get_netgroup_state);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny if (!req) return NULL;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny state->ev = ev;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny state->ctx = ipa_ctx;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny state->dp_error = DP_ERR_FATAL;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
dcb44c39dda9699cdd6488fd116a51ced0687de3Jakub Hrozek state->op = sdap_id_op_create(state, ctx->conn->conn_cache);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny if (!state->op) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "sdap_id_op_create failed\n");
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny ret = ENOMEM;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny goto fail;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny }
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
df0596ec12bc5091608371e2977f3111241e8cafSimo Sorce state->sysdb = ctx->be->domain->sysdb;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny state->domain = ctx->be->domain;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny state->name = name;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny state->timeout = dp_opt_get_int(ctx->opts->basic, SDAP_SEARCH_TIMEOUT);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny ret = sss_filter_sanitize(state, name, &clean_name);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny if (ret != EOK) {
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny goto fail;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny }
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny state->filter = talloc_asprintf(state, "(&(%s=%s)(objectclass=%s))",
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny ctx->opts->netgroup_map[IPA_AT_NETGROUP_NAME].name,
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny clean_name,
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny ctx->opts->netgroup_map[IPA_OC_NETGROUP].name);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny if (!state->filter) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to build filter\n");
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny ret = ENOMEM;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny goto fail;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny }
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny talloc_zfree(clean_name);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny ret = build_attrs_from_map(state, ctx->opts->netgroup_map,
64ddff90c7fcc02ccb06824ac93af7d5f361a88fJan Zeleny IPA_OPTS_NETGROUP, NULL,
64ddff90c7fcc02ccb06824ac93af7d5f361a88fJan Zeleny &state->attrs, NULL);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny if (ret != EOK) goto fail;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce subreq = sdap_id_op_connect_send(state->op, state, &ret);
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce if (!subreq) {
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny goto fail;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny }
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce tevent_req_set_callback(subreq, ipa_id_get_netgroup_connected, req);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny return req;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zelenyfail:
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny tevent_req_error(req, ret);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny tevent_req_post(req, ev);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny return req;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny}
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorcestatic void ipa_id_get_netgroup_connected(struct tevent_req *subreq)
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny{
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce struct tevent_req *req =
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce tevent_req_callback_data(subreq, struct tevent_req);
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce struct ipa_id_get_netgroup_state *state =
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce tevent_req_data(req, struct ipa_id_get_netgroup_state);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny int dp_error = DP_ERR_FATAL;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny int ret;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny struct sdap_id_ctx *sdap_ctx = state->ctx->sdap_id_ctx;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny ret = sdap_id_op_connect_recv(subreq, &dp_error);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny talloc_zfree(subreq);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny if (ret != EOK) {
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny state->dp_error = dp_error;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny tevent_req_error(req, ret);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny return;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny }
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
bd92e8ee315d4da9350b9ef0358c88a7b54aeebeStephen Gallagher subreq = ipa_get_netgroups_send(state, state->ev, state->sysdb,
bd92e8ee315d4da9350b9ef0358c88a7b54aeebeStephen Gallagher state->domain, sdap_ctx->opts,
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny state->ctx->ipa_options,
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny sdap_id_op_handle(state->op),
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny state->attrs, state->filter,
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny state->timeout);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny if (!subreq) {
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny tevent_req_error(req, ENOMEM);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny return;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny }
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce tevent_req_set_callback(subreq, ipa_id_get_netgroup_done, req);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny return;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny}
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorcestatic void ipa_id_get_netgroup_done(struct tevent_req *subreq)
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny{
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce struct tevent_req *req =
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce tevent_req_callback_data(subreq, struct tevent_req);
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce struct ipa_id_get_netgroup_state *state =
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce tevent_req_data(req, struct ipa_id_get_netgroup_state);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny int dp_error = DP_ERR_FATAL;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny int ret;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce ret = ipa_get_netgroups_recv(subreq, state,
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce &state->count, &state->netgroups);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny talloc_zfree(subreq);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny ret = sdap_id_op_done(state->op, ret, &dp_error);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny if (dp_error == DP_ERR_OK && ret != EOK) {
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny /* retry */
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce subreq = sdap_id_op_connect_send(state->op, state, &ret);
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce if (!subreq) {
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny tevent_req_error(req, ret);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny return;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny }
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce tevent_req_set_callback(subreq, ipa_id_get_netgroup_connected, req);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny return;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny }
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny if (ret && ret != ENOENT) {
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny state->dp_error = dp_error;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny tevent_req_error(req, ret);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny return;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny }
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny if (ret == EOK && state->count > 1) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Found more than one netgroup with the name [%s].\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov state->name);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny tevent_req_error(req, EINVAL);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny return;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny }
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny if (ret == ENOENT) {
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_delete_netgroup(state->domain, state->name);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny if (ret != EOK && ret != ENOENT) {
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny tevent_req_error(req, ret);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny return;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny }
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny }
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny state->dp_error = DP_ERR_OK;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny tevent_req_done(req);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny return;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny}
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorcestatic int ipa_id_get_netgroup_recv(struct tevent_req *req, int *dp_error)
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny{
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce struct ipa_id_get_netgroup_state *state =
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce tevent_req_data(req, struct ipa_id_get_netgroup_state);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce if (dp_error) {
39be7dbfa25a1cae78741a1c6c8c744e8c87e38fSimo Sorce *dp_error = state->dp_error;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny }
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny TEVENT_REQ_RETURN_ON_ERROR(req);
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny return EOK;
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny}
8b1f2574ce7a964965a18ab047ab09c4694380c4Jan Zeleny
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaenum ipa_account_info_type {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina IPA_ACCOUNT_INFO_SUBDOMAIN,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina IPA_ACCOUNT_INFO_NETGROUP,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina IPA_ACCOUNT_INFO_OTHER
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina};
8edf0e447266d68f10264eb3f3ea514cd1687041Jakub Hrozek
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic enum ipa_account_info_type
3d29430867cf92b2d71afa95abb679711231117cPavel Březinaipa_decide_account_info_type(struct dp_id_data *data, struct be_ctx *be_ctx)
8edf0e447266d68f10264eb3f3ea514cd1687041Jakub Hrozek{
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (strcasecmp(data->domain, be_ctx->domain->name) != 0) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return IPA_ACCOUNT_INFO_SUBDOMAIN;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina } else if ((data->entry_type & BE_REQ_TYPE_MASK) == BE_REQ_NETGROUP) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return IPA_ACCOUNT_INFO_NETGROUP;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return IPA_ACCOUNT_INFO_OTHER;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina}
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastruct ipa_account_info_handler_state {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina enum ipa_account_info_type type;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct dp_reply_std reply;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina};
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic void ipa_account_info_handler_done(struct tevent_req *subreq);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastruct tevent_req *
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaipa_account_info_handler_send(TALLOC_CTX *mem_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct ipa_id_ctx *id_ctx,
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *data,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct dp_req_params *params)
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina{
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct ipa_account_info_handler_state *state;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct tevent_req *subreq = NULL;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct tevent_req *req;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina errno_t ret;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina req = tevent_req_create(mem_ctx, &state,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct ipa_account_info_handler_state);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (req == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return NULL;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina state->type = ipa_decide_account_info_type(data, params->be_ctx);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (sdap_is_enum_request(data)) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_TRACE_LIBS, "Skipping enumeration on demand\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = EOK;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina goto immediately;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina switch (state->type) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina case IPA_ACCOUNT_INFO_SUBDOMAIN:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina /* Subdomain lookups are handled differently on server and client. */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina subreq = ipa_subdomain_account_send(state, params->ev, id_ctx, data);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina break;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina case IPA_ACCOUNT_INFO_NETGROUP:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (data->filter_type != BE_FILTER_NAME) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = EINVAL;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina goto immediately;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
8edf0e447266d68f10264eb3f3ea514cd1687041Jakub Hrozek
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina subreq = ipa_id_get_netgroup_send(state, params->ev, id_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina data->filter_value);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina break;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina case IPA_ACCOUNT_INFO_OTHER:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina subreq = ipa_id_get_account_info_send(state, params->ev, id_ctx, data);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina break;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
8edf0e447266d68f10264eb3f3ea514cd1687041Jakub Hrozek
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (subreq == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = ENOMEM;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina goto immediately;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina tevent_req_set_callback(subreq, ipa_account_info_handler_done, req);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return req;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaimmediately:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&state->reply, DP_ERR_DECIDE, ret, NULL);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina /* TODO For backward compatibility we always return EOK to DP now. */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina tevent_req_done(req);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina tevent_req_post(req, params->ev);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return req;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina}
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic void ipa_account_info_handler_done(struct tevent_req *subreq)
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina{
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct ipa_account_info_handler_state *state;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct tevent_req *req;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina int dp_error;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina errno_t ret = ERR_INTERNAL;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina state = tevent_req_data(req, struct ipa_account_info_handler_state);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina switch (state->type) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina case IPA_ACCOUNT_INFO_SUBDOMAIN:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = ipa_subdomain_account_recv(subreq, &dp_error);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina break;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina case IPA_ACCOUNT_INFO_NETGROUP:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = ipa_id_get_netgroup_recv(subreq, &dp_error);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina break;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina case IPA_ACCOUNT_INFO_OTHER:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = ipa_id_get_account_info_recv(subreq, &dp_error);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina break;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina talloc_zfree(subreq);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina /* TODO For backward compatibility we always return EOK to DP now. */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&state->reply, dp_error, ret, NULL);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina tevent_req_done(req);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina}
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaerrno_t ipa_account_info_handler_recv(TALLOC_CTX *mem_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct tevent_req *req,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct dp_reply_std *data)
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina{
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct ipa_account_info_handler_state *state = NULL;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina state = tevent_req_data(req, struct ipa_account_info_handler_state);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina TEVENT_REQ_RETURN_ON_ERROR(req);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina *data = state->reply;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return EOK;
8edf0e447266d68f10264eb3f3ea514cd1687041Jakub Hrozek}