summaryrefslogtreecommitdiffstats
path: root/src/python
diff options
context:
space:
mode:
authorMichal Zidek <mzidek@redhat.com>2012-08-16 18:48:53 +0200
committerJakub Hrozek <jhrozek@redhat.com>2012-08-23 18:09:18 +0200
commit21d485184df986e1a123f70c689517386e51a5ce (patch)
tree7b2165fdc4dadcc632d402866b704df04ede852f /src/python
parent0051296f67bd7d8e2e3094638ddff4e641324d04 (diff)
downloadsssd-21d485184df986e1a123f70c689517386e51a5ce.tar.gz
sssd-21d485184df986e1a123f70c689517386e51a5ce.tar.xz
sssd-21d485184df986e1a123f70c689517386e51a5ce.zip
Unify usage of sysdb transactions
Removing bad examples of usage of sysdb_transaction_start/commit/end functions and making it more consistent (all files except of src/db/sysdb_*.c).
Diffstat (limited to 'src/python')
-rw-r--r--src/python/pysss.c44
1 files changed, 36 insertions, 8 deletions
diff --git a/src/python/pysss.c b/src/python/pysss.c
index 45725c0c9..842c1b5e4 100644
--- a/src/python/pysss.c
+++ b/src/python/pysss.c
@@ -170,6 +170,7 @@ static PyObject *py_sss_useradd(PySssLocalObject *self,
PyObject *py_groups = Py_None;
PyObject *py_create_home = Py_None;
int create_home = 0;
+ bool in_transaction = false;
/* parse arguments */
if (!PyArg_ParseTupleAndKeywords(args, kwds,
@@ -232,12 +233,11 @@ static PyObject *py_sss_useradd(PySssLocalObject *self,
PyErr_SetSssError(tctx->error);
goto fail;
}
+ in_transaction = true;
/* useradd */
tctx->error = useradd(tctx, tctx->sysdb, tctx->octx);
if (tctx->error) {
- /* cancel transaction */
- sysdb_transaction_cancel(tctx->sysdb);
PyErr_SetSssError(tctx->error);
goto fail;
}
@@ -247,6 +247,7 @@ static PyObject *py_sss_useradd(PySssLocalObject *self,
PyErr_SetSssError(tctx->error);
goto fail;
}
+ in_transaction = false;
/* Create user's home directory and/or mail spool */
if (tctx->octx->create_homedir) {
@@ -285,6 +286,12 @@ static PyObject *py_sss_useradd(PySssLocalObject *self,
Py_RETURN_NONE;
fail:
+ if (in_transaction) {
+ /* We do not handle return value of sysdb_transaction_cancel()
+ * because we don't want to overwrite previous error code.
+ */
+ sysdb_transaction_cancel(tctx->sysdb);
+ }
talloc_zfree(tctx);
return NULL;
}
@@ -428,6 +435,7 @@ static PyObject *py_sss_usermod(PySssLocalObject *self,
const char * const kwlist[] = { "username", "uid", "gid", "lock",
"gecos", "homedir", "shell",
"addgroups", "rmgroups", NULL };
+ bool in_transaction = false;
/* parse arguments */
if (!PyArg_ParseTupleAndKeywords(args, kwds,
@@ -491,12 +499,11 @@ static PyObject *py_sss_usermod(PySssLocalObject *self,
PyErr_SetSssError(tctx->error);
goto fail;
}
+ in_transaction = true;
/* usermod */
tctx->error = usermod(tctx, tctx->sysdb, tctx->octx);
if (tctx->error) {
- /* cancel transaction */
- sysdb_transaction_cancel(tctx->sysdb);
PyErr_SetSssError(tctx->error);
goto fail;
}
@@ -506,11 +513,18 @@ static PyObject *py_sss_usermod(PySssLocalObject *self,
PyErr_SetSssError(tctx->error);
goto fail;
}
+ in_transaction = false;
talloc_zfree(tctx);
Py_RETURN_NONE;
fail:
+ if (in_transaction) {
+ /* We do not handle return value of sysdb_transaction_cancel()
+ * because we don't want to overwrite previous error code.
+ */
+ sysdb_transaction_cancel(tctx->sysdb);
+ }
talloc_zfree(tctx);
return NULL;
}
@@ -533,6 +547,7 @@ static PyObject *py_sss_groupadd(PySssLocalObject *self,
char *groupname;
unsigned long gid = 0;
const char * const kwlist[] = { "groupname", "gid", NULL };
+ bool in_transaction = false;
/* parse arguments */
if (!PyArg_ParseTupleAndKeywords(args, kwds,
@@ -558,12 +573,11 @@ static PyObject *py_sss_groupadd(PySssLocalObject *self,
PyErr_SetSssError(tctx->error);
goto fail;
}
+ in_transaction = true;
/* groupadd */
tctx->error = groupadd(tctx->sysdb, tctx->octx);
if (tctx->error) {
- /* cancel transaction */
- sysdb_transaction_cancel(tctx->sysdb);
PyErr_SetSssError(tctx->error);
goto fail;
}
@@ -573,11 +587,18 @@ static PyObject *py_sss_groupadd(PySssLocalObject *self,
PyErr_SetSssError(tctx->error);
goto fail;
}
+ in_transaction = false;
talloc_zfree(tctx);
Py_RETURN_NONE;
fail:
+ if (in_transaction) {
+ /* We do not handle return value of sysdb_transaction_cancel()
+ * because we don't want to overwrite previous error code.
+ */
+ sysdb_transaction_cancel(tctx->sysdb);
+ }
talloc_zfree(tctx);
return NULL;
}
@@ -647,6 +668,7 @@ static PyObject *py_sss_groupmod(PySssLocalObject *self,
char *groupname = NULL;
const char * const kwlist[] = { "groupname", "gid", "addgroups",
"rmgroups", NULL };
+ bool in_transaction = false;
/* parse arguments */
if (!PyArg_ParseTupleAndKeywords(args, kwds,
@@ -694,12 +716,11 @@ static PyObject *py_sss_groupmod(PySssLocalObject *self,
PyErr_SetSssError(tctx->error);
goto fail;
}
+ in_transaction = true;
/* groupmod */
tctx->error = groupmod(tctx, tctx->sysdb, tctx->octx);
if (tctx->error) {
- /* cancel transaction */
- sysdb_transaction_cancel(tctx->sysdb);
PyErr_SetSssError(tctx->error);
goto fail;
}
@@ -709,11 +730,18 @@ static PyObject *py_sss_groupmod(PySssLocalObject *self,
PyErr_SetSssError(tctx->error);
goto fail;
}
+ in_transaction = false;
talloc_zfree(tctx);
Py_RETURN_NONE;
fail:
+ if (in_transaction) {
+ /* We do not handle return value of sysdb_transaction_cancel()
+ * because we don't want to overwrite previous error code.
+ */
+ sysdb_transaction_cancel(tctx->sysdb);
+ }
talloc_zfree(tctx);
return NULL;
}