| 1 |
/*
|
| 2 |
* sbutil.h
|
| 3 |
*
|
| 4 |
* Util defines.
|
| 5 |
*
|
| 6 |
* Copyright 1999-2006 Gentoo Foundation
|
| 7 |
*
|
| 8 |
*
|
| 9 |
* This program is free software; you can redistribute it and/or modify it
|
| 10 |
* under the terms of the GNU General Public License as published by the
|
| 11 |
* Free Software Foundation version 2 of the License.
|
| 12 |
*
|
| 13 |
* This program is distributed in the hope that it will be useful, but
|
| 14 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 16 |
* General Public License for more details.
|
| 17 |
*
|
| 18 |
* You should have received a copy of the GNU General Public License along
|
| 19 |
* with this program; if not, write to the Free Software Foundation, Inc.,
|
| 20 |
* 675 Mass Ave, Cambridge, MA 02139, USA.
|
| 21 |
*
|
| 22 |
* Some parts might have Copyright:
|
| 23 |
*
|
| 24 |
* Copyright (C) 2002 Brad House <brad@mainstreetsoftworks.com>
|
| 25 |
*
|
| 26 |
* $Header$
|
| 27 |
*/
|
| 28 |
|
| 29 |
#ifndef __SBUTIL_H__
|
| 30 |
#define __SBUTIL_H__
|
| 31 |
|
| 32 |
#include <limits.h>
|
| 33 |
|
| 34 |
#include "config.h"
|
| 35 |
#include "localdecls.h"
|
| 36 |
#include "include/rcscripts/rcutil.h"
|
| 37 |
|
| 38 |
#define SANDBOX_CONF_FILE ETCDIR "/sandbox.conf"
|
| 39 |
#define SANDBOX_CONFD_DIR ETCDIR "/sandbox.d"
|
| 40 |
|
| 41 |
#define LD_PRELOAD_EQ "LD_PRELOAD="
|
| 42 |
#define LD_PRELOAD_FILE "/etc/ld.so.preload"
|
| 43 |
#define LIB_NAME "libsandbox.so"
|
| 44 |
#define BASHRC_NAME "sandbox.bashrc"
|
| 45 |
#define TMPDIR "/tmp"
|
| 46 |
#define VAR_TMPDIR "/var/tmp"
|
| 47 |
#define PORTAGE_TMPDIR "/var/tmp/portage"
|
| 48 |
#define SANDBOX_LOG_LOCATION "/var/log/sandbox"
|
| 49 |
#define LOG_FILE_PREFIX "/sandbox-"
|
| 50 |
#define DEBUG_LOG_FILE_PREFIX "/sandbox-debug-"
|
| 51 |
#define LOG_FILE_EXT ".log"
|
| 52 |
|
| 53 |
#define ENV_LD_PRELOAD "LD_PRELOAD"
|
| 54 |
|
| 55 |
#define ENV_EBUILD "EBUILD"
|
| 56 |
#define ENV_TMPDIR "TMPDIR"
|
| 57 |
#define ENV_PORTAGE_TMPDIR "PORTAGE_TMPDIR"
|
| 58 |
|
| 59 |
#define ENV_BASH_ENV "BASH_ENV"
|
| 60 |
|
| 61 |
#define ENV_NOCOLOR "NOCOLOR"
|
| 62 |
|
| 63 |
#define ENV_SANDBOX_VERBOSE "SANDBOX_VERBOSE"
|
| 64 |
#define ENV_SANDBOX_DEBUG "SANDBOX_DEBUG"
|
| 65 |
|
| 66 |
#define ENV_SANDBOX_LIB "SANDBOX_LIB"
|
| 67 |
#define ENV_SANDBOX_BASHRC "SANDBOX_BASHRC"
|
| 68 |
#define ENV_SANDBOX_LOG "SANDBOX_LOG"
|
| 69 |
#define ENV_SANDBOX_DEBUG_LOG "SANDBOX_DEBUG_LOG"
|
| 70 |
#define ENV_SANDBOX_WORKDIR "SANDBOX_WORKDIR"
|
| 71 |
|
| 72 |
#define ENV_SANDBOX_DENY "SANDBOX_DENY"
|
| 73 |
#define ENV_SANDBOX_READ "SANDBOX_READ"
|
| 74 |
#define ENV_SANDBOX_WRITE "SANDBOX_WRITE"
|
| 75 |
#define ENV_SANDBOX_PREDICT "SANDBOX_PREDICT"
|
| 76 |
|
| 77 |
#define ENV_SANDBOX_ON "SANDBOX_ON"
|
| 78 |
#define ENV_SANDBOX_BEEP "SANDBOX_BEEP"
|
| 79 |
|
| 80 |
#define ENV_SANDBOX_PID "SANDBOX_PID"
|
| 81 |
#define ENV_SANDBOX_ABORT "SANDBOX_ABORT"
|
| 82 |
#define ENV_SANDBOX_INTRACTV "SANDBOX_INTRACTV"
|
| 83 |
|
| 84 |
#define ENV_SANDBOX_ACTIVE "SANDBOX_ACTIVE"
|
| 85 |
#define SANDBOX_ACTIVE "armedandready"
|
| 86 |
|
| 87 |
#define DEFAULT_BEEP_COUNT 3
|
| 88 |
|
| 89 |
#define SB_BUF_LEN 2048
|
| 90 |
|
| 91 |
/* Gentoo style e* printing macro's */
|
| 92 |
#define SB_EINFO(_color, _hilight, _args...) \
|
| 93 |
do { \
|
| 94 |
int old_errno = errno; \
|
| 95 |
if (_color) \
|
| 96 |
fprintf(stderr, "\033[32;01m" _hilight "\033[0m" _args); \
|
| 97 |
else \
|
| 98 |
fprintf(stderr, _hilight _args); \
|
| 99 |
errno = old_errno; \
|
| 100 |
} while (0)
|
| 101 |
|
| 102 |
#define SB_EWARN(_color, _hilight, _args...) \
|
| 103 |
do { \
|
| 104 |
int old_errno = errno; \
|
| 105 |
if (_color) \
|
| 106 |
fprintf(stderr, "\033[33;01m" _hilight "\033[0m" _args); \
|
| 107 |
else \
|
| 108 |
fprintf(stderr, _hilight _args); \
|
| 109 |
errno = old_errno; \
|
| 110 |
} while (0)
|
| 111 |
|
| 112 |
#define SB_EERROR(_color, _hilight, _args...) \
|
| 113 |
do { \
|
| 114 |
int old_errno = errno; \
|
| 115 |
if (_color) \
|
| 116 |
fprintf(stderr, "\033[31;01m" _hilight "\033[0m" _args); \
|
| 117 |
else \
|
| 118 |
fprintf(stderr, _hilight _args); \
|
| 119 |
errno = old_errno; \
|
| 120 |
} while (0)
|
| 121 |
|
| 122 |
void get_sandbox_lib(char *path);
|
| 123 |
void get_sandbox_rc(char *path);
|
| 124 |
void get_sandbox_log(char *path);
|
| 125 |
void get_sandbox_debug_log(char *path);
|
| 126 |
int get_tmp_dir(char *path);
|
| 127 |
bool is_env_on (const char *);
|
| 128 |
bool is_env_off (const char *);
|
| 129 |
|
| 130 |
/* libsandbox need to use a wrapper for open */
|
| 131 |
void sb_set_open(void *new_open);
|
| 132 |
/* Convenience functions to reliably open, read and write to a file */
|
| 133 |
int sb_open(const char *path, int flags, mode_t mode);
|
| 134 |
size_t sb_read(int fd, void *buf, size_t count);
|
| 135 |
size_t sb_write(int fd, const void *buf, size_t count);
|
| 136 |
int sb_close(int fd);
|
| 137 |
|
| 138 |
/* Macro for sb_read() to goto an label on error */
|
| 139 |
#define SB_WRITE(_fd, _buf, _count, _error) \
|
| 140 |
do { \
|
| 141 |
size_t _n; \
|
| 142 |
_n = sb_write(_fd, _buf, _count); \
|
| 143 |
if (-1 == _n) \
|
| 144 |
goto _error; \
|
| 145 |
} while (0)
|
| 146 |
|
| 147 |
#endif /* __SBUTIL_H__ */
|