Ядро Linux в комментариях




Fs/binfmt_java.c


9083 /* 9084 * linux/fs/binfmt_java.c 9085 * 9086 * Copyright (C) 1996 Brian A. Lantz 9087 * derived from binfmt_script.c 9088 * 9089 * Simplified and modified to support binary java 9090 * interpreters by Tom May <ftom@netcom.com>. 9091 */ 9092 9093 #include <linux/module.h> 9094 #include <linux/string.h> 9095 #include <linux/stat.h> 9096 #include <linux/malloc.h> 9097 #include <linux/binfmts.h> 9098 #include <linux/init.h> 9099 9100 #define _PATH_JAVA "/usr/bin/java" 9101 #define _PATH_APPLET "/usr/bin/appletviewer" 9102 9103 /* These paths can be modified with sysctl(). */ 9104 9105 char binfmt_java_interpreter[65] = _PATH_JAVA; 9106 char binfmt_java_appletviewer[65] = _PATH_APPLET; 9107

9108 static int do_load_java(struct linux_binprm *bprm, 9109 struct pt_regs *regs) 9110 { 9111 char *i_name; 9112 int len; 9113 int retval; 9114 struct dentry * dentry; 9115 unsigned char *ucp = (unsigned char *) bprm->buf; 9116 9117 if ((ucp[0] != 0xca) (ucp[1] != 0xfe) 9118 (ucp[2] != 0xba) (ucp[3] != 0xbe)) 9119 return -ENOEXEC; 9120 9121 /* Fail if we're called recursively, e.g., the Java 9122 * interpreter is a java binary. */ 9123 if (bprm->java) 9124 return -ENOEXEC; 9125 9126 bprm->java = 1; 9127 9128 dput(bprm->dentry); 9129 bprm->dentry = NULL; 9130 9131 /* Set args: [0] the name of the java interpreter 9132 * [1] name of java class to execute, which 9133 * is the filename without the path and 9134 * without trailing ".class". Note that the 9135 * interpreter will use its own way to found 9136 * the class file (typically using 9137 * environment variable CLASSPATH), and may 9138 * in fact execute a different file from the 9139 * one we want. 9140 * 9141 * This is done in reverse order, because of how the 9142 * user environment and arguments are stored. */ 9143 remove_arg_zero(bprm); 9144 len = strlen (bprm->filename); 9145 if (len >= 6 && 9146 !strcmp(bprm->filename + len - 6, ".class")) 9147 bprm->filename[len - 6] = 0; 9148 if ((i_name = strrchr (bprm->filename, '/')) != NULL) 9149 i_name++; 9150 else 9151 i_name = bprm->filename; 9152 bprm->p = copy_strings(1, &i_name, bprm->page, 9153 bprm->p, 2); 9154 bprm->argc++; 9155 9156 i_name = binfmt_java_interpreter; 9157 bprm->p = copy_strings(1, &i_name, bprm->page, 9158 bprm->p, 2); 9159 bprm->argc++; 9160 9161 if (!bprm->p) 9162 return -E2BIG; 9163 /* OK, now restart the process with the interpreter's 9164 * dentry. */ 9165 bprm->filename = binfmt_java_interpreter; 9166 dentry = open_namei(binfmt_java_interpreter, 0, 0); 9167 retval = PTR_ERR(dentry); 9168 if (IS_ERR(dentry)) 9169 return retval; 9170 9171 bprm->dentry = dentry; 9172 retval = prepare_binprm(bprm); 9173 if (retval < 0) 9174 return retval; 9175 9176 return search_binary_handler(bprm,regs); 9177 } 9178 9179 static int do_load_applet(struct linux_binprm *bprm, 9180 struct pt_regs *regs) 9181 { 9182 char *i_name; 9183 struct dentry * dentry; 9184 int retval; 9185 9186 if (strncmp (bprm->buf, "<!--applet", 10)) 9187 return -ENOEXEC; 9188 9189 dput(bprm->dentry); 9190 bprm->dentry = NULL; 9191 9192 /* Set args: [0] the name of the appletviewer 9193 * [1] filename of html file 9194 * 9195 * This is done in reverse order, because of how the 9196 * user environment and arguments are stored. */ 9197 remove_arg_zero(bprm); 9198 i_name = bprm->filename; 9199 bprm->p = copy_strings(1, &i_name, bprm->page, 9200 bprm->p, 2); 9201 bprm->argc++; 9202 9203 i_name = binfmt_java_appletviewer; 9204 bprm->p = copy_strings(1, &i_name, bprm->page, 9205 bprm->p, 2); 9206 bprm->argc++; 9207 9208 if (!bprm->p) 9209 return -E2BIG; 9210 /* OK, now restart the process with the interpreter's 9211 * dentry. */ 9212 bprm->filename = binfmt_java_appletviewer; 9213 dentry = open_namei(binfmt_java_appletviewer, 0, 0); 9214 retval = PTR_ERR(dentry); 9215 if (IS_ERR(dentry)) 9216 return retval; 9217 9218 bprm->dentry = dentry; 9219 retval = prepare_binprm(bprm); 9220 if (retval < 0) 9221 return retval; 9222 9223 return search_binary_handler(bprm,regs); 9224 } 9225




Содержание  Назад  Вперед