esx: use virCryptoHashBuf

Instead of using md5_buffer from gnulib directly.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Ján Tomko 2018-05-11 16:49:32 +02:00
parent 0eeedd61a9
commit 3ec34fd7a3
3 changed files with 27 additions and 14 deletions

View 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;

View 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);

View 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;