From dd5f9826494fef6630fc55b58d63969073d1e420 Mon Sep 17 00:00:00 2001 From: wangkaiqiang Date: Fri, 10 Jan 2025 16:49:52 +0800 Subject: [PATCH] [Bug] account: fix username validation to #{13469} account: fix username validation Signed-off-by: wangkaiqiang@ieisystem.com --- 1002-account-fix-username-validation.patch | 80 ++++++++++++++++++++++ gnome-initial-setup.spec | 7 +- 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 1002-account-fix-username-validation.patch diff --git a/1002-account-fix-username-validation.patch b/1002-account-fix-username-validation.patch new file mode 100644 index 0000000..68af65d --- /dev/null +++ b/1002-account-fix-username-validation.patch @@ -0,0 +1,80 @@ +From 3a1030d8a4f07b63c78ce76185dbe676a7feea7e Mon Sep 17 00:00:00 2001 +From: Xiang Fan +Date: Sat, 29 Dec 2018 22:00:19 +0800 +Subject: [PATCH] account: fix username validation +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Current username validation does not conform to the requirement for +useradd. For example, upper case letters are allowed in the validation +but no actual account is created afterwards. + +Ideally, Initial Setup would ask the system what the rules are. +gnome-control-center tries to do this by invoking: + + usermod --login USERNAME -- USERNAME + +and checking the exit code to determine whether USERNAME is legal. +However, at least on Debian-like systems, this method accepts names +'adduser' will reject, such as 'æ' and 'a.e'. (Debian's accountsservice +is patched to call 'adduser'.) + +https://gitlab.gnome.org/GNOME/gnome-initial-setup/-/issues/117 +--- + gnome-initial-setup/pages/account/um-utils.c | 25 +++++++++++--------- + 1 file changed, 14 insertions(+), 11 deletions(-) + +diff --git a/gnome-initial-setup/pages/account/um-utils.c b/gnome-initial-setup/pages/account/um-utils.c +index 39887498..2877d94f 100644 +--- a/gnome-initial-setup/pages/account/um-utils.c ++++ b/gnome-initial-setup/pages/account/um-utils.c +@@ -128,16 +128,19 @@ is_valid_username (const gchar *username, gboolean parental_controls_enabled, gc + valid = TRUE; + + if (!in_use && !empty && !too_long) { +- /* First char must be a letter, and it must only composed +- * of ASCII letters, digits, and a '.', '-', '_' ++ /* First char must be a lower case letter, and it must only be ++ * composed of lower case letters, digits, '-', and '_'. + */ + for (c = username; *c; c++) { +- if (! ((*c >= 'a' && *c <= 'z') || +- (*c >= 'A' && *c <= 'Z') || +- (*c >= '0' && *c <= '9') || +- (*c == '_') || (*c == '.') || +- (*c == '-' && c != username))) +- valid = FALSE; ++ if (c == username) { ++ if (! (*c >= 'a' && *c <= 'z')) ++ valid = FALSE; ++ } else { ++ if (! ((*c >= 'a' && *c <= 'z') || ++ (*c >= '0' && *c <= '9') || ++ (*c == '_') || (*c == '-'))) ++ valid = FALSE; ++ } + } + } + +@@ -152,14 +155,14 @@ is_valid_username (const gchar *username, gboolean parental_controls_enabled, gc + else if (too_long) { + *tip = g_strdup_printf (_("The username is too long.")); + } +- else if (username[0] == '-') { +- *tip = g_strdup (_("The username cannot start with a “-”.")); ++ else if (!(username[0] >= 'a' && username[0] <= 'z')) { ++ *tip = g_strdup (_("The username must start with a lower case letter from a-z.")); + } + else if (parental_controls_conflict) { + *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 { +-- +2.39.3 + diff --git a/gnome-initial-setup.spec b/gnome-initial-setup.spec index 8ff1b3c..18076f7 100644 --- a/gnome-initial-setup.spec +++ b/gnome-initial-setup.spec @@ -1,4 +1,4 @@ -%define anolis_release .0.1 +%define anolis_release .0.2 %global nm_version 1.2 %global nma_version 1.0 %global glib_required_version 2.63.1 @@ -20,6 +20,8 @@ Source1: vendor.conf # https://bugzilla.redhat.com/show_bug.cgi?id=2097848 Patch0: timezones.patch Patch1001: 1001-Modify-systemd-requires.patch +# https://github.com/GNOME/gnome-initial-setup/commit/3a1030d8a4f07b63c78ce76185dbe676a7feea7e +Patch1002: 1002-account-fix-username-validation.patch BuildRequires: meson BuildRequires: gcc @@ -110,6 +112,9 @@ useradd -rM -d /run/gnome-initial-setup/ -s /sbin/nologin %{name} &>/dev/null || %{_datadir}/gnome-initial-setup/vendor.conf %changelog +* Fri Jan 10 2025 Kaiqiang Wang - 40.4-3.0.2 +- account: fix username validation (#13469) + * Tue Nov 29 2022 Chang Gao - 40.4-3.0.1 - Modify systemd requirement -- Gitee