MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / libssh_authentication

Function libssh_authentication

libavformat/libssh.c:73–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71}
72
73static av_cold int libssh_authentication(LIBSSHContext *libssh, const char *user, const char *password)
74{
75 int authorized = 0;
76 int auth_methods;
77
78 if (user)
79 ssh_options_set(libssh->session, SSH_OPTIONS_USER, user);
80
81 if (ssh_userauth_none(libssh->session, NULL) == SSH_AUTH_SUCCESS)
82 return 0;
83
84 auth_methods = ssh_userauth_list(libssh->session, NULL);
85
86 if (auth_methods & SSH_AUTH_METHOD_PUBLICKEY) {
87 if (libssh->priv_key) {
88 ssh_key priv_key;
89 if (ssh_pki_import_privkey_file(libssh->priv_key, password, NULL, NULL, &priv_key) == SSH_OK) {
90 if (ssh_userauth_publickey(libssh->session, NULL, priv_key) == SSH_AUTH_SUCCESS) {
91 av_log(libssh, AV_LOG_DEBUG, "Authentication successful with selected private key.\n");
92 authorized = 1;
93 }
94 } else {
95 av_log(libssh, AV_LOG_DEBUG, "Invalid key is provided.\n");
96 return AVERROR(EACCES);
97 }
98 } else if (ssh_userauth_publickey_auto(libssh->session, NULL, password) == SSH_AUTH_SUCCESS) {
99 av_log(libssh, AV_LOG_DEBUG, "Authentication successful with auto selected key.\n");
100 authorized = 1;
101 }
102 }
103
104 if (!authorized && password && (auth_methods & SSH_AUTH_METHOD_PASSWORD)) {
105 if (ssh_userauth_password(libssh->session, NULL, password) == SSH_AUTH_SUCCESS) {
106 av_log(libssh, AV_LOG_DEBUG, "Authentication successful with password.\n");
107 authorized = 1;
108 }
109 }
110
111 if (!authorized) {
112 av_log(libssh, AV_LOG_ERROR, "Authentication failed.\n");
113 return AVERROR(EACCES);
114 }
115
116 return 0;
117}
118
119static av_cold int libssh_create_sftp_session(LIBSSHContext *libssh)
120{

Callers 1

libssh_connectFunction · 0.85

Calls 1

av_logFunction · 0.85

Tested by

no test coverage detected