diff options
author | Andrew Bartlett <abartlet@samba.org> | 2012-10-29 15:34:41 +1100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2012-10-31 08:13:56 +1100 |
commit | a732f2a621665923322422c5a3d788c9d1aa8df9 (patch) | |
tree | 5541f22588fd136ce1a19095e997a50147916525 /source4/lib | |
parent | 76b7348299870279acec5b7c9f02f4e4b2461703 (diff) | |
download | samba-a732f2a621665923322422c5a3d788c9d1aa8df9.tar.gz samba-a732f2a621665923322422c5a3d788c9d1aa8df9.tar.bz2 samba-a732f2a621665923322422c5a3d788c9d1aa8df9.zip |
pymessaging: Add irpc_servers_byname() and irpc_all_servers()
This will allow python scripts to inspect the process list.
Andrew Bartlett
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/messaging/pymessaging.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/source4/lib/messaging/pymessaging.c b/source4/lib/messaging/pymessaging.c index fb74f3e1db..fca46e6749 100644 --- a/source4/lib/messaging/pymessaging.c +++ b/source4/lib/messaging/pymessaging.c @@ -221,6 +221,101 @@ static PyObject *py_imessaging_deregister(PyObject *self, PyObject *args, PyObje Py_RETURN_NONE; } +static PyObject *py_irpc_servers_byname(PyObject *self, PyObject *args, PyObject *kwargs) +{ + imessaging_Object *iface = (imessaging_Object *)self; + char *server_name; + struct server_id *ids; + PyObject *pylist; + int i; + TALLOC_CTX *mem_ctx = talloc_new(NULL); + if (!mem_ctx) { + PyErr_NoMemory(); + return NULL; + } + + if (!PyArg_ParseTuple(args, "s", &server_name)) { + TALLOC_FREE(mem_ctx); + return NULL; + } + + ids = irpc_servers_byname(iface->msg_ctx, mem_ctx, server_name); + + if (ids == NULL) { + TALLOC_FREE(mem_ctx); + PyErr_SetString(PyExc_KeyError, "No such name"); + return NULL; + } + + for (i = 0; ids[i].pid != 0; i++) { + /* Do nothing */ + } + + pylist = PyList_New(i); + if (pylist == NULL) { + TALLOC_FREE(mem_ctx); + PyErr_NoMemory(); + return NULL; + } + for (i = 0; ids[i].pid; i++) { + PyObject *py_server_id; + struct server_id *p_server_id = talloc(NULL, struct server_id); + if (!p_server_id) { + PyErr_NoMemory(); + return NULL; + } + *p_server_id = ids[i]; + + py_server_id = py_return_ndr_struct("samba.dcerpc.server_id", "server_id", p_server_id, p_server_id); + if (!py_server_id) { + return NULL; + } + PyList_SetItem(pylist, i, py_server_id); + talloc_unlink(NULL, p_server_id); + } + TALLOC_FREE(mem_ctx); + return pylist; +} + +static PyObject *py_irpc_all_servers(PyObject *self, PyObject *args, PyObject *kwargs) +{ + imessaging_Object *iface = (imessaging_Object *)self; + PyObject *pylist; + int i; + struct irpc_name_records *records; + TALLOC_CTX *mem_ctx = talloc_new(NULL); + if (!mem_ctx) { + PyErr_NoMemory(); + return NULL; + } + + records = irpc_all_servers(iface->msg_ctx, mem_ctx); + if (records == NULL) { + return NULL; + } + + pylist = PyList_New(records->num_records); + if (pylist == NULL) { + TALLOC_FREE(mem_ctx); + PyErr_NoMemory(); + return NULL; + } + for (i = 0; i < records->num_records; i++) { + PyObject *py_name_record + = py_return_ndr_struct("samba.dcerpc.irpc", + "name_record", + records->names[i], + records->names[i]); + if (!py_name_record) { + return NULL; + } + PyList_SetItem(pylist, i, + py_name_record); + } + TALLOC_FREE(mem_ctx); + return pylist; +} + static PyMethodDef py_imessaging_methods[] = { { "send", (PyCFunction)py_imessaging_send, METH_VARARGS|METH_KEYWORDS, "S.send(target, msg_type, data) -> None\nSend a message" }, @@ -228,6 +323,10 @@ static PyMethodDef py_imessaging_methods[] = { "S.register(callback, msg_type=None) -> msg_type\nRegister a message handler" }, { "deregister", (PyCFunction)py_imessaging_deregister, METH_VARARGS|METH_KEYWORDS, "S.deregister(callback, msg_type) -> None\nDeregister a message handler" }, + { "irpc_servers_byname", (PyCFunction)py_irpc_servers_byname, METH_VARARGS, + "S.irpc_servers_byname(name) -> list\nGet list of server_id values that are registered for a particular name" }, + { "irpc_all_servers", (PyCFunction)py_irpc_all_servers, METH_NOARGS, + "S.irpc_servers_byname() -> list\nGet list of all registered names and the associated server_id values" }, { NULL, NULL, 0, NULL } }; |