Skip to main content

smb_server/
lib.rs

1//! SMB2/3 file-sharing server with pluggable storage backends.
2//!
3//! Example:
4//!
5//! ```no_run
6//! use smb_server::{SmbServer, Share, Access, ShareBackend};
7//! # async fn run<B: ShareBackend>(backend: B) -> Result<(), Box<dyn std::error::Error>> {
8//! SmbServer::builder()
9//!     .listen("0.0.0.0:4445".parse()?)
10//!     .user("alice", "password")
11//!     .share(Share::new("home", backend).user("alice", Access::ReadWrite))
12//!     .build()?
13//!     .serve()
14//!     .await?;
15//! # Ok(()) }
16//! ```
17//!
18//! # Writing a backend
19//!
20//! A share serves any [`ShareBackend`]. Each CREATE calls
21//! [`ShareBackend::open`], which returns a [`Handle`] and the
22//! [`OpenAction`] it took; CREATE reports the action to the client. The
23//! handle serves READ, WRITE, FLUSH, QUERY_INFO, QUERY_DIRECTORY and
24//! SET_INFO on that open until the open is closed. `LocalFsBackend`
25//! (feature `localfs`) is the reference implementation.
26//!
27//! What the protocol layer does around the backend calls:
28//!
29//! - Paths arrive as [`SmbPath`], relative to the share root. `.` components
30//!   are dropped; `..`, empty components, `<>:"|?*`, control characters and
31//!   stream names are rejected before the backend sees them. The empty path
32//!   is the share root.
33//! - `open` fails with [`SmbError::PathNotFound`] when a directory on the
34//!   way to the path is missing, and with [`SmbError::NotFound`] when only
35//!   the last component is. Clients see STATUS_OBJECT_PATH_NOT_FOUND and
36//!   STATUS_OBJECT_NAME_NOT_FOUND.
37//! - Share permissions and the access the client asked for are checked
38//!   before `open`. [`OpenOptions`] carries the result: `read`, `write` and
39//!   `write_attributes` reflect the access granted to the open. READ and
40//!   WRITE on a handle without the matching access fail before the handle
41//!   is called. When [`BackendCapabilities::is_read_only`] is set, trees on
42//!   the share get read access only, so opens that ask for write access,
43//!   and dispositions that create or truncate, fail before `open`.
44//! - Share modes, byte-range locks and the delete-pending flag are kept by
45//!   the protocol layer per share, across every connection, keyed by
46//!   [`FileInfo::file_index`], or by path when it is 0. Two shares over
47//!   the same directory do not see each other's opens. A CREATE that would
48//!   truncate first opens the file without truncating it, for reading or,
49//!   when reading is refused, with the access the CREATE was granted. It
50//!   runs the checks, enters the open in the table and waits for lease
51//!   breaks, so the sharing mode holds and clients caching writes have
52//!   written back before `open` truncates. When that first open finds no
53//!   file, the CREATE calls `open` with [`OpenIntent::Create`] instead and
54//!   starts over if the file appeared meanwhile. Any other CREATE refused
55//!   by the share-mode check has already called `open` and closes the new
56//!   handle again.
57//! - [`Handle::close`] runs on every path that ends an open: CLOSE,
58//!   TREE_DISCONNECT, LOGOFF, the end of a session or connection, and
59//!   [`ConfigHandle`] changes that end sessions or trees. A durable open,
60//!   described below, outlives LOGOFF and the end of its connection or
61//!   session for a while. Before `close`, [`Handle::set_times`] puts back
62//!   access and write times that FileBasicInformation froze or set through
63//!   that open.
64//! - Delete-on-close: [`OpenOptions::delete_on_close`] and
65//!   FileDispositionInformation make the file delete-pending. When its last
66//!   open ends, on any of the paths above, the protocol layer calls
67//!   [`Handle::close`] and then [`ShareBackend::unlink`] on the file's
68//!   current path. `open` doesn't delete anything itself. Read-only files
69//!   are refused before that point, and so, for SET_INFO, are directories
70//!   that [`Handle::dir_is_empty`] reports as not empty. `unlink` returns
71//!   [`SmbError::NotEmpty`] for a directory that has entries; the directory
72//!   then stays.
73//! - A rename through SET_INFO of a directory with a file or directory open
74//!   below it first asks the clients caching handles to those files to
75//!   close them, and waits until they answer or the break times out; files
76//!   kept open for a client to reconnect are closed. If an open below
77//!   remains, the rename fails with STATUS_ACCESS_DENIED, and so does a
78//!   rename of the share root. Otherwise the rename calls
79//!   [`ShareBackend::rename`] and then moves the path of every open of the
80//!   old name. Renames on one share run
81//!   one at a time, and a CREATE or a delete waits for a rename in
82//!   progress. The backend keeps those handles working on the renamed file.
83//! - A CREATE that makes or overwrites a file passes the attributes it asks
84//!   for to [`Handle::set_attributes`] when they differ from what
85//!   [`Handle::stat`] reports. If that returns [`SmbError::NotSupported`],
86//!   it retries with READONLY alone when that was asked for; the CREATE
87//!   succeeds either way.
88//! - FileBasicInformation passes [`Handle::set_attributes`] and
89//!   [`Handle::set_times`] only the values that differ from what
90//!   [`Handle::stat`] reports. After a write or truncate, `set_times` also
91//!   puts back the times FileBasicInformation froze or set.
92//!   [`Handle::truncate`] is never called on a directory.
93//! - QUERY_DIRECTORY calls [`Handle::list_dir`] with the search pattern on
94//!   the first query and on a restart, then pages through the returned
95//!   entries itself. It adds `.` and `..` when the pattern matches them,
96//!   and opens the parent directory to describe `..`; at the share root,
97//!   `..` describes the root itself, with file id 0.
98//! - FileStandardInformation and FileAllInformation report
99//!   [`Handle::link_count`] as NumberOfLinks, and DeletePending when the
100//!   file is delete-pending or has no links left. The filesystem
101//!   QUERY_INFO classes, and the VolumeId of the on-disk id CREATE context,
102//!   come from [`ShareBackend::volume_info`].
103//! - Leases: on every share unless [`Share::leases`] turns them off, files
104//!   get read, handle and write caching leases. A client holding one
105//!   caches what it reads, keeps files open after its applications close
106//!   them, and caches writes while every other open of the file holds the
107//!   same lease or is attribute-only. An open, write, size change,
108//!   byte-range lock, rename or delete made through an open that does not
109//!   hold the lease breaks it when it needs what the lease caches, whether
110//!   that open belongs to another client or to the same client under
111//!   another lease key or none; attribute-only opens and opens holding the
112//!   same lease break nothing. An open or rename that needs the client to
113//!   write back or close first waits until the client acknowledges the
114//!   break or closes, or until the break times out 35 seconds after the
115//!   server sent it; meanwhile its backend handle stays open, except for
116//!   one that truncates, which calls `open` after the wait. A byte-range
117//!   lock asked for while another lease still caches writes is refused
118//!   with STATUS_LOCK_NOT_GRANTED until that client has written back.
119//!   Changes made outside the server, including through another share over
120//!   the same directory, break nothing: clients keep serving stale cached
121//!   data. Turn leases off on such shares.
122//! - Durable handles: on a share with leases, unless
123//!   [`Share::durable_handles`] turns them off, a file opened with a
124//!   durable handle request (DHnQ, or DH2Q on SMB 3.x) and a lease that
125//!   caches handles stays open when the client's connection drops, when it
126//!   logs off, when its session's reauthentication fails, or when a new
127//!   session names its session as the previous one. A request without such
128//!   a lease gets an open that is not durable and no durable context in the
129//!   response. The backend handle stays open, and the file keeps its share
130//!   mode, byte-range locks and lease, for
131//!   [`SmbServerBuilder::durable_handle_timeout`], or for the time a DH2Q
132//!   asked for, up to that timeout or 5 minutes, whichever is longer; the
133//!   DH2Q response carries the time granted. The PERSISTENT flag is
134//!   ignored. A file whose lease is being broken, or that holds byte-range
135//!   locks under a lease that does not cache writes, closes with its
136//!   session instead. Meanwhile the same user, from the same client, takes
137//!   the file back with a durable handle reconnect (DHnC, or DH2C naming
138//!   the CreateGuid of a DH2Q open) on a tree of the same share that names
139//!   the file and its lease; the backend handle, share mode, byte-range
140//!   locks and lease carry on, and later lease breaks go to the new
141//!   connection. A reconnect fails with STATUS_ACCESS_DENIED from another
142//!   user, STATUS_INVALID_PARAMETER for a DHnC naming another file, and
143//!   STATUS_INSUFFICIENT_RESOURCES past the connection's open limit; from
144//!   another client, on another share, naming another lease, lease version
145//!   or CreateGuid, a DH2C naming another file, or for a file that is not
146//!   kept, with STATUS_OBJECT_NAME_NOT_FOUND. The file stays kept after a
147//!   failed reconnect. One that comes while the connection holding the file
148//!   is still closing waits up to 5 seconds for it. A file whose rights
149//!   exceed what the user's tree on the share grants now is closed instead
150//!   of reconnected. [`Handle::close`] runs when the time runs out; at once
151//!   when an open, write, size change, byte-range lock, rename or delete
152//!   through an open that does not hold the lease needs what the lease
153//!   caches, or when the lease stops caching handles; on [`ConfigHandle`]
154//!   changes that end the user's sessions or the share's trees; and at
155//!   shutdown. At most [`SmbServerBuilder::max_disconnected_opens`] files
156//!   are kept at once, and a quarter of that, rounded up, for one user;
157//!   past that, files close with their session. Anonymous sessions and
158//!   clients that send a nil ClientGuid get no durable handle. A DH2Q that
159//!   repeats the CreateGuid of a live version 2 open of the same client,
160//!   with access to its data or to delete it, fails with
161//!   STATUS_DUPLICATE_OBJECTID unless it is marked as a replay; one marked
162//!   as a replay opens the file anew rather than answering with that
163//!   open.
164//! - Change notifications: on every share unless [`Share::change_notify`]
165//!   turns them off, a CHANGE_NOTIFY on a directory waits until a file or
166//!   directory in it, or below it when the client asks for the whole tree,
167//!   changes through any connection to the share:
168//!   - A create or delete is reported as an addition or a removal.
169//!   - A rename within one directory is reported as its old and new name
170//!     together, a move to another directory as a removal from one and an
171//!     addition to the other. Either is followed by a modification, under
172//!     LAST_WRITE, of the directory the entry is in afterwards, unless that
173//!     is the share root. An entry the rename replaces,
174//!     or the renamed entry itself when only the case of its name changes,
175//!     is first reported removed under its name as stored. A watched
176//!     directory can be renamed, and its watches follow it.
177//!   - Attributes and times set through FileBasicInformation are reported
178//!     at once as a modification, under ATTRIBUTES and the bit of each time
179//!     changed but the change time. What changed is what [`Handle::stat`]
180//!     shows differently afterwards, so a value the backend does not keep
181//!     reports nothing.
182//!   - New contents are reported as a modification under SIZE, LAST_WRITE
183//!     and ATTRIBUTES: a write once, when the open that wrote closes, unless
184//!     that close deletes the file; a change of size through
185//!     FileEndOfFileInformation, a truncation through
186//!     FileAllocationInformation, and an overwrite or supersede by CREATE,
187//!     at once.
188//!
189//!   A watched directory marked for deletion, through
190//!   FileDispositionInformation or by the close of an open that asked for
191//!   delete-on-close while other opens of it remain, ends every watch of
192//!   it: the requests waiting on them, and any request on an open of the
193//!   directory while it stays delete-pending, get STATUS_DELETE_PENDING. An
194//!   open that marked the directory, and any open made with delete-on-close,
195//!   always gets STATUS_DELETE_PENDING; once the mark is cleared, other
196//!   opens watch again. Watches of the directories above it stay, and hear
197//!   the removal once the directory is deleted.
198//!
199//!   Changes are buffered on the directory handle between requests, up to
200//!   the buffer size of its first request and at most 64 KiB; when more
201//!   arrive, or they do not fit the request being answered, the answer is
202//!   STATUS_NOTIFY_ENUM_DIR. Watches follow paths: a change made through a
203//!   symlink inside the share reaches the watchers of the path it was made
204//!   through, and on Linux, as a change on disk, those of the directory
205//!   the symlink leads to. Names are spelled as the client that made the
206//!   change spelled them, but for the stored names above.
207//!
208//!   Changes made outside the server, or through another share over the
209//!   same directory, are reported when the backend's [`Handle::watch`]
210//!   reports them. `LocalFsBackend` does on Linux, through inotify, unless
211//!   its `watch_host_changes` turns it off: additions, removals, renames
212//!   within the directory, new contents when a writer closes the file
213//!   (under SIZE, LAST_WRITE and ATTRIBUTES) and attribute or time changes
214//!   (under ATTRIBUTES) of the entries directly in a watched directory,
215//!   also for a client that asks for the whole tree. A move out of or into
216//!   the directory is a removal or an addition, and so is a rename from or
217//!   to a name the server cannot use. A lost kernel queue, and a watched
218//!   directory renamed or moved outside the server, are answered
219//!   STATUS_NOTIFY_ENUM_DIR; such a directory stays watched under its old
220//!   name. A watched directory deleted outside the server, or replaced by a
221//!   rename, ends its watches with STATUS_DELETE_PENDING, and every later
222//!   CHANGE_NOTIFY on its handles gets the same. The parent of each watched
223//!   directory is watched too, the share root's parent included, only to
224//!   see the directory go. A change in a parent is reported only to the
225//!   watchers of that parent, so a change in the share root's parent is
226//!   reported to no one. One backend holds at most 4096 kernel watches,
227//!   parents included. A directory past that, or one the kernel will not
228//!   watch, past `fs.inotify.max_user_watches` or
229//!   `fs.inotify.max_user_instances` or without `/proc`, gets only the
230//!   changes made through the server, with a warning logged once. Other
231//!   backends and platforms report only changes made through the server.
232//!
233//!   The server leaves out the backend's reports of its own changes. Each
234//!   addition, removal or rename it made in the last 5 seconds drops one
235//!   matching backend report. A modification or attribute change is
236//!   dropped while an open through the server that may write the entry's
237//!   data or attributes has it open, for 5 seconds after the server
238//!   reported a change to it or closed an open that wrote it or restored
239//!   times fixed through it, and once after it closed an open that could
240//!   write it, or created or overwrote it, and wrote nothing. A backend
241//!   report waits up to 200 milliseconds for that comparison, and goes out
242//!   before any change the server reports after it arrived in the same
243//!   directory, or below it to a watch of the whole tree.
244//!
245//!   The backend is called for these reports in four cases:
246//!   [`Handle::watch`], through an open of a watched directory, on the
247//!   first request on that directory and on the next request after the
248//!   backend's reports stopped; a
249//!   FileBasicInformation that passed something to the backend calls
250//!   [`Handle::stat`] once more; a size change on a share with watches
251//!   calls `stat` before and after; and a rename into a watched directory
252//!   that may replace an entry or changes the case of a name calls, on a
253//!   case-sensitive backend, [`ShareBackend::open`] of the target and
254//!   `stat`, otherwise `open` of the target's directory and
255//!   [`Handle::list_dir`] with the target's name.
256//! - Share listing: unless [`SmbServerBuilder::share_listing`] turns it
257//!   off, IPC$ serves the `srvsvc` pipe, so clients can list the server's
258//!   shares. A session sees the shares it may connect to, in the order
259//!   they were added, and IPC$; for an anonymous session that is the
260//!   public shares, and a session that cannot encrypt does not see shares
261//!   whose traffic is encrypted. [`Share::listed`] leaves a share out of
262//!   the list without hiding it from lookups by name, and
263//!   [`Share::remark`] sets the comment shown next to it. Backends are not
264//!   called. Other pipe names fail with STATUS_OBJECT_NAME_NOT_FOUND,
265//!   DCE/RPC binds that carry authentication are refused, and one
266//!   connection may hold 16 pipes at once.
267//! - READ and WRITE lengths are bounded by the negotiated maximum sizes.
268//! - Each [`SmbError`] maps to one NTSTATUS for the client; see
269//!   [`SmbError::to_nt_status`].
270//!
271//! A handle is dropped without [`Handle::close`] when the task serving its
272//! connection panics or is cancelled, and when a [`ConfigHandle`] call that
273//! ends its session or tree is cancelled, so release resources in `Drop` as
274//! well.
275//!
276//! Later releases may add methods with default bodies, fields to
277//! [`FileInfo`], [`BackendCapabilities`], [`VolumeInfo`] and [`DirChange`],
278//! and variants to [`OpenIntent`] and [`DirChangeKind`]. A backend that
279//! implements the required methods, builds those types through
280//! [`FileInfo::new`], [`DirChange::new`] and the `Default` impls, and
281//! matches `OpenIntent` and `DirChangeKind` with a wildcard arm keeps
282//! compiling.
283
284mod access_mask;
285mod auth_policy;
286mod backend;
287mod builder;
288pub(crate) mod conn;
289mod dispatch;
290mod error;
291mod files;
292#[cfg(feature = "localfs")]
293mod fs;
294mod handlers;
295pub(crate) mod info_class;
296pub mod ntstatus;
297mod path;
298mod proto;
299mod rpc;
300mod server;
301#[cfg(test)]
302mod tests {
303    mod async_requests;
304    mod durable;
305    mod dynamic_config;
306    pub(crate) mod memfs;
307    mod notify;
308    pub(crate) mod peer;
309    mod pipes;
310}
311mod utils;
312mod wildcard;
313
314pub use backend::{
315    BackendCapabilities, DirChange, DirChangeKind, DirEntry, DirWatch, FileInfo, FileTimes, Handle,
316    OpenAction, OpenIntent, OpenOptions, ShareBackend, VolumeInfo,
317};
318pub use builder::{Access, BuildError, Share, SmbServerBuilder};
319pub use bytes::Bytes;
320pub use error::{SmbError, SmbResult};
321pub use files::{
322    DEFAULT_DURABLE_HANDLE_TIMEOUT, DEFAULT_MAX_DISCONNECTED_OPENS, DEFAULT_MAX_LOCKS_PER_OPEN,
323    DEFAULT_MAX_OPENS_PER_CONNECTION,
324};
325#[cfg(feature = "localfs")]
326pub use fs::LocalFsBackend;
327pub use path::SmbPath;
328pub use proto::auth::ntlm::Identity;
329pub use server::{ConfigError, ConfigHandle, ShareMode, ShutdownHandle, SmbServer};
330
331pub mod wire {
332    pub use crate::proto::header;
333    pub use crate::proto::messages;
334}
335
336/// Entry points for the cargo-fuzz targets in `fuzz/`. Built only with
337/// `--cfg fuzzing`, which `cargo fuzz` sets.
338#[cfg(fuzzing)]
339#[doc(hidden)]
340pub mod fuzzing {
341    use std::sync::Arc;
342
343    use crate::conn::state::Connection;
344    use crate::proto::auth::{ntlm, spnego};
345    use crate::proto::framing;
346    use crate::proto::header::Smb2Header;
347
348    /// Decodes the start of `data` as a transport frame header.
349    pub fn frame(data: &[u8]) {
350        if let Some(hdr) = data.first_chunk::<{ framing::FRAME_HEADER_LEN }>() {
351            let _ = framing::decode_frame_header(hdr);
352        }
353    }
354
355    /// Parses `data` as an SMB2 header.
356    pub fn header(data: &[u8]) {
357        let _ = Smb2Header::parse(data);
358    }
359
360    /// Decodes `data` as a SPNEGO NegTokenInit and as a NegTokenResp.
361    pub fn spnego(data: &[u8]) {
362        let _ = spnego::decode_init_token(data);
363        let _ = spnego::decode_resp_token(data);
364    }
365
366    /// Parses `data` as each NTLM message the server receives.
367    pub fn ntlm(data: &[u8]) {
368        let _ = ntlm::NtlmNegotiate::parse(data);
369        let _ = ntlm::NtlmAuthenticate::parse(data);
370    }
371
372    /// Parses `data` as the data of a lease create context.
373    pub fn lease_context(data: &[u8]) {
374        let _ = crate::proto::messages::LeaseContext::parse(data);
375    }
376
377    /// Parses `data` as a lease break acknowledgment.
378    pub fn lease_ack(data: &[u8]) {
379        let _ = crate::proto::messages::LeaseBreakAck::parse(data);
380    }
381
382    /// Parses `data` as the data of each durable handle create context.
383    pub fn durable_context(data: &[u8]) {
384        use crate::proto::messages::{
385            DurableReconnect, DurableReconnectV2, DurableRequest, DurableRequestV2,
386        };
387        let _ = DurableRequest::parse(data);
388        let _ = DurableReconnect::parse(data);
389        let _ = DurableRequestV2::parse(data);
390        let _ = DurableReconnectV2::parse(data);
391    }
392
393    /// Parses `data` as a create context chain and reads its durable handle
394    /// contexts on each dialect.
395    pub fn durable_ask(data: &[u8]) {
396        use crate::proto::messages::{CreateContext, Dialect};
397        let Ok(contexts) = CreateContext::parse_chain(data) else {
398            return;
399        };
400        for dialect in [
401            None,
402            Some(Dialect::Smb202),
403            Some(Dialect::Smb210),
404            Some(Dialect::Smb300),
405            Some(Dialect::Smb302),
406            Some(Dialect::Smb311),
407            Some(Dialect::Smb2Wildcard),
408        ] {
409            let _ = crate::handlers::create::durable_ask(&contexts, dialect);
410        }
411    }
412
413    /// Parses `data` as a DCE/RPC PDU a client sends.
414    pub fn rpc_pdu(data: &[u8]) {
415        let _ = crate::rpc::pdu::parse(data);
416    }
417
418    /// Writes `data` to an association in chunks whose size the first
419    /// byte picks, answering every call with a fault and with its stub as
420    /// a response. Every PDU sent back parses, a response fits in the size
421    /// the bind negotiated, and what the association holds stays bounded.
422    pub fn rpc_association(data: &[u8]) {
423        use crate::rpc::association::{Association, Fault, Step};
424        use crate::rpc::pdu::{
425            self, MAX_FRAG, NCA_OP_RNG_ERROR, PTYPE_ALTER_CONTEXT_RESP, PTYPE_BIND_ACK,
426            PTYPE_RESPONSE,
427        };
428
429        let Some((&chunk, data)) = data.split_first() else {
430            return;
431        };
432        let chunk = usize::from(chunk).max(1);
433        let mut assoc = Association::default();
434        let mut max_frag = MAX_FRAG;
435        for mut piece in data.chunks(chunk) {
436            while let Some(step) = assoc.next_step(&mut piece) {
437                let sent = match step {
438                    Step::Send(pdu) => vec![pdu],
439                    Step::Call(call) => {
440                        let fault = Fault {
441                            status: NCA_OP_RNG_ERROR,
442                            did_not_execute: true,
443                        };
444                        let mut replies = assoc.reply(&call, Err(fault));
445                        replies.extend(assoc.reply(&call, Ok(call.stub.clone())));
446                        replies
447                    }
448                };
449                for pdu in sent {
450                    assert!(pdu::parse(&pdu).is_some());
451                    match pdu[2] {
452                        PTYPE_BIND_ACK => max_frag = u16::from_le_bytes([pdu[16], pdu[17]]),
453                        PTYPE_RESPONSE => assert!(pdu.len() <= usize::from(max_frag)),
454                        PTYPE_ALTER_CONTEXT_RESP => {}
455                        _ => assert!(pdu.len() <= usize::from(MAX_FRAG)),
456                    }
457                }
458                assert!(assoc.held() <= (64 << 10) + usize::from(u16::MAX));
459            }
460        }
461    }
462
463    /// Runs `data` as a srvsvc request stub. The first byte picks the
464    /// operation: NetrShareEnum, NetrShareGetInfo, NetrServerGetInfo or,
465    /// with the second byte, any opnum. The caller sees three shares.
466    pub fn srvsvc_request(data: &[u8]) {
467        use crate::rpc::srvsvc::{self, ListedShare, ShareView};
468
469        let Some((&pick, stub)) = data.split_first() else {
470            return;
471        };
472        let (opnum, stub) = match pick % 4 {
473            0 => (srvsvc::OPNUM_SHARE_ENUM, stub),
474            1 => (srvsvc::OPNUM_SHARE_GET_INFO, stub),
475            2 => (srvsvc::OPNUM_SERVER_GET_INFO, stub),
476            _ => match stub.split_first() {
477                Some((&opnum, stub)) => (u16::from(opnum), stub),
478                None => return,
479            },
480        };
481        let share = |name: &str, kind, remark: &str| ListedShare {
482            name: name.to_string(),
483            kind,
484            remark: remark.to_string(),
485        };
486        let view = ShareView {
487            server_name: "FUZZ".to_string(),
488            shares: vec![
489                share("public", 0, ""),
490                share("d\u{f6}cs$", 0, "\u{1F9A4} remark"),
491                share("IPC$", 0x8000_0003, "Remote IPC"),
492            ],
493        };
494        let _ = srvsvc::call(opnum, stub, &view);
495    }
496
497    /// Dispatches one frame payload on a fresh connection to `server`.
498    pub async fn dispatch(server: &crate::SmbServer, frame: &[u8]) -> Option<Vec<u8>> {
499        let state = server.state();
500        let conn = Arc::new(Connection::new(
501            state.config.server_guid,
502            state.config.max_read_size,
503            state.config.max_write_size,
504        ));
505        crate::dispatch::dispatch_frame(&state, &conn, frame)
506            .await
507            .map(|out| out.bytes)
508    }
509}