Skip to content

Commit b0ae266

Browse files
committed
Move get_kb_items_with_keys to ScriptCtx. Remove target.
1 parent 997d691 commit b0ae266

1 file changed

Lines changed: 19 additions & 33 deletions

File tree

‎rust/src/nasl/utils/scan_ctx.rs‎

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,6 @@ pub struct CtxTarget {
124124
ports_udp: BTreeSet<u16>,
125125
}
126126

127-
impl CtxTarget {
128-
fn clone_fake_temp(&self) -> Self {
129-
Self {
130-
target: self.target.clone(),
131-
vhosts: Mutex::new(vec![]),
132-
ports_tcp: self.ports_tcp.clone(),
133-
ports_udp: self.ports_udp.clone(),
134-
}
135-
}
136-
}
137-
138127
pub struct CtxTargets {
139128
targets: Vec<CtxTarget>,
140129
}
@@ -324,8 +313,6 @@ pub struct TargetId(usize);
324313
pub struct ScanCtx<'a> {
325314
/// The key for this context.
326315
scan: ScanID,
327-
/// Target against which the scan is run.
328-
target: CtxTarget,
329316
/// Targets against which the scan is run.
330317
targets: CtxTargets,
331318
/// Filename of the current script
@@ -365,7 +352,6 @@ impl<'a> ScanCtx<'a> {
365352

366353
Self {
367354
scan,
368-
target: targets.targets[0].clone_fake_temp(), // TODO
369355
targets,
370356
filename,
371357
storage,
@@ -463,24 +449,6 @@ impl<'a> ScanCtx<'a> {
463449
self.alive_test_methods.clone()
464450
}
465451

466-
async fn get_kb_items_with_keys(
467-
&self,
468-
key: &KbKey,
469-
) -> Result<Vec<(String, Vec<KbItem>)>, FnError> {
470-
let result = self
471-
.storage
472-
.retrieve(&GetKbContextKey(
473-
(
474-
self.scan.clone(),
475-
storage::Target(self.target.ip_addr().to_string()),
476-
),
477-
key.clone(),
478-
))
479-
.await?
480-
.unwrap_or_default();
481-
Ok(result)
482-
}
483-
484452
fn get_preference_bool(&self, key: &str) -> Option<bool> {
485453
let prefs = &self.scan_preferences;
486454
pref_is_true(prefs, key)
@@ -645,6 +613,25 @@ impl<'a> ScriptCtx<'a> {
645613
Ok(result)
646614
}
647615

616+
async fn get_kb_items_with_keys(
617+
&self,
618+
key: &KbKey,
619+
) -> Result<Vec<(String, Vec<KbItem>)>, FnError> {
620+
let result = self
621+
.scan_ctx
622+
.storage
623+
.retrieve(&GetKbContextKey(
624+
(
625+
self.scan_ctx.scan.clone(),
626+
storage::Target(self.target().ip_addr().to_string()),
627+
),
628+
key.clone(),
629+
))
630+
.await?
631+
.unwrap_or_default();
632+
Ok(result)
633+
}
634+
648635
pub async fn get_port_state(&self, port: u16, protocol: Protocol) -> Result<bool, FnError> {
649636
match protocol {
650637
Protocol::TCP => {
@@ -683,7 +670,6 @@ impl<'a> ScriptCtx<'a> {
683670
/// Looks up open TCP ports from the knowledge base
684671
pub async fn get_open_tcp_ports(&self) -> Result<Vec<u16>, FnError> {
685672
let open_ports = self
686-
.scan_ctx
687673
.get_kb_items_with_keys(&KbKey::Port(kb::Port::Tcp("*".to_string())))
688674
.await?;
689675

0 commit comments

Comments
 (0)