*/
#ifndef lint
-static char sccsid[] = "@(#)ftp.c 5.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)ftp.c 5.9 (Berkeley) %G%";
#endif not lint
#include "ftp_var.h"
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/time.h>
+#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/ftp.h>
int ptflag = 0;
int connected;
struct sockaddr_in myctladdr;
+uid_t getuid();
FILE *cin, *cout;
FILE *dataconn();
return (0);
}
hisctladdr.sin_port = port;
- while (connect(s, (caddr_t)&hisctladdr, sizeof (hisctladdr)) < 0) {
+ while (connect(s, &hisctladdr, sizeof (hisctladdr)) < 0) {
if (hp && hp->h_addr_list[1]) {
int oerrno = errno;
fprintf(stderr, "ftp: connect to address %s: ",
inet_ntoa(hisctladdr.sin_addr));
errno = oerrno;
- perror(0);
+ perror((char *) 0);
hp->h_addr_list++;
bcopy(hp->h_addr_list[0],
(caddr_t)&hisctladdr.sin_addr, hp->h_length);
- fprintf(stderr, "Trying %s...\n",
+ fprintf(stdout, "Trying %s...\n",
inet_ntoa(hisctladdr.sin_addr));
continue;
}
if (cin == NULL || cout == NULL) {
fprintf(stderr, "ftp: fdopen failed.\n");
if (cin)
- fclose(cin);
+ (void) fclose(cin);
if (cout)
- fclose(cout);
+ (void) fclose(cout);
code = -1;
goto bad;
}
printf("Connected to %s.\n", hostname);
if (getreply(0) != 2) { /* read startup message from server */
if (cin)
- fclose(cin);
+ (void) fclose(cin);
if (cout)
- fclose(cout);
+ (void) fclose(cout);
code = -1;
goto bad;
}
verbose = oldverbose;
return (hostname);
bad:
- close(s);
+ (void) close(s);
return ((char *)0);
}
char *host;
{
char tmp[80];
- char *user, *pass, *acct, *getlogin(), *getpass();
+ char *user, *pass, *acct, *getlogin(), *mygetpass();
int n, aflag = 0;
user = pass = acct = 0;
n = command("USER %s", user);
if (n == CONTINUE) {
if (pass == NULL)
- pass = getpass("Password:");
+ pass = mygetpass("Password:");
n = command("PASS %s", pass);
}
if (n == CONTINUE) {
aflag++;
- acct = getpass("Account:");
+ acct = mygetpass("Account:");
n = command("ACCT %s", acct);
}
if (n != COMPLETE) {
return(1);
for (n = 0; n < macnum; ++n) {
if (!strcmp("init", macros[n].mac_name)) {
- strcpy(line, "$init");
+ (void) strcpy(line, "$init");
makeargv();
domacro(margc, margv);
break;
longjmp(ptabort,1);
}
-/*VARARGS 1*/
+/*VARARGS1*/
command(fmt, args)
char *fmt;
{
if (proxflag &&
(dig == 1 || dig == 5 && verbose == 0))
printf("%s:",hostname);
- putchar(c);
+ (void) putchar(c);
}
if (dig < 4 && isdigit(c))
code = code * 10 + (c - '0');
n = c;
}
if (verbose > 0 || verbose > -1 && n == '5') {
- putchar(c);
+ (void) putchar(c);
(void) fflush (stdout);
}
if (continuation && code != originalcode) {
}
empty(mask, sec)
- long mask;
+ struct fd_set mask;
int sec;
{
struct timeval t;
t.tv_sec = (long) sec;
t.tv_usec = 0;
- if (select(20, &mask, 0, 0, &t) < 0)
+ if (select(20, &mask, (struct fd_set *) 0, (struct fd_set *) 0, &t) < 0)
return(-1);
- return (mask);
+ return (1);
}
jmp_buf sendabort;
sendrequest(cmd, local, remote)
char *cmd, *local, *remote;
{
- FILE *fin, *dout = 0, *popen();
- int (*closefunc)(), pclose(), fclose(), (*oldintr)(), (*oldintp)();
+ FILE *fin, *dout = 0, *mypopen();
+ int (*closefunc)(), mypclose(), fclose(), (*oldintr)(), (*oldintp)();
int abortsend();
char buf[BUFSIZ];
long bytes = 0, hashbytes = sizeof (buf);
fin = stdin;
else if (*local == '|') {
oldintp = signal(SIGPIPE,SIG_IGN);
- fin = popen(local + 1, "r");
+ fin = mypopen(local + 1, "r");
if (fin == NULL) {
perror(local + 1);
(void) signal(SIGINT, oldintr);
code = -1;
return;
}
- closefunc = pclose;
+ closefunc = mypclose;
} else {
fin = fopen(local, "r");
if (fin == NULL) {
closefunc = fclose;
if (fstat(fileno(fin), &st) < 0 ||
(st.st_mode&S_IFMT) != S_IFREG) {
- fprintf(stderr, "%s: not a plain file.\n", local);
+ fprintf(stdout, "%s: not a plain file.\n", local);
(void) signal(SIGINT, oldintr);
code = -1;
return;
dout = dataconn("w");
if (dout == NULL)
goto abort;
- gettimeofday(&start, (struct timezone *)0);
+ (void) gettimeofday(&start, (struct timezone *)0);
switch (type) {
case TYPE_I:
break;
bytes += c;
if (hash) {
- putchar('#');
- fflush(stdout);
+ (void) putchar('#');
+ (void) fflush(stdout);
}
}
if (hash && bytes > 0) {
- putchar('\n');
- fflush(stdout);
+ (void) putchar('\n');
+ (void) fflush(stdout);
}
if (c < 0)
perror(local);
while ((c = getc(fin)) != EOF) {
if (c == '\n') {
while (hash && (bytes >= hashbytes)) {
- putchar('#');
- fflush(stdout);
+ (void) putchar('#');
+ (void) fflush(stdout);
hashbytes += sizeof (buf);
}
if (ferror(dout))
break;
- putc('\r', dout);
+ (void) putc('\r', dout);
bytes++;
}
- putc(c, dout);
+ (void) putc(c, dout);
bytes++;
/* if (c == '\r') { */
- /* putc('\0', dout); /* this violates rfc */
+ /* (void) putc('\0', dout); /* this violates rfc */
/* bytes++; */
/* } */
}
if (hash) {
if (bytes < hashbytes)
- putchar('#');
- putchar('\n');
- fflush(stdout);
+ (void) putchar('#');
+ (void) putchar('\n');
+ (void) fflush(stdout);
}
if (ferror(fin))
perror(local);
perror("netout");
break;
}
- gettimeofday(&stop, (struct timezone *)0);
+ (void) gettimeofday(&stop, (struct timezone *)0);
if (closefunc != NULL)
(*closefunc)(fin);
(void) fclose(dout);
ptransfer("sent", bytes, &start, &stop, local, remote);
return;
abort:
- gettimeofday(&stop, (struct timezone *)0);
+ (void) gettimeofday(&stop, (struct timezone *)0);
(void) signal(SIGINT, oldintr);
if (oldintp)
(void) signal(SIGPIPE, oldintp);
recvrequest(cmd, local, remote, mode)
char *cmd, *local, *remote, *mode;
{
- FILE *fout, *din = 0, *popen();
- int (*closefunc)(), pclose(), fclose(), (*oldintr)(), (*oldintp)();
+ FILE *fout, *din = 0, *mypopen();
+ int (*closefunc)(), mypclose(), fclose(), (*oldintr)(), (*oldintp)();
int abortrecv(), oldverbose, oldtype = 0, tcrflag;
char buf[BUFSIZ], *gunique();
- long bytes = 0, hashbytes = sizeof (buf), mask;
+ long bytes = 0, hashbytes = sizeof (buf);
+ struct fd_set mask;
register int c, d;
struct timeval start, stop;
fout = stdout;
else if (*local == '|') {
oldintp = signal(SIGPIPE, SIG_IGN);
- fout = popen(local + 1, "w");
+ fout = mypopen(local + 1, "w");
if (fout == NULL) {
perror(local+1);
goto abort;
}
- closefunc = pclose;
+ closefunc = mypclose;
}
else {
fout = fopen(local, mode);
}
closefunc = fclose;
}
- gettimeofday(&start, (struct timezone *)0);
+ (void) gettimeofday(&start, (struct timezone *)0);
switch (type) {
case TYPE_I:
break;
bytes += c;
if (hash) {
- putchar('#');
- fflush(stdout);
+ (void) putchar('#');
+ (void) fflush(stdout);
}
}
if (hash && bytes > 0) {
- putchar('\n');
- fflush(stdout);
+ (void) putchar('\n');
+ (void) fflush(stdout);
}
if (c < 0)
perror("netin");
while ((c = getc(din)) != EOF) {
if (c == '\r') {
while (hash && (bytes >= hashbytes)) {
- putchar('#');
- fflush(stdout);
+ (void) putchar('#');
+ (void) fflush(stdout);
hashbytes += sizeof (buf);
}
bytes++;
if ((c = getc(din)) != '\n' || tcrflag) {
if (ferror (fout))
break;
- putc ('\r', fout);
+ (void) putc ('\r', fout);
}
/*if (c == '\0') {
bytes++;
continue;
}*/
}
- putc (c, fout);
+ (void) putc (c, fout);
bytes++;
}
if (hash) {
if (bytes < hashbytes)
- putchar('#');
- putchar('\n');
- fflush(stdout);
+ (void) putchar('#');
+ (void) putchar('\n');
+ (void) fflush(stdout);
}
if (ferror (din))
perror ("netin");
}
if (closefunc != NULL)
(*closefunc)(fout);
- signal(SIGINT, oldintr);
+ (void) signal(SIGINT, oldintr);
if (oldintp)
(void) signal(SIGPIPE, oldintp);
- gettimeofday(&stop, (struct timezone *)0);
+ (void) gettimeofday(&stop, (struct timezone *)0);
(void) fclose(din);
(void) getreply(0);
if (bytes > 0 && verbose)
/* if server command parser understands TELNET commands, abort using */
/* recommended IP,SYNC sequence */
- gettimeofday(&stop, (struct timezone *)0);
+ (void) gettimeofday(&stop, (struct timezone *)0);
if (oldintp)
(void) signal(SIGPIPE, oldintr);
(void) signal(SIGINT,SIG_IGN);
}
fprintf(cout,"ABOR\r\n");
(void) fflush(cout);
- mask = (1 << fileno(cin)) | (din ? (1 << fileno(din)) : 0);
- if ((mask = empty(mask,10)) < 0) {
+ FD_ZERO((char *) &mask);
+ FD_SET(fileno(cin), &mask);
+ if (din) {
+ FD_SET(fileno(din), &mask);
+ }
+ if (empty(mask,10) < 0) {
perror("abort");
code = -1;
lostpeer();
}
- if (din && mask & (1 << fileno(din)))
+ if (din && FD_ISSET(fileno(din), &mask)) {
while ((c = read(fileno(din), buf, sizeof (buf))) > 0)
;
+ }
if ((c = getreply(0)) == ERROR) { /* needed for nic style abort */
if (data >= 0) {
- close(data);
+ (void) close(data);
data = -1;
}
(void) getreply(0);
{
register char *p, *a;
int result, len, tmpno = 0;
- int on = 1;
+ char on = 1;
noport:
data_addr = myctladdr;
perror("ftp: setsockopt (resuse address)");
goto bad;
}
- if (bind(data, (char *)&data_addr, sizeof (data_addr), 0) < 0) {
+ if (bind(data, (struct sockaddr *)&data_addr, sizeof (data_addr)) < 0) {
perror("ftp: bind");
goto bad;
}
struct sockaddr_in from;
int s, fromlen = sizeof (from);
- s = accept(data, &from, &fromlen, 0);
+ s = accept(data, (struct sockaddr *) &from, &fromlen);
if (s < 0) {
perror("ftp: accept");
(void) close(data), data = -1;
bytes, direction, s, bs / 1024.);
}
-tvadd(tsum, t0)
+/*tvadd(tsum, t0)
struct timeval *tsum, *t0;
{
tsum->tv_usec += t0->tv_usec;
if (tsum->tv_usec > 1000000)
tsum->tv_sec++, tsum->tv_usec -= 1000000;
-}
+} */
tvsub(tdiff, t1, t0)
struct timeval *tdiff, *t1, *t0;
}
ip->connect = connected;
connected = op->connect;
- strncpy(ip->name, hostname, 31);
+ (void) strncpy(ip->name, hostname, 31);
(ip->name)[strlen(ip->name)] = '\0';
hostname = op->name;
ip->hctl = hisctladdr;
mcase = op->mcse;
ip->ntflg = ntflag;
ntflag = op->ntflg;
- strncpy(ip->nti, ntin, 16);
+ (void) strncpy(ip->nti, ntin, 16);
(ip->nti)[strlen(ip->nti)] = '\0';
- strcpy(ntin, op->nti);
- strncpy(ip->nto, ntout, 16);
+ (void) strcpy(ntin, op->nti);
+ (void) strncpy(ip->nto, ntout, 16);
(ip->nto)[strlen(ip->nto)] = '\0';
- strcpy(ntout, op->nto);
+ (void) strcpy(ntout, op->nto);
ip->mapflg = mapflag;
mapflag = op->mapflg;
- strncpy(ip->mi, mapin, MAXPATHLEN - 1);
+ (void) strncpy(ip->mi, mapin, MAXPATHLEN - 1);
(ip->mi)[strlen(ip->mi)] = '\0';
- strcpy(mapin, op->mi);
- strncpy(ip->mo, mapout, MAXPATHLEN - 1);
+ (void) strcpy(mapin, op->mi);
+ (void) strncpy(ip->mo, mapout, MAXPATHLEN - 1);
(ip->mo)[strlen(ip->mo)] = '\0';
- strcpy(mapout, op->mo);
+ (void) strcpy(mapout, op->mo);
(void) signal(SIGINT, oldintr);
if (abrtflag) {
abrtflag = 0;
abortpt()
{
printf("\n");
- fflush(stdout);
+ (void) fflush(stdout);
ptabflg++;
mflag = 0;
abrtflag = 0;
int (*oldintr)(), abortpt(), tmptype, oldtype = 0, secndflag = 0;
extern jmp_buf ptabort;
char *cmd2;
- long mask;
+ struct fd_set mask;
if (strcmp(cmd, "RETR"))
cmd2 = "RETR";
if (cpend) {
fprintf(cout,"ABOR\r\n");
(void) fflush(cout);
- mask = 1 << fileno(cin);
- if ((mask = empty(mask,10)) < 0) {
+ FD_ZERO((char *) &mask);
+ FD_SET(fileno(cin), &mask);
+ if (empty(mask,10) < 0) {
perror("abort");
if (ptabflg)
code = -1;
if (cpend) {
fprintf(cout,"ABOR\r\n");
(void) fflush(cout);
- mask = 1 << fileno(cin);
- if ((mask = empty(mask,10)) < 0) {
+ FD_ZERO((char *) &mask);
+ FD_SET(fileno(cin), &mask);
+ if ((empty(mask,10)) < 0) {
perror("abort");
if (ptabflg)
code = -1;
if (cpend) {
fprintf(cout,"ABOR\r\n");
(void) fflush(cout);
- mask = 1 << fileno(cin);
- if ((mask = empty(mask,10)) < 0) {
+ FD_ZERO((char *) &mask);
+ FD_SET(fileno(cin), &mask);
+ if (empty(mask,10) < 0) {
perror("abort");
if (ptabflg)
code = -1;
if (cpend) {
fprintf(cout,"ABOR\r\n");
(void) fflush(cout);
- mask = 1 << fileno(cin);
- if ((mask = empty(mask,10)) < 0) {
+ FD_ZERO((char *) &mask);
+ FD_SET(fileno(cin), &mask);
+ if (empty(mask,10) < 0) {
perror("abort");
if (ptabflg)
code = -1;
}
pswitch(!proxy);
if (cpend) {
- mask = 1 << fileno(cin);
- if ((mask = empty(mask,10)) < 0) {
+ FD_ZERO((char *) &mask);
+ FD_SET(fileno(cin), &mask);
+ if (empty(mask,10) < 0) {
perror("abort");
if (ptabflg)
code = -1;
reset()
{
- long mask;
+ struct fd_set mask;
+ int nfnd = 1;
- mask = 1 << fileno(cin);
- while (mask > 0) {
- if ((mask = empty(mask,0)) < 0) {
+ FD_ZERO((char *) &mask);
+ while (nfnd) {
+ FD_SET(fileno(cin), &mask);
+ if ((nfnd = empty(mask,0)) < 0) {
perror("reset");
code = -1;
lostpeer();
}
- if (mask > 0)
+ else {
(void) getreply(0);
+ }
}
}