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

Contents of /trunk/src/sandbox.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 263 - (hide annotations) (download) (as text)
Tue Jul 4 14:58:16 2006 UTC (8 years, 3 months ago) by azarah
File MIME type: text/x-csrc
File size: 16139 byte(s)
Add is_env_off().  Also check for true/false. Use is_env_*.

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