summaryrefslogtreecommitdiffstats
path: root/src/tools/sss_usermod.c
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/sss_usermod.c
parent0051296f67bd7d8e2e3094638ddff4e641324d04 (diff)
downloadsssd-21d485184df986e1a123f70c689517386e51a5ce.tar.gz
sssd-21d485184df986e1a123f70c689517386e51a5ce.tar.xz
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/sss_usermod.c')
-rw-r--r--src/tools/sss_usermod.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/tools/sss_usermod.c b/src/tools/sss_usermod.c
index b761de225..a45005caa 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) {