diff options
author | Simo Sorce <ssorce@redhat.com> | 2010-03-03 15:29:39 -0500 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2010-04-12 09:22:14 -0400 |
commit | 3b3dc1a8ad19100951d19abe4038791f01faa0b7 (patch) | |
tree | 17b006f23b47701fa4e90da5df3bd4963602b9b7 /src/providers | |
parent | ed80c73efa51780a39dfc9c72821cf88e95d264c (diff) | |
download | sssd-3b3dc1a8ad19100951d19abe4038791f01faa0b7.tar.gz sssd-3b3dc1a8ad19100951d19abe4038791f01faa0b7.tar.xz sssd-3b3dc1a8ad19100951d19abe4038791f01faa0b7.zip |
sysdb: delete sysdb_delete_group
Diffstat (limited to 'src/providers')
-rw-r--r-- | src/providers/ldap/ldap_id.c | 43 | ||||
-rw-r--r-- | src/providers/ldap/ldap_id_cleanup.c | 137 | ||||
-rw-r--r-- | src/providers/proxy.c | 69 |
3 files changed, 65 insertions, 184 deletions
diff --git a/src/providers/ldap/ldap_id.c b/src/providers/ldap/ldap_id.c index 8ac09893c..15e2f30ad 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 6b37950e0..e92545d93 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 7b56a95ec..42a19ec0d 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); |