5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
29
30 #include "lint.h"
31 #include "mtlib.h"
32 #include <sys/types.h>
33 #include <sys/wait.h>
34 #include <signal.h>
35 #include <stdlib.h>
36 #include <wait.h>
37 #include <sys/stat.h>
38 #include <unistd.h>
39 #include <memory.h>
40 #include <thread.h>
41 #include <pthread.h>
42 #include <errno.h>
43 #include <synch.h>
44 #include <spawn.h>
45 #include <paths.h>
46 #include "libc.h"
47
48 extern const char **_environ;
49
50 extern int __xpg4; /* defined in _xpg4.c; 0 if not xpg4-compiled program */
51 extern const sigset_t maskset; /* all maskable signals */
52
53 static mutex_t sys_lock = DEFAULTMUTEX; /* protects the following */
54 static uint_t sys_count = 0; /* number of threads in system() */
55 static struct sigaction sys_ibuf; /* saved SIGINT sigaction */
56 static struct sigaction sys_qbuf; /* saved SIGQUIT sigaction */
57 static struct sigaction ignore = {0, {SIG_IGN}, {0}};
58
59 /*
60 * Things needed by the cancellation cleanup handler.
61 */
62 typedef struct {
63 sigset_t savemask; /* saved signal mask */
64 pid_t pid; /* if nonzero, the child's pid */
65 } cleanup_t;
108 * There are no remaining threads in system(), so
109 * restore the SIGINT and SIGQUIT signal actions.
110 */
111 (void) sigaction(SIGINT, &sys_ibuf, NULL);
112 (void) sigaction(SIGQUIT, &sys_qbuf, NULL);
113 }
114 lmutex_unlock(&sys_lock);
115
116 (void) thr_sigsetmask(SIG_SETMASK, &cup->savemask, NULL);
117 }
118
119 int
120 system(const char *cmd)
121 {
122 cleanup_t cu;
123 pid_t w;
124 int status;
125 int error;
126 sigset_t mask;
127 struct stat64 buf;
128 const char *shpath = _PATH_BSHELL;
129 char *argv[4];
130 posix_spawnattr_t attr;
131 static const char *shell = "sh";
132
133 if (cmd == NULL) {
134 if (stat64(shpath, &buf) != 0) {
135 return (0);
136 } else if (getuid() == buf.st_uid) {
137 /* exec for user */
138 if ((buf.st_mode & 0100) == 0)
139 return (0);
140 } else if (getgid() == buf.st_gid) {
141 /* exec for group */
142 if ((buf.st_mode & 0010) == 0)
143 return (0);
144 } else if ((buf.st_mode & 0001) == 0) { /* exec for others */
145 return (0);
146 }
147 return (1);
148 }
149
150 /*
151 * Initialize the posix_spawn() attributes structure.
152 *
|
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2016 Joyent, Inc.
26 */
27
28 /* Copyright (c) 1988 AT&T */
29 /* All Rights Reserved */
30
31 #include "lint.h"
32 #include "mtlib.h"
33 #include <sys/types.h>
34 #include <sys/wait.h>
35 #include <signal.h>
36 #include <stdlib.h>
37 #include <wait.h>
38 #include <sys/stat.h>
39 #include <unistd.h>
40 #include <memory.h>
41 #include <thread.h>
42 #include <pthread.h>
43 #include <errno.h>
44 #include <synch.h>
45 #include <spawn.h>
46 #include <paths.h>
47 #include <zone.h>
48 #include "libc.h"
49
50 extern const char **_environ;
51
52 extern int __xpg4; /* defined in _xpg4.c; 0 if not xpg4-compiled program */
53 extern const sigset_t maskset; /* all maskable signals */
54
55 static mutex_t sys_lock = DEFAULTMUTEX; /* protects the following */
56 static uint_t sys_count = 0; /* number of threads in system() */
57 static struct sigaction sys_ibuf; /* saved SIGINT sigaction */
58 static struct sigaction sys_qbuf; /* saved SIGQUIT sigaction */
59 static struct sigaction ignore = {0, {SIG_IGN}, {0}};
60
61 /*
62 * Things needed by the cancellation cleanup handler.
63 */
64 typedef struct {
65 sigset_t savemask; /* saved signal mask */
66 pid_t pid; /* if nonzero, the child's pid */
67 } cleanup_t;
110 * There are no remaining threads in system(), so
111 * restore the SIGINT and SIGQUIT signal actions.
112 */
113 (void) sigaction(SIGINT, &sys_ibuf, NULL);
114 (void) sigaction(SIGQUIT, &sys_qbuf, NULL);
115 }
116 lmutex_unlock(&sys_lock);
117
118 (void) thr_sigsetmask(SIG_SETMASK, &cup->savemask, NULL);
119 }
120
121 int
122 system(const char *cmd)
123 {
124 cleanup_t cu;
125 pid_t w;
126 int status;
127 int error;
128 sigset_t mask;
129 struct stat64 buf;
130 char shpath[MAXPATHLEN];
131 const char *zroot = zone_get_nroot();
132 char *argv[4];
133 posix_spawnattr_t attr;
134 static const char *shell = "sh";
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
142 if (cmd == NULL) {
143 if (stat64(shpath, &buf) != 0) {
144 return (0);
145 } else if (getuid() == buf.st_uid) {
146 /* exec for user */
147 if ((buf.st_mode & 0100) == 0)
148 return (0);
149 } else if (getgid() == buf.st_gid) {
150 /* exec for group */
151 if ((buf.st_mode & 0010) == 0)
152 return (0);
153 } else if ((buf.st_mode & 0001) == 0) { /* exec for others */
154 return (0);
155 }
156 return (1);
157 }
158
159 /*
160 * Initialize the posix_spawn() attributes structure.
161 *
|