summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/db/sysdb.h11
-rw-r--r--src/db/sysdb_ops.c123
-rw-r--r--src/providers/ldap/ldap_id.c43
-rw-r--r--src/providers/ldap/ldap_id_cleanup.c137
-rw-r--r--src/providers/proxy.c69
-rw-r--r--src/tests/sysdb-tests.c47
6 files changed, 109 insertions, 321 deletions
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index c2190062..a0714b86 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -580,12 +580,9 @@ struct tevent_req *sysdb_search_groups_send(TALLOC_CTX *mem_ctx,
int sysdb_search_groups_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
size_t *msgs_count, struct ldb_message ***msgs);
-struct tevent_req *sysdb_delete_group_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- struct sysdb_ctx *sysdb,
- struct sysdb_handle *handle,
- struct sss_domain_info *domain,
- const char *name, gid_t gid);
-int sysdb_delete_group_recv(struct tevent_req *req);
+int sysdb_delete_group(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *sysdb,
+ struct sss_domain_info *domain,
+ const char *name, gid_t gid);
#endif /* __SYS_DB_H__ */
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index 86aa61a6..1a816dca 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -74,15 +74,6 @@ static uint32_t get_attr_as_uint32(struct ldb_message *msg, const char *attr)
#define ERROR_OUT(v, r, l) do { v = r; goto l; } while(0);
-/* =Standard-Sysdb-Operations-utility-functions=========================== */
-
-static int sysdb_op_default_recv(struct tevent_req *req)
-{
- TEVENT_REQ_RETURN_ON_ERROR(req);
-
- return EOK;
-}
-
/* =Remove-Entry-From-Sysdb=============================================== */
@@ -1984,110 +1975,62 @@ int sysdb_search_groups_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
/* =Delete-Group-by-Name-OR-gid=========================================== */
-struct sysdb_delete_group_state {
- struct tevent_context *ev;
- struct sss_domain_info *domain;
-
- const char *name;
- gid_t gid;
-
- struct sysdb_handle *handle;
-};
-
-void sysdb_delete_group_check_handle(struct tevent_req *subreq);
-
-struct tevent_req *sysdb_delete_group_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- struct sysdb_ctx *sysdb,
- struct sysdb_handle *handle,
- struct sss_domain_info *domain,
- const char *name, gid_t gid)
-{
- struct tevent_req *req, *subreq;
- struct sysdb_delete_group_state *state;
-
- req = tevent_req_create(mem_ctx, &state, struct sysdb_delete_group_state);
- if (!req) return NULL;
-
- state->ev = ev;
- state->handle = handle;
- state->domain = domain;
- state->name = name;
- state->gid = gid;
-
- subreq = sysdb_check_handle_send(state, ev, sysdb, handle);
- if (!subreq) {
- DEBUG(1, ("sysdb_check_handle_send failed.\n"));
- tevent_req_error(req, ENOMEM);
- tevent_req_post(req, ev);
- return req;
- }
- tevent_req_set_callback(subreq, sysdb_delete_group_check_handle, req);
-
- return req;
-}
-
-void sysdb_delete_group_check_handle(struct tevent_req *subreq)
+int sysdb_delete_group(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *sysdb,
+ struct sss_domain_info *domain,
+ const char *name, gid_t gid)
{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- struct sysdb_delete_group_state *state = tevent_req_data(req,
- struct sysdb_delete_group_state);
+ TALLOC_CTX *tmpctx;
struct ldb_message *msg;
int ret;
- ret = sysdb_check_handle_recv(subreq, state, &state->handle);
- talloc_zfree(subreq);
- if (ret != EOK) {
- tevent_req_error(req, ret);
- return;
+ tmpctx = talloc_new(mem_ctx);
+ if (!tmpctx) {
+ return ENOMEM;
}
- if (state->name) {
- ret = sysdb_search_group_by_name(state, state->handle->ctx,
- state->domain, state->name,
- NULL, &msg);
+ if (name) {
+ ret = sysdb_search_group_by_name(tmpctx, sysdb,
+ domain, name, NULL, &msg);
} else {
- ret = sysdb_search_group_by_gid(state, state->handle->ctx,
- state->domain, state->gid,
- NULL, &msg);
+ ret = sysdb_search_group_by_gid(tmpctx, sysdb,
+ domain, gid, NULL, &msg);
}
if (ret) {
- tevent_req_error(req, ret);
- return;
+ goto fail;
}
- if (state->name && state->gid) {
+ if (name && gid) {
/* verify name/gid match */
- const char *name;
- uint64_t gid;
+ const char *c_name;
+ uint64_t c_gid;
- name = ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
- gid = ldb_msg_find_attr_as_uint64(msg, SYSDB_GIDNUM, 0);
- if (name == NULL || gid == 0) {
+ c_name = ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
+ c_gid = ldb_msg_find_attr_as_uint64(msg, SYSDB_GIDNUM, 0);
+ if (c_name == NULL || c_gid == 0) {
DEBUG(2, ("Attribute is missing but this should never happen!\n"));
- tevent_req_error(req, EFAULT);
- return;
+ ret = EFAULT;
+ goto fail;
}
- if (strcmp(state->name, name) || state->gid != gid) {
+ if (strcmp(name, c_name) || gid != c_gid) {
/* this is not the entry we are looking for */
- tevent_req_error(req, EINVAL);
- return;
+ ret = EINVAL;
+ goto fail;
}
}
- ret = sysdb_delete_entry(state->handle->ctx, msg->dn, false);
+ ret = sysdb_delete_entry(sysdb, msg->dn, false);
if (ret) {
- tevent_req_error(req, ret);
- return;
+ goto fail;
}
- tevent_req_done(req);
-}
+ talloc_zfree(tmpctx);
+ return EOK;
-int sysdb_delete_group_recv(struct tevent_req *req)
-{
- return sysdb_op_default_recv(req);
+fail:
+ DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
+ talloc_zfree(tmpctx);
+ return ret;
}
/* ========= Authentication against cached password ============ */
diff --git a/src/providers/ldap/ldap_id.c b/src/providers/ldap/ldap_id.c
index 8ac09893..15e2f30a 100644
--- a/src/providers/ldap/ldap_id.c
+++ b/src/providers/ldap/ldap_id.c
@@ -248,7 +248,6 @@ struct groups_get_state {
static void groups_get_connect_done(struct tevent_req *subreq);
static void groups_get_done(struct tevent_req *subreq);
-static void groups_get_delete(struct tevent_req *subreq);
struct tevent_req *groups_get_send(TALLOC_CTX *memctx,
struct tevent_context *ev,
@@ -391,15 +390,13 @@ static void groups_get_done(struct tevent_req *subreq)
switch (state->filter_type) {
case BE_FILTER_NAME:
- subreq = sysdb_delete_group_send(state, state->ev,
- state->sysdb, NULL,
- state->domain, state->name, 0);
- if (!subreq) {
- tevent_req_error(req, ENOMEM);
+ ret = sysdb_delete_group(state, state->sysdb,
+ state->domain, state->name, 0);
+ if (ret) {
+ tevent_req_error(req, ret);
return;
}
- tevent_req_set_callback(subreq, groups_get_delete, req);
- return;
+ break;
case BE_FILTER_IDNUM:
errno = 0;
@@ -409,15 +406,13 @@ static void groups_get_done(struct tevent_req *subreq)
return;
}
- subreq = sysdb_delete_group_send(state, state->ev,
- state->sysdb, NULL,
- state->domain, NULL, gid);
- if (!subreq) {
- tevent_req_error(req, ENOMEM);
+ ret = sysdb_delete_group(state, state->sysdb,
+ state->domain, NULL, gid);
+ if (ret) {
+ tevent_req_error(req, ret);
return;
}
- tevent_req_set_callback(subreq, groups_get_delete, req);
- return;
+ break;
default:
tevent_req_error(req, EINVAL);
@@ -428,24 +423,6 @@ static void groups_get_done(struct tevent_req *subreq)
tevent_req_done(req);
}
-static void groups_get_delete(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- struct groups_get_state *state = tevent_req_data(req,
- struct groups_get_state);
- int ret;
-
- ret = sysdb_delete_group_recv(subreq);
- talloc_zfree(subreq);
- if (ret) {
- DEBUG(2, ("Group (%s) delete returned %d (%s)\n",
- state->name, ret, strerror(ret)));
- }
-
- tevent_req_done(req);
-}
-
int groups_get_recv(struct tevent_req *req)
{
TEVENT_REQ_RETURN_ON_ERROR(req);
diff --git a/src/providers/ldap/ldap_id_cleanup.c b/src/providers/ldap/ldap_id_cleanup.c
index 6b37950e..e92545d9 100644
--- a/src/providers/ldap/ldap_id_cleanup.c
+++ b/src/providers/ldap/ldap_id_cleanup.c
@@ -376,10 +376,6 @@ struct cleanup_groups_state {
};
static void cleanup_groups_process(struct tevent_req *subreq);
-static void cleanup_groups_check_users(struct tevent_req *req);
-static void cleanup_groups_next(struct tevent_req *req);
-static void cleanup_groups_delete(struct tevent_req *req);
-static void cleanup_groups_delete_done(struct tevent_req *subreq);
static struct tevent_req *cleanup_groups_send(TALLOC_CTX *memctx,
struct tevent_context *ev,
@@ -432,7 +428,12 @@ static void cleanup_groups_process(struct tevent_req *subreq)
struct tevent_req);
struct cleanup_groups_state *state = tevent_req_data(req,
struct cleanup_groups_state);
+ const char *subfilter;
+ const char *dn;
+ struct ldb_message **msgs;
+ size_t count;
int ret;
+ int i;
ret = sysdb_search_groups_recv(subreq, state, &state->count, &state->msgs);
talloc_zfree(subreq);
@@ -449,103 +450,55 @@ static void cleanup_groups_process(struct tevent_req *subreq)
if (state->count == 0) {
tevent_req_done(req);
- }
-
- cleanup_groups_check_users(req);
-}
-
-static void cleanup_groups_check_users(struct tevent_req *req)
-{
- struct cleanup_groups_state *state = tevent_req_data(req,
- struct cleanup_groups_state);
- const char *subfilter;
- const char *dn;
- struct ldb_message **msgs;
- size_t count;
- int ret;
-
- dn = ldb_dn_get_linearized(state->msgs[state->cur]->dn);
- if (!dn) {
- tevent_req_error(req, EINVAL);
return;
}
- subfilter = talloc_asprintf(state, "(%s=%s)",
- SYSDB_MEMBEROF, dn);
- if (!subfilter) {
- DEBUG(2, ("Failed to build filter\n"));
- tevent_req_error(req, ENOMEM);
- }
-
- ret = sysdb_search_users(state, state->sysdb,
- state->domain, subfilter, NULL, &count, &msgs);
- if (ret != EOK) {
- if (ret == ENOENT) {
- cleanup_groups_delete(req);
+ for (i = 0; i < state->count; i++) {
+ dn = ldb_dn_get_linearized(state->msgs[i]->dn);
+ if (!dn) {
+ tevent_req_error(req, EINVAL);
return;
}
- tevent_req_error(req, ret);
- return;
- }
-
- cleanup_groups_next(req);
-}
-
-static void cleanup_groups_next(struct tevent_req *req)
-{
- struct cleanup_groups_state *state = tevent_req_data(req,
- struct cleanup_groups_state);
-
- state->cur++;
- if (state->cur < state->count) {
- cleanup_groups_check_users(req);
- return;
- }
- tevent_req_done(req);
-}
-
-static void cleanup_groups_delete(struct tevent_req *req)
-{
- struct tevent_req *subreq;
- struct cleanup_groups_state *state = tevent_req_data(req,
- struct cleanup_groups_state);
- const char *name;
+ subfilter = talloc_asprintf(state, "(%s=%s)",
+ SYSDB_MEMBEROF, dn);
+ if (!subfilter) {
+ DEBUG(2, ("Failed to build filter\n"));
+ tevent_req_error(req, ENOMEM);
+ return;
+ }
- name = ldb_msg_find_attr_as_string(state->msgs[state->cur],
- SYSDB_NAME, NULL);
- if (!name) {
- DEBUG(2, ("Entry %s has no Name Attribute ?!?\n",
- ldb_dn_get_linearized(state->msgs[state->cur]->dn)));
- tevent_req_error(req, EFAULT);
- return;
- }
+ ret = sysdb_search_users(state, state->sysdb,
+ state->domain, subfilter, NULL,
+ &count, &msgs);
+ if (ret == ENOENT) {
+ const char *name;
+
+ name = ldb_msg_find_attr_as_string(state->msgs[i],
+ SYSDB_NAME, NULL);
+ if (!name) {
+ DEBUG(2, ("Entry %s has no Name Attribute ?!?\n",
+ ldb_dn_get_linearized(state->msgs[i]->dn)));
+ tevent_req_error(req, EFAULT);
+ return;
+ }
- DEBUG(8, ("About to delete group %s\n", name));
- subreq = sysdb_delete_group_send(state, state->ev,
- state->sysdb, NULL,
+ DEBUG(8, ("About to delete group %s\n", name));
+ ret = sysdb_delete_group(state, state->sysdb,
state->domain, name, 0);
- if (!subreq) {
- tevent_req_error(req, ENOMEM);
- return;
- }
- tevent_req_set_callback(subreq, cleanup_groups_delete_done, req);
-}
-
-static void cleanup_groups_delete_done(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- int ret;
-
- ret = sysdb_delete_group_recv(subreq);
- talloc_zfree(subreq);
- if (ret) {
- DEBUG(2, ("Group delete returned %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- return;
+ if (ret) {
+ DEBUG(2, ("Group delete returned %d (%s)\n",
+ ret, strerror(ret)));
+ tevent_req_error(req, ret);
+ return;
+ }
+ }
+ if (ret != EOK) {
+ tevent_req_error(req, ret);
+ return;
+ }
+ talloc_zfree(msgs);
}
- cleanup_groups_next(req);
+ tevent_req_done(req);
}
-
diff --git a/src/providers/proxy.c b/src/providers/proxy.c
index 7b56a95e..42a19ec0 100644
--- a/src/providers/proxy.c
+++ b/src/providers/proxy.c
@@ -1032,7 +1032,6 @@ fail:
/* =Getgrgid-wrapper======================================================*/
static void get_gr_gid_process(struct tevent_req *subreq);
-static void get_gr_gid_remove_done(struct tevent_req *subreq);
static struct tevent_req *get_gr_gid_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
@@ -1196,39 +1195,12 @@ again:
DEBUG(7, ("Group %d does not exist (or is invalid) on remote server,"
" deleting!\n", state->gid));
- subreq = sysdb_delete_group_send(state, state->ev,
- NULL, state->handle,
- state->domain,
- NULL, state->gid);
- if (!subreq) {
- tevent_req_error(req, ENOMEM);
+ ret = sysdb_delete_group(state, state->sysdb,
+ state->domain, NULL, state->gid);
+ if (ret) {
+ tevent_req_error(req, ret);
return;
}
- tevent_req_set_callback(subreq, get_gr_gid_remove_done, req);
- return;
- }
-
- subreq = sysdb_transaction_commit_send(state, state->ev, state->handle);
- if (!subreq) {
- tevent_req_error(req, ENOMEM);
- return;
- }
- tevent_req_set_callback(subreq, proxy_default_done, req);
-}
-
-static void get_gr_gid_remove_done(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- struct proxy_state *state = tevent_req_data(req,
- struct proxy_state);
- int ret;
-
- ret = sysdb_delete_group_recv(subreq);
- talloc_zfree(subreq);
- if (ret && ret != ENOENT) {
- tevent_req_error(req, ret);
- return;
}
subreq = sysdb_transaction_commit_send(state, state->ev, state->handle);
@@ -1454,7 +1426,6 @@ static struct tevent_req *get_group_from_gid_send(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
gid_t gid);
static int get_group_from_gid_recv(struct tevent_req *req);
-static void get_group_from_gid_send_del_done(struct tevent_req *subreq);
static struct tevent_req *get_initgr_send(TALLOC_CTX *mem_ctx,
@@ -1780,7 +1751,7 @@ static struct tevent_req *get_group_from_gid_send(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
gid_t gid)
{
- struct tevent_req *req, *subreq;
+ struct tevent_req *req;
struct proxy_state *state;
struct sss_domain_info *dom = ctx->be->domain;
enum nss_status status;
@@ -1881,8 +1852,6 @@ again:
if (ret) {
goto fail;
}
- tevent_req_done(req);
- tevent_req_post(req, ev);
break;
case NSS_STATUS_UNAVAIL:
@@ -1898,17 +1867,15 @@ again:
}
if (delete_group) {
- subreq = sysdb_delete_group_send(state, state->ev,
- NULL, state->handle,
- state->domain,
- NULL, state->gid);
- if (!subreq) {
- ret = ENOMEM;
+ ret = sysdb_delete_group(state, state->sysdb,
+ state->domain, NULL, state->gid);
+ if (ret) {
goto fail;
}
- tevent_req_set_callback(subreq, get_group_from_gid_send_del_done, req);
}
+ tevent_req_done(req);
+ tevent_req_post(req, ev);
return req;
fail:
@@ -1917,22 +1884,6 @@ fail:
return req;
}
-static void get_group_from_gid_send_del_done(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- int ret;
-
- ret = sysdb_delete_group_recv(subreq);
- talloc_zfree(subreq);
- if (ret && ret != ENOENT) {
- tevent_req_error(req, ret);
- return;
- }
-
- tevent_req_done(req);
-}
-
static int get_group_from_gid_recv(struct tevent_req *req)
{
TEVENT_REQ_RETURN_ON_ERROR(req);
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
index b01404ff..9b935d13 100644
--- a/src/tests/sysdb-tests.c
+++ b/src/tests/sysdb-tests.c
@@ -306,12 +306,9 @@ static void test_remove_user_by_uid(struct tevent_req *req)
return test_return(data, ret);
}
-static void test_remove_nonexistent_group_done(struct tevent_req *subreq);
-
static void test_remove_nonexistent_group(struct tevent_req *req)
{
struct test_data *data = tevent_req_callback_data(req, struct test_data);
- struct tevent_req *subreq;
int ret;
ret = sysdb_transaction_recv(req, data, &data->handle);
@@ -319,23 +316,8 @@ static void test_remove_nonexistent_group(struct tevent_req *req)
return test_return(data, ret);
}
- subreq = sysdb_delete_group_send(data, data->ev,
- NULL, data->handle,
- data->ctx->domain,
- NULL, data->uid);
- if (!subreq) return test_return(data, ENOMEM);
-
- tevent_req_set_callback(subreq, test_remove_nonexistent_group_done, data);
-}
-
-static void test_remove_nonexistent_group_done(struct tevent_req *subreq)
-{
- struct test_data *data = tevent_req_callback_data(subreq,
- struct test_data);
- int ret;
-
- ret = sysdb_delete_group_recv(subreq);
- talloc_zfree(subreq);
+ ret = sysdb_delete_group(data, data->handle->ctx,
+ data->ctx->domain, NULL, data->uid);
return test_return(data, ret);
}
@@ -409,11 +391,9 @@ static void test_remove_group(struct tevent_req *req)
return test_return(data, ret);
}
-static void test_remove_group_by_gid_done(struct tevent_req *subreq);
static void test_remove_group_by_gid(struct tevent_req *req)
{
struct test_data *data = tevent_req_callback_data(req, struct test_data);
- struct tevent_req *subreq;
int ret;
ret = sysdb_transaction_recv(req, data, &data->handle);
@@ -421,24 +401,11 @@ static void test_remove_group_by_gid(struct tevent_req *req)
return test_return(data, ret);
}
- subreq = sysdb_delete_group_send(data, data->ev,
- NULL, data->handle,
- data->ctx->domain,
- NULL, data->gid);
- if (!subreq) return test_return(data, ENOMEM);
-
- tevent_req_set_callback(subreq, test_remove_group_by_gid_done, data);
-}
-
-static void test_remove_group_by_gid_done(struct tevent_req *subreq)
-{
- struct test_data *data = tevent_req_callback_data(subreq,
- struct test_data);
- int ret;
-
- ret = sysdb_delete_group_recv(subreq);
- if (ret == ENOENT) ret = EOK;
- talloc_zfree(subreq);
+ ret = sysdb_delete_group(data, data->handle->ctx,
+ data->ctx->domain, NULL, data->gid);
+ if (ret == ENOENT) {
+ ret = EOK;
+ }
return test_return(data, ret);
}