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

Contents of /trunk/src/sandbox.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 83 - (hide annotations) (download) (as text)
Wed May 11 15:36:36 2005 UTC (8 years, 11 months ago) by azarah
Original Path: trunk/sandbox.c
File MIME type: text/x-csrc
File size: 17823 byte(s)
Remove ld.so.preload crap - we are not going to use it again.

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