From bc0230be1d3d439fd5219a2123d4195b178870bc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 19 Jan 2011 10:31:28 +1100 Subject: pygensec: remove special case handling for None for buffers always returning a buffer makes life easier for callers Pair-Programmed-With: Andrew Bartlett --- source4/auth/gensec/pygensec.c | 63 +++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 35 deletions(-) (limited to 'source4/auth/gensec/pygensec.c') diff --git a/source4/auth/gensec/pygensec.c b/source4/auth/gensec/pygensec.c index da62018eeb..cd05bd7ccf 100644 --- a/source4/auth/gensec/pygensec.c +++ b/source4/auth/gensec/pygensec.c @@ -349,24 +349,25 @@ static PyObject *py_gensec_have_feature(PyObject *self, PyObject *args) static PyObject *py_gensec_update(PyObject *self, PyObject *args) { NTSTATUS status; - TALLOC_CTX *mem_ctx; DATA_BLOB in, out; PyObject *ret, *py_in; struct gensec_security *security = py_talloc_get_type(self, struct gensec_security); + PyObject *finished_processing; if (!PyArg_ParseTuple(args, "O", &py_in)) return NULL; mem_ctx = talloc_new(NULL); - if (py_in == Py_None) { - in = data_blob_null; - } else { - in.data = (uint8_t *)PyString_AsString(py_in); - in.length = PyString_Size(py_in); + if (!PyString_Check(py_in)) { + PyErr_Format(PyExc_TypeError, "expected a string"); + return NULL; } + in.data = (uint8_t *)PyString_AsString(py_in); + in.length = PyString_Size(py_in); + status = gensec_update(security, mem_ctx, in, &out); if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED) @@ -375,18 +376,16 @@ static PyObject *py_gensec_update(PyObject *self, PyObject *args) talloc_free(mem_ctx); return NULL; } - if (out.length != 0) { - ret = PyString_FromStringAndSize((const char *)out.data, out.length); - } else { - ret = Py_None; - } + ret = PyString_FromStringAndSize((const char *)out.data, out.length); talloc_free(mem_ctx); - if (NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) - { - return PyTuple_Pack(2, Py_False, ret); + + if (NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { + finished_processing = Py_False; } else { - return PyTuple_Pack(2, Py_True, ret); + finished_processing = Py_True; } + + return PyTuple_Pack(2, finished_processing, ret); } static PyObject *py_gensec_wrap(PyObject *self, PyObject *args) @@ -403,12 +402,12 @@ static PyObject *py_gensec_wrap(PyObject *self, PyObject *args) mem_ctx = talloc_new(NULL); - if (py_in == Py_None) { - in = data_blob_null; - } else { - in.data = (uint8_t *)PyString_AsString(py_in); - in.length = PyString_Size(py_in); + if (!PyString_Check(py_in)) { + PyErr_Format(PyExc_TypeError, "expected a string"); + return NULL; } + in.data = (uint8_t *)PyString_AsString(py_in); + in.length = PyString_Size(py_in); status = gensec_wrap(security, mem_ctx, &in, &out); @@ -418,11 +417,7 @@ static PyObject *py_gensec_wrap(PyObject *self, PyObject *args) return NULL; } - if (out.length != 0) { - ret = PyString_FromStringAndSize((const char *)out.data, out.length); - } else { - ret = Py_None; - } + ret = PyString_FromStringAndSize((const char *)out.data, out.length); talloc_free(mem_ctx); return ret; } @@ -441,13 +436,14 @@ static PyObject *py_gensec_unwrap(PyObject *self, PyObject *args) mem_ctx = talloc_new(NULL); - if (py_in == Py_None) { - in = data_blob_null; - } else { - in.data = (uint8_t *)PyString_AsString(py_in); - in.length = PyString_Size(py_in); + if (!PyString_Check(py_in)) { + PyErr_Format(PyExc_TypeError, "expected a string"); + return NULL; } + in.data = (uint8_t *)PyString_AsString(py_in); + in.length = PyString_Size(py_in); + status = gensec_unwrap(security, mem_ctx, &in, &out); if (!NT_STATUS_IS_OK(status)) { @@ -456,11 +452,7 @@ static PyObject *py_gensec_unwrap(PyObject *self, PyObject *args) return NULL; } - if (out.length != 0) { - ret = PyString_FromStringAndSize((const char *)out.data, out.length); - } else { - ret = Py_None; - } + ret = PyString_FromStringAndSize((const char *)out.data, out.length); talloc_free(mem_ctx); return ret; } @@ -502,6 +494,7 @@ static PyTypeObject Py_Security = { .tp_basicsize = sizeof(py_talloc_Object), }; +void initgensec(void); void initgensec(void) { PyObject *m; -- cgit