Commit c4e7180c authored by Thomas Guillem's avatar Thomas Guillem

ftp: use vlc_credential

parent 3ab2b1e0
......@@ -45,6 +45,7 @@
#include <vlc_sout.h>
#include <vlc_charset.h>
#include <vlc_interrupt.h>
#include <vlc_keystore.h>
#ifndef IPPORT_FTP
# define IPPORT_FTP 21u
......@@ -74,6 +75,10 @@ static void OutClose( vlc_object_t * );
#define ACCOUNT_LONGTEXT N_("Account that will be " \
"used for the connection.")
#define LOGIN_DIALOG_TITLE _("FTP authentication")
#define LOGIN_DIALOG_TEXT _("Please enter a valid login and password for " \
"the ftp connexion to %s")
vlc_module_begin ()
set_shortname( "FTP" )
set_description( N_("FTP input") )
......@@ -115,7 +120,7 @@ static ssize_t Write( sout_access_out_t *, block_t * );
#endif
static int LoginUserPwd( vlc_object_t *, access_sys_t *,
const char *, const char * );
const char *, const char *, bool * );
static void FeaturesCheck( void *, const char * );
typedef struct ftp_features_t
......@@ -405,39 +410,35 @@ static int Login( vlc_object_t *p_access, access_sys_t *p_sys )
}
}
char *psz_user, *psz_pwd;
if( p_sys->url.psz_username && *p_sys->url.psz_username )
psz_user = strdup( p_sys->url.psz_username );
else
psz_user = var_InheritString( p_access, "ftp-user" );
if( !psz_user )
goto error;
if( p_sys->url.psz_password && *p_sys->url.psz_password )
psz_pwd = strdup( p_sys->url.psz_password );
else
psz_pwd = var_InheritString( p_access, "ftp-pwd" );
if( !psz_pwd )
{
free( psz_user );
goto error;
}
if( LoginUserPwd( p_access, p_sys, psz_user, psz_pwd ) == 0 )
{
free( psz_user );
free( psz_pwd );
vlc_url_t url;
vlc_credential credential;
vlc_UrlParse( &url, ((access_t *)p_access)->psz_url );
vlc_credential_init( &credential, &url );
bool b_logged = false;
while( vlc_credential_get( &credential, p_access, "ftp-user", "ftp-pwd",
LOGIN_DIALOG_TITLE, LOGIN_DIALOG_TEXT,
url.psz_host )
&& LoginUserPwd( p_access, p_sys, credential.psz_username,
credential.psz_password, &b_logged ) == 0
&& !b_logged );
if( b_logged )
{
vlc_credential_store( &credential );
vlc_credential_clean( &credential );
vlc_UrlClean( &url );
return 0;
}
free( psz_user );
free( psz_pwd );
vlc_credential_clean( &credential );
vlc_UrlClean( &url );
error:
clearCmdTLS( p_sys );
return -1;
}
static int LoginUserPwd( vlc_object_t *p_access, access_sys_t *p_sys,
const char *psz_user, const char *psz_pwd)
const char *psz_user, const char *psz_pwd,
bool *p_logged )
{
int i_answer;
......@@ -494,19 +495,18 @@ static int LoginUserPwd( vlc_object_t *p_access, access_sys_t *p_sys,
}
default:
msg_Err( p_access, "password rejected" );
dialog_Fatal( p_access, _("Network interaction failed"),
"%s", _("Your password was rejected.") );
return -1;
msg_Warn( p_access, "password rejected" );
*p_logged = false;
return 0;
}
break;
default:
msg_Err( p_access, "user rejected" );
dialog_Fatal( p_access, _("Network interaction failed"), "%s",
_("Your connection attempt to the server was rejected.") );
return -1;
msg_Warn( p_access, "user rejected" );
*p_logged = false;
return 0;
}
*p_logged = true;
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment