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/prstat/prtable.c
          +++ new/usr/src/cmd/prstat/prtable.c
↓ open down ↓ 11 lines elided ↑ open up ↑
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
       22 + * Copyright (c) 2013 Gary Mills
       23 + *
  22   24   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23   25   * Use is subject to license terms.
  24   26   *
  25   27   * Portions Copyright 2009 Chad Mynhier
  26   28   */
  27   29  
  28   30  #include <procfs.h>
  29   31  #include <unistd.h>
  30   32  #include <stdlib.h>
  31   33  #include <pwd.h>
↓ open down ↓ 20 lines elided ↑ open up ↑
  52   54  pwd_getid(char *name)
  53   55  {
  54   56          struct passwd *pwd;
  55   57  
  56   58          if ((pwd = getpwnam(name)) == NULL)
  57   59                  Die(gettext("invalid user name: %s\n"), name);
  58   60          return (pwd->pw_uid);
  59   61  }
  60   62  
  61   63  void
  62      -pwd_getname(uid_t uid, char *name, int length, int noresolve)
       64 +pwd_getname(uid_t uid, char *name, size_t length, int noresolve,
       65 +    int trunc, size_t width)
  63   66  {
  64   67          struct passwd *pwd;
       68 +        size_t n;
  65   69  
  66   70          if (noresolve || (pwd = getpwuid(uid)) == NULL) {
  67      -                (void) snprintf(name, length, "%u", uid);
       71 +                n = snprintf(NULL, 0, "%u", uid);
       72 +                if (trunc && n > width)
       73 +                        (void) snprintf(name, length, "%.*u%c",
       74 +                            width - 1, uid, '*');
       75 +                else
       76 +                        (void) snprintf(name, length, "%u", uid);
  68   77          } else {
  69      -                (void) snprintf(name, length, "%s", pwd->pw_name);
       78 +                n = strlen(pwd->pw_name);
       79 +                if (trunc && n > width)
       80 +                        (void) snprintf(name, length, "%.*s%c",
       81 +                            width - 1, pwd->pw_name, '*');
       82 +                else
       83 +                        (void) snprintf(name, length, "%s", pwd->pw_name);
  70   84          }
  71   85  }
  72   86  
  73   87  void
  74   88  add_uid(uidtbl_t *tbl, char *name)
  75   89  {
  76   90          uid_t *uid;
  77   91  
  78   92          if (tbl->n_size == tbl->n_nent) {       /* reallocation */
  79   93                  if ((tbl->n_size *= 2) == 0)
↓ open down ↓ 237 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX