File: groups.rs

package info (click to toggle)
rust-uzers 0.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 272 kB
  • sloc: makefile: 2
file content (38 lines) | stat: -rw-r--r-- 969 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
extern crate uzers;
use uzers::{get_user_groups, group_access_list, Group, Users, UsersCache};

extern crate env_logger;

fn main() {
    env_logger::init();

    let cache = UsersCache::new();

    let user = cache
        .get_user_by_uid(cache.get_current_uid())
        .expect("No current user?");

    let mut groups: Vec<Group> =
        get_user_groups(user.name(), user.primary_group_id()).expect("No user groups?");

    groups.sort_by(|a, b| a.gid().cmp(&b.gid()));
    for group in groups {
        println!(
            "Group {} has name {}",
            group.gid(),
            group.name().to_string_lossy()
        );
    }

    let mut groups = group_access_list().expect("Group access list");

    groups.sort_by(|a, b| a.gid().cmp(&b.gid()));
    println!("\nGroup access list:");
    for group in groups {
        println!(
            "Group {} has name {}",
            group.gid(),
            group.name().to_string_lossy()
        );
    }
}