Print this page
OS-4716 lxbrand native system(3C) broken
Reviewed by: jerry.jelinek@joyent.com
Reviewed by: patrick.mooney@joyent.com

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libc/port/stdio/system.c
          +++ new/usr/src/lib/libc/port/stdio/system.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  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  /*
  23   23   * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
       25 + * Copyright 2016 Joyent, Inc.
  25   26   */
  26   27  
  27   28  /*      Copyright (c) 1988 AT&T */
  28   29  /*        All Rights Reserved   */
  29   30  
  30   31  #include "lint.h"
  31   32  #include "mtlib.h"
  32   33  #include <sys/types.h>
  33   34  #include <sys/wait.h>
  34   35  #include <signal.h>
↓ open down ↓ 1 lines elided ↑ open up ↑
  36   37  #include <wait.h>
  37   38  #include <sys/stat.h>
  38   39  #include <unistd.h>
  39   40  #include <memory.h>
  40   41  #include <thread.h>
  41   42  #include <pthread.h>
  42   43  #include <errno.h>
  43   44  #include <synch.h>
  44   45  #include <spawn.h>
  45   46  #include <paths.h>
       47 +#include <zone.h>
  46   48  #include "libc.h"
  47   49  
  48   50  extern const char **_environ;
  49   51  
  50   52  extern int __xpg4;      /* defined in _xpg4.c; 0 if not xpg4-compiled program */
  51   53  extern const sigset_t maskset;          /* all maskable signals */
  52   54  
  53   55  static mutex_t sys_lock = DEFAULTMUTEX; /* protects the following */
  54   56  static uint_t sys_count = 0;            /* number of threads in system() */
  55   57  static struct sigaction sys_ibuf;       /* saved SIGINT sigaction */
↓ open down ↓ 62 lines elided ↑ open up ↑
 118  120  
 119  121  int
 120  122  system(const char *cmd)
 121  123  {
 122  124          cleanup_t cu;
 123  125          pid_t w;
 124  126          int status;
 125  127          int error;
 126  128          sigset_t mask;
 127  129          struct stat64 buf;
 128      -        const char *shpath = _PATH_BSHELL;
      130 +        char shpath[MAXPATHLEN];
      131 +        const char *zroot = zone_get_nroot();
 129  132          char *argv[4];
 130  133          posix_spawnattr_t attr;
 131  134          static const char *shell = "sh";
 132  135  
      136 +        /*
      137 +         * If executing in brand use native root.
      138 +         */
      139 +        (void) snprintf(shpath, sizeof (shpath), "%s%s",
      140 +            zroot != NULL ? zroot : "", _PATH_BSHELL);
      141 +
 133  142          if (cmd == NULL) {
 134  143                  if (stat64(shpath, &buf) != 0) {
 135  144                          return (0);
 136  145                  } else if (getuid() == buf.st_uid) {
 137  146                          /* exec for user */
 138  147                          if ((buf.st_mode & 0100) == 0)
 139  148                                  return (0);
 140  149                  } else if (getgid() == buf.st_gid) {
 141  150                          /* exec for group */
 142  151                          if ((buf.st_mode & 0010) == 0)
↓ open down ↓ 123 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX