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>
  32   34  #include <ctype.h>
  33   35  #include <string.h>
  34   36  #include <libintl.h>
  35   37  #include <errno.h>
  36   38  #include <zone.h>
  37   39  #include <libzonecfg.h>
       40 +#include <wchar.h>
  38   41  
  39   42  #include "prstat.h"
  40   43  #include "prutil.h"
  41   44  #include "prtable.h"
  42   45  
  43   46  static plwp_t   *plwp_tbl[PLWP_TBL_SZ];
  44   47  
  45   48  void
  46   49  lwpid_init()
  47   50  {
↓ open down ↓ 4 lines elided ↑ open up ↑
  52   55  pwd_getid(char *name)
  53   56  {
  54   57          struct passwd *pwd;
  55   58  
  56   59          if ((pwd = getpwnam(name)) == NULL)
  57   60                  Die(gettext("invalid user name: %s\n"), name);
  58   61          return (pwd->pw_uid);
  59   62  }
  60   63  
  61   64  void
  62      -pwd_getname(uid_t uid, char *name, int length, int noresolve)
       65 +pwd_getname(uid_t uid, char *name, size_t length, int noresolve,
       66 +    int trunc, size_t width)
  63   67  {
  64   68          struct passwd *pwd;
       69 +        size_t n;
  65   70  
  66   71          if (noresolve || (pwd = getpwuid(uid)) == NULL) {
  67      -                (void) snprintf(name, length, "%u", uid);
       72 +                n = snprintf(NULL, 0, "%u", uid);
       73 +                if (trunc && n > width)
       74 +                        (void) snprintf(name, length, "%.*u%c",
       75 +                            width - 1, uid, '*');
       76 +                else
       77 +                        (void) snprintf(name, length, "%u", uid);
  68   78          } else {
  69      -                (void) snprintf(name, length, "%s", pwd->pw_name);
       79 +                n = mbstowcs(NULL, pwd->pw_name, 0);
       80 +                if (n == (size_t)-1)
       81 +                        (void) snprintf(name, length, "%s", "ERROR");
       82 +                else if (trunc && n > width)
       83 +                        (void) snprintf(name, length, "%.*s%c",
       84 +                            width - 1, pwd->pw_name, '*');
       85 +                else
       86 +                        (void) snprintf(name, length, "%s", pwd->pw_name);
  70   87          }
  71   88  }
  72   89  
  73   90  void
  74   91  add_uid(uidtbl_t *tbl, char *name)
  75   92  {
  76   93          uid_t *uid;
  77   94  
  78   95          if (tbl->n_size == tbl->n_nent) {       /* reallocation */
  79   96                  if ((tbl->n_size *= 2) == 0)
↓ open down ↓ 237 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX