chiark / gitweb /
test: udp-preload: Proof of concept wrapping
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 11 Oct 2019 23:28:16 +0000 (00:28 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 12 Oct 2019 22:29:26 +0000 (23:29 +0100)
  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 <ijackson@chiark.greenend.org.uk>
.gitignore
test/udp-preload.c

index 10fbc239c5cd01d59b4ca8cd623dc67917177eb9..acfaeb78eaafef8b4d3ec6fa22799db163e4d6f5 100644 (file)
@@ -37,3 +37,4 @@ test-example/bogus-setup-request
 build-stamp
 
 test/tmp
+test/udp-preload.so
index 42630e41a00686b66e3a41a6596deea8a16a1087..8c7d18cc175b284e4e905fb6e95e3fe73a8ee2d3 100644 (file)
@@ -19,6 +19,8 @@
  * 
  */
 
+#define _GNU_SOURCE
+
 #include <dlfcn.h>
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <netinet/in.h>
 
-#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