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/ldap | |
parent | ed80c73efa51780a39dfc9c72821cf88e95d264c (diff) | |
download | sssd-3b3dc1a8ad19100951d19abe4038791f01faa0b7.tar.gz sssd-3b3dc1a8ad19100951d19abe4038791f01faa0b7.tar.bz2 sssd-3b3dc1a8ad19100951d19abe4038791f01faa0b7.zip |
sysdb: delete sysdb_delete_group
Diffstat (limited to 'src/providers/ldap')
-rw-r--r-- | src/providers/ldap/ldap_id.c | 43 | ||||
-rw-r--r-- | src/providers/ldap/ldap_id_cleanup.c | 137 |
2 files changed, 55 insertions, 125 deletions
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); } - |