diff --git a/knock-cli/Cargo.toml b/knock-cli/Cargo.toml index 40233ec..6a382e7 100644 --- a/knock-cli/Cargo.toml +++ b/knock-cli/Cargo.toml @@ -11,6 +11,7 @@ license = "Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +anyhow = "1.0.80" clap = { version = "4.5.1", features = ["derive"] } log = "0.4.21" pretty_env_logger = "0.5.0" diff --git a/knock-cli/src/config/mod.rs b/knock-cli/src/config/mod.rs index 1844075..2883392 100644 --- a/knock-cli/src/config/mod.rs +++ b/knock-cli/src/config/mod.rs @@ -1,3 +1,4 @@ +use anyhow::Result; use std::fs::File; use std::io::Read; @@ -5,7 +6,7 @@ pub use config::Config; pub use config::Rule; pub mod config; -pub fn load_config(path: &str) -> Result> { +pub fn load_config(path: &str) -> Result { let mut file = File::open(path)?; let mut content = String::new(); diff --git a/knock-cli/src/main.rs b/knock-cli/src/main.rs index 1be5247..f44884f 100644 --- a/knock-cli/src/main.rs +++ b/knock-cli/src/main.rs @@ -1,3 +1,4 @@ +use anyhow::Result; use clap::Parser; use log::{error, LevelFilter}; use pretty_env_logger::env_logger::Builder; @@ -16,7 +17,7 @@ struct Args { rule: Option, } -fn main() -> Result<(), Box> { +fn main() -> Result<()> { let args = Args::parse(); Builder::new() diff --git a/knock-cli/src/rule.rs b/knock-cli/src/rule.rs index b6bc88f..7cd4bc0 100644 --- a/knock-cli/src/rule.rs +++ b/knock-cli/src/rule.rs @@ -1,5 +1,6 @@ use crate::config::Config; use crate::config::Rule; +use anyhow::Result; use log::{error, info}; use std::collections::HashMap; use std::net::{SocketAddr, TcpStream, ToSocketAddrs}; @@ -20,7 +21,7 @@ impl RuleExecutor { RuleExecutor { rules } } - pub fn run(&self, name: &str) -> Result<(), Box> { + pub fn run(&self, name: &str) -> Result<()> { if let Some(rule) = self.rules.get(name) { info!("Executing rule: {}", rule.name); // Iterate over the ports and attempt to connect to each diff --git a/knockd/Cargo.toml b/knockd/Cargo.toml index 7dda560..99aee43 100644 --- a/knockd/Cargo.toml +++ b/knockd/Cargo.toml @@ -11,6 +11,7 @@ license = "Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +anyhow = "1.0.80" clap = { version = "4.5.1", features = ["derive"] } log = "0.4.21" pnet = "0.34.0" diff --git a/knockd/src/config/mod.rs b/knockd/src/config/mod.rs index 91f0f92..c18820f 100644 --- a/knockd/src/config/mod.rs +++ b/knockd/src/config/mod.rs @@ -1,10 +1,11 @@ +use anyhow::Result; use std::fs::File; use std::io::Read; pub use config::Config; pub mod config; -pub fn load_config(path: &str) -> Result> { +pub fn load_config(path: &str) -> Result { let mut file = File::open(path)?; let mut content = String::new(); diff --git a/knockd/src/executor.rs b/knockd/src/executor.rs index 158e456..532c093 100644 --- a/knockd/src/executor.rs +++ b/knockd/src/executor.rs @@ -1,6 +1,7 @@ +use anyhow::Result; use std::process::Command; -pub fn execute_command(command: &str) -> Result<(), Box> { +pub fn execute_command(command: &str) -> Result<()> { let mut parts = command.split_whitespace(); let command = parts.next().unwrap(); let args = parts; diff --git a/knockd/src/main.rs b/knockd/src/main.rs index ce3eae5..2329955 100644 --- a/knockd/src/main.rs +++ b/knockd/src/main.rs @@ -1,3 +1,4 @@ +use anyhow::Result; use clap::Parser; use log::LevelFilter; use pretty_env_logger::env_logger::Builder; @@ -17,7 +18,7 @@ struct Args { config: String, } -fn main() -> Result<(), Box> { +fn main() -> Result<()> { let args = Args::parse(); // Initialize the logger diff --git a/knockd/src/server/server.rs b/knockd/src/server/server.rs index d19ca5b..30eae2e 100644 --- a/knockd/src/server/server.rs +++ b/knockd/src/server/server.rs @@ -1,5 +1,6 @@ extern crate pnet; +use crate::sequence::SequenceDetector; use pnet::datalink::Channel::Ethernet; use pnet::datalink::{self, NetworkInterface}; use pnet::packet::ethernet::{EtherTypes, EthernetPacket}; @@ -7,8 +8,6 @@ use pnet::packet::ip::IpNextHeaderProtocols; use pnet::packet::tcp::TcpPacket; use pnet::packet::Packet; -use crate::sequence::SequenceDetector; - pub struct Server { interface_name: String, detector: Box,