From a93e84efb9b2e9e9f4ca249d0cdd1535ec51b380 Mon Sep 17 00:00:00 2001 From: AsadaShino <1164429449@qq.com> Date: Wed, 8 Jan 2025 21:22:39 +0800 Subject: [PATCH] authenticate_console:Stop authentication after SSH session disconnection to avoid hanging up in poll Signed-off-by: AsadaShino <1164429449@qq.com> Reviewed-by: Jakub Jelen --- examples/authentication.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/authentication.c b/examples/authentication.c index 7c47c8bd..82fad470 100644 --- a/examples/authentication.c +++ b/examples/authentication.c @@ -147,7 +147,7 @@ int authenticate_console(ssh_session session) // Try to authenticate rc = ssh_userauth_none(session, NULL); - if (rc == SSH_AUTH_ERROR) { + if (rc == SSH_AUTH_ERROR || !ssh_is_connected(session)) { error(session); return rc; } @@ -156,7 +156,7 @@ int authenticate_console(ssh_session session) while (rc != SSH_AUTH_SUCCESS) { if (method & SSH_AUTH_METHOD_GSSAPI_MIC){ rc = ssh_userauth_gssapi(session); - if(rc == SSH_AUTH_ERROR) { + if (rc == SSH_AUTH_ERROR || !ssh_is_connected(session)) { error(session); return rc; } else if (rc == SSH_AUTH_SUCCESS) { @@ -166,7 +166,7 @@ int authenticate_console(ssh_session session) // Try to authenticate with public key first if (method & SSH_AUTH_METHOD_PUBLICKEY) { rc = ssh_userauth_publickey_auto(session, NULL, NULL); - if (rc == SSH_AUTH_ERROR) { + if (rc == SSH_AUTH_ERROR || !ssh_is_connected(session)) { error(session); return rc; } else if (rc == SSH_AUTH_SUCCESS) { @@ -206,7 +206,7 @@ int authenticate_console(ssh_session session) // Try to authenticate with keyboard interactive"; if (method & SSH_AUTH_METHOD_INTERACTIVE) { rc = authenticate_kbdint(session, NULL); - if (rc == SSH_AUTH_ERROR) { + if (rc == SSH_AUTH_ERROR || !ssh_is_connected(session)) { error(session); return rc; } else if (rc == SSH_AUTH_SUCCESS) { @@ -221,7 +221,7 @@ int authenticate_console(ssh_session session) // Try to authenticate with password if (method & SSH_AUTH_METHOD_PASSWORD) { rc = ssh_userauth_password(session, NULL, password); - if (rc == SSH_AUTH_ERROR) { + if (rc == SSH_AUTH_ERROR || !ssh_is_connected(session)) { error(session); return rc; } else if (rc == SSH_AUTH_SUCCESS) {