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

Contents of /trunk/src/sandbox.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 98 - (hide annotations) (download) (as text)
Fri May 13 12:53:15 2005 UTC (8 years, 11 months ago) by azarah
Original Path: trunk/sandbox.c
File MIME type: text/x-csrc
File size: 18049 byte(s)
Remove sandbox_log_file from main() as its no longer used.

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 <fcntl.h>
21     #include <signal.h>
22     #include <stdio.h>
23     #include <stdlib.h>
24     #include <limits.h>
25     #include <string.h>
26     #include <sys/file.h>
27     #include <sys/stat.h>
28     #include <sys/time.h>
29     #include <sys/types.h>
30     #include <sys/resource.h>
31     #include <sys/wait.h>
32     #include <unistd.h>
33     #include <fcntl.h>
34     #include "sandbox.h"
35    
36     int cleaned_up = 0;
37     int print_debug = 0;
38     int stop_called = 0;
39    
40 azarah 30 /* Read pids file, and load active pids into an array. Return number of pids in array */
41     int load_active_pids(int fd, int **pids)
42 ferringb 2 {
43     char *data = NULL;
44     char *ptr = NULL, *ptr2 = NULL;
45     int my_pid;
46     int num_pids = 0;
47     long len;
48    
49     pids[0] = NULL;
50    
51     len = file_length(fd);
52    
53     /* Allocate and zero datablock to read pids file */
54 azarah 30 data = (char *)malloc((len + 1) * sizeof(char));
55 ferringb 2 memset(data, 0, len + 1);
56    
57     /* Start at beginning of file */
58     lseek(fd, 0L, SEEK_SET);
59    
60     /* read entire file into a buffer */
61     read(fd, data, len);
62    
63     ptr = data;
64    
65     /* Loop and read all pids */
66     while (1) {
67     /* Find new line */
68     ptr2 = strchr(ptr, '\n');
69     if (ptr2 == NULL)
70 azarah 30 break; /* No more PIDs */
71 ferringb 2
72     /* Clear the \n. And ptr should have a null-terminated decimal string */
73     ptr2[0] = 0;
74    
75     my_pid = atoi(ptr);
76    
77     /* If the PID is still alive, add it to our array */
78     if ((0 != my_pid) && (0 == kill(my_pid, 0))) {
79 azarah 30 pids[0] = (int *)realloc(pids[0], (num_pids + 1) * sizeof(int));
80 ferringb 2 pids[0][num_pids] = my_pid;
81     num_pids++;
82     }
83    
84     /* Put ptr past the NULL we just wrote */
85     ptr = ptr2 + 1;
86     }
87    
88     if (data)
89     free(data);
90     data = NULL;
91    
92     return num_pids;
93     }
94    
95 azarah 30 void cleanup()
96 ferringb 2 {
97     int i = 0;
98     int success = 1;
99     int pids_file = -1, num_of_pids = 0;
100     int *pids_array = NULL;
101 azarah 93 char pid_string[SB_BUF_LEN];
102 ferringb 2 char *sandbox_pids_file;
103    
104     /* Generate sandbox pids-file path */
105     sandbox_pids_file = get_sandbox_pids_file();
106    
107     /* Remove this sandbox's bash pid from the global pids
108 azarah 90 * file if we have not already done so */
109     if (0 == cleaned_up) {
110 ferringb 2 cleaned_up = 1;
111     success = 1;
112    
113     if (print_debug)
114     printf("Cleaning up pids file.\n");
115    
116     /* Stat the PIDs file, make sure it exists and is a regular file */
117     if (file_exist(sandbox_pids_file, 1) <= 0) {
118 ferringb 34 fprintf(stderr, ">>> pids file is not a regular file\n");
119 ferringb 2 success = 0;
120     /* We should really not fail if the pidsfile is missing here, but
121     * rather just exit cleanly, as there is still some cleanup to do */
122     return;
123     }
124    
125     pids_file = file_open(sandbox_pids_file, "r+", 1, 0664, "portage");
126     if (-1 == pids_file) {
127     success = 0;
128     /* Nothing more to do here */
129     return;
130     }
131    
132     /* Load "still active" pids into an array */
133     num_of_pids = load_active_pids(pids_file, &pids_array);
134     //printf("pids: %d\r\n", num_of_pids);
135    
136    
137     file_truncate(pids_file);
138    
139     /* if pids are still running, write only the running pids back to the file */
140     if (num_of_pids > 1) {
141     for (i = 0; i < num_of_pids; i++) {
142     if (pids_array[i] != getpid()) {
143     sprintf(pid_string, "%d\n", pids_array[i]);
144    
145 azarah 30 if (write(pids_file, pid_string, strlen(pid_string)) != strlen(pid_string)) {
146 ferringb 2 perror(">>> pids file write");
147     success = 0;
148     break;
149     }
150     }
151     }
152    
153     file_close(pids_file);
154     pids_file = -1;
155     } else {
156    
157     file_close(pids_file);
158     pids_file = -1;
159    
160     /* remove the pidsfile, as this was the last sandbox */
161     unlink(sandbox_pids_file);
162     }
163    
164     if (pids_array != NULL)
165     free(pids_array);
166     pids_array = NULL;
167     }
168    
169     free(sandbox_pids_file);
170     if (0 == success)
171     return;
172     }
173    
174 azarah 88 int print_sandbox_log(char *sandbox_log)
175     {
176     int sandbox_log_file = -1;
177     char *beep_count_env = NULL;
178     int i, color, beep_count = 0;
179     long len = 0;
180     char *buffer = NULL;
181    
182     sandbox_log_file = file_open(sandbox_log, "r", 1, 0664, "portage");
183     if (-1 == sandbox_log_file)
184     return 0;
185    
186     len = file_length(sandbox_log_file);
187     buffer = (char *)malloc((len + 1) * sizeof(char));
188     memset(buffer, 0, len + 1);
189     read(sandbox_log_file, buffer, len);
190     file_close(sandbox_log_file);
191    
192     color = ((getenv("NOCOLOR") != NULL) ? 0 : 1);
193    
194     if (color)
195     printf("\e[31;01m");
196     printf("--------------------------- ACCESS VIOLATION SUMMARY ---------------------------");
197     if (color)
198     printf("\033[0m");
199     if (color)
200     printf("\e[31;01m");
201     printf("\nLOG FILE = \"%s\"", sandbox_log);
202     if (color)
203     printf("\033[0m");
204     printf("\n\n");
205     printf("%s", buffer);
206     if (buffer)
207     free(buffer);
208     buffer = NULL;
209     printf("\e[31;01m--------------------------------------------------------------------------------\033[0m\n");
210    
211     beep_count_env = getenv(ENV_SANDBOX_BEEP);
212     if (beep_count_env)
213     beep_count = atoi(beep_count_env);
214     else
215     beep_count = DEFAULT_BEEP_COUNT;
216    
217     for (i = 0; i < beep_count; i++) {
218     fputc('\a', stderr);
219     if (i < beep_count - 1)
220     sleep(1);
221     }
222     return 1;
223     }
224    
225 azarah 30 void stop(int signum)
226 ferringb 2 {
227     if (stop_called == 0) {
228     stop_called = 1;
229     printf("Caught signal %d in pid %d\r\n", signum, getpid());
230 azarah 30 cleanup();
231 ferringb 2 } else {
232     fprintf(stderr, "Pid %d alreadly caught signal and is still cleaning up\n", getpid());
233     }
234     }
235    
236 azarah 89 void get_sandbox_write_envvar(char *buf, char *home_dir, char *portage_tmp_dir, char *var_tmp_dir, char *tmp_dir)
237 ferringb 2 {
238 azarah 89 /* bzero out entire buffer then append trailing 0 */
239 azarah 93 memset(buf, 0, SB_BUF_LEN);
240 azarah 30
241 azarah 89 /* these could go into make.globals later on */
242     snprintf(buf, SB_BUF_LEN,
243     "%s:%s/.gconfd/lock:%s/.bash_history:%s:%s:%s:%s",
244     "/dev/zero:/dev/fd/:/dev/null:/dev/pts/:"
245     "/dev/vc/:/dev/pty:/dev/tty:"
246     "/dev/shm/ngpt:/var/log/scrollkeeper.log:"
247     "/usr/tmp/conftest:/usr/lib/conftest:"
248     "/usr/lib32/conftest:/usr/lib64/conftest:"
249     "/usr/tmp/cf:/usr/lib/cf:/usr/lib32/cf:/usr/lib64/cf",
250     home_dir, home_dir,
251     (NULL != portage_tmp_dir) ? portage_tmp_dir : tmp_dir,
252     tmp_dir, var_tmp_dir, "/tmp/:/var/tmp/");
253     }
254    
255     void get_sandbox_predict_envvar(char *buf, char *home_dir)
256     {
257 ferringb 2 /* bzero out entire buffer then append trailing 0 */
258 azarah 93 memset(buf, 0, SB_BUF_LEN);
259 ferringb 2
260 azarah 89 /* these should go into make.globals later on */
261     snprintf(buf, SB_BUF_LEN, "%s/.:"
262     "/usr/lib/python2.0/:"
263     "/usr/lib/python2.1/:"
264     "/usr/lib/python2.2/:"
265     "/usr/lib/python2.3/:"
266     "/usr/lib/python2.4/:"
267     "/usr/lib/python2.5/:"
268     "/usr/lib/python3.0/:",
269     home_dir);
270     }
271 ferringb 2
272 azarah 89 int sandbox_setenv(char **env, char *name, char *val) {
273     char **tmp_env = env;
274     char *tmp_string = NULL;
275    
276     while (NULL != *tmp_env)
277     tmp_env++;
278    
279     /* strlen(name) + strlen(val) + '=' + '\0' */
280 azarah 96 /* FIXME: Should probably free this at some stage - more neatness than
281     * a real leak that will cause issues. */
282 azarah 89 tmp_string = calloc(strlen(name) + strlen(val) + 2, sizeof(char *));
283     if (NULL == tmp_string) {
284     perror(">>> out of memory (sandbox_setenv)");
285     exit(1);
286 ferringb 2 }
287 azarah 89
288     snprintf(tmp_string, strlen(name) + strlen(val) + 2, "%s=%s",
289     name, val);
290     *tmp_env = tmp_string;
291    
292     return 0;
293 ferringb 2 }
294    
295 azarah 89 /* We setup the environment child side only to prevent issues with
296     * setting LD_PRELOAD parent side */
297     char **sandbox_setup_environ(char *sandbox_dir, char *sandbox_lib, char *sandbox_rc, char *sandbox_log,
298     char *sandbox_debug_log, char *sandbox_write_envvar, char *sandbox_predict_envvar)
299 ferringb 2 {
300 azarah 89 int env_size = 0;
301    
302     char **new_environ;
303     char **env_ptr = environ;
304     char *ld_preload_envvar = NULL;
305 ferringb 2
306 azarah 89 /* Unset these, as its easier than replacing when setting up our
307     * new environment below */
308     unsetenv(ENV_SANDBOX_DIR);
309     unsetenv(ENV_SANDBOX_LIB);
310     unsetenv(ENV_SANDBOX_BASHRC);
311     unsetenv(ENV_SANDBOX_LOG);
312     unsetenv(ENV_SANDBOX_DEBUG_LOG);
313    
314     if (NULL != getenv("LD_PRELOAD")) {
315 azarah 96 /* FIXME: Should probably free this at some stage - more neatness
316     * than a real leak that will cause issues. */
317 azarah 89 ld_preload_envvar = malloc(strlen(getenv("LD_PRELOAD")) +
318     strlen(sandbox_lib) + 2);
319     if (NULL == ld_preload_envvar)
320     return NULL;
321     strncpy(ld_preload_envvar, sandbox_lib, strlen(sandbox_lib));
322     strncat(ld_preload_envvar, " ", 1);
323     strncat(ld_preload_envvar, getenv("LD_PRELOAD"),
324     strlen(getenv("LD_PRELOAD")));
325     } else {
326 azarah 96 /* FIXME: Should probably free this at some stage - more neatness
327     * than a real leak that will cause issues. */
328 azarah 89 ld_preload_envvar = strndup(sandbox_lib, strlen(sandbox_lib));
329     if (NULL == ld_preload_envvar)
330     return NULL;
331     }
332     unsetenv("LD_PRELOAD");
333 ferringb 2
334 azarah 89 while (NULL != *env_ptr) {
335     env_size++;
336     env_ptr++;
337     }
338 ferringb 2
339 azarah 96 /* FIXME: Should probably free this at some stage - more neatness than
340     * a real leak that will cause issues. */
341 azarah 89 new_environ = calloc((env_size + 15 + 1) * sizeof(char *), sizeof(char *));
342     if (NULL == new_environ)
343     return NULL;
344    
345     /* First add our new variables to the beginning - this is due to some
346     * weirdness that I cannot remember */
347     sandbox_setenv(new_environ, ENV_SANDBOX_DIR, sandbox_dir);
348     sandbox_setenv(new_environ, ENV_SANDBOX_LIB, sandbox_lib);
349     sandbox_setenv(new_environ, ENV_SANDBOX_BASHRC, sandbox_rc);
350     sandbox_setenv(new_environ, ENV_SANDBOX_LOG, sandbox_log);
351     sandbox_setenv(new_environ, ENV_SANDBOX_DEBUG_LOG, sandbox_debug_log);
352     sandbox_setenv(new_environ, "LD_PRELOAD", ld_preload_envvar);
353    
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     if (!getenv(ENV_SANDBOX_WRITE))
361     sandbox_setenv(new_environ, ENV_SANDBOX_WRITE, sandbox_write_envvar);
362    
363     if (!getenv(ENV_SANDBOX_PREDICT))
364     sandbox_setenv(new_environ, ENV_SANDBOX_PREDICT, sandbox_predict_envvar);
365    
366     /* This one should NEVER be set in ebuilds, as it is the one
367     * private thing libsandbox.so use to test if the sandbox
368     * should be active for this pid, or not.
369     *
370     * azarah (3 Aug 2002)
371     */
372    
373     sandbox_setenv(new_environ, "SANDBOX_ACTIVE", "armedandready");
374    
375     env_size = 0;
376     while (NULL != new_environ[env_size])
377     env_size++;
378    
379     /* Now add the rest */
380     env_ptr = environ;
381     while (NULL != *env_ptr) {
382     new_environ[env_size + (env_ptr - environ)] = *env_ptr;
383     env_ptr++;
384 ferringb 2 }
385 azarah 89
386     return new_environ;
387 ferringb 2 }
388    
389 azarah 89 int spawn_shell(char *argv_bash[], char *env[])
390 ferringb 2 {
391     int pid;
392     int status = 0;
393     int ret = 0;
394    
395     pid = fork();
396    
397     /* Child's process */
398     if (0 == pid) {
399 azarah 89 execve(argv_bash[0], argv_bash, env);
400 ferringb 2 return 0;
401     } else if (pid < 0) {
402     return 0;
403     }
404     ret = waitpid(pid, &status, 0);
405     if ((-1 == ret) || (status > 0))
406     return 0;
407 azarah 86
408 ferringb 2 return 1;
409     }
410    
411 azarah 30 int main(int argc, char **argv)
412 ferringb 2 {
413 azarah 35 int ret = 0, i = 0, success = 1;
414 ferringb 2 int sandbox_log_presence = 0;
415     int pids_file = -1;
416     long len;
417    
418     int *pids_array = NULL;
419     int num_of_pids = 0;
420    
421     // char run_arg[255];
422 azarah 89 char **sandbox_environ;
423 azarah 93 char sandbox_log[SB_PATH_MAX];
424     char sandbox_debug_log[SB_PATH_MAX];
425     char sandbox_dir[SB_PATH_MAX];
426     char sandbox_lib[SB_PATH_MAX];
427     char sandbox_rc[SB_PATH_MAX];
428 ferringb 2 char *sandbox_pids_file;
429 azarah 93 char portage_tmp_dir[SB_PATH_MAX];
430     char var_tmp_dir[SB_PATH_MAX];
431     char tmp_dir[SB_PATH_MAX];
432     char sandbox_write_envvar[SB_BUF_LEN];
433     char sandbox_predict_envvar[SB_BUF_LEN];
434     char pid_string[SB_BUF_LEN];
435 ferringb 2 char **argv_bash = NULL;
436    
437     char *run_str = "-c";
438     char *home_dir = NULL;
439     char *tmp_string = NULL;
440    
441     /* Only print info if called with no arguments .... */
442     if (argc < 2)
443     print_debug = 1;
444    
445     if (print_debug)
446 azarah 30 printf("========================== Gentoo linux path sandbox ===========================\n");
447 ferringb 2
448     /* check if a sandbox is already running */
449     if (NULL != getenv(ENV_SANDBOX_ON)) {
450 azarah 30 fprintf(stderr, "Not launching a new sandbox instance\n");
451     fprintf(stderr, "Another one is already running in this process hierarchy.\n");
452 ferringb 2 exit(1);
453     } else {
454    
455     /* determine the location of all the sandbox support files */
456     if (print_debug)
457     printf("Detection of the support files.\n");
458    
459     /* Generate base sandbox path */
460 azarah 97 snprintf(sandbox_dir, SB_PATH_MAX, "%s/",
461     get_sandbox_path(argv[0]));
462 ferringb 2
463     /* Generate sandbox lib path */
464 azarah 97 snprintf(sandbox_lib, SB_PATH_MAX, "%s",
465     get_sandbox_lib(sandbox_dir));
466 ferringb 2
467     /* Generate sandbox pids-file path */
468     sandbox_pids_file = get_sandbox_pids_file();
469    
470     /* Generate sandbox bashrc path */
471 azarah 97 snprintf(sandbox_rc, SB_PATH_MAX, "%s",
472     get_sandbox_rc(sandbox_dir));
473 ferringb 2
474     /* verify the existance of required files */
475     if (print_debug)
476     printf("Verification of the required files.\n");
477    
478     #ifndef SB_HAVE_64BIT_ARCH
479     if (file_exist(sandbox_lib, 0) <= 0) {
480 azarah 30 fprintf(stderr, "Could not open the sandbox library at '%s'.\n", sandbox_lib);
481 ferringb 2 return -1;
482 azarah 30 }
483 ferringb 2 #endif
484     if (file_exist(sandbox_rc, 0) <= 0) {
485 azarah 30 fprintf(stderr, "Could not open the sandbox rc file at '%s'.\n", sandbox_rc);
486 ferringb 2 return -1;
487     }
488    
489     /* set up the required environment variables */
490     if (print_debug)
491     printf("Setting up the required environment variables.\n");
492    
493     /* Generate sandbox log full path */
494 azarah 97 snprintf(sandbox_log, SB_PATH_MAX, "%s",
495     get_sandbox_log());
496 ferringb 2
497 azarah 97 /* Generate sandbox debug log full path */
498     snprintf(sandbox_debug_log, SB_PATH_MAX, "%s",
499     get_sandbox_debug_log());
500 ferringb 2
501     home_dir = getenv("HOME");
502     if (!home_dir) {
503     home_dir = "/tmp";
504     setenv("HOME", home_dir, 1);
505     }
506    
507 azarah 35 if (NULL == realpath(getenv("PORTAGE_TMPDIR") ? getenv("PORTAGE_TMPDIR")
508     : "/var/tmp/portage",
509     portage_tmp_dir)) {
510     perror(">>> get portage_tmp_dir");
511     exit(1);
512 ferringb 2 }
513 azarah 35 if (NULL == realpath("/var/tmp", var_tmp_dir)) {
514     perror(">>> get var_tmp_dir");
515     exit(1);
516     }
517     if (NULL == realpath("/tmp", tmp_dir)) {
518     perror(">>> get tmp_dir");
519     exit(1);
520     }
521 ferringb 2
522 azarah 91 /* This one should not be child only, as we check above to see
523     * if we are already running (check sandbox_setup_environ).
524     * This needs to be set before calling sandbox_setup_environ(),
525     * else its not set for the child */
526     setenv(ENV_SANDBOX_ON, "1", 0);
527    
528     /* Setup the child environment stuff */
529 azarah 89 get_sandbox_write_envvar(sandbox_write_envvar, home_dir,
530     portage_tmp_dir, var_tmp_dir, tmp_dir);
531     get_sandbox_predict_envvar(sandbox_predict_envvar, home_dir);
532     sandbox_environ = sandbox_setup_environ(sandbox_dir, sandbox_lib,
533     sandbox_rc, sandbox_log, sandbox_debug_log,
534     sandbox_write_envvar, sandbox_predict_envvar);
535     if (NULL == sandbox_environ) {
536     perror(">>> out of memory (environ)");
537     exit(1);
538 azarah 71 }
539 ferringb 2
540     /* if the portage temp dir was present, cd into it */
541     if (NULL != portage_tmp_dir)
542     chdir(portage_tmp_dir);
543    
544 azarah 30 argv_bash = (char **)malloc(6 * sizeof(char *));
545 ferringb 2 argv_bash[0] = strdup("/bin/bash");
546     argv_bash[1] = strdup("-rcfile");
547     argv_bash[2] = strdup(sandbox_rc);
548    
549     if (argc < 2)
550     argv_bash[3] = NULL;
551     else
552     argv_bash[3] = strdup(run_str); /* "-c" */
553    
554 azarah 30 argv_bash[4] = NULL; /* strdup(run_arg); */
555 ferringb 2 argv_bash[5] = NULL;
556    
557     if (argc >= 2) {
558     for (i = 1; i < argc; i++) {
559     if (NULL == argv_bash[4])
560     len = 0;
561     else
562     len = strlen(argv_bash[4]);
563    
564 azarah 89 argv_bash[4] = (char *)realloc(argv_bash[4],
565     (len + strlen(argv[i]) + 2) * sizeof(char));
566 ferringb 2
567     if (0 == len)
568     argv_bash[4][0] = 0;
569     if (1 != i)
570     strcat(argv_bash[4], " ");
571    
572     strcat(argv_bash[4], argv[i]);
573     }
574     }
575    
576     /* set up the required signal handlers */
577     signal(SIGHUP, &stop);
578     signal(SIGINT, &stop);
579     signal(SIGQUIT, &stop);
580     signal(SIGTERM, &stop);
581    
582     /* Load our PID into PIDs file */
583     success = 1;
584     if (file_exist(sandbox_pids_file, 1) < 0) {
585     success = 0;
586     fprintf(stderr, ">>> %s is not a regular file\n", sandbox_pids_file);
587     } else {
588     pids_file = file_open(sandbox_pids_file, "r+", 1, 0664, "portage");
589     if (-1 == pids_file)
590     success = 0;
591     }
592     if (1 == success) {
593     /* Grab still active pids */
594     num_of_pids = load_active_pids(pids_file, &pids_array);
595    
596     /* Zero out file */
597     file_truncate(pids_file);
598    
599     /* Output active pids, and append our pid */
600     for (i = 0; i < num_of_pids + 1; i++) {
601     /* Time for our entry */
602     if (i == num_of_pids)
603     sprintf(pid_string, "%d\n", getpid());
604     else
605     sprintf(pid_string, "%d\n", pids_array[i]);
606    
607 azarah 30 if (write(pids_file, pid_string, strlen(pid_string)) != strlen(pid_string)) {
608 ferringb 2 perror(">>> pids file write");
609     success = 0;
610     break;
611     }
612     }
613     /* Clean pids_array */
614     if (pids_array)
615     free(pids_array);
616     pids_array = NULL;
617     num_of_pids = 0;
618    
619     /* We're done with the pids file */
620     file_close(pids_file);
621     }
622    
623     /* Something went wrong, bail out */
624     if (0 == success) {
625     perror(">>> pids file write");
626     exit(1);
627     }
628    
629     /* STARTING PROTECTED ENVIRONMENT */
630     if (print_debug) {
631     printf("The protected environment has been started.\n");
632 azarah 30 printf("--------------------------------------------------------------------------------\n");
633 ferringb 2 }
634    
635     if (print_debug)
636     printf("Shell being started in forked process.\n");
637    
638     /* Start Bash */
639 azarah 89 if (!spawn_shell(argv_bash, sandbox_environ)) {
640 ferringb 2 if (print_debug)
641     fprintf(stderr, ">>> shell process failed to spawn\n");
642     success = 0;
643     }
644    
645     /* Free bash stuff */
646     for (i = 0; i < 6; i++) {
647     if (argv_bash[i])
648     free(argv_bash[i]);
649     argv_bash[i] = NULL;
650     }
651     if (argv_bash)
652     free(argv_bash);
653     argv_bash = NULL;
654    
655     if (print_debug)
656     printf("Cleaning up sandbox process\n");
657    
658     cleanup();
659    
660     if (print_debug) {
661 azarah 30 printf("========================== Gentoo linux path sandbox ===========================\n");
662 ferringb 2 printf("The protected environment has been shut down.\n");
663     }
664    
665     if (file_exist(sandbox_log, 0)) {
666     sandbox_log_presence = 1;
667     success = 1;
668     if (!print_sandbox_log(sandbox_log))
669     success = 0;
670    
671     #if 0
672     if (!success)
673     exit(1);
674     #endif
675    
676     } else if (print_debug) {
677 azarah 30 printf("--------------------------------------------------------------------------------\n");
678 ferringb 2 }
679    
680 azarah 35 free(sandbox_pids_file);
681    
682 ferringb 2 if ((sandbox_log_presence) || (!success))
683     return 1;
684     else
685     return 0;
686     }
687     }
688    
689 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