python: Use py_check_dcerpc_type() to safely check for credentials
authorAndrew Bartlett <abartlet@samba.org>
Tue, 24 Oct 2017 03:40:02 +0000 (16:40 +1300)
committerGarming Sam <garming@samba.org>
Mon, 20 Nov 2017 20:41:15 +0000 (21:41 +0100)
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
libgpo/pygpo.c
libgpo/wscript_build

index 757c713b0278ca537079e3c7cc81f9c5c75bb65d..09e03af9650214263cb0ba442819cbff0ffba152 100644 (file)
@@ -24,6 +24,7 @@
 #include "ads.h"
 #include "secrets.h"
 #include "../libds/common/flags.h"
+#include "librpc/rpc/pyrpc_util.h"
 #include "auth/credentials/pycredentials.h"
 #include "libcli/util/pyerrors.h"
 
@@ -196,17 +197,27 @@ 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 *creds = NULL;
+       PyObject *py_creds = NULL;
        PyObject *lp_obj = NULL;
        struct loadparm_context *lp_ctx = NULL;
 
        static const char *kwlist[] = {"ldap_server", "loadparm_context", "credentials", NULL};
-       if (!PyArg_ParseTupleAndKeywords(args, kwds, "sO|O", discard_const_p(char *, kwlist), &ldap_server, &lp_obj, &creds))
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "sO|O", discard_const_p(char *, kwlist), &ldap_server, &lp_obj, &py_creds))
                return -1;
 
        self->frame = talloc_stackframe();
 
-       if (creds) self->cli_creds = pytalloc_get_type(creds, struct cli_credentials);
+       if (py_creds) {
+               if (!py_check_dcerpc_type(py_creds, "samba.credentials",
+                                         "Credentials")) {
+                       PyErr_Format(PyExc_TypeError,
+                                    "Expected samba.credentaials "
+                                    "for credentials argument");
+                       return -1;
+               }
+               self->cli_creds
+                       = PyCredentials_AsCliCredentials(py_creds);
+       }
 
        if (lp_obj) {
                lp_ctx = pytalloc_get_type(lp_obj, struct loadparm_context);
index 7d1d32628f0d7a08cb72b9550d3d5399636e602e..2ef66f7fa9d02dc8c0c3fbe2158476131d288647 100644 (file)
@@ -8,5 +8,6 @@ bld.SAMBA3_LIBRARY('gpext',
                    private_library=True)
 
 bld.SAMBA3_PYTHON('python_samba_libgpo', 'pygpo.c',
-                 deps='pyparam_util gpext talloc ads TOKEN_UTIL auth',
+                 deps='''pyparam_util gpext talloc ads TOKEN_UTIL
+                 auth pyrpc_util''',
                  realname='samba/gpo.so')