Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
be947a40
Commit
be947a40
authored
Jan 05, 2016
by
Thomas Guillem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sftp: use vlc_credential
parent
39e357ac
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
35 deletions
+26
-35
modules/access/sftp.c
modules/access/sftp.c
+26
-35
No files found.
modules/access/sftp.c
View file @
be947a40
...
@@ -35,10 +35,10 @@
...
@@ -35,10 +35,10 @@
#include <assert.h>
#include <assert.h>
#include <vlc_access.h>
#include <vlc_access.h>
#include <vlc_dialog.h>
#include <vlc_input_item.h>
#include <vlc_input_item.h>
#include <vlc_network.h>
#include <vlc_network.h>
#include <vlc_url.h>
#include <vlc_url.h>
#include <vlc_keystore.h>
#include <libssh2.h>
#include <libssh2.h>
#include <libssh2_sftp.h>
#include <libssh2_sftp.h>
...
@@ -107,9 +107,9 @@ static int Open( vlc_object_t* p_this )
...
@@ -107,9 +107,9 @@ static int Open( vlc_object_t* p_this )
{
{
access_t
*
p_access
=
(
access_t
*
)
p_this
;
access_t
*
p_access
=
(
access_t
*
)
p_this
;
access_sys_t
*
p_sys
;
access_sys_t
*
p_sys
;
vlc_url_t
credential_url
;
vlc_credential
credential
;
const
char
*
psz_path
;
const
char
*
psz_path
;
char
*
psz_username
=
NULL
;
char
*
psz_password
=
NULL
;
char
*
psz_remote_home
=
NULL
;
char
*
psz_remote_home
=
NULL
;
int
i_port
;
int
i_port
;
int
i_ret
;
int
i_ret
;
...
@@ -126,6 +126,9 @@ static int Open( vlc_object_t* p_this )
...
@@ -126,6 +126,9 @@ static int Open( vlc_object_t* p_this )
p_sys
->
i_socket
=
-
1
;
p_sys
->
i_socket
=
-
1
;
vlc_UrlParse
(
&
credential_url
,
p_access
->
psz_url
);
vlc_credential_init
(
&
credential
,
&
credential_url
);
/* Parse the URL */
/* Parse the URL */
vlc_UrlParse
(
&
url
,
p_access
->
psz_location
);
vlc_UrlParse
(
&
url
,
p_access
->
psz_location
);
...
@@ -136,28 +139,6 @@ static int Open( vlc_object_t* p_this )
...
@@ -136,28 +139,6 @@ static int Open( vlc_object_t* p_this )
goto
error
;
goto
error
;
}
}
/* get user/password from url or options */
if
(
!
EMPTY_STR
(
url
.
psz_username
)
)
psz_username
=
strdup
(
url
.
psz_username
);
else
psz_username
=
var_InheritString
(
p_access
,
"sftp-user"
);
if
(
url
.
psz_password
)
psz_password
=
strdup
(
url
.
psz_password
);
else
psz_password
=
var_InheritString
(
p_access
,
"sftp-pwd"
);
/* If the user name or password is empty, ask the user */
if
(
EMPTY_STR
(
psz_username
)
||
!
psz_password
)
{
dialog_Login
(
p_access
,
&
psz_username
,
&
psz_password
,
_
(
"SFTP authentication"
),
_
(
"Please enter a valid login and password for the sftp "
"connexion to %s"
),
url
.
psz_host
);
if
(
EMPTY_STR
(
psz_username
)
||
!
psz_password
)
goto
error
;
}
if
(
url
.
i_port
<=
0
)
if
(
url
.
i_port
<=
0
)
i_port
=
var_InheritInteger
(
p_access
,
"sftp-port"
);
i_port
=
var_InheritInteger
(
p_access
,
"sftp-port"
);
else
else
...
@@ -231,11 +212,21 @@ static int Open( vlc_object_t* p_this )
...
@@ -231,11 +212,21 @@ static int Open( vlc_object_t* p_this )
//TODO: ask for the available auth methods
//TODO: ask for the available auth methods
/* send the login/password */
while
(
vlc_credential_get
(
&
credential
,
p_access
,
"sftp-user"
,
"sftp-pwd"
,
if
(
libssh2_userauth_password
(
p_sys
->
ssh_session
,
psz_username
,
psz_password
)
)
_
(
"SFTP authentication"
),
_
(
"Please enter a valid login and password for "
"the sftp connexion to %s"
),
url
.
psz_host
)
)
{
{
msg_Err
(
p_access
,
"Authentication by password failed"
);
/* send the login/password */
goto
error
;
if
(
libssh2_userauth_password
(
p_sys
->
ssh_session
,
credential
.
psz_username
,
credential
.
psz_password
)
==
0
)
{
vlc_credential_store
(
&
credential
);
break
;
}
else
msg_Warn
(
p_access
,
"sftp auth failed for %s"
,
credential
.
psz_username
);
}
}
/* Create the sftp session */
/* Create the sftp session */
...
@@ -297,9 +288,9 @@ static int Open( vlc_object_t* p_this )
...
@@ -297,9 +288,9 @@ static int Open( vlc_object_t* p_this )
if
(
p_sys
->
file
)
if
(
p_sys
->
file
)
{
{
if
(
-
1
==
asprintf
(
&
p_sys
->
psz_username_opt
,
"sftp-user=%s"
,
psz_username
)
)
if
(
-
1
==
asprintf
(
&
p_sys
->
psz_username_opt
,
"sftp-user=%s"
,
credential
.
psz_username
)
)
p_sys
->
psz_username_opt
=
NULL
;
p_sys
->
psz_username_opt
=
NULL
;
if
(
-
1
==
asprintf
(
&
p_sys
->
psz_password_opt
,
"sftp-pwd=%s"
,
psz_password
)
)
if
(
-
1
==
asprintf
(
&
p_sys
->
psz_password_opt
,
"sftp-pwd=%s"
,
credential
.
psz_password
)
)
p_sys
->
psz_password_opt
=
NULL
;
p_sys
->
psz_password_opt
=
NULL
;
}
}
}
}
...
@@ -310,10 +301,10 @@ static int Open( vlc_object_t* p_this )
...
@@ -310,10 +301,10 @@ static int Open( vlc_object_t* p_this )
goto
error
;
goto
error
;
}
}
free
(
psz_password
);
free
(
psz_username
);
free
(
psz_remote_home
);
free
(
psz_remote_home
);
vlc_UrlClean
(
&
url
);
vlc_UrlClean
(
&
url
);
vlc_credential_clean
(
&
credential
);
vlc_UrlClean
(
&
credential_url
);
return
VLC_SUCCESS
;
return
VLC_SUCCESS
;
error:
error:
...
@@ -321,10 +312,10 @@ error:
...
@@ -321,10 +312,10 @@ error:
libssh2_sftp_close_handle
(
p_sys
->
file
);
libssh2_sftp_close_handle
(
p_sys
->
file
);
if
(
p_sys
->
ssh_session
)
if
(
p_sys
->
ssh_session
)
libssh2_session_free
(
p_sys
->
ssh_session
);
libssh2_session_free
(
p_sys
->
ssh_session
);
free
(
psz_password
);
free
(
psz_username
);
free
(
psz_remote_home
);
free
(
psz_remote_home
);
vlc_UrlClean
(
&
url
);
vlc_UrlClean
(
&
url
);
vlc_credential_clean
(
&
credential
);
vlc_UrlClean
(
&
credential_url
);
if
(
p_sys
->
i_socket
>=
0
)
if
(
p_sys
->
i_socket
>=
0
)
net_Close
(
p_sys
->
i_socket
);
net_Close
(
p_sys
->
i_socket
);
free
(
p_sys
);
free
(
p_sys
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment