aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2008-11-10 19:55:50 +0000
committerMike Frysinger <vapier@gentoo.org>2008-11-10 19:55:50 +0000
commit1789ad209be18f72d2e42cf69ab10fcbdff17c3b (patch)
tree1aaadc64b62f57846150f3078e15c87833937c30 /libsandbox/wrapper-funcs/openat.c
parentsandbox.bashrc: use proper escape chars in PS1 so bash knows about them (diff)
downloadsandbox-1789ad209be18f72d2e42cf69ab10fcbdff17c3b.tar.gz
sandbox-1789ad209be18f72d2e42cf69ab10fcbdff17c3b.tar.bz2
sandbox-1789ad209be18f72d2e42cf69ab10fcbdff17c3b.zip
libsandbox: initial support for wrapping *at functions #174233
URL: http://bugs.gentoo.org/174233 Signed-off-by: Mike Frysinger <vapier@gentoo.org> Reported-by: Zhixu Liu <zhixu.liu@gmail.com>
Diffstat (limited to 'libsandbox/wrapper-funcs/openat.c')
-rw-r--r--libsandbox/wrapper-funcs/openat.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/libsandbox/wrapper-funcs/openat.c b/libsandbox/wrapper-funcs/openat.c
new file mode 100644
index 0000000..ba97a1f
--- /dev/null
+++ b/libsandbox/wrapper-funcs/openat.c
@@ -0,0 +1,47 @@
+/*
+ * openat() wrapper.
+ *
+ * Copyright 1999-2008 Gentoo Foundation
+ * Licensed under the GPL-2
+ *
+ * Partly Copyright (C) 1998-9 Pancrazio `Ezio' de Mauro <p@demauro.net>,
+ * as some of the InstallWatch code was used.
+ */
+
+#define WRAPPER_ARGS int dirfd, const char *pathname, int flags, ...
+extern int EXTERN_NAME(WRAPPER_ARGS);
+static int (*WRAPPER_TRUE_NAME)(WRAPPER_ARGS) = NULL;
+
+/* Eventually, there is a third parameter: it's mode_t mode */
+int WRAPPER_NAME(WRAPPER_ARGS)
+{
+ va_list ap;
+ int mode = 0;
+ int result = -1;
+ int old_errno = errno;
+ struct stat st;
+
+ if (flags & O_CREAT) {
+ va_start(ap, flags);
+ mode = va_arg(ap, int);
+ va_end(ap);
+ } else {
+ /* XXX: If we're not trying to create, fail normally if
+ * file does not stat */
+ if (-1 == stat(pathname, &st)) {
+ return -1;
+ }
+ }
+ errno = old_errno;
+
+ if FUNCTION_SANDBOX_SAFE_OPEN_INT_AT(dirfd, STRING_NAME, pathname, flags) {
+ check_dlsym(WRAPPER_TRUE_NAME, WRAPPER_SYMNAME,
+ WRAPPER_SYMVER);
+ if (flags & O_CREAT)
+ result = WRAPPER_TRUE_NAME(dirfd, pathname, flags, mode);
+ else
+ result = WRAPPER_TRUE_NAME(dirfd, pathname, flags);
+ }
+
+ return result;
+}