--- tsocks.c.orig 2006-01-28 16:36:44.000000000 -0800 +++ tsocks.c 2006-01-28 16:27:51.000000000 -0800 @@ -99,6 +99,7 @@ static int read_socksv4_req(struct connreq *conn); static int read_socksv5_connect(struct connreq *conn); static int read_socksv5_auth(struct connreq *conn); +void _init(void) __attribute__ ((constructor)); void _init(void) { #ifdef USE_OLD_DLSYM @@ -191,9 +192,10 @@ struct sockaddr_in *connaddr; struct sockaddr_in peer_address; struct sockaddr_in server_address; - int gotvalidserver = 0, rc, namelen = sizeof(peer_address); + int gotvalidserver = 0, rc; int sock_type = -1; - int sock_type_len = sizeof(sock_type); + socklen_t sock_type_len = sizeof(sock_type); + socklen_t namelen = sizeof(peer_address); unsigned int res = -1; struct serverent *path; struct connreq *newconn; --- Makefile.in.orig 2006-01-28 17:33:25.000000000 -0800 +++ Makefile.in 2006-01-28 17:33:33.000000000 -0800 @@ -1,6 +1,7 @@ # Makefile used by configure to create real Makefile CC=@CC@ +SHLIB_EXT=@SHLIB_EXT@ prefix=@prefix@ exec_prefix = @exec_prefix@ libexecdir = @libexecdir@ @@ -23,11 +24,12 @@ SCRIPT = tsocks SHLIB_MAJOR = 1 SHLIB_MINOR = 8 -SHLIB = ${LIB_NAME}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} +SHLIB = ${LIB_NAME}.${SHLIB_EXT}.${SHLIB_MAJOR}.${SHLIB_MINOR} INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ CFLAGS = @CFLAGS@ +LDFLAGS = @LDFLAGS@ INCLUDES = -I. LIBS = @LIBS@ SPECIALLIBS = @SPECIALLIBS@ @@ -47,11 +49,11 @@ ${SHCC} ${CFLAGS} ${INCLUDES} -o ${INSPECT} ${INSPECT}.c ${COMMON}.o ${LIBS} ${SAVE}: ${SAVE}.c - ${SHCC} ${CFLAGS} ${INCLUDES} -static -o ${SAVE} ${SAVE}.c + ${SHCC} ${CFLAGS} ${INCLUDES} -o ${SAVE} ${SAVE}.c ${SHLIB}: ${OBJS} ${COMMON}.o ${PARSER}.o - ${SHCC} ${CFLAGS} ${INCLUDES} -nostdlib -shared -o ${SHLIB} ${OBJS} ${COMMON}.o ${PARSER}.o ${DYNLIB_FLAGS} ${SPECIALLIBS} ${LIBS} - ln -sf ${SHLIB} ${LIB_NAME}.so + ${SHCC} ${CFLAGS} ${INCLUDES} -nostdlib ${LDFLAGS} -o ${SHLIB} ${OBJS} ${COMMON}.o ${PARSER}.o ${DYNLIB_FLAGS} ${SPECIALLIBS} ${LIBS} + ln -sf ${SHLIB} ${LIB_NAME}.${SHLIB_EXT} %.so: %.c ${SHCC} ${CFLAGS} ${INCLUDES} -c ${CC_SWITCHES} $< -o $@ @@ -68,8 +70,8 @@ installlib: ${MKINSTALLDIRS} "${DESTDIR}${libdir}" ${INSTALL} ${SHLIB} ${DESTDIR}${libdir} - ln -sf ${SHLIB} ${DESTDIR}${libdir}/${LIB_NAME}.so.${SHLIB_MAJOR} - ln -sf ${LIB_NAME}.so.${SHLIB_MAJOR} ${DESTDIR}${libdir}/${LIB_NAME}.so + ln -sf ${SHLIB} ${DESTDIR}${libdir}/${LIB_NAME}.${SHLIB_EXT}.${SHLIB_MAJOR} + ln -sf ${LIB_NAME}.${SHLIB_EXT}.${SHLIB_MAJOR} ${DESTDIR}${libdir}/${LIB_NAME}.${SHLIB_EXT} installman: ${MKINSTALLDIRS} "${DESTDIR}${mandir}/man1" @@ -80,7 +82,7 @@ ${INSTALL_DATA} tsocks.conf.5 ${DESTDIR}${mandir}/man5/ clean: - -rm -f *.so *.so.* *.o *~ ${TARGETS} + -rm -f *.so *.so.* *.dylib *.dylib.* *.o *~ ${TARGETS} distclean: clean -rm -f config.cache config.log config.h Makefile --- configure.in.orig 2006-01-28 17:53:15.000000000 -0800 +++ configure.in 2006-01-28 18:13:45.000000000 -0800 @@ -33,6 +33,12 @@ AC_DEFINE_UNQUOTED(CONF_FILE, "/etc/tsocks.conf") ]) +dnl ----------------------------------- +dnl On Mac OS X, gcc-4.0 leads to link errors; must use gcc-3.3 +dnl ----------------------------------- +if test -x "/usr/bin/gcc-3.3"; then + CC=gcc-3.3 +fi dnl ----------------------------------- dnl Get hostname and other information. @@ -312,7 +318,7 @@ dnl Find the correct poll prototype on this machine AC_MSG_CHECKING(for correct poll prototype) PROTO= -for testproto in 'struct pollfd *ufds, unsigned long nfds, int timeout' +for testproto in 'struct pollfd *ufds, nfds_t nfds, int timeout' do if test "${PROTO}" = ""; then AC_TRY_COMPILE([ @@ -332,4 +338,42 @@ AC_SUBST(SPECIALLIBS) LIBS=${SIMPLELIBS} -AC_OUTPUT(Makefile) +dnl Check if the linker accepts -dynamiclib; necessary on Mac OS X +AC_MSG_CHECKING(if the linker accepts -dynamiclib) +OLDLDFLAGS="$LDFLAGS" +LDFLAGS="$LDFLAGS -dynamiclib" +AC_TRY_COMPILE(,,AC_MSG_RESULT(yes),[ + LDFLAGS="$OLDLDFLAGS" + AC_MSG_RESULT(no)]) + +dnl Check if the linker accepts -multiply_defined suppress; necessary on Mac OS X +AC_MSG_CHECKING(if the linker accepts -multiply_defined suppress) +OLDLDFLAGS="$LDFLAGS" +LDFLAGS="$LDFLAGS -multiply_defined suppress" +AC_TRY_COMPILE(,,AC_MSG_RESULT(yes),[ + LDFLAGS="$OLDLDFLAGS" + AC_MSG_RESULT(no)]) + +dnl Check if the linker accepts -single_module; necessary on Mac OS X +AC_MSG_CHECKING(if the linker accepts -single_module) +OLDLDFLAGS="$LDFLAGS" +SHLIB_EXT="so" +LD_PRELOAD="LD_PRELOAD" +LDFLAGS="$LDFLAGS -single_module" +AC_TRY_COMPILE(,, + [ + SHLIB_EXT="dylib" + LD_PRELOAD="DYLD_INSERT_LIBRARIES" + AC_MSG_RESULT(yes) + ], [ + LDFLAGS="$OLDLDFLAGS" + AC_MSG_RESULT(no) + ] +) + +AC_SUBST(SHLIB_EXT) +AC_SUBST(LD_PRELOAD) +AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([tsocks], [chmod +x tsocks]) +AC_OUTPUT + --- /dev/null 2006-01-31 20:56:18.000000000 -0800 +++ tsocks.in 2006-01-31 20:55:30.000000000 -0800 @@ -0,0 +1,103 @@ +#!/bin/sh +# Wrapper script for use of the tsocks(8) transparent socksification library +# +# There are three forms of usage for this script: +# +# /usr/bin/tsocks program [program arguments...] +# +# This form sets the users @LD_PRELOAD@ environment variable so that tsocks(8) +# will be loaded to socksify the application then executes the specified +# program (with the provided arguments). The following simple example might +# be used to telnet to www.foo.org via a tsocks.conf(5) configured socks server: +# +# /usr/bin/tsocks telnet www.foo.org +# +# The second form allows for tsocks(8) to be switched on and off for a +# session (that is, it adds and removes tsocks from the @LD_PRELOAD@ environment +# variable). This form must be _sourced_ into the user's existing session +# (and will only work with bourne shell users): +# +# . /usr/bin/tsocks on +# telnet www.foo.org +# . /usr/bin/tsocks off +# +# Or +# +# source /usr/bin/tsocks on +# telnet www.foo.org +# source /usr/bin/tsocks off +# +# The third form creates a new shell with @LD_PRELOAD@ set and is achieved +# simply by running the script with no arguments +# +# /usr/bin/tsocks +# +# When finished the user can simply terminate the shell with 'exit' +# +# This script is originally from the debian tsocks package by +# Tamas Szerb + +if [ $# = 0 ] ; then + echo "$0: insufficient arguments" + exit +fi + +LIBDIR="@libdir@" +LIB_NAME="libtsocks" +SHLIB_EXT="@SHLIB_EXT@" +SHLIB="${LIBDIR}/${LIB_NAME}.${SHLIB_EXT}" + +function show() { + echo "@LD_PRELOAD@ = \"$@LD_PRELOAD@\"" +} + +case "$1" in + on) + if [ -z "$@LD_PRELOAD@" ] + then + echo "Setting @LD_PRELOAD@ ..." + export @LD_PRELOAD@="${SHLIB}" + else + echo "Appending to @LD_PRELOAD@ ..." + echo $@LD_PRELOAD@ | grep -q "${SHLIB}" || \ + export @LD_PRELOAD@="${SHLIB} $@LD_PRELOAD@" + fi + show + ;; + off) + echo "Removing ${SHLIB} from @LD_PRELOAD@ ..." + export @LD_PRELOAD@=`echo -n $@LD_PRELOAD@ | sed 's#@libdir@/libtsocks\.@SHLIB_EXT@ *##'` + if [ -z "$@LD_PRELOAD@" ] + then + unset @LD_PRELOAD@ + fi + show + ;; + show|sh) + show + ;; + -h|-?) + echo "$0: Please see tsocks(1) or read comment at top of $0" + ;; + *) + if [ -z "$@LD_PRELOAD@" ] + then + export @LD_PRELOAD@="${SHLIB}" + else + echo $@LD_PRELOAD@ | grep -q "${SHLIB}" || \ + export @LD_PRELOAD@="${SHLIB} $@LD_PRELOAD@" + fi + + if [ $# = 0 ] + then + ${SHELL:-/bin/sh} + fi + + if [ $# -gt 0 ] + then + exec "$@" + fi + ;; +esac + +#EOF