Article delegate-en/1964 of [1-5169] on the server localhost:119
  upper oldest olders older1 this newer1 newers latest
search
[Top/Up] [oldest] - [Older+chunk] - [Newer+chunk] - [newest + Check]
[Reference:<_A1963@delegate-en.ML_>]
Newsgroups: mail-lists.delegate-en

[DeleGate-En] forwarding BIND/SOCKS5 (Re: "500 Illegal PORT Command" error)
08 Nov 2002 22:31:56 GMT y.sato@delegate.org (Yutaka Sato)


On 11/08/02(20:27) you "Giovanni P. Bautista" <pvedqbdyi-xtqvdm3cnljr.ml@ml.delegate.org> wrote
in <_A1963@delegate-en.ML_>
 |11/08 19:13:44.10 [14431] 2+1: ##ViaSocks-B(by rule)## 172.28.60.253:21
 |11/08 19:13:44.10 [14431] 2+1: #### MUST DO bindViaSocks... 172.28.60.253:21

Ah... I see.  You are trying to forward BIND/SOCKS command (for PORT/FTP)
from SOCKS-DeleGate to an upstream SOCKS server.  But forwarding BIND
command is not implemented yet, since it is rarely required because resent
FTP clients uses PASV/FTP which is forwarded as CONNECT/SOCKS command or
SOCKS-DeleGate has rarely used in cascade.
As I got a request now, I made a patch as enclosed (for DeleGate/8.0.9)
to enable forwarding BIND/SOCKS by Socks-DeleGate.  Try this if you please.

Cheers,
Yutaka
--
  @ @ Yutaka Sato <y.sato@delegate.org> http://www.delegate.org/y.sato/
 ( - ) National Institute of Advanced Industrial Science and Technology (AIST)
_<   >_ 1-1-4 Umezono, Tsukuba, Ibaraki, 305-8568 Japan
Do the more with the less -- B. Fuller


diff -cr ../dgs/delegate8.0.9/rary/socks5.c ./rary/socks5.c
*** ../dgs/delegate8.0.9/rary/socks5.c	Fri May 24 00:27:47 2002
--- ./rary/socks5.c	Sat Nov  9 07:11:38 2002
***************
*** 611,616 ****
--- 611,618 ----
  	char remote[512],local[512],*bound;
  	int qauth,rauth;
  	int ai;
+ 	char rhost[512];
+ 	int rport,viasocks;
  
  	fc = fdopen(fromcl,"r");
  	tc = fdopen(tocl,"w");
***************
*** 719,739 ****
--- 721,769 ----
  		break;
  
  	    case 2: /* BIND */
+ 		viasocks = 0;
  		if( GetViaSocks(ctx,host,port) ){
+ 			/*
  			syslog_ERROR("#### MUST DO bindViaSocks... %s:%d\n",
  				host,port);
+ 			*/
+ 			bsock = bindViaSocks(ctx,host,port,rhost,&rport);
+ 			if( bsock < 0 ){
+ 				syslog_ERROR("##bindViaSocks(%s) ERROR\n",
+ 					remote);
+ 			}else{
+ 				viasocks = 1;
+ 				sprintf(local,"%s:%d",rhost,rport);
+ 				syslog_ERROR("##bindViaSocks(%s)=%d [%s]\n",
+ 					remote,bsock,local);
+ 			}
  		}
+ 		else
+ 		{
  		/*
  		 * local port must be derived from DST.PORT, in new protocol ?
  		 */
  		bsock = VSocket(ctx,"BIND/SocksV5",-1,local,remote,"listen=1");
+ 		}
  		if( bsock < 0 ){ rep = 0x01; goto ERREXIT; }
  		send_resp(tc,rep,bound=local);
  
  /* MUST POLL {fromcl,bsock} */
  
+ 		if( viasocks ){
+ 			if( acceptViaSocks(bsock,rhost,&rport) < 0 ){
+ 				svsock = -1;
+ 				syslog_ERROR("##acceptViaSocks() ERROR\n");
+ 			}else{
+ 				svsock = bsock;
+ 				sprintf(remote,"%s:%d",rhost,rport);
+ 				syslog_ERROR("##acceptViaSocks() = [%s]\n",
+ 					remote);
+ 			}
+ 		}else{
  		svsock = VSocket(ctx,"ACPT/SocksV5",bsock,local,remote,"");
  		close(bsock);
+ 		}
  		if( svsock < 0 ){ rep = 0x01; goto ERREXIT; }
  
  		send_resp(tc,rep,bound=remote);
diff -cr ../dgs/delegate8.0.9/src/socks.c ./src/socks.c
*** ../dgs/delegate8.0.9/src/socks.c	Wed Oct  9 16:45:48 2002
--- ./src/socks.c	Sat Nov  9 06:39:21 2002
***************
*** 131,136 ****
--- 131,156 ----
  	found = find_CMAP(Conn,key,map);
  	return 0 <= found;
  }
+ static matchConnX(Conn,sx,dstproto,dsthost,dstport)
+ 	Connection *Conn;
+ 	char *dstproto,*dsthost;
+ {	int sav,found;
+ 
+ 	sav = 0;
+ 	if( streq(DFLT_PROTO,"socks") && REAL_PROTO[0] == 0 ){
+ 		strcpy(REAL_PROTO,dstproto);
+ 		wordScan(dsthost,REAL_HOST);
+ 		REAL_PORT = dstport;
+ 		sav = 1;
+ 	}
+ 	found = matchConn(Conn,sx);
+ 	if( sav ){
+ 		REAL_PROTO[0] = 0;
+ 		REAL_HOST[0] = 0;
+ 		REAL_PORT = 0;
+ 	}
+ 	return found;
+ }
  static tobeViaSocks(Conn)
  	Connection *Conn;
  {	int sx;
***************
*** 402,408 ****
--- 422,431 ----
  	}
  
  	for( sx = 0; sockservs[sx].s_host; sx++ ){
+ 		/*
  		if( !matchConn(Conn,sx) )
+ 		*/
+ 		if( !matchConnX(Conn,sx,"tcprelay",dsthost,dstport) )
  			continue;
  
  		sv = &sockservs[sx];

  admin search upper oldest olders older1 this newer1 newers latest
[Top/Up] [oldest] - [Older+chunk] - [Newer+chunk] - [newest + Check]
@_@V