Skip to content

Commit

Permalink
Fix: use target() from Context (#1406)
Browse files Browse the repository at this point in the history
Also fix a bug setting a session option.
  • Loading branch information
jjnicola committed May 4, 2023
1 parent 699d39b commit 1263b30
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions rust/nasl-interpreter/src/built_in_functions/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use crate::NaslLogger;
use crate::{
error::FunctionErrorKind, lookup_keys::TARGET, sessions::SshSession, Context, ContextType,
NaslFunction, NaslValue, Register,
error::FunctionErrorKind, sessions::SshSession, Context, ContextType, NaslFunction, NaslValue,
Register,
};
use core::str;
use libssh_rs::{AuthMethods, AuthStatus, Channel, LogLevel, Session, SshKey, SshOption};
Expand Down Expand Up @@ -305,12 +305,11 @@ fn nasl_ssh_connect<K>(
}
};

let ip_str: String = register
.named(TARGET)
.unwrap_or(&ContextType::Value(NaslValue::String(
"127.0.0.1".to_string(),
)))
.into();
let ip_str: String = match ctx.target() {
x if !x.is_empty() => x.to_string(),
_ => "127.0.0.1".to_string(),
};

let timeout: i64 = register
.named("timeout")
.unwrap_or(&ContextType::Value(NaslValue::Number(0)))
Expand Down Expand Up @@ -389,7 +388,7 @@ fn nasl_ssh_connect<K>(
}

if !key_type.is_empty() {
let option = SshOption::PublicKeyAcceptedTypes(key_type.to_owned());
let option = SshOption::HostKeys(key_type.to_owned());
if let Err(err) = session.set_option(option) {
return Err(FunctionErrorKind::Diagnostic(
format!(
Expand Down

0 comments on commit 1263b30

Please sign in to comment.