Article delegate-en/2004 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:<_A2002@delegate-en.ML_>]
Newsgroups: mail-lists.delegate-en

[DeleGate-En] Re: how to get the server/client info in the ftp-data filter
30 Nov 2002 12:10:30 GMT feedback@delegate.org (Yutaka Sato)


Hi,

On 11/29/02(21:04) you "Wu Jiafu" <p2idqbdyi-kvnd4bfys3jr.ml@ml.delegate.org> wrote
in <_A2002@delegate-en.ML_>
 |I did a small FTP filter for DeleGate 8.1.0, using
 |"CMAP=filter:{FTOSV,FTOCL}:ftp-data".
 |
 |Now, I am considering logging the filtering result, such as the FTP server
 |IP, path/file name, client IP, etc in my filter. I print out all the
 |**environ of my filter, but find nothing about these info.
 |
 |Is it possible to get these info in the filter? or I must patch the
 |DeleGate?

At least DeleGate passes client identity to filter program in
environment variables compatible with CGI (REMOTE_HOST, REMOTE_ADDR
and REMOTE_IDENT).  I can see it with the following filter and
parameters for example: 

  [catenv]
  #!/bin/sh
  env | grep REMOTE_ | cat -n > /dev/tty
  cat

$ delegated -P9999 -f SERVER=ftp://localhost CMAP=catenv:FTOCL:ftp-data
<DeleGate/8.2.0 by ysato@delegate.org> [10494] -P9999 READY
DGROOT=/home/y.sato/delegate
ADMIN=ysato@delegate.org
AIST Product ID: 2000-ETL-198715-01, H14PRO-049
Copyright (c) 1994-2000 Yutaka Sato and ETL,AIST,MITI
Copyright (c) 2001-2002 National Institute of Advanced Industrial Science and Technology (AIST)
     1  REMOTE_IDENT=-
     2  REMOTE_HOST=yslinux
     3  REMOTE_ADDR=192.168.1.111
     1  REMOTE_IDENT=-
     2  REMOTE_HOST=localhost
     3  REMOTE_ADDR=127.0.0.1

Information about server side identity and resource name are available
only in "CFI-script" and when applied to HTTP protocol.  Applying it
to arbitrary protocol is desirable of course.
The enclosed patch will set SERVER_HOST and SERVER_ADDR which represent
server's name and address respectively, and PATH_INFO for the path name
of transferred data on FTP.

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 -c ../../dgs/delegate8.1.0/src/filter.c ./filter.c
*** ../../dgs/delegate8.1.0/src/filter.c	Fri Nov 15 03:29:33 2002
--- ./filter.c	Sat Nov 30 20:54:24 2002
***************
*** 770,779 ****
--- 770,790 ----
  static addConnEnviron(Conn)
  	Connection *Conn;
  {	char env[1024];
+ 	char *serv;
+ 	char *gethostaddr();
  
  	strfConn(Conn,"REMOTE_IDENT=%u",env); putenv(stralloc(env));
  	strfConn(Conn,"REMOTE_HOST=%h", env); putenv(stralloc(env));
  	strfConn(Conn,"REMOTE_ADDR=%a", env); putenv(stralloc(env));
+ 
+ 	serv = DST_HOST;
+ 	sprintf(env,"SERVER_HOST=%s",serv); putenv(stralloc(env));
+ 	sprintf(env,"SERVER_ADDR=%s",gethostaddr(serv)); putenv(stralloc(env));
+ 
+ 	if( getenv("PATH_INFO") == 0 ){
+ 		sprintf(env,"PATH_INFO=%s",D_SELECTOR);
+ 		putenv(stralloc(env));
+ 	}
  }
  static addSockEnviron(Conn,what,sock)
  	Connection *Conn;
diff -c ../../dgs/delegate8.1.0/src/ftp.c ./ftp.c
*** ../../dgs/delegate8.1.0/src/ftp.c	Fri Oct 11 03:14:48 2002
--- ./ftp.c	Sat Nov 30 20:45:34 2002
***************
*** 2984,2989 ****
--- 2984,2992 ----
  	xc = 0;
  	Verbose("FTP data-relay(%d,%d): bufsize=%d\n",src,dst,size);
  
+ 	strcpy(dataConn->dd_selector,D_SELECTOR);
+ 	wordScan(FS->fs_host,dataConn->sv.p_host); /* set REAL_HOST */
+ 
  	if( REAL_HOST[0] == 0 )
  		strcpy(dataConn->sv.p_host,"-"); /* for DST_PROTO */
  	else	strcpy(dataConn->sv.p_host,REAL_HOST);
***************
*** 3355,3360 ****
--- 3358,3366 ----
  	char path[1024],cachepath[1024],xcachepath[1024];
  	FILE *cachefp;
  	int STOR = comUPLOAD(com);
+ 
+ 	strcpy(D_SELECTOR,FS->fs_CWD); /* D_SELECTOR for the path in server */
+ 	chdir_cwd(D_SELECTOR,arg,0);
  
  	if( err ){
  		sv1log("#### close data connection because of error.\n");

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