summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/auth/gensec/gensec.c5
-rw-r--r--source4/auth/gensec/pygensec.c33
-rw-r--r--source4/scripting/python/samba/tests/gensec.py13
3 files changed, 40 insertions, 11 deletions
diff --git a/source4/auth/gensec/gensec.c b/source4/auth/gensec/gensec.c
index 3520585c95..7220d0e836 100644
--- a/source4/auth/gensec/gensec.c
+++ b/source4/auth/gensec/gensec.c
@@ -718,10 +718,9 @@ _PUBLIC_ const char *gensec_get_name_by_oid(struct gensec_security *gensec_secur
}
return oid_string;
}
-
-/**
- * Start a GENSEC sub-mechanism with a specifed mechansim structure, used in SPNEGO
+/**
+ * Start a GENSEC sub-mechanism with a specified mechansim structure, used in SPNEGO
*
*/
diff --git a/source4/auth/gensec/pygensec.c b/source4/auth/gensec/pygensec.c
index fc76fad1be..28441cc9ca 100644
--- a/source4/auth/gensec/pygensec.c
+++ b/source4/auth/gensec/pygensec.c
@@ -67,7 +67,7 @@ static struct gensec_settings *settings_from_object(TALLOC_CTX *mem_ctx, PyObjec
PyErr_SetString(PyExc_ValueError, "settings.lp_ctx not found");
return NULL;
}
-
+
s->target_hostname = PyString_AsString(py_hostname);
s->lp_ctx = lpcfg_from_py_object(s, py_lp_ctx);
return s;
@@ -81,6 +81,7 @@ static PyObject *py_gensec_start_client(PyTypeObject *type, PyObject *args, PyOb
const char *kwnames[] = { "settings", NULL };
PyObject *py_settings;
struct tevent_context *ev;
+ struct gensec_security *gensec;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", discard_const_p(char *, kwnames), &py_settings))
return NULL;
@@ -101,7 +102,7 @@ static PyObject *py_gensec_start_client(PyTypeObject *type, PyObject *args, PyOb
PyObject_DEL(self);
return NULL;
}
-
+
ev = tevent_context_init(self->talloc_ctx);
if (ev == NULL) {
PyErr_NoMemory();
@@ -116,13 +117,15 @@ static PyObject *py_gensec_start_client(PyTypeObject *type, PyObject *args, PyOb
return NULL;
}
- status = gensec_client_start(self->talloc_ctx,
- (struct gensec_security **)&self->ptr, ev, settings);
+ status = gensec_client_start(self->talloc_ctx, &gensec, ev, settings);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
PyObject_DEL(self);
return NULL;
}
+
+ self->ptr = gensec;
+
return (PyObject *)self;
}
@@ -132,7 +135,7 @@ static PyObject *py_gensec_session_info(PyObject *self)
struct gensec_security *security = (struct gensec_security *)py_talloc_get_ptr(self);
struct auth_session_info *info;
if (security->ops == NULL) {
- PyErr_SetString(PyExc_ValueError, "gensec not fully initialised - ask Andrew");
+ PyErr_SetString(PyExc_RuntimeError, "no mechanism selected");
return NULL;
}
status = gensec_session_info(security, &info);
@@ -145,6 +148,24 @@ static PyObject *py_gensec_session_info(PyObject *self)
Py_RETURN_NONE;
}
+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);
+ NTSTATUS status;
+
+ if (!PyArg_ParseTuple(args, "s", &name))
+ return NULL;
+
+ status = gensec_start_mech_by_name(security, name);
+ if (!NT_STATUS_IS_OK(status)) {
+ PyErr_SetNTSTATUS(status);
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
+}
+
static PyMethodDef py_gensec_security_methods[] = {
{ "start_client", (PyCFunction)py_gensec_start_client, METH_VARARGS|METH_KEYWORDS|METH_CLASS,
"S.start_client(settings) -> gensec" },
@@ -152,6 +173,8 @@ static PyMethodDef py_gensec_security_methods[] = {
"S.start_server(auth_ctx, settings) -> gensec" },*/
{ "session_info", (PyCFunction)py_gensec_session_info, METH_NOARGS,
"S.session_info() -> info" },
+ { "start_mech_by_name", (PyCFunction)py_gensec_start_mech_by_name, METH_VARARGS,
+ "S.start_mech_by_name(name)" },
{ "get_name_by_authtype", (PyCFunction)py_get_name_by_authtype, METH_VARARGS,
"S.get_name_by_authtype(authtype) -> name\nLookup an auth type." },
{ NULL }
diff --git a/source4/scripting/python/samba/tests/gensec.py b/source4/scripting/python/samba/tests/gensec.py
index 21e3fa379a..05b9a5946f 100644
--- a/source4/scripting/python/samba/tests/gensec.py
+++ b/source4/scripting/python/samba/tests/gensec.py
@@ -2,17 +2,17 @@
# Unix SMB/CIFS implementation.
# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2009
-#
+#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
@@ -35,5 +35,12 @@ class CredentialsTests(samba.tests.TestCase):
settings["lp_ctx"] = samba.tests.env_loadparm()
self.gensec = gensec.Security.start_client(settings)
+ def test_start_mech_by_unknown_name(self):
+ self.assertRaises(RuntimeError, self.gensec.start_mech_by_name, "foo")
+
+ def test_info_uninitialized(self):
+ self.assertRaises(RuntimeError, self.gensec.session_info)
+
def test_info(self):
+ self.gensec.start_mech_by_name("spnego")
self.assertEquals(None, self.gensec.session_info())