Function users::switch::switch_user_group[][src]

pub fn switch_user_group(uid: uid_t, gid: gid_t) -> Result<SwitchUserGuard>

Sets the effective user and the effective group for the current scope.

Typically, trying to switch to any user or group other than the ones already running the process requires root privileges.

Security considerations

libc functions used

Errors

This function will return Err when an I/O error occurs during either the seteuid or setegid calls.

Examples

use users::switch::switch_user_group;
use std::mem::drop;

{
    let guard = switch_user_group(1001, 1001);
    // current and effective user and group IDs are 1001
    drop(guard);
}
// back to the old values