diff options
Diffstat (limited to 'network/socks/socks.cstc.4.2/lib')
-rw-r--r-- | network/socks/socks.cstc.4.2/lib/Makefile | 113 | ||||
-rw-r--r-- | network/socks/socks.cstc.4.2/lib/Rconnect.c | 867 | ||||
-rw-r--r-- | network/socks/socks.cstc.4.2/lib/Rrcmd.c | 254 | ||||
-rw-r--r-- | network/socks/socks.cstc.4.2/lib/SendGetDst.c | 102 | ||||
-rw-r--r-- | network/socks/socks.cstc.4.2/lib/check_cconf.c | 258 | ||||
-rw-r--r-- | network/socks/socks.cstc.4.2/lib/check_user.c | 175 | ||||
-rw-r--r-- | network/socks/socks.cstc.4.2/lib/getpass.c | 128 | ||||
-rw-r--r-- | network/socks/socks.cstc.4.2/lib/percent_x.c | 110 | ||||
-rw-r--r-- | network/socks/socks.cstc.4.2/lib/porttoserv.c | 20 | ||||
-rw-r--r-- | network/socks/socks.cstc.4.2/lib/saddrtoname.c | 19 | ||||
-rw-r--r-- | network/socks/socks.cstc.4.2/lib/shell_cmd.c | 112 |
11 files changed, 0 insertions, 2158 deletions
diff --git a/network/socks/socks.cstc.4.2/lib/Makefile b/network/socks/socks.cstc.4.2/lib/Makefile deleted file mode 100644 index 5c742544..00000000 --- a/network/socks/socks.cstc.4.2/lib/Makefile +++ /dev/null @@ -1,113 +0,0 @@ -#CC=gcc - -# Define RCMD and SUPPORT_RCMD if you want to use the library -# for rlogin, rsh, and rcp. -SUPPORT_RCMD=-DSUPPORT_RCMD -RCMD=Rrcmd.o - -# Comment out next macro to produce library compatible with -# clients SOCKSified for SOCKS.CSTC 4.1 and 4.0 -SHORTENED_RBIND=-DSHORTENED_RBIND - -# You should not have to define the next macro -#NO_GUESSING_REMHOST=-DNO_GUESSING_REMHOST - -# Directory into which socks_clients's man page files will be installed: -MAN_DEST_DIR=/usr/local/man - -# If you want to install the SOCKS library into /usr/locallib, -# uncomment the next line: -#LIB_DEST_DIR=/usr/locallib -# Installing the library in /usr/locallib makes it possible to -# use '-lsocks' with cc or ld command to search the library. -# /usr/lib and /lib may also be used instead of /usr/local/lib. - -# Remember to include -Dindex=strchr in OTHER_CFLAGS if -# you don't have index() (Sys-V camp) - -# SunOS should use -OTHER_CFLAGS= $(SHORTENED_RBIND) -#RANLIB=ranlib - -# IRIX should use -#OTHER_CFLAGS=-cckr $(SHORTENED_RBIND) -#RANLIB=/bin/true - -# AIX should use -#OTHER_CFLAGS=-D_BSD -D_NONSTD_TYPES -D_NO_PROTO -DAIX $(SHORTENED_RBIND) -#RANLIB=ranlib - -#For SOLARIS -#OTHER_CFLAGS=-DSOLARIS -Dindex=strchr -Drindex=strrchr -DUSE_DIRENT $(SHORTENED_RBIND) -#RANLIB=/bin/true - -# Interactive Systems Unix should use -# OTHER_CFLAGS = -DISC $(SHORTENED_RBIND) - -# LINUX should use -#CC=gcc -#RESOLV_LIB= -#OTHER_CFLAGS=-traditional -DLINUX $(SHORTENED_RBIND) - -# UnixWare should use -#RESOLV_LIB=-lresolv -lnsl -lsocket -#OTHER_CFLAGS= -DSOLARIS -Dindex=strchr -Drindex=strrchr -DUSE_DIRENT $(SHORTENED_RBIND) -#RANLIB=/bin/true -#INSTALL=bsdinstall - -# >>>---------------- Others: - -RANLIB=ranlib -# Systems that do not need (and thus don't have) ranlib should use -#RANLIB=/bin/true - -# <<<---------------- - -OPTIMIZE=-g -CFLAGS = -I../include ${OPTIMIZE} ${OTHER_CFLAGS} ${SUPPORT_RCMD} ${NO_GUESSING_REMHOST} - -# Comment out defintion of GETPASS if your system has problem -# compiling it. The version built into your system will be used. -# The getpass() function in most Unix systems truncate password -# after 8 characters; the version provided here does not. -# This only affects telnet and ftp with non-anonymous login. -# Ftp with anonymous login allows long passwords regardless -# of whether GETPASS is defined or not. -GETPASS=getpass.o - -# The 'install' command is assumed to be the BSD variety (using -m to -# set the file mode). If the default 'install' on your system doesn't -# do that, you have to either specify an alternative one in the line below -# (e.g., bsdinstall or /usr/ucb/install) or modify the install instructions. -INSTALL= install - -#============================================================================== - -OBJS = Rconnect.o SendGetDst.o saddrtoname.o porttoserv.o check_cconf.o \ - percent_x.o shell_cmd.o check_user.o $(GETPASS) $(RCMD) -SRCS = Rconnect.c SendGetDst.c saddrtoname.c porttoserv.c check_cconf.c \ - percent_x.c shell_cmd.c check_user.c getpass.c -INC =../include/socks.h -LIB = libsocks.a - -all: echocwd $(LIB) - -$(LIB): $(OBJS) $(INC) - rm -f $(LIB) - ar rc $(LIB) $(OBJS) - $(RANLIB) $(LIB) - -install: echocwd $(LIB) - -if [ -d $(LIB_DEST_DIR) ]; then \ - ($(INSTALL) -m 644 $(LIB) $(LIB_DEST_DIR); \ - $(RANLIB) -t $(LIB_DEST_DIR)/$(LIB)); fi - -install.man: echocwd - $(INSTALL) -m 444 ../doc/socks_clients.1 $(MAN_DEST_DIR)/man1 - $(INSTALL) -m 444 ../doc/socks.conf.5 $(MAN_DEST_DIR)/man5 - -clean: echocwd - rm -f $(OBJS) $(LIB) core - -echocwd: - @pwd diff --git a/network/socks/socks.cstc.4.2/lib/Rconnect.c b/network/socks/socks.cstc.4.2/lib/Rconnect.c deleted file mode 100644 index 460bbed8..00000000 --- a/network/socks/socks.cstc.4.2/lib/Rconnect.c +++ /dev/null @@ -1,867 +0,0 @@ -#include <sys/types.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <sys/errno.h> -#include <stdio.h> -#include <netdb.h> -#include <arpa/nameser.h> -#include <resolv.h> -#include <pwd.h> -#include <syslog.h> -#if (defined(sun) && !defined(SOLARIS)) || defined(sgi) -#include <strings.h> -#else -#include <string.h> -#endif -#include "socks.h" -#ifdef LINUX -#include <linux/time.h> -#endif - -/* >>> K. Shackelford */ -#if defined(hpux) || defined(ultrix) || defined (__NetBSD__) || defined(AIX) || defined(__bsdi__) || defined(SCO) -extern int h_errno; -#endif -/* <<< K.Shackelford */ - -#include <signal.h> -#include <sys/wait.h> - -#define NAMELEN 128 -char socks_dst_name[NAMELEN], socks_dst_serv[NAMELEN]; -char socks_src_name[NAMELEN], socks_src_user[NAMELEN], socks_real_user[NAMELEN]; -char *socks_def_server; -char *socks_server; -char *socks_serverlist; - -char socks_cmd[] = "connect"; - -extern int errno; -extern char *getenv(); -extern char *getlogin(); -static struct sockaddr_in cursin; -u_int32 SocksHost; -static unsigned short socks_port; -static int socks_conn_sock = 0; -static int socks_conn_init = 0; -static unsigned short socks_conn_port = 0; -static u_int32 socks_conn_host = 0; -static int socks_conn_code = 0; -static unsigned short socks_last_conn_port = 0; -static u_int32 socks_last_conn_host = 0; -static int socks_init_done = 0; - -struct sockaddr_in socks_nsin; -static struct sockaddr_in me; -static struct passwd *pw; -static int direct = 0; - -extern char *porttoserv(); -extern char *saddrtoname(); - - -int check_result(code) -char code; -{ - switch (code) { - case SOCKS_FAIL: -/* - errno = ETIMEDOUT; -*/ - errno = ECONNREFUSED; - return -1; - case SOCKS_NO_IDENTD: - errno = ECONNREFUSED; - fprintf(stderr, "Error: SOCKS proxy server cannot connect to identd on your machine.\n"); - return -1; - case SOCKS_BAD_ID: - errno = ECONNREFUSED; - fprintf(stderr, "Error: user-id does not agree with the one reported by identd on your machine.\n"); - return -1; - default: - return 0; - } -} - -/* - SOCKSinit() must be called once in the application program. - */ - -SOCKSinit(Progname) -char *Progname; /* name of the calling program, "rfinger", "rftp", etc. */ -{ -#ifdef SOCKS_DEFAULT_NS - static char defaultNS[] = SOCKS_DEFAULT_NS; -#endif -#ifdef SOCKS_DEFAULT_DNAME - static char defaultDNAME[] = SOCKS_DEFAULT_DNAME; -#endif - static char defaultSERVER[] = SOCKS_DEFAULT_SERVER; - char *cp, *ns, *dp; - struct hostent *hp; - struct servent *sp; - int v,uid; - -/* >>> YDL 94/01/25 */ - if (socks_init_done) - return; - socks_init_done = 1; -/* <<< YDL 94/01/25 */ - socks_port = htons(SOCKS_DEF_PORT); - - bzero((char *)&cursin, sizeof(cursin)); - bzero((char *)&socks_nsin, sizeof(socks_nsin)); - bzero((char *)&me, sizeof(me)); - /* skip the path if included in Progname */ - if( (cp = rindex(Progname, '/')) == NULL) - cp = Progname; - else - cp++; - -#ifndef LOG_DAEMON - (void) openlog(cp, LOG_PID); -#else - (void) openlog(cp, LOG_PID, SYSLOG_FAC); -#endif - - gethostname(socks_src_name, sizeof(socks_src_name)); - if ( (hp = gethostbyname(socks_src_name)) == NULL ) { - fprintf (stderr, "gethostbyname(%s): error #%d\n", - socks_src_name, h_errno); - return (1); - } - bcopy(hp->h_addr_list[0], &me.sin_addr.s_addr, hp->h_length); - -#if !defined(DNS_THROUGH_NIS) - - if ((ns = getenv("SOCKS_NS")) == NULL) { -#ifdef SOCKS_DEFAULT_NS - ns = defaultNS; -#else - ; -#endif - } - if ((dp = getenv("SOCKS_DNAME")) == NULL) { -#ifdef SOCKS_DEFAULT_DNAME - dp = defaultDNAME; -#else - ; -#endif - } - - if ((ns != NULL) || (dp != NULL)) { - res_init(); -#ifdef sgi - sethostresorder("local:nis:bind"); -#endif - } - - if (ns != NULL) { -#ifdef ultrix - _res.ns_list[0].addr.sin_addr.s_addr = inet_addr(ns); -#else - _res.nsaddr_list[0].sin_addr.s_addr = inet_addr(ns); -#endif - _res.nscount = 1; - } - if (dp != NULL) { - strncpy(_res.defdname, dp, sizeof(_res.defdname)-1); - } - -/* >>> jon r. luini <jonl@hal.com> */ -/* -#ifdef SOCKS_DEFAULT_DNAME - bzero (_res.defdname, sizeof (_res.defdname)); - - if ( (cp = getenv("SOCKS_DNAME")) != NULL ) - { - strncpy (_res.defdname, cp, sizeof (_res.defdname)-1); - } - else - { - strncpy (_res.defdname, SOCKS_DEFAULT_DNAME, - sizeof (_res.defdname)-1); - } -#endif -*/ -/* <<< jon r. luini <jonl@hal.com> */ - -#endif /* #if !defined(DNS_THROUGH_NIS) */ - - if ((socks_def_server = getenv("SOCKS_SERVER")) == NULL) - socks_def_server = defaultSERVER; - socks_server = socks_def_server; - if ((cp = getenv("SOCKS_BANNER")) != NULL) { - fprintf(stderr, "CSTC version %s SOCKS client. Default SOCKS server: %s\n", - CSTC_RELEASE, socks_def_server); - } - - if ((hp = gethostbyname(socks_server)) == NULL) { - SocksHost = inet_addr(socks_server); - } else { - bcopy(hp->h_addr_list[0], &SocksHost, hp->h_length); - } - - if ((sp = getservbyname("socks", "tcp")) != NULL) - socks_port = sp->s_port; - - if ((cp = getlogin()) == NULL) { - if ((pw = getpwuid(uid=getuid())) == NULL) { - fprintf(stderr, "Unknown user-id %d\n",uid); - return (1); - } - cp = pw->pw_name; - } - strncpy(socks_real_user, cp, sizeof(socks_real_user)); - - if ((pw = getpwuid(uid=geteuid())) == NULL) { - fprintf(stderr, "Unknown user-id %d\n",uid); - return (1); - } - strncpy(socks_src_user, pw->pw_name, sizeof(socks_src_user)); - - socks_nsin.sin_family = AF_INET; - socks_nsin.sin_port = socks_port; - socks_nsin.sin_addr.s_addr = SocksHost; - -} - - -int connect_sockd(sock, lport) -int sock; -int *lport; -/* returns 0 if successfully connected to a SOCKS server, - returns -1 otherwise - */ -{ -#ifndef VERSATILE_CLIENTS - if (connect(sock, &socks_nsin, sizeof(struct sockaddr_in)) == 0) - return 0; - else { - syslog(LOG_LOW, "Failed to connect to sockd at %s: %m", - socks_server); - return -1; - } -#else /* Now the version when VERSATILE_CLIENTS is defined */ - int last = 0; - int new_sock; - struct hostent *hp; - - while (socks_server = socks_serverlist) { - if (socks_serverlist = index(socks_serverlist, ',')) - *socks_serverlist++ = '\0'; - if ((hp = gethostbyname(socks_server)) == NULL) - socks_nsin.sin_addr.s_addr = inet_addr(socks_server); - else - bcopy(hp->h_addr_list[0], &socks_nsin.sin_addr, hp->h_length); - if (connect(sock, (struct sockaddr *)&socks_nsin, sizeof(struct sockaddr_in)) == 0) - return 0; - else { -#ifdef SVR4 - if ((errno == EISCONN) || (errno == EINPROGRESS) || (errno == EAGAIN)) -#else - if ((errno == EISCONN) || (errno == EINPROGRESS)) -#endif - return -1; - syslog(LOG_LOW, "Failed to connect to sockd at %s: %m", - socks_server); - if (!(socks_serverlist)) { - return -1; - } -#if defined(SUPPORT_RCMD) - if ((*lport < IPPORT_RESERVED) && (*lport >= IPPORT_RESERVED/2)) - new_sock = rresvport(lport); - else - new_sock = socket(PF_INET, SOCK_STREAM, 0); -#else /* SUPPORT_RCMD is not defined */ - new_sock = socket(PF_INET, SOCK_STREAM, 0); -#endif /* #if defined(SUPPORT_RCMD) */ - if (new_sock < 0) { - return -1; - } - if (dup2(new_sock, sock) < 0) { - close(new_sock); - return -1; - } else { - close(new_sock); - } - } - } - errno = ECONNREFUSED; - return -1; -#endif /* #ifndef VERSATILE_CLIENTS */ - -} - -static int send_src_user(s, user) -int s; -char *user; -{ - char *p = user; - int i, n, ret; - fd_set fds; - int fdsbits = s + 1; - struct timeval timeout; - - i = strlen(user) + 1; - while ( i > 0) { - FD_ZERO(&fds); - FD_SET(s, &fds); - timeout.tv_sec = 15; - timeout.tv_usec = 0; - if ((ret = select(fdsbits, NULL, &fds, NULL, &timeout)) < 0) { - return(-1); - } - if (ret == 0) - continue; - if((n = write(s, p, i)) <= 0) { - return(-2); - } - p += n; - i -= n; - } - return(0); -} - - -static int socksC_proto(s, dst) -int s; -Socks_t *dst; -{ - int sta; - - if ((sta = SendDst(s, dst)) < 0) { - if (sta == -1) - perror("select in SendDst"); - else - perror("write in SendDst"); - return(sta); - } - if ((sta = send_src_user(s, socks_src_user)) < 0) { - if (sta == -1) - perror("select in send_src_user"); - else - perror("write in send_src_user"); - return(sta); - } - if ((sta = GetDst(s, dst)) < 0) { - if (sta == -1) - perror("select in GetDst"); - else - perror("read in GetDst"); - return(sta); - } - return(0); -} - -static void quit_C_proto() -{ - exit(SOCKS_FAIL); -} - -static void do_C_proto(sock, port, addr) -int sock; -unsigned short port; -u_int32 addr; -{ - Socks_t dst; - - signal(SIGALRM, quit_C_proto); - alarm(CLIENT_CONN_TIMEOUT); - dst.version = SOCKS_VERSION; - dst.cmd = SOCKS_CONNECT; - dst.port = port; - dst.host = addr; - if (socksC_proto(sock, &dst) < 0) { - alarm(0); - exit(SOCKS_FAIL); - } - alarm(0); - if ((dst.cmd == SOCKS_FAIL) || (dst.cmd == SOCKS_NO_IDENTD) - || (dst.cmd == SOCKS_BAD_ID)) { - exit(dst.cmd); - } - exit(SOCKS_RESULT); - -} - - -Rconnect(sock, sin, size) -int sock; -struct sockaddr_in *sin; -int size; -{ - Socks_t dst; - int i; - int res_ret, con_ret, con_errno; - int lport = 0; - - int status, wait_ret, child_pid; - - if (socks_init_done == 0) - SOCKSinit("SOCKSclient"); -#ifdef DEBUG -fprintf(stderr, "Rconnect 10\n"); -fprintf(stderr,"socks_conn_sock=%d, socks_conn_host=%ld, socks_conn_port=%d, socks_conn_init=%d\n", socks_conn_sock, socks_conn_host, socks_conn_port, socks_conn_init); -fprintf(stderr,"sock=%d, sin->sin_addr.s_addr=%ld, sin->sin_port=%d\n", sock, sin->sin_addr.s_addr, sin->sin_port); -#endif /* #ifdef DEBUG */ - - if ((sock != socks_conn_sock) || (sin->sin_port != socks_conn_port) - || (sin->sin_addr.s_addr != socks_conn_host)) { - if (socks_conn_init) - kill(socks_conn_init, SIGKILL); - socks_conn_code = 0; - socks_conn_init = 0; - strcpy(socks_cmd, "connect"); - saddrtoname(&sin->sin_addr, socks_dst_name, sizeof(socks_dst_name)); - porttoserv(sin->sin_port, socks_dst_serv, sizeof(socks_dst_serv)); -#ifdef DEBUG -fprintf(stderr, "Rconnect 100, Rconnect(%d, %s, %s)\n", sock, socks_dst_name, socks_dst_serv); -#endif /* #ifdef DEBUG */ - } else if (status = socks_conn_code) { - socks_conn_init = 0; - socks_conn_code = 0; - socks_conn_sock = 0; - socks_conn_port = 0; - socks_conn_host = 0; - res_ret = check_result(status); - if (status == SOCKS_RESULT) { - errno = EISCONN; - socks_last_conn_host = sin->sin_addr.s_addr; - socks_last_conn_port = sin->sin_port; - } else { - syslog(LOG_LOW, "Connection failed.\n"); - } - return(-1); - } else if (socks_conn_init) { -#ifdef DEBUG -fprintf(stderr, "Rconnect 200, Rconnect(%d, %s, %s)\n", sock, socks_dst_name, socks_dst_serv); -#endif /* #ifdef DEBUG */ - wait_ret = waitpid(socks_conn_init, &status, WNOHANG); - if (wait_ret == 0) { - errno = EALREADY; -#ifdef DEBUG -fprintf(stderr, "Rconnect 300, ret=-1, errno=EALREADY\n"); -#endif /* #ifdef DEBUG */ - return(-1); - } else if (wait_ret == socks_conn_init) { - socks_conn_init = 0; - socks_conn_code = 0; - socks_conn_sock = 0; - socks_conn_port = 0; - socks_conn_host = 0; - if (status & 0x00ff) { - kill(socks_conn_init, SIGKILL); - errno = ECONNREFUSED; -#ifdef DEBUG -fprintf(stderr, "Rconnect 400, ret=-1, errno=ECONNREFUSED\n"); -#endif /* #ifdef DEBUG */ - syslog(LOG_LOW, "Connection failed.\n"); - return(-1); - } else { - status = (status >> 8) & 0x00ff; - res_ret = check_result(status); -#ifdef DEBUG -fprintf(stderr, "Rconnect 500, ret=%d, status=%d\n", res_ret, status); -#endif /* #ifdef DEBUG */ - if (res_ret == 0) { - errno = EISCONN; - socks_last_conn_host = sin->sin_addr.s_addr; - socks_last_conn_port = sin->sin_port; - } else { - syslog(LOG_LOW, "Connection failed.\n"); - } - return(-1); - } - } else { - kill(socks_conn_init, SIGKILL); - errno = ECONNREFUSED; -#ifdef DEBUG -fprintf(stderr, "Rconnect 600, ret=-1, errno=ECONNREFUSED\n"); -#endif /* #ifdef DEBUG */ - socks_conn_init = 0; - socks_conn_code = 0; - socks_conn_sock = 0; - socks_conn_port = 0; - socks_conn_host = 0; - syslog(LOG_LOW, "Connection failed.\n"); - return(-1); - } - } - -#ifdef DEBUG -fprintf(stderr, "Rconnect 700, Rconnect(%d, %s, %s)\n", sock, socks_dst_name, socks_dst_serv); -#endif /* #ifdef DEBUG */ - -#ifdef VERSATILE_CLIENTS - direct = check_cconf(&me, sin); -#ifdef DEBUG -fprintf(stderr, "Rconnect() 800: direct = %d\n", direct); -#endif /* #ifdef DEBUG */ - if (direct < 0) { - syslog(LOG_LOW, "refused -- connect() from %s(%s) to %s (%s)", - socks_src_user, socks_real_user, socks_dst_name, socks_dst_serv); - errno = ECONNREFUSED; -#ifdef DEBUG -fprintf(stderr, "Rconnect 900, ret=-1, errno=EALREADY\n"); -#endif /* #ifdef DEBUG */ - return(-1); - } - - if (direct == 1) { - syslog(LOG_LOW, "connect() directly from %s(%s) to %s (%s)", - socks_src_user, socks_real_user, socks_dst_name, socks_dst_serv); - con_ret = connect(sock, (struct sockaddr *)sin, size); - if (con_ret == 0) { - socks_last_conn_host = sin->sin_addr.s_addr; - socks_last_conn_port = sin->sin_port; - } -#ifdef DEBUG -fprintf(stderr, "Rconnect 1000, ret=%d, ", con_ret); -perror(" "); -#endif /* #ifdef DEBUG */ - return(con_ret); - } -#endif /* #ifdef VERSATILE_CLIENTS */ - - con_ret = connect_sockd(sock, &lport); -#ifdef DEBUG - fprintf(stderr, "con_ret=connect_sockd()=%d", con_ret); - if(con_ret < 0) - perror(""); - else - fprintf(stderr,"\n"); -#endif /* #ifdef DEBUG */ - if (con_ret == 0) { - syslog(LOG_LOW, "connect() from %s(%s) to %s (%s) using sockd at %s", - socks_src_user, socks_real_user, socks_dst_name, socks_dst_serv, socks_server); - dst.version = SOCKS_VERSION; - dst.cmd = SOCKS_CONNECT; - dst.port = sin->sin_port; - dst.host = sin->sin_addr.s_addr; - if (socksC_proto(sock, &dst) < 0) { - return(-1); - } - res_ret = check_result(dst.cmd); -#ifdef DEBUG -fprintf(stderr, "Rconnect 1100, ret=%d, ", res_ret); -perror(" "); -#endif /* #ifdef DEBUG */ - if (res_ret == 0) { - socks_last_conn_host = sin->sin_addr.s_addr; - socks_last_conn_port = sin->sin_port; - } - return(res_ret); - } - if ((con_ret < 0) && (errno != EINPROGRESS)) { -#ifdef DEBUG -fprintf(stderr, "Rconnect 1200, ret=%d, ", con_ret); -perror(" "); -#endif /* #ifdef DEBUG */ - return(-1); - } -/* - con_errno = errno; -*/ - syslog(LOG_LOW, "connect() from %s(%s) to %s (%s) using sockd at %s", - socks_src_user, socks_real_user, socks_dst_name, socks_dst_serv, socks_server); - - switch (child_pid = fork()) { - case -1: - perror("fork()"); - errno = ECONNREFUSED; -#ifdef DEBUG -fprintf(stderr, "Rconnect 1300, ret=-1, "); -perror(" "); -#endif /* #ifdef DEBUG */ - return(-1); - case 0: - do_C_proto(sock, sin->sin_port, sin->sin_addr.s_addr); - default: - socks_conn_init = child_pid; - socks_conn_code = 0; - socks_conn_sock = sock; - socks_conn_port = sin->sin_port; - socks_conn_host = sin->sin_addr.s_addr; - errno = EINPROGRESS; -#ifdef DEBUG -fprintf(stderr, "Rconnect 1400, ret=-1 "); -perror(" "); -#endif /* #ifdef DEBUG */ - return(-1); - } -} - -/* >>> YDL 94/01/25 */ -#ifdef SHORTENED_RBIND -Rbind(sock, sin, size) -int sock; -struct sockaddr_in *sin; -int size; -#else -/* -** Set up a bind for a remote host, add fill 'cursin' in with the -** remote server information. -** If using reserved port, the port must have already been reserved -** through a rresvport() call. -*/ -Rbind(sock, sin, size, dsthost) -int sock; -struct sockaddr_in *sin; -int size; -u_int32 dsthost; /* as in sin_addr.s_addr */ -#endif /* #ifdef SHORTENED_RBIND */ -/* <<< YDL 94/01/25 */ -{ - Socks_t dst; - struct sockaddr_in psin; - int i; - int new_sock, lport; - u_int32 remhost; - int con_ret; - struct timeval tmo; - fd_set fds; - - if (socks_init_done == 0) - SOCKSinit("SOCKSclient"); - bzero((char *)&psin, sizeof(psin)); - lport = ntohs(sin->sin_port); - strcpy(socks_cmd, "bind"); -#ifdef SHORTENED_RBIND -# ifdef NO_GUESSING_REMHOST - remhost = 0L; - strcpy(socks_dst_name, "Unspecified.Host"); -# else - remhost = socks_last_conn_host; - saddrtoname(&remhost, socks_dst_name, sizeof(socks_dst_name)); -# endif /* # ifdef NO_GUESSING_REMHOST */ -#else - remhost = dsthost; - saddrtoname(&remhost, socks_dst_name, sizeof(socks_dst_name)); -#endif /* #ifdef SHORTENED_RBIND */ - porttoserv(socks_last_conn_port, socks_dst_serv, sizeof(socks_dst_serv)); -#ifdef DEBUG -fprintf(stderr, "Rbind 100, lport=%u, socks_dst_name=>%s<, socks_dst_serv=>%s<\n", lport, socks_dst_name, socks_dst_serv); -fprintf(stderr, "Rbind(%d, %s, %s)\n", sock, socks_dst_name, socks_dst_serv); -#endif /* #ifdef DEBUG */ - - psin.sin_addr.s_addr = remhost; - psin.sin_port = socks_last_conn_port; -#ifdef VERSATILE_CLIENTS - direct = check_cconf(&me, &psin); -#ifdef DEBUG -fprintf(stderr, "Rbind() 200, direct = %d\n", direct); -#endif /* #ifdef DEBUG */ - if (direct < 0) { - syslog(LOG_LOW, "Refused -- bind() from %s(%s) for %s (%s)", - socks_src_user, socks_real_user, socks_dst_name, socks_dst_serv); - errno = ECONNREFUSED; - return -1; - } - - if (direct == 1) { - syslog(LOG_LOW, "bind() directly from %s(%s) for %s (%s)", - socks_src_user, socks_real_user, socks_dst_name, socks_dst_serv); -#ifdef DEBUG -fprintf(stderr,"Rbind() 300, direct=1, lport=%u\n", lport); -#endif /* #ifdef DEBUG */ -#if defined(SUPPORT_RCMD) - if ((lport >= IPPORT_RESERVED) || (lport < IPPORT_RESERVED/2)) - return (bind(sock, (struct sockaddr *)sin, size)); - else - return 0; -#else /* SUPPORT_RCMD not defined */ - return (bind(sock, (struct sockaddr *)sin, size)); -#endif /* #if defined(SUPPORT_RCMD) */ - } -#endif /* #ifdef VERSATILE_CLIENTS */ - - con_ret = connect_sockd(sock, &lport); - if (con_ret == 0) { - ; -#ifdef SVR4 - } else if ((errno == EINPROGRESS) || (errno == EAGAIN)) { -#else - } else if (errno == EINPROGRESS) { -#endif - while (1) { - tmo.tv_sec = 0; - tmo.tv_usec = 100000; - FD_ZERO(&fds); - FD_SET(sock, &fds); - select(sock+1, NULL, &fds, NULL, &tmo); - con_ret = connect(sock, (struct sockaddr *)&socks_nsin, sizeof(struct sockaddr_in)); - if ((con_ret < 0) && (errno == EISCONN)) { - con_ret = 0; - break; -#if defined(SVR4) - } else if ((con_ret < 0) && ((errno == EALREADY) || - (errno == EAGAIN))) { -#else /* !defined(SVR4) */ - } else if ((con_ret < 0) && (errno == EALREADY)) { -#endif /* #if defined(SVR4) */ - continue; - } else - break; - } - } - if (con_ret < 0) { - syslog(LOG_LOW, "Failed -- bind() from %s(%s) for %s (%s)", - socks_src_user, socks_real_user, socks_dst_name, socks_dst_serv); - errno = ECONNREFUSED; - return -1; - } - syslog(LOG_LOW, "bind() from %s(%s) for %s (%s) using sockd at %s", - socks_src_user, socks_real_user, socks_dst_name, socks_dst_serv, socks_server); - - dst.version = SOCKS_VERSION; - dst.cmd = SOCKS_BIND; - dst.port = socks_last_conn_port; - dst.host = remhost; - if (socksC_proto(sock, &dst) < 0) - return(-1); - cursin.sin_family = AF_INET; - cursin.sin_port = dst.port; - if (ntohl(dst.host) == INADDR_ANY) - cursin.sin_addr.s_addr = socks_nsin.sin_addr.s_addr; - else - cursin.sin_addr.s_addr = dst.host; -/* - fprintf(stderr,"Rbind interface: %s, port: %u\n", - inet_ntoa(cursin.sin_addr), htons(cursin.sin_port)); -*/ - - return (check_result(dst.cmd)); -} - -/* -** Stub routine since the listen will have alread succeded on the -** server. -*/ -Rlisten(s, n) -int s, n; -{ -#ifdef DEBUG - fprintf(stderr, "direct=%d, Rlisten(%d, %d)\n", direct, s, n); -#endif -#ifdef VERSATILE_CLIENTS - if (direct) - return (listen(s, n)); -#endif /* #ifdef VERSATILE_CLIENTS */ - - return 0; -} - -/* -** Well we know where we got a connection from. -*/ -Rgetsockname(sock, sin, size) -int sock; -struct sockaddr_in *sin; -int *size; -{ -#ifdef DEBUG - saddrtoname(&sin->sin_addr, socks_dst_name, sizeof(socks_dst_name)); - porttoserv(sin->sin_port, socks_dst_serv, sizeof(socks_dst_serv)); - fprintf(stderr, "direct= %d, Rgetsockname(%d, %s, %s)\n", - direct, sock, socks_dst_name, socks_dst_serv); -#endif -#ifdef VERSATILE_CLIENTS - if (direct) - return (getsockname(sock, (struct sockaddr *)sin, size)); -#endif /* #ifdef VERSATILE_CLIENTS */ - - *size = sizeof(struct sockaddr_in); - *sin = cursin; - - return 0; -} - -/* -** Do an accept, which is really a select for some data on -** the present socket. -*/ -Raccept(sock, sin, size) -int sock; -struct sockaddr_in *sin; -int *size; -{ - fd_set fds; - Socks_t dst; - int fdsbits = sock + 1; - -#ifdef DEBUG - fprintf(stderr, "direct= %d, Raccept(%d, sin, size)\n", - direct, sock); -#endif - -#ifdef VERSATILE_CLIENTS - if (direct) - return(accept(sock, (struct sockaddr *)sin, size)); -#endif /* #ifdef VERSATILE_CLIENTS */ - - FD_ZERO(&fds); - FD_SET(sock, &fds); - - if (select(fdsbits, &fds, NULL, NULL, NULL) > 0) - if (FD_ISSET(sock, &fds)) { - GetDst(sock, &dst); - sin->sin_family = AF_INET; - sin->sin_port = dst.port; - sin->sin_addr.s_addr = dst.host; - return(dup(sock)); - } - return -1; -} - -int Rselect(width, readfds, writefds, exceptfds, timeout) -int width; -fd_set *readfds, *writefds, *exceptfds; -struct timeval *timeout; -{ - int wait_ret, status; - - if(!socks_conn_init ) { - return(select(width, readfds, writefds, exceptfds, timeout)); - } - - if (readfds != NULL) - FD_CLR(socks_conn_sock, readfds); - if (exceptfds != NULL) - FD_CLR(socks_conn_sock, exceptfds); - if ((writefds == NULL) || !FD_ISSET(socks_conn_sock, writefds)) - return(select(width, readfds, writefds, exceptfds, timeout)); - - wait_ret = waitpid(socks_conn_init, &status, WNOHANG); - if (wait_ret == 0) { - FD_CLR(socks_conn_sock, writefds); - return(select(width, readfds, writefds, exceptfds, timeout)); - } else if (wait_ret == socks_conn_init) { -/* - socks_conn_init = 0; - socks_conn_sock = 0; - socks_conn_port = 0; - socks_conn_host = 0; -*/ - if (status & 0x00ff) { - kill(socks_conn_init, SIGKILL); - socks_conn_init = 0; - socks_conn_code = SOCKS_FAIL; - } else { - status = (status >> 8) & 0x00ff; - if (status == SOCKS_RESULT) { - socks_last_conn_host = socks_conn_host; - socks_last_conn_port = socks_conn_port; - } - socks_conn_init = 0; - socks_conn_code = status; - } - } else { - kill(socks_conn_init, SIGKILL); - socks_conn_init = 0; - socks_conn_code = SOCKS_FAIL; - } - - return(select(width, readfds, writefds, exceptfds, timeout)); -} diff --git a/network/socks/socks.cstc.4.2/lib/Rrcmd.c b/network/socks/socks.cstc.4.2/lib/Rrcmd.c deleted file mode 100644 index e08f91e3..00000000 --- a/network/socks/socks.cstc.4.2/lib/Rrcmd.c +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright (c) 1983 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -/*static char *sccsid = "from: @(#)rcmd.c 5.24 (Berkeley) 2/24/91";*/ -static char *rcsid = "$Id: rcmd.c,v 1.4 1993/12/05 14:42:26 deraadt Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <sys/socket.h> -#include <sys/stat.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <signal.h> -#include <fcntl.h> -#include <netdb.h> -#include <pwd.h> -#include <errno.h> -#include <stdio.h> -#include <ctype.h> -#include <unistd.h> -#include <string.h> - -Rrcmd(ahost, rport, locuser, remuser, cmd, fd2p) - char **ahost; - u_short rport; -/* - const char *locuser, *remuser, *cmd; -*/ - char *locuser, *remuser, *cmd; - int *fd2p; -{ - int s, timo = 1, pid; - long oldmask; - struct sockaddr_in sin, from; - char c; - int lport = IPPORT_RESERVED - 1; - struct hostent hoste; - struct hostent *hp; - fd_set reads; - - pid = getpid(); - hp = gethostbyname(*ahost); - if (hp == 0) { - herror(*ahost); - return (-1); - } - bcopy(hp, &hoste, sizeof(struct hostent)); - hp = &hoste; - *ahost = hp->h_name; - oldmask = sigblock(sigmask(SIGURG)); - for (;;) { -#ifdef DEBUG -fprintf(stderr, "Rrcmd 100, lport = %d\n", lport); -#endif /* #ifdef DEBUG */ - s = rresvport(&lport); -#ifdef DEBUG -fprintf(stderr, "Rrcmd 200, s = %d\n", s); -#endif /* #ifdef DEBUG */ - if (s < 0) { - if (errno == EAGAIN) - fprintf(stderr, "socket: All ports in use\n"); - else - perror("rcmd: socket"); - sigsetmask(oldmask); - return (-1); - } -#ifdef DEBUG -fprintf(stderr, "Rrcmd 300\n"); -#endif /* #ifdef DEBUG */ -#if defined(hpux) - ioctl(s, FIOSSAIOOWN, pid); -#else /* hpux not defined */ - fcntl(s, F_SETOWN, pid); -#endif /* #if defined(hpux) */ - bzero((char *)&sin, sizeof sin); - sin.sin_family = hp->h_addrtype; - bcopy(hp->h_addr_list[0], (caddr_t)&sin.sin_addr, hp->h_length); - sin.sin_port = rport; -#ifdef DEBUG -fprintf(stderr, "Rrcmd 400, sin.sin_family=%d, sin.sin_port=%u, sin.sin_addr=%s\n",sin.sin_family, ntohs(sin.sin_port), inet_ntoa(sin.sin_addr)); -#endif /* #ifdef DEBUG */ - if (Rconnect(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) - break; -#ifdef DEBUG -fprintf(stderr, "Rrcmd 500, Rconnect failed\n"); -#endif /* #ifdef DEBUG */ - (void) close(s); - if (errno == EADDRINUSE) { - lport--; - continue; - } - if (errno == ECONNREFUSED && timo <= 16) { - sleep(timo); - timo *= 2; - continue; - } - if (hp->h_addr_list[1] != NULL) { - int oerrno = errno; - - fprintf(stderr, - "connect to address %s: ", inet_ntoa(sin.sin_addr)); - errno = oerrno; - perror(0); - hp->h_addr_list++; - bcopy(hp->h_addr_list[0], (caddr_t)&sin.sin_addr, - hp->h_length); - fprintf(stderr, "Trying %s...\n", - inet_ntoa(sin.sin_addr)); - continue; - } - perror(hp->h_name); - sigsetmask(oldmask); - return (-1); - } - lport--; -#ifdef DEBUG -fprintf(stderr, "Rrcmd 600, f2dp=%u\n", fd2p); -#endif /* #ifdef DEBUG */ - if (fd2p == 0) { - write(s, "", 1); - lport = 0; - } else { - char num[8]; - int s2 = rresvport(&lport), s3; - int len = sizeof (from); - struct sockaddr_in tsin; - int tlen = sizeof(tsin); - -#ifdef DEBUG -fprintf(stderr, "Rrcmd 650, lport=%u\n", lport); -#endif /* #ifdef DEBUG */ - if (s2 < 0) - goto bad; - tsin.sin_family = AF_INET; - tsin.sin_addr.s_addr = INADDR_ANY; - tsin.sin_port = htons((u_short)lport); -/* - s2 = socket(AF_INET, SOCK_STREAM, 0); -*/ - if (Rbind(s2, (struct sockaddr *)&tsin, sizeof(tsin), - sin.sin_addr.s_addr) < 0) { - perror("Rrcmd: Rbind() "); - (void) close(s2); - goto bad; - } - if (Rgetsockname(s2, (struct sockaddr *)&tsin, &tlen) < 0) { - perror("Rrcmd: Rgetsockname() "); - (void) close(s2); - goto bad; - } - Rlisten(s2, 1); -/* - (void) sprintf(num, "%d", lport); -*/ - (void) sprintf(num, "%u", ntohs(tsin.sin_port)); -#ifdef DEBUG -fprintf(stderr,"Rrcmd 800, num=>%s<\n", num); -#endif /* #ifdef DEBUG */ - if (write(s, num, strlen(num)+1) != strlen(num)+1) { - perror("write: setting up stderr"); - (void) close(s2); - goto bad; - } - FD_ZERO(&reads); - FD_SET(s, &reads); - FD_SET(s2, &reads); - errno = 0; - if (select(32, &reads, 0, 0, 0) < 1 || - !FD_ISSET(s2, &reads)) { - if (errno != 0) - perror("select: setting up stderr"); - else - fprintf(stderr, - "select: protocol failure in circuit setup.\n"); - (void) close(s2); - goto bad; - } -#ifdef DEBUG -fprintf(stderr,"Rrcmd 900, before Raccept()\n"); -#endif /* #ifdef DEBUG */ - s3 = Raccept(s2, (struct sockaddr *)&from, &len); - (void) close(s2); - if (s3 < 0) { - perror("accept"); - lport = 0; - goto bad; - } - *fd2p = s3; - from.sin_port = ntohs((u_short)from.sin_port); - if (from.sin_family != AF_INET || - from.sin_port >= IPPORT_RESERVED || - from.sin_port < IPPORT_RESERVED / 2) { - fprintf(stderr, - "socket: protocol failure in circuit setup.\n"); - goto bad2; - } - } - (void) write(s, locuser, strlen(locuser)+1); - (void) write(s, remuser, strlen(remuser)+1); - (void) write(s, cmd, strlen(cmd)+1); - if (read(s, &c, 1) != 1) { - perror(*ahost); - goto bad2; - } - if (c != 0) { - while (read(s, &c, 1) == 1) { - (void) write(2, &c, 1); - if (c == '\n') - break; - } - goto bad2; - } - sigsetmask(oldmask); - return (s); -bad2: - if (lport) - (void) close(*fd2p); -bad: - (void) close(s); - sigsetmask(oldmask); - return (-1); -} - diff --git a/network/socks/socks.cstc.4.2/lib/SendGetDst.c b/network/socks/socks.cstc.4.2/lib/SendGetDst.c deleted file mode 100644 index e119324a..00000000 --- a/network/socks/socks.cstc.4.2/lib/SendGetDst.c +++ /dev/null @@ -1,102 +0,0 @@ -#include <sys/types.h> -#include <sys/time.h> -#include "socks.h" -#if defined(DEBUG) -#include <sys/errno.h> -extern int errno; -#endif - -#define NULL ((char *)0) - -int SendDst(s, dst) -int s; -Socks_t *dst; -{ - char c[sizeof(Socks_t)]; - char *p = c; - int i = sizeof(Socks_t), n, ret; - fd_set fds; - int fdsbits = s + 1; - struct timeval timeout; - - c[0] = dst->version; - c[1] = dst->cmd; - bcopy(&dst->port, c+2, sizeof(dst->port)); - bcopy(&dst->host, c+2+sizeof(dst->port), sizeof(dst->host)); - - while ( i > 0) { - FD_ZERO(&fds); - FD_SET(s, &fds); - timeout.tv_sec = 15; - timeout.tv_usec = 0; - while ((ret = select(fdsbits, NULL, &fds, NULL, &timeout)) < 0) { -/* - perror("select in SendDst"); - exit(-1); -*/ -#if defined(DEBUG) - if (errno != EINTR) -#endif - return(-1); - } - if (ret == 0) - continue; - if((n = write(s, p, i)) <= 0) { -/* - perror("write in SendDst"); - exit(-1); -*/ - return (-2); - } - p += n; - i -= n; - } - return(0); -} - -int GetDst(s, dst) -int s; -Socks_t *dst; -{ - char c[sizeof(Socks_t)]; - char *p = c; - int i = sizeof(Socks_t), n, ret; - fd_set fds; - int fdsbits = s + 1; - struct timeval timeout; - - while ( i > 0) { - FD_ZERO(&fds); - FD_SET(s, &fds); - timeout.tv_sec = 15; - timeout.tv_usec = 0; - while ((ret = select(fdsbits, &fds, NULL, NULL, &timeout)) < 0) { -/* - perror("select in GetDst"); - exit(-1); -*/ -#if defined(DEBUG) - if (errno != EINTR) -#endif - return(-1); - } - if (ret == 0) - continue; - if((n = read(s, p, i)) <= 0) { -/* - perror("read in GetDst"); - exit(-1); -*/ - return(-2); - } - p += n; - i -= n; - } - - dst->version = c[0]; - dst->cmd = c[1]; - bcopy(c+2, &dst->port, sizeof(dst->port)); - bcopy(c+2+sizeof(dst->port), &dst->host, sizeof(dst->host)); - return(0); -} - diff --git a/network/socks/socks.cstc.4.2/lib/check_cconf.c b/network/socks/socks.cstc.4.2/lib/check_cconf.c deleted file mode 100644 index 23ba368b..00000000 --- a/network/socks/socks.cstc.4.2/lib/check_cconf.c +++ /dev/null @@ -1,258 +0,0 @@ -#include <sys/types.h> -#include <syslog.h> -#include <netinet/in.h> -#include <netdb.h> -#include <stdio.h> -#include <ctype.h> -/* >>> YDL, 93/10/26 */ -#if (defined(sun) && !defined(SOLARIS)) || defined(sgi) -#include <strings.h> -#else -#include <string.h> -#endif -/* <<< YDL< 93/10/26 */ -#include "socks.h" - -#define STREQ(a, b) (strcmp(a, b) == 0) - -#ifdef OLD_CONF_MASK -static char conf_mask[] = OLD_CONF_MASK; -#endif -char *socks_conf = SOCKS_CONF; -extern char *porttoserv(); -extern char *saddrtoname(); -extern void mkargs(); -extern int GetAddr(); -extern long GetPort(); -extern int check_user(); -extern char socks_src_user[]; -extern char *socks_server; -extern struct sockaddr_in socks_nsin; -extern u_int32 SocksHost; -extern char *socks_def_server; -extern char *socks_serverlist; - -check_cconf(src, dst) -/* Return 0 if sockd should be used, - 1 if direct connection should be made, - -1 if the connection request should be denied. - */ -struct sockaddr_in *src, *dst; -{ - FILE *fd; - static char buf[1024]; -#ifdef TEST - char temp[1024]; -#endif - char *bp; - int linenum = 0, direct; - char *argv[10]; - int argc; - u_int32 daddr, dmask; - unsigned short dport; - enum { e_lt, e_gt, e_eq, e_neq, e_le, e_ge, e_nil } tst; - char *userlist; - int next_arg; - unsigned short dst_sin_port = ntohs(dst->sin_port); - long p; - char *cmdp; - struct hostent *hp; - struct in_addr self; - - - self.s_addr = inet_addr("127.0.0.1"); - if ((dst->sin_addr.s_addr == self.s_addr) || (dst->sin_addr.s_addr == 0)) - return(1); - if ((fd = fopen(socks_conf, "r")) == NULL) - return(1); - - while (fgets(buf, sizeof(buf) - 1, fd) != NULL) { - linenum++; -#ifdef TEST - strcpy(temp, buf); -#endif - /* - ** Comments start with a '#' anywhere on the line - */ - cmdp = (char *)0; - if ((bp = index(buf, '\n')) != NULL) - *bp = '\0'; - for (bp = buf; *bp != '\0'; bp++) { - if (*bp == ':') { - *bp++ = '\0'; - cmdp = bp; - break; - } else if (*bp == '#') { - *bp = '\0'; - break; - } else if (*bp == '\t') - *bp = ' '; - } - - mkargs(buf, &argc, argv, 7); - if (argc == 0) - continue; - if ((argc < 3) || (argc > 7)) { -#ifdef TEST - printf("Invalid entry at line %d\n", linenum); -#else - syslog(LOG_LOW, "Invalid entry at line %d", linenum); -#endif - continue; - } - - next_arg = 1; - if (STREQ(argv[0], "sockd")) { - socks_serverlist = socks_def_server; - direct = 0; - if (strncmp(argv[next_arg], "@=", 2) == 0) { - socks_serverlist = argv[next_arg] + 2; - if(*socks_serverlist == '\0') -/* - socks_serverlist = (char *)0; -*/ - socks_serverlist = socks_def_server; - next_arg++; - } - } else if (strncmp(argv[0], "sockd@", 6) == 0) { - direct = 0; - socks_serverlist = argv[0] + 6; - if (*socks_serverlist == '\0') -/* - socks_serverlist = (char *)0; -*/ - socks_serverlist = socks_def_server; - } else if (STREQ(argv[0], "direct")) { - direct = 1; - } else if (STREQ(argv[0], "deny")) { - direct = -1; - } else { -#ifdef TEST - printf("Invalid sockd/direct/deny field at line %d\n", linenum); -#else - syslog(LOG_LOW, "Invalid sockd/direct/deny field at line %d", linenum); -#endif - continue; - } - - userlist = (char *)0; - if (strncmp(argv[next_arg], "*=", 2) == 0) { - if (argv[next_arg][2]) userlist = argv[next_arg] + 2; - next_arg++; - } - if(argc <= next_arg+1) { -#ifdef TEST - printf("Invalid entry at line %d\n", linenum); -#else - syslog(LOG_LOW, "Invalid entry at line %d", linenum); -#endif - continue; - } - GetAddr(argv[next_arg++], &daddr); - GetAddr(argv[next_arg++], &dmask); - if (argc > next_arg + 1) { - if (STREQ(argv[next_arg], "eq")) - tst = e_eq; - else if (STREQ(argv[next_arg], "neq")) - tst = e_neq; - else if (STREQ(argv[next_arg], "lt")) - tst = e_lt; - else if (STREQ(argv[next_arg], "gt")) - tst = e_gt; - else if (STREQ(argv[next_arg], "le")) - tst = e_le; - else if (STREQ(argv[next_arg], "ge")) - tst = e_ge; - else { -#ifdef TEST - printf("Invalid comparison at line %d\n", linenum); -#else - syslog(LOG_LOW, "Invalid comparison at line %d", linenum); -#endif - continue; - } - - if (((p = GetPort(argv[next_arg+1])) < 0) || - (p >= (1L << 16))) { -#ifdef TEST - printf("Invalid port number at line %d\n", linenum); -#else - syslog(LOG_LOW, "Invalid port number at line %d", linenum); -#endif - continue; - } else { - dport = p; - } - } else { - tst = e_nil; - dport = 0; - } - -#ifdef DEBUG - { - char msg[1024]; - if (userlist) - sprintf(msg,"%s %s 0x%08x 0x%08x %s %u", - argv[0], userlist, daddr, dmask, - tst == e_eq ? "==" : - tst == e_neq ? "!=" : - tst == e_lt ? "<" : - tst == e_gt ? ">" : - tst == e_le ? "<=" : - tst == e_ge ? ">=" : "NIL", - dport); - else - sprintf(msg,"%s 0x%08x 0x%08x %s %u", - argv[0], daddr, dmask, - tst == e_eq ? "==" : - tst == e_neq ? "!=" : - tst == e_lt ? "<" : - tst == e_gt ? ">" : - tst == e_le ? "<=" : - tst == e_ge ? ">=" : "NIL", - dport); - syslog(LOG_LOW, "%s", msg); - } -#endif - /* comparisons of port numbers must be done in host order */ - -#ifdef OLD_CONF_MASK - if((daddr & ~dmask) == (dst->sin_addr.s_addr & ~dmask) && -#else - if((daddr & dmask) == (dst->sin_addr.s_addr & dmask) && -#endif - check_user(userlist, socks_src_user)) { - if (tst == e_nil) - goto GotIt; - if ((tst == e_eq) && (dst_sin_port == dport)) - goto GotIt; - if ((tst == e_neq) && (dst_sin_port != dport)) - goto GotIt; - if ((tst == e_lt) && (dst_sin_port < dport)) - goto GotIt; - if ((tst == e_gt) && (dst_sin_port > dport)) - goto GotIt; - if ((tst == e_le) && (dst_sin_port <= dport)) - goto GotIt; - if ((tst == e_ge) && (dst_sin_port >= dport)) - goto GotIt; - } - } - - fclose(fd); -#ifdef TEST - printf("*** No match with any line. Access denied.\n"); -#endif - return -1; - -GotIt: -#ifdef TEST - printf("Line %d: %s", linenum, temp); -#endif - fclose(fd); - if (cmdp != (char *)0) - shell_cmd(cmdp, src, dst); - return direct; - -} - diff --git a/network/socks/socks.cstc.4.2/lib/check_user.c b/network/socks/socks.cstc.4.2/lib/check_user.c deleted file mode 100644 index c64a189d..00000000 --- a/network/socks/socks.cstc.4.2/lib/check_user.c +++ /dev/null @@ -1,175 +0,0 @@ -#include "socks.h" - -#include <netdb.h> -/* >>> K. Shackelford */ -#if defined(hpux) || defined(AIX) -#include <sys/types.h> -#include <netinet/in.h> -#endif -/* <<< K. Shackelford */ -#include <stdio.h> -#include <ctype.h> -/* >>> YDL, 93/10/26 */ -#if (defined(sun) && !defined(SOLARIS)) || defined(sgi) -#include <strings.h> -#else -#include <string.h> -#endif - -#ifdef SOLARIS -#include "bstring.h" -#endif - -/* <<< YDL< 93/10/26 */ -extern char *porttoserv(); -extern char *saddrtoname(); - -/* - * These functions are used by both Validate (for sockd) - * and check_cconf (for clients). - */ - -/* -** Simple 'mkargs' doesn't handle \, ", or '. -*/ -void mkargs(cp, argc, argv, max) -char *cp; -int *argc; -char *argv[]; -int max; -{ - *argc = 0; - while (isspace(*cp)) - cp++; - - while (*cp != '\0') { - argv[(*argc)++] = cp; - if (*argc >= max) - return; - - while (!isspace(*cp) && (*cp != '\0')) - cp++; - while (isspace(*cp)) - *cp++ = '\0'; - } -} - -/* -** Get address, either numeric or dotted quad, or hex. - * Result is in network byte order. -*/ -int GetAddr(name, addr) -char *name; -u_int32 *addr; -{ - struct hostent *hp; - struct netent *np; - - if ((hp = gethostbyname(name)) != NULL) { - bcopy(hp->h_addr_list[0], addr, sizeof(*addr)); - return *addr; - } - if ((np = getnetbyname(name)) != NULL) { - bcopy(&np->n_net, addr, sizeof(*addr)); - return *addr; - } - return *addr = inet_addr(name); -} - -long GetPort(name) -char *name; -/* result is in HOST byte order */ -{ - struct servent *sp; - - if ((sp = getservbyname(name, "tcp")) != NULL) { - return ntohs(sp->s_port); - } - if (!isdigit(*name)) - return -1; - return atol(name); -} - - -int check_user(userlist, src_user) - -char *userlist, *src_user; - -/* - * Unless userlist is a null pointer, in which case all users are - * allowed (return 1), otherwise - * userlist is a nonempty string containing userids separated by - * commas, no other separators are allowed in the string. - * 94/03/02: if userlist starts with '/', it specifies a file - * containing userids. - * - * Return 1 if src_user is in the userlist; - * return 0 if not, or if userfile cannot be open. - */ -{ - char *p, *q; - - if (!(p = userlist)) { - return 1; - } - do { - if (q = index(p, ',')) - *q++ = '\0'; - if (*p == '/') { - switch (check_userfile(p, src_user)) { - case 1: - return 1; - case -1: - return 0; - default: - ; - } - } else if (strcmp(p, src_user) == 0) { - return 1; - } - } while ( p = q); - - return 0; -} - -#include <string.h> -#include <syslog.h> - -int check_userfile(userfile, src_user) -char *userfile, *src_user; -/* return 1 if match, 0 otherwise */ -/* return -1 if cannot open file */ -{ - FILE *fd; -#define BUFLEN 1024 - static char buf[BUFLEN]; - char *bp; - - if ((fd = fopen(userfile, "r")) == NULL) { -/* -#ifdef MONITOR - sendto(mon_sd, &mon_msg, socks_type1_len, 0, mon_un_addr, mon_un_len); - failure_mon(MON_ERR_NO_USERFILE); -#endif -*/ - syslog(LOG_HIGH,"Unable to open userfile (%s)\n", userfile); - return (-1); - } - - while (fgets(buf, BUFLEN, fd) != NULL) { - if ((bp = index(buf, '\n')) != NULL) - *bp = '\0'; - if (( bp = index(buf, '#')) != NULL) - *bp = '\0'; - - for (bp = strtok(buf, " ,\t"); bp != NULL; - bp = strtok(NULL, " ,\t")) { - if (strcmp(bp, src_user) == 0) { - fclose(fd); - return 1; - } - } - } - fclose(fd); - return 0; -} diff --git a/network/socks/socks.cstc.4.2/lib/getpass.c b/network/socks/socks.cstc.4.2/lib/getpass.c deleted file mode 100644 index 61c8efde..00000000 --- a/network/socks/socks.cstc.4.2/lib/getpass.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 1988 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the University of California, Berkeley. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)getpass.c based on 5.3 (Berkeley) 9/22/88"; -#endif /* LIBC_SCCS and not lint */ - -#if defined(__NetBSD__) -#define USE_OLD_TTY -#endif - -/* >>> Craig Metz */ -#if defined(LINUX) -#define SVR3 -#endif -/* <<< Craig Metz */ - -#if defined(SOLARIS) || defined(hpux) -#include <signal.h> -#include <sgtty.h> -#include <sys/ioctl.h> -#else -#ifdef SVR3 -#include <termio.h> -#else -#include <sys/ioctl.h> -#endif -#include <sys/signal.h> -#endif -#include <stdio.h> - -char * -getpass(prompt) - char *prompt; -{ -#ifdef SVR3 - struct termio term_struct; - tcflag_t svflagval; -#else - struct sgttyb ttyb; - int svflagval; -#endif - register int ch; - register char *p; - FILE *fp, *outfp; -#ifdef SOLARIS - sigset_t maskset; -#else - long omask; -#endif -#define PASSWD_LEN 128 - static char buf[PASSWD_LEN + 1]; - - /* - * read and write to /dev/tty if possible; else read from - * stdin and write to stderr. - */ - if ((outfp = fp = fopen("/dev/tty", "w+")) == NULL) { - outfp = stderr; - fp = stdin; - } -#ifdef SVR3 - (void)ioctl(fileno(fp), TCGETA, &term_struct); - svflagval = term_struct.c_lflag; - term_struct.c_lflag &= ~ECHO; -#else - (void)ioctl(fileno(fp), TIOCGETP, &ttyb); - svflagval = ttyb.sg_flags; - ttyb.sg_flags &= ~ECHO; -#endif - -#ifdef SOLARIS - if (sigprocmask(0, (sigset_t *)0, &maskset) || sighold(SIGINT)) { - perror("Can't block SIGINT in getpass() "); - exit(1); - } -#else - omask = sigblock(sigmask(SIGINT)); -#endif - -#ifdef SVR3 - (void)ioctl(fileno(fp), TCSETA, &term_struct); -#else - (void)ioctl(fileno(fp), TIOCSETP, &ttyb); -#endif - - fputs(prompt, outfp); - rewind(outfp); /* implied flush */ - for (p = buf; (ch = getc(fp)) != EOF && ch != '\n';) - if (p < buf + PASSWD_LEN) - *p++ = ch; - *p = '\0'; - (void)write(fileno(outfp), "\n", 1); -#ifdef SVR3 - term_struct.c_lflag = svflagval; - (void)ioctl(fileno(fp), TCSETA, &term_struct); -#else - ttyb.sg_flags = svflagval; - (void)ioctl(fileno(fp), TIOCSETP, &ttyb); -#endif - -#ifdef SOLARIS - if (sigprocmask(SIG_SETMASK, &maskset, (sigset_t *)0)) { - perror("Can't restore signal mask in getpass() "); - exit(1); - } -#else - (void)sigsetmask(omask); -#endif - if (fp != stdin) - (void)fclose(fp); - return(buf); -} - diff --git a/network/socks/socks.cstc.4.2/lib/percent_x.c b/network/socks/socks.cstc.4.2/lib/percent_x.c deleted file mode 100644 index db5d8760..00000000 --- a/network/socks/socks.cstc.4.2/lib/percent_x.c +++ /dev/null @@ -1,110 +0,0 @@ - /* - * percent_x() takes a string and performs %x subsitutions. - * It aborts the program when the result of - * expansion would overflow the output buffer. Because the result of %<char> - * expansion is typically passed on to a shell process, characters that may - * confuse the shell are replaced by underscores. - * - * Diagnostics are reported through syslog(3). - * - * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands. - * - * Adapted for use with SOCKS by Ying-Da Lee, NEC Systems Lab, CSTC - * ylee@syl.dl.nec.com - * - */ - -#ifndef lint -static char sccsid[] = "@(#) percent_x.c 1.2 92/08/24 21:46:22"; -#endif - -/* System libraries. */ - -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <stdio.h> -#include <syslog.h> -#include "socks.h" - -extern char *strncpy(); -extern char *strchr(); -extern void exit(); - -extern char socks_src_name[], socks_src_user[]; -extern char socks_real_user[]; -extern char socks_dst_name[], socks_dst_serv[]; -extern char socks_cmd[]; - -/* percent_x - do %<char> expansion, abort if result buffer is too small */ - -void percent_x(result, result_len, str, src, dst, pid) -char *result; -int result_len; -char *str; -struct sockaddr_in *src, *dst; -int pid; -{ - char *end = result + result_len - 1; /* end of result buffer */ - char *expansion; - int expansion_len; - char pid_buf[10]; - char port_buf[10]; - static char ok_chars[] = "1234567890!@%-_=+\\:,./\ -abcdefghijklmnopqrstuvwxyz\ -ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - char *cp; - - /* - * %A: the client domainname if known, IP address otherwise - * %a: the client IP address - * %c: "connect" or "bind" - * %p: the daemon or client program process id - * %S: the service name (ftp, telnet,etc.) if known, port number otherwise - * %s: the destination port number - * %U: for sockd, this is the username as reported by identd; - * for client program, this is the name used at login - * %u: for sockd, this is the username as reported by the client program; - * for client program, this is the username of the effective userid - * %Z: the destination domainname if known, IP address otherwise - * %z: the destination IP address - * - * %% becomes a %, and %other is ignored. We terminate with a diagnostic if - * we would overflow the result buffer. Characters that may confuse the - * shell are mapped to underscores. - */ - - while (*str) { - if (*str == '%') { - str++; - expansion = - *str == 'A' ? (str++, socks_src_name) : - *str == 'a' ? (str++, inet_ntoa(src->sin_addr)) : - *str == 'c' ? (str++, socks_cmd) : - *str == 'p' ? (str++, sprintf(pid_buf, "%d", pid), pid_buf) : - *str == 'S' ? (str++, socks_dst_serv) : - *str == 's' ? (str++, sprintf(port_buf, "%u", ntohs(dst->sin_port)), port_buf) : - *str == 'U' ? (str++, socks_real_user) : - *str == 'u' ? (str++, socks_src_user) : - *str == 'Z' ? (str++, socks_dst_name) : - *str == 'z' ? (str++, inet_ntoa(dst->sin_addr)) : - *str == '%' ? (str++, "%") : - *str == 0 ? "" : (str++, ""); - expansion_len = strlen(expansion); - for (cp = expansion; *cp; cp++) - if (strchr(ok_chars, *cp) == 0) - *cp = '_'; - } else { - expansion = str++; - expansion_len = 1; - } - if (result + expansion_len >= end) { - syslog(LOG_HIGH, "shell command too long: %30s...", result); - exit(0); - } - strncpy(result, expansion, expansion_len); - result += expansion_len; - } - *result = 0; -} diff --git a/network/socks/socks.cstc.4.2/lib/porttoserv.c b/network/socks/socks.cstc.4.2/lib/porttoserv.c deleted file mode 100644 index 2da25bda..00000000 --- a/network/socks/socks.cstc.4.2/lib/porttoserv.c +++ /dev/null @@ -1,20 +0,0 @@ -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> - -char *porttoserv(sin_port, name, namelen) -int sin_port; /* port number in network byte order */ -char *name; -int namelen; -{ - struct servent *serv; - int port = ntohs(sin_port); - - if ((serv = getservbyport(port, "tcp")) != (struct servent *)0) - strncpy(name, serv->s_name, namelen); - else - sprintf(name, "%u", port); - return(name); -} - diff --git a/network/socks/socks.cstc.4.2/lib/saddrtoname.c b/network/socks/socks.cstc.4.2/lib/saddrtoname.c deleted file mode 100644 index aee0f56f..00000000 --- a/network/socks/socks.cstc.4.2/lib/saddrtoname.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> - -char *saddrtoname(addr, name, namelen) -struct in_addr *addr; -char *name; -int namelen; -{ - struct hostent *host; - - if ((host = gethostbyaddr((char *)addr, 4, AF_INET)) != (struct hostent *)0) - strncpy(name, host->h_name, namelen); - else - strncpy(name, inet_ntoa(*addr), namelen); - return(name); -} - diff --git a/network/socks/socks.cstc.4.2/lib/shell_cmd.c b/network/socks/socks.cstc.4.2/lib/shell_cmd.c deleted file mode 100644 index 579ca878..00000000 --- a/network/socks/socks.cstc.4.2/lib/shell_cmd.c +++ /dev/null @@ -1,112 +0,0 @@ - /* - * shell_cmd() takes a shell command template and performs %x substitutions. - * The result is executed - * by a /bin/sh child process, with standard input, standard output and - * standard error connected to /dev/null. - * - * Diagnostics are reported through syslog(3). - * - * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands. - * - * Adapted for use with SOCKS by Ying-Da Lee, NEC Systems Lab, CSTC - * ylee@syl.dl.nec.com - * - */ - -#ifndef lint -static char sccsid[] = "@(#) shell_cmd.c 1.2 92/06/11 22:21:28"; -#endif - -/* System libraries. */ - -#include <sys/types.h> -#include <sys/param.h> -#include <netinet/in.h> -#include <stdio.h> -#include <syslog.h> -#include "socks.h" - -extern char *strncpy(); -extern void closelog(); -extern void exit(); - -/* Forward declarations. */ - -static void do_child(); - -/* shell_cmd - expand %<char> sequences and execute shell command */ - -void shell_cmd(string, src, dst) -char *string; -struct sockaddr_in *src, *dst; -{ - char cmd[BUFSIZ]; - static char alpha_num[] = "abcdefghijklmnopqrstuvwxyz\ -ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - int child_pid; - int wait_pid; - int daemon_pid = getpid(); - - percent_x(cmd, sizeof(cmd), string, src, dst, daemon_pid); - if (strpbrk(cmd, alpha_num) == NULL) { - syslog(LOG_HIGH, "error -- shell command \"%s\" contains no alphanumeric characters.", cmd); - return; - } - - /* - * Most of the work is done within the child process, to minimize the - * risk of damage to the parent. - */ - - switch (child_pid = fork()) { - case -1: /* error */ - syslog(LOG_HIGH, "error -- shell_cmd fork() %m"); - break; - case 00: /* child */ - do_child(daemon_pid, cmd); - /* NOTREACHED */ - default: /* parent */ - while ((wait_pid = wait((int *) 0)) != -1 && wait_pid != child_pid) - /* void */ ; - } -} - -/* do_child - exec command with { stdin, stdout, stderr } to /dev/null */ - -static void do_child(daemon_pid, command) -int daemon_pid; -char *command; -{ - char *error = 0; - int tmp_fd; - - /* - * Close a bunch of file descriptors. The Ultrix inetd only passes stdin, - * but other inetd implementations set up stdout as well. Ignore errors. - */ - - closelog(); - for (tmp_fd = 0; tmp_fd < 10; tmp_fd++) - (void) close(tmp_fd); - - /* Set up new stdin, stdout, stderr, and exec the shell command. */ - - if (open("/dev/null", 2) != 0) { - error = "open /dev/null: %m"; - } else if (dup(0) != 1 || dup(0) != 2) { - error = "dup: %m"; - } else { - (void) execl("/bin/sh", "sh", "-c", command, (char *) 0); - error = "execl /bin/sh: %m"; - } - - /* We can reach the following code only if there was an error. */ - -#ifdef LOG_DAEMON - (void) openlog("sockd", LOG_PID, SYSLOG_FAC); -#else - (void) openlog("sockd", LOG_PID); -#endif - syslog(LOG_HIGH, "Cannot execute shell command for pid %d", daemon_pid); - exit(0); -} |