aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2009-02-20 02:31:19 -0500
committerMike Frysinger <vapier@gentoo.org>2009-02-20 02:31:19 -0500
commit3f36f0ce46a85a7f60afb33e251782af99eec015 (patch)
treec95b22914802ab081686b8856630389c3fb84bff /libsandbox/wrapper-funcs
parentlibsandbox: unify creat/creat64 wrappers (diff)
downloadsandbox-3f36f0ce46a85a7f60afb33e251782af99eec015.tar.gz
sandbox-3f36f0ce46a85a7f60afb33e251782af99eec015.tar.bz2
sandbox-3f36f0ce46a85a7f60afb33e251782af99eec015.zip
libsandbox: unify openat and __wrapper_simple
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'libsandbox/wrapper-funcs')
-rw-r--r--libsandbox/wrapper-funcs/__wrapper_simple.c23
-rw-r--r--libsandbox/wrapper-funcs/openat.c52
2 files changed, 40 insertions, 35 deletions
diff --git a/libsandbox/wrapper-funcs/__wrapper_simple.c b/libsandbox/wrapper-funcs/__wrapper_simple.c
index 8aaf612..1cdf176 100644
--- a/libsandbox/wrapper-funcs/__wrapper_simple.c
+++ b/libsandbox/wrapper-funcs/__wrapper_simple.c
@@ -8,6 +8,12 @@
#ifndef WRAPPER_ARGS_PROTO
# error WRAPPER_ARGS_PROTO needs to be defined
#endif
+#ifndef WRAPPER_ARGS_PROTO_FULL
+# define WRAPPER_ARGS_PROTO_FULL WRAPPER_ARGS_PROTO
+#endif
+#ifndef WRAPPER_ARGS_FULL
+# define WRAPPER_ARGS_FULL WRAPPER_ARGS
+#endif
#ifndef WRAPPER_RET_TYPE
# define WRAPPER_RET_TYPE int
#endif
@@ -17,6 +23,9 @@
#ifndef WRAPPER_PRE_CHECKS
# define WRAPPER_PRE_CHECKS() true
#endif
+#ifndef WRAPPER_SAFE_POST_EXPAND
+# define WRAPPER_SAFE_POST_EXPAND
+#endif
extern WRAPPER_RET_TYPE EXTERN_NAME(WRAPPER_ARGS_PROTO);
static WRAPPER_RET_TYPE (*WRAPPER_TRUE_NAME)(WRAPPER_ARGS_PROTO) = NULL;
@@ -26,10 +35,10 @@ static WRAPPER_RET_TYPE (*WRAPPER_TRUE_NAME)(WRAPPER_ARGS_PROTO) = NULL;
# define SB_HIDDEN_FUNC(x) _SB_HIDDEN_FUNC(x)
#endif
attribute_hidden
-WRAPPER_RET_TYPE SB_HIDDEN_FUNC(WRAPPER_NAME)(WRAPPER_ARGS_PROTO)
+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);
+ return WRAPPER_TRUE_NAME(WRAPPER_ARGS_FULL);
}
WRAPPER_RET_TYPE WRAPPER_NAME(WRAPPER_ARGS_PROTO)
@@ -37,8 +46,14 @@ WRAPPER_RET_TYPE WRAPPER_NAME(WRAPPER_ARGS_PROTO)
WRAPPER_RET_TYPE result = WRAPPER_RET_DEFAULT;
if (WRAPPER_PRE_CHECKS())
- if (WRAPPER_SAFE())
- result = SB_HIDDEN_FUNC(WRAPPER_NAME)(WRAPPER_ARGS);
+ if (WRAPPER_SAFE()) {
+ WRAPPER_SAFE_POST_EXPAND
+ result = SB_HIDDEN_FUNC(WRAPPER_NAME)(WRAPPER_ARGS_FULL);
+ }
return result;
}
+
+#undef WRAPPER_ARGS_FULL
+#undef WRAPPER_ARGS_PROTO_FULL
+#undef WRAPPER_SAFE_POST_EXPAND
diff --git a/libsandbox/wrapper-funcs/openat.c b/libsandbox/wrapper-funcs/openat.c
index d8edf13..9468515 100644
--- a/libsandbox/wrapper-funcs/openat.c
+++ b/libsandbox/wrapper-funcs/openat.c
@@ -16,54 +16,44 @@
#else
# define USE_AT 0
#endif
-#define WRAPPER_RET_TYPE int
-#define WRAPPER_RET_DEFAULT -1
-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);
-}
+#ifndef PRE_CHECK_FUNC
+# define _PRE_CHECK_FUNC(x) sb_##x##_pre_check
+# define PRE_CHECK_FUNC(x) _PRE_CHECK_FUNC(x)
+#endif
-/* Eventually, there is a third parameter: it's mode_t mode */
-WRAPPER_RET_TYPE WRAPPER_NAME(WRAPPER_ARGS_PROTO)
+static inline bool PRE_CHECK_FUNC(WRAPPER_NAME)(_WRAPPER_ARGS_PROTO)
{
- 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 */
+ /* If we're not trying to create, fail normally if
+ * file does not stat
+ */
struct stat st;
#if USE_AT
if (dirfd == AT_FDCWD || pathname[0] == '/')
#endif
#undef USE_AT
if (-1 == stat(pathname, &st))
- return -1;
+ return false;
restore_errno();
}
- if (WRAPPER_SAFE()) {
- 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 true;
+}
+#define WRAPPER_PRE_CHECKS() PRE_CHECK_FUNC(WRAPPER_NAME)(WRAPPER_ARGS)
+
+#define WRAPPER_SAFE_POST_EXPAND \
+ int mode = 0; \
+ if (flags & O_CREAT) { \
+ va_list ap; \
+ va_start(ap, flags); \
+ mode = va_arg(ap, int); \
+ va_end(ap); \
}
- return result;
-}
+#include "__wrapper_simple.c"
#undef _WRAPPER_ARGS_PROTO
-#undef WRAPPER_ARGS_PROTO_FULL
-#undef WRAPPER_ARGS_FULL