c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher/*
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher SSSD
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher Authors:
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher Simo Sorce <ssorce@redhat.com>
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher Stephen Gallagher <sgallagh@redhat.com>
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher Copyright (C) 2008-2011 Simo Sorce <ssorce@redhat.com>
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher Copyright (C) 2008-2011 Stephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher This program is free software; you can redistribute it and/or modify
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher it under the terms of the GNU General Public License as published by
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher the Free Software Foundation; either version 3 of the License, or
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher (at your option) any later version.
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher This program is distributed in the hope that it will be useful,
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher but WITHOUT ANY WARRANTY; without even the implied warranty of
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher GNU General Public License for more details.
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher You should have received a copy of the GNU General Public License
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher along with this program. If not, see <http://www.gnu.org/licenses/>.
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher*/
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher#include "util/util.h"
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher#include "db/sysdb_private.h"
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek#include "db/sysdb_autofs.h"
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorcestruct upgrade_ctx {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce struct ldb_context *ldb;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce const char *new_version;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce};
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorcestatic errno_t commence_upgrade(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce const char *new_ver, struct upgrade_ctx **_ctx)
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce{
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce struct upgrade_ctx *ctx;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce int ret;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "UPGRADING DB TO VERSION %s\n", new_ver);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ctx = talloc(mem_ctx, struct upgrade_ctx);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (!ctx) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce return ENOMEM;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce }
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ctx->ldb = ldb;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ctx->new_version = new_ver;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = ldb_transaction_start(ldb);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (ret != LDB_SUCCESS) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = EIO;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce goto done;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce }
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = EOK;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorcedone:
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (ret != EOK) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce talloc_free(ctx);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce } else {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce *_ctx = ctx;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce }
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce return ret;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce}
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorcestatic errno_t update_version(struct upgrade_ctx *ctx)
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce{
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce struct ldb_message *msg = NULL;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce errno_t ret;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce msg = ldb_msg_new(ctx);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (!msg) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = ENOMEM;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce goto done;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce }
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce msg->dn = ldb_dn_new(msg, ctx->ldb, SYSDB_BASE);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (!msg->dn) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = ENOMEM;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce goto done;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce }
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = ldb_msg_add_empty(msg, "version", LDB_FLAG_MOD_REPLACE, NULL);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (ret != LDB_SUCCESS) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = ENOMEM;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce goto done;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce }
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = ldb_msg_add_string(msg, "version", ctx->new_version);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (ret != LDB_SUCCESS) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = ENOMEM;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce goto done;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce }
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = ldb_modify(ctx->ldb, msg);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (ret != LDB_SUCCESS) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = sysdb_error_to_errno(ret);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce goto done;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce }
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = EOK;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorcedone:
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce talloc_free(msg);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce return ret;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce}
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorcestatic int finish_upgrade(int ret, struct upgrade_ctx **ctx, const char **ver)
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher{
cff916f5352fe7c3a679571130090efdb935618aStephen Gallagher int lret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret == EOK) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce lret = ldb_transaction_commit((*ctx)->ldb);
cff916f5352fe7c3a679571130090efdb935618aStephen Gallagher ret = sysdb_error_to_errno(lret);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret == EOK) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce *ver = (*ctx)->new_version;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != EOK) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce lret = ldb_transaction_cancel((*ctx)->ldb);
cff916f5352fe7c3a679571130090efdb935618aStephen Gallagher if (lret != LDB_SUCCESS) {
cff916f5352fe7c3a679571130090efdb935618aStephen Gallagher DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not cancel transaction! [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ldb_strerror(lret));
cff916f5352fe7c3a679571130090efdb935618aStephen Gallagher /* Do not overwrite ret here, we want to return
cff916f5352fe7c3a679571130090efdb935618aStephen Gallagher * the original failure, not the failure of the
cff916f5352fe7c3a679571130090efdb935618aStephen Gallagher * transaction cancellation.
cff916f5352fe7c3a679571130090efdb935618aStephen Gallagher */
cff916f5352fe7c3a679571130090efdb935618aStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce talloc_zfree(*ctx);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher return ret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher}
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher/* serach all groups that have a memberUid attribute.
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher * change it into a member attribute for a user of same domain.
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher * remove the memberUid attribute
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher * add the new member attribute
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher * finally stop indexing memberUid
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher * upgrade version to 0.2
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagherint sysdb_upgrade_01(struct ldb_context *ldb, const char **ver)
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher{
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct ldb_message_element *el;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct ldb_result *res;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct ldb_dn *basedn;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct ldb_dn *mem_dn;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct ldb_message *msg;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher const struct ldb_val *val;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose /* No change needed because this version has objectclass group */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher const char *filter = "(&(memberUid=*)(objectclass=group))";
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher const char *attrs[] = { "memberUid", NULL };
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher const char *mdn;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher char *domain;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher int ret, i, j;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher TALLOC_CTX *tmp_ctx;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce struct upgrade_ctx *ctx;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher tmp_ctx = talloc_new(NULL);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!tmp_ctx) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce return ENOMEM;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce }
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = commence_upgrade(tmp_ctx, ldb, SYSDB_VERSION_0_2, &ctx);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (ret) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce talloc_free(tmp_ctx);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce return ret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher basedn = ldb_dn_new(tmp_ctx, ldb, SYSDB_BASE);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!basedn) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = EIO;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_search(ldb, tmp_ctx, &res,
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher basedn, LDB_SCOPE_SUBTREE,
87c9241da76f8a7c93095649b2c09a2a07190a36Krzysztof Klimonda attrs, "%s", filter);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = EIO;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher for (i = 0; i < res->count; i++) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher el = ldb_msg_find_element(res->msgs[i], "memberUid");
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!el) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "memberUid is missing from message [%s], skipping\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ldb_dn_get_linearized(res->msgs[i]->dn));
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher continue;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* create modification message */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher msg = ldb_msg_new(tmp_ctx);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!msg) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher msg->dn = res->msgs[i]->dn;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_msg_add_empty(msg, "memberUid", LDB_FLAG_MOD_DELETE, NULL);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_msg_add_empty(msg, SYSDB_MEMBER, LDB_FLAG_MOD_ADD, NULL);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* get domain name component value */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher val = ldb_dn_get_component_val(res->msgs[i]->dn, 2);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher domain = talloc_strndup(tmp_ctx, (const char *)val->data, val->length);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!domain) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher for (j = 0; j < el->num_values; j++) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher mem_dn = ldb_dn_new_fmt(tmp_ctx, ldb, SYSDB_TMPL_USER,
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher (const char *)el->values[j].data, domain);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!mem_dn) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher mdn = talloc_strdup(msg, ldb_dn_get_linearized(mem_dn));
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!mdn) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_msg_add_string(msg, SYSDB_MEMBER, mdn);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher talloc_zfree(mem_dn);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* ok now we are ready to modify the entry */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_modify(ldb, msg);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = sysdb_error_to_errno(ret);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher talloc_zfree(msg);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce /* conversion done, update version number */
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = update_version(ctx);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagherdone:
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = finish_upgrade(ret, &ctx, ver);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher talloc_free(tmp_ctx);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher return ret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher}
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagherint sysdb_check_upgrade_02(struct sss_domain_info *domains,
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher const char *db_path)
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher{
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher TALLOC_CTX *tmp_ctx = NULL;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct ldb_context *ldb;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher char *ldb_file;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct sysdb_ctx *sysdb;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct sss_domain_info *dom;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct ldb_message_element *el;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct ldb_message *msg;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct ldb_result *res;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct ldb_dn *verdn;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher const char *version = NULL;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher bool do_02_upgrade = false;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher bool ctx_trans = false;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher int ret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher tmp_ctx = talloc_new(NULL);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!tmp_ctx) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher return ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek ldb_file = talloc_asprintf(tmp_ctx, "%s/"LOCAL_SYSDB_FILE,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek db_path);
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek if (ldb_file == NULL) {
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto exit;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_ldb_connect(tmp_ctx, ldb_file, 0, &ldb);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_ldb_connect failed.\n");
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher return ret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher verdn = ldb_dn_new(tmp_ctx, ldb, SYSDB_BASE);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!verdn) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = EIO;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto exit;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_search(ldb, tmp_ctx, &res,
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher verdn, LDB_SCOPE_BASE,
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher NULL, NULL);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = EIO;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto exit;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (res->count > 1) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = EIO;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto exit;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (res->count == 1) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher el = ldb_msg_find_element(res->msgs[0], "version");
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (el) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (el->num_values != 1) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = EINVAL;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto exit;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher version = talloc_strndup(tmp_ctx,
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher (char *)(el->values[0].data),
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher el->values[0].length);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!version) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto exit;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (strcmp(version, SYSDB_VERSION) == 0) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* all fine, return */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = EOK;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto exit;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CONF_SETTINGS,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Upgrading DB from version: %s\n", version);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (strcmp(version, SYSDB_VERSION_0_1) == 0) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* convert database */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = sysdb_upgrade_01(ldb, &version);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != EOK) goto exit;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (strcmp(version, SYSDB_VERSION_0_2) == 0) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* need to convert database to split files */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher do_02_upgrade = true;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!do_02_upgrade) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* not a v2 upgrade, return and let the normal code take over any
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher * further upgrade */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = EOK;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto exit;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* == V2->V3 UPGRADE == */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "UPGRADING DB TO VERSION %s\n", SYSDB_VERSION_0_3);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* ldb uses posix locks,
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher * posix is stupid and kills all locks when you close *any* file
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher * descriptor associated to the same file.
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher * Therefore we must close and reopen the ldb file here */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* == Backup and reopen ldb == */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* close */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher talloc_zfree(ldb);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* backup*/
dfdc99afd56b605632adc265bfb1f55cd52b3dbeNikolai Kondrashov ret = backup_file(ldb_file, SSSDBG_FATAL_FAILURE);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != EOK) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto exit;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* reopen */
72dbcd0a3361f1c0f0c3e348aa2fbcabd926188bJakub Hrozek ret = sysdb_ldb_connect(tmp_ctx, ldb_file, 0, &ldb);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_ldb_connect failed.\n");
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher return ret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* open a transaction */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_transaction_start(ldb);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Failed to start ldb transaction! (%d)\n", ret);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = EIO;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto exit;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* == Upgrade contents == */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher for (dom = domains; dom; dom = dom->next) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct ldb_dn *domain_dn;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct ldb_dn *users_dn;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct ldb_dn *groups_dn;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher int i;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* skip local */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (strcasecmp(dom->provider, "local") == 0) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher continue;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* create new dom db */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = sysdb_domain_init_internal(tmp_ctx, dom,
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher db_path, false, &sysdb);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != EOK) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_transaction_start(sysdb->ldb);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Failed to start ldb transaction! (%d)\n", ret);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = EIO;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ctx_trans = true;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* search all entries for this domain in local,
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher * copy them all in the new database,
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher * then remove them from local */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher domain_dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb,
46675b5033169e1e954cd570413ce85b2c5e11fcSimo Sorce SYSDB_DOM_BASE, dom->name);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!domain_dn) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_search(ldb, tmp_ctx, &res,
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher domain_dn, LDB_SCOPE_SUBTREE,
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher NULL, NULL);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = EIO;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
311836214245600566f881ff6253594e0999008ePetr Cech /*
311836214245600566f881ff6253594e0999008ePetr Cech * dom->sysdb->ldb is not initialized,
311836214245600566f881ff6253594e0999008ePetr Cech * so ldb_dn_new_fmt() shouldn't be changed to sysdb_*_base_dn()
311836214245600566f881ff6253594e0999008ePetr Cech */
311836214245600566f881ff6253594e0999008ePetr Cech users_dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb,
311836214245600566f881ff6253594e0999008ePetr Cech SYSDB_TMPL_USER_BASE, dom->name);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!users_dn) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
311836214245600566f881ff6253594e0999008ePetr Cech
311836214245600566f881ff6253594e0999008ePetr Cech /*
311836214245600566f881ff6253594e0999008ePetr Cech * dom->sysdb->ldb is not initialized,
311836214245600566f881ff6253594e0999008ePetr Cech * so ldb_dn_new_fmt() shouldn't be changed to sysdb_*_base_dn()
311836214245600566f881ff6253594e0999008ePetr Cech */
311836214245600566f881ff6253594e0999008ePetr Cech groups_dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb,
311836214245600566f881ff6253594e0999008ePetr Cech SYSDB_TMPL_GROUP_BASE, dom->name);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!groups_dn) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher for (i = 0; i < res->count; i++) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct ldb_dn *orig_dn;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher msg = res->msgs[i];
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* skip pre-created congtainers */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if ((ldb_dn_compare(msg->dn, domain_dn) == 0) ||
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher (ldb_dn_compare(msg->dn, users_dn) == 0) ||
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher (ldb_dn_compare(msg->dn, groups_dn) == 0)) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher continue;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* regenerate the DN against the new ldb as it may have different
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher * casefolding rules (example: name changing from case insensitive
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher * to case sensitive) */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher orig_dn = msg->dn;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher msg->dn = ldb_dn_new(msg, sysdb->ldb,
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ldb_dn_get_linearized(orig_dn));
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!msg->dn) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_add(sysdb->ldb, msg);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "WARNING: Could not add entry %s,"
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher " to new ldb file! (%d [%s])\n",
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ldb_dn_get_linearized(msg->dn),
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, ldb_errstring(sysdb->ldb));
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_delete(ldb, orig_dn);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "WARNING: Could not remove entry %s,"
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher " from old ldb file! (%d [%s])\n",
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ldb_dn_get_linearized(orig_dn),
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, ldb_errstring(ldb));
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* now remove the basic containers from local */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* these were optional so debug at level 9 in case
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher * of failure just for tracing */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_delete(ldb, groups_dn);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "WARNING: Could not remove entry %s,"
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher " from old ldb file! (%d [%s])\n",
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ldb_dn_get_linearized(groups_dn),
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, ldb_errstring(ldb));
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_delete(ldb, users_dn);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "WARNING: Could not remove entry %s,"
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher " from old ldb file! (%d [%s])\n",
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ldb_dn_get_linearized(users_dn),
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, ldb_errstring(ldb));
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_delete(ldb, domain_dn);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL, "WARNING: Could not remove entry %s,"
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher " from old ldb file! (%d [%s])\n",
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ldb_dn_get_linearized(domain_dn),
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, ldb_errstring(ldb));
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_transaction_commit(sysdb->ldb);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Failed to commit ldb transaction! (%d)\n", ret);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = EIO;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ctx_trans = false;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher talloc_zfree(domain_dn);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher talloc_zfree(groups_dn);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher talloc_zfree(users_dn);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher talloc_zfree(res);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* conversion done, upgrade version number */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher msg = ldb_msg_new(tmp_ctx);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!msg) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher msg->dn = ldb_dn_new(tmp_ctx, ldb, SYSDB_BASE);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!msg->dn) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_msg_add_empty(msg, "version", LDB_FLAG_MOD_REPLACE, NULL);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_msg_add_string(msg, "version", SYSDB_VERSION_0_3);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_modify(ldb, msg);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = sysdb_error_to_errno(ret);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_transaction_commit(ldb);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Failed to commit ldb transaction! (%d)\n", ret);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = EIO;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto exit;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = EOK;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagherdone:
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != EOK) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ctx_trans) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_transaction_cancel(sysdb->ldb);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Failed to cancel ldb transaction! (%d)\n", ret);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_transaction_cancel(ldb);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Failed to cancel ldb transaction! (%d)\n", ret);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagherexit:
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher talloc_free(tmp_ctx);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher return ret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher}
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagherint sysdb_upgrade_03(struct sysdb_ctx *sysdb, const char **ver)
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher{
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher TALLOC_CTX *tmp_ctx;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher int ret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct ldb_message *msg;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce struct upgrade_ctx *ctx;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher tmp_ctx = talloc_new(NULL);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!tmp_ctx) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher return ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_4, &ctx);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (ret) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce return ret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* Make this database case-sensitive */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher msg = ldb_msg_new(tmp_ctx);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!msg) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@ATTRIBUTES");
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!msg->dn) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_msg_add_empty(msg, "name", LDB_FLAG_MOD_DELETE, NULL);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_modify(sysdb->ldb, msg);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = sysdb_error_to_errno(ret);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce /* conversion done, update version number */
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = update_version(ctx);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagherdone:
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = finish_upgrade(ret, &ctx, ver);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher talloc_free(tmp_ctx);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher return ret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher}
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagherint sysdb_upgrade_04(struct sysdb_ctx *sysdb, const char **ver)
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher{
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher TALLOC_CTX *tmp_ctx;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher int ret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct ldb_message *msg;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce struct upgrade_ctx *ctx;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher tmp_ctx = talloc_new(NULL);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!tmp_ctx) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher return ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_5, &ctx);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (ret) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce return ret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* Add new index */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher msg = ldb_msg_new(tmp_ctx);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!msg) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@INDEXLIST");
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!msg->dn) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_msg_add_string(msg, "@IDXATTR", "originalDN");
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_modify(sysdb->ldb, msg);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = sysdb_error_to_errno(ret);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* Rebuild memberuid and memberoif attributes */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher msg = ldb_msg_new(tmp_ctx);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!msg) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@MEMBEROF-REBUILD");
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!msg->dn) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_add(sysdb->ldb, msg);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = sysdb_error_to_errno(ret);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce /* conversion done, update version number */
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = update_version(ctx);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagherdone:
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = finish_upgrade(ret, &ctx, ver);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher talloc_free(tmp_ctx);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher return ret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher}
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagherint sysdb_upgrade_05(struct sysdb_ctx *sysdb, const char **ver)
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher{
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher TALLOC_CTX *tmp_ctx;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher int ret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct ldb_message *msg;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce struct upgrade_ctx *ctx;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher tmp_ctx = talloc_new(NULL);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!tmp_ctx) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher return ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_6, &ctx);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (ret) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce return ret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* Add new indexes */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher msg = ldb_msg_new(tmp_ctx);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!msg) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@INDEXLIST");
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!msg->dn) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* Add Index for dataExpireTimestamp */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_msg_add_string(msg, "@IDXATTR", "dataExpireTimestamp");
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* Add index to speed up ONELEVEL searches */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_msg_add_empty(msg, "@IDXONE", LDB_FLAG_MOD_ADD, NULL);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_msg_add_string(msg, "@IDXONE", "1");
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_modify(sysdb->ldb, msg);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = sysdb_error_to_errno(ret);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce /* conversion done, update version number */
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = update_version(ctx);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagherdone:
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = finish_upgrade(ret, &ctx, ver);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher talloc_free(tmp_ctx);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher return ret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher}
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagherint sysdb_upgrade_06(struct sysdb_ctx *sysdb, const char **ver)
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher{
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher TALLOC_CTX *tmp_ctx;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher int ret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher struct ldb_message *msg;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce struct upgrade_ctx *ctx;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher tmp_ctx = talloc_new(NULL);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!tmp_ctx) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher return ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_7, &ctx);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (ret) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce return ret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* Add new indexes */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher msg = ldb_msg_new(tmp_ctx);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!msg) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@ATTRIBUTES");
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (!msg->dn) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher /* Case insensitive search for originalDN */
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_msg_add_empty(msg, SYSDB_ORIG_DN, LDB_FLAG_MOD_ADD, NULL);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_msg_add_string(msg, SYSDB_ORIG_DN, "CASE_INSENSITIVE");
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ENOMEM;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = ldb_modify(sysdb->ldb, msg);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher if (ret != LDB_SUCCESS) {
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher ret = sysdb_error_to_errno(ret);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher goto done;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher }
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce /* conversion done, update version number */
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = update_version(ctx);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagherdone:
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = finish_upgrade(ret, &ctx, ver);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher talloc_free(tmp_ctx);
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher return ret;
c2352a73f52f600d95966ebe0b0819649ba923faStephen Gallagher}
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher
0387564f38698c5301b76b24eda000c448174171Stephen Gallagherint sysdb_upgrade_07(struct sysdb_ctx *sysdb, const char **ver)
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher{
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher TALLOC_CTX *tmp_ctx;
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher int ret;
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher struct ldb_message *msg;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce struct upgrade_ctx *ctx;
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher tmp_ctx = talloc_new(NULL);
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher if (!tmp_ctx) {
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher return ENOMEM;
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher }
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_8, &ctx);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (ret) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce return ret;
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher }
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher /* Add new indexes */
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher msg = ldb_msg_new(tmp_ctx);
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher if (!msg) {
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher ret = ENOMEM;
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher goto done;
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher }
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@INDEXLIST");
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher if (!msg->dn) {
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher ret = ENOMEM;
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher goto done;
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher }
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher /* Add Index for nameAlias */
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL);
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher if (ret != LDB_SUCCESS) {
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher ret = ENOMEM;
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher goto done;
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher }
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher ret = ldb_msg_add_string(msg, "@IDXATTR", "nameAlias");
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher if (ret != LDB_SUCCESS) {
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher ret = ENOMEM;
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher goto done;
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher }
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher ret = ldb_modify(sysdb->ldb, msg);
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher if (ret != LDB_SUCCESS) {
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher ret = sysdb_error_to_errno(ret);
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher goto done;
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher }
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce /* conversion done, update version number */
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = update_version(ctx);
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher
0387564f38698c5301b76b24eda000c448174171Stephen Gallagherdone:
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = finish_upgrade(ret, &ctx, ver);
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher talloc_free(tmp_ctx);
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher return ret;
0387564f38698c5301b76b24eda000c448174171Stephen Gallagher}
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagherint sysdb_upgrade_08(struct sysdb_ctx *sysdb, const char **ver)
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher{
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher TALLOC_CTX *tmp_ctx;
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher int ret;
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher struct ldb_message *msg;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce struct upgrade_ctx *ctx;
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher tmp_ctx = talloc_new(NULL);
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher if (!tmp_ctx) {
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher return ENOMEM;
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher }
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_9, &ctx);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (ret) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce return ret;
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher }
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher /* Add new indexes */
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher msg = ldb_msg_new(tmp_ctx);
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher if (!msg) {
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher ret = ENOMEM;
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher goto done;
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher }
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@INDEXLIST");
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher if (!msg->dn) {
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher ret = ENOMEM;
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher goto done;
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher }
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher /* Add Index for servicePort and serviceProtocol */
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL);
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher if (ret != LDB_SUCCESS) {
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher ret = ENOMEM;
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher goto done;
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher }
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher ret = ldb_msg_add_string(msg, "@IDXATTR", "servicePort");
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher if (ret != LDB_SUCCESS) {
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher ret = ENOMEM;
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher goto done;
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher }
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher ret = ldb_msg_add_string(msg, "@IDXATTR", "serviceProtocol");
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher if (ret != LDB_SUCCESS) {
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher ret = ENOMEM;
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher goto done;
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher }
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher ret = ldb_modify(sysdb->ldb, msg);
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher if (ret != LDB_SUCCESS) {
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher ret = sysdb_error_to_errno(ret);
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher goto done;
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher }
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce /* conversion done, update version number */
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = update_version(ctx);
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagherdone:
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = finish_upgrade(ret, &ctx, ver);
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher talloc_free(tmp_ctx);
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher return ret;
ff907ba7a9b5e429de086515642f97a0447e546aStephen Gallagher}
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozekint sysdb_upgrade_09(struct sysdb_ctx *sysdb, const char **ver)
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek{
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek TALLOC_CTX *tmp_ctx;
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek int ret;
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek struct ldb_message *msg;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce struct upgrade_ctx *ctx;
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek tmp_ctx = talloc_new(NULL);
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek if (!tmp_ctx) {
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek return ENOMEM;
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek }
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_10, &ctx);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (ret) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce return ret;
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek }
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek /* Add new indexes */
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek msg = ldb_msg_new(tmp_ctx);
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek if (!msg) {
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek ret = ENOMEM;
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek goto done;
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek }
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@INDEXLIST");
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek if (!msg->dn) {
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek ret = ENOMEM;
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek goto done;
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek }
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek /* Add Index for servicePort and serviceProtocol */
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL);
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek if (ret != LDB_SUCCESS) {
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek ret = ENOMEM;
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek goto done;
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek }
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek ret = ldb_msg_add_string(msg, "@IDXATTR", "sudoUser");
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek if (ret != LDB_SUCCESS) {
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek ret = ENOMEM;
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek goto done;
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek }
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek ret = ldb_modify(sysdb->ldb, msg);
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek if (ret != LDB_SUCCESS) {
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek ret = sysdb_error_to_errno(ret);
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek goto done;
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek }
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce /* conversion done, update version number */
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = update_version(ctx);
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozekdone:
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = finish_upgrade(ret, &ctx, ver);
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek talloc_free(tmp_ctx);
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek return ret;
25a9a1768d2e3587cc68b76a0a5df1e42a2c89abJakub Hrozek}
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny
46675b5033169e1e954cd570413ce85b2c5e11fcSimo Sorceint sysdb_upgrade_10(struct sysdb_ctx *sysdb, struct sss_domain_info *domain,
46675b5033169e1e954cd570413ce85b2c5e11fcSimo Sorce const char **ver)
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny{
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny TALLOC_CTX *tmp_ctx;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny int ret;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny struct ldb_result *res;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny struct ldb_message *msg;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny struct ldb_message *user;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny struct ldb_message_element *memberof_el;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny const char *name;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny struct ldb_dn *basedn;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose /* No change needed because version 10 has objectclass user */
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny const char *filter = "(&(objectClass=user)(!(uidNumber=*))(memberOf=*))";
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny const char *attrs[] = { "name", "memberof", NULL };
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce struct upgrade_ctx *ctx;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny int i, j;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny tmp_ctx = talloc_new(NULL);
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny if (tmp_ctx == NULL) {
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny return ENOMEM;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny }
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_11, &ctx);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (ret) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce return ret;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce }
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
311836214245600566f881ff6253594e0999008ePetr Cech /*
311836214245600566f881ff6253594e0999008ePetr Cech * dom->sysdb->ldb is not initialized,
311836214245600566f881ff6253594e0999008ePetr Cech * so ldb_dn_new_fmt() shouldn't be changed to sysdb_*_base_dn()
311836214245600566f881ff6253594e0999008ePetr Cech */
311836214245600566f881ff6253594e0999008ePetr Cech basedn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb,
311836214245600566f881ff6253594e0999008ePetr Cech SYSDB_TMPL_USER_BASE, domain->name);
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny if (basedn == NULL) {
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny ret = EIO;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny goto done;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny }
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny ret = ldb_search(sysdb->ldb, tmp_ctx, &res, basedn, LDB_SCOPE_SUBTREE,
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny attrs, "%s", filter);
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny if (ret != LDB_SUCCESS) {
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny ret = EIO;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny goto done;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny }
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny for (i = 0; i < res->count; i++) {
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny user = res->msgs[i];
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny memberof_el = ldb_msg_find_element(user, "memberof");
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny name = ldb_msg_find_attr_as_string(user, "name", NULL);
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny if (name == NULL) {
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny ret = EIO;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny goto done;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny }
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS, "User [%s] is a member of %d groups\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov name, memberof_el->num_values);
3cf417b8502f5af34e6680f12a3365bcdd9fa40dJakub Hrozek
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny for (j = 0; j < memberof_el->num_values; j++) {
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny msg = ldb_msg_new(tmp_ctx);
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny if (msg == NULL) {
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny ret = ENOMEM;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny goto done;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny }
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny msg->dn = ldb_dn_from_ldb_val(tmp_ctx, sysdb->ldb, &memberof_el->values[j]);
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny if (msg->dn == NULL) {
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny ret = ENOMEM;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny goto done;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny }
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny if (!ldb_dn_validate(msg->dn)) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "DN validation failed during "
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny "upgrade: [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov memberof_el->values[j].data);
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny talloc_zfree(msg);
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny continue;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny }
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny ret = ldb_msg_add_empty(msg, "ghost", LDB_FLAG_MOD_ADD, NULL);
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny if (ret != LDB_SUCCESS) {
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny ret = ENOMEM;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny goto done;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny }
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny ret = ldb_msg_add_string(msg, "ghost", name);
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny if (ret != LDB_SUCCESS) {
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny ret = ENOMEM;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny goto done;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny }
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Adding ghost [%s] to entry [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov name, ldb_dn_get_linearized(msg->dn));
3cf417b8502f5af34e6680f12a3365bcdd9fa40dJakub Hrozek
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek ret = sss_ldb_modify_permissive(sysdb->ldb, msg);
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny talloc_zfree(msg);
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek if (ret == LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS) {
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek /* If we failed adding the ghost user(s) because the values already
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek * exist, they were probably propagated from a parent that was
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek * upgraded before us. Mark the group as expired so that it is
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek * refreshed on next request.
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek */
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek msg = ldb_msg_new(tmp_ctx);
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek if (msg == NULL) {
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek ret = ENOMEM;
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek goto done;
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek }
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek msg->dn = ldb_dn_from_ldb_val(tmp_ctx, sysdb->ldb, &memberof_el->values[j]);
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek if (msg->dn == NULL) {
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek ret = ENOMEM;
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek goto done;
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek }
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek ret = ldb_msg_add_empty(msg, SYSDB_CACHE_EXPIRE,
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek LDB_FLAG_MOD_REPLACE, NULL);
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek if (ret != LDB_SUCCESS) {
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek goto done;
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek }
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek ret = ldb_msg_add_string(msg, SYSDB_CACHE_EXPIRE, "1");
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek if (ret != LDB_SUCCESS) {
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek goto done;
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek }
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek ret = sss_ldb_modify_permissive(sysdb->ldb, msg);
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek talloc_zfree(msg);
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek if (ret != LDB_SUCCESS) {
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek goto done;
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek }
541ee4f36c58dac103dfb766231cf8f26db93676Jakub Hrozek } else if (ret != LDB_SUCCESS) {
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny ret = sysdb_error_to_errno(ret);
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny goto done;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny }
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny }
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Removing fake user [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ldb_dn_get_linearized(user->dn));
3cf417b8502f5af34e6680f12a3365bcdd9fa40dJakub Hrozek
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny ret = ldb_delete(sysdb->ldb, user->dn);
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny if (ret != LDB_SUCCESS) {
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny ret = sysdb_error_to_errno(ret);
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny goto done;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny }
7733e4179f56fb0ca41788b5d8de2ee1130b1badJakub Hrozek }
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce /* conversion done, update version number */
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = update_version(ctx);
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zelenydone:
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = finish_upgrade(ret, &ctx, ver);
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny talloc_free(tmp_ctx);
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny return ret;
c193cdcb43bffc1eac1bde6dfb0311e033e0c12fJan Zeleny}
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek
46675b5033169e1e954cd570413ce85b2c5e11fcSimo Sorceint sysdb_upgrade_11(struct sysdb_ctx *sysdb, struct sss_domain_info *domain,
46675b5033169e1e954cd570413ce85b2c5e11fcSimo Sorce const char **ver)
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek{
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek TALLOC_CTX *tmp_ctx;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek errno_t ret;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek struct ldb_result *res;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek struct ldb_message *entry;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek const char *key;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek const char *value;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek struct ldb_message_element *memberof_el;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek struct ldb_dn *memberof_dn;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek struct ldb_dn *basedn;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek const struct ldb_val *val;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek const char *attrs[] = { SYSDB_AUTOFS_ENTRY_KEY,
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek SYSDB_AUTOFS_ENTRY_VALUE,
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek SYSDB_MEMBEROF,
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek NULL };
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce struct upgrade_ctx *ctx;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek size_t i, j;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek tmp_ctx = talloc_new(NULL);
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek if (!tmp_ctx) {
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek return ENOMEM;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek }
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_12, &ctx);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (ret) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce return ret;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce }
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek basedn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_TMPL_CUSTOM_SUBTREE,
46675b5033169e1e954cd570413ce85b2c5e11fcSimo Sorce AUTOFS_ENTRY_SUBDIR, domain->name);
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek if (basedn == NULL) {
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek ret = ENOMEM;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek goto done;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek }
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek ret = ldb_search(sysdb->ldb, tmp_ctx, &res, basedn, LDB_SCOPE_SUBTREE,
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek attrs, "(objectClass=%s)", SYSDB_AUTOFS_ENTRY_OC);
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek if (ret != LDB_SUCCESS) {
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek ret = EIO;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek goto done;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek }
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS, "Found %d autofs entries\n", res->count);
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek for (i = 0; i < res->count; i++) {
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek entry = res->msgs[i];
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek key = ldb_msg_find_attr_as_string(entry,
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek SYSDB_AUTOFS_ENTRY_KEY, NULL);
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek value = ldb_msg_find_attr_as_string(entry,
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek SYSDB_AUTOFS_ENTRY_VALUE, NULL);
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek memberof_el = ldb_msg_find_element(entry, SYSDB_MEMBEROF);
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek if (key && value && memberof_el) {
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek for (j = 0; j < memberof_el->num_values; j++) {
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek memberof_dn = ldb_dn_from_ldb_val(tmp_ctx, sysdb->ldb,
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek &(memberof_el->values[j]));
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek if (!memberof_dn) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Cannot convert memberof into DN, skipping\n");
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek continue;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek }
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek val = ldb_dn_get_rdn_val(memberof_dn);
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek if (!val) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Cannot get map name from map DN\n");
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek continue;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek }
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek ret = sysdb_save_autofsentry(domain,
2913240aee51ce81195148a4d814e967f66839c4Simo Sorce (const char *) val->data,
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek key, value, NULL);
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek if (ret != EOK) {
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Cannot save autofs entry [%s]-[%s] into map %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov key, value, val->data);
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek continue;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek }
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek }
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek }
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek /* Delete the old entry if it was either processed or incomplete */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS, "Deleting [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ldb_dn_get_linearized(entry->dn));
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek ret = ldb_delete(sysdb->ldb, entry->dn);
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Cannot delete old autofs entry %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ldb_dn_get_linearized(entry->dn));
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek continue;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek }
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek }
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce /* conversion done, update version number */
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = update_version(ctx);
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozekdone:
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = finish_upgrade(ret, &ctx, ver);
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek talloc_free(tmp_ctx);
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek return ret;
77f445dbaecc8e792e1ad42e3742800ad141bee0Jakub Hrozek}
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholastaint sysdb_upgrade_12(struct sysdb_ctx *sysdb, const char **ver)
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta{
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta TALLOC_CTX *tmp_ctx;
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta int ret;
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta struct ldb_message *msg;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce struct upgrade_ctx *ctx;
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta tmp_ctx = talloc_new(NULL);
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta if (!tmp_ctx) {
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta return ENOMEM;
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta }
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_13, &ctx);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (ret) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce return ret;
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta }
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta /* add new indexes */
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta msg = ldb_msg_new(tmp_ctx);
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta if (!msg) {
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta ret = ENOMEM;
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta goto done;
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta }
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@INDEXLIST");
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta if (!msg->dn) {
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta ret = ENOMEM;
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta goto done;
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta }
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta /* add index for sshKnownHostsExpire */
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL);
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta if (ret != LDB_SUCCESS) {
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta ret = ENOMEM;
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta goto done;
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta }
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta ret = ldb_msg_add_string(msg, "@IDXATTR", "sshKnownHostsExpire");
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta if (ret != LDB_SUCCESS) {
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta ret = ENOMEM;
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta goto done;
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta }
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta ret = ldb_modify(sysdb->ldb, msg);
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta if (ret != LDB_SUCCESS) {
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta ret = sysdb_error_to_errno(ret);
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta goto done;
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta }
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce /* conversion done, update version number */
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = update_version(ctx);
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorcedone:
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = finish_upgrade(ret, &ctx, ver);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce talloc_free(tmp_ctx);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce return ret;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce}
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorceint sysdb_upgrade_13(struct sysdb_ctx *sysdb, const char **ver)
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce{
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce struct upgrade_ctx *ctx;
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce struct ldb_result *dom_res;
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce struct ldb_result *res;
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce struct ldb_dn *basedn;
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce const char *attrs[] = { "cn", "name", NULL };
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce const char *tmp_str;
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce errno_t ret;
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce int i, j, l, n;
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_14, &ctx);
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce if (ret) {
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce return ret;
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce }
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce basedn = ldb_dn_new(ctx, sysdb->ldb, SYSDB_BASE);
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce if (!basedn) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to build base dn\n");
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce ret = EIO;
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce goto done;
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce }
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce ret = ldb_search(sysdb->ldb, ctx, &dom_res,
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce basedn, LDB_SCOPE_ONELEVEL,
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce attrs, "objectclass=%s", SYSDB_SUBDOMAIN_CLASS);
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce if (ret != LDB_SUCCESS) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to search subdomains\n");
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce ret = EIO;
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce goto done;
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce }
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce for (i = 0; i < dom_res->count; i++) {
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce tmp_str = ldb_msg_find_attr_as_string(dom_res->msgs[i], "cn", NULL);
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce if (tmp_str == NULL) {
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "The object [%s] doesn't have a name\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ldb_dn_get_linearized(dom_res->msgs[i]->dn));
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce continue;
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce }
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce basedn = ldb_dn_new_fmt(ctx, sysdb->ldb, SYSDB_DOM_BASE, tmp_str);
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce if (!basedn) {
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to build base dn for subdomain %s\n", tmp_str);
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce continue;
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce }
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce ret = ldb_search(sysdb->ldb, ctx, &res,
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce basedn, LDB_SCOPE_SUBTREE, attrs, NULL);
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce if (ret != LDB_SUCCESS) {
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to search subdomain %s\n", tmp_str);
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce talloc_free(basedn);
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce continue;
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce }
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce l = ldb_dn_get_comp_num(basedn);
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce for (j = 0; j < res->count; j++) {
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce n = ldb_dn_get_comp_num(res->msgs[j]->dn);
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce if (n <= l + 1) {
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce /* Do not remove subdomain containers, only their contents */
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce continue;
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce }
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce ret = ldb_delete(sysdb->ldb, res->msgs[j]->dn);
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce if (ret) {
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to delete %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ldb_dn_get_linearized(res->msgs[j]->dn));
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce continue;
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce }
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce }
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce talloc_free(basedn);
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce talloc_free(res);
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce }
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce talloc_free(dom_res);
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce /* conversion done, update version number */
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce ret = update_version(ctx);
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorcedone:
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce ret = finish_upgrade(ret, &ctx, ver);
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce return ret;
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce}
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorceint sysdb_upgrade_14(struct sysdb_ctx *sysdb, const char **ver)
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce{
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce struct upgrade_ctx *ctx;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce struct ldb_message *msg;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce struct ldb_result *res;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce struct ldb_dn *basedn;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce struct ldb_dn *newdn;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce const char *attrs[] = { SYSDB_NAME, NULL };
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce const char *tmp_str;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce errno_t ret;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce int i;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_15, &ctx);
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce if (ret) {
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce return ret;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce }
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce basedn = ldb_dn_new(ctx, sysdb->ldb, SYSDB_BASE);
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce if (!basedn) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to build base dn\n");
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce ret = EIO;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce goto done;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce }
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce /* create base ranges container */
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce msg = ldb_msg_new(ctx);
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce if (!msg) {
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce ret = ENOMEM;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce goto done;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce }
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce msg->dn = ldb_dn_new(msg, sysdb->ldb, SYSDB_TMPL_RANGE_BASE);
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce if (!msg->dn) {
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce ret = ENOMEM;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce goto done;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce }
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce ret = ldb_msg_add_string(msg, "cn", "ranges");
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce if (ret != LDB_SUCCESS) {
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce ret = EIO;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce goto done;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce }
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce /* do a synchronous add */
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce ret = ldb_add(sysdb->ldb, msg);
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce if (ret != LDB_SUCCESS) {
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce DEBUG(SSSDBG_FATAL_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to upgrade DB (%d, [%s])!\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, ldb_errstring(sysdb->ldb));
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce ret = EIO;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce goto done;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce }
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce talloc_zfree(msg);
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce ret = ldb_search(sysdb->ldb, ctx, &res,
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce basedn, LDB_SCOPE_SUBTREE, attrs,
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce "objectclass=%s", SYSDB_ID_RANGE_CLASS);
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce if (ret != LDB_SUCCESS) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to search range objects\n");
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce ret = EIO;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce goto done;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce }
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce /* Failure to convert any range is not fatal. As long as there are no
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce * left-over objects we can fail to move them around, as they will be
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce * recreated on the next online access */
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce for (i = 0; i < res->count; i++) {
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce tmp_str = ldb_msg_find_attr_as_string(res->msgs[i], SYSDB_NAME, NULL);
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce if (tmp_str == NULL) {
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "The object [%s] doesn't have a name\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ldb_dn_get_linearized(res->msgs[i]->dn));
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce ret = ldb_delete(sysdb->ldb, res->msgs[i]->dn);
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce if (ret) {
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to delete %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ldb_dn_get_linearized(res->msgs[i]->dn));
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce ret = EIO;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce goto done;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce }
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce continue;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce }
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce newdn = ldb_dn_new_fmt(ctx, sysdb->ldb, SYSDB_TMPL_RANGE, tmp_str);
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce if (!newdn) {
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to create new DN to move [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ldb_dn_get_linearized(res->msgs[i]->dn));
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce ret = ENOMEM;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce goto done;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce }
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce ret = ldb_rename(sysdb->ldb, res->msgs[i]->dn, newdn);
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce if (ret != LDB_SUCCESS) {
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to move [%s] to [%s]\n",
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce ldb_dn_get_linearized(res->msgs[i]->dn),
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ldb_dn_get_linearized(newdn));
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce ret = ldb_delete(sysdb->ldb, res->msgs[i]->dn);
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce if (ret) {
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to delete %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ldb_dn_get_linearized(res->msgs[i]->dn));
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce ret = EIO;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce goto done;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce }
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce }
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce talloc_zfree(newdn);
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce }
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce /* conversion done, update version number */
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce ret = update_version(ctx);
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorcedone:
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce ret = finish_upgrade(ret, &ctx, ver);
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce return ret;
73120327cc136229d56d08f7f8c5e8df4129c1e3Simo Sorce}
d096233fe7610186ee12f41f97ca9602a3768405Simo Sorce
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Boseint sysdb_upgrade_15(struct sysdb_ctx *sysdb, const char **ver)
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose{
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose TALLOC_CTX *tmp_ctx;
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose int ret;
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose struct ldb_message *msg;
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose struct upgrade_ctx *ctx;
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose tmp_ctx = talloc_new(NULL);
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose if (!tmp_ctx) {
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose return ENOMEM;
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose }
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_16, &ctx);
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose if (ret) {
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose return ret;
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose }
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose /* Add new indexes */
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose msg = ldb_msg_new(tmp_ctx);
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose if (!msg) {
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose ret = ENOMEM;
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose goto done;
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose }
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@ATTRIBUTES");
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose if (!msg->dn) {
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose ret = ENOMEM;
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose goto done;
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose }
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose /* Case insensitive search for canonicalUserPrincipalName */
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose ret = ldb_msg_add_empty(msg, SYSDB_CANONICAL_UPN, LDB_FLAG_MOD_ADD, NULL);
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose if (ret != LDB_SUCCESS) {
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose ret = ENOMEM;
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose goto done;
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose }
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose ret = ldb_msg_add_string(msg, SYSDB_CANONICAL_UPN, "CASE_INSENSITIVE");
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose if (ret != LDB_SUCCESS) {
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose ret = ENOMEM;
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose goto done;
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose }
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose ret = ldb_modify(sysdb->ldb, msg);
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose if (ret != LDB_SUCCESS) {
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose ret = sysdb_error_to_errno(ret);
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose goto done;
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose }
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose /* conversion done, update version number */
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose ret = update_version(ctx);
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bosedone:
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose ret = finish_upgrade(ret, &ctx, ver);
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose talloc_free(tmp_ctx);
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose return ret;
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose}
9ad2756fcf4df945f4cd09238e3f9fe707b0b70cSumit Bose
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozekint sysdb_upgrade_16(struct sysdb_ctx *sysdb, const char **ver)
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek{
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek struct ldb_message *msg;
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek struct upgrade_ctx *ctx;
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek errno_t ret;
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_17, &ctx);
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek if (ret) {
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek return ret;
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek }
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek msg = ldb_msg_new(ctx);
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek if (msg == NULL) {
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek ret = ENOMEM;
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek goto done;
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek }
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek msg->dn = ldb_dn_new(msg, sysdb->ldb, "@INDEXLIST");
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek if (msg->dn == NULL) {
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek ret = ENOMEM;
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek goto done;
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek }
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek /* add index for objectSIDString */
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL);
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek if (ret != LDB_SUCCESS) {
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek ret = ENOMEM;
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek goto done;
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek }
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek ret = ldb_msg_add_string(msg, "@IDXATTR", "objectSIDString");
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek if (ret != LDB_SUCCESS) {
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek ret = ENOMEM;
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek goto done;
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek }
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek ret = ldb_modify(sysdb->ldb, msg);
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek if (ret != LDB_SUCCESS) {
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek ret = sysdb_error_to_errno(ret);
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek goto done;
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek }
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek /* conversion done, update version number */
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek ret = update_version(ctx);
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozekdone:
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek ret = finish_upgrade(ret, &ctx, ver);
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek return ret;
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek}
e61b0e41cb44004d2b260ad9d05802995f7bcb2eJakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozekstatic char *object_domain_from_dn(TALLOC_CTX *mem_ctx,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_dn *dn,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek unsigned domain_index)
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek{
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const struct ldb_val *val;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek val = ldb_dn_get_component_val(dn, domain_index);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (val == NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return NULL;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return talloc_strdup(mem_ctx, (const char *) val->data);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek}
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozekstatic char *object_domain(TALLOC_CTX *mem_ctx,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_context *ldb,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_message *msg,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *domain_attr,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek unsigned domain_index)
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek{
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_dn *dom_dn;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (domain_attr != NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek dom_dn = ldb_msg_find_attr_as_dn(ldb, mem_ctx, msg, domain_attr);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek } else {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek /* If no specific attribute to take the domain from is specified,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek * use the DN */
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek dom_dn = msg->dn;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (dom_dn == NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return NULL;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return object_domain_from_dn(mem_ctx, dom_dn, domain_index);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek}
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek/* Used for attributes like sudoUser which contain group or user name or
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek * ID, depending on the value prefix */
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozektypedef bool (*should_qualify_val_fn)(const char *val);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek/* Qualifies a string attribute using domain_name. Optionally, if qfn is
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek * given, only qualifies the name if qfn returns true */
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozekstatic errno_t qualify_attr(struct ldb_message *msg,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_message *mod_msg,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct sss_names_ctx *names,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *domain_name,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *attrname,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek should_qualify_val_fn qfn)
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek{
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_message_element *el;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_message_element *mod_el;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek char *fqval;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek char *shortname;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *rawname;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek int ret;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_val val;
1ea5a9c1930f531b21f8bc67c9c071d8ce533786Sumit Bose bool exists = false;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek el = ldb_msg_find_element(msg, attrname);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (el == NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek /* This entry does not have this element, fine */
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return EOK;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek for (size_t c = 0; c < el->num_values; c++) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek rawname = (const char *) el->values[c].data;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (qfn != NULL && qfn(rawname) == false) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek continue;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = sss_parse_name(mod_msg, names, rawname, NULL, &shortname);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (ret != EOK) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek "Cannot parse raw attribute %s\n", rawname);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek continue;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek fqval = sss_create_internal_fqname(el->values, shortname, domain_name);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek talloc_free(shortname);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (fqval == NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Cannot qualify %s@%s\n",
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek shortname, domain_name);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek continue;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek mod_el = ldb_msg_find_element(mod_msg, attrname);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (mod_el != NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek val.data = (uint8_t *) fqval;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek val.length = strlen(fqval);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (ldb_msg_find_val(mod_el, &val) != NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return true;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "Qualified %s:%s into %s\n",
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek attrname, rawname, fqval);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
1ea5a9c1930f531b21f8bc67c9c071d8ce533786Sumit Bose if (!exists) {
1ea5a9c1930f531b21f8bc67c9c071d8ce533786Sumit Bose ret = ldb_msg_add_empty(mod_msg, attrname, LDB_FLAG_MOD_REPLACE, NULL);
1ea5a9c1930f531b21f8bc67c9c071d8ce533786Sumit Bose if (ret != LDB_SUCCESS) {
1ea5a9c1930f531b21f8bc67c9c071d8ce533786Sumit Bose continue;
1ea5a9c1930f531b21f8bc67c9c071d8ce533786Sumit Bose }
1ea5a9c1930f531b21f8bc67c9c071d8ce533786Sumit Bose
1ea5a9c1930f531b21f8bc67c9c071d8ce533786Sumit Bose exists = true;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = ldb_msg_add_steal_string(mod_msg, attrname, fqval);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (ret != LDB_SUCCESS) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek continue;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return EOK;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek}
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek/* Returns a copy of old_dn_val with RDN qualified. The domain name
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek * is read from the DN itself
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek */
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozekstatic struct ldb_dn *qualify_rdn(TALLOC_CTX *mem_ctx,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_context *ldb,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct sss_names_ctx *names,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_dn *old_dn_val)
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek{
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_dn *parent_dn = NULL;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const struct ldb_val *val = NULL;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *rdn_name = NULL;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_dn *new_dn = NULL;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek char *fqrdn = NULL;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek char *shortname = NULL;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek char *dn_domain = NULL;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek TALLOC_CTX *tmp_ctx = NULL;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek int ret;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek rdn_name = ldb_dn_get_rdn_name(old_dn_val);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (rdn_name == NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return NULL;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (strcmp(rdn_name, SYSDB_NAME) != 0) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek /* Only qualify DNs with name= rdn. This applies to overrideDNs mostly,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek * because those can contain either names or UUIDs
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek */
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return ldb_dn_copy(mem_ctx, old_dn_val);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek val = ldb_dn_get_rdn_val(old_dn_val);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (val == NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return NULL;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek tmp_ctx = talloc_new(NULL);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (tmp_ctx == NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return NULL;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek dn_domain = object_domain_from_dn(tmp_ctx, old_dn_val, 2);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (dn_domain == NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek "Cannot determine domain of %s\n",
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ldb_dn_get_linearized(old_dn_val));
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek goto done;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = sss_parse_name(tmp_ctx, names, (const char *) val->data,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek NULL, &shortname);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (ret != EOK) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek "Cannot parse raw RDN %s\n", (const char *) val->data);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek goto done;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek fqrdn = sss_create_internal_fqname(tmp_ctx, shortname, dn_domain);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (fqrdn == NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Cannot qualify %s@%s\n",
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek shortname, dn_domain);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek goto done;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek parent_dn = ldb_dn_get_parent(tmp_ctx, old_dn_val);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (parent_dn == NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek "Cannot get parent of %s\n",
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ldb_dn_get_linearized(old_dn_val));
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek goto done;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek new_dn = ldb_dn_new_fmt(mem_ctx, ldb, "%s=%s,%s",
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek rdn_name, fqrdn,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ldb_dn_get_linearized(parent_dn));
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozekdone:
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek talloc_free(tmp_ctx);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return new_dn;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek}
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozekstatic errno_t qualify_dn_attr(struct ldb_context *ldb,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_message *msg,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_message *mod_msg,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct sss_names_ctx *names,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *attrname)
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek{
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_message_element *el;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_message_element *mod_el;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_dn *attr_dn;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_dn *fqdn;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek errno_t ret;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek TALLOC_CTX *tmp_ctx = NULL;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek el = ldb_msg_find_element(msg, attrname);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (el == NULL || el->num_values == 0) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return EOK;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek tmp_ctx = talloc_new(NULL);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (tmp_ctx == NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return ENOMEM;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek for (size_t c = 0; c < el->num_values; c++) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek attr_dn = ldb_dn_new(tmp_ctx, ldb, (const char *) el->values[c].data);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (attr_dn == NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Cannot create DN from %s\n",
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek (const char *) el->values[c].data);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek continue;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (!ldb_dn_validate(attr_dn)) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "DN %s does not validate\n",
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek (const char *) el->values[c].data);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek continue;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek fqdn = qualify_rdn(tmp_ctx, ldb, names, attr_dn);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (fqdn == NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Cannot qualify %s\n",
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek (const char *) el->values[c].data);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek continue;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = ldb_msg_add_linearized_dn(mod_msg, attrname, fqdn);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (ret != LDB_SUCCESS) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek continue;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek talloc_free(attr_dn);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek talloc_free(fqdn);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek mod_el = ldb_msg_find_element(mod_msg, attrname);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (mod_el != NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek mod_el->flags = LDB_FLAG_MOD_REPLACE;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek talloc_free(tmp_ctx);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return EOK;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek}
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozekstatic errno_t expire_object(struct ldb_message *object,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_message *mod_msg)
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek{
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek errno_t ret;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_message_element *el;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *attrs[] = { SYSDB_CACHE_EXPIRE,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek SYSDB_LAST_UPDATE,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek SYSDB_INITGR_EXPIRE,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek NULL
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek };
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek for (size_t c = 0; attrs[c] != NULL; c++) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek el = ldb_msg_find_element(object, attrs[c]);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (el == NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek continue;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = ldb_msg_add_empty(mod_msg, attrs[c], LDB_FLAG_MOD_REPLACE, NULL);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (ret != LDB_SUCCESS) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return ret;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = ldb_msg_add_fmt(mod_msg, attrs[c], "%d", 1);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (ret != LDB_SUCCESS) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return ret;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return EOK;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek}
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozekstatic errno_t qualify_object(TALLOC_CTX *mem_ctx,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_context *ldb,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct sss_names_ctx *names,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_message *object,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek bool qualify_dn,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *domain_attr,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek unsigned domain_index,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *name_attrs[],
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *dn_attrs[],
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek should_qualify_val_fn qfn)
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek{
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek int ret;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_message *mod_msg = NULL;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_dn *new_object_dn = NULL;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *dom_name;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek mod_msg = ldb_msg_new(mem_ctx);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (mod_msg == NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return ENOMEM;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek mod_msg->dn = object->dn;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek dom_name = object_domain(mod_msg, ldb, object, domain_attr, domain_index);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (dom_name == NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek "Cannot determine domain of %s\n",
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ldb_dn_get_linearized(mod_msg->dn));
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return EINVAL;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (name_attrs != NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek for (size_t c = 0; name_attrs[c]; c++) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = qualify_attr(object, mod_msg, names,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek dom_name, name_attrs[c], qfn);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (ret != EOK) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek "Cannot qualify %s of %s\n",
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek name_attrs[c], ldb_dn_get_linearized(object->dn));
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek continue;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (dn_attrs != NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek for (size_t c = 0; dn_attrs[c]; c++) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = qualify_dn_attr(ldb, object, mod_msg,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek names, dn_attrs[c]);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (ret != EOK) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek "Cannot qualify %s of %s\n",
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek dn_attrs[c], ldb_dn_get_linearized(object->dn));
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = expire_object(object, mod_msg);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (ret != EOK) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek "Cannot expire %s\n", ldb_dn_get_linearized(object->dn));
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek /* Override objects can contain both qualified and non-qualified names.
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek * Need to use permissive modification here, otherwise we might attempt
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek * to store duplicate qualified names
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek */
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = sss_ldb_modify_permissive(ldb, mod_msg);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (ret != LDB_SUCCESS) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek "Cannot modify %s\n", ldb_dn_get_linearized(object->dn));
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek goto done;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (qualify_dn) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek new_object_dn = qualify_rdn(mod_msg, ldb, names, mod_msg->dn);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (new_object_dn == NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = EIO;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek goto done;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = ldb_rename(ldb, object->dn, new_object_dn);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (ret != LDB_SUCCESS) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek "Cannot rename %s to %s\n",
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ldb_dn_get_linearized(object->dn),
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ldb_dn_get_linearized(new_object_dn));
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek goto done;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = EOK;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozekdone:
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek talloc_free(mod_msg);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return ret;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek}
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozekstatic void qualify_objects(struct upgrade_ctx *ctx,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_context *ldb,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct sss_names_ctx *names,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_dn *base_dn,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek bool qualify_dn,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *domain_attr,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek unsigned domain_index,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *filter,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *name_attrs[],
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *dn_attrs[],
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek should_qualify_val_fn qfn)
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek{
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek errno_t ret;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_result *objects = NULL;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *attrs[] = { "*", NULL };
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = ldb_search(ldb, ctx, &objects, base_dn,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek LDB_SCOPE_SUBTREE, attrs, "%s", filter);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (ret != LDB_SUCCESS) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Failed to search objects: %d\n", ret);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (objects == NULL || objects->count == 0) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "No match for: %s\n", filter);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek for (size_t c = 0; c < objects->count; c++) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = qualify_object(ctx, ldb, names, objects->msgs[c],
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek qualify_dn, domain_attr, domain_index,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek name_attrs, dn_attrs, qfn);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (ret != EOK) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek "Could not qualify object %s: %d\n",
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ldb_dn_get_linearized(objects->msgs[c]->dn), ret);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek continue;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek talloc_free(objects);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek}
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozekstatic void qualify_users(struct upgrade_ctx *ctx,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_context *ldb,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct sss_names_ctx *names,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_dn *base_dn)
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek{
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose /* No change needed because this version has objectclass user */
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *user_filter = "objectclass=user";
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *user_name_attrs[] = { SYSDB_NAME,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek SYSDB_NAME_ALIAS,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek SYSDB_DEFAULT_OVERRIDE_NAME,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ORIGINALAD_PREFIX SYSDB_NAME,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek NULL
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek };
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *user_dn_attrs[] = { SYSDB_MEMBEROF,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek SYSDB_OVERRIDE_DN,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek NULL
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek };
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return qualify_objects(ctx, ldb, names, base_dn,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek true, /* qualify dn */
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek NULL, /* no special domain attr, use DN */
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek 2, /* DN's domain is third RDN from top */
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek user_filter,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek user_name_attrs, user_dn_attrs, NULL);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek}
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozekstatic void qualify_groups(struct upgrade_ctx *ctx,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_context *ldb,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct sss_names_ctx *names,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_dn *base_dn)
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek{
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose /* No change needed because this version has objectclass group */
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *group_filter = "objectclass=group";
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *group_name_attrs[] = { SYSDB_NAME,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek SYSDB_NAME_ALIAS,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek SYSDB_DEFAULT_OVERRIDE_NAME,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ORIGINALAD_PREFIX SYSDB_NAME,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek SYSDB_MEMBERUID,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek SYSDB_GHOST,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek NULL
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek };
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *group_dn_attrs[] = { SYSDB_MEMBER,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek SYSDB_MEMBEROF,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek SYSDB_OVERRIDE_DN,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek NULL
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek };
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return qualify_objects(ctx, ldb, names, base_dn, true,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek NULL, 2, group_filter,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek group_name_attrs, group_dn_attrs, NULL);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek}
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozekstatic void qualify_user_overrides(struct upgrade_ctx *ctx,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_context *ldb,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct sss_names_ctx *names,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_dn *base_dn)
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek{
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *user_override_filter = "objectclass=userOverride";
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *user_ovr_name_attrs[] = { SYSDB_NAME,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek SYSDB_NAME_ALIAS,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek NULL
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek };
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *user_ovr_dn_attrs[] = { SYSDB_OVERRIDE_OBJECT_DN,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek NULL
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek };
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return qualify_objects(ctx, ldb, names, base_dn,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek /* Don't qualify RDN of override DN */
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek false,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek /* Read domain from override DN */
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek SYSDB_OVERRIDE_OBJECT_DN,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek 2, /* Third RDN from top is domain */
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek user_override_filter, user_ovr_name_attrs,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek user_ovr_dn_attrs, NULL);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek}
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozekstatic void qualify_group_overrides(struct upgrade_ctx *ctx,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_context *ldb,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct sss_names_ctx *names,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_dn *base_dn)
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek{
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *group_override_filter = "objectclass=groupOverride";
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *group_ovr_name_attrs[] = { SYSDB_NAME,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek SYSDB_NAME_ALIAS,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek NULL
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek };
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *group_ovr_dn_attrs[] = { SYSDB_OVERRIDE_OBJECT_DN,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek NULL
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek };
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return qualify_objects(ctx, ldb, names, base_dn,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek false, SYSDB_OVERRIDE_OBJECT_DN, 2,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek group_override_filter, group_ovr_name_attrs,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek group_ovr_dn_attrs, NULL);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek}
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozekstatic void qualify_sudo_rules(struct upgrade_ctx *ctx,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_context *ldb,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct sss_names_ctx *names,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_dn *base_dn)
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek{
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *group_override_filter = "objectclass=sudoRule";
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char *sudo_rule_name_attrs[] = { "sudoUser",
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek NULL
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek };
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return qualify_objects(ctx, ldb, names, base_dn,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek false, NULL, 3,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek group_override_filter, sudo_rule_name_attrs,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek NULL, is_user_or_group_name);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek}
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozekint sysdb_upgrade_17(struct sysdb_ctx *sysdb,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct sysdb_dom_upgrade_ctx *upgrade_ctx,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek const char **ver)
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek{
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct upgrade_ctx *ctx;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek errno_t ret, envret;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct ldb_dn *base_dn;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek struct sss_names_ctx *names = upgrade_ctx->names;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (names == NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return EINVAL;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_18, &ctx);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (ret) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return ret;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek /* Disable memberof plugin during this update */
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = setenv("SSSD_UPGRADE_DB", "1", 1);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (ret != 0) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek goto done;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek base_dn = ldb_dn_new_fmt(ctx, sysdb->ldb, SYSDB_BASE);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (base_dn == NULL) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = ENOMEM;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek goto done;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek qualify_users(ctx, sysdb->ldb, names, base_dn);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek qualify_groups(ctx, sysdb->ldb, names, base_dn);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek qualify_user_overrides(ctx, sysdb->ldb, names, base_dn);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek qualify_group_overrides(ctx, sysdb->ldb, names, base_dn);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek qualify_sudo_rules(ctx, sysdb->ldb, names, base_dn);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek /* conversion done, update version number */
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = update_version(ctx);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozekdone:
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek ret = finish_upgrade(ret, &ctx, ver);
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek envret = unsetenv("SSSD_UPGRADE_DB");
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek if (envret != EOK) {
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek "Cannot unset SSSD_UPGRADE_DB, SSSD might not work correctly\n");
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek }
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek return ret;
8531bd4585f9135ffd4cbb9bb4c880dc77b5adc4Jakub Hrozek}
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Boseint sysdb_upgrade_18(struct sysdb_ctx *sysdb, const char **ver)
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose{
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose struct upgrade_ctx *ctx;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose errno_t ret;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose struct ldb_message *msg = NULL;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_19, &ctx);
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose if (ret) {
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose return ret;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose }
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose /* Add missing indices */
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose msg = ldb_msg_new(ctx);
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose if (msg == NULL) {
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = ENOMEM;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose goto done;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose }
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose msg->dn = ldb_dn_new(msg, sysdb->ldb, "@INDEXLIST");
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose if (msg->dn == NULL) {
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = ENOMEM;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose goto done;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose }
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL);
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose if (ret != LDB_SUCCESS) {
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = ENOMEM;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose goto done;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose }
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = ldb_msg_add_string(msg, "@IDXATTR", SYSDB_GHOST);
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose if (ret != LDB_SUCCESS) {
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = ENOMEM;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose goto done;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose }
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = ldb_msg_add_string(msg, "@IDXATTR", SYSDB_UPN);
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose if (ret != LDB_SUCCESS) {
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = ENOMEM;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose goto done;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose }
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = ldb_msg_add_string(msg, "@IDXATTR", SYSDB_CANONICAL_UPN);
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose if (ret != LDB_SUCCESS) {
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = ENOMEM;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose goto done;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose }
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = ldb_msg_add_string(msg, "@IDXATTR", SYSDB_UUID);
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose if (ret != LDB_SUCCESS) {
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = ENOMEM;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose goto done;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose }
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = ldb_msg_add_string(msg, "@IDXATTR", SYSDB_USER_EMAIL);
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose if (ret != LDB_SUCCESS) {
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = ENOMEM;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose goto done;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose }
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = ldb_modify(sysdb->ldb, msg);
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose if (ret != LDB_SUCCESS) {
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = sysdb_error_to_errno(ret);
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose goto done;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose }
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose talloc_free(msg);
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose /* conversion done, update version number */
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = update_version(ctx);
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bosedone:
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose ret = finish_upgrade(ret, &ctx, ver);
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose return ret;
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose}
9acdf51bf32d7b4389f3faea0fc6b73c56b6da71Sumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bosestatic errno_t add_object_category(struct ldb_context *ldb,
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose struct upgrade_ctx *ctx)
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose{
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose errno_t ret;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose struct ldb_result *objects = NULL;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose const char *attrs[] = { SYSDB_OBJECTCLASS, NULL };
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose struct ldb_dn *base_dn;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose size_t c;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose const char *class_name;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose struct ldb_message *msg = NULL;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose struct ldb_message *del_msg = NULL;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose base_dn = ldb_dn_new(ctx, ldb, SYSDB_BASE);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (base_dn == NULL) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Failed create base dn.\n");
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose return ENOMEM;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = ldb_search(ldb, ctx, &objects, base_dn,
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose LDB_SCOPE_SUBTREE, attrs,
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose "(|("SYSDB_OBJECTCLASS"="SYSDB_USER_CLASS")"
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose "("SYSDB_OBJECTCLASS"="SYSDB_GROUP_CLASS"))");
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose talloc_free(base_dn);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (ret != LDB_SUCCESS) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "Failed to search objects: %d\n", ret);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = sysdb_error_to_errno(ret);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (objects == NULL || objects->count == 0) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose DEBUG(SSSDBG_TRACE_LIBS, "No objects found, nothing to do.");
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = EOK;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose del_msg = ldb_msg_new(ctx);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (del_msg == NULL) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_msg_new failed.\n");
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = ENOMEM;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = ldb_msg_add_empty(del_msg, SYSDB_OBJECTCLASS, LDB_FLAG_MOD_DELETE,
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose NULL);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (ret != LDB_SUCCESS) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_msg_add_empty failed.\n");
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = sysdb_error_to_errno(ret);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose DEBUG(SSSDBG_TRACE_ALL, "Found [%d] objects.\n", objects->count);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose for (c = 0; c < objects->count; c++) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose DEBUG(SSSDBG_TRACE_ALL, "Updating [%s].\n",
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ldb_dn_get_linearized(objects->msgs[c]->dn));
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose class_name = ldb_msg_find_attr_as_string(objects->msgs[c],
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose SYSDB_OBJECTCLASS, NULL);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (class_name == NULL) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "Searched objects by objectClass, "
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose "but result does not have one.\n");
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = EINVAL;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose talloc_free(msg);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose msg = ldb_msg_new(ctx);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (msg == NULL) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_msg_new failed.\n");
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = ENOMEM;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose msg->dn = objects->msgs[c]->dn;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose del_msg->dn = objects->msgs[c]->dn;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = ldb_msg_add_empty(msg, SYSDB_OBJECTCATEGORY, LDB_FLAG_MOD_ADD,
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose NULL);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (ret != LDB_SUCCESS) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_msg_add_empty failed.\n");
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = sysdb_error_to_errno(ret);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = ldb_msg_add_string(msg, SYSDB_OBJECTCATEGORY, class_name);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (ret != LDB_SUCCESS) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose DEBUG(SSSDBG_OP_FAILURE, "ldb_msg_add_string failed.\n");
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = sysdb_error_to_errno(ret);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose DEBUG(SSSDBG_TRACE_ALL, "Adding [%s] to [%s].\n", class_name,
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ldb_dn_get_linearized(objects->msgs[c]->dn));
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = ldb_modify(ldb, msg);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (ret != LDB_SUCCESS) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose DEBUG(SSSDBG_OP_FAILURE,
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose "Failed to add objectCategory to %s: %d.\n",
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ldb_dn_get_linearized(objects->msgs[c]->dn),
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose sysdb_error_to_errno(ret));
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = sysdb_error_to_errno(ret);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = ldb_modify(ldb, del_msg);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (ret != LDB_SUCCESS) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose DEBUG(SSSDBG_OP_FAILURE,
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose "Failed to remove objectClass from %s: %d.\n",
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ldb_dn_get_linearized(objects->msgs[c]->dn),
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose sysdb_error_to_errno(ret));
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = sysdb_error_to_errno(ret);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = EOK;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bosedone:
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose talloc_free(msg);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose talloc_free(del_msg);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose talloc_free(objects);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose return ret;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose}
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Boseint sysdb_upgrade_19(struct sysdb_ctx *sysdb, const char **ver)
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose{
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose struct upgrade_ctx *ctx;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose errno_t ret;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose struct ldb_message *msg = NULL;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_20, &ctx);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (ret) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose return ret;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = add_object_category(sysdb->ldb, ctx);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (ret != EOK) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "add_object_category failed.\n");
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose /* Remove @IDXONE from index */
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose msg = ldb_msg_new(ctx);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (msg == NULL) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = ENOMEM;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose msg->dn = ldb_dn_new(msg, sysdb->ldb, "@INDEXLIST");
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (msg->dn == NULL) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = ENOMEM;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = ldb_msg_add_empty(msg, "@IDXONE", LDB_FLAG_MOD_DELETE, NULL);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (ret != LDB_SUCCESS) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = ENOMEM;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
5b78fff78bb44d1af5420db23b02210f755f5f17Sumit Bose ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL);
5b78fff78bb44d1af5420db23b02210f755f5f17Sumit Bose if (ret != LDB_SUCCESS) {
5b78fff78bb44d1af5420db23b02210f755f5f17Sumit Bose ret = ENOMEM;
5b78fff78bb44d1af5420db23b02210f755f5f17Sumit Bose goto done;
5b78fff78bb44d1af5420db23b02210f755f5f17Sumit Bose }
5b78fff78bb44d1af5420db23b02210f755f5f17Sumit Bose
5b78fff78bb44d1af5420db23b02210f755f5f17Sumit Bose ret = ldb_msg_add_string(msg, "@IDXATTR", SYSDB_USER_MAPPED_CERT);
5b78fff78bb44d1af5420db23b02210f755f5f17Sumit Bose if (ret != LDB_SUCCESS) {
5b78fff78bb44d1af5420db23b02210f755f5f17Sumit Bose ret = ENOMEM;
5b78fff78bb44d1af5420db23b02210f755f5f17Sumit Bose goto done;
5b78fff78bb44d1af5420db23b02210f755f5f17Sumit Bose }
5b78fff78bb44d1af5420db23b02210f755f5f17Sumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = ldb_modify(sysdb->ldb, msg);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (ret != LDB_SUCCESS) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = sysdb_error_to_errno(ret);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose /* conversion done, update version number */
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = update_version(ctx);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bosedone:
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = finish_upgrade(ret, &ctx, ver);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose return ret;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose}
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Boseint sysdb_ts_upgrade_01(struct sysdb_ctx *sysdb, const char **ver)
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose{
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose struct upgrade_ctx *ctx;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose errno_t ret;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose struct ldb_message *msg = NULL;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_TS_VERSION_0_2, &ctx);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (ret) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose return ret;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose /* Remove @IDXONE from index */
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose talloc_free(msg);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose msg = ldb_msg_new(ctx);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (msg == NULL) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = ENOMEM;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose msg->dn = ldb_dn_new(msg, sysdb->ldb, "@INDEXLIST");
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (msg->dn == NULL) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = ENOMEM;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = ldb_msg_add_empty(msg, "@IDXONE", LDB_FLAG_MOD_DELETE, NULL);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (ret != LDB_SUCCESS) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = ENOMEM;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = ldb_modify(sysdb->ldb, msg);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose if (ret != LDB_SUCCESS) {
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = sysdb_error_to_errno(ret);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose goto done;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose }
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose /* conversion done, update version number */
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = update_version(ctx);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bosedone:
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose ret = finish_upgrade(ret, &ctx, ver);
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose return ret;
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose}
2927da49dd8a16fff6312d89ad43cc355655800cSumit Bose
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce/*
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce * Example template for future upgrades.
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce * Copy and change version numbers as appropriate.
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce */
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce#if 0
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorceint sysdb_upgrade_13(struct sysdb_ctx *sysdb, const char **ver)
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce{
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce struct upgrade_ctx *ctx;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce errno_t ret;
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_14, &ctx);
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce if (ret) {
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce return ret;
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta }
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce /* DO STUFF HERE (use ctx, as the local temporary memory context) */
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce /* conversion done, update version number */
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = update_version(ctx);
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholastadone:
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce ret = finish_upgrade(ret, &ctx, ver);
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta return ret;
3882325ff60f89d0c312e9519bdfd1351978fd73Jan Cholasta}
868ae511c9b0d610f83acf8f01975e1f5e3c1aa3Simo Sorce#endif