From f24c2dd7cc8414ea0a5c8c4ae7766ca71554480f Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 29 Sep 2009 10:14:36 -0400 Subject: Fix tools sync operations and mem hierarchy Tools were using nested loops that are illegal. (and enforced in latest tevent with a nice abort()) Fix them by creating appropriate synchronous transaction calls. Also fix tools_ctx mem hierarchy setup. --- server/tools/sss_useradd.c | 67 ++++++++++++---------------------------------- 1 file changed, 17 insertions(+), 50 deletions(-) (limited to 'server/tools/sss_useradd.c') diff --git a/server/tools/sss_useradd.c b/server/tools/sss_useradd.c index 61034bef6..07e741e47 100644 --- a/server/tools/sss_useradd.c +++ b/server/tools/sss_useradd.c @@ -30,6 +30,7 @@ #include "util/util.h" #include "db/sysdb.h" #include "tools/tools_util.h" +#include "tools/sss_sync_ops.h" #include "util/sssd-i18n.h" /* Default settings for user attributes */ @@ -107,42 +108,6 @@ done: return ret; } -static void add_user_transaction(struct tevent_req *req) -{ - int ret; - struct tools_ctx *tctx = tevent_req_callback_data(req, - struct tools_ctx); - struct tevent_req *subreq; - - ret = sysdb_transaction_recv(req, tctx, &tctx->handle); - if (ret) { - tevent_req_error(req, ret); - return; - } - talloc_zfree(req); - - /* useradd */ - ret = useradd(tctx, tctx->ev, - tctx->sysdb, tctx->handle, tctx->octx); - if (ret != EOK) { - goto fail; - } - - subreq = sysdb_transaction_commit_send(tctx, tctx->ev, tctx->handle); - if (!subreq) { - ret = ENOMEM; - goto fail; - } - tevent_req_set_callback(subreq, tools_transaction_done, tctx); - return; - -fail: - /* free transaction and signal error */ - talloc_zfree(tctx->handle); - tctx->transaction_done = true; - tctx->error = ret; -} - int main(int argc, const char **argv) { uid_t pc_uid = 0; @@ -164,7 +129,6 @@ int main(int argc, const char **argv) POPT_TABLEEND }; poptContext pc = NULL; - struct tevent_req *req; struct tools_ctx *tctx = NULL; char *groups = NULL; int ret; @@ -272,30 +236,33 @@ int main(int argc, const char **argv) goto fini; } - /* useradd */ - req = sysdb_transaction_send(tctx->octx, tctx->ev, tctx->sysdb); - if (!req) { - DEBUG(1, ("Could not start transaction (%d)[%s]\n", ret, strerror(ret))); - ERROR("Transaction error. Could not modify user.\n"); - ret = EXIT_FAILURE; - goto fini; + start_transaction(tctx); + if (tctx->error != EOK) { + goto done; } - tevent_req_set_callback(req, add_user_transaction, tctx); - while (!tctx->transaction_done) { - tevent_loop_once(tctx->ev); + /* useradd */ + ret = useradd(tctx, tctx->ev, tctx->sysdb, tctx->handle, tctx->octx); + if (ret != EOK) { + tctx->error = ret; + + /* cancel transaction */ + talloc_zfree(tctx->handle); + goto done; } + end_transaction(tctx); + +done: if (tctx->error) { - ret = tctx->error; - switch (ret) { + switch (tctx->error) { case EEXIST: ERROR("A user with the same name or UID already exists\n"); break; default: DEBUG(1, ("sysdb operation failed (%d)[%s]\n", - ret, strerror(ret))); + tctx->error, strerror(tctx->error))); ERROR("Transaction error. Could not add user.\n"); break; } -- cgit