summaryrefslogtreecommitdiff
path: root/source4/auth/gensec
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2011-01-19 10:31:28 +1100
committerAndrew Tridgell <tridge@samba.org>2011-01-19 01:35:22 +0100
commitbc0230be1d3d439fd5219a2123d4195b178870bc (patch)
treecea7420fea7459405e1e84e553a0f8f161d9ac80 /source4/auth/gensec
parentf8f1711f61d8b3befe10173081cecaa431f0c714 (diff)
downloadsamba-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>
Diffstat (limited to 'source4/auth/gensec')
-rw-r--r--source4/auth/gensec/pygensec.c63
1 files changed, 28 insertions, 35 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;