mirror of
https://github.com/samba-team/samba.git
synced 2025-08-02 00:22:11 +03:00
Add working Python bindings for NBT.
(This used to be commit 9c88f5e1de
)
This commit is contained in:
@ -73,13 +73,11 @@ LIBCLI_NETLOGON_OBJ_FILES = $(addprefix $(libclisrcdir)/, \
|
||||
|
||||
$(eval $(call proto_header_template,$(libclisrcdir)/netlogon_proto.h,$(LIBCLI_NETLOGON_OBJ_FILES:.o=.c)))
|
||||
|
||||
[PYTHON::python_libcli_nbt]
|
||||
LIBRARY_REALNAME = samba/_libcli_nbt.$(SHLIBEXT)
|
||||
[PYTHON::python_netbios]
|
||||
LIBRARY_REALNAME = samba/netbios.$(SHLIBEXT)
|
||||
PUBLIC_DEPENDENCIES = LIBCLI_NBT DYNCONFIG LIBSAMBA-HOSTCONFIG
|
||||
|
||||
python_libcli_nbt_OBJ_FILES = $(libclisrcdir)/swig/libcli_nbt_wrap.o
|
||||
|
||||
$(eval $(call python_py_module_template,samba/nbt.py,$(libclisrcdir)/swig/libcli_nbt.py))
|
||||
python_netbios_OBJ_FILES = $(libclisrcdir)/nbt/pynbt.o
|
||||
|
||||
$(python_libcli_nbt_OBJ_FILES): CFLAGS+=$(CFLAG_NO_UNUSED_MACROS) $(CFLAG_NO_CAST_QUAL)
|
||||
|
||||
|
408
source4/libcli/nbt/pynbt.c
Normal file
408
source4/libcli/nbt/pynbt.c
Normal file
@ -0,0 +1,408 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
Samba utility functions
|
||||
Copyright © Jelmer Vernooij <jelmer@samba.org> 2008
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include <Python.h>
|
||||
#include "libcli/util/pyerrors.h"
|
||||
#include "libcli/nbt/libnbt.h"
|
||||
#include "lib/events/events.h"
|
||||
#include "param/param.h"
|
||||
|
||||
PyAPI_DATA(PyTypeObject) nbt_node_Type;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
TALLOC_CTX *mem_ctx;
|
||||
struct nbt_name_socket *socket;
|
||||
} nbt_node_Object;
|
||||
|
||||
static void py_nbt_node_dealloc(PyObject *obj)
|
||||
{
|
||||
talloc_free(((nbt_node_Object *)obj)->mem_ctx);
|
||||
PyObject_Del(obj);
|
||||
}
|
||||
|
||||
static PyObject *py_nbt_node_init(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
struct event_context *ev;
|
||||
nbt_node_Object *ret = PyObject_New(nbt_node_Object, &nbt_node_Type);
|
||||
|
||||
ret->mem_ctx = talloc_new(NULL);
|
||||
if (ret->mem_ctx == NULL)
|
||||
return NULL;
|
||||
|
||||
ev = event_context_init(ret->mem_ctx);
|
||||
ret->socket = nbt_name_socket_init(ret->mem_ctx, ev, lp_iconv_convenience(global_loadparm));
|
||||
return (PyObject *)ret;
|
||||
}
|
||||
|
||||
static bool PyObject_AsDestinationTuple(PyObject *obj, const char **dest_addr, uint16_t *dest_port)
|
||||
{
|
||||
if (PyString_Check(obj)) {
|
||||
*dest_addr = PyString_AsString(obj);
|
||||
*dest_port = NBT_NAME_SERVICE_PORT;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (PyTuple_Check(obj)) {
|
||||
if (PyTuple_Size(obj) < 1) {
|
||||
PyErr_SetString(PyExc_TypeError, "Destination tuple size invalid");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!PyString_Check(PyTuple_GetItem(obj, 0))) {
|
||||
PyErr_SetString(PyExc_TypeError, "Destination tuple first element not string");
|
||||
return false;
|
||||
}
|
||||
|
||||
*dest_addr = PyString_AsString(obj);
|
||||
|
||||
if (PyTuple_Size(obj) == 1) {
|
||||
*dest_port = NBT_NAME_SERVICE_PORT;
|
||||
return true;
|
||||
} else if (PyInt_Check(PyTuple_GetItem(obj, 1))) {
|
||||
*dest_port = PyInt_AsLong(PyTuple_GetItem(obj, 1));
|
||||
return true;
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError, "Destination tuple second element not a port");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "Destination tuple second element not a port");
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool PyObject_AsNBTName(PyObject *obj, struct nbt_name_socket *socket, struct nbt_name *name)
|
||||
{
|
||||
if (PyTuple_Check(obj)) {
|
||||
if (PyTuple_Size(obj) == 2) {
|
||||
name->name = PyString_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->type = PyInt_AsLong(PyTuple_GetItem(obj, 2));
|
||||
return true;
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError, "Invalid tuple size");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (PyString_Check(obj)) {
|
||||
/* FIXME: Parse string to be able to interpret things like RHONWYN<02> ? */
|
||||
name->name = PyString_AsString(obj);
|
||||
name->scope = NULL;
|
||||
name->type = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "Invalid type for object");
|
||||
return false;
|
||||
}
|
||||
|
||||
static PyObject *PyObject_FromNBTName(struct nbt_name_socket *socket, struct smb_iconv_convenience *ic,
|
||||
struct nbt_name *name)
|
||||
{
|
||||
if (name->scope) {
|
||||
return Py_BuildValue("(ssi)", name->name, name->scope, name->type);
|
||||
} else {
|
||||
return Py_BuildValue("(si)", name->name, name->type);
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *py_nbt_name_query(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
nbt_node_Object *node = (nbt_node_Object *)self;
|
||||
PyObject *ret, *reply_addrs, *py_dest, *py_name;
|
||||
struct nbt_name_query io;
|
||||
NTSTATUS status;
|
||||
int i;
|
||||
|
||||
const char *kwnames[] = { "name", "dest", "broadcast", "wins", "timeout",
|
||||
"retries", NULL };
|
||||
io.in.broadcast = true;
|
||||
io.in.wins_lookup = false;
|
||||
io.in.timeout = 0;
|
||||
io.in.retries = 3;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|bbii:query_name",
|
||||
discard_const_p(char *, kwnames),
|
||||
&py_name, &py_dest,
|
||||
&io.in.broadcast, &io.in.wins_lookup,
|
||||
&io.in.timeout, &io.in.retries)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!PyObject_AsDestinationTuple(py_dest, &io.in.dest_addr, &io.in.dest_port))
|
||||
return NULL;
|
||||
|
||||
if (!PyObject_AsNBTName(py_name, node->socket, &io.in.name))
|
||||
return NULL;
|
||||
|
||||
status = nbt_name_query(node->socket, NULL, &io);
|
||||
|
||||
if (NT_STATUS_IS_ERR(status)) {
|
||||
PyErr_SetNTSTATUS(status);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = PyTuple_New(3);
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
PyTuple_SetItem(ret, 0, PyString_FromString(io.out.reply_from));
|
||||
|
||||
py_name = PyObject_FromNBTName(node->socket, lp_iconv_convenience(global_loadparm), &io.out.name);
|
||||
if (py_name == NULL)
|
||||
return NULL;
|
||||
|
||||
PyTuple_SetItem(ret, 1, py_name);
|
||||
|
||||
reply_addrs = PyList_New(io.out.num_addrs);
|
||||
if (reply_addrs == NULL) {
|
||||
Py_DECREF(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < io.out.num_addrs; i++) {
|
||||
PyList_SetItem(reply_addrs, i, PyString_FromString(io.out.reply_addrs[i]));
|
||||
}
|
||||
|
||||
PyTuple_SetItem(ret, 2, reply_addrs);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static PyObject *py_nbt_name_status(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
nbt_node_Object *node = (nbt_node_Object *)self;
|
||||
PyObject *ret, *py_dest, *py_name, *py_names;
|
||||
struct nbt_name_status io;
|
||||
int i;
|
||||
NTSTATUS status;
|
||||
|
||||
const char *kwnames[] = { "name", "dest", "timeout", "retries", NULL };
|
||||
|
||||
io.in.timeout = 0;
|
||||
io.in.retries = 0;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|ii:name_status",
|
||||
discard_const_p(char *, kwnames),
|
||||
&py_name, &py_dest,
|
||||
&io.in.timeout, &io.in.retries)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!PyObject_AsDestinationTuple(py_dest, &io.in.dest_addr, &io.in.dest_port))
|
||||
return NULL;
|
||||
|
||||
if (!PyObject_AsNBTName(py_name, node->socket, &io.in.name))
|
||||
return NULL;
|
||||
|
||||
status = nbt_name_status(node->socket, NULL, &io);
|
||||
|
||||
if (NT_STATUS_IS_ERR(status)) {
|
||||
PyErr_SetNTSTATUS(status);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = PyTuple_New(3);
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
PyTuple_SetItem(ret, 0, PyString_FromString(io.out.reply_from));
|
||||
|
||||
py_name = PyObject_FromNBTName(node->socket, lp_iconv_convenience(global_loadparm), &io.out.name);
|
||||
if (py_name == NULL)
|
||||
return NULL;
|
||||
|
||||
PyTuple_SetItem(ret, 1, py_name);
|
||||
|
||||
py_names = PyList_New(io.out.status.num_names);
|
||||
|
||||
for (i = 0; i < io.out.status.num_names; i++) {
|
||||
PyList_SetItem(py_names, i, Py_BuildValue("(sii)",
|
||||
io.out.status.names[i].name,
|
||||
io.out.status.names[i].nb_flags,
|
||||
io.out.status.names[i].type));
|
||||
}
|
||||
|
||||
PyTuple_SetItem(ret, 2, py_names);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static PyObject *py_nbt_name_register(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
nbt_node_Object *node = (nbt_node_Object *)self;
|
||||
PyObject *ret, *py_dest, *py_name;
|
||||
struct nbt_name_register io;
|
||||
NTSTATUS status;
|
||||
|
||||
const char *kwnames[] = { "name", "address", "dest", "register_demand", "broadcast",
|
||||
"multi_homed", "ttl", "timeout", "retries", NULL };
|
||||
|
||||
io.in.broadcast = true;
|
||||
io.in.multi_homed = true;
|
||||
io.in.register_demand = true;
|
||||
io.in.timeout = 0;
|
||||
io.in.retries = 0;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OsO|bbbiii:query_name",
|
||||
discard_const_p(char *, kwnames),
|
||||
&py_name, &io.in.address, &py_dest,
|
||||
&io.in.register_demand,
|
||||
&io.in.broadcast, &io.in.multi_homed,
|
||||
&io.in.ttl, &io.in.timeout, &io.in.retries)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!PyObject_AsDestinationTuple(py_dest, &io.in.dest_addr, &io.in.dest_port))
|
||||
return NULL;
|
||||
|
||||
if (!PyObject_AsNBTName(py_name, node->socket, &io.in.name))
|
||||
return NULL;
|
||||
|
||||
status = nbt_name_register(node->socket, NULL, &io);
|
||||
|
||||
if (NT_STATUS_IS_ERR(status)) {
|
||||
PyErr_SetNTSTATUS(status);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = PyTuple_New(3);
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
PyTuple_SetItem(ret, 0, PyString_FromString(io.out.reply_from));
|
||||
|
||||
py_name = PyObject_FromNBTName(node->socket, lp_iconv_convenience(global_loadparm), &io.out.name);
|
||||
if (py_name == NULL)
|
||||
return NULL;
|
||||
|
||||
PyTuple_SetItem(ret, 1, py_name);
|
||||
|
||||
PyTuple_SetItem(ret, 2, PyString_FromString(io.out.reply_addr));
|
||||
|
||||
PyTuple_SetItem(ret, 3, PyInt_FromLong(io.out.rcode));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static PyObject *py_nbt_name_refresh(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
nbt_node_Object *node = (nbt_node_Object *)self;
|
||||
PyObject *ret, *py_dest, *py_name;
|
||||
struct nbt_name_refresh io;
|
||||
NTSTATUS status;
|
||||
|
||||
const char *kwnames[] = { "name", "address", "dest", "nb_flags", "broadcast",
|
||||
"ttl", "timeout", "retries", NULL };
|
||||
|
||||
io.in.broadcast = true;
|
||||
io.in.nb_flags = 0;
|
||||
io.in.timeout = 0;
|
||||
io.in.retries = 0;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OsO|ibiii:query_name",
|
||||
discard_const_p(char *, kwnames),
|
||||
&py_name, &io.in.address, &py_dest,
|
||||
&io.in.nb_flags,
|
||||
&io.in.broadcast,
|
||||
&io.in.ttl, &io.in.timeout, &io.in.retries)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!PyObject_AsDestinationTuple(py_dest, &io.in.dest_addr, &io.in.dest_port))
|
||||
return NULL;
|
||||
|
||||
if (!PyObject_AsNBTName(py_name, node->socket, &io.in.name))
|
||||
return NULL;
|
||||
|
||||
status = nbt_name_refresh(node->socket, NULL, &io);
|
||||
|
||||
if (NT_STATUS_IS_ERR(status)) {
|
||||
PyErr_SetNTSTATUS(status);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = PyTuple_New(3);
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
PyTuple_SetItem(ret, 0, PyString_FromString(io.out.reply_from));
|
||||
|
||||
py_name = PyObject_FromNBTName(node->socket, lp_iconv_convenience(global_loadparm), &io.out.name);
|
||||
if (py_name == NULL)
|
||||
return NULL;
|
||||
|
||||
PyTuple_SetItem(ret, 1, py_name);
|
||||
|
||||
PyTuple_SetItem(ret, 2, PyString_FromString(io.out.reply_addr));
|
||||
|
||||
PyTuple_SetItem(ret, 3, PyInt_FromLong(io.out.rcode));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static PyObject *py_nbt_name_release(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
return Py_None; /* FIXME */
|
||||
}
|
||||
|
||||
static PyMethodDef py_nbt_methods[] = {
|
||||
{ "query_name", (PyCFunction)py_nbt_name_query, METH_VARARGS|METH_KEYWORDS,
|
||||
"S.query_name(name, dest, broadcast=True, wins=False, timeout=0, retries=3) -> (reply_from, name, reply_addr)\n"
|
||||
"Query for a NetBIOS name" },
|
||||
{ "register_name", (PyCFunction)py_nbt_name_register, METH_VARARGS|METH_KEYWORDS,
|
||||
"S.register_name(name, address, dest, register_demand=True, broadcast=True, multi_homed=True, ttl=0, timeout=0, retries=0) -> (reply_from, name, reply_addr, rcode)\n"
|
||||
"Register a new name" },
|
||||
{ "release_name", (PyCFunction)py_nbt_name_release, METH_VARARGS|METH_KEYWORDS, "S.release_name(name, address, dest, nb_flags=0, broadcast=true, timeout=0, retries=3) -> (reply_from, name, reply_addr, rcode)\n"
|
||||
"release a previously registered name" },
|
||||
{ "refresh_name", (PyCFunction)py_nbt_name_refresh, METH_VARARGS|METH_KEYWORDS, "S.refresh_name(name, address, dest, nb_flags=0, broadcast=True, ttl=0, timeout=0, retries=0) -> (reply_from, name, reply_addr, rcode)\n"
|
||||
"release a previously registered name" },
|
||||
{ "name_status", (PyCFunction)py_nbt_name_status, METH_VARARGS|METH_KEYWORDS,
|
||||
"S.name_status(name, dest, timeout=0, retries=0) -> (reply_from, name, status)\n"
|
||||
"Find the status of a name" },
|
||||
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
PyTypeObject nbt_node_Type = {
|
||||
PyObject_HEAD_INIT(NULL) 0,
|
||||
.tp_name = "netbios.Node",
|
||||
.tp_basicsize = sizeof(nbt_node_Object),
|
||||
.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
|
||||
.tp_new = py_nbt_node_init,
|
||||
.tp_dealloc = py_nbt_node_dealloc,
|
||||
.tp_methods = py_nbt_methods,
|
||||
.tp_doc = "Node()\n"
|
||||
"Create a new NetBIOS node\n"
|
||||
};
|
||||
|
||||
void initnetbios(void)
|
||||
{
|
||||
PyObject *mod;
|
||||
if (PyType_Ready(&nbt_node_Type) < 0)
|
||||
return;
|
||||
|
||||
mod = Py_InitModule3("netbios", NULL, "NetBIOS over TCP/IP support");
|
||||
|
||||
Py_INCREF((PyObject *)&nbt_node_Type);
|
||||
PyModule_AddObject(mod, "Node", (PyObject *)&nbt_node_Type);
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
Swig interface to libcli_nbt library.
|
||||
|
||||
Copyright (C) 2006 Tim Potter <tpot@samba.org>
|
||||
|
||||
** NOTE! The following LGPL license applies to the tdb
|
||||
** library. This does NOT imply that all of Samba is released
|
||||
** under the LGPL
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
%module libcli_nbt
|
||||
|
||||
%{
|
||||
|
||||
#include "includes.h"
|
||||
#include "lib/talloc/talloc.h"
|
||||
#include "libcli/nbt/libnbt.h"
|
||||
#include "param/param.h"
|
||||
#include "lib/events/events.h"
|
||||
|
||||
/* Undo strcpy safety macro as it's used by swig )-: */
|
||||
|
||||
#undef strcpy
|
||||
|
||||
%}
|
||||
|
||||
%import "stdint.i"
|
||||
%import "../util/errors.i"
|
||||
%import "../../lib/talloc/talloc.i"
|
||||
%import "../../lib/events/events.i"
|
||||
|
||||
/* Function prototypes */
|
||||
struct nbt_name_socket *nbt_name_socket_init(TALLOC_CTX *mem_ctx,
|
||||
struct event_context *event_ctx,
|
||||
struct smb_iconv_convenience *iconv_convenience);
|
||||
|
||||
enum nbt_name_type {
|
||||
NBT_NAME_CLIENT=0x00,
|
||||
NBT_NAME_MS=0x01,
|
||||
NBT_NAME_USER=0x03,
|
||||
NBT_NAME_SERVER=0x20,
|
||||
NBT_NAME_PDC=0x1B,
|
||||
NBT_NAME_LOGON=0x1C,
|
||||
NBT_NAME_MASTER=0x1D,
|
||||
NBT_NAME_BROWSER=0x1E
|
||||
};
|
||||
|
||||
struct nbt_name {
|
||||
const char *name;
|
||||
const char *scope;
|
||||
enum nbt_name_type type;
|
||||
};
|
||||
|
||||
%rename(data_in) in;
|
||||
%rename(data_out) out;
|
||||
|
||||
struct nbt_name_query {
|
||||
struct {
|
||||
struct nbt_name name;
|
||||
const char *dest_addr;
|
||||
bool broadcast;
|
||||
bool wins_lookup;
|
||||
int timeout; /* in seconds */
|
||||
int retries;
|
||||
} in;
|
||||
struct {
|
||||
const char *reply_from;
|
||||
struct nbt_name name;
|
||||
int16_t num_addrs;
|
||||
const char **reply_addrs;
|
||||
} out;
|
||||
};
|
||||
|
||||
%include "carrays.i"
|
||||
%array_functions(char *, char_ptr_array);
|
||||
|
||||
NTSTATUS do_nbt_name_query(struct nbt_name_socket *nbtsock,
|
||||
TALLOC_CTX *mem_ctx, struct nbt_name_query *io);
|
||||
|
||||
%{
|
||||
NTSTATUS do_nbt_name_query(struct nbt_name_socket *nbtsock,
|
||||
TALLOC_CTX *mem_ctx, struct nbt_name_query *io)
|
||||
{
|
||||
return nbt_name_query(nbtsock, mem_ctx, io);
|
||||
}
|
||||
%}
|
@ -1,127 +0,0 @@
|
||||
# This file was automatically generated by SWIG (http://www.swig.org).
|
||||
# Version 1.3.35
|
||||
#
|
||||
# Don't modify this file, modify the SWIG interface instead.
|
||||
|
||||
import _libcli_nbt
|
||||
import new
|
||||
new_instancemethod = new.instancemethod
|
||||
try:
|
||||
_swig_property = property
|
||||
except NameError:
|
||||
pass # Python < 2.2 doesn't have 'property'.
|
||||
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
|
||||
if (name == "thisown"): return self.this.own(value)
|
||||
if (name == "this"):
|
||||
if type(value).__name__ == 'PySwigObject':
|
||||
self.__dict__[name] = value
|
||||
return
|
||||
method = class_type.__swig_setmethods__.get(name,None)
|
||||
if method: return method(self,value)
|
||||
if (not static) or hasattr(self,name):
|
||||
self.__dict__[name] = value
|
||||
else:
|
||||
raise AttributeError("You cannot add attributes to %s" % self)
|
||||
|
||||
def _swig_setattr(self,class_type,name,value):
|
||||
return _swig_setattr_nondynamic(self,class_type,name,value,0)
|
||||
|
||||
def _swig_getattr(self,class_type,name):
|
||||
if (name == "thisown"): return self.this.own()
|
||||
method = class_type.__swig_getmethods__.get(name,None)
|
||||
if method: return method(self)
|
||||
raise AttributeError,name
|
||||
|
||||
def _swig_repr(self):
|
||||
try: strthis = "proxy of " + self.this.__repr__()
|
||||
except: strthis = ""
|
||||
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
|
||||
|
||||
import types
|
||||
try:
|
||||
_object = types.ObjectType
|
||||
_newclass = 1
|
||||
except AttributeError:
|
||||
class _object : pass
|
||||
_newclass = 0
|
||||
del types
|
||||
|
||||
|
||||
def _swig_setattr_nondynamic_method(set):
|
||||
def set_attr(self,name,value):
|
||||
if (name == "thisown"): return self.this.own(value)
|
||||
if hasattr(self,name) or (name == "this"):
|
||||
set(self,name,value)
|
||||
else:
|
||||
raise AttributeError("You cannot add attributes to %s" % self)
|
||||
return set_attr
|
||||
|
||||
|
||||
import events
|
||||
nbt_name_socket_init = _libcli_nbt.nbt_name_socket_init
|
||||
NBT_NAME_CLIENT = _libcli_nbt.NBT_NAME_CLIENT
|
||||
NBT_NAME_MS = _libcli_nbt.NBT_NAME_MS
|
||||
NBT_NAME_USER = _libcli_nbt.NBT_NAME_USER
|
||||
NBT_NAME_SERVER = _libcli_nbt.NBT_NAME_SERVER
|
||||
NBT_NAME_PDC = _libcli_nbt.NBT_NAME_PDC
|
||||
NBT_NAME_LOGON = _libcli_nbt.NBT_NAME_LOGON
|
||||
NBT_NAME_MASTER = _libcli_nbt.NBT_NAME_MASTER
|
||||
NBT_NAME_BROWSER = _libcli_nbt.NBT_NAME_BROWSER
|
||||
class nbt_name(object):
|
||||
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
|
||||
__repr__ = _swig_repr
|
||||
name = _swig_property(_libcli_nbt.nbt_name_name_get, _libcli_nbt.nbt_name_name_set)
|
||||
scope = _swig_property(_libcli_nbt.nbt_name_scope_get, _libcli_nbt.nbt_name_scope_set)
|
||||
type = _swig_property(_libcli_nbt.nbt_name_type_get, _libcli_nbt.nbt_name_type_set)
|
||||
def __init__(self, *args, **kwargs):
|
||||
_libcli_nbt.nbt_name_swiginit(self,_libcli_nbt.new_nbt_name(*args, **kwargs))
|
||||
__swig_destroy__ = _libcli_nbt.delete_nbt_name
|
||||
nbt_name_swigregister = _libcli_nbt.nbt_name_swigregister
|
||||
nbt_name_swigregister(nbt_name)
|
||||
|
||||
class nbt_name_query(object):
|
||||
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
|
||||
__repr__ = _swig_repr
|
||||
data_out = _swig_property(_libcli_nbt.nbt_name_query_data_out_get)
|
||||
data_in = _swig_property(_libcli_nbt.nbt_name_query_data_in_get)
|
||||
def __init__(self, *args, **kwargs):
|
||||
_libcli_nbt.nbt_name_query_swiginit(self,_libcli_nbt.new_nbt_name_query(*args, **kwargs))
|
||||
__swig_destroy__ = _libcli_nbt.delete_nbt_name_query
|
||||
nbt_name_query_swigregister = _libcli_nbt.nbt_name_query_swigregister
|
||||
nbt_name_query_swigregister(nbt_name_query)
|
||||
|
||||
class nbt_name_query_out(object):
|
||||
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
|
||||
__repr__ = _swig_repr
|
||||
reply_from = _swig_property(_libcli_nbt.nbt_name_query_out_reply_from_get, _libcli_nbt.nbt_name_query_out_reply_from_set)
|
||||
name = _swig_property(_libcli_nbt.nbt_name_query_out_name_get, _libcli_nbt.nbt_name_query_out_name_set)
|
||||
num_addrs = _swig_property(_libcli_nbt.nbt_name_query_out_num_addrs_get, _libcli_nbt.nbt_name_query_out_num_addrs_set)
|
||||
reply_addrs = _swig_property(_libcli_nbt.nbt_name_query_out_reply_addrs_get, _libcli_nbt.nbt_name_query_out_reply_addrs_set)
|
||||
def __init__(self, *args, **kwargs):
|
||||
_libcli_nbt.nbt_name_query_out_swiginit(self,_libcli_nbt.new_nbt_name_query_out(*args, **kwargs))
|
||||
__swig_destroy__ = _libcli_nbt.delete_nbt_name_query_out
|
||||
nbt_name_query_out_swigregister = _libcli_nbt.nbt_name_query_out_swigregister
|
||||
nbt_name_query_out_swigregister(nbt_name_query_out)
|
||||
|
||||
class nbt_name_query_in(object):
|
||||
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
|
||||
__repr__ = _swig_repr
|
||||
name = _swig_property(_libcli_nbt.nbt_name_query_in_name_get, _libcli_nbt.nbt_name_query_in_name_set)
|
||||
dest_addr = _swig_property(_libcli_nbt.nbt_name_query_in_dest_addr_get, _libcli_nbt.nbt_name_query_in_dest_addr_set)
|
||||
broadcast = _swig_property(_libcli_nbt.nbt_name_query_in_broadcast_get, _libcli_nbt.nbt_name_query_in_broadcast_set)
|
||||
wins_lookup = _swig_property(_libcli_nbt.nbt_name_query_in_wins_lookup_get, _libcli_nbt.nbt_name_query_in_wins_lookup_set)
|
||||
timeout = _swig_property(_libcli_nbt.nbt_name_query_in_timeout_get, _libcli_nbt.nbt_name_query_in_timeout_set)
|
||||
retries = _swig_property(_libcli_nbt.nbt_name_query_in_retries_get, _libcli_nbt.nbt_name_query_in_retries_set)
|
||||
def __init__(self, *args, **kwargs):
|
||||
_libcli_nbt.nbt_name_query_in_swiginit(self,_libcli_nbt.new_nbt_name_query_in(*args, **kwargs))
|
||||
__swig_destroy__ = _libcli_nbt.delete_nbt_name_query_in
|
||||
nbt_name_query_in_swigregister = _libcli_nbt.nbt_name_query_in_swigregister
|
||||
nbt_name_query_in_swigregister(nbt_name_query_in)
|
||||
|
||||
new_char_ptr_array = _libcli_nbt.new_char_ptr_array
|
||||
delete_char_ptr_array = _libcli_nbt.delete_char_ptr_array
|
||||
char_ptr_array_getitem = _libcli_nbt.char_ptr_array_getitem
|
||||
char_ptr_array_setitem = _libcli_nbt.char_ptr_array_setitem
|
||||
do_nbt_name_query = _libcli_nbt.do_nbt_name_query
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -668,11 +668,11 @@ PRIVATE_DEPENDENCIES = dcerpc_atsvc PYTALLOC param swig_credentials python_dcer
|
||||
|
||||
python_atsvc_OBJ_FILES = $(gen_ndrsrcdir)/py_atsvc.o
|
||||
|
||||
[PYTHON::python_nbt]
|
||||
[PYTHON::python_dcerpc_nbt]
|
||||
LIBRARY_REALNAME = samba/nbt.$(SHLIBEXT)
|
||||
PRIVATE_DEPENDENCIES = NDR_NBT PYTALLOC param swig_credentials python_dcerpc
|
||||
|
||||
python_nbt_OBJ_FILES = $(gen_ndrsrcdir)/py_nbt.o
|
||||
python_dcerpc_nbt_OBJ_FILES = $(gen_ndrsrcdir)/py_nbt.o
|
||||
|
||||
[PYTHON::python_samr]
|
||||
LIBRARY_REALNAME = samba/dcerpc/samr.$(SHLIBEXT)
|
||||
@ -712,7 +712,7 @@ python_unixinfo_OBJ_FILES = $(gen_ndrsrcdir)/py_unixinfo.o
|
||||
|
||||
[PYTHON::python_irpc]
|
||||
LIBRARY_REALNAME = samba/irpc.$(SHLIBEXT)
|
||||
PRIVATE_DEPENDENCIES = RPC_NDR_IRPC PYTALLOC param swig_credentials python_dcerpc_security python_dcerpc_misc python_dcerpc python_nbt
|
||||
PRIVATE_DEPENDENCIES = RPC_NDR_IRPC PYTALLOC param swig_credentials python_dcerpc_security python_dcerpc_misc python_dcerpc python_dcerpc_nbt
|
||||
|
||||
python_irpc_OBJ_FILES = $(gen_ndrsrcdir)/py_irpc.o
|
||||
|
||||
|
28
source4/scripting/python/examples/netbios.py
Normal file
28
source4/scripting/python/examples/netbios.py
Normal file
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# Unix SMB/CIFS implementation.
|
||||
# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
from samba.netbios import Node
|
||||
|
||||
n = Node()
|
||||
(reply_from, names, addresses) = n.query_name("GANIEDA", "192.168.4.0",
|
||||
timeout=4)
|
||||
|
||||
print "Received reply from %s:" % (reply_from, )
|
||||
print "Names: %r" % (names, )
|
||||
print "Addresses: %r" % (addresses, )
|
Reference in New Issue
Block a user