mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
virStorageBackendISCSISetAuth: Refactor cleanup
Automatically free 'conn' and remove the 'cleanup' section and 'ret' variable. 'datatypes.h' contains the declaration of the autoptr cleanup function for virConnect. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
880cd081de
commit
fbb323fe61
@ -26,6 +26,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include "datatypes.h"
|
||||||
#include "driver.h"
|
#include "driver.h"
|
||||||
#include "storage_backend_iscsi.h"
|
#include "storage_backend_iscsi.h"
|
||||||
#include "viralloc.h"
|
#include "viralloc.h"
|
||||||
@ -255,8 +256,8 @@ virStorageBackendISCSISetAuth(const char *portal,
|
|||||||
size_t secret_size;
|
size_t secret_size;
|
||||||
g_autofree char *secret_str = NULL;
|
g_autofree char *secret_str = NULL;
|
||||||
virStorageAuthDef *authdef = source->auth;
|
virStorageAuthDef *authdef = source->auth;
|
||||||
int ret = -1;
|
int ret = 0;
|
||||||
virConnectPtr conn = NULL;
|
g_autoptr(virConnect) conn = NULL;
|
||||||
VIR_IDENTITY_AUTORESTORE virIdentity *oldident = NULL;
|
VIR_IDENTITY_AUTORESTORE virIdentity *oldident = NULL;
|
||||||
|
|
||||||
if (!authdef || authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE)
|
if (!authdef || authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE)
|
||||||
@ -280,7 +281,7 @@ virStorageBackendISCSISetAuth(const char *portal,
|
|||||||
if (virSecretGetSecretString(conn, &authdef->seclookupdef,
|
if (virSecretGetSecretString(conn, &authdef->seclookupdef,
|
||||||
VIR_SECRET_USAGE_TYPE_ISCSI,
|
VIR_SECRET_USAGE_TYPE_ISCSI,
|
||||||
&secret_value, &secret_size) < 0)
|
&secret_value, &secret_size) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
secret_str = g_new0(char, secret_size + 1);
|
secret_str = g_new0(char, secret_size + 1);
|
||||||
memcpy(secret_str, secret_value, secret_size);
|
memcpy(secret_str, secret_value, secret_size);
|
||||||
@ -299,13 +300,9 @@ virStorageBackendISCSISetAuth(const char *portal,
|
|||||||
source->devices[0].path,
|
source->devices[0].path,
|
||||||
"node.session.auth.password",
|
"node.session.auth.password",
|
||||||
secret_str) < 0)
|
secret_str) < 0)
|
||||||
goto cleanup;
|
ret = -1;
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virSecureErase(secret_str, secret_size);
|
virSecureErase(secret_str, secret_size);
|
||||||
virObjectUnref(conn);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user