Ядро 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


9226 static int load_java(struct linux_binprm *bprm, 9227 struct pt_regs *regs) 9228 { 9229 int retval; 9230 MOD_INC_USE_COUNT; 9231 retval = do_load_java(bprm,regs); 9232 MOD_DEC_USE_COUNT; 9233 return retval; 9234 } 9235 9236 static struct linux_binfmt java_format = { 9237 #ifndef MODULE 9238 NULL, 0, load_java, NULL, NULL 9239 #else 9240 NULL, &__this_module, load_java, NULL, NULL 9241 #endif 9242 }; 9243 9244 static int load_applet(struct linux_binprm *bprm, 9245 struct pt_regs *regs) 9246 { 9247 int retval; 9248 MOD_INC_USE_COUNT; 9249 retval = do_load_applet(bprm,regs); 9250 MOD_DEC_USE_COUNT; 9251 return retval; 9252 } 9253 9254 static struct linux_binfmt applet_format = { 9255 #ifndef MODULE 9256 NULL, 0, load_applet, NULL, NULL 9257 #else 9258 NULL, &__this_module, load_applet, NULL, NULL 9259 #endif 9260 }; 9261 9262 int __init init_java_binfmt(void) 9263 { 9264 register_binfmt(&java_format); 9265 return register_binfmt(&applet_format); 9266 } 9267 9268 #ifdef MODULE 9269 int init_module(void) 9270 { 9271 return init_java_binfmt(); 9272 } 9273 9274 void cleanup_module( void) { 9275 unregister_binfmt(&java_format); 9276 unregister_binfmt(&applet_format); 9277 } 9278 #endif


Содержание раздела