From d2a75489477a6628662e7bb5dd94b3e769e8c3b1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristj=C3=A1n=20Valur?= Date: Wed, 27 Feb 2019 16:36:32 +0000 Subject: [PATCH] pygpo: keep a reference to python credentials in the ADS struct to keep the internal pointer valid. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit BUG: https://bugzilla.samba.org/show_bug.cgi?id=13822 Signed-off-by: Kristján Valur Jónsson Reviewed-by: Andrew Bartlett Reviewed-by: Noel Power --- libgpo/pygpo.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libgpo/pygpo.c b/libgpo/pygpo.c index 5e012dfc972..36e5f1052d0 100644 --- a/libgpo/pygpo.c +++ b/libgpo/pygpo.c @@ -132,12 +132,14 @@ static PyTypeObject GPOType = { typedef struct { PyObject_HEAD ADS_STRUCT *ads_ptr; + PyObject *py_creds; struct cli_credentials *cli_creds; } ADS; static void py_ads_dealloc(ADS* self) { ads_destroy(&(self->ads_ptr)); + Py_CLEAR(self->py_creds); Py_TYPE(self)->tp_free((PyObject*)self); } @@ -154,7 +156,6 @@ static int py_ads_init(ADS *self, PyObject *args, PyObject *kwds) const char *realm = NULL; const char *workgroup = NULL; const char *ldap_server = NULL; - PyObject *py_creds = NULL; PyObject *lp_obj = NULL; struct loadparm_context *lp_ctx = NULL; bool ok = false; @@ -164,18 +165,20 @@ static int py_ads_init(ADS *self, PyObject *args, PyObject *kwds) }; if (!PyArg_ParseTupleAndKeywords(args, kwds, "sO|O", discard_const_p(char *, kwlist), - &ldap_server, &lp_obj, &py_creds)) { + &ldap_server, &lp_obj, &self->py_creds)) { return -1; } + /* keep reference to the credentials */ + Py_XINCREF(self->py_creds); - if (py_creds) { - ok = py_check_dcerpc_type(py_creds, "samba.credentials", + if (self->py_creds) { + ok = py_check_dcerpc_type(self->py_creds, "samba.credentials", "Credentials"); if (!ok) { return -1; } self->cli_creds - = PyCredentials_AsCliCredentials(py_creds); + = PyCredentials_AsCliCredentials(self->py_creds); } ok = py_check_dcerpc_type(lp_obj, "samba.param", "LoadParm"); -- 2.34.1