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

Diff of /trunk/src/sandbox.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 279 Revision 280
26#include <signal.h> 26#include <signal.h>
27#include <unistd.h> 27#include <unistd.h>
28#include <fcntl.h> 28#include <fcntl.h>
29 29
30#include "sandbox.h" 30#include "sandbox.h"
31#include "rcscripts/rcutil.h"
31 32
32struct sandbox_info_t { 33struct sandbox_info_t {
33 char sandbox_log[SB_PATH_MAX]; 34 char sandbox_log[SB_PATH_MAX];
34 char sandbox_debug_log[SB_PATH_MAX]; 35 char sandbox_debug_log[SB_PATH_MAX];
35 char sandbox_lib[SB_PATH_MAX]; 36 char sandbox_lib[SB_PATH_MAX];
58 return -1; 59 return -1;
59 } 60 }
60 } 61 }
61 62
62 /* Do not resolve symlinks, etc .. libsandbox will handle that. */ 63 /* Do not resolve symlinks, etc .. libsandbox will handle that. */
63 if (1 != is_dir(VAR_TMPDIR, 1)) { 64 if (1 != rc_is_dir(VAR_TMPDIR, 1)) {
64 perror("sandbox: Failed to get var_tmp_dir"); 65 perror("sandbox: Failed to get var_tmp_dir");
65 return -1; 66 return -1;
66 } 67 }
67 snprintf(sandbox_info->var_tmp_dir, SB_PATH_MAX, "%s", VAR_TMPDIR); 68 snprintf(sandbox_info->var_tmp_dir, SB_PATH_MAX, "%s", VAR_TMPDIR);
68 69
84 /* Generate sandbox bashrc path */ 85 /* Generate sandbox bashrc path */
85 get_sandbox_rc(sandbox_info->sandbox_rc); 86 get_sandbox_rc(sandbox_info->sandbox_rc);
86 87
87 /* Generate sandbox log full path */ 88 /* Generate sandbox log full path */
88 get_sandbox_log(sandbox_info->sandbox_log); 89 get_sandbox_log(sandbox_info->sandbox_log);
89 if (1 == exists(sandbox_info->sandbox_log)) { 90 if (1 == rc_file_exists(sandbox_info->sandbox_log)) {
90 if (-1 == unlink(sandbox_info->sandbox_log)) { 91 if (-1 == unlink(sandbox_info->sandbox_log)) {
91 perror("sandbox: Could not unlink old log file"); 92 perror("sandbox: Could not unlink old log file");
92 return -1; 93 return -1;
93 } 94 }
94 } 95 }
95 96
96 /* Generate sandbox debug log full path */ 97 /* Generate sandbox debug log full path */
97 get_sandbox_debug_log(sandbox_info->sandbox_debug_log); 98 get_sandbox_debug_log(sandbox_info->sandbox_debug_log);
98 if (1 == exists(sandbox_info->sandbox_debug_log)) { 99 if (1 == rc_file_exists(sandbox_info->sandbox_debug_log)) {
99 if (-1 == unlink(sandbox_info->sandbox_debug_log)) { 100 if (-1 == unlink(sandbox_info->sandbox_debug_log)) {
100 perror("sandbox: Could not unlink old debug log file"); 101 perror("sandbox: Could not unlink old debug log file");
101 return -1; 102 return -1;
102 } 103 }
103 } 104 }
111 char *beep_count_env = NULL; 112 char *beep_count_env = NULL;
112 int i, color, beep_count = 0; 113 int i, color, beep_count = 0;
113 long len = 0; 114 long len = 0;
114 char *buffer = NULL; 115 char *buffer = NULL;
115 116
116 if (1 != is_file(sandbox_log)) { 117 if (1 != rc_is_file(sandbox_log, 0)) {
117 perror("sandbox: Log file is not a regular file"); 118 perror("sandbox: Log file is not a regular file");
118 return 0; 119 return 0;
119 } 120 }
120 121
121 sandbox_log_file = open(sandbox_log, O_RDONLY); 122 sandbox_log_file = open(sandbox_log, O_RDONLY);
323 strlen(sandbox_info->sandbox_lib) + 2, "%s %s", 324 strlen(sandbox_info->sandbox_lib) + 2, "%s %s",
324 sandbox_info->sandbox_lib, orig_ld_preload_envvar); 325 sandbox_info->sandbox_lib, orig_ld_preload_envvar);
325 } else { 326 } else {
326 /* FIXME: Should probably free this at some stage - more neatness 327 /* FIXME: Should probably free this at some stage - more neatness
327 * than a real leak that will cause issues. */ 328 * than a real leak that will cause issues. */
328 ld_preload_envvar = gstrndup(sandbox_info->sandbox_lib, 329 ld_preload_envvar = rc_strndup(sandbox_info->sandbox_lib,
329 strlen(sandbox_info->sandbox_lib)); 330 strlen(sandbox_info->sandbox_lib));
330 if (NULL == ld_preload_envvar) 331 if (NULL == ld_preload_envvar)
331 return NULL; 332 return NULL;
332 } 333 }
333 /* Do not unset this, as strange things might happen */ 334 /* Do not unset this, as strange things might happen */
487 /* verify the existance of required files */ 488 /* verify the existance of required files */
488 if (print_debug) 489 if (print_debug)
489 printf("Verification of the required files.\n"); 490 printf("Verification of the required files.\n");
490 491
491#ifndef SB_HAVE_MULTILIB 492#ifndef SB_HAVE_MULTILIB
492 if (0 >= exists(sandbox_info.sandbox_lib)) { 493 if (0 >= rc_file_exists(sandbox_info.sandbox_lib)) {
493 perror("sandbox: Could not open the sandbox library"); 494 perror("sandbox: Could not open the sandbox library");
494 exit(EXIT_FAILURE); 495 exit(EXIT_FAILURE);
495 } 496 }
496#endif 497#endif
497 if (0 >= exists(sandbox_info.sandbox_rc)) { 498 if (0 >= rc_file_exists(sandbox_info.sandbox_rc)) {
498 perror("sandbox: Could not open the sandbox rc file"); 499 perror("sandbox: Could not open the sandbox rc file");
499 exit(EXIT_FAILURE); 500 exit(EXIT_FAILURE);
500 } 501 }
501 502
502 /* set up the required environment variables */ 503 /* set up the required environment variables */
585 if (print_debug) { 586 if (print_debug) {
586 printf("========================== Gentoo linux path sandbox ===========================\n"); 587 printf("========================== Gentoo linux path sandbox ===========================\n");
587 printf("The protected environment has been shut down.\n"); 588 printf("The protected environment has been shut down.\n");
588 } 589 }
589 590
590 if (1 == exists(sandbox_info.sandbox_log)) { 591 if (1 == rc_file_exists(sandbox_info.sandbox_log)) {
591 sandbox_log_presence = 1; 592 sandbox_log_presence = 1;
592 print_sandbox_log(sandbox_info.sandbox_log); 593 print_sandbox_log(sandbox_info.sandbox_log);
593 } else if (print_debug) { 594 } else if (print_debug) {
594 printf("--------------------------------------------------------------------------------\n"); 595 printf("--------------------------------------------------------------------------------\n");
595 } 596 }

Legend:
Removed from v.279  
changed lines
  Added in v.280

  ViewVC Help
Powered by ViewVC 1.1.20