user-util: rework how we validate user names
This reworks the user validation infrastructure. There are now two modes. In regular mode we are strict and test against a strict set of valid chars. And in "relaxed" mode we just filter out some really obvious, dangerous stuff. i.e. strict is whitelisting what is OK, but "relaxed" is blacklisting what is really not OK. The idea is that we use strict mode whenver we allocate a new user (i.e. in sysusers.d or homed), while "relaxed" mode is when we process users registered elsewhere, (i.e. userdb, logind, …) The requirements on user name validity vary wildly. SSSD thinks its fine to embedd "@" for example, while the suggested NAME_REGEX field on Debian does not even allow uppercase chars… This effectively liberaralizes a lot what we expect from usernames. The code that warns about questionnable user names is now optional and only used at places such as unit file parsing, so that it doesn't show up on every userdb query, but only when processing configuration files that know better. Fixes: #15149 #15090
This commit is contained in:
+7
-14
@@ -97,20 +97,13 @@ static inline bool userns_supported(void) {
|
||||
return access("/proc/self/uid_map", F_OK) >= 0;
|
||||
}
|
||||
|
||||
bool valid_user_group_name_full(const char *u, bool strict);
|
||||
bool valid_user_group_name_or_id_full(const char *u, bool strict);
|
||||
static inline bool valid_user_group_name(const char *u) {
|
||||
return valid_user_group_name_full(u, true);
|
||||
}
|
||||
static inline bool valid_user_group_name_or_id(const char *u) {
|
||||
return valid_user_group_name_or_id_full(u, true);
|
||||
}
|
||||
static inline bool valid_user_group_name_compat(const char *u) {
|
||||
return valid_user_group_name_full(u, false);
|
||||
}
|
||||
static inline bool valid_user_group_name_or_id_compat(const char *u) {
|
||||
return valid_user_group_name_or_id_full(u, false);
|
||||
}
|
||||
typedef enum ValidUserFlags {
|
||||
VALID_USER_RELAX = 1 << 0,
|
||||
VALID_USER_WARN = 1 << 1,
|
||||
VALID_USER_ALLOW_NUMERIC = 1 << 2,
|
||||
} ValidUserFlags;
|
||||
|
||||
bool valid_user_group_name(const char *u, ValidUserFlags flags);
|
||||
bool valid_gecos(const char *d);
|
||||
bool valid_home(const char *p);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user