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 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #include <sys/types.h>
28 #include <sys/param.h>
29 #include <sys/sysmacros.h>
30 #include <sys/signal.h>
31 #include <sys/cred.h>
32 #include <sys/user.h>
33 #include <sys/errno.h>
34 #include <sys/vnode.h>
35 #include <sys/proc.h>
36 #include <sys/cmn_err.h>
37 #include <sys/debug.h>
38 #include <sys/pathname.h>
39 #include <sys/disp.h>
40 #include <sys/exec.h>
41 #include <sys/kmem.h>
42 #include <sys/note.h>
43
44 /*
45 * This is the loadable module wrapper.
46 */
47 #include <sys/modctl.h>
48
49 /* Local prototypes */
50 static int
51 shbinexec(
52 struct vnode *vp,
53 struct execa *uap,
54 struct uarg *args,
55 struct intpdata *idatap,
56 int level,
57 long *execsz,
58 int setid,
59 caddr_t exec_file,
60 struct cred *cred,
61 int brand_action);
62
63 #define SHBIN_CNTL(x) ((x)&037)
64 #define SHBINMAGIC_LEN 4
65 extern char shbinmagicstr[];
66
67 /*
68 * Our list where we may find a copy of ksh93. The ordering is:
69 * 1. 64bit (may not be installed or not supported in hardware)
70 * 2. 32bit
71 * 3. Use /sbin/ksh93 when /usr is not available
72 *
73 * ([1] and [2] explicitly bypass /usr/bin/ksh93 to avoid the
74 * isaexec overhead).
75 */
76 static char *shell_list[] =
77 {
78 /* Bypass /usr/bin/ksh93 (which is "isaexec") for performance */
79 #if defined(__sparc)
80 "/usr/bin/sparcv9/ksh93",
81 "/usr/bin/sparcv7/ksh93",
145 UIO_SYSSPACE, 0, (rlim64_t)0, CRED(), &resid))
146 return (error);
147
148 if (memcmp(linep, shbinmagicstr, SHBINMAGIC_LEN) != 0)
149 return (ENOEXEC);
150
151 return (0);
152 }
153
154 static int
155 shbinexec(
156 struct vnode *vp,
157 struct execa *uap,
158 struct uarg *args,
159 struct intpdata *idatap,
160 int level,
161 long *execsz,
162 int setid,
163 caddr_t exec_file,
164 struct cred *cred,
165 int brand_action)
166 {
167 _NOTE(ARGUNUSED(brand_action))
168 vnode_t *nvp;
169 int error = 0;
170 struct intpdata idata;
171 struct pathname intppn;
172 struct pathname resolvepn;
173 char *opath;
174 char devfd[19]; /* 32-bit int fits in 10 digits + 8 for "/dev/fd/" */
175 int fd = -1;
176 int i;
177
178 if (level) { /* Can't recurse */
179 error = ENOEXEC;
180 goto bad;
181 }
182
183 ASSERT(idatap == (struct intpdata *)NULL);
184
185 /*
|
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 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2015, Joyent, Inc.
26 */
27
28 #include <sys/types.h>
29 #include <sys/param.h>
30 #include <sys/sysmacros.h>
31 #include <sys/signal.h>
32 #include <sys/cred.h>
33 #include <sys/user.h>
34 #include <sys/errno.h>
35 #include <sys/vnode.h>
36 #include <sys/proc.h>
37 #include <sys/cmn_err.h>
38 #include <sys/debug.h>
39 #include <sys/pathname.h>
40 #include <sys/disp.h>
41 #include <sys/exec.h>
42 #include <sys/kmem.h>
43 #include <sys/note.h>
44
45 /*
46 * This is the loadable module wrapper.
47 */
48 #include <sys/modctl.h>
49
50 /* Local prototypes */
51 static int
52 shbinexec(
53 struct vnode *vp,
54 struct execa *uap,
55 struct uarg *args,
56 struct intpdata *idatap,
57 int level,
58 long *execsz,
59 int setid,
60 caddr_t exec_file,
61 struct cred *cred,
62 int *brand_action);
63
64 #define SHBIN_CNTL(x) ((x)&037)
65 #define SHBINMAGIC_LEN 4
66 extern char shbinmagicstr[];
67
68 /*
69 * Our list where we may find a copy of ksh93. The ordering is:
70 * 1. 64bit (may not be installed or not supported in hardware)
71 * 2. 32bit
72 * 3. Use /sbin/ksh93 when /usr is not available
73 *
74 * ([1] and [2] explicitly bypass /usr/bin/ksh93 to avoid the
75 * isaexec overhead).
76 */
77 static char *shell_list[] =
78 {
79 /* Bypass /usr/bin/ksh93 (which is "isaexec") for performance */
80 #if defined(__sparc)
81 "/usr/bin/sparcv9/ksh93",
82 "/usr/bin/sparcv7/ksh93",
146 UIO_SYSSPACE, 0, (rlim64_t)0, CRED(), &resid))
147 return (error);
148
149 if (memcmp(linep, shbinmagicstr, SHBINMAGIC_LEN) != 0)
150 return (ENOEXEC);
151
152 return (0);
153 }
154
155 static int
156 shbinexec(
157 struct vnode *vp,
158 struct execa *uap,
159 struct uarg *args,
160 struct intpdata *idatap,
161 int level,
162 long *execsz,
163 int setid,
164 caddr_t exec_file,
165 struct cred *cred,
166 int *brand_action)
167 {
168 _NOTE(ARGUNUSED(brand_action))
169 vnode_t *nvp;
170 int error = 0;
171 struct intpdata idata;
172 struct pathname intppn;
173 struct pathname resolvepn;
174 char *opath;
175 char devfd[19]; /* 32-bit int fits in 10 digits + 8 for "/dev/fd/" */
176 int fd = -1;
177 int i;
178
179 if (level) { /* Can't recurse */
180 error = ENOEXEC;
181 goto bad;
182 }
183
184 ASSERT(idatap == (struct intpdata *)NULL);
185
186 /*
|