diff options
author | jkh <jkh@FreeBSD.org> | 1996-04-28 20:54:11 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1996-04-28 20:54:11 +0000 |
commit | 590017a61ca58be6918c7060127977c51861c36b (patch) | |
tree | 4feb68ad24dca3ea106d8e7eaa8949c9e16a1f31 /release/sysinstall/ftp.c | |
parent | c17cc2e1bedeb94384f0251f46ed703860b946d6 (diff) | |
download | FreeBSD-src-590017a61ca58be6918c7060127977c51861c36b.zip FreeBSD-src-590017a61ca58be6918c7060127977c51861c36b.tar.gz |
Add a new -fake argument to make sysinstall not actually change things while
I'm testing it.
Diffstat (limited to 'release/sysinstall/ftp.c')
-rw-r--r-- | release/sysinstall/ftp.c | 83 |
1 files changed, 43 insertions, 40 deletions
diff --git a/release/sysinstall/ftp.c b/release/sysinstall/ftp.c index e4b2c3e..0668416 100644 --- a/release/sysinstall/ftp.c +++ b/release/sysinstall/ftp.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: ftp.c,v 1.14.2.1 1995/10/21 14:06:35 jkh Exp $ + * $Id: ftp.c,v 1.15 1995/12/07 10:33:47 peter Exp $ * * Return values have been sanitized: * -1 error, but you (still) have a session. @@ -49,9 +49,9 @@ debug(FTP_t ftp, const char *fmt, ...) va_start(ap, fmt); #ifdef STANDALONE_FTP strcpy(p,"LIBFTP: "); - (void) vsnprintf(p+strlen(p), sizeof p - strlen(p), fmt, ap); + (void) vsnprintf(p + strlen(p), sizeof p - strlen(p), fmt, ap); va_end(ap); - write(ftp->fd_debug,p,strlen(p)); + write(ftp->fd_debug, p, strlen(p)); #else if (isDebug()) { (void) vsnprintf(p, sizeof p - strlen(p), fmt, ap); @@ -64,7 +64,7 @@ static int writes(int fd, char *s) { int i = strlen(s); - if (i != write(fd,s,i)) + if (i != write(fd, s, i)) return -2; return 0; } @@ -76,14 +76,14 @@ get_a_line(FTP_t ftp) int i,j; for(i=0;i<BUFSIZ;) { - j = read(ftp->fd_ctrl,buf+i,1); + j = read(ftp->fd_ctrl, buf+i, 1); if (j != 1) return 0; if (buf[i] == '\r' || buf[i] == '\n') { if (!i) continue; buf[i] = '\0'; - debug(ftp, "received <%s>\n",buf); + debug(ftp, "received <%s>\n", buf); return buf; } i++; @@ -152,11 +152,11 @@ cmd(FTP_t ftp, const char *fmt, ...) (void) vsnprintf(p, sizeof p, fmt, ap); va_end(ap); - debug(ftp, "send <%s>\n",p); + debug(ftp, "send <%s>\n", p); strcat(p,"\r\n"); - if (writes(ftp->fd_ctrl,p)) + if (writes(ftp->fd_ctrl, p)) return -2; - i = get_a_number(ftp,0); + i = get_a_number(ftp, 0); return i; } @@ -239,11 +239,12 @@ FtpOpen(FTP_t ftp, char *host, char *user, char *passwd) debug(ftp, "open (%d)\n",get_a_number(ftp,0)); - i = cmd(ftp,"USER %s",user); + i = cmd(ftp, "USER %s", user); if (i >= 300 && i < 400) i = cmd(ftp,"PASS %s",passwd); if (i >= 299 || i < 0) { - close(ftp->fd_ctrl); ftp->fd_ctrl = -1; + close(ftp->fd_ctrl); + ftp->fd_ctrl = -1; return zap(ftp); } ftp->state = isopen; @@ -267,9 +268,10 @@ int FtpChdir(FTP_t ftp, char *dir) { int i; + if (ftp->state != isopen) return botch(ftp,"FtpChdir","open"); - i = cmd(ftp,"CWD %s",dir); + i = cmd(ftp, "CWD %s", dir); if (i < 0) return i; else if (i != 250) @@ -286,27 +288,27 @@ FtpGet(FTP_t ftp, char *file) struct sockaddr_in sin; u_long a; - debug(ftp, "FtpGet(ftp,%s)\n",file); + debug(ftp, "FtpGet(ftp,%s)\n", file); if (ftp->state != isopen) - return botch(ftp,"FtpGet","open"); - if(ftp->binary) { - i = cmd(ftp,"TYPE I"); + return botch(ftp, "FtpGet", "open"); + if (ftp->binary) { + i = cmd(ftp, "TYPE I"); if (i < 0 || FTP_TIMEOUT(i)) return zap(ftp); if (i > 299) return -1; - } else { - return -1; } + else + return -1; if ((s = socket(ftp->addrtype, SOCK_STREAM, 0)) < 0) return zap(ftp); if (ftp->passive) { - debug(ftp, "send <%s>\n","PASV"); - if (writes(ftp->fd_ctrl,"PASV\r\n")) + debug(ftp, "send <%s>\n", "PASV"); + if (writes(ftp->fd_ctrl, "PASV\r\n")) return zap(ftp); - i = get_a_number(ftp,&q); + i = get_a_number(ftp, &q); if (i < 0) return zap(ftp); if (i != 227) @@ -316,14 +318,14 @@ FtpGet(FTP_t ftp, char *file) if (!*q) return zap(ftp); q--; - for(i=0;i<6;i++) { + for(i = 0; i < 6; i++) { q++; - addr[i] = strtol(q,&q,10); + addr[i] = strtol(q, &q, 10); } sin.sin_family = ftp->addrtype; bcopy(addr, (char *)&sin.sin_addr, 4); - bcopy(addr+4, (char *)&sin.sin_port, 2); + bcopy(addr + 4, (char *)&sin.sin_port, 2); debug(ftp, "Opening active socket to %s : %u\n", inet_ntoa(sin.sin_addr), htons(sin.sin_port)); debug(ftp, "Connecting to %s:%u\n", inet_ntoa(sin.sin_addr), htons(sin.sin_port)); @@ -333,7 +335,7 @@ FtpGet(FTP_t ftp, char *file) return -1; } ftp->fd_xfer = s; - i = cmd(ftp,"RETR %s",file); + i = cmd(ftp,"RETR %s", file); if (i < 0 || FTP_TIMEOUT(i)) { close(s); return zap(ftp); @@ -348,31 +350,31 @@ FtpGet(FTP_t ftp, char *file) return s; } else { i = sizeof sin; - getsockname(ftp->fd_ctrl,(struct sockaddr *)&sin,&i); + getsockname(ftp->fd_ctrl, (struct sockaddr *)&sin, &i); sin.sin_port = 0; i = sizeof sin; if (bind(s,(struct sockaddr *)&sin, i) < 0) { - close (s); - debug(ftp,"bind failed %d\n",errno); - return zap(ftp); + close (s); + debug(ftp, "bind failed %d\n", errno); + return zap(ftp); } - getsockname(s,(struct sockaddr *)&sin,&i); - if (listen(s,1) < 0) { - close (s); - debug(ftp,"listen failed %d\n",errno); - return zap(ftp); + getsockname(s, (struct sockaddr *)&sin, &i); + if (listen(s, 1) < 0) { + close (s); + debug(ftp, "listen failed %d\n", errno); + return zap(ftp); } a = ntohl(sin.sin_addr.s_addr); - i = cmd(ftp,"PORT %d,%d,%d,%d,%d,%d", + i = cmd(ftp, "PORT %d,%d,%d,%d,%d,%d", (a >> 24) & 0xff, (a >> 16) & 0xff, (a >> 8) & 0xff, - a & 0xff, + a & 0xff, (ntohs(sin.sin_port) >> 8) & 0xff, - ntohs(sin.sin_port) & 0xff); + ntohs(sin.sin_port) & 0xff); if (i != 200) return -1; - i = cmd(ftp,"RETR %s",file); + i = cmd(ftp,"RETR %s", file); if (i < 0) { close(s); return zap(ftp); @@ -403,9 +405,10 @@ FtpEOF(FTP_t ftp) int i; if (ftp->state != xfer) - return botch(ftp,"FtpEOF","xfer"); + return botch(ftp, "FtpEOF", "xfer"); debug(ftp, "FtpEOF(ftp)\n"); - close(ftp->fd_xfer); ftp->fd_xfer = -1; + close(ftp->fd_xfer); + ftp->fd_xfer = -1; ftp->state = isopen; i = get_a_number(ftp,0); if (i < 0) |