summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-05-26 04:14:28 +0200
committerJelmer Vernooij <jelmer@samba.org>2008-05-26 04:14:28 +0200
commitd5434f0b4bcf744e5a5f0e933bdcf629d42a6478 (patch)
treeace24381ce274aa5d1d29af03ffd7917732334da
parentd60d8e57d83acfc94fa36c59fcfb9c6e03ee02b6 (diff)
downloadsamba-d5434f0b4bcf744e5a5f0e933bdcf629d42a6478.tar.gz
samba-d5434f0b4bcf744e5a5f0e933bdcf629d42a6478.tar.bz2
samba-d5434f0b4bcf744e5a5f0e933bdcf629d42a6478.zip
Allow using IRPC functions on the messaging bus from Python.
(This used to be commit 6ecf81ae13dffa05356c1177c617206c120fb7d7)
-rw-r--r--source4/lib/messaging/config.mk8
-rw-r--r--source4/lib/messaging/pymessaging.c (renamed from source4/lib/messaging/pyirpc.c)49
-rw-r--r--source4/librpc/config.mk17
-rw-r--r--source4/librpc/rpc/pyrpc.h2
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4/Python.pm2
-rwxr-xr-xsource4/scripting/bin/smbstatus39
6 files changed, 76 insertions, 41 deletions
diff --git a/source4/lib/messaging/config.mk b/source4/lib/messaging/config.mk
index f330ed7cab..e92f78c8e3 100644
--- a/source4/lib/messaging/config.mk
+++ b/source4/lib/messaging/config.mk
@@ -11,8 +11,8 @@ PUBLIC_DEPENDENCIES = \
MESSAGING_OBJ_FILES = $(libmessagingsrcdir)/messaging.o
-[PYTHON::python_irpc]
-LIBRARY_REALNAME = samba/irpc.$(SHLIBEXT)
-PRIVATE_DEPENDENCIES = MESSAGING LIBEVENTS
+[PYTHON::python_messaging]
+LIBRARY_REALNAME = samba/messaging.$(SHLIBEXT)
+PRIVATE_DEPENDENCIES = MESSAGING LIBEVENTS python_irpc
-python_irpc_OBJ_FILES = $(libmessagingsrcdir)/pyirpc.o
+python_messaging_OBJ_FILES = $(libmessagingsrcdir)/pymessaging.o
diff --git a/source4/lib/messaging/pyirpc.c b/source4/lib/messaging/pymessaging.c
index 41475daaff..e05d5eb1f1 100644
--- a/source4/lib/messaging/pyirpc.c
+++ b/source4/lib/messaging/pymessaging.c
@@ -31,7 +31,7 @@
#include "librpc/gen_ndr/py_irpc.h"
PyAPI_DATA(PyTypeObject) messaging_Type;
-PyAPI_DATA(PyTypeObject) irpc_InterfaceType;
+PyAPI_DATA(PyTypeObject) irpc_ClientConnectionType;
static bool server_id_from_py(PyObject *object, struct server_id *server_id)
{
@@ -65,7 +65,7 @@ PyObject *py_messaging_connect(PyTypeObject *self, PyObject *args, PyObject *kwa
const char *messaging_path = NULL;
messaging_Object *ret;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Os:connect",
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Oz:connect",
discard_const_p(char *, kwnames), &own_id, &messaging_path)) {
return NULL;
}
@@ -280,6 +280,9 @@ PyTypeObject messaging_Type = {
.tp_dealloc = py_messaging_dealloc,
.tp_methods = py_messaging_methods,
.tp_getset = py_messaging_getset,
+ .tp_doc = "Messaging(own_id=None, messaging_path=None)\n" \
+ "Create a new object that can be used to communicate with the peers in the specified messaging path.\n" \
+ "If no path is specified, the default path from smb.conf will be used."
};
@@ -292,7 +295,7 @@ typedef struct {
struct server_id *dest_ids;
struct messaging_context *msg_ctx;
TALLOC_CTX *mem_ctx;
-} irpc_InterfaceObject;
+} irpc_ClientConnectionObject;
/*
setup a context for talking to a irpc server
@@ -307,14 +310,14 @@ PyObject *py_irpc_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs)
char *server;
const char *messaging_path = NULL;
PyObject *own_id = Py_None;
- irpc_InterfaceObject *ret;
+ irpc_ClientConnectionObject *ret;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|Os:connect",
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|Oz:connect",
discard_const_p(char *, kwnames), &server, &own_id, &messaging_path)) {
return NULL;
}
- ret = PyObject_New(irpc_InterfaceObject, &irpc_InterfaceType);
+ ret = PyObject_New(irpc_ClientConnectionObject, &irpc_ClientConnectionType);
if (ret == NULL)
return NULL;
@@ -326,6 +329,8 @@ PyObject *py_irpc_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs)
if (messaging_path == NULL) {
messaging_path = lp_messaging_path(ret, global_loadparm);
+ } else {
+ messaging_path = talloc_strdup(ret->mem_ctx, messaging_path);
}
if (own_id != Py_None) {
@@ -413,12 +418,13 @@ PyTypeObject irpc_ResultIteratorType = {
.tp_name = "irpc.ResultIterator",
.tp_basicsize = sizeof(irpc_ResultObject),
.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
- .tp_iter = (iternextfunc)irpc_result_next,
+ .tp_iternext = (iternextfunc)irpc_result_next,
+ .tp_iter = PyObject_SelfIter,
.tp_methods = irpc_result_methods,
.tp_dealloc = irpc_result_dealloc,
};
-static PyObject *py_irpc_call(irpc_InterfaceObject *p, struct PyNdrRpcMethodDef *method_def, PyObject *args, PyObject *kwargs)
+static PyObject *py_irpc_call(irpc_ClientConnectionObject *p, struct PyNdrRpcMethodDef *method_def, PyObject *args, PyObject *kwargs)
{
void *ptr;
struct irpc_request **reqs;
@@ -476,7 +482,7 @@ done:
static PyObject *py_irpc_call_wrapper(PyObject *self, PyObject *args, void *wrapped, PyObject *kwargs)
{
- irpc_InterfaceObject *iface = (irpc_InterfaceObject *)self;
+ irpc_ClientConnectionObject *iface = (irpc_ClientConnectionObject *)self;
struct PyNdrRpcMethodDef *md = wrapped;
return py_irpc_call(iface, md, args, kwargs);
@@ -484,21 +490,24 @@ static PyObject *py_irpc_call_wrapper(PyObject *self, PyObject *args, void *wrap
static void py_irpc_dealloc(PyObject *self)
{
- irpc_InterfaceObject *iface = (irpc_InterfaceObject *)self;
+ irpc_ClientConnectionObject *iface = (irpc_ClientConnectionObject *)self;
talloc_free(iface->mem_ctx);
PyObject_Del(self);
}
-PyTypeObject irpc_InterfaceType = {
+PyTypeObject irpc_ClientConnectionType = {
PyObject_HEAD_INIT(NULL) 0,
.tp_name = "irpc.ClientConnection",
- .tp_basicsize = sizeof(irpc_InterfaceObject),
+ .tp_basicsize = sizeof(irpc_ClientConnectionObject),
.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
.tp_new = py_irpc_connect,
.tp_dealloc = py_irpc_dealloc,
+ .tp_doc = "ClientConnection(server, own_id=None, messaging_path=None)\n" \
+ "Create a new IRPC client connection to communicate with the servers in the specified path.\n" \
+ "If no path is specified, the default path from smb.conf will be used."
};
-static bool irpc_AddNdrRpcMethods(PyTypeObject *ifacetype, struct PyNdrRpcMethodDef *mds)
+static bool irpc_AddNdrRpcMethods(PyTypeObject *ifacetype, const struct PyNdrRpcMethodDef *mds)
{
int i;
for (i = 0; mds[i].name; i++) {
@@ -510,7 +519,7 @@ static bool irpc_AddNdrRpcMethods(PyTypeObject *ifacetype, struct PyNdrRpcMethod
wb->wrapper = (wrapperfunc)py_irpc_call_wrapper;
wb->doc = discard_const_p(char, mds[i].doc);
- ret = PyDescr_NewWrapper(ifacetype, wb, &mds[i]);
+ ret = PyDescr_NewWrapper(ifacetype, wb, discard_const_p(void, &mds[i]));
PyDict_SetItemString(ifacetype->tp_dict, mds[i].name,
(PyObject *)ret);
@@ -519,11 +528,11 @@ static bool irpc_AddNdrRpcMethods(PyTypeObject *ifacetype, struct PyNdrRpcMethod
return true;
}
-void initirpc(void)
+void initmessaging(void)
{
PyObject *mod;
- if (PyType_Ready(&irpc_InterfaceType) < 0)
+ if (PyType_Ready(&irpc_ClientConnectionType) < 0)
return;
if (PyType_Ready(&messaging_Type) < 0)
@@ -532,15 +541,15 @@ void initirpc(void)
if (PyType_Ready(&irpc_ResultIteratorType) < 0)
return;
- if (!irpc_AddNdrRpcMethods(&irpc_InterfaceType, py_ndr_irpc_methods))
+ if (!irpc_AddNdrRpcMethods(&irpc_ClientConnectionType, py_ndr_irpc_methods))
return;
- mod = Py_InitModule3("irpc", NULL, "Internal RPC");
+ mod = Py_InitModule3("messaging", NULL, "Internal RPC");
if (mod == NULL)
return;
- Py_INCREF((PyObject *)&irpc_InterfaceType);
- PyModule_AddObject(mod, "ClientConnection", (PyObject *)&irpc_InterfaceType);
+ Py_INCREF((PyObject *)&irpc_ClientConnectionType);
+ PyModule_AddObject(mod, "ClientConnection", (PyObject *)&irpc_ClientConnectionType);
Py_INCREF((PyObject *)&messaging_Type);
PyModule_AddObject(mod, "Messaging", (PyObject *)&messaging_Type);
diff --git a/source4/librpc/config.mk b/source4/librpc/config.mk
index 2943c7b516..ab25921ef8 100644
--- a/source4/librpc/config.mk
+++ b/source4/librpc/config.mk
@@ -434,6 +434,11 @@ PUBLIC_DEPENDENCIES = dcerpc NDR_UNIXINFO
RPC_NDR_UNIXINFO_OBJ_FILES = $(gen_ndrsrcdir)/ndr_unixinfo_c.o
+[SUBSYSTEM::RPC_NDR_IRPC]
+PUBLIC_DEPENDENCIES = dcerpc NDR_IRPC
+
+RPC_NDR_IRPC_OBJ_FILES = $(gen_ndrsrcdir)/ndr_irpc_c.o
+
[LIBRARY::dcerpc_samr]
PUBLIC_DEPENDENCIES = dcerpc NDR_SAMR
@@ -658,6 +663,12 @@ PRIVATE_DEPENDENCIES = dcerpc_atsvc PYTALLOC param swig_credentials python_dcer
python_atsvc_OBJ_FILES = $(gen_ndrsrcdir)/py_atsvc.o
+[PYTHON::python_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::python_samr]
LIBRARY_REALNAME = samba/dcerpc/samr.$(SHLIBEXT)
PRIVATE_DEPENDENCIES = dcerpc_samr PYTALLOC python_dcerpc_security python_lsa python_dcerpc_misc swig_credentials param python_dcerpc
@@ -694,6 +705,12 @@ PRIVATE_DEPENDENCIES = RPC_NDR_UNIXINFO PYTALLOC param swig_credentials python_d
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
+
+python_irpc_OBJ_FILES = $(gen_ndrsrcdir)/py_irpc.o
+
[PYTHON::python_drsuapi]
LIBRARY_REALNAME = samba/dcerpc/drsuapi.$(SHLIBEXT)
PRIVATE_DEPENDENCIES = RPC_NDR_DRSUAPI PYTALLOC param swig_credentials python_dcerpc_misc python_dcerpc_security python_dcerpc
diff --git a/source4/librpc/rpc/pyrpc.h b/source4/librpc/rpc/pyrpc.h
index 989aeecc7b..af9ca728d8 100644
--- a/source4/librpc/rpc/pyrpc.h
+++ b/source4/librpc/rpc/pyrpc.h
@@ -29,8 +29,10 @@
fail; \
}
+#define dom_sid0_Type dom_sid_Type
#define dom_sid2_Type dom_sid_Type
#define dom_sid28_Type dom_sid_Type
+#define dom_sid0_Check dom_sid_Check
#define dom_sid2_Check dom_sid_Check
#define dom_sid28_Check dom_sid_Check
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
index 055ee13b10..b5ae801ff8 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -651,7 +651,7 @@ sub Interface($$$)
}
$self->pidl("const struct PyNdrRpcMethodDef py_ndr_$interface->{NAME}\_methods[] = {");
- $self->pidl_hdr("const struct PyNdrRpcMethodDef py_ndr_$interface->{NAME}\_methods[];");
+ $self->pidl_hdr("extern const struct PyNdrRpcMethodDef py_ndr_$interface->{NAME}\_methods[];");
$self->indent;
foreach my $d (@fns) {
my ($infn, $outfn, $callfn, $prettyname, $docstring, $opnum) = @$d;
diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus
index 782e83e4cf..6d852c279c 100755
--- a/source4/scripting/bin/smbstatus
+++ b/source4/scripting/bin/smbstatus
@@ -15,11 +15,12 @@ sys.path.insert(0, "bin/python")
import optparse
import samba.getopt as options
-import samba.irpc
+from samba import messaging, irpc
-def show_sessions():
+def show_sessions(conn):
"""show open sessions"""
- sessions = smbsrv_sessions()
+ conn = open_connection("smb_server")
+ sessions = conn.smbsrv_information(irpc.SMBSRV_INFO_SESSIONS).next()
print "User Client Connected at"
print "-------------------------------------------------------------------------------"
for session in sessions:
@@ -27,37 +28,43 @@ def show_sessions():
print "%-30s %16s %s" % (fulluser, session.client_ip, sys.httptime(session.connect_time))
print ""
-def show_tcons():
+def show_tcons(open_connection):
"""show open tree connects"""
- tcons = smbsrv_tcons()
+ conn = open_connection("smb_server")
+ tcons = conn.smbsrv_information(irpc.SMBSRV_INFO_TCONS).next()
print "Share Client Connected at"
print "-------------------------------------------------------------------------------"
for tcon in tcons:
print "%-30s %16s %s\n" % (tcon.share_name, tcon.client_ip, sys.httptime(tcon.connect_time))
-def show_nbt():
+def show_nbt(open_connection):
"""show nbtd information"""
- stats = nbtd_statistics()
- print "NBT server statistics:",
+ conn = open_connection("nbt_server")
+ stats = conn.nbtd_information(irpc.NBTD_INFO_STATISTICS).next()
+ print "NBT server statistics:"
for r in stats:
- print "\t" + r + ":\t" + stats[r] + "\n"
+ print "\t" + r + ":\t" + getattr(stats, r) + "\n"
print ""
parser = optparse.OptionParser("%s [options]" % sys.argv[0])
sambaopts = options.SambaOptions(parser)
parser.add_option_group(sambaopts)
-parser.add_option("--nbt", type="string", metavar="NBT",
- help="show NetBIOS status")
+parser.add_option("--messaging-path", type="string", metavar="PATH",
+ help="messaging path")
+parser.add_option("--nbt", help="show NetBIOS status", action="store_true")
+
+opts, args = parser.parse_args()
lp = sambaopts.get_loadparm()
print "%s\n\n" % lp.get("server string")
+def open_connection(name):
+ return messaging.ClientConnection(name, messaging_path=opts.messaging_path)
+
if opts.nbt:
- show_nbt()
+ show_nbt(open_connection)
else:
- show_sessions()
- show_tcons()
-
-return 0
+ show_sessions(open_connection)
+ show_tcons(open_connection)