Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion smb/src/protocol/body/create/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl SMBCreateRequest {
// TODO make this the right error code
return Err(SMBError::response_error(NTStatus::NotSupported));
}
Ok((&self.file_name(), self.disposition(), self.create_options.contains(SMBCreateOptions::DIRECTORY_FILE)))
Ok((self.file_name(), self.disposition(), self.create_options.contains(SMBCreateOptions::DIRECTORY_FILE)))
}
}

Expand Down
10 changes: 10 additions & 0 deletions smb/src/protocol/body/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ pub struct SMBErrorResponse {
error_data: PhantomData<Vec<u8>>,
}

impl Default for SMBErrorResponse {
fn default() -> Self {
Self {
reserved: PhantomData,
byte_count: PhantomData,
error_data: PhantomData,
}
}
}

impl SMBErrorResponse {
pub fn new() -> Self {
Self {
Expand Down
2 changes: 1 addition & 1 deletion smb/src/protocol/body/filetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const TIME_SINCE_1601_AND_EPOCH: u64 = 11644473600000;

impl FileTime {
pub fn from_unix(unix_timestamp: u64) -> Self {
let filetype_normalized = unix_timestamp + TIME_SINCE_1601_AND_EPOCH as u64;
let filetype_normalized = unix_timestamp + TIME_SINCE_1601_AND_EPOCH;
let bytes = u64_to_bytes(filetype_normalized);
FileTime {
low_date_time: bytes_to_u32(&bytes[0..4]),
Expand Down
5 changes: 2 additions & 3 deletions smb/src/protocol/body/negotiate/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::any::Any;
use std::collections::HashSet;
use std::marker::PhantomData;

Expand Down Expand Up @@ -62,7 +61,7 @@ impl SMBNegotiateRequest {
return Err(SMBError::response_error(NTStatus::InvalidParameter));
}
let mut update = SMBConnectionUpdate::default();
let mut received_ctxs = HashSet::new();
let received_ctxs = HashSet::new();
// TODO: uncomment after signing is fixed + working
// for context in self.negotiate_contexts.iter() {
// let (change, actual) = context.validate_and_set_state(update, server)?;
Expand Down Expand Up @@ -104,7 +103,7 @@ impl SMBNegotiateRequest {
let dialect = SMBDialect::V2_1_0;
let preauth_value = if dialect == SMBDialect::V3_1_1 {
let mut sha = Sha512::default();
sha.update(&self.smb_to_bytes());
sha.update(self.smb_to_bytes());
sha.finalize().to_vec()
} else {
Vec::new()
Expand Down
5 changes: 2 additions & 3 deletions smb/src/protocol/body/session_setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::server::preauth_session::SMBPreauthSession;
use crate::server::Server;
use crate::server::session::{Session, SessionState};
use crate::socket::message_stream::{SMBReadStream, SMBWriteStream};
use crate::util::auth::AuthProvider;

pub mod security_mode;
pub mod flags;
Expand Down Expand Up @@ -98,7 +97,7 @@ impl SMBSessionSetupRequest {
if connection.dialect() == SMBDialect::V3_1_1 && !connection.preauth_sessions().contains_key(&session.id()) {
let mut sha = Sha512::default();
sha.update(connection.preauth_integtiry_hash_value());
sha.update(&self.smb_to_bytes());
sha.update(self.smb_to_bytes());
let bytes = sha.finalize().to_vec();
let preauth_session = SMBPreauthSession::new(session.id(), bytes);
update = update.preauth_session_table(HashMap::from([(session.id(), preauth_session)]));
Expand Down Expand Up @@ -152,7 +151,7 @@ impl SMBSessionSetupResponse {
}
}

pub fn from_request(request: SMBSessionSetupRequest, token: Vec<u8>) -> Option<Self> {
pub fn from_request(_request: SMBSessionSetupRequest, token: Vec<u8>) -> Option<Self> {
Some(Self {
session_flags: SMBSessionFlags::empty(),
buffer: token,
Expand Down
2 changes: 1 addition & 1 deletion smb/src/protocol/body/tree_connect/access_mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl SMBAccessMask {
}

pub fn from_desired_access(desired: &SMBAccessMask) -> Self {
let mut mask = desired.clone();
let mask = desired.clone();
if mask.includes_maximum_allowed() {
match mask {
SMBAccessMask::FilePipePrinter(mut x) => x |= SMBFilePipePrinterAccessMask::GENERIC_ALL,
Expand Down
2 changes: 1 addition & 1 deletion smb/src/protocol/body/tree_connect/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl SMBByteSize for SMBTreeConnectContext {

impl SMBFromBytes for SMBTreeConnectContext {
fn smb_from_bytes(input: &[u8]) -> SMBParseResult<&[u8], Self> where Self: Sized {
let (remaining, ctx_type) = u16::smb_from_bytes(input)?;
let (_remaining, ctx_type) = u16::smb_from_bytes(input)?;
match ctx_type {
0x01 => {
let (remaining, identity) = RemotedIdentity::smb_from_bytes(input)?;
Expand Down
11 changes: 3 additions & 8 deletions smb/src/protocol/body/tree_connect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Default for SMBTreeConnectResponse {
}

impl SMBTreeConnectResponse {
pub fn IPC() -> Self {
pub fn ipc() -> Self {
Self {
maximal_access: SMBAccessMask::FilePipePrinter(SMBFilePipePrinterAccessMask::from_bits_truncate(2032127)),
share_type: SMBShareType::Pipe,
Expand Down Expand Up @@ -113,19 +113,14 @@ impl SMBTreeConnectResponse {
}

#[repr(u8)]
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Copy, Clone, SMBByteSize, SMBFromBytes, SMBToBytes, TryFromPrimitive)]
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Copy, Clone, SMBByteSize, SMBFromBytes, SMBToBytes, TryFromPrimitive, Default)]
pub enum SMBShareType {
#[default]
Disk = 0x01,
Pipe,
Print,
}

impl Default for SMBShareType {
fn default() -> Self {
Self::Disk
}
}

impl_smb_byte_size_for_bitflag! {
SMBTreeConnectFlags
SMBShareFlags
Expand Down
12 changes: 6 additions & 6 deletions smb/src/protocol/header/command_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ pub enum SMBCommandCode {
LegacyNegotiate
}

impl Into<u64> for SMBCommandCode {
fn into(self) -> u64 {
self as u16 as u64
impl From<SMBCommandCode> for u64 {
fn from(val: SMBCommandCode) -> Self {
val as u16 as u64
}
}

Expand Down Expand Up @@ -110,9 +110,9 @@ pub enum LegacySMBCommandCode {
WriteBulkData
}

impl Into<u64> for LegacySMBCommandCode {
fn into(self) -> u64 {
self as u8 as u64
impl From<LegacySMBCommandCode> for u64 {
fn from(val: LegacySMBCommandCode) -> Self {
val as u8 as u64
}
}

Expand Down
1 change: 1 addition & 0 deletions smb/src/server/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ impl<R: SMBReadStream, W: SMBWriteStream, S: Server<Connection=Self>> SMBConnect
}

type LockedSMBConnection<R, W, S> = Arc<RwLock<SMBConnection<R, W, S>>>;
pub type WeakLockedSMBConnection<R, W, S> = Weak<RwLock<SMBConnection<R, W, S>>>;

impl<R: SMBReadStream, W: SMBWriteStream, S: Server<Connection=Self>> InnerGetter for SMBConnection<R, W, S> {
type Upper = S;
Expand Down
1 change: 1 addition & 0 deletions smb/src/server/lease.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::server::Server;

pub trait Lease: Send + Sync {}


#[derive(Debug)]
pub struct SMBLeaseTable<L: Lease> {
client_guid: Uuid,
Expand Down
42 changes: 21 additions & 21 deletions smb/src/server/message_handler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::future::Future;

use smb_core::error::SMBError;
use smb_core::logging::{trace, debug, warn};
use smb_core::logging::{trace, debug};
use smb_core::nt_status::NTStatus;
use smb_core::SMBResult;

Expand Down Expand Up @@ -75,87 +75,87 @@ pub trait SMBLockedMessageHandlerBase {
SMBBody::ErrorResponse(_) => {
let status = NTStatus::try_from(message.header.channel_sequence)
.unwrap_or(NTStatus::NotSupported);
return Err(SMBError::response_error(status));
Err(SMBError::response_error(status))
},
_ => Err(SMBError::server_error("Command not implemented")),
}
}
}

fn handle_negotiate(&mut self, header: &SMBSyncHeader, message: &SMBNegotiateRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
fn handle_negotiate(&mut self, _header: &SMBSyncHeader, _message: &SMBNegotiateRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
async { Ok(SMBHandlerState::Next(None)) }
}

fn handle_session_setup(&mut self, header: &SMBSyncHeader, message: &SMBSessionSetupRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
fn handle_session_setup(&mut self, _header: &SMBSyncHeader, _message: &SMBSessionSetupRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
async { Ok(SMBHandlerState::Next(None)) }
}

fn handle_logoff(&mut self, header: &SMBSyncHeader, message: &SMBLogoffRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
fn handle_logoff(&mut self, _header: &SMBSyncHeader, _message: &SMBLogoffRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
async { Ok(SMBHandlerState::Next(None)) }
}

fn handle_tree_connect(&mut self, header: &SMBSyncHeader, message: &SMBTreeConnectRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
fn handle_tree_connect(&mut self, _header: &SMBSyncHeader, _message: &SMBTreeConnectRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
async { Ok(SMBHandlerState::Next(None)) }
}

fn handle_tree_disconnect(&mut self, header: &SMBSyncHeader, message: &SMBTreeDisconnectRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
fn handle_tree_disconnect(&mut self, _header: &SMBSyncHeader, _message: &SMBTreeDisconnectRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
async { Ok(SMBHandlerState::Next(None)) }
}

fn handle_create(&mut self, header: &SMBSyncHeader, message: &SMBCreateRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
fn handle_create(&mut self, _header: &SMBSyncHeader, _message: &SMBCreateRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
debug!("create request, passing to next handler");
async { Ok(SMBHandlerState::Next(None)) }
}

fn handle_close(&mut self, header: &SMBSyncHeader, message: &SMBCloseRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
fn handle_close(&mut self, _header: &SMBSyncHeader, _message: &SMBCloseRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
async { Ok(SMBHandlerState::Next(None)) }
}

fn handle_flush(&mut self, header: &SMBSyncHeader, message: &SMBFlushRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
fn handle_flush(&mut self, _header: &SMBSyncHeader, _message: &SMBFlushRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
async { Ok(SMBHandlerState::Next(None)) }
}

fn handle_read(&mut self, header: &SMBSyncHeader, message: &SMBReadRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
fn handle_read(&mut self, _header: &SMBSyncHeader, _message: &SMBReadRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
async { Ok(SMBHandlerState::Next(None)) }
}

fn handle_write(&mut self, header: &SMBSyncHeader, message: &SMBWriteRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
fn handle_write(&mut self, _header: &SMBSyncHeader, _message: &SMBWriteRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
async { Ok(SMBHandlerState::Next(None)) }
}

fn handle_lock(&mut self, header: &SMBSyncHeader, message: &SMBLockRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
fn handle_lock(&mut self, _header: &SMBSyncHeader, _message: &SMBLockRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
async { Ok(SMBHandlerState::Next(None)) }
}

fn handle_ioctl(&mut self, header: &SMBSyncHeader, message: &SMBIoCtlRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
fn handle_ioctl(&mut self, _header: &SMBSyncHeader, _message: &SMBIoCtlRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
async { Ok(SMBHandlerState::Next(None)) }
}

fn handle_cancel(&mut self, header: &SMBSyncHeader, message: &SMBCancelRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
fn handle_cancel(&mut self, _header: &SMBSyncHeader, _message: &SMBCancelRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
async { Ok(SMBHandlerState::Next(None)) }
}

fn handle_echo(&mut self, header: &SMBSyncHeader, message: &SMBEchoRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
fn handle_echo(&mut self, _header: &SMBSyncHeader, _message: &SMBEchoRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
async { Ok(SMBHandlerState::Next(None)) }
}

fn handle_query_directory(&mut self, header: &SMBSyncHeader, message: &SMBQueryDirectoryRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
fn handle_query_directory(&mut self, _header: &SMBSyncHeader, _message: &SMBQueryDirectoryRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
async { Ok(SMBHandlerState::Next(None)) }
}

fn handle_change_notify(&mut self, header: &SMBSyncHeader, message: &SMBChangeNotifyRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
fn handle_change_notify(&mut self, _header: &SMBSyncHeader, _message: &SMBChangeNotifyRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
async { Ok(SMBHandlerState::Next(None)) }
}

fn handle_query_info(&mut self, header: &SMBSyncHeader, message: &SMBQueryInfoRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
fn handle_query_info(&mut self, _header: &SMBSyncHeader, _message: &SMBQueryInfoRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
async { Ok(SMBHandlerState::Next(None)) }
}

fn handle_set_info(&mut self, header: &SMBSyncHeader, message: &SMBSetInfoRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
fn handle_set_info(&mut self, _header: &SMBSyncHeader, _message: &SMBSetInfoRequest) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
async { Ok(SMBHandlerState::Next(None)) }
}

fn handle_oplock_break(&mut self, header: &SMBSyncHeader, message: &SMBOplockBreakAcknowledgement) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
fn handle_oplock_break(&mut self, _header: &SMBSyncHeader, _message: &SMBOplockBreakAcknowledgement) -> impl Future<Output=SMBResult<SMBHandlerState<Self::Inner>>> {
async { Ok(SMBHandlerState::Next(None)) }
}
}
Expand Down
Loading
Loading