]> xenbits.xensource.com Git - libvirt.git/commitdiff
esx: use virCryptoHashBuf
authorJán Tomko <jtomko@redhat.com>
Fri, 11 May 2018 14:49:32 +0000 (16:49 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 14 May 2018 12:05:21 +0000 (14:05 +0200)
Instead of using md5_buffer from gnulib directly.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
src/esx/esx_network_driver.c
src/esx/esx_storage_backend_iscsi.c
src/esx/esx_storage_backend_vmfs.c

index b19c06a4cbf87342798eb6955025be3e6b0f1413..7386efb0f543e4d7da85a1f0af67f44bcc5c05cc 100644 (file)
@@ -33,6 +33,7 @@
 #include "esx_vi.h"
 #include "esx_vi_methods.h"
 #include "esx_util.h"
+#include "vircrypto.h"
 #include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_ESX
@@ -152,7 +153,8 @@ esxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
 
     for (hostVirtualSwitch = hostVirtualSwitchList; hostVirtualSwitch;
          hostVirtualSwitch = hostVirtualSwitch->_next) {
-        md5_buffer(hostVirtualSwitch->key, strlen(hostVirtualSwitch->key), md5);
+        if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, hostVirtualSwitch->key, md5) < 0)
+            goto cleanup;
 
         if (memcmp(uuid, md5, VIR_UUID_BUFLEN) == 0)
             break;
@@ -201,7 +203,8 @@ esxNetworkLookupByName(virConnectPtr conn, const char *name)
      * The MD5 sum of the key can be used as UUID, assuming MD5 is considered
      * to be collision-free enough for this use case.
      */
-    md5_buffer(hostVirtualSwitch->key, strlen(hostVirtualSwitch->key), md5);
+    if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, hostVirtualSwitch->key, md5) < 0)
+        return NULL;
 
     network = virGetNetwork(conn, hostVirtualSwitch->name, md5);
 
@@ -464,7 +467,8 @@ esxNetworkDefineXML(virConnectPtr conn, const char *xml)
         goto cleanup;
     }
 
-    md5_buffer(hostVirtualSwitch->key, strlen(hostVirtualSwitch->key), md5);
+    if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, hostVirtualSwitch->key, md5) < 0)
+        goto cleanup;
 
     network = virGetNetwork(conn, hostVirtualSwitch->name, md5);
 
@@ -655,7 +659,8 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags)
         goto cleanup;
     }
 
-    md5_buffer(hostVirtualSwitch->key, strlen(hostVirtualSwitch->key), def->uuid);
+    if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, hostVirtualSwitch->key, def->uuid) < 0)
+        goto cleanup;
 
     if (VIR_STRDUP(def->name, hostVirtualSwitch->name) < 0)
         goto cleanup;
index b106c517e8d5deb06ae70979d0c4c42e6223f634..42b52214d11afa65fd9eb5a7e783328be827d544 100644 (file)
@@ -37,6 +37,7 @@
 #include "esx_vi.h"
 #include "esx_vi_methods.h"
 #include "esx_util.h"
+#include "vircrypto.h"
 #include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_ESX
@@ -180,7 +181,8 @@ esxStoragePoolLookupByName(virConnectPtr conn,
      * but iScsiName (or widely known as IQN) is unique across the multiple
      * hosts, using it to compute key
      */
-    md5_buffer(target->iScsiName, strlen(target->iScsiName), md5);
+    if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, target->iScsiName, md5) < 0)
+        goto cleanup;
 
     pool = virGetStoragePool(conn, name, md5, &esxStorageBackendISCSI, NULL);
 
@@ -218,7 +220,8 @@ esxStoragePoolLookupByUUID(virConnectPtr conn,
 
     for (target = hostInternetScsiHba->configuredStaticTarget;
          target; target = target->_next) {
-        md5_buffer(target->iScsiName, strlen(target->iScsiName), md5);
+        if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, target->iScsiName, md5) < 0)
+            goto cleanup;
 
         if (memcmp(uuid, md5, VIR_UUID_BUFLEN) == 0)
             break;
@@ -456,7 +459,8 @@ esxStorageVolLookupByName(virStoragePoolPtr pool,
              * compute MD5 hash to transform it to an acceptable
              * libvirt format
              */
-            md5_buffer(scsiLun->uuid, strlen(scsiLun->uuid), md5);
+            if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, scsiLun->uuid, md5) < 0)
+                goto cleanup;
             virUUIDFormat(md5, uuid_string);
 
             /*
@@ -507,7 +511,8 @@ esxStorageVolLookupByPath(virConnectPtr conn, const char *path)
                 goto cleanup;
             }
 
-            md5_buffer(scsiLun->uuid, strlen(scsiLun->uuid), md5);
+            if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, scsiLun->uuid, md5) < 0)
+                goto cleanup;
             virUUIDFormat(md5, uuid_string);
 
             volume = virGetStorageVol(conn, poolName, path, uuid_string,
@@ -549,7 +554,8 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
         memset(uuid_string, '\0', sizeof(uuid_string));
         memset(md5, '\0', sizeof(md5));
 
-        md5_buffer(scsiLun->uuid, strlen(scsiLun->uuid), md5);
+        if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, scsiLun->uuid, md5) < 0)
+            goto cleanup;
         virUUIDFormat(md5, uuid_string);
 
         if (STREQ(key, uuid_string)) {
@@ -697,7 +703,8 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume,
 
     def.name = volume->name;
 
-    md5_buffer(scsiLun->uuid, strlen(scsiLun->uuid), md5);
+    if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, scsiLun->uuid,  md5) < 0)
+        goto cleanup;
 
     virUUIDFormat(md5, uuid_string);
 
index 940e5d1f0685d770213f98b91f030a19b5328779..bf5093cf456e7cd959dbc18847301734df620c9e 100644 (file)
@@ -41,6 +41,7 @@
 #include "esx_vi.h"
 #include "esx_vi_methods.h"
 #include "esx_util.h"
+#include "vircrypto.h"
 #include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_ESX
@@ -236,8 +237,8 @@ esxStoragePoolLookupByName(virConnectPtr conn,
         goto cleanup;
     }
 
-    md5_buffer(hostMount->mountInfo->path,
-               strlen(hostMount->mountInfo->path), md5);
+    if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, hostMount->mountInfo->path, md5) < 0)
+        goto cleanup;
 
     pool = virGetStoragePool(conn, name, md5, &esxStorageBackendVMFS, NULL);
 
@@ -289,8 +290,8 @@ esxStoragePoolLookupByUUID(virConnectPtr conn,
             goto cleanup;
         }
 
-        md5_buffer(hostMount->mountInfo->path,
-                   strlen(hostMount->mountInfo->path), md5);
+        if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, hostMount->mountInfo->path, md5) < 0)
+            goto cleanup;
 
         if (memcmp(uuid, md5, VIR_UUID_BUFLEN) == 0)
             break;