Skip to main content

Share

Struct Share 

Source
pub struct Share { /* private fields */ }
Expand description

One share definition, attached to a single backend.

Implementations§

Source§

impl Share

Source

pub fn new(name: impl Into<String>, backend: impl ShareBackend) -> Self

Build a new share with the given name and backend.

Source

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.

Source

pub fn public_read_only(self) -> Self

Anonymous + authenticated read-only. Guest logons get the same access as anonymous sessions, as with Share::public.

Source

pub fn user(self, name: impl Into<String>, access: Access) -> Self

Grant access to the given (already-registered) user. Multiple calls accumulate.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn remark(self, remark: impl Into<String>) -> Self

Text shown next to the share in share lists: the Comment column of Explorer and smbclient -L, the Remark column of net view. At most 1024 UTF-16 code units, without NUL. Empty by default.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Share

§

impl !UnwindSafe for Share

§

impl Forget for Share

§

impl Freeze for Share

§

impl Move for Share

§

impl Send for Share

§

impl Sync for Share

§

impl Unpin for Share

§

impl UnsafeUnpin for Share

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more