-
Notifications
You must be signed in to change notification settings - Fork 6
/
tsocks-1.8_macosx.patch
256 lines (244 loc) · 7.46 KB
/
tsocks-1.8_macosx.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
--- 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 <toma@rulez.org>
+
+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