* -1 and error message if fail to add secret information
*/
static int
-qemuBuildGeneralSecinfoURI(virURI *uri,
+qemuBuildGeneralSecinfoURI(virURI *uri G_GNUC_UNUSED,
qemuDomainSecretInfo *secinfo)
{
if (!secinfo)
return 0;
switch ((qemuDomainSecretInfoType) secinfo->type) {
- case VIR_DOMAIN_SECRET_INFO_TYPE_PLAIN:
- if (secinfo->s.plain.secret) {
- if (!virStringBufferIsPrintable(secinfo->s.plain.secret,
- secinfo->s.plain.secretlen)) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("found non printable characters in secret"));
- return -1;
- }
- uri->user = g_strdup_printf("%s:%s", secinfo->s.plain.username,
- secinfo->s.plain.secret);
- } else {
- uri->user = g_strdup(secinfo->s.plain.username);
- }
- break;
-
case VIR_DOMAIN_SECRET_INFO_TYPE_AES:
case VIR_DOMAIN_SECRET_INFO_TYPE_LAST:
return -1;
qemuBuildRBDSecinfoURI(virBuffer *buf,
qemuDomainSecretInfo *secinfo)
{
- g_autofree char *base64secret = NULL;
-
if (!secinfo) {
virBufferAddLit(buf, ":auth_supported=none");
return 0;
}
switch ((qemuDomainSecretInfoType) secinfo->type) {
- case VIR_DOMAIN_SECRET_INFO_TYPE_PLAIN:
- base64secret = g_base64_encode(secinfo->s.plain.secret,
- secinfo->s.plain.secretlen);
- virBufferEscape(buf, '\\', ":", ":id=%s", secinfo->s.plain.username);
- virBufferEscape(buf, '\\', ":",
- ":key=%s:auth_supported=cephx\\;none",
- base64secret);
- virSecureEraseString(base64secret);
- break;
-
case VIR_DOMAIN_SECRET_INFO_TYPE_AES:
virBufferEscape(buf, '\\', ":", ":id=%s:auth_supported=cephx\\;none",
secinfo->s.aes.username);
}
-static void
-qemuDomainSecretPlainClear(struct _qemuDomainSecretPlain *secret)
-{
- VIR_FREE(secret->username);
- virSecureErase(secret->secret, secret->secretlen);
- g_clear_pointer(&secret->secret, g_free);
-}
-
-
static void
qemuDomainSecretAESClear(struct _qemuDomainSecretAES *secret,
bool keepAlias)
return;
switch ((qemuDomainSecretInfoType) secinfo->type) {
- case VIR_DOMAIN_SECRET_INFO_TYPE_PLAIN:
- qemuDomainSecretPlainClear(&secinfo->s.plain);
- break;
-
case VIR_DOMAIN_SECRET_INFO_TYPE_AES:
qemuDomainSecretAESClear(&secinfo->s.aes, keepAlias);
break;
/* Type of domain secret */
typedef enum {
- VIR_DOMAIN_SECRET_INFO_TYPE_PLAIN = 0,
VIR_DOMAIN_SECRET_INFO_TYPE_AES, /* utilize GNUTLS_CIPHER_AES_256_CBC */
VIR_DOMAIN_SECRET_INFO_TYPE_LAST
} qemuDomainSecretInfoType;
-typedef struct _qemuDomainSecretPlain qemuDomainSecretPlain;
-struct _qemuDomainSecretPlain {
- char *username;
- uint8_t *secret;
- size_t secretlen;
-};
-
#define QEMU_DOMAIN_AES_IV_LEN 16 /* 16 bytes for 128 bit random */
/* initialization vector */
typedef struct _qemuDomainSecretAES qemuDomainSecretAES;
struct _qemuDomainSecretInfo {
qemuDomainSecretInfoType type;
union {
- qemuDomainSecretPlain plain;
qemuDomainSecretAES aes;
} s;
};