#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>
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)
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();
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)) {
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);