pub struct Share { /* private fields */ }Expand description
One share definition, attached to a single backend.
Implementations§
Sourcepub fn new(name: impl Into<String>, backend: impl ShareBackend) -> Self
pub fn new(name: impl Into<String>, backend: impl ShareBackend) -> Self
Build a new share with the given name and backend.
Sourcepub fn public(self) -> Self
pub fn public(self) -> Self
Anonymous + authenticated read+write. A logon as guest with an
empty password, which the Finder sends for Connect As Guest, gets the
same access as an anonymous session unless a user of that name is
configured; the name matches in any case. Guest and anonymous traffic
is neither signed nor encrypted, so a client that requires signing
gets no guest session.
Sourcepub fn public_read_only(self) -> Self
pub fn public_read_only(self) -> Self
Anonymous + authenticated read-only. Guest logons get the same
access as anonymous sessions, as with Share::public.
Sourcepub fn user(self, name: impl Into<String>, access: Access) -> Self
pub fn user(self, name: impl Into<String>, access: Access) -> Self
Grant access to the given (already-registered) user. Multiple calls
accumulate.
Sourcepub fn encrypt_data(self) -> Self
pub fn encrypt_data(self) -> Self
Encrypt all traffic to this share. SMB 3.x clients that cannot
encrypt, SMB 2.x clients, and anonymous and guest sessions are
refused at TREE_CONNECT unless
SmbServerBuilder::reject_unencrypted_access is turned off.
Sourcepub fn leases(self, enabled: bool) -> Self
pub fn leases(self, enabled: bool) -> Self
Grant read, handle and write caching leases on this share’s files. A client holding one caches what it reads, keeps files open after its applications close them, and caches what it writes while every other open of the file holds the same lease or is attribute-only.
Opens on the share that do not hold the lease, from another client or from the same client under another lease key or none, break it: the client writes back and stops caching writes before such an open, drops cached data before a write, a size change, a byte-range lock or an overwrite through it, and closes the handles it keeps before an open they block, a rename or delete of the file, a rename over it, or a rename of a directory above it. Attribute-only opens and opens holding the same lease break nothing. An open or rename that needs the client to write back or close first waits until the client acknowledges the break or closes, or until the break times out 35 seconds after the server sent it; a byte-range lock is refused instead until the client has written back. On by default.
Each named stream of a file or directory has leases of its own: opens, writes, locks and leases of the file’s other streams break none of them, and a lease key held on one stream fails with STATUS_INVALID_PARAMETER on another, as on another file. A rename or delete of the file leaves them alone; an overwrite of the file, which deletes its streams, breaks their handle caching without waiting.
Changes made outside the server, or through another share over the same directory, break no lease: clients keep serving the old data. Turn leases off for such a share.
Sourcepub fn durable_handles(self, enabled: bool) -> Self
pub fn durable_handles(self, enabled: bool) -> Self
Keep a client’s open files for a while after its connection drops or
it logs off, with their share modes, byte-range locks and leases, so
the client can take them back when it reconnects. Only files opened
with a durable handle request and a lease that caches handles are
kept, so this does nothing when leases are off. The backend handle
stays open for SmbServerBuilder::durable_handle_timeout, or the
time a version 2 request was granted, or until an open, write, size change, byte-range lock, rename or
delete through an open that does not hold the lease needs what the
lease caches, which closes the file at once. A kept open of a named
stream also closes when its file is renamed, or deleted while no
connected open holds the same lease. The same user, from the
same client, on this share, takes a kept file back with a durable
handle reconnect that names the file, or its named stream, and its
lease, and for a version 2 open its CreateGuid. Another user gets
STATUS_ACCESS_DENIED; another client, share, lease or CreateGuid
gets STATUS_OBJECT_NAME_NOT_FOUND. A kept file whose rights exceed
what the user’s tree on the share grants at the reconnect is closed
instead. Version 1 and version 2 requests are both served; the
PERSISTENT flag is ignored. On by default.
Sourcepub fn change_notify(self, enabled: bool) -> Self
pub fn change_notify(self, enabled: bool) -> Self
Answer change notification requests: a client watching a folder, as
Explorer and Finder do for an open window, hears when a file or
folder in it is created, deleted, renamed, written, truncated or
overwritten, or has its attributes, times or extended attributes
set, through any connection to this share. A write, and a set of
extended attributes, is reported when the open that made it closes.
Changes made outside the server, or through another
share over the same directory, are reported only by a backend that
watches for them: LocalFsBackend does on Linux, for the entries
directly in a watched folder. When off, such a request reports
nothing and waits until it is cancelled or its handle closes. On by
default.
Sourcepub fn named_streams(self, enabled: bool) -> Self
pub fn named_streams(self, enabled: bool) -> Self
Serve named streams (file.txt:name) on the share when its backend
stores them (BackendCapabilities::named_streams). The share then
reports FILE_NAMED_STREAMS, and macOS clients keep extended
attributes, Finder tags and resource forks in streams rather than in
._ files. When off, a CREATE that names a stream fails with
STATUS_OBJECT_NAME_INVALID. On by default.
Sourcepub fn extended_attributes(self, enabled: bool) -> Self
pub fn extended_attributes(self, enabled: bool) -> Self
Serve the extended attributes of files and directories on the share
when its backend stores them
(BackendCapabilities::extended_attributes), as Linux clients
use for user.* attributes on a cifs mount. The share then reports
FILE_SUPPORTS_EXTENDED_ATTRIBUTES. When off, the share answers as a
volume that keeps none: FileFullEaInformation queries and sets fail
with STATUS_INVALID_DEVICE_REQUEST, FileEaInformation reports 0, and
a CREATE that carries some fails with STATUS_EAS_NOT_SUPPORTED.
Named streams do not depend on it. On by default.
Sourcepub fn server_side_copy(self, enabled: bool) -> Self
pub fn server_side_copy(self, enabled: bool) -> Self
Copy file data on the server when a client asks for it. Windows
Explorer, Linux cp and the macOS Finder send such a request for a
copy within a share; Windows and Linux also for a copy between two
shares of one session, which needs this on both. When off, the
requests fail with STATUS_NOT_SUPPORTED, a macOS whole-file copy of a
file fails with STATUS_ACCESS_DENIED, and a request on a named stream
fails with STATUS_INVALID_DEVICE_REQUEST; clients then read and write
the data themselves. The requests to clone a range of a file that a
backend with BackendCapabilities::block_cloning serves fail with
STATUS_INVALID_DEVICE_REQUEST too, and the share does not report
FILE_SUPPORTS_BLOCK_REFCOUNTING. On by default.
Sourcepub fn listed(self, listed: bool) -> Self
pub fn listed(self, listed: bool) -> Self
Whether the share appears when clients list the server’s shares.
An unlisted share is still reachable by name, and a client that may
connect to it can still look it up by name, so this is not access
control. Clients hide shares whose name ends in $ from ordinary
lists; net view /all and smbclient -L show them. On by default.