summaryrefslogtreecommitdiff
path: root/libgpo
diff options
context:
space:
mode:
authorKristján Valur <kristjan@rvx.is>2019-02-27 14:12:43 +0000
committerNoel Power <npower@samba.org>2019-03-07 14:08:21 +0000
commit08b5b11b96c5325d314a0ec8dc9291542e255f6f (patch)
tree65b6e017aa59a7ea3d2905d2cdaa1e61f81eebfa /libgpo
parent36adf08fabb4977e534eff30bccff30ce427787d (diff)
downloadsamba-08b5b11b96c5325d314a0ec8dc9291542e255f6f.tar.gz
pygpo: Proper exception exit in py_ads_connect().
connect() now succeeds or raises an exception. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13822 Signed-off-by: Kristján Valur Jónsson <kristjan@rvx.is> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Noel Power <npower@samba.org>
Diffstat (limited to 'libgpo')
-rw-r--r--libgpo/pygpo.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/libgpo/pygpo.c b/libgpo/pygpo.c
index 02147f9e670..ceb60e886bb 100644
--- a/libgpo/pygpo.c
+++ b/libgpo/pygpo.c
@@ -220,6 +220,7 @@ static int py_ads_init(ADS *self, PyObject *args, PyObject *kwds)
return 0;
}
+/* connect. Failure to connect results in an Exception */
static PyObject* py_ads_connect(ADS *self)
{
ADS_STATUS status;
@@ -235,10 +236,10 @@ static PyObject* py_ads_connect(ADS *self)
status = ads_connect_user_creds(self->ads_ptr);
if (!ADS_ERR_OK(status)) {
- PyErr_SetString(PyExc_RuntimeError,
- "ads_connect() failed");
- TALLOC_FREE(frame);
- Py_RETURN_FALSE;
+ PyErr_Format(PyExc_RuntimeError,
+ "ads_connect() failed: %s",
+ ads_errstr(status));
+ goto err;
}
} else {
char *passwd = NULL;
@@ -247,8 +248,7 @@ static PyObject* py_ads_connect(ADS *self)
if (ret == -1) {
PyErr_SetString(PyExc_RuntimeError,
"Failed to asprintf");
- TALLOC_FREE(frame);
- Py_RETURN_FALSE;
+ goto err;
} else {
self->ads_ptr->auth.flags |= ADS_AUTH_USER_CREDS;
}
@@ -256,8 +256,7 @@ static PyObject* py_ads_connect(ADS *self)
if (!secrets_init()) {
PyErr_SetString(PyExc_RuntimeError,
"secrets_init() failed");
- TALLOC_FREE(frame);
- Py_RETURN_FALSE;
+ goto err;
}
passwd = secrets_fetch_machine_password(self->ads_ptr->server.workgroup,
@@ -266,30 +265,32 @@ static PyObject* py_ads_connect(ADS *self)
PyErr_SetString(PyExc_RuntimeError,
"Failed to fetch the machine account "
"password");
- TALLOC_FREE(frame);
- Py_RETURN_FALSE;
+ goto err;
}
self->ads_ptr->auth.password = smb_xstrdup(passwd);
SAFE_FREE(passwd);
self->ads_ptr->auth.realm =
smb_xstrdup(self->ads_ptr->server.realm);
if (!strupper_m(self->ads_ptr->auth.realm)) {
- PyErr_SetString(PyExc_RuntimeError, "Failed to strdup");
- TALLOC_FREE(frame);
- Py_RETURN_FALSE;
+ PyErr_SetString(PyExc_RuntimeError, "Failed to strupper");
+ goto err;
}
status = ads_connect(self->ads_ptr);
if (!ADS_ERR_OK(status)) {
- PyErr_SetString(PyExc_RuntimeError,
- "ads_connect() failed");
- TALLOC_FREE(frame);
- Py_RETURN_FALSE;
+ PyErr_Format(PyExc_RuntimeError,
+ "ads_connect() failed: %s",
+ ads_errstr(status));
+ goto err;
}
}
TALLOC_FREE(frame);
Py_RETURN_TRUE;
+
+err:
+ TALLOC_FREE(frame);
+ return NULL;
}
/* Parameter mapping and functions for the GP_EXT struct */