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

@@ -21,16 +21,16 @@
 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
 /*        All Rights Reserved   */
 
 
 /*
+ * Copyright (c) 2013 Gary Mills
+ *
  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
 /*
  *      This program analyzes information found in /var/adm/utmpx
  *
  *      Additionally information is gathered from /etc/inittab
  *      if requested.

@@ -98,23 +98,19 @@
 static void dump(void);
 
 static struct   utmpx *utmpp;   /* pointer for getutxent()      */
 
 /*
- * utmpx defines wider fields for user and line.  For compatibility of output,
- * we are limiting these to the old maximums in utmp. Define UTMPX_NAMELEN
- * to use the full lengths.
+ * Use the full lengths from utmpx for user and line.
  */
-#ifndef UTMPX_NAMELEN
-/* XXX - utmp - fix name length */
-#define NMAX    (_POSIX_LOGIN_NAME_MAX - 1)
-#define LMAX    12
-#else /* UTMPX_NAMELEN */
 #define NMAX    (sizeof (utmpp->ut_user))
 #define LMAX    (sizeof (utmpp->ut_line))
-#endif
 
+/* Print minimum field widths. */
+#define LOGIN_WIDTH     8
+#define LINE_WIDTH      12
+
 static char     comment[BUFSIZ]; /* holds inittab comment       */
 static char     errmsg[BUFSIZ]; /* used in snprintf for errors  */
 static int      fildes;         /* file descriptor for inittab  */
 static int      Hopt = 0;       /* 1 = who -H                   */
 static char     *inittab;       /* ptr to inittab contents      */

@@ -166,11 +162,12 @@
         stbufp = &stbuf;
 
         /*
          *      Strip off path name of this command
          */
-        for (i = strlen(argv[0]); i >= 0 && argv[0][i] != '/'; --i);
+        for (i = strlen(argv[0]); i >= 0 && argv[0][i] != '/'; --i)
+                ;
         if (i >= 0)
                 argv[0] += i+1;
         program = argv[0];
 
         /*

@@ -507,11 +504,11 @@
                 /*
                  * XCU4 - Use non user macro for correct user count
                  */
                 if (((totlusrs - 1) % number) == 0 && totlusrs > 1)
                         (void) printf("\n");
-                (void) printf("%-*s ", NMAX, user);
+                (void) printf("%-*.*s ", LOGIN_WIDTH, NMAX, user);
                 return;
         }
 
 
         pexit = (int)' ';

@@ -563,11 +560,12 @@
                 w = ' ';
 
         /*
          *      Print the TERSE portion of the output
          */
-        (void) printf("%-*s %c %-12s %s", NMAX, user, w, device, time_buf);
+        (void) printf("%-*.*s %c %-12s %s", LOGIN_WIDTH, NMAX, user,
+            w, device, time_buf);
 
         if (!terse) {
                 /*
                  *      Stat device for idle time
                  *      (Don't complain if you can't)

@@ -624,11 +622,12 @@
                          *      Look for a line beginning with
                          *      utmpp->ut_id
                          */
                         while ((rc = strncmp(utmpp->ut_id, iinit,
                             strcspn(iinit, ":"))) != 0) {
-                                for (; *iinit != '\n'; iinit++);
+                                for (; *iinit != '\n'; iinit++)
+                                        ;
                                 iinit++;
 
                                 /*
                                  *      Wrap once if necessary to
                                  *      find entry in inittab

@@ -644,14 +643,16 @@
                         if (*iinit != '\0') {
                                 /*
                                  *      We found our entry
                                  */
                                 for (iinit++; *iinit != '#' &&
-                                         *iinit != '\n'; iinit++);
+                                    *iinit != '\n'; iinit++)
+                                        ;
                                 if (*iinit == '#') {
                                         for (iinit++; *iinit == ' ' ||
-                                                 *iinit == '\t'; iinit++);
+                                            *iinit == '\t'; iinit++)
+                                                ;
                                         for (rc = 0; *iinit != '\n'; iinit++)
                                                 comment[rc++] = *iinit;
                                         comment[rc] = '\0';
                                 } else
                                         (void) strcpy(comment, " ");

@@ -754,11 +755,12 @@
                          */
                         if (validtype[utmpp->ut_type]) {
 #ifdef  XPG4
                                 if (utmpp->ut_type == LOGIN_PROCESS) {
                                         if ((utmpp->ut_line[0] == '\0') ||
-                                        (strcmp(utmpp->ut_user, "LOGIN") != 0))
+                                            (strcmp(utmpp->ut_user,
+                                            "LOGIN") != 0))
                                                 continue;
                                 }
 #endif  /* XPG4 */
                                 dump();
                         }