[gnome-initial-setup/gbsneto/accounts-crash-bug: 3/3] accounts: Also check against NAME_REGEX if provided
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup/gbsneto/accounts-crash-bug: 3/3] accounts: Also check against NAME_REGEX if provided
- Date: Wed, 27 Jul 2022 18:06:07 +0000 (UTC)
commit 2aee81e9aaf257dd223fa4d7001ac91f12b20821
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed Jul 27 14:58:00 2022 -0300
accounts: Also check against NAME_REGEX if provided
In addition to checking if each character of the proposed username
conforms to UNIX concentions, if /etc/adduser.conf is present and
it provides NAME_REGEX, try and match the username against this
regex too.
This should fix cases where Initial Setup thinks the password is
okay, but accountsservice rejects the proposed username.
gnome-initial-setup/pages/account/um-utils.c | 51 ++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
---
diff --git a/gnome-initial-setup/pages/account/um-utils.c b/gnome-initial-setup/pages/account/um-utils.c
index 39887498..9f9b2a29 100644
--- a/gnome-initial-setup/pages/account/um-utils.c
+++ b/gnome-initial-setup/pages/account/um-utils.c
@@ -106,6 +106,46 @@ is_valid_name (const gchar *name)
return !is_empty;
}
+static GRegex*
+get_adduser_regex (void)
+{
+ static gboolean initialized = FALSE;
+ static GRegex *adduser_regex = NULL;
+
+ if (!initialized) {
+ g_autofree gchar *contents = NULL;
+
+ if (g_file_get_contents ("/etc/adduser.conf", &contents, NULL, NULL)) {
+ g_auto(GStrv) lines = g_strsplit (contents, "\n", -1);
+ gsize i;
+
+ for (i = 0; lines && lines[i] != NULL; i++) {
+ g_autofree gchar *unquoted = NULL;
+ gchar *line = g_strstrip (lines[i]);
+
+ if (*line == '#' || !g_str_has_prefix (line, "NAME_REGEX="))
+ continue;
+
+ line += strlen ("NAME_REGEX=");
+ unquoted = g_shell_unquote (line, NULL);
+
+ if (!unquoted)
+ continue;
+
+ adduser_regex = g_regex_new (unquoted,
+ G_REGEX_OPTIMIZE,
+ 0,
+ NULL);
+ break;
+ }
+ }
+
+ initialized = TRUE;
+ }
+
+ return adduser_regex;
+}
+
gboolean
is_valid_username (const gchar *username, gboolean parental_controls_enabled, gchar **tip)
{
@@ -139,6 +179,17 @@ is_valid_username (const gchar *username, gboolean parental_controls_enabled, gc
(*c == '-' && c != username)))
valid = FALSE;
}
+
+ /* Second, if useradd.conf provides a regex for username
+ * validation, use it.
+ */
+ if (valid) {
+ GRegex *adduser_regex = get_adduser_regex ();
+
+ if (adduser_regex)
+ valid = g_regex_match (adduser_regex, username, 0, NULL);
+ }
+
}
parental_controls_conflict = (parental_controls_enabled && g_strcmp0 (username, "administrator") ==
0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]