summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimo Sorce <ssorce@redhat.com>2010-03-02 23:11:59 -0500
committerStephen Gallagher <sgallagh@redhat.com>2010-04-12 09:22:14 -0400
commit16ef1ec0d10d24703351d02bbd7d0c2255da4359 (patch)
tree7c5d36c1f0d16ac3e20cef817f055e536b62f204 /src
parentcdc174f69d071c26257275e2478e3c8c08b95306 (diff)
downloadsssd-16ef1ec0d10d24703351d02bbd7d0c2255da4359.tar.gz
sssd-16ef1ec0d10d24703351d02bbd7d0c2255da4359.tar.bz2
sssd-16ef1ec0d10d24703351d02bbd7d0c2255da4359.zip
sysdb: convert sysdb_search_users
Diffstat (limited to 'src')
-rw-r--r--src/db/sysdb.h16
-rw-r--r--src/db/sysdb_ops.c121
-rw-r--r--src/providers/ldap/ldap_id_cleanup.c104
3 files changed, 72 insertions, 169 deletions
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index f82f3115..e60777c8 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -557,15 +557,13 @@ int sysdb_asq_search(TALLOC_CTX *mem_ctx,
size_t *msgs_count,
struct ldb_message ***msgs);
-struct tevent_req *sysdb_search_users_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- struct sysdb_ctx *sysdb,
- struct sysdb_handle *handle,
- struct sss_domain_info *domain,
- const char *sub_filter,
- const char **attrs);
-int sysdb_search_users_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
- size_t *msgs_count, struct ldb_message ***msgs);
+int sysdb_search_users(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *sysdb,
+ struct sss_domain_info *domain,
+ const char *sub_filter,
+ const char **attrs,
+ size_t *msgs_count,
+ struct ldb_message ***msgs);
struct tevent_req *sysdb_delete_user_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index b6fe166a..0eb12a11 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -1752,120 +1752,55 @@ fail:
/* =Search-Users-with-Custom-Filter====================================== */
-struct sysdb_search_users_state {
- struct tevent_context *ev;
- struct sysdb_handle *handle;
- struct sss_domain_info *domain;
- const char *sub_filter;
- const char **attrs;
-
- struct ldb_message **msgs;
- size_t msgs_count;
-};
-
-static void sysdb_search_users_check_handle(struct tevent_req *subreq);
-
-struct tevent_req *sysdb_search_users_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- struct sysdb_ctx *sysdb,
- struct sysdb_handle *handle,
- struct sss_domain_info *domain,
- const char *sub_filter,
- const char **attrs)
-{
- struct tevent_req *req, *subreq;
- struct sysdb_search_users_state *state;
- int ret;
-
- req = tevent_req_create(mem_ctx, &state, struct sysdb_search_users_state);
- if (req == NULL) {
- DEBUG(1, ("tevent_req_create failed.\n"));
- return NULL;
- }
-
- state->ev = ev;
- state->handle = handle;
- state->domain = domain;
- state->sub_filter = sub_filter;
- state->attrs = attrs;
-
- state->msgs_count = 0;
- state->msgs = NULL;
-
- subreq = sysdb_check_handle_send(state, ev, sysdb, handle);
- if (!subreq) {
- DEBUG(1, ("sysdb_check_handle_send failed.\n"));
- ret = ENOMEM;
- goto fail;
- }
- tevent_req_set_callback(subreq, sysdb_search_users_check_handle, req);
-
- return req;
-
-fail:
- tevent_req_error(req, ret);
- tevent_req_post(req, ev);
- return req;
-}
-
-static void sysdb_search_users_check_handle(struct tevent_req *subreq)
+int sysdb_search_users(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *sysdb,
+ struct sss_domain_info *domain,
+ const char *sub_filter,
+ const char **attrs,
+ size_t *msgs_count,
+ struct ldb_message ***msgs)
{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- struct sysdb_search_users_state *state = tevent_req_data(req,
- struct sysdb_search_users_state);
+ TALLOC_CTX *tmpctx;
struct ldb_dn *basedn;
char *filter;
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;
}
- basedn = ldb_dn_new_fmt(state, state->handle->ctx->ldb,
- SYSDB_TMPL_USER_BASE, state->domain->name);
+ basedn = ldb_dn_new_fmt(tmpctx, sysdb->ldb,
+ SYSDB_TMPL_USER_BASE, domain->name);
if (!basedn) {
DEBUG(2, ("Failed to build base dn\n"));
- tevent_req_error(req, ENOMEM);
- return;
+ ret = ENOMEM;
+ goto fail;
}
- filter = talloc_asprintf(state, "(&(%s)%s)",
- SYSDB_UC, state->sub_filter);
+ filter = talloc_asprintf(tmpctx, "(&(%s)%s)", SYSDB_UC, sub_filter);
if (!filter) {
DEBUG(2, ("Failed to build filter\n"));
- tevent_req_error(req, ENOMEM);
- return;
+ ret = ENOMEM;
+ goto fail;
}
DEBUG(6, ("Search users with filter: %s\n", filter));
- ret = sysdb_search_entry(state, state->handle->ctx, basedn,
- LDB_SCOPE_SUBTREE, filter, state->attrs,
- &state->msgs_count, &state->msgs);
+ ret = sysdb_search_entry(mem_ctx, sysdb, basedn,
+ LDB_SCOPE_SUBTREE, filter, attrs,
+ msgs_count, msgs);
if (ret) {
- tevent_req_error(req, ret);
- return;
+ goto fail;
}
- tevent_req_done(req);
-}
-
-int sysdb_search_users_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
- size_t *msgs_count, struct ldb_message ***msgs)
-{
- struct sysdb_search_users_state *state = tevent_req_data(req,
- struct sysdb_search_users_state);
-
- TEVENT_REQ_RETURN_ON_ERROR(req);
-
- *msgs_count = state->msgs_count;
- *msgs = talloc_move(mem_ctx, &state->msgs);
-
+ talloc_zfree(tmpctx);
return EOK;
+
+fail:
+ DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
+ talloc_zfree(tmpctx);
+ return ret;
}
/* =Delete-User-by-Name-OR-uid============================================ */
diff --git a/src/providers/ldap/ldap_id_cleanup.c b/src/providers/ldap/ldap_id_cleanup.c
index 53c9501f..fa6d907b 100644
--- a/src/providers/ldap/ldap_id_cleanup.c
+++ b/src/providers/ldap/ldap_id_cleanup.c
@@ -262,23 +262,23 @@ struct cleanup_users_state {
int cur;
};
-static void cleanup_users_process(struct tevent_req *subreq);
static int cleanup_users_logged_in(hash_table_t *table,
const struct ldb_message *msg);
-static void cleanup_users_delete(struct tevent_req *req);
-static void cleanup_users_next(struct tevent_req *req);
+static int cleanup_users_delete(struct tevent_req *req);
+static int cleanup_users_next(struct tevent_req *req);
static void cleanup_users_delete_done(struct tevent_req *subreq);
static struct tevent_req *cleanup_users_send(TALLOC_CTX *memctx,
struct tevent_context *ev,
struct sdap_id_ctx *ctx)
{
- struct tevent_req *req, *subreq;
+ struct tevent_req *req;
struct cleanup_users_state *state;
static const char *attrs[] = { SYSDB_NAME, SYSDB_UIDNUM, NULL };
time_t now = time(NULL);
char *subfilter = NULL;
int account_cache_expiration;
+ int ret;
req = tevent_req_create(memctx, &state, struct cleanup_users_state);
if (!req) {
@@ -317,45 +317,26 @@ static struct tevent_req *cleanup_users_send(TALLOC_CTX *memctx,
}
if (!subfilter) {
DEBUG(2, ("Failed to build filter\n"));
- talloc_zfree(req);
- return NULL;
+ tevent_req_error(req, ENOMEM);
+ goto done;
}
- subreq = sysdb_search_users_send(state, state->ev,
- state->sysdb, NULL,
- state->domain, subfilter, attrs);
- if (!subreq) {
- DEBUG(2, ("Failed to send entry search\n"));
- talloc_zfree(req);
- return NULL;
- }
- tevent_req_set_callback(subreq, cleanup_users_process, req);
- return req;
-}
-
-static void cleanup_users_process(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- struct cleanup_users_state *state = tevent_req_data(req,
- struct cleanup_users_state);
- int ret;
-
- ret = sysdb_search_users_recv(subreq, state, &state->count, &state->msgs);
- talloc_zfree(subreq);
+ ret = sysdb_search_users(state, state->sysdb,
+ state->domain, subfilter, attrs,
+ &state->count, &state->msgs);
if (ret) {
if (ret == ENOENT) {
- tevent_req_done(req);
- return;
+ tevent_req_done(req);;
}
tevent_req_error(req, ret);
- return;
+ goto done;
}
DEBUG(4, ("Found %d expired user entries!\n", state->count));
if (state->count == 0) {
tevent_req_done(req);
+ goto done;
}
ret = get_uid_table(state, &state->uid_table);
@@ -364,13 +345,22 @@ static void cleanup_users_process(struct tevent_req *subreq)
*/
if (ret != EOK && ret != ENOSYS) {
tevent_req_error(req, ret);
- return;
+ goto done;
}
- cleanup_users_delete(req);
+ ret = cleanup_users_delete(req);
+ if (ret != 0) {
+ goto done;
+ }
+
+ return req;
+
+done:
+ tevent_req_post(req, ev);
+ return req;
}
-static void cleanup_users_delete(struct tevent_req *req)
+static int cleanup_users_delete(struct tevent_req *req)
{
struct tevent_req *subreq;
struct cleanup_users_state *state = tevent_req_data(req,
@@ -384,7 +374,7 @@ static void cleanup_users_delete(struct tevent_req *req)
DEBUG(2, ("Entry %s has no Name Attribute ?!?\n",
ldb_dn_get_linearized(state->msgs[state->cur]->dn)));
tevent_req_error(req, EFAULT);
- return;
+ return 1;
}
if (state->uid_table) {
@@ -392,11 +382,10 @@ static void cleanup_users_delete(struct tevent_req *req)
if (ret == EOK) {
/* If the user is logged in, proceed to the next one */
DEBUG(5, ("User %s is still logged in, keeping his data\n", name));
- cleanup_users_next(req);
- return;
+ return cleanup_users_next(req);
} else if (ret != ENOENT) {
tevent_req_error(req, ret);
- return;
+ return 1;
}
}
@@ -407,10 +396,10 @@ static void cleanup_users_delete(struct tevent_req *req)
state->domain, name, 0);
if (!subreq) {
tevent_req_error(req, ENOMEM);
- return;
+ return 1;
}
tevent_req_set_callback(subreq, cleanup_users_delete_done, req);
- return;
+ return 0;
}
static int cleanup_users_logged_in(hash_table_t *table,
@@ -442,18 +431,18 @@ static int cleanup_users_logged_in(hash_table_t *table,
return EIO;
}
-static void cleanup_users_next(struct tevent_req *req)
+static int cleanup_users_next(struct tevent_req *req)
{
struct cleanup_users_state *state = tevent_req_data(req,
struct cleanup_users_state);
state->cur++;
if (state->cur < state->count) {
- cleanup_users_delete(req);
- return;
+ return cleanup_users_delete(req);
}
tevent_req_done(req);
+ return 1;
}
static void cleanup_users_delete_done(struct tevent_req *subreq)
@@ -490,7 +479,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_check_users_done(struct tevent_req *subreq);
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);
@@ -572,9 +560,11 @@ static void cleanup_groups_check_users(struct tevent_req *req)
{
struct cleanup_groups_state *state = tevent_req_data(req,
struct cleanup_groups_state);
- struct tevent_req *subreq;
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) {
@@ -589,28 +579,8 @@ static void cleanup_groups_check_users(struct tevent_req *req)
tevent_req_error(req, ENOMEM);
}
- subreq = sysdb_search_users_send(state, state->ev,
- state->sysdb, NULL,
- state->domain, subfilter, NULL);
- if (!subreq) {
- DEBUG(2, ("Failed to send entry search\n"));
- tevent_req_error(req, ENOMEM);
- }
- tevent_req_set_callback(subreq, cleanup_groups_check_users_done, req);
-}
-
-static void cleanup_groups_check_users_done(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- struct cleanup_groups_state *state = tevent_req_data(req,
- struct cleanup_groups_state);
- int ret;
- struct ldb_message **msgs;
- size_t count;
-
- ret = sysdb_search_users_recv(subreq, state, &count, &msgs);
- talloc_zfree(subreq);
+ ret = sysdb_search_users(state, state->sysdb,
+ state->domain, subfilter, NULL, &count, &msgs);
if (ret != EOK) {
if (ret == ENOENT) {
cleanup_groups_delete(req);