shared/user-util: emit a warning on names with dots

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-08-28 12:05:52 +02:00
parent ae480f0b09
commit 88e2ed0b5b
1 changed files with 20 additions and 7 deletions

View File

@ -645,13 +645,26 @@ bool valid_user_group_name_full(const char *u, bool strict) {
u[0] != '_')
return false;
for (i = u+1; *i; i++)
if (!((*i >= 'a' && *i <= 'z') ||
(*i >= 'A' && *i <= 'Z') ||
(*i >= '0' && *i <= '9') ||
IN_SET(*i, '_', '-') ||
(!strict && *i == '.')))
return false;
bool warned = false;
for (i = u+1; *i; i++) {
if (((*i >= 'a' && *i <= 'z') ||
(*i >= 'A' && *i <= 'Z') ||
(*i >= '0' && *i <= '9') ||
IN_SET(*i, '_', '-')))
continue;
if (*i == '.' && !strict) {
if (!warned) {
log_warning("Bad user or group name \"%s\", accepting for compatibility.", u);
warned = true;
}
continue;
}
return false;
}
sz = sysconf(_SC_LOGIN_NAME_MAX);
assert_se(sz > 0);