client_finished = False
server_finished = False
- server_to_client = ""
+ server_to_client = b""
"""Run the actual call loop"""
while not client_finished and not server_finished:
if not client_finished:
- print "running client gensec_update"
+ print("running client gensec_update")
(client_finished, client_to_server) = self.gensec_client.update(server_to_client)
if not server_finished:
- print "running server gensec_update"
+ print("running server gensec_update")
(server_finished, server_to_client) = self.gensec_server.update(client_to_server)
session_info = self.gensec_server.session_info()
- test_string = "Hello Server"
- test_wrapped = self.gensec_client.wrap(test_string)
+ test_bytes = b"Hello Server"
+ test_wrapped = self.gensec_client.wrap(test_bytes)
test_unwrapped = self.gensec_server.unwrap(test_wrapped)
- self.assertEqual(test_string, test_unwrapped)
- test_string = "Hello Client"
- test_wrapped = self.gensec_server.wrap(test_string)
+ self.assertEqual(test_bytes, test_unwrapped)
+ test_bytes = b"Hello Client"
+ test_wrapped = self.gensec_server.wrap(test_bytes)
test_unwrapped = self.gensec_client.unwrap(test_wrapped)
- self.assertEqual(test_string, test_unwrapped)
+ self.assertEqual(test_bytes, test_unwrapped)
client_session_key = self.gensec_client.session_key()
server_session_key = self.gensec_server.session_key()
client_finished = False
server_finished = False
- server_to_client = ""
+ server_to_client = b""
"""Run the actual call loop"""
i = 0
while not client_finished or not server_finished:
i += 1
if not client_finished:
- print "running client gensec_update: %d: %r" % (len(server_to_client), server_to_client)
+ print("running client gensec_update: %d: %r" % (len(server_to_client), server_to_client))
(client_finished, client_to_server) = self.gensec_client.update(server_to_client)
if not server_finished:
- print "running server gensec_update: %d: %r" % (len(client_to_server), client_to_server)
+ print("running server gensec_update: %d: %r" % (len(client_to_server), client_to_server))
(server_finished, server_to_client) = self.gensec_server.update(client_to_server)
"""Here we expect a lot more than the typical 1 or 2 roundtrips"""
session_info = self.gensec_server.session_info()
- test_string = "Hello Server"
- test_wrapped = self.gensec_client.wrap(test_string)
+ test_bytes = b"Hello Server"
+ test_wrapped = self.gensec_client.wrap(test_bytes)
test_unwrapped = self.gensec_server.unwrap(test_wrapped)
- self.assertEqual(test_string, test_unwrapped)
- test_string = "Hello Client"
- test_wrapped = self.gensec_server.wrap(test_string)
+ self.assertEqual(test_bytes, test_unwrapped)
+ test_bytes = b"Hello Client"
+ test_wrapped = self.gensec_server.wrap(test_bytes)
test_unwrapped = self.gensec_client.unwrap(test_wrapped)
- self.assertEqual(test_string, test_unwrapped)
+ self.assertEqual(test_bytes, test_unwrapped)
client_session_key = self.gensec_client.session_key()
server_session_key = self.gensec_server.session_key()
*/
#include <Python.h>
+#include "python/py3compat.h"
#include "includes.h"
#include "param/pyparam.h"
#include "auth/gensec/gensec.h"
if (name == NULL)
Py_RETURN_NONE;
- return PyString_FromString(name);
+ return PyStr_FromString(name);
}
static struct gensec_settings *settings_from_object(TALLOC_CTX *mem_ctx, PyObject *object)
return NULL;
}
- s->target_hostname = PyString_AsString(py_hostname);
+ s->target_hostname = PyStr_AsString(py_hostname);
s->lp_ctx = lpcfg_from_py_object(s, py_lp_ctx);
return s;
}
return NULL;
}
- session_key_obj = PyString_FromStringAndSize((const char *)session_key.data,
+ session_key_obj = PyBytes_FromStringAndSize((const char *)session_key.data,
session_key.length);
talloc_free(mem_ctx);
return session_key_obj;
return NULL;
mem_ctx = talloc_new(NULL);
-
- if (!PyString_Check(py_in)) {
- PyErr_Format(PyExc_TypeError, "expected a string");
+ if (!PyBytes_Check(py_in)) {
+ PyErr_Format(PyExc_TypeError, "bytes expected");
return NULL;
}
- in.data = (uint8_t *)PyString_AsString(py_in);
- in.length = PyString_Size(py_in);
+ in.data = (uint8_t *)PyBytes_AsString(py_in);
+ in.length = PyBytes_Size(py_in);
status = gensec_update(security, mem_ctx, in, &out);
talloc_free(mem_ctx);
return NULL;
}
- ret = PyString_FromStringAndSize((const char *)out.data, out.length);
+ ret = PyBytes_FromStringAndSize((const char *)out.data, out.length);
talloc_free(mem_ctx);
if (NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
mem_ctx = talloc_new(NULL);
- if (!PyString_Check(py_in)) {
- PyErr_Format(PyExc_TypeError, "expected a string");
+ if (!PyBytes_Check(py_in)) {
+ PyErr_Format(PyExc_TypeError, "bytes expected");
return NULL;
}
- in.data = (uint8_t *)PyString_AsString(py_in);
- in.length = PyString_Size(py_in);
+ in.data = (uint8_t *)PyBytes_AsString(py_in);
+ in.length = PyBytes_Size(py_in);
status = gensec_wrap(security, mem_ctx, &in, &out);
return NULL;
}
- ret = PyString_FromStringAndSize((const char *)out.data, out.length);
+ ret = PyBytes_FromStringAndSize((const char *)out.data, out.length);
talloc_free(mem_ctx);
return ret;
}
+
static PyObject *py_gensec_unwrap(PyObject *self, PyObject *args)
{
NTSTATUS status;
mem_ctx = talloc_new(NULL);
- if (!PyString_Check(py_in)) {
- PyErr_Format(PyExc_TypeError, "expected a string");
+ if (!PyBytes_Check(py_in)) {
+ PyErr_Format(PyExc_TypeError, "bytes expected");
return NULL;
}
- in.data = (uint8_t *)PyString_AsString(py_in);
- in.length = PyString_Size(py_in);
+ in.data = (uint8_t *)PyBytes_AsString(py_in);
+ in.length = PyBytes_Size(py_in);
status = gensec_unwrap(security, mem_ctx, &in, &out);
return NULL;
}
- ret = PyString_FromStringAndSize((const char *)out.data, out.length);
+ ret = PyBytes_FromStringAndSize((const char *)out.data, out.length);
talloc_free(mem_ctx);
return ret;
}
{ NULL }
};
+static struct PyModuleDef moduledef = {
+ PyModuleDef_HEAD_INIT,
+ .m_name = "gensec",
+ .m_doc = "Generic Security Interface.",
+ .m_size = -1,
+};
+
static PyTypeObject Py_Security = {
.tp_name = "gensec.Security",
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_methods = py_gensec_security_methods,
};
-void initgensec(void);
-void initgensec(void)
+MODULE_INIT_FUNC(gensec)
{
PyObject *m;
if (pytalloc_BaseObject_PyType_Ready(&Py_Security) < 0)
- return;
+ return NULL;
- m = Py_InitModule3("gensec", NULL, "Generic Security Interface.");
+ m = PyModule_Create(&moduledef);
if (m == NULL)
- return;
+ return NULL;
PyModule_AddObject(m, "FEATURE_SESSION_KEY", PyInt_FromLong(GENSEC_FEATURE_SESSION_KEY));
PyModule_AddObject(m, "FEATURE_SIGN", PyInt_FromLong(GENSEC_FEATURE_SIGN));
Py_INCREF(&Py_Security);
PyModule_AddObject(m, "Security", (PyObject *)&Py_Security);
+
+ return m;
}