Print this page
3946 ::gcore
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/ptools/ppriv/ppriv.c
          +++ new/usr/src/cmd/ptools/ppriv/ppriv.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  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   22   * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  23      - *
       23 + */
       24 +/*
       25 + * Copyright (c) 2013 by Delphix. All rights reserved.
       26 + */
       27 +/*
  24   28   * Program to examine or set process privileges.
  25   29   */
  26   30  
  27   31  #include <stdio.h>
  28   32  #include <stdio_ext.h>
  29   33  #include <stdlib.h>
  30   34  #include <unistd.h>
  31   35  #include <fcntl.h>
  32   36  #include <string.h>
  33   37  #include <limits.h>
↓ open down ↓ 117 lines elided ↑ open up ↑
 151  155                  while (argc-- > 0)
 152  156                          rc += look(*argv++);
 153  157          }
 154  158  
 155  159          return (rc);
 156  160  }
 157  161  
 158  162  static int
 159  163  look(char *arg)
 160  164  {
 161      -        static size_t pprivsz = sizeof (prpriv_t);
 162      -        static prpriv_t *ppriv;
 163      -
 164  165          struct ps_prochandle *Pr;
 165  166          int gcode;
 166  167          size_t sz;
 167  168          void *pdata;
 168  169          char *x;
 169  170          int i;
 170  171          boolean_t nodata;
      172 +        prpriv_t *ppriv;
 171  173  
 172  174          procname = arg;         /* for perr() */
 173  175  
 174  176          if ((Pr = proc_arg_grab(arg, set ? PR_ARG_PIDS : PR_ARG_ANY,
 175  177              PGRAB_RETAIN | PGRAB_FORCE | (set ? 0 : PGRAB_RDONLY) |
 176  178              PGRAB_NOSTOP, &gcode)) == NULL) {
 177  179                  (void) fprintf(stderr, "%s: cannot examine %s: %s\n",
 178  180                      command, arg, Pgrab_error(gcode));
 179  181                  return (1);
 180  182          }
 181  183  
 182      -        if (ppriv == NULL)
 183      -                ppriv = malloc(pprivsz);
 184      -
 185      -        if (Ppriv(Pr, ppriv, pprivsz) == -1) {
      184 +        if (Ppriv(Pr, &ppriv) == -1) {
 186  185                  perr(command);
 187  186                  Prelease(Pr, 0);
 188  187                  return (1);
 189  188          }
 190      -
 191  189          sz = PRIV_PRPRIV_SIZE(ppriv);
 192  190  
 193  191          /*
 194  192           * The ppriv fields are unsigned and may overflow, so check them
 195  193           * separately.  Size must be word aligned, so check that too.
 196  194           * Make sure size is "smallish" too.
 197  195           */
 198  196          if ((sz & 3) || ppriv->pr_nsets == 0 ||
 199  197              sz / ppriv->pr_nsets < ppriv->pr_setsize ||
 200  198              ppriv->pr_infosize > sz || sz > 1024 * 1024) {
 201  199                  (void) fprintf(stderr,
 202  200                      "%s: %s: bad PRNOTES section, size = %lx\n",
 203  201                      command, arg, (long)sz);
 204  202                  Prelease(Pr, 0);
      203 +                free(ppriv);
 205  204                  return (1);
 206  205          }
 207  206  
 208      -        if (sz > pprivsz) {
 209      -                ppriv = realloc(ppriv, sz);
 210      -
 211      -                if (ppriv == NULL || Ppriv(Pr, ppriv, sz) != sz) {
 212      -                        perr(command);
 213      -                        Prelease(Pr, 0);
 214      -                        return (1);
 215      -                }
 216      -                pprivsz = sz;
 217      -        }
 218      -
 219  207          if (set) {
 220  208                  privupdate(ppriv, arg);
 221  209                  if (Psetpriv(Pr, ppriv) != 0) {
 222  210                          perr(command);
 223  211                          Prelease(Pr, 0);
      212 +                        free(ppriv);
 224  213                          return (1);
 225  214                  }
 226  215                  Prelease(Pr, 0);
      216 +                free(ppriv);
 227  217                  return (0);
 228  218          }
 229  219  
 230  220          if (Pstate(Pr) == PS_DEAD) {
 231  221                  (void) printf("core '%s' of %d:\t%.70s\n",
 232  222                      arg, (int)Ppsinfo(Pr)->pr_pid, Ppsinfo(Pr)->pr_psargs);
 233  223                  pdata = Pprivinfo(Pr);
 234  224                  nodata = Pstate(Pr) == PS_DEAD && pdata == NULL;
 235  225          } else {
 236  226                  (void) printf("%d:\t%.70s\n",
↓ open down ↓ 54 lines elided ↑ open up ↑
 291  281                          (void) puts(s);
 292  282                          free(s);
 293  283                  } else {
 294  284                          int j;
 295  285                          for (j = 0; j < ppriv->pr_setsize; j++)
 296  286                                  (void) printf("%08x", pc[j]);
 297  287                          (void) putchar('\n');
 298  288                  }
 299  289          }
 300  290          Prelease(Pr, 0);
      291 +        free(ppriv);
 301  292          return (0);
 302  293  }
 303  294  
 304  295  static void
 305  296  fatal(const char *s)
 306  297  {
 307  298          (void) fprintf(stderr, "%s: %s: %s\n", command, s, strerror(errno));
 308  299          exit(3);
 309  300  }
 310  301  
↓ open down ↓ 381 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX