aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2009-02-18 01:52:09 -0500
committerMike Frysinger <vapier@gentoo.org>2009-02-18 02:31:50 -0500
commit4141146ff8cf41a6a3ccd7a4580d0814698429e9 (patch)
tree365bcd45c669f9528ef5524038521479f1e565ab /libsandbox/wrapper-funcs
parentlibsandbox: convert internal getcwd func to sb_unwrapped_foo style (diff)
downloadsandbox-4141146ff8cf41a6a3ccd7a4580d0814698429e9.tar.gz
sandbox-4141146ff8cf41a6a3ccd7a4580d0814698429e9.tar.bz2
sandbox-4141146ff8cf41a6a3ccd7a4580d0814698429e9.zip
libsandbox: convert internal open func to sb_unwrapped_foo style
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'libsandbox/wrapper-funcs')
-rw-r--r--libsandbox/wrapper-funcs/open.c5
-rw-r--r--libsandbox/wrapper-funcs/openat.c56
2 files changed, 39 insertions, 22 deletions
diff --git a/libsandbox/wrapper-funcs/open.c b/libsandbox/wrapper-funcs/open.c
index ef649ca..fd23f31 100644
--- a/libsandbox/wrapper-funcs/open.c
+++ b/libsandbox/wrapper-funcs/open.c
@@ -5,7 +5,10 @@
* Licensed under the GPL-2
*/
-#define WRAPPER_ARGS_PROTO const char *pathname, int flags, ...
+#define _WRAPPER_ARGS_PROTO const char *pathname, int flags
+#define WRAPPER_ARGS_PROTO _WRAPPER_ARGS_PROTO, ...
+#define WRAPPER_ARGS_PROTO_FULL _WRAPPER_ARGS_PROTO, mode_t mode
#define WRAPPER_ARGS pathname, flags
+#define WRAPPER_ARGS_FULL WRAPPER_ARGS, mode
#define WRAPPER_SAFE() FUNCTION_SANDBOX_SAFE_OPEN_INT(pathname, flags)
#include "openat.c"
diff --git a/libsandbox/wrapper-funcs/openat.c b/libsandbox/wrapper-funcs/openat.c
index 3df904f..d8edf13 100644
--- a/libsandbox/wrapper-funcs/openat.c
+++ b/libsandbox/wrapper-funcs/openat.c
@@ -6,30 +6,37 @@
*/
#ifndef WRAPPER_ARGS_PROTO /* let open() use us */
-# define WRAPPER_ARGS_PROTO int dirfd, const char *pathname, int flags, ...
+# define _WRAPPER_ARGS_PROTO int dirfd, const char *pathname, int flags
+# define WRAPPER_ARGS_PROTO _WRAPPER_ARGS_PROTO, ...
+# define WRAPPER_ARGS_PROTO_FULL _WRAPPER_ARGS_PROTO, mode_t mode
# define WRAPPER_ARGS dirfd, pathname, flags
+# define WRAPPER_ARGS_FULL WRAPPER_ARGS, mode
# define WRAPPER_SAFE() FUNCTION_SANDBOX_SAFE_OPEN_INT_AT(dirfd, pathname, flags)
# define USE_AT 1
#else
# define USE_AT 0
#endif
+#define WRAPPER_RET_TYPE int
+#define WRAPPER_RET_DEFAULT -1
-extern int EXTERN_NAME(WRAPPER_ARGS_PROTO);
-static int (*WRAPPER_TRUE_NAME)(WRAPPER_ARGS_PROTO) = NULL;
+extern WRAPPER_RET_TYPE EXTERN_NAME(WRAPPER_ARGS_PROTO);
+static WRAPPER_RET_TYPE (*WRAPPER_TRUE_NAME)(WRAPPER_ARGS_PROTO) = NULL;
+
+attribute_hidden
+WRAPPER_RET_TYPE SB_HIDDEN_FUNC(WRAPPER_NAME)(WRAPPER_ARGS_PROTO_FULL)
+{
+ check_dlsym(WRAPPER_TRUE_NAME, WRAPPER_SYMNAME, WRAPPER_SYMVER);
+ return WRAPPER_TRUE_NAME(WRAPPER_ARGS_FULL);
+}
/* Eventually, there is a third parameter: it's mode_t mode */
-int WRAPPER_NAME(WRAPPER_ARGS_PROTO)
+WRAPPER_RET_TYPE WRAPPER_NAME(WRAPPER_ARGS_PROTO)
{
- va_list ap;
- int mode = 0;
- int result = -1;
-
- save_errno();
- if (flags & O_CREAT) {
- va_start(ap, flags);
- mode = va_arg(ap, int);
- va_end(ap);
- } else {
+ WRAPPER_RET_TYPE result = WRAPPER_RET_DEFAULT;
+
+ if (!(flags & O_CREAT)) {
+ save_errno();
+
/* XXX: If we're not trying to create, fail normally if
* file does not stat */
struct stat st;
@@ -39,17 +46,24 @@ int WRAPPER_NAME(WRAPPER_ARGS_PROTO)
#undef USE_AT
if (-1 == stat(pathname, &st))
return -1;
+
+ restore_errno();
}
- restore_errno();
if (WRAPPER_SAFE()) {
- check_dlsym(WRAPPER_TRUE_NAME, WRAPPER_SYMNAME,
- WRAPPER_SYMVER);
- if (flags & O_CREAT)
- result = WRAPPER_TRUE_NAME(WRAPPER_ARGS, mode);
- else
- result = WRAPPER_TRUE_NAME(WRAPPER_ARGS);
+ int mode = 0;
+ if (flags & O_CREAT) {
+ va_list ap;
+ va_start(ap, flags);
+ mode = va_arg(ap, int);
+ va_end(ap);
+ }
+ result = SB_HIDDEN_FUNC(WRAPPER_NAME)(WRAPPER_ARGS_FULL);
}
return result;
}
+
+#undef _WRAPPER_ARGS_PROTO
+#undef WRAPPER_ARGS_PROTO_FULL
+#undef WRAPPER_ARGS_FULL