]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
esx: Escape password for XML
authorMatthias Bolte <matthias.bolte@googlemail.com>
Thu, 3 Mar 2011 21:11:24 +0000 (22:11 +0100)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Thu, 3 Mar 2011 21:18:09 +0000 (22:18 +0100)
Passwords are allowed to contain <, >, &, ', " characters.
Those need to be replaced by the corresponding entities.

Reported by Hereward Cooper.

src/esx/esx_driver.c
src/esx/esx_util.c
src/esx/esx_util.h

index 116ad0f51f20978c7cd0dc6bfa20e5346ba4abd5..13374b75e4ba30b41e5de60434883f00a00d26e4 100644 (file)
@@ -626,6 +626,7 @@ esxConnectToHost(esxPrivate *priv, virConnectAuthPtr auth,
     int result = -1;
     char ipAddress[NI_MAXHOST] = "";
     char *username = NULL;
+    char *unescapedPassword = NULL;
     char *password = NULL;
     char *url = NULL;
     esxVI_String *propertyNameList = NULL;
@@ -657,13 +658,19 @@ esxConnectToHost(esxPrivate *priv, virConnectAuthPtr auth,
         }
     }
 
-    password = virRequestPassword(auth, username, hostname);
+    unescapedPassword = virRequestPassword(auth, username, hostname);
 
-    if (password == NULL) {
+    if (unescapedPassword == NULL) {
         ESX_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Password request failed"));
         goto cleanup;
     }
 
+    password = esxUtil_EscapeForXml(unescapedPassword);
+
+    if (password == NULL) {
+        goto cleanup;
+    }
+
     if (virAsprintf(&url, "%s://%s:%d/sdk", priv->transport, hostname,
                     port) < 0) {
         virReportOOMError();
@@ -727,8 +734,9 @@ esxConnectToHost(esxPrivate *priv, virConnectAuthPtr auth,
     result = 0;
 
   cleanup:
-    VIR_FREE(password);
     VIR_FREE(username);
+    VIR_FREE(unescapedPassword);
+    VIR_FREE(password);
     VIR_FREE(url);
     esxVI_String_Free(&propertyNameList);
     esxVI_ObjectContent_Free(&hostSystem);
@@ -748,6 +756,7 @@ esxConnectToVCenter(esxPrivate *priv, virConnectAuthPtr auth,
     int result = -1;
     char ipAddress[NI_MAXHOST] = "";
     char *username = NULL;
+    char *unescapedPassword = NULL;
     char *password = NULL;
     char *url = NULL;
 
@@ -779,13 +788,19 @@ esxConnectToVCenter(esxPrivate *priv, virConnectAuthPtr auth,
         }
     }
 
-    password = virRequestPassword(auth, username, hostname);
+    unescapedPassword = virRequestPassword(auth, username, hostname);
 
-    if (password == NULL) {
+    if (unescapedPassword == NULL) {
         ESX_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Password request failed"));
         goto cleanup;
     }
 
+    password = esxUtil_EscapeForXml(unescapedPassword);
+
+    if (password == NULL) {
+        goto cleanup;
+    }
+
     if (virAsprintf(&url, "%s://%s:%d/sdk", priv->transport, hostname,
                     port) < 0) {
         virReportOOMError();
@@ -822,8 +837,9 @@ esxConnectToVCenter(esxPrivate *priv, virConnectAuthPtr auth,
     result = 0;
 
   cleanup:
-    VIR_FREE(password);
     VIR_FREE(username);
+    VIR_FREE(unescapedPassword);
+    VIR_FREE(password);
     VIR_FREE(url);
 
     return result;
index 2603957dd7cf723236b2d1232c8d10483bbb6d65..9ef947c747901dccd048fa581360a7a94467b728 100644 (file)
@@ -552,3 +552,22 @@ esxUtil_EscapeDatastoreItem(const char *string)
 
     return escaped2;
 }
+
+
+
+char *
+esxUtil_EscapeForXml(const char *string)
+{
+    virBuffer buffer = VIR_BUFFER_INITIALIZER;
+
+    virBufferEscapeString(&buffer, "%s", string);
+
+    if (virBufferError(&buffer)) {
+        virReportOOMError();
+        virBufferFreeAndReset(&buffer);
+
+        return NULL;
+    }
+
+    return virBufferContentAndReset(&buffer);
+}
index d00e28aa2bc42f0a865107ffe0d21711dddb3748..39fdb6db415f4e8ff07a435c299988cd85088912 100644 (file)
@@ -62,4 +62,6 @@ void esxUtil_ReplaceSpecialWindowsPathChars(char *string);
 
 char *esxUtil_EscapeDatastoreItem(const char *string);
 
+char *esxUtil_EscapeForXml(const char *string);
+
 #endif /* __ESX_UTIL_H__ */