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.

Note that this commit doesn't completely fix the bug, as our definition
of MAXNAMELEN is different from useradd's.

https://bugzilla.gnome.org/show_bug.cgi?id=766401
This commit is contained in:
Michael Catanzaro 2016-05-13 19:54:55 -05:00 committed by Michael Catanzaro
parent ed03e9c49f
commit 0344f663dc

View file

@ -665,6 +665,15 @@ generate_username_choices (const gchar *name,
item3 = g_string_append (item3, first_word->str);
item4 = g_string_prepend (item4, last_word->str);
g_string_truncate (first_word, MAXNAMELEN);
g_string_truncate (last_word, MAXNAMELEN);
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);