Struct login_cap::LoginCap[][src]

pub struct LoginCap { /* fields omitted */ }
Expand description

High-level type for login_cap_t

Implementations

Get the login class for the provided user name

Supplying an empty user name will look up the default user

Fails if the username is not a valid UTF8 string, or if no class can be found for the user

Example:

assert!(LoginCap::new("default").is_ok());
assert!(LoginCap::new("not-a-class").is_err());

Get the style of authentication for this user class

If style or type are empty, a NULL pointer will be supplied to the FFI call to login_getstyle

Example:

let cap = LoginCap::new("default").unwrap();

let cap_style = cap.getstyle("passwd", "").unwrap();
assert_eq!(cap_style.as_str(), "passwd");

let cap_style = cap.getstyle("", "auth-doas").unwrap();
assert_eq!(cap_style.as_str(), "passwd");

assert!(cap.getstyle("not-a-style", "").is_err());

From login_getclass(3):

The login_getstyle() function is used to obtain the style of authentication that should be used for this user class.

The style argument may either be NULL or the desired style of authentication.
If NULL, the first available authentication style will be used.

The type argument refers to the type of authentication being performed. 
This is used to override the standard auth entry in the database.
By convention this should be of the form "auth-type".

Future releases may remove the requirement for the "auth-" prefix and add it if it is missing.

If type is NULL then only "auth" will be looked at (see login.conf(5)).  The

login_getstyle() function will return NULL if the desired style of
authentication is not available, or if no style is available.

Get whether capabilities are found for the login class

Example:

let cap = LoginCap::new("default").unwrap();
assert!(cap.getcapbool("umask", 022).unwrap());
assert!(cap.getcapbool("not a cap", 0).is_err());

From login_getclass(3):

login_getcapbool(3) returns def if no capabilities were found for this class (typically meaning that
the default class was used and the /etc/login.conf file is missing).  It
returns a non-zero value if cap, with no value, was found, zero
otherwise.

Returns error if default class was used, and /etc/login.conf file is missing

Returns Ok(false) if non-zero value returned

Returns Ok(true) otherwise

Get the capability value for the login class

Example:

let cap = LoginCap::new("default").unwrap();
let cap_num = cap.getcapnum("umask", 0, -1).unwrap();

assert_eq!(cap_num, 18);

From login_getclass(3):

The login_getcapnum() function queries the database entry for a field
named cap.  If the field is found, its value is returned.  If the field
is not found, the value specified by def is returned.  If an error is
encountered while trying to find the field, err is returned.

See login.conf(5) for a discussion of the various textual forms the value may take.

Get the capability value for the login class

Example:

let cap = LoginCap::new("default").unwrap();
let cap_size = cap.getcapsize("umask", 0, -1).unwrap();

assert_eq!(cap_size, 18);

From login_getclass(3):

The login_getcapsize() function queries the database entry for a field
named cap.  If the field is found, its value is returned.  If the field
is not found, the value specified by def is returned.  If an error is
encountered while trying to find the field, err is returned.

See login.conf(5) for a discussion of the various textual forms the value may take.

Get the capability value for the login class

Example:

let cap = LoginCap::new("default").unwrap();
let cap_str = cap.getcapstr("localcipher", "default", "no cipher").unwrap();
assert_eq!(cap_str.as_str(), "blowfish,a");

From login_getclass(3):

The login_getcapstr() function queries the database entry for a field
named cap.  If the field is found, its value is returned.  If the field
is not found, the value specified by def is returned.  If an error is
encountered while trying to find the field, err is returned.

See login.conf(5) for a discussion of the various textual forms the value may take.

Get the capability value for the login class

Example:

let cap = LoginCap::new("default").unwrap();
let cap_time = cap.getcaptime("umask", 0, -1).unwrap();

assert_eq!(cap_time, 18);

From login_getclass(3):

The login_getcaptime() function queries the database entry for a field
named cap.  If the field is found, its value is returned.  If the field
is not found, the value specified by def is returned.  If an error is
encountered while trying to find the field, err is returned.

See login.conf(5) for a discussion of the various textual forms the value may take.

Set user resources according to flags

The flags argument can be produced by ORing together two or more LoginFlags variants, or converting a single LoginFlags variant.

Example:

if let Ok(cap) = LoginCap::new("default") {
    let nobody_uid = Uid::from_raw(32767);
    cap.setusercontext(
        None,
        nobody_uid,
        LoginFlags::SetEnv | LoginFlags::SetUmask,
    ).unwrap();
    /* or */
    cap.setusercontext(
        None,
        nobody_uid,
        LoginFlags::SetEnv.into(),
    ).unwrap();
}

From login_getclass(3):

The setusercontext() function sets the resources according to flags.  The
lc argument, if not NULL, contains the class information that should be
used.  The pwd argument, if not NULL, provides information about the
user.  Both lc and pwd cannot be NULL.  The uid argument is used in place
of the user ID contained in the pwd structure when calling setuid(2).
The setusercontext() function returns 0 on success and -1 on failure.

Trait Implementations

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.