mirror of
https://github.com/upa/mscp.git
synced 2026-02-15 01:34:44 +08:00
try pubkey auth first instead of noauth
The libssh auth document suggets to call ssh_userauth_none() first to obtain userauth list. However, it can lead PerSourcePenalties. Thus, try pubkey auth first and try password and interactive auths next.
This commit is contained in:
18
src/ssh.c
18
src/ssh.c
@@ -117,23 +117,11 @@ static int ssh_authenticate(ssh_session ssh, struct mscp_ssh_opts *opts)
|
||||
int auth_bit_mask;
|
||||
int ret;
|
||||
|
||||
/* none method */
|
||||
ret = ssh_userauth_none(ssh, NULL);
|
||||
if (ret == SSH_AUTH_SUCCESS)
|
||||
/* try publickey auth first */
|
||||
char *p = opts->passphrase ? opts->passphrase : NULL;
|
||||
if (ssh_userauth_publickey_auto(ssh, NULL, p) == SSH_AUTH_SUCCESS)
|
||||
return 0;
|
||||
|
||||
auth_bit_mask = ssh_userauth_list(ssh, NULL);
|
||||
if (auth_bit_mask & SSH_AUTH_METHOD_NONE &&
|
||||
ssh_userauth_none(ssh, NULL) == SSH_AUTH_SUCCESS)
|
||||
return 0;
|
||||
|
||||
auth_bit_mask = ssh_userauth_list(ssh, NULL);
|
||||
if (auth_bit_mask & SSH_AUTH_METHOD_PUBLICKEY) {
|
||||
char *p = opts->passphrase ? opts->passphrase : NULL;
|
||||
if (ssh_userauth_publickey_auto(ssh, NULL, p) == SSH_AUTH_SUCCESS)
|
||||
return 0;
|
||||
}
|
||||
|
||||
auth_bit_mask = ssh_userauth_list(ssh, NULL);
|
||||
if (auth_bit_mask & SSH_AUTH_METHOD_PASSWORD) {
|
||||
if (!opts->password) {
|
||||
|
||||
Reference in New Issue
Block a user