summaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
Diffstat (limited to 'src/db')
-rw-r--r--src/db/sysdb.h30
-rw-r--r--src/db/sysdb_ops.c603
2 files changed, 174 insertions, 459 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)