| 1 |
/* |
| 2 |
* Copyright (C) 2002 Brad House <brad@mainstreetsoftworks.com>, |
| 3 |
* Possibly based on code from Geert Bevin, Uwyn, http://www.uwyn.com |
| 4 |
* Distributed under the terms of the GNU General Public License, v2 or later |
| 5 |
* Author: Brad House <brad@mainstreetsoftworks.com> |
| 6 |
* |
| 7 |
* $Header$ |
| 8 |
*/ |
| 9 |
|
| 10 |
#ifndef __SANDBOX_H__ |
| 11 |
#define __SANDBOX_H__ |
| 12 |
|
| 13 |
#include "localdecls.h" |
| 14 |
#include "config.h" |
| 15 |
|
| 16 |
/* Uncomment below to use flock instead of fcntl (POSIX way) to lock/unlock files */ |
| 17 |
/* #define USE_FLOCK */ |
| 18 |
|
| 19 |
#define LD_PRELOAD_EQ "LD_PRELOAD=" |
| 20 |
#define LD_PRELOAD_FILE "/etc/ld.so.preload" |
| 21 |
#define LIB_NAME "libsandbox.so" |
| 22 |
#define BASHRC_NAME "sandbox.bashrc" |
| 23 |
#define TMPDIR "/tmp" |
| 24 |
#define VAR_TMPDIR "/var/tmp" |
| 25 |
#define PORTAGE_TMPDIR "/var/tmp/portage" |
| 26 |
#define SANDBOX_LOG_LOCATION "/var/log/sandbox" |
| 27 |
#define LOG_FILE_PREFIX "/sandbox-" |
| 28 |
#define DEBUG_LOG_FILE_PREFIX "/sandbox-debug-" |
| 29 |
#define LOG_FILE_EXT ".log" |
| 30 |
|
| 31 |
#define ENV_LD_PRELOAD "LD_PRELOAD" |
| 32 |
|
| 33 |
#define ENV_EBUILD "EBUILD" |
| 34 |
#define ENV_TMPDIR "TMPDIR" |
| 35 |
#define ENV_PORTAGE_TMPDIR "PORTAGE_TMPDIR" |
| 36 |
|
| 37 |
#define ENV_BASH_ENV "BASH_ENV" |
| 38 |
|
| 39 |
#define ENV_SANDBOX_VERBOSE "SANDBOX_VERBOSE" |
| 40 |
#define ENV_SANDBOX_DEBUG "SANDBOX_DEBUG" |
| 41 |
|
| 42 |
#define ENV_SANDBOX_LIB "SANDBOX_LIB" |
| 43 |
#define ENV_SANDBOX_BASHRC "SANDBOX_BASHRC" |
| 44 |
#define ENV_SANDBOX_LOG "SANDBOX_LOG" |
| 45 |
#define ENV_SANDBOX_DEBUG_LOG "SANDBOX_DEBUG_LOG" |
| 46 |
|
| 47 |
#define ENV_SANDBOX_DENY "SANDBOX_DENY" |
| 48 |
#define ENV_SANDBOX_READ "SANDBOX_READ" |
| 49 |
#define ENV_SANDBOX_WRITE "SANDBOX_WRITE" |
| 50 |
#define ENV_SANDBOX_PREDICT "SANDBOX_PREDICT" |
| 51 |
|
| 52 |
#define ENV_SANDBOX_ON "SANDBOX_ON" |
| 53 |
#define ENV_SANDBOX_BEEP "SANDBOX_BEEP" |
| 54 |
|
| 55 |
#define ENV_SANDBOX_ACTIVE "SANDBOX_ACTIVE" |
| 56 |
#define SANDBOX_ACTIVE "armedandready" |
| 57 |
|
| 58 |
#define DEFAULT_BEEP_COUNT 3 |
| 59 |
|
| 60 |
#define SB_BUF_LEN 2048 |
| 61 |
|
| 62 |
#if !HAVE_DLVSYM |
| 63 |
# define dlvsym(lib, sym, ver) dlsym(lib, sym) |
| 64 |
#endif |
| 65 |
|
| 66 |
/* Gentoo style e* printing macro's */ |
| 67 |
#define EINFO(_color, _hilight, _args...) \ |
| 68 |
do { \ |
| 69 |
int old_errno = errno; \ |
| 70 |
if (_color) \ |
| 71 |
fprintf(stderr, "\033[32;01m" _hilight "\033[0m" _args); \ |
| 72 |
else \ |
| 73 |
fprintf(stderr, _hilight _args); \ |
| 74 |
errno = old_errno; \ |
| 75 |
} while (0) |
| 76 |
|
| 77 |
#define EWARN(_color, _hilight, _args...) \ |
| 78 |
do { \ |
| 79 |
int old_errno = errno; \ |
| 80 |
if (_color) \ |
| 81 |
fprintf(stderr, "\033[33;01m" _hilight "\033[0m" _args); \ |
| 82 |
else \ |
| 83 |
fprintf(stderr, _hilight _args); \ |
| 84 |
errno = old_errno; \ |
| 85 |
} while (0) |
| 86 |
|
| 87 |
#define EERROR(_color, _hilight, _args...) \ |
| 88 |
do { \ |
| 89 |
int old_errno = errno; \ |
| 90 |
if (_color) \ |
| 91 |
fprintf(stderr, "\033[31;01m" _hilight "\033[0m" _args); \ |
| 92 |
else \ |
| 93 |
fprintf(stderr, _hilight _args); \ |
| 94 |
errno = old_errno; \ |
| 95 |
} while (0) |
| 96 |
|
| 97 |
SB_STATIC void get_sandbox_lib(char *path); |
| 98 |
#ifdef OUTSIDE_LIBSANDBOX |
| 99 |
SB_STATIC void get_sandbox_rc(char *path); |
| 100 |
SB_STATIC void get_sandbox_log(char *path); |
| 101 |
SB_STATIC void get_sandbox_debug_log(char *path); |
| 102 |
SB_STATIC int get_tmp_dir(char *path); |
| 103 |
#endif /* OUTSIDE_LIBSANDBOX */ |
| 104 |
SB_STATIC int exists(const char *pathname); |
| 105 |
#ifdef OUTSIDE_LIBSANDBOX |
| 106 |
SB_STATIC int is_file(const char *pathname); |
| 107 |
SB_STATIC int is_dir(const char *pathname, int follow_link); |
| 108 |
SB_STATIC long file_length(int fd); |
| 109 |
#endif /* OUTSIDE_LIBSANDBOX */ |
| 110 |
|
| 111 |
#endif |
| 112 |
|
| 113 |
// vim:noexpandtab noai:cindent ai |