static int test_several_auth_methods(ssh_session session, url_t* urlp) { int rc = ssh_userauth_none(session, NULL); /* if (rc != SSH_AUTH_SUCCESS) { return rc; } */ int method = ssh_userauth_list(session, NULL); if (method & SSH_AUTH_METHOD_NONE) { rc = authenticate_none(session); if (rc == SSH_AUTH_SUCCESS) return rc; } if (method & SSH_AUTH_METHOD_PUBLICKEY) { rc = authenticate_pubkey(session); if (rc == SSH_AUTH_SUCCESS) return rc; } if (method & SSH_AUTH_METHOD_INTERACTIVE) { rc = authenticate_kbdint(session); if (rc == SSH_AUTH_SUCCESS) return rc; } if (method & SSH_AUTH_METHOD_PASSWORD) { rc = authenticate_password(session, urlp); if (rc == SSH_AUTH_SUCCESS) return rc; } return SSH_AUTH_ERROR; }
int authenticate_console(ssh_session session) { int rc; int method; // Try to authenticate rc = ssh_userauth_none(session, NULL); if (rc == SSH_AUTH_ERROR) { error(session); return rc; } method = ssh_userauth_list(session,NULL); while (rc != SSH_AUTH_SUCCESS) { // Try to authenticate with public key first rc = ssh_userauth_autopubkey(session, NULL); if (rc == SSH_AUTH_ERROR) { error(session); return rc; } else if (rc == SSH_AUTH_SUCCESS) { break; } rc=authenticate_kbdint(session,pass_word); if (rc == SSH_AUTH_ERROR) { error(session); return rc; } else if (rc == SSH_AUTH_SUCCESS) { break; } rc = ssh_userauth_password(session, NULL, pass_word); if (rc == SSH_AUTH_ERROR) { error(session); return rc; } else if (rc == SSH_AUTH_SUCCESS) { break; } else if(rc == SSH_AUTH_DENIED) { } else if(rc == SSH_AUTH_PARTIAL) { } else if(rc == SSH_AUTH_INFO) { } else if(rc == SSH_AUTH_AGAIN) { } } return rc; }
int authenticate(ssh_session session){ int rc; int method; char password[128] = {0}; char *banner; // Try to authenticate rc = ssh_userauth_none(session, NULL); if (rc == SSH_AUTH_ERROR) { error(session); return rc; } method = ssh_auth_list(session); while (rc != SSH_AUTH_SUCCESS) { // Try to authenticate with public key first if (method & SSH_AUTH_METHOD_PUBLICKEY) { rc = ssh_userauth_autopubkey(session, NULL); if (rc == SSH_AUTH_ERROR) { error(session); return rc; } else if (rc == SSH_AUTH_SUCCESS) { break; } } // Try to authenticate with keyboard interactive"; if (method & SSH_AUTH_METHOD_INTERACTIVE) { rc = authenticate_kbdint(session, NULL); if (rc == SSH_AUTH_ERROR) { error(session); return rc; } else if (rc == SSH_AUTH_SUCCESS) { break; } } if (ssh_getpass("Password: "******"%s\n",banner); ssh_string_free_char(banner); } return rc; }