Print this page
2989 Eliminate use of LOGNAME_MAX in ON
1166 useradd have warning with name more 8 chars

@@ -18,10 +18,12 @@
  * information: Portions Copyright [yyyy] [name of copyright owner]
  *
  * CDDL HEADER END
  */
 /*
+ * Copyright (c) 2013 Gary Mills
+ *
  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 /*

@@ -37,12 +39,10 @@
  * University Acknowledgment- Portions of this document are derived from
  * software developed by the University of California, Berkeley, and its
  * contributors.
  */
 
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
 /*
  * last
  */
 #include <sys/types.h>
 #include <stdio.h>

@@ -56,17 +56,20 @@
 #include <utmpx.h>
 #include <locale.h>
 #include <ctype.h>
 
 /*
- * NMAX, LMAX and HMAX are set to these values for now. They
- * should be much higher because of the max allowed limit in
- * utmpx.h
+ * Use the full lengths from utmpx for NMAX, LMAX and HMAX .
  */
-#define NMAX    8
-#define LMAX    12
+#define NMAX    (sizeof (((struct utmpx *)0)->ut_user))
+#define LMAX    (sizeof (((struct utmpx *)0)->ut_line))
 #define HMAX    (sizeof (((struct utmpx *)0)->ut_host))
+
+/* Print minimum field widths. */
+#define LOGIN_WIDTH     8
+#define LINE_WIDTH      12
+
 #define SECDAY  (24*60*60)
 #define CHUNK_SIZE 256
 
 #define lineq(a, b)     (strncmp(a, b, LMAX) == 0)
 #define nameq(a, b)     (strncmp(a, b, NMAX) == 0)

@@ -288,12 +291,12 @@
                                 if (strncmp(bp->ut_line, "uucp", 4) == 0)
                                         bp->ut_line[4] = '\0';
 
                                 ct = ctime(&bp->ut_xtime);
                                 (void) printf(gettext("%-*.*s  %-*.*s "),
-                                    NMAX, NMAX, bp->ut_name,
-                                    LMAX, LMAX, bp->ut_line);
+                                    LOGIN_WIDTH, NMAX, bp->ut_name,
+                                    LINE_WIDTH, LMAX, bp->ut_line);
                                 hostf_len = strlen(bp->ut_host);
                                 (void) snprintf(hostf, sizeof (hostf),
                                     "%-*.*s", hostf_len, hostf_len,
                                     bp->ut_host);
                                 fpos = snprintf(timef, sizeof (timef),