#include "lock_driver.h"
#include "virconf.h"
#include "viralloc.h"
+#include "vircrypto.h"
#include "virlog.h"
#include "viruuid.h"
#include "virfile.h"
#include "rpc/virnetclient.h"
#include "lock_protocol.h"
#include "configmake.h"
-#include "sha256.h"
#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_LOCKING
}
-static const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
-
-static char *virLockManagerLockDaemonDiskLeaseName(const char *path)
-{
- unsigned char buf[SHA256_DIGEST_SIZE];
- char *ret;
- size_t i;
-
- if (!(sha256_buffer(path, strlen(path), buf))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Unable to compute sha256 checksum"));
- return NULL;
- }
-
- if (VIR_ALLOC_N(ret, (SHA256_DIGEST_SIZE * 2) + 1) < 0)
- return NULL;
-
- for (i = 0; i < SHA256_DIGEST_SIZE; i++) {
- ret[i*2] = hex[(buf[i] >> 4) & 0xf];
- ret[(i*2)+1] = hex[buf[i] & 0xf];
- }
- ret[(SHA256_DIGEST_SIZE * 2) + 1] = '\0';
-
- return ret;
-}
-
-
static int virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
unsigned int type,
const char *name,
if (driver->fileLockSpaceDir) {
if (VIR_STRDUP(newLockspace, driver->fileLockSpaceDir) < 0)
goto error;
- if (!(newName = virLockManagerLockDaemonDiskLeaseName(name)))
+ if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, name, &newName) < 0)
goto error;
autoCreate = true;
VIR_DEBUG("Using indirect lease %s for %s", newName, name);
#include "virlog.h"
#include "virerror.h"
#include "viralloc.h"
+#include "vircrypto.h"
#include "virfile.h"
-#include "md5.h"
#include "virconf.h"
#include "virstring.h"
}
-static const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
-
-static int virLockManagerSanlockDiskLeaseName(const char *path,
- char *str,
- size_t strbuflen)
-{
- unsigned char buf[MD5_DIGEST_SIZE];
- size_t i;
-
- if (strbuflen < ((MD5_DIGEST_SIZE * 2) + 1)) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("String length too small to store md5 checksum"));
- return -1;
- }
-
- if (!(md5_buffer(path, strlen(path), buf))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Unable to compute md5 checksum"));
- return -1;
- }
-
- for (i = 0; i < MD5_DIGEST_SIZE; i++) {
- str[i*2] = hex[(buf[i] >> 4) & 0xf];
- str[(i*2)+1] = hex[buf[i] & 0xf];
- }
- str[(MD5_DIGEST_SIZE*2)+1] = '\0';
- return 0;
-}
-
static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
const char *name,
size_t nparams,
int ret = -1;
struct sanlk_resource *res = NULL;
char *path = NULL;
+ char *hash = NULL;
if (nparams) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
res->flags = shared ? SANLK_RES_SHARED : 0;
res->num_disks = 1;
- if (virLockManagerSanlockDiskLeaseName(name, res->name, SANLK_NAME_LEN) < 0)
+ if (virCryptoHashString(VIR_CRYPTO_HASH_MD5, name, &hash) < 0)
+ goto cleanup;
+ if (!virStrcpy(res->name, hash, SANLK_NAME_LEN)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("MD5 hash '%s' unexpectedly larger than %d characters"),
+ hash, (SANLK_NAME_LEN - 1));
goto cleanup;
+ }
if (virAsprintf(&path, "%s/%s",
driver->autoDiskLeasePath, res->name) < 0)
if (ret == -1)
VIR_FREE(res);
VIR_FREE(path);
+ VIR_FREE(hash);
return ret;
}