Skip to content

Commit 303ec33

Browse files
authored
Document and format smb-msg (#157)
* Add more documentation to the smb-msg crate, and improve code formatting. * **Bug Fixes & Improvements** * Improved message structure parsing and validation * Better support for SMB2/SMB3 feature detection and negotiation * **Chores** * Workspace reorganization with modular crate structure * Added safety constraints across crates
1 parent 095ef3f commit 303ec33

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+2462
-1268
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Contain a code snippet that uses the crate, and reproduces the bug.
1919

2020
- If this is a runtime failure, please provide:
2121
- SMB server software and version (e.g. Samba 4.15.0 or Windows Server 2022)
22-
- Authentication method, if relevant
22+
- Authentication method, if relevant (ntlm/kerberos - domain environment?)
2323
- Custom configuration or used features, if relevant
2424

2525
- Crate version: [e.g. 0.8.1]

.github/copilot-instructions.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Utility for documenting structures based on MSDN specifications
2+
3+
- When you document a structure, the *final* document you use should be official Microsoft documentation.
4+
5+
- Structure documentation should include:
6+
- A brief description of the structure's purpose.
7+
- A reference to the page. Use the index of specifications (MS-SMB2 X.Y.Z...), do not put url parts.
8+
- Field documentation should be brief and helpful, if any critical information is provided, include it.
9+
- Never include constant names or values in the documentation! especially bit shift flags, or arbitrary symbols.
10+
- Don't make up stuff! Always base documentation on official documentation.
11+
- Avoid documenting for the sake of documenting. If the documentation doesn't add value, don't add it. (e.g. don't just repeat the field name in the field documentation...).
12+
- Do not summarize or put again the instructions, that just makes me pay for more tokens.
13+
14+
- If the structure is under the `smb-msg` crate, you can look up the documentation.
15+
- Make sure that the documentation is MS-SMB2 2.* indexed - that's where structures are documented.
16+
- Request the documentation page to be used, do not try to look it up yourself. It won't work!
17+
- Do not simple document helper structures that are not part of the specification and/or produced by macros.
18+
- This does NOT apply to enums that represent possible field values, for example, or bitfield structs - of course!
19+
- NEVER document reserved fields.

.github/workflows/build.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,18 @@ jobs:
5959
run: |
6060
rustup component add clippy
6161
cargo clippy --verbose --no-default-features --features "${{ matrix.compile_features }},${COMMON_FEATURES}" -- -Dclippy::all
62+
- name: Build/${{ matrix.compile_features }}
63+
run: |
64+
cargo build --no-default-features --features "${{ matrix.compile_features }},${COMMON_FEATURES}"
6265
- name: Tests/${{ matrix.compile_features }}
6366
run: |
64-
cargo test -p smb-msg --features both -- --nocapture
67+
cargo test -p smb-msg --features server --no-default-features -- --nocapture
68+
cargo test -p smb-msg --features both --no-default-features -- --nocapture
69+
70+
# Full client tests with all features
6571
cargo test --no-default-features --features "${{ matrix.compile_features }},${COMMON_FEATURES}" -- --nocapture
66-
# Test without encryption and compression
67-
cargo test --no-default-features --features "${{ matrix.compile_features }},sign" -- --nocapture
68-
# Test signing with specific algorithms
69-
cargo test --no-default-features --features "${{ matrix.compile_features }},sign_cmac" -- --nocapture
70-
cargo test --no-default-features --features "${{ matrix.compile_features }},sign_gmac" -- --nocapture
71-
cargo test --no-default-features --features "${{ matrix.compile_features }},sign_hmac" -- --nocapture
72-
- name: Build/${{ matrix.compile_features }}
72+
- name: Doc/${{ matrix.compile_features }}
7373
run: |
74-
cargo build --no-default-features --features "${{ matrix.compile_features }},${COMMON_FEATURES}"
7574
cargo doc --no-default-features --features "${{ matrix.compile_features }},${COMMON_FEATURES}"
7675
7776
build:

Cargo.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["crates/*"]
2+
members = ["crates/*", "smb-cli"]
33
resolver = "2"
44

55
[workspace.package]
@@ -16,6 +16,19 @@ readme = "README.md"
1616
version = "0.10.4"
1717

1818
[workspace.dependencies]
19+
# Crates in this workspace
20+
smb = { path = "crates/smb", version = "0.10.4", default-features = false }
21+
smb-tests = { path = "crates/smb-tests", version = "0.10.4" }
22+
smb-msg = { path = "crates/smb-msg", version = "0.10.4", default-features = false, features = [
23+
"client",
24+
] }
25+
smb-msg-derive = { path = "crates/smb-msg-derive", version = "0.10.4" }
26+
smb-dtyp = { path = "crates/smb-dtyp", version = "0.10.4" }
27+
smb-dtyp-derive = { path = "crates/smb-dtyp-derive", version = "0.10.4" }
28+
smb-rpc = { path = "crates/smb-rpc", version = "0.10.4" }
29+
smb-fscc = { path = "crates/smb-fscc", version = "0.10.4" }
30+
smb-transport = { path = "crates/smb-transport", version = "0.10.4", default-features = false }
31+
1932
# Binary encoding/decoding
2033
binrw = "0.15.0"
2134
modular-bitfield = "0.11.2"

crates/smb-dtyp-derive/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "smb-dtyp-derive"
3+
description = "Derive macros for smb-dtyp, and general smb* crates."
4+
readme = "README.md"
5+
version.workspace = true
6+
edition.workspace = true
7+
rust-version.workspace = true
8+
license.workspace = true
9+
repository.workspace = true
10+
authors.workspace = true
11+
keywords.workspace = true
12+
categories.workspace = true
13+
14+
[lib]
15+
proc-macro = true
16+
17+
[dependencies]
18+
quote = "1"
19+
proc-macro2 = "1"
20+
syn = { version = "2", features = ["full"] }

crates/smb-dtyp-derive/src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use proc_macro::TokenStream;
2+
3+
/// A helper macro that invokes `modular_bitfield` and `binrw` derives for bitfield structs.
4+
/// Those must be installed as dependencies in the crate where this macro is used.
5+
///
6+
/// Adds derives for `Debug`, `Default`, `Clone`, `Copy`, `PartialEq`, and `Eq`.
7+
#[proc_macro_attribute]
8+
pub fn mbitfield(_attr: TokenStream, input: TokenStream) -> TokenStream {
9+
let input = syn::parse_macro_input!(input as syn::ItemStruct);
10+
quote::quote! {
11+
#[::modular_bitfield::bitfield]
12+
#[derive(::binrw::BinWrite, ::binrw::BinRead)]
13+
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
14+
#[bw(map = |&x| Self::into_bytes(x))]
15+
#[br(map = Self::from_bytes)]
16+
#input
17+
}
18+
.into()
19+
}

crates/smb-dtyp/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ modular-bitfield = { workspace = true }
1717
time = { workspace = true }
1818
pastey = { workspace = true }
1919
rand = { workspace = true }
20+
smb-dtyp-derive = { workspace = true }
2021

2122
[dev-dependencies]
22-
smb-tests = { path = "../smb-tests", version = "0.10.4" }
23+
smb-tests = { workspace = true }

crates/smb-dtyp/src/binrw_util/boolean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! [`Boolean`][crate::Boolean] implementation for binrw.
1+
//! [`Boolean`] implementation for binrw.
22
33
use binrw::{Endian, prelude::*};
44
use std::io::{Read, Seek, Write};

crates/smb-dtyp/src/binrw_util/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn read_u48() -> binrw::BinResult<u64> {
2424

2525
/// Utility binrw parser function that reads an optional value of type `T`
2626
/// if there is _ANY_ data left in the stream
27-
/// (any data, not enough data - for Option<u32> it's 1 byte in the stream).
27+
/// (any data, not enough data - even for [`Option<u32>`] it's 1 byte in the stream).
2828
#[binrw::parser(reader, endian)]
2929
pub fn binread_if_has_data<T>() -> BinResult<Option<T>>
3030
where

0 commit comments

Comments
 (0)