4 * The contents of this file are subject to the terms of the
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 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /*
27 * Launch Java executables via exec(2).
28 *
29 * Java executables are platform-independent executable files
30 * based on the JAR file format. Executable JAR files contain a
31 * special 'extra field' header in the first file of the archive
32 * that marks the file as a true executable. The data in that field
33 * is used to pass additional run-time information to the Java VM.
34 *
35 * This handler looks for the appropriate magic number on the
36 * front of the file, checks that the JAR file is executable, then
37 * invokes the Java runtime environment to do the rest of the work.
38 */
39
40 #include <sys/types.h>
41 #include <sys/proc.h>
42 #include <sys/vnode.h>
43 #include <sys/exec.h>
68 #define SIGSIZ 4
69 #define LOCSIG "PK\003\004"
70 #define LOCHDRSIZ 30
71
72 #define CH(b, n) (((unsigned char *)(b))[n])
73 #define SH(b, n) (CH(b, n) | (CH(b, n+1) << 8))
74 #define LG(b, n) (SH(b, n) | (SH(b, n+2) << 16))
75
76 #define LOCNAM(b) (SH(b, 26)) /* filename size */
77 #define LOCEXT(b) (SH(b, 28)) /* extra field size */
78
79 #define XFHSIZ 4 /* header id, data size */
80 #define XFHID(b) (SH(b, 0)) /* extract field header id */
81 #define XFDATASIZ(b) (SH(b, 2)) /* extract field data size */
82 #define XFJAVASIG 0xcafe /* java executables */
83
84 /*ARGSUSED3*/
85 static int
86 javaexec(vnode_t *vp, struct execa *uap, struct uarg *args,
87 struct intpdata *idatap, int level, long *execsz, int setid,
88 caddr_t execfile, cred_t *cred, int brand_action)
89 {
90 struct intpdata idata;
91 int error;
92 ssize_t resid;
93 vnode_t *nvp;
94 off_t xoff, xoff_end;
95 char lochdr[LOCHDRSIZ];
96 struct pathname lookpn;
97 struct pathname resolvepn;
98 char *opath;
99
100 if (level)
101 return (ENOEXEC); /* no recursion */
102
103 /*
104 * Read in the full local file header, and validate
105 * the initial signature.
106 */
107 if ((error = vn_rdwr(UIO_READ, vp, lochdr, sizeof (lochdr),
108 0, UIO_SYSSPACE, 0, (rlim64_t)0, cred, &resid)) != 0)
|
4 * The contents of this file are subject to the terms of the
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 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright 2015, Joyent, Inc.
25 */
26
27 /*
28 * Launch Java executables via exec(2).
29 *
30 * Java executables are platform-independent executable files
31 * based on the JAR file format. Executable JAR files contain a
32 * special 'extra field' header in the first file of the archive
33 * that marks the file as a true executable. The data in that field
34 * is used to pass additional run-time information to the Java VM.
35 *
36 * This handler looks for the appropriate magic number on the
37 * front of the file, checks that the JAR file is executable, then
38 * invokes the Java runtime environment to do the rest of the work.
39 */
40
41 #include <sys/types.h>
42 #include <sys/proc.h>
43 #include <sys/vnode.h>
44 #include <sys/exec.h>
69 #define SIGSIZ 4
70 #define LOCSIG "PK\003\004"
71 #define LOCHDRSIZ 30
72
73 #define CH(b, n) (((unsigned char *)(b))[n])
74 #define SH(b, n) (CH(b, n) | (CH(b, n+1) << 8))
75 #define LG(b, n) (SH(b, n) | (SH(b, n+2) << 16))
76
77 #define LOCNAM(b) (SH(b, 26)) /* filename size */
78 #define LOCEXT(b) (SH(b, 28)) /* extra field size */
79
80 #define XFHSIZ 4 /* header id, data size */
81 #define XFHID(b) (SH(b, 0)) /* extract field header id */
82 #define XFDATASIZ(b) (SH(b, 2)) /* extract field data size */
83 #define XFJAVASIG 0xcafe /* java executables */
84
85 /*ARGSUSED3*/
86 static int
87 javaexec(vnode_t *vp, struct execa *uap, struct uarg *args,
88 struct intpdata *idatap, int level, long *execsz, int setid,
89 caddr_t execfile, cred_t *cred, int *brand_action)
90 {
91 struct intpdata idata;
92 int error;
93 ssize_t resid;
94 vnode_t *nvp;
95 off_t xoff, xoff_end;
96 char lochdr[LOCHDRSIZ];
97 struct pathname lookpn;
98 struct pathname resolvepn;
99 char *opath;
100
101 if (level)
102 return (ENOEXEC); /* no recursion */
103
104 /*
105 * Read in the full local file header, and validate
106 * the initial signature.
107 */
108 if ((error = vn_rdwr(UIO_READ, vp, lochdr, sizeof (lochdr),
109 0, UIO_SYSSPACE, 0, (rlim64_t)0, cred, &resid)) != 0)
|