This source file includes following definitions.
- do_load_script
- load_script
- init_script_binfmt
- init_module
- cleanup_module
1
2
3
4
5
6
7
8 #include <linux/module.h>
9 #include <linux/string.h>
10 #include <linux/stat.h>
11 #include <linux/malloc.h>
12 #include <linux/binfmts.h>
13
14 static int do_load_script(struct linux_binprm *bprm,struct pt_regs *regs)
15 {
16 char *cp, *interp, *i_name, *i_arg;
17 int retval;
18 if ((bprm->buf[0] != '#') || (bprm->buf[1] != '!') || (bprm->sh_bang))
19 return -ENOEXEC;
20
21
22
23
24
25 bprm->sh_bang++;
26 iput(bprm->inode);
27 bprm->dont_iput=1;
28
29 bprm->buf[127] = '\0';
30 if ((cp = strchr(bprm->buf, '\n')) == NULL)
31 cp = bprm->buf+127;
32 *cp = '\0';
33 while (cp > bprm->buf) {
34 cp--;
35 if ((*cp == ' ') || (*cp == '\t'))
36 *cp = '\0';
37 else
38 break;
39 }
40 for (cp = bprm->buf+2; (*cp == ' ') || (*cp == '\t'); cp++);
41 if (!cp || *cp == '\0')
42 return -ENOEXEC;
43 interp = i_name = cp;
44 i_arg = 0;
45 for ( ; *cp && (*cp != ' ') && (*cp != '\t'); cp++) {
46 if (*cp == '/')
47 i_name = cp+1;
48 }
49 while ((*cp == ' ') || (*cp == '\t'))
50 *cp++ = '\0';
51 if (*cp)
52 i_arg = cp;
53
54
55
56
57
58
59
60
61
62
63 remove_arg_zero(bprm);
64 bprm->p = copy_strings(1, &bprm->filename, bprm->page, bprm->p, 2);
65 bprm->argc++;
66 if (i_arg) {
67 bprm->p = copy_strings(1, &i_arg, bprm->page, bprm->p, 2);
68 bprm->argc++;
69 }
70 bprm->p = copy_strings(1, &i_name, bprm->page, bprm->p, 2);
71 bprm->argc++;
72 if (!bprm->p)
73 return -E2BIG;
74
75
76
77
78
79 retval = open_namei(interp, 0, 0, &bprm->inode, NULL);
80 if (retval)
81 return retval;
82 bprm->dont_iput=0;
83 retval=prepare_binprm(bprm);
84 if(retval<0)
85 return retval;
86 return search_binary_handler(bprm,regs);
87 }
88
89 static int load_script(struct linux_binprm *bprm,struct pt_regs *regs)
90 {
91 int retval;
92 MOD_INC_USE_COUNT;
93 retval = do_load_script(bprm,regs);
94 MOD_DEC_USE_COUNT;
95 return retval;
96 }
97
98 struct linux_binfmt script_format = {
99 #ifndef MODULE
100 NULL, 0, load_script, NULL, NULL
101 #else
102 NULL, &mod_use_count_, load_script, NULL, NULL
103 #endif
104 };
105
106 int init_script_binfmt(void) {
107 return register_binfmt(&script_format);
108 }
109
110 #ifdef MODULE
111 int init_module(void)
112 {
113 return init_script_binfmt();
114 }
115
116 void cleanup_module( void) {
117 unregister_binfmt(&script_format);
118 }
119 #endif