diff --git a/appl/ftp/ftp/ftp.c b/appl/ftp/ftp/ftp.c index 28926f87c..5ee901946 100644 --- a/appl/ftp/ftp/ftp.c +++ b/appl/ftp/ftp/ftp.c @@ -32,36 +32,36 @@ */ #include "ftp_locl.h" -RCSID("$Id$"); +RCSID ("$Id$"); -struct sockaddr_in hisctladdr; -struct sockaddr_in data_addr; -int data = -1; -int abrtflag = 0; -jmp_buf ptabort; -int ptabflg; -int ptflag = 0; -struct sockaddr_in myctladdr; -off_t restart_point = 0; +struct sockaddr_in hisctladdr; +struct sockaddr_in data_addr; +int data = -1; +int abrtflag = 0; +jmp_buf ptabort; +int ptabflg; +int ptflag = 0; +struct sockaddr_in myctladdr; +off_t restart_point = 0; -FILE *cin, *cout; +FILE *cin, *cout; -typedef void (*sighand)(int); +typedef void (*sighand) (int); char * -hookup(char *host, int port) +hookup (char *host, int port) { struct hostent *hp = 0; int s, len; static char hostnamebuf[MaxHostNameLen]; - memset(&hisctladdr, 0, sizeof (hisctladdr)); - if(inet_aton(host, &hisctladdr.sin_addr)){ + memset (&hisctladdr, 0, sizeof (hisctladdr)); + if (inet_aton (host, &hisctladdr.sin_addr)) { hisctladdr.sin_family = AF_INET; strcpy_truncate (hostnamebuf, host, sizeof (hostnamebuf)); } else { - hp = gethostbyname(host); + hp = gethostbyname (host); if (hp == NULL) { warnx("%s: %s", host, hstrerror(h_errno)); code = -1; @@ -74,43 +74,43 @@ hookup(char *host, int port) strcpy_truncate (hostnamebuf, hp->h_name, sizeof (hostnamebuf)); } hostname = hostnamebuf; - s = socket(hisctladdr.sin_family, SOCK_STREAM, 0); + s = socket (hisctladdr.sin_family, SOCK_STREAM, 0); if (s < 0) { - warn("socket"); + warn ("socket"); code = -1; return (0); } hisctladdr.sin_port = port; - while (connect(s, (struct sockaddr *)&hisctladdr, sizeof (hisctladdr)) < 0) { + while (connect (s, (struct sockaddr *) & hisctladdr, sizeof (hisctladdr)) < 0) { if (hp && hp->h_addr_list[1]) { int oerrno = errno; char *ia; - ia = inet_ntoa(hisctladdr.sin_addr); + ia = inet_ntoa (hisctladdr.sin_addr); errno = oerrno; - warn("connect to address %s", ia); + warn ("connect to address %s", ia); hp->h_addr_list++; - memmove(&hisctladdr.sin_addr, - hp->h_addr_list[0], - sizeof(hisctladdr.sin_addr)); - fprintf(stdout, "Trying %s...\n", - inet_ntoa(hisctladdr.sin_addr)); - close(s); - s = socket(hisctladdr.sin_family, SOCK_STREAM, 0); + memmove (&hisctladdr.sin_addr, + hp->h_addr_list[0], + sizeof (hisctladdr.sin_addr)); + fprintf (stdout, "Trying %s...\n", + inet_ntoa (hisctladdr.sin_addr)); + close (s); + s = socket (hisctladdr.sin_family, SOCK_STREAM, 0); if (s < 0) { - warn("socket"); + warn ("socket"); code = -1; return (0); } continue; } - warn("connect"); + warn ("connect"); code = -1; goto bad; } len = sizeof (myctladdr); - if (getsockname(s, (struct sockaddr *)&myctladdr, &len) < 0) { - warn("getsockname"); + if (getsockname (s, (struct sockaddr *) & myctladdr, &len) < 0) { + warn ("getsockname"); code = -1; goto bad; } @@ -122,24 +122,24 @@ hookup(char *host, int port) warn("setsockopt TOS (ignored)"); } #endif - cin = fdopen(s, "r"); - cout = fdopen(s, "w"); + cin = fdopen (s, "r"); + cout = fdopen (s, "w"); if (cin == NULL || cout == NULL) { - warnx("fdopen failed."); + warnx ("fdopen failed."); if (cin) - fclose(cin); + fclose (cin); if (cout) - fclose(cout); + fclose (cout); code = -1; goto bad; } if (verbose) - printf("Connected to %s.\n", hostname); - if (getreply(0) > 2) { /* read startup message from server */ + printf ("Connected to %s.\n", hostname); + if (getreply (0) > 2) { /* read startup message from server */ if (cin) - fclose(cin); + fclose (cin); if (cout) - fclose(cout); + fclose (cout); code = -1; goto bad; } @@ -147,21 +147,21 @@ hookup(char *host, int port) { int on = 1; - if (setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on)) + if (setsockopt (s, SOL_SOCKET, SO_OOBINLINE, (char *) &on, sizeof (on)) < 0 && debug) { - warn("setsockopt"); + warn ("setsockopt"); } } -#endif /* SO_OOBINLINE */ +#endif /* SO_OOBINLINE */ return (hostname); bad: - close(s); + close (s); return NULL; } int -login(char *host) +login (char *host) { char tmp[80]; char defaultpass[128]; @@ -182,17 +182,17 @@ login(char *host) printf("Kerberos authentication successful.\n\n"); } - if (ruserpass(host, &user, &pass, &acct) < 0) { + if (ruserpass (host, &user, &pass, &acct) < 0) { code = -1; return (0); } while (user == NULL) { if (myname) - printf("Name (%s:%s): ", host, myname); + printf ("Name (%s:%s): ", host, myname); else - printf("Name (%s): ", host); - fgets(tmp, sizeof(tmp) - 1, stdin); - tmp[strlen(tmp) - 1] = '\0'; + printf ("Name (%s): ", host); + fgets (tmp, sizeof (tmp) - 1, stdin); + tmp[strlen (tmp) - 1] = '\0'; if (*tmp == '\0') user = myname; else @@ -216,24 +216,24 @@ login(char *host) snprintf(prompt, sizeof(prompt), "Password: "); } pass = defaultpass; - des_read_pw_string (tmp, sizeof(tmp), prompt, 0); - if(tmp[0]) + des_read_pw_string (tmp, sizeof (tmp), prompt, 0); + if (tmp[0]) pass = tmp; } - n = command("PASS %s", pass); + n = command ("PASS %s", pass); } if (n == CONTINUE) { aflag++; acct = tmp; - des_read_pw_string(acct, 128, "Account:", 0); - n = command("ACCT %s", acct); + des_read_pw_string (acct, 128, "Account:", 0); + n = command ("ACCT %s", acct); } if (n != COMPLETE) { - warnx("Login failed."); + warnx ("Login failed."); return (0); } if (!aflag && acct != NULL) - command("ACCT %s", acct); + command ("ACCT %s", acct); if (proxy) return (1); for (n = 0; n < macnum; ++n) { @@ -244,23 +244,23 @@ login(char *host) break; } } - sec_set_protection_level(); + sec_set_protection_level (); return (1); } void -cmdabort(int sig) +cmdabort (int sig) { - printf("\n"); - fflush(stdout); + printf ("\n"); + fflush (stdout); abrtflag++; if (ptflag) - longjmp(ptabort,1); + longjmp (ptabort, 1); } int -command(char *fmt, ...) +command (char *fmt,...) { va_list ap; int r; @@ -268,7 +268,7 @@ command(char *fmt, ...) abrtflag = 0; if (cout == NULL) { - warn("No control connection for command"); + warn ("No control connection for command"); code = -1; return (0); } @@ -288,20 +288,20 @@ command(char *fmt, ...) printf("\n"); fflush(stdout); } - fprintf(cout, "\r\n"); - fflush(cout); + fprintf (cout, "\r\n"); + fflush (cout); cpend = 1; - r = getreply(!strcmp(fmt, "QUIT")); + r = getreply (!strcmp (fmt, "QUIT")); if (abrtflag && oldintr != SIG_IGN) - (*oldintr)(SIGINT); - signal(SIGINT, oldintr); + (*oldintr) (SIGINT); + signal (SIGINT, oldintr); return (r); } -char reply_string[BUFSIZ]; /* last line of previous reply */ +char reply_string[BUFSIZ]; /* last line of previous reply */ int -getreply(int expecteof) +getreply (int expecteof) { char *p; char *lead_string; @@ -309,37 +309,37 @@ getreply(int expecteof) struct sigaction sa, osa; char buf[1024]; - sigemptyset(&sa.sa_mask); + sigemptyset (&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = cmdabort; - sigaction(SIGINT, &sa, &osa); - + sigaction (SIGINT, &sa, &osa); + p = buf; - while(1){ - c = getc(cin); - switch(c){ + while (1) { + c = getc (cin); + switch (c) { case EOF: if (expecteof) { - sigaction(SIGINT,&osa, NULL); + sigaction (SIGINT, &osa, NULL); code = 221; return 0; } - lostpeer(0); + lostpeer (0); if (verbose) { - printf("421 Service not available, " - "remote server has closed connection\n"); - fflush(stdout); + printf ("421 Service not available, " + "remote server has closed connection\n"); + fflush (stdout); } code = 421; return (4); break; case IAC: - c = getc(cin); - if(c == WILL || c == WONT) - fprintf(cout, "%c%c%c", IAC, DONT, getc(cin)); - if(c == DO || c == DONT) - fprintf(cout, "%c%c%c", IAC, WONT, getc(cin)); + c = getc (cin); + if (c == WILL || c == WONT) + fprintf (cout, "%c%c%c", IAC, DONT, getc (cin)); + if (c == DO || c == DONT) + fprintf (cout, "%c%c%c", IAC, WONT, getc (cin)); continue; case '\n': *p++ = '\0'; @@ -361,27 +361,27 @@ getreply(int expecteof) lead_string = "!!"; else lead_string = ""; - if(verbose > 0 || (verbose > -1 && code > 499)) - fprintf(stdout, "%s%s\n", lead_string, buf); - if(buf[3] == ' '){ - strcpy(reply_string, buf); + if (verbose > 0 || (verbose > -1 && code > 499)) + fprintf (stdout, "%s%s\n", lead_string, buf); + if (buf[3] == ' ') { + strcpy (reply_string, buf); if (code >= 200) cpend = 0; - sigaction(SIGINT, &osa, NULL); + sigaction (SIGINT, &osa, NULL); if (code == 421) - lostpeer(0); + lostpeer (0); #if 1 - if (abrtflag && - osa.sa_handler != cmdabort && + if (abrtflag && + osa.sa_handler != cmdabort && osa.sa_handler != SIG_IGN) - osa.sa_handler(SIGINT); + osa.sa_handler (SIGINT); #endif - if(code == 227){ + if (code == 227) { char *p, *q; pasv[0] = 0; - p = strchr(reply_string, '('); - if(p){ + p = strchr (reply_string, '('); + if (p) { p++; q = strchr(p, ')'); if(q){ @@ -405,13 +405,13 @@ getreply(int expecteof) *p++ = c; } } - + } #if 0 int -getreply(int expecteof) +getreply (int expecteof) { int c, n; int dig; @@ -420,24 +420,24 @@ getreply(int expecteof) int pflag = 0; char *cp, *pt = pasv; - oldintr = signal(SIGINT, cmdabort); + oldintr = signal (SIGINT, cmdabort); for (;;) { dig = n = code = 0; cp = reply_string; - while ((c = getc(cin)) != '\n') { - if (c == IAC) { /* handle telnet commands */ - switch (c = getc(cin)) { + while ((c = getc (cin)) != '\n') { + if (c == IAC) { /* handle telnet commands */ + switch (c = getc (cin)) { case WILL: case WONT: - c = getc(cin); - fprintf(cout, "%c%c%c", IAC, DONT, c); - fflush(cout); + c = getc (cin); + fprintf (cout, "%c%c%c", IAC, DONT, c); + fflush (cout); break; case DO: case DONT: - c = getc(cin); - fprintf(cout, "%c%c%c", IAC, WONT, c); - fflush(cout); + c = getc (cin); + fprintf (cout, "%c%c%c", IAC, WONT, c); + fflush (cout); break; default: break; @@ -447,14 +447,14 @@ getreply(int expecteof) dig++; if (c == EOF) { if (expecteof) { - signal(SIGINT,oldintr); + signal (SIGINT, oldintr); code = 221; return (0); } - lostpeer(0); + lostpeer (0); if (verbose) { - printf("421 Service not available, remote server has closed connection\n"); - fflush(stdout); + printf ("421 Service not available, remote server has closed connection\n"); + fflush (stdout); } code = 421; return (4); @@ -463,14 +463,14 @@ getreply(int expecteof) (verbose > -1 && n == '5' && dig > 4))) { if (proxflag && (dig == 1 || dig == 5 && verbose == 0)) - printf("%s:",hostname); - putchar(c); + printf ("%s:", hostname); + putchar (c); } - if (dig < 4 && isdigit(c)) + if (dig < 4 && isdigit (c)) code = code * 10 + (c - '0'); if (!pflag && code == 227) pflag = 1; - if (dig > 4 && pflag == 1 && isdigit(c)) + if (dig > 4 && pflag == 1 && isdigit (c)) pflag = 2; if (pflag == 2) { if (c != '\r' && c != ')') @@ -487,11 +487,11 @@ getreply(int expecteof) } if (n == 0) n = c; - if (cp < &reply_string[sizeof(reply_string) - 1]) + if (cp < &reply_string[sizeof (reply_string) - 1]) *cp++ = c; } if (verbose > 0 || verbose > -1 && n == '5') { - putchar(c); + putchar (c); fflush (stdout); } if (continuation && code != originalcode) { @@ -511,11 +511,11 @@ getreply(int expecteof) } if (n != '1') cpend = 0; - signal(SIGINT,oldintr); + signal (SIGINT, oldintr); if (code == 421 || originalcode == 421) - lostpeer(0); + lostpeer (0); if (abrtflag && oldintr != cmdabort && oldintr != SIG_IGN) - (*oldintr)(SIGINT); + (*oldintr) (SIGINT); return (n - '0'); } } @@ -523,32 +523,32 @@ getreply(int expecteof) #endif int -empty(fd_set *mask, int sec) +empty (fd_set * mask, int sec) { struct timeval t; t.tv_sec = (long) sec; t.tv_usec = 0; - return (select(32, mask, NULL, NULL, &t)); + return (select (32, mask, NULL, NULL, &t)); } -jmp_buf sendabort; +jmp_buf sendabort; static RETSIGTYPE -abortsend(int sig) +abortsend (int sig) { mflag = 0; abrtflag = 0; - printf("\nsend aborted\nwaiting for remote to finish abort\n"); - fflush(stdout); - longjmp(sendabort, 1); + printf ("\nsend aborted\nwaiting for remote to finish abort\n"); + fflush (stdout); + longjmp (sendabort, 1); } #define HASHBYTES 1024 static int -copy_stream(FILE *from, FILE *to) +copy_stream (FILE * from, FILE * to) { static size_t bufsize; static char *buf; @@ -557,7 +557,7 @@ copy_stream(FILE *from, FILE *to) int werr; int hashbytes = HASHBYTES; struct stat st; - + #if defined(HAVE_MMAP) && !defined(NO_MMAP) void *chunk; @@ -565,172 +565,171 @@ copy_stream(FILE *from, FILE *to) #define MAP_FAILED (-1) #endif - if(fstat(fileno(from), &st) == 0 && S_ISREG(st.st_mode)){ - chunk = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fileno(from), 0); - if (chunk != (void *)MAP_FAILED) { + if (fstat (fileno (from), &st) == 0 && S_ISREG (st.st_mode)) { + chunk = mmap (0, st.st_size, PROT_READ, MAP_SHARED, fileno (from), 0); + if (chunk != (void *) MAP_FAILED) { int res; - res = sec_write(fileno(to), chunk, st.st_size); - if (munmap(chunk, st.st_size) < 0) + res = sec_write (fileno (to), chunk, st.st_size); + if (munmap (chunk, st.st_size) < 0) warn ("munmap"); - sec_fflush(to); + sec_fflush (to); return res; } } #endif buf = alloc_buffer (buf, &bufsize, - fstat(fileno(from), &st) >= 0 ? &st : NULL); + fstat (fileno (from), &st) >= 0 ? &st : NULL); if (buf == NULL) return -1; - while((n = read(fileno(from), buf, bufsize)) > 0){ - werr = sec_write(fileno(to), buf, n); - if(werr < 0) + while ((n = read (fileno (from), buf, bufsize)) > 0) { + werr = sec_write (fileno (to), buf, n); + if (werr < 0) break; bytes += werr; - while(hash && bytes > hashbytes){ - putchar('#'); + while (hash && bytes > hashbytes) { + putchar ('#'); hashbytes += HASHBYTES; } } - sec_fflush(to); - if(n < 0) - warn("local"); + sec_fflush (to); + if (n < 0) + warn ("local"); - if(werr < 0){ - if(errno != EPIPE) - warn("netout"); + if (werr < 0) { + if (errno != EPIPE) + warn ("netout"); bytes = -1; } return bytes; } void -sendrequest(char *cmd, char *local, char *remote, int printnames) +sendrequest (char *cmd, char *local, char *remote, int printnames) { struct stat st; struct timeval start, stop; int c, d; FILE *fin, *dout = 0; int (*closefunc) (FILE *); - RETSIGTYPE (*oldintr)(), (*oldintp)(); long bytes = 0, hashbytes = HASHBYTES; char *lmode; if (verbose && printnames) { - if (local && strcmp(local, "-") != 0) - printf("local: %s ", local); + if (local && strcmp (local, "-") != 0) + printf ("local: %s ", local); if (remote) - printf("remote: %s\n", remote); + printf ("remote: %s\n", remote); } if (proxy) { - proxtrans(cmd, local, remote); + proxtrans (cmd, local, remote); return; } if (curtype != type) - changetype(type, 0); + changetype (type, 0); closefunc = NULL; oldintr = NULL; oldintp = NULL; lmode = "w"; - if (setjmp(sendabort)) { + if (setjmp (sendabort)) { while (cpend) { - getreply(0); + getreply (0); } if (data >= 0) { - close(data); + close (data); data = -1; } if (oldintr) - signal(SIGINT,oldintr); + signal (SIGINT, oldintr); if (oldintp) - signal(SIGPIPE,oldintp); + signal (SIGPIPE, oldintp); code = -1; return; } - oldintr = signal(SIGINT, abortsend); - if (strcmp(local, "-") == 0) + oldintr = signal (SIGINT, abortsend); + if (strcmp (local, "-") == 0) fin = stdin; else if (*local == '|') { - oldintp = signal(SIGPIPE,SIG_IGN); - fin = popen(local + 1, "r"); + oldintp = signal (SIGPIPE, SIG_IGN); + fin = popen (local + 1, "r"); if (fin == NULL) { - warn("%s", local + 1); - signal(SIGINT, oldintr); - signal(SIGPIPE, oldintp); + warn ("%s", local + 1); + signal (SIGINT, oldintr); + signal (SIGPIPE, oldintp); code = -1; return; } closefunc = pclose; } else { - fin = fopen(local, "r"); + fin = fopen (local, "r"); if (fin == NULL) { - warn("local: %s", local); - signal(SIGINT, oldintr); + warn ("local: %s", local); + signal (SIGINT, oldintr); code = -1; return; } closefunc = fclose; - if (fstat(fileno(fin), &st) < 0 || - (st.st_mode&S_IFMT) != S_IFREG) { - fprintf(stdout, "%s: not a plain file.\n", local); - signal(SIGINT, oldintr); - fclose(fin); + if (fstat (fileno (fin), &st) < 0 || + (st.st_mode & S_IFMT) != S_IFREG) { + fprintf (stdout, "%s: not a plain file.\n", local); + signal (SIGINT, oldintr); + fclose (fin); code = -1; return; } } - if (initconn()) { - signal(SIGINT, oldintr); + if (initconn ()) { + signal (SIGINT, oldintr); if (oldintp) - signal(SIGPIPE, oldintp); + signal (SIGPIPE, oldintp); code = -1; if (closefunc != NULL) - (*closefunc)(fin); + (*closefunc) (fin); return; } - if (setjmp(sendabort)) + if (setjmp (sendabort)) goto abort; if (restart_point && - (strcmp(cmd, "STOR") == 0 || strcmp(cmd, "APPE") == 0)) { + (strcmp (cmd, "STOR") == 0 || strcmp (cmd, "APPE") == 0)) { int rc; switch (curtype) { case TYPE_A: - rc = fseek(fin, (long) restart_point, SEEK_SET); + rc = fseek (fin, (long) restart_point, SEEK_SET); break; case TYPE_I: case TYPE_L: - rc = lseek(fileno(fin), restart_point, SEEK_SET); + rc = lseek (fileno (fin), restart_point, SEEK_SET); break; } if (rc < 0) { - warn("local: %s", local); + warn ("local: %s", local); restart_point = 0; if (closefunc != NULL) - (*closefunc)(fin); + (*closefunc) (fin); return; } - if (command("REST %ld", (long) restart_point) + if (command ("REST %ld", (long) restart_point) != CONTINUE) { restart_point = 0; if (closefunc != NULL) - (*closefunc)(fin); + (*closefunc) (fin); return; } restart_point = 0; lmode = "r+w"; } if (remote) { - if (command("%s %s", cmd, remote) != PRELIM) { - signal(SIGINT, oldintr); + if (command ("%s %s", cmd, remote) != PRELIM) { + signal (SIGINT, oldintr); if (oldintp) - signal(SIGPIPE, oldintp); + signal (SIGPIPE, oldintp); if (closefunc != NULL) - (*closefunc)(fin); + (*closefunc) (fin); return; } } else if (command ("%s", cmd) != PRELIM) { @@ -744,99 +743,99 @@ sendrequest(char *cmd, char *local, char *remote, int printnames) dout = dataconn(lmode); if (dout == NULL) goto abort; - set_buffer_size(fileno(dout), 0); - gettimeofday(&start, (struct timezone *)0); - oldintp = signal(SIGPIPE, SIG_IGN); + set_buffer_size (fileno (dout), 0); + gettimeofday (&start, (struct timezone *) 0); + oldintp = signal (SIGPIPE, SIG_IGN); switch (curtype) { case TYPE_I: case TYPE_L: errno = d = c = 0; - bytes = copy_stream(fin, dout); + bytes = copy_stream (fin, dout); break; case TYPE_A: - while ((c = getc(fin)) != EOF) { + while ((c = getc (fin)) != EOF) { if (c == '\n') { while (hash && (bytes >= hashbytes)) { - putchar('#'); - fflush(stdout); + putchar ('#'); + fflush (stdout); hashbytes += HASHBYTES; } - if (ferror(dout)) + if (ferror (dout)) break; - sec_putc('\r', dout); + sec_putc ('\r', dout); bytes++; } - sec_putc(c, dout); + sec_putc (c, dout); bytes++; } - sec_fflush(dout); + sec_fflush (dout); if (hash) { if (bytes < hashbytes) - putchar('#'); - putchar('\n'); - fflush(stdout); + putchar ('#'); + putchar ('\n'); + fflush (stdout); } - if (ferror(fin)) - warn("local: %s", local); - if (ferror(dout)) { + if (ferror (fin)) + warn ("local: %s", local); + if (ferror (dout)) { if (errno != EPIPE) - warn("netout"); + warn ("netout"); bytes = -1; } break; } if (closefunc != NULL) - (*closefunc)(fin); - fclose(dout); - gettimeofday(&stop, (struct timezone *)0); - getreply(0); - signal(SIGINT, oldintr); + (*closefunc) (fin); + fclose (dout); + gettimeofday (&stop, (struct timezone *) 0); + getreply (0); + signal (SIGINT, oldintr); if (oldintp) - signal(SIGPIPE, oldintp); + signal (SIGPIPE, oldintp); if (bytes > 0) - ptransfer("sent", bytes, &start, &stop); + ptransfer ("sent", bytes, &start, &stop); return; abort: - signal(SIGINT, oldintr); + signal (SIGINT, oldintr); if (oldintp) - signal(SIGPIPE, oldintp); + signal (SIGPIPE, oldintp); if (!cpend) { code = -1; return; } if (data >= 0) { - close(data); + close (data); data = -1; } if (dout) - fclose(dout); - getreply(0); + fclose (dout); + getreply (0); code = -1; if (closefunc != NULL && fin != NULL) - (*closefunc)(fin); - gettimeofday(&stop, (struct timezone *)0); + (*closefunc) (fin); + gettimeofday (&stop, (struct timezone *) 0); if (bytes > 0) - ptransfer("sent", bytes, &start, &stop); + ptransfer ("sent", bytes, &start, &stop); } -jmp_buf recvabort; +jmp_buf recvabort; void -abortrecv(int sig) +abortrecv (int sig) { mflag = 0; abrtflag = 0; - printf("\nreceive aborted\nwaiting for remote to finish abort\n"); - fflush(stdout); - longjmp(recvabort, 1); + printf ("\nreceive aborted\nwaiting for remote to finish abort\n"); + fflush (stdout); + longjmp (recvabort, 1); } void -recvrequest(char *cmd, char *local, char *remote, - char *lmode, int printnames, int local_given) +recvrequest (char *cmd, char *local, char *remote, + char *lmode, int printnames, int local_given) { FILE *fout, *din = 0; int (*closefunc) (FILE *); @@ -848,67 +847,67 @@ recvrequest(char *cmd, char *local, char *remote, struct timeval start, stop; struct stat st; - is_retr = strcmp(cmd, "RETR") == 0; + is_retr = strcmp (cmd, "RETR") == 0; if (is_retr && verbose && printnames) { - if (local && strcmp(local, "-") != 0) - printf("local: %s ", local); + if (local && strcmp (local, "-") != 0) + printf ("local: %s ", local); if (remote) - printf("remote: %s\n", remote); + printf ("remote: %s\n", remote); } if (proxy && is_retr) { - proxtrans(cmd, local, remote); + proxtrans (cmd, local, remote); return; } closefunc = NULL; oldintr = NULL; oldintp = NULL; tcrflag = !crflag && is_retr; - if (setjmp(recvabort)) { + if (setjmp (recvabort)) { while (cpend) { - getreply(0); + getreply (0); } if (data >= 0) { - close(data); + close (data); data = -1; } if (oldintr) - signal(SIGINT, oldintr); + signal (SIGINT, oldintr); code = -1; return; } - oldintr = signal(SIGINT, abortrecv); - if (!local_given || (strcmp(local, "-") && *local != '|')) { - if (access(local, 2) < 0) { - char *dir = strrchr(local, '/'); + oldintr = signal (SIGINT, abortrecv); + if (!local_given || (strcmp (local, "-") && *local != '|')) { + if (access (local, 2) < 0) { + char *dir = strrchr (local, '/'); if (errno != ENOENT && errno != EACCES) { - warn("local: %s", local); - signal(SIGINT, oldintr); + warn ("local: %s", local); + signal (SIGINT, oldintr); code = -1; return; } if (dir != NULL) *dir = 0; - d = access(dir ? local : ".", 2); + d = access (dir ? local : ".", 2); if (dir != NULL) *dir = '/'; if (d < 0) { - warn("local: %s", local); - signal(SIGINT, oldintr); + warn ("local: %s", local); + signal (SIGINT, oldintr); code = -1; return; } if (!runique && errno == EACCES && - chmod(local, 0600) < 0) { - warn("local: %s", local); - signal(SIGINT, oldintr); - signal(SIGINT, oldintr); + chmod (local, 0600) < 0) { + warn ("local: %s", local); + signal (SIGINT, oldintr); + signal (SIGINT, oldintr); code = -1; return; } if (runique && errno == EACCES && - (local = gunique(local)) == NULL) { - signal(SIGINT, oldintr); + (local = gunique (local)) == NULL) { + signal (SIGINT, oldintr); code = -1; return; } @@ -920,98 +919,98 @@ recvrequest(char *cmd, char *local, char *remote, } if (!is_retr) { if (curtype != TYPE_A) - changetype(TYPE_A, 0); + changetype (TYPE_A, 0); } else if (curtype != type) - changetype(type, 0); - if (initconn()) { - signal(SIGINT, oldintr); + changetype (type, 0); + if (initconn ()) { + signal (SIGINT, oldintr); code = -1; return; } - if (setjmp(recvabort)) + if (setjmp (recvabort)) goto abort; if (is_retr && restart_point && - command("REST %ld", (long) restart_point) != CONTINUE) + command ("REST %ld", (long) restart_point) != CONTINUE) return; if (remote) { - if (command("%s %s", cmd, remote) != PRELIM) { - signal(SIGINT, oldintr); + if (command ("%s %s", cmd, remote) != PRELIM) { + signal (SIGINT, oldintr); return; } } else { - if (command("%s", cmd) != PRELIM) { - signal(SIGINT, oldintr); + if (command ("%s", cmd) != PRELIM) { + signal (SIGINT, oldintr); return; } } - din = dataconn("r"); + din = dataconn ("r"); if (din == NULL) goto abort; - set_buffer_size(fileno(din), 1); - if (local_given && strcmp(local, "-") == 0) + set_buffer_size (fileno (din), 1); + if (local_given && strcmp (local, "-") == 0) fout = stdout; else if (local_given && *local == '|') { - oldintp = signal(SIGPIPE, SIG_IGN); - fout = popen(local + 1, "w"); + oldintp = signal (SIGPIPE, SIG_IGN); + fout = popen (local + 1, "w"); if (fout == NULL) { - warn("%s", local+1); + warn ("%s", local + 1); goto abort; } closefunc = pclose; } else { - fout = fopen(local, lmode); + fout = fopen (local, lmode); if (fout == NULL) { - warn("local: %s", local); + warn ("local: %s", local); goto abort; } closefunc = fclose; } buf = alloc_buffer (buf, &bufsize, - fstat(fileno(fout), &st) >= 0 ? &st : NULL); + fstat (fileno (fout), &st) >= 0 ? &st : NULL); if (buf == NULL) goto abort; - gettimeofday(&start, (struct timezone *)0); + gettimeofday (&start, (struct timezone *) 0); switch (curtype) { case TYPE_I: case TYPE_L: if (restart_point && - lseek(fileno(fout), restart_point, SEEK_SET) < 0) { - warn("local: %s", local); + lseek (fileno (fout), restart_point, SEEK_SET) < 0) { + warn ("local: %s", local); if (closefunc != NULL) - (*closefunc)(fout); + (*closefunc) (fout); return; } errno = d = 0; - while ((c = sec_read(fileno(din), buf, bufsize)) > 0) { - if ((d = write(fileno(fout), buf, c)) != c) + while ((c = sec_read (fileno (din), buf, bufsize)) > 0) { + if ((d = write (fileno (fout), buf, c)) != c) break; bytes += c; if (hash) { while (bytes >= hashbytes) { - putchar('#'); + putchar ('#'); hashbytes += HASHBYTES; } - fflush(stdout); + fflush (stdout); } } if (hash && bytes > 0) { if (bytes < HASHBYTES) - putchar('#'); - putchar('\n'); - fflush(stdout); + putchar ('#'); + putchar ('\n'); + fflush (stdout); } if (c < 0) { if (errno != EPIPE) - warn("netin"); + warn ("netin"); bytes = -1; } if (d < c) { if (d < 0) - warn("local: %s", local); + warn ("local: %s", local); else - warnx("%s: short write", local); + warnx ("%s: short write", local); } break; @@ -1019,20 +1018,20 @@ recvrequest(char *cmd, char *local, char *remote, if (restart_point) { int i, n, ch; - if (fseek(fout, 0L, SEEK_SET) < 0) + if (fseek (fout, 0L, SEEK_SET) < 0) goto done; n = restart_point; for (i = 0; i++ < n;) { - if ((ch = sec_getc(fout)) == EOF) + if ((ch = sec_getc (fout)) == EOF) goto done; if (ch == '\n') i++; } - if (fseek(fout, 0L, SEEK_CUR) < 0) { - done: - warn("local: %s", local); + if (fseek (fout, 0L, SEEK_CUR) < 0) { + done: + warn ("local: %s", local); if (closefunc != NULL) - (*closefunc)(fout); + (*closefunc) (fout); return; } } @@ -1041,15 +1040,15 @@ recvrequest(char *cmd, char *local, char *remote, bare_lfs++; while (c == '\r') { while (hash && (bytes >= hashbytes)) { - putchar('#'); - fflush(stdout); + putchar ('#'); + fflush (stdout); hashbytes += HASHBYTES; } bytes++; - if ((c = sec_getc(din)) != '\n' || tcrflag) { - if (ferror(fout)) + if ((c = sec_getc (din)) != '\n' || tcrflag) { + if (ferror (fout)) goto break2; - putc('\r', fout); + putc ('\r', fout); if (c == '\0') { bytes++; goto contin2; @@ -1058,68 +1057,68 @@ recvrequest(char *cmd, char *local, char *remote, goto contin2; } } - putc(c, fout); + putc (c, fout); bytes++; - contin2: ; + contin2:; } - break2: +break2: if (bare_lfs) { - printf("WARNING! %d bare linefeeds received in ASCII mode\n", - bare_lfs); - printf("File may not have transferred correctly.\n"); + printf ("WARNING! %d bare linefeeds received in ASCII mode\n", + bare_lfs); + printf ("File may not have transferred correctly.\n"); } if (hash) { if (bytes < hashbytes) - putchar('#'); - putchar('\n'); - fflush(stdout); + putchar ('#'); + putchar ('\n'); + fflush (stdout); } - if (ferror(din)) { + if (ferror (din)) { if (errno != EPIPE) - warn("netin"); + warn ("netin"); bytes = -1; } - if (ferror(fout)) - warn("local: %s", local); + if (ferror (fout)) + warn ("local: %s", local); break; } if (closefunc != NULL) - (*closefunc)(fout); - signal(SIGINT, oldintr); + (*closefunc) (fout); + signal (SIGINT, oldintr); if (oldintp) - signal(SIGPIPE, oldintp); - fclose(din); - gettimeofday(&stop, (struct timezone *)0); - getreply(0); + signal (SIGPIPE, oldintp); + fclose (din); + gettimeofday (&stop, (struct timezone *) 0); + getreply (0); if (bytes > 0 && is_retr) - ptransfer("received", bytes, &start, &stop); + ptransfer ("received", bytes, &start, &stop); return; abort: /* abort using RFC959 recommended IP,SYNC sequence */ if (oldintp) - signal(SIGPIPE, oldintr); - signal(SIGINT, SIG_IGN); + signal (SIGPIPE, oldintr); + signal (SIGINT, SIG_IGN); if (!cpend) { code = -1; - signal(SIGINT, oldintr); + signal (SIGINT, oldintr); return; } abort_remote(din); code = -1; if (data >= 0) { - close(data); + close (data); data = -1; } if (closefunc != NULL && fout != NULL) - (*closefunc)(fout); + (*closefunc) (fout); if (din) - fclose(din); - gettimeofday(&stop, (struct timezone *)0); + fclose (din); + gettimeofday (&stop, (struct timezone *) 0); if (bytes > 0) - ptransfer("received", bytes, &start, &stop); - signal(SIGINT, oldintr); + ptransfer ("received", bytes, &start, &stop); + signal (SIGINT, oldintr); } /* @@ -1127,26 +1126,26 @@ abort: * otherwise the server's connect may fail. */ int -initconn(void) +initconn (void) { int result, len, tmpno = 0; int on = 1; int a0, a1, a2, a3, p0, p1; if (passivemode) { - data = socket(AF_INET, SOCK_STREAM, 0); + data = socket (AF_INET, SOCK_STREAM, 0); if (data < 0) { - perror("ftp: socket"); - return(1); + perror ("ftp: socket"); + return (1); } #if defined(SO_DEBUG) && defined(HAVE_SETSOCKOPT) if ((options & SO_DEBUG) && - setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on, - sizeof (on)) < 0) - perror("ftp: setsockopt (ignored)"); + setsockopt (data, SOL_SOCKET, SO_DEBUG, (char *) &on, + sizeof (on)) < 0) + perror ("ftp: setsockopt (ignored)"); #endif - if (command("PASV") != COMPLETE) { - printf("Passive mode refused.\n"); + if (command ("PASV") != COMPLETE) { + printf ("Passive mode refused.\n"); goto bad; } @@ -1157,76 +1156,76 @@ initconn(void) * LSB. From that we'll prepare a sockaddr_in. */ - if (sscanf(pasv,"%d,%d,%d,%d,%d,%d", - &a0, &a1, &a2, &a3, &p0, &p1) != 6) { - printf("Passive mode address scan failure. " - "Shouldn't happen!\n"); + if (sscanf (pasv, "%d,%d,%d,%d,%d,%d", + &a0, &a1, &a2, &a3, &p0, &p1) != 6) { + printf ("Passive mode address scan failure. " + "Shouldn't happen!\n"); goto bad; } - if(a0 < 0 || a0 > 255 || - a1 < 0 || a1 > 255 || - a2 < 0 || a2 > 255 || - a3 < 0 || a3 > 255 || - p0 < 0 || p0 > 255 || - p1 < 0 || p1 > 255){ - printf("Can't parse passive mode string.\n"); + if (a0 < 0 || a0 > 255 || + a1 < 0 || a1 > 255 || + a2 < 0 || a2 > 255 || + a3 < 0 || a3 > 255 || + p0 < 0 || p0 > 255 || + p1 < 0 || p1 > 255) { + printf ("Can't parse passive mode string.\n"); goto bad; } memset(&data_addr, 0, sizeof(data_addr)); data_addr.sin_family = AF_INET; - data_addr.sin_addr.s_addr = htonl((a0 << 24) | (a1 << 16) | - (a2 << 8) | a3); - data_addr.sin_port = htons((p0 << 8) | p1); + data_addr.sin_addr.s_addr = htonl ((a0 << 24) | (a1 << 16) | + (a2 << 8) | a3); + data_addr.sin_port = htons ((p0 << 8) | p1); - if (connect(data, (struct sockaddr *)&data_addr, - sizeof(data_addr)) < 0) { - perror("ftp: connect"); + if (connect (data, (struct sockaddr *) & data_addr, + sizeof (data_addr)) < 0) { + perror ("ftp: connect"); goto bad; } #if defined(IP_TOS) && defined(HAVE_SETSOCKOPT) on = IPTOS_THROUGHPUT; - if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&on, - sizeof(int)) < 0) - perror("ftp: setsockopt TOS (ignored)"); + if (setsockopt (data, IPPROTO_IP, IP_TOS, (char *) &on, + sizeof (int)) < 0) + perror ("ftp: setsockopt TOS (ignored)"); #endif - return(0); + return (0); } noport: data_addr = myctladdr; if (sendport) - data_addr.sin_port = 0; /* let system pick one */ + data_addr.sin_port = 0; /* let system pick one */ if (data != -1) - close(data); - data = socket(AF_INET, SOCK_STREAM, 0); + close (data); + data = socket (AF_INET, SOCK_STREAM, 0); if (data < 0) { - warn("socket"); + warn ("socket"); if (tmpno) sendport = 1; return (1); } #if defined(SO_REUSEADDR) && defined(HAVE_SETSOCKOPT) if (!sendport) - if (setsockopt(data, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof (on)) < 0) { - warn("setsockopt (reuse address)"); + if (setsockopt (data, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) { + warn ("setsockopt (reuse address)"); goto bad; } #endif - if (bind(data, (struct sockaddr *)&data_addr, sizeof (data_addr)) < 0) { - warn("bind"); + if (bind (data, (struct sockaddr *) & data_addr, sizeof (data_addr)) < 0) { + warn ("bind"); goto bad; } #if defined(SO_DEBUG) && defined(HAVE_SETSOCKOPT) if (options & SO_DEBUG && - setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on, sizeof (on)) < 0) - warn("setsockopt (ignored)"); + setsockopt (data, SOL_SOCKET, SO_DEBUG, (char *) &on, sizeof (on)) < 0) + warn ("setsockopt (ignored)"); #endif len = sizeof (data_addr); - if (getsockname(data, (struct sockaddr *)&data_addr, &len) < 0) { - warn("getsockname"); + if (getsockname (data, (struct sockaddr *) & data_addr, &len) < 0) { + warn ("getsockname"); goto bad; } - if (listen(data, 1) < 0) - warn("listen"); + if (listen (data, 1) < 0) + warn ("listen"); if (sendport) { unsigned int a = ntohl(data_addr.sin_addr.s_addr); unsigned int p = ntohs(data_addr.sin_port); @@ -1249,88 +1248,88 @@ noport: sendport = 1; #if defined(IP_TOS) && defined(HAVE_SETSOCKOPT) on = IPTOS_THROUGHPUT; - if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&on, sizeof(int)) < 0) - warn("setsockopt TOS (ignored)"); + if (setsockopt (data, IPPROTO_IP, IP_TOS, (char *) &on, sizeof (int)) < 0) + warn ("setsockopt TOS (ignored)"); #endif return (0); bad: - close(data), data = -1; + close (data), data = -1; if (tmpno) sendport = 1; return (1); } FILE * -dataconn(char *lmode) +dataconn (char *lmode) { struct sockaddr_in from; int s, fromlen = sizeof (from), tos; if (passivemode) - return (fdopen(data, lmode)); + return (fdopen (data, lmode)); - s = accept(data, (struct sockaddr *) &from, &fromlen); + s = accept (data, (struct sockaddr *) & from, &fromlen); if (s < 0) { - warn("accept"); - close(data), data = -1; + warn ("accept"); + close (data), data = -1; return (NULL); } - close(data); + close (data); data = s; #if defined(IP_TOS) && defined(HAVE_SETSOCKOPT) tos = IPTOS_THROUGHPUT; - if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) < 0) - warn("setsockopt TOS (ignored)"); + if (setsockopt (s, IPPROTO_IP, IP_TOS, (char *) &tos, sizeof (int)) < 0) + warn ("setsockopt TOS (ignored)"); #endif - return (fdopen(data, lmode)); + return (fdopen (data, lmode)); } void -ptransfer(char *direction, long int bytes, - struct timeval *t0, struct timeval *t1) +ptransfer (char *direction, long int bytes, + struct timeval * t0, struct timeval * t1) { struct timeval td; float s; float bs; int prec; char *unit; - + if (verbose) { td.tv_sec = t1->tv_sec - t0->tv_sec; td.tv_usec = t1->tv_usec - t0->tv_usec; - if(td.tv_usec < 0){ + if (td.tv_usec < 0) { td.tv_sec--; td.tv_usec += 1000000; } s = td.tv_sec + (td.tv_usec / 1000000.); - bs = bytes / (s?s:1); - if(bs >= 1048576){ + bs = bytes / (s ? s : 1); + if (bs >= 1048576) { bs /= 1048576; unit = "M"; prec = 2; - }else if(bs >= 1024){ + } else if (bs >= 1024) { bs /= 1024; unit = "k"; prec = 1; - }else{ + } else { unit = ""; prec = 0; } - - printf("%ld bytes %s in %.3g seconds (%.*f %sbyte/s)\n", - bytes, direction, s, prec, bs, unit); + + printf ("%ld bytes %s in %.3g seconds (%.*f %sbyte/s)\n", + bytes, direction, s, prec, bs, unit); } } void -psabort(int sig) +psabort (int sig) { abrtflag++; } void -pswitch(int flag) +pswitch (int flag) { sighand oldintr; static struct comvars { @@ -1356,7 +1355,7 @@ pswitch(int flag) struct comvars *ip, *op; abrtflag = 0; - oldintr = signal(SIGINT, psabort); + oldintr = signal (SIGINT, psabort); if (flag) { if (proxy) return; @@ -1412,31 +1411,31 @@ pswitch(int flag) signal(SIGINT, oldintr); if (abrtflag) { abrtflag = 0; - (*oldintr)(SIGINT); + (*oldintr) (SIGINT); } } void -abortpt(int sig) +abortpt (int sig) { - printf("\n"); - fflush(stdout); + printf ("\n"); + fflush (stdout); ptabflg++; mflag = 0; abrtflag = 0; - longjmp(ptabort, 1); + longjmp (ptabort, 1); } void -proxtrans(char *cmd, char *local, char *remote) +proxtrans (char *cmd, char *local, char *remote) { sighand oldintr; int secndflag = 0, prox_type, nfnd; char *cmd2; fd_set mask; - if (strcmp(cmd, "RETR")) + if (strcmp (cmd, "RETR")) cmd2 = "RETR"; else cmd2 = runique ? "STOU" : "STOR"; @@ -1447,116 +1446,116 @@ proxtrans(char *cmd, char *local, char *remote) prox_type = TYPE_A; } if (curtype != prox_type) - changetype(prox_type, 1); - if (command("PASV") != COMPLETE) { - printf("proxy server does not support third party transfers.\n"); + changetype (prox_type, 1); + if (command ("PASV") != COMPLETE) { + printf ("proxy server does not support third party transfers.\n"); return; } - pswitch(0); + pswitch (0); if (!connected) { - printf("No primary connection\n"); - pswitch(1); + printf ("No primary connection\n"); + pswitch (1); code = -1; return; } if (curtype != prox_type) - changetype(prox_type, 1); - if (command("PORT %s", pasv) != COMPLETE) { - pswitch(1); + changetype (prox_type, 1); + if (command ("PORT %s", pasv) != COMPLETE) { + pswitch (1); return; } - if (setjmp(ptabort)) + if (setjmp (ptabort)) goto abort; - oldintr = signal(SIGINT, abortpt); - if (command("%s %s", cmd, remote) != PRELIM) { - signal(SIGINT, oldintr); - pswitch(1); + oldintr = signal (SIGINT, abortpt); + if (command ("%s %s", cmd, remote) != PRELIM) { + signal (SIGINT, oldintr); + pswitch (1); return; } - sleep(2); - pswitch(1); + sleep (2); + pswitch (1); secndflag++; - if (command("%s %s", cmd2, local) != PRELIM) + if (command ("%s %s", cmd2, local) != PRELIM) goto abort; ptflag++; - getreply(0); - pswitch(0); - getreply(0); - signal(SIGINT, oldintr); - pswitch(1); + getreply (0); + pswitch (0); + getreply (0); + signal (SIGINT, oldintr); + pswitch (1); ptflag = 0; - printf("local: %s remote: %s\n", local, remote); + printf ("local: %s remote: %s\n", local, remote); return; abort: - signal(SIGINT, SIG_IGN); + signal (SIGINT, SIG_IGN); ptflag = 0; - if (strcmp(cmd, "RETR") && !proxy) - pswitch(1); - else if (!strcmp(cmd, "RETR") && proxy) - pswitch(0); - if (!cpend && !secndflag) { /* only here if cmd = "STOR" (proxy=1) */ - if (command("%s %s", cmd2, local) != PRELIM) { - pswitch(0); + if (strcmp (cmd, "RETR") && !proxy) + pswitch (1); + else if (!strcmp (cmd, "RETR") && proxy) + pswitch (0); + if (!cpend && !secndflag) { /* only here if cmd = "STOR" (proxy=1) */ + if (command ("%s %s", cmd2, local) != PRELIM) { + pswitch (0); if (cpend) - abort_remote((FILE *) NULL); + abort_remote ((FILE *) NULL); } - pswitch(1); + pswitch (1); if (ptabflg) code = -1; - signal(SIGINT, oldintr); + signal (SIGINT, oldintr); return; } if (cpend) - abort_remote((FILE *) NULL); - pswitch(!proxy); - if (!cpend && !secndflag) { /* only if cmd = "RETR" (proxy=1) */ - if (command("%s %s", cmd2, local) != PRELIM) { - pswitch(0); + abort_remote ((FILE *) NULL); + pswitch (!proxy); + if (!cpend && !secndflag) { /* only if cmd = "RETR" (proxy=1) */ + if (command ("%s %s", cmd2, local) != PRELIM) { + pswitch (0); if (cpend) - abort_remote((FILE *) NULL); - pswitch(1); + abort_remote ((FILE *) NULL); + pswitch (1); if (ptabflg) code = -1; - signal(SIGINT, oldintr); + signal (SIGINT, oldintr); return; } } if (cpend) - abort_remote((FILE *) NULL); - pswitch(!proxy); + abort_remote ((FILE *) NULL); + pswitch (!proxy); if (cpend) { - FD_ZERO(&mask); - FD_SET(fileno(cin), &mask); - if ((nfnd = empty(&mask, 10)) <= 0) { + FD_ZERO (&mask); + FD_SET (fileno (cin), &mask); + if ((nfnd = empty (&mask, 10)) <= 0) { if (nfnd < 0) { - warn("abort"); + warn ("abort"); } if (ptabflg) code = -1; - lostpeer(0); + lostpeer (0); } - getreply(0); - getreply(0); + getreply (0); + getreply (0); } if (proxy) - pswitch(0); - pswitch(1); + pswitch (0); + pswitch (1); if (ptabflg) code = -1; - signal(SIGINT, oldintr); + signal (SIGINT, oldintr); } void -reset(int argc, char **argv) +reset (int argc, char **argv) { fd_set mask; int nfnd = 1; - FD_ZERO(&mask); + FD_ZERO (&mask); while (nfnd > 0) { - FD_SET(fileno(cin), &mask); - if ((nfnd = empty(&mask,0)) < 0) { - warn("reset"); + FD_SET (fileno (cin), &mask); + if ((nfnd = empty (&mask, 0)) < 0) { + warn ("reset"); code = -1; lostpeer(0); } else if (nfnd) { @@ -1566,20 +1565,20 @@ reset(int argc, char **argv) } char * -gunique(char *local) +gunique (char *local) { static char new[MaxPathLen]; - char *cp = strrchr(local, '/'); - int d, count=0; + char *cp = strrchr (local, '/'); + int d, count = 0; char ext = '1'; if (cp) *cp = '\0'; - d = access(cp ? local : ".", 2); + d = access (cp ? local : ".", 2); if (cp) *cp = '/'; if (d < 0) { - warn("local: %s", local); + warn ("local: %s", local); return NULL; } strcpy_truncate (new, local, sizeof(new)); @@ -1587,7 +1586,7 @@ gunique(char *local) *cp++ = '.'; while (!d) { if (++count == 100) { - printf("runique: can't find unique file name.\n"); + printf ("runique: can't find unique file name.\n"); return NULL; } *cp++ = ext; @@ -1596,7 +1595,7 @@ gunique(char *local) ext = '0'; else ext++; - if ((d = access(new, 0)) < 0) + if ((d = access (new, 0)) < 0) break; if (ext != '0') cp--; @@ -1611,7 +1610,7 @@ gunique(char *local) } void -abort_remote(FILE *din) +abort_remote (FILE * din) { char buf[BUFSIZ]; int nfnd; @@ -1621,31 +1620,31 @@ abort_remote(FILE *din) * send IAC in urgent mode instead of DM because 4.3BSD places oob mark * after urgent byte rather than before as is protocol now */ - snprintf(buf, sizeof(buf), "%c%c%c", IAC, IP, IAC); - if (send(fileno(cout), buf, 3, MSG_OOB) != 3) - warn("abort"); - fprintf(cout,"%cABOR\r\n", DM); - fflush(cout); - FD_ZERO(&mask); - FD_SET(fileno(cin), &mask); - if (din) { - FD_SET(fileno(din), &mask); + snprintf (buf, sizeof (buf), "%c%c%c", IAC, IP, IAC); + if (send (fileno (cout), buf, 3, MSG_OOB) != 3) + warn ("abort"); + fprintf (cout, "%cABOR\r\n", DM); + fflush (cout); + FD_ZERO (&mask); + FD_SET (fileno (cin), &mask); + if (din) { + FD_SET (fileno (din), &mask); } - if ((nfnd = empty(&mask, 10)) <= 0) { + if ((nfnd = empty (&mask, 10)) <= 0) { if (nfnd < 0) { - warn("abort"); + warn ("abort"); } if (ptabflg) code = -1; - lostpeer(0); + lostpeer (0); } - if (din && FD_ISSET(fileno(din), &mask)) { - while (read(fileno(din), buf, BUFSIZ) > 0) - /* LOOP */; + if (din && FD_ISSET (fileno (din), &mask)) { + while (read (fileno (din), buf, BUFSIZ) > 0) + /* LOOP */ ; } - if (getreply(0) == ERROR && code == 552) { + if (getreply (0) == ERROR && code == 552) { /* 552 needed for nic style abort */ - getreply(0); + getreply (0); } - getreply(0); + getreply (0); } diff --git a/appl/ftp/ftp/ftp_locl.h b/appl/ftp/ftp/ftp_locl.h index 93c6d8c7c..0e97ad225 100644 --- a/appl/ftp/ftp/ftp_locl.h +++ b/appl/ftp/ftp/ftp_locl.h @@ -119,7 +119,12 @@ #ifdef SOCKS #include -extern int LIBPREFIX(fclose) __P((FILE *)); +extern int LIBPREFIX(fclose) (FILE *); + +/* This doesn't belong here. */ +struct tm *localtime(const time_t *); +struct hostent *gethostbyname(const char *); + #endif #include "ftp_var.h" diff --git a/appl/ftp/ftp/krb4.c b/appl/ftp/ftp/krb4.c index c84810353..c545ceaf1 100644 --- a/appl/ftp/ftp/krb4.c +++ b/appl/ftp/ftp/krb4.c @@ -203,6 +203,7 @@ mk_auth(struct krb4_data *d, KTEXT adat, int ret; CREDENTIALS cred; char sname[SNAME_SZ], inst[INST_SZ], realm[REALM_SZ]; + strcpy_truncate(sname, service, sizeof(sname)); strcpy_truncate(inst, krb_get_phost(host), sizeof(inst)); strcpy_truncate(realm, krb_realmofhost(host), sizeof(realm)); diff --git a/appl/ftp/ftpd/ftpcmd.y b/appl/ftp/ftpd/ftpcmd.y index f1e97e4a0..9b9dd3003 100644 --- a/appl/ftp/ftpd/ftpcmd.y +++ b/appl/ftp/ftpd/ftpcmd.y @@ -1100,7 +1100,7 @@ yylex(void) #ifdef HAVE_SETPROCTITLE if (strncasecmp(cbuf, "PASS", 4) != NULL) setproctitle("%s: %s", proctitle, cbuf); -#endif +#endif /* HAVE_SETPROCTITLE */ if ((cp = strchr(cbuf, '\r'))) { *cp++ = '\n'; *cp = '\0'; @@ -1385,7 +1385,8 @@ sizecmd(char *filename) reply(550, "%s: not a plain file.", filename); else reply(213, "%lu", (unsigned long)stbuf.st_size); - break; } + break; + } case TYPE_A: { FILE *fin; int c; @@ -1411,7 +1412,8 @@ sizecmd(char *filename) fclose(fin); reply(213, "%lu", (unsigned long)count); - break; } + break; + } default: reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]); } diff --git a/appl/ftp/ftpd/ftpd_locl.h b/appl/ftp/ftpd/ftpd_locl.h index 15e949fef..55c11a6ba 100644 --- a/appl/ftp/ftpd/ftpd_locl.h +++ b/appl/ftp/ftpd/ftpd_locl.h @@ -158,7 +158,7 @@ #ifdef SOCKS #include -extern int LIBPREFIX(fclose) __P((FILE *)); +extern int LIBPREFIX(fclose) (FILE *); #endif int yyparse(); diff --git a/appl/ftp/ftpd/kauth.c b/appl/ftp/ftpd/kauth.c index 908e69390..33fb4ed07 100644 --- a/appl/ftp/ftpd/kauth.c +++ b/appl/ftp/ftpd/kauth.c @@ -88,7 +88,7 @@ store_ticket(KTEXT cip) len = strnlen(ptr, left); if (len == left) return(INTK_BADPW); - + /* extract server's instance */ strcpy_truncate(sp.instance, ptr, sizeof(sp.instance)); ptr += len + 1; @@ -97,7 +97,7 @@ store_ticket(KTEXT cip) len = strnlen(ptr, left); if (len == left) return(INTK_BADPW); - + /* extract server's realm */ strcpy_truncate(sp.realm, ptr, sizeof(sp.realm)); ptr += len + 1; diff --git a/appl/kx/kx.h b/appl/kx/kx.h index c111acd09..d0bbe4fbd 100644 --- a/appl/kx/kx.h +++ b/appl/kx/kx.h @@ -107,6 +107,9 @@ #ifdef SOCKS #include +/* This doesn't belong here. */ +struct tm *localtime(const time_t *); +struct hostent *gethostbyname(const char *); #endif #include diff --git a/appl/telnet/libtelnet/auth.c b/appl/telnet/libtelnet/auth.c index d258e3aa8..32fd88ca2 100644 --- a/appl/telnet/libtelnet/auth.c +++ b/appl/telnet/libtelnet/auth.c @@ -67,12 +67,13 @@ RCSID("$Id$"); #endif #include #include + +#include + #ifdef SOCKS #include #endif -#include - #include "encrypt.h" #include "auth.h" #include "misc-proto.h" diff --git a/appl/telnet/libtelnet/enc_des.c b/appl/telnet/libtelnet/enc_des.c index 7c15a0c45..984bd3a5a 100644 --- a/appl/telnet/libtelnet/enc_des.c +++ b/appl/telnet/libtelnet/enc_des.c @@ -42,13 +42,13 @@ RCSID("$Id$"); #include #include #endif +#include #ifdef SOCKS #include #endif #include "encrypt.h" #include "misc-proto.h" -#include #include diff --git a/appl/telnet/libtelnet/encrypt.c b/appl/telnet/libtelnet/encrypt.c index f816902a4..c512ed8a5 100644 --- a/appl/telnet/libtelnet/encrypt.c +++ b/appl/telnet/libtelnet/encrypt.c @@ -67,11 +67,11 @@ RCSID("$Id$"); #include #include #include +#include #ifdef SOCKS #include #endif -#include /* * These functions pointers point to the current routines diff --git a/appl/telnet/libtelnet/kerberos.c b/appl/telnet/libtelnet/kerberos.c index c8686262e..d74cbbc00 100644 --- a/appl/telnet/libtelnet/kerberos.c +++ b/appl/telnet/libtelnet/kerberos.c @@ -70,11 +70,11 @@ RCSID("$Id$"); #include #include #include +#include #ifdef SOCKS #include #endif -#include #include "encrypt.h" #include "auth.h" diff --git a/appl/telnet/libtelnet/kerberos5.c b/appl/telnet/libtelnet/kerberos5.c index fccd95b6a..89850e1e5 100644 --- a/appl/telnet/libtelnet/kerberos5.c +++ b/appl/telnet/libtelnet/kerberos5.c @@ -68,11 +68,11 @@ RCSID("$Id$"); #define Authenticator k5_Authenticator #include #undef Authenticator +#include #ifdef SOCKS #include #endif -#include #include "encrypt.h" #include "auth.h" diff --git a/appl/telnet/libtelnet/misc.c b/appl/telnet/libtelnet/misc.c index 00eecda19..43b6c0112 100644 --- a/appl/telnet/libtelnet/misc.c +++ b/appl/telnet/libtelnet/misc.c @@ -38,6 +38,7 @@ RCSID("$Id$"); #include #include #include +#include #ifdef SOCKS #include #endif @@ -45,7 +46,6 @@ RCSID("$Id$"); #include "auth.h" #include "encrypt.h" -#include char *RemoteHostName; char *LocalHostName; diff --git a/appl/telnet/telnetd/telnetd.h b/appl/telnet/telnetd/telnetd.h index 5923ce82f..09d6b33d0 100644 --- a/appl/telnet/telnetd/telnetd.h +++ b/appl/telnet/telnetd/telnetd.h @@ -160,6 +160,9 @@ #ifdef SOCKS #include +/* This doesn't belong here. */ +struct tm *localtime(const time_t *); +struct hostent *gethostbyname(const char *); #endif #ifdef KRB4 diff --git a/appl/telnet/telnetd/utility.c b/appl/telnet/telnetd/utility.c index bd9080d0d..4bae20554 100644 --- a/appl/telnet/telnetd/utility.c +++ b/appl/telnet/telnetd/utility.c @@ -259,8 +259,11 @@ netflush(void) * old 4.2 client (and thus unable to survive TCP urgent data), * write the entire buffer in non-OOB mode. */ +#if 1 /* remove this to make it work between solaris 2.6 and linux */ if ((neturg == 0) || (not42 == 0)) { +#endif n = write(net, nbackp, n); /* normal write */ +#if 1 /* remove this to make it work between solaris 2.6 and linux */ } else { n = neturg - nbackp; /* @@ -277,6 +280,7 @@ netflush(void) n = send(net, nbackp, n, MSG_OOB); /* URGENT data */ } } +#endif } if (n < 0) { if (errno == EWOULDBLOCK || errno == EINTR)