diff options
Diffstat (limited to 'server/db')
-rw-r--r-- | server/db/sysdb.c | 128 | ||||
-rw-r--r-- | server/db/sysdb_private.h | 4 |
2 files changed, 129 insertions, 3 deletions
diff --git a/server/db/sysdb.c b/server/db/sysdb.c index bd3acc6c..7325f112 100644 --- a/server/db/sysdb.c +++ b/server/db/sysdb.c @@ -1221,6 +1221,8 @@ static int sysdb_upgrade_03(struct sysdb_ctx *ctx, const char **ver) return ENOMEM; } + DEBUG(0, ("UPGRADING DB TO VERSION %s\n", SYSDB_VERSION_0_4)); + ret = ldb_transaction_start(ctx->ldb); if (ret != LDB_SUCCESS) { ret = EIO; @@ -1289,12 +1291,125 @@ done: ret = ldb_transaction_cancel(ctx->ldb); } else { ret = ldb_transaction_commit(ctx->ldb); + *ver = SYSDB_VERSION_0_4; + } + if (ret != LDB_SUCCESS) { + ret = EIO; + } + + return ret; +} + +static int sysdb_upgrade_04(struct sysdb_ctx *ctx, const char **ver) +{ + TALLOC_CTX *tmp_ctx; + int ret; + struct ldb_message *msg; + + tmp_ctx = talloc_new(ctx); + if (!tmp_ctx) { + return ENOMEM; + } + + DEBUG(0, ("UPGRADING DB TO VERSION %s\n", SYSDB_VERSION_0_5)); + + ret = ldb_transaction_start(ctx->ldb); + if (ret != LDB_SUCCESS) { + ret = EIO; + goto done; + } + + /* Add new index */ + msg = ldb_msg_new(tmp_ctx); + if (!msg) { + ret = ENOMEM; + goto done; + } + msg->dn = ldb_dn_new(tmp_ctx, ctx->ldb, "@INDEXLIST"); + if (!msg->dn) { + ret = ENOMEM; + goto done; + } + + ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL); + if (ret != LDB_SUCCESS) { + ret = ENOMEM; + goto done; + } + ret = ldb_msg_add_string(msg, "@IDXATTR", "originalDN"); + if (ret != LDB_SUCCESS) { + ret = ENOMEM; + goto done; + } + + ret = ldb_modify(ctx->ldb, msg); + if (ret != LDB_SUCCESS) { + ret = sysdb_error_to_errno(ret); + goto done; + } + + /* Rebuild memberuid and memberoif attributes */ + msg = ldb_msg_new(tmp_ctx); + if (!msg) { + ret = ENOMEM; + goto done; + } + msg->dn = ldb_dn_new(tmp_ctx, ctx->ldb, "@MEMBEROF-REBUILD"); + if (!msg->dn) { + ret = ENOMEM; + goto done; + } + + ret = ldb_add(ctx->ldb, msg); + if (ret != LDB_SUCCESS) { + ret = sysdb_error_to_errno(ret); + goto done; + } + + /* conversion done, upgrade version number */ + msg = ldb_msg_new(tmp_ctx); + if (!msg) { + ret = ENOMEM; + goto done; + } + msg->dn = ldb_dn_new(tmp_ctx, ctx->ldb, "cn=sysdb"); + if (!msg->dn) { + ret = ENOMEM; + goto done; + } + + ret = ldb_msg_add_empty(msg, "version", LDB_FLAG_MOD_REPLACE, NULL); + if (ret != LDB_SUCCESS) { + ret = ENOMEM; + goto done; + } + ret = ldb_msg_add_string(msg, "version", SYSDB_VERSION_0_5); + if (ret != LDB_SUCCESS) { + ret = ENOMEM; + goto done; + } + + ret = ldb_modify(ctx->ldb, msg); + if (ret != LDB_SUCCESS) { + ret = sysdb_error_to_errno(ret); + goto done; + } + + ret = EOK; + +done: + talloc_zfree(tmp_ctx); + + if (ret != EOK) { + ret = ldb_transaction_cancel(ctx->ldb); + } else { + ret = ldb_transaction_commit(ctx->ldb); + *ver = SYSDB_VERSION_0_5; } if (ret != LDB_SUCCESS) { ret = EIO; } - *ver = SYSDB_VERSION_0_4; return ret; } @@ -1406,6 +1521,9 @@ static int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx, goto done; } + DEBUG(4, ("Upgrading DB [%s] from version: %s\n", + domain->name, version)); + if (strcmp(version, SYSDB_VERSION_0_1) == 0) { /* convert database */ ret = sysdb_upgrade_01(ctx, &version); @@ -1439,9 +1557,15 @@ static int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx, if (strcmp(version, SYSDB_VERSION_0_3) == 0) { ret = sysdb_upgrade_03(ctx, &version); - goto done; + if (ret != EOK) { + goto done; + } } + if (strcmp(version, SYSDB_VERSION_0_4) == 0) { + ret = sysdb_upgrade_04(ctx, &version); + goto done; + } } DEBUG(0,("Unknown DB version [%s], expected [%s] for domain %s!\n", diff --git a/server/db/sysdb_private.h b/server/db/sysdb_private.h index 4400665c..270cf360 100644 --- a/server/db/sysdb_private.h +++ b/server/db/sysdb_private.h @@ -23,12 +23,13 @@ #ifndef __INT_SYS_DB_H__ #define __INT_SYS_DB_H__ +#define SYSDB_VERSION_0_5 "0.5" #define SYSDB_VERSION_0_4 "0.4" #define SYSDB_VERSION_0_3 "0.3" #define SYSDB_VERSION_0_2 "0.2" #define SYSDB_VERSION_0_1 "0.1" -#define SYSDB_VERSION SYSDB_VERSION_0_4 +#define SYSDB_VERSION SYSDB_VERSION_0_5 #define SYSDB_BASE_LDIF \ "dn: @ATTRIBUTES\n" \ @@ -47,6 +48,7 @@ "@IDXATTR: uidNumber\n" \ "@IDXATTR: gidNumber\n" \ "@IDXATTR: lastUpdate\n" \ + "@IDXATTR: originalDN\n" \ "\n" \ "dn: @MODULES\n" \ "@LIST: asq,memberof\n" \ |