Commit c4e7180c authored by Thomas Guillem's avatar Thomas Guillem

ftp: use vlc_credential

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