diff options
author | Andrew Bartlett <abartlet@samba.org> | 2011-01-17 16:21:28 +1100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2011-01-18 10:55:05 +0100 |
commit | 017fbcdd101b3e8503ce643202fdbaa6d076a995 (patch) | |
tree | 23445753ebeea1a89c9224f7726cc5de1ceb45a5 /source4/auth | |
parent | 9b643c8c83bda42b5f8ad1d9ca0419e1e1c0e372 (diff) | |
download | samba-017fbcdd101b3e8503ce643202fdbaa6d076a995.tar.gz samba-017fbcdd101b3e8503ce643202fdbaa6d076a995.tar.bz2 samba-017fbcdd101b3e8503ce643202fdbaa6d076a995.zip |
s4-pyauth Use py_talloc_get_type() for greater talloc binding safety
This does a talloc check of the returned pointer before casting it.
Andrew Bartlett
Diffstat (limited to 'source4/auth')
-rw-r--r-- | source4/auth/gensec/pygensec.c | 15 | ||||
-rw-r--r-- | source4/auth/pyauth.c | 12 |
2 files changed, 15 insertions, 12 deletions
diff --git a/source4/auth/gensec/pygensec.c b/source4/auth/gensec/pygensec.c index e16ba37ca9..483a50cfcd 100644 --- a/source4/auth/gensec/pygensec.c +++ b/source4/auth/gensec/pygensec.c @@ -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; diff --git a/source4/auth/pyauth.c b/source4/auth/pyauth.c index c8ab460b0d..65f86fb7f7 100644 --- a/source4/auth/pyauth.c +++ b/source4/auth/pyauth.c @@ -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; } |