[gnome-control-center/T20818: 28/54] user-accounts: Do not suggest usernames that are too long
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/T20818: 28/54] user-accounts: Do not suggest usernames that are too long
- Date: Tue, 23 Jan 2018 21:32:23 +0000 (UTC)
commit 1c3a732ca2e759b8da9ad97128a6b3655c206bcb
Author: Michael Catanzaro <mcatanzaro igalia com>
Date: Fri May 13 20:20:02 2016 -0500
user-accounts: Do not suggest usernames that are too long
We assume that we only generate valid usernames, so make sure they're
short enough to be used, else we'll display a dialog with a meaningless
error message when useradd fails.
https://bugzilla.gnome.org/show_bug.cgi?id=766401
https://phabricator.endlessm.com/T3597
panels/user-accounts/um-utils.c | 34 ++++++++++++++++------------------
1 files changed, 16 insertions(+), 18 deletions(-)
---
diff --git a/panels/user-accounts/um-utils.c b/panels/user-accounts/um-utils.c
index 72eada4..b54e233 100644
--- a/panels/user-accounts/um-utils.c
+++ b/panels/user-accounts/um-utils.c
@@ -25,6 +25,7 @@
#include <sys/types.h>
#include <limits.h>
#include <unistd.h>
+#include <utmpx.h>
#include <pwd.h>
#include <gio/gio.h>
@@ -404,24 +405,11 @@ rounded_rectangle (cairo_t *cr,
cairo_close_path (cr);
}
-static guint
-get_login_name_max (void)
-{
-#ifdef LOGIN_NAME_MAX
- return LOGIN_NAME_MAX;
-#else
- static gint length;
-
- if (!length) {
- length = sysconf (_SC_LOGIN_NAME_MAX);
- g_assert_cmpint (length, >=, 0);
- }
-
- return length;
-#endif
-}
-
-#define MAXNAMELEN get_login_name_max ()
+/* Taken from defines.h in shadow-utils. On Linux, this value is much smaller
+ * than the sysconf limit LOGIN_NAME_MAX, and values larger than this will
+ * result in failure when running useradd.
+ */
+#define MAXNAMELEN (sizeof (((struct utmpx *)NULL)->ut_user))
static gboolean
is_username_used (const gchar *username)
@@ -661,10 +649,20 @@ generate_username_choices (const gchar *name,
g_strfreev (words2);
}
+
+ g_string_truncate (first_word, MAXNAMELEN);
+ g_string_truncate (last_word, MAXNAMELEN);
+
item2 = g_string_append (item2, last_word->str);
item3 = g_string_append (item3, first_word->str);
item4 = g_string_prepend (item4, last_word->str);
+ g_string_truncate (item0, MAXNAMELEN);
+ g_string_truncate (item1, MAXNAMELEN);
+ g_string_truncate (item2, MAXNAMELEN);
+ g_string_truncate (item3, MAXNAMELEN);
+ g_string_truncate (item4, MAXNAMELEN);
+
items = g_hash_table_new (g_str_hash, g_str_equal);
in_use = is_username_used (item0->str);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]