summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/db/sysdb.h9
-rw-r--r--server/db/sysdb_ops.c23
-rw-r--r--server/providers/proxy.c15
-rw-r--r--server/tests/sysdb-tests.c156
4 files changed, 182 insertions, 21 deletions
diff --git a/server/db/sysdb.h b/server/db/sysdb.h
index d6ecb2ae..df2a946e 100644
--- a/server/db/sysdb.h
+++ b/server/db/sysdb.h
@@ -274,7 +274,8 @@ int sysdb_get_user_attr(TALLOC_CTX *mem_ctx,
struct tevent_req *sysdb_delete_entry_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct sysdb_handle *handle,
- struct ldb_dn *dn);
+ struct ldb_dn *dn,
+ bool ignore_not_found);
int sysdb_delete_entry_recv(struct tevent_req *req);
/* Search Entry */
@@ -313,7 +314,8 @@ struct tevent_req *sysdb_delete_user_by_uid_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct sysdb_handle *handle,
struct sss_domain_info *domain,
- uid_t uid);
+ uid_t uid,
+ bool ignore_not_found);
int sysdb_delete_user_by_uid_recv(struct tevent_req *req);
/* Search Group (gy gid or name) */
@@ -340,7 +342,8 @@ struct tevent_req *sysdb_delete_group_by_gid_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct sysdb_handle *handle,
struct sss_domain_info *domain,
- gid_t gid);
+ gid_t gid,
+ bool ignore_not_found);
int sysdb_delete_group_by_gid_recv(struct tevent_req *req);
/* Replace entry attrs */
diff --git a/server/db/sysdb_ops.c b/server/db/sysdb_ops.c
index c172b70e..8610e634 100644
--- a/server/db/sysdb_ops.c
+++ b/server/db/sysdb_ops.c
@@ -245,7 +245,8 @@ static int sysdb_op_default_recv(struct tevent_req *req)
struct tevent_req *sysdb_delete_entry_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct sysdb_handle *handle,
- struct ldb_dn *dn)
+ struct ldb_dn *dn,
+ bool ignore_not_found)
{
struct tevent_req *req, *subreq;
struct sysdb_op_state *state;
@@ -257,7 +258,7 @@ struct tevent_req *sysdb_delete_entry_send(TALLOC_CTX *mem_ctx,
state->ev = ev;
state->handle = handle;
- state->ignore_not_found = true;
+ state->ignore_not_found = ignore_not_found;
state->ldbreply = NULL;
ret = ldb_build_del_req(&ldbreq, handle->ctx->ldb, state, dn,
@@ -613,7 +614,8 @@ struct tevent_req *sysdb_delete_user_by_uid_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct sysdb_handle *handle,
struct sss_domain_info *domain,
- uid_t uid)
+ uid_t uid,
+ bool ignore_not_found)
{
struct tevent_req *req, *subreq;
struct sysdb_op_state *state;
@@ -623,7 +625,7 @@ struct tevent_req *sysdb_delete_user_by_uid_send(TALLOC_CTX *mem_ctx,
state->ev = ev;
state->handle = handle;
- state->ignore_not_found = true;
+ state->ignore_not_found = ignore_not_found;
state->ldbreply = NULL;
subreq = sysdb_search_user_by_uid_send(state, ev, NULL, handle,
@@ -656,7 +658,9 @@ static void sysdb_delete_user_by_uid_found(struct tevent_req *subreq)
return;
}
- subreq = sysdb_delete_entry_send(state, state->ev, state->handle, msg->dn);
+ subreq = sysdb_delete_entry_send(state, state->ev,
+ state->handle, msg->dn,
+ state->ignore_not_found);
if (!subreq) {
tevent_req_error(req, ENOMEM);
return;
@@ -896,7 +900,8 @@ struct tevent_req *sysdb_delete_group_by_gid_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct sysdb_handle *handle,
struct sss_domain_info *domain,
- gid_t gid)
+ gid_t gid,
+ bool ignore_not_found)
{
struct tevent_req *req, *subreq;
struct sysdb_op_state *state;
@@ -906,7 +911,7 @@ struct tevent_req *sysdb_delete_group_by_gid_send(TALLOC_CTX *mem_ctx,
state->ev = ev;
state->handle = handle;
- state->ignore_not_found = true;
+ state->ignore_not_found = ignore_not_found;
state->ldbreply = NULL;
subreq = sysdb_search_group_by_gid_send(state, ev, NULL, handle,
@@ -939,7 +944,9 @@ static void sysdb_delete_group_by_gid_found(struct tevent_req *subreq)
return;
}
- subreq = sysdb_delete_entry_send(state, state->ev, state->handle, msg->dn);
+ subreq = sysdb_delete_entry_send(state, state->ev,
+ state->handle, msg->dn,
+ state->ignore_not_found);
if (!subreq) {
tevent_req_error(req, ENOMEM);
return;
diff --git a/server/providers/proxy.c b/server/providers/proxy.c
index ddfbe393..106530fc 100644
--- a/server/providers/proxy.c
+++ b/server/providers/proxy.c
@@ -477,7 +477,7 @@ static void get_pw_name_process(struct tevent_req *subreq)
return;
}
- subreq = sysdb_delete_entry_send(state, state->ev, state->handle, dn);
+ subreq = sysdb_delete_entry_send(state, state->ev, state->handle, dn, true);
if (!subreq) {
tevent_req_error(req, ENOMEM);
return;
@@ -650,7 +650,8 @@ static void get_pw_uid_process(struct tevent_req *subreq)
subreq = sysdb_delete_user_by_uid_send(state, state->ev,
state->handle,
state->domain,
- state->uid);
+ state->uid,
+ true);
if (!subreq) {
tevent_req_error(req, ENOMEM);
return;
@@ -979,7 +980,7 @@ again:
return;
}
- subreq = sysdb_delete_entry_send(state, state->ev, state->handle, dn);
+ subreq = sysdb_delete_entry_send(state, state->ev, state->handle, dn, true);
if (!subreq) {
tevent_req_error(req, ENOMEM);
return;
@@ -1166,7 +1167,8 @@ again:
subreq = sysdb_delete_group_by_gid_send(state, state->ev,
state->handle,
state->domain,
- state->gid);
+ state->gid,
+ true);
if (!subreq) {
tevent_req_error(req, ENOMEM);
return;
@@ -1496,7 +1498,7 @@ static void get_initgr_process(struct tevent_req *subreq)
return;
}
- subreq = sysdb_delete_entry_send(state, state->ev, state->handle, dn);
+ subreq = sysdb_delete_entry_send(state, state->ev, state->handle, dn, true);
if (!subreq) {
tevent_req_error(req, ENOMEM);
return;
@@ -1797,7 +1799,8 @@ again:
subreq = sysdb_delete_group_by_gid_send(state, state->ev,
state->handle,
state->domain,
- state->gid);
+ state->gid,
+ true);
if (!subreq) {
ret = ENOMEM;
goto fail;
diff --git a/server/tests/sysdb-tests.c b/server/tests/sysdb-tests.c
index b2dc8ab3..72f80edc 100644
--- a/server/tests/sysdb-tests.c
+++ b/server/tests/sysdb-tests.c
@@ -313,7 +313,7 @@ static void test_remove_user(struct tevent_req *req)
user_dn = sysdb_user_dn(data->ctx->sysdb, data, "LOCAL", data->username);
if (!user_dn) return test_return(data, ENOMEM);
- subreq = sysdb_delete_entry_send(data, data->ev, data->handle, user_dn);
+ subreq = sysdb_delete_entry_send(data, data->ev, data->handle, user_dn, true);
if (!subreq) return test_return(data, ENOMEM);
tevent_req_set_callback(subreq, test_remove_user_done, data);
@@ -346,7 +346,8 @@ static void test_remove_user_by_uid(struct tevent_req *req)
subreq = sysdb_delete_user_by_uid_send(data,
data->ev, data->handle,
- data->domain, data->uid);
+ data->domain, data->uid,
+ true);
if (!subreq) return test_return(data, ENOMEM);
tevent_req_set_callback(subreq, test_remove_user_by_uid_done, data);
@@ -364,6 +365,74 @@ static void test_remove_user_by_uid_done(struct tevent_req *subreq)
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);
+ if (ret != EOK) {
+ return test_return(data, ret);
+ }
+
+ subreq = sysdb_delete_group_by_gid_send(data,
+ data->ev, data->handle,
+ data->domain, data->uid,
+ false);
+ 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_by_gid_recv(subreq);
+ talloc_zfree(subreq);
+
+ return test_return(data, ret);
+}
+
+static void test_remove_nonexistent_user_done(struct tevent_req *subreq);
+
+static void test_remove_nonexistent_user(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);
+ if (ret != EOK) {
+ return test_return(data, ret);
+ }
+
+ subreq = sysdb_delete_user_by_uid_send(data,
+ data->ev, data->handle,
+ data->domain, data->uid,
+ false);
+ if (!subreq) return test_return(data, ENOMEM);
+
+ tevent_req_set_callback(subreq, test_remove_nonexistent_user_done, data);
+}
+
+static void test_remove_nonexistent_user_done(struct tevent_req *subreq)
+{
+ struct test_data *data = tevent_req_callback_data(subreq,
+ struct test_data);
+ int ret;
+
+ ret = sysdb_delete_user_by_uid_recv(subreq);
+ talloc_zfree(subreq);
+
+ return test_return(data, ret);
+}
+
static void test_add_group_done(struct tevent_req *subreq);
static void test_add_group(struct tevent_req *req)
@@ -448,7 +517,7 @@ static void test_remove_group(struct tevent_req *req)
group_dn = sysdb_group_dn(data->ctx->sysdb, data, "LOCAL", data->groupname);
if (!group_dn) return test_return(data, ENOMEM);
- subreq = sysdb_delete_entry_send(data, data->ev, data->handle, group_dn);
+ subreq = sysdb_delete_entry_send(data, data->ev, data->handle, group_dn, true);
if (!subreq) return test_return(data, ENOMEM);
tevent_req_set_callback(subreq, test_remove_group_done, data);
@@ -479,7 +548,8 @@ static void test_remove_group_by_gid(struct tevent_req *req)
}
subreq = sysdb_delete_group_by_gid_send(data, data->ev, data->handle,
- data->domain, data->gid);
+ data->domain, data->gid,
+ true);
if (!subreq) return test_return(data, ENOMEM);
tevent_req_set_callback(subreq, test_remove_group_by_gid_done, data);
@@ -1478,6 +1548,78 @@ START_TEST (test_sysdb_remove_group_member)
}
END_TEST
+START_TEST (test_sysdb_remove_nonexistent_user)
+{
+ struct sysdb_test_ctx *test_ctx;
+ struct test_data *data;
+ struct tevent_req *req;
+ int ret;
+
+ /* Setup */
+ ret = setup_sysdb_tests(&test_ctx);
+ if (ret != EOK) {
+ fail("Could not set up the test");
+ return;
+ }
+
+ data = talloc_zero(test_ctx, struct test_data);
+ data->ctx = test_ctx;
+ data->ev = test_ctx->ev;
+ data->uid = 12345;
+ data->domain = get_local_domain(test_ctx->domains);
+
+ req = sysdb_transaction_send(data, data->ev, test_ctx->sysdb);
+ if (!req) {
+ ret = ENOMEM;
+ }
+
+ if (ret == EOK) {
+ tevent_req_set_callback(req, test_remove_nonexistent_user, data);
+
+ ret = test_loop(data);
+ }
+
+ fail_if(ret != ENOENT, "Unexpected return code %d, expected ENOENT", ret);
+ talloc_free(test_ctx);
+}
+END_TEST
+
+START_TEST (test_sysdb_remove_nonexistent_group)
+{
+ struct sysdb_test_ctx *test_ctx;
+ struct test_data *data;
+ struct tevent_req *req;
+ int ret;
+
+ /* Setup */
+ ret = setup_sysdb_tests(&test_ctx);
+ if (ret != EOK) {
+ fail("Could not set up the test");
+ return;
+ }
+
+ data = talloc_zero(test_ctx, struct test_data);
+ data->ctx = test_ctx;
+ data->ev = test_ctx->ev;
+ data->uid = 12345;
+ data->domain = get_local_domain(test_ctx->domains);
+
+ req = sysdb_transaction_send(data, data->ev, test_ctx->sysdb);
+ if (!req) {
+ ret = ENOMEM;
+ }
+
+ if (ret == EOK) {
+ tevent_req_set_callback(req, test_remove_nonexistent_group, data);
+
+ ret = test_loop(data);
+ }
+
+ fail_if(ret != ENOENT, "Unexpected return code %d, expected ENOENT", ret);
+ talloc_free(test_ctx);
+}
+END_TEST
+
Suite *create_sysdb_suite(void)
{
Suite *s = suite_create("sysdb");
@@ -1544,6 +1686,12 @@ Suite *create_sysdb_suite(void)
/* Remove the groups by name */
tcase_add_loop_test(tc_sysdb, test_sysdb_remove_local_group, 28010, 28020);
+ /* test the ignore_not_found parameter for users */
+ tcase_add_test(tc_sysdb, test_sysdb_remove_nonexistent_user);
+
+ /* test the ignore_not_found parameter for groups */
+ tcase_add_test(tc_sysdb, test_sysdb_remove_nonexistent_group);
+
/* Add all test cases to the test suite */
suite_add_tcase(s, tc_sysdb);