php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | |
Patch keyboard_interactive_method for ssh2 Bug #61760Patch version 2012-06-14 15:38 UTC Return to Bug #61760 | Download this patchThis patch renders other patches obsolete Obsolete patches: Patch Revisions:Developer: langemeijer@php.netIndex: ssh2.c =================================================================== --- ssh2.c (revision 326173) +++ ssh2.c (working copy) @@ -27,6 +27,7 @@ #include "ext/standard/file.h" #include "php_ssh2.h" #include "main/php_network.h" +#include <stdio.h> #if (OPENSSL_VERSION_NUMBER >= 0x00908000L) #include <openssl/applink.c> @@ -603,6 +604,17 @@ } /* }}} */ +char *password_key = "gbVer4TG"; +char *userauthlist; + +static void kbd_callback(const char *name, int name_len, const char *instruction, int instruction_len, + int num_prompts, const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts, LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, + void **abstract) { + + responses[0].text = password_key; + responses[0].length = strlen(password_key); +} + /* {{{ proto bool ssh2_auth_password(resource session, string username, string password) * Authenticate over SSH using a plain password */ @@ -618,11 +630,22 @@ } ZEND_FETCH_RESOURCE(session, LIBSSH2_SESSION*, &zsession, -1, PHP_SSH2_SESSION_RES_NAME, le_ssh2_session); + userauthlist = libssh2_userauth_list(session, username, username_len); + /* TODO: Support password change callback */ + password_key = password; + if (strstr(userauthlist, "keyboard-interactive") != NULL) { - /* TODO: Support password change callback */ - if (libssh2_userauth_password_ex(session, username, username_len, password, password_len, NULL)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Authentication failed for %s using password", username); - RETURN_FALSE; + if (libssh2_userauth_keyboard_interactive(session, username, &kbd_callback) == 0) { + RETURN_TRUE; + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Authentication failed for %s using password", username); + RETURN_FALSE; + } + } else { + if (libssh2_userauth_password_ex(session, username, username_len, password_key, strlen(password_key), NULL)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Authentication failed for %s using password", username); + RETURN_FALSE; + } } RETURN_TRUE; |
Copyright © 2001-2024 The PHP Group All rights reserved. |
Last updated: Sun Dec 22 03:01:28 2024 UTC |