summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2011-08-09 08:26:03 -0400
committerStephen Gallagher <sgallagh@redhat.com>2011-08-10 14:05:48 -0400
commit7e39ef3f052c5d5394b515fd5dd660e11d5baa7e (patch)
tree6da1dde514c1d170390031c940f3cd37c330903d /src
parent80a746e4c2f5168794bd8747db01e25c0b16d876 (diff)
downloadsssd-7e39ef3f052c5d5394b515fd5dd660e11d5baa7e.tar.gz
sssd-7e39ef3f052c5d5394b515fd5dd660e11d5baa7e.tar.bz2
sssd-7e39ef3f052c5d5394b515fd5dd660e11d5baa7e.zip
Cancel sysdb upgrade transaction if commit fails
Diffstat (limited to 'src')
-rw-r--r--src/db/sysdb.c90
1 files changed, 30 insertions, 60 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index 8165e923..a9e6975c 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -794,6 +794,27 @@ static int sysdb_get_db_file(TALLOC_CTX *mem_ctx,
return EOK;
}
+static int finish_upgrade(int result, struct ldb_context *ldb,
+ const char *next_ver, const char **ver)
+{
+ int ret = result;
+
+ if (ret == EOK) {
+ ret = ldb_transaction_commit(ldb);
+ ret = sysdb_error_to_errno(ret);
+ if (ret == EOK) {
+ *ver = next_ver;
+ }
+ }
+
+ if (ret != EOK) {
+ ret = ldb_transaction_cancel(ldb);
+ ret = sysdb_error_to_errno(ret);
+ }
+
+ return ret;
+}
+
/* serach all groups that have a memberUid attribute.
* change it into a member attribute for a user of same domain.
* remove the memberUid attribute
@@ -937,18 +958,7 @@ static int sysdb_upgrade_01(TALLOC_CTX *mem_ctx,
ret = EOK;
done:
- if (ret != EOK) {
- ldb_transaction_cancel(ldb);
- } else {
- ret = ldb_transaction_commit(ldb);
- if (ret != LDB_SUCCESS) {
- return EIO;
- }
-
- *ver = SYSDB_VERSION_0_2;
- }
-
- return ret;
+ return finish_upgrade(ret, ldb, SYSDB_VERSION_0_2, ver);
}
static int sysdb_check_upgrade_02(TALLOC_CTX *mem_ctx,
@@ -1356,18 +1366,8 @@ static int sysdb_upgrade_03(struct sysdb_ctx *ctx, const char **ver)
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_4;
- }
- if (ret != LDB_SUCCESS) {
- ret = EIO;
- }
-
+ ret = finish_upgrade(ret, ctx->ldb, SYSDB_VERSION_0_4, ver);
+ talloc_free(tmp_ctx);
return ret;
}
@@ -1469,18 +1469,8 @@ static int sysdb_upgrade_04(struct sysdb_ctx *ctx, const char **ver)
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;
- }
-
+ ret = finish_upgrade(ret, ctx->ldb, SYSDB_VERSION_0_5, ver);
+ talloc_free(tmp_ctx);
return ret;
}
@@ -1577,18 +1567,8 @@ static int sysdb_upgrade_05(struct sysdb_ctx *ctx, const char **ver)
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_6;
- }
- if (ret != LDB_SUCCESS) {
- ret = EIO;
- }
-
+ ret = finish_upgrade(ret, ctx->ldb, SYSDB_VERSION_0_6, ver);
+ talloc_free(tmp_ctx);
return ret;
}
@@ -1673,18 +1653,8 @@ static int sysdb_upgrade_06(struct sysdb_ctx *ctx, const char **ver)
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_7;
- }
- if (ret != LDB_SUCCESS) {
- ret = EIO;
- }
-
+ ret = finish_upgrade(ret, ctx->ldb, SYSDB_VERSION_0_7, ver);
+ talloc_free(tmp_ctx);
return ret;
}