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_userdel.c | 62 +++++++++++----------------------------------- 1 file changed, 15 insertions(+), 47 deletions(-) (limited to 'server/tools/sss_userdel.c') diff --git a/server/tools/sss_userdel.c b/server/tools/sss_userdel.c index 83db3cd5..8c7c7bd7 100644 --- a/server/tools/sss_userdel.c +++ b/server/tools/sss_userdel.c @@ -29,47 +29,11 @@ #include "db/sysdb.h" #include "util/util.h" #include "tools/tools_util.h" - -static void del_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); - - /* userdel */ - ret = userdel(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; -} +#include "tools/sss_sync_ops.h" int main(int argc, const char **argv) { int ret = EXIT_SUCCESS; - struct tevent_req *req; struct tools_ctx *tctx = NULL; struct passwd *pwd_info; const char *pc_username = NULL; @@ -141,20 +105,24 @@ int main(int argc, const char **argv) goto fini; } - /* userdel */ - 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 remove user.\n"); - ret = EXIT_FAILURE; - goto fini; + start_transaction(tctx); + if (tctx->error != EOK) { + goto done; } - tevent_req_set_callback(req, del_user_transaction, tctx); - while (!tctx->transaction_done) { - tevent_loop_once(tctx->ev); + /* userdel */ + ret = userdel(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; DEBUG(1, ("sysdb operation failed (%d)[%s]\n", ret, strerror(ret))); -- cgit