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

Contents of /trunk/sandbox.c

Parent Directory Parent Directory | Revision Log Revision Log


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