sysdb_upgrade.c revision 12a000c8c7c07259e438fb1e992134bdd07d9a30
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose/*
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose SSSD
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose Authors:
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose Simo Sorce <ssorce@redhat.com>
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose Stephen Gallagher <sgallagh@redhat.com>
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose Copyright (C) 2008-2011 Simo Sorce <ssorce@redhat.com>
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose Copyright (C) 2008-2011 Stephen Gallagher
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose This program is free software; you can redistribute it and/or modify
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose it under the terms of the GNU General Public License as published by
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose the Free Software Foundation; either version 3 of the License, or
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose (at your option) any later version.
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose This program is distributed in the hope that it will be useful,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose GNU General Public License for more details.
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose You should have received a copy of the GNU General Public License
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose*/
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose#include "util/util.h"
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose#include "db/sysdb_private.h"
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose#include "db/sysdb_autofs.h"
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bosestruct upgrade_ctx {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose struct ldb_context *ldb;
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce const char *new_version;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose};
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenystatic errno_t commence_upgrade(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose const char *new_ver, struct upgrade_ctx **_ctx)
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny{
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct upgrade_ctx *ctx;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose int ret;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "UPGRADING DB TO VERSION %s\n", new_ver);
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ctx = talloc(mem_ctx, struct upgrade_ctx);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (!ctx) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose return ENOMEM;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ctx->ldb = ldb;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ctx->new_version = new_ver;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = ldb_transaction_start(ldb);
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce if (ret != LDB_SUCCESS) {
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce ret = EIO;
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce goto done;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose }
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = EOK;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zelenydone:
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != EOK) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny talloc_free(ctx);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny } else {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny *_ctx = ctx;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny return ret;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny}
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bosestatic errno_t update_version(struct upgrade_ctx *ctx)
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny{
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny struct ldb_message *msg = NULL;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce errno_t ret;
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce
418e6ccd116eced7ccc75aca999a4c37c67289baJakub Hrozek msg = ldb_msg_new(ctx);
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce if (!msg) {
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce ret = ENOMEM;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce goto done;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce }
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose msg->dn = ldb_dn_new(msg, ctx->ldb, SYSDB_BASE);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (!msg->dn) {
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce ret = ENOMEM;
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce goto done;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose }
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose ret = ldb_msg_add_empty(msg, "version", LDB_FLAG_MOD_REPLACE, NULL);
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce if (ret != LDB_SUCCESS) {
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce ret = ENOMEM;
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose goto done;
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose }
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose ret = ldb_msg_add_string(msg, "version", ctx->new_version);
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose if (ret != LDB_SUCCESS) {
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose ret = ENOMEM;
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose goto done;
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose }
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose ret = ldb_modify(ctx->ldb, msg);
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose if (ret != LDB_SUCCESS) {
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose ret = sysdb_error_to_errno(ret);
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose goto done;
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose }
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret = EOK;
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bosedone:
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose talloc_free(msg);
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose return ret;
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose}
b1829e54acbc8a010aca7f14b9ffa9625f8c102cSumit Bose
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozekstatic int finish_upgrade(int ret, struct upgrade_ctx **ctx, const char **ver)
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozek{
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozek int lret;
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozek
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozek if (ret == EOK) {
c3243e3212f91b69ef9990e2cb4c9339bf2f7888Jakub Hrozek lret = ldb_transaction_commit((*ctx)->ldb);
c3243e3212f91b69ef9990e2cb4c9339bf2f7888Jakub Hrozek ret = sysdb_error_to_errno(lret);
c3243e3212f91b69ef9990e2cb4c9339bf2f7888Jakub Hrozek if (ret == EOK) {
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose *ver = (*ctx)->new_version;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose }
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose }
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose if (ret != EOK) {
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose lret = ldb_transaction_cancel((*ctx)->ldb);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose if (lret != LDB_SUCCESS) {
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
c3243e3212f91b69ef9990e2cb4c9339bf2f7888Jakub Hrozek "Could not cancel transaction! [%s]\n",
c3243e3212f91b69ef9990e2cb4c9339bf2f7888Jakub Hrozek ldb_strerror(lret));
c3243e3212f91b69ef9990e2cb4c9339bf2f7888Jakub Hrozek /* Do not overwrite ret here, we want to return
c3243e3212f91b69ef9990e2cb4c9339bf2f7888Jakub Hrozek * the original failure, not the failure of the
c3243e3212f91b69ef9990e2cb4c9339bf2f7888Jakub Hrozek * transaction cancellation.
c3243e3212f91b69ef9990e2cb4c9339bf2f7888Jakub Hrozek */
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozek }
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozek }
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozek talloc_zfree(*ctx);
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozek return ret;
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozek}
06424c5ac5ffb871476208155762bb5b73e0b665Jakub Hrozek
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozek/* serach all groups that have a memberUid attribute.
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozek * change it into a member attribute for a user of same domain.
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov * remove the memberUid attribute
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozek * add the new member attribute
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozek * finally stop indexing memberUid
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozek * upgrade version to 0.2
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozek */
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozekint sysdb_upgrade_01(struct ldb_context *ldb, const char **ver)
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozek{
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose struct ldb_message_element *el;
096a9678919fae460342469989b97fd47d812823Sumit Bose struct ldb_result *res;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose struct ldb_dn *basedn;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose struct ldb_dn *mem_dn;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose struct ldb_message *msg;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose const struct ldb_val *val;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose const char *filter = "(&(memberUid=*)(objectclass=group))";
096a9678919fae460342469989b97fd47d812823Sumit Bose const char *attrs[] = { "memberUid", NULL };
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose const char *mdn;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose char *domain;
096a9678919fae460342469989b97fd47d812823Sumit Bose int ret, i, j;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose TALLOC_CTX *tmp_ctx;
096a9678919fae460342469989b97fd47d812823Sumit Bose struct upgrade_ctx *ctx;
096a9678919fae460342469989b97fd47d812823Sumit Bose
096a9678919fae460342469989b97fd47d812823Sumit Bose tmp_ctx = talloc_new(NULL);
096a9678919fae460342469989b97fd47d812823Sumit Bose if (!tmp_ctx) {
096a9678919fae460342469989b97fd47d812823Sumit Bose return ENOMEM;
096a9678919fae460342469989b97fd47d812823Sumit Bose }
096a9678919fae460342469989b97fd47d812823Sumit Bose
096a9678919fae460342469989b97fd47d812823Sumit Bose ret = commence_upgrade(tmp_ctx, ldb, SYSDB_VERSION_0_2, &ctx);
096a9678919fae460342469989b97fd47d812823Sumit Bose if (ret) {
096a9678919fae460342469989b97fd47d812823Sumit Bose talloc_free(tmp_ctx);
096a9678919fae460342469989b97fd47d812823Sumit Bose return ret;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose basedn = ldb_dn_new(tmp_ctx, ldb, SYSDB_BASE);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov if (!basedn) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = EIO;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
096a9678919fae460342469989b97fd47d812823Sumit Bose ret = ldb_search(ldb, tmp_ctx, &res,
096a9678919fae460342469989b97fd47d812823Sumit Bose basedn, LDB_SCOPE_SUBTREE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov attrs, "%s", filter);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != LDB_SUCCESS) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = EIO;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose for (i = 0; i < res->count; i++) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov el = ldb_msg_find_element(res->msgs[i], "memberUid");
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (!el) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
096a9678919fae460342469989b97fd47d812823Sumit Bose "memberUid is missing from message [%s], skipping\n",
096a9678919fae460342469989b97fd47d812823Sumit Bose ldb_dn_get_linearized(res->msgs[i]->dn));
096a9678919fae460342469989b97fd47d812823Sumit Bose continue;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose /* create modification message */
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose msg = ldb_msg_new(tmp_ctx);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (!msg) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = ENOMEM;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
096a9678919fae460342469989b97fd47d812823Sumit Bose }
096a9678919fae460342469989b97fd47d812823Sumit Bose msg->dn = res->msgs[i]->dn;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = ldb_msg_add_empty(msg, "memberUid", LDB_FLAG_MOD_DELETE, NULL);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != LDB_SUCCESS) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = ENOMEM;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = ldb_msg_add_empty(msg, SYSDB_MEMBER, LDB_FLAG_MOD_ADD, NULL);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != LDB_SUCCESS) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = ENOMEM;
096a9678919fae460342469989b97fd47d812823Sumit Bose goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose /* get domain name component value */
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose val = ldb_dn_get_component_val(res->msgs[i]->dn, 2);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose domain = talloc_strndup(tmp_ctx, (const char *)val->data, val->length);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (!domain) {
096a9678919fae460342469989b97fd47d812823Sumit Bose ret = ENOMEM;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose for (j = 0; j < el->num_values; j++) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose mem_dn = ldb_dn_new_fmt(tmp_ctx, ldb, SYSDB_TMPL_USER,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose (const char *)el->values[j].data, domain);
096a9678919fae460342469989b97fd47d812823Sumit Bose if (!mem_dn) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = ENOMEM;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose mdn = talloc_strdup(msg, ldb_dn_get_linearized(mem_dn));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (!mdn) {
096a9678919fae460342469989b97fd47d812823Sumit Bose ret = ENOMEM;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = ldb_msg_add_string(msg, SYSDB_MEMBER, mdn);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != LDB_SUCCESS) {
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose ret = ENOMEM;
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose goto done;
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose }
096a9678919fae460342469989b97fd47d812823Sumit Bose
096a9678919fae460342469989b97fd47d812823Sumit Bose talloc_zfree(mem_dn);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov }
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose /* ok now we are ready to modify the entry */
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose ret = ldb_modify(ldb, msg);
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose if (ret != LDB_SUCCESS) {
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose ret = sysdb_error_to_errno(ret);
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose goto done;
096a9678919fae460342469989b97fd47d812823Sumit Bose }
096a9678919fae460342469989b97fd47d812823Sumit Bose
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose talloc_zfree(msg);
096a9678919fae460342469989b97fd47d812823Sumit Bose }
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose /* conversion done, update version number */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret = update_version(ctx);
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bosedone:
096a9678919fae460342469989b97fd47d812823Sumit Bose ret = finish_upgrade(ret, &ctx, ver);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov talloc_free(tmp_ctx);
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose return ret;
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose}
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose
096a9678919fae460342469989b97fd47d812823Sumit Boseint sysdb_check_upgrade_02(struct sss_domain_info *domains,
096a9678919fae460342469989b97fd47d812823Sumit Bose const char *db_path)
096a9678919fae460342469989b97fd47d812823Sumit Bose{
096a9678919fae460342469989b97fd47d812823Sumit Bose TALLOC_CTX *tmp_ctx = NULL;
096a9678919fae460342469989b97fd47d812823Sumit Bose struct ldb_context *ldb;
096a9678919fae460342469989b97fd47d812823Sumit Bose char *ldb_file;
096a9678919fae460342469989b97fd47d812823Sumit Bose struct sysdb_ctx *sysdb;
096a9678919fae460342469989b97fd47d812823Sumit Bose struct sss_domain_info *dom;
096a9678919fae460342469989b97fd47d812823Sumit Bose struct ldb_message_element *el;
096a9678919fae460342469989b97fd47d812823Sumit Bose struct ldb_message *msg;
096a9678919fae460342469989b97fd47d812823Sumit Bose struct ldb_result *res;
096a9678919fae460342469989b97fd47d812823Sumit Bose struct ldb_dn *verdn;
096a9678919fae460342469989b97fd47d812823Sumit Bose const char *version = NULL;
096a9678919fae460342469989b97fd47d812823Sumit Bose bool do_02_upgrade = false;
096a9678919fae460342469989b97fd47d812823Sumit Bose bool ctx_trans = false;
096a9678919fae460342469989b97fd47d812823Sumit Bose int ret;
096a9678919fae460342469989b97fd47d812823Sumit Bose
096a9678919fae460342469989b97fd47d812823Sumit Bose tmp_ctx = talloc_new(NULL);
096a9678919fae460342469989b97fd47d812823Sumit Bose if (!tmp_ctx) {
096a9678919fae460342469989b97fd47d812823Sumit Bose return ENOMEM;
096a9678919fae460342469989b97fd47d812823Sumit Bose }
096a9678919fae460342469989b97fd47d812823Sumit Bose
096a9678919fae460342469989b97fd47d812823Sumit Bose ret = sysdb_get_db_file(tmp_ctx,
096a9678919fae460342469989b97fd47d812823Sumit Bose "local", "UPGRADE",
096a9678919fae460342469989b97fd47d812823Sumit Bose db_path, &ldb_file);
096a9678919fae460342469989b97fd47d812823Sumit Bose if (ret != EOK) {
096a9678919fae460342469989b97fd47d812823Sumit Bose goto exit;
096a9678919fae460342469989b97fd47d812823Sumit Bose }
096a9678919fae460342469989b97fd47d812823Sumit Bose
096a9678919fae460342469989b97fd47d812823Sumit Bose ret = sysdb_ldb_connect(tmp_ctx, ldb_file, &ldb);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != EOK) {
096a9678919fae460342469989b97fd47d812823Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_ldb_connect failed.\n");
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose return ret;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose verdn = ldb_dn_new(tmp_ctx, ldb, SYSDB_BASE);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (!verdn) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = EIO;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto exit;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = ldb_search(ldb, tmp_ctx, &res,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose verdn, LDB_SCOPE_BASE,
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose NULL, NULL);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != LDB_SUCCESS) {
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek ret = EIO;
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek goto exit;
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek }
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek if (res->count > 1) {
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek ret = EIO;
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek goto exit;
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek }
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek if (res->count == 1) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov el = ldb_msg_find_element(res->msgs[0], "version");
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek if (el) {
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek if (el->num_values != 1) {
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek ret = EINVAL;
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek goto exit;
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek }
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek version = talloc_strndup(tmp_ctx,
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek (char *)(el->values[0].data),
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose el->values[0].length);
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose if (!version) {
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose ret = ENOMEM;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose goto exit;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose }
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose if (strcmp(version, SYSDB_VERSION) == 0) {
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose /* all fine, return */
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose ret = EOK;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose goto exit;
89ddc9ed474e9ac2b1e7bccb0a58610babf26cf8Jakub Hrozek }
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose
89ddc9ed474e9ac2b1e7bccb0a58610babf26cf8Jakub Hrozek DEBUG(SSSDBG_CONF_SETTINGS,
89ddc9ed474e9ac2b1e7bccb0a58610babf26cf8Jakub Hrozek "Upgrading DB from version: %s\n", version);
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose if (strcmp(version, SYSDB_VERSION_0_1) == 0) {
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose /* convert database */
89ddc9ed474e9ac2b1e7bccb0a58610babf26cf8Jakub Hrozek ret = sysdb_upgrade_01(ldb, &version);
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose if (ret != EOK) goto exit;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose }
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose if (strcmp(version, SYSDB_VERSION_0_2) == 0) {
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose /* need to convert database to split files */
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose do_02_upgrade = true;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose }
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose }
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose }
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose if (!do_02_upgrade) {
89ddc9ed474e9ac2b1e7bccb0a58610babf26cf8Jakub Hrozek /* not a v2 upgrade, return and let the normal code take over any
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose * further upgrade */
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose ret = EOK;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose goto exit;
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose }
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose /* == V2->V3 UPGRADE == */
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose DEBUG(SSSDBG_FATAL_FAILURE,
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose "UPGRADING DB TO VERSION %s\n", SYSDB_VERSION_0_3);
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek /* ldb uses posix locks,
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek * posix is stupid and kills all locks when you close *any* file
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek * descriptor associated to the same file.
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek * Therefore we must close and reopen the ldb file here */
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek /* == Backup and reopen ldb == */
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek /* close */
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek talloc_zfree(ldb);
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek /* backup*/
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek ret = backup_file(ldb_file, SSSDBG_FATAL_FAILURE);
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek if (ret != EOK) {
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek goto exit;
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek }
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek /* reopen */
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek ret = sysdb_ldb_connect(tmp_ctx, ldb_file, &ldb);
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose if (ret != EOK) {
9b7762729da24a901388ea53da29448f23e0f77bJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_ldb_connect failed.\n");
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose return ret;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce /* open a transaction */
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = ldb_transaction_start(ldb);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (ret != LDB_SUCCESS) {
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose "Failed to start ldb transaction! (%d)\n", ret);
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose ret = EIO;
9b7762729da24a901388ea53da29448f23e0f77bJakub Hrozek goto exit;
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek /* == Upgrade contents == */
5627532b81802c2654ced8edac07f420bd677930Jakub Hrozek
5627532b81802c2654ced8edac07f420bd677930Jakub Hrozek for (dom = domains; dom; dom = dom->next) {
5627532b81802c2654ced8edac07f420bd677930Jakub Hrozek struct ldb_dn *domain_dn;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce struct ldb_dn *users_dn;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce struct ldb_dn *groups_dn;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce int i;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce /* skip local */
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (strcasecmp(dom->provider, "local") == 0) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose continue;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce /* create new dom db */
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = sysdb_domain_init_internal(tmp_ctx, dom,
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce db_path, false, &sysdb);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret != EOK) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce goto done;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce }
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = ldb_transaction_start(sysdb->ldb);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (ret != LDB_SUCCESS) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce "Failed to start ldb transaction! (%d)\n", ret);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce ret = EIO;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov goto done;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce ctx_trans = true;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce
fdda4b659fa3be3027df91a2b053835186ec2c59Sumit Bose /* search all entries for this domain in local,
09d7c105839bfc7447ea0f766413ed86675ca075Sumit Bose * copy them all in the new database,
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose * then remove them from local */
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose domain_dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb,
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose SYSDB_DOM_BASE, dom->name);
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose if (!domain_dn) {
c5711b0279ea85d69fe3c77dfb194360c346e1d7Sumit Bose ret = ENOMEM;
9b7762729da24a901388ea53da29448f23e0f77bJakub Hrozek goto done;
9b7762729da24a901388ea53da29448f23e0f77bJakub Hrozek }
9b7762729da24a901388ea53da29448f23e0f77bJakub Hrozek
9b7762729da24a901388ea53da29448f23e0f77bJakub Hrozek ret = ldb_search(ldb, tmp_ctx, &res,
9b7762729da24a901388ea53da29448f23e0f77bJakub Hrozek domain_dn, LDB_SCOPE_SUBTREE,
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek NULL, NULL);
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek if (ret != LDB_SUCCESS) {
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek ret = EIO;
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek goto done;
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek }
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek users_dn = sysdb_user_base_dn(tmp_ctx, dom);
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek if (!users_dn) {
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek ret = ENOMEM;
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek goto done;
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek }
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek groups_dn = sysdb_group_base_dn(tmp_ctx, dom);
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek if (!groups_dn) {
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek ret = ENOMEM;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce goto done;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov }
0fcdef99980260d2da308c2c26861492ab983e3dJakub Hrozek
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce for (i = 0; i < res->count; i++) {
204cfc89a076fd32bf34f2abb3f809304aaa88abSimo Sorce
0fcdef99980260d2da308c2c26861492ab983e3dJakub Hrozek struct ldb_dn *orig_dn;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce msg = res->msgs[i];
0fcdef99980260d2da308c2c26861492ab983e3dJakub Hrozek
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce /* skip pre-created congtainers */
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if ((ldb_dn_compare(msg->dn, domain_dn) == 0) ||
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek (ldb_dn_compare(msg->dn, users_dn) == 0) ||
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek (ldb_dn_compare(msg->dn, groups_dn) == 0)) {
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek continue;
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek }
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek /* regenerate the DN against the new ldb as it may have different
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek * casefolding rules (example: name changing from case insensitive
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek * to case sensitive) */
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek orig_dn = msg->dn;
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek msg->dn = ldb_dn_new(msg, sysdb->ldb,
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek ldb_dn_get_linearized(orig_dn));
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek if (!msg->dn) {
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek ret = ENOMEM;
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek goto done;
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek }
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek ret = ldb_add(sysdb->ldb, msg);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (ret != LDB_SUCCESS) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce DEBUG(SSSDBG_FATAL_FAILURE, "WARNING: Could not add entry %s,"
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce " to new ldb file! (%d [%s])\n",
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce ldb_dn_get_linearized(msg->dn),
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek ret, ldb_errstring(sysdb->ldb));
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce }
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce ret = ldb_delete(ldb, orig_dn);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (ret != LDB_SUCCESS) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce DEBUG(SSSDBG_FATAL_FAILURE,
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek "WARNING: Could not remove entry %s,"
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce " from old ldb file! (%d [%s])\n",
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ldb_dn_get_linearized(orig_dn),
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce ret, ldb_errstring(ldb));
95e94691178297f2b8225a83d43ae388cab04b45Simo Sorce }
31dd31b00ad759f256282ef0f7054e60672161ceJakub Hrozek }
4f118e3e6a25762f40a43e6dbefb09f44adbef32Simo Sorce
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce /* now remove the basic containers from local */
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce /* these were optional so debug at level 9 in case
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce * of failure just for tracing */
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce ret = ldb_delete(ldb, groups_dn);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (ret != LDB_SUCCESS) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce DEBUG(SSSDBG_TRACE_ALL, "WARNING: Could not remove entry %s,"
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce " from old ldb file! (%d [%s])\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ldb_dn_get_linearized(groups_dn),
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret, ldb_errstring(ldb));
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = ldb_delete(ldb, users_dn);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (ret != LDB_SUCCESS) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce DEBUG(SSSDBG_TRACE_ALL, "WARNING: Could not remove entry %s,"
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose " from old ldb file! (%d [%s])\n",
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ldb_dn_get_linearized(users_dn),
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce ret, ldb_errstring(ldb));
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce }
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ret = ldb_delete(ldb, domain_dn);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (ret != LDB_SUCCESS) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce DEBUG(SSSDBG_TRACE_ALL, "WARNING: Could not remove entry %s,"
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce " from old ldb file! (%d [%s])\n",
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce ldb_dn_get_linearized(domain_dn),
418e6ccd116eced7ccc75aca999a4c37c67289baJakub Hrozek ret, ldb_errstring(ldb));
418e6ccd116eced7ccc75aca999a4c37c67289baJakub Hrozek }
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce ret = ldb_transaction_commit(sysdb->ldb);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (ret != LDB_SUCCESS) {
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek "Failed to commit ldb transaction! (%d)\n", ret);
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek ret = EIO;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce goto done;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce }
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce ctx_trans = false;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce talloc_zfree(domain_dn);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce talloc_zfree(groups_dn);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce talloc_zfree(users_dn);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce talloc_zfree(res);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce }
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce /* conversion done, upgrade version number */
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce msg = ldb_msg_new(tmp_ctx);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (!msg) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce ret = ENOMEM;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce goto done;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce }
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce msg->dn = ldb_dn_new(tmp_ctx, ldb, SYSDB_BASE);
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce if (!msg->dn) {
9b7762729da24a901388ea53da29448f23e0f77bJakub Hrozek ret = ENOMEM;
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek goto done;
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek }
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ldb_msg_add_empty(msg, "version", LDB_FLAG_MOD_REPLACE, NULL);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret != LDB_SUCCESS) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce }
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce ret = ldb_msg_add_string(msg, "version", SYSDB_VERSION_0_3);
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce if (ret != LDB_SUCCESS) {
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce ret = ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ldb_modify(ldb, msg);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret != LDB_SUCCESS) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = sysdb_error_to_errno(ret);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ldb_transaction_commit(ldb);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret != LDB_SUCCESS) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose DEBUG(SSSDBG_CRIT_FAILURE,
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose "Failed to commit ldb transaction! (%d)\n", ret);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = EIO;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto exit;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = EOK;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosedone:
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (ret != EOK) {
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek if (ctx_trans) {
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek ret = ldb_transaction_cancel(sysdb->ldb);
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek if (ret != LDB_SUCCESS) {
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek "Failed to cancel ldb transaction! (%d)\n", ret);
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = ldb_transaction_cancel(ldb);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != LDB_SUCCESS) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny DEBUG(SSSDBG_CRIT_FAILURE,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny "Failed to cancel ldb transaction! (%d)\n", ret);
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce }
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce }
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorceexit:
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce talloc_free(tmp_ctx);
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce return ret;
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek}
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorceint sysdb_upgrade_03(struct sysdb_ctx *sysdb, const char **ver)
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce{
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce TALLOC_CTX *tmp_ctx;
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce int ret;
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce struct ldb_message *msg;
5e60c73cb91d1659755fb5ea829837db68d46163Sumit Bose struct upgrade_ctx *ctx;
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce
5ea449b18d2597f2581627de80bcaf2bc70b0fd3Simo Sorce tmp_ctx = talloc_new(NULL);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (!tmp_ctx) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose return ENOMEM;
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_4, &ctx);
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce if (ret) {
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce return ret;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce /* Make this database case-sensitive */
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce msg = ldb_msg_new(tmp_ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (!msg) {
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce ret = ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@ATTRIBUTES");
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce if (!msg->dn) {
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce ret = ENOMEM;
20ccfd63a17dc15dd24e6543424d86913d511c4bSumit Bose goto done;
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce }
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce ret = ldb_msg_add_empty(msg, "name", LDB_FLAG_MOD_DELETE, NULL);
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce if (ret != LDB_SUCCESS) {
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce ret = ENOMEM;
dcb44c39dda9699cdd6488fd116a51ced0687de3Jakub Hrozek goto done;
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce }
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ldb_modify(sysdb->ldb, msg);
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce if (ret != LDB_SUCCESS) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = sysdb_error_to_errno(ret);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov /* conversion done, update version number */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret = update_version(ctx);
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosedone:
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = finish_upgrade(ret, &ctx, ver);
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce talloc_free(tmp_ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose return ret;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose}
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorceint sysdb_upgrade_04(struct sysdb_ctx *sysdb, const char **ver)
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce{
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce TALLOC_CTX *tmp_ctx;
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce int ret;
4c20fe34346919cf676c3e1b54b7701069e2aac6Simo Sorce struct ldb_message *msg;
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose struct upgrade_ctx *ctx;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose tmp_ctx = talloc_new(NULL);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (!tmp_ctx) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose return ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_5, &ctx);
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce if (ret) {
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce return ret;
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose /* Add new index */
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose msg = ldb_msg_new(tmp_ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (!msg) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ENOMEM;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov goto done;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@INDEXLIST");
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (!msg->dn) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret = ENOMEM;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret != LDB_SUCCESS) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ENOMEM;
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek goto done;
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek }
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek ret = ldb_msg_add_string(msg, "@IDXATTR", "originalDN");
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret != LDB_SUCCESS) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ldb_modify(sysdb->ldb, msg);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret != LDB_SUCCESS) {
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose ret = sysdb_error_to_errno(ret);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny /* Rebuild memberuid and memberoif attributes */
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny msg = ldb_msg_new(tmp_ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (!msg) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@MEMBEROF-REBUILD");
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (!msg->dn) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = ENOMEM;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = ldb_add(sysdb->ldb, msg);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret != LDB_SUCCESS) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = sysdb_error_to_errno(ret);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose /* conversion done, update version number */
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce ret = update_version(ctx);
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosedone:
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = finish_upgrade(ret, &ctx, ver);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose talloc_free(tmp_ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose return ret;
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce}
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Boseint sysdb_upgrade_05(struct sysdb_ctx *sysdb, const char **ver)
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose{
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose TALLOC_CTX *tmp_ctx;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose int ret;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct ldb_message *msg;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct upgrade_ctx *ctx;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov tmp_ctx = talloc_new(NULL);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (!tmp_ctx) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose return ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_6, &ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose return ret;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek /* Add new indexes */
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek msg = ldb_msg_new(tmp_ctx);
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek if (!msg) {
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek ret = ENOMEM;
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek goto done;
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek }
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@INDEXLIST");
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek if (!msg->dn) {
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek ret = ENOMEM;
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek goto done;
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek }
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek /* Add Index for dataExpireTimestamp */
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL);
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek if (ret != LDB_SUCCESS) {
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek ret = ENOMEM;
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek goto done;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose }
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = ldb_msg_add_string(msg, "@IDXATTR", "dataExpireTimestamp");
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose if (ret != LDB_SUCCESS) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = ENOMEM;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose goto done;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose }
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose /* Add index to speed up ONELEVEL searches */
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = ldb_msg_add_empty(msg, "@IDXONE", LDB_FLAG_MOD_ADD, NULL);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose if (ret != LDB_SUCCESS) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = ENOMEM;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose goto done;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose }
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = ldb_msg_add_string(msg, "@IDXONE", "1");
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose if (ret != LDB_SUCCESS) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = ENOMEM;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose goto done;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose }
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = ldb_modify(sysdb->ldb, msg);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose if (ret != LDB_SUCCESS) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = sysdb_error_to_errno(ret);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose goto done;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose }
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose /* conversion done, update version number */
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = update_version(ctx);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bosedone:
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = finish_upgrade(ret, &ctx, ver);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose talloc_free(tmp_ctx);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose return ret;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose}
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Boseint sysdb_upgrade_06(struct sysdb_ctx *sysdb, const char **ver)
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose{
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose TALLOC_CTX *tmp_ctx;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose int ret;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose struct ldb_message *msg;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose struct upgrade_ctx *ctx;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose tmp_ctx = talloc_new(NULL);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose if (!tmp_ctx) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose return ENOMEM;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose }
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_7, &ctx);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose if (ret) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose return ret;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose }
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose /* Add new indexes */
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose msg = ldb_msg_new(tmp_ctx);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose if (!msg) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = ENOMEM;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose goto done;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose }
a50b229c8ea1e22c9efa677760b94d8c48c3ec89Sumit Bose msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@ATTRIBUTES");
a50b229c8ea1e22c9efa677760b94d8c48c3ec89Sumit Bose if (!msg->dn) {
a50b229c8ea1e22c9efa677760b94d8c48c3ec89Sumit Bose ret = ENOMEM;
a50b229c8ea1e22c9efa677760b94d8c48c3ec89Sumit Bose goto done;
a50b229c8ea1e22c9efa677760b94d8c48c3ec89Sumit Bose }
a50b229c8ea1e22c9efa677760b94d8c48c3ec89Sumit Bose
a50b229c8ea1e22c9efa677760b94d8c48c3ec89Sumit Bose /* Case insensitive search for originalDN */
a50b229c8ea1e22c9efa677760b94d8c48c3ec89Sumit Bose ret = ldb_msg_add_empty(msg, SYSDB_ORIG_DN, LDB_FLAG_MOD_ADD, NULL);
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose if (ret != LDB_SUCCESS) {
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose ret = ENOMEM;
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose goto done;
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose }
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose ret = ldb_msg_add_string(msg, SYSDB_ORIG_DN, "CASE_INSENSITIVE");
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose if (ret != LDB_SUCCESS) {
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose ret = ENOMEM;
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose goto done;
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose }
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose ret = ldb_modify(sysdb->ldb, msg);
44329653f423c632b027065a9c0ea0bf4199396aSumit Bose if (ret != LDB_SUCCESS) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = sysdb_error_to_errno(ret);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose goto done;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose }
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose /* conversion done, update version number */
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = update_version(ctx);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bosedone:
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = finish_upgrade(ret, &ctx, ver);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose talloc_free(tmp_ctx);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose return ret;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose}
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Boseint sysdb_upgrade_07(struct sysdb_ctx *sysdb, const char **ver)
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose{
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose TALLOC_CTX *tmp_ctx;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose int ret;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose struct ldb_message *msg;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose struct upgrade_ctx *ctx;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose tmp_ctx = talloc_new(NULL);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose if (!tmp_ctx) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose return ENOMEM;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose }
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_8, &ctx);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose if (ret) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose return ret;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose }
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose /* Add new indexes */
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose msg = ldb_msg_new(tmp_ctx);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose if (!msg) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = ENOMEM;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose goto done;
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose }
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@INDEXLIST");
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose if (!msg->dn) {
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose ret = ENOMEM;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose goto done;
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose }
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose /* Add Index for nameAlias */
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL);
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose if (ret != LDB_SUCCESS) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = ENOMEM;
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose goto done;
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose }
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose ret = ldb_msg_add_string(msg, "@IDXATTR", "nameAlias");
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose if (ret != LDB_SUCCESS) {
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose ret = ENOMEM;
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose goto done;
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose }
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose ret = ldb_modify(sysdb->ldb, msg);
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose if (ret != LDB_SUCCESS) {
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose ret = sysdb_error_to_errno(ret);
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose goto done;
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose }
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose /* conversion done, update version number */
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose ret = update_version(ctx);
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bosedone:
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose ret = finish_upgrade(ret, &ctx, ver);
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose talloc_free(tmp_ctx);
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose return ret;
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose}
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Boseint sysdb_upgrade_08(struct sysdb_ctx *sysdb, const char **ver)
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose{
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose TALLOC_CTX *tmp_ctx;
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose int ret;
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose struct ldb_message *msg;
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose struct upgrade_ctx *ctx;
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose tmp_ctx = talloc_new(NULL);
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose if (!tmp_ctx) {
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose return ENOMEM;
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose }
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_9, &ctx);
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose if (ret) {
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose return ret;
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose }
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose /* Add new indexes */
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose msg = ldb_msg_new(tmp_ctx);
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose if (!msg) {
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose ret = ENOMEM;
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose goto done;
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose }
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@INDEXLIST");
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose if (!msg->dn) {
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose ret = ENOMEM;
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose goto done;
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose }
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose /* Add Index for servicePort and serviceProtocol */
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL);
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose if (ret != LDB_SUCCESS) {
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose ret = ENOMEM;
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose goto done;
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose }
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose ret = ldb_msg_add_string(msg, "@IDXATTR", "servicePort");
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose if (ret != LDB_SUCCESS) {
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose ret = ENOMEM;
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose goto done;
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose }
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose ret = ldb_msg_add_string(msg, "@IDXATTR", "serviceProtocol");
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose if (ret != LDB_SUCCESS) {
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose ret = ENOMEM;
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose goto done;
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose }
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose ret = ldb_modify(sysdb->ldb, msg);
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose if (ret != LDB_SUCCESS) {
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose ret = sysdb_error_to_errno(ret);
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose goto done;
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose }
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose /* conversion done, update version number */
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose ret = update_version(ctx);
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bosedone:
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose ret = finish_upgrade(ret, &ctx, ver);
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose talloc_free(tmp_ctx);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose return ret;
61d2ccf1dae3f1e7fc987ae98cb5c493cc73a782Sumit Bose}
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Boseint sysdb_upgrade_09(struct sysdb_ctx *sysdb, const char **ver)
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose{
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose TALLOC_CTX *tmp_ctx;
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose int ret;
61d2ccf1dae3f1e7fc987ae98cb5c493cc73a782Sumit Bose struct ldb_message *msg;
61d2ccf1dae3f1e7fc987ae98cb5c493cc73a782Sumit Bose struct upgrade_ctx *ctx;
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose
2bf1cbffaac3b4bc0bd736493c985ca865092805Sumit Bose tmp_ctx = talloc_new(NULL);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose if (!tmp_ctx) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose return ENOMEM;
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek }
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_10, &ctx);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose if (ret) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose return ret;
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose }
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose /* Add new indexes */
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose msg = ldb_msg_new(tmp_ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (!msg) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@INDEXLIST");
1e6f2180724de4722a5218826c9401181168d9d4Simo Sorce if (!msg->dn) {
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce ret = ENOMEM;
ce29aa8998332fd3c2e4e4b81e7302d41c461893Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce
ccc2af010bbbe6d8a7496fb717216135bc4c1993Simo Sorce /* Add Index for servicePort and serviceProtocol */
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret != LDB_SUCCESS) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ldb_msg_add_string(msg, "@IDXATTR", "sudoUser");
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret != LDB_SUCCESS) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ENOMEM;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ldb_modify(sysdb->ldb, msg);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose if (ret != LDB_SUCCESS) {
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = sysdb_error_to_errno(ret);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose goto done;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose /* conversion done, update version number */
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = update_version(ctx);
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek
81165faf5d951aca69f410713730c26ff048ec44Sumit Bosedone:
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = finish_upgrade(ret, &ctx, ver);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose talloc_free(tmp_ctx);
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose return ret;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose}
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorceint sysdb_upgrade_10(struct sysdb_ctx *sysdb, struct sss_domain_info *domain,
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce const char **ver)
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose{
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose TALLOC_CTX *tmp_ctx;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose int ret;
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose struct ldb_result *res;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce struct ldb_message *msg;
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozek struct ldb_message *user;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce struct ldb_message_element *memberof_el;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov const char *name;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce struct ldb_dn *basedn;
efea50efda58be66638e5d38c8e57fdf9992f204Simo Sorce const char *filter = "(&(objectClass=user)(!(uidNumber=*))(memberOf=*))";
b17b51c2779906bf3a5e4aecbb9ef8bfbfc2ebabJakub Hrozek const char *attrs[] = { "name", "memberof", NULL };
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek struct upgrade_ctx *ctx;
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek int i, j;
b17b51c2779906bf3a5e4aecbb9ef8bfbfc2ebabJakub Hrozek
b17b51c2779906bf3a5e4aecbb9ef8bfbfc2ebabJakub Hrozek tmp_ctx = talloc_new(NULL);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov if (tmp_ctx == NULL) {
b17b51c2779906bf3a5e4aecbb9ef8bfbfc2ebabJakub Hrozek return ENOMEM;
b17b51c2779906bf3a5e4aecbb9ef8bfbfc2ebabJakub Hrozek }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_11, &ctx);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose if (ret) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose return ret;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose }
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose basedn = sysdb_user_base_dn(tmp_ctx, domain);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose if (basedn == NULL) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = EIO;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose goto done;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose }
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = ldb_search(sysdb->ldb, tmp_ctx, &res, basedn, LDB_SCOPE_SUBTREE,
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose attrs, "%s", filter);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose if (ret != LDB_SUCCESS) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = EIO;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose goto done;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose }
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose for (i = 0; i < res->count; i++) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose user = res->msgs[i];
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose memberof_el = ldb_msg_find_element(user, "memberof");
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose name = ldb_msg_find_attr_as_string(user, "name", NULL);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose if (name == NULL) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = EIO;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose goto done;
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek }
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose DEBUG(SSSDBG_TRACE_LIBS, "User [%s] is a member of %d groups\n",
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose name, memberof_el->num_values);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose for (j = 0; j < memberof_el->num_values; j++) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose msg = ldb_msg_new(tmp_ctx);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose if (msg == NULL) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = ENOMEM;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose goto done;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose }
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose msg->dn = ldb_dn_from_ldb_val(tmp_ctx, sysdb->ldb, &memberof_el->values[j]);
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose if (msg->dn == NULL) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = ENOMEM;
20ccfd63a17dc15dd24e6543424d86913d511c4bSumit Bose goto done;
20ccfd63a17dc15dd24e6543424d86913d511c4bSumit Bose }
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (!ldb_dn_validate(msg->dn)) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_MINOR_FAILURE, "DN validation failed during "
20ccfd63a17dc15dd24e6543424d86913d511c4bSumit Bose "upgrade: [%s]\n",
20ccfd63a17dc15dd24e6543424d86913d511c4bSumit Bose memberof_el->values[j].data);
20ccfd63a17dc15dd24e6543424d86913d511c4bSumit Bose talloc_zfree(msg);
20ccfd63a17dc15dd24e6543424d86913d511c4bSumit Bose continue;
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek }
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek ret = ldb_msg_add_empty(msg, "ghost", LDB_FLAG_MOD_ADD, NULL);
20ccfd63a17dc15dd24e6543424d86913d511c4bSumit Bose if (ret != LDB_SUCCESS) {
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose ret = ENOMEM;
20ccfd63a17dc15dd24e6543424d86913d511c4bSumit Bose goto done;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose }
20ccfd63a17dc15dd24e6543424d86913d511c4bSumit Bose ret = ldb_msg_add_string(msg, "ghost", name);
20ccfd63a17dc15dd24e6543424d86913d511c4bSumit Bose if (ret != LDB_SUCCESS) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = ENOMEM;
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose DEBUG(SSSDBG_TRACE_FUNC, "Adding ghost [%s] to entry [%s]\n",
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose name, ldb_dn_get_linearized(msg->dn));
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = sss_ldb_modify_permissive(sysdb->ldb, msg);
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce talloc_zfree(msg);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret == LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose /* If we failed adding the ghost user(s) because the values already
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce * exist, they were probably propagated from a parent that was
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose * upgraded before us. Mark the group as expired so that it is
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose * refreshed on next request.
0754ff886f909f0404038eb9c99dd61be1acf5b9Simo Sorce */
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose msg = ldb_msg_new(tmp_ctx);
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce if (msg == NULL) {
ccc2af010bbbe6d8a7496fb717216135bc4c1993Simo Sorce ret = ENOMEM;
ccc2af010bbbe6d8a7496fb717216135bc4c1993Simo Sorce goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose msg->dn = ldb_dn_from_ldb_val(tmp_ctx, sysdb->ldb, &memberof_el->values[j]);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (msg->dn == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret = ENOMEM;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
096a9678919fae460342469989b97fd47d812823Sumit Bose ret = ldb_msg_add_empty(msg, SYSDB_CACHE_EXPIRE,
096a9678919fae460342469989b97fd47d812823Sumit Bose LDB_FLAG_MOD_REPLACE, NULL);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != LDB_SUCCESS) {
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce goto done;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose ret = ldb_msg_add_string(msg, SYSDB_CACHE_EXPIRE, "1");
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != LDB_SUCCESS) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose }
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret = sss_ldb_modify_permissive(sysdb->ldb, msg);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose talloc_zfree(msg);
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose if (ret != LDB_SUCCESS) {
386a66b1aa18a176e6a06fa126556c9590c373b6Sumit Bose goto done;
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek }
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek } else if (ret != LDB_SUCCESS) {
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek ret = sysdb_error_to_errno(ret);
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek goto done;
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek }
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek }
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "Removing fake user [%s]\n",
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek ldb_dn_get_linearized(user->dn));
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek ret = ldb_delete(sysdb->ldb, user->dn);
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek if (ret != LDB_SUCCESS) {
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek ret = sysdb_error_to_errno(ret);
20ccfd63a17dc15dd24e6543424d86913d511c4bSumit Bose goto done;
20ccfd63a17dc15dd24e6543424d86913d511c4bSumit Bose }
20ccfd63a17dc15dd24e6543424d86913d511c4bSumit Bose }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny /* conversion done, update version number */
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = update_version(ctx);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
20ccfd63a17dc15dd24e6543424d86913d511c4bSumit Bosedone:
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = finish_upgrade(ret, &ctx, ver);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny talloc_free(tmp_ctx);
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce return ret;
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce}
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Boseint sysdb_upgrade_11(struct sysdb_ctx *sysdb, struct sss_domain_info *domain,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny const char **ver)
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny{
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny TALLOC_CTX *tmp_ctx;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny errno_t ret;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny struct ldb_result *res;
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce struct ldb_message *entry;
f99534c058e9367d2610de89b1af4dcc1ec63035Sumit Bose const char *key;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny const char *value;
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce struct ldb_message_element *memberof_el;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny struct ldb_dn *memberof_dn;
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce struct ldb_dn *basedn;
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce const struct ldb_val *val;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny const char *attrs[] = { SYSDB_AUTOFS_ENTRY_KEY,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny SYSDB_AUTOFS_ENTRY_VALUE,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny SYSDB_MEMBEROF,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov NULL };
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny struct upgrade_ctx *ctx;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny size_t i, j;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny tmp_ctx = talloc_new(NULL);
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce if (!tmp_ctx) {
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce return ENOMEM;
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_12, &ctx);
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce if (ret) {
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce return ret;
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce basedn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_TMPL_CUSTOM_SUBTREE,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny AUTOFS_ENTRY_SUBDIR, domain->name);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (basedn == NULL) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = ENOMEM;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny goto done;
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek }
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek ret = ldb_search(sysdb->ldb, tmp_ctx, &res, basedn, LDB_SCOPE_SUBTREE,
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek attrs, "(objectClass=%s)", SYSDB_AUTOFS_ENTRY_OC);
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek if (ret != LDB_SUCCESS) {
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek ret = EIO;
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek goto done;
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek }
3912262270a6449ebe1d3e92c27c217b4044f894Simo Sorce
9af86b9c936d07cff9d0c2054acde908749ea522Jakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "Found %d autofs entries\n", res->count);
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek for (i = 0; i < res->count; i++) {
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek entry = res->msgs[i];
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek key = ldb_msg_find_attr_as_string(entry,
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek SYSDB_AUTOFS_ENTRY_KEY, NULL);
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek value = ldb_msg_find_attr_as_string(entry,
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek SYSDB_AUTOFS_ENTRY_VALUE, NULL);
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek memberof_el = ldb_msg_find_element(entry, SYSDB_MEMBEROF);
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek if (key && value && memberof_el) {
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek for (j = 0; j < memberof_el->num_values; j++) {
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek memberof_dn = ldb_dn_from_ldb_val(tmp_ctx, sysdb->ldb,
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek &(memberof_el->values[j]));
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek if (!memberof_dn) {
5a5f1e1053415efaa99bb4d5bc7ce7ac0a95b757Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE, "Cannot convert memberof into DN, skipping\n");
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny continue;
ad9ca94d0c793c2e30e77f4cc385bf10e42e382fJakub Hrozek }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny val = ldb_dn_get_rdn_val(memberof_dn);
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny if (!val) {
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny DEBUG(SSSDBG_OP_FAILURE, "Cannot get map name from map DN\n");
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny continue;
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny ret = sysdb_save_autofsentry(domain,
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny (const char *) val->data,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov key, value, NULL);
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose if (ret != EOK) {
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose DEBUG(SSSDBG_OP_FAILURE,
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose "Cannot save autofs entry [%s]-[%s] into map %s\n",
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose key, value, val->data);
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose continue;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny }
84c611c1b7c04cc7735ab54d4e5f48284b79e6fbJan Zeleny
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose }
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce /* Delete the old entry if it was either processed or incomplete */
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce DEBUG(SSSDBG_TRACE_LIBS, "Deleting [%s]\n",
21f19d573047e70ee8ec0119ec00c1ed1af9ec04Simo Sorce ldb_dn_get_linearized(entry->dn));
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose
81165faf5d951aca69f410713730c26ff048ec44Sumit Bose ret = ldb_delete(sysdb->ldb, entry->dn);
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce if (ret != EOK) {
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce DEBUG(SSSDBG_OP_FAILURE, "Cannot delete old autofs entry %s\n",
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce ldb_dn_get_linearized(entry->dn));
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce continue;
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce }
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce }
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce /* conversion done, update version number */
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce ret = update_version(ctx);
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorcedone:
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce ret = finish_upgrade(ret, &ctx, ver);
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce talloc_free(tmp_ctx);
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce return ret;
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce}
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorceint sysdb_upgrade_12(struct sysdb_ctx *sysdb, const char **ver)
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce{
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose TALLOC_CTX *tmp_ctx;
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose int ret;
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose struct ldb_message *msg;
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose struct upgrade_ctx *ctx;
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose tmp_ctx = talloc_new(NULL);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov if (!tmp_ctx) {
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose return ENOMEM;
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose }
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_13, &ctx);
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose if (ret) {
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose return ret;
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose }
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce /* add new indexes */
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce msg = ldb_msg_new(tmp_ctx);
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce if (!msg) {
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce ret = ENOMEM;
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce goto done;
cd4cc8d8829f1ea5257bf874b91980368114275fPavel Březina }
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@INDEXLIST");
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce if (!msg->dn) {
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce ret = ENOMEM;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov goto done;
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce }
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce /* add index for sshKnownHostsExpire */
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL);
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce if (ret != LDB_SUCCESS) {
cd4cc8d8829f1ea5257bf874b91980368114275fPavel Březina ret = ENOMEM;
cd4cc8d8829f1ea5257bf874b91980368114275fPavel Březina goto done;
99151f2217ddaa179543b89b49f836f29f7dcd2aSimo Sorce }
99151f2217ddaa179543b89b49f836f29f7dcd2aSimo Sorce
44af0057c1fd52f6252f82ca73a06acfcac6c5e3Michal Zidek ret = ldb_msg_add_string(msg, "@IDXATTR", "sshKnownHostsExpire");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov if (ret != LDB_SUCCESS) {
44af0057c1fd52f6252f82ca73a06acfcac6c5e3Michal Zidek ret = ENOMEM;
44af0057c1fd52f6252f82ca73a06acfcac6c5e3Michal Zidek goto done;
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce }
d6d8287a9b8a240e068a26769dc6ce4582604850Simo Sorce
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce ret = ldb_modify(sysdb->ldb, msg);
cd4cc8d8829f1ea5257bf874b91980368114275fPavel Březina if (ret != LDB_SUCCESS) {
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce ret = sysdb_error_to_errno(ret);
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce goto done;
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce }
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce /* conversion done, update version number */
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce ret = update_version(ctx);
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorcedone:
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce ret = finish_upgrade(ret, &ctx, ver);
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce talloc_free(tmp_ctx);
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce return ret;
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce}
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorceint sysdb_upgrade_13(struct sysdb_ctx *sysdb, const char **ver)
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce{
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce struct upgrade_ctx *ctx;
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce struct ldb_result *dom_res;
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce struct ldb_result *res;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose struct ldb_dn *basedn;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose const char *attrs[] = { "cn", "name", NULL };
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose const char *tmp_str;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose errno_t ret;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose int i, j, l, n;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_14, &ctx);
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose if (ret) {
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose return ret;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov }
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose basedn = ldb_dn_new(ctx, sysdb->ldb, SYSDB_BASE);
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose if (!basedn) {
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "Failed to build base dn\n");
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose ret = EIO;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose goto done;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose }
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose ret = ldb_search(sysdb->ldb, ctx, &dom_res,
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose basedn, LDB_SCOPE_ONELEVEL,
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose attrs, "objectclass=%s", SYSDB_SUBDOMAIN_CLASS);
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose if (ret != LDB_SUCCESS) {
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose DEBUG(SSSDBG_OP_FAILURE, "Failed to search subdomains\n");
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose ret = EIO;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose goto done;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose }
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov for (i = 0; i < dom_res->count; i++) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose tmp_str = ldb_msg_find_attr_as_string(dom_res->msgs[i], "cn", NULL);
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose if (tmp_str == NULL) {
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose DEBUG(SSSDBG_MINOR_FAILURE,
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose "The object [%s] doesn't have a name\n",
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose ldb_dn_get_linearized(dom_res->msgs[i]->dn));
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose continue;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose }
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose basedn = ldb_dn_new_fmt(ctx, sysdb->ldb, SYSDB_DOM_BASE, tmp_str);
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce if (!basedn) {
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce DEBUG(SSSDBG_OP_FAILURE,
03abdaa21ecf562b714f204ca42379ff08626f75Simo Sorce "Failed to build base dn for subdomain %s\n", tmp_str);
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce continue;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose }
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce
03abdaa21ecf562b714f204ca42379ff08626f75Simo Sorce ret = ldb_search(sysdb->ldb, ctx, &res,
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce basedn, LDB_SCOPE_SUBTREE, attrs, NULL);
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce if (ret != LDB_SUCCESS) {
8e5549e453558d4bebdec333a93e215d5d6ffaecSimo Sorce DEBUG(SSSDBG_OP_FAILURE,
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce "Failed to search subdomain %s\n", tmp_str);
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce talloc_free(basedn);
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce continue;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose }
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose l = ldb_dn_get_comp_num(basedn);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov for (j = 0; j < res->count; j++) {
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose n = ldb_dn_get_comp_num(res->msgs[j]->dn);
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose if (n <= l + 1) {
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose /* Do not remove subdomain containers, only their contents */
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose continue;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose }
cd5033e86bb4065d75188e2b6ef287a4421344c8Sumit Bose ret = ldb_delete(sysdb->ldb, res->msgs[j]->dn);
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce if (ret) {
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce DEBUG(SSSDBG_OP_FAILURE,
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce "Failed to delete %s\n",
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce ldb_dn_get_linearized(res->msgs[j]->dn));
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce continue;
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce }
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce }
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce talloc_free(basedn);
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce talloc_free(res);
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce }
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce talloc_free(dom_res);
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce /* conversion done, update version number */
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce ret = update_version(ctx);
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorcedone:
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose ret = finish_upgrade(ret, &ctx, ver);
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose return ret;
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose}
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashovint sysdb_upgrade_14(struct sysdb_ctx *sysdb, const char **ver)
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose{
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose struct upgrade_ctx *ctx;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce struct ldb_message *msg;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce struct ldb_result *res;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce struct ldb_dn *basedn;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov struct ldb_dn *newdn;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce const char *attrs[] = { SYSDB_NAME, NULL };
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce const char *tmp_str;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce errno_t ret;
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce int i;
418e6ccd116eced7ccc75aca999a4c37c67289baJakub Hrozek
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_15, &ctx);
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce if (ret) {
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce return ret;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce }
08ab0d4ede41a1749e0bc26f78a37a4d10c20db8Sumit Bose
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose basedn = ldb_dn_new(ctx, sysdb->ldb, SYSDB_BASE);
5063dcc5ab685dce325b13b9c1e93cee2a673e60Sumit Bose if (!basedn) {
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce DEBUG(SSSDBG_OP_FAILURE, "Failed to build base dn\n");
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce ret = EIO;
87ed72b47859e673b636c85f35b85f1546c7ed3dSimo Sorce goto done;
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose }
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose /* create base ranges container */
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose msg = ldb_msg_new(ctx);
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose if (!msg) {
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik ret = ENOMEM;
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose goto done;
fab48878db202d620f43c9da23e375866d1db2c6Sumit Bose }
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce msg->dn = ldb_dn_new(msg, sysdb->ldb, SYSDB_TMPL_RANGE_BASE);
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce if (!msg->dn) {
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik ret = ENOMEM;
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce goto done;
6a81cb8c3424dbe9f764af3738299cbbe5874a15Simo Sorce }
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce ret = ldb_msg_add_string(msg, "cn", "ranges");
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce if (ret != LDB_SUCCESS) {
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik ret = EIO;
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce goto done;
3b533d57a737e2de1b3e85b073b14d3bfb49dafcSimo Sorce }
d2a8b08561e6700bdd4feb988becae4e8f5368ddJakub Hrozek /* do a synchronous add */
2b4b6b829f197493b4901bec96fefaadbc7a2464Jakub Hrozek ret = ldb_add(sysdb->ldb, msg);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov if (ret != LDB_SUCCESS) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE,
2b4b6b829f197493b4901bec96fefaadbc7a2464Jakub Hrozek "Failed to upgrade DB (%d, [%s])!\n",
2b4b6b829f197493b4901bec96fefaadbc7a2464Jakub Hrozek ret, ldb_errstring(sysdb->ldb));
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek ret = EIO;
b17b51c2779906bf3a5e4aecbb9ef8bfbfc2ebabJakub Hrozek goto done;
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek }
b17b51c2779906bf3a5e4aecbb9ef8bfbfc2ebabJakub Hrozek talloc_zfree(msg);
b17b51c2779906bf3a5e4aecbb9ef8bfbfc2ebabJakub Hrozek
b17b51c2779906bf3a5e4aecbb9ef8bfbfc2ebabJakub Hrozek ret = ldb_search(sysdb->ldb, ctx, &res,
f8a4a5f6240156809e1b5ef03816f673281e3fa0Jakub Hrozek basedn, LDB_SCOPE_SUBTREE, attrs,
f8a4a5f6240156809e1b5ef03816f673281e3fa0Jakub Hrozek "objectclass=%s", SYSDB_ID_RANGE_CLASS);
if (ret != LDB_SUCCESS) {
DEBUG(SSSDBG_OP_FAILURE, "Failed to search range objects\n");
ret = EIO;
goto done;
}
/* Failure to convert any range is not fatal. As long as there are no
* left-over objects we can fail to move them around, as they will be
* recreated on the next online access */
for (i = 0; i < res->count; i++) {
tmp_str = ldb_msg_find_attr_as_string(res->msgs[i], SYSDB_NAME, NULL);
if (tmp_str == NULL) {
DEBUG(SSSDBG_OP_FAILURE,
"The object [%s] doesn't have a name\n",
ldb_dn_get_linearized(res->msgs[i]->dn));
ret = ldb_delete(sysdb->ldb, res->msgs[i]->dn);
if (ret) {
DEBUG(SSSDBG_OP_FAILURE,
"Failed to delete %s\n",
ldb_dn_get_linearized(res->msgs[i]->dn));
ret = EIO;
goto done;
}
continue;
}
newdn = ldb_dn_new_fmt(ctx, sysdb->ldb, SYSDB_TMPL_RANGE, tmp_str);
if (!newdn) {
DEBUG(SSSDBG_CRIT_FAILURE,
"Failed to create new DN to move [%s]\n",
ldb_dn_get_linearized(res->msgs[i]->dn));
ret = ENOMEM;
goto done;
}
ret = ldb_rename(sysdb->ldb, res->msgs[i]->dn, newdn);
if (ret != LDB_SUCCESS) {
DEBUG(SSSDBG_CRIT_FAILURE,
"Failed to move [%s] to [%s]\n",
ldb_dn_get_linearized(res->msgs[i]->dn),
ldb_dn_get_linearized(newdn));
ret = ldb_delete(sysdb->ldb, res->msgs[i]->dn);
if (ret) {
DEBUG(SSSDBG_OP_FAILURE,
"Failed to delete %s\n",
ldb_dn_get_linearized(res->msgs[i]->dn));
ret = EIO;
goto done;
}
}
talloc_zfree(newdn);
}
/* conversion done, update version number */
ret = update_version(ctx);
done:
ret = finish_upgrade(ret, &ctx, ver);
return ret;
}
int sysdb_upgrade_15(struct sysdb_ctx *sysdb, const char **ver)
{
TALLOC_CTX *tmp_ctx;
int ret;
struct ldb_message *msg;
struct upgrade_ctx *ctx;
tmp_ctx = talloc_new(NULL);
if (!tmp_ctx) {
return ENOMEM;
}
ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_16, &ctx);
if (ret) {
return ret;
}
/* Add new indexes */
msg = ldb_msg_new(tmp_ctx);
if (!msg) {
ret = ENOMEM;
goto done;
}
msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@ATTRIBUTES");
if (!msg->dn) {
ret = ENOMEM;
goto done;
}
/* Case insensitive search for canonicalUserPrincipalName */
ret = ldb_msg_add_empty(msg, SYSDB_CANONICAL_UPN, LDB_FLAG_MOD_ADD, NULL);
if (ret != LDB_SUCCESS) {
ret = ENOMEM;
goto done;
}
ret = ldb_msg_add_string(msg, SYSDB_CANONICAL_UPN, "CASE_INSENSITIVE");
if (ret != LDB_SUCCESS) {
ret = ENOMEM;
goto done;
}
ret = ldb_modify(sysdb->ldb, msg);
if (ret != LDB_SUCCESS) {
ret = sysdb_error_to_errno(ret);
goto done;
}
/* conversion done, update version number */
ret = update_version(ctx);
done:
ret = finish_upgrade(ret, &ctx, ver);
talloc_free(tmp_ctx);
return ret;
}
/*
* Example template for future upgrades.
* Copy and change version numbers as appropriate.
*/
#if 0
int sysdb_upgrade_13(struct sysdb_ctx *sysdb, const char **ver)
{
struct upgrade_ctx *ctx;
errno_t ret;
ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_14, &ctx);
if (ret) {
return ret;
}
/* DO STUFF HERE (use ctx, as the local temporary memory context) */
/* conversion done, update version number */
ret = update_version(ctx);
done:
ret = finish_upgrade(ret, &ctx, ver);
return ret;
}
#endif