[vlc-commits] [Git][videolan/vlc][master] 3 commits: keystore: change vlc_credential_get return type
Rémi Denis-Courmont (@Courmisch)
gitlab at videolan.org
Sat Jun 4 06:52:48 UTC 2022
Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC
Commits:
9edef14a by Thomas Guillem at 2022-06-04T06:38:18+00:00
keystore: change vlc_credential_get return type
No functional changes.
Refs #27027
- - - - -
5b6735a9 by Thomas Guillem at 2022-06-04T06:38:18+00:00
keystore: return -EINTR when interrupted
Refs #27027
- - - - -
c55033cf by Thomas Guillem at 2022-06-04T06:38:18+00:00
modules: access: handle vlc_credential_get interruption
Fix a possible interrupt miss if vlc_credential_get() receive an
interruption and if access don't check vlc_killed() before doing I/O.
Refs #27027
- - - - -
13 changed files:
- include/vlc_keystore.h
- modules/access/dsm/access.c
- modules/access/ftp.c
- modules/access/http.c
- modules/access/http/access.c
- modules/access/live555.cpp
- modules/access/samba.c
- modules/access/sftp.c
- modules/access/smb2.c
- modules/access/unc.c
- modules/demux/adaptive/http/HTTPConnection.cpp
- src/misc/keystore.c
- test/src/misc/keystore.c
Changes:
=====================================
include/vlc_keystore.h
=====================================
@@ -231,11 +231,11 @@ vlc_credential_clean(vlc_credential *p_credential);
* keystore or the dialog
* @param psz_dialog_fmt dialog text using format
*
- * @return true if vlc_credential.psz_username and vlc_credential.psz_password
- * are valid, otherwise this function should not be called again.
+ * @return 0 if vlc_credential.psz_username and vlc_credential.psz_password
+ * are valid, or a negative errno code.
*/
-VLC_API bool
+VLC_API int
vlc_credential_get(vlc_credential *p_credential, vlc_object_t *p_parent,
const char *psz_option_username,
const char *psz_option_password,
=====================================
modules/access/dsm/access.c
=====================================
@@ -444,8 +444,10 @@ static int login( stream_t *p_access )
psz_var_domain = var_InheritString( p_access, "smb-domain" );
credential.psz_realm = psz_var_domain ? psz_var_domain : NULL;
- vlc_credential_get( &credential, p_access, "smb-user", "smb-pwd",
- NULL, NULL );
+ if (vlc_credential_get( &credential, p_access, "smb-user", "smb-pwd",
+ NULL, NULL ) == -EINTR )
+ goto error;
+
if( !credential.psz_username )
{
@@ -522,7 +524,7 @@ static int login( stream_t *p_access )
while( connect_err == EACCES
&& vlc_credential_get( &credential, p_access, "smb-user", "smb-pwd",
SMB1_LOGIN_DIALOG_TITLE,
- SMB_LOGIN_DIALOG_TEXT, p_sys->netbios_name ) )
+ SMB_LOGIN_DIALOG_TEXT, p_sys->netbios_name ) == 0 )
{
b_guest = false;
psz_login = credential.psz_username;
=====================================
modules/access/ftp.c
=====================================
@@ -455,8 +455,13 @@ static int Login( vlc_object_t *p_access, access_sys_t *p_sys, const char *path
bool b_logged = false;
/* First: try credentials from url / option */
- vlc_credential_get( &credential, p_access, "ftp-user", "ftp-pwd",
- NULL, NULL );
+ if (vlc_credential_get( &credential, p_access, "ftp-user", "ftp-pwd",
+ NULL, NULL ) == -EINTR )
+ {
+ vlc_credential_clean( &credential );
+ goto error;
+ }
+
do
{
const char *psz_username = credential.psz_username;
@@ -471,7 +476,7 @@ static int Login( vlc_object_t *p_access, access_sys_t *p_sys, const char *path
}
while( vlc_credential_get( &credential, p_access, "ftp-user", "ftp-pwd",
LOGIN_DIALOG_TITLE, LOGIN_DIALOG_TEXT,
- url.psz_host ) );
+ url.psz_host ) == 0 );
if( b_logged )
{
=====================================
modules/access/http.c
=====================================
@@ -259,11 +259,16 @@ static int Open( vlc_object_t *p_this )
p_sys->b_reconnect = var_InheritBool( p_access, "http-reconnect" );
- if( vlc_credential_get( &credential, p_access, NULL, NULL, NULL, NULL ) )
+ ret = vlc_credential_get( &credential, p_access, NULL, NULL, NULL, NULL );
+ if( ret == 0 )
{
p_sys->url.psz_username = (char *) credential.psz_username;
p_sys->url.psz_password = (char *) credential.psz_password;
}
+ else if( ret == -EINTR )
+ goto error;
+
+ ret = VLC_EGENERIC;
connect:
/* Connect */
@@ -297,7 +302,7 @@ connect:
if( vlc_credential_get( &credential, p_access, NULL, NULL,
_("HTTP authentication"),
_("Please enter a valid login name and a "
- "password for realm %s."), p_sys->auth.psz_realm ) )
+ "password for realm %s."), p_sys->auth.psz_realm ) == 0 )
{
p_sys->psz_username = strdup(credential.psz_username);
p_sys->psz_password = strdup(credential.psz_password);
=====================================
modules/access/http/access.c
=====================================
@@ -190,9 +190,12 @@ static int Open(vlc_object_t *obj)
if (sys->resource == NULL)
goto error;
- if (vlc_credential_get(&crd, obj, NULL, NULL, NULL, NULL))
+ ret = vlc_credential_get(&crd, obj, NULL, NULL, NULL, NULL);
+ if (ret == 0)
vlc_http_res_set_login(sys->resource,
crd.psz_username, crd.psz_password);
+ else if (ret == -EINTR)
+ goto error;
ret = VLC_EGENERIC;
@@ -207,9 +210,9 @@ static int Open(vlc_object_t *obj)
if (psz_realm == NULL)
break;
crd.psz_realm = psz_realm;
- if (!vlc_credential_get(&crd, obj, NULL, NULL, _("HTTP authentication"),
- _("Please enter a valid login name and "
- "a password for realm %s."), crd.psz_realm))
+ if (vlc_credential_get(&crd, obj, NULL, NULL, _("HTTP authentication"),
+ _("Please enter a valid login name and "
+ "a password for realm %s."), crd.psz_realm) != 0)
break;
vlc_http_res_set_login(sys->resource,
=====================================
modules/access/live555.cpp
=====================================
@@ -616,18 +616,23 @@ static int Connect( demux_t *p_demux )
const char *psz_user = NULL;
const char *psz_pwd = NULL;
int i_http_port = 0;
- int i_ret = VLC_SUCCESS;
+ int i_ret;
const int i_timeout = var_InheritInteger( p_demux, "ipv4-timeout" );
vlc_credential_init( &credential, &p_sys->url );
+ i_ret = vlc_credential_get( &credential, p_demux, "rtsp-user", "rtsp-pwd",
+ NULL, NULL );
/* Credentials can be NULL since they may not be needed */
- if( vlc_credential_get( &credential, p_demux, "rtsp-user", "rtsp-pwd",
- NULL, NULL) )
+ if( i_ret == 0 )
{
psz_user = credential.psz_username;
psz_pwd = credential.psz_password;
}
+ else if( i_ret == -EINTR )
+ goto bailout;
+
+ i_ret = VLC_SUCCESS;
createnew:
/* FIXME: This is naive and incorrect; it does not prevent the thread
@@ -678,7 +683,7 @@ describe:
if( vlc_credential_get( &credential, p_demux, "rtsp-user", "rtsp-pwd",
_("RTSP authentication"),
- _("Please enter a valid login name and a password.") ) )
+ _("Please enter a valid login name and a password.") ) == 0 )
{
psz_user = credential.psz_username;
psz_pwd = credential.psz_password;
=====================================
modules/access/samba.c
=====================================
@@ -309,7 +309,9 @@ static int Open(vlc_object_t *obj)
vlc_credential_init(&credential, &url);
psz_var_domain = var_InheritString(access, "smb-domain");
credential.psz_realm = psz_var_domain;
- vlc_credential_get(&credential, access, "smb-user", "smb-pwd", NULL, NULL);
+ if (vlc_credential_get(&credential, access, "smb-user", "smb-pwd", NULL, NULL)
+ == -EINTR)
+ goto error;
smbc_stat_fn stat_fn = smbc_getFunctionStat(ctx);
assert(stat_fn);
@@ -347,9 +349,9 @@ static int Open(vlc_object_t *obj)
break;
errno = 0;
- if (!vlc_credential_get(&credential, access, "smb-user",
- "smb-pwd", SMB_LOGIN_DIALOG_TITLE,
- SMB_LOGIN_DIALOG_TEXT, url.psz_host))
+ if (vlc_credential_get(&credential, access, "smb-user",
+ "smb-pwd", SMB_LOGIN_DIALOG_TITLE,
+ SMB_LOGIN_DIALOG_TEXT, url.psz_host) != 0)
break;
}
=====================================
modules/access/sftp.c
=====================================
@@ -403,8 +403,10 @@ static int Open( vlc_object_t* p_this )
goto error;
}
- vlc_credential_get( &credential, p_access, "sftp-user", "sftp-pwd",
- NULL, NULL );
+ if (vlc_credential_get( &credential, p_access, "sftp-user", "sftp-pwd",
+ NULL, NULL) == -EINTR)
+ goto error;
+
char* psz_userauthlist = NULL;
bool b_publickey_tried = false;
do
@@ -463,7 +465,7 @@ static int Open( vlc_object_t* p_this )
} while( vlc_credential_get( &credential, p_access, "sftp-user", "sftp-pwd",
_("SFTP authentication"),
_("Please enter a valid login and password for "
- "the SFTP connection to %s"), url.psz_host ) );
+ "the SFTP connection to %s"), url.psz_host ) == 0 );
/* Create the sftp session */
p_sys->sftp_session = libssh2_sftp_init( p_sys->ssh_session );
=====================================
modules/access/smb2.c
=====================================
@@ -857,14 +857,21 @@ Open(vlc_object_t *p_obj)
/* First, try Guest login or using "smb-" options (without
* keystore/user interaction) */
- vlc_credential_get(&credential, access, "smb-user", "smb-pwd", NULL,
- NULL);
+ if (vlc_credential_get(&credential, access, "smb-user", "smb-pwd", NULL,
+ NULL) == -EINTR)
+ {
+ vlc_credential_clean(&credential);
+ free(resolved_host);
+ ret = -EINTR;
+ goto error;
+ }
+
ret = vlc_smb2_connect_open_share(access, url, &credential);
while (VLC_SMB2_STATUS_DENIED(ret)
&& vlc_credential_get(&credential, access, "smb-user", "smb-pwd",
SMB_LOGIN_DIALOG_TITLE, SMB_LOGIN_DIALOG_TEXT,
- sys->encoded_url.psz_host))
+ sys->encoded_url.psz_host) == 0)
ret = vlc_smb2_connect_open_share(access, url, &credential);
free(resolved_host);
free(url);
=====================================
modules/access/unc.c
=====================================
@@ -294,7 +294,14 @@ static int Open(vlc_object_t *obj)
vlc_credential_init(&credential, &url);
psz_var_domain = var_InheritString(access, "smb-domain");
credential.psz_realm = psz_var_domain;
- vlc_credential_get(&credential, access, "smb-user", "smb-pwd", NULL, NULL);
+ if (vlc_credential_get(&credential, access, "smb-user", "smb-pwd", NULL, NULL) == -EINTR)
+ {
+ vlc_credential_clean(&credential);
+ free(psz_var_domain);
+ free(psz_decoded_path);
+ vlc_UrlClean(&url);
+ return VLC_EGENERIC;
+ }
for (;;)
{
@@ -326,9 +333,9 @@ static int Open(vlc_object_t *obj)
break;
errno = 0;
- if (!vlc_credential_get(&credential, access, "smb-user",
- "smb-pwd", SMB_LOGIN_DIALOG_TITLE,
- SMB_LOGIN_DIALOG_TEXT, url.psz_host))
+ if (vlc_credential_get(&credential, access, "smb-user",
+ "smb-pwd", SMB_LOGIN_DIALOG_TITLE,
+ SMB_LOGIN_DIALOG_TEXT, url.psz_host) != 0)
break;
}
=====================================
modules/demux/adaptive/http/HTTPConnection.cpp
=====================================
@@ -311,11 +311,18 @@ RequestStatus LibVLCHTTPConnection::request(const std::string &path,
vlc_UrlParse(&crd_url, params.getUrl().c_str());
vlc_credential_init(&crd, &crd_url);
- if (vlc_credential_get(&crd, p_object, NULL, NULL, NULL, NULL))
+ int ret = vlc_credential_get(&crd, p_object, NULL, NULL, NULL, NULL);
+ if (ret == 0)
{
vlc_http_res_set_login(source->http_res,
crd.psz_username, crd.psz_password);
}
+ else if (ret == -EINTR)
+ {
+ vlc_credential_clean(&crd);
+ vlc_UrlClean(&crd_url);
+ return RequestStatus::GenericError;
+ }
int status = vlc_http_res_get_status(source->http_res);
if (status < 0)
@@ -337,7 +344,7 @@ RequestStatus LibVLCHTTPConnection::request(const std::string &path,
if (vlc_credential_get(&crd, p_object, NULL, NULL,
_("HTTP authentication"),
_("Please enter a valid login name and a "
- "password for realm %s."), psz_realm))
+ "password for realm %s."), psz_realm) == 0)
{
if(source->abortandlogin(crd.psz_username, crd.psz_password))
{
=====================================
src/misc/keystore.c
=====================================
@@ -27,6 +27,7 @@
#include <vlc_keystore.h>
#include <vlc_modules.h>
#include <vlc_url.h>
+#include <vlc_interrupt.h>
#include <libvlc.h>
#include <assert.h>
@@ -372,7 +373,7 @@ vlc_credential_clean(vlc_credential *p_credential)
}
#undef vlc_credential_get
-bool
+int
vlc_credential_get(vlc_credential *p_credential, vlc_object_t *p_parent,
const char *psz_option_username,
const char *psz_option_password,
@@ -385,7 +386,7 @@ vlc_credential_get(vlc_credential *p_credential, vlc_object_t *p_parent,
if (!is_url_valid(p_url))
{
msg_Err(p_parent, "vlc_credential_get: invalid url");
- return false;
+ return -EINVAL;
}
p_credential->b_from_keystore = false;
@@ -451,13 +452,16 @@ vlc_credential_get(vlc_credential *p_credential, vlc_object_t *p_parent,
if (p_credential->p_keystore != NULL)
credential_find_keystore(p_credential, p_credential->p_keystore);
+ if (vlc_killed())
+ return -EINTR;
+
p_credential->i_get_order++;
break;
default:
case GET_FROM_DIALOG:
if (!psz_dialog_title || !psz_dialog_fmt)
- return false;
+ return -ENOENT;
char *psz_dialog_username = NULL;
char *psz_dialog_password = NULL;
va_list ap;
@@ -483,7 +487,7 @@ vlc_credential_get(vlc_credential *p_credential, vlc_object_t *p_parent,
if (i_ret != 1)
{
p_credential->psz_username = p_credential->psz_password = NULL;
- return false;
+ return vlc_killed() ? -EINTR : -ENOENT;
}
p_credential->psz_username = p_credential->psz_dialog_username;
@@ -495,7 +499,7 @@ vlc_credential_get(vlc_credential *p_credential, vlc_object_t *p_parent,
break;
}
}
- return is_credential_valid(p_credential);
+ return is_credential_valid(p_credential) ? 0 : -ENOENT;
}
#undef vlc_credential_store
=====================================
test/src/misc/keystore.c
=====================================
@@ -298,7 +298,7 @@ test(vlc_object_t *p_obj, unsigned int i_id, const struct testcase *p_test)
bool b_found = false;
while (vlc_credential_get(&credential, p_obj, psz_opt_user, psz_opt_pwd,
- "test authentication", "this a test"))
+ "test authentication", "this a test") == 0)
{
bool realm_match = !p_test->result.psz_realm
|| (credential.psz_realm
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/77bf795c0dd4015e7475df4a1addf43150649f41...c55033cf75e9145bb58b81a2c3ef6bd55aa98c1b
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/77bf795c0dd4015e7475df4a1addf43150649f41...c55033cf75e9145bb58b81a2c3ef6bd55aa98c1b
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list