if (*pass == '@') {
if (pass == host || *pass == '@') { bad_ftp_url:
auto_fetch(argc, argv, fd)	int argc;	char *argv[];	int fd;{	static char lasthost[MAXHOSTNAMELEN];	char *xargv[5];	char *cp, *line, *host, *dir, *file, *portnum;	char *user, *pass;	char *ftpproxy, *httpproxy;	int rval, xargc, argpos;	int dirhasglob, filehasglob;	char rempath[MAXPATHLEN], fakedev[MAXPATHLEN];	argpos = 0;	if (setjmp(toplevel)) {		if (connected)			disconnect(0, NULL);		return (argpos + 1);	}	(void)signal(SIGINT, (sig_t)intr);	(void)signal(SIGPIPE, (sig_t)lostpeer);	ftpproxy = getenv(FTP_PROXY);	httpproxy = getenv(HTTP_PROXY);	/*	 * Loop through as long as there's files to fetch.	 */	for (rval = 0; (rval == 0) && (argpos < argc); free(line), argpos++) {		if (strchr(argv[argpos], ':') == NULL)			break;		host = dir = file = portnum = user = pass = NULL;		/*		 * We muck with the string, so we make a copy.		 */		line = strdup(argv[argpos]);		if (line == NULL)			errx(1, "Can't allocate memory for auto-fetch.");		/*		 * Try HTTP URL-style arguments first.		 */		if (strncasecmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) {			if (url_get(line, httpproxy, fd) == -1)				rval = argpos + 1;			continue;		}		/*		 * Try FTP URL-style arguments next. If ftpproxy is		 * set, use url_get() instead of standard ftp.		 * Finally, try host:file.		 */		host = line;		if (strncasecmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0) {			if (ftpproxy) {				if (url_get(line, ftpproxy, fd) == -1)					rval = argpos + 1;				continue;			}			host += sizeof(FTP_URL) - 1;			dir = strchr(host, '/');			/* Look for [user:pass@]host[:port] */			user = host;			pass = strpbrk(user, ":@/");			if (pass == NULL || *pass == '/') {				user = pass = NULL;				goto parsed_url;			}			if (*pass == '@') {				warnx("Bad ftp URL: %s", argv[argpos]);				rval = argpos + 1;				continue;			}			*pass++ = '\0';			cp = strpbrk(pass, ":@/");			if (cp == NULL || *cp == '/') {				portnum = pass;				user = pass = NULL;				goto parsed_url;			}			if (*cp == ':') {				warnx("Bad ftp URL: %s", argv[argpos]);				rval = argpos + 1;				continue;			}			*cp++ = '\0';			host = cp;			portnum = strchr(host, ':');			if (portnum != NULL)				*portnum++ = '\0';parsed_url:		} else {			/* classic style `host:file' */			dir = strchr(host, ':');		}		if (EMPTYSTRING(host)) {			rval = argpos + 1;			continue;		}		/*		 * If dir is NULL, the file wasn't specified		 * (URL looked something like ftp://host)		 */		if (dir != NULL)			*dir++ = '\0';		/*		 * Extract the file and (if present) directory name.		 */		if (! EMPTYSTRING(dir)) {			cp = strrchr(dir, '/');			if (cp != NULL) {				*cp++ = '\0';				file = cp;			} else {				file = dir;				dir = NULL;			}		}		if (debug)			fprintf(ttyout, "user %s:%s host %s port %s dir %s file %s\n",			    user, pass, host, portnum, dir, file);		/*		 * Set up the connection if we don't have one.		 */		if (strcmp(host, lasthost) != 0) {			int oautologin;			(void)strcpy(lasthost, host);			if (connected)				disconnect(0, NULL);			xargv[0] = __progname;			xargv[1] = host;			xargv[2] = NULL;			xargc = 2;			if (! EMPTYSTRING(portnum)) {				xargv[2] = portnum;				xargv[3] = NULL;				xargc = 3;			}			oautologin = autologin;			if (user != NULL)				autologin = 0;			setpeer(xargc, xargv);			autologin = oautologin;			if ((connected == 0) ||			    ((connected == 1) && !login(host, user, pass)) ) {				warnx("Can't connect or login to host `%s'",				    host);				rval = argpos + 1;				continue;			}			/* Always use binary transfers. */			setbinary(0, NULL);		}		/* cd back to '/' */		xargv[0] = "cd";		xargv[1] = "/";		xargv[2] = NULL;		cd(2, xargv);		if (! dirchange) {			rval = argpos + 1;			continue;		}		dirhasglob = filehasglob = 0;		if (doglob) {			if (! EMPTYSTRING(dir) &&			    strpbrk(dir, "*?[]{}") != NULL)				dirhasglob = 1;			if (! EMPTYSTRING(file) &&			    strpbrk(file, "*?[]{}") != NULL)				filehasglob = 1;		}		/* Change directories, if necessary. */		if (! EMPTYSTRING(dir) && !dirhasglob) {			xargv[0] = "cd";			xargv[1] = dir;			xargv[2] = NULL;			cd(2, xargv);			if (! dirchange) {				rval = argpos + 1;				continue;			}		}		if (EMPTYSTRING(file)) {			rval = -1;			continue;		}		if (!verbose)			fprintf(ttyout, "Retrieving %s/%s\n", dir ? dir : "", file);		if (dirhasglob) {			snprintf(rempath, sizeof(rempath), "%s/%s", dir, file);			file = rempath;		}		/* Fetch the file(s). */		xargc = 2;		xargv[0] = "get";		xargv[1] = file;		xargv[2] = NULL;		if (dirhasglob || filehasglob) {			int ointeractive;			ointeractive = interactive;			interactive = 0;			xargv[0] = "mget";			mget(xargc, xargv);			interactive = ointeractive;		} else {			if (fd != -1) {				xargv[2] = "-";				xargc++;			}			xargv[3] = NULL;			get(xargc, xargv);		}		if ((code / 100) != COMPLETE)			rval = argpos + 1;	}	if (connected && rval != -1)		disconnect(0, NULL);	return (rval);}