Ticket #3921: sftp_ip.patch

File sftp_ip.patch, 3.7 KB (added by adamm, 6 years ago)
  • src/vfs/sftpfs/connection.c

    commit 7910ef3ee50a847edf72d755381699f169d46278
    Author: Adam Majer <amajer@suse.de>
    Date:   Mon Jun 25 15:06:38 2018 +0200
    
        Ticket #3921: Enable keyboard interactive authentication
        
        If SSH server does not support cleartext tunneled password
        authentication and only 'keyboard interactive' authentication
        instead, then we need to use different authentication
        function along with a interactive callback.
        
        Signed-off-by: Adam Majer <amajer@suse.de>
    
    diff --git a/src/vfs/sftpfs/connection.c b/src/vfs/sftpfs/connection.c
    index 537159129..a6b7d1b2c 100644
    a b sftpfs_open_connection_ssh_key (struct vfs_s_super *super, GError ** mcerror) 
    292292    return ret_value; 
    293293} 
    294294 
     295 
     296/** 
     297 * Keyboard-interactive password helper for opening connection to host by 
     298 * sftpfs_open_connection_ssh_password 
     299 * 
     300 * Uses global kbi_super (data with existing connection) and kbi_passwd (password) 
     301 * 
     302 * @param name             username 
     303 * @param name_len         length of @name 
     304 * @param instruction      unused 
     305 * @param instruction_len  unused 
     306 * @param num_prompts      number of possible problems to process 
     307 * @param prompts          array of prompts to process 
     308 * @param responses        array of responses, one per prompt 
     309 * @param abstract         unused 
     310 */ 
     311 
     312static const char *kbi_passwd; 
     313static const struct vfs_s_super *kbi_super; 
     314static 
     315LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC (keyboard_interactive_helper) 
     316{ 
     317    int i; 
     318    int len; 
     319 
     320    (void) instruction; 
     321    (void) instruction_len; 
     322    (void) abstract; 
     323 
     324    if (!kbi_super || !kbi_passwd) 
     325        return; 
     326 
     327    if (strncmp (name, kbi_super->path_element->user, name_len) != 0) 
     328        return; 
     329 
     330    // assume these are password prompts 
     331    len = strlen (kbi_passwd); 
     332    for (i = 0; i < num_prompts; ++i) 
     333    { 
     334        if (strncmp (prompts[i].text, "Password: ", prompts[i].length) == 0) 
     335        { 
     336            responses[i].text = strdup (kbi_passwd); 
     337            responses[i].length = len; 
     338        } 
     339    } 
     340} 
     341 
    295342/* --------------------------------------------------------------------------------------------- */ 
    296343/** 
    297344 * Open connection to host using password. 
    sftpfs_open_connection_ssh_password (struct vfs_s_super *super, GError ** mcerro 
    323370               LIBSSH2_ERROR_EAGAIN); 
    324371        if (rc == 0) 
    325372            return TRUE; 
     373 
     374        kbi_super = super; 
     375        kbi_passwd = super->path_element->password; 
     376        while ((rc = 
     377                libssh2_userauth_keyboard_interactive (super_data->session, 
     378                                                       super->path_element->user, 
     379                                                       keyboard_interactive_helper)) == 
     380               LIBSSH2_ERROR_EAGAIN); 
     381        kbi_super = NULL; 
     382        kbi_passwd = NULL; 
     383        if (rc == 0) 
     384            return TRUE; 
    326385    } 
    327386 
    328387    p = g_strdup_printf (_("sftp: Enter password for %s "), super->path_element->user); 
    sftpfs_open_connection_ssh_password (struct vfs_s_super *super, GError ** mcerro 
    337396                                                passwd)) == LIBSSH2_ERROR_EAGAIN) 
    338397            ; 
    339398 
     399        if (rc != 0) 
     400        { 
     401            kbi_super = super; 
     402            kbi_passwd = passwd; 
     403            while ((rc = 
     404                    libssh2_userauth_keyboard_interactive (super_data->session, 
     405                                                           super->path_element->user, 
     406                                                           keyboard_interactive_helper)) == 
     407                   LIBSSH2_ERROR_EAGAIN); 
     408            kbi_super = NULL; 
     409            kbi_passwd = NULL; 
     410        } 
     411 
    340412        if (rc == 0) 
    341413        { 
    342414            ret_value = TRUE;