[libvirt] [PATCH v2 01/11] src/driver.c: add virConnectValidateURIPath()

Daniel Henrique Barboza danielhb413 at gmail.com
Mon Sep 23 20:44:13 UTC 2019


The code to validate the URI path is repeated across several
files. This patch creates a common validation code to be
used across all of them.

Suggested-by: Cole Robinson <crobinso at redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
---
 src/driver.c             | 24 ++++++++++++++++++++++++
 src/driver.h             |  4 ++++
 src/libvirt_private.syms |  1 +
 3 files changed, 29 insertions(+)

diff --git a/src/driver.c b/src/driver.c
index 5e8f68f6df..e627b0c1d7 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -269,3 +269,27 @@ virSetConnectStorage(virConnectPtr conn)
     VIR_DEBUG("Override storage connection with %p", conn);
     return virThreadLocalSet(&connectStorage, conn);
 }
+
+bool
+virConnectValidateURIPath(const char *uriPath,
+                          const char *entityName,
+                          bool privileged)
+{
+    if (privileged) {
+        if (STRNEQ(uriPath, "/system")) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("unexpected %s URI path '%s', try %s:///system"),
+                           entityName, uriPath, entityName);
+            return false;
+        }
+    } else {
+        if (STRNEQ(uriPath, "/session")) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("unexpected %s URI path '%s', try %s:///session"),
+                           entityName, uriPath, entityName);
+            return false;
+        }
+    }
+
+    return true;
+}
diff --git a/src/driver.h b/src/driver.h
index f7d667a03c..68c0004d86 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -127,3 +127,7 @@ int virSetConnectNWFilter(virConnectPtr conn);
 int virSetConnectNodeDev(virConnectPtr conn);
 int virSetConnectSecret(virConnectPtr conn);
 int virSetConnectStorage(virConnectPtr conn);
+
+bool virConnectValidateURIPath(const char *uriPath,
+                               const char *entityName,
+                               bool privileged);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 39812227aa..eb9c5c22ee 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1343,6 +1343,7 @@ virStreamClass;
 
 
 # driver.h
+virConnectValidateURIPath;
 virGetConnectInterface;
 virGetConnectNetwork;
 virGetConnectNodeDev;
-- 
2.21.0




More information about the libvir-list mailing list