summaryrefslogtreecommitdiff
path: root/server/tools/sss_usermod.c
diff options
context:
space:
mode:
Diffstat (limited to 'server/tools/sss_usermod.c')
-rw-r--r--server/tools/sss_usermod.c61
1 files changed, 15 insertions, 46 deletions
diff --git a/server/tools/sss_usermod.c b/server/tools/sss_usermod.c
index 5be1dfb6..2c2b80ec 100644
--- a/server/tools/sss_usermod.c
+++ b/server/tools/sss_usermod.c
@@ -30,42 +30,7 @@
#include "util/util.h"
#include "db/sysdb.h"
#include "tools/tools_util.h"
-
-static void mod_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);
-
- /* usermod */
- ret = usermod(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)
{
@@ -95,7 +60,6 @@ int main(int argc, const char **argv)
int ret;
const char *pc_username = NULL;
struct tools_ctx *tctx = NULL;
- struct tevent_req *req;
debug_prg_name = argv[0];
@@ -215,19 +179,24 @@ int main(int argc, const char **argv)
tctx->octx->gid = pc_gid;
tctx->octx->lock = pc_lock;
- 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, mod_user_transaction, tctx);
- while (!tctx->transaction_done) {
- tevent_loop_once(tctx->ev);
+ /* usermod */
+ ret = usermod(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) {