Skip to content

Commit e99dc92

Browse files
committed
add new struct to handle also .inc files
1 parent 3708397 commit e99dc92

6 files changed

Lines changed: 35 additions & 6 deletions

File tree

rust/crates/greenbone-scanner-framework/src/models/vtdata.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,11 @@ impl TagValue {
544544
}
545545
}
546546

547+
pub enum ScriptMetadata {
548+
VT(VTData),
549+
IncFile(IncFileData),
550+
}
551+
547552
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
548553
#[serde(rename_all = "snake_case")]
549554
/// Structure to hold a NVT
@@ -583,3 +588,17 @@ impl Display for VTData {
583588
write!(f, "VT {} ({})", self.oid, self.filename)
584589
}
585590
}
591+
592+
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
593+
#[serde(rename_all = "snake_case")]
594+
/// Structure to hold an IncFile
595+
/// For integrity check and feed update
596+
pub struct IncFileData {
597+
pub filename: String,
598+
}
599+
600+
impl Display for IncFileData {
601+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
602+
write!(f, "{}", self.filename)
603+
}
604+
}

rust/src/openvasd/config/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ impl Config {
696696
config.feed.path.clone_from(path);
697697
}
698698
if let Some(path) = cmds.get_one::<PathBuf>("lock-file-dir") {
699-
config.feed.lock_file_dir.clone_from(path);
699+
config.feed.lock_file_dir.clone_from(&Some(path.to_path_buf()));
700700
}
701701
if let Some(path) = cmds.get_one::<PathBuf>("notus-products") {
702702
config.notus.products_path.clone_from(path);

rust/src/openvasd/scans/scheduling.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ where
531531
scanner: Arc::new(scanner),
532532
feed_sync_in_progress: Arc::new(RwLock::new(IsInProgress::default())),
533533
scan_state: change_scan_status,
534-
lock_file_dir: config.feed.lock_file_dir.to_string_lossy().to_string(),
534+
lock_file_dir: config.feed.lock_file_dir.clone().unwrap_or(PathBuf::from("/var/lib/openvas")).to_string_lossy().to_string(),
535535
};
536536

537537
run_scheduler(config.scheduler.check_interval, scheduler, feed).await

rust/src/openvasd/vts/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::{
77

88
use greenbone_scanner_framework::{GetVTsError, StreamResult};
99
use scannerlib::Promise;
10+
use scannerlib::models::{IncFile, ScriptMetadata};
1011
use scannerlib::nasl::syntax::Loader;
1112
use scannerlib::notus::advisory_loader;
1213
use scannerlib::{
@@ -269,7 +270,8 @@ where
269270
synchronize_json(ps, &hash, move |sender| {
270271
let file = std::fs::File::open(&path).map_err(|_| not_found())?;
271272
let reader = BufReader::new(file);
272-
for element in json_stream::iter_json_array::<VTData, _>(reader).filter_map(|x| x.ok()) {
273+
for element in json_stream::iter_json_array::<ScriptMetadata, _>(reader).filter_map(|x| x.ok()) {
274+
tracing::info!("{}", &element.filename);
273275
if sender.send(element).is_err() {
274276
break;
275277
}

rust/src/openvasd/vts/redis.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ impl PluginStorer for RedisPluginHandler {
320320
Some(vt) => {
321321
let mut file = feed_path;
322322
file.push(vt.filename.clone());
323-
let mtime = fs::metadata(file)
324-
.expect("File Metadata")
323+
let mtime = fs::metadata(&file)
324+
.expect(format!("File Metadata {:?}", file.to_string_lossy()).as_str())
325325
.modified()
326326
.expect("File mtime not supported")
327327
.duration_since(UNIX_EPOCH)

rust/src/storage/redis/connector.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use std::collections::BTreeMap;
66
use std::fmt::Debug;
77

8+
use std::path::PathBuf;
89
use std::str::FromStr;
910

1011
use super::dberror::DbError;
@@ -542,6 +543,14 @@ pub trait RedisAddNvt: RedisWrapper {
542543
/// - 'oid:<OID>:prefs': stores the plugins preferences, including the script_timeout
543544
/// (which is especial and uses preferences id 0)
544545
fn redis_add_nvt(&mut self, nvt: VTData, mtime: String) -> RedisStorageResult<()> {
546+
let filename = nvt.filename;
547+
if let Some(vt_fn) = PathBuf::from(filename.clone()).extension() && vt_fn == "inc" {
548+
let key_name = format!("signaturecheck:{filename}");
549+
self.del(&key_name)?;
550+
self.rpush(&key_name, mtime)?;
551+
return Ok(());
552+
};
553+
545554
let oid = nvt.oid;
546555
let name = nvt.name;
547556
let required_keys = nvt.required_keys.join(", ");
@@ -558,7 +567,6 @@ pub trait RedisAddNvt: RedisWrapper {
558567
.join("|");
559568
let category = (nvt.category as i64).to_string();
560569
let family = nvt.family;
561-
let filename = nvt.filename;
562570

563571
// Get the references
564572
let (cves, bids, xrefs) = Self::refs(&nvt.references);

0 commit comments

Comments
 (0)