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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux