From 03d4c598998e9373fd538ce1fb920c62dbde1cdd Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 12 Oct 2019 00:28:16 +0100 Subject: [PATCH] test: udp-preload: Proof of concept wrapping gcc -D_REENTRANT -fPIC -c udp-preload.c -ldl -lc && \ ld -shared -soname foo.so.1 udp-preload.o -o udp-preload.so produces a library which makes secnet go secnet fatal error: Failed to initialise ADNS: Message too long Signed-off-by: Ian Jackson --- .gitignore | 1 + test/udp-preload.c | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 10fbc23..acfaeb7 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ test-example/bogus-setup-request build-stamp test/tmp +test/udp-preload.so diff --git a/test/udp-preload.c b/test/udp-preload.c index 42630e4..8c7d18c 100644 --- a/test/udp-preload.c +++ b/test/udp-preload.c @@ -19,6 +19,8 @@ * */ +#define _GNU_SOURCE + #include #include #include @@ -31,14 +33,11 @@ #include #include -#include "authbind.h" - -typedef void anyfn_type(void); -typedef int bindfn_type(int fd, const struct sockaddr *addr, socklen_t addrlen); - #define STDERRSTR_CONST(m) write(2,m,sizeof(m)-1) #define STDERRSTR_STRING(m) write(2,m,strlen(m)) +typedef void anyfn_type(void); + static anyfn_type *find_any(const char *name) { static const char *dlerr; anyfn_type *kv; @@ -54,6 +53,33 @@ static anyfn_type *find_any(const char *name) { return 0; } +#define socket_args int domain, int type, int protocol +#define WRAPS(X) X(socket, (domain,type,protocol)) + +#define DEF_OLD(fn,args) \ + typedef int fn##_fn_type(fn##_args); \ + static int find_##fn(fn##_args); \ + static fn##_fn_type find_##fn, *old_##fn=find_##fn; \ + static int find_##fn(fn##_args) { \ + anyfn_type *anyfn; \ + anyfn= find_any(#fn); if (!anyfn) return -1; \ + old_##fn= (fn##_fn_type*)anyfn; \ + return old_##fn args; \ + } + +WRAPS(DEF_OLD) + +#define WRAP(fn) int fn(fn##_args) + +WRAP(socket) { + errno=EMSGSIZE; return -1; +} + +#if 0 +WRAP(bind, (int fd, const struct sockaddr *addr, socklen_t addrlen), { + +}); + static bindfn_type find_bind, *old_bind= find_bind; int find_bind(int fd, const struct sockaddr *addr, socklen_t addrlen) { @@ -251,3 +277,4 @@ x: } return r; } +#endif -- 2.30.2