summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimo Sorce <ssorce@redhat.com>2010-02-28 01:44:42 -0500
committerStephen Gallagher <sgallagh@redhat.com>2010-04-12 09:22:12 -0400
commit1c733ece101ca43b84c59a8dc7953346312dbf64 (patch)
tree672ba8c8fed42fefe8a4f3fa67a8ff38397e874a
parent0995e4cc173577122bea5a1d4698262fd0e9c200 (diff)
downloadsssd-1c733ece101ca43b84c59a8dc7953346312dbf64.tar.gz
sssd-1c733ece101ca43b84c59a8dc7953346312dbf64.tar.xz
sssd-1c733ece101ca43b84c59a8dc7953346312dbf64.zip
sysdb: convert sysdb_search_user_by_name/uid
-rw-r--r--src/db/sysdb.h30
-rw-r--r--src/db/sysdb_ops.c603
-rw-r--r--src/providers/ipa/ipa_access.c75
-rw-r--r--src/tools/sss_groupshow.c127
4 files changed, 219 insertions, 616 deletions
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index b7c53e1d0..9e638f500 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -352,23 +352,19 @@ int sysdb_search_entry(TALLOC_CTX *mem_ctx,
struct ldb_message ***msgs);
/* Search User (by uid or name) */
-struct tevent_req *sysdb_search_user_by_name_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,
- const char **attrs);
-struct tevent_req *sysdb_search_user_by_uid_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- struct sysdb_ctx *sysdb,
- struct sysdb_handle *handle,
- struct sss_domain_info *domain,
- uid_t uid,
- const char **attrs);
-int sysdb_search_user_recv(struct tevent_req *req,
- TALLOC_CTX *mem_ctx,
- struct ldb_message **msg);
+int sysdb_search_user_by_name(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *ctx,
+ struct sss_domain_info *domain,
+ const char *name,
+ const char **attrs,
+ struct ldb_message **msg);
+
+int sysdb_search_user_by_uid(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *ctx,
+ struct sss_domain_info *domain,
+ uid_t uid,
+ const char **attrs,
+ struct ldb_message **msg);
/* Search Group (gy gid or name) */
struct tevent_req *sysdb_search_group_by_name_send(TALLOC_CTX *mem_ctx,
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index 830e28efc..d0cdcc378 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -350,193 +350,95 @@ int sysdb_search_entry(TALLOC_CTX *mem_ctx,
/* =Search-User-by-[UID/NAME]============================================= */
-struct sysdb_search_user_state {
- struct tevent_context *ev;
- struct sysdb_handle *handle;
-
- struct ldb_dn *basedn;
- const char **attrs;
- const char *filter;
- int scope;
-
- size_t msgs_count;
- struct ldb_message **msgs;
-};
-
-static void sysdb_search_user_cont(struct tevent_req *subreq);
-
-struct tevent_req *sysdb_search_user_by_name_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,
- const char **attrs)
+int sysdb_search_user_by_name(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *ctx,
+ struct sss_domain_info *domain,
+ const char *name,
+ const char **attrs,
+ struct ldb_message **msg)
{
- struct tevent_req *req, *subreq;
- struct sysdb_search_user_state *state;
- static const char *def_attrs[] = { SYSDB_NAME, SYSDB_UIDNUM, NULL };
+ TALLOC_CTX *tmpctx;
+ const char *def_attrs[] = { SYSDB_NAME, SYSDB_UIDNUM, NULL };
+ struct ldb_message **msgs = NULL;
+ struct ldb_dn *basedn;
+ size_t msgs_count = 0;
int ret;
- if (!sysdb && !handle) return NULL;
-
- req = tevent_req_create(mem_ctx, &state, struct sysdb_search_user_state);
- if (!req) return NULL;
-
- state->ev = ev;
- state->handle = handle;
- state->msgs_count = 0;
- state->msgs = NULL;
-
- state->attrs = attrs ? attrs : def_attrs;
- state->filter = NULL;
- state->scope = LDB_SCOPE_BASE;
-
- if (!sysdb) sysdb = handle->ctx;
-
- state->basedn = sysdb_user_dn(sysdb, state, domain->name, name);
- if (!state->basedn) {
- ERROR_OUT(ret, ENOMEM, fail);
+ tmpctx = talloc_new(mem_ctx);
+ if (!tmpctx) {
+ return ENOMEM;
}
- if (!handle) {
- subreq = sysdb_operation_send(state, state->ev, sysdb);
- if (!subreq) {
- ERROR_OUT(ret, ENOMEM, fail);
- }
- tevent_req_set_callback(subreq, sysdb_search_user_cont, req);
+ basedn = sysdb_user_dn(ctx, tmpctx, domain->name, name);
+ if (!basedn) {
+ ret = ENOMEM;
+ goto done;
}
- else {
- ret = sysdb_search_entry(state, state->handle->ctx, state->basedn,
- state->scope, state->filter, state->attrs,
- &state->msgs_count, &state->msgs);
- if (ret) {
- goto fail;
- }
- tevent_req_done(req);
- tevent_req_post(req, ev);
+
+ ret = sysdb_search_entry(tmpctx, ctx, basedn, LDB_SCOPE_BASE, NULL,
+ attrs?attrs:def_attrs, &msgs_count, &msgs);
+ if (ret) {
+ goto done;
}
- return req;
+ *msg = talloc_steal(mem_ctx, msgs[0]);
-fail:
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- tevent_req_post(req, ev);
- return req;
+done:
+ if (ret) {
+ DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
+ }
+ talloc_zfree(tmpctx);
+ return ret;
}
-struct tevent_req *sysdb_search_user_by_uid_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- struct sysdb_ctx *sysdb,
- struct sysdb_handle *handle,
- struct sss_domain_info *domain,
- uid_t uid,
- const char **attrs)
+int sysdb_search_user_by_uid(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *ctx,
+ struct sss_domain_info *domain,
+ uid_t uid,
+ const char **attrs,
+ struct ldb_message **msg)
{
- struct tevent_req *req, *subreq;
- struct sysdb_search_user_state *state;
- static const char *def_attrs[] = { SYSDB_NAME, SYSDB_UIDNUM, NULL };
+ TALLOC_CTX *tmpctx;
+ const char *def_attrs[] = { SYSDB_NAME, SYSDB_UIDNUM, NULL };
+ struct ldb_message **msgs = NULL;
+ struct ldb_dn *basedn;
+ size_t msgs_count = 0;
+ char *filter;
int ret;
- if (!sysdb && !handle) return NULL;
-
- req = tevent_req_create(mem_ctx, &state, struct sysdb_search_user_state);
- if (!req) return NULL;
-
- state->ev = ev;
- state->handle = handle;
- state->msgs_count = 0;
- state->msgs = NULL;
- state->attrs = attrs ? attrs : def_attrs;
-
- if (!sysdb) sysdb = handle->ctx;
-
- state->basedn = ldb_dn_new_fmt(state, sysdb->ldb,
- SYSDB_TMPL_USER_BASE, domain->name);
- if (!state->basedn) {
- ERROR_OUT(ret, ENOMEM, fail);
- }
-
- state->filter = talloc_asprintf(state, SYSDB_PWUID_FILTER,
- (unsigned long)uid);
- if (!state->filter) {
- ERROR_OUT(ret, ENOMEM, fail);
+ tmpctx = talloc_new(mem_ctx);
+ if (!tmpctx) {
+ return ENOMEM;
}
- state->scope = LDB_SCOPE_ONELEVEL;
-
- if (!handle) {
- subreq = sysdb_operation_send(state, state->ev, sysdb);
- if (!subreq) {
- ERROR_OUT(ret, ENOMEM, fail);
- }
- tevent_req_set_callback(subreq, sysdb_search_user_cont, req);
- }
- else {
- ret = sysdb_search_entry(state, state->handle->ctx, state->basedn,
- state->scope, state->filter, state->attrs,
- &state->msgs_count, &state->msgs);
- if (ret) {
- goto fail;
- }
- tevent_req_done(req);
- tevent_req_post(req, ev);
+ basedn = ldb_dn_new_fmt(tmpctx, ctx->ldb,
+ SYSDB_TMPL_USER_BASE, domain->name);
+ if (!basedn) {
+ ret = ENOMEM;
+ goto done;
}
- return req;
-
-fail:
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- tevent_req_post(req, ev);
- return req;
-}
-
-static void sysdb_search_user_cont(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- struct sysdb_search_user_state *state = tevent_req_data(req,
- struct sysdb_search_user_state);
- int ret;
-
- ret = sysdb_operation_recv(subreq, state, &state->handle);
- talloc_zfree(subreq);
- if (ret) {
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- return;
+ filter = talloc_asprintf(tmpctx, SYSDB_PWUID_FILTER, (unsigned long)uid);
+ if (!filter) {
+ ret = ENOMEM;
+ goto done;
}
- ret = sysdb_search_entry(state, state->handle->ctx, state->basedn,
- state->scope, state->filter, state->attrs,
- &state->msgs_count, &state->msgs);
+ ret = sysdb_search_entry(tmpctx, ctx, basedn, LDB_SCOPE_ONELEVEL, filter,
+ attrs?attrs:def_attrs, &msgs_count, &msgs);
if (ret) {
- tevent_req_error(req, ret);
- return;
+ goto done;
}
- tevent_req_done(req);
-}
-
-int sysdb_search_user_recv(struct tevent_req *req,
- TALLOC_CTX *mem_ctx,
- struct ldb_message **msg)
-{
- struct sysdb_search_user_state *state = tevent_req_data(req,
- struct sysdb_search_user_state);
-
- TEVENT_REQ_RETURN_ON_ERROR(req);
+ *msg = talloc_steal(mem_ctx, msgs[0]);
- if (state->msgs_count > 1) {
- DEBUG(1, ("More than one result found.\n"));
- return EFAULT;
+done:
+ if (ret) {
+ DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
}
- *msg = talloc_move(mem_ctx, &state->msgs[0]);
-
- return EOK;
+ talloc_zfree(tmpctx);
+ return ret;
}
@@ -1428,7 +1330,6 @@ struct sysdb_add_user_state {
};
static void sysdb_add_user_group_check(struct tevent_req *subreq);
-static void sysdb_add_user_uid_check(struct tevent_req *subreq);
static void sysdb_add_user_basic_done(struct tevent_req *subreq);
static void sysdb_add_user_get_id_done(struct tevent_req *subreq);
static void sysdb_add_user_set_id_done(struct tevent_req *subreq);
@@ -1449,6 +1350,7 @@ struct tevent_req *sysdb_add_user_send(TALLOC_CTX *mem_ctx,
{
struct tevent_req *req, *subreq;
struct sysdb_add_user_state *state;
+ struct ldb_message *msg;
int ret;
req = tevent_req_create(mem_ctx, &state, struct sysdb_add_user_state);
@@ -1505,13 +1407,12 @@ struct tevent_req *sysdb_add_user_send(TALLOC_CTX *mem_ctx,
/* check no other user with the same uid exist */
if (state->uid != 0) {
- subreq = sysdb_search_user_by_uid_send(state, ev, NULL, handle,
- domain, uid, NULL);
- if (!subreq) {
- ERROR_OUT(ret, ENOMEM, fail);
+ ret = sysdb_search_user_by_uid(state, handle->ctx,
+ domain, uid, NULL, &msg);
+ if (ret != ENOENT) {
+ if (ret == EOK) ret = EEXIST;
+ goto fail;
}
- tevent_req_set_callback(subreq, sysdb_add_user_uid_check, req);
- return req;
}
/* try to add the user */
@@ -1525,7 +1426,7 @@ struct tevent_req *sysdb_add_user_send(TALLOC_CTX *mem_ctx,
return req;
fail:
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
+ DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
tevent_req_error(req, ret);
tevent_req_post(req, ev);
return req;
@@ -1553,52 +1454,13 @@ static void sysdb_add_user_group_check(struct tevent_req *subreq)
/* check no other user with the same uid exist */
if (state->uid != 0) {
- subreq = sysdb_search_user_by_uid_send(state, state->ev,
- NULL, state->handle,
- state->domain, state->uid,
- NULL);
- if (!subreq) {
- DEBUG(6, ("Error: Out of memory\n"));
- tevent_req_error(req, ENOMEM);
+ ret = sysdb_search_user_by_uid(state, state->handle->ctx,
+ state->domain, state->uid, NULL, &msg);
+ if (ret != ENOENT) {
+ if (ret == EOK) ret = EEXIST;
+ tevent_req_error(req, ret);
return;
}
- tevent_req_set_callback(subreq, sysdb_add_user_uid_check, req);
- return;
- }
-
- /* try to add the user */
- subreq = sysdb_add_basic_user_send(state, state->ev, state->handle,
- state->domain, state->name,
- state->uid, state->gid,
- state->gecos,
- state->homedir,
- state->shell);
- if (!subreq) {
- DEBUG(6, ("Error: Out of memory\n"));
- tevent_req_error(req, ENOMEM);
- return;
- }
- tevent_req_set_callback(subreq, sysdb_add_user_basic_done, req);
-}
-
-static void sysdb_add_user_uid_check(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- struct sysdb_add_user_state *state = tevent_req_data(req,
- struct sysdb_add_user_state);
- struct ldb_message *msg;
- int ret;
-
- /* We can succeed only if we get an ENOENT error, which means no user
- * with the same uid exist.
- * If any other error is returned fail as well. */
- ret = sysdb_search_user_recv(subreq, state, &msg);
- talloc_zfree(subreq);
- if (ret != ENOENT) {
- if (ret == EOK) ret = EEXIST;
- tevent_req_error(req, ret);
- return;
}
/* try to add the user */
@@ -1882,7 +1744,6 @@ struct sysdb_add_group_state {
int cache_timeout;
};
-static void sysdb_add_group_user_check(struct tevent_req *subreq);
static void sysdb_add_group_gid_check(struct tevent_req *subreq);
static void sysdb_add_group_basic_done(struct tevent_req *subreq);
static void sysdb_add_group_get_id_done(struct tevent_req *subreq);
@@ -1899,6 +1760,7 @@ struct tevent_req *sysdb_add_group_send(TALLOC_CTX *mem_ctx,
{
struct tevent_req *req, *subreq;
struct sysdb_add_group_state *state;
+ struct ldb_message *msg;
int ret;
req = tevent_req_create(mem_ctx, &state, struct sysdb_add_group_state);
@@ -1925,13 +1787,12 @@ struct tevent_req *sysdb_add_group_send(TALLOC_CTX *mem_ctx,
* Don't worry about users, if we try to add a user with the same
* name the operation will fail */
- subreq = sysdb_search_user_by_name_send(state, ev, NULL, handle,
- domain, name, NULL);
- if (!subreq) {
- ERROR_OUT(ret, ENOMEM, fail);
+ ret = sysdb_search_user_by_name(state, handle->ctx,
+ domain, name, NULL, &msg);
+ if (ret != ENOENT) {
+ if (ret == EOK) ret = EEXIST;
+ goto fail;
}
- tevent_req_set_callback(subreq, sysdb_add_group_user_check, req);
- return req;
}
/* check no other groups with the same gid exist */
@@ -1961,53 +1822,6 @@ fail:
return req;
}
-static void sysdb_add_group_user_check(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- struct sysdb_add_group_state *state = tevent_req_data(req,
- struct sysdb_add_group_state);
- struct ldb_message *msg;
- int ret;
-
- /* We can succeed only if we get an ENOENT error, which means no users
- * with the same name exist.
- * If any other error is returned fail as well. */
- ret = sysdb_search_user_recv(subreq, state, &msg);
- talloc_zfree(subreq);
- if (ret != ENOENT) {
- if (ret == EOK) ret = EEXIST;
- tevent_req_error(req, ret);
- return;
- }
-
- /* check no other group with the same gid exist */
- if (state->gid != 0) {
- subreq = sysdb_search_group_by_gid_send(state, state->ev,
- NULL, state->handle,
- state->domain, state->gid,
- NULL);
- if (!subreq) {
- DEBUG(6, ("Error: Out of memory\n"));
- tevent_req_error(req, ENOMEM);
- return;
- }
- tevent_req_set_callback(subreq, sysdb_add_group_gid_check, req);
- return;
- }
-
- /* try to add the group */
- subreq = sysdb_add_basic_group_send(state, state->ev,
- state->handle, state->domain,
- state->name, state->gid);
- if (!subreq) {
- DEBUG(6, ("Error: Out of memory\n"));
- tevent_req_error(req, ENOMEM);
- return;
- }
- tevent_req_set_callback(subreq, sysdb_add_group_basic_done, req);
-}
-
static void sysdb_add_group_gid_check(struct tevent_req *subreq)
{
struct tevent_req *req = tevent_req_callback_data(subreq,
@@ -2273,7 +2087,6 @@ struct sysdb_store_user_state {
uint64_t cache_timeout;
};
-static void sysdb_store_user_check(struct tevent_req *subreq);
static void sysdb_store_user_add_done(struct tevent_req *subreq);
static void sysdb_store_user_attr_done(struct tevent_req *subreq);
@@ -2292,6 +2105,8 @@ struct tevent_req *sysdb_store_user_send(TALLOC_CTX *mem_ctx,
{
struct tevent_req *req, *subreq;
struct sysdb_store_user_state *state;
+ struct ldb_message *msg;
+ time_t now;
int ret;
req = tevent_req_create(mem_ctx, &state, struct sysdb_store_user_state);
@@ -2314,37 +2129,10 @@ struct tevent_req *sysdb_store_user_send(TALLOC_CTX *mem_ctx,
if (ret) goto fail;
}
- subreq = sysdb_search_user_by_name_send(state, ev, NULL, handle,
- domain, name, NULL);
- if (!subreq) {
- ERROR_OUT(ret, ENOMEM, fail);
- }
- tevent_req_set_callback(subreq, sysdb_store_user_check, req);
-
- return req;
-
-fail:
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- tevent_req_post(req, ev);
- return req;
-}
-
-static void sysdb_store_user_check(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- struct sysdb_store_user_state *state = tevent_req_data(req,
- struct sysdb_store_user_state);
- struct ldb_message *msg;
- time_t now = time(NULL);
- int ret;
-
- ret = sysdb_search_user_recv(subreq, state, &msg);
- talloc_zfree(subreq);
+ ret = sysdb_search_user_by_name(state, handle->ctx,
+ domain, name, NULL, &msg);
if (ret && ret != ENOENT) {
- tevent_req_error(req, ret);
- return;
+ goto fail;
}
if (ret == ENOENT) {
@@ -2356,105 +2144,81 @@ static void sysdb_store_user_check(struct tevent_req *subreq)
state->shell, state->attrs,
state->cache_timeout);
if (!subreq) {
- DEBUG(6, ("Error: Out of memory\n"));
- tevent_req_error(req, ENOMEM);
- return;
+ ret = ENOMEM;
+ goto fail;
}
tevent_req_set_callback(subreq, sysdb_store_user_add_done, req);
- return;
+
+ return req;
}
/* the user exists, let's just replace attributes when set */
if (!state->attrs) {
state->attrs = sysdb_new_attrs(state);
if (!state->attrs) {
- DEBUG(6, ("Error: Out of memory\n"));
- tevent_req_error(req, ENOMEM);
- return;
+ ret = ENOMEM;
+ goto fail;
}
}
if (state->uid) {
ret = sysdb_attrs_add_uint32(state->attrs, SYSDB_UIDNUM, state->uid);
- if (ret) {
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- return;
- }
+ if (ret) goto fail;
}
if (state->gid) {
ret = sysdb_attrs_add_uint32(state->attrs, SYSDB_GIDNUM, state->gid);
- if (ret) {
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- return;
- }
+ if (ret) goto fail;
}
if (state->uid && !state->gid && state->handle->ctx->mpg) {
ret = sysdb_attrs_add_uint32(state->attrs, SYSDB_GIDNUM, state->uid);
- if (ret) {
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- return;
- }
+ if (ret) goto fail;
}
if (state->gecos) {
ret = sysdb_attrs_add_string(state->attrs, SYSDB_GECOS, state->gecos);
- if (ret) {
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- return;
- }
+ if (ret) goto fail;
}
if (state->homedir) {
ret = sysdb_attrs_add_string(state->attrs,
SYSDB_HOMEDIR, state->homedir);
- if (ret) {
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- return;
- }
+ if (ret) goto fail;
}
if (state->shell) {
ret = sysdb_attrs_add_string(state->attrs, SYSDB_SHELL, state->shell);
- if (ret) {
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- return;
- }
+ if (ret) goto fail;
}
+ now = time(NULL);
+
ret = sysdb_attrs_add_time_t(state->attrs, SYSDB_LAST_UPDATE, now);
- if (ret) {
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- return;
- }
+ if (ret) goto fail;
ret = sysdb_attrs_add_time_t(state->attrs, SYSDB_CACHE_EXPIRE,
((state->cache_timeout) ?
(now + state->cache_timeout) : 0));
- if (ret) {
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- return;
- }
+ if (ret) goto fail;
subreq = sysdb_set_user_attr_send(state, state->ev,
state->handle, state->domain,
state->name, state->attrs,
SYSDB_MOD_REP);
if (!subreq) {
- DEBUG(6, ("Error: Out of memory\n"));
- tevent_req_error(req, ENOMEM);
- return;
+ ret = ENOMEM;
+ goto fail;
}
tevent_req_set_callback(subreq, sysdb_store_user_attr_done, req);
+
+ return req;
+
+fail:
+ DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
+ tevent_req_error(req, ret);
+ tevent_req_post(req, ev);
+ return req;
}
static void sysdb_store_user_add_done(struct tevent_req *subreq)
@@ -3864,7 +3628,6 @@ struct sysdb_delete_user_state {
};
void sysdb_delete_user_check_handle(struct tevent_req *subreq);
-static void sysdb_delete_user_done(struct tevent_req *subreq);
struct tevent_req *sysdb_delete_user_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
@@ -3903,7 +3666,7 @@ void sysdb_delete_user_check_handle(struct tevent_req *subreq)
struct tevent_req);
struct sysdb_delete_user_state *state = tevent_req_data(req,
struct sysdb_delete_user_state);
- static const char *attrs[] = { SYSDB_NAME, SYSDB_UIDNUM, NULL };
+ struct ldb_message *msg;
int ret;
ret = sysdb_check_handle_recv(subreq, state, &state->handle);
@@ -3914,33 +3677,14 @@ void sysdb_delete_user_check_handle(struct tevent_req *subreq)
}
if (state->name) {
- subreq = sysdb_search_user_by_name_send(state, state->ev, NULL,
- state->handle, state->domain,
- state->name, attrs);
+ ret = sysdb_search_user_by_name(state, state->handle->ctx,
+ state->domain, state->name,
+ NULL, &msg);
} else {
- subreq = sysdb_search_user_by_uid_send(state, state->ev, NULL,
- state->handle, state->domain,
- state->uid, NULL);
- }
-
- if (!subreq) {
- tevent_req_error(req, ENOMEM);
- return;
+ ret = sysdb_search_user_by_uid(state, state->handle->ctx,
+ state->domain, state->uid,
+ NULL, &msg);
}
- tevent_req_set_callback(subreq, sysdb_delete_user_done, req);
-}
-
-static void sysdb_delete_user_done(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- struct sysdb_delete_user_state *state = tevent_req_data(req,
- struct sysdb_delete_user_state);
- struct ldb_message *msg;
- int ret;
-
- ret = sysdb_search_user_recv(subreq, state, &msg);
- talloc_zfree(subreq);
if (ret) {
tevent_req_error(req, ret);
return;
@@ -4302,7 +4046,6 @@ errno_t check_failed_login_attempts(TALLOC_CTX *mem_ctx, struct confdb_ctx *cdb,
return EOK;
}
-static void sysdb_cache_auth_get_attrs_done(struct tevent_req *subreq);
static void sysdb_cache_auth_transaction_start_done(struct tevent_req *subreq);
static void sysdb_cache_auth_attr_update_done(struct tevent_req *subreq);
static void sysdb_cache_auth_done(struct tevent_req *subreq);
@@ -4319,42 +4062,49 @@ struct tevent_req *sysdb_cache_auth_send(TALLOC_CTX *mem_ctx,
struct tevent_req *req;
struct tevent_req *subreq;
struct sysdb_cache_auth_state *state;
+ const char *attrs[] = { SYSDB_NAME, SYSDB_CACHEDPWD, SYSDB_DISABLED,
+ SYSDB_LAST_LOGIN, SYSDB_LAST_ONLINE_AUTH,
+ "lastCachedPasswordChange",
+ "accountExpires", SYSDB_FAILED_LOGIN_ATTEMPTS,
+ SYSDB_LAST_FAILED_LOGIN, NULL };
+ struct ldb_message *ldb_msg;
+ const char *userhash;
+ char *comphash;
+ char *password = NULL;
+ uint64_t lastLogin = 0;
+ int cred_expiration;
+ uint32_t failed_login_attempts = 0;
+ int ret;
+ int i;
+
+ req = tevent_req_create(mem_ctx, &state, struct sysdb_cache_auth_state);
+ if (req == NULL) {
+ DEBUG(1, ("tevent_req_create failed.\n"));
+ return NULL;
+ }
if (name == NULL || *name == '\0') {
DEBUG(1, ("Missing user name.\n"));
- return NULL;
+ ret = EINVAL;
+ goto done;
}
if (cdb == NULL) {
DEBUG(1, ("Missing config db context.\n"));
- return NULL;
+ ret = EINVAL;
+ goto done;
}
if (sysdb == NULL) {
DEBUG(1, ("Missing sysdb db context.\n"));
- return NULL;
+ ret = EINVAL;
+ goto done;
}
if (!domain->cache_credentials) {
DEBUG(3, ("Cached credentials not available.\n"));
- return NULL;
- }
-
- static const char *attrs[] = {SYSDB_NAME,
- SYSDB_CACHEDPWD,
- SYSDB_DISABLED,
- SYSDB_LAST_LOGIN,
- SYSDB_LAST_ONLINE_AUTH,
- "lastCachedPasswordChange",
- "accountExpires",
- SYSDB_FAILED_LOGIN_ATTEMPTS,
- SYSDB_LAST_FAILED_LOGIN,
- NULL};
-
- req = tevent_req_create(mem_ctx, &state, struct sysdb_cache_auth_state);
- if (req == NULL) {
- DEBUG(1, ("tevent_req_create failed.\n"));
- return NULL;
+ ret = EINVAL;
+ goto done;
}
state->ev = ev;
@@ -4370,43 +4120,11 @@ struct tevent_req *sysdb_cache_auth_send(TALLOC_CTX *mem_ctx,
state->expire_date = -1;
state->delayed_until = -1;
- subreq = sysdb_search_user_by_name_send(state, ev, sysdb, NULL, domain,
- name, attrs);
- if (subreq == NULL) {
- DEBUG(1, ("sysdb_search_user_by_name_send failed.\n"));
- talloc_zfree(req);
- return NULL;
- }
- tevent_req_set_callback(subreq, sysdb_cache_auth_get_attrs_done, req);
-
- return req;
-}
-
-static void sysdb_cache_auth_get_attrs_done(struct tevent_req *subreq)
-{
- struct ldb_message *ldb_msg;
- const char *userhash;
- char *comphash;
- char *password = NULL;
- int i;
- int ret;
- uint64_t lastLogin = 0;
- int cred_expiration;
- uint32_t failed_login_attempts = 0;
-
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
-
- struct sysdb_cache_auth_state *state = tevent_req_data(req,
- struct sysdb_cache_auth_state);
-
- ret = sysdb_search_user_recv(subreq, state, &ldb_msg);
- talloc_zfree(subreq);
+ ret = sysdb_search_user_by_name(state, sysdb, domain, name, attrs, &ldb_msg);
if (ret != EOK) {
- DEBUG(1, ("sysdb_search_user_by_name_send failed [%d][%s].\n",
+ DEBUG(1, ("sysdb_search_user_by_name failed [%d][%s].\n",
ret, strerror(ret)));
- tevent_req_error(req, ENOENT);
- return;
+ goto done;
}
/* Check offline_auth_cache_timeout */
@@ -4418,7 +4136,6 @@ static void sysdb_cache_auth_get_attrs_done(struct tevent_req *subreq)
CONFDB_PAM_CRED_TIMEOUT, 0, &cred_expiration);
if (ret != EOK) {
DEBUG(1, ("Failed to read expiration time of offline credentials.\n"));
- ret = EACCES;
goto done;
}
DEBUG(9, ("Offline credentials expiration is [%d] days.\n",
@@ -4440,6 +4157,7 @@ static void sysdb_cache_auth_get_attrs_done(struct tevent_req *subreq)
&failed_login_attempts,
&state->delayed_until);
if (ret != EOK) {
+ DEBUG(1, ("Failed to check login attempts\n"));
goto done;
}
@@ -4470,6 +4188,7 @@ static void sysdb_cache_auth_get_attrs_done(struct tevent_req *subreq)
state->update_attrs = sysdb_new_attrs(state);
if (state->update_attrs == NULL) {
DEBUG(1, ("sysdb_new_attrs failed.\n"));
+ ret = ENOMEM;
goto done;
}
@@ -4506,7 +4225,6 @@ static void sysdb_cache_auth_get_attrs_done(struct tevent_req *subreq)
time(NULL));
if (ret != EOK) {
DEBUG(3, ("sysdb_attrs_add_time_t failed\n."));
- ret = EINVAL;
goto done;
}
@@ -4515,7 +4233,6 @@ static void sysdb_cache_auth_get_attrs_done(struct tevent_req *subreq)
++failed_login_attempts);
if (ret != EOK) {
DEBUG(3, ("sysdb_attrs_add_uint32 failed.\n"));
- ret = EINVAL;
goto done;
}
}
@@ -4525,18 +4242,20 @@ static void sysdb_cache_auth_get_attrs_done(struct tevent_req *subreq)
DEBUG(1, ("sysdb_transaction_send failed.\n"));
goto done;
}
- tevent_req_set_callback(subreq, sysdb_cache_auth_transaction_start_done,
- req);
- return;
+ tevent_req_set_callback(subreq,
+ sysdb_cache_auth_transaction_start_done, req);
+
+ return req;
done:
if (password) for (i = 0; password[i]; i++) password[i] = 0;
- if (ret == EOK) {
- tevent_req_done(req);
- } else {
+ if (ret) {
tevent_req_error(req, ret);
+ } else {
+ tevent_req_done(req);
}
- return;
+ tevent_req_post(req, ev);
+ return req;
}
static void sysdb_cache_auth_transaction_start_done(struct tevent_req *subreq)
diff --git a/src/providers/ipa/ipa_access.c b/src/providers/ipa/ipa_access.c
index 5cf9bf492..1ea77b202 100644
--- a/src/providers/ipa/ipa_access.c
+++ b/src/providers/ipa/ipa_access.c
@@ -110,7 +110,6 @@ struct hbac_get_user_info_state {
const char **groups;
};
-static void search_user_done(struct tevent_req *subreq);
static void search_groups_done(struct tevent_req *subreq);
struct tevent_req *hbac_get_user_info_send(TALLOC_CTX *memctx,
@@ -122,7 +121,9 @@ struct tevent_req *hbac_get_user_info_send(TALLOC_CTX *memctx,
struct tevent_req *subreq = NULL;
struct hbac_get_user_info_state *state;
int ret;
- const char **attrs;
+ static const char *attrs[] = { SYSDB_ORIG_DN, NULL };
+ struct ldb_message *user_msg;
+ const char *dummy;
req = tevent_req_create(memctx, &state, struct hbac_get_user_info_state);
if (req == NULL) {
@@ -139,50 +140,10 @@ struct tevent_req *hbac_get_user_info_send(TALLOC_CTX *memctx,
state->groups_count = 0;
state->groups = NULL;
- attrs = talloc_array(state, const char *, 2);
- if (attrs == NULL) {
- ret = ENOMEM;
- goto fail;
- }
-
- attrs[0] = SYSDB_ORIG_DN;
- attrs[1] = NULL;
-
- subreq = sysdb_search_user_by_name_send(state, ev, be_ctx->sysdb, NULL,
- be_ctx->domain, user, attrs);
- if (subreq == NULL) {
- DEBUG(1, ("sysdb_search_user_by_name_send failed.\n"));
- ret = ENOMEM;
- goto fail;
- }
-
- tevent_req_set_callback(subreq, search_user_done, req);
-
- return req;
-
-fail:
- tevent_req_error(req, ret);
- tevent_req_post(req, ev);
- return req;
-}
-
-static void search_user_done(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- struct hbac_get_user_info_state *state = tevent_req_data(req,
- struct hbac_get_user_info_state);
- int ret;
- const char **attrs;
- const char *dummy;
- struct ldb_message *user_msg;
-
-
- ret = sysdb_search_user_recv(subreq, state, &user_msg);
- talloc_zfree(subreq);
+ ret = sysdb_search_user_by_name(state, be_ctx->sysdb,
+ be_ctx->domain, user, attrs, &user_msg);
if (ret != EOK) {
- tevent_req_error(req, ret);
- return;
+ goto fail;
}
DEBUG(9, ("Found user info for user [%s].\n", state->user));
@@ -191,41 +152,33 @@ static void search_user_done(struct tevent_req *subreq)
if (dummy == NULL) {
DEBUG(1, ("Original DN of user [%s] not available.\n", state->user));
ret = EINVAL;
- goto failed;
+ goto fail;
}
state->user_orig_dn = talloc_strdup(state, dummy);
if (state->user_dn == NULL) {
DEBUG(1, ("talloc_strdup failed.\n"));
ret = ENOMEM;
- goto failed;
+ goto fail;
}
DEBUG(9, ("Found original DN [%s] for user [%s].\n", state->user_orig_dn,
state->user));
- attrs = talloc_array(state, const char *, 2);
- if (attrs == NULL) {
- DEBUG(1, ("talloc_array failed.\n"));
- ret = ENOMEM;
- goto failed;
- }
- attrs[0] = SYSDB_ORIG_DN;
- attrs[1] = NULL;
-
subreq = sysdb_asq_search_send(state, state->ev, state->be_ctx->sysdb, NULL,
state->be_ctx->domain, state->user_dn, NULL,
SYSDB_MEMBEROF, attrs);
if (subreq == NULL) {
DEBUG(1, ("sysdb_asq_search_send failed.\n"));
ret = ENOMEM;
- goto failed;
+ goto fail;
}
-
tevent_req_set_callback(subreq, search_groups_done, req);
- return;
-failed:
+ return req;
+
+fail:
tevent_req_error(req, ret);
- return;
+ tevent_req_post(req, ev);
+ return req;
}
static void search_groups_done(struct tevent_req *subreq)
diff --git a/src/tools/sss_groupshow.c b/src/tools/sss_groupshow.c
index 084da21b9..95af22a45 100644
--- a/src/tools/sss_groupshow.c
+++ b/src/tools/sss_groupshow.c
@@ -822,90 +822,48 @@ static int group_show_recurse_recv(TALLOC_CTX *mem_ctx,
}
/*==================Get info about MPG================================= */
-struct group_show_mpg_state {
- struct ldb_context *ldb;
- struct group_info *info;
-};
-static void group_show_mpg_done(struct tevent_req *);
-
-struct tevent_req *group_show_mpg_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)
+static int group_show_mpg(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *sysdb,
+ struct sss_domain_info *domain,
+ const char *name,
+ struct group_info **res)
{
- struct tevent_req *req = NULL;
- struct tevent_req *subreq = NULL;
- struct group_show_mpg_state *state;
- static const char *mpg_attrs[] = GROUP_SHOW_MPG_ATTRS;
-
- req = tevent_req_create(mem_ctx, &state, struct group_show_mpg_state);
- if (req == NULL) {
- return NULL;
- }
- state->ldb = sysdb_ctx_get_ldb(sysdb);
+ const char *attrs[] = GROUP_SHOW_MPG_ATTRS;
+ struct ldb_message *msg;
+ struct group_info *info;
+ int ret;
- subreq = sysdb_search_user_by_name_send(mem_ctx, ev, sysdb, handle,
- domain, name, mpg_attrs);
- if (!subreq) {
- talloc_zfree(req);
- return NULL;
+ info = talloc_zero(mem_ctx, struct group_info);
+ if (!info) {
+ ret = ENOMEM;
+ goto fail;
}
- tevent_req_set_callback(subreq, group_show_mpg_done, req);
-
- return req;
-}
-
-static void group_show_mpg_done(struct tevent_req *subreq)
-{
- int ret;
- struct ldb_message *msg = NULL;
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- struct group_show_mpg_state *state = tevent_req_data(req,
- struct group_show_mpg_state);
- ret = sysdb_search_user_recv(subreq, req, &msg);
- talloc_zfree(subreq);
+ ret = sysdb_search_user_by_name(info, sysdb,
+ domain, name, attrs, &msg);
if (ret) {
DEBUG(2, ("Search failed: %s (%d)\n", strerror(ret), ret));
- tevent_req_error(req, ret);
- return;
- }
-
- state->info = talloc_zero(state, struct group_info);
- if (!state->info) {
- tevent_req_error(req, ENOMEM);
- return;
+ goto fail;
}
- state->info->name = talloc_strdup(state->info,
- ldb_msg_find_attr_as_string(msg,
- SYSDB_NAME,
- NULL));
- state->info->gid = ldb_msg_find_attr_as_uint64(msg, SYSDB_UIDNUM, 0);
- if (state->info->gid == 0 || state->info->name == NULL) {
+ info->name = talloc_strdup(info,
+ ldb_msg_find_attr_as_string(msg,
+ SYSDB_NAME, NULL));
+ info->gid = ldb_msg_find_attr_as_uint64(msg, SYSDB_UIDNUM, 0);
+ if (info->gid == 0 || info->name == NULL) {
DEBUG(3, ("No name or no GID?\n"));
- tevent_req_error(req, EIO);
- return;
+ ret = EIO;
+ goto fail;
}
- state->info->mpg = true;
-
- tevent_req_done(req);
-}
-
-static int group_show_mpg_recv(TALLOC_CTX *mem_ctx,
- struct tevent_req *req,
- struct group_info **res)
-{
- struct group_show_mpg_state *state = tevent_req_data(req,
- struct group_show_mpg_state);
- TEVENT_REQ_RETURN_ON_ERROR(req);
- *res = talloc_move(mem_ctx, &state->info);
+ info->mpg = true;
+ *res = info;
return EOK;
+
+fail:
+ talloc_zfree(info);
+ return ret;
}
/*==================The main program=================================== */
@@ -929,19 +887,6 @@ static void sss_group_show_done(struct tevent_req *req)
sss_state->done = true;
}
-static void sss_group_show_mpg_done(struct tevent_req *req)
-{
- int ret;
- struct sss_groupshow_state *sss_state = tevent_req_callback_data(req,
- struct sss_groupshow_state);
-
- ret = group_show_mpg_recv(sss_state, req, &sss_state->root);
- talloc_zfree(req);
-
- sss_state->ret = ret;
- sss_state->done = true;
-}
-
static void print_group_info(struct group_info *g, int level)
{
int i;
@@ -1093,18 +1038,8 @@ int main(int argc, const char **argv)
state->done = false;
state->ret = EOK;
- req = group_show_mpg_send(tctx, tctx->ev, tctx->sysdb, tctx->handle,
- tctx->local, tctx->octx->name);
- if (!req) {
- ERROR("Cannot initiate search\n");
- ret = EXIT_FAILURE;
- goto fini;
- }
- tevent_req_set_callback(req, sss_group_show_mpg_done, state);
- while (!state->done) {
- tevent_loop_once(tctx->ev);
- }
- ret = state->ret;
+ ret = group_show_mpg(tctx, tctx->sysdb, tctx->local,
+ tctx->octx->name, &state->root);
}
/* Process result */