summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOsier Yang <jyang@redhat.com>2012-09-05 00:10:19 +0800
committerOsier Yang <jyang@redhat.com>2012-09-12 15:37:09 +0800
commitb286824eee96095ba18b44339e8d33e8eb367d6a (patch)
tree3bf4d29509fcd14efb85f775358c45aa0fdc30b8
parentc3a037d4129e360d608e29329ede93318cc0ce19 (diff)
downloadlibvirt-python-split-b286824eee96095ba18b44339e8d33e8eb367d6a.zip
libvirt-python-split-b286824eee96095ba18b44339e8d33e8eb367d6a.tar.gz
libvirt-python-split-b286824eee96095ba18b44339e8d33e8eb367d6a.tar.xz
list: Expose virConnectListAllInterfaces to Python bindingCVE-2012-4423
The implementation is done manually as the generator does not support wrapping lists of C pointers into Python objects. python/libvirt-override-api.xml: Document python/libvirt-override-virConnect.py: * New file, includes implementation of listAllInterfaces. python/libvirt-override.c: Implementation for the wrapper.
-rw-r--r--libvirt-override-api.xml6
-rw-r--r--libvirt-override-virConnect.py12
-rw-r--r--libvirt-override.c48
3 files changed, 66 insertions, 0 deletions
diff --git a/libvirt-override-api.xml b/libvirt-override-api.xml
index 5f51fc7..ab6f407 100644
--- a/libvirt-override-api.xml
+++ b/libvirt-override-api.xml
@@ -416,6 +416,12 @@
<arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
<return type='str *' info='the list of Names of None in case of error'/>
</function>
+ <function name='virConnectListAllInterfaces' file='python'>
+ <info>returns list of all interfaces</info>
+ <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
+ <arg name='flags' type='unsigned int' info='optional flags'/>
+ <return type='interface *' info='the list of interfaces or None in case of error'/>
+ </function>
<function name='virConnectBaselineCPU' file='python'>
<info>Computes the most feature-rich CPU which is compatible with all given host CPUs.</info>
<return type='char *' info='XML description of the computed CPU or NULL on error.'/>
diff --git a/libvirt-override-virConnect.py b/libvirt-override-virConnect.py
index 85db5fe..ffa1a3c 100644
--- a/libvirt-override-virConnect.py
+++ b/libvirt-override-virConnect.py
@@ -230,3 +230,15 @@
retlist.append(virNetwork(self, _obj=netptr))
return retlist
+
+ def listAllInterfaces(self, flags):
+ """Returns a list of interface objects"""
+ ret = libvirtmod.virConnectListAllInterfaces(self._o, flags)
+ if ret is None:
+ raise libvirtError("virConnectListAllInterfaces() failed", conn=self)
+
+ retlist = list()
+ for ifaceptr in ret:
+ retlist.append(virInterface(self, _obj=ifaceptr))
+
+ return retlist
diff --git a/libvirt-override.c b/libvirt-override.c
index 485ed28..d07e7cb 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -3828,6 +3828,53 @@ libvirt_virConnectListDefinedInterfaces(PyObject *self ATTRIBUTE_UNUSED,
static PyObject *
+libvirt_virConnectListAllInterfaces(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args)
+{
+ PyObject *pyobj_conn;
+ PyObject *py_retval = NULL;
+ PyObject *tmp = NULL;
+ virConnectPtr conn;
+ virInterfacePtr *ifaces = NULL;
+ int c_retval = 0;
+ int i;
+ unsigned int flags;
+
+ if (!PyArg_ParseTuple(args, (char *)"Oi:virConnectListAllInterfaces",
+ &pyobj_conn, &flags))
+ return NULL;
+ conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ c_retval = virConnectListAllInterfaces(conn, &ifaces, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+ if (c_retval < 0)
+ return VIR_PY_NONE;
+
+ if (!(py_retval = PyList_New(c_retval)))
+ goto cleanup;
+
+ for (i = 0; i < c_retval; i++) {
+ if (!(tmp = libvirt_virInterfacePtrWrap(ifaces[i])) ||
+ PyList_SetItem(py_retval, i, tmp) < 0) {
+ Py_XDECREF(tmp);
+ Py_DECREF(py_retval);
+ py_retval = NULL;
+ goto cleanup;
+ }
+ /* python steals the pointer */
+ ifaces[i] = NULL;
+ }
+
+cleanup:
+ for (i = 0; i < c_retval; i++)
+ if (ifaces[i])
+ virInterfaceFree(ifaces[i]);
+ VIR_FREE(ifaces);
+ return py_retval;
+}
+
+static PyObject *
libvirt_virConnectBaselineCPU(PyObject *self ATTRIBUTE_UNUSED,
PyObject *args) {
PyObject *pyobj_conn;
@@ -6053,6 +6100,7 @@ static PyMethodDef libvirtMethods[] = {
{(char *) "virConnectListNWFilters", libvirt_virConnectListNWFilters, METH_VARARGS, NULL},
{(char *) "virConnectListInterfaces", libvirt_virConnectListInterfaces, METH_VARARGS, NULL},
{(char *) "virConnectListDefinedInterfaces", libvirt_virConnectListDefinedInterfaces, METH_VARARGS, NULL},
+ {(char *) "virConnectListAllInterfaces", libvirt_virConnectListAllInterfaces, METH_VARARGS, NULL},
{(char *) "virConnectBaselineCPU", libvirt_virConnectBaselineCPU, METH_VARARGS, NULL},
{(char *) "virDomainGetJobInfo", libvirt_virDomainGetJobInfo, METH_VARARGS, NULL},
{(char *) "virDomainSnapshotListNames", libvirt_virDomainSnapshotListNames, METH_VARARGS, NULL},