along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Python.h>
+#include "python/py3compat.h"
#include "librpc/gen_ndr/misc.h"
+#if PY_MAJOR_VERSION >= 3
+static PyObject *py_GUID_richcmp(PyObject *py_self, PyObject *py_other, int op)
+{
+ int ret;
+ struct GUID *self = pytalloc_get_ptr(py_self), *other;
+ other = pytalloc_get_ptr(py_other);
+ if (other == NULL) {
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+ }
+
+ ret = GUID_compare(self, other);
+
+ switch (op) {
+ case Py_EQ: if (ret == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
+ case Py_NE: if (ret != 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
+ case Py_LT: if (ret < 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
+ case Py_GT: if (ret > 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
+ case Py_LE: if (ret <= 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
+ case Py_GE: if (ret >= 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
+ }
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+}
+#else
static int py_GUID_cmp(PyObject *py_self, PyObject *py_other)
{
int ret;
return 0;
}
}
+#endif
static PyObject *py_GUID_str(PyObject *py_self)
{
struct GUID *self = pytalloc_get_ptr(py_self);
char *str = GUID_string(NULL, self);
- PyObject *ret = PyString_FromString(str);
+ PyObject *ret = PyStr_FromString(str);
talloc_free(str);
return ret;
}
{
struct GUID *self = pytalloc_get_ptr(py_self);
char *str = GUID_string(NULL, self);
- PyObject *ret = PyString_FromFormat("GUID('%s')", str);
+ PyObject *ret = PyStr_FromFormat("GUID('%s')", str);
talloc_free(str);
return ret;
}
if (str != NULL) {
DATA_BLOB guid_val;
+ Py_ssize_t _size;
- if (!PyString_Check(str)) {
+ if (!PyStr_Check(str)) {
PyErr_SetString(PyExc_TypeError, "Expected a string argument to GUID()");
return -1;
}
- guid_val.data = (uint8_t *)PyString_AsString(str);
- guid_val.length = PyString_Size(str);
+ guid_val.data = (uint8_t *)PyStr_AsUTF8AndSize(str, &_size);
+ guid_val.length = _size;
status = GUID_from_data_blob(&guid_val, guid);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
type->tp_init = py_GUID_init;
type->tp_str = py_GUID_str;
type->tp_repr = py_GUID_repr;
+#if PY_MAJOR_VERSION >= 3
+ type->tp_richcompare = py_GUID_richcmp;
+#else
type->tp_compare = py_GUID_cmp;
+#endif
}
#define PY_GUID_PATCH py_GUID_patch
{
struct policy_handle *self = pytalloc_get_ptr(py_self);
char *uuid_str = GUID_string(NULL, &self->uuid);
- PyObject *ret = PyString_FromFormat("policy_handle(%d, '%s')", self->handle_type, uuid_str);
+ PyObject *ret = PyStr_FromFormat("policy_handle(%d, '%s')", self->handle_type, uuid_str);
talloc_free(uuid_str);
return ret;
}
{
struct policy_handle *self = pytalloc_get_ptr(py_self);
char *uuid_str = GUID_string(NULL, &self->uuid);
- PyObject *ret = PyString_FromFormat("%d, %s", self->handle_type, uuid_str);
+ PyObject *ret = PyStr_FromFormat("%d, %s", self->handle_type, uuid_str);
talloc_free(uuid_str);
return ret;
}
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-from base import *
+from samba.dcerpc.base import *
*/
#include <Python.h>
+#include "python/py3compat.h"
#include "includes.h"
#include <structmember.h>
#include "librpc/rpc/pyrpc.h"
static bool PyString_AsGUID(PyObject *object, struct GUID *uuid)
{
NTSTATUS status;
- status = GUID_from_string(PyString_AsString(object), uuid);
+ status = GUID_from_string(PyStr_AsString(object), uuid);
if (NT_STATUS_IS_ERR(status)) {
PyErr_SetNTSTATUS(status);
return false;
{
ZERO_STRUCTP(syntax_id);
- if (PyString_Check(object)) {
+ if (PyStr_Check(object)) {
return PyString_AsGUID(object, &syntax_id->uuid);
} else if (PyTuple_Check(object)) {
if (PyTuple_Size(object) < 1 || PyTuple_Size(object) > 2) {
return false;
}
- if (!PyString_Check(PyTuple_GetItem(object, 0))) {
+ if (!PyStr_Check(PyTuple_GetItem(object, 0))) {
PyErr_SetString(PyExc_ValueError, "Expected GUID as first element in tuple");
return false;
}
if (server_name == NULL)
Py_RETURN_NONE;
- return PyString_FromString(server_name);
+ return PyStr_FromString(server_name);
}
static PyObject *py_ndr_syntax_id(struct ndr_syntax_id *syntax_id)
NTSTATUS status = dcerpc_fetch_session_key(iface->pipe, &session_key);
PyErr_NTSTATUS_IS_ERR_RAISE(status);
- return PyString_FromStringAndSize((const char *)session_key.data, session_key.length);
+ return PyBytes_FromStringAndSize((const char *)session_key.data, session_key.length);
}
static PyObject *py_iface_user_session_key(PyObject *obj, void *closure)
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;
}
- ret = PyString_FromStringAndSize((char *)data_out.data, data_out.length);
+ ret = PyBytes_FromStringAndSize((char *)data_out.data, data_out.length);
talloc_free(mem_ctx);
return ret;
}
static PyTypeObject dcerpc_InterfaceType = {
- PyObject_HEAD_INIT(NULL) 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "dcerpc.ClientConnection",
.tp_basicsize = sizeof(dcerpc_InterfaceObject),
.tp_dealloc = dcerpc_interface_dealloc,
}
static PyTypeObject py_transfer_syntax_ndr_SyntaxType = {
- PyObject_HEAD_INIT(NULL) 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "base.transfer_syntax_ndr",
.tp_doc = "transfer_syntax_ndr()\n",
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
}
static PyTypeObject py_transfer_syntax_ndr64_SyntaxType = {
- PyObject_HEAD_INIT(NULL) 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "base.transfer_syntax_ndr64",
.tp_doc = "transfer_syntax_ndr64()\n",
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
}
static PyTypeObject py_bind_time_features_syntax_SyntaxType = {
- PyObject_HEAD_INIT(NULL) 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "base.bind_time_features_syntax",
.tp_doc = "bind_time_features_syntax(features)\n",
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_new = py_bind_time_features_syntax_new,
};
-void initbase(void)
+static struct PyModuleDef moduledef = {
+ PyModuleDef_HEAD_INIT,
+ .m_name = "base",
+ .m_doc = "DCE/RPC protocol implementation",
+ .m_size = -1,
+};
+
+MODULE_INIT_FUNC(base)
{
PyObject *m;
PyObject *dep_samba_dcerpc_misc;
dep_samba_dcerpc_misc = PyImport_ImportModule("samba.dcerpc.misc");
if (dep_samba_dcerpc_misc == NULL)
- return;
+ return NULL;
ndr_syntax_id_Type = (PyTypeObject *)PyObject_GetAttrString(dep_samba_dcerpc_misc, "ndr_syntax_id");
if (ndr_syntax_id_Type == NULL)
- return;
+ return NULL;
py_transfer_syntax_ndr_SyntaxType.tp_base = ndr_syntax_id_Type;
py_transfer_syntax_ndr_SyntaxType.tp_basicsize = pytalloc_BaseObject_size();
py_bind_time_features_syntax_SyntaxType.tp_basicsize = pytalloc_BaseObject_size();
if (PyType_Ready(&dcerpc_InterfaceType) < 0)
- return;
+ return NULL;
if (PyType_Ready(&py_transfer_syntax_ndr_SyntaxType) < 0)
- return;
+ return NULL;
if (PyType_Ready(&py_transfer_syntax_ndr64_SyntaxType) < 0)
- return;
+ return NULL;
if (PyType_Ready(&py_bind_time_features_syntax_SyntaxType) < 0)
- return;
+ return NULL;
- m = Py_InitModule3("base", NULL, "DCE/RPC protocol implementation");
+ m = PyModule_Create(&moduledef);
if (m == NULL)
- return;
+ return NULL;
Py_INCREF((PyObject *)&dcerpc_InterfaceType);
PyModule_AddObject(m, "ClientConnection", (PyObject *)&dcerpc_InterfaceType);
PyModule_AddObject(m, "transfer_syntax_ndr64", (PyObject *)(void *)&py_transfer_syntax_ndr64_SyntaxType);
Py_INCREF((PyObject *)(void *)&py_bind_time_features_syntax_SyntaxType);
PyModule_AddObject(m, "bind_time_features_syntax", (PyObject *)(void *)&py_bind_time_features_syntax_SyntaxType);
+ return m;
}
*/
#include <Python.h>
+#include "python/py3compat.h"
#include "includes.h"
#include "librpc/rpc/pyrpc_util.h"
#include "librpc/rpc/dcerpc.h"
if (str == NULL) {
Py_RETURN_NONE;
}
- return PyString_FromString(str);
+ return PyStr_FromString(str);
}
PyObject *pyrpc_import_union(PyTypeObject *type, TALLOC_CTX *mem_ctx, int level,
vnum='0.0.1'
)
-bld.SAMBA_SUBSYSTEM('pyrpc_util',
- source='rpc/pyrpc_util.c',
- public_deps='pytalloc-util pyparam_util dcerpc MESSAGING',
- pyext=True,
- )
+for env in bld.gen_python_environments():
+ pyrpc_util = bld.pyembed_libname('pyrpc_util')
+ pytalloc_util = bld.pyembed_libname('pytalloc-util')
+ pyparam_util = bld.pyembed_libname('pyparam_util')
+
+ bld.SAMBA_SUBSYSTEM(pyrpc_util,
+ source='rpc/pyrpc_util.c',
+ public_deps='%s %s dcerpc MESSAGING' % (pytalloc_util, pyparam_util),
+ pyext=True,
+ )
+ bld.SAMBA_PYTHON('python_dcerpc',
+ source='rpc/pyrpc.c',
+ public_deps='LIBCLI_SMB samba-util samba-hostconfig dcerpc-samr RPC_NDR_LSA DYNCONFIG %s gensec' % (pyrpc_util),
+ realname='samba/dcerpc/base.so'
+ )
-bld.SAMBA_PYTHON('python_dcerpc',
- source='rpc/pyrpc.c',
- public_deps='LIBCLI_SMB samba-util samba-hostconfig dcerpc-samr RPC_NDR_LSA DYNCONFIG pyrpc_util gensec',
- realname='samba/dcerpc/base.so'
- )
bld.SAMBA_PYTHON('python_srvsvc',
source='../../librpc/gen_ndr/py_srvsvc.c',
)
-bld.SAMBA_PYTHON('python_dcerpc_misc',
- source='../../librpc/gen_ndr/py_misc.c',
- deps='pytalloc-util pyrpc_util ndr-krb5pac',
- realname='samba/dcerpc/misc.so'
- )
+for env in bld.gen_python_environments():
+ pytalloc_util = bld.pyembed_libname('pytalloc-util')
+ pyrpc_util = bld.pyembed_libname('pyrpc_util')
+ bld.SAMBA_PYTHON('python_dcerpc_misc',
+ source='../../librpc/gen_ndr/py_misc.c',
+ deps='%s %s ndr-krb5pac' % (pytalloc_util, pyrpc_util),
+ realname='samba/dcerpc/misc.so'
+ )
bld.SAMBA_PYTHON('python_initshutdown',