+SWAN Solaris runsocks
[nethome.git] / bin / runsocks
diff --git a/bin/runsocks b/bin/runsocks
new file mode 100755 (executable)
index 0000000..adc8a57
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/sh
+#
+# Put the path to the socks shared library in our LD_LIBRARY_PATH so when we
+# preload the library, ld.so will find it...
+#
+if test -n "${SOCKS5_SHLIB_RUNPATH}" ; then
+       SOCKS5_SHLIB_RUNPATH="${SOCKS5_SHLIB_RUNPATH}/"
+elif test -n "/usr/local/lib"; then
+       SOCKS5_SHLIB_RUNPATH="/usr/local/lib/"
+else 
+       SOCKS5_SHLIB_RUNPATH="./"
+fi
+
+#
+# Some OS's use PRELOADS=lib while others use _RLD_LIST=lib:DEFAULT.  Hopefully 
+# this can handle all those cases.  At any rate, this is basically causing the
+# socks5 shared libary to be used to resolve symbols before other libraries,
+# hence we get socks's connect before we get libc's connect...
+#
+# Also, on SunOS 4*, LD_LIBRARY_PATH has no effect on, so we need to put the path
+# in front of it.  We make the path overridable with SOCKS5_SHLIB_RUNPATH...
+#
+case `uname -rs` in
+SunOS*4.*)
+       LD_PRELOAD=${SOCKS5_SHLIB_RUNPATH}libsocks5_sh.so
+       export LD_PRELOAD
+       ;;
+*)
+       if test -z "$LD_LIBRARY_PATH" ; then
+               LD_LIBRARY_PATH=${SOCKS5_SHLIB_RUNPATH}
+       else
+               LD_LIBRARY_PATH=${SOCKS5_SHLIB_RUNPATH}:${LD_LIBRARY_PATH}
+               export LD_LIBRARY_PATH
+       fi
+
+       LD_PRELOAD=libsocks5_sh.so
+       export LD_LIBRARY_PATH
+       ;;
+esac
+# 
+# Run the actual program...
+#
+export LD_PRELOAD
+exec "$@"