s4-pydsdb: Improve PyErr_LDB_{DN,}_OR_RAISE to use py_check_dcerpc_type
authorAndrew Bartlett <abartlet@samba.org>
Fri, 6 Jul 2012 10:48:34 +0000 (20:48 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 6 Jul 2012 12:45:34 +0000 (22:45 +1000)
This checks the type rather than just dereferencing the pointer.

Andrew Bartlett

source4/dsdb/pydsdb.c

index d3486a41ec66a760d09d215440acfb8855d50b4f..08d87b957c9662af5d551a4578dd441667092d1b 100644 (file)
@@ -40,12 +40,19 @@ typedef intargfunc ssizeargfunc;
 
 /* FIXME: These should be in a header file somewhere */
 #define PyErr_LDB_OR_RAISE(py_ldb, ldb) \
-/*     if (!PyLdb_Check(py_ldb)) { \
+       if (!py_check_dcerpc_type(py_ldb, "ldb", "Ldb")) { \
                PyErr_SetString(py_ldb_get_exception(), "Ldb connection object required"); \
                return NULL; \
-       } */\
+       } \
        ldb = pyldb_Ldb_AsLdbContext(py_ldb);
 
+#define PyErr_LDB_DN_OR_RAISE(py_ldb_dn, dn) \
+       if (!py_check_dcerpc_type(py_ldb_dn, "ldb", "Dn")) { \
+               PyErr_SetString(py_ldb_get_exception(), "ldb Dn object required"); \
+               return NULL; \
+       } \
+       dn = pyldb_Dn_AsDn(py_ldb_dn);
+
 static PyObject *py_ldb_get_exception(void)
 {
        PyObject *mod = PyImport_ImportModule("ldb");