1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-11 09:17:52 +03:00

virStorageBackendISCSIDirectSetAuth: Refactor cleanup

Use automatic pointer for 'conn' and remove the 'cleanup' label and
'ret' variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Peter Krempa 2022-12-08 11:13:53 +01:00
parent edd644e7a8
commit 2811fdaf3e

View File

@ -91,8 +91,7 @@ virStorageBackendISCSIDirectSetAuth(struct iscsi_context *iscsi,
size_t secret_size;
g_autofree char *secret_str = NULL;
virStorageAuthDef *authdef = source->auth;
int ret = -1;
virConnectPtr conn = NULL;
g_autoptr(virConnect) conn = NULL;
VIR_IDENTITY_AUTORESTORE virIdentity *oldident = NULL;
if (!authdef || authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE)
@ -104,19 +103,19 @@ virStorageBackendISCSIDirectSetAuth(struct iscsi_context *iscsi,
if (authdef->authType != VIR_STORAGE_AUTH_TYPE_CHAP) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("iscsi-direct pool only supports 'chap' auth type"));
return ret;
return -1;
}
if (!(oldident = virIdentityElevateCurrent()))
return -1;
if (!(conn = virGetConnectSecret()))
return ret;
return -1;
if (virSecretGetSecretString(conn, &authdef->seclookupdef,
VIR_SECRET_USAGE_TYPE_ISCSI,
&secret_value, &secret_size) < 0)
goto cleanup;
return -1;
secret_str = g_new0(char, secret_size + 1);
memcpy(secret_str, secret_value, secret_size);
@ -125,17 +124,15 @@ virStorageBackendISCSIDirectSetAuth(struct iscsi_context *iscsi,
if (iscsi_set_initiator_username_pwd(iscsi,
authdef->username, secret_str) < 0) {
virSecureErase(secret_str, secret_size);
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to set credential: %s"),
iscsi_get_error(iscsi));
goto cleanup;
return -1;
}
ret = 0;
cleanup:
virSecureErase(secret_str, secret_size);
virObjectUnref(conn);
return ret;
return 0;
}
static int