aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schlemmer <azarah@gentoo.org>2006-07-05 16:51:12 +0000
committerMartin Schlemmer <azarah@gentoo.org>2006-07-05 16:51:12 +0000
commit415047660cc5c63caaefa6ffd731cee0d704369e (patch)
tree6817be145b0c8b11431d04de81a4c85c3afa22a2 /src
parentRename EINFO, etc to SB_EINFO, etc to not conflict with macros from (diff)
downloadsandbox-415047660cc5c63caaefa6ffd731cee0d704369e.tar.gz
sandbox-415047660cc5c63caaefa6ffd731cee0d704369e.tar.bz2
sandbox-415047660cc5c63caaefa6ffd731cee0d704369e.zip
Use librcutil.
Signed-off-by: Martin Schlemmer <azarah@gentoo.org>
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/sandbox.c17
-rw-r--r--src/sandbox.h17
-rw-r--r--src/sandbox_utils.c69
4 files changed, 23 insertions, 82 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 07e2c37..8e5b01d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,6 +9,7 @@ AM_CPPFLAGS = \
-DSANDBOX_BASHRC_PATH=\"$(pkgdatadir)\" \
-I$(top_srcdir) -Wall
+INCLUDES = -I$(top_srcdir)/librcutil/include
LOCAL_INCLUDES = $(top_srcdir)/localdecls.h
# We need -fexceptions here, else we do not catch exceptions
@@ -27,6 +28,7 @@ libsandbox_la_SOURCES = \
$(LOCAL_INCLUDES)
sandbox_CFLAGS = -DOUTSIDE_LIBSANDBOX
+sandbox_LDADD = $(top_builddir)/librcutil/librcutil.la
sandbox_SOURCES = \
sandbox.c \
sandbox.h \
diff --git a/src/sandbox.c b/src/sandbox.c
index 4685ba8..a376026 100644
--- a/src/sandbox.c
+++ b/src/sandbox.c
@@ -28,6 +28,7 @@
#include <fcntl.h>
#include "sandbox.h"
+#include "rcscripts/rcutil.h"
struct sandbox_info_t {
char sandbox_log[SB_PATH_MAX];
@@ -60,7 +61,7 @@ int sandbox_setup(struct sandbox_info_t *sandbox_info)
}
/* Do not resolve symlinks, etc .. libsandbox will handle that. */
- if (1 != is_dir(VAR_TMPDIR, 1)) {
+ if (1 != rc_is_dir(VAR_TMPDIR, 1)) {
perror("sandbox: Failed to get var_tmp_dir");
return -1;
}
@@ -86,7 +87,7 @@ int sandbox_setup(struct sandbox_info_t *sandbox_info)
/* Generate sandbox log full path */
get_sandbox_log(sandbox_info->sandbox_log);
- if (1 == exists(sandbox_info->sandbox_log)) {
+ if (1 == rc_file_exists(sandbox_info->sandbox_log)) {
if (-1 == unlink(sandbox_info->sandbox_log)) {
perror("sandbox: Could not unlink old log file");
return -1;
@@ -95,7 +96,7 @@ int sandbox_setup(struct sandbox_info_t *sandbox_info)
/* Generate sandbox debug log full path */
get_sandbox_debug_log(sandbox_info->sandbox_debug_log);
- if (1 == exists(sandbox_info->sandbox_debug_log)) {
+ if (1 == rc_file_exists(sandbox_info->sandbox_debug_log)) {
if (-1 == unlink(sandbox_info->sandbox_debug_log)) {
perror("sandbox: Could not unlink old debug log file");
return -1;
@@ -113,7 +114,7 @@ int print_sandbox_log(char *sandbox_log)
long len = 0;
char *buffer = NULL;
- if (1 != is_file(sandbox_log)) {
+ if (1 != rc_is_file(sandbox_log, 0)) {
perror("sandbox: Log file is not a regular file");
return 0;
}
@@ -325,7 +326,7 @@ char **sandbox_setup_environ(struct sandbox_info_t *sandbox_info, bool interacti
} else {
/* FIXME: Should probably free this at some stage - more neatness
* than a real leak that will cause issues. */
- ld_preload_envvar = gstrndup(sandbox_info->sandbox_lib,
+ ld_preload_envvar = rc_strndup(sandbox_info->sandbox_lib,
strlen(sandbox_info->sandbox_lib));
if (NULL == ld_preload_envvar)
return NULL;
@@ -489,12 +490,12 @@ int main(int argc, char **argv)
printf("Verification of the required files.\n");
#ifndef SB_HAVE_MULTILIB
- if (0 >= exists(sandbox_info.sandbox_lib)) {
+ if (0 >= rc_file_exists(sandbox_info.sandbox_lib)) {
perror("sandbox: Could not open the sandbox library");
exit(EXIT_FAILURE);
}
#endif
- if (0 >= exists(sandbox_info.sandbox_rc)) {
+ if (0 >= rc_file_exists(sandbox_info.sandbox_rc)) {
perror("sandbox: Could not open the sandbox rc file");
exit(EXIT_FAILURE);
}
@@ -587,7 +588,7 @@ int main(int argc, char **argv)
printf("The protected environment has been shut down.\n");
}
- if (1 == exists(sandbox_info.sandbox_log)) {
+ if (1 == rc_file_exists(sandbox_info.sandbox_log)) {
sandbox_log_presence = 1;
print_sandbox_log(sandbox_info.sandbox_log);
} else if (print_debug) {
diff --git a/src/sandbox.h b/src/sandbox.h
index f446e05..f21efe5 100644
--- a/src/sandbox.h
+++ b/src/sandbox.h
@@ -12,6 +12,7 @@
#include "localdecls.h"
#include "config.h"
+#include "rcscripts/rctypes.h"
#define LD_PRELOAD_EQ "LD_PRELOAD="
#define LD_PRELOAD_FILE "/etc/ld.so.preload"
@@ -93,37 +94,29 @@
errno = old_errno; \
} while (0)
-typedef enum {
- false,
- true
-} bool;
-
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);
-#endif /* OUTSIDE_LIBSANDBOX */
-int exists(const char *pathname);
-#ifdef OUTSIDE_LIBSANDBOX
-int is_file(const char *pathname);
-int is_dir(const char *pathname, int follow_link);
-long file_length(int fd);
+long file_length(int);
#endif /* OUTSIDE_LIBSANDBOX */
bool is_env_on (const char *);
bool is_env_off (const char *);
+#ifndef OUTSIDE_LIBSANDBOX
/* Compat functions for GNU extensions */
char *gstrndup (const char *str, size_t size);
/* Same as basename(3), but do not modify path */
char *gbasename (const char *path);
+#endif /* !OUTSIDE_LIBSANDBOX */
/* glibc modified realpath() function */
char *erealpath(const char *, char *);
#ifndef OUTSIDE_LIBSANDBOX
char *egetcwd(char *, size_t);
-#endif
+#endif /* !OUTSIDE_LIBSANDBOX */
#endif /* __SANDBOX_H__ */
diff --git a/src/sandbox_utils.c b/src/sandbox_utils.c
index dccd2a3..070c2de 100644
--- a/src/sandbox_utils.c
+++ b/src/sandbox_utils.c
@@ -94,64 +94,6 @@ int get_tmp_dir(char *path)
return 0;
}
-#endif /* OUTSIDE_LIBSANDBOX */
-
-int exists(const char *pathname)
-{
- struct stat buf;
- int retval;
-
- if ((NULL == pathname) || (0 == strlen(pathname)))
- return 0;
-
- retval = lstat(pathname, &buf);
- if (-1 != retval)
- return 1;
- /* Some or other error occurred */
- if (ENOENT != errno)
- return -1;
-
- return 0;
-}
-
-#ifdef OUTSIDE_LIBSANDBOX
-
-int is_file(const char *pathname)
-{
- struct stat buf;
- int retval;
-
- if ((NULL == pathname) || (0 == strlen(pathname)))
- return 0;
-
- retval = lstat(pathname, &buf);
- if ((-1 != retval) && (S_ISREG(buf.st_mode)))
- return 1;
- /* Some or other error occurred */
- if ((-1 == retval) && (ENOENT != errno))
- return -1;
-
- return 0;
-}
-
-int is_dir(const char *pathname, int follow_link)
-{
- struct stat buf;
- int retval;
-
- if ((NULL == pathname) || (0 == strlen(pathname)))
- return 0;
-
- retval = follow_link ? stat(pathname, &buf) : lstat(pathname, &buf);
- if ((-1 != retval) && (S_ISDIR(buf.st_mode)))
- return 1;
- /* Some or other error occurred */
- if ((-1 == retval) && (ENOENT != errno))
- return -1;
-
- return 0;
-}
-
long file_length(int fd)
{
struct stat st;
@@ -172,9 +114,9 @@ bool is_env_on (const char *env)
((0 == strncasecmp(getenv(env), "1", 1)) ||
(0 == strncasecmp(getenv(env), "true", 4)) ||
(0 == strncasecmp(getenv(env), "yes", 3))))
- return true;
+ return TRUE;
- return false;
+ return FALSE;
}
bool is_env_off (const char *env)
@@ -183,11 +125,13 @@ bool is_env_off (const char *env)
((0 == strncasecmp(getenv(env), "0", 1)) ||
(0 == strncasecmp(getenv(env), "false", 5)) ||
(0 == strncasecmp(getenv(env), "no", 2))))
- return true;
+ return TRUE;
- return false;
+ return FALSE;
}
+#ifndef OUTSIDE_LIBSANDBOX
+
char * gstrndup (const char *str, size_t size)
{
char *new_str = NULL;
@@ -222,5 +166,6 @@ gbasename (const char *path)
return new_path ? new_path + 1 : (char *) path;
}
+#endif /* !OUTSIDE_LIBSANDBOX */
// vim:noexpandtab noai:cindent ai