[gnome-initial-setup/wip/wjt/forbid-uppercase-letters-in-usernames] account: Apply stricter rules for usernames
- From: Will Thompson <wjt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup/wip/wjt/forbid-uppercase-letters-in-usernames] account: Apply stricter rules for usernames
- Date: Fri, 26 Aug 2022 20:25:55 +0000 (UTC)
commit 1e35caca43cb7fc0a7bc7e38bcccaa22248bda5e
Author: Will Thompson <wjt endlessos org>
Date: Fri Aug 26 21:11:54 2022 +0100
account: Apply stricter rules for usernames
On Debian-like systems, accountsservice is patched to invoke 'adduser'
rather than 'useradd'. 'adduser', by default, imposes stricter rules on
usernames than Initial Setup previously enforced: they may not contain
uppercase letters or periods.
Ideally, Initial Setup would simply ask the system what rules are in
place. However no mechanism to do that is obvious at this time:
- gnome-control-center invokes 'usermod --login USERNAME -- USERNAME'
and inspects its exit code; but some quick testing reveals that this
method fails to reject names that 'adduser' will reject, such as 'æ'
and 'a.e'.
- We could parse /etc/adduser.conf and use its NAME_REGEX on Debian-like
systems, but
https://gitlab.gnome.org/GNOME/gnome-initial-setup/-/issues/117
suggests that this problem also affects Arch-like systems, which as
far as I know do not have /etc/adduser.conf – they have a *different*
adduser script!
- Of course the ultimate test is just to try creating the user and see
if it fails; but Initial Setup is not currently structured in a way
that makes that possible.
So as a shorter-term workaround, just impose the same rules that Debian
imposes. Alas, this means rejecting valid usernames on other distros.
(I'm keeping the old tip as a translatable string in case such distros
wish to revert this patch.)
Fixes https://gitlab.gnome.org/GNOME/gnome-initial-setup/-/issues/117
gnome-initial-setup/pages/account/um-utils.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/gnome-initial-setup/pages/account/um-utils.c b/gnome-initial-setup/pages/account/um-utils.c
index 39887498..e0bc4403 100644
--- a/gnome-initial-setup/pages/account/um-utils.c
+++ b/gnome-initial-setup/pages/account/um-utils.c
@@ -106,6 +106,9 @@ is_valid_name (const gchar *name)
return !is_empty;
}
+#define OLD_TIP N_("The username should only consist of upper and lower case letters from a-z, digits and
the following characters: . - _")
+#undef OLD_TIP
+
gboolean
is_valid_username (const gchar *username, gboolean parental_controls_enabled, gchar **tip)
{
@@ -129,13 +132,12 @@ is_valid_username (const gchar *username, gboolean parental_controls_enabled, gc
if (!in_use && !empty && !too_long) {
/* First char must be a letter, and it must only composed
- * of ASCII letters, digits, and a '.', '-', '_'
+ * of lowercase ASCII letters, digits, and '-' or '_'
*/
for (c = username; *c; c++) {
if (! ((*c >= 'a' && *c <= 'z') ||
- (*c >= 'A' && *c <= 'Z') ||
(*c >= '0' && *c <= '9') ||
- (*c == '_') || (*c == '.') ||
+ (*c == '_') ||
(*c == '-' && c != username)))
valid = FALSE;
}
@@ -159,7 +161,7 @@ is_valid_username (const gchar *username, gboolean parental_controls_enabled, gc
*tip = g_strdup (_("That username isn’t available. Please try another."));
}
else {
- *tip = g_strdup (_("The username should only consist of upper and lower case letters
from a-z, digits and the following characters: . - _"));
+ *tip = g_strdup (_("The username should only consist of lower case letters from a-z,
digits and the following characters: - _"));
}
}
else {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]