Enum AncillaryData

Source
pub enum AncillaryData<'a> {
    FileDescriptors(Cow<'a, [c_int]>),
    Credentials {
        pid: pid_t,
        uid: uid_t,
        gid: gid_t,
    },
}
Available on Unix only.
Expand description

Ancillary data to be sent through a Unix domain socket or read from an input buffer.

Ancillary data gives unique possibilities to Unix domain sockets which no other POSIX API has: passing file descriptors between two processes which do not have a parent-child relationship. It also can be used to transfer credentials of a process reliably.

Variants§

§

FileDescriptors(Cow<'a, [c_int]>)

One or more file descriptors to be sent.

§

Credentials

Available on Linux and (GNU or musl or target_env="musleabi" or target_env="musleabihf"), or Emscripten, or Redox only.

Credentials to be sent. The specified values are checked by the system when sent for all users except for the superuser – for senders, this means that the correct values need to be filled out, otherwise, an error is returned; for receivers, this means that the credentials are to be trusted for authentification purposes. For convenience, the credentials function provides a value which is known to be valid when sent.

Fields

§pid: pid_t

The process identificator (PID) for the process.

§uid: uid_t

The user identificator (UID) of the user who started the process.

§gid: gid_t

The group identificator (GID) of the user who started the process.

Implementations§

Source§

impl<'a> AncillaryData<'a>

Source

pub const ENCODED_SIZE_OF_CREDENTIALS: usize = 28usize

The size of a single AncillaryData::Credentials element when packed into the Unix ancillary data format. Useful for allocating a buffer when you expect to receive credentials.

Source

pub const fn encoded_size_of_file_descriptors(num_descriptors: usize) -> usize

Calculates the size of an AncillaryData::FileDescriptors element with the specified amount of file descriptors when packed into the Unix ancillary data format. Useful for allocating a buffer when you expect to receive a specific amount of file descriptors.

Source

pub fn clone_ref(&'a self) -> Self

Inexpensievly clones self by borrowing the FileDescriptors variant or copying the Credentials variant.

Source

pub fn encoded_size(&self) -> usize

Returns the size of an ancillary data element when packed into the Unix ancillary data format.

Source

pub fn encode( op: impl IntoIterator<Item = Self>, ) -> EncodedAncillaryData<'static>

Encodes the ancillary data into EncodedAncillaryData which is ready to be sent via a Unix domain socket.

Source§

impl AncillaryData<'static>

Source

pub fn credentials() -> Self

Available on Linux and (GNU or musl or target_env="musleabi" or target_env="musleabihf"), or Emscripten, or Redox only.

Fetches the credentials of the process from the system and returns a value which can be safely sent to another process without the system complaining about an unauthorized attempt to impersonate another process/user/group.

If you want to send credentials to another process, this is usually the function you need to obtain the desired ancillary payload.

Trait Implementations§

Source§

impl<'a> Clone for AncillaryData<'a>

Source§

fn clone(&self) -> AncillaryData<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for AncillaryData<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'b> FromIterator<AncillaryData<'b>> for EncodedAncillaryData<'static>

Source§

fn from_iter<I: IntoIterator<Item = AncillaryData<'b>>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a> Hash for AncillaryData<'a>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> PartialEq for AncillaryData<'a>

Source§

fn eq(&self, other: &AncillaryData<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Eq for AncillaryData<'a>

Source§

impl<'a> StructuralPartialEq for AncillaryData<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for AncillaryData<'a>

§

impl<'a> RefUnwindSafe for AncillaryData<'a>

§

impl<'a> Send for AncillaryData<'a>

§

impl<'a> Sync for AncillaryData<'a>

§

impl<'a> Unpin for AncillaryData<'a>

§

impl<'a> UnwindSafe for AncillaryData<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> To for T
where T: ?Sized,

Source§

fn to<T>(self) -> T
where Self: Into<T>,

Converts to T by calling Into<T>::into.
Source§

fn try_to<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Tries to convert to T by calling TryInto<T>::try_into.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.