/[path-sandbox]/trunk/libsbutil/sbutil.h
Gentoo

Contents of /trunk/libsbutil/sbutil.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 370 - (show annotations) (download) (as text)
Sun Nov 9 10:29:58 2008 UTC (6 years, 1 month ago) by vapier
File MIME type: text/x-chdr
File size: 3691 byte(s)
consolidate all random system includes into headers.h
1 /*
2 * sbutil.h
3 *
4 * Util defines.
5 *
6 * Copyright 1999-2008 Gentoo Foundation
7 * Licensed under the GPL-2
8 *
9 * Some parts might have Copyright:
10 * Copyright (C) 2002 Brad House <brad@mainstreetsoftworks.com>
11 */
12
13 #ifndef __SBUTIL_H__
14 #define __SBUTIL_H__
15
16 #include "headers.h"
17 #include "include/rcscripts/rcutil.h"
18
19 #define SANDBOX_CONF_FILE ETCDIR "/sandbox.conf"
20 #define SANDBOX_CONFD_DIR ETCDIR "/sandbox.d"
21
22 #define LD_PRELOAD_EQ "LD_PRELOAD="
23 #define LD_PRELOAD_FILE "/etc/ld.so.preload"
24 #define LIB_NAME "libsandbox.so"
25 #define BASHRC_NAME "sandbox.bashrc"
26 #define TMPDIR "/tmp"
27 #define VAR_TMPDIR "/var/tmp"
28 #define PORTAGE_TMPDIR "/var/tmp/portage"
29 #define SANDBOX_LOG_LOCATION "/var/log/sandbox"
30 #define LOG_FILE_PREFIX "/sandbox-"
31 #define DEBUG_LOG_FILE_PREFIX "/sandbox-debug-"
32 #define LOG_FILE_EXT ".log"
33
34 #define ENV_LD_PRELOAD "LD_PRELOAD"
35
36 #define ENV_EBUILD "EBUILD"
37 #define ENV_TMPDIR "TMPDIR"
38 #define ENV_PORTAGE_TMPDIR "PORTAGE_TMPDIR"
39
40 #define ENV_BASH_ENV "BASH_ENV"
41
42 #define ENV_NOCOLOR "NOCOLOR"
43
44 #define ENV_SANDBOX_VERBOSE "SANDBOX_VERBOSE"
45 #define ENV_SANDBOX_DEBUG "SANDBOX_DEBUG"
46
47 #define ENV_SANDBOX_LIB "SANDBOX_LIB"
48 #define ENV_SANDBOX_BASHRC "SANDBOX_BASHRC"
49 #define ENV_SANDBOX_LOG "SANDBOX_LOG"
50 #define ENV_SANDBOX_DEBUG_LOG "SANDBOX_DEBUG_LOG"
51 #define ENV_SANDBOX_WORKDIR "SANDBOX_WORKDIR"
52
53 #define ENV_SANDBOX_DENY "SANDBOX_DENY"
54 #define ENV_SANDBOX_READ "SANDBOX_READ"
55 #define ENV_SANDBOX_WRITE "SANDBOX_WRITE"
56 #define ENV_SANDBOX_PREDICT "SANDBOX_PREDICT"
57
58 #define ENV_SANDBOX_ON "SANDBOX_ON"
59 #define ENV_SANDBOX_BEEP "SANDBOX_BEEP"
60
61 #define ENV_SANDBOX_PID "SANDBOX_PID"
62 #define ENV_SANDBOX_ABORT "SANDBOX_ABORT"
63 #define ENV_SANDBOX_INTRACTV "SANDBOX_INTRACTV"
64
65 #define ENV_SANDBOX_ACTIVE "SANDBOX_ACTIVE"
66 #define SANDBOX_ACTIVE "armedandready"
67
68 #define DEFAULT_BEEP_COUNT 3
69
70 #define SB_BUF_LEN 2048
71
72 /* Gentoo style e* printing macro's */
73 #define SB_EINFO(_color, _hilight, _args...) \
74 do { \
75 int old_errno = errno; \
76 if (_color) \
77 fprintf(stderr, "\033[32;01m" _hilight "\033[0m" _args); \
78 else \
79 fprintf(stderr, _hilight _args); \
80 errno = old_errno; \
81 } while (0)
82
83 #define SB_EWARN(_color, _hilight, _args...) \
84 do { \
85 int old_errno = errno; \
86 if (_color) \
87 fprintf(stderr, "\033[33;01m" _hilight "\033[0m" _args); \
88 else \
89 fprintf(stderr, _hilight _args); \
90 errno = old_errno; \
91 } while (0)
92
93 #define SB_EERROR(_color, _hilight, _args...) \
94 do { \
95 int old_errno = errno; \
96 if (_color) \
97 fprintf(stderr, "\033[31;01m" _hilight "\033[0m" _args); \
98 else \
99 fprintf(stderr, _hilight _args); \
100 errno = old_errno; \
101 } while (0)
102
103 void get_sandbox_lib(char *path);
104 void get_sandbox_rc(char *path);
105 void get_sandbox_log(char *path);
106 void get_sandbox_debug_log(char *path);
107 int get_tmp_dir(char *path);
108 bool is_env_on (const char *);
109 bool is_env_off (const char *);
110
111 /* libsandbox need to use a wrapper for open */
112 void sb_set_open(void *new_open);
113 /* Convenience functions to reliably open, read and write to a file */
114 int sb_open(const char *path, int flags, mode_t mode);
115 size_t sb_read(int fd, void *buf, size_t count);
116 size_t sb_write(int fd, const void *buf, size_t count);
117 int sb_close(int fd);
118
119 /* Macro for sb_read() to goto an label on error */
120 #define SB_WRITE(_fd, _buf, _count, _error) \
121 do { \
122 size_t _n; \
123 _n = sb_write(_fd, _buf, _count); \
124 if (-1 == _n) \
125 goto _error; \
126 } while (0)
127
128 #endif /* __SBUTIL_H__ */

  ViewVC Help
Powered by ViewVC 1.1.20