提交 c3e1275b 编写于 作者: P Peter Krempa

rpc: Refactor cleanup paths in virNetLibsshAuthenticatePassword

Now that the memory disposal is handled automatically we can simplify
the cleanup paths. In this case it's not as simple as sometimes the
value of the called function is returned.

While at it fix the initialization value of the returned variable.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 99582f24
...@@ -606,25 +606,22 @@ virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess, ...@@ -606,25 +606,22 @@ virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess,
virNetLibsshAuthMethodPtr priv) virNetLibsshAuthMethodPtr priv)
{ {
const char *errmsg; const char *errmsg;
int ret = -1; int rc = SSH_AUTH_ERROR;
VIR_DEBUG("sess=%p", sess); VIR_DEBUG("sess=%p", sess);
if (priv->password) { if (priv->password) {
/* tunelled password authentication */ /* tunelled password authentication */
if ((ret = ssh_userauth_password(sess->session, NULL, if ((rc = ssh_userauth_password(sess->session, NULL,
priv->password)) == 0) { priv->password)) == 0)
ret = SSH_AUTH_SUCCESS; return SSH_AUTH_SUCCESS;
goto cleanup;
}
} else { } else {
/* password authentication with interactive password request */ /* password authentication with interactive password request */
if (!sess->cred || !sess->cred->cb) { if (!sess->cred || !sess->cred->cb) {
virReportError(VIR_ERR_LIBSSH, "%s", virReportError(VIR_ERR_LIBSSH, "%s",
_("Can't perform authentication: " _("Can't perform authentication: "
"Authentication callback not provided")); "Authentication callback not provided"));
ret = SSH_AUTH_ERROR; return SSH_AUTH_ERROR;
goto cleanup;
} }
/* Try the authenticating the set amount of times. The server breaks the /* Try the authenticating the set amount of times. The server breaks the
...@@ -634,19 +631,15 @@ virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess, ...@@ -634,19 +631,15 @@ virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess,
if (!(password = virAuthGetPasswordPath(sess->authPath, sess->cred, if (!(password = virAuthGetPasswordPath(sess->authPath, sess->cred,
"ssh", sess->username, "ssh", sess->username,
sess->hostname))) { sess->hostname)))
ret = SSH_AUTH_ERROR; return SSH_AUTH_ERROR;
goto cleanup;
}
/* tunelled password authentication */ /* tunelled password authentication */
if ((ret = ssh_userauth_password(sess->session, NULL, if ((rc = ssh_userauth_password(sess->session, NULL,
password)) == 0) { password)) == 0)
ret = SSH_AUTH_SUCCESS; return SSH_AUTH_SUCCESS;
goto cleanup;
}
if (ret != SSH_AUTH_DENIED) if (rc != SSH_AUTH_DENIED)
break; break;
} }
} }
...@@ -655,9 +648,7 @@ virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess, ...@@ -655,9 +648,7 @@ virNetLibsshAuthenticatePassword(virNetLibsshSessionPtr sess,
errmsg = ssh_get_error(sess->session); errmsg = ssh_get_error(sess->session);
virReportError(VIR_ERR_AUTH_FAILED, virReportError(VIR_ERR_AUTH_FAILED,
_("authentication failed: %s"), errmsg); _("authentication failed: %s"), errmsg);
return rc;
cleanup:
return ret;
} }
/* perform keyboard interactive authentication /* perform keyboard interactive authentication
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册