[SCM] Samba Shared Repository - branch master updated - tevent-0-9-8-880-g5a5c30c

Andrew Tridgell tridge at samba.org
Fri Oct 2 02:52:41 MDT 2009


The branch, master has been updated
       via  5a5c30cb38c7e08fbe1abbc98496142ac022e7f8 (commit)
      from  084407fe2072a66ec753aa4dcceaa5a9622fce9e (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 5a5c30cb38c7e08fbe1abbc98496142ac022e7f8
Author: Andrew Tridgell <tridge at samba.org>
Date:   Fri Oct 2 18:50:59 2009 +1000

    s4-pygensec: a bit closer to working
    
    I'll need help from Andrew on how to get gensec to initialise it's ops
    element

-----------------------------------------------------------------------

Summary of changes:
 source4/auth/gensec/config.mk         |    2 +-
 source4/auth/gensec/pygensec.c        |   57 +++++++++++++++++++++++++++++----
 source4/auth/gensec/tests/bindings.py |    6 +++-
 3 files changed, 56 insertions(+), 9 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/auth/gensec/config.mk b/source4/auth/gensec/config.mk
index 65f5208..aa52b18 100644
--- a/source4/auth/gensec/config.mk
+++ b/source4/auth/gensec/config.mk
@@ -86,7 +86,7 @@ SCHANNELDB_OBJ_FILES = $(addprefix $(gensecsrcdir)/, schannel_state.o)
 $(eval $(call proto_header_template,$(gensecsrcdir)/schannel_state.h,$(SCHANNELDB_OBJ_FILES:.o=.c)))
 
 [PYTHON::pygensec]
-PRIVATE_DEPENDENCIES = gensec PYTALLOC
+PRIVATE_DEPENDENCIES = gensec PYTALLOC pyparam_util
 LIBRARY_REALNAME = samba/gensec.$(SHLIBEXT)
 
 pygensec_OBJ_FILES = $(gensecsrcdir)/pygensec.o
diff --git a/source4/auth/gensec/pygensec.c b/source4/auth/gensec/pygensec.c
index efa97e0..d6d1f63 100644
--- a/source4/auth/gensec/pygensec.c
+++ b/source4/auth/gensec/pygensec.c
@@ -19,8 +19,10 @@
 #include "includes.h"
 #include <Python.h>
 #include "param/param.h"
+#include "param/pyparam.h"
 #include "auth/gensec/gensec.h"
 #include "libcli/util/pyerrors.h"
+#include "scripting/python/modules.h"
 #include "pytalloc.h"
 #include <tevent.h>
 
@@ -46,9 +48,35 @@ static PyObject *py_get_name_by_authtype(PyObject *self, PyObject *args)
 	return PyString_FromString(name);
 }
 
-static struct gensec_settings *settings_from_object(PyObject *object)
+static struct gensec_settings *settings_from_object(TALLOC_CTX *mem_ctx, PyObject *object)
 {
-	return NULL; /* FIXME */
+	struct gensec_settings *s;
+	PyObject *py_hostname, *py_lp_ctx;
+
+	if (!PyDict_Check(object)) {
+		PyErr_SetString(PyExc_ValueError, "settings should be a dictionary");
+		return NULL;
+	}
+
+	s = talloc_zero(mem_ctx, struct gensec_settings);
+	if (!s) return NULL;
+
+	py_hostname = PyDict_GetItemString(object, "target_hostname");
+	if (!py_hostname) {
+		PyErr_SetString(PyExc_ValueError, "settings.target_hostname not found");
+		return NULL;
+	}
+
+	py_lp_ctx = PyDict_GetItemString(object, "lp_ctx");
+	if (!py_lp_ctx) {
+		PyErr_SetString(PyExc_ValueError, "settings.lp_ctx not found");
+		return NULL;
+	}
+	
+	s->target_hostname = PyString_AsString(py_hostname);
+	s->lp_ctx = lp_from_py_object(py_lp_ctx);
+	s->iconv_convenience = py_iconv_convenience(s);
+	return s;
 }
 
 static PyObject *py_gensec_start_client(PyTypeObject *type, PyObject *args, PyObject *kwargs)
@@ -60,13 +88,9 @@ static PyObject *py_gensec_start_client(PyTypeObject *type, PyObject *args, PyOb
 	PyObject *py_settings;
 	struct tevent_context *ev;
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwnames, &py_settings))
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", discard_const_p(char *, kwnames), &py_settings))
 		return NULL;
 
-	settings = settings_from_object(py_settings);
-	if (settings == NULL)
-		return NULL;
-	
 	self = (py_talloc_Object*)type->tp_alloc(type, 0);
 	if (self == NULL) {
 		PyErr_NoMemory();
@@ -77,12 +101,27 @@ static PyObject *py_gensec_start_client(PyTypeObject *type, PyObject *args, PyOb
 		PyErr_NoMemory();
 		return NULL;
 	}
+
+	settings = settings_from_object(self->talloc_ctx, py_settings);
+	if (settings == NULL) {
+		PyObject_DEL(self);
+		return NULL;
+	}
+	
 	ev = tevent_context_init(self->talloc_ctx);
 	if (ev == NULL) {
 		PyErr_NoMemory();
 		PyObject_Del(self);
 		return NULL;
 	}
+
+	status = gensec_init(settings->lp_ctx);
+	if (!NT_STATUS_IS_OK(status)) {
+		PyErr_SetNTSTATUS(status);
+		PyObject_DEL(self);
+		return NULL;
+	}
+
 	status = gensec_client_start(self->talloc_ctx, 
 		(struct gensec_security **)&self->ptr, ev, settings);
 	if (!NT_STATUS_IS_OK(status)) {
@@ -98,6 +137,10 @@ static PyObject *py_gensec_session_info(PyObject *self)
 	NTSTATUS status;
 	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");
+		return NULL;
+	}
 	status = gensec_session_info(security, &info);
 	if (NT_STATUS_IS_ERR(status)) {
 		PyErr_SetNTSTATUS(status);
diff --git a/source4/auth/gensec/tests/bindings.py b/source4/auth/gensec/tests/bindings.py
index 95d7833..f88fa82 100644
--- a/source4/auth/gensec/tests/bindings.py
+++ b/source4/auth/gensec/tests/bindings.py
@@ -25,11 +25,15 @@ the functionality, that's already done in other tests.
 
 import unittest
 from samba import gensec
+from samba.tests import cmdline_loadparm
 
 class CredentialsTests(unittest.TestCase):
 
     def setUp(self):
-        self.gensec = gensec.Security.start_client()
+        settings = {}
+        settings["target_hostname"] = "localhost"
+        settings["lp_ctx"] = cmdline_loadparm
+        self.gensec = gensec.Security.start_client(settings)
 
     def test_info(self):
         self.assertEquals(None, self.gensec.session_info())


-- 
Samba Shared Repository


More information about the samba-cvs mailing list