diff options
author | Andrew Tridgell <tridge@samba.org> | 2011-01-19 10:31:28 +1100 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2011-01-19 01:35:22 +0100 |
commit | bc0230be1d3d439fd5219a2123d4195b178870bc (patch) | |
tree | cea7420fea7459405e1e84e553a0f8f161d9ac80 | |
parent | f8f1711f61d8b3befe10173081cecaa431f0c714 (diff) | |
download | samba-bc0230be1d3d439fd5219a2123d4195b178870bc.tar.gz samba-bc0230be1d3d439fd5219a2123d4195b178870bc.tar.bz2 samba-bc0230be1d3d439fd5219a2123d4195b178870bc.zip |
pygensec: remove special case handling for None for buffers
always returning a buffer makes life easier for callers
Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
-rw-r--r-- | source4/auth/gensec/pygensec.c | 63 | ||||
-rw-r--r-- | source4/scripting/python/samba/tests/gensec.py | 2 |
2 files changed, 29 insertions, 36 deletions
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; diff --git a/source4/scripting/python/samba/tests/gensec.py b/source4/scripting/python/samba/tests/gensec.py index f1cc44bca7..ddca0df980 100644 --- a/source4/scripting/python/samba/tests/gensec.py +++ b/source4/scripting/python/samba/tests/gensec.py @@ -67,7 +67,7 @@ class GensecTests(samba.tests.TestCase): client_finished = False server_finished = False - server_to_client = None + server_to_client = "" """Run the actual call loop""" while client_finished == False and server_finished == False: |