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(a)redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/driver.c | 26 ++++++++++++++++++++++++++
src/driver.h | 4 ++++
src/libvirt_private.syms | 1 +
3 files changed, 31 insertions(+)
diff --git a/src/driver.c b/src/driver.c
index 5e8f68f6df..6b75622689 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -269,3 +269,29 @@ 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 287e63bffa..3668a531a4 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