0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose/*
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose SSSD
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose IPA Identity Backend Module for views and overrides
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose Authors:
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose Sumit Bose <sbose@redhat.com>
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose Copyright (C) 2014 Red Hat
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose This program is free software; you can redistribute it and/or modify
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose it under the terms of the GNU General Public License as published by
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose the Free Software Foundation; either version 3 of the License, or
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose (at your option) any later version.
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose This program is distributed in the hope that it will be useful,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose GNU General Public License for more details.
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose You should have received a copy of the GNU General Public License
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose*/
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose#include "util/util.h"
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose#include "util/strtonum.h"
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose#include "util/cert.h"
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose#include "providers/ldap/sdap_async.h"
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose#include "providers/ipa/ipa_id.h"
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
3d29430867cf92b2d71afa95abb679711231117cPavel Březinastatic errno_t dp_id_data_to_override_filter(TALLOC_CTX *mem_ctx,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose struct ipa_options *ipa_opts,
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *ar,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose char **override_filter)
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose{
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose char *filter;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose uint32_t id;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose char *endptr;
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose char *cert_filter;
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose int ret;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek char *shortname;
c2dec0dc740ba426f26563563c0aea3a38f3c3c1Sumit Bose char *sanitized_name;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose switch (ar->filter_type) {
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose case BE_FILTER_NAME:
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek ret = sss_parse_internal_fqname(mem_ctx, ar->filter_value,
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek &shortname, NULL);
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek if (ret != EOK) {
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek return ret;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek }
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek
c2dec0dc740ba426f26563563c0aea3a38f3c3c1Sumit Bose ret = sss_filter_sanitize(mem_ctx, shortname, &sanitized_name);
c2dec0dc740ba426f26563563c0aea3a38f3c3c1Sumit Bose talloc_free(shortname);
c2dec0dc740ba426f26563563c0aea3a38f3c3c1Sumit Bose if (ret != EOK) {
c2dec0dc740ba426f26563563c0aea3a38f3c3c1Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sss_filter_sanitize failed.\n");
c2dec0dc740ba426f26563563c0aea3a38f3c3c1Sumit Bose return ret;
c2dec0dc740ba426f26563563c0aea3a38f3c3c1Sumit Bose }
c2dec0dc740ba426f26563563c0aea3a38f3c3c1Sumit Bose
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose switch ((ar->entry_type & BE_REQ_TYPE_MASK)) {
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose case BE_REQ_USER:
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose case BE_REQ_INITGROUPS:
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose filter = talloc_asprintf(mem_ctx, "(&(objectClass=%s)(%s=%s))",
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ipa_opts->override_map[IPA_OC_OVERRIDE_USER].name,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ipa_opts->override_map[IPA_AT_OVERRIDE_USER_NAME].name,
c2dec0dc740ba426f26563563c0aea3a38f3c3c1Sumit Bose sanitized_name);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose break;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose case BE_REQ_GROUP:
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose filter = talloc_asprintf(mem_ctx, "(&(objectClass=%s)(%s=%s))",
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ipa_opts->override_map[IPA_OC_OVERRIDE_GROUP].name,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ipa_opts->override_map[IPA_AT_OVERRIDE_GROUP_NAME].name,
c2dec0dc740ba426f26563563c0aea3a38f3c3c1Sumit Bose sanitized_name);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose break;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose case BE_REQ_USER_AND_GROUP:
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose filter = talloc_asprintf(mem_ctx, "(&(objectClass=%s)(|(%s=%s)(%s=%s)))",
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ipa_opts->override_map[IPA_OC_OVERRIDE].name,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ipa_opts->override_map[IPA_AT_OVERRIDE_USER_NAME].name,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ar->filter_value,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ipa_opts->override_map[IPA_AT_OVERRIDE_GROUP_NAME].name,
c2dec0dc740ba426f26563563c0aea3a38f3c3c1Sumit Bose sanitized_name);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose break;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose default:
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Unexpected entry type [%d] for name filter.\n",
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ar->entry_type);
c2dec0dc740ba426f26563563c0aea3a38f3c3c1Sumit Bose talloc_free(sanitized_name);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose return EINVAL;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose }
c2dec0dc740ba426f26563563c0aea3a38f3c3c1Sumit Bose talloc_free(sanitized_name);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose break;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose case BE_FILTER_IDNUM:
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose errno = 0;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose id = strtouint32(ar->filter_value, &endptr, 10);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose if (errno != 0|| *endptr != '\0' || (ar->filter_value == endptr)) {
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Invalid id value [%s].\n",
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ar->filter_value);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose return EINVAL;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose }
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose switch ((ar->entry_type & BE_REQ_TYPE_MASK)) {
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose case BE_REQ_USER:
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose case BE_REQ_INITGROUPS:
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose filter = talloc_asprintf(mem_ctx, "(&(objectClass=%s)(%s=%"PRIu32"))",
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ipa_opts->override_map[IPA_OC_OVERRIDE_USER].name,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ipa_opts->override_map[IPA_AT_OVERRIDE_UID_NUMBER].name,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose id);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose break;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose case BE_REQ_GROUP:
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose filter = talloc_asprintf(mem_ctx,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose "(&(objectClass=%s)(%s=%"PRIu32"))",
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ipa_opts->override_map[IPA_OC_OVERRIDE_GROUP].name,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ipa_opts->override_map[IPA_AT_OVERRIDE_GROUP_GID_NUMBER].name,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose id);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose break;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose case BE_REQ_USER_AND_GROUP:
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose filter = talloc_asprintf(mem_ctx,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose "(&(objectClass=%s)(|(%s=%"PRIu32")(%s=%"PRIu32")))",
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ipa_opts->override_map[IPA_OC_OVERRIDE].name,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ipa_opts->override_map[IPA_AT_OVERRIDE_UID_NUMBER].name,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose id,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ipa_opts->override_map[IPA_AT_OVERRIDE_GROUP_GID_NUMBER].name,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose id);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose break;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose default:
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose "Unexpected entry type [%d] for id filter.\n",
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ar->entry_type);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose return EINVAL;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose }
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose break;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose case BE_FILTER_SECID:
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose if ((ar->entry_type & BE_REQ_TYPE_MASK) == BE_REQ_BY_SECID) {
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose filter = talloc_asprintf(mem_ctx, "(&(objectClass=%s)(%s=:SID:%s))",
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ipa_opts->override_map[IPA_OC_OVERRIDE].name,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ipa_opts->override_map[IPA_AT_OVERRIDE_ANCHOR_UUID].name,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ar->filter_value);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose } else {
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose "Unexpected entry type [%d] for SID filter.\n",
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ar->entry_type);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose return EINVAL;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose }
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose break;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose case BE_FILTER_UUID:
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose if ((ar->entry_type & BE_REQ_TYPE_MASK) == BE_REQ_BY_UUID) {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose filter = talloc_asprintf(mem_ctx, "(&(objectClass=%s)(%s=:IPA:%s:%s))",
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ipa_opts->override_map[IPA_OC_OVERRIDE].name,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ipa_opts->override_map[IPA_AT_OVERRIDE_ANCHOR_UUID].name,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose dp_opt_get_string(ipa_opts->basic, IPA_DOMAIN),
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ar->filter_value);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose } else {
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose "Unexpected entry type [%d] for UUID filter.\n",
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose ar->entry_type);
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose return EINVAL;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose }
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose break;
acebf94a16c91b17c7c082538ab3083ee26aa992Sumit Bose
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose case BE_FILTER_CERT:
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose if ((ar->entry_type & BE_REQ_TYPE_MASK) == BE_REQ_BY_CERT) {
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose ret = sss_cert_derb64_to_ldap_filter(mem_ctx, ar->filter_value,
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose ipa_opts->override_map[IPA_AT_OVERRIDE_USER_CERT].name,
b341ee51cffd98b642b9c68a417f8a7504e303a1Sumit Bose NULL, NULL, &cert_filter);
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose if (ret != EOK) {
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose DEBUG(SSSDBG_OP_FAILURE,
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose "sss_cert_derb64_to_ldap_filter failed.\n");
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose return ret;
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose }
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose filter = talloc_asprintf(mem_ctx, "(&(objectClass=%s)%s)",
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose ipa_opts->override_map[IPA_OC_OVERRIDE_USER].name,
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose cert_filter);
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose talloc_free(cert_filter);
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose } else {
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose "Unexpected entry type [%d] for certificate filter.\n",
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose ar->entry_type);
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose return EINVAL;
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose }
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose break;
a1210c8db81a1cc0b45eb62a8450abcdea3afc7bSumit Bose
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose default:
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose DEBUG(SSSDBG_OP_FAILURE, "Invalid sub-domain filter type.\n");
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose return EINVAL;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose }
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose if (filter == NULL) {
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n");
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose return ENOMEM;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose }
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose *override_filter = filter;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose return EOK;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose}
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
3d29430867cf92b2d71afa95abb679711231117cPavel Březinastatic errno_t get_dp_id_data_for_xyz(TALLOC_CTX *mem_ctx, const char *val,
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose const char *domain_name,
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose int type,
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data **_ar)
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose{
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *ar;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
3d29430867cf92b2d71afa95abb679711231117cPavel Březina ar = talloc_zero(mem_ctx, struct dp_id_data);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose if (ar == NULL) {
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_zero failed.\n");
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose return ENOMEM;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose }
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose switch (type) {
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose case BE_REQ_BY_SECID:
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose ar->entry_type = BE_REQ_BY_SECID;
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose ar->filter_type = BE_FILTER_SECID;
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose break;
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose case BE_REQ_BY_UUID:
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose ar->entry_type = BE_REQ_BY_UUID;
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose ar->filter_type = BE_FILTER_UUID;
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose break;
d32b165fad7b89462f49c82349e1df5a2343afa2Sumit Bose case BE_REQ_USER:
d32b165fad7b89462f49c82349e1df5a2343afa2Sumit Bose ar->entry_type = BE_REQ_USER;
d32b165fad7b89462f49c82349e1df5a2343afa2Sumit Bose ar->filter_type = BE_FILTER_NAME;
d32b165fad7b89462f49c82349e1df5a2343afa2Sumit Bose break;
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose default:
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Unsupported request type [%d].\n", type);
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose talloc_free(ar);
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose return EINVAL;
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose }
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose ar->filter_value = talloc_strdup(ar, val);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose ar->domain = talloc_strdup(ar, domain_name);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose if (ar->filter_value == NULL || ar->domain == NULL) {
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose talloc_free(ar);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose return ENOMEM;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose }
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose *_ar = ar;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose return EOK;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose}
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose
3d29430867cf92b2d71afa95abb679711231117cPavel Březinaerrno_t get_dp_id_data_for_sid(TALLOC_CTX *mem_ctx, const char *sid,
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose const char *domain_name,
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data **_ar)
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose{
3d29430867cf92b2d71afa95abb679711231117cPavel Březina return get_dp_id_data_for_xyz(mem_ctx, sid, domain_name, BE_REQ_BY_SECID,
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose _ar);
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose}
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose
3d29430867cf92b2d71afa95abb679711231117cPavel Březinaerrno_t get_dp_id_data_for_uuid(TALLOC_CTX *mem_ctx, const char *uuid,
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose const char *domain_name,
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data **_ar)
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose{
3d29430867cf92b2d71afa95abb679711231117cPavel Březina return get_dp_id_data_for_xyz(mem_ctx, uuid, domain_name, BE_REQ_BY_UUID,
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose _ar);
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose}
1c82a31a254c2fca6dfa3e3b52986b75221d8742Sumit Bose
3d29430867cf92b2d71afa95abb679711231117cPavel Březinaerrno_t get_dp_id_data_for_user_name(TALLOC_CTX *mem_ctx,
d32b165fad7b89462f49c82349e1df5a2343afa2Sumit Bose const char *user_name,
d32b165fad7b89462f49c82349e1df5a2343afa2Sumit Bose const char *domain_name,
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data **_ar)
d32b165fad7b89462f49c82349e1df5a2343afa2Sumit Bose{
3d29430867cf92b2d71afa95abb679711231117cPavel Březina return get_dp_id_data_for_xyz(mem_ctx, user_name, domain_name, BE_REQ_USER,
d32b165fad7b89462f49c82349e1df5a2343afa2Sumit Bose _ar);
d32b165fad7b89462f49c82349e1df5a2343afa2Sumit Bose}
d32b165fad7b89462f49c82349e1df5a2343afa2Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bosestruct ipa_get_ad_override_state {
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct tevent_context *ev;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct sdap_id_ctx *sdap_id_ctx;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct ipa_options *ipa_options;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose const char *ipa_realm;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose const char *ipa_view_name;
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *ar;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct sdap_id_op *sdap_op;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose int dp_error;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct sysdb_attrs *override_attrs;
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose char *filter;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose};
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bosestatic void ipa_get_ad_override_connect_done(struct tevent_req *subreq);
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozekstatic errno_t ipa_get_ad_override_qualify_name(
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek struct ipa_get_ad_override_state *state);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bosestatic void ipa_get_ad_override_done(struct tevent_req *subreq);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bosestruct tevent_req *ipa_get_ad_override_send(TALLOC_CTX *mem_ctx,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct tevent_context *ev,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct sdap_id_ctx *sdap_id_ctx,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct ipa_options *ipa_options,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose const char *ipa_realm,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose const char *view_name,
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct dp_id_data *ar)
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose{
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose int ret;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct tevent_req *req;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct tevent_req *subreq;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct ipa_get_ad_override_state *state;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose req = tevent_req_create(mem_ctx, &state, struct ipa_get_ad_override_state);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose if (req == NULL) {
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "tevent_req_create failed.\n");
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose return NULL;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose }
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose state->ev = ev;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose state->sdap_id_ctx = sdap_id_ctx;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose state->ipa_options = ipa_options;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose state->ipa_realm = ipa_realm;
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose state->ar = ar;
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose state->dp_error = -1;
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose state->override_attrs = NULL;
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose state->filter = NULL;
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose if (view_name == NULL) {
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose DEBUG(SSSDBG_TRACE_ALL, "View not defined, nothing to do.\n");
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose ret = EOK;
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose goto done;
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose }
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose
9ac2a33f4cdc4941fa63118dcffe8058854f33c4Michal Židek if (is_default_view(view_name)) {
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose state->ipa_view_name = IPA_DEFAULT_VIEW_NAME;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose } else {
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose state->ipa_view_name = view_name;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose }
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose state->sdap_op = sdap_id_op_create(state,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose state->sdap_id_ctx->conn->conn_cache);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose if (state->sdap_op == NULL) {
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sdap_id_op_create failed\n");
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose ret = ENOMEM;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose goto done;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose }
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose subreq = sdap_id_op_connect_send(state->sdap_op, state, &ret);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose if (subreq == NULL) {
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sdap_id_op_connect_send failed: %d(%s).\n",
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose ret, strerror(ret));
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose goto done;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose }
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose tevent_req_set_callback(subreq, ipa_get_ad_override_connect_done, req);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose return req;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bosedone:
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose if (ret != EOK) {
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose state->dp_error = DP_ERR_FATAL;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose tevent_req_error(req, ret);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose } else {
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose state->dp_error = DP_ERR_OK;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose tevent_req_done(req);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose }
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose tevent_req_post(req, state->ev);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose return req;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose}
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bosestatic void ipa_get_ad_override_connect_done(struct tevent_req *subreq)
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose{
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct tevent_req *req = tevent_req_callback_data(subreq,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct tevent_req);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct ipa_get_ad_override_state *state = tevent_req_data(req,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct ipa_get_ad_override_state);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose int ret;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose char *basedn;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose char *search_base;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct ipa_options *ipa_opts = state->ipa_options;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose ret = sdap_id_op_connect_recv(subreq, &state->dp_error);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose talloc_zfree(subreq);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose if (ret != EOK) {
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose if (state->dp_error == DP_ERR_OFFLINE) {
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose DEBUG(SSSDBG_MINOR_FAILURE,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose "No IPA server is available, going offline\n");
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose } else {
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose "Failed to connect to IPA server: [%d](%s)\n",
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose ret, strerror(ret));
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose }
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose goto fail;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose }
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose ret = domain_to_basedn(state, state->ipa_realm, &basedn);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose if (ret != EOK) {
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "domain_to_basedn failed.\n");
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose goto fail;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose }
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose search_base = talloc_asprintf(state, "cn=%s,%s", state->ipa_view_name,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose ipa_opts->views_search_bases[0]->basedn);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose if (search_base == NULL) {
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n");
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose ret = ENOMEM;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose goto fail;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose }
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
3d29430867cf92b2d71afa95abb679711231117cPavel Březina ret = dp_id_data_to_override_filter(state, state->ipa_options, state->ar,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose &state->filter);
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose if (ret != EOK) {
3d29430867cf92b2d71afa95abb679711231117cPavel Březina DEBUG(SSSDBG_OP_FAILURE, "dp_id_data_to_override_filter failed.\n");
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose goto fail;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose }
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose DEBUG(SSSDBG_TRACE_ALL,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose "Searching for overrides in view [%s] with filter [%s].\n",
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose state->ipa_view_name, state->filter);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose subreq = sdap_get_generic_send(state, state->ev, state->sdap_id_ctx->opts,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose sdap_id_op_handle(state->sdap_op), search_base,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose LDAP_SCOPE_SUBTREE,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose state->filter, NULL,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose state->ipa_options->override_map,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose IPA_OPTS_OVERRIDE,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose dp_opt_get_int(state->sdap_id_ctx->opts->basic,
a687f4473bf305bc2ccb075cd93154c9d661b638Jakub Hrozek SDAP_SEARCH_TIMEOUT),
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose false);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose if (subreq == NULL) {
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sdap_get_generic_send failed.\n");
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose ret = ENOMEM;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose goto fail;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose }
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose tevent_req_set_callback(subreq, ipa_get_ad_override_done, req);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose return;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bosefail:
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose state->dp_error = DP_ERR_FATAL;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose tevent_req_error(req, ret);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose return;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose}
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bosestatic void ipa_get_ad_override_done(struct tevent_req *subreq)
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose{
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct tevent_req *req = tevent_req_callback_data(subreq,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct tevent_req);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct ipa_get_ad_override_state *state = tevent_req_data(req,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct ipa_get_ad_override_state);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose int ret;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose size_t reply_count = 0;
9c8db0a17a66c58c36966b17d004142a4aaace8dSumit Bose struct sysdb_attrs **reply = NULL;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose ret = sdap_get_generic_recv(subreq, state, &reply_count, &reply);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose talloc_zfree(subreq);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose if (ret != EOK) {
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ipa_get_ad_override request failed.\n");
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose goto fail;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose }
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose if (reply_count == 0) {
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose DEBUG(SSSDBG_TRACE_ALL, "No override found with filter [%s].\n",
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose state->filter);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose state->dp_error = DP_ERR_OK;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose tevent_req_done(req);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose return;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose } else if (reply_count > 1) {
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose "Found [%zu] overrides with filter [%s], expected only 1.\n",
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose reply_count, state->filter);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose ret = EINVAL;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose goto fail;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose }
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose DEBUG(SSSDBG_TRACE_ALL, "Found override for object with filter [%s].\n",
ed4a9bd4d0f7fb359bed66a8d63a92e7be633aaeSumit Bose state->filter);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose state->override_attrs = reply[0];
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek ret = ipa_get_ad_override_qualify_name(state);
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek if (ret != EOK) {
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Cannot qualify object name\n");
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek goto fail;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek }
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose state->dp_error = DP_ERR_OK;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose tevent_req_done(req);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose return;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bosefail:
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose state->dp_error = DP_ERR_FATAL;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose tevent_req_error(req, ret);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose return;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose}
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozekstatic errno_t ipa_get_ad_override_qualify_name(
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek struct ipa_get_ad_override_state *state)
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek{
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek int ret;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek struct ldb_message_element *name;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek char *fqdn;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek ret = sysdb_attrs_get_el_ext(state->override_attrs, SYSDB_NAME,
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek false, &name);
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek if (ret == ENOENT) {
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek return EOK; /* Does not override name */
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek } else if (ret != EOK && ret != ENOENT) {
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek return ret;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek }
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek fqdn = sss_create_internal_fqname(name->values,
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek (const char *) name->values[0].data,
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek state->ar->domain);
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek if (fqdn == NULL) {
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek return ENOMEM;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek }
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek name->values[0].data = (uint8_t *) fqdn;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek name->values[0].length = strlen(fqdn);
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek return EOK;
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek}
c125e741d3111e2f9b56866ba00835ca05c6f349Jakub Hrozek
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Boseerrno_t ipa_get_ad_override_recv(struct tevent_req *req, int *dp_error_out,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose TALLOC_CTX *mem_ctx,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct sysdb_attrs **override_attrs)
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose{
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct ipa_get_ad_override_state *state = tevent_req_data(req,
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose struct ipa_get_ad_override_state);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose if (dp_error_out != NULL) {
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose *dp_error_out = state->dp_error;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose }
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose TEVENT_REQ_RETURN_ON_ERROR(req);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose if (override_attrs != NULL) {
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose *override_attrs = talloc_steal(mem_ctx, state->override_attrs);
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose }
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose return EOK;
0f3df54840ec9a050cc0b1b68269c3f28c859e64Sumit Bose}