[vlc-devel] [PATCH] sftp: try to get username for ssh auth

Ion Agorria ion at agorria.com
Thu Oct 26 10:45:04 CEST 2017


Currently even user is provided, the dialog appears asking for user, in case of agent or public key should be tried before asking and only ask if fails
---
 modules/access/sftp.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/modules/access/sftp.c b/modules/access/sftp.c
index c119a223f8..b10bb9862d 100644
--- a/modules/access/sftp.c
+++ b/modules/access/sftp.c
@@ -306,30 +306,42 @@ static int Open( vlc_object_t* p_this )
         goto error;
     }
 
+    /* Try to get username from URL and cmdline for ssh auth */
     char* psz_userauthlist = NULL;
+    const char* psz_current_username;
+    if (credential_url.psz_username) {
+        psz_current_username = credential_url.psz_username;
+    } else {
+        psz_current_username = var_InheritString(p_access, "sftp-user");
+    }
     do
     {
-        if (!credential.psz_username || !credential.psz_username[0])
+        if (credential.psz_username) {
+            psz_current_username = credential.psz_username;
+        } 
+        if (!psz_current_username || !psz_current_username[0]) {
+            msg_Dbg( p_access, "sftp auth no username");
             continue;
+        }
 
         psz_userauthlist = libssh2_userauth_list( p_sys->ssh_session, credential.psz_username, strlen( credential.psz_username ) );
 
         /* TODO: Follow PreferredAuthentications in ssh_config */
 
         if( strstr( psz_userauthlist, "publickey" ) != NULL &&
-            ( AuthKeyAgent( p_access, credential.psz_username ) == VLC_SUCCESS ||
-              AuthPublicKey( p_access, psz_home, credential.psz_username ) == VLC_SUCCESS ) )
+            ( AuthKeyAgent( p_access, psz_current_username ) == VLC_SUCCESS ||
+              AuthPublicKey( p_access, psz_home, psz_current_username ) == VLC_SUCCESS ) )
             break;
         if( strstr( psz_userauthlist, "password" ) != NULL &&
             libssh2_userauth_password( p_sys->ssh_session,
-                                       credential.psz_username,
+                                       psz_current_username,
                                        credential.psz_password ) == 0 )
         {
             vlc_credential_store( &credential, p_access );
             break;
         }
 
-        msg_Warn( p_access, "sftp auth failed for %s", credential.psz_username );
+        msg_Warn( p_access, "sftp auth failed for %s", psz_current_username );
     } while( vlc_credential_get( &credential, p_access, "sftp-user", "sftp-pwd",
                                 _("SFTP authentication"),
                                 _("Please enter a valid login and password for "
-- 
2.13.6



More information about the vlc-devel mailing list