Skip to content

Further relax username requirements #1149

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

Merged
merged 2 commits into from
Jun 11, 2025
Merged
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
10 changes: 10 additions & 0 deletions src/sudoers/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,16 @@ fn invalid_username() {
parse_eval::<ast::Sudo>("User_Alias FOO = $dollar");
}

#[test]
fn inclusive_username() {
let UserSpecifier::User(Identifier::Name(sirin)) = parse_eval::<ast::UserSpecifier>("şirin")
else {
panic!();
};

assert_eq!(sirin, "şirin");
}

#[test]
fn directive_test() {
let y = parse_eval::<Spec<UserSpecifier>>;
Expand Down
7 changes: 4 additions & 3 deletions src/sudoers/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use crate::common::{HARDENED_ENUM_VALUE_0, HARDENED_ENUM_VALUE_1, HARDENED_ENUM_
#[cfg_attr(test, derive(Clone, PartialEq, Eq))]
pub struct Username(pub SudoString);

/// A username consists of alphanumeric characters as well as "." and "-", but does not start with an underscore.
/// A username consists of alphanumeric characters as well as ".", "-", "_".
/// Furthermore, it may contain embedded "@" characters (but not start with them) and end in a "$".
// See: https://systemd.io/USER_NAMES/
impl Token for Username {
fn construct(text: String) -> Result<Self, String> {
Expand All @@ -23,11 +24,11 @@ impl Token for Username {
}

fn accept(c: char) -> bool {
c.is_ascii_alphanumeric() || ".-_@$".contains(c)
c.is_alphanumeric() || ".-_@$".contains(c)
}

fn accept_1st(c: char) -> bool {
c != '_' && c != '@' && Self::accept(c)
c != '@' && Self::accept(c)
}

const ALLOW_ESCAPE: bool = true;
Expand Down
Loading