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

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/wall/wall.c
          +++ new/usr/src/cmd/wall/wall.c
↓ open down ↓ 23 lines elided ↑ open up ↑
  24   24  
  25   25  
  26   26  
  27   27  /*
  28   28   * Copyright 1988-2003 Sun Microsystems, Inc.  All rights reserved.
  29   29   * Use is subject to license terms.
  30   30   */
  31   31  
  32   32  /*
  33   33   * Copyright 2012 Joyent, Inc. All rights reserved.
       34 + *
       35 + * Copyright (c) 2013 Gary Mills
  34   36   */
  35   37  
  36   38  #include <signal.h>
  37   39  #include <stdio.h>
  38   40  #include <stdlib.h>
  39   41  #include <grp.h>
  40   42  #include <sys/types.h>
  41   43  #include <unistd.h>
  42   44  #include <string.h>
  43   45  #include <ctype.h>
↓ open down ↓ 9 lines elided ↑ open up ↑
  53   55  #include <syslog.h>
  54   56  #include <sys/wait.h>
  55   57  #include <limits.h>
  56   58  #include <libzonecfg.h>
  57   59  #include <zone.h>
  58   60  #include <sys/contract/process.h>
  59   61  #include <libcontract.h>
  60   62  #include <sys/ctfs.h>
  61   63  
  62   64  /*
  63      - * utmpx defines wider fields for user and line.  For compatibility of output,
  64      - * we are limiting these to the old maximums in utmp. Define UTMPX_NAMELEN
  65      - * to use the full lengths.
       65 + * Use the full lengths from utmpx for user and line.
  66   66   */
  67      -#ifndef UTMPX_NAMELEN
  68      -/* XXX - utmp -fix name length */
  69      -#define NMAX    (_POSIX_LOGIN_NAME_MAX - 1)
  70      -#define LMAX    12
  71      -#else /* UTMPX_NAMELEN */
  72      -#define NMAX    (sizeof (((struct utmpx *)0)->ut_user)
  73      -#define LMAX    (sizeof (((struct utmpx *)0)->ut_line)
  74      -#endif /* UTMPX_NAMELEN */
       67 +#define NMAX    (sizeof (((struct utmpx *)0)->ut_user))
       68 +#define LMAX    (sizeof (((struct utmpx *)0)->ut_line))
  75   69  
  76   70  static char     mesg[3000];
  77   71  static char     *infile;
  78   72  static int      gflag;
  79   73  static struct   group *pgrp;
  80   74  static char     *grpname;
  81   75  static char     line[MAXNAMLEN+1] = "???";
  82   76  static char     systm[MAXNAMLEN+1];
  83   77  static time_t   tloc;
  84   78  static struct   utsname utsn;
  85      -static char     who[9]  = "???";
       79 +static char     who[NMAX+1]     = "???";
  86   80  static char     time_buf[50];
  87   81  #define DATE_FMT        "%a %b %e %H:%M:%S"
  88   82  
  89   83  static void sendmes(struct utmpx *, zoneid_t);
  90   84  static void sendmes_tozone(zoneid_t, int);
  91   85  static int chkgrp(char *);
  92   86  static char *copy_str_till(char *, char *, char, int);
  93   87  
  94   88  static int init_template(void);
  95   89  int contract_abandon_id(ctid_t);
↓ open down ↓ 123 lines elided ↑ open up ↑
 219  213                  char *cp;
 220  214  
 221  215                  if (strncmp(mesg, "From ", 5) == 0) {
 222  216                          cp = &mesg[5];
 223  217                          cp = copy_str_till(rwho, cp, '@', MAXNAMLEN + 1);
 224  218                          if (rwho[0] != '\0') {
 225  219                                  cp = copy_str_till(rsystm, ++cp, ':',
 226  220                                      MAXNAMLEN + 1);
 227  221                                  if (rsystm[0] != '\0') {
 228  222                                          (void) strcpy(systm, rsystm);
 229      -                                        (void) strncpy(rwho, who, 9);
      223 +                                        (void) strncpy(rwho, who,
      224 +                                            sizeof (who));
 230  225                                          (void) strcpy(line, "rpc.rwalld");
 231  226                                  }
 232  227                          }
 233  228                  }
 234  229          }
 235  230          (void) time(&tloc);
 236  231          (void) strftime(time_buf, sizeof (time_buf),
 237  232              DATE_FMT, localtime(&tloc));
 238  233  
 239  234          if (zflg != 0) {
↓ open down ↓ 181 lines elided ↑ open up ↑
 421  416                  (void) fflush(stderr);
 422  417                  _exit(1);
 423  418          }
 424  419          (void) fprintf(f,
 425  420              "\07\07\07Broadcast Message from %s (%s) on %s %19.19s",
 426  421              who, line, systm, time_buf);
 427  422          if (gflag)
 428  423                  (void) fprintf(f, " to group %s", grpname);
 429  424          (void) fprintf(f, "...\n");
 430  425  #ifdef DEBUG
 431      -        (void) fprintf(f, "DEBUG: To %.8s on %s\n", p->ut_user, s);
      426 +        (void) fprintf(f, "DEBUG: To %.*s on %s\n", NMAX, p->ut_user, s);
 432  427  #endif
 433  428          i = strlen(mesg);
 434  429          for (bp = mesg; --i >= 0; bp++) {
 435  430                  ibp = (unsigned int)((unsigned char) *bp);
 436  431                  if (*bp == '\n')
 437  432                          (void) putc('\r', f);
 438  433                  if (isprint(ibp) || *bp == '\r' || *bp == '\013' ||
 439  434                      *bp == ' ' || *bp == '\t' || *bp == '\n' || *bp == '\007') {
 440  435                          (void) putc(*bp, f);
 441  436                  } else {
↓ open down ↓ 21 lines elided ↑ open up ↑
 463  458          (void) fclose(f);
 464  459          (void) close(fd);
 465  460          _exit(0);
 466  461  }
 467  462  
 468  463  
 469  464  static int
 470  465  chkgrp(char *name)
 471  466  {
 472  467          int i;
 473      -        char *p;
      468 +        char user[NMAX + 1];
 474  469  
      470 +        (void) strlcpy(user, name, sizeof (user));
 475  471          for (i = 0; pgrp->gr_mem[i] && pgrp->gr_mem[i][0]; i++) {
 476      -                for (p = name; *p && *p != ' '; p++)
 477      -                ;
 478      -                *p = 0;
 479      -                if (strncmp(name, pgrp->gr_mem[i], 8) == 0)
      472 +                if (strcmp(user, pgrp->gr_mem[i]) == 0)
 480  473                          return (1);
 481  474          }
 482  475  
 483  476          return (0);
 484  477  }
 485  478  
 486  479  static int
 487  480  init_template(void) {
 488  481          int fd = 0;
 489  482          int err = 0;
↓ open down ↓ 16 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX