/[path-sandbox]/trunk/src/sandbox.c
Gentoo

Contents of /trunk/src/sandbox.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 265 - (hide annotations) (download) (as text)
Tue Jul 4 15:32:43 2006 UTC (8 years ago) by azarah
File MIME type: text/x-csrc
File size: 16285 byte(s)
Add SANDBOX_INTRACTV logic, and Vapier's sandboxshell mojo.

1 ferringb 2 /*
2     ** Path sandbox for the gentoo linux portage package system, initially
3     ** based on the ROCK Linux Wrapper for getting a list of created files
4     **
5     ** to integrate with bash, bash should have been built like this
6     **
7     ** ./configure --prefix=<prefix> --host=<host> --without-gnu-malloc
8     **
9     ** it's very important that the --enable-static-link option is NOT specified
10     **
11     ** Copyright (C) 2001 Geert Bevin, Uwyn, http://www.uwyn.com
12     ** Distributed under the terms of the GNU General Public License, v2 or later
13     ** Author : Geert Bevin <gbevin@uwyn.com>
14     ** $Header$
15     */
16    
17     /* #define _GNU_SOURCE */
18    
19     #include <errno.h>
20     #include <signal.h>
21     #include <stdio.h>
22     #include <stdlib.h>
23     #include <limits.h>
24     #include <string.h>
25     #include <sys/wait.h>
26 azarah 261 #include <signal.h>
27 ferringb 2 #include <unistd.h>
28     #include <fcntl.h>
29 azarah 142
30 ferringb 2 #include "sandbox.h"
31    
32 azarah 101 struct sandbox_info_t {
33     char sandbox_log[SB_PATH_MAX];
34     char sandbox_debug_log[SB_PATH_MAX];
35     char sandbox_lib[SB_PATH_MAX];
36     char sandbox_rc[SB_PATH_MAX];
37 azarah 157 char work_dir[SB_PATH_MAX];
38 azarah 101 char var_tmp_dir[SB_PATH_MAX];
39     char tmp_dir[SB_PATH_MAX];
40     char *home_dir;
41     } sandbox_info_t;
42 ferringb 2
43 azarah 99 static int print_debug = 0;
44     static int stop_called = 0;
45    
46 azarah 261 volatile static pid_t child_pid = 0;
47    
48 azarah 216 extern char **environ;
49    
50 azarah 141 int sandbox_setup(struct sandbox_info_t *sandbox_info)
51 azarah 101 {
52 azarah 165 if (NULL != getenv(ENV_PORTAGE_TMPDIR)) {
53     /* Portage handle setting SANDBOX_WRITE itself. */
54     sandbox_info->work_dir[0] = '\0';
55 azarah 157 } else {
56 azarah 224 if (NULL == getcwd(sandbox_info->work_dir, SB_PATH_MAX)) {
57 azarah 157 perror("sandbox: Failed to get current directory");
58     return -1;
59     }
60 azarah 101 }
61    
62 azarah 152 /* Do not resolve symlinks, etc .. libsandbox will handle that. */
63     if (1 != is_dir(VAR_TMPDIR, 1)) {
64 azarah 145 perror("sandbox: Failed to get var_tmp_dir");
65 azarah 101 return -1;
66     }
67 azarah 152 snprintf(sandbox_info->var_tmp_dir, SB_PATH_MAX, "%s", VAR_TMPDIR);
68 azarah 139
69 azarah 101 if (-1 == get_tmp_dir(sandbox_info->tmp_dir)) {
70 azarah 145 perror("sandbox: Failed to get tmp_dir");
71 azarah 101 return -1;
72     }
73 azarah 158 setenv(ENV_TMPDIR, sandbox_info->tmp_dir, 1);
74 azarah 101
75     sandbox_info->home_dir = getenv("HOME");
76     if (!sandbox_info->home_dir) {
77 azarah 158 sandbox_info->home_dir = sandbox_info->tmp_dir;
78 azarah 101 setenv("HOME", sandbox_info->home_dir, 1);
79     }
80    
81     /* Generate sandbox lib path */
82 azarah 140 get_sandbox_lib(sandbox_info->sandbox_lib);
83 azarah 101
84     /* Generate sandbox bashrc path */
85 azarah 140 get_sandbox_rc(sandbox_info->sandbox_rc);
86 azarah 101
87     /* Generate sandbox log full path */
88 azarah 140 get_sandbox_log(sandbox_info->sandbox_log);
89 azarah 146 if (1 == exists(sandbox_info->sandbox_log)) {
90     if (-1 == unlink(sandbox_info->sandbox_log)) {
91     perror("sandbox: Could not unlink old log file");
92 azarah 147 return -1;
93 azarah 146 }
94     }
95 azarah 101
96     /* Generate sandbox debug log full path */
97 azarah 140 get_sandbox_debug_log(sandbox_info->sandbox_debug_log);
98 azarah 147 if (1 == exists(sandbox_info->sandbox_debug_log)) {
99 azarah 146 if (-1 == unlink(sandbox_info->sandbox_debug_log)) {
100     perror("sandbox: Could not unlink old debug log file");
101 azarah 147 return -1;
102 azarah 146 }
103     }
104 azarah 101
105     return 0;
106     }
107    
108 azarah 88 int print_sandbox_log(char *sandbox_log)
109     {
110     int sandbox_log_file = -1;
111     char *beep_count_env = NULL;
112     int i, color, beep_count = 0;
113     long len = 0;
114     char *buffer = NULL;
115    
116 azarah 139 if (1 != is_file(sandbox_log)) {
117 azarah 145 perror("sandbox: Log file is not a regular file");
118 azarah 88 return 0;
119 azarah 139 }
120    
121     sandbox_log_file = open(sandbox_log, O_RDONLY);
122     if (-1 == sandbox_log_file) {
123 azarah 145 perror("sandbox: Could not open Log file");
124 azarah 139 return 0;
125     }
126 azarah 88
127     len = file_length(sandbox_log_file);
128     buffer = (char *)malloc((len + 1) * sizeof(char));
129     memset(buffer, 0, len + 1);
130     read(sandbox_log_file, buffer, len);
131 azarah 139 close(sandbox_log_file);
132 azarah 88
133 azarah 263 color = ((is_env_on(ENV_NOCOLOR)) ? 0 : 1);
134 azarah 88
135 azarah 144 EERROR(color,
136     "--------------------------- ACCESS VIOLATION SUMMARY ---------------------------",
137     "\n");
138     EERROR(color, "LOG FILE = \"%s\"", "\n\n", sandbox_log);
139     fprintf(stderr, "%s", buffer);
140     if (NULL != buffer)
141 azarah 88 free(buffer);
142 azarah 144 EERROR(color,
143     "--------------------------------------------------------------------------------",
144     "\n");
145 azarah 88
146     beep_count_env = getenv(ENV_SANDBOX_BEEP);
147     if (beep_count_env)
148     beep_count = atoi(beep_count_env);
149     else
150     beep_count = DEFAULT_BEEP_COUNT;
151    
152     for (i = 0; i < beep_count; i++) {
153     fputc('\a', stderr);
154     if (i < beep_count - 1)
155     sleep(1);
156     }
157 azarah 139
158 azarah 88 return 1;
159     }
160    
161 azarah 30 void stop(int signum)
162 ferringb 2 {
163     if (stop_called == 0) {
164     stop_called = 1;
165 azarah 145 printf("sandbox: Caught signal %d in pid %d\n",
166     signum, getpid());
167 azarah 261
168     if ((SIGUSR1 == signum) && (0 != child_pid))
169     kill(child_pid, SIGKILL);
170 ferringb 2 } else {
171 azarah 145 fprintf(stderr,
172     "sandbox: Signal already caught and busy still cleaning up!\n");
173 ferringb 2 }
174     }
175    
176 azarah 159 int get_sandbox_write_envvar(char *buf, struct sandbox_info_t *sandbox_info)
177 ferringb 2 {
178 azarah 159 int retval = 0;
179    
180 azarah 89 /* bzero out entire buffer then append trailing 0 */
181 azarah 93 memset(buf, 0, SB_BUF_LEN);
182 azarah 30
183 azarah 89 /* these could go into make.globals later on */
184 azarah 159 retval = snprintf(buf, SB_BUF_LEN,
185 azarah 89 "%s:%s/.gconfd/lock:%s/.bash_history:%s:%s:%s:%s",
186 azarah 113 "/dev/zero:/dev/null:/dev/fd:/proc/self/fd:/dev/pts/:"
187 azarah 155 "/dev/vc/:/dev/pty:/dev/tty:/dev/tts:/dev/console:"
188 azarah 204 "/dev/shm:/dev/shm/ngpt:/var/log/scrollkeeper.log:"
189 azarah 89 "/usr/tmp/conftest:/usr/lib/conftest:"
190     "/usr/lib32/conftest:/usr/lib64/conftest:"
191     "/usr/tmp/cf:/usr/lib/cf:/usr/lib32/cf:/usr/lib64/cf",
192 azarah 101 sandbox_info->home_dir, sandbox_info->home_dir,
193 azarah 165 sandbox_info->work_dir[0] != '\0' ? sandbox_info->work_dir
194     : "",
195 azarah 101 sandbox_info->tmp_dir, sandbox_info->var_tmp_dir,
196     "/tmp/:/var/tmp/");
197 azarah 159 if (SB_BUF_LEN <= retval) {
198     errno = EMSGSIZE;
199     perror("sandbox: Failed to generate SANDBOX_WRITE");
200     return -1;
201     }
202    
203     return 0;
204 azarah 89 }
205    
206 azarah 159 int get_sandbox_predict_envvar(char *buf, struct sandbox_info_t *sandbox_info)
207 azarah 89 {
208 azarah 159 int retval = 0;
209 ferringb 2 /* bzero out entire buffer then append trailing 0 */
210 azarah 93 memset(buf, 0, SB_BUF_LEN);
211 ferringb 2
212 azarah 89 /* these should go into make.globals later on */
213 azarah 159 retval = snprintf(buf, SB_BUF_LEN, "%s/.:"
214 azarah 89 "/usr/lib/python2.0/:"
215     "/usr/lib/python2.1/:"
216     "/usr/lib/python2.2/:"
217     "/usr/lib/python2.3/:"
218     "/usr/lib/python2.4/:"
219     "/usr/lib/python2.5/:"
220 azarah 126 "/usr/lib/python3.0/:"
221     "/var/db/aliases.db:"
222     "/var/db/netgroup.db:"
223     "/var/db/netmasks.db:"
224     "/var/db/ethers.db:"
225     "/var/db/rpc.db:"
226     "/var/db/protocols.db:"
227     "/var/db/services.db:"
228     "/var/db/networks.db:"
229     "/var/db/hosts.db:"
230     "/var/db/group.db:"
231 azarah 131 "/var/db/passwd.db",
232 azarah 101 sandbox_info->home_dir);
233 azarah 159 if (SB_BUF_LEN <= retval) {
234     errno = EMSGSIZE;
235     perror("sandbox: Failed to generate SANDBOX_PREDICT");
236     return -1;
237     }
238    
239     return 0;
240 azarah 89 }
241 ferringb 2
242 azarah 124 int sandbox_setenv(char **env, const char *name, const char *val) {
243 azarah 89 char **tmp_env = env;
244     char *tmp_string = NULL;
245 azarah 159 int retval = 0;
246 azarah 89
247 azarah 100 /* XXX: We add the new variable to the end (no replacing). If this
248     * is changed, we need to fix sandbox_setup_environ() below */
249 azarah 89 while (NULL != *tmp_env)
250     tmp_env++;
251    
252     /* strlen(name) + strlen(val) + '=' + '\0' */
253 azarah 96 /* FIXME: Should probably free this at some stage - more neatness than
254     * a real leak that will cause issues. */
255 azarah 89 tmp_string = calloc(strlen(name) + strlen(val) + 2, sizeof(char *));
256     if (NULL == tmp_string) {
257 azarah 145 perror("sandbox: Out of memory (sandbox_setenv)");
258     exit(EXIT_FAILURE);
259 ferringb 2 }
260 azarah 89
261 azarah 159 retval = snprintf(tmp_string, strlen(name) + strlen(val) + 2, "%s=%s",
262     name, val);
263 azarah 89 *tmp_env = tmp_string;
264    
265     return 0;
266 ferringb 2 }
267    
268 azarah 89 /* We setup the environment child side only to prevent issues with
269     * setting LD_PRELOAD parent side */
270 azarah 265 char **sandbox_setup_environ(struct sandbox_info_t *sandbox_info, bool interactive)
271 ferringb 2 {
272 azarah 89 int env_size = 0;
273 azarah 100 int have_ld_preload = 0;
274 azarah 89
275     char **new_environ;
276     char **env_ptr = environ;
277 azarah 124 char sandbox_write_envvar[SB_BUF_LEN];
278     char sandbox_predict_envvar[SB_BUF_LEN];
279 azarah 89 char *ld_preload_envvar = NULL;
280 azarah 100 char *orig_ld_preload_envvar = NULL;
281 azarah 261 char sb_pid[64];
282 ferringb 2
283 azarah 89 /* Unset these, as its easier than replacing when setting up our
284     * new environment below */
285 azarah 193 unsetenv(ENV_SANDBOX_ON);
286 azarah 261 unsetenv(ENV_SANDBOX_PID);
287 azarah 89 unsetenv(ENV_SANDBOX_LIB);
288     unsetenv(ENV_SANDBOX_BASHRC);
289     unsetenv(ENV_SANDBOX_LOG);
290     unsetenv(ENV_SANDBOX_DEBUG_LOG);
291 azarah 261 unsetenv(ENV_SANDBOX_ACTIVE);
292 azarah 89
293 azarah 100 if (NULL != getenv(ENV_LD_PRELOAD)) {
294     have_ld_preload = 1;
295     orig_ld_preload_envvar = getenv(ENV_LD_PRELOAD);
296    
297 azarah 96 /* FIXME: Should probably free this at some stage - more neatness
298     * than a real leak that will cause issues. */
299 azarah 100 ld_preload_envvar = calloc(strlen(orig_ld_preload_envvar) +
300 azarah 101 strlen(sandbox_info->sandbox_lib) + 2,
301     sizeof(char *));
302 azarah 89 if (NULL == ld_preload_envvar)
303     return NULL;
304 azarah 100 snprintf(ld_preload_envvar, strlen(orig_ld_preload_envvar) +
305 azarah 101 strlen(sandbox_info->sandbox_lib) + 2, "%s %s",
306     sandbox_info->sandbox_lib, orig_ld_preload_envvar);
307 azarah 89 } else {
308 azarah 96 /* FIXME: Should probably free this at some stage - more neatness
309     * than a real leak that will cause issues. */
310 azarah 216 ld_preload_envvar = gstrndup(sandbox_info->sandbox_lib,
311 azarah 101 strlen(sandbox_info->sandbox_lib));
312 azarah 89 if (NULL == ld_preload_envvar)
313     return NULL;
314     }
315 azarah 100 /* Do not unset this, as strange things might happen */
316     /* unsetenv(ENV_LD_PRELOAD); */
317 ferringb 2
318 azarah 89 while (NULL != *env_ptr) {
319     env_size++;
320     env_ptr++;
321     }
322 ferringb 2
323 azarah 96 /* FIXME: Should probably free this at some stage - more neatness than
324     * a real leak that will cause issues. */
325 azarah 89 new_environ = calloc((env_size + 15 + 1) * sizeof(char *), sizeof(char *));
326     if (NULL == new_environ)
327     return NULL;
328    
329 azarah 261 snprintf(sb_pid, sizeof(sb_pid), "%i", getpid());
330    
331 azarah 89 /* First add our new variables to the beginning - this is due to some
332     * weirdness that I cannot remember */
333 azarah 193 sandbox_setenv(new_environ, ENV_SANDBOX_ON, "1");
334 azarah 261 sandbox_setenv(new_environ, ENV_SANDBOX_PID, sb_pid);
335 azarah 101 sandbox_setenv(new_environ, ENV_SANDBOX_LIB, sandbox_info->sandbox_lib);
336     sandbox_setenv(new_environ, ENV_SANDBOX_BASHRC, sandbox_info->sandbox_rc);
337     sandbox_setenv(new_environ, ENV_SANDBOX_LOG, sandbox_info->sandbox_log);
338     sandbox_setenv(new_environ, ENV_SANDBOX_DEBUG_LOG,
339     sandbox_info->sandbox_debug_log);
340 azarah 265 /* Is this an interactive session? */
341     if (interactive)
342     sandbox_setenv(new_environ, ENV_SANDBOX_INTRACTV, "1");
343 azarah 263 /* Just set the these if not already set so that is_env_on() work */
344     if (!getenv(ENV_SANDBOX_VERBOSE))
345     sandbox_setenv(new_environ, ENV_SANDBOX_VERBOSE, "1");
346     if (!getenv(ENV_SANDBOX_DEBUG))
347     sandbox_setenv(new_environ, ENV_SANDBOX_DEBUG, "0");
348     if (!getenv(ENV_NOCOLOR))
349     sandbox_setenv(new_environ, ENV_NOCOLOR, "0");
350 azarah 100 /* If LD_PRELOAD was not set, set it here, else do it below */
351     if (1 != have_ld_preload)
352     sandbox_setenv(new_environ, ENV_LD_PRELOAD, ld_preload_envvar);
353 azarah 89
354     if (!getenv(ENV_SANDBOX_DENY))
355     sandbox_setenv(new_environ, ENV_SANDBOX_DENY, LD_PRELOAD_FILE);
356    
357     if (!getenv(ENV_SANDBOX_READ))
358     sandbox_setenv(new_environ, ENV_SANDBOX_READ, "/");
359    
360 azarah 159 if (-1 == get_sandbox_write_envvar(sandbox_write_envvar, sandbox_info))
361     return NULL;
362 azarah 89 if (!getenv(ENV_SANDBOX_WRITE))
363     sandbox_setenv(new_environ, ENV_SANDBOX_WRITE, sandbox_write_envvar);
364    
365 azarah 159 if (-1 == get_sandbox_predict_envvar(sandbox_predict_envvar, sandbox_info))
366     return NULL;
367 azarah 89 if (!getenv(ENV_SANDBOX_PREDICT))
368     sandbox_setenv(new_environ, ENV_SANDBOX_PREDICT, sandbox_predict_envvar);
369    
370 azarah 175 /* Make sure our bashrc gets preference */
371     sandbox_setenv(new_environ, ENV_BASH_ENV, sandbox_info->sandbox_rc);
372    
373 azarah 89 /* This one should NEVER be set in ebuilds, as it is the one
374     * private thing libsandbox.so use to test if the sandbox
375     * should be active for this pid, or not.
376     *
377     * azarah (3 Aug 2002)
378     */
379    
380 azarah 173 sandbox_setenv(new_environ, ENV_SANDBOX_ACTIVE, SANDBOX_ACTIVE);
381 azarah 89
382     env_size = 0;
383     while (NULL != new_environ[env_size])
384     env_size++;
385    
386     /* Now add the rest */
387     env_ptr = environ;
388     while (NULL != *env_ptr) {
389 azarah 100 if ((1 == have_ld_preload) &&
390     (strstr(*env_ptr, LD_PRELOAD_EQ) == *env_ptr))
391     /* If LD_PRELOAD was set, and this is it in the original
392     * environment, replace it with our new copy */
393 azarah 101 /* XXX: The following works as it just add whatever as
394     * the last variable to nev_environ */
395 azarah 100 sandbox_setenv(new_environ, ENV_LD_PRELOAD,
396     ld_preload_envvar);
397     else
398     new_environ[env_size + (env_ptr - environ)] = *env_ptr;
399 azarah 89 env_ptr++;
400 ferringb 2 }
401 azarah 89
402     return new_environ;
403 ferringb 2 }
404    
405 azarah 145 int spawn_shell(char *argv_bash[], char *env[], int debug)
406 ferringb 2 {
407     int status = 0;
408     int ret = 0;
409    
410 azarah 261 child_pid = fork();
411 ferringb 2
412     /* Child's process */
413 azarah 261 if (0 == child_pid) {
414 azarah 89 execve(argv_bash[0], argv_bash, env);
415 ferringb 2 return 0;
416 azarah 261 } else if (child_pid < 0) {
417 azarah 145 if (debug)
418     fprintf(stderr, "Process failed to spawn!\n");
419 ferringb 2 return 0;
420     }
421 azarah 261 ret = waitpid(child_pid, &status, 0);
422 azarah 145 if ((-1 == ret) || (status > 0)) {
423     if (debug)
424     fprintf(stderr, "Process returned with failed exit status!\n");
425 ferringb 2 return 0;
426 azarah 145 }
427 azarah 86
428 ferringb 2 return 1;
429     }
430    
431 azarah 30 int main(int argc, char **argv)
432 ferringb 2 {
433 azarah 101 int i = 0, success = 1;
434 ferringb 2 int sandbox_log_presence = 0;
435     long len;
436    
437 azarah 101 struct sandbox_info_t sandbox_info;
438 ferringb 2
439 azarah 89 char **sandbox_environ;
440 ferringb 2 char **argv_bash = NULL;
441    
442     char *run_str = "-c";
443    
444     /* Only print info if called with no arguments .... */
445     if (argc < 2)
446     print_debug = 1;
447    
448     if (print_debug)
449 azarah 30 printf("========================== Gentoo linux path sandbox ===========================\n");
450 ferringb 2
451     /* check if a sandbox is already running */
452 azarah 184 if (NULL != getenv(ENV_SANDBOX_ACTIVE)) {
453 azarah 30 fprintf(stderr, "Not launching a new sandbox instance\n");
454     fprintf(stderr, "Another one is already running in this process hierarchy.\n");
455 azarah 145 exit(EXIT_FAILURE);
456     }
457 ferringb 2
458 azarah 145 /* determine the location of all the sandbox support files */
459     if (print_debug)
460     printf("Detection of the support files.\n");
461 ferringb 2
462 azarah 145 if (-1 == sandbox_setup(&sandbox_info)) {
463 azarah 147 fprintf(stderr, "sandbox: Failed to setup sandbox.");
464 azarah 145 exit(EXIT_FAILURE);
465     }
466    
467     /* verify the existance of required files */
468     if (print_debug)
469     printf("Verification of the required files.\n");
470 ferringb 2
471 azarah 181 #ifndef SB_HAVE_MULTILIB
472 azarah 145 if (0 >= exists(sandbox_info.sandbox_lib)) {
473     perror("sandbox: Could not open the sandbox library");
474     exit(EXIT_FAILURE);
475     }
476 ferringb 2 #endif
477 azarah 145 if (0 >= exists(sandbox_info.sandbox_rc)) {
478     perror("sandbox: Could not open the sandbox rc file");
479     exit(EXIT_FAILURE);
480     }
481 ferringb 2
482 azarah 145 /* set up the required environment variables */
483     if (print_debug)
484     printf("Setting up the required environment variables.\n");
485 ferringb 2
486 azarah 145 /* Setup the child environment stuff */
487 azarah 265 sandbox_environ = sandbox_setup_environ(&sandbox_info, print_debug);
488 azarah 145 if (NULL == sandbox_environ) {
489     perror("sandbox: Out of memory (environ)");
490     exit(EXIT_FAILURE);
491     }
492 ferringb 2
493 azarah 165 /* If not in portage, cd into it work directory */
494     if ('\0' != sandbox_info.work_dir[0])
495 azarah 157 chdir(sandbox_info.work_dir);
496 ferringb 2
497 azarah 145 argv_bash = (char **)malloc(6 * sizeof(char *));
498     argv_bash[0] = strdup("/bin/bash");
499     argv_bash[1] = strdup("-rcfile");
500     argv_bash[2] = strdup(sandbox_info.sandbox_rc);
501 ferringb 2
502 azarah 145 if (argc < 2)
503     argv_bash[3] = NULL;
504     else
505     argv_bash[3] = strdup(run_str); /* "-c" */
506 ferringb 2
507 azarah 145 argv_bash[4] = NULL; /* strdup(run_arg); */
508     argv_bash[5] = NULL;
509 ferringb 2
510 azarah 145 if (argc >= 2) {
511     for (i = 1; i < argc; i++) {
512     if (NULL == argv_bash[4])
513     len = 0;
514     else
515     len = strlen(argv_bash[4]);
516 ferringb 2
517 azarah 145 argv_bash[4] = (char *)realloc(argv_bash[4],
518     (len + strlen(argv[i]) + 2) * sizeof(char));
519 ferringb 2
520 azarah 145 if (0 == len)
521     argv_bash[4][0] = 0;
522     if (1 != i)
523     strcat(argv_bash[4], " ");
524 ferringb 2
525 azarah 145 strcat(argv_bash[4], argv[i]);
526 ferringb 2 }
527 azarah 145 }
528 ferringb 2
529 azarah 145 /* set up the required signal handlers */
530     signal(SIGHUP, &stop);
531     signal(SIGINT, &stop);
532     signal(SIGQUIT, &stop);
533     signal(SIGTERM, &stop);
534 azarah 261 signal(SIGUSR1, &stop);
535 ferringb 2
536 azarah 145 /* STARTING PROTECTED ENVIRONMENT */
537     if (print_debug) {
538     printf("The protected environment has been started.\n");
539     printf("--------------------------------------------------------------------------------\n");
540     }
541 ferringb 2
542 azarah 145 if (print_debug)
543     printf("Process being started in forked instance.\n");
544 ferringb 2
545 azarah 145 /* Start Bash */
546     if (!spawn_shell(argv_bash, sandbox_environ, print_debug))
547     success = 0;
548 ferringb 2
549 azarah 145 /* Free bash stuff */
550     for (i = 0; i < 6; i++) {
551     if (argv_bash[i])
552     free(argv_bash[i]);
553     argv_bash[i] = NULL;
554     }
555     if (argv_bash)
556     free(argv_bash);
557     argv_bash = NULL;
558 ferringb 2
559 azarah 145 if (print_debug)
560     printf("Cleaning up sandbox process\n");
561 ferringb 2
562 azarah 145 if (print_debug) {
563     printf("========================== Gentoo linux path sandbox ===========================\n");
564     printf("The protected environment has been shut down.\n");
565     }
566 ferringb 2
567 azarah 145 if (1 == exists(sandbox_info.sandbox_log)) {
568     sandbox_log_presence = 1;
569     print_sandbox_log(sandbox_info.sandbox_log);
570     } else if (print_debug) {
571     printf("--------------------------------------------------------------------------------\n");
572     }
573 ferringb 2
574 azarah 145 if ((sandbox_log_presence) || (!success))
575     return 1;
576     else
577     return 0;
578 ferringb 2 }
579    
580 azarah 30 // vim:noexpandtab noai:cindent ai

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20