1 | | |
2 | | |
3 | | |
4 | | |
5 | | |
6 | | |
7 | | |
8 | | |
9 | | |
10 | | |
11 | | |
12 | | |
13 | | |
14 | | |
15 | | |
16 | | |
17 | | |
18 | | |
19 | | |
20 | | |
21 | | |
22 | | |
23 | | |
24 | | |
25 | | |
26 | | |
27 | | |
28 | | |
29 | | |
30 | | |
31 | | |
32 | | |
33 | | |
34 | | |
35 | | |
36 | | |
37 | | |
38 | | |
39 | | |
40 | | |
41 | | |
42 | | |
43 | | |
44 | | |
45 | | |
46 | | |
47 | | |
48 | | |
49 | | |
50 | | |
51 | | |
52 | | |
53 | | |
54 | | |
55 | | |
56 | | |
57 | | |
58 | | |
59 | | |
60 | | |
61 | | |
62 | | |
63 | | |
64 | | |
65 | | |
66 | | |
67 | | |
68 | | |
69 | | |
70 | | |
71 | | |
72 | | |
73 | | |
74 | | |
75 | | |
76 | | |
77 | | |
78 | | |
79 | | |
80 | | |
81 | | |
82 | | |
83 | | |
84 | | |
85 | | |
86 | | |
87 | | |
88 | | |
89 | | |
90 | | |
91 | | |
92 | | |
93 | | |
94 | | |
95 | | |
96 | | |
97 | | |
98 | | |
99 | | |
100 | | |
101 | | |
102 | | |
103 | | |
104 | | |
105 | | |
106 | | |
107 | | |
108 | | |
109 | | |
110 | | |
111 | | |
112 | | |
113 | | |
114 | | |
115 | | |
116 | | |
117 | | |
118 | | |
119 | | |
120 | | |
121 | | |
122 | | |
123 | | |
124 | | |
| string popen(string s, void|mapping env) | { | object p,p2 | | p2 = File() | p=p2->pipe() | if(!p) error("Popen failed. (couldn't create pipe)\n") | | if(!fork()) | { | array (int) olduid | catch { | if(p->query_fd() < 0) | { | perror("File to dup2 to closed!\n") | exit(99) | } | p->dup2(File("stdout")) | | olduid = ({ geteuid(), getegid() }) | seteuid(0) | #if efun(setegid) | setegid(getgid()) | #endif | setgid(olduid[1]) | setuid(olduid[0]) | catch(exece("/bin/sh", ({ "-c", s }), (env||environment))) | } | exit(69) | }else{ | string t | destruct(p) | t=p2->read(6553555) | destruct(p2) | return t | } | } | | | mapping make_mapping(string *f) | { | mapping foo=([ ]) | string s, a, b | foreach(f, s) | { | sscanf(s, "%s=%s", a, b) | foo[a]=b | } | return foo | } | | int low_spawne(string s,string *args, mapping|array env, object stdin, | object stdout, object stderr, void|string wd) | { | object p | int pid | string t | | if(arrayp(env)) | env = make_mapping(env) | if(!mappingp(env)) | env=([]) | | | stdin->dup2(File("stdin")) | stdout->dup2(File("stdout")) | stderr->dup2(File("stderr")) | if(stringp(wd) && sizeof(wd)) | cd(wd) | exece(s, args, env) | perror(sprintf("Spawne: Failed to exece %s\n", s)) | exit(0) | } | | int spawne(string s,string *args, mapping|array env, object stdin, | object stdout, object stderr, void|string wd, void|array (int) uid) | { | int pid, *olduid = allocate(2, "int") | if(pid=fork()) | return pid | if(arrayp(uid) && sizeof(uid) == 2) | { | #if efun(seteuid) | olduid = ({ geteuid(), getegid() }) | seteuid(0) | #endif | #if efun(setegid) | setegid(getgid()) | #endif | setgid(uid[1]) | setuid(uid[0]) | if(!getuid()) | { | #if efun(seteuid) | setgid(olduid[1]) | setuid(olduid[0]) | #else | setgid(-1) | setuid(-1) | #endif | } else { | olduid = ({ geteuid(), getegid() }) | #if efun(seteuid) | seteuid(0) | #endif | #if efun(setegid) | setegid(getgid()) | #endif | setgid(olduid[1]) | setuid(olduid[0]) | } | } | catch(low_spawne(s, args, env, stdin, stdout, stderr, wd)) | exit(0) | } | | void create() | { | add_constant("spawne",spawne) | add_constant("perror",werror) | add_constant("popen",popen) | } | | |
|