diff options
Diffstat (limited to 'libsbutil/sbutil.h')
-rw-r--r-- | libsbutil/sbutil.h | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/libsbutil/sbutil.h b/libsbutil/sbutil.h index 66c6f73..6d284f1 100644 --- a/libsbutil/sbutil.h +++ b/libsbutil/sbutil.h @@ -54,8 +54,11 @@ #define ENV_SANDBOX_WRITE "SANDBOX_WRITE" #define ENV_SANDBOX_PREDICT "SANDBOX_PREDICT" +#define ENV_SANDBOX_METHOD "SANDBOX_METHOD" #define ENV_SANDBOX_ON "SANDBOX_ON" +#define ENV_SANDBOX_INTRACTV "SANDBOX_INTRACTV" + #define ENV_SANDBOX_ACTIVE "SANDBOX_ACTIVE" #define SANDBOX_ACTIVE "armedandready" @@ -84,12 +87,20 @@ static inline bool is_env_var(const char *env, const char *var, size_t vlen) return !strncmp(env, var, vlen) && env[vlen] == '='; } +typedef enum sandbox_method_t { + SANDBOX_METHOD_ANY = 0, + SANDBOX_METHOD_PRELOAD, +} sandbox_method_t; +sandbox_method_t parse_sandbox_method(const char *); +const char *str_sandbox_method(sandbox_method_t); + /* proc helpers */ extern const char sb_fd_dir[]; #define sb_get_fd_dir() sb_fd_dir const char *sb_get_cmdline(pid_t pid); /* libsandbox need to use a wrapper for open */ +attribute_hidden extern int (*sbio_faccessat)(int, const char *, int, int); attribute_hidden extern int (*sbio_open)(const char *, int, mode_t); attribute_hidden extern FILE *(*sbio_popen)(const char *, const char *); extern const char *sbio_message_path; @@ -101,6 +112,7 @@ size_t sb_write(int fd, const void *buf, size_t count); int sb_close(int fd); void sb_close_all_fds(void); int sb_copy_file_to_fd(const char *file, int ofd); +int sb_exists(int dirfd, const char *pathname, int flags); /* Reliable output */ __printf(1, 2) void sb_printf(const char *format, ...); @@ -130,7 +142,14 @@ void sb_maybe_gdb(void); #define sb_fprintf(fp, ...) sb_fdprintf(fileno(fp), __VA_ARGS__) #define sb_vfprintf(fp, ...) sb_vfdprintf(fileno(fp), __VA_ARGS__) -/* Memory functions */ +/* + * Memory functions. + * + * NB: These are wrappers around libsbutil functions that build off memory calls that we + * implement directly (see libsandbox/memory.c). Do not add any helpers here that cannot + * be mirrored in libsandbox as attempts to pass memory between the two allocators will + * lead to corruption & crashes. + */ void *__xcalloc(size_t nmemb, size_t size, const char *file, const char *func, size_t line); void *__xmalloc(size_t size, const char *file, const char *func, size_t line); void *__xzalloc(size_t size /*, const char *file, const char *func, size_t line */); @@ -145,11 +164,23 @@ char *__xstrndup(const char *str, size_t size, const char *file, const char *fun #define xstrndup(_str, _size) __xstrndup(_str, _size, __FILE__, __func__, __LINE__) #define xalloc_die() __sb_ebort(__FILE__, __func__, __LINE__, "out of memory") +/* string helpers */ +#define streq(s1, s2) (strcmp(s1, s2) == 0) + /* errno helpers */ #define save_errno() int old_errno = errno; #define restore_errno() errno = old_errno; #define saved_errno old_errno +#define RETRY_EINTR(call) \ +({ \ + long result; \ + do { \ + result = (call); \ + } while (result == -1 && errno == EINTR); \ + result; \ +}) + #include "gnulib/canonicalize.h" #endif /* __SBUTIL_H__ */ |