
# line 26 "ftpcmd.y"

#ifndef lint
static char sccsid[] = "@(#)ftpcmd.y	5.12 (Berkeley) 10/30/88";
#endif /* not lint */

#include <sys/types.h>
#include <sys/socket.h>

#ifdef KERBEROS
#include <krb.h>
#endif

#ifdef HESIOD
#include <hesiod.h>
#endif

#include <netinet/in.h>

#include <arpa/ftp.h>

#include <stdio.h>
#include <signal.h>
#include <ctype.h>
#include <pwd.h>
#include <setjmp.h>
#include <syslog.h>

extern	struct sockaddr_in data_dest;
extern	int logged_in;
extern	struct passwd *pw;
extern	int guest;
extern	int logging;
extern	int type;
extern	int form;
extern	int debug;
extern	int timeout;
extern  int pdata;
extern  int errno;
extern  char *sys_errlist[];
extern	char hostname[];
extern	char *globerr;
extern	int usedefault;
extern	int unique;
extern  int transflag;
extern  char tmpline[];
char	**glob();

static	int cmd_type;
static	int cmd_form;
static	int cmd_bytesz;
char cbuf[512];
char *fromname;

/* Kerberos/Hesiod stuff */
extern char	**kinit_argv;
extern int	kinit_argc, has_tickets, krb_debug;
int 		hesiod=0;

char	*index();
# define A 257
# define B 258
# define C 259
# define E 260
# define F 261
# define I 262
# define L 263
# define N 264
# define P 265
# define R 266
# define S 267
# define T 268
# define SP 269
# define CRLF 270
# define COMMA 271
# define STRING 272
# define NUMBER 273
# define USER 274
# define PASS 275
# define ACCT 276
# define REIN 277
# define QUIT 278
# define PORT 279
# define PASV 280
# define TYPE 281
# define STRU 282
# define MODE 283
# define RETR 284
# define STOR 285
# define APPE 286
# define MLFL 287
# define MAIL 288
# define MSND 289
# define MSOM 290
# define MSAM 291
# define MRSQ 292
# define MRCP 293
# define ALLO 294
# define REST 295
# define RNFR 296
# define RNTO 297
# define ABOR 298
# define DELE 299
# define CWD 300
# define LIST 301
# define NLST 302
# define SITE 303
# define STAT 304
# define HELP 305
# define NOOP 306
# define XMKD 307
# define XRMD 308
# define XPWD 309
# define XCUP 310
# define STOU 311
# define ATCH 312
# define KDBG 313
# define KDST 314
# define LEXERR 315
#define yyclearin yychar = -1
#define yyerrok yyerrflag = 0
extern int yychar;
extern short yyerrflag;
#ifndef YYMAXDEPTH
#define YYMAXDEPTH 150
#endif
#ifndef YYSTYPE
#define YYSTYPE int
#endif
YYSTYPE yylval, yyval;
# define YYERRCODE 256

# line 534 "ftpcmd.y"


extern jmp_buf errcatch;

#define	CMD	0	/* beginning of command */
#define	ARGS	1	/* expect miscellaneous arguments */
#define	STR1	2	/* expect SP followed by STRING */
#define	STR2	3	/* expect STRING */
#define	OSTR	4	/* optional STRING */

struct tab {
	char	*name;
	short	token;
	short	state;
	short	implemented;	/* 1 if command is implemented */
	char	*help;
};

struct tab cmdtab[] = {		/* In order defined in RFC 765 */
	{ "USER", USER, STR1, 1,	"<sp> username [-i instance]\
 [-r realm] [-l lifetime]" },
	{ "PASS", PASS, STR1, 1,	"<sp> password" },
	{ "KDBG", KDBG, ARGS, 1,        "" },
	{ "KDST", KDST, ARGS, 1,        "" },
	{ "ATCH", ATCH, STR1, 1,        "<sp> <attach options>"},
	{ "ACCT", ACCT, STR1, 0,	"(specify account)" },
	{ "REIN", REIN, ARGS, 0,	"(reinitialize server state)" },
	{ "QUIT", QUIT, ARGS, 1,	"(terminate service)", },
	{ "PORT", PORT, ARGS, 1,	"<sp> b0, b1, b2, b3, b4" },
	{ "PASV", PASV, ARGS, 1,	"(set server in passive mode)" },
	{ "TYPE", TYPE, ARGS, 1,	"<sp> [ A | E | I | L ]" },
	{ "STRU", STRU, ARGS, 1,	"(specify file structure)" },
	{ "MODE", MODE, ARGS, 1,	"(specify transfer mode)" },
	{ "RETR", RETR, STR1, 1,	"<sp> file-name" },
	{ "STOR", STOR, STR1, 1,	"<sp> file-name" },
	{ "APPE", APPE, STR1, 1,	"<sp> file-name" },
	{ "MLFL", MLFL, OSTR, 0,	"(mail file)" },
	{ "MAIL", MAIL, OSTR, 0,	"(mail to user)" },
	{ "MSND", MSND, OSTR, 0,	"(mail send to terminal)" },
	{ "MSOM", MSOM, OSTR, 0,	"(mail send to terminal or mailbox)" },
	{ "MSAM", MSAM, OSTR, 0,	"(mail send to terminal and mailbox)" },
	{ "MRSQ", MRSQ, OSTR, 0,	"(mail recipient scheme question)" },
	{ "MRCP", MRCP, STR1, 0,	"(mail recipient)" },
	{ "ALLO", ALLO, ARGS, 1,	"allocate storage (vacuously)" },
	{ "REST", REST, STR1, 0,	"(restart command)" },
	{ "RNFR", RNFR, STR1, 1,	"<sp> file-name" },
	{ "RNTO", RNTO, STR1, 1,	"<sp> file-name" },
	{ "ABOR", ABOR, ARGS, 1,	"(abort operation)" },
	{ "DELE", DELE, STR1, 1,	"<sp> file-name" },
	{ "CWD",  CWD,  OSTR, 1,	"[ <sp> directory-name]" },
	{ "XCWD", CWD,	OSTR, 1,	"[ <sp> directory-name ]" },
	{ "LIST", LIST, OSTR, 1,	"[ <sp> path-name ]" },
	{ "NLST", NLST, OSTR, 1,	"[ <sp> path-name ]" },
	{ "SITE", SITE, STR1, 0,	"(get site parameters)" },
	{ "STAT", STAT, OSTR, 0,	"(get server status)" },
	{ "HELP", HELP, OSTR, 1,	"[ <sp> <string> ]" },
	{ "NOOP", NOOP, ARGS, 1,	"" },
	{ "MKD",  XMKD, STR1, 1,	"<sp> path-name" },
	{ "XMKD", XMKD, STR1, 1,	"<sp> path-name" },
	{ "RMD",  XRMD, STR1, 1,	"<sp> path-name" },
	{ "XRMD", XRMD, STR1, 1,	"<sp> path-name" },
	{ "PWD",  XPWD, ARGS, 1,	"(return current directory)" },
	{ "XPWD", XPWD, ARGS, 1,	"(return current directory)" },
	{ "CDUP", XCUP, ARGS, 1,	"(change to parent directory)" },
	{ "XCUP", XCUP, ARGS, 1,	"(change to parent directory)" },
	{ "STOU", STOU, STR1, 1,	"<sp> file-name" },
	{ NULL,   0,    0,    0,	0 }
};

struct tab *
lookup(cmd)
	char *cmd;
{
	register struct tab *p;

	for (p = cmdtab; p->name != NULL; p++)
		if (strcmp(cmd, p->name) == 0)
			return (p);
	return (0);
}

#include <arpa/telnet.h>

/*
 * getline - a hacked up version of fgets to ignore TELNET escape codes.
 */
char *
getline(s, n, iop)
	char *s;
	register FILE *iop;
{
	register c;
	register char *cs;

	cs = s;
/* tmpline may contain saved command from urgent mode interruption */
	for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) {
		*cs++ = tmpline[c];
		if (tmpline[c] == '\n') {
			*cs++ = '\0';
			if (debug) {
				syslog(LOG_DEBUG, "FTPD: command: %s", s);
			}
			tmpline[0] = '\0';
			return(s);
		}
		if (c == 0) {
			tmpline[0] = '\0';
		}
	}
	while (--n > 0 && (c = getc(iop)) != EOF) {
		c = 0377 & c;
		while (c == IAC) {
			switch (c = 0377 & getc(iop)) {
			case WILL:
			case WONT:
				c = 0377 & getc(iop);
				printf("%c%c%c", IAC, WONT, c);
				(void) fflush(stdout);
				break;
			case DO:
			case DONT:
				c = 0377 & getc(iop);
				printf("%c%c%c", IAC, DONT, c);
				(void) fflush(stdout);
				break;
			default:
				break;
			}
			c = 0377 & getc(iop); /* try next character */
		}
		*cs++ = c;
		if (c=='\n')
			break;
	}
	if (c == EOF && cs == s)
		return (NULL);
	*cs++ = '\0';
	if (debug) {
		syslog(LOG_DEBUG, "FTPD: command: %s", s);
	}
	return (s);
}

static int
toolong()
{
	time_t now;
	extern char *ctime();
	extern time_t time();

	reply(421,
	  "Timeout (%d seconds): closing control connection.", timeout);
	(void) time(&now);
	if (logging) {
		syslog(LOG_INFO,
			"FTPD: User %s timed out after %d seconds at %s",
			(pw ? pw -> pw_name : "unknown"), timeout, ctime(&now));
	}
	dologout(1);
}

yylex()
{
	static int cpos, state;
	register char *cp;
	register struct tab *p;
	int n;
	char c;

	for (;;) {
		switch (state) {

		case CMD:
			(void) signal(SIGALRM, toolong);
			(void) alarm((unsigned) timeout);
			if (getline(cbuf, sizeof(cbuf)-1, stdin) == NULL) {
				reply(221, "You could at least say goodbye.");
				dologout(0);
			}
			(void) alarm(0);
			if (index(cbuf, '\r')) {
				cp = index(cbuf, '\r');
				cp[0] = '\n'; cp[1] = 0;
			}
			if (index(cbuf, ' '))
				cpos = index(cbuf, ' ') - cbuf;
			else
				cpos = index(cbuf, '\n') - cbuf;
			if (cpos == 0) {
				cpos = 4;
			}
			c = cbuf[cpos];
			cbuf[cpos] = '\0';
			upper(cbuf);
			p = lookup(cbuf);
			cbuf[cpos] = c;
			if (p != 0) {
				if (p->implemented == 0) {
					nack(p->name);
					longjmp(errcatch,0);
					/* NOTREACHED */
				}
				state = p->state;
				yylval = (int) p->name;
				return (p->token);
			}
			break;

		case OSTR:
			if (cbuf[cpos] == '\n') {
				state = CMD;
				return (CRLF);
			}
			/* FALL THRU */

		case STR1:
			if (cbuf[cpos] == ' ') {
				cpos++;
				state = STR2;
				return (SP);
			}
			break;

		case STR2:
			cp = &cbuf[cpos];
			n = strlen(cp);
			cpos += n - 1;
			/*
			 * Make sure the string is nonempty and \n terminated.
			 */
			if (n > 1 && cbuf[cpos] == '\n') {
				cbuf[cpos] = '\0';
				yylval = copy(cp);
				cbuf[cpos] = '\n';
				state = ARGS;
				return (STRING);
			}
			break;

		case ARGS:
			if (isdigit(cbuf[cpos])) {
				cp = &cbuf[cpos];
				while (isdigit(cbuf[++cpos]))
					;
				c = cbuf[cpos];
				cbuf[cpos] = '\0';
				yylval = atoi(cp);
				cbuf[cpos] = c;
				return (NUMBER);
			}
			switch (cbuf[cpos++]) {

			case '\n':
				state = CMD;
				return (CRLF);

			case ' ':
				return (SP);

			case ',':
				return (COMMA);

			case 'A':
			case 'a':
				return (A);

			case 'B':
			case 'b':
				return (B);

			case 'C':
			case 'c':
				return (C);

			case 'E':
			case 'e':
				return (E);

			case 'F':
			case 'f':
				return (F);

			case 'I':
			case 'i':
				return (I);

			case 'L':
			case 'l':
				return (L);

			case 'N':
			case 'n':
				return (N);

			case 'P':
			case 'p':
				return (P);

			case 'R':
			case 'r':
				return (R);

			case 'S':
			case 's':
				return (S);

			case 'T':
			case 't':
				return (T);

			}
			break;

		default:
			fatal("Unknown state in scanner.");
		}
		yyerror((char *) 0);
		state = CMD;
		longjmp(errcatch,0);
	}
}

upper(s)
	char *s;
{
	while (*s != '\0') {
		if (islower(*s))
			*s = toupper(*s);
		s++;
	}
}

copy(s)
	char *s;
{
	char *p;
	extern char *malloc(), *strcpy();

	p = malloc((unsigned) strlen(s) + 1);
	if (p == NULL)
		fatal("Ran out of memory.");
	(void) strcpy(p, s);
	return ((int)p);
}

help(s)
	char *s;
{
	register struct tab *c;
	register int width, NCMDS;

	width = 0, NCMDS = 0;
	for (c = cmdtab; c->name != NULL; c++) {
		int len = strlen(c->name) + 1;

		if (len > width)
			width = len;
		NCMDS++;
	}
	width = (width + 8) &~ 7;
	if (s == 0) {
		register int i, j, w;
		int columns, lines;

		lreply(214,
	  "The following commands are recognized (* =>'s unimplemented).");
		columns = 76 / width;
		if (columns == 0)
			columns = 1;
		lines = (NCMDS + columns - 1) / columns;
		for (i = 0; i < lines; i++) {
			printf("   ");
			for (j = 0; j < columns; j++) {
				c = cmdtab + j * lines + i;
				printf("%s%c", c->name,
					c->implemented ? ' ' : '*');
				if (c + lines >= &cmdtab[NCMDS])
					break;
				w = strlen(c->name) + 1;
				while (w < width) {
					putchar(' ');
					w++;
				}
			}
			printf("\r\n");
		}
		(void) fflush(stdout);
		reply(214, "Direct comments to ftp-bugs@%s.", hostname);
		return;
	}
	upper(s);
	c = lookup(s);
	if (c == (struct tab *)0) {
		reply(502, "Unknown command %s.", s);
		return;
	}
	if (c->implemented)
		reply(214, "Syntax: %s %s", c->name, c->help);
	else
		reply(214, "%-*s\t%s; unimplemented.", width, c->name, c->help);
}
short yyexca[] ={
-1, 1,
	0, -1,
	-2, 0,
	};
# define YYNPROD 62
# define YYLAST 235
short yyact[]={

  32, 114, 158, 156, 154, 116, 152, 116, 133,  85,
  71,  96,  99,  69,  68,  66, 157, 155,   4,   5,
 153, 151,  31,   9,  10,  11,  12,  13,  15,  16,
  17, 110,  98,  97,  92,  91,  90,  89,  14, 150,
  33,  21,  22,  20,  23,  19,  18,  55,  54,  24,
  25,  26,  27,  28,  29,  30,   8,   6,   7, 149,
 148, 147, 146, 145, 144, 143, 142, 141, 140, 137,
 128, 126, 119, 118, 135, 117, 111, 109, 136, 108,
  94, 107, 106, 103, 102,  63,  62,  56,  52,  40,
  37,  36, 113, 112, 105, 104, 101, 100,  93,  88,
  87,  86,  83,  84,  51,  44,  43,  42,  41,  39,
  38,  82,  35,  78,  34, 115,  73,  80,  79,  74,
 134,  75,  76,  45,  95,  81,  77,  72,  70,  67,
  65,   3,   2,   1,   0,   0,   0,   0,   0,   0,
  46,  47,  48,  49,  50,   0,   0,  53,   0,   0,
  57,  58,  59,  60,  61,   0,   0,  64,   0,   0,
   0,   0,   0,   0,   0,   0,   0, 120, 121, 122,
   0, 123,   0, 124, 125,   0,   0,   0,   0, 127,
   0, 129, 130,   0,   0, 131, 132,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
 139,   0,   0,   0, 138 };
short yypact[]={

-1000,-256,-1000,-1000,-155,-157,-179,-180,-159,-160,
-181,-161,-162,-163,-164,-1000,-1000,-1000,-1000,-1000,
-1000,-165,-182,-1000,-222,-183,-1000,-1000,-1000,-1000,
-1000,-184,-185,-1000,-257,-258,-1000,-1000,-259,-263,
-1000,-141,-148,-156,-264,-168,-169,-170,-233,-235,
-171,-261,-1000,-237,-1000,-260,-1000,-172,-173,-186,
-187,-174,-1000,-1000,-175,-188,-1000,-189,-1000,-191,
-193,-240,-194,-176,-177,-1000,-268,-195,-1000,-1000,
-1000,-197,-1000,-1000,-1000,-198,-261,-261,-261,-1000,
-261,-1000,-261,-261,-199,-1000,-1000,-1000,-261,-200,
-261,-261,-1000,-1000,-261,-261,-1000,-1000,-1000,-1000,
-265,-1000,-190,-190,-266,-1000,-1000,-1000,-1000,-1000,
-202,-203,-204,-205,-206,-207,-1000,-208,-1000,-209,
-210,-211,-231,-250,-1000,-1000,-1000,-1000,-1000,-1000,
-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
-1000,-267,-251,-269,-254,-270,-255,-271,-1000 };
short yypgo[]={

   0, 133, 132, 131, 130, 129, 128, 127, 126, 125,
 123,  80, 115, 120, 124 };
short yyr1[]={

   0,   1,   1,   1,   2,   2,   2,   2,   2,   2,
   2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
   2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
   2,   2,   2,   2,   2,   2,   2,   3,   4,   5,
  12,   6,  13,  13,  13,   7,   7,   7,   7,   7,
   7,   7,   7,   8,   8,   8,   9,   9,   9,  11,
  14,  10 };
short yyr2[]={

   0,   0,   2,   2,   4,   4,   2,   2,   4,   4,
   2,   4,   4,   4,   4,   5,   5,   5,   3,   5,
   3,   5,   5,   4,   2,   3,   5,   2,   4,   2,
   5,   5,   3,   3,   5,   2,   2,   5,   1,   1,
   1,  11,   1,   1,   1,   1,   3,   1,   3,   1,
   1,   3,   2,   1,   1,   1,   1,   1,   1,   1,
   1,   0 };
short yychk[]={

-1000,  -1,  -2,  -3, 274, 275, 313, 314, 312, 279,
 280, 281, 282, 283, 294, 284, 285, 286, 302, 301,
 299, 297, 298, 300, 305, 306, 307, 308, 309, 310,
 311, 278, 256, 296, 269, 269, 270, 270, 269, 269,
 270, 269, 269, 269, 269, -10, -10, -10, -10, -10,
 -10, 269, 270, -10, 270, 269, 270, -10, -10, -10,
 -10, -10, 270, 270, -10,  -4, 272,  -5, 272, 272,
  -6, 273,  -7, 257, 260, 262, 263,  -8, 261, 266,
 265,  -9, 267, 258, 259, 273, 269, 269, 269, 270,
 269, 270, 269, 269, -11, -14, 272, 270, 269, 272,
 269, 269, 270, 270, 269, 269, 270, 270, 270, 270,
 271, 270, 269, 269, 269, -12, 273, 270, 270, 270,
 -11, -11, -11, -11, -11, -11, 270, -11, 270, -11,
 -11, -11, -11, 273, -13, 264, 268, 259, -13, -12,
 270, 270, 270, 270, 270, 270, 270, 270, 270, 270,
 270, 271, 273, 271, 273, 271, 273, 271, 273 };
short yydef[]={

   1,  -2,   2,   3,   0,   0,   0,   0,   0,   0,
   0,   0,   0,   0,   0,  61,  61,  61,  61,  61,
  61,   0,   0,  61,   0,   0,  61,  61,  61,  61,
  61,   0,   0,  61,   0,   0,   6,   7,   0,   0,
  10,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   0,   0,  24,   0,  27,   0,  29,   0,   0,   0,
   0,   0,  35,  36,   0,   0,  38,   0,  39,   0,
   0,   0,   0,  45,  47,  49,  50,   0,  53,  54,
  55,   0,  56,  57,  58,   0,   0,   0,   0,  18,
   0,  20,   0,   0,   0,  59,  60,  25,   0,   0,
   0,   0,  32,  33,   0,   0,   4,   5,   8,   9,
   0,  11,   0,   0,   0,  52,  40,  12,  13,  14,
   0,   0,   0,   0,   0,   0,  23,   0,  28,   0,
   0,   0,   0,   0,  46,  42,  43,  44,  48,  51,
  15,  16,  17,  19,  21,  22,  26,  30,  31,  34,
  37,   0,   0,   0,   0,   0,   0,   0,  41 };
/*
 *	$Source: /afs/rel-eng.athena.mit.edu/project/release/current/source/bsd-4.3/common/usr.bin/yacc/RCS/yaccpar,v $
 *	$Author: epeisach $
 *	$Locker:  $
 *	$Header: /afs/rel-eng.athena.mit.edu/project/release/current/source/bsd-4.3/common/usr.bin/yacc/RCS/yaccpar,v 1.4 90/03/30 10:09:19 epeisach Exp $
 */

#ifndef lint
static char yaccpar_sccsid[] = "@(#)yaccpar	4.1	(Berkeley)	2/11/83";
#endif /* not lint */

# define YYFLAG -1000
# define YYERROR goto yyerrlab
# define YYACCEPT return(0)
# define YYABORT return(1)

/*	parser for yacc output	*/

#ifdef YYDEBUG
int yydebug = 0; /* 1 for debugging */
#endif
YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
int yychar = -1; /* current input token number */
int yynerrs = 0;  /* number of errors */
short yyerrflag = 0;  /* error recovery flag */

yyparse() {

	short yys[YYMAXDEPTH];
	short yyj, yym;
	register YYSTYPE *yypvt;
	register short yystate, *yyps, yyn;
	register YYSTYPE *yypv;
	register short *yyxi;

	yystate = 0;
	yychar = -1;
	yynerrs = 0;
	yyerrflag = 0;
	yyps= yys -1;
	yypv= yyv -1;

 yystack:    /* put a state and value onto the stack */

#ifdef YYDEBUG
	if( yydebug  ) printf( "state %d, char 0%o\n", yystate, yychar );
#endif
		if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); }
		*yyps = yystate;
		++yypv;
		*yypv = yyval;

 yynewstate:

	yyn = yypact[yystate];

	if( yyn<= YYFLAG ) goto yydefault; /* simple state */

	if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
	if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;

	if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
		yychar = -1;
		yyval = yylval;
		yystate = yyn;
		if( yyerrflag > 0 ) --yyerrflag;
		goto yystack;
		}

 yydefault:
	/* default state action */

	if( (yyn=yydef[yystate]) == -2 ) {
		if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
		/* look through exception table */

		for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */

		while( *(yyxi+=2) >= 0 ){
			if( *yyxi == yychar ) break;
			}
		if( (yyn = yyxi[1]) < 0 ) return(0);   /* accept */
		}

	if( yyn == 0 ){ /* error */
		/* error ... attempt to resume parsing */

		switch( yyerrflag ){

		case 0:   /* brand new error */

			yyerror( "syntax error" );
		yyerrlab:
			++yynerrs;

		case 1:
		case 2: /* incompletely recovered error ... try again */

			yyerrflag = 3;

			/* find a state where "error" is a legal shift action */

			while ( yyps >= yys ) {
			   yyn = yypact[*yyps] + YYERRCODE;
			   if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
			      yystate = yyact[yyn];  /* simulate a shift of "error" */
			      goto yystack;
			      }
			   yyn = yypact[*yyps];

			   /* the current yyps has no shift onn "error", pop stack */

#ifdef YYDEBUG
			   if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
#endif
			   --yyps;
			   --yypv;
			   }

			/* there is no state on the stack with an error shift ... abort */

	yyabort:
			return(1);


		case 3:  /* no shift yet; clobber input char */

#ifdef YYDEBUG
			if( yydebug ) printf( "error recovery discards char %d\n", yychar );
#endif

			if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
			yychar = -1;
			goto yynewstate;   /* try again in the same state */

			}

		}

	/* reduction by production yyn */

#ifdef YYDEBUG
		if( yydebug ) printf("reduce %d\n",yyn);
#endif
		yyps -= yyr2[yyn];
		yypvt = yypv;
		yypv -= yyr2[yyn];
		yyval = yypv[1];
		yym=yyn;
			/* consult goto table to find next state */
		yyn = yyr1[yyn];
		yyj = yypgo[yyn] + *yyps + 1;
		if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
		switch(yym){
			
case 2:
# line 109 "ftpcmd.y"
 {
			fromname = (char *) 0;
		} break;
case 4:
# line 116 "ftpcmd.y"
 {
		     ftp_user((char *) yypvt[-1]);
		     free((char *) yypvt[-1]);
		} break;
case 5:
# line 121 "ftpcmd.y"
 {
		     ftp_pass((char *) yypvt[-1]);
		     free((char *) yypvt[-1]);
		} break;
case 6:
# line 126 "ftpcmd.y"
 {
#ifdef KERBEROS
		     krb_debug = !krb_debug;
		     reply(200, "Kerberos: Debug is now %s.",(krb_debug) ?
			   "ON" : "OFF");
#else
		     reply(509, "Kerberos functions not supported.");
#endif
		} break;
case 7:
# line 136 "ftpcmd.y"
 {
#ifdef KERBEROS
		     int	kerrno;
		     
		     if (! has_tickets)
			  reply( 999, "KDESTROY:  You do not have tickets.");
		     else {
			  kerrno = ftp_kdest();
			  if (! kerrno) {
			       reply(200, "KDESTROY successful.");
			       has_tickets = 0; }
			  else reply(999,"KDESTROY: System error: %s",
				     sys_errlist[errno]);
		     }
#else
		     reply(509, "Kerberos functions not supported.");
#endif
		} break;
case 8:
# line 155 "ftpcmd.y"
 {
		     int	aerror;

		     lreply(214,"Invoking 'attach %s'",(char *) yypvt[-1]);
		     aerror = ftp_attach((char *) yypvt[-1]);
		     (void) fflush(stdout);
		     if (! aerror) reply(214,"ATTACH command successful.");
		     else reply(214, "ATTACH: Exit code %d.",aerror);
		} break;
case 9:
# line 165 "ftpcmd.y"
 {
			usedefault = 0;
			if (pdata > 0) {
				(void) close(pdata);
			}
			pdata = -1;
			reply(200, "PORT command successful.");
		} break;
case 10:
# line 174 "ftpcmd.y"
 {
			passive();
		} break;
case 11:
# line 178 "ftpcmd.y"
 {
			switch (cmd_type) {

			case TYPE_A:
				if (cmd_form == FORM_N) {
					reply(200, "Type set to A.");
					type = cmd_type;
					form = cmd_form;
				} else
					reply(504, "Form must be N.");
				break;

			case TYPE_E:
				reply(504, "Type E not implemented.");
				break;

			case TYPE_I:
				reply(200, "Type set to I.");
				type = cmd_type;
				break;

			case TYPE_L:
				if (cmd_bytesz == 8) {
					reply(200,
					    "Type set to L (byte size 8).");
					type = cmd_type;
				} else
					reply(504, "Byte size must be 8.");
			}
		} break;
case 12:
# line 209 "ftpcmd.y"
 {
			switch (yypvt[-1]) {

			case STRU_F:
				reply(200, "STRU F ok.");
				break;

			default:
				reply(504, "Unimplemented STRU type.");
			}
		} break;
case 13:
# line 221 "ftpcmd.y"
 {
			switch (yypvt[-1]) {

			case MODE_S:
				reply(200, "MODE S ok.");
				break;

			default:
				reply(502, "Unimplemented MODE type.");
			}
		} break;
case 14:
# line 233 "ftpcmd.y"
 {
			reply(202, "ALLO command ignored.");
		} break;
case 15:
# line 237 "ftpcmd.y"
 {
			if (yypvt[-3] && yypvt[-1] != NULL)
				retrieve((char *) 0, (char *) yypvt[-1]);
			if (yypvt[-1] != NULL)
				free((char *) yypvt[-1]);
		} break;
case 16:
# line 244 "ftpcmd.y"
 {
			if (yypvt[-3] && yypvt[-1] != NULL)
				store((char *) yypvt[-1], "w");
			if (yypvt[-1] != NULL)
				free((char *) yypvt[-1]);
		} break;
case 17:
# line 251 "ftpcmd.y"
 {
			if (yypvt[-3] && yypvt[-1] != NULL)
				store((char *) yypvt[-1], "a");
			if (yypvt[-1] != NULL)
				free((char *) yypvt[-1]);
		} break;
case 18:
# line 258 "ftpcmd.y"
 {
			if (yypvt[-1])
				retrieve("/bin/ls", "");
		} break;
case 19:
# line 263 "ftpcmd.y"
 {
			if (yypvt[-3] && yypvt[-1] != NULL)
				retrieve("/bin/ls %s", (char *) yypvt[-1]);
			if (yypvt[-1] != NULL)
				free((char *) yypvt[-1]);
		} break;
case 20:
# line 270 "ftpcmd.y"
 {
			if (yypvt[-1])
				retrieve("/bin/ls -lg", "");
		} break;
case 21:
# line 275 "ftpcmd.y"
 {
			if (yypvt[-3] && yypvt[-1] != NULL)
				retrieve("/bin/ls -lg %s", (char *) yypvt[-1]);
			if (yypvt[-1] != NULL)
				free((char *) yypvt[-1]);
		} break;
case 22:
# line 282 "ftpcmd.y"
 {
			if (yypvt[-3] && yypvt[-1] != NULL)
				delete((char *) yypvt[-1]);
			if (yypvt[-1] != NULL)
				free((char *) yypvt[-1]);
		} break;
case 23:
# line 289 "ftpcmd.y"
 {
			if (fromname) {
				renamecmd(fromname, (char *) yypvt[-1]);
				free(fromname);
				fromname = (char *) 0;
			} else {
				reply(503, "Bad sequence of commands.");
			}
			free((char *) yypvt[-1]);
		} break;
case 24:
# line 300 "ftpcmd.y"
 {
			reply(225, "ABOR command successful.");
		} break;
case 25:
# line 304 "ftpcmd.y"
 {
			if (yypvt[-1])
				cwd(pw->pw_dir);
		} break;
case 26:
# line 309 "ftpcmd.y"
 {
			if (yypvt[-3] && yypvt[-1] != NULL)
				cwd((char *) yypvt[-1]);
			if (yypvt[-1] != NULL)
				free((char *) yypvt[-1]);
		} break;
case 27:
# line 316 "ftpcmd.y"
 {
			help((char *) 0);
		} break;
case 28:
# line 320 "ftpcmd.y"
 {
			help((char *) yypvt[-1]);
		} break;
case 29:
# line 324 "ftpcmd.y"
 {
			reply(200, "NOOP command successful.");
		} break;
case 30:
# line 328 "ftpcmd.y"
 {
			if (yypvt[-3] && yypvt[-1] != NULL)
				makedir((char *) yypvt[-1]);
			if (yypvt[-1] != NULL)
				free((char *) yypvt[-1]);
		} break;
case 31:
# line 335 "ftpcmd.y"
 {
			if (yypvt[-3] && yypvt[-1] != NULL)
				removedir((char *) yypvt[-1]);
			if (yypvt[-1] != NULL)
				free((char *) yypvt[-1]);
		} break;
case 32:
# line 342 "ftpcmd.y"
 {
			if (yypvt[-1])
				pwd();
		} break;
case 33:
# line 347 "ftpcmd.y"
 {
			if (yypvt[-1])
				cwd("..");
		} break;
case 34:
# line 352 "ftpcmd.y"
 {
			if (yypvt[-3] && yypvt[-1] != NULL) {
				unique++;
				store((char *) yypvt[-1], "w");
				unique = 0;
			}
			if (yypvt[-1] != NULL)
				free((char *) yypvt[-1]);
		} break;
case 35:
# line 362 "ftpcmd.y"
 {
		     if (has_tickets) {
			  if (ftp_kdest())
			       reply(532, "Error destroying tickets: %s",
				     sys_errlist[errno]);
			  else {
			       reply(221, "Tickets destroyed.  Goodbye.");
			       dologout(0); }
		     }
		     else {
			  reply(221, "Goodbye.");
			  dologout(0);
		     }
		} break;
case 36:
# line 377 "ftpcmd.y"
 {
			yyerrok;
		} break;
case 37:
# line 383 "ftpcmd.y"
 {
			char *renamefrom();

			if (yypvt[-3] && yypvt[-1]) {
				fromname = renamefrom((char *) yypvt[-1]);
				if (fromname == (char *) 0 && yypvt[-1]) {
					free((char *) yypvt[-1]);
				}
			}
		} break;
case 41:
# line 406 "ftpcmd.y"
 {
			register char *a, *p;

			a = (char *)&data_dest.sin_addr;
			a[0] = yypvt[-10]; a[1] = yypvt[-8]; a[2] = yypvt[-6]; a[3] = yypvt[-4];
			p = (char *)&data_dest.sin_port;
			p[0] = yypvt[-2]; p[1] = yypvt[-0];
			data_dest.sin_family = AF_INET;
		} break;
case 42:
# line 418 "ftpcmd.y"
 {
		yyval = FORM_N;
	} break;
case 43:
# line 422 "ftpcmd.y"
 {
		yyval = FORM_T;
	} break;
case 44:
# line 426 "ftpcmd.y"
 {
		yyval = FORM_C;
	} break;
case 45:
# line 432 "ftpcmd.y"
 {
		cmd_type = TYPE_A;
		cmd_form = FORM_N;
	} break;
case 46:
# line 437 "ftpcmd.y"
 {
		cmd_type = TYPE_A;
		cmd_form = yypvt[-0];
	} break;
case 47:
# line 442 "ftpcmd.y"
 {
		cmd_type = TYPE_E;
		cmd_form = FORM_N;
	} break;
case 48:
# line 447 "ftpcmd.y"
 {
		cmd_type = TYPE_E;
		cmd_form = yypvt[-0];
	} break;
case 49:
# line 452 "ftpcmd.y"
 {
		cmd_type = TYPE_I;
	} break;
case 50:
# line 456 "ftpcmd.y"
 {
		cmd_type = TYPE_L;
		cmd_bytesz = 8;
	} break;
case 51:
# line 461 "ftpcmd.y"
 {
		cmd_type = TYPE_L;
		cmd_bytesz = yypvt[-0];
	} break;
case 52:
# line 467 "ftpcmd.y"
 {
		cmd_type = TYPE_L;
		cmd_bytesz = yypvt[-0];
	} break;
case 53:
# line 474 "ftpcmd.y"
 {
		yyval = STRU_F;
	} break;
case 54:
# line 478 "ftpcmd.y"
 {
		yyval = STRU_R;
	} break;
case 55:
# line 482 "ftpcmd.y"
 {
		yyval = STRU_P;
	} break;
case 56:
# line 488 "ftpcmd.y"
 {
		yyval = MODE_S;
	} break;
case 57:
# line 492 "ftpcmd.y"
 {
		yyval = MODE_B;
	} break;
case 58:
# line 496 "ftpcmd.y"
 {
		yyval = MODE_C;
	} break;
case 59:
# line 502 "ftpcmd.y"
 {
		/*
		 * Problem: this production is used for all pathname
		 * processing, but only gives a 550 error reply.
		 * This is a valid reply in some cases but not in others.
		 */
		if (yypvt[-0] && strncmp((char *) yypvt[-0], "~", 1) == 0) {
			yyval = (int)*glob((char *) yypvt[-0]);
			if (globerr != NULL) {
				reply(550, globerr);
				yyval = NULL;
			}
			free((char *) yypvt[-0]);
		} else
			yyval = yypvt[-0];
	} break;
case 61:
# line 524 "ftpcmd.y"
 {
		if (logged_in)
			yyval = 1;
		else {
			reply(530, "Please login with USER and PASS.");
			yyval = 0;
		}
	} break;
		}
		goto yystack;  /* stack new state and value */

	}
