sysdb_views.c revision ab355eced46b5f488ed62a79a7f2e5ac2b6a574c
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose/*
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose SSSD
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose System Database - View and Override related calls
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose Copyright (C) 2014 Sumit Bose <sbose@redhat.com>
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose This program is free software; you can redistribute it and/or modify
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose it under the terms of the GNU General Public License as published by
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose the Free Software Foundation; either version 3 of the License, or
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose (at your option) any later version.
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose This program is distributed in the hope that it will be useful,
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose GNU General Public License for more details.
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose You should have received a copy of the GNU General Public License
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose*/
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose#include "util/util.h"
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose#include "db/sysdb_private.h"
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose/* In general is should not be possible that there is a view container without
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose * a view name set. But to be on the safe side we return both information
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose * separately. */
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bosestatic errno_t sysdb_get_view_name_ex(TALLOC_CTX *mem_ctx,
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose struct sysdb_ctx *sysdb,
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose char **_view_name,
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose bool *view_container_exists)
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose{
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose errno_t ret;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose TALLOC_CTX *tmp_ctx;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose const char *tmp_str;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose struct ldb_dn *view_base_dn;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose struct ldb_result *res;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose const char *attrs[] = {SYSDB_VIEW_NAME,
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose NULL};
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose tmp_ctx = talloc_new(NULL);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose if (tmp_ctx == NULL) {
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose return ENOMEM;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose }
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose view_base_dn = ldb_dn_new(tmp_ctx, sysdb->ldb, SYSDB_TMPL_VIEW_BASE);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose if (view_base_dn == NULL) {
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose ret = EIO;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose goto done;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose }
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose ret = ldb_search(sysdb->ldb, tmp_ctx, &res, view_base_dn, LDB_SCOPE_BASE,
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose attrs, NULL);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose if (ret != LDB_SUCCESS) {
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose ret = EIO;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose goto done;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose }
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose if (res->count > 1) {
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "Base search returned [%d] results, "
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose "expected 1.\n", res->count);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose ret = EINVAL;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose goto done;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose }
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose if (res->count == 0) {
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose *view_container_exists = false;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose ret = ENOENT;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose goto done;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose } else {
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose *view_container_exists = true;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose tmp_str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_VIEW_NAME,
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose NULL);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose if (tmp_str == NULL) {
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose ret = ENOENT;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose goto done;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose }
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose }
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose *_view_name = talloc_steal(mem_ctx, discard_const(tmp_str));
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose ret = EOK;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bosedone:
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose talloc_free(tmp_ctx);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose return ret;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose}
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Boseerrno_t sysdb_get_view_name(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose char **view_name)
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose{
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose bool view_container_exists;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose return sysdb_get_view_name_ex(mem_ctx, sysdb, view_name,
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose &view_container_exists);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose}
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Boseerrno_t sysdb_update_view_name(struct sysdb_ctx *sysdb,
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose const char *view_name)
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose{
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose errno_t ret;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose TALLOC_CTX *tmp_ctx;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose char *tmp_str;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose bool view_container_exists = false;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose bool add_view_name = false;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose struct ldb_message *msg;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose tmp_ctx = talloc_new(NULL);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose if (tmp_ctx == NULL) {
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose return ENOMEM;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose }
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose ret = sysdb_get_view_name_ex(tmp_ctx, sysdb, &tmp_str,
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose &view_container_exists);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose if (ret != EOK && ret != ENOENT) {
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_get_view_name_ex failed.\n");
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose goto done;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose }
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose if (ret == EOK) {
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose if (strcmp(tmp_str, view_name) == 0) {
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose /* view name already known, nothing to do */
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose DEBUG(SSSDBG_TRACE_ALL, "View name already in place.\n");
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose ret = EOK;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose goto done;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose } else {
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose /* view name changed */
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose /* not supported atm */
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose "View name changed from [%s] to [%s]. NOT SUPPORTED.\n",
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose tmp_str, view_name);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose ret = ENOTSUP;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose goto done;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose }
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose }
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose add_view_name = true;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose msg = ldb_msg_new(tmp_ctx);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose if (msg == NULL) {
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_msg_new failed.\n");
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose ret = ENOMEM;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose goto done;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose }
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, SYSDB_TMPL_VIEW_BASE);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose if (msg->dn == NULL) {
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_new failed.\n");
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose ret = EIO;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose goto done;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose }
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose ret = ldb_msg_add_empty(msg, SYSDB_VIEW_NAME,
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose add_view_name ? LDB_FLAG_MOD_ADD
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose : LDB_FLAG_MOD_REPLACE,
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose NULL);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose if (ret != LDB_SUCCESS) {
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose ret = sysdb_error_to_errno(ret);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose goto done;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose }
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose ret = ldb_msg_add_string(msg, SYSDB_VIEW_NAME, view_name);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose if (ret != LDB_SUCCESS) {
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose ret = sysdb_error_to_errno(ret);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose goto done;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose }
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose if (view_container_exists) {
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose ret = ldb_modify(sysdb->ldb, msg);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose } else {
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose ret = ldb_add(sysdb->ldb, msg);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose }
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose if (ret != LDB_SUCCESS) {
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose DEBUG(SSSDBG_FATAL_FAILURE, "Failed to %s view container",
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose view_container_exists ? "modify" : "add");
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose ret = sysdb_error_to_errno(ret);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose goto done;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose }
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bosedone:
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose talloc_free(tmp_ctx);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose return ret;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose}
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bosestatic errno_t
9da27cbc7532f775afc411d809735760dd5294a7Sumit Boseadd_name_and_aliases_for_name_override(struct sss_domain_info *domain,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose struct sysdb_attrs *attrs,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose bool add_name,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose const char *name_override)
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose{
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose char *fq_name = NULL;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose int ret;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (strchr(name_override, '@') == NULL) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose fq_name = sss_tc_fqname(attrs, domain->names, domain, name_override);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (fq_name == NULL) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sss_tc_fqname failed.\n");
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose return ENOMEM;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (!domain->case_sensitive) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = sysdb_attrs_add_lc_name_alias(attrs, fq_name);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose } else {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = sysdb_attrs_add_string(attrs, SYSDB_NAME_ALIAS,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose fq_name);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (ret != EOK) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose "sysdb_attrs_add_lc_name_alias failed.\n");
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (add_name) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose ret = sysdb_attrs_add_string(attrs, SYSDB_DEFAULT_OVERRIDE_NAME,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose fq_name == NULL ? name_override : fq_name);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (ret != EOK) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_attrs_add_lc_name_alias failed.\n");
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (!domain->case_sensitive) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose ret = sysdb_attrs_add_lc_name_alias(attrs, name_override);
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose } else {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose ret = sysdb_attrs_add_string(attrs, SYSDB_NAME_ALIAS, name_override);
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (ret != EOK) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_attrs_add_lc_name_alias failed.\n");
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose goto done;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose ret = EOK;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bosedone:
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose talloc_free(fq_name);
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose return ret;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose}
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Boseerrno_t sysdb_store_override(struct sss_domain_info *domain,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose const char *view_name,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose enum sysdb_member_type type,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose struct sysdb_attrs *attrs, struct ldb_dn *obj_dn)
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose{
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose TALLOC_CTX *tmp_ctx;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose const char *anchor;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose int ret;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose struct ldb_dn *override_dn;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose const char *override_dn_str;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose const char *obj_dn_str;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose const char *obj_attrs[] = { SYSDB_OBJECTCLASS,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose SYSDB_OVERRIDE_DN,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose NULL};
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose size_t count = 0;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose struct ldb_message **msgs;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose struct ldb_message *msg = NULL;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose const char *obj_override_dn;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose bool add_ref = true;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose size_t c;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose bool in_transaction = false;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose bool has_override = true;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose const char *name_override;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose tmp_ctx = talloc_new(NULL);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (tmp_ctx == NULL) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = ENOMEM;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (attrs != NULL) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose has_override = true;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = sysdb_attrs_get_string(attrs, SYSDB_OVERRIDE_ANCHOR_UUID,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose &anchor);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (ret != EOK) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose "Missing anchor in override attributes.\n");
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = EINVAL;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose override_dn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose SYSDB_TMPL_OVERRIDE, anchor, view_name);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (override_dn == NULL) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_new_fmt failed.\n");
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = ENOMEM;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose } else {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose /* if there is no override for the given object, just store the DN of
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose * the object iself in the SYSDB_OVERRIDE_DN attribute to indicate
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose * that it was checked if an override exists and none was found. */
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose has_override = false;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose override_dn = obj_dn;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose override_dn_str = ldb_dn_get_linearized(override_dn);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose obj_dn_str = ldb_dn_get_linearized(obj_dn);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (override_dn_str == NULL || obj_dn_str == NULL) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_get_linearized failed.\n");
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = ENOMEM;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = sysdb_search_entry(tmp_ctx, domain->sysdb, obj_dn, LDB_SCOPE_BASE,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose NULL, obj_attrs, &count, &msgs);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (ret != EOK) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (ret == ENOENT) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Object to override does not exists.\n");
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose } else {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_search_entry failed.\n");
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (count != 1) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Base searched returned more than one object.\n");
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = EINVAL;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose obj_override_dn = ldb_msg_find_attr_as_string(msgs[0], SYSDB_OVERRIDE_DN,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose NULL);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (obj_override_dn != NULL) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (strcmp(obj_override_dn, override_dn_str) != 0) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose "Existing [%s] and new [%s] override DN do not match.\n",
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose obj_override_dn, override_dn_str);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = EINVAL;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose add_ref = false;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = ldb_transaction_start(domain->sysdb->ldb);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (ret != EOK) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose return sysdb_error_to_errno(ret);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose in_transaction = true;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (has_override) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = ldb_delete(domain->sysdb->ldb, override_dn);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (ret != EOK) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose DEBUG(SSSDBG_TRACE_ALL,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose "ldb_delete failed, maybe object did not exist. Ignoring.\n");
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = sysdb_attrs_get_string(attrs, SYSDB_NAME, &name_override);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (ret == EOK) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose ret = add_name_and_aliases_for_name_override(domain, attrs, false,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose name_override);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (ret != EOK) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose "add_name_and_aliases_for_name_override failed.\n");
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose } else if (ret != ENOENT) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_attrs_get_string failed.\n");
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose msg = ldb_msg_new(tmp_ctx);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (msg == NULL) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = ENOMEM;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose msg->dn = override_dn;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose msg->elements = talloc_array(msg, struct ldb_message_element,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose attrs->num);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (msg->elements == NULL) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = ENOMEM;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose /* TODO: add nameAlias for case-insentitive searches */
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose for (c = 0; c < attrs->num; c++) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose msg->elements[c] = attrs->a[c];
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose msg->elements[c].flags = LDB_FLAG_MOD_ADD;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose msg->num_elements = attrs->num;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = ldb_msg_add_empty(msg, SYSDB_OBJECTCLASS, LDB_FLAG_MOD_ADD, NULL);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (ret != LDB_SUCCESS) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_msg_add_empty failed.\n");
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = sysdb_error_to_errno(ret);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose switch(type) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose case SYSDB_MEMBER_USER:
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = ldb_msg_add_string(msg, SYSDB_OBJECTCLASS,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose SYSDB_OVERRIDE_USER_CLASS);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose break;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose case SYSDB_MEMBER_GROUP:
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = ldb_msg_add_string(msg, SYSDB_OBJECTCLASS,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose SYSDB_OVERRIDE_GROUP_CLASS);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose break;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose default:
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Unexpected object type.\n");
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = EINVAL;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (ret != LDB_SUCCESS) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = sysdb_error_to_errno(ret);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = ldb_msg_add_empty(msg, SYSDB_OVERRIDE_OBJECT_DN, LDB_FLAG_MOD_ADD,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose NULL);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (ret != LDB_SUCCESS) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_msg_add_empty failed.\n");
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = sysdb_error_to_errno(ret);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = ldb_msg_add_string(msg, SYSDB_OVERRIDE_OBJECT_DN, obj_dn_str);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (ret != LDB_SUCCESS) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = sysdb_error_to_errno(ret);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = ldb_add(domain->sysdb->ldb, msg);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (ret != LDB_SUCCESS) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose "Failed to store override entry: %s(%d)[%s]\n",
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ldb_strerror(ret), ret, ldb_errstring(domain->sysdb->ldb));
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = sysdb_error_to_errno(ret);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (add_ref) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose talloc_free(msg);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose msg = ldb_msg_new(tmp_ctx);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (msg == NULL) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = ENOMEM;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose msg->dn = obj_dn;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = ldb_msg_add_empty(msg, SYSDB_OVERRIDE_DN, LDB_FLAG_MOD_ADD,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose NULL);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (ret != LDB_SUCCESS) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_msg_add_empty failed.\n");
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = sysdb_error_to_errno(ret);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = ldb_msg_add_string(msg, SYSDB_OVERRIDE_DN, override_dn_str);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (ret != LDB_SUCCESS) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = sysdb_error_to_errno(ret);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = ldb_modify(domain->sysdb->ldb, msg);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (ret != LDB_SUCCESS) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose "Failed to store override DN: %s(%d)[%s]\n",
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ldb_strerror(ret), ret, ldb_errstring(domain->sysdb->ldb));
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = sysdb_error_to_errno(ret);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose goto done;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = EOK;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bosedone:
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (in_transaction) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (ret != EOK) {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose DEBUG(SSSDBG_TRACE_FUNC, "Error: %d (%s)\n", ret, strerror(ret));
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ldb_transaction_cancel(domain->sysdb->ldb);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose } else {
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = ldb_transaction_commit(domain->sysdb->ldb);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose ret = sysdb_error_to_errno(ret);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose talloc_zfree(tmp_ctx);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose return ret;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose}
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bosestatic errno_t safe_original_attributes(struct sss_domain_info *domain,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose struct sysdb_attrs *attrs,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose struct ldb_dn *obj_dn,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose const char **allowed_attrs)
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose{
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose int ret;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose size_t c;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose TALLOC_CTX *tmp_ctx;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose struct ldb_result *orig_obj;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose char *orig_attr_name;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose struct ldb_message_element *el = NULL;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose tmp_ctx = talloc_new(NULL);
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (tmp_ctx == NULL) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose return ENOMEM;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose ret = ldb_search(domain->sysdb->ldb, tmp_ctx, &orig_obj, obj_dn,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose LDB_SCOPE_BASE, NULL, NULL);
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (ret != EOK || orig_obj->count != 1) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Original object not found.\n");
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose goto done;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose /* Safe orginal values in attributes prefixed by OriginalAD. */
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose for (c = 0; allowed_attrs[c] != NULL; c++) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose el = ldb_msg_find_element(orig_obj->msgs[0], allowed_attrs[c]);
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (el != NULL) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose orig_attr_name = talloc_asprintf(tmp_ctx, "%s%s",
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose ORIGINALAD_PREFIX,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose allowed_attrs[c]);
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (orig_attr_name == NULL) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n");
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose ret = ENOMEM;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose goto done;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose ret = sysdb_attrs_add_val(attrs, orig_attr_name,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose &el->values[0]);
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (ret != EOK) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose "sysdb_attrs_add_val failed.\n");
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose goto done;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose } else {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose DEBUG(SSSDBG_TRACE_ALL,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose "Original object does not have [%s] set.\n",
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose allowed_attrs[c]);
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose /* Add existing aliases to new ones */
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose el = ldb_msg_find_element(orig_obj->msgs[0], SYSDB_NAME_ALIAS);
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (el != NULL) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose for (c = 0; c < el->num_values; c++) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose /* To avoid issue with ldb_modify if e.g. the orginal and the
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose * override name are the same, we use the *_safe version here. */
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose ret = sysdb_attrs_add_val_safe(attrs, SYSDB_NAME_ALIAS,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose &el->values[c]);
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (ret != EOK) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_attrs_add_val failed.\n");
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose goto done;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose ret = EOK;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bosedone:
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose talloc_free(tmp_ctx);
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose return ret;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose}
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Boseerrno_t sysdb_apply_default_override(struct sss_domain_info *domain,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose struct sysdb_attrs *override_attrs,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose struct ldb_dn *obj_dn)
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose{
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose int ret;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose TALLOC_CTX *tmp_ctx;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose struct sysdb_attrs *attrs;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose size_t c;
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose size_t d;
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose size_t num_values;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose struct ldb_message_element *el = NULL;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose const char *allowed_attrs[] = { SYSDB_UIDNUM,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose SYSDB_GIDNUM,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose SYSDB_GECOS,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose SYSDB_HOMEDIR,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose SYSDB_SHELL,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose SYSDB_NAME,
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose SYSDB_SSH_PUBKEY,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose NULL };
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose bool override_attrs_found = false;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose tmp_ctx = talloc_new(NULL);
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (tmp_ctx == NULL) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose return ENOMEM;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose attrs = sysdb_new_attrs(tmp_ctx);
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (attrs == NULL) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_new_attrs failed.\n");
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose ret = ENOMEM;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose goto done;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose for (c = 0; allowed_attrs[c] != NULL; c++) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose ret = sysdb_attrs_get_el_ext(override_attrs, allowed_attrs[c], false,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose &el);
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (ret == EOK) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose override_attrs_found = true;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (strcmp(allowed_attrs[c], SYSDB_NAME) == 0) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (el->values[0].data[el->values[0].length] != '\0') {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose "String attribute does not end with \\0.\n");
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose ret = EINVAL;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose goto done;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose ret = add_name_and_aliases_for_name_override(domain, attrs,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose true,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose (char *) el->values[0].data);
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (ret != EOK) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose "add_name_and_aliases_for_name_override failed.\n");
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose goto done;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose } else {
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose num_values = el->num_values;
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose /* Only SYSDB_SSH_PUBKEY is allowed to have multiple values. */
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose if (strcmp(allowed_attrs[c], SYSDB_SSH_PUBKEY) != 0
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose && num_values != 1) {
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose DEBUG(SSSDBG_MINOR_FAILURE,
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose "Override attribute for [%s] has more [%zd] " \
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose "than one value, using only the first.\n",
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose allowed_attrs[c], num_values);
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose num_values = 1;
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose }
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose for (d = 0; d < num_values; d++) {
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose ret = sysdb_attrs_add_val(attrs, allowed_attrs[c],
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose &el->values[d]);
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose if (ret != EOK) {
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose DEBUG(SSSDBG_OP_FAILURE,
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose "sysdb_attrs_add_val failed.\n");
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose goto done;
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose }
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose DEBUG(SSSDBG_TRACE_ALL,
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose "Override [%s] with [%.*s] for [%s].\n",
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose allowed_attrs[c], (int) el->values[d].length,
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose el->values[d].data, ldb_dn_get_linearized(obj_dn));
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose } else if (ret != ENOENT) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_attrs_get_el_ext failed.\n");
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose goto done;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (override_attrs_found) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose ret = safe_original_attributes(domain, attrs, obj_dn, allowed_attrs);
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (ret != EOK) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "safe_original_attributes failed.\n");
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose goto done;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose ret = sysdb_set_entry_attr(domain->sysdb, obj_dn, attrs, SYSDB_MOD_REP);
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (ret != EOK) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_set_entry_attr failed.\n");
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose goto done;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose ret = EOK;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bosedone:
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose talloc_free(tmp_ctx);
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose return ret;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose}
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose#define SYSDB_USER_NAME_OVERRIDE_FILTER "(&(objectClass="SYSDB_OVERRIDE_USER_CLASS")(|("SYSDB_NAME_ALIAS"=%s)("SYSDB_NAME_ALIAS"=%s)("SYSDB_NAME"=%s)))"
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose#define SYSDB_USER_UID_OVERRIDE_FILTER "(&(objectClass="SYSDB_OVERRIDE_USER_CLASS")("SYSDB_UIDNUM"=%lu))"
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose#define SYSDB_GROUP_NAME_OVERRIDE_FILTER "(&(objectClass="SYSDB_OVERRIDE_GROUP_CLASS")(|("SYSDB_NAME_ALIAS"=%s)("SYSDB_NAME_ALIAS"=%s)("SYSDB_NAME"=%s)))"
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose#define SYSDB_GROUP_GID_OVERRIDE_FILTER "(&(objectClass="SYSDB_OVERRIDE_GROUP_CLASS")("SYSDB_GIDNUM"=%lu))"
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Boseenum override_object_type {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose OO_TYPE_UNDEF = 0,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose OO_TYPE_USER,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose OO_TYPE_GROUP
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose};
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bosestatic errno_t sysdb_search_override_by_name(TALLOC_CTX *mem_ctx,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose struct sss_domain_info *domain,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose const char *name,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina const char *filter,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina const char **attrs,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose struct ldb_result **override_obj,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose struct ldb_result **orig_obj)
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose{
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose TALLOC_CTX *tmp_ctx;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose struct ldb_dn *base_dn;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose struct ldb_result *override_res;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose struct ldb_result *orig_res;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose char *sanitized_name;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose char *lc_sanitized_name;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose const char *src_name;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose int ret;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose const char *orig_obj_dn;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose tmp_ctx = talloc_new(NULL);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose if (!tmp_ctx) {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose return ENOMEM;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose base_dn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose SYSDB_TMPL_VIEW_SEARCH_BASE, domain->view_name);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose if (base_dn == NULL) {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_new_fmt failed.\n");
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = ENOMEM;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose goto done;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose /* If this is a subdomain we need to use fully qualified names for the
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose * search as well by default */
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose src_name = sss_get_domain_name(tmp_ctx, name, domain);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose if (src_name == NULL) {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sss_get_domain_name failed.\n");
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = ENOMEM;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose goto done;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = sss_filter_sanitize_for_dom(tmp_ctx, src_name, domain,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose &sanitized_name, &lc_sanitized_name);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose if (ret != EOK) {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sss_filter_sanitize_for_dom failed.\n");
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose goto done;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = ldb_search(domain->sysdb->ldb, tmp_ctx, &override_res, base_dn,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose LDB_SCOPE_SUBTREE, attrs, filter,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose lc_sanitized_name,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose sanitized_name, sanitized_name);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose if (ret != LDB_SUCCESS) {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = sysdb_error_to_errno(ret);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose goto done;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose if (override_res->count == 0) {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose DEBUG(SSSDBG_TRACE_FUNC, "No user override found for name [%s].\n",
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose name);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = ENOENT;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose goto done;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose } else if (override_res->count > 1) {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
e087497ad7648e81a1b4d0752e07c2fb6fcfe2b1Pavel Reichl "Found more than one override for name [%s].\n", name);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = EINVAL;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose goto done;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose if (orig_obj != NULL) {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose orig_obj_dn = ldb_msg_find_attr_as_string(override_res->msgs[0],
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose SYSDB_OVERRIDE_OBJECT_DN,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose NULL);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose if (orig_obj_dn == NULL) {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose "Missing link to original object in override [%s].\n",
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ldb_dn_get_linearized(override_res->msgs[0]->dn));
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = EINVAL;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose goto done;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose base_dn = ldb_dn_new(tmp_ctx, domain->sysdb->ldb, orig_obj_dn);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose if (base_dn == NULL) {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_new failed.\n");
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = ENOMEM;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose goto done;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = ldb_search(domain->sysdb->ldb, tmp_ctx, &orig_res, base_dn,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose LDB_SCOPE_BASE, attrs, NULL);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose if (ret != LDB_SUCCESS) {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = sysdb_error_to_errno(ret);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose goto done;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose *orig_obj = talloc_steal(mem_ctx, orig_res);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose *override_obj = talloc_steal(mem_ctx, override_res);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = EOK;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bosedone:
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose talloc_zfree(tmp_ctx);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose return ret;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose}
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
727d46f4dace666c809310b3f685eef387023f65Pavel Březinaerrno_t sysdb_search_user_override_attrs_by_name(TALLOC_CTX *mem_ctx,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina struct sss_domain_info *domain,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina const char *name,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina const char **attrs,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina struct ldb_result **override_obj,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina struct ldb_result **orig_obj)
727d46f4dace666c809310b3f685eef387023f65Pavel Březina{
727d46f4dace666c809310b3f685eef387023f65Pavel Březina
727d46f4dace666c809310b3f685eef387023f65Pavel Březina return sysdb_search_override_by_name(mem_ctx, domain, name,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina SYSDB_USER_NAME_OVERRIDE_FILTER,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina attrs, override_obj, orig_obj);
727d46f4dace666c809310b3f685eef387023f65Pavel Březina}
727d46f4dace666c809310b3f685eef387023f65Pavel Březina
727d46f4dace666c809310b3f685eef387023f65Pavel Březinaerrno_t sysdb_search_group_override_attrs_by_name(TALLOC_CTX *mem_ctx,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina struct sss_domain_info *domain,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina const char *name,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina const char **attrs,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina struct ldb_result **override_obj,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina struct ldb_result **orig_obj)
727d46f4dace666c809310b3f685eef387023f65Pavel Březina{
727d46f4dace666c809310b3f685eef387023f65Pavel Březina return sysdb_search_override_by_name(mem_ctx, domain, name,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina SYSDB_GROUP_NAME_OVERRIDE_FILTER,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina attrs, override_obj, orig_obj);
727d46f4dace666c809310b3f685eef387023f65Pavel Březina}
727d46f4dace666c809310b3f685eef387023f65Pavel Březina
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Boseerrno_t sysdb_search_user_override_by_name(TALLOC_CTX *mem_ctx,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose struct sss_domain_info *domain,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose const char *name,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose struct ldb_result **override_obj,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose struct ldb_result **orig_obj)
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose{
727d46f4dace666c809310b3f685eef387023f65Pavel Březina const char *attrs[] = SYSDB_PW_ATTRS;
727d46f4dace666c809310b3f685eef387023f65Pavel Březina
727d46f4dace666c809310b3f685eef387023f65Pavel Březina return sysdb_search_override_by_name(mem_ctx, domain, name,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina SYSDB_USER_NAME_OVERRIDE_FILTER,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina attrs, override_obj, orig_obj);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose}
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Boseerrno_t sysdb_search_group_override_by_name(TALLOC_CTX *mem_ctx,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose struct sss_domain_info *domain,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose const char *name,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose struct ldb_result **override_obj,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose struct ldb_result **orig_obj)
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose{
727d46f4dace666c809310b3f685eef387023f65Pavel Březina const char *attrs[] = SYSDB_GRSRC_ATTRS;
727d46f4dace666c809310b3f685eef387023f65Pavel Březina
727d46f4dace666c809310b3f685eef387023f65Pavel Březina return sysdb_search_override_by_name(mem_ctx, domain, name,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina SYSDB_GROUP_NAME_OVERRIDE_FILTER,
727d46f4dace666c809310b3f685eef387023f65Pavel Březina attrs, override_obj, orig_obj);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose}
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bosestatic errno_t sysdb_search_override_by_id(TALLOC_CTX *mem_ctx,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose struct sss_domain_info *domain,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose unsigned long int id,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose enum override_object_type type,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose struct ldb_result **override_obj,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose struct ldb_result **orig_obj)
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose{
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose TALLOC_CTX *tmp_ctx;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose static const char *user_attrs[] = SYSDB_PW_ATTRS;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose static const char *group_attrs[] = SYSDB_GRSRC_ATTRS;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose const char **attrs;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose struct ldb_dn *base_dn;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose struct ldb_result *override_res;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose struct ldb_result *orig_res;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose int ret;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose const char *orig_obj_dn;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose const char *filter;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose tmp_ctx = talloc_new(NULL);
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose if (!tmp_ctx) {
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose return ENOMEM;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose }
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose base_dn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose SYSDB_TMPL_VIEW_SEARCH_BASE, domain->view_name);
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose if (base_dn == NULL) {
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_new_fmt failed.\n");
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose ret = ENOMEM;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose goto done;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose }
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose switch(type) {
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose case OO_TYPE_USER:
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose filter = SYSDB_USER_UID_OVERRIDE_FILTER;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose attrs = user_attrs;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose break;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose case OO_TYPE_GROUP:
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose filter = SYSDB_GROUP_GID_OVERRIDE_FILTER;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose attrs = group_attrs;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose break;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose default:
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Unexpected override object type [%d].\n",
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose type);
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose ret = EINVAL;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose goto done;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose }
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose ret = ldb_search(domain->sysdb->ldb, tmp_ctx, &override_res, base_dn,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose LDB_SCOPE_SUBTREE, attrs, filter, id);
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose if (ret != LDB_SUCCESS) {
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose ret = sysdb_error_to_errno(ret);
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose goto done;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose }
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose if (override_res->count == 0) {
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose DEBUG(SSSDBG_TRACE_FUNC,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose "No user override found for %s with id [%lu].\n",
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose (type == OO_TYPE_USER ? "user" : "group"), id);
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose ret = ENOENT;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose goto done;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose } else if (override_res->count > 1) {
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
e087497ad7648e81a1b4d0752e07c2fb6fcfe2b1Pavel Reichl "Found more than one override for id [%lu].\n", id);
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose ret = EINVAL;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose goto done;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose }
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose if (orig_obj != NULL) {
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose orig_obj_dn = ldb_msg_find_attr_as_string(override_res->msgs[0],
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose SYSDB_OVERRIDE_OBJECT_DN,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose NULL);
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose if (orig_obj_dn == NULL) {
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose "Missing link to original object in override [%s].\n",
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose ldb_dn_get_linearized(override_res->msgs[0]->dn));
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose ret = EINVAL;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose goto done;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose }
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose base_dn = ldb_dn_new(tmp_ctx, domain->sysdb->ldb, orig_obj_dn);
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose if (base_dn == NULL) {
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_new failed.\n");
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose ret = ENOMEM;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose goto done;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose }
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose ret = ldb_search(domain->sysdb->ldb, tmp_ctx, &orig_res, base_dn,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose LDB_SCOPE_BASE, attrs, NULL);
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose if (ret != LDB_SUCCESS) {
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose ret = sysdb_error_to_errno(ret);
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose goto done;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose }
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose *orig_obj = talloc_steal(mem_ctx, orig_res);
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose }
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose *override_obj = talloc_steal(mem_ctx, override_res);
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose ret = EOK;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bosedone:
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose talloc_zfree(tmp_ctx);
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose return ret;
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose}
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Boseerrno_t sysdb_search_user_override_by_uid(TALLOC_CTX *mem_ctx,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose struct sss_domain_info *domain,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose uid_t uid,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose struct ldb_result **override_obj,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose struct ldb_result **orig_obj)
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose{
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose return sysdb_search_override_by_id(mem_ctx, domain, uid, OO_TYPE_USER,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose override_obj, orig_obj);
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose}
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Boseerrno_t sysdb_search_group_override_by_gid(TALLOC_CTX *mem_ctx,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose struct sss_domain_info *domain,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose gid_t gid,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose struct ldb_result **override_obj,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose struct ldb_result **orig_obj)
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose{
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose return sysdb_search_override_by_id(mem_ctx, domain, gid, OO_TYPE_GROUP,
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose override_obj, orig_obj);
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose}
89b065cb85f57e80760ce4d4b1215b533e249e92Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose/**
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose * @brief Add override data to the original object
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose *
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose * @param[in] domain Domain struct, needed to access the cache
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose * @oaram[in] obj The original object
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose * @param[in] override_obj The object with the override data, may be NULL
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose * @param[in] req_attrs List of attributes to be requested, if not set a
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose * default list dependig on the object type will be used
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose *
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose * @return EOK - Override data was added successfully
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose * @return ENOMEM - There was insufficient memory to complete the operation
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose * @return ENOENT - The original object did not have the SYSDB_OVERRIDE_DN
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose * attribute or the value of the attribute points an object
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose * which does not exists. Both conditions indicate that the
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose * cache must be refreshed.
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose */
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Boseerrno_t sysdb_add_overrides_to_object(struct sss_domain_info *domain,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose struct ldb_message *obj,
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose struct ldb_message *override_obj,
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose const char **req_attrs)
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose{
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose int ret;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose const char *override_dn_str;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose struct ldb_dn *override_dn;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose TALLOC_CTX *tmp_ctx;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose struct ldb_result *res;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose struct ldb_message *override;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose uint64_t uid;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose static const char *user_attrs[] = SYSDB_PW_ATTRS;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose static const char *group_attrs[] = SYSDB_GRSRC_ATTRS;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose const char **attrs;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose struct attr_map {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose const char *attr;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose const char *new_attr;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose } attr_map[] = {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose {SYSDB_UIDNUM, OVERRIDE_PREFIX SYSDB_UIDNUM},
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose {SYSDB_GIDNUM, OVERRIDE_PREFIX SYSDB_GIDNUM},
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose {SYSDB_GECOS, OVERRIDE_PREFIX SYSDB_GECOS},
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose {SYSDB_HOMEDIR, OVERRIDE_PREFIX SYSDB_HOMEDIR},
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose {SYSDB_SHELL, OVERRIDE_PREFIX SYSDB_SHELL},
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose {SYSDB_NAME, OVERRIDE_PREFIX SYSDB_NAME},
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose {SYSDB_SSH_PUBKEY, OVERRIDE_PREFIX SYSDB_SSH_PUBKEY},
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose {NULL, NULL}
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose };
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose size_t c;
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose size_t d;
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose struct ldb_message_element *tmp_el;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose tmp_ctx = talloc_new(NULL);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose if (tmp_ctx == NULL) {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose return ENOMEM;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose if (override_obj == NULL) {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose override_dn_str = ldb_msg_find_attr_as_string(obj,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose SYSDB_OVERRIDE_DN, NULL);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose if (override_dn_str == NULL) {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose "Missing override DN for objext [%s].\n",
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ldb_dn_get_linearized(obj->dn));
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = ENOENT;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose goto done;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose override_dn = ldb_dn_new(tmp_ctx, domain->sysdb->ldb, override_dn_str);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose if (override_dn == NULL) {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_new failed.\n");
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = ENOMEM;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose goto done;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose if (ldb_dn_compare(obj->dn, override_dn) == 0) {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose DEBUG(SSSDBG_TRACE_ALL, "Object [%s] has no overrides.\n",
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ldb_dn_get_linearized(obj->dn));
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = EOK;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose goto done;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose attrs = req_attrs;
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose if (attrs == NULL) {
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose uid = ldb_msg_find_attr_as_uint64(obj, SYSDB_UIDNUM, 0);
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose if (uid == 0) {
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose /* No UID hence group object */
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose attrs = group_attrs;
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose } else {
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose attrs = user_attrs;
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = ldb_search(domain->sysdb->ldb, tmp_ctx, &res, override_dn,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose LDB_SCOPE_BASE, attrs, NULL);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose if (ret != LDB_SUCCESS) {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = sysdb_error_to_errno(ret);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose goto done;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose if (res->count == 1) {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose override = res->msgs[0];
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose } else if (res->count == 0) {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose DEBUG(SSSDBG_TRACE_FUNC, "Override object [%s] does not exists.\n",
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose override_dn_str);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = ENOENT;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose goto done;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose } else {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose "Base search for override object returned [%d] results.\n",
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose res->count);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = EINVAL;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose goto done;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose } else {
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose override = override_obj;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose for (c = 0; attr_map[c].attr != NULL; c++) {
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose tmp_el = ldb_msg_find_element(override, attr_map[c].attr);
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose if (tmp_el != NULL) {
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose for (d = 0; d < tmp_el->num_values; d++) {
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose ret = ldb_msg_add_steal_value(obj, attr_map[c].new_attr,
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose &tmp_el->values[d]);
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose if (ret != LDB_SUCCESS) {
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_msg_add_value failed.\n");
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose ret = sysdb_error_to_errno(ret);
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose goto done;
1a9f66352070d71a6b998c5afbc268ba6fddc51cSumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose }
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ret = EOK;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bosedone:
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose talloc_free(tmp_ctx);
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose return ret;
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose}
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Boseerrno_t sysdb_add_group_member_overrides(struct sss_domain_info *domain,
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose struct ldb_message *obj)
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose{
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose int ret;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose size_t c;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose struct ldb_message_element *members;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose TALLOC_CTX *tmp_ctx;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose struct ldb_dn *member_dn;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose struct ldb_result *member_obj;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose struct ldb_result *override_obj;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose static const char *member_attrs[] = SYSDB_PW_ATTRS;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose const char *override_dn_str;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose struct ldb_dn *override_dn;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose const char *memberuid;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose members = ldb_msg_find_element(obj, SYSDB_MEMBER);
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose if (members == NULL || members->num_values == 0) {
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose DEBUG(SSSDBG_TRACE_ALL, "Group has no members.\n");
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose return EOK;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose }
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose tmp_ctx = talloc_new(NULL);
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose if (tmp_ctx == NULL) {
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose ret = ENOMEM;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose goto done;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose }
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose for (c = 0; c < members->num_values; c++) {
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose member_dn = ldb_dn_from_ldb_val(tmp_ctx, domain->sysdb->ldb,
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose &members->values[c]);
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose if (member_dn == NULL) {
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_from_ldb_val failed.\n");
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose ret = ENOMEM;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose goto done;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose }
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose ret = ldb_search(domain->sysdb->ldb, member_dn, &member_obj, member_dn,
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose LDB_SCOPE_BASE, member_attrs, NULL);
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose if (ret != LDB_SUCCESS) {
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose ret = sysdb_error_to_errno(ret);
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose goto done;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose }
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose if (member_obj->count != 1) {
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose "Base search for member object returned [%d] results.\n",
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose member_obj->count);
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose ret = EINVAL;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose goto done;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose }
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose override_dn_str = ldb_msg_find_attr_as_string(member_obj->msgs[0],
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose SYSDB_OVERRIDE_DN, NULL);
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose if (override_dn_str == NULL) {
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose "Missing override DN for objext [%s].\n",
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose ldb_dn_get_linearized(member_obj->msgs[0]->dn));
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose ret = ENOENT;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose goto done;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose }
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose override_dn = ldb_dn_new(member_obj, domain->sysdb->ldb,
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose override_dn_str);
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose if (override_dn == NULL) {
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_new failed.\n");
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose ret = ENOMEM;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose goto done;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose }
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose memberuid = NULL;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose if (ldb_dn_compare(member_obj->msgs[0]->dn, override_dn) != 0) {
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose DEBUG(SSSDBG_TRACE_ALL, "Checking override for object [%s].\n",
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose ldb_dn_get_linearized(member_obj->msgs[0]->dn));
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose ret = ldb_search(domain->sysdb->ldb, member_obj, &override_obj,
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose override_dn, LDB_SCOPE_BASE, member_attrs, NULL);
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose if (ret != LDB_SUCCESS) {
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose ret = sysdb_error_to_errno(ret);
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose goto done;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose }
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose if (override_obj->count != 1) {
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose "Base search for override object returned [%d] results.\n",
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose member_obj->count);
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose ret = EINVAL;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose goto done;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose }
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose memberuid = ldb_msg_find_attr_as_string(override_obj->msgs[0],
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose SYSDB_NAME,
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose NULL);
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose }
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose if (memberuid == NULL) {
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose DEBUG(SSSDBG_TRACE_ALL, "No override name available.\n");
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose memberuid = ldb_msg_find_attr_as_string(member_obj->msgs[0],
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose SYSDB_NAME,
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose NULL);
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose if (memberuid == NULL) {
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Object [%s] has no name.\n",
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose ldb_dn_get_linearized(member_obj->msgs[0]->dn));
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose ret = EINVAL;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose goto done;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose }
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose }
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose ret = ldb_msg_add_string(obj, OVERRIDE_PREFIX SYSDB_MEMBERUID,
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose memberuid);
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose if (ret != LDB_SUCCESS) {
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_msg_add_string failed.\n");
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose ret = sysdb_error_to_errno(ret);
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose goto done;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose }
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose /* Free all temporary data of the current member to avoid memory usage
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose * spikes. All temporary data should be allocated below member_dn. */
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose talloc_free(member_dn);
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose }
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose ret = EOK;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bosedone:
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose talloc_free(tmp_ctx);
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose return ret;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose}
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bosestruct ldb_message_element *
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bosesss_view_ldb_msg_find_element(struct sss_domain_info *dom,
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose const struct ldb_message *msg,
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose const char *attr_name)
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose{
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose TALLOC_CTX *tmp_ctx = NULL;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose struct ldb_message_element *val;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose char *override_attr_name;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose if (DOM_HAS_VIEWS(dom)) {
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose tmp_ctx = talloc_new(NULL);
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose if (tmp_ctx == NULL) {
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose val = NULL;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose goto done;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose }
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose override_attr_name = talloc_asprintf(tmp_ctx, "%s%s", OVERRIDE_PREFIX,
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose attr_name);
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose if (override_attr_name == NULL) {
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n");
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose val = NULL;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose goto done;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose }
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose val = ldb_msg_find_element(msg, override_attr_name);
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose if (val != NULL) {
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose goto done;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose }
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose }
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose val = ldb_msg_find_element(msg, attr_name);
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bosedone:
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose talloc_free(tmp_ctx);
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose return val;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose}
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Boseuint64_t sss_view_ldb_msg_find_attr_as_uint64(struct sss_domain_info *dom,
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose const struct ldb_message *msg,
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose const char *attr_name,
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose uint64_t default_value)
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose{
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose TALLOC_CTX *tmp_ctx = NULL;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose uint64_t val;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose char *override_attr_name;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose if (DOM_HAS_VIEWS(dom)) {
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose tmp_ctx = talloc_new(NULL);
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose if (tmp_ctx == NULL) {
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose val = default_value;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose goto done;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose }
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose override_attr_name = talloc_asprintf(tmp_ctx, "%s%s", OVERRIDE_PREFIX,
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose attr_name);
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose if (override_attr_name == NULL) {
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n");
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose val = default_value;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose goto done;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose }
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose if (ldb_msg_find_element(msg, override_attr_name) != NULL) {
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose val = ldb_msg_find_attr_as_uint64(msg, override_attr_name,
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose default_value);
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose goto done;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose }
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose }
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose val = ldb_msg_find_attr_as_uint64(msg, attr_name, default_value);
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bosedone:
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose talloc_free(tmp_ctx);
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose return val;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose}
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Boseconst char *sss_view_ldb_msg_find_attr_as_string(struct sss_domain_info *dom,
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose const struct ldb_message *msg,
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose const char *attr_name,
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose const char * default_value)
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose{
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose TALLOC_CTX *tmp_ctx = NULL;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose const char *val;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose char *override_attr_name;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose if (DOM_HAS_VIEWS(dom)) {
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose tmp_ctx = talloc_new(NULL);
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose if (tmp_ctx == NULL) {
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose val = default_value;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose goto done;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose }
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose override_attr_name = talloc_asprintf(tmp_ctx, "%s%s", OVERRIDE_PREFIX,
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose attr_name);
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose if (override_attr_name == NULL) {
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_asprintf failed.\n");
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose val = default_value;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose goto done;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose }
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose if (ldb_msg_find_element(msg, override_attr_name) != NULL) {
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose val = ldb_msg_find_attr_as_string(msg, override_attr_name,
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose default_value);
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose goto done;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose }
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose }
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose val = ldb_msg_find_attr_as_string(msg, attr_name, default_value);
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bosedone:
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose talloc_free(tmp_ctx);
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose return val;
ba88f3617e5a56bba19a0d65d35069d8e4d0c89cSumit Bose}