summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2011-10-31 17:46:58 +0100
committerStephen Gallagher <sgallagh@redhat.com>2011-11-11 14:36:17 -0500
commitd8e4e7a40eb75810c58a81bda7e27a2aaecc868f (patch)
tree6307709fd04afcbc35071b08c23abac7df4c9a64
parent88ab259f993956b6cd0b1a07d3d88d105e368a8c (diff)
downloadsssd-d8e4e7a40eb75810c58a81bda7e27a2aaecc868f.tar.gz
sssd-d8e4e7a40eb75810c58a81bda7e27a2aaecc868f.tar.bz2
sssd-d8e4e7a40eb75810c58a81bda7e27a2aaecc868f.zip
Use one transaction instead of two during RFC2307bis group processing
https://fedorahosted.org/sssd/ticket/1054
-rw-r--r--src/providers/ldap/sdap_async_groups.c86
1 files changed, 55 insertions, 31 deletions
diff --git a/src/providers/ldap/sdap_async_groups.c b/src/providers/ldap/sdap_async_groups.c
index 8940c334..25a3e0a5 100644
--- a/src/providers/ldap/sdap_async_groups.c
+++ b/src/providers/ldap/sdap_async_groups.c
@@ -1537,11 +1537,13 @@ static errno_t sdap_nested_group_populate_users(struct sysdb_ctx *sysdb,
static void sdap_nested_done(struct tevent_req *subreq)
{
- errno_t ret;
+ errno_t ret, tret;
int hret;
unsigned long i;
- unsigned long count;
+ unsigned long user_count;
+ unsigned long group_count;
hash_value_t *values;
+ bool in_transaction = false;
struct sysdb_attrs **users = NULL;
struct sysdb_attrs **groups = NULL;
struct tevent_req *req = tevent_req_callback_data(subreq,
@@ -1554,67 +1556,89 @@ static void sdap_nested_done(struct tevent_req *subreq)
if (ret != EOK) {
DEBUG(1, ("Nested group processing failed: [%d][%s]\n",
ret, strerror(ret)));
- tevent_req_error(req, ret);
- return;
+ goto fail;
}
- hret = hash_values(state->user_hash, &count, &values);
+ hret = hash_values(state->user_hash, &user_count, &values);
if (hret != HASH_SUCCESS) {
- tevent_req_error(req, EIO);
+ ret = EIO;
+ goto fail;
}
- if (count) {
- users = talloc_array(state, struct sysdb_attrs *, count);
+ if (user_count) {
+ users = talloc_array(state, struct sysdb_attrs *, user_count);
if (!users) {
talloc_free(values);
- tevent_req_error(req, ENOMEM);
- return;
+ ret = ENOMEM;
+ goto fail;
}
- for (i = 0; i < count; i++) {
+ for (i = 0; i < user_count; i++) {
users[i] = talloc_get_type(values[i].ptr, struct sysdb_attrs);
}
talloc_zfree(values);
}
- /* Save all of the users first so that they are in
- * place for the groups to add them.
- */
- ret = sdap_nested_group_populate_users(state->sysdb, state->dom,
- state->opts, users, count);
- if (ret != EOK) {
- tevent_req_error(req, ret);
- return;
- }
-
/* Users are all saved. Now save groups */
- hret = hash_values(state->group_hash, &count, &values);
+ hret = hash_values(state->group_hash, &group_count, &values);
if (hret != HASH_SUCCESS) {
- tevent_req_error(req, EIO);
- return;
+ ret = EIO;
+ goto fail;
}
- groups = talloc_array(state, struct sysdb_attrs *, count);
+ groups = talloc_array(state, struct sysdb_attrs *, group_count);
if (!groups) {
talloc_free(values);
- tevent_req_error(req, ENOMEM);
- return;
+ ret = ENOMEM;
+ goto fail;
}
- for (i = 0; i < count; i++) {
+ for (i = 0; i < group_count; i++) {
groups[i] = talloc_get_type(values[i].ptr, struct sysdb_attrs);
}
talloc_zfree(values);
+ /* Save all of the users first so that they are in
+ * place for the groups to add them.
+ */
+ ret = sysdb_transaction_start(state->sysdb);
+ if (ret != EOK) {
+ DEBUG(1, ("Failed to start transaction\n"));
+ goto fail;
+ }
+ in_transaction = true;
+
+ ret = sdap_nested_group_populate_users(state->sysdb, state->dom,
+ state->opts, users, user_count);
+ if (ret != EOK) {
+ goto fail;
+ }
+
ret = sdap_save_groups(state, state->sysdb, state->dom, state->opts,
- groups, count, false, &state->higher_usn);
+ groups, group_count, false, &state->higher_usn);
if (ret != EOK) {
- tevent_req_error(req, ret);
- return;
+ goto fail;
+ }
+
+ ret = sysdb_transaction_commit(state->sysdb);
+ if (ret != EOK) {
+ DEBUG(1, ("Failed to commit transaction\n"));
+ goto fail;
}
+ in_transaction = false;
/* Processing complete */
tevent_req_done(req);
+ return;
+
+fail:
+ if (in_transaction) {
+ tret = sysdb_transaction_cancel(state->sysdb);
+ if (tret != EOK) {
+ DEBUG(1, ("Failed to cancel transaction\n"));
+ }
+ }
+ tevent_req_error(req, ret);
}
static errno_t sdap_nested_group_populate_users(struct sysdb_ctx *sysdb,