Subject: bin/5556: ftp doesn't work with some proxies
To: None <gnats-bugs@gnats.netbsd.org>
From: Lennart Augustsson <augustss@cs.chalmers.se>
List: netbsd-bugs
Date: 06/08/1998 11:10:28
>Number:         5556
>Category:       bin
>Synopsis:       ftp doesn't work with some proxies
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Jun  8 02:20:01 1998
>Last-Modified:
>Originator:     Lennart Augustsson
>Organization:
Chalmers University
>Release:        NetBSD-current 980607
>Environment:
System: NetBSD dogbert.cs.chalmers.se 1.3E NetBSD 1.3E (DOGBERT) #0: Thu Mar 12 10:45:34 CET 1998 augustss@dogbert.cs.chalmers.se:/usr/src/sys/arch/i386/compile/DOGBERT i386


>Description:
	I cannot find a way to use ftp in a transparent way through some
	proxy schemes (maybe I've not read the source closely enough :-).
	There is what I've got: Without proxy you would use
	host user password
	but with the proxy you should use
	proxyhost user@host password

	I don't think ftp can do this translation, but it would be
	very convenient to have for fetching packages (for manual
	ftp I don't care so much).

>How-To-Repeat:
	Try it.
>Fix:
	Here's a fix, maybe not the most beautiful, but it works for me.
	To use the proxy the envrionment variable FTP_VIA should be set
	to the proxy host name.


diff -c ftp/fetch.c new/fetch.c
*** ftp/fetch.c	Fri Jun  5 14:16:45 1998
--- new/fetch.c	Fri Jun  5 15:37:09 1998
***************
*** 448,453 ****
--- 448,455 ----
  	longjmp(httpabort, 1);
  }
  
+ char *oldhost;
+ 
  /*
   * Retrieve multiple files from the command line, transferring
   * files of the form "host:path", "ftp://host/path" using the
***************
*** 477,482 ****
--- 479,485 ----
  	volatile int argpos;
  	int dirhasglob, filehasglob;
  	char rempath[MAXPATHLEN];
+ 	char *ftpvia;
  
  #ifdef __GNUC__			/* to shut up gcc warnings */
  	(void)&outfile;
***************
*** 495,500 ****
--- 498,505 ----
  	ftpproxy = getenv(FTP_PROXY);
  	httpproxy = getenv(HTTP_PROXY);
  
+ 	ftpvia = getenv("FTP_VIA");
+ 
  	/*
  	 * Loop through as long as there's files to fetch.
  	 */
***************
*** 596,601 ****
--- 601,612 ----
  			fprintf(ttyout,
  			    "user %s:%s host %s port %s dir %s file %s\n",
  			    user, pass, host, portnum, dir, file);
+ 
+ 		if (ftpvia) {
+ 			oldhost = host;
+ 			host = ftpvia;
+ 		} else
+ 			oldhost = 0;
  
  		/*
  		 * Set up the connection if we don't have one.
diff -c ftp/util.c new/util.c
*** ftp/util.c	Fri Jun  5 14:16:46 1998
--- new/util.c	Fri Jun  5 15:49:14 1998
***************
*** 193,198 ****
--- 193,200 ----
  	}
  }
  
+ extern char *oldhost;
+ 
  /*
   * login to remote host, using given username & password if supplied
   */
***************
*** 204,209 ****
--- 206,212 ----
  	char tmp[80];
  	char *acct;
  	char anonpass[MAXLOGNAME + 1 + MAXHOSTNAMELEN];	/* "user@hostname" */
+ 	char userhost[MAXLOGNAME + 1 + MAXHOSTNAMELEN];	/* "user@hostname" */
  	char hostname[MAXHOSTNAMELEN];
  	struct passwd *pw;
  	int n, aflag = 0;
***************
*** 268,273 ****
--- 271,280 ----
  		else
  			user = tmp;
  	}
+ 	if (oldhost) {
+ 		sprintf(userhost, "%s@%s", user, oldhost);
+ 		user = userhost;
+ 	}
  	n = command("USER %s", user);
  	if (n == CONTINUE) {
  		if (pass == NULL)

>Audit-Trail:
>Unformatted: