Rather than inline code secret lookup for rbd/iscsi, use the common function.
Signed-off-by: John Ferlan <jferlan@redhat.com>
libvirt_driver_storage_impl_la_CFLAGS = \
-I$(srcdir)/access \
-I$(srcdir)/conf \
+ -I$(srcdir)/secret \
$(AM_CFLAGS)
libvirt_driver_storage_impl_la_LDFLAGS = $(AM_LDFLAGS)
libvirt_driver_storage_impl_la_LIBADD =
/*
* storage_backend_iscsi.c: storage backend for iSCSI handling
*
- * Copyright (C) 2007-2014 Red Hat, Inc.
+ * Copyright (C) 2007-2016 Red Hat, Inc.
* Copyright (C) 2007-2008 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
#include "virobject.h"
#include "virstring.h"
#include "viruuid.h"
+#include "secret_util.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
virConnectPtr conn,
virStoragePoolSourcePtr source)
{
- virSecretPtr secret = NULL;
unsigned char *secret_value = NULL;
+ size_t secret_size;
virStorageAuthDefPtr authdef = source->auth;
int ret = -1;
- char uuidStr[VIR_UUID_STRING_BUFLEN];
if (!authdef || authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE)
return 0;
return -1;
}
- if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID)
- secret = virSecretLookupByUUID(conn, authdef->secret.uuid);
- else
- secret = virSecretLookupByUsage(conn, VIR_SECRET_USAGE_TYPE_ISCSI,
- authdef->secret.usage);
-
- if (secret) {
- size_t secret_size;
- secret_value =
- conn->secretDriver->secretGetValue(secret, &secret_size, 0,
- VIR_SECRET_GET_VALUE_INTERNAL_CALL);
- if (!secret_value) {
- if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID) {
- virUUIDFormat(authdef->secret.uuid, uuidStr);
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("could not get the value of the secret "
- "for username %s using uuid '%s'"),
- authdef->username, uuidStr);
- } else {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("could not get the value of the secret "
- "for username %s using usage value '%s'"),
- authdef->username, authdef->secret.usage);
- }
- goto cleanup;
- }
- } else {
- if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID) {
- virUUIDFormat(authdef->secret.uuid, uuidStr);
- virReportError(VIR_ERR_NO_SECRET,
- _("no secret matches uuid '%s'"),
- uuidStr);
- } else {
- virReportError(VIR_ERR_NO_SECRET,
- _("no secret matches usage value '%s'"),
- authdef->secret.usage);
- }
+ if (virSecretGetSecretString(conn, authdef, VIR_SECRET_USAGE_TYPE_ISCSI,
+ &secret_value, &secret_size) < 0)
goto cleanup;
- }
if (virISCSINodeUpdate(portal,
source->devices[0].path,
ret = 0;
cleanup:
- virObjectUnref(secret);
- VIR_FREE(secret_value);
+ VIR_DISPOSE_N(secret_value, secret_size);
return ret;
}
#include "virrandom.h"
#include "rados/librados.h"
#include "rbd/librbd.h"
+#include "secret_util.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
size_t secret_value_size = 0;
char *rados_key = NULL;
virBuffer mon_host = VIR_BUFFER_INITIALIZER;
- virSecretPtr secret = NULL;
- char secretUuid[VIR_UUID_STRING_BUFLEN];
size_t i;
char *mon_buff = NULL;
const char *client_mount_timeout = "30";
return -1;
}
- if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID) {
- virUUIDFormat(authdef->secret.uuid, secretUuid);
- VIR_DEBUG("Looking up secret by UUID: %s", secretUuid);
- secret = virSecretLookupByUUIDString(conn, secretUuid);
- } else if (authdef->secret.usage != NULL) {
- VIR_DEBUG("Looking up secret by usage: %s",
- authdef->secret.usage);
- secret = virSecretLookupByUsage(conn, VIR_SECRET_USAGE_TYPE_CEPH,
- authdef->secret.usage);
- }
-
- if (secret == NULL) {
- if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID) {
- virReportError(VIR_ERR_NO_SECRET,
- _("no secret matches uuid '%s'"),
- secretUuid);
- } else {
- virReportError(VIR_ERR_NO_SECRET,
- _("no secret matches usage value '%s'"),
- authdef->secret.usage);
- }
+ if (virSecretGetSecretString(conn, authdef, VIR_SECRET_USAGE_TYPE_CEPH,
+ &secret_value, &secret_value_size) < 0)
goto cleanup;
- }
-
- secret_value = conn->secretDriver->secretGetValue(secret,
- &secret_value_size, 0,
- VIR_SECRET_GET_VALUE_INTERNAL_CALL);
-
- if (!secret_value) {
- if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("could not get the value of the secret "
- "for username '%s' using uuid '%s'"),
- authdef->username, secretUuid);
- } else {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("could not get the value of the secret "
- "for username '%s' using usage value '%s'"),
- authdef->username, authdef->secret.usage);
- }
- goto cleanup;
- }
if (!(rados_key = virStringEncodeBase64(secret_value, secret_value_size)))
goto cleanup;
VIR_DISPOSE_N(secret_value, secret_value_size);
VIR_DISPOSE_STRING(rados_key);
- virObjectUnref(secret);
-
virBufferFreeAndReset(&mon_host);
VIR_FREE(mon_buff);
return ret;