Expand description

Get user information stored in the password file /etc/passwd.

This crate provides a safe wrapper for libc functions such as getpwnam_r(3) and getpwuid_r(3).

Usage

Add this to your Cargo.toml:

[dependencies]
etc-passwd = "0.2.0"

Examples

Get a current user information:

use etc_passwd::Passwd;

if let Some(passwd) = Passwd::current_user()? {
    println!("current user name is: {}", passwd.name.to_str()?);
    println!("your user id is: {}", passwd.uid);
    println!("your group id is: {}", passwd.gid);
    println!("your full name is: {}", passwd.gecos.to_str()?);
    println!("your home directory is: {}", passwd.dir.to_str()?);
    println!("your login shell is: {}", passwd.shell.to_str()?);
} else {
    println!("oops! current user is not found... who are you?");
}

Structs

Representation of a user information stored in the password file /etc/passwd.