summaryrefslogtreecommitdiff
path: root/libcli
diff options
context:
space:
mode:
authorNoel Power <noel.power@suse.com>2018-02-02 17:08:00 +0000
committerAndrew Bartlett <abartlet@samba.org>2018-03-23 07:28:25 +0100
commit330bbf7c3cfadd7f07fb5a83c5a7473c93e127dc (patch)
treea6bed34c521d70ef02b2779f3f3ca7eb1b2fac37 /libcli
parent0fa93f5fe99bd31c3f13241960c4ac600197c837 (diff)
downloadsamba-330bbf7c3cfadd7f07fb5a83c5a7473c93e127dc.tar.gz
python3 port for netbios module
Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Diffstat (limited to 'libcli')
-rw-r--r--libcli/nbt/pynbt.c55
-rw-r--r--libcli/nbt/wscript_build3
2 files changed, 35 insertions, 23 deletions
diff --git a/libcli/nbt/pynbt.c b/libcli/nbt/pynbt.c
index 70e08c69de9..6337092b226 100644
--- a/libcli/nbt/pynbt.c
+++ b/libcli/nbt/pynbt.c
@@ -19,6 +19,7 @@
#include <Python.h>
#include "includes.h"
+#include "python/py3compat.h"
#include "libcli/util/pyerrors.h"
#include "python/modules.h"
#include "../libcli/nbt/libnbt.h"
@@ -37,7 +38,7 @@ typedef struct {
static void py_nbt_node_dealloc(nbt_node_Object *self)
{
talloc_free(self->mem_ctx);
- self->ob_type->tp_free(self);
+ Py_TYPE(self)->tp_free(self);
}
static PyObject *py_nbt_node_init(PyTypeObject *self, PyObject *args, PyObject *kwargs)
@@ -56,8 +57,8 @@ static PyObject *py_nbt_node_init(PyTypeObject *self, PyObject *args, PyObject *
static bool PyObject_AsDestinationTuple(PyObject *obj, const char **dest_addr, uint16_t *dest_port)
{
- if (PyString_Check(obj)) {
- *dest_addr = PyString_AsString(obj);
+ if (PyStr_Check(obj)) {
+ *dest_addr = PyStr_AsString(obj);
*dest_port = NBT_NAME_SERVICE_PORT;
return true;
}
@@ -68,12 +69,12 @@ static bool PyObject_AsDestinationTuple(PyObject *obj, const char **dest_addr, u
return false;
}
- if (!PyString_Check(PyTuple_GetItem(obj, 0))) {
+ if (!PyStr_Check(PyTuple_GetItem(obj, 0))) {
PyErr_SetString(PyExc_TypeError, "Destination tuple first element not string");
return false;
}
- *dest_addr = PyString_AsString(obj);
+ *dest_addr = PyStr_AsString(obj);
if (PyTuple_Size(obj) == 1) {
*dest_port = NBT_NAME_SERVICE_PORT;
@@ -95,13 +96,13 @@ static bool PyObject_AsNBTName(PyObject *obj, struct nbt_name_socket *name_socke
{
if (PyTuple_Check(obj)) {
if (PyTuple_Size(obj) == 2) {
- name->name = PyString_AsString(PyTuple_GetItem(obj, 0));
+ name->name = PyStr_AsString(PyTuple_GetItem(obj, 0));
name->type = PyInt_AsLong(PyTuple_GetItem(obj, 1));
name->scope = NULL;
return true;
} else if (PyTuple_Size(obj) == 3) {
- name->name = PyString_AsString(PyTuple_GetItem(obj, 0));
- name->scope = PyString_AsString(PyTuple_GetItem(obj, 1));
+ name->name = PyStr_AsString(PyTuple_GetItem(obj, 0));
+ name->scope = PyStr_AsString(PyTuple_GetItem(obj, 1));
name->type = PyInt_AsLong(PyTuple_GetItem(obj, 2));
return true;
} else {
@@ -110,9 +111,9 @@ static bool PyObject_AsNBTName(PyObject *obj, struct nbt_name_socket *name_socke
}
}
- if (PyString_Check(obj)) {
+ if (PyStr_Check(obj)) {
/* FIXME: Parse string to be able to interpret things like RHONWYN<02> ? */
- name->name = PyString_AsString(obj);
+ name->name = PyStr_AsString(obj);
name->scope = NULL;
name->type = 0;
return true;
@@ -171,7 +172,7 @@ static PyObject *py_nbt_name_query(PyObject *self, PyObject *args, PyObject *kwa
ret = PyTuple_New(3);
if (ret == NULL)
return NULL;
- PyTuple_SetItem(ret, 0, PyString_FromString(io.out.reply_from));
+ PyTuple_SetItem(ret, 0, PyStr_FromString(io.out.reply_from));
py_name = PyObject_FromNBTName(node->socket, &io.out.name);
if (py_name == NULL)
@@ -186,7 +187,7 @@ static PyObject *py_nbt_name_query(PyObject *self, PyObject *args, PyObject *kwa
}
for (i = 0; i < io.out.num_addrs; i++) {
- PyList_SetItem(reply_addrs, i, PyString_FromString(io.out.reply_addrs[i]));
+ PyList_SetItem(reply_addrs, i, PyStr_FromString(io.out.reply_addrs[i]));
}
PyTuple_SetItem(ret, 2, reply_addrs);
@@ -229,7 +230,7 @@ static PyObject *py_nbt_name_status(PyObject *self, PyObject *args, PyObject *kw
ret = PyTuple_New(3);
if (ret == NULL)
return NULL;
- PyTuple_SetItem(ret, 0, PyString_FromString(io.out.reply_from));
+ PyTuple_SetItem(ret, 0, PyStr_FromString(io.out.reply_from));
py_name = PyObject_FromNBTName(node->socket, &io.out.name);
if (py_name == NULL)
@@ -292,7 +293,7 @@ static PyObject *py_nbt_name_register(PyObject *self, PyObject *args, PyObject *
ret = PyTuple_New(4);
if (ret == NULL)
return NULL;
- PyTuple_SetItem(ret, 0, PyString_FromString(io.out.reply_from));
+ PyTuple_SetItem(ret, 0, PyStr_FromString(io.out.reply_from));
py_name = PyObject_FromNBTName(node->socket, &io.out.name);
if (py_name == NULL)
@@ -300,7 +301,7 @@ static PyObject *py_nbt_name_register(PyObject *self, PyObject *args, PyObject *
PyTuple_SetItem(ret, 1, py_name);
- PyTuple_SetItem(ret, 2, PyString_FromString(io.out.reply_addr));
+ PyTuple_SetItem(ret, 2, PyStr_FromString(io.out.reply_addr));
PyTuple_SetItem(ret, 3, PyInt_FromLong(io.out.rcode));
@@ -347,7 +348,7 @@ static PyObject *py_nbt_name_refresh(PyObject *self, PyObject *args, PyObject *k
ret = PyTuple_New(3);
if (ret == NULL)
return NULL;
- PyTuple_SetItem(ret, 0, PyString_FromString(io.out.reply_from));
+ PyTuple_SetItem(ret, 0, PyStr_FromString(io.out.reply_from));
py_name = PyObject_FromNBTName(node->socket, &io.out.name);
if (py_name == NULL)
@@ -355,7 +356,7 @@ static PyObject *py_nbt_name_refresh(PyObject *self, PyObject *args, PyObject *k
PyTuple_SetItem(ret, 1, py_name);
- PyTuple_SetItem(ret, 2, PyString_FromString(io.out.reply_addr));
+ PyTuple_SetItem(ret, 2, PyStr_FromString(io.out.reply_addr));
PyTuple_SetItem(ret, 3, PyInt_FromLong(io.out.rcode));
@@ -386,7 +387,7 @@ static PyMethodDef py_nbt_methods[] = {
};
PyTypeObject nbt_node_Type = {
- PyObject_HEAD_INIT(NULL) 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "netbios.Node",
.tp_basicsize = sizeof(nbt_node_Object),
.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
@@ -397,14 +398,24 @@ PyTypeObject nbt_node_Type = {
"Create a new NetBIOS node\n"
};
-void initnetbios(void)
+static struct PyModuleDef moduledef = {
+ PyModuleDef_HEAD_INIT,
+ .m_name = "netbios",
+ .m_doc = "NetBIOS over TCP/IP support",
+ .m_size = -1,
+ .m_methods = NULL,
+};
+
+MODULE_INIT_FUNC(netbios)
{
- PyObject *mod;
+ PyObject *mod = NULL;
if (PyType_Ready(&nbt_node_Type) < 0)
- return;
+ return mod;
+
+ mod = PyModule_Create(&moduledef);
- mod = Py_InitModule3("netbios", NULL, "NetBIOS over TCP/IP support");
Py_INCREF((PyObject *)&nbt_node_Type);
PyModule_AddObject(mod, "Node", (PyObject *)&nbt_node_Type);
+ return mod;
}
diff --git a/libcli/nbt/wscript_build b/libcli/nbt/wscript_build
index 090789ce99a..e965a347204 100644
--- a/libcli/nbt/wscript_build
+++ b/libcli/nbt/wscript_build
@@ -24,7 +24,8 @@ bld.SAMBA_BINARY('nmblookup' + bld.env.suffix4,
install=False
)
-bld.SAMBA_PYTHON('python_netbios',
+for env in bld.gen_python_environments():
+ bld.SAMBA_PYTHON('python_netbios',
source='pynbt.c',
public_deps='cli-nbt DYNCONFIG samba-hostconfig',
realname='samba/netbios.so'