mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
virNetLibsshSessionAuthAddPrivKeyAuth: Refactor cleanup
Shuffle the code around to remove the need for temporary variables and labels for cleaning them. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
34e522418f
commit
5761f8ab54
@ -1013,10 +1013,7 @@ virNetLibsshSessionAuthAddPrivKeyAuth(virNetLibsshSessionPtr sess,
|
|||||||
const char *keyfile,
|
const char *keyfile,
|
||||||
const char *password)
|
const char *password)
|
||||||
{
|
{
|
||||||
int ret;
|
|
||||||
virNetLibsshAuthMethodPtr auth;
|
virNetLibsshAuthMethodPtr auth;
|
||||||
VIR_AUTODISPOSE_STR pass = NULL;
|
|
||||||
char *file = NULL;
|
|
||||||
|
|
||||||
if (!keyfile) {
|
if (!keyfile) {
|
||||||
virReportError(VIR_ERR_LIBSSH, "%s",
|
virReportError(VIR_ERR_LIBSSH, "%s",
|
||||||
@ -1026,28 +1023,18 @@ virNetLibsshSessionAuthAddPrivKeyAuth(virNetLibsshSessionPtr sess,
|
|||||||
|
|
||||||
virObjectLock(sess);
|
virObjectLock(sess);
|
||||||
|
|
||||||
file = g_strdup(keyfile);
|
|
||||||
pass = g_strdup(password);
|
|
||||||
|
|
||||||
if (!(auth = virNetLibsshSessionAuthMethodNew(sess))) {
|
if (!(auth = virNetLibsshSessionAuthMethodNew(sess))) {
|
||||||
ret = -1;
|
virObjectUnlock(sess);
|
||||||
goto error;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auth->password = g_steal_pointer(&pass);
|
auth->password = g_strdup(password);
|
||||||
auth->filename = file;
|
auth->filename = g_strdup(keyfile);
|
||||||
auth->method = VIR_NET_LIBSSH_AUTH_PRIVKEY;
|
auth->method = VIR_NET_LIBSSH_AUTH_PRIVKEY;
|
||||||
auth->ssh_flags = SSH_AUTH_METHOD_PUBLICKEY;
|
auth->ssh_flags = SSH_AUTH_METHOD_PUBLICKEY;
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virObjectUnlock(sess);
|
virObjectUnlock(sess);
|
||||||
return ret;
|
return 0;
|
||||||
|
|
||||||
error:
|
|
||||||
VIR_FREE(file);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
Reference in New Issue
Block a user