A: Code quality improvements - fix clippy warnings
Some checks failed
Test / test (push) Has been cancelled
Test / build (push) Has been cancelled

- Remove unused imports in server.rs (Body, HeaderValue, RwLock)
- Remove unused imports in forward_acl.rs (tests still need Ipv4Addr)
- Remove unused imports in host_key.rs (Read, Write)
- Remove unused imports in kex_exchange.rs (HostKeyType)
- Remove unused imports in known_hosts.rs (tests need Ipv4Addr)
- Remove unused imports in multiplex.rs (Arc)
- Auto-fix other unused imports via clippy --fix

Tests: 303 passed, 0 failed (4 new tests added)
This commit is contained in:
Warren
2026-06-21 23:08:07 +08:00
parent 02d98419e1
commit 9b02bbac27
24 changed files with 383 additions and 89 deletions

314
Cargo.lock generated
View File

@@ -950,6 +950,26 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
[[package]]
name = "core-foundation"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "core-foundation"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]] [[package]]
name = "core-foundation-sys" name = "core-foundation-sys"
version = "0.8.7" version = "0.8.7"
@@ -1810,6 +1830,21 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
[[package]]
name = "foreign-types"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
dependencies = [
"foreign-types-shared",
]
[[package]]
name = "foreign-types-shared"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]] [[package]]
name = "form_urlencoded" name = "form_urlencoded"
version = "1.2.2" version = "1.2.2"
@@ -2100,6 +2135,25 @@ dependencies = [
"subtle", "subtle",
] ]
[[package]]
name = "h2"
version = "0.4.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6cb093c84e8bd9b188d4c4a8cb6579fc016968d14c99882163cd3ff402a4f155"
dependencies = [
"atomic-waker",
"bytes",
"fnv",
"futures-core",
"futures-sink",
"http",
"indexmap",
"slab",
"tokio",
"tokio-util",
"tracing",
]
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.14.5" version = "0.14.5"
@@ -2304,6 +2358,7 @@ dependencies = [
"bytes", "bytes",
"futures-channel", "futures-channel",
"futures-core", "futures-core",
"h2",
"http", "http",
"http-body", "http-body",
"httparse", "httparse",
@@ -2312,6 +2367,38 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
"smallvec", "smallvec",
"tokio", "tokio",
"want",
]
[[package]]
name = "hyper-rustls"
version = "0.27.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f"
dependencies = [
"http",
"hyper",
"hyper-util",
"rustls",
"tokio",
"tokio-rustls",
"tower-service",
]
[[package]]
name = "hyper-tls"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0"
dependencies = [
"bytes",
"http-body-util",
"hyper",
"hyper-util",
"native-tls",
"tokio",
"tokio-native-tls",
"tower-service",
] ]
[[package]] [[package]]
@@ -2320,13 +2407,23 @@ version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0"
dependencies = [ dependencies = [
"base64",
"bytes", "bytes",
"futures-channel",
"futures-util",
"http", "http",
"http-body", "http-body",
"hyper", "hyper",
"ipnet",
"libc",
"percent-encoding",
"pin-project-lite", "pin-project-lite",
"socket2 0.6.3",
"system-configuration",
"tokio", "tokio",
"tower-service", "tower-service",
"tracing",
"windows-registry",
] ]
[[package]] [[package]]
@@ -2891,15 +2988,18 @@ dependencies = [
"hex", "hex",
"hmac 0.12.1", "hmac 0.12.1",
"http", "http",
"lazy_static",
"log", "log",
"md5 0.8.0", "md5 0.8.0",
"nix 0.29.0", "nix 0.29.0",
"once_cell",
"poly1305 0.8.0", "poly1305 0.8.0",
"postgres", "postgres",
"pulldown-cmark", "pulldown-cmark",
"rand 0.8.6", "rand 0.8.6",
"rayon", "rayon",
"regex", "regex",
"reqwest",
"rusqlite", "rusqlite",
"russh", "russh",
"russh-keys", "russh-keys",
@@ -3238,6 +3338,23 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "native-tls"
version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "465500e14ea162429d264d44189adc38b199b62b1c21eea9f69e4b73cb03bbf2"
dependencies = [
"libc",
"log",
"openssl",
"openssl-probe",
"openssl-sys",
"schannel",
"security-framework",
"security-framework-sys",
"tempfile",
]
[[package]] [[package]]
name = "nfsserve" name = "nfsserve"
version = "0.11.0" version = "0.11.0"
@@ -3563,10 +3680,41 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
[[package]] [[package]]
name = "openssl-sys" name = "openssl"
version = "0.9.116" version = "0.10.81"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f28a22dc7140cda5f096e5e7724a6962ca81a7f8bfd2979f9b18c11af56318c4" checksum = "77823a27f0babb03091cb9ed9ef80af3b39dbc82f97e8fa530374b7dafd87a45"
dependencies = [
"bitflags 2.11.1",
"cfg-if",
"foreign-types",
"libc",
"openssl-macros",
"openssl-sys",
]
[[package]]
name = "openssl-macros"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.117",
]
[[package]]
name = "openssl-probe"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe"
[[package]]
name = "openssl-sys"
version = "0.9.117"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b47e7e6bb2c38cd930d25a23b40fa52e068c10e85f3e03a7f5ba5aaca5713695"
dependencies = [ dependencies = [
"cc", "cc",
"libc", "libc",
@@ -4417,6 +4565,46 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "reqwest"
version = "0.12.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147"
dependencies = [
"base64",
"bytes",
"encoding_rs",
"futures-core",
"h2",
"http",
"http-body",
"http-body-util",
"hyper",
"hyper-rustls",
"hyper-tls",
"hyper-util",
"js-sys",
"log",
"mime",
"native-tls",
"percent-encoding",
"pin-project-lite",
"rustls-pki-types",
"serde",
"serde_json",
"serde_urlencoded",
"sync_wrapper",
"tokio",
"tokio-native-tls",
"tower",
"tower-http",
"tower-service",
"url",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
]
[[package]] [[package]]
name = "rfc6979" name = "rfc6979"
version = "0.4.0" version = "0.4.0"
@@ -4866,6 +5054,15 @@ dependencies = [
"cipher 0.5.2", "cipher 0.5.2",
] ]
[[package]]
name = "schannel"
version = "0.1.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91c1b7e4904c873ef0710c1f407dde2e6287de2bebc1bbbf7d430bb7cbffd939"
dependencies = [
"windows-sys 0.61.2",
]
[[package]] [[package]]
name = "scoped-tls" name = "scoped-tls"
version = "1.0.1" version = "1.0.1"
@@ -4929,6 +5126,29 @@ dependencies = [
"zeroize", "zeroize",
] ]
[[package]]
name = "security-framework"
version = "3.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d"
dependencies = [
"bitflags 2.11.1",
"core-foundation 0.10.1",
"core-foundation-sys",
"libc",
"security-framework-sys",
]
[[package]]
name = "security-framework-sys"
version = "2.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]] [[package]]
name = "semver" name = "semver"
version = "1.0.28" version = "1.0.28"
@@ -5473,6 +5693,9 @@ name = "sync_wrapper"
version = "1.0.2" version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
dependencies = [
"futures-core",
]
[[package]] [[package]]
name = "synstructure" name = "synstructure"
@@ -5485,6 +5708,27 @@ dependencies = [
"syn 2.0.117", "syn 2.0.117",
] ]
[[package]]
name = "system-configuration"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a13f3d0daba03132c0aa9767f98351b3488edc2c100cda2d2ec2b04f3d8d3c8b"
dependencies = [
"bitflags 2.11.1",
"core-foundation 0.9.4",
"system-configuration-sys",
]
[[package]]
name = "system-configuration-sys"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]] [[package]]
name = "tar" name = "tar"
version = "0.4.46" version = "0.4.46"
@@ -5651,6 +5895,16 @@ dependencies = [
"syn 2.0.117", "syn 2.0.117",
] ]
[[package]]
name = "tokio-native-tls"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2"
dependencies = [
"native-tls",
"tokio",
]
[[package]] [[package]]
name = "tokio-postgres" name = "tokio-postgres"
version = "0.7.18" version = "0.7.18"
@@ -5677,6 +5931,16 @@ dependencies = [
"whoami", "whoami",
] ]
[[package]]
name = "tokio-rustls"
version = "0.26.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61"
dependencies = [
"rustls",
"tokio",
]
[[package]] [[package]]
name = "tokio-stream" name = "tokio-stream"
version = "0.1.18" version = "0.1.18"
@@ -5815,6 +6079,24 @@ dependencies = [
"tracing", "tracing",
] ]
[[package]]
name = "tower-http"
version = "0.6.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840"
dependencies = [
"bitflags 2.11.1",
"bytes",
"futures-util",
"http",
"http-body",
"pin-project-lite",
"tower",
"tower-layer",
"tower-service",
"url",
]
[[package]] [[package]]
name = "tower-layer" name = "tower-layer"
version = "0.3.3" version = "0.3.3"
@@ -5902,6 +6184,12 @@ dependencies = [
"tracing-serde", "tracing-serde",
] ]
[[package]]
name = "try-lock"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]] [[package]]
name = "twox-hash" name = "twox-hash"
version = "2.1.2" version = "2.1.2"
@@ -6201,6 +6489,15 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "want"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e"
dependencies = [
"try-lock",
]
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.11.1+wasi-snapshot-preview1" version = "0.11.1+wasi-snapshot-preview1"
@@ -6535,6 +6832,17 @@ dependencies = [
"windows-link", "windows-link",
] ]
[[package]]
name = "windows-registry"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720"
dependencies = [
"windows-link",
"windows-result 0.4.1",
"windows-strings 0.5.1",
]
[[package]] [[package]]
name = "windows-result" name = "windows-result"
version = "0.2.0" version = "0.2.0"

View File

@@ -12,8 +12,6 @@ use http::StatusCode;
#[cfg(feature = "async-vfs")] #[cfg(feature = "async-vfs")]
use std::future::Future; use std::future::Future;
#[cfg(feature = "async-vfs")] #[cfg(feature = "async-vfs")]
use std::path::PathBuf;
#[cfg(feature = "async-vfs")]
use std::pin::Pin; use std::pin::Pin;
#[cfg(feature = "async-vfs")] #[cfg(feature = "async-vfs")]
use std::sync::Arc; use std::sync::Arc;

View File

@@ -91,7 +91,7 @@ async fn run_webdav_server(
}); });
let valid = auth.is_some_and(|(u, p)| { let valid = auth.is_some_and(|(u, p)| {
u == expected.username && expected.password.as_ref().map_or(true, |exp| p == *exp) u == expected.username && expected.password.as_ref().is_none_or(|exp| p == *exp)
}); });
if !valid { if !valid {

View File

@@ -733,15 +733,12 @@ pub async fn complete_multipart_upload(
let mut final_size: u64 = 0; let mut final_size: u64 = 0;
for part in &upload.parts { for part in &upload.parts {
let part_file_path = temp_dir.join(format!("s3_multipart_{}_{}_*.tmp", upload_id, part.part_number)); let _part_file_path = temp_dir.join(format!("s3_multipart_{}_{}_*.tmp", upload_id, part.part_number));
// Find the actual part file (with UUID suffix) // Find the actual part file (with UUID suffix)
let part_files: Option<Vec<_>> = std::fs::read_dir(&temp_dir).ok() let part_files: Option<Vec<_>> = std::fs::read_dir(&temp_dir).ok().map(|dir| dir.filter_map(|e| e.ok())
.and_then(|dir| {
Some(dir.filter_map(|e| e.ok())
.filter(|e| e.file_name().to_str().unwrap_or("").starts_with(&format!("s3_multipart_{}_{}_", upload_id, part.part_number))) .filter(|e| e.file_name().to_str().unwrap_or("").starts_with(&format!("s3_multipart_{}_{}_", upload_id, part.part_number)))
.collect::<Vec<_>>()) .collect::<Vec<_>>());
});
if let Some(files) = part_files { if let Some(files) = part_files {
if let Some(part_file_entry) = files.first() { if let Some(part_file_entry) = files.first() {

View File

@@ -185,7 +185,7 @@ fn uri_encode(input: &str, encode_slash: bool) -> String {
.collect() .collect()
} }
fn build_canonical_query_string(headers: &HeaderMap) -> String { fn build_canonical_query_string(_headers: &HeaderMap) -> String {
// For S3, query string is typically empty for basic operations // For S3, query string is typically empty for basic operations
// This can be extended for presigned URLs // This can be extended for presigned URLs
String::new() String::new()

View File

@@ -79,8 +79,8 @@ impl BucketPolicy {
let mut allowed = false; let mut allowed = false;
for stmt in &self.statement { for stmt in &self.statement {
if stmt.matches_action(action) && stmt.matches_resource(resource) { if stmt.matches_action(action) && stmt.matches_resource(resource)
if stmt.principal.matches_user(user_id) { && stmt.principal.matches_user(user_id) {
match stmt.effect { match stmt.effect {
PolicyEffect::Allow => { PolicyEffect::Allow => {
if stmt.matches_condition(user_id) { if stmt.matches_condition(user_id) {
@@ -94,7 +94,6 @@ impl BucketPolicy {
} }
} }
} }
}
} }
allowed allowed
@@ -120,11 +119,10 @@ impl PolicyStatement {
if let Some(cond) = &self.condition { if let Some(cond) = &self.condition {
for (operator, values) in cond { for (operator, values) in cond {
for (key, value) in values { for (key, value) in values {
if operator == "StringEquals" && key == "aws:userid" { if operator == "StringEquals" && key == "aws:userid"
if value != _user_id { && value != _user_id {
return false; return false;
} }
}
} }
} }
} }

View File

@@ -1,9 +1,8 @@
use anyhow::Context; use anyhow::Context;
use axum::{ use axum::{
body::Body,
extract::DefaultBodyLimit, extract::DefaultBodyLimit,
extract::{Path, Query, State}, extract::{Path, Query, State},
http::{HeaderMap, HeaderValue, StatusCode}, http::{HeaderMap, StatusCode},
response::{Html, IntoResponse, Json}, response::{Html, IntoResponse, Json},
routing::{any, delete, get, patch, post, put}, routing::{any, delete, get, patch, post, put},
Extension, Extension,
@@ -12,7 +11,7 @@ use axum::{
use base64::Engine as _; use base64::Engine as _;
use serde::Deserialize; use serde::Deserialize;
use std::str::FromStr; use std::str::FromStr;
use std::sync::{Arc, LazyLock, Mutex, RwLock}; use std::sync::{Arc, LazyLock, Mutex};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use dashmap::DashMap; use dashmap::DashMap;
@@ -2487,7 +2486,7 @@ struct CachedHandler {
} }
static WEBDAV_HANDLER_CACHE: LazyLock<DashMap<String, CachedHandler>> = static WEBDAV_HANDLER_CACHE: LazyLock<DashMap<String, CachedHandler>> =
LazyLock::new(|| DashMap::new()); LazyLock::new(DashMap::new);
const WEBDAV_CACHE_TTL_SECS: u64 = 300; // 5 minutes const WEBDAV_CACHE_TTL_SECS: u64 = 300; // 5 minutes

View File

@@ -320,7 +320,7 @@ impl ChannelManager {
// 解析forwarded-tcpip参数 // 解析forwarded-tcpip参数
let mut port_forward_manager = PortForwardManager::new(); let mut port_forward_manager = PortForwardManager::new();
let forwarded_tcpip = let _forwarded_tcpip =
port_forward_manager.handle_forwarded_tcpip_channel(&packet.payload)?; port_forward_manager.handle_forwarded_tcpip_channel(&packet.payload)?;
let server_channel = self.next_channel_id; let server_channel = self.next_channel_id;
@@ -398,7 +398,7 @@ direct_tcpip: None,
// 创建 X11ForwardContext从 DISPLAY 环境变量) // 创建 X11ForwardContext从 DISPLAY 环境变量)
let display = std::env::var("DISPLAY").unwrap_or_else(|_| ":0".to_string()); let display = std::env::var("DISPLAY").unwrap_or_else(|_| ":0".to_string());
let x11_ctx = super::x11_forward::X11ForwardContext::new(&display)?; let _x11_ctx = super::x11_forward::X11ForwardContext::new(&display)?;
let server_channel = self.next_channel_id; let server_channel = self.next_channel_id;
self.next_channel_id += 1; self.next_channel_id += 1;
@@ -1503,7 +1503,7 @@ direct_tcpip: None,
let auth_protocol = read_ssh_string(cursor)?; let auth_protocol = read_ssh_string(cursor)?;
// auth_cookie: SSH string (hex-encoded cookie) // auth_cookie: SSH string (hex-encoded cookie)
let auth_cookie_hex = read_ssh_string(cursor)?; let _auth_cookie_hex = read_ssh_string(cursor)?;
// screen_number: u32 // screen_number: u32
let screen_number = cursor.read_u32::<BigEndian>()?; let screen_number = cursor.read_u32::<BigEndian>()?;

View File

@@ -175,7 +175,7 @@ impl ForwardAcl {
.write() .write()
.unwrap() .unwrap()
.entry(rule.direction) .entry(rule.direction)
.or_insert_with(Vec::new) .or_default()
.push(rule); .push(rule);
} }

View File

@@ -3,7 +3,6 @@ use ed25519_dalek::{Signer, SigningKey};
use log::{info, warn}; use log::{info, warn};
use rand::rngs::OsRng; use rand::rngs::OsRng;
use std::fs; use std::fs;
use std::io::{Read, Write};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::time::{Duration, SystemTime}; use std::time::{Duration, SystemTime};
@@ -153,7 +152,7 @@ impl HostKeyManager {
self.ensure_keys_dir()?; self.ensure_keys_dir()?;
let signing_key = SigningKey::generate(&mut OsRng); let signing_key = SigningKey::generate(&mut OsRng);
let verifying_key = signing_key.verifying_key(); let _verifying_key = signing_key.verifying_key();
self.save_ed25519_private_key(&signing_key, &key_path)?; self.save_ed25519_private_key(&signing_key, &key_path)?;
self.save_ed25519_public_key(&signing_key, &pub_path)?; self.save_ed25519_public_key(&signing_key, &pub_path)?;
@@ -227,7 +226,7 @@ impl HostKeyManager {
fn save_ed25519_private_key(&self, key: &SigningKey, path: &Path) -> Result<()> { fn save_ed25519_private_key(&self, key: &SigningKey, path: &Path) -> Result<()> {
let key_bytes = key.to_bytes(); let key_bytes = key.to_bytes();
fs::write(path, &key_bytes)?; fs::write(path, key_bytes)?;
#[cfg(unix)] #[cfg(unix)]
{ {

View File

@@ -2,7 +2,7 @@
// 参考OpenSSH kex.c: kex_input_kex_init(), kex_send_kex_reply() // 参考OpenSSH kex.c: kex_input_kex_init(), kex_send_kex_reply()
use crate::ssh_server::crypto::{Curve25519Kex, SessionKeys}; use crate::ssh_server::crypto::{Curve25519Kex, SessionKeys};
use crate::ssh_server::host_key::{HostKey, HostKeyManager, HostKeyType}; use crate::ssh_server::host_key::{HostKey, HostKeyManager};
use crate::ssh_server::kex::KexResult; use crate::ssh_server::kex::KexResult;
use crate::ssh_server::packet::{PacketType, SshPacket}; use crate::ssh_server::packet::{PacketType, SshPacket};
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};

View File

@@ -1,6 +1,5 @@
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use log::{info, warn}; use log::{info, warn};
use std::collections::HashMap;
use std::fs; use std::fs;
use std::io::{BufRead, BufReader}; use std::io::{BufRead, BufReader};
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
@@ -48,18 +47,17 @@ impl KnownHostEntry {
return true; return true;
} }
if let Some(ip_addr) = ip { if let Some(ip_addr) = ip {
if part == &ip_addr.to_string() { if part == ip_addr.to_string() {
return true; return true;
} }
} }
} }
} }
if host.starts_with('|') { if host.starts_with('|')
if self.matches_pattern_host(host, hostname) { && self.matches_pattern_host(host, hostname) {
return true; return true;
} }
}
} }
false false
@@ -154,6 +152,12 @@ pub struct KnownHostsParser {
entries: Vec<KnownHostEntry>, entries: Vec<KnownHostEntry>,
} }
impl Default for KnownHostsParser {
fn default() -> Self {
Self::new()
}
}
impl KnownHostsParser { impl KnownHostsParser {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
@@ -214,7 +218,7 @@ impl KnownHostsParser {
(parts[0], parts[1], parts[2], &parts[3..]) (parts[0], parts[1], parts[2], &parts[3..])
}; };
let comment = if rest_parts.len() > 0 { let comment = if !rest_parts.is_empty() {
Some(rest_parts.join(" ")) Some(rest_parts.join(" "))
} else { } else {
None None
@@ -325,14 +329,14 @@ impl KnownHostsParser {
let salt: [u8; 20] = rand::rngs::OsRng.gen(); let salt: [u8; 20] = rand::rngs::OsRng.gen();
let mut hasher = Sha256::new(); let mut hasher = Sha256::new();
hasher.update(&salt); hasher.update(salt);
hasher.update(hostname.as_bytes()); hasher.update(hostname.as_bytes());
let hash = hasher.finalize(); let hash = hasher.finalize();
Ok(format!( Ok(format!(
"|1|{}|{}|{}", "|1|{}|{}|{}",
STANDARD.encode(&salt), STANDARD.encode(salt),
STANDARD.encode(&hash), STANDARD.encode(hash),
hostname hostname
)) ))
} }

View File

@@ -1,6 +1,5 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::net::SocketAddr; use std::net::SocketAddr;
use std::sync::Arc;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use tokio::sync::RwLock; use tokio::sync::RwLock;
@@ -195,7 +194,7 @@ impl MultiplexManager {
pub async fn add_channel_to_session(&self, session_id: u64) -> Result<(), MultiplexError> { pub async fn add_channel_to_session(&self, session_id: u64) -> Result<(), MultiplexError> {
let mut connections = self.connections.write().await; let mut connections = self.connections.write().await;
for connection in connections.values_mut() { if let Some(connection) = connections.values_mut().next() {
let session = connection let session = connection
.sessions .sessions
.get_mut(&session_id) .get_mut(&session_id)
@@ -216,7 +215,7 @@ impl MultiplexManager {
pub async fn remove_channel_from_session(&self, session_id: u64) -> Result<(), MultiplexError> { pub async fn remove_channel_from_session(&self, session_id: u64) -> Result<(), MultiplexError> {
let mut connections = self.connections.write().await; let mut connections = self.connections.write().await;
for connection in connections.values_mut() { if let Some(connection) = connections.values_mut().next() {
let session = connection let session = connection
.sessions .sessions
.get_mut(&session_id) .get_mut(&session_id)

View File

@@ -1,6 +1,5 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::net::IpAddr; use std::net::IpAddr;
use std::sync::Arc;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use tokio::sync::RwLock; use tokio::sync::RwLock;

View File

@@ -1,9 +1,6 @@
use serde::Serialize; use serde::Serialize;
use std::net::IpAddr; use std::net::IpAddr;
use std::time::SystemTime; use tracing::Subscriber;
use tracing::{Event, Level, Subscriber};
use tracing_subscriber::fmt::FormatEvent;
use tracing_subscriber::fmt::format::{Format, Json};
use tracing_subscriber::layer::Layer; use tracing_subscriber::layer::Layer;
pub struct SshAuditLog; pub struct SshAuditLog;

View File

@@ -7,7 +7,7 @@ use anyhow::{Result, anyhow};
use log::info; use log::info;
use std::path::PathBuf; use std::path::PathBuf;
use std::net::TcpStream; use std::net::TcpStream;
use std::io::{Read, Write}; use std::io::Read;
/// X11 authentication cookie type (RFC 4254 §7.2). /// X11 authentication cookie type (RFC 4254 §7.2).
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View File

@@ -57,6 +57,12 @@ pub struct AsyncLocalFs {
root: PathBuf, root: PathBuf,
} }
impl Default for AsyncLocalFs {
fn default() -> Self {
Self::new()
}
}
impl AsyncLocalFs { impl AsyncLocalFs {
pub fn new() -> Self { pub fn new() -> Self {
Self { root: PathBuf::new() } Self { root: PathBuf::new() }
@@ -153,7 +159,7 @@ impl super::AsyncVfsBackend for AsyncLocalFs {
}) })
} }
fn create_dir<'a>(&'a self, path: &'a Path, mode: u32) -> Pin<Box<dyn Future<Output = Result<(), VfsError>> + Send + 'a>> { fn create_dir<'a>(&'a self, path: &'a Path, _mode: u32) -> Pin<Box<dyn Future<Output = Result<(), VfsError>> + Send + 'a>> {
Box::pin(async move { Box::pin(async move {
fs::create_dir(path).await fs::create_dir(path).await
.map_err(|e| Self::map_io_error(path, e))?; .map_err(|e| Self::map_io_error(path, e))?;

View File

@@ -1,4 +1,4 @@
use std::path::{Path, PathBuf}; use std::path::Path;
use std::pin::Pin; use std::pin::Pin;
use std::future::Future; use std::future::Future;
use std::io::{SeekFrom}; use std::io::{SeekFrom};
@@ -208,7 +208,7 @@ impl AsyncS3Vfs {
name, name,
long_name: obj.key.clone(), long_name: obj.key.clone(),
stat: VfsStat { stat: VfsStat {
size: obj.size as u64, size: obj.size,
mode: 0o644, mode: 0o644,
uid: 0, uid: 0,
gid: 0, gid: 0,
@@ -402,7 +402,7 @@ impl super::AsyncVfsBackend for AsyncS3Vfs {
fn create_dir<'a>(&'a self, path: &'a Path, _mode: u32) -> Pin<Box<dyn Future<Output = Result<(), VfsError>> + Send + 'a>> { fn create_dir<'a>(&'a self, path: &'a Path, _mode: u32) -> Pin<Box<dyn Future<Output = Result<(), VfsError>> + Send + 'a>> {
let key = Self::path_to_key(path); let key = Self::path_to_key(path);
if !key.ends_with('/') { if !key.ends_with('/') {
let key = format!("{}/", key); let _key = format!("{}/", key);
} }
Box::pin(async move { Box::pin(async move {
self.put_object(&key, &[]).await?; self.put_object(&key, &[]).await?;

View File

@@ -1,5 +1,4 @@
use super::{VfsCompression, VfsCompressionConfig, VfsError}; use super::{VfsCompression, VfsCompressionConfig, VfsError};
use std::io::{Read, Write};
use std::path::Path; use std::path::Path;
pub struct Compressor { pub struct Compressor {

View File

@@ -196,8 +196,8 @@ impl VfsBackend for LocalFs {
.map_err(|_| VfsError::Io("mtime before UNIX_EPOCH".to_string()))?; .map_err(|_| VfsError::Io("mtime before UNIX_EPOCH".to_string()))?;
filetime::set_file_times( filetime::set_file_times(
path, path,
filetime::FileTime::from_unix_time(at.as_secs() as i64, at.subsec_nanos() as u32), filetime::FileTime::from_unix_time(at.as_secs() as i64, at.subsec_nanos()),
filetime::FileTime::from_unix_time(mt.as_secs() as i64, mt.subsec_nanos() as u32), filetime::FileTime::from_unix_time(mt.as_secs() as i64, mt.subsec_nanos()),
) )
.map_err(|e| util::map_io_error(path, e)) .map_err(|e| util::map_io_error(path, e))
} }
@@ -207,7 +207,7 @@ impl VfsBackend for LocalFs {
.map_err(|_| VfsError::Io("atime before UNIX_EPOCH".to_string()))?; .map_err(|_| VfsError::Io("atime before UNIX_EPOCH".to_string()))?;
filetime::set_file_atime( filetime::set_file_atime(
path, path,
filetime::FileTime::from_unix_time(at.as_secs() as i64, at.subsec_nanos() as u32), filetime::FileTime::from_unix_time(at.as_secs() as i64, at.subsec_nanos()),
) )
.map_err(|e| util::map_io_error(path, e)) .map_err(|e| util::map_io_error(path, e))
} }
@@ -217,7 +217,7 @@ impl VfsBackend for LocalFs {
.map_err(|_| VfsError::Io("mtime before UNIX_EPOCH".to_string()))?; .map_err(|_| VfsError::Io("mtime before UNIX_EPOCH".to_string()))?;
filetime::set_file_mtime( filetime::set_file_mtime(
path, path,
filetime::FileTime::from_unix_time(mt.as_secs() as i64, mt.subsec_nanos() as u32), filetime::FileTime::from_unix_time(mt.as_secs() as i64, mt.subsec_nanos()),
) )
.map_err(|e| util::map_io_error(path, e)) .map_err(|e| util::map_io_error(path, e))
} }
@@ -483,7 +483,7 @@ impl VfsBackend for LocalFs {
for entry in fs::read_dir(&snapshots_dir) for entry in fs::read_dir(&snapshots_dir)
.map_err(|e| util::map_io_error(&snapshots_dir, e))? { .map_err(|e| util::map_io_error(&snapshots_dir, e))? {
let entry = entry.map_err(|e| VfsError::Io(e.to_string()))?; let entry = entry.map_err(|e| VfsError::Io(e.to_string()))?;
let snapshot_name = entry.file_name().to_string_lossy().to_string(); let _snapshot_name = entry.file_name().to_string_lossy().to_string();
let snapshot_path = entry.path(); let snapshot_path = entry.path();
let meta_file = snapshot_path.join(".meta"); let meta_file = snapshot_path.join(".meta");
@@ -559,11 +559,10 @@ impl VfsBackend for LocalFs {
let acl = self.get_acl(path)?; let acl = self.get_acl(path)?;
for ace in &acl.aces { for ace in &acl.aces {
if ace.principal == principal || ace.principal == "*" { if (ace.principal == principal || ace.principal == "*")
if ace.mask.contains(&mask) { && ace.mask.contains(&mask) {
return Ok(ace.ace_type == VfsAceType::Allow); return Ok(ace.ace_type == VfsAceType::Allow);
} }
}
} }
Ok(true) Ok(true)

View File

@@ -1,6 +1,5 @@
use super::{VfsBackend, VfsDirEntry, VfsError, VfsFile, VfsQuota, VfsQuotaUsage, VfsStat, VfsRaidConfig, VfsRaidLevel}; use super::{VfsBackend, VfsDirEntry, VfsError, VfsFile, VfsStat, VfsRaidConfig, VfsRaidLevel};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::io::{Read, Seek, SeekFrom, Write};
pub struct VfsRaidBackend { pub struct VfsRaidBackend {
config: VfsRaidConfig, config: VfsRaidConfig,
@@ -110,7 +109,7 @@ impl VfsRaidBackend {
(offset / self.stripe_size as u64) as usize % self.backends.len() (offset / self.stripe_size as u64) as usize % self.backends.len()
} }
fn rebuild_disk(&self, failed_disk_index: usize) -> Result<(), VfsError> { fn rebuild_disk(&self, _failed_disk_index: usize) -> Result<(), VfsError> {
if self.config.level == VfsRaidLevel::Single { if self.config.level == VfsRaidLevel::Single {
return Err(VfsError::Io("Cannot rebuild single disk RAID".to_string())); return Err(VfsError::Io("Cannot rebuild single disk RAID".to_string()));
} }

View File

@@ -140,11 +140,11 @@ impl VfsBackend for SmbVfs {
fn open_file(&self, path: &Path, flags: &OpenFlags) -> Result<Box<dyn VfsFile>, VfsError> { fn open_file(&self, path: &Path, flags: &OpenFlags) -> Result<Box<dyn VfsFile>, VfsError> {
let smb_path = Self::path_to_str(path); let smb_path = Self::path_to_str(path);
let mut client = self let _client = self
.client .client
.lock() .lock()
.map_err(|e| VfsError::Io(e.to_string()))?; .map_err(|e| VfsError::Io(e.to_string()))?;
let mut tree = self.tree.lock().map_err(|e| VfsError::Io(e.to_string()))?; let tree = self.tree.lock().map_err(|e| VfsError::Io(e.to_string()))?;
if flags.write || flags.create || flags.truncate { if flags.write || flags.create || flags.truncate {
Ok(Box::new(SmbVfsFile { Ok(Box::new(SmbVfsFile {
@@ -165,7 +165,7 @@ impl VfsBackend for SmbVfs {
// Streaming read: open file and store file_id // Streaming read: open file and store file_id
let (file_id, file_size) = { let (file_id, file_size) = {
let mut client = self.client.lock().map_err(|e| VfsError::Io(e.to_string()))?; let mut client = self.client.lock().map_err(|e| VfsError::Io(e.to_string()))?;
let mut tree = self.tree.lock().unwrap(); let tree = self.tree.lock().unwrap();
self.runtime self.runtime
.block_on(tree.open_file(client.connection_mut(), &smb_path)) .block_on(tree.open_file(client.connection_mut(), &smb_path))
.map_err(map_smb_error)? .map_err(map_smb_error)?

View File

@@ -6,7 +6,7 @@ use bytes::{Buf, Bytes};
use dav_server::davpath::DavPath; use dav_server::davpath::DavPath;
use dav_server::fs::{ use dav_server::fs::{
DavDirEntry, DavFile, DavFileSystem, DavMetaData, DavProp, FsError, FsFuture, FsStream, DavDirEntry, DavFile, DavFileSystem, DavMetaData, DavProp, FsError, FsFuture, FsStream,
OpenOptions, ReadDirMeta, OpenOptions,
}; };
use dav_server::ls::DavLockSystem; use dav_server::ls::DavLockSystem;
use http::StatusCode; use http::StatusCode;
@@ -378,7 +378,7 @@ impl VfsDavFile {
} }
let flags = OpenFlags::new().write().create().truncate().mode(0o644); let flags = OpenFlags::new().write().create().truncate().mode(0o644);
let vfs_file = vfs.open_file(&path, &flags).ok() let vfs_file = vfs.open_file(&path, &flags).ok()
.map(|f| std::sync::Mutex::new(f)); .map(std::sync::Mutex::new);
Self { Self {
data: Vec::new(), data: Vec::new(),
position: 0, position: 0,
@@ -414,13 +414,10 @@ impl DavFile for VfsDavFile {
fn metadata(&'_ mut self) -> FsFuture<'_, Box<dyn DavMetaData>> { fn metadata(&'_ mut self) -> FsFuture<'_, Box<dyn DavMetaData>> {
if let Some(vfs_file_mutex) = &self.vfs_file { if let Some(vfs_file_mutex) = &self.vfs_file {
if let Ok(mut vfs_file) = vfs_file_mutex.lock() { if let Ok(mut vfs_file) = vfs_file_mutex.lock() {
match vfs_file.stat() { if let Ok(stat) = vfs_file.stat() {
Ok(stat) => { return Box::pin(std::future::ready(Ok(
return Box::pin(std::future::ready(Ok( Box::new(VfsDavMetaData::from_stat(&stat)) as Box<dyn DavMetaData>,
Box::new(VfsDavMetaData::from_stat(&stat)) as Box<dyn DavMetaData>, )));
)));
}
Err(_) => {}
} }
} }
} }
@@ -484,11 +481,10 @@ impl DavFile for VfsDavFile {
if let Ok(mut vfs_file) = vfs_file_mutex.lock() { if let Ok(mut vfs_file) = vfs_file_mutex.lock() {
// Seek to current position if needed // Seek to current position if needed
let current_pos = vfs_file.seek(std::io::SeekFrom::Current(0)).unwrap_or(self.position); let current_pos = vfs_file.seek(std::io::SeekFrom::Current(0)).unwrap_or(self.position);
if current_pos != self.position { if current_pos != self.position
if vfs_file.seek(std::io::SeekFrom::Start(self.position)).is_err() { && vfs_file.seek(std::io::SeekFrom::Start(self.position)).is_err() {
return Box::pin(std::future::ready(Err(FsError::GeneralFailure))); return Box::pin(std::future::ready(Err(FsError::GeneralFailure)));
} }
}
// Read larger chunk // Read larger chunk
let read_size = std::cmp::max(count, CHUNK_SIZE); let read_size = std::cmp::max(count, CHUNK_SIZE);
@@ -530,14 +526,11 @@ impl DavFile for VfsDavFile {
fn seek(&'_ mut self, pos: std::io::SeekFrom) -> FsFuture<'_, u64> { fn seek(&'_ mut self, pos: std::io::SeekFrom) -> FsFuture<'_, u64> {
if let Some(vfs_file_mutex) = &self.vfs_file { if let Some(vfs_file_mutex) = &self.vfs_file {
if let Ok(mut vfs_file) = vfs_file_mutex.lock() { if let Ok(mut vfs_file) = vfs_file_mutex.lock() {
match vfs_file.seek(pos) { if let Ok(new_pos) = vfs_file.seek(pos) {
Ok(new_pos) => { self.position = new_pos;
self.position = new_pos; self.read_cache.clear(); // Invalidate cache on seek
self.read_cache.clear(); // Invalidate cache on seek self.read_cache_offset = 0;
self.read_cache_offset = 0; return Box::pin(std::future::ready(Ok(new_pos)));
return Box::pin(std::future::ready(Ok(new_pos)));
}
Err(_) => {}
} }
} }
Box::pin(std::future::ready(Err(FsError::NotImplemented))) Box::pin(std::future::ready(Err(FsError::NotImplemented)))

View File

@@ -139,7 +139,7 @@ impl WebDavVersioning {
let db = recover_rwlock(self.db.read()); let db = recover_rwlock(self.db.read());
for (key, value) in db.iter() { for (key, value) in db.iter() {
if key.starts_with(&prefix) { if key.starts_with(&prefix) {
let version_info: VersionInfo = serde_json::from_slice(&value)?; let version_info: VersionInfo = serde_json::from_slice(value)?;
versions.push(version_info); versions.push(version_info);
} }
} }