#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)
{
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;
}
.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."
};
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
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;
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) {
.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;
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);
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++) {
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);
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)
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);
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:
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)