summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorMichal Zidek <mzidek@redhat.com>2012-08-16 18:48:53 +0200
committerJakub Hrozek <jhrozek@redhat.com>2012-08-23 18:09:18 +0200
commit21d485184df986e1a123f70c689517386e51a5ce (patch)
tree7b2165fdc4dadcc632d402866b704df04ede852f /src/tools
parent0051296f67bd7d8e2e3094638ddff4e641324d04 (diff)
downloadsssd-21d485184df986e1a123f70c689517386e51a5ce.tar.gz
sssd-21d485184df986e1a123f70c689517386e51a5ce.tar.bz2
sssd-21d485184df986e1a123f70c689517386e51a5ce.zip
Unify usage of sysdb transactions
Removing bad examples of usage of sysdb_transaction_start/commit/end functions and making it more consistent (all files except of src/db/sysdb_*.c).
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/sss_cache.c5
-rw-r--r--src/tools/sss_groupadd.c18
-rw-r--r--src/tools/sss_groupmod.c17
-rw-r--r--src/tools/sss_seed.c5
-rw-r--r--src/tools/sss_useradd.c15
-rw-r--r--src/tools/sss_usermod.c18
6 files changed, 67 insertions, 11 deletions
diff --git a/src/tools/sss_cache.c b/src/tools/sss_cache.c
index 1b2b29fe..950ff1c1 100644
--- a/src/tools/sss_cache.c
+++ b/src/tools/sss_cache.c
@@ -131,7 +131,10 @@ int main(int argc, const char *argv[])
ret = sysdb_transaction_commit(sysdb);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, ("Could not commit the transaction!\n"));
- sysdb_transaction_cancel(sysdb);
+ ret = sysdb_transaction_cancel(sysdb);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to cancel transaction\n"));
+ }
}
if (skipped == true) {
diff --git a/src/tools/sss_groupadd.c b/src/tools/sss_groupadd.c
index f2e09a10..2a01f392 100644
--- a/src/tools/sss_groupadd.c
+++ b/src/tools/sss_groupadd.c
@@ -46,7 +46,9 @@ int main(int argc, const char **argv)
poptContext pc = NULL;
struct tools_ctx *tctx = NULL;
int ret = EXIT_SUCCESS;
+ errno_t sret;
const char *pc_groupname = NULL;
+ bool in_transaction = false;
debug_prg_name = argv[0];
@@ -106,20 +108,32 @@ int main(int argc, const char **argv)
tctx->error = sysdb_transaction_start(tctx->sysdb);
if (tctx->error != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to start transaction\n"));
goto done;
}
+ in_transaction = true;
/* groupadd */
tctx->error = groupadd(tctx->sysdb, tctx->octx);
if (tctx->error) {
- /* cancel transaction */
- sysdb_transaction_cancel(tctx->sysdb);
goto done;
}
tctx->error = sysdb_transaction_commit(tctx->sysdb);
+ if (tctx->error != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to commit transaction\n"));
+ goto done;
+ }
+ in_transaction = false;
done:
+ if (in_transaction) {
+ sret = sysdb_transaction_cancel(tctx->sysdb);
+ if (sret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to cancel transaction\n"));
+ }
+ }
+
if (tctx->error) {
ret = tctx->error;
switch (ret) {
diff --git a/src/tools/sss_groupmod.c b/src/tools/sss_groupmod.c
index abab4f57..c210bad7 100644
--- a/src/tools/sss_groupmod.c
+++ b/src/tools/sss_groupmod.c
@@ -52,8 +52,10 @@ int main(int argc, const char **argv)
struct tools_ctx *tctx = NULL;
char *addgroups = NULL, *rmgroups = NULL;
int ret;
+ errno_t sret;
const char *pc_groupname = NULL;
char *badgroup = NULL;
+ bool in_transaction = false;
debug_prg_name = argv[0];
@@ -194,20 +196,31 @@ int main(int argc, const char **argv)
tctx->error = sysdb_transaction_start(tctx->sysdb);
if (tctx->error != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to start transaction\n"));
goto done;
}
+ in_transaction = true;
/* groupmod */
tctx->error = groupmod(tctx, tctx->sysdb, tctx->octx);
if (tctx->error) {
- /* cancel transaction */
- sysdb_transaction_cancel(tctx->sysdb);
goto done;
}
tctx->error = sysdb_transaction_commit(tctx->sysdb);
+ if (tctx->error != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to commit transaction\n"));
+ goto done;
+ }
+ in_transaction = false;
done:
+ if (in_transaction) {
+ sret = sysdb_transaction_cancel(tctx->sysdb);
+ if (sret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to cancel transaction\n"));
+ }
+ }
if (tctx->error) {
ret = tctx->error;
DEBUG(1, ("sysdb operation failed (%d)[%s]\n", ret, strerror(ret)));
diff --git a/src/tools/sss_seed.c b/src/tools/sss_seed.c
index 9136de34..37267896 100644
--- a/src/tools/sss_seed.c
+++ b/src/tools/sss_seed.c
@@ -678,6 +678,7 @@ static int seed_cache_user(struct seed_ctx *sctx)
{
bool in_transaction = false;
int ret = EOK;
+ errno_t sret;
ret = sysdb_transaction_start(sctx->sysdb);
if (ret != EOK) {
@@ -720,8 +721,8 @@ static int seed_cache_user(struct seed_ctx *sctx)
done:
if (in_transaction == true) {
- ret = sysdb_transaction_cancel(sctx->sysdb);
- if (ret != EOK) {
+ sret = sysdb_transaction_cancel(sctx->sysdb);
+ if (sret != EOK) {
DEBUG(SSSDBG_OP_FAILURE, ("Failed to cancel transaction\n"));
}
}
diff --git a/src/tools/sss_useradd.c b/src/tools/sss_useradd.c
index 4df7c098..1bf174c5 100644
--- a/src/tools/sss_useradd.c
+++ b/src/tools/sss_useradd.c
@@ -62,6 +62,8 @@ int main(int argc, const char **argv)
char *groups = NULL;
char *badgroup = NULL;
int ret;
+ errno_t sret;
+ bool in_transaction = false;
debug_prg_name = argv[0];
@@ -179,21 +181,23 @@ int main(int argc, const char **argv)
tctx->error = sysdb_transaction_start(tctx->sysdb);
if (tctx->error != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to start transaction\n"));
goto done;
}
+ in_transaction = true;
/* useradd */
tctx->error = useradd(tctx, tctx->sysdb, tctx->octx);
if (tctx->error) {
- /* cancel transaction */
- sysdb_transaction_cancel(tctx->sysdb);
goto done;
}
tctx->error = sysdb_transaction_commit(tctx->sysdb);
if (tctx->error) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to commit transaction\n"));
goto done;
}
+ in_transaction = false;
/* Set SELinux login context - must be done after transaction is done
* b/c libselinux calls getpwnam */
@@ -249,6 +253,13 @@ int main(int argc, const char **argv)
}
done:
+ if (in_transaction) {
+ sret = sysdb_transaction_cancel(tctx->sysdb);
+ if (sret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to cancel transaction\n"));
+ }
+ }
+
if (tctx->error) {
switch (tctx->error) {
case ERANGE:
diff --git a/src/tools/sss_usermod.c b/src/tools/sss_usermod.c
index b761de22..a45005ca 100644
--- a/src/tools/sss_usermod.c
+++ b/src/tools/sss_usermod.c
@@ -60,9 +60,11 @@ int main(int argc, const char **argv)
poptContext pc = NULL;
char *addgroups = NULL, *rmgroups = NULL;
int ret;
+ errno_t sret;
const char *pc_username = NULL;
struct tools_ctx *tctx = NULL;
char *badgroup = NULL;
+ bool in_transaction = false;
debug_prg_name = argv[0];
@@ -216,18 +218,23 @@ int main(int argc, const char **argv)
tctx->error = sysdb_transaction_start(tctx->sysdb);
if (tctx->error != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to start transaction\n"));
goto done;
}
+ in_transaction = true;
/* usermod */
tctx->error = usermod(tctx, tctx->sysdb, tctx->octx);
if (tctx->error) {
- /* cancel transaction */
- sysdb_transaction_cancel(tctx->sysdb);
goto done;
}
tctx->error = sysdb_transaction_commit(tctx->sysdb);
+ if (tctx->error) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to commit transaction\n"));
+ goto done;
+ }
+ in_transaction = false;
/* Set SELinux login context - must be done after transaction is done
* b/c libselinux calls getpwnam */
@@ -239,6 +246,13 @@ int main(int argc, const char **argv)
}
done:
+ if (in_transaction) {
+ sret = sysdb_transaction_cancel(tctx->sysdb);
+ if (sret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to cancel transaction\n"));
+ }
+ }
+
if (tctx->error) {
ret = tctx->error;
switch (ret) {