diff options
-rw-r--r-- | src/db/sysdb.h | 38 | ||||
-rw-r--r-- | src/db/sysdb_ops.c | 236 | ||||
-rw-r--r-- | src/tests/sysdb-tests.c | 42 | ||||
-rw-r--r-- | src/tools/sss_sync_ops.c | 429 |
4 files changed, 117 insertions, 628 deletions
diff --git a/src/db/sysdb.h b/src/db/sysdb.h index 6daad776d..29dac35d0 100644 --- a/src/db/sysdb.h +++ b/src/db/sysdb.h @@ -447,13 +447,11 @@ int sysdb_add_group(TALLOC_CTX *mem_ctx, int cache_timeout); /* mod_op must be either LDB_FLAG_MOD_ADD or LDB_FLAG_MOD_DELETE */ -struct tevent_req *sysdb_mod_group_member_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct sysdb_handle *handle, - struct ldb_dn *member_dn, - struct ldb_dn *group_dn, - int mod_op); -int sysdb_mod_group_member_recv(struct tevent_req *req); +int sysdb_mod_group_member(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *ctx, + struct ldb_dn *member_dn, + struct ldb_dn *group_dn, + int mod_op); int sysdb_set_group_gid(struct sysdb_handle *handle, struct sss_domain_info *domain, @@ -480,21 +478,17 @@ int sysdb_store_group(TALLOC_CTX *mem_ctx, struct sysdb_attrs *attrs, uint64_t cache_timeout); -struct tevent_req *sysdb_add_group_member_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct sysdb_handle *handle, - struct sss_domain_info *domain, - const char *group, - const char *member); -int sysdb_add_group_member_recv(struct tevent_req *req); - -struct tevent_req *sysdb_remove_group_member_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct sysdb_handle *handle, - struct sss_domain_info *domain, - const char *group, - const char *member); -int sysdb_remove_group_member_recv(struct tevent_req *req); +int sysdb_add_group_member(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *ctx, + struct sss_domain_info *domain, + const char *group, + const char *user); + +int sysdb_remove_group_member(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *ctx, + struct sss_domain_info *domain, + const char *group, + const char *user); /* Password caching function. * If you are in a transaction ignore sysdb and pass in the handle. diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c index 879517000..cdbe9aafb 100644 --- a/src/db/sysdb_ops.c +++ b/src/db/sysdb_ops.c @@ -201,46 +201,6 @@ static int sldb_request_recv(struct tevent_req *req, /* =Standard-Sysdb-Operations-utility-functions=========================== */ -struct sysdb_op_state { - struct tevent_context *ev; - struct sysdb_handle *handle; - - bool ignore_not_found; - - struct ldb_reply *ldbreply; - size_t msgs_count; - struct ldb_message **msgs; -}; - -static void sysdb_op_default_done(struct tevent_req *subreq) -{ - struct tevent_req *req = tevent_req_callback_data(subreq, - struct tevent_req); - struct sysdb_op_state *state = tevent_req_data(req, - struct sysdb_op_state); - int ret; - - ret = sldb_request_recv(subreq, state, &state->ldbreply); - talloc_zfree(subreq); - if (ret) { - if (state->ignore_not_found && ret == ENOENT) { - goto done; - } - DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); - tevent_req_error(req, ret); - return; - } - - if (state->ldbreply->type != LDB_REPLY_DONE) { - DEBUG(6, ("Error: %d (%s)\n", EIO, strerror(EIO))); - tevent_req_error(req, EIO); - return; - } - -done: - tevent_req_done(req); -} - static int sysdb_op_default_recv(struct tevent_req *req) { TEVENT_REQ_RETURN_ON_ERROR(req); @@ -1143,29 +1103,17 @@ done: /* =Add-Or-Remove-Group-Memeber=========================================== */ /* mod_op must be either SYSDB_MOD_ADD or SYSDB_MOD_DEL */ -struct tevent_req *sysdb_mod_group_member_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct sysdb_handle *handle, - struct ldb_dn *member_dn, - struct ldb_dn *group_dn, - int mod_op) +int sysdb_mod_group_member(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *ctx, + struct ldb_dn *member_dn, + struct ldb_dn *group_dn, + int mod_op) { - struct tevent_req *req, *subreq; - struct sysdb_op_state *state; - struct ldb_request *ldbreq; struct ldb_message *msg; const char *dn; int ret; - req = tevent_req_create(mem_ctx, &state, struct sysdb_op_state); - if (!req) return NULL; - - state->ev = ev; - state->handle = handle; - state->ignore_not_found = false; - state->ldbreply = NULL; - - msg = ldb_msg_new(state); + msg = ldb_msg_new(mem_ctx); if (!msg) { ERROR_OUT(ret, ENOMEM, fail); } @@ -1186,32 +1134,15 @@ struct tevent_req *sysdb_mod_group_member_send(TALLOC_CTX *mem_ctx, ERROR_OUT(ret, EINVAL, fail); } - ret = ldb_build_mod_req(&ldbreq, handle->ctx->ldb, state, msg, - NULL, NULL, NULL, NULL); - if (ret != LDB_SUCCESS) { - DEBUG(1, ("Failed to build modify request: %s(%d)[%s]\n", - ldb_strerror(ret), ret, ldb_errstring(handle->ctx->ldb))); - ERROR_OUT(ret, sysdb_error_to_errno(ret), fail); - } - - subreq = sldb_request_send(state, ev, handle->ctx->ldb, ldbreq); - if (!subreq) { - ERROR_OUT(ret, ENOMEM, fail); - } - tevent_req_set_callback(subreq, sysdb_op_default_done, req); - - return req; + ret = ldb_modify(ctx->ldb, msg); + ret = sysdb_error_to_errno(ret); fail: - DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); - tevent_req_error(req, ret); - tevent_req_post(req, ev); - return req; -} - -int sysdb_mod_group_member_recv(struct tevent_req *req) -{ - return sysdb_op_default_recv(req); + if (ret) { + DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); + } + talloc_zfree(msg); + return ret; } @@ -1404,149 +1335,56 @@ done: /* =Add-User-to-Group(Native/Legacy)====================================== */ -static void sysdb_add_group_member_done(struct tevent_req *subreq); -struct tevent_req *sysdb_add_group_member_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct sysdb_handle *handle, - struct sss_domain_info *domain, - const char *group, - const char *user) +int sysdb_add_group_member(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *ctx, + struct sss_domain_info *domain, + const char *group, + const char *user) { - struct tevent_req *req, *subreq; - struct sysdb_op_state *state; struct ldb_dn *group_dn, *user_dn; int ret; - req = tevent_req_create(mem_ctx, &state, struct sysdb_op_state); - if (!req) return NULL; - - state->ev = ev; - state->handle = handle; - state->ignore_not_found = false; - state->ldbreply = NULL; - - group_dn = sysdb_group_dn(handle->ctx, state, domain->name, group); + group_dn = sysdb_group_dn(ctx, mem_ctx, domain->name, group); if (!group_dn) { - ERROR_OUT(ret, ENOMEM, fail); + return ENOMEM; } - user_dn = sysdb_user_dn(handle->ctx, state, domain->name, user); + user_dn = sysdb_user_dn(ctx, mem_ctx, domain->name, user); if (!user_dn) { - ERROR_OUT(ret, ENOMEM, fail); - } - - subreq = sysdb_mod_group_member_send(state, ev, handle, - user_dn, group_dn, - SYSDB_MOD_ADD); - if (!subreq) { - ERROR_OUT(ret, ENOMEM, fail); - } - tevent_req_set_callback(subreq, sysdb_add_group_member_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_add_group_member_done(struct tevent_req *subreq) -{ - struct tevent_req *req = tevent_req_callback_data(subreq, - struct tevent_req); - int ret; - - ret = sysdb_mod_group_member_recv(subreq); - talloc_zfree(subreq); - if (ret) { - DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); - tevent_req_error(req, ret); - return; + return ENOMEM; } - tevent_req_done(req); -} - -int sysdb_add_group_member_recv(struct tevent_req *req) -{ - return sysdb_op_default_recv(req); + ret = sysdb_mod_group_member(mem_ctx, ctx, + user_dn, group_dn, SYSDB_MOD_ADD); + return ret; } - /* =Remove-member-from-Group(Native/Legacy)=============================== */ -static void sysdb_remove_group_member_done(struct tevent_req *subreq); -struct tevent_req *sysdb_remove_group_member_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct sysdb_handle *handle, - struct sss_domain_info *domain, - const char *group, - const char *user) +int sysdb_remove_group_member(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *ctx, + struct sss_domain_info *domain, + const char *group, + const char *user) { - struct tevent_req *req, *subreq; - struct sysdb_op_state *state; struct ldb_dn *group_dn, *user_dn; int ret; - req = tevent_req_create(mem_ctx, &state, struct sysdb_op_state); - if (!req) return NULL; - - state->ev = ev; - state->handle = handle; - state->ignore_not_found = false; - state->ldbreply = NULL; - - group_dn = sysdb_group_dn(handle->ctx, state, domain->name, group); + group_dn = sysdb_group_dn(ctx, mem_ctx, domain->name, group); if (!group_dn) { - ERROR_OUT(ret, ENOMEM, fail); + return ENOMEM; } - user_dn = sysdb_user_dn(handle->ctx, state, domain->name, user); + user_dn = sysdb_user_dn(ctx, mem_ctx, domain->name, user); if (!user_dn) { - ERROR_OUT(ret, ENOMEM, fail); - } - - subreq = sysdb_mod_group_member_send(state, ev, handle, - user_dn, group_dn, - SYSDB_MOD_DEL); - if (!subreq) { - ERROR_OUT(ret, ENOMEM, fail); - } - tevent_req_set_callback(subreq, sysdb_remove_group_member_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_remove_group_member_done(struct tevent_req *subreq) -{ - struct tevent_req *req = tevent_req_callback_data(subreq, - struct tevent_req); - int ret; - - ret = sysdb_mod_group_member_recv(subreq); - talloc_zfree(subreq); - if (ret) { - DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); - tevent_req_error(req, ret); - return; + return ENOMEM; } - tevent_req_done(req); -} - -int sysdb_remove_group_member_recv(struct tevent_req *req) -{ - return sysdb_op_default_recv(req); + ret = sysdb_mod_group_member(mem_ctx, ctx, + user_dn, group_dn, SYSDB_MOD_DEL); + return ret; } diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c index 061858daf..140179634 100644 --- a/src/tests/sysdb-tests.c +++ b/src/tests/sysdb-tests.c @@ -662,12 +662,9 @@ static void test_get_user_attr(void *pvt, int error, struct ldb_result *res) } } -static void test_add_group_member_done(struct tevent_req *subreq); - static void test_add_group_member(struct tevent_req *req) { struct test_data *data = tevent_req_callback_data(req, struct test_data); - struct tevent_req *subreq; const char *username; int ret; @@ -681,31 +678,16 @@ static void test_add_group_member(struct tevent_req *req) test_return(data, ENOMEM); } - subreq = sysdb_add_group_member_send(data, data->ev, - data->handle, data->ctx->domain, - data->groupname, username); - if (!subreq) { - test_return(data, ENOMEM); - } - - tevent_req_set_callback(subreq, test_add_group_member_done, data); -} - -static void test_add_group_member_done(struct tevent_req *subreq) -{ - struct test_data *data = tevent_req_callback_data(subreq, - struct test_data); - int ret = sysdb_add_group_member_recv(subreq); + ret = sysdb_add_group_member(data, data->handle->ctx, + data->ctx->domain, + data->groupname, username); test_return(data, ret); } -static void test_remove_group_member_done(struct tevent_req *subreq); - static void test_remove_group_member(struct tevent_req *req) { struct test_data *data = tevent_req_callback_data(req, struct test_data); - struct tevent_req *subreq; const char *username; int ret; @@ -719,21 +701,9 @@ static void test_remove_group_member(struct tevent_req *req) test_return(data, ENOMEM); } - subreq = sysdb_remove_group_member_send(data, data->ev, - data->handle, data->ctx->domain, - data->groupname, username); - if (!subreq) { - test_return(data, ENOMEM); - } - - tevent_req_set_callback(subreq, test_remove_group_member_done, data); -} - -static void test_remove_group_member_done(struct tevent_req *subreq) -{ - struct test_data *data = tevent_req_callback_data(subreq, - struct test_data); - int ret = sysdb_remove_group_member_recv(subreq); + ret = sysdb_remove_group_member(data, data->handle->ctx, + data->ctx->domain, + data->groupname, username); test_return(data, ret); } diff --git a/src/tools/sss_sync_ops.c b/src/tools/sss_sync_ops.c index 900edeafc..d84ec7c26 100644 --- a/src/tools/sss_sync_ops.c +++ b/src/tools/sss_sync_ops.c @@ -67,230 +67,56 @@ static int sync_ops_recv(struct tevent_req *req) } /* - * Generic add member to group + * Generic modify groups member */ -struct add_to_groups_state { - struct tevent_context *ev; - struct sysdb_ctx *sysdb; - struct sysdb_handle *handle; - - int cur; - struct ops_ctx *data; - struct ldb_dn *member_dn; -}; - -static void add_to_groups_done(struct tevent_req *subreq); - -static struct tevent_req *add_to_groups_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct sysdb_ctx *sysdb, - struct sysdb_handle *handle, - struct ops_ctx *data, - struct ldb_dn *member_dn) +static int mod_groups_member(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *sysdb, + struct sss_domain_info *domain, + char **grouplist, + struct ldb_dn *member_dn, + int optype) { - struct add_to_groups_state *state; - struct tevent_req *req; - struct tevent_req *subreq; + TALLOC_CTX *tmpctx; struct ldb_dn *parent_dn; - - req = tevent_req_create(mem_ctx, &state, struct add_to_groups_state); - if (req == NULL) { - return NULL; - } - state->ev = ev; - state->sysdb = sysdb; - state->handle = handle; - state->data = data; - state->member_dn = member_dn; - state->cur = 0; - - parent_dn = sysdb_group_dn(state->sysdb, state, - state->data->domain->name, - state->data->addgroups[state->cur]); - if (!parent_dn) { - return NULL; - } - - subreq = sysdb_mod_group_member_send(state, - state->ev, - state->handle, - member_dn, - parent_dn, - LDB_FLAG_MOD_ADD); - if (!subreq) { - talloc_zfree(req); - return NULL; - } - - tevent_req_set_callback(subreq, add_to_groups_done, req); - return req; -} - -static void add_to_groups_done(struct tevent_req *subreq) -{ - struct tevent_req *req = tevent_req_callback_data(subreq, - struct tevent_req); - struct add_to_groups_state *state = tevent_req_data(req, - struct add_to_groups_state); int ret; - struct ldb_dn *parent_dn; - struct tevent_req *next_group_req; + int i; - ret = sysdb_mod_group_member_recv(subreq); - talloc_zfree(subreq); - if (ret) { - tevent_req_error(req, ret); - return; - } - - /* go on to next group */ - state->cur++; - - /* check if we added all of them */ - if (state->data->addgroups[state->cur] == NULL) { - tevent_req_done(req); - return; - } - - /* if not, schedule a new addition */ - parent_dn = sysdb_group_dn(state->sysdb, state, - state->data->domain->name, - state->data->addgroups[state->cur]); - if (!parent_dn) { - tevent_req_error(req, ENOMEM); - return; - } - - next_group_req = sysdb_mod_group_member_send(state, - state->ev, - state->handle, - state->member_dn, - parent_dn, - LDB_FLAG_MOD_ADD); - if (!next_group_req) { - tevent_req_error(req, ENOMEM); - return; - } - tevent_req_set_callback(next_group_req, add_to_groups_done, req); -} - -static int add_to_groups_recv(struct tevent_req *req) -{ - return sync_ops_recv(req); -} - -/* - * Generic remove member from group - */ -struct remove_from_groups_state { - struct tevent_context *ev; - struct sysdb_ctx *sysdb; - struct sysdb_handle *handle; - - int cur; - struct ops_ctx *data; - struct ldb_dn *member_dn; -}; - -static void remove_from_groups_done(struct tevent_req *subreq); - -static struct tevent_req *remove_from_groups_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct sysdb_ctx *sysdb, - struct sysdb_handle *handle, - struct ops_ctx *data, - struct ldb_dn *member_dn) -{ - struct tevent_req *req; - struct tevent_req *subreq; - struct ldb_dn *parent_dn; - struct remove_from_groups_state *state; - - req = tevent_req_create(mem_ctx, &state, struct remove_from_groups_state); - if (req == NULL) { - return NULL; - } - state->ev = ev; - state->sysdb = sysdb; - state->handle = handle; - state->data = data; - state->member_dn = member_dn; - state->cur = 0; - - parent_dn = sysdb_group_dn(state->sysdb, state, - state->data->domain->name, - state->data->rmgroups[state->cur]); - if (!parent_dn) { - return NULL; - } - - subreq = sysdb_mod_group_member_send(state, - state->ev, - state->handle, - state->member_dn, - parent_dn, - LDB_FLAG_MOD_DELETE); - if (!subreq) { - talloc_zfree(req); - return NULL; + tmpctx = talloc_new(NULL); + if (!tmpctx) { + return ENOMEM; } - tevent_req_set_callback(subreq, remove_from_groups_done, req); - return req; -} - -static void remove_from_groups_done(struct tevent_req *subreq) -{ - struct tevent_req *req = tevent_req_callback_data(subreq, - struct tevent_req); - struct remove_from_groups_state *state = tevent_req_data(req, - struct remove_from_groups_state); - int ret; - struct ldb_dn *parent_dn; - struct tevent_req *next_group_req; +/* FIXME: add transaction around loop */ + for (i = 0; grouplist[i]; i++) { - ret = sysdb_mod_group_member_recv(subreq); - talloc_zfree(subreq); - if (ret) { - tevent_req_error(req, ret); - return; - } - - /* go on to next group */ - state->cur++; + parent_dn = sysdb_group_dn(sysdb, tmpctx, + domain->name, + grouplist[i]); + if (!parent_dn) { + ret = ENOMEM; + goto done; + } - /* check if we removed all of them */ - if (state->data->rmgroups[state->cur] == NULL) { - tevent_req_done(req); - return; + ret = sysdb_mod_group_member(tmpctx, sysdb, + member_dn, parent_dn, optype); + if (ret) { + goto done; + } } - /* if not, schedule a new removal */ - parent_dn = sysdb_group_dn(state->sysdb, state, - state->data->domain->name, - state->data->rmgroups[state->cur]); - if (!parent_dn) { - tevent_req_error(req, ENOMEM); - return; - } + ret = EOK; - next_group_req = sysdb_mod_group_member_send(state, - state->ev, - state->handle, - state->member_dn, - parent_dn, - LDB_FLAG_MOD_DELETE); - if (!next_group_req) { - tevent_req_error(req, ENOMEM); - return; - } - tevent_req_set_callback(next_group_req, remove_from_groups_done, req); +done: + talloc_zfree(tmpctx); + return ret; } -static int remove_from_groups_recv(struct tevent_req *req) -{ - return sync_ops_recv(req); -} +#define add_to_groups(memctx, sysdb, data, member_dn) \ + mod_groups_member(memctx, sysdb, data->domain, \ + data->addgroups, member_dn, LDB_FLAG_MOD_ADD) +#define remove_from_groups(memctx, sysdb, data, member_dn) \ + mod_groups_member(memctx, sysdb, data->domain, \ + data->rmgroups, member_dn, LDB_FLAG_MOD_DELETE) /* * Modify a user @@ -385,8 +211,6 @@ static int usermod_build_attrs(TALLOC_CTX *mem_ctx, } static void user_mod_attr_wakeup(struct tevent_req *subreq); -static void user_mod_rm_group_done(struct tevent_req *groupreq); -static void user_mod_add_group_done(struct tevent_req *groupreq); static struct tevent_req *user_mod_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, @@ -448,7 +272,6 @@ static void user_mod_attr_wakeup(struct tevent_req *subreq) struct tevent_req); struct user_mod_state *state = tevent_req_data(req, struct user_mod_state); - struct tevent_req *groupreq; int ret; if (state->attrs->num != 0) { @@ -462,76 +285,24 @@ static void user_mod_attr_wakeup(struct tevent_req *subreq) } if (state->data->rmgroups != NULL) { - groupreq = remove_from_groups_send(state, state->ev, state->sysdb, - state->handle, state->data, state->member_dn); - if (!groupreq) { - tevent_req_error(req, ENOMEM); + ret = remove_from_groups(state, state->sysdb, + state->data, state->member_dn); + if (ret) { + tevent_req_error(req, ret); return; } - tevent_req_set_callback(groupreq, user_mod_rm_group_done, req); - return; } if (state->data->addgroups != NULL) { - groupreq = add_to_groups_send(state, state->ev, state->sysdb, - state->handle, state->data, state->member_dn); - if (!groupreq) { - tevent_req_error(req, ENOMEM); + ret = add_to_groups(state, state->sysdb, + state->data, state->member_dn); + if (ret) { + tevent_req_error(req, ret); return; } - tevent_req_set_callback(groupreq, user_mod_add_group_done, req); - return; - } - - /* No changes to be made, mark request as done */ - tevent_req_done(req); -} - -static void user_mod_rm_group_done(struct tevent_req *groupreq) -{ - struct tevent_req *req = tevent_req_callback_data(groupreq, - struct tevent_req); - struct user_mod_state *state = tevent_req_data(req, - struct user_mod_state); - int ret; - struct tevent_req *addreq; - - ret = remove_from_groups_recv(groupreq); - talloc_zfree(groupreq); - if (ret) { - tevent_req_error(req, ret); - return; - } - - if (state->data->addgroups != NULL) { - addreq = add_to_groups_send(state, state->ev, state->sysdb, - state->handle, state->data, state->member_dn); - if (!addreq) { - tevent_req_error(req, ENOMEM); - } - tevent_req_set_callback(addreq, user_mod_add_group_done, req); - return; } tevent_req_done(req); - return; -} - -static void user_mod_add_group_done(struct tevent_req *groupreq) -{ - struct tevent_req *req = tevent_req_callback_data(groupreq, - struct tevent_req); - int ret; - - ret = add_to_groups_recv(groupreq); - talloc_zfree(groupreq); - if (ret) { - tevent_req_error(req, ret); - return; - } - - tevent_req_done(req); - return; } static int user_mod_recv(struct tevent_req *req) @@ -554,8 +325,6 @@ struct group_mod_state { }; static void group_mod_attr_wakeup(struct tevent_req *); -static void group_mod_add_group_done(struct tevent_req *groupreq); -static void group_mod_rm_group_done(struct tevent_req *groupreq); static struct tevent_req *group_mod_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, @@ -603,7 +372,6 @@ static void group_mod_attr_wakeup(struct tevent_req *subreq) struct group_mod_state *state = tevent_req_data(req, struct group_mod_state); struct sysdb_attrs *attrs; - struct tevent_req *groupreq; int ret; if (state->data->gid != 0) { @@ -628,76 +396,24 @@ static void group_mod_attr_wakeup(struct tevent_req *subreq) } if (state->data->rmgroups != NULL) { - groupreq = remove_from_groups_send(state, state->ev, state->sysdb, - state->handle, state->data, state->member_dn); - if (!groupreq) { - tevent_req_error(req, ENOMEM); + ret = remove_from_groups(state, state->sysdb, + state->data, state->member_dn); + if (ret) { + tevent_req_error(req, ret); return; } - tevent_req_set_callback(groupreq, group_mod_rm_group_done, req); - return; } if (state->data->addgroups != NULL) { - groupreq = add_to_groups_send(state, state->ev, state->sysdb, - state->handle, state->data, state->member_dn); - if (!groupreq) { - tevent_req_error(req, ENOMEM); + ret = add_to_groups(state, state->sysdb, + state->data, state->member_dn); + if (ret) { + tevent_req_error(req, ret); return; } - tevent_req_set_callback(groupreq, group_mod_add_group_done, req); - return; - } - - /* No changes to be made, mark request as done */ - tevent_req_done(req); -} - -static void group_mod_rm_group_done(struct tevent_req *groupreq) -{ - struct tevent_req *req = tevent_req_callback_data(groupreq, - struct tevent_req); - struct group_mod_state *state = tevent_req_data(req, - struct group_mod_state); - int ret; - struct tevent_req *addreq; - - ret = remove_from_groups_recv(groupreq); - talloc_zfree(groupreq); - if (ret) { - tevent_req_error(req, ret); - return; - } - - if (state->data->addgroups != NULL) { - addreq = add_to_groups_send(state, state->ev, state->sysdb, - state->handle, state->data, state->member_dn); - if (!addreq) { - tevent_req_error(req, ENOMEM); - } - tevent_req_set_callback(addreq, group_mod_add_group_done, req); - return; - } - - tevent_req_done(req); - return; -} - -static void group_mod_add_group_done(struct tevent_req *groupreq) -{ - struct tevent_req *req = tevent_req_callback_data(groupreq, - struct tevent_req); - int ret; - - ret = add_to_groups_recv(groupreq); - talloc_zfree(groupreq); - if (ret) { - tevent_req_error(req, ret); - return; } tevent_req_done(req); - return; } static int group_mod_recv(struct tevent_req *req) @@ -868,8 +584,6 @@ done: /* * Public interface for adding users */ -static void useradd_done(struct tevent_req *); - int useradd(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct sysdb_ctx *sysdb, @@ -877,16 +591,8 @@ int useradd(TALLOC_CTX *mem_ctx, struct ops_ctx *data) { int ret; - struct tevent_req *req; - struct sync_op_res *res = NULL; - struct ldb_dn *member_dn; - - res = talloc_zero(mem_ctx, struct sync_op_res); - if (!res) { - return ENOMEM; - } - ret = sysdb_add_user(res, sysdb, + ret = sysdb_add_user(mem_ctx, sysdb, data->domain, data->name, data->uid, data->gid, data->gecos, data->home, data->shell, NULL, 0); if (ret) { @@ -894,47 +600,28 @@ int useradd(TALLOC_CTX *mem_ctx, } if (data->addgroups) { - member_dn = sysdb_user_dn(sysdb, res, + struct ldb_dn *member_dn; + + member_dn = sysdb_user_dn(sysdb, mem_ctx, data->domain->name, data->name); if (!member_dn) { ret = ENOMEM; goto done; } - req = add_to_groups_send(res, ev, sysdb, handle, data, member_dn); - if (!req) { - ret = ENOMEM; + ret = add_to_groups(mem_ctx, sysdb, data, member_dn); + if (ret) { goto done; } - tevent_req_set_callback(req, useradd_done, res); - - SYNC_LOOP(res, ret); } flush_nscd_cache(mem_ctx, NSCD_DB_PASSWD); flush_nscd_cache(mem_ctx, NSCD_DB_GROUP); done: - talloc_free(res); return ret; } -static void useradd_done(struct tevent_req *req) -{ - int ret; - struct sync_op_res *res = tevent_req_callback_data(req, - struct sync_op_res); - - ret = add_to_groups_recv(req); - talloc_free(req); - if (ret) { - DEBUG(2, ("Adding user failed: %s (%d)\n", strerror(ret), ret)); - } - - res->done = true; - res->error = ret; -} - /* * Public interface for deleting users */ |