+2000-08-17 Ezra Peisach <epeisach@mit.edu>
+
+ * domacro.c: Compiler warning cleanups and fix the overflow fix to
+ index the proper array.
+
+ * cmds.c, cmdtab.c, ftp.c, ftp_var.h, getpass.c, glob.c, main.c,
+ radix.c, ruserpass.c, secure.c, secure.h: Compiler warning
+ cleanups including providing prototypes, cleanup of assignments in
+ conditionals, including unistd.h and stdlib.h (if present),
+ declaring local functions as static.
+
+ * Makefile.in: Do not compile pclose.c - the code is not used.
+
2000-05-11 Nalin Dahyabhai <nalin@redhat.com>
* domacro.c (domacro): Don't overflow "line2"
SRCS = $(srcdir)/cmds.c $(srcdir)/cmdtab.c $(srcdir)/domacro.c \
$(srcdir)/ftp.c $(srcdir)/getpass.c $(srcdir)/glob.c \
- $(srcdir)/main.c $(srcdir)/pclose.c $(srcdir)/radix.c \
+ $(srcdir)/main.c $(srcdir)/radix.c \
$(srcdir)/ruserpass.c $(srcdir)/secure.c
-OBJS = cmds.o cmdtab.o domacro.o ftp.o getpass.o glob.o main.o pclose.o \
+OBJS = cmds.o cmdtab.o domacro.o ftp.o getpass.o glob.o main.o \
radix.o ruserpass.o secure.o
LOCALINCLUDES = -I$(srcdir)/.. -I$(srcdir) @KRB4_INCLUDES@
done
ftp.o cmds.o main.o: $(srcdir)/../arpa/ftp.h
-ftp.o cmds.o cmdtab.o domacro.o main.o ruserpass.o: $(srcdir)/ftp_var.h
+ftp.o cmds.o cmdtab.o domacro.o main.o ruserpass.o: $(srcdir)/ftp_var.h
secure.o: secure.h
cmds.o: $(srcdir)/cmds.c
/*
* FTP User Program -- Command Routines.
*/
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
#include <sys/param.h>
#include <sys/wait.h>
#include <sys/stat.h>
typedef sigtype (*sig_t)();
extern char *globerr;
-extern char **ftpglob();
extern char *home;
extern char *remglob();
extern char *getenv();
char *mname;
jmp_buf jabort;
-char *dotrans(), *domap();
extern char *auth_type;
extern int do_auth();
+static int globulize PROTOTYPE((char **));
+static int confirm PROTOTYPE((char *, char *));
+static int getit PROTOTYPE((int, char **, int, char *));
+static sigtype mabort PROTOTYPE((int));
+static void quote1 PROTOTYPE((char *, int, char **));
+static char *dotrans PROTOTYPE((char *));
+static char *domap PROTOTYPE((char *));
+
/*
* `Another' gets another argument, and stores the new argc and argv.
* It reverts to the top level (via main.c's intr()) on EOF/error.
*
* Returns false if no new arguments have been added.
*/
+int
another(pargc, pargv, prompt)
int *pargc;
char ***pargv;
char *prompt;
{
- int len = strlen(line), ret;
+ int len = strlen(line), ret;
extern sig_t intr();
if (len >= sizeof(line) - 3) {
}
printf("(%s) ", prompt);
line[len++] = ' ';
- if (fgets(&line[len], sizeof(line) - len, stdin) == NULL)
+ if (fgets(&line[len], (signed) sizeof(line) - len, stdin) == NULL)
intr();
len += strlen(&line[len]);
if (len > 0 && line[len - 1] == '\n')
* Connect to peer server and
* auto-login, if possible.
*/
-setpeer(argc, argv)
+void setpeer(argc, argv)
int argc;
char *argv[];
{
if (debug == 0)
verbose = -1;
if (command("SYST") == COMPLETE && overbose) {
- register char *cp, c;
+ register char *cp, c=0;
cp = strchr(reply_string+4, ' ');
if (cp == NULL)
cp = strchr(reply_string+4, '\r');
#ifndef NOENCRYPTION
{ "private", "P", PROT_P },
#endif
- 0
+ { 0, 0, 0}
};
-char *
+static char *
getclevel()
{
register struct levels *p;
return(p->p_name);
}
-char *
+static char *
getdlevel()
{
register struct levels *p;
/*
* Set control channel protection level.
*/
-setclevel(argc, argv)
+void setclevel(argc, argv)
char *argv[];
{
register struct levels *p;
/*
* Set data channel protection level.
*/
+void
setdlevel(argc, argv)
char *argv[];
{
* Set clear command protection level.
*/
/*VARARGS*/
+void
ccc()
{
plevel[1] = "clear";
* Set clear data protection level.
*/
/*VARARGS*/
+void
setclear()
{
plevel[1] = "clear";
* Set safe data protection level.
*/
/*VARARGS*/
+void
setsafe()
{
plevel[1] = "safe";
* Set private data protection level.
*/
/*VARARGS*/
+void
setprivate()
{
plevel[1] = "private";
{ "image", "I", TYPE_I, 0 },
{ "ebcdic", "E", TYPE_E, 0 },
{ "tenex", "L", TYPE_L, bytename },
- 0
+ { 0, 0 , 0, 0}
};
-char *
+static char *
gettype()
{
register struct types *p;
/*
* Set transfer type.
*/
+void
settype(argc, argv)
int argc;
char *argv[];
* without changing our notion of the type for data transfers.
* Used to change to and from ascii for listings.
*/
-changetype(newtype, show)
+void changetype(newtype, show)
int newtype, show;
{
register struct types *p;
* Set binary transfer type.
*/
/*VARARGS*/
-setbinary()
+void setbinary()
{
stype[1] = "binary";
settype(2, stype);
* Set ascii transfer type.
*/
/*VARARGS*/
-setascii()
+void setascii()
{
stype[1] = "ascii";
settype(2, stype);
* Set tenex transfer type.
*/
/*VARARGS*/
-settenex()
+void settenex()
{
stype[1] = "tenex";
settype(2, stype);
}
-char *
+static char *
getmode()
{
return("stream");
* Set file transfer mode.
*/
/*ARGSUSED*/
-setmode(argc, argv)
+void setmode(argc, argv)
int argc;
char *argv[];
{
code = -1;
}
-char *
+static char *
getform()
{
return("non-print");
* Set file transfer format.
*/
/*ARGSUSED*/
-setform(argc, argv)
+void setform(argc, argv)
int argc;
char *argv[];
{
code = -1;
}
-char *
+static char *
getstruct()
{
return("file");
* Set file transfer structure.
*/
/*ARGSUSED*/
-setstruct(argc, argv)
+void setstruct(argc, argv)
int argc;
char *argv[];
{
/*
* Send a single file.
*/
-put(argc, argv)
+void put(argc, argv)
int argc;
char *argv[];
{
/*
* Send multiple files.
*/
-mput(argc, argv)
+void mput(argc, argv)
int argc;
char **argv;
{
- extern jmp_buf jabort;
register int i;
sig_t oldintr;
int ointer;
char *tp;
- sigtype mabort();
if (argc < 2 && !another(&argc, &argv, "local-files")) {
printf("usage: %s local-files\n", argv[0]);
mflag = 0;
}
-reget(argc, argv)
+void reget(argc, argv)
int argc;
char *argv[];
{
(void) getit(argc, argv, 1, "r+w");
}
-get(argc, argv)
+void get(argc, argv)
int argc;
char *argv[];
{
/*
* Receive one file.
*/
-getit(argc, argv, restartit, mode)
+static int getit(argc, argv, restartit, rmode)
int argc;
char *argv[];
- char *mode;
+ char *rmode;
{
int loc = 0;
char *oldargv1, *oldargv2;
}
}
- recvrequest("RETR", argv[2], argv[1], mode,
+ recvrequest("RETR", argv[2], argv[1], rmode,
argv[1] != oldargv1 || argv[2] != oldargv2);
restart_point = 0;
return (0);
}
-sigtype
+static sigtype
mabort(sig)
int sig;
{
int ointer;
- extern jmp_buf jabort;
printf("\n");
(void) fflush(stdout);
/*
* Get multiple files.
*/
-mget(argc, argv)
+void mget(argc, argv)
int argc;
char **argv;
{
- extern jmp_buf jabort;
sig_t oldintr;
int ointer;
char *cp, *tp, *tp2, tmpbuf[MAXPATHLEN];
- sigtype mabort();
if (argc < 2 && !another(&argc, &argv, "remote-files")) {
printf("usage: %s remote-files\n", argv[0]);
static FILE *ftemp = NULL;
static char **args;
int oldverbose, oldhash;
- char *cp, *mode;
+ char *cp, *rmode;
if (!mflag) {
if (!doglob) {
if (doswitch) {
pswitch(!proxy);
}
- for (mode = "w"; *++argv != NULL; mode = "a")
- recvrequest ("NLST", temp, *argv, mode, 0);
+ for (rmode = "w"; *++argv != NULL; rmode = "a")
+ recvrequest ("NLST", temp, *argv, rmode, 0);
if (doswitch) {
pswitch(!proxy);
}
return (buf);
}
-char *
+static char *
onoff(bool)
int bool;
{
return (bool ? "on" : "off");
}
-cstatus()
+static void cstatus()
{
if (!connected) {
printf(proxy ? "No proxy connection.\n" : "Not connected.\n");
* Show status.
*/
/*ARGSUSED*/
-status(argc, argv)
+void status(argc, argv)
char *argv[];
{
int i;
* Set beep on cmd completed mode.
*/
/*VARARGS*/
-setbell()
+void setbell()
{
bell = !bell;
* Turn on packet tracing.
*/
/*VARARGS*/
-settrace()
+void settrace()
{
trace = !trace;
* Toggle hash mark printing during transfers.
*/
/*VARARGS*/
-sethash()
+void sethash()
{
hash = !hash;
* Turn on printing of server echo's.
*/
/*VARARGS*/
-setverbose()
+void setverbose()
{
verbose = !verbose;
* Toggle PORT cmd use before each data connection.
*/
/*VARARGS*/
-setport()
+void setport()
{
sendport = !sendport;
* during mget, mput, and mdelete.
*/
/*VARARGS*/
-setprompt()
+void setprompt()
{
interactive = !interactive;
* on local file names.
*/
/*VARARGS*/
-setglob()
+void setglob()
{
doglob = !doglob;
* set level of debugging.
*/
/*VARARGS*/
-setdebug(argc, argv)
+void setdebug(argc, argv)
int argc;
char *argv[];
{
* Set current working directory
* on remote machine.
*/
-cd(argc, argv)
+void cd(argc, argv)
int argc;
char *argv[];
{
* Set current working directory
* on local machine.
*/
-lcd(argc, argv)
+void lcd(argc, argv)
int argc;
char *argv[];
{
/*
* Delete a single file.
*/
-delete_file(argc, argv)
+void delete_file(argc, argv)
int argc;
char *argv[];
{
/*
* Delete multiple files.
*/
-mdelete(argc, argv)
+void mdelete(argc, argv)
int argc;
char **argv;
{
- extern jmp_buf jabort;
sig_t oldintr;
int ointer;
char *cp;
- sigtype mabort();
if (argc < 2 && !another(&argc, &argv, "remote-files")) {
printf("usage: %s remote-files\n", argv[0]);
/*
* Rename a remote file.
*/
-renamefile(argc, argv)
+void renamefile(argc, argv)
int argc;
char *argv[];
{
* Get a directory listing
* of remote files.
*/
-ls(argc, argv)
+void ls(argc, argv)
int argc;
char *argv[];
{
* Get a directory listing
* of multiple remote files.
*/
-mls(argc, argv)
+void mls(argc, argv)
int argc;
char **argv;
{
- extern jmp_buf jabort;
sig_t oldintr;
int ointer, i;
- char *volatile cmd, mode[1], *dest;
- sigtype mabort();
+ char *volatile cmd, rmode[1], *dest;
if (argc < 2 && !another(&argc, &argv, "remote-files"))
goto usage;
oldintr = signal(SIGINT, mabort);
(void) setjmp(jabort);
for (i = 1; mflag && i < argc-1; ++i) {
- *mode = (i == 1) ? 'w' : 'a';
- recvrequest(cmd, dest, argv[i], mode, 0);
+ *rmode = (i == 1) ? 'w' : 'a';
+ recvrequest(cmd, dest, argv[i], rmode, 0);
if (!mflag && fromatty) {
ointer = interactive;
interactive = 1;
* Do a shell escape
*/
/*ARGSUSED*/
-shell(argc, argv)
+void shell(argc, argv)
int argc;
char **argv;
{
int pid;
sig_t old1, old2;
- char shellnam[40], *shell, *namep;
+ char shellnam[40], *shellprog, *namep;
#ifdef WAIT_USES_INT
- int status;
+ int w_status;
#else
- union wait status;
+ union wait w_status;
#endif
old1 = signal (SIGINT, SIG_IGN);
(void) close(pid);
(void) signal(SIGINT, SIG_DFL);
(void) signal(SIGQUIT, SIG_DFL);
- shell = getenv("SHELL");
- if (shell == NULL)
- shell = "/bin/sh";
- namep = strrchr(shell,'/');
+ shellprog = getenv("SHELL");
+ if (shellprog == NULL)
+ shellprog = "/bin/sh";
+ namep = strrchr(shellprog,'/');
if (namep == NULL)
- namep = shell;
+ namep = shellprog;
(void) strcpy(shellnam,"-");
(void) strncat(shellnam, ++namep, sizeof(shellnam) - 1 - strlen(shellnam));
shellnam[sizeof(shellnam) - 1] = '\0';
if (strcmp(namep, "sh") != 0)
shellnam[0] = '+';
if (debug) {
- printf ("%s\n", shell);
+ printf ("%s\n", shellprog);
(void) fflush (stdout);
}
if (argc > 1) {
- execl(shell,shellnam,"-c",altarg,(char *)0);
+ execl(shellprog,shellnam,"-c",altarg,(char *)0);
}
else {
- execl(shell,shellnam,(char *)0);
+ execl(shellprog,shellnam,(char *)0);
}
- perror(shell);
+ perror(shellprog);
code = -1;
exit(1);
}
if (pid > 0)
- while (wait(&status) != pid)
+ while (wait(&w_status) != pid)
;
(void) signal(SIGINT, old1);
(void) signal(SIGQUIT, old2);
else {
code = 0;
}
- return (0);
+ return;
}
/*
* Send new user information (re-login)
*/
-user(argc, argv)
+void user(argc, argv)
int argc;
char **argv;
{
- char acct[80], *mygetpass();
+ char macct[80];
int n, aflag = 0;
if (argc < 2)
if (argc < 2 || argc > 4) {
printf("usage: %s username [password] [account]\n", argv[0]);
code = -1;
- return (0);
+ return;
}
n = command("USER %s", argv[1]);
if (n == COMPLETE)
if (n == CONTINUE) {
if (argc < 4) {
printf("Account: "); (void) fflush(stdout);
- (void) fgets(acct, sizeof(acct) - 1, stdin);
- acct[strlen(acct) - 1] = '\0';
- argv[3] = acct; argc++;
+ (void) fgets(macct, sizeof(macct) - 1, stdin);
+ macct[strlen(macct) - 1] = '\0';
+ argv[3] = macct; argc++;
}
n = command("ACCT %s", argv[3]);
aflag++;
}
if (n != COMPLETE) {
fprintf(stdout, "Login failed.\n");
- return (0);
+ /* code = -1;*/
+ return;
}
if (!aflag && argc == 4) {
(void) command("ACCT %s", argv[3]);
}
- return (1);
+ return;
}
/*
* Print working directory.
*/
/*VARARGS*/
-pwd()
+void pwd()
{
int oldverbose = verbose;
/*
* Make a directory.
*/
-makedir(argc, argv)
+void makedir(argc, argv)
int argc;
char *argv[];
{
/*
* Remove a directory.
*/
-removedir(argc, argv)
+void removedir(argc, argv)
int argc;
char *argv[];
{
/*
* Send a line, verbatim, to the remote machine.
*/
-quote(argc, argv)
+void quote(argc, argv)
int argc;
char *argv[];
{
* is sent verbatim to the remote machine, except that the
* word "SITE" is added at the front.
*/
-site(argc, argv)
+void site(argc, argv)
int argc;
char *argv[];
{
* Turn argv[1..argc) into a space-separated string, then prepend initial text.
* Send the result as a one-line command and get response.
*/
-quote1(initial, argc, argv)
+static void quote1(initial, argc, argv)
char *initial;
int argc;
char **argv;
}
}
-do_chmod(argc, argv)
+void do_chmod(argc, argv)
int argc;
char *argv[];
{
(void) command("SITE CHMOD %s %s", argv[1], argv[2]);
}
-do_umask(argc, argv)
+void do_umask(argc, argv)
int argc;
char *argv[];
{
verbose = oldverbose;
}
-siteidle(argc, argv)
+void siteidle(argc, argv)
int argc;
char *argv[];
{
/*
* Ask the other side for help.
*/
-rmthelp(argc, argv)
+void rmthelp(argc, argv)
int argc;
char *argv[];
{
* Terminate session and exit.
*/
/*VARARGS*/
-quit()
+void quit()
{
if (connected)
/*
* Terminate session, but don't exit.
*/
-disconnect()
+void disconnect()
{
extern FILE *cout;
extern int data;
dlevel = PROT_C;
}
-confirm(cmd, file)
+static int confirm(cmd, file)
char *cmd, *file;
{
- char line[FTP_BUFSIZ];
+ char mline[FTP_BUFSIZ];
if (!interactive)
return (1);
printf("%s %s? ", cmd, file);
(void) fflush(stdout);
- if (fgets(line, sizeof line, stdin) == NULL)
+ if (fgets(mline, sizeof mline, stdin) == NULL)
return (0);
- return (*line != 'n' && *line != 'N');
+ return (*mline != 'n' && *mline != 'N');
}
-fatal(msg)
+void fatal(msg)
char *msg;
{
* Can't control multiple values being expanded
* from the expression, we return only the first.
*/
-globulize(cpp)
+static int globulize(cpp)
char **cpp;
{
char **globbed;
return (1);
}
-account(argc,argv)
+void account(argc,argv)
int argc;
char **argv;
{
- char acct[50], *mygetpass(), *ap;
+ char macct[50], *ap;
if (argc > 1) {
++argv;
--argc;
- (void) strncpy(acct,*argv,49);
- acct[49] = '\0';
+ (void) strncpy(macct,*argv,49);
+ macct[49] = '\0';
while (argc > 1) {
--argc;
++argv;
- (void) strncat(acct,*argv, 49-strlen(acct));
+ (void) strncat(macct,*argv, 49-strlen(macct));
}
- ap = acct;
+ ap = macct;
}
else {
ap = mygetpass("Account:");
jmp_buf abortprox;
-sigtype
+static sigtype
proxabort(sig)
int sig;
{
longjmp(abortprox,1);
}
-doproxy(argc,argv)
+void doproxy(argc,argv)
int argc;
char *argv[];
{
- extern struct cmd cmdtab[];
- extern jmp_buf abortprox;
register struct cmd *c;
struct cmd *getcmd();
sig_t oldintr;
- sigtype proxabort();
if (argc < 2 && !another(&argc, &argv, "command")) {
printf("usage: %s command\n", argv[0]);
(void) signal(SIGINT, oldintr);
}
-setcase()
+void setcase()
{
mcase = !mcase;
printf("Case mapping %s.\n", onoff(mcase));
code = mcase;
}
-setcr()
+void setcr()
{
crflag = !crflag;
printf("Carriage Return stripping %s.\n", onoff(crflag));
code = crflag;
}
-setntrans(argc,argv)
+void setntrans(argc,argv)
int argc;
char *argv[];
{
ntout[16] = '\0';
}
-char *
+static char *
dotrans(name)
char *name;
{
return(new);
}
-setnmap(argc, argv)
+void setnmap(argc, argv)
int argc;
char *argv[];
{
(void) strncpy(mapout, cp, MAXPATHLEN - 1);
}
-char *
+static char *
domap(name)
char *name;
{
return(new);
}
-setsunique()
+void setsunique()
{
sunique = !sunique;
printf("Store unique %s.\n", onoff(sunique));
code = sunique;
}
-setrunique()
+void setrunique()
{
runique = !runique;
printf("Receive unique %s.\n", onoff(runique));
}
/* change directory to perent directory */
-cdup()
+void cdup()
{
if (command("CDUP") == ERROR && code == 500) {
if (verbose)
}
/* restart transfer at specific point */
-restart(argc, argv)
+void restart(argc, argv)
int argc;
char *argv[];
{
printf("restart: offset not specified\n");
else {
restart_point = atol(argv[1]);
- printf("restarting at %ld. %s\n", restart_point,
+ printf("restarting at %ld. %s\n", (long) restart_point,
"execute get, put or append to initiate transfer");
}
}
/* show remote system type */
-syst()
+void syst()
{
(void) command("SYST");
}
-macdef(argc, argv)
+void macdef(argc, argv)
int argc;
char *argv[];
{
/*
* get size of file on remote machine
*/
-sizecmd(argc, argv)
+void sizecmd(argc, argv)
int argc;
char *argv[];
{
/*
* get last modification time of file on remote machine
*/
-modtime(argc, argv)
+void modtime(argc, argv)
int argc;
char *argv[];
{
}
/*
- * show status on reomte machine
+ * show status on remote machine
*/
-rmtstatus(argc, argv)
+void rmtstatus(argc, argv)
int argc;
char *argv[];
{
/*
* get file if modtime is more recent than current file
*/
-newer(argc, argv)
+void newer(argc, argv)
int argc;
char *argv[];
{
*/
/*VARARGS*/
-setpassive()
+void setpassive()
{
passivemode = !passivemode;
/*
* User FTP -- Command Tables.
*/
-int setascii(), setbell(), setbinary(), setdebug(), setform();
-int setglob(), sethash(), setmode(), setpeer(), setport();
-int setprompt(), setstruct();
-int settenex(), settrace(), settype(), setverbose();
-int setclevel(), setdlevel(), setclear(), setsafe(), ccc();
-#ifndef NOENCRYPTION
-int setprivate();
-#endif
-int disconnect(), restart(), reget(), syst();
-int cd(), lcd(), delete_file(), mdelete(), user();
-int ls(), mls(), get(), mget(), help(), append(), put(), mput();
-int quit(), renamefile(), status();
-int quote(), rmthelp(), shell(), site();
-int pwd(), makedir(), removedir(), setcr();
-int account(), doproxy(), reset(), setcase(), setntrans(), setnmap();
-int setsunique(), setrunique(), cdup(), macdef(), domacro();
-int sizecmd(), modtime(), newer(), rmtstatus();
-int do_chmod(), do_umask(), siteidle();
-#ifndef NO_PASSIVE_MODE
-int setpassive();
-#endif
char accounthelp[] = "send account command to remote server";
char appendhelp[] = "append to a file";
#include <ctype.h>
#include <string.h>
-domacro(argc, argv)
+void domacro(argc, argv)
int argc;
char *argv[];
{
register char *cp1, *cp2;
int count = 2, loopflg = 0;
char line2[200];
- extern char **glob(), *globerr;
+ extern char **glob();
struct cmd *getcmd(), *c;
- extern struct cmd cmdtab[];
if (argc < 2 && !another(&argc, &argv, "macro name")) {
printf("Usage: %s macro_name.\n", argv[0]);
loopflg = 1;
cp1++;
if (count < argc) {
- if(cp2 + strlen(argv[j+1]) - line < sizeof(line))
+ if(cp2 + strlen(argv[count]) - line < sizeof(line))
(void) strncpy(cp2, argv[count],
sizeof(line) - 1 -
(cp2 - line));
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#define DEFINITIONS
#include "ftp_var.h"
+#include "secure.h"
+
+#ifdef GSSAPI
+void user_gss_error PROTOTYPE((OM_uint32, OM_uint32, char *));
+#endif
+
+static void proxtrans PROTOTYPE((char *, char *, char *));
+static int initconn PROTOTYPE((void));
+static void ptransfer PROTOTYPE((char *, long, struct timeval *, struct timeval *));
+static void abort_remote PROTOTYPE((FILE *));
+static void tvsub PROTOTYPE((struct timeval *, struct timeval *, struct timeval *));
+static char *gunique PROTOTYPE((char *));
#define sig_t my_sig_t
#define sigtype krb5_sigtype
uid_t getuid();
sig_t lostpeer();
off_t restart_point = 0;
+jmp_buf ptabort;
#define strerror(error) (sys_errlist[error])
#ifdef NEED_SYS_ERRLIST
#define herror() printf("unknown host\n")
FILE *cin, *cout;
-FILE *dataconn();
+FILE *dataconn PROTOTYPE((char *));
char *
hookup(host, port)
return ((char *)0);
}
-login(host)
+int login(host)
char *host;
{
char tmp[80];
- char *user, *pass, *acct, *getenv(), *getlogin(), *mygetpass();
+ char *l_user, *pass, *l_acct, *getenv(), *getlogin();
int n, aflag = 0;
- user = pass = acct = 0;
- if (ruserpass(host, &user, &pass, &acct) < 0) {
+ l_user = pass = l_acct = 0;
+ if (ruserpass(host, &l_user, &pass, &l_acct) < 0) {
code = -1;
return(0);
}
- while (user == NULL) {
+ while (l_user == NULL) {
char *myname;
myname = getenv("LOGNAME");
(void) fgets(tmp, sizeof(tmp) - 1, stdin);
tmp[strlen(tmp) - 1] = '\0';
if (*tmp == '\0')
- user = myname;
+ l_user = myname;
else
- user = tmp;
+ l_user = tmp;
}
- n = command("USER %s", user);
+ n = command("USER %s", l_user);
if (n == COMPLETE) {
/* determine if we need to send a dummy password */
int oldverbose = verbose;
}
if (n == CONTINUE) {
aflag++;
- acct = mygetpass("Account:");
- n = command("ACCT %s", acct);
+ l_acct = mygetpass("Account:");
+ n = command("ACCT %s", l_acct);
}
if (n != COMPLETE) {
fprintf(stderr, "Login failed.\n");
return (0);
}
- if (!aflag && acct != NULL)
- (void) command("ACCT %s", acct);
+ if (!aflag && l_acct != NULL)
+ (void) command("ACCT %s", l_acct);
if (proxy)
return(1);
for (n = 0; n < macnum; ++n) {
return (1);
}
-sigtype
+static sigtype
cmdabort(sig)
int sig;
{
- extern jmp_buf ptabort;
-
printf("\n");
(void) fflush(stdout);
abrtflag++;
longjmp(ptabort,1);
}
-secure_command(cmd)
+static int secure_command(cmd)
char *cmd;
{
- char in[FTP_BUFSIZ], out[FTP_BUFSIZ];
+ unsigned char in[FTP_BUFSIZ], out[FTP_BUFSIZ];
int length;
if (auth_type && clevel != PROT_C) {
if ((length = clevel == PROT_P ?
krb_mk_priv((unsigned char *)cmd, (unsigned char *)out,
strlen(cmd), schedule,
- &cred.session, &myctladdr, &hisctladdr)
+ cred.session, &myctladdr, &hisctladdr)
: krb_mk_safe((unsigned char *)cmd, (unsigned char *)out,
- strlen(cmd), &cred.session,
+ strlen(cmd), cred.session,
&myctladdr, &hisctladdr)) == -1) {
fprintf(stderr, "krb_mk_%s failed for KERBEROS_V4\n",
clevel == PROT_P ? "priv" : "safe");
fprintf(stderr, "sealed (%s) %d bytes\n",
clevel==PROT_P?"ENC":"MIC",
out_buf.length);
- memcpy(out, out_buf.value,
- length=out_buf.length);
+ length=out_buf.length;
+ memcpy(out, out_buf.value, out_buf.length);
gss_release_buffer(&min_stat, &out_buf);
}
}
#endif /* GSSAPI */
/* Other auth types go here ... */
- if (kerror = radix_encode(out, in, &length, 0)) {
+ kerror = radix_encode(out, in, &length, 0);
+ if (kerror) {
fprintf(stderr,"Couldn't base 64 encode command (%s)\n",
radix_error(kerror));
return(0);
}
#ifdef STDARG
-command(char *fmt, ...)
+int command(char *fmt, ...)
#else
/*VARARGS*/
-command(va_alist)
+int command(va_alist)
va_dcl
#endif
{
#endif
int r;
sig_t oldintr;
- sigtype cmdabort();
abrtflag = 0;
if (debug) {
#include <ctype.h>
-getreply(expecteof)
+int getreply(expecteof)
int expecteof;
{
register int i, c, n;
sig_t oldintr;
int pflag = 0;
char *pt = pasv;
- sigtype cmdabort();
char ibuf[FTP_BUFSIZ], obuf[FTP_BUFSIZ];
int safe = 0;
#ifndef strpbrk
if (c != '\r' && (verbose > 0 ||
(verbose > -1 && n == '5' && dig > 4))) {
if (proxflag &&
- (dig == 1 || dig == 5 && verbose == 0))
+ (dig == 1 || (dig == 5 && verbose == 0)))
printf("%s:",hostname);
(void) putchar(c);
}
if (auth_type && !ibuf[0] && n != '6')
return(getreply(expecteof));
ibuf[0] = obuf[i] = '\0';
- if (code && n == '6')
+ if (code && n == '6') {
if (code != 631 && code != 632 && code != 633) {
printf("Unknown reply: %d %s\n", code, obuf);
n = '5';
} else safe = (code == 631);
+ }
if (obuf[0]) /* if there is a string to decode */
if (!auth_type) {
printf("Cannot decode reply:\n%d %s\n", code, obuf);
#endif
else {
int len;
- if (kerror = radix_encode(obuf, ibuf, &len, 1)) {
+ kerror = radix_encode((unsigned char *)obuf,
+ (unsigned char *)ibuf,
+ &len, 1);
+ if (kerror) {
printf("Can't base 64 decode reply %d (%s)\n\"%s\"\n",
code, radix_error(kerror), obuf);
n = '5';
#ifdef KRB5_KRB4_COMPAT
else if (strcmp(auth_type, "KERBEROS_V4") == 0)
if ((kerror = safe ?
- krb_rd_safe((unsigned char *)ibuf, len,
- &cred.session,
- &hisctladdr, &myctladdr, &msg_data)
- : krb_rd_priv((unsigned char *)ibuf, len,
- schedule, &cred.session,
- &hisctladdr, &myctladdr, &msg_data))
+ krb_rd_safe((unsigned char *)ibuf,
+ (unsigned int) len,
+ cred.session,
+ &hisctladdr,
+ &myctladdr, &msg_data)
+ : krb_rd_priv((unsigned char *)ibuf,
+ (unsigned int) len,
+ schedule, cred.session,
+ &hisctladdr, &myctladdr,
+ &msg_data))
!= KSUCCESS) {
printf("%d reply %s! (krb_rd_%s: %s)\n", code,
safe ? "modified" : "garbled",
/* Other auth types go here... */
}
else
- if (verbose > 0 || verbose > -1 && n == '5') {
+ if (verbose > 0 || (verbose > -1 && n == '5')) {
(void) putchar(c);
(void) fflush (stdout);
}
(*oldintr)(SIGINT);
if (reply_parse) {
*reply_ptr = '\0';
- if (reply_ptr = strstr(reply_buf, reply_parse)) {
+ reply_ptr = strstr(reply_buf, reply_parse);
+ if (reply_ptr) {
reply_parse = reply_ptr + strlen(reply_parse);
- if (reply_ptr = strpbrk(reply_parse, " \r"))
+ reply_ptr = strpbrk(reply_parse, " \r");
+ if (reply_ptr)
*reply_ptr = '\0';
} else reply_parse = reply_ptr;
}
}
}
-empty(mask, sec)
+static int empty(mask, sec)
fd_set *mask;
int sec;
{
jmp_buf sendabort;
-sigtype
+static sigtype
abortsend(sig)
int sig;
{
}
#ifdef STDARG
-secure_error(char *fmt, ...)
+void secure_error(char *fmt, ...)
#else
/* VARARGS1 */
-secure_error(fmt, p1, p2, p3, p4, p5)
+void secure_error(fmt, p1, p2, p3, p4, p5)
char *fmt;
#endif
{
#define HASHBYTES 1024
-sendrequest(cmd, local, remote, printnames)
+void sendrequest(cmd, local, remote, printnames)
char *cmd, *local, *remote;
int printnames;
{
int (*volatile closefunc)(), pclose(), fclose();
volatile sig_t oldintr, oldintp;
volatile long bytes = 0, hashbytes = HASHBYTES;
- char *volatile lmode, buf[FTP_BUFSIZ], *bufp;
- sigtype abortsend();
+ char *volatile lmode;
+ unsigned char buf[FTP_BUFSIZ], *bufp;
if (verbose && printnames) {
if (local && *local != '-')
return;
}
if (setjmp(sendabort))
- goto abort;
+ goto die;
if (restart_point &&
(strcmp(cmd, "STOR") == 0 || strcmp(cmd, "APPE") == 0)) {
}
dout = dataconn(lmode);
if (dout == NULL)
- goto abort;
+ goto die;
(void) gettimeofday(&start, (struct timezone *)0);
oldintp = signal(SIGPIPE, SIG_IGN);
switch (curtype) {
while ((c = read(fileno(fin), buf, sizeof (buf))) > 0) {
bytes += c;
for (bufp = buf; c > 0; c -= d, bufp += d)
- if ((d = secure_write(fileno(dout), bufp, c)) <= 0)
+ if ((d = secure_write(fileno(dout), bufp,
+ (unsigned int) c)) <= 0)
break;
if (hash) {
while (bytes >= hashbytes) {
break;
bytes++;
/* if (c == '\r') { */
- /* (void) putc('\0', dout); /* this violates rfc */
+ /* (void) putc('\0', dout); this violates rfc */
/* bytes++; */
/* } */
}
if (bytes > 0)
ptransfer("sent", bytes, &start, &stop);
return;
-abort:
+die:
(void) gettimeofday(&stop, (struct timezone *)0);
(void) signal(SIGINT, oldintr);
if (oldintp)
jmp_buf recvabort;
-sigtype
+static sigtype
abortrecv(sig)
int sig;
{
longjmp(recvabort, 1);
}
-recvrequest(cmd, local, remote, lmode, printnames)
+void recvrequest(cmd, local, remote, lmode, printnames)
char *cmd, *volatile local, *remote, *lmode;
{
FILE *volatile fout, *volatile din = 0, *popen();
int (*volatile closefunc)(), pclose(), fclose();
volatile sig_t oldintr, oldintp;
volatile int is_retr, tcrflag, bare_lfs = 0;
- char *gunique();
- static int bufsize;
+ static unsigned int bufsize;
static char *buf;
- int blksize;
+ unsigned int blksize;
volatile long bytes = 0, hashbytes = HASHBYTES;
register int c, d;
struct timeval start, stop;
struct stat st;
off_t lseek();
- sigtype abortrecv();
is_retr = strcmp(cmd, "RETR") == 0;
if (is_retr && verbose && printnames) {
return;
}
if (setjmp(recvabort))
- goto abort;
+ goto die;
if (is_retr && restart_point &&
command("REST %ld", (long) restart_point) != CONTINUE)
return;
}
din = dataconn("r");
if (din == NULL)
- goto abort;
+ goto die;
if (strcmp(local, "-") == 0)
fout = stdout;
else if (*local == '|') {
fout = popen(local + 1, "w");
if (fout == NULL) {
perror(local+1);
- goto abort;
+ goto die;
}
closefunc = pclose;
} else {
if (fout == NULL) {
fprintf(stderr, "local: %s: %s\n", local,
strerror(errno));
- goto abort;
+ goto die;
}
closefunc = fclose;
}
if (buf == NULL) {
perror("malloc");
bufsize = 0;
- goto abort;
+ goto die;
}
bufsize = blksize;
}
}
errno = d = 0;
while ((c = secure_read(fileno(din), buf, bufsize)) > 0) {
- if ((d = write(fileno(fout), buf, c)) != c)
+ d = write(fileno(fout), buf,(unsigned int) c);
+ if (d != c)
break;
bytes += c;
if (hash) {
if (bytes > 0 && is_retr)
ptransfer("received", bytes, &start, &stop);
return;
-abort:
+die:
/* abort using RFC959 recommended IP,SYNC sequence */
* Need to start a listen on the data channel before we send the command,
* otherwise the server's connect may fail.
*/
-initconn()
+static int initconn()
{
register char *p, *a;
int result, len, tmpno = 0;
return (fdopen(data, lmode));
}
-ptransfer(direction, bytes, t0, t1)
+static void ptransfer(direction, bytes, t0, t1)
char *direction;
long bytes;
struct timeval *t0, *t1;
tsum->tv_sec++, tsum->tv_usec -= 1000000;
} */
-tvsub(tdiff, t1, t0)
+static void tvsub(tdiff, t1, t0)
struct timeval *tdiff, *t1, *t0;
{
tdiff->tv_sec--, tdiff->tv_usec += 1000000;
}
-sigtype
+static sigtype
psabort(sig)
int sig;
{
- extern int abrtflag;
-
abrtflag++;
}
-pswitch(flag)
+void pswitch(flag)
int flag;
{
- extern int proxy, abrtflag;
sig_t oldintr;
static struct comvars {
int connect;
}
}
-jmp_buf ptabort;
int ptabflg;
-sigtype
+static sigtype
abortpt(sig)
int sig;
{
longjmp(ptabort, 1);
}
+static void
proxtrans(cmd, local, remote)
char *cmd, *local, *remote;
{
volatile sig_t oldintr;
volatile int secndflag = 0;
int prox_type, nfnd;
- extern jmp_buf ptabort;
char *volatile cmd2;
fd_set mask;
- sigtype abortpt();
if (strcmp(cmd, "RETR"))
cmd2 = "RETR";
return;
}
if (setjmp(ptabort))
- goto abort;
+ goto die;
oldintr = signal(SIGINT, abortpt);
if (command("%s %s", cmd, remote) != PRELIM) {
(void) signal(SIGINT, oldintr);
pswitch(1);
secndflag++;
if (command("%s %s", cmd2, local) != PRELIM)
- goto abort;
+ goto die;
ptflag++;
(void) getreply(0);
pswitch(0);
ptflag = 0;
printf("local: %s remote: %s\n", local, remote);
return;
-abort:
+die:
(void) signal(SIGINT, SIG_IGN);
ptflag = 0;
if (strcmp(cmd, "RETR") && !proxy)
(void) signal(SIGINT, oldintr);
}
-reset()
+void reset()
{
fd_set mask;
int nfnd = 1;
}
}
-char *
+static char *
gunique(local)
char *local;
{
int n_gss_trials = sizeof(gss_trials)/sizeof(gss_trials[0]);
#endif /* GSSAPI */
-do_auth()
+int do_auth()
{
- extern int setsafe();
int oldverbose = verbose;
#ifdef KRB5_KRB4_COMPAT
char *service, inst[INST_SZ];
- u_long cksum, checksum = (u_long) getpid();
+ KRB4_32 cksum, checksum = getpid();
#endif /* KRB5_KRB4_COMPAT */
#if defined(KRB5_KRB4_COMPAT) || defined(GSSAPI)
u_char out_buf[FTP_BUFSIZ];
target_name,
*gss_trials[trial].mech_type,
GSS_C_MUTUAL_FLAG | GSS_C_REPLAY_FLAG |
- (forward ? GSS_C_DELEG_FLAG : 0),
+ (forward ? GSS_C_DELEG_FLAG :
+ (unsigned) 0),
0,
&chan, /* channel bindings */
token_ptr,
user_gss_error(maj_stat, min_stat, "no reply, huh?");
goto gss_complete_loop;
}
- } else if (kerror = radix_encode(reply_parse,out_buf,&i,1)) {
+ } else if ((kerror = radix_encode((unsigned char *)reply_parse,
+ out_buf,&i,1))) {
fprintf(stderr, "Base 64 decoding failed: %s\n",
radix_error(kerror));
} else {
if (realm[0] == '\0')
strncpy(realm, (char *) krb_realmofhost(hostname), sizeof(realm) - 1);
realm[sizeof(realm) - 1] = '\0';
+ fprintf(stderr, "inst=%s, realm=%s, checksum %d\n", inst, realm, checksum);
if ((kerror = krb_mk_req(&ticket, service = "ftp",
inst, realm, checksum))
&& (kerror != KDC_PR_UNKNOWN ||
inst, realm, checksum))))
fprintf(stderr, "Kerberos V4 krb_mk_req failed: %s\n",
krb_get_err_text(kerror));
- else if (kerror = krb_get_cred(service, inst, realm, &cred))
+ else if ((kerror = krb_get_cred(service, inst, realm, &cred)))
fprintf(stderr, "Kerberos V4 krb_get_cred failed: %s\n",
krb_get_err_text(kerror));
else {
oldverbose = verbose;
verbose = 0;
i = ticket.length;
- if (kerror = radix_encode(ticket.dat, out_buf, &i, 0))
+ if ((kerror = radix_encode(ticket.dat, out_buf, &i, 0)))
fprintf(stderr, "Base 64 encoding failed: %s\n",
radix_error(kerror));
else if (command("ADAT %s", out_buf) != COMPLETE)
else if (!reply_parse)
fprintf(stderr,
"No authentication data received from server\n");
- else if (kerror = radix_encode(reply_parse, out_buf, &i, 1))
+ else if ((kerror = radix_encode((unsigned char *)reply_parse, out_buf, &i, 1)))
fprintf(stderr, "Base 64 decoding failed: %s\n",
radix_error(kerror));
- else if (kerror = krb_rd_safe(out_buf, i, &cred.session,
- &hisctladdr, &myctladdr, &msg_data))
+ else if ((kerror = krb_rd_safe(out_buf, (unsigned )i,
+ cred.session,
+ &hisctladdr, &myctladdr,
+ &msg_data)))
fprintf(stderr, "Kerberos V4 krb_rd_safe failed: %s\n",
krb_get_err_text(kerror));
else {
return(0);
}
+void
setpbsz(size)
unsigned int size;
{
verbose = oldverbose;
}
-abort_remote(din)
+static void abort_remote(din)
FILE *din;
{
char buf[FTP_BUFSIZ];
}
(void) getreply(0);
}
+
#ifdef GSSAPI
-user_gss_error(maj_stat, min_stat, s)
+void user_gss_error(maj_stat, min_stat, s)
OM_uint32 maj_stat, min_stat;
char *s;
{
/* a lot of work just to report the error */
- OM_uint32 gmaj_stat, gmin_stat;
+ OM_uint32 gmaj_stat, gmin_stat, msg_ctx;
gss_buffer_desc msg;
- int msg_ctx;
msg_ctx = 0;
while (!msg_ctx) {
gmaj_stat = gss_display_status(&gmin_stat, maj_stat,
fprintf(stderr, "GSSAPI error: %s\n", s);
}
-secure_gss_error(maj_stat, min_stat, s)
+void secure_gss_error(maj_stat, min_stat, s)
OM_uint32 maj_stat, min_stat;
char *s;
{
- return user_gss_error(maj_stat, min_stat, s);
+ user_gss_error(maj_stat, min_stat, s);
+ return;
}
#endif /* GSSAPI */
char c_bell; /* give bell when command completes */
char c_conn; /* must be connected to use command */
char c_proxy; /* proxy server may execute */
- int (*c_handler)(); /* function to call */
+ void (*c_handler)(); /* function to call */
};
struct macel {
#endif
extern char *tail();
-extern char *remglob();
extern int errno;
extern char *mktemp();
#if (defined(STDARG) || (defined(__STDC__) && ! defined(VARARGS))) || defined(HAVE_STDARG_H)
-extern command(char *, ...);
+extern int command(char *, ...);
#endif
+
+#if (defined(__STDC__) || defined(__cplusplus) || defined(_MSDOS) || defined(_WIN32) || defined(KRB5_PROVIDE_PROTOTYPES)) && !defined(KRB5_NO_PROTOTYPES)
+#define PROTOTYPE(x) x
+#else
+#define PROTOTYPE(x) ()
+#endif /* STDC or PROTOTYPES */
+
+char *remglob PROTOTYPE((char **, int));
+int another PROTOTYPE((int *, char ***, char *));
+void makeargv PROTOTYPE((void));
+void setpeer PROTOTYPE((int, char **));
+void setclevel PROTOTYPE((int, char **));
+void setdlevel PROTOTYPE((int, char **));
+void ccc PROTOTYPE((void));
+void setclear PROTOTYPE((void));
+void setsafe PROTOTYPE((void));
+void setprivate PROTOTYPE((void));
+void settype PROTOTYPE((int, char **));
+void changetype PROTOTYPE((int, int));
+void setbinary PROTOTYPE((void));
+void setascii PROTOTYPE((void));
+void settenex PROTOTYPE((void));
+void setmode PROTOTYPE((int, char **));
+void setform PROTOTYPE((int, char **));
+void setstruct PROTOTYPE((int, char **));
+void siteidle PROTOTYPE((int, char **));
+void put PROTOTYPE((int, char **));
+void mput PROTOTYPE((int, char **));
+void reget PROTOTYPE((int, char **));
+void get PROTOTYPE((int, char **));
+void mget PROTOTYPE((int, char **));
+void status PROTOTYPE((int, char **));
+void setbell PROTOTYPE((void));
+void settrace PROTOTYPE((void));
+void sethash PROTOTYPE((void));
+void setverbose PROTOTYPE((void));
+void setport PROTOTYPE((void));
+void setprompt PROTOTYPE((void));
+void setglob PROTOTYPE((void));
+void setdebug PROTOTYPE((int, char **));
+void cd PROTOTYPE((int, char **));
+void lcd PROTOTYPE((int, char **));
+void delete_file PROTOTYPE((int, char **));
+void mdelete PROTOTYPE((int, char **));
+void renamefile PROTOTYPE((int, char **));
+void ls PROTOTYPE((int, char **));
+void mls PROTOTYPE((int, char **));
+void shell PROTOTYPE((int, char **));
+void user PROTOTYPE((int, char **));
+void pwd PROTOTYPE((void));
+void makedir PROTOTYPE((int, char **));
+void removedir PROTOTYPE((int, char **));
+void quote PROTOTYPE((int, char **));
+void site PROTOTYPE((int, char **));
+void do_chmod PROTOTYPE((int, char **));
+void do_umask PROTOTYPE((int, char **));
+void setidle PROTOTYPE((int, char **));
+void rmthelp PROTOTYPE((int, char **));
+void quit PROTOTYPE((void));
+void disconnect PROTOTYPE((void));
+void fatal PROTOTYPE((char *));
+void account PROTOTYPE((int, char **));
+void doproxy PROTOTYPE((int, char **));
+void setcase PROTOTYPE((void));
+void setcr PROTOTYPE((void));
+void setntrans PROTOTYPE((int, char **));
+void setnmap PROTOTYPE((int, char **));
+void setsunique PROTOTYPE((void));
+void setrunique PROTOTYPE((void));
+void cdup PROTOTYPE((void));
+void restart PROTOTYPE((int, char **));
+void syst PROTOTYPE((void));
+void macdef PROTOTYPE((int, char **));
+void sizecmd PROTOTYPE((int, char **));
+void modtime PROTOTYPE((int, char **));
+void rmtstatus PROTOTYPE((int, char **));
+void newer PROTOTYPE((int, char **));
+void setpassive PROTOTYPE((void));
+
+/* ftp.c */
+void sendrequest PROTOTYPE((char *, char *, char *, int));
+void recvrequest PROTOTYPE((char *, char *, char *, char *, int));
+int login PROTOTYPE((char *));
+void setpbsz PROTOTYPE((unsigned int));
+void pswitch PROTOTYPE((int));
+int getreply PROTOTYPE((int));
+void reset PROTOTYPE((void));
+char *hookup PROTOTYPE((char *, int));
+int do_auth PROTOTYPE((void));
+
+/* glob.c */
+void blkfree PROTOTYPE((char **));
+
+/* domacro.c */
+void domacro PROTOTYPE((int, char **));
+
+
+/* main.c */
+void help PROTOTYPE((int, char **));
+struct cmd *getcmd PROTOTYPE((char *));
+
+
+/* ruserpass.c */
+int ruserpass PROTOTYPE((char *, char **, char **, char **));
+
+/* radix.h */
+int radix_encode PROTOTYPE((unsigned char *, unsigned char *, int *, int));
+char *radix_error PROTOTYPE((int));
+
+/* getpass.c */
+char *mygetpass PROTOTYPE((char *));
+
+/* glob.c */
+char **ftpglob PROTOTYPE((char *));
static char sccsid[] = "@(#)getpass.c 1.1 90/04/28 SMI"; /* from UCB 5.4 3/7/86 */
#endif /* not lint */
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
#include <stdio.h>
#include <signal.h>
static struct sgttyb ttyo, ttyb;
#endif
+#include "ftp_var.h"
+
static FILE *fi;
#define sig_t my_sig_t
char *prompt;
{
register char *p;
- register c;
+ register int c;
static char pbuf[50+1];
sigtype (*sig)();
#include <limits.h>
#endif
+#include "ftp_var.h"
+
#ifdef ARG_MAX
#undef NCARGS
#define NCARGS ARG_MAX
static int gargc; /* Number args in gargv */
static int gnleft;
static short gflag;
-static int tglob();
char **ftpglob();
char *globerr;
char *home;
extern int errno;
-static char *strspl(), *strend();
-char **copyblk();
-
-static void acollect(), addpath(), collect(), expand(), Gcat();
-static void ginit(), matchdir(), rscan(), sort();
-static int amatch(), execbrc(), match();
+static char *strspl PROTOTYPE((char *, char *)), *strend PROTOTYPE((char *));
+char **copyblk PROTOTYPE((char **));
+
+static void acollect PROTOTYPE((char *)), addpath PROTOTYPE((int)),
+ collect PROTOTYPE((char *)), expand PROTOTYPE((char *)),
+ Gcat PROTOTYPE((char *, char *));
+static void ginit PROTOTYPE((char **)), matchdir PROTOTYPE((char *)),
+ rscan PROTOTYPE((char **, int (*f)())), sort PROTOTYPE((void));
+static int amatch PROTOTYPE((char *, char *)),
+ execbrc PROTOTYPE((char *, char *)), match PROTOTYPE((char *, char *));
+static int digit PROTOTYPE((int)), letter PROTOTYPE((int)),
+ any PROTOTYPE((int, char *));
+static int gethdir PROTOTYPE((char *));
+static int tglob PROTOTYPE((int ));
static int globcnt;
matchdir(pattern)
char *pattern;
{
+#if 0
struct stat stb;
+#endif
register struct dirent *dp;
DIR *dirp;
closedir(dirp);
return;
+#if 0
patherr1:
+#endif
closedir(dirp);
patherr2:
globerr = "Bad directory components";
case '[':
ok = 0;
lc = 077777;
- while (cc = *p++) {
+ while ((cc = *p++)) {
if (cc == ']') {
if (ok)
break;
if (scc == (lc = cc))
ok++;
}
- if (cc == 0)
+ if (cc == 0) {
if (ok)
p--;
else
return 0;
+ }
continue;
case '*':
while (*s)
addpath(*s++);
addpath('/');
- if (stat(gpath, &stb) == 0 && isdir(stb))
+ if (stat(gpath, &stb) == 0 && isdir(stb)) {
if (*p == 0) {
Gcat(gpath, "");
globcnt++;
} else
expand(p);
+ }
gpathp = sgpathp;
*gpathp = 0;
return (0);
}
}
-static
+static int
Gmatch(s, p)
register char *s, *p;
{
case '[':
ok = 0;
lc = 077777;
- while (cc = *p++) {
+ while ((cc = *p++)) {
if (cc == ']') {
if (ok)
break;
if (scc == (lc = cc))
ok++;
}
- if (cc == 0)
+ if (cc == 0) {
if (ok)
p--;
else
return 0;
+ }
continue;
case '*':
static void
addpath(c)
- char c;
+ int c;
{
if (gpathp >= lastgpathp)
globerr = "Pathname too long";
else {
- *gpathp++ = c;
+ *gpathp++ = c & 0xff;
*gpathp = 0;
}
}
{
register char *p, c;
- while (p = *t++) {
- if (f == tglob)
+ while ((p = *t++)) {
+ if (f == tglob) {
if (*p == '~')
gflag |= 2;
else if (eq(p, "{") || eq(p, "{}"))
continue;
- while (c = *p++)
+ }
+ while ((c = *p++))
(*f)(c);
}
}
*p++ = (*f)(c);
} */
-static
+static int
tglob(c)
- register char c;
+ register int c;
{
if (any(c, globchars))
} */
+static int
letter(c)
- register char c;
+ register int c;
{
- return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '_');
+ return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_');
}
+static int
digit(c)
- register char c;
+ register int c;
{
return (c >= '0' && c <= '9');
}
-any(c, s)
+static int any(c, s)
register int c;
register char *s;
{
return(1);
return(0);
}
-blklen(av)
+static int blklen(av)
register char **av;
{
register int i = 0;
return (i);
}
-char **
+static char **
blkcpy(oav, bv)
char **oav;
register char **bv;
{
register char **av = oav;
- while (*av++ = *bv++)
+ while ((*av++ = *bv++))
continue;
return (oav);
}
-blkfree(av0)
+void blkfree(av0)
char **av0;
{
register char **av = av0;
* user whose home directory is sought is currently.
* We write the home directory of the user back there.
*/
-gethdir(home)
- char *home;
+static int gethdir(mhome)
+ char *mhome;
{
- register struct passwd *pp = getpwnam(home);
+ register struct passwd *pp = getpwnam(mhome);
- if (!pp || ((home + strlen(pp->pw_dir)) >= lastgpathp))
+ if (!pp || ((mhome + strlen(pp->pw_dir)) >= lastgpathp))
return (1);
- (void) strcpy(home, pp->pw_dir);
+ (void) strcpy(mhome, pp->pw_dir);
return (0);
}
/*
* FTP User Program -- Command Interface.
*/
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
#include <stdio.h>
#include "ftp_var.h"
#ifndef KRB5_KRB4_COMPAT
typedef sigtype (*sig_t)();
uid_t getuid();
-sigtype intr(), lostpeer();
+sigtype intr PROTOTYPE((int)), lostpeer PROTOTYPE((int));
extern char *home;
char *getlogin();
#ifdef KRB5_KRB4_COMPAT
extern char realm[];
#endif /* KRB5_KRB4_COMPAT */
+static void cmdscanner PROTOTYPE((int));
+static char *slurpstring PROTOTYPE((void));
+
+
+int
main(argc, argv)
volatile int argc;
char **volatile argv;
/*
* Command parser.
*/
+static void
cmdscanner(top)
int top;
{
register struct cmd *c;
register int l;
- struct cmd *getcmd();
- extern int help();
if (!top)
(void) putchar('\n');
longest = 0;
nmatches = 0;
found = 0;
- for (c = cmdtab; p = c->c_name; c++) {
+ for (c = cmdtab; (p = c->c_name) != NULL; c++) {
for (q = name; *q == *p++; q++)
if (*q == 0) /* exact match? */
return (c);
int slrflag;
-makeargv()
+void makeargv()
{
char **argp;
- char *slurpstring();
margc = 0;
argp = margv;
stringbase = line; /* scan from first of buffer */
argbase = argbuf; /* store from first of buffer */
slrflag = 0;
- while (*argp++ = slurpstring())
+ while ((*argp++ = slurpstring()))
margc++;
}
* implemented with FSM to
* handle quoting and strings
*/
-char *
+static char *
slurpstring()
{
int got_one = 0;
return((char *)0);
}
-#define HELPINDENT (sizeof ("directory"))
+#define HELPINDENT ((int) sizeof("disconnect"))
/*
* Help command.
* Call each command handler with argc == 0 and argv[0] == name.
*/
-help(argc, argv)
+void help(argc, argv)
int argc;
char *argv[];
{
#include <ctype.h>
#include <string.h>
+#include "ftp_var.h"
+
static char *radixN =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static char pad = '=';
-radix_encode(inbuf, outbuf, len, decode)
+int radix_encode(inbuf, outbuf, len, decode)
unsigned char inbuf[], outbuf[];
int *len, decode;
{
char *
radix_error(e)
+int e;
{
switch (e) {
case 0: return("Success");
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
#include <ctype.h>
#include <sys/stat.h>
#include <errno.h>
#endif
char *renvlook(), *getenv();
+static int token PROTOTYPE((void));
static FILE *cfile;
#define DEFAULT 1
char *tokstr;
int tval;
} toktab[]= {
- "default", DEFAULT,
- "login", LOGIN,
- "password", PASSWD,
- "passwd", PASSWD,
- "account", ACCOUNT,
- "machine", MACH,
- "macdef", MACDEF,
- 0, 0
+ { "default", DEFAULT },
+ { "login", LOGIN },
+ { "password", PASSWD },
+ { "passwd", PASSWD },
+ { "account", ACCOUNT },
+ { "machine", MACH },
+ { "macdef", MACDEF },
+ { NULL, 0 }
};
-static
+static int
token()
{
char *cp;
return (ID);
}
+int
ruserpass(host, aname, apass, aacct)
char *host, **aname, **apass, **aacct;
{
char *hdir, buf[FTP_BUFSIZ], *tmp;
- char myname[MAXHOSTNAMELEN], *mydomain;
+ char myname[MAXHOSTNAMELEN + 1], *mydomain;
int t, i, c, usedefault = 0;
struct stat stb;
goto match;
if ((tmp = strchr(hostname, '.')) != NULL &&
strcasecmp(tmp, mydomain) == 0 &&
- strncasecmp(hostname, tokval, tmp-hostname) == 0 &&
+ strncasecmp(hostname, tokval,
+ (unsigned) (tmp-hostname)) == 0 &&
tokval[tmp - hostname] == '\0')
goto match;
if ((tmp = strchr(host, '.')) != NULL &&
strcasecmp(tmp, mydomain) == 0 &&
- strncasecmp(host, tokval, tmp - host) == 0 &&
+ strncasecmp(host, tokval,
+ (unsigned ) (tmp - host)) == 0 &&
tokval[tmp - host] == '\0')
goto match;
continue;
while ((t = token()) && t != MACH && t != DEFAULT) switch(t) {
case LOGIN:
- if (token())
+ if (token()) {
if (*aname == 0) {
*aname = malloc((unsigned) strlen(tokval) + 1);
(void) strcpy(*aname, tokval);
if (strcmp(*aname, tokval))
goto next;
}
+ }
break;
case PASSWD:
if (strcmp(*aname, "anonymous") &&
(void) fclose(cfile);
return(0);
}
- while ((c=getc(cfile)) != EOF && c == ' ' || c == '\t');
+ while ((c = getc(cfile)) != EOF)
+ if (c != ' ' && c != '\t')
+ break;
if (c == EOF || c == '\n') {
printf("Missing macdef name argument.\n");
goto bad;
* Only one security context, thus only work on one fd at a time!
*/
+#ifdef GSSAPI
+#include <gssapi/gssapi.h>
+#include <gssapi/gssapi_generic.h>
+extern gss_ctx_id_t gcontext;
+#endif /* GSSAPI */
+
#include <secure.h> /* stuff which is specific to client or server */
#ifdef KRB5_KRB4_COMPAT
extern MSG_DAT msg_data;
extern Key_schedule schedule;
#endif /* KRB5_KRB4_COMPAT */
-#ifdef GSSAPI
-#include <gssapi/gssapi.h>
-#include <gssapi/gssapi_generic.h>
-extern gss_ctx_id_t gcontext;
-#endif /* GSSAPI */
#include <arpa/ftp.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
#include <sys/types.h>
#include <netinet/in.h>
#include <errno.h>
typedef long ftp_int32;
#endif
+static int secure_putbuf PROTOTYPE((int, unsigned char *, unsigned int));
extern struct sockaddr_in hisaddr;
extern struct sockaddr_in myaddr;
#define MAX maxbuf
extern unsigned int maxbuf; /* maximum output buffer size */
extern unsigned char *ucbuf; /* cleartext buffer */
-static unsigned int nout, bufp; /* number of chars in ucbuf,
+static unsigned int nout; /* number of chars in ucbuf,
* pointer into ucbuf */
#ifdef KRB5_KRB4_COMPAT
#endif
-#if defined(STDARG) || (defined(__STDC__) && ! defined(VARARGS)) || defined(HAVE_STDARG_H)
-extern secure_error(char *, ...);
-#else
-extern secure_error();
-#endif
#define ERR -2
-static
+static int
secure_putbyte(fd, c)
int fd;
unsigned char c;
* -1 on error (errno set)
* -2 on security error
*/
-secure_flush(fd)
+int secure_flush(fd)
int fd;
{
int ret;
if (dlevel == PROT_C)
return(0);
- if (nout)
- if (ret = secure_putbuf(fd, ucbuf, nout))
+ if (nout) {
+ ret = secure_putbuf(fd, ucbuf, nout);
+ if (ret)
return(ret);
- return(secure_putbuf(fd, "", nout = 0));
+ }
+ return(secure_putbuf(fd, (unsigned char *) "", nout = 0));
}
/* returns:
* -1 on error
* -2 on security error
*/
-secure_putc(c, stream)
-char c;
+int secure_putc(c, stream)
+int c;
FILE *stream;
{
if (dlevel == PROT_C)
* -1 on error (errno set)
* -2 on security error
*/
+int
secure_write(fd, buf, nbyte)
int fd;
unsigned char *buf;
* -1 on error (errno set)
* -2 on security error
*/
+static int
secure_putbuf(fd, buf, nbyte)
int fd;
unsigned char *buf;
}
}
- memcpy(outbuf, out_buf.value, length=out_buf.length);
+ length=out_buf.length;
+ memcpy(outbuf, out_buf.value, out_buf.length);
gss_release_buffer(&min_stat, &out_buf);
}
#endif /* GSSAPI */
net_len = htonl((u_long) length);
- if (looping_write(fd, &net_len, 4) == -1) return(-1);
+ if (looping_write(fd, (char *) &net_len, 4) == -1) return(-1);
if (looping_write(fd, outbuf, length) != length) return(-1);
return(0);
}
-static
+static int
secure_getbyte(fd)
int fd;
{
ftp_uint32 length;
if (nin == 0) {
- if ((kerror = looping_read(fd, &length, sizeof(length)))
+ if ((kerror = looping_read(fd, (char *) &length,
+ sizeof(length)))
!= sizeof(length)) {
secure_error("Couldn't read PROT buffer length: %d/%s",
kerror,
length, MAX);
return(ERR);
}
- if ((kerror = looping_read(fd, ucbuf, length)) != length) {
+ if ((kerror = looping_read(fd, (char *) ucbuf, (int) length)) != length) {
secure_error("Couldn't read %u byte PROT buffer: %s",
length, kerror == -1 ?
sys_errlist[errno] : "premature EOF");
/* Other auth types go here ... */
#ifdef KRB5_KRB4_COMPAT
if (strcmp(auth_type, "KERBEROS_V4") == 0) {
- if (kerror = dlevel == PROT_P ?
+ if ((kerror = dlevel == PROT_P ?
krb_rd_priv(ucbuf, length, schedule, SESSION,
&hisaddr, &myaddr, &msg_data)
: krb_rd_safe(ucbuf, length, SESSION,
- &hisaddr, &myaddr, &msg_data)) {
+ &hisaddr, &myaddr, &msg_data))) {
secure_error("krb_rd_%s failed for KERBEROS_V4 (%s)",
dlevel == PROT_P ? "priv" : "safe",
krb_get_err_text(kerror));
* -1 on EOF
* -2 on security error
*/
-secure_getc(stream)
+int secure_getc(stream)
FILE *stream;
{
if (dlevel == PROT_C)
* -1 on error (errno set), only for PROT_C
* -2 on security error
*/
-secure_read(fd, buf, nbyte)
+int secure_read(fd, buf, nbyte)
int fd;
char *buf;
-int nbyte;
+unsigned int nbyte;
{
static int c;
int i;
+#include <stdio.h>
+
#define CRED_DECL extern CREDENTIALS cred;
-#define SESSION &cred.session
+#define SESSION cred.session
#define myaddr myctladdr
#define hisaddr hisdataaddr
+
+#if (defined(__STDC__) || defined(__cplusplus) || defined(_MSDOS) || defined(_WIN32) || defined(KRB5_PROVIDE_PROTOTYPES)) && !defined(KRB5_NO_PROTOTYPES)
+#define PROTOTYPE(x) x
+#else
+#define PROTOTYPE(x) ()
+#endif /* STDC or PROTOTYPES */
+
+int secure_flush PROTOTYPE((int));
+int secure_putc PROTOTYPE((int, FILE *));
+int secure_getc PROTOTYPE((FILE *));
+int secure_write PROTOTYPE((int, unsigned char *, unsigned int));
+int secure_read PROTOTYPE((int, char *, unsigned int));
+void secure_gss_error PROTOTYPE((OM_uint32 maj_stat, OM_uint32 min_stat, char *s));
+
+#if defined(STDARG) || (defined(__STDC__) && ! defined(VARARGS)) || defined(HAVE_STDARG_H)
+void secure_error(char *, ...);
+#else
+void secure_error();
+#endif