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
4 changes: 2 additions & 2 deletions smb-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl<T: SMBFromBytes> SMBVecFromBytesCnt for Vec<T> {
remaining = &remaining[extra..];
let (r, val) = T::smb_from_bytes(remaining)?;
pos += T::smb_byte_size(&val);
extra = if align > 0 && pos % align != 0 {
extra = if align > 0 && !pos.is_multiple_of(align) {
align - (pos % align)
} else {
0
Expand All @@ -125,7 +125,7 @@ impl<T: SMBFromBytes> SMBVecFromBytesLen for Vec<T> {
let (_, val) = T::smb_from_bytes(remaining)?;
let size = T::smb_byte_size(&val);
pos += size;
extra = if align > 0 && pos % align != 0 {
extra = if align > 0 && !pos.is_multiple_of(align) {
align - (pos % align)
} else {
0
Expand Down
27 changes: 13 additions & 14 deletions smb-derive/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,11 @@ impl FromMeta for AttributeInfo {
fn from_list(items: &[NestedMeta]) -> darling::Result<Self> {
for item in items {
if let NestedMeta::Meta(Meta::NameValue(meta)) = item {
if meta.path.is_ident("fixed") {
if let Expr::Lit(lit) = &meta.value {
if let Lit::Int(int) = &lit.lit {
return Ok(AttributeInfo::Fixed(int.base10_parse::<usize>()?))
}
}
if meta.path.is_ident("fixed")
&& let Expr::Lit(lit) = &meta.value
&& let Lit::Int(int) = &lit.lit
{
return Ok(AttributeInfo::Fixed(int.base10_parse::<usize>()?))
}
} else if let NestedMeta::Meta(Meta::List(list)) = item {
if list.path.is_ident("inner") {
Expand Down Expand Up @@ -388,7 +387,7 @@ impl Vector {
let _name_str = name.to_string();
quote_spanned! { spanned.span() =>
#vec_count_or_len
if #align > 0 && current_pos % #align != 0 {
if #align > 0 && !current_pos.is_multiple_of(#align) {
current_pos += #align - (current_pos % #align);
}
#offset
Expand Down Expand Up @@ -423,7 +422,7 @@ impl Vector {
quote_spanned! { spanned.span()=>
#count_info
let get_aligned_pos = |align: usize, current_pos: usize| {
if align > 0 && current_pos % align != 0 {
if align > 0 && !current_pos.is_multiple_of(align) {
current_pos + (align - current_pos % align)
} else {
current_pos
Expand Down Expand Up @@ -824,12 +823,12 @@ impl FromAttributes for Repr {
if attr.path().is_ident("repr") {
let nested = attr.parse_args_with(Punctuated::<Meta, Token![,]>::parse_terminated)?;
for meta in nested {
if let Meta::Path(p) = meta {
if let Some(ident) = p.get_ident() {
return Ok(Self {
ident: ident.clone()
})
}
if let Meta::Path(p) = meta
&& let Some(ident) = p.get_ident()
{
return Ok(Self {
ident: ident.clone()
})
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions smb-derive/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ impl<T: Spanned + Debug> SMBField<'_, T> {
pub(crate) fn get_smb_message_size(&self, size_tokens: TokenStream) -> TokenStream {
let tmp = SMBFieldType::Skip(Skip::new(0, 0));
let (start_val, ty) = self.val_type.iter().fold((0, &tmp), |prev, val| {
if let SMBFieldType::Skip(skip) = val {
if skip.length + skip.start > prev.0 {
return (skip.length + skip.start, val);
}
if let SMBFieldType::Skip(skip) = val
&& skip.length + skip.start > prev.0
{
return (skip.length + skip.start, val);
}
if val.weight_of_enum() == 2 || val.find_start_val() > prev.0 {
(val.find_start_val(), val)
Expand Down Expand Up @@ -229,7 +229,7 @@ impl<T: Spanned + Debug> SMBField<'_, T> {
impl<'a> SMBField<'a, Field> {
pub(crate) fn from_iter<U: Iterator<Item=&'a Field>>(fields: U) -> Result<Vec<Self>, SMBDeriveError<Field>> {
fields.enumerate().map(|(idx, field)| {
let val_types = field.attrs.iter().map(|attr| get_field_types(field, &[attr.clone()])).collect::<Result<Vec<SMBFieldType>, SMBDeriveError<Field>>>()?;
let val_types = field.attrs.iter().map(|attr| get_field_types(field, std::slice::from_ref(attr))).collect::<Result<Vec<SMBFieldType>, SMBDeriveError<Field>>>()?;
let name = if let Some(x) = &field.ident {
x.clone()
} else {
Expand Down Expand Up @@ -368,5 +368,5 @@ impl FromAttributes for SMBFieldType {

fn get_field_types(field: &Field, attrs: &[Attribute]) -> Result<SMBFieldType, SMBDeriveError<Field>> {
SMBFieldType::from_attributes(attrs)
.map_err(|_e| SMBDeriveError::TypeError(field.clone()))
.map_err(|_e| SMBDeriveError::TypeError(Box::new(field.clone())))
}
10 changes: 4 additions & 6 deletions smb-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn derive_impl_creator(input: DeriveInput, creator: impl CreatorFn) -> proc_macr

let parent_attrs = parent_attrs(&input);

let parse_token = match &input.data {
match &input.data {
Data::Struct(structure) => {
let mapping = get_struct_field_mapping(&structure.fields, parent_attrs, vec![], None)
.map(|r| vec![r]);
Expand Down Expand Up @@ -209,9 +209,7 @@ fn derive_impl_creator(input: DeriveInput, creator: impl CreatorFn) -> proc_macr
}
},
_ => invalid_token
};

parse_token
}
}


Expand All @@ -220,7 +218,7 @@ fn derive_impl_creator(input: DeriveInput, creator: impl CreatorFn) -> proc_macr
/// `DeriveInput` and returns them as a sorted list of [`SMBFieldType`]s.
fn parent_attrs(input: &DeriveInput) -> Vec<SMBFieldType> {
input.attrs.iter().filter_map(|attr| {
SMBFieldType::from_attributes(&[attr.clone()]).ok()
SMBFieldType::from_attributes(std::slice::from_ref(attr)).ok()
}).collect()
}

Expand All @@ -236,7 +234,7 @@ trait CreatorFn {
/// Errors that can occur during derive-macro expansion.
#[derive(Debug)]
enum SMBDeriveError<T: Spanned + Debug> {
TypeError(T),
TypeError(Box<T>),
MissingField,
InvalidType,
}
Expand Down
2 changes: 2 additions & 0 deletions smb/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// TODO: Remove once protocol implementation consumes all public types
#![allow(dead_code)]
// TODO: Reduce generic params on SMBServer to eliminate need for this allow
#![allow(clippy::type_complexity)]
//! # SMB Reader
//!
//! A Rust implementation of the **Server Message Block (SMB) Protocol Versions 2 and 3**
Expand Down
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
1 change: 1 addition & 0 deletions smb/src/protocol/body/ioctl/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use smb_derive::{SMBByteSize, SMBFromBytes, SMBToBytes};

#[repr(u32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TryFromPrimitive, SMBFromBytes, SMBByteSize, SMBToBytes)]
#[allow(clippy::upper_case_acronyms)]
pub enum SMBIoCtlRequestFlags {
IOCTL = 0x0,
FSCTL = 0x1,
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/protocol/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub trait Header: SMBFromBytes + SMBToBytes {
SMBByteSize,
Clone
)]
#[allow(clippy::duplicated_attributes)]
#[smb_byte_tag(value = 0xFE, order = 0)]
#[smb_string_tag(value = "SMB", order = 1)]
#[smb_byte_tag(value = 64, order = 2)]
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
Loading
Loading