diff options
author | jdp <jdp@FreeBSD.org> | 1996-11-01 10:37:35 +0800 |
---|---|---|
committer | jdp <jdp@FreeBSD.org> | 1996-11-01 10:37:35 +0800 |
commit | cc0a779e9a2548a146eef59e528387cf5cfb457b (patch) | |
tree | 872518e47aa52008beb19bf127c36b78405b65db /lang/modula-3-socks | |
parent | ec7d2f089bc5add0ccc9ee96bfb0a9640476d517 (diff) | |
download | freebsd-ports-gnome-cc0a779e9a2548a146eef59e528387cf5cfb457b.tar.gz freebsd-ports-gnome-cc0a779e9a2548a146eef59e528387cf5cfb457b.tar.zst freebsd-ports-gnome-cc0a779e9a2548a146eef59e528387cf5cfb457b.zip |
This package implements SOCKS support for Modula-3 applications. It
will be used to support SOCKS operation in the soon-to-be-released next
version of CVSup.
A tip of the hat to: Darryl Okahata, who developed the patches
necessary to make the SOCKS library work with Modula-3's multithreaded
I/O system.
Diffstat (limited to 'lang/modula-3-socks')
36 files changed, 1076 insertions, 0 deletions
diff --git a/lang/modula-3-socks/Makefile b/lang/modula-3-socks/Makefile new file mode 100644 index 000000000000..f8ee0777fce4 --- /dev/null +++ b/lang/modula-3-socks/Makefile @@ -0,0 +1,52 @@ +# New ports collection makefile for: modula-3-socks +# Version required: A.B9.06 +# Date created: 31 Oct 1996 +# Whom: John Polstra <jdp@polstra.com> +# +# $Id$ +# + +DISTNAME= modula-3-socks +PKGNAME= modula-3-socks-1.0 +CATEGORIES+= lang +MASTER_SITES= ftp://ftp.cup.hp.com/dist/socks/A.B9.06/ +DISTFILES= socks.tar.gz + +MAINTAINER= jdp@polstra.com + +NO_WRKSUBDIR= yes + +libm3socks_files= accept.c bind.c close.c connect.c dup.c dup2.c \ + gethostbyaddr.c gethostbyname.c getpeername.c \ + getsockname.c listen.c read.c recv.c recvfrom.c \ + select.c send.c sendto.c shutdown.c socket.c \ + socksconf.h wrap.h write.c + +m3socks_files= m3socks.sh m3socks.1 m3socks.conf.5 + +post-extract: + @cp -p ${FILESDIR}/Makefile.top ${WRKSRC}/Makefile + @test -d ${WRKSRC}/libm3socks || mkdir ${WRKSRC}/libm3socks + @cd ${FILESDIR}; \ + cp -p Makefile.libm3socks ${WRKSRC}/libm3socks/Makefile; \ + cp -p ${libm3socks_files} ${WRKSRC}/libm3socks + @test -d ${WRKSRC}/m3socks || mkdir ${WRKSRC}/m3socks + @cd ${FILESDIR}; \ + cp -p Makefile.m3socks ${WRKSRC}/m3socks/Makefile; \ + cp -p ${m3socks_files} ${WRKSRC}/m3socks + +pre-install: + @cd ${PREFIX}/lib; \ + test -d m3/FreeBSD2 || { \ + mkdir -p m3/FreeBSD2; \ + chown ${BINOWN}.${BINGRP} m3 m3/FreeBSD2; \ + } + +post-install: + @if [ ! -f ${PREFIX}/etc/m3socks.conf ]; then \ + echo -n "Please create a configuration file in "; \ + echo "${PREFIX}/etc/m3socks.conf"; \ + echo "Read m3socks.conf(5) for details"; \ + fi + +.include <bsd.port.mk> diff --git a/lang/modula-3-socks/distinfo b/lang/modula-3-socks/distinfo new file mode 100644 index 000000000000..a06d6138c407 --- /dev/null +++ b/lang/modula-3-socks/distinfo @@ -0,0 +1 @@ +MD5 (socks.tar.gz) = e20003ba420c94582ede06b1243e395d diff --git a/lang/modula-3-socks/files/Makefile.libm3socks b/lang/modula-3-socks/files/Makefile.libm3socks new file mode 100644 index 000000000000..362d11e25025 --- /dev/null +++ b/lang/modula-3-socks/files/Makefile.libm3socks @@ -0,0 +1,19 @@ +PROG= libm3socks.so +SRCS= accept.c bind.c close.c connect.c dup.c dup2.c \ + gethostbyaddr.c gethostbyname.c getpeername.c getsockname.c \ + listen.c read.c recv.c recvfrom.c select.c send.c sendto.c \ + shutdown.c socket.c socksconf.h wrap.h write.c \ + Xconnect.c bytes.c check_cconf.c check_user.c percent_x.c \ + saddrtoname.c shell_cmd.c stubs.c +CFLAGS+= -I${.CURDIR}/../SOCKS-SOURCE/h -DPIC -fpic -w +LDFLAGS+= -Bshareable +BINDIR= ${PREFIX}/lib/m3/FreeBSD2 +NOMAN= yes + +.PATH: ${.CURDIR}/../SOCKS-SOURCE/lib \ + ${.CURDIR}/../SOCKS-SOURCE/client + +${PROG}: + ${LD} -o ${PROG} ${LDFLAGS} ${OBJS} ${LDADD} + +.include <bsd.prog.mk> diff --git a/lang/modula-3-socks/files/Makefile.m3socks b/lang/modula-3-socks/files/Makefile.m3socks new file mode 100644 index 000000000000..1e6555a147e4 --- /dev/null +++ b/lang/modula-3-socks/files/Makefile.m3socks @@ -0,0 +1,18 @@ +CLEANFILES+= m3socks +MAN1= m3socks.1 +MAN5= m3socks.conf.5 +BINDIR= ${PREFIX}/bin +MANDIR= ${PREFIX}/man/man + +all: m3socks + +.SUFFIXES: .sh + +.sh: + cp $@.sh $@ + +realinstall: + ${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ + m3socks ${BINDIR} + +.include <bsd.prog.mk> diff --git a/lang/modula-3-socks/files/Makefile.top b/lang/modula-3-socks/files/Makefile.top new file mode 100644 index 000000000000..0e015de14485 --- /dev/null +++ b/lang/modula-3-socks/files/Makefile.top @@ -0,0 +1,3 @@ +SUBDIR= libm3socks m3socks + +.include <bsd.subdir.mk> diff --git a/lang/modula-3-socks/files/accept.c b/lang/modula-3-socks/files/accept.c new file mode 100644 index 000000000000..89f955d78d28 --- /dev/null +++ b/lang/modula-3-socks/files/accept.c @@ -0,0 +1,16 @@ +#include "wrap.h" +#include <sys/types.h> +#include <sys/socket.h> + +int +m3_accept(int s, struct sockaddr *addr, int *addrlen) +{ + int result; + + ENTER_CRITICAL; + MAKE_WRITABLE(addr); + MAKE_WRITABLE(addrlen); + result = accept(s, addr, addrlen); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/files/bind.c b/lang/modula-3-socks/files/bind.c new file mode 100644 index 000000000000..d5cc51d56f64 --- /dev/null +++ b/lang/modula-3-socks/files/bind.c @@ -0,0 +1,15 @@ +#include "wrap.h" +#include <sys/types.h> +#include <sys/socket.h> + +int +m3_bind(int s, const struct sockaddr *name, int namelen) +{ + int result; + + ENTER_CRITICAL; + MAKE_READABLE(name); + result = bind(s, name, namelen); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/files/close.c b/lang/modula-3-socks/files/close.c new file mode 100644 index 000000000000..0b00e8ebe0c8 --- /dev/null +++ b/lang/modula-3-socks/files/close.c @@ -0,0 +1,13 @@ +#include "wrap.h" +#include <unistd.h> + +int +m3_close(int d) +{ + int result; + + ENTER_CRITICAL; + result = close(d); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/files/connect.c b/lang/modula-3-socks/files/connect.c new file mode 100644 index 000000000000..02c9f7878b32 --- /dev/null +++ b/lang/modula-3-socks/files/connect.c @@ -0,0 +1,15 @@ +#include "wrap.h" +#include <sys/types.h> +#include <sys/socket.h> + +int +m3_connect(int s, const struct sockaddr *name, int namelen) +{ + int result; + + ENTER_CRITICAL; + MAKE_READABLE(name); + result = connect(s, name, namelen); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/files/dup.c b/lang/modula-3-socks/files/dup.c new file mode 100644 index 000000000000..188ff67fd6b3 --- /dev/null +++ b/lang/modula-3-socks/files/dup.c @@ -0,0 +1,13 @@ +#include "wrap.h" +#include <unistd.h> + +int +m3_dup(int oldd) +{ + int result; + + ENTER_CRITICAL; + result = dup(oldd); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/files/dup2.c b/lang/modula-3-socks/files/dup2.c new file mode 100644 index 000000000000..582d570695e1 --- /dev/null +++ b/lang/modula-3-socks/files/dup2.c @@ -0,0 +1,13 @@ +#include "wrap.h" +#include <unistd.h> + +int +m3_dup2(int oldd, int newd) +{ + int result; + + ENTER_CRITICAL; + result = dup2(oldd, newd); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/files/gethostbyaddr.c b/lang/modula-3-socks/files/gethostbyaddr.c new file mode 100644 index 000000000000..cf52f5117479 --- /dev/null +++ b/lang/modula-3-socks/files/gethostbyaddr.c @@ -0,0 +1,14 @@ +#include "wrap.h" +#include <netdb.h> + +struct hostent * +m3_gethostbyaddr(const char *addr, int len, int type) +{ + struct hostent *result; + + ENTER_CRITICAL; + MAKE_READABLE(addr); + result = gethostbyaddr(addr, len, type); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/files/gethostbyname.c b/lang/modula-3-socks/files/gethostbyname.c new file mode 100644 index 000000000000..715471ea86eb --- /dev/null +++ b/lang/modula-3-socks/files/gethostbyname.c @@ -0,0 +1,14 @@ +#include "wrap.h" +#include <netdb.h> + +struct hostent * +m3_gethostbyname(const char *name) +{ + struct hostent *result; + + ENTER_CRITICAL; + MAKE_READABLE(name); + result = gethostbyname(name); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/files/getpeername.c b/lang/modula-3-socks/files/getpeername.c new file mode 100644 index 000000000000..4da8eaa201b2 --- /dev/null +++ b/lang/modula-3-socks/files/getpeername.c @@ -0,0 +1,16 @@ +#include "wrap.h" +#include <sys/types.h> +#include <sys/socket.h> + +int +m3_getpeername(int s, struct sockaddr *name, int *namelen) +{ + int result; + + ENTER_CRITICAL; + MAKE_WRITABLE(name); + MAKE_WRITABLE(namelen); + result = getpeername(s, name, namelen); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/files/getsockname.c b/lang/modula-3-socks/files/getsockname.c new file mode 100644 index 000000000000..fdad80aed556 --- /dev/null +++ b/lang/modula-3-socks/files/getsockname.c @@ -0,0 +1,16 @@ +#include "wrap.h" +#include <sys/types.h> +#include <sys/socket.h> + +int +m3_getsockname(int s, struct sockaddr *name, int *namelen) +{ + int result; + + ENTER_CRITICAL; + MAKE_WRITABLE(name); + MAKE_WRITABLE(namelen); + result = getsockname(s, name, namelen); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/files/listen.c b/lang/modula-3-socks/files/listen.c new file mode 100644 index 000000000000..33e28e87a242 --- /dev/null +++ b/lang/modula-3-socks/files/listen.c @@ -0,0 +1,14 @@ +#include "wrap.h" +#include <sys/types.h> +#include <sys/socket.h> + +int +m3_listen(int s, int backlog) +{ + int result; + + ENTER_CRITICAL; + result = listen(s, backlog); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/files/m3socks.1 b/lang/modula-3-socks/files/m3socks.1 new file mode 100644 index 000000000000..3d27c40d40dc --- /dev/null +++ b/lang/modula-3-socks/files/m3socks.1 @@ -0,0 +1,46 @@ +.Dd October 31, 1996 +.Os FreeBSD +.Dt M3SOCKS 1 +.Sh NAME +.Nm m3socks +.Nd execute a Modula-3 program using a SOCKS proxy server +.Sh SYNOPSIS +.Nm +.Ar command +.Op Ar arguments +.Sh DESCRIPTION +.Nm +runs +.Ar command +after dynamically linking SOCKS support into its memory image. +The +.Ar command +must be a dynamically linked Modula-3 program. +.Sh ENVIRONMENT +.Nm +exports the environment setting +.Ev M3SOCKS=1 +to +.Ar command . +This can be used by +.Ar command +to detect whether it is being run using SOCKS. +.Sh FILES +.Bl -tag -width /usr/local/etc/m3socks.confxx -compact +.It Pa /usr/local/etc/m3socks.conf +SOCKS configuration file. +.El +.Sh SEE ALSO +.Xr m3socks.conf 5 +.Sh STANDARDS +.Nm +uses version 4 of the SOCKS protocol. +This protocol is supported by version 4 and version 5 SOCKS servers. +.Sh BUGS +.Nm +has no effect if the +.Ar command +is a set-user-ID or set-group-ID program. +.Sh AUTHORS +John Polstra, +.Aq jdp@polstra.com . diff --git a/lang/modula-3-socks/files/m3socks.conf.5 b/lang/modula-3-socks/files/m3socks.conf.5 new file mode 100644 index 000000000000..5c45c364a044 --- /dev/null +++ b/lang/modula-3-socks/files/m3socks.conf.5 @@ -0,0 +1,256 @@ +.\" From: /3a/socks/man/RCS/socks.conf.4,v 2.11 1995/05/05 18:05:26 lamont Exp +.Dd May 5, 1995 +.Os FreeBSD +.Dt M3SOCKS.CONF 5 +.Sh NAME +.Nm m3socks.conf +.Nd configuration file for Modula-3 socks clients +.Sh DESCRIPTION +The Modula-3 SOCKS library reads its configuration information from +.Pa /usr/local/etc/m3socks.conf +when +.Fn bind +or +.Fn connect +is called. +If the file does not exist, then the environment variable +.Ev SOCKS_CONF +is expected to give the name of the configuration file. +.Pp +Each non-blank, non-comment line in the file contains a direction on how +to process requests that match certain criteria. +Comments are denoted by a +.Ql # +at any point in the line prior to the +.Ic : Ns Ar shellcmd , +if present. +Non-comment lines take the form: +.Pp +.Bl -item -compact +.It +.Ic bind default Ns \*(Ba Ns Ic wild +.It +.Ic domain Ar domain +.It +.Ic nameserver Ar nameserver +.It +.Ic findserver Ar findserver +.It +.Ic sockd +.Op Ic @= Ns Ar server +.Op Ic *= Ns Ar users +.Ar destspec +.Op Ar op Ar dport Op Ar dport2 +.Op Ic : Ns Ar shellcmd +.It +.Ic direct +.Op Ic *= Ns Ar users +.Ar destspec +.Op Ar op Ar dport Op Ar dport2 +.Op Ic : Ns Ar shellcmd +.It +.Ic deny +.Op Ic *= Ns Ar users +.Ar destspec +.Op Ar op Ar dport Op Ar dport2 +.Op Ic : Ns Ar shellcmd +.El +.Pp +Fields are constructed as follows: +.Bl -tag -width Fl +.It Ar domain +The +.Dq local +domain: the default name resolver is assumed to have +information for all hosts in +.Ar domain . +The user can override this field using the +.Ev SOCKS_LOCAL_DOMAIN +environment variable. +To indicate that the default server is able to resolve all addresses, +use the command: +.Ql domain \&. . +.It Ar nameserver +A comma separated list of name servers that are able to resolve addresses +outside of +.Ar domain . +The user can override this field using the +.Ev SOCKS_NS +environment variable. +.It Ar findserver +One of +.Ic Yes +or +.Ic \&No . +The default is +.Ic Yes . +If set, the client will attempt to find the +.Dq best +SOCKS server, based +on the results of looking up +.Ar destnet Ns Ic .socks-addr +(note that this is not an FQDN). +.Ar destnet +consists of the first one, two, or three octets of the destination network, +depending on whether the destination network is class A, B, or C. The octets +are used in reverse order, just like +.Ic IN-ADDR.ARPA . +For example, if the destination address is 129.105.69.100, then a search for +TXT records for '105.129.socks-addr' would be made. If any TXT records are +found, the record is prepended +to the list of servers from the config file. There is no environment +variable to override this. +.Pp +If clear +.Pq Ic findserver Ic \&No , +then the lookup is not performed. +.It Ar server +A comma separated list of SOCKS servers that can +be used as proxy for this destination. No spaces or tabs are allowed +inside the list. Names beginning with a +.Ql $ +are expanded from the users +environment. Each server in the list is tried until a successful +connection is established. When a server has multiple addresses, it +is assumed to be a group of hosts: the address list is randomized and +each address is tried before proceeding to the next name in the list. +The user can override this field using the +.Ev SOCKS_SERVER +environment variable. +.It Ar users +Specifies the users on the requesting host (not the destination host +or server host) to whom this line should apply. This is a comma +separated list of names and/or filenames, with no spaces or tabs. +Filenames must be fully qualified with a leading +.Ql / . +Inside the file, user names may be listed one or several +per line, with spaces, tabs, and commas being valid separators. +The appearance of +.Ql # +marks the remainder of the line as a comment. Each line in a file +is limited to 1023 characters. If +.Ar users +is omitted, the line applies to all users. +.It Ar destspec +The destination specification, which is either +.Ar daddr dmask +or +.Ic *. Ns Ar some.domain , +which indicates that the line applies to all IP addresses +whose reverse lookup, using +.Fn gethostbyaddr , +produces a name ending in +.Ql Cm . Ns Ar some.domain . +.It Ar daddr +The destination address to which this line applies. This is +usually specified in dotted form (e.g., 15.28.96.137). +If a hostname is used, then the first address returned by +.Fn gethostbyname +is used. +.It Ar dmask +Mask for +.Ar daddr , +in dotted form. Bits in +.Ar dmask +which are 0 are ignored in +.Ar daddr . +Specifying 255.255.255.255 requires an exact match, while 0.0.0.0 matches +regardless of the value of +.Ar daddr . +This is the same way netmasks are specified, and is the opposite +of the interpretation used in older versions of SOCKS. +.It Ar op dport Op Ar dport2 +A constraint on the destination TCP port. +If +.Ar op +is +.Ic eq , +.Ic neq , +.Ic \< , +.Ic gt , +.Ic le , +or +.Ic ge , +the destination port must have the corresponding relation to +.Ar dport . +If +.Ar op +is +.Ic btw , +the destination port must be between +.Ar dport +and +.Ar dport2 , +inclusive. +.It Ic : Ns Ar shellcmd +When the line is matched, +.Ar shellcmd +is passed to +.Pa /bin/sh , +with stdin, stdout, and stderr redirected to +.Pa /dev/null . +The following substitutions occur before the string +is presented to the shell: +.Bl -tag -width \&%Xxx +.It Cm \&%A +replaced by the client host's domainname if known, +by its IP address otherwise. +.It Cm \&%a +replaced by the client host's IP address. +.It Cm \&%c +replaced by +.Ql connect +or +.Ql bind . +.It Cm \&%p +replaced by the process id of the client program. +.It Cm \&%S +replaced by the service name (e.g., ftp) if known, +by the destination port number otherwise. +.It Cm \&%s +replaced by the destination port number. +.It Cm \&%U +replaced by the user-id at login. +.It Cm \&%u +replaced by the effective user-id. +.It Cm \&%Z +replaced by the destination host's domainname if known, +by its IP address otherwise. +.It Cm \&%z +replaced by the destination host's IP address. +.It Cm \&%% +replaced by a single +.Ql \&% . +.El +.El +.Sh EXAMPLES +All connections to net 15 are local: +.Dl Ic direct 15.0.0.0 255.0.0.0 +.Pp +Deny all requests destined for hosts on network 23: +.Dl Ic deny 23.0.0.0 255.0.0.0 +.Pp +Use the server my-server for hosts on network 36: +.Dl Ic sockd @=my-server 36.0.0.0 255.0.0.0 +.Pp +A typical complete configuration file: +.Bd -literal -offset indent +# The default name server is used for addresses inside +# the FreeBSD.org domain. +domain FreeBSD.org +# ns.FreeBSD.org is used as the name server for addresses +# outside FreeBSD.org. +nameserver ns.FreeBSD.org +# Don't find socks servers automatically. +findserver No +# All local connections are direct. +direct *.FreeBSD.org +# All other connections use the SOCKS server +# on socks.FreeBSD.org. +sockd @=socks.FreeBSD.org 0.0.0.0 0.0.0.0 +.Ed +.Sh SEE ALSO +.Xr m3socks 1 +.Sh AUTHORS +SOCKS was developed by David Koblas and Ying-Da Lee. +The HP enhancements were done by LaMont Jones. diff --git a/lang/modula-3-socks/files/m3socks.sh b/lang/modula-3-socks/files/m3socks.sh new file mode 100644 index 000000000000..55bb198a8ed6 --- /dev/null +++ b/lang/modula-3-socks/files/m3socks.sh @@ -0,0 +1,10 @@ +#! /bin/sh + +if [ $# -eq 0 ]; then + echo "Usage: $0 command [arguments]" >&2 + exit 2 +fi + +export M3SOCKS=1 +export LD_PRELOAD=/usr/local/lib/m3/FreeBSD2/libm3socks.so +exec "$@" diff --git a/lang/modula-3-socks/files/patch-aa b/lang/modula-3-socks/files/patch-aa new file mode 100644 index 000000000000..0805679fe4df --- /dev/null +++ b/lang/modula-3-socks/files/patch-aa @@ -0,0 +1,27 @@ +Index: SOCKS-SOURCE/h/socksdef.h +--- socksdef.h.orig Wed Aug 7 19:25:31 1996 ++++ socksdef.h Wed Oct 30 21:05:37 1996 +@@ -15,9 +15,11 @@ + #define P_(x) () + #endif /* ! ANSI C */ + ++#ifndef __FreeBSD__ + extern int syslog P_((int , const char *, ...)); + extern int openlog P_((const char *, int , int )); + extern int closelog P_((void)); ++#endif + + #define LOG_LOW LOG_NOTICE + #define LOG_HIGH LOG_ERR +@@ -34,9 +36,9 @@ + #define INETD_SEC "/var/adm/inetd.sec" + #define DEFAULT_DEST "/opt/socks/bin" /* for socksify */ + #else /* ! V4FS */ +-#define SOCKD_DUMP_FILE "/usr/tmp/sockd.conf.dump" ++#define SOCKD_DUMP_FILE "/var/tmp/sockd.conf.dump" + #define SOCKD_CONF "/usr/local/etc/sockd.conf" +-#define SOCKS_CONF "/etc/socks.conf" ++#define SOCKS_CONF "/usr/local/etc/m3socks.conf" + #define OTHER_SOCKS_CONF "/usr/local/etc/socks.conf" + #define INETD_SEC "/usr/adm/inetd.sec" + #define DEFAULT_DEST "." /* for socksify */ diff --git a/lang/modula-3-socks/files/patch-ab b/lang/modula-3-socks/files/patch-ab new file mode 100644 index 000000000000..11c68bc51aca --- /dev/null +++ b/lang/modula-3-socks/files/patch-ab @@ -0,0 +1,249 @@ +Index: SOCKS-SOURCE/client/Xconnect.c +diff -r -u SOCKS-SOURCE/client/Xconnect.c socks-jdp/client/Xconnect.c +--- SOCKS-SOURCE/client/Xconnect.c Wed Aug 7 19:25:51 1996 ++++ socks-jdp/client/Xconnect.c Thu Oct 24 21:35:47 1996 +@@ -24,7 +24,9 @@ + #include <netdb.h> + #include <arpa/nameser.h> + int res_init PARAM((void)); ++#ifndef __FreeBSD__ + int res_search PARAM((char*,int,int,u_char*,int)); ++#endif + int dn_skipname PARAM((u_char*,u_char*)); + #include <arpa/inet.h> + #include <resolv.h> +@@ -39,6 +41,10 @@ + #include "bytes.h" + #include "check_user.h" + ++#ifndef FIOSNBIO ++# define FIOSNBIO FIONBIO ++#endif ++ + unsigned char _SOCKS_version=SOCKS_VERSION; + + char *socks_dst_serv=NULL, *socks_dst_name=NULL; +@@ -102,6 +108,8 @@ + struct info *l; /* must be first field */ + int snum; + unsigned short type; ++ int connect_done:8; ++ int bind_done:8; + int sin_valid:8; + int peer_valid:8; + struct sockaddr_in sin; +@@ -185,16 +193,34 @@ + #ifndef INTERNAL_ONLY + if (_SOCKS_external) { + u_short port; ++ int status, oldf; ++ ++ oldf = -1; ++ status = 0; ++ while (1) ++ { ++ if ((oldf = fcntl(s, F_GETFL, NULL)) == -1) ++ { ++ break; ++ } ++ (void)fcntl(s, F_SETFL, oldf&~(O_NDELAY|O_NONBLOCK)); + if (_SOCKS_read(s,&net.version,sizeof(net.version)) < -1) +- return -1; ++ break; + if (_SOCKS_read(s,&net.cmd,sizeof(net.cmd)) < -1) +- return -1; ++ break; + if (_SOCKS_read(s,&port,sizeof(port)) < -1) +- return -1; +- net.port=port; ++ break; ++ net.port = port; + if (_SOCKS_read(s,&net.host,sizeof(net.host)) < -1) +- return -1; +- } else ++ break; ++ status = 1; ++ break; ++ } ++ if (oldf != -1) ++ (void)fcntl(s, F_SETFL, oldf); ++ if (!status) ++ return (-1); ++ } else + #endif /* INTERNAL_ONLY */ + { + if (_SOCKS_read(s,&net,sizeof(net)) < -1) +@@ -297,6 +323,12 @@ + + if (s>=0 && af == AF_INET) { + (void)add_sock(s,NULL,type); ++#if 1 ++ bval = size; ++ blen = sizeof(bval); ++ (void)setsockopt(s,SOL_SOCKET,SO_RCVBUF,&bval,blen); ++ (void)setsockopt(s,SOL_SOCKET,SO_SNDBUF,&bval,blen); ++#else + if (getsockopt(s,SOL_SOCKET,SO_RCVBUF,&bval,&blen)==0 && bval<size) { + bval=size; + (void)setsockopt(s,SOL_SOCKET,SO_RCVBUF,&bval,blen); +@@ -305,6 +337,7 @@ + bval=size; + (void)setsockopt(s,SOL_SOCKET,SO_SNDBUF,&bval,blen); + } ++#endif + } + return s; + } +@@ -380,6 +413,7 @@ + oldf=fcntl(sock,F_GETFL,NULL); + (void)fcntl(sock,F_SETFL,oldf&~(O_NDELAY|O_NONBLOCK)); + (void)ioctl(sock,FIOSNBIO,0); ++ errno = 0; + if (Xconnect(sock, sin, sizeof(struct sockaddr_in)) == 0) { + if (SendDst(sock, dst) < 0) { + ret_val=-1; +@@ -389,6 +423,7 @@ + lastSocksHost=sin->sin_addr.s_addr; + lastSocksPort=sin->sin_port; + *dst=mydst; ++ (void)fcntl(sock,F_SETFL,oldf); + return 0; + } else { + errno=ECONNREFUSED; +@@ -402,7 +437,7 @@ + exit(1); + } + Xclose(new_sock); +- ++ (void)fcntl(sock,F_SETFL,oldf); + return ret_val; + } + #ifdef PROTOTYPES +@@ -605,6 +640,12 @@ + l->sin.sin_family = AF_INET; + l->sin_valid = 1; + ++ if (type == SOCKS_CONNECT) { ++ l->connect_done = 1; ++ } else if (type == SOCKS_BIND) { ++ l->bind_done = 1; ++ } ++ + return 0; + break; + default: +@@ -627,9 +668,20 @@ + struct sockaddr_in *sin=(struct sockaddr_in *)usin; + + if (size == sizeof(struct sockaddr_in) && sin->sin_family == AF_INET) { ++ register infot *l=find_sock(sock); + _SOCKS_last_connect=*sin; +- return _SOCKS_cbind(sock,sin,size, +- sin->sin_addr.s_addr,SOCKS_CONNECT); ++ if (l == NULL || !l->connect_done) { ++ return _SOCKS_cbind(sock,sin,size, ++ sin->sin_addr.s_addr, ++ SOCKS_CONNECT); ++ l=find_sock(sock); ++ if (l) { ++ l->connect_done = 1; ++ } ++ } else { ++ errno = EISCONN; ++ return -1; ++ } + } else { + register infot *l=find_sock(sock); + if (l!=NULL) +@@ -713,10 +765,10 @@ + } + + #ifdef PROTOTYPES +-int Rrecvfrom(int s,char *m,int len,int f,struct sockaddr_in *from,int *size) ++int Rrecvfrom(int s,char *m,size_t len,int f,struct sockaddr_in *from,int *size) + #else + int Rrecvfrom(s,m,len,f,from,size) +-int s;char *m;int len;int f;struct sockaddr_in *from;int *size; ++int s;char *m;size_t len;int f;struct sockaddr_in *from;int *size; + #endif + { + infot *l=find_sock(s); +@@ -758,10 +810,10 @@ + } + + #ifdef PROTOTYPES +-int Rrecv(int s,char *m,int len,int f) ++int Rrecv(int s,char *m,size_t len,int f) + #else + int Rrecv(s,m,len,f) +-int s;char *m;int len;int f; ++int s;char *m;size_t len;int f; + #endif + { + struct sockaddr_in from; +@@ -771,10 +823,10 @@ + } + + #ifdef PROTOTYPES +-int Rsendto(int s,char *m,int len,int f,struct sockaddr_in *to,int size) ++int Rsendto(int s,char *m,size_t len,int f,struct sockaddr_in *to,int size) + #else + int Rsendto(s,m,len,f,to,size) +-int s;char *m;int len;int f;struct sockaddr_in *to;int size; ++int s;char *m;size_t len;int f;struct sockaddr_in *to;int size; + #endif + { + infot *l=find_sock(s); +@@ -805,10 +857,10 @@ + return _SOCKS_write(s,m,len); + } + #ifdef PROTOTYPES +-int Rsend(int s,char *m,int len,int f) ++int Rsend(int s,char *m,size_t len,int f) + #else + int Rsend(s,m,len,f) +-int s;char *m;int len;int f; ++int s;char *m;size_t len;int f; + #endif + { + infot *l=find_sock(s); +@@ -877,17 +929,28 @@ + fd_set fds; + Socks_t dst; + infot *l=find_sock(sock); ++ int nfds; ++ struct timeval timeout, *tptr=NULL; ++ int flags; + ++ errno = 0; + if (l == NULL || !l->sin_valid) + return Xaccept(sock,sin,size); + + /* if we found the entry, bind or connect was called, so no + SOCKSinit is needed. */ + ++ flags = fcntl(sock, F_GETFL, 0); ++ if (flags != -1 && (flags & O_NONBLOCK)) { ++ timeout.tv_sec = 0; ++ timeout.tv_usec = 0; ++ tptr = &timeout; ++ } ++ + FD_ZERO(&fds); + FD_SET(sock, &fds); + +- if (select(sock+1, (int*)&fds, NULL, NULL, NULL) > 0) ++ if ((nfds = select(sock+1, &fds, NULL, NULL, tptr)) > 0) { + if (FD_ISSET(sock, &fds)) { + if (GetDst(sock, &dst) < 0) + return -1; +@@ -901,6 +964,9 @@ + + return dup(sock); + } ++ } ++ if (nfds == 0) ++ errno = EWOULDBLOCK; + return -1; + } + #ifdef PROTOTYPES diff --git a/lang/modula-3-socks/files/read.c b/lang/modula-3-socks/files/read.c new file mode 100644 index 000000000000..2172d2b73661 --- /dev/null +++ b/lang/modula-3-socks/files/read.c @@ -0,0 +1,15 @@ +#include "wrap.h" +#include <sys/types.h> +#include <unistd.h> + +ssize_t +m3_read(int d, void *buf, size_t nbytes) +{ + int result; + + ENTER_CRITICAL; + MAKE_WRITABLE(buf); + result = read(d, buf, nbytes); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/files/recv.c b/lang/modula-3-socks/files/recv.c new file mode 100644 index 000000000000..bf4729092b70 --- /dev/null +++ b/lang/modula-3-socks/files/recv.c @@ -0,0 +1,15 @@ +#include "wrap.h" +#include <sys/types.h> +#include <sys/socket.h> + +ssize_t +m3_recv(int s, void *buf, size_t len, int flags) +{ + int result; + + ENTER_CRITICAL; + MAKE_WRITABLE(buf); + result = recv(s, buf, len, flags); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/files/recvfrom.c b/lang/modula-3-socks/files/recvfrom.c new file mode 100644 index 000000000000..d4a346b3d86d --- /dev/null +++ b/lang/modula-3-socks/files/recvfrom.c @@ -0,0 +1,18 @@ +#include "wrap.h" +#include <sys/types.h> +#include <sys/socket.h> + +ssize_t +m3_recvfrom(int s, void *buf, size_t len, int flags, + struct sockaddr *from, int *fromlen) +{ + int result; + + ENTER_CRITICAL; + MAKE_WRITABLE(buf); + MAKE_WRITABLE(from); + MAKE_WRITABLE(fromlen); + result = recvfrom(s, buf, len, flags, from, fromlen); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/files/select.c b/lang/modula-3-socks/files/select.c new file mode 100644 index 000000000000..a3602472ce7a --- /dev/null +++ b/lang/modula-3-socks/files/select.c @@ -0,0 +1,20 @@ +#include "wrap.h" +#include <sys/types.h> +#include <sys/time.h> +#include <unistd.h> + +int +m3_select(int nfds, fd_set *readfds, fd_set *writefds, + fd_set *exceptfds, struct timeval *timeout) +{ + int result; + + ENTER_CRITICAL; + MAKE_WRITABLE(readfds); + MAKE_WRITABLE(writefds); + MAKE_WRITABLE(exceptfds); + MAKE_READABLE(timeout); + result = select(nfds, readfds, writefds, exceptfds, timeout); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/files/send.c b/lang/modula-3-socks/files/send.c new file mode 100644 index 000000000000..20608ab0d402 --- /dev/null +++ b/lang/modula-3-socks/files/send.c @@ -0,0 +1,15 @@ +#include "wrap.h" +#include <sys/types.h> +#include <sys/socket.h> + +ssize_t +m3_send(int s, const void *msg, size_t len, int flags) +{ + int result; + + ENTER_CRITICAL; + MAKE_READABLE(msg); + result = send(s, msg, len, flags); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/files/sendto.c b/lang/modula-3-socks/files/sendto.c new file mode 100644 index 000000000000..30edf8aed4ed --- /dev/null +++ b/lang/modula-3-socks/files/sendto.c @@ -0,0 +1,17 @@ +#include "wrap.h" +#include <sys/types.h> +#include <sys/socket.h> + +ssize_t +m3_sendto(int s, const void *msg, size_t len, int flags, + const struct sockaddr *to, int tolen) +{ + int result; + + ENTER_CRITICAL; + MAKE_READABLE(msg); + MAKE_READABLE(to); + result = sendto(s, msg, len, flags, to, tolen); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/files/shutdown.c b/lang/modula-3-socks/files/shutdown.c new file mode 100644 index 000000000000..828d25e9a131 --- /dev/null +++ b/lang/modula-3-socks/files/shutdown.c @@ -0,0 +1,14 @@ +#include "wrap.h" +#include <sys/types.h> +#include <sys/socket.h> + +int +m3_shutdown(int s, int how) +{ + int result; + + ENTER_CRITICAL; + result = shutdown(s, how); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/files/socket.c b/lang/modula-3-socks/files/socket.c new file mode 100644 index 000000000000..64dcae3737d1 --- /dev/null +++ b/lang/modula-3-socks/files/socket.c @@ -0,0 +1,14 @@ +#include "wrap.h" +#include <sys/types.h> +#include <sys/socket.h> + +int +m3_socket(int domain, int type, int protocol) +{ + int result; + + ENTER_CRITICAL; + result = socket(domain, type, protocol); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/files/socksconf.h b/lang/modula-3-socks/files/socksconf.h new file mode 100644 index 000000000000..033c831f4cba --- /dev/null +++ b/lang/modula-3-socks/files/socksconf.h @@ -0,0 +1,6 @@ +/* + * Define 0 or 1 of these, to select the variety of SOCKS support you want. + */ +#define HPSOCKS +#undef SOCKS4 +#undef SOCKS5 diff --git a/lang/modula-3-socks/files/wrap.h b/lang/modula-3-socks/files/wrap.h new file mode 100644 index 000000000000..1199c604ccfc --- /dev/null +++ b/lang/modula-3-socks/files/wrap.h @@ -0,0 +1,61 @@ +#include "socksconf.h" + +#if defined(HPSOCKS) /* { */ + #define accept Raccept + #define bind Rxbind + #define close Rclose + #define connect Rconnect + #define dup Rdup + #define dup2 Rdup2 + #define gethostbyaddr Rgethostbyaddr + #define gethostbyname Rgethostbyname + #define getpeername Rgetpeername + #define getsockname Rgetsockname + #define listen Rlisten + #define recv Rrecv + #define recvfrom Rrecvfrom + #define send Rsend + #define sendto Rsendto + #define shutdown Rshutdown + #define socket Rsocket +#elif defined(SOCKS4) /* } { */ + #define accept Raccept + #define bind Rbind + #define connect Rconnect + #define getpeername Rgetpeername + #define getsockname Rgetsockname + #define listen Rlisten + #define select Rselect +#elif defined(SOCKS5) /* } { */ + #define accept SOCKSaccept + #define bind SOCKSbind + #define close SOCKSclose + #define connect SOCKSconnect + #define dup SOCKSdup + #define dup2 SOCKSdup2 + #define fclose SOCKSfclose + #define gethostbyname SOCKSgethostbyname + #define getpeername SOCKSgetpeername + #define getsockname SOCKSgetsockname + #define listen SOCKSlisten + #define read SOCKSread + #define recv SOCKSrecv + #define recvfrom SOCKSrecvfrom + #define rresvport SOCKSrresvport + #define select SOCKSselect + #define send SOCKSsend + #define sendto SOCKSsendto + #define shutdown SOCKSshutdown + #define write SOCKSwrite +#endif /* } */ + +extern int RT0u__inCritical; +#define ENTER_CRITICAL RT0u__inCritical++ +#define EXIT_CRITICAL RT0u__inCritical-- + +static char RTHeapDepC__c; +#define MAKE_READABLE(x) \ + if ((int)x) { RTHeapDepC__c = *(char*)(x); } + +#define MAKE_WRITABLE(x) \ + if ((int)x) { *(char*)(x) = RTHeapDepC__c = *(char*)(x); } diff --git a/lang/modula-3-socks/files/write.c b/lang/modula-3-socks/files/write.c new file mode 100644 index 000000000000..fc9412ea0774 --- /dev/null +++ b/lang/modula-3-socks/files/write.c @@ -0,0 +1,15 @@ +#include "wrap.h" +#include <sys/types.h> +#include <unistd.h> + +size_t +m3_write(int fd, const void *buf, int nbytes) +{ + int result; + + ENTER_CRITICAL; + MAKE_READABLE(buf); + result = write(fd, buf, nbytes); + EXIT_CRITICAL; + return result; +} diff --git a/lang/modula-3-socks/pkg-comment b/lang/modula-3-socks/pkg-comment new file mode 100644 index 000000000000..4a8655717719 --- /dev/null +++ b/lang/modula-3-socks/pkg-comment @@ -0,0 +1 @@ +SOCKS support for Modula-3 programs. diff --git a/lang/modula-3-socks/pkg-descr b/lang/modula-3-socks/pkg-descr new file mode 100644 index 000000000000..fdbf96cc3c6c --- /dev/null +++ b/lang/modula-3-socks/pkg-descr @@ -0,0 +1,7 @@ +This provides SOCKS support for Modula-3 network applications. It is +based on the H-P SOCKS library, with modifications developed by Darryl +Okahata to support Modula-3's thread package. It uses version 4 of the +SOCKS protocol, which is compatible with both version 4 and version 5 +SOCKS servers. + +jdp@freebsd.org diff --git a/lang/modula-3-socks/pkg-plist b/lang/modula-3-socks/pkg-plist new file mode 100644 index 000000000000..980d2ad0ad55 --- /dev/null +++ b/lang/modula-3-socks/pkg-plist @@ -0,0 +1,5 @@ +bin/m3socks +lib/m3/FreeBSD2/libm3socks.so +man/man1/m3socks.1.gz +man/man5/m3socks.conf.5.gz +@exec if [ ! -f %D/etc/m3socks.conf ]; then echo "Please create a configuration file in %D/etc/m3socks.conf"; echo "Read m3socks.conf(5) for details"; fi diff --git a/lang/modula-3-socks/scripts/configure b/lang/modula-3-socks/scripts/configure new file mode 100644 index 000000000000..0016fb236bb0 --- /dev/null +++ b/lang/modula-3-socks/scripts/configure @@ -0,0 +1,13 @@ +#! /bin/sh + +files="SOCKS-SOURCE/h/socksdef.h \ + m3socks/m3socks.sh \ + m3socks/m3socks.1 \ + m3socks/m3socks.conf.5" + +cd ${WRKSRC} +for i in ${files}; do + test -f $i.bak || cp $i $i.bak + chmod +w $i + sed "s|/usr/local/|${PREFIX}/|g" $i.bak > $i && rm -f $i.bak +done |