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

@@ -29,10 +29,12 @@
  * Use is subject to license terms.
  */
 
 /*
  * Copyright 2012 Joyent, Inc. All rights reserved.
+ *
+ * Copyright (c) 2013 Gary Mills
  */
 
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>

@@ -58,22 +60,14 @@
 #include <sys/contract/process.h>
 #include <libcontract.h>
 #include <sys/ctfs.h>
 
 /*
- * 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 (((struct utmpx *)0)->ut_user)
-#define LMAX    (sizeof (((struct utmpx *)0)->ut_line)
-#endif /* UTMPX_NAMELEN */
+#define NMAX    (sizeof (((struct utmpx *)0)->ut_user))
+#define LMAX    (sizeof (((struct utmpx *)0)->ut_line))
 
 static char     mesg[3000];
 static char     *infile;
 static int      gflag;
 static struct   group *pgrp;

@@ -80,11 +74,11 @@
 static char     *grpname;
 static char     line[MAXNAMLEN+1] = "???";
 static char     systm[MAXNAMLEN+1];
 static time_t   tloc;
 static struct   utsname utsn;
-static char     who[9]  = "???";
+static char     who[NMAX+1]     = "???";
 static char     time_buf[50];
 #define DATE_FMT        "%a %b %e %H:%M:%S"
 
 static void sendmes(struct utmpx *, zoneid_t);
 static void sendmes_tozone(zoneid_t, int);

@@ -224,11 +218,12 @@
                         if (rwho[0] != '\0') {
                                 cp = copy_str_till(rsystm, ++cp, ':',
                                     MAXNAMLEN + 1);
                                 if (rsystm[0] != '\0') {
                                         (void) strcpy(systm, rsystm);
-                                        (void) strncpy(rwho, who, 9);
+                                        (void) strncpy(rwho, who,
+                                            sizeof (who));
                                         (void) strcpy(line, "rpc.rwalld");
                                 }
                         }
                 }
         }

@@ -426,11 +421,11 @@
             who, line, systm, time_buf);
         if (gflag)
                 (void) fprintf(f, " to group %s", grpname);
         (void) fprintf(f, "...\n");
 #ifdef DEBUG
-        (void) fprintf(f, "DEBUG: To %.8s on %s\n", p->ut_user, s);
+        (void) fprintf(f, "DEBUG: To %.*s on %s\n", NMAX, p->ut_user, s);
 #endif
         i = strlen(mesg);
         for (bp = mesg; --i >= 0; bp++) {
                 ibp = (unsigned int)((unsigned char) *bp);
                 if (*bp == '\n')

@@ -468,17 +463,16 @@
 
 static int
 chkgrp(char *name)
 {
         int i;
-        char *p;
+        char user[NMAX + 1];
 
+        (void) strncpy(user, name, NMAX);
+        user[NMAX] = '\0';
         for (i = 0; pgrp->gr_mem[i] && pgrp->gr_mem[i][0]; i++) {
-                for (p = name; *p && *p != ' '; p++)
-                ;
-                *p = 0;
-                if (strncmp(name, pgrp->gr_mem[i], 8) == 0)
+                if (strcmp(user, pgrp->gr_mem[i]) == 0)
                         return (1);
         }
 
         return (0);
 }