Struct UCred

Source
pub struct UCred { /* private fields */ }

Implementations§

Source§

impl UCred

Source

pub fn from_self() -> Result<UCred>

Use ucred_get(3C) with the P_MYID argument to get credentials for the current process.

Examples found in repository?
examples/whoami.rs (line 14)
13fn main() -> std::io::Result<()> {
14    let uc = UCred::from_self()?;
15
16    dbg!(uc.euid());
17    dbg!(uc.euser());
18
19    dbg!(uc.ruid());
20    dbg!(uc.ruser());
21
22    dbg!(uc.suid());
23    dbg!(uc.suser());
24
25    dbg!(uc.egid());
26    dbg!(uc.egroup());
27
28    dbg!(uc.rgid());
29    dbg!(uc.rgroup());
30
31    dbg!(uc.sgid());
32    dbg!(uc.sgroup());
33
34    dbg!(uc.groups());
35
36    dbg!(uc.pid());
37    dbg!(uc.project());
38    dbg!(uc.zoneid());
39
40    dbg!(uc.is_same_zone());
41    dbg!(uc.is_global_zone());
42
43    Ok(())
44}
Source

pub fn from_pid(pid: pid_t) -> Result<UCred>

Use ucred_get(3C) with get credentials for the nominated process.

Source

pub fn from_socket(fd: BorrowedFd<'_>) -> Result<UCred>

Use getpeerucred(3C) to obtain the credentials of the peer endpoint of a connection-oriented socket (SOCK_STREAM) or stream file descriptor.

Source

pub fn from_door_call() -> Result<UCred>

Use door_ucred(3C) to obtain the credentials of the client responsible for the current door invocation. It only makes sense to call this routine from a door call service procedure that is actively serving a door call.

Source

pub fn pid(&self) -> Option<pid_t>

Return the process ID, if the credential contains one.

Examples found in repository?
examples/whoami.rs (line 36)
13fn main() -> std::io::Result<()> {
14    let uc = UCred::from_self()?;
15
16    dbg!(uc.euid());
17    dbg!(uc.euser());
18
19    dbg!(uc.ruid());
20    dbg!(uc.ruser());
21
22    dbg!(uc.suid());
23    dbg!(uc.suser());
24
25    dbg!(uc.egid());
26    dbg!(uc.egroup());
27
28    dbg!(uc.rgid());
29    dbg!(uc.rgroup());
30
31    dbg!(uc.sgid());
32    dbg!(uc.sgroup());
33
34    dbg!(uc.groups());
35
36    dbg!(uc.pid());
37    dbg!(uc.project());
38    dbg!(uc.zoneid());
39
40    dbg!(uc.is_same_zone());
41    dbg!(uc.is_global_zone());
42
43    Ok(())
44}
Source

pub fn is_same_process(&self) -> bool

Does this credential come from the current process?

Source

pub fn project(&self) -> Option<projid_t>

Return the project ID of the process, if the credential contains one.

Examples found in repository?
examples/whoami.rs (line 37)
13fn main() -> std::io::Result<()> {
14    let uc = UCred::from_self()?;
15
16    dbg!(uc.euid());
17    dbg!(uc.euser());
18
19    dbg!(uc.ruid());
20    dbg!(uc.ruser());
21
22    dbg!(uc.suid());
23    dbg!(uc.suser());
24
25    dbg!(uc.egid());
26    dbg!(uc.egroup());
27
28    dbg!(uc.rgid());
29    dbg!(uc.rgroup());
30
31    dbg!(uc.sgid());
32    dbg!(uc.sgroup());
33
34    dbg!(uc.groups());
35
36    dbg!(uc.pid());
37    dbg!(uc.project());
38    dbg!(uc.zoneid());
39
40    dbg!(uc.is_same_zone());
41    dbg!(uc.is_global_zone());
42
43    Ok(())
44}
Source

pub fn zoneid(&self) -> Option<zoneid_t>

Return the zone ID of the zone in which the process resides, if the credential contains one.

Examples found in repository?
examples/whoami.rs (line 38)
13fn main() -> std::io::Result<()> {
14    let uc = UCred::from_self()?;
15
16    dbg!(uc.euid());
17    dbg!(uc.euser());
18
19    dbg!(uc.ruid());
20    dbg!(uc.ruser());
21
22    dbg!(uc.suid());
23    dbg!(uc.suser());
24
25    dbg!(uc.egid());
26    dbg!(uc.egroup());
27
28    dbg!(uc.rgid());
29    dbg!(uc.rgroup());
30
31    dbg!(uc.sgid());
32    dbg!(uc.sgroup());
33
34    dbg!(uc.groups());
35
36    dbg!(uc.pid());
37    dbg!(uc.project());
38    dbg!(uc.zoneid());
39
40    dbg!(uc.is_same_zone());
41    dbg!(uc.is_global_zone());
42
43    Ok(())
44}
Source

pub fn is_same_zone(&self) -> Result<bool>

Does this credential come from the same zone as the current process?

Examples found in repository?
examples/whoami.rs (line 40)
13fn main() -> std::io::Result<()> {
14    let uc = UCred::from_self()?;
15
16    dbg!(uc.euid());
17    dbg!(uc.euser());
18
19    dbg!(uc.ruid());
20    dbg!(uc.ruser());
21
22    dbg!(uc.suid());
23    dbg!(uc.suser());
24
25    dbg!(uc.egid());
26    dbg!(uc.egroup());
27
28    dbg!(uc.rgid());
29    dbg!(uc.rgroup());
30
31    dbg!(uc.sgid());
32    dbg!(uc.sgroup());
33
34    dbg!(uc.groups());
35
36    dbg!(uc.pid());
37    dbg!(uc.project());
38    dbg!(uc.zoneid());
39
40    dbg!(uc.is_same_zone());
41    dbg!(uc.is_global_zone());
42
43    Ok(())
44}
Source

pub fn is_global_zone(&self) -> bool

Does this credential come from a process in the global zone?

Examples found in repository?
examples/whoami.rs (line 41)
13fn main() -> std::io::Result<()> {
14    let uc = UCred::from_self()?;
15
16    dbg!(uc.euid());
17    dbg!(uc.euser());
18
19    dbg!(uc.ruid());
20    dbg!(uc.ruser());
21
22    dbg!(uc.suid());
23    dbg!(uc.suser());
24
25    dbg!(uc.egid());
26    dbg!(uc.egroup());
27
28    dbg!(uc.rgid());
29    dbg!(uc.rgroup());
30
31    dbg!(uc.sgid());
32    dbg!(uc.sgroup());
33
34    dbg!(uc.groups());
35
36    dbg!(uc.pid());
37    dbg!(uc.project());
38    dbg!(uc.zoneid());
39
40    dbg!(uc.is_same_zone());
41    dbg!(uc.is_global_zone());
42
43    Ok(())
44}
Source

pub fn euid(&self) -> Option<uid_t>

Return the effective user ID for the user credential, if it contains one.

Examples found in repository?
examples/whoami.rs (line 16)
13fn main() -> std::io::Result<()> {
14    let uc = UCred::from_self()?;
15
16    dbg!(uc.euid());
17    dbg!(uc.euser());
18
19    dbg!(uc.ruid());
20    dbg!(uc.ruser());
21
22    dbg!(uc.suid());
23    dbg!(uc.suser());
24
25    dbg!(uc.egid());
26    dbg!(uc.egroup());
27
28    dbg!(uc.rgid());
29    dbg!(uc.rgroup());
30
31    dbg!(uc.sgid());
32    dbg!(uc.sgroup());
33
34    dbg!(uc.groups());
35
36    dbg!(uc.pid());
37    dbg!(uc.project());
38    dbg!(uc.zoneid());
39
40    dbg!(uc.is_same_zone());
41    dbg!(uc.is_global_zone());
42
43    Ok(())
44}
Source

pub fn euser(&self) -> Result<Option<User>>

Resolve the effective user ID to a username and return it.

NOTE: Each zone has its own independent passwd(5) database. If this credential represents a user in another zone, it may not be correct to resolve it to a name using the local database unless those databases are synchronised through some operational process.

Examples found in repository?
examples/whoami.rs (line 17)
13fn main() -> std::io::Result<()> {
14    let uc = UCred::from_self()?;
15
16    dbg!(uc.euid());
17    dbg!(uc.euser());
18
19    dbg!(uc.ruid());
20    dbg!(uc.ruser());
21
22    dbg!(uc.suid());
23    dbg!(uc.suser());
24
25    dbg!(uc.egid());
26    dbg!(uc.egroup());
27
28    dbg!(uc.rgid());
29    dbg!(uc.rgroup());
30
31    dbg!(uc.sgid());
32    dbg!(uc.sgroup());
33
34    dbg!(uc.groups());
35
36    dbg!(uc.pid());
37    dbg!(uc.project());
38    dbg!(uc.zoneid());
39
40    dbg!(uc.is_same_zone());
41    dbg!(uc.is_global_zone());
42
43    Ok(())
44}
Source

pub fn ruid(&self) -> Option<uid_t>

Return the real user ID for the user credential, if it contains one.

Examples found in repository?
examples/whoami.rs (line 19)
13fn main() -> std::io::Result<()> {
14    let uc = UCred::from_self()?;
15
16    dbg!(uc.euid());
17    dbg!(uc.euser());
18
19    dbg!(uc.ruid());
20    dbg!(uc.ruser());
21
22    dbg!(uc.suid());
23    dbg!(uc.suser());
24
25    dbg!(uc.egid());
26    dbg!(uc.egroup());
27
28    dbg!(uc.rgid());
29    dbg!(uc.rgroup());
30
31    dbg!(uc.sgid());
32    dbg!(uc.sgroup());
33
34    dbg!(uc.groups());
35
36    dbg!(uc.pid());
37    dbg!(uc.project());
38    dbg!(uc.zoneid());
39
40    dbg!(uc.is_same_zone());
41    dbg!(uc.is_global_zone());
42
43    Ok(())
44}
Source

pub fn ruser(&self) -> Result<Option<User>>

Resolve the real user ID to a username and return it.

NOTE: Each zone has its own independent passwd(5) database. If this credential represents a user in another zone, it may not be correct to resolve it to a name using the local database unless those databases are synchronised through some operational process.

Examples found in repository?
examples/whoami.rs (line 20)
13fn main() -> std::io::Result<()> {
14    let uc = UCred::from_self()?;
15
16    dbg!(uc.euid());
17    dbg!(uc.euser());
18
19    dbg!(uc.ruid());
20    dbg!(uc.ruser());
21
22    dbg!(uc.suid());
23    dbg!(uc.suser());
24
25    dbg!(uc.egid());
26    dbg!(uc.egroup());
27
28    dbg!(uc.rgid());
29    dbg!(uc.rgroup());
30
31    dbg!(uc.sgid());
32    dbg!(uc.sgroup());
33
34    dbg!(uc.groups());
35
36    dbg!(uc.pid());
37    dbg!(uc.project());
38    dbg!(uc.zoneid());
39
40    dbg!(uc.is_same_zone());
41    dbg!(uc.is_global_zone());
42
43    Ok(())
44}
Source

pub fn suid(&self) -> Option<uid_t>

Return the saved user ID for the user credential, if it contains one.

Examples found in repository?
examples/whoami.rs (line 22)
13fn main() -> std::io::Result<()> {
14    let uc = UCred::from_self()?;
15
16    dbg!(uc.euid());
17    dbg!(uc.euser());
18
19    dbg!(uc.ruid());
20    dbg!(uc.ruser());
21
22    dbg!(uc.suid());
23    dbg!(uc.suser());
24
25    dbg!(uc.egid());
26    dbg!(uc.egroup());
27
28    dbg!(uc.rgid());
29    dbg!(uc.rgroup());
30
31    dbg!(uc.sgid());
32    dbg!(uc.sgroup());
33
34    dbg!(uc.groups());
35
36    dbg!(uc.pid());
37    dbg!(uc.project());
38    dbg!(uc.zoneid());
39
40    dbg!(uc.is_same_zone());
41    dbg!(uc.is_global_zone());
42
43    Ok(())
44}
Source

pub fn suser(&self) -> Result<Option<User>>

Resolve the saved user ID to a username and return it.

NOTE: Each zone has its own independent passwd(5) database. If this credential represents a user in another zone, it may not be correct to resolve it to a name using the local database unless those databases are synchronised through some operational process.

Examples found in repository?
examples/whoami.rs (line 23)
13fn main() -> std::io::Result<()> {
14    let uc = UCred::from_self()?;
15
16    dbg!(uc.euid());
17    dbg!(uc.euser());
18
19    dbg!(uc.ruid());
20    dbg!(uc.ruser());
21
22    dbg!(uc.suid());
23    dbg!(uc.suser());
24
25    dbg!(uc.egid());
26    dbg!(uc.egroup());
27
28    dbg!(uc.rgid());
29    dbg!(uc.rgroup());
30
31    dbg!(uc.sgid());
32    dbg!(uc.sgroup());
33
34    dbg!(uc.groups());
35
36    dbg!(uc.pid());
37    dbg!(uc.project());
38    dbg!(uc.zoneid());
39
40    dbg!(uc.is_same_zone());
41    dbg!(uc.is_global_zone());
42
43    Ok(())
44}
Source

pub fn egid(&self) -> Option<gid_t>

Return the effective user ID for the user credential, if it contains one.

Examples found in repository?
examples/whoami.rs (line 25)
13fn main() -> std::io::Result<()> {
14    let uc = UCred::from_self()?;
15
16    dbg!(uc.euid());
17    dbg!(uc.euser());
18
19    dbg!(uc.ruid());
20    dbg!(uc.ruser());
21
22    dbg!(uc.suid());
23    dbg!(uc.suser());
24
25    dbg!(uc.egid());
26    dbg!(uc.egroup());
27
28    dbg!(uc.rgid());
29    dbg!(uc.rgroup());
30
31    dbg!(uc.sgid());
32    dbg!(uc.sgroup());
33
34    dbg!(uc.groups());
35
36    dbg!(uc.pid());
37    dbg!(uc.project());
38    dbg!(uc.zoneid());
39
40    dbg!(uc.is_same_zone());
41    dbg!(uc.is_global_zone());
42
43    Ok(())
44}
Source

pub fn egroup(&self) -> Result<Option<Group>>

Resolve the effective group ID to a group name and return it.

NOTE: Each zone has its own independent group(5) database. If this credential represents a group in another zone, it may not be correct to resolve it to a name using the local database unless those databases are synchronised through some operational process.

Examples found in repository?
examples/whoami.rs (line 26)
13fn main() -> std::io::Result<()> {
14    let uc = UCred::from_self()?;
15
16    dbg!(uc.euid());
17    dbg!(uc.euser());
18
19    dbg!(uc.ruid());
20    dbg!(uc.ruser());
21
22    dbg!(uc.suid());
23    dbg!(uc.suser());
24
25    dbg!(uc.egid());
26    dbg!(uc.egroup());
27
28    dbg!(uc.rgid());
29    dbg!(uc.rgroup());
30
31    dbg!(uc.sgid());
32    dbg!(uc.sgroup());
33
34    dbg!(uc.groups());
35
36    dbg!(uc.pid());
37    dbg!(uc.project());
38    dbg!(uc.zoneid());
39
40    dbg!(uc.is_same_zone());
41    dbg!(uc.is_global_zone());
42
43    Ok(())
44}
Source

pub fn rgid(&self) -> Option<gid_t>

Return the real user ID for the user credential, if it contains one.

Examples found in repository?
examples/whoami.rs (line 28)
13fn main() -> std::io::Result<()> {
14    let uc = UCred::from_self()?;
15
16    dbg!(uc.euid());
17    dbg!(uc.euser());
18
19    dbg!(uc.ruid());
20    dbg!(uc.ruser());
21
22    dbg!(uc.suid());
23    dbg!(uc.suser());
24
25    dbg!(uc.egid());
26    dbg!(uc.egroup());
27
28    dbg!(uc.rgid());
29    dbg!(uc.rgroup());
30
31    dbg!(uc.sgid());
32    dbg!(uc.sgroup());
33
34    dbg!(uc.groups());
35
36    dbg!(uc.pid());
37    dbg!(uc.project());
38    dbg!(uc.zoneid());
39
40    dbg!(uc.is_same_zone());
41    dbg!(uc.is_global_zone());
42
43    Ok(())
44}
Source

pub fn rgroup(&self) -> Result<Option<Group>>

Resolve the real group ID to a group name and return it.

NOTE: Each zone has its own independent group(5) database. If this credential represents a group in another zone, it may not be correct to resolve it to a name using the local database unless those databases are synchronised through some operational process.

Examples found in repository?
examples/whoami.rs (line 29)
13fn main() -> std::io::Result<()> {
14    let uc = UCred::from_self()?;
15
16    dbg!(uc.euid());
17    dbg!(uc.euser());
18
19    dbg!(uc.ruid());
20    dbg!(uc.ruser());
21
22    dbg!(uc.suid());
23    dbg!(uc.suser());
24
25    dbg!(uc.egid());
26    dbg!(uc.egroup());
27
28    dbg!(uc.rgid());
29    dbg!(uc.rgroup());
30
31    dbg!(uc.sgid());
32    dbg!(uc.sgroup());
33
34    dbg!(uc.groups());
35
36    dbg!(uc.pid());
37    dbg!(uc.project());
38    dbg!(uc.zoneid());
39
40    dbg!(uc.is_same_zone());
41    dbg!(uc.is_global_zone());
42
43    Ok(())
44}
Source

pub fn sgid(&self) -> Option<gid_t>

Return the saved user ID for the user credential, if it contains one.

Examples found in repository?
examples/whoami.rs (line 31)
13fn main() -> std::io::Result<()> {
14    let uc = UCred::from_self()?;
15
16    dbg!(uc.euid());
17    dbg!(uc.euser());
18
19    dbg!(uc.ruid());
20    dbg!(uc.ruser());
21
22    dbg!(uc.suid());
23    dbg!(uc.suser());
24
25    dbg!(uc.egid());
26    dbg!(uc.egroup());
27
28    dbg!(uc.rgid());
29    dbg!(uc.rgroup());
30
31    dbg!(uc.sgid());
32    dbg!(uc.sgroup());
33
34    dbg!(uc.groups());
35
36    dbg!(uc.pid());
37    dbg!(uc.project());
38    dbg!(uc.zoneid());
39
40    dbg!(uc.is_same_zone());
41    dbg!(uc.is_global_zone());
42
43    Ok(())
44}
Source

pub fn sgroup(&self) -> Result<Option<Group>>

Resolve the saved group ID to a group name and return it.

NOTE: Each zone has its own independent group(5) database. If this credential represents a group in another zone, it may not be correct to resolve it to a name using the local database unless those databases are synchronised through some operational process.

Examples found in repository?
examples/whoami.rs (line 32)
13fn main() -> std::io::Result<()> {
14    let uc = UCred::from_self()?;
15
16    dbg!(uc.euid());
17    dbg!(uc.euser());
18
19    dbg!(uc.ruid());
20    dbg!(uc.ruser());
21
22    dbg!(uc.suid());
23    dbg!(uc.suser());
24
25    dbg!(uc.egid());
26    dbg!(uc.egroup());
27
28    dbg!(uc.rgid());
29    dbg!(uc.rgroup());
30
31    dbg!(uc.sgid());
32    dbg!(uc.sgroup());
33
34    dbg!(uc.groups());
35
36    dbg!(uc.pid());
37    dbg!(uc.project());
38    dbg!(uc.zoneid());
39
40    dbg!(uc.is_same_zone());
41    dbg!(uc.is_global_zone());
42
43    Ok(())
44}
Source

pub fn groups(&self) -> Option<&[gid_t]>

Examples found in repository?
examples/whoami.rs (line 34)
13fn main() -> std::io::Result<()> {
14    let uc = UCred::from_self()?;
15
16    dbg!(uc.euid());
17    dbg!(uc.euser());
18
19    dbg!(uc.ruid());
20    dbg!(uc.ruser());
21
22    dbg!(uc.suid());
23    dbg!(uc.suser());
24
25    dbg!(uc.egid());
26    dbg!(uc.egroup());
27
28    dbg!(uc.rgid());
29    dbg!(uc.rgroup());
30
31    dbg!(uc.sgid());
32    dbg!(uc.sgroup());
33
34    dbg!(uc.groups());
35
36    dbg!(uc.pid());
37    dbg!(uc.project());
38    dbg!(uc.zoneid());
39
40    dbg!(uc.is_same_zone());
41    dbg!(uc.is_global_zone());
42
43    Ok(())
44}

Trait Implementations§

Source§

impl Drop for UCred

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for UCred

§

impl RefUnwindSafe for UCred

§

impl !Send for UCred

§

impl !Sync for UCred

§

impl Unpin for UCred

§

impl UnwindSafe for UCred

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, 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, 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.