diff options
author | 2006-07-09 19:13:57 +0000 | |
---|---|---|
committer | 2006-07-09 19:13:57 +0000 | |
commit | af23d1cbc9351808befde8e61da51ce202eaaa64 (patch) | |
tree | 3aac0dab22ed88d4293bd28021e690ff2daf103e /src | |
parent | Reformat previous added code a bit, and add debug messages (diff) | |
download | sandbox-af23d1cbc9351808befde8e61da51ce202eaaa64.tar.gz sandbox-af23d1cbc9351808befde8e61da51ce202eaaa64.tar.bz2 sandbox-af23d1cbc9351808befde8e61da51ce202eaaa64.zip |
As we are using a symbol map for libsandbox, its no longer needed
to have all the internal functions static, and thus we can break
things out a bit and make the source layout more sane. Start by
moving librcutil to libsbutil, and adding all the defines and
helper functions needed by both libsandbox and sandbox.
Signed-off-by: Martin Schlemmer <azarah@gentoo.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 32 | ||||
-rw-r--r-- | src/canonicalize.c | 2 | ||||
-rw-r--r-- | src/libsandbox.c | 3 | ||||
-rw-r--r-- | src/sandbox.c | 3 | ||||
-rw-r--r-- | src/sandbox.h | 120 | ||||
-rw-r--r-- | src/sandbox_utils.c | 134 |
6 files changed, 15 insertions, 279 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index c5ae5ce..bc551c8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,44 +4,36 @@ lib_LTLIBRARIES = libsandbox.la bin_PROGRAMS = sandbox AM_CPPFLAGS = \ - -DPIC -fPIC -D_REENTRANT \ - -DETCDIR=\"$(sysconfdir)\" \ - -DLIBSANDBOX_PATH=\"$(libdir)\" \ - -DSANDBOX_BASHRC_PATH=\"$(pkgdatadir)\" \ + $(SANDBOX_DEFINES) \ + -DPIC -fPIC -D_REENTRANT \ -I$(top_srcdir) -Wall -INCLUDES = -I$(top_srcdir)/librcutil/include -LOCAL_INCLUDES = $(top_srcdir)/localdecls.h +INCLUDES = \ + -I$(top_srcdir)/libsbutil \ + -I$(top_srcdir)/libsbutil/include # We need -fexceptions here, else we do not catch exceptions # (nptl/tst-cancelx4.c in glibc among others fails for wrapped functions). libsandbox_la_CFLAGS = -fexceptions # Could use the following to libsandbox_la_LIBADD, but then libtool links it # with --whole-archive: -# $(top_builddir)/librcutil/librcutil.la -libsandbox_la_LIBRCOBJS = $(wildcard $(top_builddir)/librcutil/*.lo) +# $(top_builddir)/libsbutil/libsbutil.la +libsandbox_la_LIBSBOBJS = $(wildcard $(top_builddir)/libsbutil/*.lo) libsandbox_la_LIBADD = \ -lc $(LIBDL) \ - $(libsandbox_la_LIBRCOBJS) -# $(top_builddir)/librcutil/.libs/librcutil.a + $(libsandbox_la_LIBSBOBJS) # Do not add -nostdlib or -nostartfiles, as then our constructor # and destructor will not be executed ... libsandbox_la_LDFLAGS = \ -nodefaultlibs \ -Wl,--version-script,libsandbox.map libsandbox_la_SOURCES = \ - libsandbox.c \ - canonicalize.c \ - sandbox_utils.c \ - $(LOCAL_INCLUDES) + libsandbox.c \ + canonicalize.c sandbox_CFLAGS = -DOUTSIDE_LIBSANDBOX -sandbox_LDADD = $(top_builddir)/librcutil/librcutil.la -sandbox_SOURCES = \ - sandbox.c \ - sandbox.h \ - sandbox_utils.c \ - $(LOCAL_INCLUDES) +sandbox_LDADD = $(top_builddir)/libsbutil/libsbutil.la +sandbox_SOURCES = sandbox.c libsandbox.c: libsandbox.map symbols.h diff --git a/src/canonicalize.c b/src/canonicalize.c index 8a5c989..c23ae7c 100644 --- a/src/canonicalize.c +++ b/src/canonicalize.c @@ -34,7 +34,7 @@ #include "config.h" #include "localdecls.h" -#include "sandbox.h" +#include "sbutil.h" #ifndef __set_errno # define __set_errno(val) errno = (val) diff --git a/src/libsandbox.c b/src/libsandbox.c index f40e81c..83042a7 100644 --- a/src/libsandbox.c +++ b/src/libsandbox.c @@ -72,8 +72,7 @@ #undef open #undef open64 -#include "sandbox.h" -#include "rcscripts/rcutil.h" +#include "sbutil.h" #define LOG_VERSION "1.0" #define LOG_STRING "VERSION " LOG_VERSION "\n" diff --git a/src/sandbox.c b/src/sandbox.c index 11c6c2e..f4b9478 100644 --- a/src/sandbox.c +++ b/src/sandbox.c @@ -27,8 +27,7 @@ #include <unistd.h> #include <fcntl.h> -#include "sandbox.h" -#include "rcscripts/rcutil.h" +#include "sbutil.h" struct sandbox_info_t { char sandbox_log[SB_PATH_MAX]; diff --git a/src/sandbox.h b/src/sandbox.h deleted file mode 100644 index a9cd3b4..0000000 --- a/src/sandbox.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2002 Brad House <brad@mainstreetsoftworks.com>, - * Possibly based on code from Geert Bevin, Uwyn, http://www.uwyn.com - * Distributed under the terms of the GNU General Public License, v2 or later - * Author: Brad House <brad@mainstreetsoftworks.com> - * - * $Header$ - */ - -#ifndef __SANDBOX_H__ -#define __SANDBOX_H__ - -#include "localdecls.h" -#include "config.h" -#include "rcscripts/rctypes.h" - -#define SANDBOX_CONF_FILE ETCDIR "/sandbox.conf" -#define SANDBOX_CONFD_DIR ETCDIR "/sandbox.d" - -#define LD_PRELOAD_EQ "LD_PRELOAD=" -#define LD_PRELOAD_FILE "/etc/ld.so.preload" -#define LIB_NAME "libsandbox.so" -#define BASHRC_NAME "sandbox.bashrc" -#define TMPDIR "/tmp" -#define VAR_TMPDIR "/var/tmp" -#define PORTAGE_TMPDIR "/var/tmp/portage" -#define SANDBOX_LOG_LOCATION "/var/log/sandbox" -#define LOG_FILE_PREFIX "/sandbox-" -#define DEBUG_LOG_FILE_PREFIX "/sandbox-debug-" -#define LOG_FILE_EXT ".log" - -#define ENV_LD_PRELOAD "LD_PRELOAD" - -#define ENV_EBUILD "EBUILD" -#define ENV_TMPDIR "TMPDIR" -#define ENV_PORTAGE_TMPDIR "PORTAGE_TMPDIR" - -#define ENV_BASH_ENV "BASH_ENV" - -#define ENV_NOCOLOR "NOCOLOR" - -#define ENV_SANDBOX_VERBOSE "SANDBOX_VERBOSE" -#define ENV_SANDBOX_DEBUG "SANDBOX_DEBUG" - -#define ENV_SANDBOX_LIB "SANDBOX_LIB" -#define ENV_SANDBOX_BASHRC "SANDBOX_BASHRC" -#define ENV_SANDBOX_LOG "SANDBOX_LOG" -#define ENV_SANDBOX_DEBUG_LOG "SANDBOX_DEBUG_LOG" -#define ENV_SANDBOX_WORKDIR "SANDBOX_WORKDIR" - -#define ENV_SANDBOX_DENY "SANDBOX_DENY" -#define ENV_SANDBOX_READ "SANDBOX_READ" -#define ENV_SANDBOX_WRITE "SANDBOX_WRITE" -#define ENV_SANDBOX_PREDICT "SANDBOX_PREDICT" - -#define ENV_SANDBOX_ON "SANDBOX_ON" -#define ENV_SANDBOX_BEEP "SANDBOX_BEEP" - -#define ENV_SANDBOX_PID "SANDBOX_PID" -#define ENV_SANDBOX_ABORT "SANDBOX_ABORT" -#define ENV_SANDBOX_INTRACTV "SANDBOX_INTRACTV" - -#define ENV_SANDBOX_ACTIVE "SANDBOX_ACTIVE" -#define SANDBOX_ACTIVE "armedandready" - -#define DEFAULT_BEEP_COUNT 3 - -#define SB_BUF_LEN 2048 - -/* Gentoo style e* printing macro's */ -#define SB_EINFO(_color, _hilight, _args...) \ - do { \ - int old_errno = errno; \ - if (_color) \ - fprintf(stderr, "\033[32;01m" _hilight "\033[0m" _args); \ - else \ - fprintf(stderr, _hilight _args); \ - errno = old_errno; \ - } while (0) - -#define SB_EWARN(_color, _hilight, _args...) \ - do { \ - int old_errno = errno; \ - if (_color) \ - fprintf(stderr, "\033[33;01m" _hilight "\033[0m" _args); \ - else \ - fprintf(stderr, _hilight _args); \ - errno = old_errno; \ - } while (0) - -#define SB_EERROR(_color, _hilight, _args...) \ - do { \ - int old_errno = errno; \ - if (_color) \ - fprintf(stderr, "\033[31;01m" _hilight "\033[0m" _args); \ - else \ - fprintf(stderr, _hilight _args); \ - errno = old_errno; \ - } while (0) - -void get_sandbox_lib(char *path); -#ifdef OUTSIDE_LIBSANDBOX -void get_sandbox_rc(char *path); -void get_sandbox_log(char *path); -void get_sandbox_debug_log(char *path); -int get_tmp_dir(char *path); -long file_length(int); -#endif /* OUTSIDE_LIBSANDBOX */ -bool is_env_on (const char *); -bool is_env_off (const char *); - -/* glibc modified realpath() function */ -char *erealpath(const char *, char *); -#ifndef OUTSIDE_LIBSANDBOX -char *egetcwd(char *, size_t); -#endif /* !OUTSIDE_LIBSANDBOX */ - -#endif /* __SANDBOX_H__ */ - -// vim:noexpandtab noai:cindent ai diff --git a/src/sandbox_utils.c b/src/sandbox_utils.c deleted file mode 100644 index 0ce60ab..0000000 --- a/src/sandbox_utils.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) 2002 Brad House <brad@mainstreetsoftworks.com> - * Distributed under the terms of the GNU General Public License, v2 or later - * Author: Brad House <brad@mainstreetsoftworks.com> - * Author: Martin Schlemmer <azarah@gentoo.org> - * - * $Header$ - * - */ - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <limits.h> -#include <string.h> -#include <sys/stat.h> -#include <unistd.h> -#include <fcntl.h> -#include <libgen.h> - -#include "config.h" -#include "localdecls.h" - -#include "sandbox.h" - -void get_sandbox_lib(char *path) -{ -#ifdef SB_HAVE_MULTILIB - snprintf(path, SB_PATH_MAX, "%s", LIB_NAME); -#else - snprintf(path, SB_PATH_MAX, "%s/%s", LIBSANDBOX_PATH, LIB_NAME); - if (!rc_file_exists(path)) { - snprintf(path, SB_PATH_MAX, "%s", LIB_NAME); - } -#endif -} - -#ifdef OUTSIDE_LIBSANDBOX - -void get_sandbox_rc(char *path) -{ - snprintf(path, SB_PATH_MAX, "%s/%s", SANDBOX_BASHRC_PATH, BASHRC_NAME); -} - -void get_sandbox_log(char *path) -{ - char *sandbox_log_env = NULL; - - sandbox_log_env = getenv(ENV_SANDBOX_LOG); - - /* THIS CHUNK BREAK THINGS BY DOING THIS: - * SANDBOX_LOG=/tmp/sandbox-app-admin/superadduser-1.0.7-11063.log - */ - if ((NULL != sandbox_log_env) && - (NULL != strchr(sandbox_log_env, '/'))) - sandbox_log_env = NULL; - - snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s", - SANDBOX_LOG_LOCATION, LOG_FILE_PREFIX, - (sandbox_log_env == NULL ? "" : sandbox_log_env), - (sandbox_log_env == NULL ? "" : "-"), - getpid(), LOG_FILE_EXT); -} - -void get_sandbox_debug_log(char *path) -{ - char *sandbox_debug_log_env = NULL; - - sandbox_debug_log_env = getenv(ENV_SANDBOX_DEBUG_LOG); - - /* THIS CHUNK BREAK THINGS BY DOING THIS: - * SANDBOX_DEBUG_LOG=/tmp/sandbox-app-admin/superadduser-1.0.7-11063.log - */ - if ((NULL != sandbox_debug_log_env) && - (NULL != strchr(sandbox_debug_log_env, '/'))) - sandbox_debug_log_env = NULL; - - snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s", - SANDBOX_LOG_LOCATION, DEBUG_LOG_FILE_PREFIX, - (sandbox_debug_log_env == NULL ? "" : sandbox_debug_log_env), - (sandbox_debug_log_env == NULL ? "" : "-"), - getpid(), LOG_FILE_EXT); -} - -int get_tmp_dir(char *path) -{ - if (NULL == realpath(getenv(ENV_TMPDIR) ? getenv(ENV_TMPDIR) - : TMPDIR, - path)) { - if (NULL == realpath(TMPDIR, path)) - return -1; - } - - return 0; -} - -long file_length(int fd) -{ - struct stat st; - int retval; - - retval = fstat(fd, &st); - if (-1 == retval) - return 0; - - return (st.st_size); -} - -#endif /* OUTSIDE_LIBSANDBOX */ - -bool is_env_on (const char *env) -{ - if ((NULL != env) && (NULL != getenv(env)) && - ((0 == strncasecmp(getenv(env), "1", 1)) || - (0 == strncasecmp(getenv(env), "true", 4)) || - (0 == strncasecmp(getenv(env), "yes", 3)))) - return TRUE; - - return FALSE; -} - -bool is_env_off (const char *env) -{ - if ((NULL != env) && (NULL != getenv(env)) && - ((0 == strncasecmp(getenv(env), "0", 1)) || - (0 == strncasecmp(getenv(env), "false", 5)) || - (0 == strncasecmp(getenv(env), "no", 2)))) - return TRUE; - - return FALSE; -} - - -// vim:noexpandtab noai:cindent ai |