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

Contents of /trunk/src/sandbox.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 282 - (hide annotations) (download) (as text)
Thu Jul 6 07:46:12 2006 UTC (8 years, 1 month ago) by azarah
File MIME type: text/x-csrc
File size: 17085 byte(s)
Updates for changes to librcutil.

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