s4-pyauth Use py_talloc_get_type() for greater talloc binding safety
authorAndrew Bartlett <abartlet@samba.org>
Mon, 17 Jan 2011 05:21:28 +0000 (16:21 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 18 Jan 2011 09:55:05 +0000 (10:55 +0100)
This does a talloc check of the returned pointer before casting it.

Andrew Bartlett

source4/auth/gensec/pygensec.c
source4/auth/pyauth.c

index e16ba37ca9b0d92a42c6c76110e3b0371e7227ec..483a50cfcd61f5f6b15a6f457682f6b97d2e84e6 100644 (file)
@@ -24,6 +24,7 @@
 #include "scripting/python/modules.h"
 #include "lib/talloc/pytalloc.h"
 #include <tevent.h>
+#include "librpc/rpc/pyrpc_util.h"
 
 static PyObject *py_get_name_by_authtype(PyObject *self, PyObject *args)
 {
@@ -34,7 +35,7 @@ static PyObject *py_get_name_by_authtype(PyObject *self, PyObject *args)
        if (!PyArg_ParseTuple(args, "i", &type))
                return NULL;
 
-       security = (struct gensec_security *)py_talloc_get_ptr(self);
+       security = py_talloc_get_type(self, struct gensec_security);
 
        name = gensec_get_name_by_authtype(security, type);
        if (name == NULL)
@@ -132,7 +133,8 @@ static PyObject *py_gensec_start_client(PyTypeObject *type, PyObject *args, PyOb
 static PyObject *py_gensec_session_info(PyObject *self)
 {
        NTSTATUS status;
-       struct gensec_security *security = (struct gensec_security *)py_talloc_get_ptr(self);
+       PyObject *py_session_info;
+       struct gensec_security *security = py_talloc_get_type(self, struct gensec_security);
        struct auth_session_info *info;
        if (security->ops == NULL) {
                PyErr_SetString(PyExc_RuntimeError, "no mechanism selected");
@@ -144,14 +146,15 @@ static PyObject *py_gensec_session_info(PyObject *self)
                return NULL;
        }
 
-       /* FIXME */
-       Py_RETURN_NONE;
+       py_session_info = py_return_ndr_struct("samba.auth", "session_info",
+                                                info, info);
+       return py_session_info;
 }
 
 static PyObject *py_gensec_start_mech_by_name(PyObject *self, PyObject *args)
 {
     char *name;
-    struct gensec_security *security = (struct gensec_security *)py_talloc_get_ptr(self);
+    struct gensec_security *security = py_talloc_get_type(self, struct gensec_security);
     NTSTATUS status;
 
     if (!PyArg_ParseTuple(args, "s", &name))
@@ -169,7 +172,7 @@ static PyObject *py_gensec_start_mech_by_name(PyObject *self, PyObject *args)
 static PyObject *py_gensec_start_mech_by_authtype(PyObject *self, PyObject *args)
 {
        int authtype, level;
-    struct gensec_security *security = (struct gensec_security *)py_talloc_get_ptr(self);
+       struct gensec_security *security = py_talloc_get_type(self, struct gensec_security);
        NTSTATUS status;
        if (!PyArg_ParseTuple(args, "ii", &authtype, &level))
                return NULL;
index c8ab460b0d8aa6cbfbdf905b2b4e59eec25f7397..65f86fb7f731726087736a13444903a77688aa4a 100644 (file)
@@ -32,7 +32,7 @@
 
 static PyObject *py_auth_session_get_security_token(PyObject *self, void *closure)
 {
-       struct auth_session_info *session = (struct auth_session_info *)py_talloc_get_ptr(self);
+       struct auth_session_info *session = py_talloc_get_type(self, struct auth_session_info);
        PyObject *py_security_token;
        py_security_token = py_return_ndr_struct("samba.dcerpc.security", "token",
                                                 session->security_token, session->security_token);
@@ -41,21 +41,21 @@ static PyObject *py_auth_session_get_security_token(PyObject *self, void *closur
 
 static int py_auth_session_set_security_token(PyObject *self, PyObject *value, void *closure)
 {
-       struct auth_session_info *session = (struct auth_session_info *)py_talloc_get_ptr(self);
+       struct auth_session_info *session = py_talloc_get_type(self, struct auth_session_info);
        session->security_token = talloc_reference(session, py_talloc_get_ptr(value));
        return 0;
 }
 
 static PyObject *py_auth_session_get_session_key(PyObject *self, void *closure)
 {
-       struct auth_session_info *session = (struct auth_session_info *)py_talloc_get_ptr(self);
+       struct auth_session_info *session = py_talloc_get_type(self, struct auth_session_info);
        return PyString_FromStringAndSize((char *)session->session_key.data, session->session_key.length);
 }
 
 static int py_auth_session_set_session_key(PyObject *self, PyObject *value, void *closure)
 {
        DATA_BLOB val;
-       struct auth_session_info *session = (struct auth_session_info *)py_talloc_get_ptr(self);
+       struct auth_session_info *session = py_talloc_get_type(self, struct auth_session_info);
        val.data = (uint8_t *)PyString_AsString(value);
        val.length = PyString_Size(value);
 
@@ -65,7 +65,7 @@ static int py_auth_session_set_session_key(PyObject *self, PyObject *value, void
 
 static PyObject *py_auth_session_get_credentials(PyObject *self, void *closure)
 {
-       struct auth_session_info *session = (struct auth_session_info *)py_talloc_get_ptr(self);
+       struct auth_session_info *session = py_talloc_get_type(self, struct auth_session_info);
        PyObject *py_credentials;
        /* This is evil, as the credentials are not IDL structures */
        py_credentials = py_return_ndr_struct("samba.credentials", "Credentials", session->credentials, session->credentials);
@@ -74,7 +74,7 @@ static PyObject *py_auth_session_get_credentials(PyObject *self, void *closure)
 
 static int py_auth_session_set_credentials(PyObject *self, PyObject *value, void *closure)
 {
-       struct auth_session_info *session = (struct auth_session_info *)py_talloc_get_ptr(self);
+       struct auth_session_info *session = py_talloc_get_type(self, struct auth_session_info);
        session->credentials = talloc_reference(session, PyCredentials_AsCliCredentials(value));
        return 0;
 }