127 |
static void set_sandbox(void) { |
static void set_sandbox(void) { |
128 |
|
|
129 |
int i; |
int i; |
|
int max_descriptors = 1024; |
|
130 |
struct stat st; |
struct stat st; |
131 |
extern char **environ; |
extern char **environ; |
132 |
char *path = "PATH=/bin:/usr/bin:/sbin:/usr/sbin"; |
char *path = "PATH=/bin:/usr/bin:/sbin:/usr/sbin"; |
133 |
|
|
134 |
/* |
/* |
135 |
|
* Purge the environment. Then make sure PATH is set; some shells default |
136 |
|
* to a path with '.' first. You may have to putenv() other stuff, too, |
137 |
|
* but be careful with importing too much. |
138 |
|
*/ |
139 |
|
environ[0]= 0; |
140 |
|
|
141 |
|
if(putenv(path)) { |
142 |
|
|
143 |
|
log("%s: cannot set the PATH variable -- %s\n", prog, STRERROR); |
144 |
|
exit(1); |
145 |
|
|
146 |
|
} |
147 |
|
|
148 |
|
/* |
149 |
* Require that file descriptors 0,1,2 are open. Mysterious things |
* Require that file descriptors 0,1,2 are open. Mysterious things |
150 |
* can happen if that is not the case. |
* can happen if that is not the case. |
151 |
*/ |
*/ |
160 |
|
|
161 |
} |
} |
162 |
|
|
163 |
/* |
fd_close(); |
|
* Require that the other file descriptios are closed. Everything |
|
|
* seems to have getdtablesize, so we'll use it here, and back |
|
|
* out to use 1024 if getdtablesize not available. |
|
|
*/ |
|
|
#ifdef HAVE_UNISTD_H |
|
|
max_descriptors = getdtablesize(); |
|
|
#endif |
|
|
for(i = 3; i < max_descriptors; i++) |
|
|
(void) close(i); |
|
|
errno= 0; |
|
|
|
|
|
/* |
|
|
* Purge the environment. Then make sure PATH is set; some shells default |
|
|
* to a path with '.' first. You may have to putenv() other stuff, too, |
|
|
* but be careful with importing too much. |
|
|
*/ |
|
|
environ[0]= 0; |
|
|
|
|
|
if(putenv(path)) { |
|
|
|
|
|
log("%s: cannot set the PATH variable -- %s\n", prog, STRERROR); |
|
|
exit(1); |
|
|
|
|
|
} |
|
164 |
|
|
165 |
} |
} |
166 |
|
|