diff options
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/sss_cache.c | 5 | ||||
-rw-r--r-- | src/tools/sss_groupadd.c | 18 | ||||
-rw-r--r-- | src/tools/sss_groupmod.c | 17 | ||||
-rw-r--r-- | src/tools/sss_seed.c | 5 | ||||
-rw-r--r-- | src/tools/sss_useradd.c | 15 | ||||
-rw-r--r-- | src/tools/sss_usermod.c | 18 |
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) { |