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

Contents of /trunk/src/sandbox.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 97 - (hide annotations) (download) (as text)
Fri May 13 12:52:10 2005 UTC (9 years, 7 months ago) by azarah
Original Path: trunk/sandbox.c
File MIME type: text/x-csrc
File size: 18103 byte(s)
Add get_sandbox_debug_log(), and use it (add behaviour similar to SANDBOX_LOG
if already exported when sandbox started).  Fix get_sandbox_log() and new
get_sandbox_debug_log() to not use already exported environment variables if
they have '/' in them.  Use snprintf()'s instead of strncpy()'s.  More
SB_PATH_MAX fixes.

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 sandbox_log_file = -1;
416     int pids_file = -1;
417     long len;
418    
419     int *pids_array = NULL;
420     int num_of_pids = 0;
421    
422     // char run_arg[255];
423 azarah 89 char **sandbox_environ;
424 azarah 93 char sandbox_log[SB_PATH_MAX];
425     char sandbox_debug_log[SB_PATH_MAX];
426     char sandbox_dir[SB_PATH_MAX];
427     char sandbox_lib[SB_PATH_MAX];
428     char sandbox_rc[SB_PATH_MAX];
429 ferringb 2 char *sandbox_pids_file;
430 azarah 93 char portage_tmp_dir[SB_PATH_MAX];
431     char var_tmp_dir[SB_PATH_MAX];
432     char tmp_dir[SB_PATH_MAX];
433     char sandbox_write_envvar[SB_BUF_LEN];
434     char sandbox_predict_envvar[SB_BUF_LEN];
435     char pid_string[SB_BUF_LEN];
436 ferringb 2 char **argv_bash = NULL;
437    
438     char *run_str = "-c";
439     char *home_dir = NULL;
440     char *tmp_string = NULL;
441    
442     /* Only print info if called with no arguments .... */
443     if (argc < 2)
444     print_debug = 1;
445    
446     if (print_debug)
447 azarah 30 printf("========================== Gentoo linux path sandbox ===========================\n");
448 ferringb 2
449     /* check if a sandbox is already running */
450     if (NULL != getenv(ENV_SANDBOX_ON)) {
451 azarah 30 fprintf(stderr, "Not launching a new sandbox instance\n");
452     fprintf(stderr, "Another one is already running in this process hierarchy.\n");
453 ferringb 2 exit(1);
454     } else {
455    
456     /* determine the location of all the sandbox support files */
457     if (print_debug)
458     printf("Detection of the support files.\n");
459    
460     /* Generate base sandbox path */
461 azarah 97 snprintf(sandbox_dir, SB_PATH_MAX, "%s/",
462     get_sandbox_path(argv[0]));
463 ferringb 2
464     /* Generate sandbox lib path */
465 azarah 97 snprintf(sandbox_lib, SB_PATH_MAX, "%s",
466     get_sandbox_lib(sandbox_dir));
467 ferringb 2
468     /* Generate sandbox pids-file path */
469     sandbox_pids_file = get_sandbox_pids_file();
470    
471     /* Generate sandbox bashrc path */
472 azarah 97 snprintf(sandbox_rc, SB_PATH_MAX, "%s",
473     get_sandbox_rc(sandbox_dir));
474 ferringb 2
475     /* verify the existance of required files */
476     if (print_debug)
477     printf("Verification of the required files.\n");
478    
479     #ifndef SB_HAVE_64BIT_ARCH
480     if (file_exist(sandbox_lib, 0) <= 0) {
481 azarah 30 fprintf(stderr, "Could not open the sandbox library at '%s'.\n", sandbox_lib);
482 ferringb 2 return -1;
483 azarah 30 }
484 ferringb 2 #endif
485     if (file_exist(sandbox_rc, 0) <= 0) {
486 azarah 30 fprintf(stderr, "Could not open the sandbox rc file at '%s'.\n", sandbox_rc);
487 ferringb 2 return -1;
488     }
489    
490     /* set up the required environment variables */
491     if (print_debug)
492     printf("Setting up the required environment variables.\n");
493    
494     /* Generate sandbox log full path */
495 azarah 97 snprintf(sandbox_log, SB_PATH_MAX, "%s",
496     get_sandbox_log());
497 ferringb 2
498 azarah 97 /* Generate sandbox debug log full path */
499     snprintf(sandbox_debug_log, SB_PATH_MAX, "%s",
500     get_sandbox_debug_log());
501 ferringb 2
502     home_dir = getenv("HOME");
503     if (!home_dir) {
504     home_dir = "/tmp";
505     setenv("HOME", home_dir, 1);
506     }
507    
508 azarah 35 if (NULL == realpath(getenv("PORTAGE_TMPDIR") ? getenv("PORTAGE_TMPDIR")
509     : "/var/tmp/portage",
510     portage_tmp_dir)) {
511     perror(">>> get portage_tmp_dir");
512     exit(1);
513 ferringb 2 }
514 azarah 35 if (NULL == realpath("/var/tmp", var_tmp_dir)) {
515     perror(">>> get var_tmp_dir");
516     exit(1);
517     }
518     if (NULL == realpath("/tmp", tmp_dir)) {
519     perror(">>> get tmp_dir");
520     exit(1);
521     }
522 ferringb 2
523 azarah 91 /* This one should not be child only, as we check above to see
524     * if we are already running (check sandbox_setup_environ).
525     * This needs to be set before calling sandbox_setup_environ(),
526     * else its not set for the child */
527     setenv(ENV_SANDBOX_ON, "1", 0);
528    
529     /* Setup the child environment stuff */
530 azarah 89 get_sandbox_write_envvar(sandbox_write_envvar, home_dir,
531     portage_tmp_dir, var_tmp_dir, tmp_dir);
532     get_sandbox_predict_envvar(sandbox_predict_envvar, home_dir);
533     sandbox_environ = sandbox_setup_environ(sandbox_dir, sandbox_lib,
534     sandbox_rc, sandbox_log, sandbox_debug_log,
535     sandbox_write_envvar, sandbox_predict_envvar);
536     if (NULL == sandbox_environ) {
537     perror(">>> out of memory (environ)");
538     exit(1);
539 azarah 71 }
540 ferringb 2
541     /* if the portage temp dir was present, cd into it */
542     if (NULL != portage_tmp_dir)
543     chdir(portage_tmp_dir);
544    
545 azarah 30 argv_bash = (char **)malloc(6 * sizeof(char *));
546 ferringb 2 argv_bash[0] = strdup("/bin/bash");
547     argv_bash[1] = strdup("-rcfile");
548     argv_bash[2] = strdup(sandbox_rc);
549    
550     if (argc < 2)
551     argv_bash[3] = NULL;
552     else
553     argv_bash[3] = strdup(run_str); /* "-c" */
554    
555 azarah 30 argv_bash[4] = NULL; /* strdup(run_arg); */
556 ferringb 2 argv_bash[5] = NULL;
557    
558     if (argc >= 2) {
559     for (i = 1; i < argc; i++) {
560     if (NULL == argv_bash[4])
561     len = 0;
562     else
563     len = strlen(argv_bash[4]);
564    
565 azarah 89 argv_bash[4] = (char *)realloc(argv_bash[4],
566     (len + strlen(argv[i]) + 2) * sizeof(char));
567 ferringb 2
568     if (0 == len)
569     argv_bash[4][0] = 0;
570     if (1 != i)
571     strcat(argv_bash[4], " ");
572    
573     strcat(argv_bash[4], argv[i]);
574     }
575     }
576    
577     /* set up the required signal handlers */
578     signal(SIGHUP, &stop);
579     signal(SIGINT, &stop);
580     signal(SIGQUIT, &stop);
581     signal(SIGTERM, &stop);
582    
583     /* Load our PID into PIDs file */
584     success = 1;
585     if (file_exist(sandbox_pids_file, 1) < 0) {
586     success = 0;
587     fprintf(stderr, ">>> %s is not a regular file\n", sandbox_pids_file);
588     } else {
589     pids_file = file_open(sandbox_pids_file, "r+", 1, 0664, "portage");
590     if (-1 == pids_file)
591     success = 0;
592     }
593     if (1 == success) {
594     /* Grab still active pids */
595     num_of_pids = load_active_pids(pids_file, &pids_array);
596    
597     /* Zero out file */
598     file_truncate(pids_file);
599    
600     /* Output active pids, and append our pid */
601     for (i = 0; i < num_of_pids + 1; i++) {
602     /* Time for our entry */
603     if (i == num_of_pids)
604     sprintf(pid_string, "%d\n", getpid());
605     else
606     sprintf(pid_string, "%d\n", pids_array[i]);
607    
608 azarah 30 if (write(pids_file, pid_string, strlen(pid_string)) != strlen(pid_string)) {
609 ferringb 2 perror(">>> pids file write");
610     success = 0;
611     break;
612     }
613     }
614     /* Clean pids_array */
615     if (pids_array)
616     free(pids_array);
617     pids_array = NULL;
618     num_of_pids = 0;
619    
620     /* We're done with the pids file */
621     file_close(pids_file);
622     }
623    
624     /* Something went wrong, bail out */
625     if (0 == success) {
626     perror(">>> pids file write");
627     exit(1);
628     }
629    
630     /* STARTING PROTECTED ENVIRONMENT */
631     if (print_debug) {
632     printf("The protected environment has been started.\n");
633 azarah 30 printf("--------------------------------------------------------------------------------\n");
634 ferringb 2 }
635    
636     if (print_debug)
637     printf("Shell being started in forked process.\n");
638    
639     /* Start Bash */
640 azarah 89 if (!spawn_shell(argv_bash, sandbox_environ)) {
641 ferringb 2 if (print_debug)
642     fprintf(stderr, ">>> shell process failed to spawn\n");
643     success = 0;
644     }
645    
646     /* Free bash stuff */
647     for (i = 0; i < 6; i++) {
648     if (argv_bash[i])
649     free(argv_bash[i]);
650     argv_bash[i] = NULL;
651     }
652     if (argv_bash)
653     free(argv_bash);
654     argv_bash = NULL;
655    
656     if (print_debug)
657     printf("Cleaning up sandbox process\n");
658    
659     cleanup();
660    
661     if (print_debug) {
662 azarah 30 printf("========================== Gentoo linux path sandbox ===========================\n");
663 ferringb 2 printf("The protected environment has been shut down.\n");
664     }
665    
666     if (file_exist(sandbox_log, 0)) {
667     sandbox_log_presence = 1;
668     success = 1;
669     if (!print_sandbox_log(sandbox_log))
670     success = 0;
671    
672     #if 0
673     if (!success)
674     exit(1);
675     #endif
676    
677     sandbox_log_file = -1;
678     } else if (print_debug) {
679 azarah 30 printf("--------------------------------------------------------------------------------\n");
680 ferringb 2 }
681    
682 azarah 35 free(sandbox_pids_file);
683    
684 ferringb 2 if ((sandbox_log_presence) || (!success))
685     return 1;
686     else
687     return 0;
688     }
689     }
690    
691 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