+Fri Sep 21 15:06:00 EST 2007 Daniel P. Berrange <berrange@redhat.com>
+
+ * src/qemu_driver.c: Use libxml for parsing & checking URIs
+
Thu Sep 20 19:37:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
* src/bridge.c, src/qemu_driver.c, configure.in: Try to detect
#include <pwd.h>
#include <stdio.h>
#include <sys/wait.h>
+#include <libxml/uri.h>
#include <libvirt/virterror.h>
static virDrvOpenStatus qemudOpen(virConnectPtr conn,
- const char *name,
- int flags ATTRIBUTE_UNUSED) {
+ const char *name,
+ int flags ATTRIBUTE_UNUSED) {
+ xmlURIPtr uri = NULL;
uid_t uid = getuid();
if (qemu_driver == NULL)
return VIR_DRV_OPEN_DECLINED;
+ uri = xmlParseURI(name);
+ if (uri == NULL || uri->scheme == NULL || uri->path == NULL)
+ goto decline;
+
+ if (STRNEQ (uri->scheme, "qemu"))
+ goto decline;
+
if (uid != 0) {
- if (STRNEQ (name, "qemu:///session"))
- return VIR_DRV_OPEN_DECLINED;
+ if (STRNEQ (uri->path, "/session"))
+ goto decline;
} else { /* root */
- if (STRNEQ (name, "qemu:///system") &&
- STRNEQ (name, "qemu:///session"))
- return VIR_DRV_OPEN_DECLINED;
+ if (STRNEQ (uri->path, "/system") &&
+ STRNEQ (uri->path, "/session"))
+ goto decline;
}
conn->privateData = qemu_driver;
+ xmlFreeURI(uri);
return VIR_DRV_OPEN_SUCCESS;
+
+ decline:
+ if (uri != NULL)
+ xmlFreeURI(uri);
+ return VIR_DRV_OPEN_DECLINED;
}
static int qemudClose(virConnectPtr conn) {