From 9a7fe9d3e81487e8f499666a5d617dbd8187a968 Mon Sep 17 00:00:00 2001 From: Antoine POPINEAU Date: Sat, 11 Nov 2023 09:45:24 +0100 Subject: [PATCH] Added a test and changed README. --- .github/workflows/dev.yml | 6 ++++++ .github/workflows/release.yml | 6 ++++++ .github/workflows/tip.yml | 6 ++++++ Cargo.toml | 4 ++++ README.md | 2 +- contrib/fixtures/group | 0 contrib/fixtures/passwd | 4 ++++ src/greeter.rs | 2 +- src/info.rs | 17 +++++++++++++++++ 9 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 contrib/fixtures/group create mode 100644 contrib/fixtures/passwd diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index e8ebf9f..e463686 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -22,10 +22,16 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable + - run: | + sudo apt update && sudo apt install -y libnss-wrapper - uses: Swatinem/rust-cache@v2 - name: Test + env: + NSS_WRAPPER_PASSWD: contrib/fixtures/passwd + NSS_WRAPPER_GROUP: contrib/fixtures/group run: | cargo test + LD_PRELOAD=libnss_wrapper.so cargo test --features nsswrapper nsswrapper_ build: strategy: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8270b4d..4a9e4d5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,10 +22,16 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable + - run: | + sudo apt update && sudo apt install -y libnss-wrapper - uses: Swatinem/rust-cache@v2 - name: Test + env: + NSS_WRAPPER_PASSWD: contrib/fixtures/passwd + NSS_WRAPPER_GROUP: contrib/fixtures/group run: | cargo test + LD_PRELOAD=libnss_wrapper.so cargo test --features nsswrapper nsswrapper_ build: strategy: diff --git a/.github/workflows/tip.yml b/.github/workflows/tip.yml index 56f3f65..4aeaf31 100644 --- a/.github/workflows/tip.yml +++ b/.github/workflows/tip.yml @@ -22,10 +22,16 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable + - run: | + sudo apt update && sudo apt install -y libnss-wrapper - uses: Swatinem/rust-cache@v2 - name: Test + env: + NSS_WRAPPER_PASSWD: contrib/fixtures/passwd + NSS_WRAPPER_GROUP: contrib/fixtures/group run: | cargo test + LD_PRELOAD=libnss_wrapper.so cargo test --features nsswrapper nsswrapper_ build: strategy: diff --git a/Cargo.toml b/Cargo.toml index 4b3ee34..9480fe5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,10 @@ authors = ["Antoine POPINEAU "] edition = "2018" build = "build.rs" +[features] +default = [] +nsswrapper = [] + [dependencies] chrono = { version = "^0.4", features = ["unstable-locales"] } crossterm = { version = "^0.27", features = ["event-stream"] } diff --git a/README.md b/README.md index 301e2a0..31161a5 100644 --- a/README.md +++ b/README.md @@ -195,7 +195,7 @@ Note that, by default, all commands are prefixed with `setsid` to completely det ### User menu -Optionally, a user can be selected from a menu instead of typing out their name, with the `--user-menu` option, this will present all users present in `/etc/passwd` at the time `tuigreet` was run, with a UID within the acceptable range. The values for the minimum and maximum UIDs are selected as follows, for each value: +Optionally, a user can be selected from a menu instead of typing out their name, with the `--user-menu` option, this will present all users returned by NSS at the time `tuigreet` was run, with a UID within the acceptable range. The values for the minimum and maximum UIDs are selected as follows, for each value: * A user-provided value, through `--user-menu-min-uid` or `--user-menu-max-uid`; * **Or**, the available values for `UID_MIN` or `UID_MAX` from `/etc/login.defs`; diff --git a/contrib/fixtures/group b/contrib/fixtures/group new file mode 100644 index 0000000..e69de29 diff --git a/contrib/fixtures/passwd b/contrib/fixtures/passwd new file mode 100644 index 0000000..5e4950a --- /dev/null +++ b/contrib/fixtures/passwd @@ -0,0 +1,4 @@ +root:x:0:0::/root:/bin/bash +joe:x:1000:1000:Joe:/home/joe:/bin/bash +bob:x:1500:1500::/home/bob:/bin/zsh +postgres:x:2100:2100::/srv/postgresql:/usr/bin/nologin diff --git a/src/greeter.rs b/src/greeter.rs index 175c23f..76ce43d 100644 --- a/src/greeter.rs +++ b/src/greeter.rs @@ -379,7 +379,7 @@ impl Greeter { } // Parses command line arguments to configured the software accordingly. - async fn parse_options(&mut self) { + pub async fn parse_options(&mut self) { let opts = Greeter::options(); self.config = match opts.parse(env::args().collect::>()) { diff --git a/src/info.rs b/src/info.rs index b4de606..0f364b4 100644 --- a/src/info.rs +++ b/src/info.rs @@ -256,3 +256,20 @@ pub fn capslock_status() -> bool { Err(_) => false, } } + +#[cfg(feature = "nsswrapper")] +#[cfg(test)] +mod nsswrapper_tests { + #[test] + fn nsswrapper_get_users_from_nss() { + use super::get_users; + + let users = get_users(1000, 2000); + + assert_eq!(users.len(), 2); + assert_eq!(users[0].username, "joe"); + assert_eq!(users[0].name, Some("Joe".to_string())); + assert_eq!(users[1].username, "bob"); + assert_eq!(users[1].name, None); + } +}