[gnome-control-center] user-accounts: Fix definition of MAXNAMELEN
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] user-accounts: Fix definition of MAXNAMELEN
- Date: Thu, 1 Feb 2018 15:33:11 +0000 (UTC)
commit 09b94a9b539056bedb1d19b7f99591122143b689
Author: Michael Catanzaro <mcatanzaro igalia com>
Date: Wed Jan 31 14:31:02 2018 -0600
user-accounts: Fix definition of MAXNAMELEN
Currently we get MAXNAMELEN from glibc's LOGIN_NAME_MAX, if available,
and sysconf otherwise. But the maximum username length supported by
glibc and the kernel is actually way larger than the maximum length that
actually works in practice. On Linux, anything larger than 32 characters
is not going to fit into utmp, and will therefore be rejected by
useradd. Then gnome-control-center will spit out a confusing error
message dialog.
Let's spare our users from that.
useradd (in shadow-utils) gets its max name size from the following
magic:
/* Maximum length of usernames */
#ifdef HAVE_UTMPX_H
# include <utmpx.h>
# define USER_NAME_MAX_LENGTH (sizeof (((struct utmpx *)NULL)->ut_user))
#else
# include <utmp.h>
# ifdef HAVE_STRUCT_UTMP_UT_USER
# define USER_NAME_MAX_LENGTH (sizeof (((struct utmp *)NULL)->ut_user))
# else
# ifdef HAVE_STRUCT_UTMP_UT_NAME
# define USER_NAME_MAX_LENGTH (sizeof (((struct utmp *)NULL)->ut_name))
# else
# define USER_NAME_MAX_LENGTH 32
# endif
# endif
#endif
It's more work than necessary. utmpx is standardized by POSIX (it's
actually an XSI extension), whereas utmp is not, so let's just use
utmpx. This ought to work on at least FreeBSD as well. And if any free
operating systems that care about GNOME don't have utmpx yet, no doubt
they'll send patches.
https://bugzilla.gnome.org/show_bug.cgi?id=724193
panels/user-accounts/um-utils.c | 25 +++++++------------------
1 files changed, 7 insertions(+), 18 deletions(-)
---
diff --git a/panels/user-accounts/um-utils.c b/panels/user-accounts/um-utils.c
index f0de95c..c01bc1f 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,12 @@ 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. We could check UT_NAMESIZE instead,
+ * but that is nonstandard. Better to use POSIX utmpx.
+ */
+#define MAXNAMELEN (sizeof (((struct utmpx *)NULL)->ut_user))
static gboolean
is_username_used (const gchar *username)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]