summaryrefslogtreecommitdiffstats
path: root/src/providers/ldap/sdap_async_initgroups.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/providers/ldap/sdap_async_initgroups.c')
-rw-r--r--src/providers/ldap/sdap_async_initgroups.c74
1 files changed, 47 insertions, 27 deletions
diff --git a/src/providers/ldap/sdap_async_initgroups.c b/src/providers/ldap/sdap_async_initgroups.c
index a1c73f960..d55f661ff 100644
--- a/src/providers/ldap/sdap_async_initgroups.c
+++ b/src/providers/ldap/sdap_async_initgroups.c
@@ -42,6 +42,7 @@ static errno_t sdap_add_incomplete_groups(struct sysdb_ctx *sysdb,
char **missing;
gid_t gid;
int ret;
+ errno_t sret;
bool in_transaction = false;
bool posix;
time_t now;
@@ -57,18 +58,10 @@ static errno_t sdap_add_incomplete_groups(struct sysdb_ctx *sysdb,
missing = talloc_array(tmp_ctx, char *, ldap_groups_count+1);
if (!missing) {
ret = ENOMEM;
- goto fail;
+ goto done;
}
mi = 0;
- ret = sysdb_transaction_start(sysdb);
- if (ret != EOK) {
- DEBUG(1, ("Cannot start sysdb transaction [%d]: %s\n",
- ret, strerror(ret)));
- goto fail;
- }
- in_transaction = true;
-
for (i=0; groupnames[i]; i++) {
ret = sysdb_search_group_by_name(tmp_ctx, sysdb, groupnames[i], NULL, &msg);
if (ret == EOK) {
@@ -82,7 +75,7 @@ static errno_t sdap_add_incomplete_groups(struct sysdb_ctx *sysdb,
} else if (ret != ENOENT) {
DEBUG(1, ("search for group failed [%d]: %s\n",
ret, strerror(ret)));
- goto fail;
+ goto done;
}
}
missing[mi] = NULL;
@@ -93,6 +86,16 @@ static errno_t sdap_add_incomplete_groups(struct sysdb_ctx *sysdb,
goto done;
}
+ ret = sysdb_transaction_start(sysdb);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ ("Cannot start sysdb transaction [%d]: %s\n",
+ ret, strerror(ret)));
+ goto done;
+ }
+ in_transaction = true;
+
+
now = time(NULL);
for (i=0; missing[i]; i++) {
/* The group is not in sysdb, need to add a fake entry */
@@ -102,7 +105,7 @@ static errno_t sdap_add_incomplete_groups(struct sysdb_ctx *sysdb,
&name);
if (ret != EOK) {
DEBUG(1, ("The group has no name attribute\n"));
- goto fail;
+ goto done;
}
if (strcmp(name, missing[i]) == 0) {
@@ -116,7 +119,7 @@ static errno_t sdap_add_incomplete_groups(struct sysdb_ctx *sysdb,
tmp_ctx, opts->idmap_ctx, ldap_groups[ai],
opts->group_map[SDAP_AT_GROUP_OBJECTSID].sys_name,
&sid_str);
- if (ret != EOK) goto fail;
+ if (ret != EOK) goto done;
DEBUG(SSSDBG_TRACE_INTERNAL,
("Group [%s] has objectSID [%s]\n",
@@ -151,7 +154,7 @@ static errno_t sdap_add_incomplete_groups(struct sysdb_ctx *sysdb,
posix = false;
} else if (ret) {
DEBUG(1, ("The GID attribute is malformed\n"));
- goto fail;
+ goto done;
}
}
@@ -167,7 +170,7 @@ static errno_t sdap_add_incomplete_groups(struct sysdb_ctx *sysdb,
ret = sysdb_add_incomplete_group(sysdb, name, gid, original_dn,
posix, now);
if (ret != EOK) {
- goto fail;
+ goto done;
}
break;
}
@@ -176,21 +179,24 @@ static errno_t sdap_add_incomplete_groups(struct sysdb_ctx *sysdb,
if (ai == ldap_groups_count) {
DEBUG(2, ("Group %s not present in LDAP\n", missing[i]));
ret = EINVAL;
- goto fail;
+ goto done;
}
}
-done:
ret = sysdb_transaction_commit(sysdb);
if (ret != EOK) {
- DEBUG(1, ("sysdb_transaction_commit failed.\n"));
- goto fail;
+ DEBUG(SSSDBG_CRIT_FAILURE, ("sysdb_transaction_commit failed.\n"));
+ goto done;
}
in_transaction = false;
ret = EOK;
-fail:
+
+done:
if (in_transaction) {
- sysdb_transaction_cancel(sysdb);
+ sret = sysdb_transaction_cancel(sysdb);
+ if (sret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to cancel transaction\n"));
+ }
}
talloc_free(tmp_ctx);
return ret;
@@ -1964,6 +1970,7 @@ errno_t save_rfc2307bis_user_memberships(
DEBUG(7, ("Save parent groups to sysdb\n"));
ret = sysdb_transaction_start(state->sysdb);
if (ret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to start transaction\n"));
goto error;
}
in_transaction = true;
@@ -2012,6 +2019,7 @@ errno_t save_rfc2307bis_user_memberships(
ret = sysdb_transaction_commit(state->sysdb);
if (ret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to commit transaction\n"));
goto error;
}
in_transaction = false;
@@ -2630,8 +2638,10 @@ static void sdap_get_initgr_user(struct tevent_req *subreq)
struct sysdb_attrs **usr_attrs;
size_t count;
int ret;
+ errno_t sret;
const char *orig_dn;
const char *cname;
+ bool in_transaction = false;
DEBUG(9, ("Receiving info for the user\n"));
@@ -2666,9 +2676,10 @@ static void sdap_get_initgr_user(struct tevent_req *subreq)
ret = sysdb_transaction_start(state->sysdb);
if (ret) {
- tevent_req_error(req, ret);
- return;
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to start transaction\n"));
+ goto fail;
}
+ in_transaction = true;
DEBUG(9, ("Storing the user\n"));
@@ -2677,18 +2688,17 @@ static void sdap_get_initgr_user(struct tevent_req *subreq)
state->orig_user,
true, NULL, 0);
if (ret) {
- sysdb_transaction_cancel(state->sysdb);
- tevent_req_error(req, ret);
- return;
+ goto fail;
}
DEBUG(9, ("Commit change\n"));
ret = sysdb_transaction_commit(state->sysdb);
if (ret) {
- tevent_req_error(req, ret);
- return;
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to commit transaction\n"));
+ goto fail;
}
+ in_transaction = false;
ret = sysdb_get_real_name(state, state->sysdb, state->name, &cname);
if (ret != EOK) {
@@ -2760,6 +2770,16 @@ static void sdap_get_initgr_user(struct tevent_req *subreq)
tevent_req_error(req, EINVAL);
return;
}
+
+ return;
+fail:
+ if (in_transaction) {
+ sret = sysdb_transaction_cancel(state->sysdb);
+ if (sret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to cancel transaction\n"));
+ }
+ }
+ tevent_req_error(req, ret);
}
static int sdap_initgr_rfc2307bis_recv(struct tevent_req *req);