sysdb_views.c revision fb81f337b68c85471c3f5140850dccf549a2d0ac
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"
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose#include "util/cert.h"
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose#include "db/sysdb_private.h"
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio#include "db/sysdb_domain_resolution_order.h"
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio#define SYSDB_VIEWS_BASE "cn=views,cn=sysdb"
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 */
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose DEBUG(SSSDBG_CONF_SETTINGS,
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose "View name changed from [%s] to [%s].\n", tmp_str, view_name);
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose }
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose } else {
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose add_view_name = true;
2ef62c64e7f07c8aced3f72850008ecb72860162Sumit Bose }
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) {
04d138472cc086fb7961f0d378852b09961b1a33Lukas Slebodnik DEBUG(SSSDBG_FATAL_FAILURE,
04d138472cc086fb7961f0d378852b09961b1a33Lukas Slebodnik "Failed to %s view container [%s](%d)[%s]\n",
04d138472cc086fb7961f0d378852b09961b1a33Lukas Slebodnik view_container_exists ? "modify" : "add",
04d138472cc086fb7961f0d378852b09961b1a33Lukas Slebodnik ldb_strerror(ret), ret, ldb_errstring(sysdb->ldb));
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
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncioerrno_t
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidênciosysdb_get_view_domain_resolution_order(TALLOC_CTX *mem_ctx,
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio struct sysdb_ctx *sysdb,
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio const char **_domain_resolution_order)
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio{
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio TALLOC_CTX *tmp_ctx;
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio struct ldb_dn *dn;
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio errno_t ret;
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio tmp_ctx = talloc_new(NULL);
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio if (tmp_ctx == NULL) {
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio return ENOMEM;
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio }
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio dn = ldb_dn_new(tmp_ctx, sysdb->ldb, SYSDB_VIEWS_BASE);
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio if (dn == NULL) {
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio ret = ENOMEM;
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio goto done;
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio }
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio ret = sysdb_get_domain_resolution_order(mem_ctx, sysdb, dn,
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio _domain_resolution_order);
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidênciodone:
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio talloc_free(tmp_ctx);
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio return ret;
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio}
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncioerrno_t
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidênciosysdb_update_view_domain_resolution_order(struct sysdb_ctx *sysdb,
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio const char *domain_resolution_order)
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio{
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio TALLOC_CTX *tmp_ctx;
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio struct ldb_dn *dn;
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio errno_t ret;
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio tmp_ctx = talloc_new(NULL);
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio if (tmp_ctx == NULL) {
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio return ENOMEM;
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio }
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio dn = ldb_dn_new(tmp_ctx, sysdb->ldb, SYSDB_VIEWS_BASE);
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio if (dn == NULL) {
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio ret = ENOMEM;
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio goto done;
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio }
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio ret = sysdb_update_domain_resolution_order(sysdb, dn,
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio domain_resolution_order);
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio if (ret != EOK) {
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio DEBUG(SSSDBG_OP_FAILURE,
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio "sysdb_update_domain_resolution_order() failed [%d]: [%s].\n",
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio ret, sss_strerror(ret));
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio goto done;
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio }
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio ret = EOK;
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidênciodone:
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio talloc_free(tmp_ctx);
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio return ret;
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio}
fb81f337b68c85471c3f5140850dccf549a2d0acFabiano Fidêncio
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Boseerrno_t sysdb_delete_view_tree(struct sysdb_ctx *sysdb, const char *view_name)
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose{
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose struct ldb_dn *dn;
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose TALLOC_CTX *tmp_ctx;
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose int ret;
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose tmp_ctx = talloc_new(NULL);
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose if (tmp_ctx == NULL) {
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose return ENOMEM;
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose }
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_TMPL_VIEW_SEARCH_BASE,
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose view_name);
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose if (dn == NULL) {
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_new_fmt failed.\n");
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose ret = EIO;
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose goto done;
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose }
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose ret = sysdb_delete_recursive(sysdb, dn, true);
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose if (ret != EOK) {
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_delete_recursive failed.\n");
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose goto done;
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose }
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose ret = EOK;
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bosedone:
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose talloc_free(tmp_ctx);
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose return ret;
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose}
fe2ab0d67fe8c66fb6352e9d8f845bb46d1848cbSumit Bose
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Boseerrno_t sysdb_invalidate_overrides(struct sysdb_ctx *sysdb)
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose{
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose int ret;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose int sret;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose TALLOC_CTX *tmp_ctx;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose bool in_transaction = false;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose struct ldb_result *res;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose size_t c;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose struct ldb_message *msg;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose struct ldb_dn *base_dn;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose tmp_ctx = talloc_new(NULL);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose if (tmp_ctx == NULL) {
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose return ENOMEM;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose }
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose msg = ldb_msg_new(tmp_ctx);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose if (msg == NULL) {
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_msg_new failed.\n");
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose ret = ENOMEM;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose goto done;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose }
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose base_dn = ldb_dn_new(tmp_ctx, sysdb->ldb, SYSDB_BASE);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose if (base_dn == NULL) {
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_new failed\n");
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose ret = ENOMEM;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose goto done;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose }
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose ret = ldb_msg_add_empty(msg, SYSDB_CACHE_EXPIRE, LDB_FLAG_MOD_REPLACE,
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose NULL);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose if (ret != LDB_SUCCESS) {
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_msg_add_empty failed.\n");
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose ret = sysdb_error_to_errno(ret);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose goto done;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose }
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose ret = ldb_msg_add_string(msg, SYSDB_CACHE_EXPIRE, "1");
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose if (ret != LDB_SUCCESS) {
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_msg_add_string failed.\n");
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose ret = sysdb_error_to_errno(ret);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose goto done;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose }
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose ret = ldb_msg_add_empty(msg, SYSDB_OVERRIDE_DN, LDB_FLAG_MOD_DELETE, NULL);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose if (ret != LDB_SUCCESS) {
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_msg_add_empty failed.\n");
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose ret = sysdb_error_to_errno(ret);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose goto done;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose }
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose ret = sysdb_transaction_start(sysdb);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose if (ret != EOK) {
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_transaction_start failed.\n");
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose goto done;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose }
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose in_transaction = true;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose ret = ldb_search(sysdb->ldb, tmp_ctx, &res, base_dn, LDB_SCOPE_SUBTREE,
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose NULL, "%s", SYSDB_UC);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose if (ret != LDB_SUCCESS) {
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_search_entry failed.\n");
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose ret = sysdb_error_to_errno(ret);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose goto done;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose }
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose for (c = 0; c < res->count; c++) {
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose msg->dn = res->msgs[c]->dn;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose ret = ldb_modify(sysdb->ldb, msg);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose if (ret != LDB_SUCCESS && ret != LDB_ERR_NO_SUCH_ATTRIBUTE) {
04d138472cc086fb7961f0d378852b09961b1a33Lukas Slebodnik DEBUG(SSSDBG_OP_FAILURE,
04d138472cc086fb7961f0d378852b09961b1a33Lukas Slebodnik "ldb_modify failed: [%s](%d)[%s]\n",
04d138472cc086fb7961f0d378852b09961b1a33Lukas Slebodnik ldb_strerror(ret), ret, ldb_errstring(sysdb->ldb));
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose ret = sysdb_error_to_errno(ret);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose goto done;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose }
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose }
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose talloc_free(res);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose ret = ldb_search(sysdb->ldb, tmp_ctx, &res, base_dn, LDB_SCOPE_SUBTREE,
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose NULL, "%s", SYSDB_GC);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose if (ret != LDB_SUCCESS) {
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_search_entry failed.\n");
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose ret = sysdb_error_to_errno(ret);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose goto done;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose }
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose for (c = 0; c < res->count; c++) {
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose msg->dn = res->msgs[c]->dn;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose ret = ldb_modify(sysdb->ldb, msg);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose if (ret != LDB_SUCCESS && ret != LDB_ERR_NO_SUCH_ATTRIBUTE) {
04d138472cc086fb7961f0d378852b09961b1a33Lukas Slebodnik DEBUG(SSSDBG_OP_FAILURE,
04d138472cc086fb7961f0d378852b09961b1a33Lukas Slebodnik "ldb_modify failed: [%s](%d)[%s]\n",
04d138472cc086fb7961f0d378852b09961b1a33Lukas Slebodnik ldb_strerror(ret), ret, ldb_errstring(sysdb->ldb));
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose ret = sysdb_error_to_errno(ret);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose goto done;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose }
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose }
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose ret = EOK;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bosedone:
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose if (in_transaction) {
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose if (ret == EOK) {
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose sret = sysdb_transaction_commit(sysdb);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose if (sret != EOK) {
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_transaction_commit failed, " \
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose "nothing we can do about.\n");
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose ret = sret;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose }
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose } else {
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose sret = sysdb_transaction_cancel(sysdb);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose if (sret != EOK) {
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_transaction_cancel failed, " \
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose "nothing we can do about.\n");
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose }
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose }
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose }
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose talloc_free(tmp_ctx);
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose return ret;
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit Bose}
2fe140d3a41e1ac66400069d35adc9379348c1e5Sumit 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 int ret;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose if (add_name) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose ret = sysdb_attrs_add_string(attrs, SYSDB_DEFAULT_OVERRIDE_NAME,
da1fd52202cffa3260470565b74af885a466cb00Jakub Hrozek name_override);
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (ret != EOK) {
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sysdb_attrs_add_lc_name_alias failed.\n");
da1fd52202cffa3260470565b74af885a466cb00Jakub Hrozek return ret;
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");
da1fd52202cffa3260470565b74af885a466cb00Jakub Hrozek return ret;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose }
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
da1fd52202cffa3260470565b74af885a466cb00Jakub Hrozek return EOK;
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) {
26a3d4f2ef35a088e4c5fc928290052c89a2ff43Sumit Bose /* obj_override_dn can either point to the object itself, i.e there is
26a3d4f2ef35a088e4c5fc928290052c89a2ff43Sumit Bose * no override, or to a overide object. This means it can change from
26a3d4f2ef35a088e4c5fc928290052c89a2ff43Sumit Bose * the object DN to a override DN and back but not from one override
26a3d4f2ef35a088e4c5fc928290052c89a2ff43Sumit Bose * DN to a different override DN. If the new and the old DN are the
26a3d4f2ef35a088e4c5fc928290052c89a2ff43Sumit Bose * same we do not need to update the original object. */
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose if (strcmp(obj_override_dn, override_dn_str) != 0) {
26a3d4f2ef35a088e4c5fc928290052c89a2ff43Sumit Bose if (strcmp(obj_override_dn, obj_dn_str) != 0
26a3d4f2ef35a088e4c5fc928290052c89a2ff43Sumit Bose && strcmp(override_dn_str, obj_dn_str) != 0) {
26a3d4f2ef35a088e4c5fc928290052c89a2ff43Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
26a3d4f2ef35a088e4c5fc928290052c89a2ff43Sumit Bose "Existing [%s] and new [%s] override DN do not match.\n",
26a3d4f2ef35a088e4c5fc928290052c89a2ff43Sumit Bose obj_override_dn, override_dn_str);
26a3d4f2ef35a088e4c5fc928290052c89a2ff43Sumit Bose ret = EINVAL;
26a3d4f2ef35a088e4c5fc928290052c89a2ff43Sumit Bose goto done;
26a3d4f2ef35a088e4c5fc928290052c89a2ff43Sumit Bose }
26a3d4f2ef35a088e4c5fc928290052c89a2ff43Sumit Bose } else {
26a3d4f2ef35a088e4c5fc928290052c89a2ff43Sumit Bose add_ref = false;
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose }
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
ca49ae1eee321751681e99f3ebe2547211db3bf6Sumit Bose for (c = 0; c < attrs->num; c++) {
b52b26176c92f3b06dba5598428c70c0cde13fd1Sumit Bose /* Set num_values to 1 because by default user and group overrides
b52b26176c92f3b06dba5598428c70c0cde13fd1Sumit Bose * use the same attribute name for the GID and this cause SSSD
b52b26176c92f3b06dba5598428c70c0cde13fd1Sumit Bose * machinery to add the same value twice */
b52b26176c92f3b06dba5598428c70c0cde13fd1Sumit Bose if (attrs->a[c].num_values > 1
b52b26176c92f3b06dba5598428c70c0cde13fd1Sumit Bose && strcmp(attrs->a[c].name, SYSDB_GIDNUM) == 0) {
b52b26176c92f3b06dba5598428c70c0cde13fd1Sumit Bose attrs->a[c].num_values = 1;
b52b26176c92f3b06dba5598428c70c0cde13fd1Sumit Bose }
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
26a3d4f2ef35a088e4c5fc928290052c89a2ff43Sumit Bose ret = ldb_msg_add_empty(msg, SYSDB_OVERRIDE_DN,
26a3d4f2ef35a088e4c5fc928290052c89a2ff43Sumit Bose obj_override_dn == NULL ? LDB_FLAG_MOD_ADD
26a3d4f2ef35a088e4c5fc928290052c89a2ff43Sumit Bose : LDB_FLAG_MOD_REPLACE,
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,
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose SYSDB_USER_CERT,
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose NULL };
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose bool override_attrs_found = false;
9da27cbc7532f775afc411d809735760dd5294a7Sumit Bose
145578006684481434ced78461ab8d1c3570f478Sumit Bose if (override_attrs == NULL) {
145578006684481434ced78461ab8d1c3570f478Sumit Bose /* nothing to do */
145578006684481434ced78461ab8d1c3570f478Sumit Bose return EOK;
145578006684481434ced78461ab8d1c3570f478Sumit Bose }
145578006684481434ced78461ab8d1c3570f478Sumit 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;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose /* Only SYSDB_SSH_PUBKEY and SYSDB_USER_CERT are allowed to
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose * have multiple values. */
ab355eced46b5f488ed62a79a7f2e5ac2b6a574cSumit Bose if (strcmp(allowed_attrs[c], SYSDB_SSH_PUBKEY) != 0
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose && strcmp(allowed_attrs[c], SYSDB_USER_CERT) != 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))"
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose#define SYSDB_USER_CERT_OVERIDE_FILTER "(&(objectClass="SYSDB_OVERRIDE_USER_CLASS")%s)"
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
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Boseerrno_t sysdb_search_override_by_cert(TALLOC_CTX *mem_ctx,
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose struct sss_domain_info *domain,
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose const char *cert,
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose const char **attrs,
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose struct ldb_result **override_obj,
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose struct ldb_result **orig_obj)
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose{
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose TALLOC_CTX *tmp_ctx;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose struct ldb_dn *base_dn;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose struct ldb_result *override_res;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose struct ldb_result *orig_res;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose char *cert_filter;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose int ret;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose const char *orig_obj_dn;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose tmp_ctx = talloc_new(NULL);
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose if (!tmp_ctx) {
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose return ENOMEM;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose }
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose base_dn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose SYSDB_TMPL_VIEW_SEARCH_BASE, domain->view_name);
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose if (base_dn == NULL) {
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_new_fmt failed.\n");
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose ret = ENOMEM;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose goto done;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose }
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose
b341ee51cffd98b642b9c68a417f8a7504e303a1Sumit Bose ret = sss_cert_derb64_to_ldap_filter(tmp_ctx, cert, SYSDB_USER_CERT, NULL,
b341ee51cffd98b642b9c68a417f8a7504e303a1Sumit Bose NULL, &cert_filter);
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose if (ret != EOK) {
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "sss_cert_derb64_to_ldap_filter failed.\n");
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose goto done;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose }
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose ret = ldb_search(domain->sysdb->ldb, tmp_ctx, &override_res, base_dn,
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose LDB_SCOPE_SUBTREE, attrs, SYSDB_USER_CERT_OVERIDE_FILTER,
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose cert_filter);
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose if (ret != LDB_SUCCESS) {
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose ret = sysdb_error_to_errno(ret);
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose goto done;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose }
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose if (override_res->count == 0) {
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose DEBUG(SSSDBG_TRACE_FUNC, "No user override found for cert [%s].\n",
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose cert);
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose ret = ENOENT;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose goto done;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose } else if (override_res->count > 1) {
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose "Found more than one override for cert [%s].\n", cert);
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose ret = EINVAL;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose goto done;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose }
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose if (orig_obj != NULL) {
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose orig_obj_dn = ldb_msg_find_attr_as_string(override_res->msgs[0],
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose SYSDB_OVERRIDE_OBJECT_DN,
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose NULL);
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose if (orig_obj_dn == NULL) {
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose "Missing link to original object in override [%s].\n",
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose ldb_dn_get_linearized(override_res->msgs[0]->dn));
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose ret = EINVAL;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose goto done;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose }
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose base_dn = ldb_dn_new(tmp_ctx, domain->sysdb->ldb, orig_obj_dn);
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose if (base_dn == NULL) {
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_new failed.\n");
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose ret = ENOMEM;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose goto done;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose }
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose ret = ldb_search(domain->sysdb->ldb, tmp_ctx, &orig_res, base_dn,
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose LDB_SCOPE_BASE, attrs, NULL);
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose if (ret != LDB_SUCCESS) {
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose ret = sysdb_error_to_errno(ret);
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose goto done;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose }
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose *orig_obj = talloc_steal(mem_ctx, orig_res);
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose }
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose *override_obj = talloc_steal(mem_ctx, override_res);
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose ret = EOK;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bosedone:
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose talloc_zfree(tmp_ctx);
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose return ret;
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose}
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit 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 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
da1fd52202cffa3260470565b74af885a466cb00Jakub Hrozek ret = sss_filter_sanitize_for_dom(tmp_ctx, 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},
6cb34580ee6e9e2c9190b77b10db8a3c43e3c9c8Sumit Bose {SYSDB_USER_CERT, OVERRIDE_PREFIX SYSDB_USER_CERT},
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) {
a8d31510d12af6ee39fb3e1e13f3a4f6bdef33c1Pavel Březina if (is_local_view(domain->view_name)) {
a8d31510d12af6ee39fb3e1e13f3a4f6bdef33c1Pavel Březina /* LOCAL view doesn't have to have overrideDN specified. */
a8d31510d12af6ee39fb3e1e13f3a4f6bdef33c1Pavel Březina ret = EOK;
a8d31510d12af6ee39fb3e1e13f3a4f6bdef33c1Pavel Březina goto done;
a8d31510d12af6ee39fb3e1e13f3a4f6bdef33c1Pavel Březina }
a8d31510d12af6ee39fb3e1e13f3a4f6bdef33c1Pavel Březina
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
d5e26a3ec3fa1f217f0afd045a03b29d4f88fe1dPavel Březina "Missing override DN for object [%s].\n",
d70023a7fa95c8c12683de965a76ec38a6234ae5Sumit Bose ldb_dn_get_linearized(obj->dn));
a8d31510d12af6ee39fb3e1e13f3a4f6bdef33c1Pavel Březina
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,
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose struct ldb_message *obj,
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose bool expect_override_dn)
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose{
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose int ret;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose size_t c;
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose struct ldb_result *res_members;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose TALLOC_CTX *tmp_ctx;
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;
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose const char *orig_name;
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose char *orig_domain;
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose char *val;
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose struct sss_domain_info *orig_dom;
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
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose ret = sysdb_get_user_members_recursively(tmp_ctx, domain, obj->dn,
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose &res_members);
b969ccc2cc58fdf761e5d314de9217f2d914bc9bLukas Slebodnik if (ret == ENOENT) {
b969ccc2cc58fdf761e5d314de9217f2d914bc9bLukas Slebodnik ret = EOK;
b969ccc2cc58fdf761e5d314de9217f2d914bc9bLukas Slebodnik goto done;
b969ccc2cc58fdf761e5d314de9217f2d914bc9bLukas Slebodnik } else if (ret != EOK) {
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose DEBUG(SSSDBG_OP_FAILURE,
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose "sysdb_get_user_members_recursively failed.\n");
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose goto done;
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose }
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose for (c = 0; c < res_members->count; c++) {
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose if (ldb_msg_find_attr_as_uint64(res_members->msgs[c],
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose SYSDB_UIDNUM, 0) == 0) {
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose /* Skip non-POSIX-user members i.e. groups and non-POSIX users */
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose continue;
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose }
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose if (expect_override_dn) {
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose override_dn_str = ldb_msg_find_attr_as_string(res_members->msgs[c],
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose SYSDB_OVERRIDE_DN,
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose NULL);
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose } else {
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose override_dn_str = ldb_dn_get_linearized(res_members->msgs[c]->dn);
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose }
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose if (override_dn_str == NULL) {
9571c9ba5ee7f8aad24e9dec6c44ce21688fa044Pavel Březina if (is_local_view(domain->view_name)) {
9571c9ba5ee7f8aad24e9dec6c44ce21688fa044Pavel Březina /* LOCAL view doesn't have to have overrideDN specified. */
9571c9ba5ee7f8aad24e9dec6c44ce21688fa044Pavel Březina ret = EOK;
9571c9ba5ee7f8aad24e9dec6c44ce21688fa044Pavel Březina goto done;
9571c9ba5ee7f8aad24e9dec6c44ce21688fa044Pavel Březina }
9571c9ba5ee7f8aad24e9dec6c44ce21688fa044Pavel Březina
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
d5e26a3ec3fa1f217f0afd045a03b29d4f88fe1dPavel Březina "Missing override DN for object [%s].\n",
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose ldb_dn_get_linearized(res_members->msgs[c]->dn));
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose ret = ENOENT;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose goto done;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose }
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose override_dn = ldb_dn_new(res_members, 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
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose orig_name = ldb_msg_find_attr_as_string(res_members->msgs[c],
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose SYSDB_NAME,
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose NULL);
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose if (orig_name == NULL) {
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Object [%s] has no name.\n",
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose ldb_dn_get_linearized(res_members->msgs[c]->dn));
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose ret = EINVAL;
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose goto done;
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose }
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose /* start with default view name, if it exists or use NULL */
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose memberuid = ldb_msg_find_attr_as_string(res_members->msgs[c],
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose SYSDB_DEFAULT_OVERRIDE_NAME,
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose NULL);
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose /* If there is an override object, check if the name is overridden */
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose if (ldb_dn_compare(res_members->msgs[c]->dn, override_dn) != 0) {
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose DEBUG(SSSDBG_TRACE_ALL, "Checking override for object [%s].\n",
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose ldb_dn_get_linearized(res_members->msgs[c]->dn));
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose ret = ldb_search(domain->sysdb->ldb, res_members, &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",
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose override_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,
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose memberuid);
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose }
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose /* add domain name if memberuid is a short name */
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose if (memberuid != NULL && strchr(memberuid, '@') == NULL) {
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose ret = sss_parse_internal_fqname(tmp_ctx, orig_name,
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose NULL, &orig_domain);
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose if (ret != EOK) {
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose DEBUG(SSSDBG_OP_FAILURE,
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose "sss_parse_internal_fqname failed to split [%s].\n",
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose orig_name);
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose goto done;
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose }
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose if (orig_domain != NULL) {
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose orig_dom = find_domain_by_name(get_domains_head(domain),
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose orig_domain, true);
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose if (orig_dom == NULL) {
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose "Cannot find domain with name [%s].\n",
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose orig_domain);
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose ret = ERR_DOMAIN_NOT_FOUND;
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose goto done;
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose }
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose memberuid = sss_create_internal_fqname(tmp_ctx, memberuid,
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose orig_dom->name);
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose if (memberuid == NULL) {
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose DEBUG(SSSDBG_OP_FAILURE,
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose "sss_create_internal_fqname failed.\n");
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose ret = ENOMEM;
1594701fbdc341069e11cff9a85e7a795e52db3dSumit Bose goto done;
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose }
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose }
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose }
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose if (memberuid == NULL) {
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose DEBUG(SSSDBG_TRACE_ALL, "No override name available.\n");
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose memberuid = orig_name;
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose }
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose val = talloc_strdup(obj, memberuid);
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose if (val == NULL) {
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose ret = ENOMEM;
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose goto done;
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose }
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose ret = ldb_msg_add_string(obj, OVERRIDE_PREFIX SYSDB_MEMBERUID, val);
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 }
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose DEBUG(SSSDBG_TRACE_ALL, "Added [%s] to [%s].\n", memberuid,
fbcdc08722aa8ed17c4b114e01fbb37c02cfb2feSumit Bose OVERRIDE_PREFIX SYSDB_MEMBERUID);
d2f4551519698809e73a029c49599e1f67e6bdd4Sumit Bose
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}