Fixed ssh crash when username in URI is null

This commit is contained in:
Abdelilah El Aissaoui 2023-08-28 10:51:53 +02:00
parent 1a523d04ef
commit 804b83769f
No known key found for this signature in database
GPG Key ID: 7587FC860F594869
3 changed files with 12 additions and 5 deletions

View File

@ -34,8 +34,15 @@ class GRemoteSession @Inject constructor(
fun setup(uri: URIish) { fun setup(uri: URIish) {
val session = processSession.get() val session = processSession.get()
session.setOptions(LibSshOptions.SSH_OPTIONS_HOST, uri.host) session.setOptions(LibSshOptions.SSH_OPTIONS_HOST, uri.host)
session.setOptions(LibSshOptions.SSH_OPTIONS_USER, uri.user)
session.setOptions(LibSshOptions.SSH_OPTIONS_PUBLICKEY_ACCEPTED_TYPES, "ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-rsa,rsa-sha2-512,rsa-sha2-256,ssh-dss") uri.user?.let {
session.setOptions(LibSshOptions.SSH_OPTIONS_USER, uri.user)
}
session.setOptions(
LibSshOptions.SSH_OPTIONS_PUBLICKEY_ACCEPTED_TYPES,
"ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-rsa,rsa-sha2-512,rsa-sha2-256,ssh-dss"
)
session.loadOptionsFromConfig() session.loadOptionsFromConfig()
session.connect() session.connect()

View File

@ -17,7 +17,7 @@ class LibSshSession @Inject constructor() {
} }
fun loadOptionsFromConfig() { fun loadOptionsFromConfig() {
checkValidResult(sshLib.ssh_options_parse_config(session, null)) checkValidResult("loadOptionsFromConfig", sshLib.ssh_options_parse_config(session, null))
} }
fun connect() { fun connect() {

View File

@ -20,7 +20,7 @@ class LibSshChannelOutputStream(private val sshChannel: ssh_channel) : OutputStr
} }
} }
fun checkValidResult(result: Int) { fun checkValidResult(tag: String, result: Int) {
if (result != 0) if (result != 0)
throw Exception("Result is $result") throw Exception("$tag - Result is $result")
} }