Skip to content

Conversation

@sargas
Copy link

@sargas sargas commented Dec 10, 2025

This PR establishes the foundational structure for the login utility, focusing primarily on parsing the /etc/login.defs configuration file and setting up the basic command-line interface.

This is the first step towards implementing parts of shadow-utils. The goal of this PR is to get the configuration loading and argument parsing logic in place so that subsequent PRs can focus on the actual authentication, PAM integration, and session management logic.

Key Changes

  1. Configuration Parsing (login_defs.rs)
    I've implemented a robust parser for login.defs that mirrors the behavior of shadow-utils. The parser collects warnings (e.g., file not found, permission errors, invalid values) instead of crashing, allowing login to fall back to safe defaults. It maps configuration keys to strongly typed fields (e.g., Option<u32> for timeouts, Option<PathBuf> for files). It handles most keys in shadow-utils's login.defs(5), including all the ones that seem required for login.
  2. CLI Structure (login.rs)
    Add clap argument parsing, along with a LoginConfiguration struct to hold parsed arguments.
  3. Integration test
    Added a preliminary check to ensure the login binary is running with root privileges (or SUID), returning a standard "must be suid to work properly" error if not. This gave some behavior for a basic test case to be created.
  4. Dependency updates
    Most dependencies are updated except for uucore. Adopting this codebase to the current uucore appears to need some code changes due to the help_about and help_usage macros changing. A change to build.rs was needed; it appears to be part of Bump phf_codegen & fix compilation error #169 and can be removed from this PR if that one is merged first.

@sargas
Copy link
Author

sargas commented Dec 10, 2025

The unused warnings are deliberate - I'm trying to do only part of the work here.

The compiling errors on Windows due to the bytes->file names ambiguity could be worked around (I could assume the login.defs file is utf8 and find an equivalent utf16 file name for Windows, or assume the whole file is encoded differently, or just the file paths). This seems pretty pointless though: I'm not sure which of these tools in shadow would be usable without Unix paths or at least something like WSL.

…rser

Implement the core infrastructure for the login utility, including
command-line argument parsing and a comprehensive parser for the
/etc/login.defs configuration file.

- Add src/uu/login/src/login_defs.rs to parse login.defs configuration.
- Implement `LoginDefs` struct with support for numeric and string fields.
- Add extensive unit tests for configuration parsing, including error handling
  for permissions and invalid values.
- Update src/uu/login/src/login.rs with `clap` arguments for standard
  flags (-p, -f, -h, -H).
- Add `LoginConfiguration` to map CLI arguments.
- Add basic root privileges check in `perform_login`.
- Add basic integration test in tests/by-util/test_login.rs.
- Update dependencies in `Cargo.toml`.
Remove Windows from matrices for check, test, clippy, and coverage.
Windows has a completely different model for what "users" and "groups"
are compared to *nix systems.
@sargas sargas force-pushed the login-defs-definition branch from 9a8339a to eabda9d Compare December 11, 2025 01:15
# spell-checker:ignore (libs) mangen procfs

[package]
name = "login"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much of this is reordered for consistency with uutils/coreutils's workspace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant