Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rfct: /etc/login.defs #91

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@ jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install GTK4
run: sudo apt update && sudo apt install libgtk-4-dev build-essential
- name: Install Rust
id: toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt, clippy
- run: rustup toolchain install stable --profile minimal
- name: Restore build cache
uses: Swatinem/rust-cache@v2
uses: Swatinem/[email protected]

- run: cargo build --verbose
- run: cargo test --verbose

- name: pre-commit
uses: pre-commit/[email protected].0
- uses: pre-commit-ci/lite-action@v1.0.0
uses: pre-commit/[email protected].1
- uses: pre-commit-ci/lite-action@v1.1.0
if: always()
67 changes: 59 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ license = "GPL-3.0-or-later"
[dependencies]
chrono = { version = "0.4.22", default-features = false }
clap = { version = "4.1.4", features = ["derive"] }
const_format = "0.2.26"
const_format = { version = "0.2.33", features = ["rust_1_64"] }
derivative = "2.2.0"
file-rotate = "0.7.2"
glob = "0.3.0"
greetd_ipc = { version = "0.9.0", features = ["tokio-codec"] }
gtk4 = "0.5"
lazy_static = "1.5.0"
lru = "0.9.0"
pwd = "1.4.0"
regex = "1.7.1"
Expand All @@ -38,3 +39,6 @@ tracker = "0.2.0"

[features]
gtk4_8 = ["gtk4/v4_8"]

[dev-dependencies]
test-case = "3.3.1"
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ LOG\_DIR | `/var/log/regreet` | The directory used to store logs
SESSION\_DIRS | `/usr/share/xsessions:/usr/share/wayland-sessions` | A colon (:) separated list of directories where the greeter looks for session files
REBOOT\_CMD | `reboot` | The default command used to reboot the system
POWEROFF\_CMD | `poweroff` | The default command used to shut down the system
LOGIN\_DEFS\_PATHS | `/etc/login.defs:/usr/etc/login.defs` | A colon (:) separated list of `login.defs` file paths. First found is loaded.
LOGIN\_DEFS\_UID\_MIN | 1000 | Override the assumed default if `login.defs` doesnt specify `UID_MIN`.
LOGIN\_DEFS\_UID\_MAX | 60000 | Override the assumed default if `login.defs` doesnt specify `UID_MAX`.

The greeter can be installed by copying the file `target/release/regreet` to `/usr/bin` (or similar directories like `/bin`).

Expand Down
1 change: 0 additions & 1 deletion src/cache/lru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use serde::{
ser::SerializeMap,
Deserialize, Deserializer, Serialize, Serializer,
};
use tracing::warn;

/// Wrapper to enable (de)serialization
pub(super) struct LruCache<K, V, S = DefaultHasher>(OrigLruCache<K, V, S>);
Expand Down
1 change: 0 additions & 1 deletion src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::num::NonZeroUsize;
use std::path::Path;

use serde::{Deserialize, Serialize};
use tracing::info;

use self::lru::LruCache;
use crate::constants::CACHE_PATH;
Expand Down
2 changes: 0 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use greetd_ipc::{
AuthMessageType, ErrorType, Request, Response,
};
use tokio::net::UnixStream;
use tracing::info;
use tracing::warn;

/// Environment variable containing the path to the greetd socket
const GREETD_SOCK_ENV_VAR: &str = "GREETD_SOCK";
Expand Down
41 changes: 39 additions & 2 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

//! Stores constants that can be configured at compile time

use const_format::concatcp;

/// Get an environment variable during compile time, else return a default.
macro_rules! env_or {
($name:expr, $default:expr) => {
Expand Down Expand Up @@ -49,6 +47,45 @@ pub const POWEROFF_CMD: &str = env_or!("POWEROFF_CMD", "poweroff");
/// Default greeting message
pub const GREETING_MSG: &str = "Welcome back!";

/// `:`-separated search path for `login.defs` file.
///
/// By default this file is at `/etc/login.defs`, however some distros (e.g. Tumbleweed) move it to other locations.
///
/// See: <https://github.com/rharish101/ReGreet/issues/89>
pub const LOGIN_DEFS_PATHS: &[&str] = {
const ENV: &str = env_or!("LOGIN_DEFS_PATHS", "/etc/login.defs:/usr/etc/login.defs");
&str_split!(ENV, ':')
};

lazy_static! {
/// Override the default `UID_MIN` in `login.defs`. If the string cannot be parsed at runtime, the value is `1_000`.
///
/// This is not meant as a configuration facility. Only override this value if it's a different default in the
/// `passwd` suite.
pub static ref LOGIN_DEFS_UID_MIN: u64 = {
const DEFAULT: u64 = 1_000;
const ENV: &str = env_or!("LOGIN_DEFS_UID_MIN", formatcp!("{DEFAULT}"));

ENV.parse()
.map_err(|e| error!("Failed to parse LOGIN_DEFS_UID_MIN='{ENV}': {e}. This is a compile time mistake!"))
.unwrap_or(DEFAULT)
};

/// Override the default `UID_MAX` in `login.defs`. If the string cannot be parsed at runtime, the value is
/// `60_000`.
///
/// This is not meant as a configuration facility. Only override this value if it's a different default in the
/// `passwd` suite.
pub static ref LOGIN_DEFS_UID_MAX: u64 = {
const DEFAULT: u64 = 60_000;
const ENV: &str = env_or!("LOGIN_DEFS_UID_MAX", formatcp!("{DEFAULT}"));

ENV.parse()
.map_err(|e| error!("Failed to parse LOGIN_DEFS_UID_MAX='{ENV}': {e}. This is a compile time mistake!"))
.unwrap_or(DEFAULT)
};
}

/// Directories separated by `:`, containing desktop files for X11/Wayland sessions
pub const SESSION_DIRS: &str = env_or!(
"SESSION_DIRS",
Expand Down
1 change: 0 additions & 1 deletion src/gui/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::path::PathBuf;
use std::time::Duration;

use chrono::Local;
use tracing::{debug, info, warn};

use gtk::prelude::*;
use relm4::{
Expand Down
1 change: 0 additions & 1 deletion src/gui/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use relm4::{
AsyncComponentSender,
};
use tokio::{sync::Mutex, time::sleep};
use tracing::{debug, error, info, instrument, warn};

use crate::cache::Cache;
use crate::client::{AuthStatus, GreetdClient};
Expand Down
11 changes: 11 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ use tracing_subscriber::{
use crate::constants::{APP_ID, CONFIG_PATH, CSS_PATH, LOG_PATH};
use crate::gui::{Greeter, GreeterInit};

#[macro_use]
extern crate tracing;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate const_format;

#[cfg(test)]
#[macro_use]
extern crate test_case;

const MAX_LOG_FILES: usize = 3;
const MAX_LOG_SIZE: usize = 1024 * 1024;

Expand Down
Loading