1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//! SMB2/3 file-sharing server with pluggable storage backends.
//!
//! Example:
//!
//! ```no_run
//! use smb_server::{SmbServer, Share, Access, ShareBackend};
//! # async fn run<B: ShareBackend>(backend: B) -> Result<(), Box<dyn std::error::Error>> {
//! SmbServer::builder()
//! .listen("0.0.0.0:4445".parse()?)
//! .user("alice", "password")
//! .share(Share::new("home", backend).user("alice", Access::ReadWrite))
//! .build()?
//! .serve()
//! .await?;
//! # Ok(()) }
//! ```
//!
//! # Writing a backend
//!
//! A share serves any [`ShareBackend`]. Each CREATE calls
//! [`ShareBackend::open`], which returns a [`Handle`] and the
//! [`OpenAction`] it took; CREATE reports the action to the client. The
//! handle serves READ, WRITE, FLUSH, QUERY_INFO, QUERY_DIRECTORY and
//! SET_INFO on that open until the open is closed. `LocalFsBackend`
//! (feature `localfs`) is the reference implementation.
//!
//! What the protocol layer does around the backend calls:
//!
//! - Paths arrive as [`SmbPath`], relative to the share root. `.` components
//! are dropped; `..`, empty components, `<>:"|?*`, control characters and
//! stream names are rejected before the backend sees them. The empty path
//! is the share root.
//! - `open` fails with [`SmbError::PathNotFound`] when a directory on the
//! way to the path is missing, and with [`SmbError::NotFound`] when only
//! the last component is. Clients see STATUS_OBJECT_PATH_NOT_FOUND and
//! STATUS_OBJECT_NAME_NOT_FOUND.
//! - Share permissions and the access the client asked for are checked
//! before `open`. [`OpenOptions`] carries the result: `read`, `write` and
//! `write_attributes` reflect the access granted to the open. READ and
//! WRITE on a handle without the matching access fail before the handle
//! is called. When [`BackendCapabilities::is_read_only`] is set, trees on
//! the share get read access only, so opens that ask for write access,
//! and dispositions that create or truncate, fail before `open`.
//! - Share modes, byte-range locks and the delete-pending flag are kept by
//! the protocol layer per share, across every connection, keyed by
//! [`FileInfo::file_index`], or by path when it is 0. Two shares over
//! the same directory do not see each other's opens. A CREATE that would
//! truncate first opens the file without write access, runs the checks
//! and enters the open in the table, so the sharing mode holds while
//! `open` truncates. Any other CREATE refused by the share-mode check has
//! already called `open` and closes the new handle again.
//! - [`Handle::close`] runs on every path that ends an open: CLOSE,
//! TREE_DISCONNECT, LOGOFF, the end of a session or connection, and
//! [`ConfigHandle`] changes that end sessions or trees. Before it,
//! [`Handle::set_times`] puts back access and write times that
//! FileBasicInformation froze or set through that open.
//! - Delete-on-close: [`OpenOptions::delete_on_close`] and
//! FileDispositionInformation make the file delete-pending. When its last
//! open ends, on any of the paths above, the protocol layer calls
//! [`Handle::close`] and then [`ShareBackend::unlink`] on the file's
//! current path. `open` doesn't delete anything itself. Read-only files
//! are refused before that point, and so, for SET_INFO, are directories
//! that [`Handle::dir_is_empty`] reports as not empty. `unlink` returns
//! [`SmbError::NotEmpty`] for a directory that has entries; the directory
//! then stays.
//! - A rename through SET_INFO calls [`ShareBackend::rename`] and then moves
//! the path of every open at or below the old name. Renames on one share
//! run one at a time. The backend keeps those handles working on the
//! renamed file.
//! - A CREATE that makes or overwrites a file passes the attributes it asks
//! for to [`Handle::set_attributes`] when they differ from what
//! [`Handle::stat`] reports. If that returns [`SmbError::NotSupported`],
//! it retries with READONLY alone when that was asked for; the CREATE
//! succeeds either way.
//! - FileBasicInformation passes [`Handle::set_attributes`] and
//! [`Handle::set_times`] only the values that differ from what
//! [`Handle::stat`] reports. After a write or truncate, `set_times` also
//! puts back the times FileBasicInformation froze or set.
//! [`Handle::truncate`] is never called on a directory.
//! - QUERY_DIRECTORY calls [`Handle::list_dir`] with the search pattern on
//! the first query and on a restart, then pages through the returned
//! entries itself. Below the share root it adds `.` and `..`, and opens
//! the parent directory to describe `..`.
//! - FileStandardInformation and FileAllInformation report
//! [`Handle::link_count`] as NumberOfLinks, and DeletePending when the
//! file is delete-pending or has no links left. The filesystem
//! QUERY_INFO classes, and the VolumeId of the on-disk id CREATE context,
//! come from [`ShareBackend::volume_info`].
//! - READ and WRITE lengths are bounded by the negotiated maximum sizes.
//! - Each [`SmbError`] maps to one NTSTATUS for the client; see
//! [`SmbError::to_nt_status`].
//!
//! A handle is dropped without [`Handle::close`] when the task serving its
//! connection panics or is cancelled, and when a [`ConfigHandle`] call that
//! ends its session or tree is cancelled, so release resources in `Drop` as
//! well.
//!
//! Later releases may add methods with default bodies, fields to
//! [`FileInfo`], [`BackendCapabilities`] and [`VolumeInfo`], and variants
//! to [`OpenIntent`]. A backend that implements the required methods,
//! builds those types through [`FileInfo::new`] and the `Default` impls, and
//! matches `OpenIntent` with a wildcard arm keeps compiling.
pub
pub
pub use ;
pub use ;
pub use Bytes;
pub use ;
pub use ;
pub use LocalFsBackend;
pub use SmbPath;
pub use Identity;
pub use ;
/// Entry points for the cargo-fuzz targets in `fuzz/`. Built only with
/// `--cfg fuzzing`, which `cargo fuzz` sets.
/// Parses `data` as an SMB2 header.
/// Decodes `data` as a SPNEGO NegTokenInit and as a NegTokenResp.
/// Parses `data` as each NTLM message the server receives.
/// Dispatches one frame payload on a fresh connection to `server`.
pub async
}