summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-02-17 22:19:57 +1100
committerStefan Metzmacher <metze@samba.org>2010-02-23 13:48:20 +0100
commitcb7ab80ee883a69f575940bfa6b4c99242c7f646 (patch)
treea255aa421ca288f526e4ef49aab06fd098b0b635
parent61af327e5d2bb97909f349fbc918d6981aa1f196 (diff)
downloadsamba-cb7ab80ee883a69f575940bfa6b4c99242c7f646.tar.gz
samba-cb7ab80ee883a69f575940bfa6b4c99242c7f646.tar.bz2
samba-cb7ab80ee883a69f575940bfa6b4c99242c7f646.zip
s4-pyglue: added interface_ips() call
This allows a python script to query the internal network interface lists from Samba
-rw-r--r--source4/scripting/python/pyglue.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/source4/scripting/python/pyglue.c b/source4/scripting/python/pyglue.c
index 57e6043eb2..f072386791 100644
--- a/source4/scripting/python/pyglue.c
+++ b/source4/scripting/python/pyglue.c
@@ -34,6 +34,8 @@
#include "auth/pyauth.h"
#include "param/pyparam.h"
#include "auth/credentials/pycredentials.h"
+#include "lib/socket/netif.h"
+#include "lib/socket/netif_proto.h"
/* FIXME: These should be in a header file somewhere, once we finish moving
* away from SWIG .. */
@@ -486,6 +488,45 @@ static PyObject *py_dsdb_load_partition_usn(PyObject *self, PyObject *args)
}
+/*
+ return the list of interface IPs we have configured
+ takes an loadparm context, returns a list of IPs in string form
+ */
+static PyObject *py_interface_ips(PyObject *self, PyObject *args)
+{
+ PyObject *pylist;
+ int count;
+ TALLOC_CTX *tmp_ctx;
+ PyObject *py_lp_ctx;
+ struct loadparm_context *lp_ctx;
+ struct interface *ifaces;
+ int i;
+
+ if (!PyArg_ParseTuple(args, "O", &py_lp_ctx))
+ return NULL;
+
+ lp_ctx = lp_from_py_object(py_lp_ctx);
+ if (lp_ctx == NULL) {
+ PyErr_SetString(PyExc_TypeError, "Expected loadparm object");
+ return NULL;
+ }
+
+ tmp_ctx = talloc_new(NULL);
+
+ load_interfaces(tmp_ctx, lp_interfaces(lp_ctx), &ifaces);
+
+ count = iface_count(ifaces);
+
+ pylist = PyList_New(count);
+ for (i = 0; i<count; i++) {
+ PyList_SetItem(pylist, i,
+ PyString_FromString(iface_n_ip(ifaces, i)));
+ }
+ talloc_free(tmp_ctx);
+ return pylist;
+}
+
+
static PyMethodDef py_misc_methods[] = {
{ "generate_random_str", (PyCFunction)py_generate_random_str, METH_VARARGS,
"random_password(len) -> string\n"
@@ -533,6 +574,8 @@ static PyMethodDef py_misc_methods[] = {
"set debug level" },
{ "dsdb_load_partition_usn", (PyCFunction)py_dsdb_load_partition_usn, METH_VARARGS,
"get uSNHighest and uSNUrgent from the partition @REPLCHANGED"},
+ { "interface_ips", (PyCFunction)py_interface_ips, METH_VARARGS,
+ "get interface IP address list"},
{ NULL }
};