2 static char const yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
10 #define yyclearin (yychar=(YYEMPTY))
11 #define yyerrok (yyerrflag=0)
12 #define YYRECOVERING (yyerrflag!=0)
13 #if defined(c_plusplus) || defined(__cplusplus)
16 extern char *getenv();
17 extern void *realloc();
19 static int yygrowstack();
24 static char sccsid[] = "@(#)ftpcmd.y 5.20.1.1 (Berkeley) 3/2/89";
27 #include <sys/param.h>
28 #include <sys/socket.h>
30 #include <netinet/in.h>
43 extern struct sockaddr_in data_dest;
45 extern struct passwd *pw;
52 extern int maxtimeout;
54 extern char hostname[], remotehost[];
55 extern char proctitle[];
57 extern int usedefault;
59 extern char tmpline[];
64 static int cmd_bytesz;
133 #define YYERRCODE 256
134 const short yylhs[] = { -1,
135 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
136 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
137 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
138 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
139 1, 1, 1, 1, 1, 1, 2, 3, 4, 4,
140 12, 5, 13, 13, 13, 6, 6, 6, 6, 6,
141 6, 6, 6, 7, 7, 7, 8, 8, 8, 10,
144 const short yylen[] = { 2,
145 0, 2, 2, 4, 4, 4, 2, 4, 4, 4,
146 4, 8, 5, 5, 5, 3, 5, 3, 5, 5,
147 2, 5, 4, 2, 3, 5, 2, 4, 2, 5,
148 5, 3, 3, 4, 6, 5, 7, 9, 4, 6,
149 5, 2, 5, 5, 2, 2, 5, 1, 0, 1,
150 1, 11, 1, 1, 1, 1, 3, 1, 3, 1,
151 1, 3, 2, 1, 1, 1, 1, 1, 1, 1,
154 const short yydefred[] = { 1,
155 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
156 73, 73, 73, 0, 73, 0, 0, 73, 73, 73,
157 73, 0, 0, 0, 0, 73, 73, 73, 73, 73,
158 0, 73, 73, 2, 3, 46, 0, 0, 45, 0,
159 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
160 24, 0, 0, 0, 0, 0, 21, 0, 0, 27,
161 29, 0, 0, 0, 0, 0, 42, 0, 0, 48,
162 0, 50, 0, 0, 0, 0, 0, 60, 0, 0,
163 64, 66, 65, 0, 68, 69, 67, 0, 0, 0,
164 0, 0, 0, 71, 0, 70, 0, 0, 25, 0,
165 18, 0, 16, 0, 73, 0, 73, 0, 0, 0,
166 0, 32, 33, 0, 0, 0, 4, 5, 0, 6,
167 0, 0, 0, 51, 63, 8, 9, 10, 0, 0,
168 0, 0, 11, 0, 23, 0, 0, 0, 0, 0,
169 34, 0, 0, 39, 0, 0, 28, 0, 0, 0,
170 0, 0, 0, 55, 53, 54, 57, 59, 62, 13,
171 14, 15, 0, 47, 22, 26, 19, 17, 0, 0,
172 36, 0, 0, 20, 30, 31, 41, 43, 44, 0,
173 0, 35, 72, 0, 40, 0, 0, 0, 37, 0,
174 0, 12, 0, 0, 38, 0, 0, 0, 52,
176 const short yydgoto[] = { 1,
177 34, 35, 71, 73, 75, 80, 84, 88, 45, 95,
180 const short yysindex[] = { 0,
181 -224, -247, -239, -236, -232, -222, -204, -200, -181, -177,
182 0, 0, 0, -166, 0, -161, -199, 0, 0, 0,
183 0, -160, -159, -264, -158, 0, 0, 0, 0, 0,
184 -157, 0, 0, 0, 0, 0, -167, -162, 0, -156,
185 0, -250, -198, -165, -155, -154, -153, -151, -150, -152,
186 0, -145, -252, -229, -217, -302, 0, -144, -146, 0,
187 0, -142, -141, -140, -139, -137, 0, -136, -135, 0,
188 -134, 0, -133, -132, -130, -131, -128, 0, -249, -127,
189 0, 0, 0, -126, 0, 0, 0, -125, -152, -152,
190 -152, -205, -152, 0, -124, 0, -152, -152, 0, -152,
191 0, -143, 0, -173, 0, -171, 0, -152, -123, -152,
192 -152, 0, 0, -152, -152, -152, 0, 0, -138, 0,
193 -164, -164, -122, 0, 0, 0, 0, 0, -121, -120,
194 -118, -148, 0, -117, 0, -116, -115, -114, -113, -112,
195 0, -163, -111, 0, -110, -109, 0, -107, -106, -105,
196 -104, -103, -129, 0, 0, 0, 0, 0, 0, 0,
197 0, 0, -101, 0, 0, 0, 0, 0, -100, -102,
198 0, -98, -102, 0, 0, 0, 0, 0, 0, -99,
199 -97, 0, 0, -95, 0, -96, -94, -92, 0, -152,
200 -93, 0, -91, -90, 0, -88, -87, -86, 0,
202 const short yyrindex[] = { 0,
203 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
204 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205 0, 0, -83, 0, 0, 0, 0, 0, 0, 0,
206 0, 0, 0, 0, 0, 0, 0, -82, 0, 0,
207 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
208 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
209 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
210 0, 0, 0, 0, 0, -81, -80, 0, -158, 0,
211 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
212 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
213 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
214 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
215 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
216 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
218 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
219 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
220 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
221 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
222 0, 0, 0, 0, 0, 0, 0, 0, 0,
224 const short yygindex[] = { 0,
225 0, 0, 0, 0, 0, 0, 0, 0, 16, -89,
228 #define YYTABLESIZE 190
229 const short yytable[] = { 129,
230 130, 131, 104, 134, 59, 60, 76, 136, 137, 77,
231 138, 78, 79, 105, 106, 107, 98, 99, 146, 123,
232 148, 149, 36, 124, 150, 151, 152, 46, 47, 37,
233 49, 2, 38, 52, 53, 54, 55, 39, 58, 100,
234 101, 62, 63, 64, 65, 66, 40, 68, 69, 3,
235 4, 102, 103, 5, 6, 7, 8, 9, 10, 11,
236 12, 13, 81, 132, 133, 41, 82, 83, 42, 14,
237 51, 15, 16, 17, 18, 19, 20, 21, 22, 23,
238 24, 25, 26, 27, 28, 29, 30, 43, 31, 32,
239 33, 44, 85, 86, 154, 140, 141, 143, 144, 155,
240 193, 87, 48, 156, 70, 170, 171, 50, 56, 72,
241 57, 61, 67, 89, 90, 91, 74, 163, 93, 94,
242 142, 92, 145, 97, 108, 109, 110, 111, 139, 112,
243 113, 114, 115, 116, 153, 117, 118, 121, 119, 120,
244 122, 180, 126, 127, 128, 135, 147, 186, 160, 161,
245 124, 162, 164, 165, 166, 167, 168, 159, 173, 169,
246 174, 172, 175, 176, 177, 178, 179, 181, 158, 182,
247 183, 185, 190, 187, 189, 188, 191, 192, 195, 194,
248 196, 0, 0, 198, 197, 73, 199, 49, 56, 58,
250 const short yycheck[] = { 89,
251 90, 91, 305, 93, 269, 270, 257, 97, 98, 260,
252 100, 262, 263, 316, 317, 318, 269, 270, 108, 269,
253 110, 111, 270, 273, 114, 115, 116, 12, 13, 269,
254 15, 256, 269, 18, 19, 20, 21, 270, 23, 269,
255 270, 26, 27, 28, 29, 30, 269, 32, 33, 274,
256 275, 269, 270, 278, 279, 280, 281, 282, 283, 284,
257 285, 286, 261, 269, 270, 270, 265, 266, 269, 294,
258 270, 296, 297, 298, 299, 300, 301, 302, 303, 304,
259 305, 306, 307, 308, 309, 310, 311, 269, 313, 314,
260 315, 269, 258, 259, 259, 269, 270, 269, 270, 264,
261 190, 267, 269, 268, 272, 269, 270, 269, 269, 272,
262 270, 270, 270, 269, 269, 269, 273, 266, 269, 272,
263 105, 273, 107, 269, 269, 272, 269, 269, 272, 270,
264 270, 269, 269, 269, 273, 270, 270, 269, 271, 270,
265 269, 271, 270, 270, 270, 270, 270, 173, 270, 270,
266 273, 270, 270, 270, 270, 270, 270, 123, 269, 272,
267 270, 273, 270, 270, 270, 270, 270, 269, 122, 270,
268 273, 270, 269, 273, 270, 273, 271, 270, 270, 273,
269 271, -1, -1, 271, 273, 269, 273, 270, 270, 270,
277 #define YYMAXTOKEN 319
279 const char * const yyname[] = {
280 "end-of-file",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,
281 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,
282 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,
283 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,
284 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,
285 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,
286 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"A","B","C","E","F","I","L","N",
287 "P","R","S","T","SP","CRLF","COMMA","STRING","NUMBER","USER","PASS","ACCT",
288 "REIN","QUIT","PORT","PASV","TYPE","STRU","MODE","RETR","STOR","APPE","MLFL",
289 "MAIL","MSND","MSOM","MSAM","MRSQ","MRCP","ALLO","REST","RNFR","RNTO","ABOR",
290 "DELE","CWD","LIST","NLST","SITE","STAT","HELP","NOOP","MKD","RMD","PWD","CDUP",
291 "STOU","SMNT","SYST","SIZE","MDTM","UMASK","IDLE","CHMOD","LEXERR",
293 const char * const yyrule[] = {
294 "$accept : cmd_list",
296 "cmd_list : cmd_list cmd",
297 "cmd_list : cmd_list rcmd",
298 "cmd : USER SP username CRLF",
299 "cmd : PASS SP password CRLF",
300 "cmd : PORT SP host_port CRLF",
302 "cmd : TYPE SP type_code CRLF",
303 "cmd : STRU SP struct_code CRLF",
304 "cmd : MODE SP mode_code CRLF",
305 "cmd : ALLO SP NUMBER CRLF",
306 "cmd : ALLO SP NUMBER SP R SP NUMBER CRLF",
307 "cmd : RETR check_login SP pathname CRLF",
308 "cmd : STOR check_login SP pathname CRLF",
309 "cmd : APPE check_login SP pathname CRLF",
310 "cmd : NLST check_login CRLF",
311 "cmd : NLST check_login SP STRING CRLF",
312 "cmd : LIST check_login CRLF",
313 "cmd : LIST check_login SP pathname CRLF",
314 "cmd : STAT check_login SP pathname CRLF",
316 "cmd : DELE check_login SP pathname CRLF",
317 "cmd : RNTO SP pathname CRLF",
319 "cmd : CWD check_login CRLF",
320 "cmd : CWD check_login SP pathname CRLF",
322 "cmd : HELP SP STRING CRLF",
324 "cmd : MKD check_login SP pathname CRLF",
325 "cmd : RMD check_login SP pathname CRLF",
326 "cmd : PWD check_login CRLF",
327 "cmd : CDUP check_login CRLF",
328 "cmd : SITE SP HELP CRLF",
329 "cmd : SITE SP HELP SP STRING CRLF",
330 "cmd : SITE SP UMASK check_login CRLF",
331 "cmd : SITE SP UMASK check_login SP octal_number CRLF",
332 "cmd : SITE SP CHMOD check_login SP octal_number SP pathname CRLF",
333 "cmd : SITE SP IDLE CRLF",
334 "cmd : SITE SP IDLE SP NUMBER CRLF",
335 "cmd : STOU check_login SP pathname CRLF",
337 "cmd : SIZE check_login SP pathname CRLF",
338 "cmd : MDTM check_login SP pathname CRLF",
341 "rcmd : RNFR check_login SP pathname CRLF",
345 "byte_size : NUMBER",
346 "host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER",
351 "type_code : A SP form_code",
353 "type_code : E SP form_code",
356 "type_code : L SP byte_size",
357 "type_code : L byte_size",
364 "pathname : pathstring",
365 "pathstring : STRING",
366 "octal_number : NUMBER",
375 #define YYMAXDEPTH YYSTACKSIZE
378 #define YYSTACKSIZE YYMAXDEPTH
380 #define YYSTACKSIZE 10000
381 #define YYMAXDEPTH 10000
384 #define YYINITSTACKSIZE 200
399 extern jmp_buf errcatch;
401 #define CMD 0 /* beginning of command */
402 #define ARGS 1 /* expect miscellaneous arguments */
403 #define STR1 2 /* expect SP followed by STRING */
404 #define STR2 3 /* expect STRING */
405 #define OSTR 4 /* optional SP then STRING */
406 #define ZSTR1 5 /* SP then optional STRING */
407 #define ZSTR2 6 /* optional STRING after SP */
408 #define SITECMD 7 /* SITE command */
409 #define NSTR 8 /* Number followed by a string */
415 short implemented; /* 1 if command is implemented */
419 struct tab cmdtab[] = { /* In order defined in RFC 765 */
420 { "USER", USER, STR1, 1, "<sp> username" },
421 { "PASS", PASS, ZSTR1, 1, "<sp> password" },
422 { "ACCT", ACCT, STR1, 0, "(specify account)" },
423 { "SMNT", SMNT, ARGS, 0, "(structure mount)" },
424 { "REIN", REIN, ARGS, 0, "(reinitialize server state)" },
425 { "QUIT", QUIT, ARGS, 1, "(terminate service)", },
426 { "PORT", PORT, ARGS, 1, "<sp> b0, b1, b2, b3, b4" },
427 { "PASV", PASV, ARGS, 1, "(set server in passive mode)" },
428 { "TYPE", TYPE, ARGS, 1, "<sp> [ A | E | I | L ]" },
429 { "STRU", STRU, ARGS, 1, "(specify file structure)" },
430 { "MODE", MODE, ARGS, 1, "(specify transfer mode)" },
431 { "RETR", RETR, STR1, 1, "<sp> file-name" },
432 { "STOR", STOR, STR1, 1, "<sp> file-name" },
433 { "APPE", APPE, STR1, 1, "<sp> file-name" },
434 { "MLFL", MLFL, OSTR, 0, "(mail file)" },
435 { "MAIL", MAIL, OSTR, 0, "(mail to user)" },
436 { "MSND", MSND, OSTR, 0, "(mail send to terminal)" },
437 { "MSOM", MSOM, OSTR, 0, "(mail send to terminal or mailbox)" },
438 { "MSAM", MSAM, OSTR, 0, "(mail send to terminal and mailbox)" },
439 { "MRSQ", MRSQ, OSTR, 0, "(mail recipient scheme question)" },
440 { "MRCP", MRCP, STR1, 0, "(mail recipient)" },
441 { "ALLO", ALLO, ARGS, 1, "allocate storage (vacuously)" },
442 { "REST", REST, ARGS, 0, "(restart command)" },
443 { "RNFR", RNFR, STR1, 1, "<sp> file-name" },
444 { "RNTO", RNTO, STR1, 1, "<sp> file-name" },
445 { "ABOR", ABOR, ARGS, 1, "(abort operation)" },
446 { "DELE", DELE, STR1, 1, "<sp> file-name" },
447 { "CWD", CWD, OSTR, 1, "[ <sp> directory-name ]" },
448 { "XCWD", CWD, OSTR, 1, "[ <sp> directory-name ]" },
449 { "LIST", LIST, OSTR, 1, "[ <sp> path-name ]" },
450 { "NLST", NLST, OSTR, 1, "[ <sp> path-name ]" },
451 { "SITE", SITE, SITECMD, 1, "site-cmd [ <sp> arguments ]" },
452 { "SYST", SYST, ARGS, 1, "(get type of operating system)" },
453 { "STAT", STAT, OSTR, 1, "[ <sp> path-name ]" },
454 { "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" },
455 { "NOOP", NOOP, ARGS, 1, "" },
456 { "MKD", MKD, STR1, 1, "<sp> path-name" },
457 { "XMKD", MKD, STR1, 1, "<sp> path-name" },
458 { "RMD", RMD, STR1, 1, "<sp> path-name" },
459 { "XRMD", RMD, STR1, 1, "<sp> path-name" },
460 { "PWD", PWD, ARGS, 1, "(return current directory)" },
461 { "XPWD", PWD, ARGS, 1, "(return current directory)" },
462 { "CDUP", CDUP, ARGS, 1, "(change to parent directory)" },
463 { "XCUP", CDUP, ARGS, 1, "(change to parent directory)" },
464 { "STOU", STOU, STR1, 1, "<sp> file-name" },
465 { "SIZE", SIZE, OSTR, 1, "<sp> path-name" },
466 { "MDTM", MDTM, OSTR, 1, "<sp> path-name" },
470 struct tab sitetab[] = {
471 { "UMASK", UMASK, ARGS, 1, "[ <sp> umask ]" },
472 { "IDLE", IDLE, ARGS, 1, "[ <sp> maximum-idle-time ]" },
473 { "CHMOD", CHMOD, NSTR, 1, "<sp> mode <sp> file-name" },
474 { "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" },
480 register struct tab *p;
484 for (; p->name != NULL; p++)
485 if (strcmp(cmd, p->name) == 0)
490 #include <arpa/telnet.h>
493 * getline - a hacked up version of fgets to ignore TELNET escape codes.
504 /* tmpline may contain saved command from urgent mode interruption */
505 for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) {
507 if (tmpline[c] == '\n') {
510 syslog(LOG_DEBUG, "command: %s", s);
517 while ((c = getc(iop)) != EOF) {
520 if ((c = getc(iop)) != EOF) {
526 printf("%c%c%c", IAC, DONT, 0377&c);
527 (void) fflush(stdout);
532 printf("%c%c%c", IAC, WONT, 0377&c);
533 (void) fflush(stdout);
538 continue; /* ignore command */
543 if (--n <= 0 || c == '\n')
546 if (c == EOF && cs == s)
550 syslog(LOG_DEBUG, "command: %s", s);
558 extern char *ctime();
559 extern time_t time();
562 "Timeout (%d seconds): closing control connection.", timeout);
566 "User %s timed out after %d seconds at %s",
567 (pw ? pw -> pw_name : "unknown"), timeout, ctime(&now));
574 static int cpos, state;
575 register char *cp, *cp2;
576 register struct tab *p;
585 (void) signal(SIGALRM, toolong);
586 (void) alarm((unsigned) timeout);
587 if (getline(cbuf, sizeof(cbuf)-1, stdin) == NULL) {
588 reply(221, "You could at least say goodbye.");
593 if (strncasecmp(cbuf, "PASS", 4) != NULL)
594 setproctitle("%s: %s", proctitle, cbuf);
595 #endif /* SETPROCTITLE */
596 if ((cp = index(cbuf, '\r'))) {
600 if ((cp = strpbrk(cbuf, " \n")))
607 p = lookup(cmdtab, cbuf);
610 if (p->implemented == 0) {
616 *(char **)&yylval = p->name;
622 if (cbuf[cpos] == ' ') {
627 if ((cp2 = strpbrk(cp, " \n")))
632 p = lookup(sitetab, cp);
635 if (p->implemented == 0) {
642 *(char **)&yylval = p->name;
649 if (cbuf[cpos] == '\n') {
658 if (cbuf[cpos] == ' ') {
660 state = state == OSTR ? STR2 : ++state;
666 if (cbuf[cpos] == '\n') {
677 * Make sure the string is nonempty and \n terminated.
679 if (n > 1 && cbuf[cpos] == '\n') {
681 *(char **)&yylval = copy(cp);
689 if (cbuf[cpos] == ' ') {
693 if (isdigit(cbuf[cpos])) {
695 while (isdigit(cbuf[++cpos]))
708 if (isdigit(cbuf[cpos])) {
710 while (isdigit(cbuf[++cpos]))
718 switch (cbuf[cpos++]) {
782 fatal("Unknown state in scanner.");
805 extern char *malloc(), *strcpy();
807 p = malloc((unsigned) strlen(s) + 1);
809 fatal("Ran out of memory.");
818 register struct tab *c;
819 register int width, NCMDS;
826 width = 0, NCMDS = 0;
827 for (c = ctab; c->name != NULL; c++) {
828 int len = strlen(c->name);
834 width = (width + 8) &~ 7;
836 register int i, j, w;
839 lreply(214, "The following %scommands are recognized %s.",
840 type, "(* =>'s unimplemented)");
841 columns = 76 / width;
844 lines = (NCMDS + columns - 1) / columns;
845 for (i = 0; i < lines; i++) {
847 for (j = 0; j < columns; j++) {
848 c = ctab + j * lines + i;
849 printf("%s%c", c->name,
850 c->implemented ? ' ' : '*');
851 if (c + lines >= &ctab[NCMDS])
853 w = strlen(c->name) + 1;
861 (void) fflush(stdout);
862 reply(214, "Direct comments to ftp-bugs@%s.", hostname);
867 if (c == (struct tab *)0) {
868 reply(502, "Unknown command %s.", s);
872 reply(214, "Syntax: %s%s %s", type, c->name, c->help);
874 reply(214, "%s%-*s\t%s; unimplemented.", type, width,
885 if (stat(filename, &stbuf) < 0 ||
886 (stbuf.st_mode&S_IFMT) != S_IFREG)
887 reply(550, "%s: not a plain file.", filename);
889 reply(213, "%lu", stbuf.st_size);
893 register int c, count;
895 fin = fopen(filename, "r");
897 perror_reply(550, filename);
900 if (fstat(fileno(fin), &stbuf) < 0 ||
901 (stbuf.st_mode&S_IFMT) != S_IFREG) {
902 reply(550, "%s: not a plain file.", filename);
908 while((c=getc(fin)) != EOF) {
909 if (c == '\n') /* will get expanded to \r\n */
915 reply(213, "%ld", count);
918 reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]);
921 #line 920 "ftp.tab.c"
922 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
923 static int yygrowstack()
929 if ((newsize = yystacksize) == 0)
930 newsize = YYINITSTACKSIZE;
931 else if (newsize >= YYMAXDEPTH)
933 else if ((newsize *= 2) > YYMAXDEPTH)
934 newsize = YYMAXDEPTH;
936 if ((newss = (short *)realloc(yyss, newsize * sizeof *newss)) == NULL)
940 if ((newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs)) == NULL)
944 yystacksize = newsize;
945 yysslim = yyss + newsize - 1;
949 #define YYABORT goto yyabort
950 #define YYREJECT goto yyabort
951 #define YYACCEPT goto yyaccept
952 #define YYERROR goto yyerrlab
957 register int yym, yyn, yystate;
959 register const char *yys;
961 if ((yys = getenv("YYDEBUG")))
964 if (yyn >= '0' && yyn <= '9')
973 if (yyss == NULL && yygrowstack()) goto yyoverflow;
976 *yyssp = yystate = 0;
979 if ((yyn = yydefred[yystate])) goto yyreduce;
982 if ((yychar = yylex()) < 0) yychar = 0;
987 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
988 if (!yys) yys = "illegal-symbol";
989 printf("%sdebug: state %d, reading %d (%s)\n",
990 YYPREFIX, yystate, yychar, yys);
994 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
995 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
999 printf("%sdebug: state %d, shifting to state %d\n",
1000 YYPREFIX, yystate, yytable[yyn]);
1002 if (yyssp >= yysslim && yygrowstack())
1006 *++yyssp = yystate = yytable[yyn];
1009 if (yyerrflag > 0) --yyerrflag;
1012 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
1013 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1018 if (yyerrflag) goto yyinrecovery;
1019 #if defined(lint) || defined(__GNUC__)
1023 yyerror("syntax error");
1024 #if defined(lint) || defined(__GNUC__)
1035 if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
1036 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
1040 printf("%sdebug: state %d, error recovery shifting\
1041 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
1043 if (yyssp >= yysslim && yygrowstack())
1047 *++yyssp = yystate = yytable[yyn];
1055 printf("%sdebug: error recovery discarding state %d\n",
1058 if (yyssp <= yyss) goto yyabort;
1066 if (yychar == 0) goto yyabort;
1071 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1072 if (!yys) yys = "illegal-symbol";
1073 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1074 YYPREFIX, yystate, yychar, yys);
1083 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1084 YYPREFIX, yystate, yyn, yyrule[yyn]);
1087 yyval = yyvsp[1-yym];
1093 fromname = (char *) 0;
1099 user((char *) yyvsp[-1]);
1100 free((char *) yyvsp[-1]);
1106 pass((char *) yyvsp[-1]);
1107 free((char *) yyvsp[-1]);
1115 (void) close(pdata);
1118 reply(200, "PORT command successful.");
1133 if (cmd_form == FORM_N) {
1134 reply(200, "Type set to A.");
1138 reply(504, "Form must be N.");
1142 reply(504, "Type E not implemented.");
1146 reply(200, "Type set to I.");
1152 if (cmd_bytesz == 8) {
1154 "Type set to L (byte size 8).");
1157 reply(504, "Byte size must be 8.");
1158 #else /* NBBY == 8 */
1159 UNIMPLEMENTED for NBBY != 8
1160 #endif /* NBBY == 8 */
1167 switch (yyvsp[-1]) {
1170 reply(200, "STRU F ok.");
1174 reply(504, "Unimplemented STRU type.");
1181 switch (yyvsp[-1]) {
1184 reply(200, "MODE S ok.");
1188 reply(502, "Unimplemented MODE type.");
1195 reply(202, "ALLO command ignored.");
1201 reply(202, "ALLO command ignored.");
1207 if (yyvsp[-3] && yyvsp[-1] != NULL)
1208 retrieve((char *) 0, (char *) yyvsp[-1]);
1209 if (yyvsp[-1] != NULL)
1210 free((char *) yyvsp[-1]);
1216 if (yyvsp[-3] && yyvsp[-1] != NULL)
1217 store((char *) yyvsp[-1], "w", 0);
1218 if (yyvsp[-1] != NULL)
1219 free((char *) yyvsp[-1]);
1225 if (yyvsp[-3] && yyvsp[-1] != NULL)
1226 store((char *) yyvsp[-1], "a", 0);
1227 if (yyvsp[-1] != NULL)
1228 free((char *) yyvsp[-1]);
1235 send_file_list(".");
1241 if (yyvsp[-3] && yyvsp[-1] != NULL)
1242 send_file_list((char *) yyvsp[-1]);
1243 if (yyvsp[-1] != NULL)
1244 free((char *) yyvsp[-1]);
1251 retrieve("/bin/ls -lgA", "");
1257 if (yyvsp[-3] && yyvsp[-1] != NULL)
1258 retrieve("/bin/ls -lgA %s", (char *) yyvsp[-1]);
1259 if (yyvsp[-1] != NULL)
1260 free((char *) yyvsp[-1]);
1266 if (yyvsp[-3] && yyvsp[-1] != NULL)
1267 statfilecmd((char *) yyvsp[-1]);
1268 if (yyvsp[-1] != NULL)
1269 free((char *) yyvsp[-1]);
1281 if (yyvsp[-3] && yyvsp[-1] != NULL)
1282 delete((char *) yyvsp[-1]);
1283 if (yyvsp[-1] != NULL)
1284 free((char *) yyvsp[-1]);
1291 renamecmd(fromname, (char *) yyvsp[-1]);
1293 fromname = (char *) 0;
1295 reply(503, "Bad sequence of commands.");
1297 free((char *) yyvsp[-1]);
1303 reply(225, "ABOR command successful.");
1316 if (yyvsp[-3] && yyvsp[-1] != NULL)
1317 cwd((char *) yyvsp[-1]);
1318 if (yyvsp[-1] != NULL)
1319 free((char *) yyvsp[-1]);
1325 help(cmdtab, (char *) 0);
1331 register char *cp = (char *)yyvsp[-1];
1333 if (strncasecmp(cp, "SITE", 4) == 0) {
1334 cp = (char *)yyvsp[-1] + 4;
1340 help(sitetab, (char *) 0);
1342 help(cmdtab, (char *) yyvsp[-1]);
1348 reply(200, "NOOP command successful.");
1354 if (yyvsp[-3] && yyvsp[-1] != NULL)
1355 makedir((char *) yyvsp[-1]);
1356 if (yyvsp[-1] != NULL)
1357 free((char *) yyvsp[-1]);
1363 if (yyvsp[-3] && yyvsp[-1] != NULL)
1364 removedir((char *) yyvsp[-1]);
1365 if (yyvsp[-1] != NULL)
1366 free((char *) yyvsp[-1]);
1386 help(sitetab, (char *) 0);
1392 help(sitetab, (char *) yyvsp[-1]);
1402 (void) umask(oldmask);
1403 reply(200, "Current UMASK is %03o", oldmask);
1413 if ((yyvsp[-1] == -1) || (yyvsp[-1] > 0777)) {
1414 reply(501, "Bad UMASK value");
1416 oldmask = umask(yyvsp[-1]);
1418 "UMASK set to %03o (was %03o)",
1419 yyvsp[-1], oldmask);
1427 if (yyvsp[-5] && (yyvsp[-1] != NULL)) {
1428 if (yyvsp[-3] > 0777)
1430 "CHMOD: Mode value must be between 0 and 0777");
1431 else if (chmod((char *) yyvsp[-1], yyvsp[-3]) < 0)
1432 perror_reply(550, (char *) yyvsp[-1]);
1434 reply(200, "CHMOD command successful.");
1436 if (yyvsp[-1] != NULL)
1437 free((char *) yyvsp[-1]);
1444 "Current IDLE time limit is %d seconds; max %d",
1445 timeout, maxtimeout);
1451 if (yyvsp[-1] < 30 || yyvsp[-1] > maxtimeout) {
1453 "Maximum IDLE time must be between 30 and %d seconds",
1456 timeout = yyvsp[-1];
1457 (void) alarm((unsigned) timeout);
1459 "Maximum IDLE time set to %d seconds",
1467 if (yyvsp[-3] && yyvsp[-1] != NULL)
1468 store((char *) yyvsp[-1], "w", 1);
1469 if (yyvsp[-1] != NULL)
1470 free((char *) yyvsp[-1]);
1478 reply(215, "UNIX Type: L%d Version: BSD-%d",
1481 reply(215, "UNIX Type: L%d", NBBY);
1484 reply(215, "UNKNOWN Type: L%d", NBBY);
1491 if (yyvsp[-3] && yyvsp[-1] != NULL)
1492 sizecmd((char *) yyvsp[-1]);
1493 if (yyvsp[-1] != NULL)
1494 free((char *) yyvsp[-1]);
1500 if (yyvsp[-3] && yyvsp[-1] != NULL) {
1502 if (stat((char *) yyvsp[-1], &stbuf) < 0)
1503 perror_reply(550, "%s", (char *) yyvsp[-1]);
1504 else if ((stbuf.st_mode&S_IFMT) != S_IFREG) {
1505 reply(550, "%s: not a plain file.",
1506 (char *) yyvsp[-1]);
1508 register struct tm *t;
1509 struct tm *gmtime();
1510 t = gmtime(&stbuf.st_mtime);
1512 "%d%02d%02d%02d%02d%02d",
1513 t->tm_year+1900, t->tm_mon+1, t->tm_mday,
1514 t->tm_hour, t->tm_min, t->tm_sec);
1517 if (yyvsp[-1] != NULL)
1518 free((char *) yyvsp[-1]);
1524 reply(221, "Goodbye.");
1539 if (yyvsp[-3] && yyvsp[-1]) {
1540 fromname = renamefrom((char *) yyvsp[-1]);
1541 if (fromname == (char *) 0 && yyvsp[-1]) {
1542 free((char *) yyvsp[-1]);
1550 *(char **)&(yyval) = "";
1556 register char *a, *p;
1558 a = (char *)&data_dest.sin_addr;
1559 a[0] = yyvsp[-10]; a[1] = yyvsp[-8]; a[2] = yyvsp[-6]; a[3] = yyvsp[-4];
1560 p = (char *)&data_dest.sin_port;
1561 p[0] = yyvsp[-2]; p[1] = yyvsp[0];
1562 data_dest.sin_family = AF_INET;
1594 cmd_form = yyvsp[0];
1608 cmd_form = yyvsp[0];
1628 cmd_bytesz = yyvsp[0];
1635 cmd_bytesz = yyvsp[0];
1678 * Problem: this production is used for all pathname
1679 * processing, but only gives a 550 error reply.
1680 * This is a valid reply in some cases but not in others.
1682 if (logged_in && yyvsp[0] && strncmp((char *) yyvsp[0], "~", 1) == 0) {
1683 *(char **)&(yyval) = *glob((char *) yyvsp[0]);
1684 if (globerr != NULL) {
1685 reply(550, globerr);
1688 free((char *) yyvsp[0]);
1696 register int ret, dec, multby, digit;
1699 * Convert a number that was read as decimal number
1700 * to what it would be if it had been read as octal.
1711 ret += digit * multby;
1724 reply(530, "Please login with USER and PASS.");
1729 #line 1728 "ftp.tab.c"
1735 if (yystate == 0 && yym == 0)
1739 printf("%sdebug: after reduction, shifting from state 0 to\
1740 state %d\n", YYPREFIX, YYFINAL);
1747 if ((yychar = yylex()) < 0) yychar = 0;
1752 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1753 if (!yys) yys = "illegal-symbol";
1754 printf("%sdebug: state %d, reading %d (%s)\n",
1755 YYPREFIX, YYFINAL, yychar, yys);
1759 if (yychar == 0) goto yyaccept;
1762 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
1763 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
1764 yystate = yytable[yyn];
1766 yystate = yydgoto[yym];
1769 printf("%sdebug: after reduction, shifting from state %d \
1770 to state %d\n", YYPREFIX, *yyssp, yystate);
1772 if (yyssp >= yysslim && yygrowstack())
1780 yyerror("yacc stack overflow");