[SSSD] [PATCH] SYSDB: Commit transaction in sysdb_store_user
Jakub Hrozek
jhrozek at redhat.com
Tue Sep 4 21:34:20 UTC 2012
The recent sysdb patch broke sysdb_store_user and by extension the unit
tests. Neither me nor Michal have noticed most probably due to a bug
either in our Makefile.am or perhaps even the autotools -- the tests
binary doesn't get rebuild on issuing a simple make tests.
Anyway, a fix for the sysdb_store_user() function is attached. When
testing, please make sure to make clean before building the tests.
I renamed the previous done label into fail label as it was only
reachable on error condition and used a new done label to shortcut to
the transaction commit.
-------------- next part --------------
>From 43522f2a5d617ec494c58a42ff642ca12efd106a Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Tue, 4 Sep 2012 21:51:01 +0200
Subject: [PATCH] SYSDB: Commit transaction in sysdb_store_user
---
src/db/sysdb_ops.c | 36 +++++++++++++++++++-----------------
1 file changed, 19 insertions(+), 17 deletions(-)
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index 1b86276925020508980ebd66fb341045974cbdb4..91fa21e9624db55ecfe31e46878fee6b5448aede 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -1516,19 +1516,19 @@ int sysdb_store_user(struct sysdb_ctx *sysdb,
attrs = sysdb_new_attrs(tmp_ctx);
if (!attrs) {
ret = ENOMEM;
- goto done;
+ goto fail;
}
}
if (pwd && (sysdb->domain->legacy_passwords || !*pwd)) {
ret = sysdb_attrs_add_string(attrs, SYSDB_PWD, pwd);
- if (ret) goto done;
+ if (ret) goto fail;
}
ret = sysdb_transaction_start(sysdb);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to start transaction\n"));
- goto done;
+ goto fail;
}
in_transaction = true;
@@ -1536,7 +1536,7 @@ int sysdb_store_user(struct sysdb_ctx *sysdb,
ret = sysdb_search_user_by_name(tmp_ctx, sysdb,
name, NULL, &msg);
if (ret && ret != ENOENT) {
- goto done;
+ goto fail;
}
/* get transaction timestamp */
@@ -1557,9 +1557,10 @@ int sysdb_store_user(struct sysdb_ctx *sysdb,
/* Not found by UID, return the original EEXIST,
* this may be a conflict in MPG domain or something
* else */
- return EEXIST;
+ ret = EEXIST;
+ goto fail;
} else if (ret != EOK) {
- goto done;
+ goto fail;
}
DEBUG(SSSDBG_MINOR_FAILURE,
("A user with the same UID [%llu] was removed from the "
@@ -1573,44 +1574,44 @@ int sysdb_store_user(struct sysdb_ctx *sysdb,
/* the user exists, let's just replace attributes when set */
if (uid) {
ret = sysdb_attrs_add_uint32(attrs, SYSDB_UIDNUM, uid);
- if (ret) goto done;
+ if (ret) goto fail;
}
if (gid) {
ret = sysdb_attrs_add_uint32(attrs, SYSDB_GIDNUM, gid);
- if (ret) goto done;
+ if (ret) goto fail;
}
if (uid && !gid && sysdb->mpg) {
ret = sysdb_attrs_add_uint32(attrs, SYSDB_GIDNUM, uid);
- if (ret) goto done;
+ if (ret) goto fail;
}
if (gecos) {
ret = sysdb_attrs_add_string(attrs, SYSDB_GECOS, gecos);
- if (ret) goto done;
+ if (ret) goto fail;
}
if (homedir) {
ret = sysdb_attrs_add_string(attrs, SYSDB_HOMEDIR, homedir);
- if (ret) goto done;
+ if (ret) goto fail;
}
if (shell) {
ret = sysdb_attrs_add_string(attrs, SYSDB_SHELL, shell);
- if (ret) goto done;
+ if (ret) goto fail;
}
ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now);
- if (ret) goto done;
+ if (ret) goto fail;
ret = sysdb_attrs_add_time_t(attrs, SYSDB_CACHE_EXPIRE,
((cache_timeout) ?
(now + cache_timeout) : 0));
- if (ret) goto done;
+ if (ret) goto fail;
ret = sysdb_set_user_attr(sysdb, name, attrs, SYSDB_MOD_REP);
- if (ret != EOK) goto done;
+ if (ret != EOK) goto fail;
if (remove_attrs) {
ret = sysdb_remove_attrs(sysdb, name,
@@ -1621,15 +1622,16 @@ int sysdb_store_user(struct sysdb_ctx *sysdb,
}
}
+done:
ret = sysdb_transaction_commit(sysdb);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to commit transaction\n"));
- goto done;
+ goto fail;
}
in_transaction = false;
-done:
+fail:
if (in_transaction) {
sret = sysdb_transaction_cancel(sysdb);
if (sret != EOK) {
--
1.7.11.4
More information about the sssd-devel
mailing list