sysdb_upgrade.c revision e7d1cd14ce1a427007b1a7e9789dcb7e9619f84f
842ae4bd224140319ae7feec1872b93dfd491143fielding Simo Sorce <ssorce@redhat.com>
842ae4bd224140319ae7feec1872b93dfd491143fielding Stephen Gallagher <sgallagh@redhat.com>
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd Copyright (C) 2008-2011 Simo Sorce <ssorce@redhat.com>
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding Copyright (C) 2008-2011 Stephen Gallagher
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd This program is free software; you can redistribute it and/or modify
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd it under the terms of the GNU General Public License as published by
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd the Free Software Foundation; either version 3 of the License, or
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd (at your option) any later version.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding This program is distributed in the hope that it will be useful,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding but WITHOUT ANY WARRANTY; without even the implied warranty of
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e8f95a682820a599fe41b22977010636be5c2717jim GNU General Public License for more details.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding You should have received a copy of the GNU General Public License
e8f95a682820a599fe41b22977010636be5c2717jim along with this program. If not, see <http://www.gnu.org/licenses/>.
2d71630471d1c23f0137309e3c3957c633ecbfd6rbb const char *new_version;
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic errno_t commence_upgrade(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding DEBUG(SSSDBG_CRIT_FAILURE, ("UPGRADING DB TO VERSION %s\n", new_ver));
291eb44b3adaf8247425286615b4f4b69fbea274minfrinstatic errno_t update_version(struct upgrade_ctx *ctx)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = ldb_msg_add_empty(msg, "version", LDB_FLAG_MOD_REPLACE, NULL);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ret = ldb_msg_add_string(msg, "version", ctx->new_version);
291eb44b3adaf8247425286615b4f4b69fbea274minfrinstatic int finish_upgrade(int ret, struct upgrade_ctx **ctx, const char **ver)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ("Could not cancel transaction! [%s]\n",
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein /* Do not overwrite ret here, we want to return
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein * the original failure, not the failure of the
066877f1a045103acfdd376d48cdd473c33f409bdougm * transaction cancellation.
291eb44b3adaf8247425286615b4f4b69fbea274minfrin/* serach all groups that have a memberUid attribute.
291eb44b3adaf8247425286615b4f4b69fbea274minfrin * change it into a member attribute for a user of same domain.
291eb44b3adaf8247425286615b4f4b69fbea274minfrin * remove the memberUid attribute
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * add the new member attribute
36d38d22e0d385db01f5773a579f44b8f02e4b1fsf * finally stop indexing memberUid
076ae4ad21f0b3f25e2feabd9886b9500929eb2ejerenkrantz * upgrade version to 0.2
36d38d22e0d385db01f5773a579f44b8f02e4b1fsfint sysdb_upgrade_01(struct ldb_context *ldb, const char **ver)
36d38d22e0d385db01f5773a579f44b8f02e4b1fsf const char *filter = "(&(memberUid=*)(objectclass=group))";
36d38d22e0d385db01f5773a579f44b8f02e4b1fsf const char *mdn;
36d38d22e0d385db01f5773a579f44b8f02e4b1fsf ret = commence_upgrade(tmp_ctx, ldb, SYSDB_VERSION_0_2, &ctx);
291eb44b3adaf8247425286615b4f4b69fbea274minfrin el = ldb_msg_find_element(res->msgs[i], "memberUid");
291eb44b3adaf8247425286615b4f4b69fbea274minfrin DEBUG(1, ("memberUid is missing from message [%s], skipping\n",
291eb44b3adaf8247425286615b4f4b69fbea274minfrin /* create modification message */
291eb44b3adaf8247425286615b4f4b69fbea274minfrin ret = ldb_msg_add_empty(msg, "memberUid", LDB_FLAG_MOD_DELETE, NULL);
291eb44b3adaf8247425286615b4f4b69fbea274minfrin ret = ldb_msg_add_empty(msg, SYSDB_MEMBER, LDB_FLAG_MOD_ADD, NULL);
291eb44b3adaf8247425286615b4f4b69fbea274minfrin /* get domain name component value */
291eb44b3adaf8247425286615b4f4b69fbea274minfrin val = ldb_dn_get_component_val(res->msgs[i]->dn, 2);
291eb44b3adaf8247425286615b4f4b69fbea274minfrin domain = talloc_strndup(tmp_ctx, (const char *)val->data, val->length);
e8f95a682820a599fe41b22977010636be5c2717jim mdn = talloc_strdup(msg, ldb_dn_get_linearized(mem_dn));
f23a64b4e8a5f213b2aafb2bf6775e883e21f05fjim /* ok now we are ready to modify the entry */
f23a64b4e8a5f213b2aafb2bf6775e883e21f05fjim /* conversion done, update version number */
f23a64b4e8a5f213b2aafb2bf6775e883e21f05fjimint sysdb_check_upgrade_02(struct sss_domain_info *domains,
f23a64b4e8a5f213b2aafb2bf6775e883e21f05fjim const char *db_path)
291eb44b3adaf8247425286615b4f4b69fbea274minfrin bool do_02_upgrade = false;
291eb44b3adaf8247425286615b4f4b69fbea274minfrin bool ctx_trans = false;
36d38d22e0d385db01f5773a579f44b8f02e4b1fsf /* all fine, return */
076ae4ad21f0b3f25e2feabd9886b9500929eb2ejerenkrantz DEBUG(4, ("Upgrading DB from version: %s\n", version));
c7ab5a433d38d5eae5fc0bb76be80ffab6e4f71dniq /* convert database */
076ae4ad21f0b3f25e2feabd9886b9500929eb2ejerenkrantz /* need to convert database to split files */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* not a v2 upgrade, return and let the normal code take over any
36d38d22e0d385db01f5773a579f44b8f02e4b1fsf * further upgrade */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* == V2->V3 UPGRADE == */
a7ad08f37d876bde1a32f0cf793f4799536ab1a5ben DEBUG(0, ("UPGRADING DB TO VERSION %s\n", SYSDB_VERSION_0_3));
076ae4ad21f0b3f25e2feabd9886b9500929eb2ejerenkrantz /* ldb uses posix locks,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * posix is stupid and kills all locks when you close *any* file
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * descriptor associated to the same file.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Therefore we must close and reopen the ldb file here */
a7ad08f37d876bde1a32f0cf793f4799536ab1a5ben /* == Backup and reopen ldb == */
a7ad08f37d876bde1a32f0cf793f4799536ab1a5ben /* close */
a7ad08f37d876bde1a32f0cf793f4799536ab1a5ben /* backup*/
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* reopen */
291eb44b3adaf8247425286615b4f4b69fbea274minfrin /* open a transaction */
4f9a74ad7e44b0464f7cf56525a205d788becacbtrawick DEBUG(1, ("Failed to start ldb transaction! (%d)\n", ret));
4f9a74ad7e44b0464f7cf56525a205d788becacbtrawick /* == Upgrade contents == */
e8f95a682820a599fe41b22977010636be5c2717jim /* skip local */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* create new dom db */
076ae4ad21f0b3f25e2feabd9886b9500929eb2ejerenkrantz DEBUG(1, ("Failed to start ldb transaction! (%d)\n", ret));
fd7cb2b590294250e5b219512992cd5747289fbbbrianp /* search all entries for this domain in local,
fd7cb2b590294250e5b219512992cd5747289fbbbrianp * copy them all in the new database,
076ae4ad21f0b3f25e2feabd9886b9500929eb2ejerenkrantz * then remove them from local */
291eb44b3adaf8247425286615b4f4b69fbea274minfrin /* skip pre-created congtainers */
291eb44b3adaf8247425286615b4f4b69fbea274minfrin /* regenerate the DN against the new ldb as it may have different
291eb44b3adaf8247425286615b4f4b69fbea274minfrin * casefolding rules (example: name changing from case insensitive
291eb44b3adaf8247425286615b4f4b69fbea274minfrin * to case sensitive) */
291eb44b3adaf8247425286615b4f4b69fbea274minfrin " to new ldb file! (%d [%s])\n",
291eb44b3adaf8247425286615b4f4b69fbea274minfrin " from old ldb file! (%d [%s])\n",
337489fc0f19fa2ccac530ca0e2de9fe60f28e09ylavic /* now remove the basic containers from local */
337489fc0f19fa2ccac530ca0e2de9fe60f28e09ylavic /* these were optional so debug at level 9 in case
291eb44b3adaf8247425286615b4f4b69fbea274minfrin * of failure just for tracing */
291eb44b3adaf8247425286615b4f4b69fbea274minfrin " from old ldb file! (%d [%s])\n",
291eb44b3adaf8247425286615b4f4b69fbea274minfrin " from old ldb file! (%d [%s])\n",
291eb44b3adaf8247425286615b4f4b69fbea274minfrin " from old ldb file! (%d [%s])\n",
33510984c759eb3da154ceb0db9b75fa0031d3b4sf DEBUG(1, ("Failed to commit ldb transaction! (%d)\n", ret));
36d38d22e0d385db01f5773a579f44b8f02e4b1fsf /* conversion done, upgrade version number */
33510984c759eb3da154ceb0db9b75fa0031d3b4sf ret = ldb_msg_add_empty(msg, "version", LDB_FLAG_MOD_REPLACE, NULL);
33510984c759eb3da154ceb0db9b75fa0031d3b4sf ret = ldb_msg_add_string(msg, "version", SYSDB_VERSION_0_3);
1d9e72aaaebdda86c3afc856c35872edf19c69bbsf DEBUG(1, ("Failed to commit ldb transaction! (%d)\n", ret));
076ae4ad21f0b3f25e2feabd9886b9500929eb2ejerenkrantz DEBUG(1, ("Failed to cancel ldb transaction! (%d)\n", ret));
076ae4ad21f0b3f25e2feabd9886b9500929eb2ejerenkrantz DEBUG(1, ("Failed to cancel ldb transaction! (%d)\n", ret));
9bf4319b4fc7b31295b945215a55e2a92ba57903wroweint sysdb_upgrade_03(struct sysdb_ctx *sysdb, const char **ver)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_4, &ctx);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Make this database case-sensitive */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@ATTRIBUTES");
291eb44b3adaf8247425286615b4f4b69fbea274minfrin ret = ldb_msg_add_empty(msg, "name", LDB_FLAG_MOD_DELETE, NULL);
30e3e760b737f13ce800fa02c5930ade7659ba66niq /* conversion done, update version number */
30e3e760b737f13ce800fa02c5930ade7659ba66niqint sysdb_upgrade_04(struct sysdb_ctx *sysdb, const char **ver)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_5, &ctx);
076ae4ad21f0b3f25e2feabd9886b9500929eb2ejerenkrantz /* Add new index */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@INDEXLIST");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL);
291eb44b3adaf8247425286615b4f4b69fbea274minfrin ret = ldb_msg_add_string(msg, "@IDXATTR", "originalDN");
449efc4dc68e42cc4421d15498a689618aab5dc3coar /* Rebuild memberuid and memberoif attributes */
a877b7d5d03f91d6c93076d9ccf14469c70c648dcoar msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@MEMBEROF-REBUILD");
a877b7d5d03f91d6c93076d9ccf14469c70c648dcoar /* conversion done, update version number */
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fieldingint sysdb_upgrade_05(struct sysdb_ctx *sysdb, const char **ver)
076ae4ad21f0b3f25e2feabd9886b9500929eb2ejerenkrantz ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_6, &ctx);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Add new indexes */
if (!msg) {
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
done:
return ret;
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (ret) {
return ret;
if (!msg) {
goto done;
goto done;
goto done;
goto done;
goto done;
done:
return ret;
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (ret) {
return ret;
if (!msg) {
goto done;
goto done;
goto done;
goto done;
goto done;
done:
return ret;
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (ret) {
return ret;
if (!msg) {
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
done:
return ret;
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (ret) {
return ret;
if (!msg) {
goto done;
goto done;
goto done;
goto done;
goto done;
done:
return ret;
const char **ver)
int ret;
const char *name;
return ENOMEM;
if (ret) {
return ret;
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
goto done;
done:
return ret;
const char **ver)
const char *key;
const char *value;
NULL };
size_t i, j;
if (!tmp_ctx) {
return ENOMEM;
if (ret) {
return ret;
goto done;
goto done;
if (!memberof_dn) {
if (!val) {
done:
return ret;
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (ret) {
return ret;
if (!msg) {
goto done;
goto done;
goto done;
goto done;
goto done;
done:
return ret;
const char *tmp_str;
if (ret) {
return ret;
if (!basedn) {
goto done;
goto done;
if (!basedn) {
if (ret) {
done:
return ret;
const char *tmp_str;
if (ret) {
return ret;
if (!basedn) {
goto done;
if (!msg) {
goto done;
goto done;
goto done;
goto done;
goto done;
if (ret) {
goto done;
if (!newdn) {
goto done;
if (ret) {
goto done;
done:
return ret;
if (ret) {
return ret;
done:
return ret;