Skip to content

Commit 401bcd1

Browse files
authored
Further relax username requirements (#1149)
2 parents 65576dd + 0216e7e commit 401bcd1

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/sudoers/test/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,16 @@ fn invalid_username() {
364364
parse_eval::<ast::Sudo>("User_Alias FOO = $dollar");
365365
}
366366

367+
#[test]
368+
fn inclusive_username() {
369+
let UserSpecifier::User(Identifier::Name(sirin)) = parse_eval::<ast::UserSpecifier>("şirin")
370+
else {
371+
panic!();
372+
};
373+
374+
assert_eq!(sirin, "şirin");
375+
}
376+
367377
#[test]
368378
fn directive_test() {
369379
let y = parse_eval::<Spec<UserSpecifier>>;

src/sudoers/tokens.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use crate::common::{HARDENED_ENUM_VALUE_0, HARDENED_ENUM_VALUE_1, HARDENED_ENUM_
88
#[cfg_attr(test, derive(Clone, PartialEq, Eq))]
99
pub struct Username(pub SudoString);
1010

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

2526
fn accept(c: char) -> bool {
26-
c.is_ascii_alphanumeric() || ".-_@$".contains(c)
27+
c.is_alphanumeric() || ".-_@$".contains(c)
2728
}
2829

2930
fn accept_1st(c: char) -> bool {
30-
c != '_' && c != '@' && Self::accept(c)
31+
c != '@' && Self::accept(c)
3132
}
3233

3334
const ALLOW_ESCAPE: bool = true;

0 commit comments

Comments
 (0)