tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / byacc / dist / test / ftp.tab.c
blob2aba796e9bcf2adedfe0970fd9e0e4c1c1a5ffab
1 /* $NetBSD: ftp.tab.c,v 1.5 2013/04/06 14:52:24 christos Exp $ */
3 #ifndef lint
4 /* static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; */
5 static char rcsid[] = "$NetBSD: ftp.tab.c,v 1.5 2013/04/06 14:52:24 christos Exp $";
6 #endif
8 #define YYBYACC 1
9 #define YYMAJOR 1
10 #define YYMINOR 9
12 #define YYEMPTY (-1)
13 #define yyclearin (yychar = YYEMPTY)
14 #define yyerrok (yyerrflag = 0)
15 #define YYRECOVERING() (yyerrflag != 0)
18 #ifndef yyparse
19 #define yyparse ftp_parse
20 #endif /* yyparse */
22 #ifndef yylex
23 #define yylex ftp_lex
24 #endif /* yylex */
26 #ifndef yyerror
27 #define yyerror ftp_error
28 #endif /* yyerror */
30 #ifndef yychar
31 #define yychar ftp_char
32 #endif /* yychar */
34 #ifndef yyval
35 #define yyval ftp_val
36 #endif /* yyval */
38 #ifndef yylval
39 #define yylval ftp_lval
40 #endif /* yylval */
42 #ifndef yydebug
43 #define yydebug ftp_debug
44 #endif /* yydebug */
46 #ifndef yynerrs
47 #define yynerrs ftp_nerrs
48 #endif /* yynerrs */
50 #ifndef yyerrflag
51 #define yyerrflag ftp_errflag
52 #endif /* yyerrflag */
54 #ifndef yylhs
55 #define yylhs ftp_lhs
56 #endif /* yylhs */
58 #ifndef yylen
59 #define yylen ftp_len
60 #endif /* yylen */
62 #ifndef yydefred
63 #define yydefred ftp_defred
64 #endif /* yydefred */
66 #ifndef yydgoto
67 #define yydgoto ftp_dgoto
68 #endif /* yydgoto */
70 #ifndef yysindex
71 #define yysindex ftp_sindex
72 #endif /* yysindex */
74 #ifndef yyrindex
75 #define yyrindex ftp_rindex
76 #endif /* yyrindex */
78 #ifndef yygindex
79 #define yygindex ftp_gindex
80 #endif /* yygindex */
82 #ifndef yytable
83 #define yytable ftp_table
84 #endif /* yytable */
86 #ifndef yycheck
87 #define yycheck ftp_check
88 #endif /* yycheck */
90 #ifndef yyname
91 #define yyname ftp_name
92 #endif /* yyname */
94 #ifndef yyrule
95 #define yyrule ftp_rule
96 #endif /* yyrule */
97 #define YYPREFIX "ftp_"
99 #define YYPURE 0
101 #line 26 "ftp.y"
103 /* sccsid[] = "@(#)ftpcmd.y 5.20.1.1 (Berkeley) 3/2/89"; */
105 #include <sys/param.h>
106 #include <sys/socket.h>
108 #include <netinet/in.h>
110 #include <arpa/ftp.h>
112 #include <stdlib.h>
113 #include <unistd.h>
114 #include <stdio.h>
115 #include <signal.h>
116 #include <ctype.h>
117 #include <pwd.h>
118 #include <setjmp.h>
119 #include <syslog.h>
120 #include <sys/stat.h>
121 #include <string.h>
122 #include <time.h>
123 #include <assert.h>
125 #ifdef YYBISON
126 int yylex(void);
127 static void yyerror(const char *);
128 #endif
130 extern struct sockaddr_in data_dest;
131 extern int logged_in;
132 extern struct passwd *pw;
133 extern int guest;
134 extern int logging;
135 extern int type;
136 extern int form;
137 extern int debug;
138 extern int timeout;
139 extern int maxtimeout;
140 extern int pdata;
141 extern char hostname[], remotehost[];
142 extern char proctitle[];
143 extern char *globerr;
144 extern int usedefault;
145 extern int transflag;
146 extern char tmpline[];
148 extern char **glob(char *);
149 extern char *renamefrom(char *);
150 extern void cwd(const char *);
152 extern void dologout(int);
153 extern void fatal(const char *);
154 extern void makedir(const char *);
155 extern void nack(const char *);
156 extern void pass(const char *);
157 extern void passive(void);
158 extern void pwd(void);
159 extern void removedir(char *);
160 extern void renamecmd(char *, char *);
161 extern void retrieve(const char *, const char *);
162 extern void send_file_list(const char *);
163 extern void statcmd(void);
164 extern void statfilecmd(const char *);
165 extern void store(char *, const char *, int);
166 extern void user(const char *);
168 extern void perror_reply(int, const char *, ...);
169 extern void reply(int, const char *, ...);
170 extern void lreply(int, const char *, ...);
172 static int cmd_type;
173 static int cmd_form;
174 static int cmd_bytesz;
175 char cbuf[512];
176 char *fromname;
178 struct tab {
179 const char *name;
180 short token;
181 short state;
182 short implemented; /* 1 if command is implemented */
183 const char *help;
186 static char * copy(const char *);
188 #ifdef YYBISON
189 static void sizecmd(char *filename);
190 static void help(struct tab *ctab, char *s);
191 struct tab cmdtab[];
192 struct tab sitetab[];
193 #endif
195 static void
196 yyerror(const char *msg)
198 perror(msg);
200 #line 126 "ftp.y"
201 #ifdef YYSTYPE
202 #undef YYSTYPE_IS_DECLARED
203 #define YYSTYPE_IS_DECLARED 1
204 #endif
205 #ifndef YYSTYPE_IS_DECLARED
206 #define YYSTYPE_IS_DECLARED 1
207 typedef union
209 int ival;
210 char *sval;
211 } YYSTYPE;
212 #endif /* !YYSTYPE_IS_DECLARED */
213 #line 211 "ftp.tab.c"
215 /* compatibility with bison */
216 #ifdef YYPARSE_PARAM
217 /* compatibility with FreeBSD */
218 # ifdef YYPARSE_PARAM_TYPE
219 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
220 # else
221 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
222 # endif
223 #else
224 # define YYPARSE_DECL() yyparse(void)
225 #endif
227 /* Parameters sent to lex. */
228 #ifdef YYLEX_PARAM
229 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
230 # define YYLEX yylex(YYLEX_PARAM)
231 #else
232 # define YYLEX_DECL() yylex(void)
233 # define YYLEX yylex()
234 #endif
236 /* Parameters sent to yyerror. */
237 #ifndef YYERROR_DECL
238 #define YYERROR_DECL() yyerror(const char *s)
239 #endif
240 #ifndef YYERROR_CALL
241 #define YYERROR_CALL(msg) yyerror(msg)
242 #endif
244 extern int YYPARSE_DECL();
246 #define NUMBER 257
247 #define STRING 258
248 #define A 259
249 #define B 260
250 #define C 261
251 #define E 262
252 #define F 263
253 #define I 264
254 #define L 265
255 #define N 266
256 #define P 267
257 #define R 268
258 #define S 269
259 #define T 270
260 #define SP 271
261 #define CRLF 272
262 #define COMMA 273
263 #define USER 274
264 #define PASS 275
265 #define ACCT 276
266 #define REIN 277
267 #define QUIT 278
268 #define PORT 279
269 #define PASV 280
270 #define TYPE 281
271 #define STRU 282
272 #define MODE 283
273 #define RETR 284
274 #define STOR 285
275 #define APPE 286
276 #define MLFL 287
277 #define MAIL 288
278 #define MSND 289
279 #define MSOM 290
280 #define MSAM 291
281 #define MRSQ 292
282 #define MRCP 293
283 #define ALLO 294
284 #define REST 295
285 #define RNFR 296
286 #define RNTO 297
287 #define ABOR 298
288 #define DELE 299
289 #define CWD 300
290 #define LIST 301
291 #define NLST 302
292 #define SITE 303
293 #define STAT 304
294 #define HELP 305
295 #define NOOP 306
296 #define MKD 307
297 #define RMD 308
298 #define PWD 309
299 #define CDUP 310
300 #define STOU 311
301 #define SMNT 312
302 #define SYST 313
303 #define SIZE 314
304 #define MDTM 315
305 #define UMASK 316
306 #define IDLE 317
307 #define CHMOD 318
308 #define LEXERR 319
309 #define YYERRCODE 256
310 static const short ftp_lhs[] = { -1,
311 0, 0, 0, 11, 11, 11, 11, 11, 11, 11,
312 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
313 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
314 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
315 11, 11, 11, 11, 11, 11, 12, 10, 7, 7,
316 1, 13, 3, 3, 3, 14, 14, 14, 14, 14,
317 14, 14, 14, 6, 6, 6, 4, 4, 4, 8,
318 9, 5, 2,
320 static const short ftp_len[] = { 2,
321 0, 2, 2, 4, 4, 4, 2, 4, 4, 4,
322 4, 8, 5, 5, 5, 3, 5, 3, 5, 5,
323 2, 5, 4, 2, 3, 5, 2, 4, 2, 5,
324 5, 3, 3, 4, 6, 5, 7, 9, 4, 6,
325 5, 2, 5, 5, 2, 2, 5, 1, 0, 1,
326 1, 11, 1, 1, 1, 1, 3, 1, 3, 1,
327 1, 3, 2, 1, 1, 1, 1, 1, 1, 1,
328 1, 1, 0,
330 static const short ftp_defred[] = { 1,
331 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
332 73, 73, 73, 0, 73, 0, 0, 73, 73, 73,
333 73, 0, 0, 0, 0, 73, 73, 73, 73, 73,
334 0, 73, 73, 2, 3, 46, 0, 0, 45, 0,
335 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
336 24, 0, 0, 0, 0, 0, 21, 0, 0, 27,
337 29, 0, 0, 0, 0, 0, 42, 0, 0, 48,
338 0, 50, 0, 0, 0, 0, 0, 60, 0, 0,
339 64, 66, 65, 0, 68, 69, 67, 0, 0, 0,
340 0, 0, 0, 71, 0, 70, 0, 0, 25, 0,
341 18, 0, 16, 0, 73, 0, 73, 0, 0, 0,
342 0, 32, 33, 0, 0, 0, 4, 5, 0, 6,
343 0, 0, 51, 0, 63, 8, 9, 10, 0, 0,
344 0, 0, 11, 0, 23, 0, 0, 0, 0, 0,
345 34, 0, 0, 39, 0, 0, 28, 0, 0, 0,
346 0, 0, 0, 55, 53, 54, 57, 59, 62, 13,
347 14, 15, 0, 47, 22, 26, 19, 17, 0, 0,
348 36, 0, 0, 20, 30, 31, 41, 43, 44, 0,
349 0, 35, 72, 0, 40, 0, 0, 0, 37, 0,
350 0, 12, 0, 0, 38, 0, 0, 0, 52,
352 static const short ftp_dgoto[] = { 1,
353 125, 45, 157, 88, 184, 84, 73, 95, 96, 71,
354 34, 35, 75, 80,
356 static const short ftp_sindex[] = { 0,
357 -224, -256, -248, -241, -239, -233, -225, -218, -200, -165,
358 0, 0, 0, -164, 0, -163, -176, 0, 0, 0,
359 0, -162, -161, -231, -160, 0, 0, 0, 0, 0,
360 -159, 0, 0, 0, 0, 0, -240, -148, 0, -143,
361 0, -252, -175, -255, -156, -155, -154, -139, -152, -138,
362 0, -149, -205, -203, -177, -253, 0, -147, -133, 0,
363 0, -145, -144, -142, -141, -137, 0, -136, -135, 0,
364 -140, 0, -134, -132, -130, -131, -128, 0, -254, -127,
365 0, 0, 0, -126, 0, 0, 0, -125, -138, -138,
366 -138, -174, -138, 0, -124, 0, -138, -138, 0, -138,
367 0, -129, 0, -172, 0, -169, 0, -138, -123, -138,
368 -138, 0, 0, -138, -138, -138, 0, 0, -120, 0,
369 -246, -246, 0, -118, 0, 0, 0, 0, -122, -121,
370 -119, -116, 0, -117, 0, -115, -114, -113, -112, -104,
371 0, -167, -101, 0, -110, -109, 0, -108, -107, -106,
372 -105, -103, -111, 0, 0, 0, 0, 0, 0, 0,
373 0, 0, -100, 0, 0, 0, 0, 0, -102, -85,
374 0, -99, -85, 0, 0, 0, 0, 0, 0, -83,
375 -82, 0, 0, -96, 0, -94, -95, -93, 0, -138,
376 -77, 0, -91, -90, 0, -75, -88, -73, 0,
378 static const short ftp_rindex[] = { 0,
379 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
380 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
381 0, 0, -84, 0, 0, 0, 0, 0, 0, 0,
382 0, 0, 0, 0, 0, 0, 0, -86, 0, 0,
383 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
384 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
385 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
386 0, 0, 0, 0, 0, -81, -80, 0, -160, 0,
387 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
388 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
389 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
390 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
391 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
392 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
393 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
394 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
395 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
396 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
397 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
398 0, 0, 0, 0, 0, 0, 0, 0, 0,
400 static const short ftp_gindex[] = { 0,
401 4, 16, 11, 0, -29, 0, 0, -89, 0, 0,
402 0, 0, 0, 0,
404 #define YYTABLESIZE 192
405 static const short ftp_table[] = { 129,
406 130, 131, 123, 134, 85, 86, 76, 136, 137, 77,
407 138, 78, 79, 87, 154, 36, 124, 70, 146, 155,
408 148, 149, 37, 156, 150, 151, 152, 46, 47, 38,
409 49, 2, 39, 52, 53, 54, 55, 40, 58, 59,
410 60, 62, 63, 64, 65, 66, 41, 68, 69, 3,
411 4, 104, 42, 5, 6, 7, 8, 9, 10, 11,
412 12, 13, 105, 106, 107, 98, 99, 100, 101, 14,
413 43, 15, 16, 17, 18, 19, 20, 21, 22, 23,
414 24, 25, 26, 27, 28, 29, 30, 81, 31, 32,
415 33, 82, 83, 102, 103, 51, 132, 133, 140, 141,
416 193, 143, 144, 170, 171, 44, 48, 50, 56, 72,
417 57, 61, 67, 74, 89, 90, 91, 92, 93, 94,
418 142, 97, 145, 108, 109, 110, 111, 159, 139, 112,
419 113, 117, 158, 114, 115, 116, 153, 118, 123, 121,
420 119, 120, 122, 186, 126, 127, 128, 135, 147, 160,
421 161, 163, 162, 169, 164, 172, 165, 166, 167, 168,
422 173, 180, 174, 175, 176, 177, 178, 0, 179, 182,
423 181, 183, 185, 187, 188, 189, 190, 191, 192, 194,
424 195, 197, 196, 199, 198, 49, 73, 0, 0, 0,
425 56, 58,
427 static const short ftp_check[] = { 89,
428 90, 91, 257, 93, 260, 261, 259, 97, 98, 262,
429 100, 264, 265, 269, 261, 272, 271, 258, 108, 266,
430 110, 111, 271, 270, 114, 115, 116, 12, 13, 271,
431 15, 256, 272, 18, 19, 20, 21, 271, 23, 271,
432 272, 26, 27, 28, 29, 30, 272, 32, 33, 274,
433 275, 305, 271, 278, 279, 280, 281, 282, 283, 284,
434 285, 286, 316, 317, 318, 271, 272, 271, 272, 294,
435 271, 296, 297, 298, 299, 300, 301, 302, 303, 304,
436 305, 306, 307, 308, 309, 310, 311, 263, 313, 314,
437 315, 267, 268, 271, 272, 272, 271, 272, 271, 272,
438 190, 271, 272, 271, 272, 271, 271, 271, 271, 258,
439 272, 272, 272, 257, 271, 271, 271, 257, 271, 258,
440 105, 271, 107, 271, 258, 271, 271, 124, 258, 272,
441 272, 272, 122, 271, 271, 271, 257, 272, 257, 271,
442 273, 272, 271, 173, 272, 272, 272, 272, 272, 272,
443 272, 268, 272, 258, 272, 257, 272, 272, 272, 272,
444 271, 273, 272, 272, 272, 272, 272, -1, 272, 272,
445 271, 257, 272, 257, 257, 272, 271, 273, 272, 257,
446 272, 257, 273, 257, 273, 272, 271, -1, -1, -1,
447 272, 272,
449 #define YYFINAL 1
450 #ifndef YYDEBUG
451 #define YYDEBUG 0
452 #endif
453 #define YYMAXTOKEN 319
454 #if YYDEBUG
455 static const char *yyname[] = {
457 "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,
458 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,
459 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,
460 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,
461 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,
462 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,
463 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"NUMBER","STRING","A","B","C","E",
464 "F","I","L","N","P","R","S","T","SP","CRLF","COMMA","USER","PASS","ACCT","REIN",
465 "QUIT","PORT","PASV","TYPE","STRU","MODE","RETR","STOR","APPE","MLFL","MAIL",
466 "MSND","MSOM","MSAM","MRSQ","MRCP","ALLO","REST","RNFR","RNTO","ABOR","DELE",
467 "CWD","LIST","NLST","SITE","STAT","HELP","NOOP","MKD","RMD","PWD","CDUP","STOU",
468 "SMNT","SYST","SIZE","MDTM","UMASK","IDLE","CHMOD","LEXERR",
470 static const char *yyrule[] = {
471 "$accept : cmd_list",
472 "cmd_list :",
473 "cmd_list : cmd_list cmd",
474 "cmd_list : cmd_list rcmd",
475 "cmd : USER SP username CRLF",
476 "cmd : PASS SP password CRLF",
477 "cmd : PORT SP host_port CRLF",
478 "cmd : PASV CRLF",
479 "cmd : TYPE SP type_code CRLF",
480 "cmd : STRU SP struct_code CRLF",
481 "cmd : MODE SP mode_code CRLF",
482 "cmd : ALLO SP NUMBER CRLF",
483 "cmd : ALLO SP NUMBER SP R SP NUMBER CRLF",
484 "cmd : RETR check_login SP pathname CRLF",
485 "cmd : STOR check_login SP pathname CRLF",
486 "cmd : APPE check_login SP pathname CRLF",
487 "cmd : NLST check_login CRLF",
488 "cmd : NLST check_login SP STRING CRLF",
489 "cmd : LIST check_login CRLF",
490 "cmd : LIST check_login SP pathname CRLF",
491 "cmd : STAT check_login SP pathname CRLF",
492 "cmd : STAT CRLF",
493 "cmd : DELE check_login SP pathname CRLF",
494 "cmd : RNTO SP pathname CRLF",
495 "cmd : ABOR CRLF",
496 "cmd : CWD check_login CRLF",
497 "cmd : CWD check_login SP pathname CRLF",
498 "cmd : HELP CRLF",
499 "cmd : HELP SP STRING CRLF",
500 "cmd : NOOP CRLF",
501 "cmd : MKD check_login SP pathname CRLF",
502 "cmd : RMD check_login SP pathname CRLF",
503 "cmd : PWD check_login CRLF",
504 "cmd : CDUP check_login CRLF",
505 "cmd : SITE SP HELP CRLF",
506 "cmd : SITE SP HELP SP STRING CRLF",
507 "cmd : SITE SP UMASK check_login CRLF",
508 "cmd : SITE SP UMASK check_login SP octal_number CRLF",
509 "cmd : SITE SP CHMOD check_login SP octal_number SP pathname CRLF",
510 "cmd : SITE SP IDLE CRLF",
511 "cmd : SITE SP IDLE SP NUMBER CRLF",
512 "cmd : STOU check_login SP pathname CRLF",
513 "cmd : SYST CRLF",
514 "cmd : SIZE check_login SP pathname CRLF",
515 "cmd : MDTM check_login SP pathname CRLF",
516 "cmd : QUIT CRLF",
517 "cmd : error CRLF",
518 "rcmd : RNFR check_login SP pathname CRLF",
519 "username : STRING",
520 "password :",
521 "password : STRING",
522 "byte_size : NUMBER",
523 "host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER",
524 "form_code : N",
525 "form_code : T",
526 "form_code : C",
527 "type_code : A",
528 "type_code : A SP form_code",
529 "type_code : E",
530 "type_code : E SP form_code",
531 "type_code : I",
532 "type_code : L",
533 "type_code : L SP byte_size",
534 "type_code : L byte_size",
535 "struct_code : F",
536 "struct_code : R",
537 "struct_code : P",
538 "mode_code : S",
539 "mode_code : B",
540 "mode_code : C",
541 "pathname : pathstring",
542 "pathstring : STRING",
543 "octal_number : NUMBER",
544 "check_login :",
547 #endif
549 int yydebug;
550 int yynerrs;
552 int yyerrflag;
553 int yychar;
554 YYSTYPE yyval;
555 YYSTYPE yylval;
557 /* define the initial stack-sizes */
558 #ifdef YYSTACKSIZE
559 #undef YYMAXDEPTH
560 #define YYMAXDEPTH YYSTACKSIZE
561 #else
562 #ifdef YYMAXDEPTH
563 #define YYSTACKSIZE YYMAXDEPTH
564 #else
565 #define YYSTACKSIZE 500
566 #define YYMAXDEPTH 500
567 #endif
568 #endif
570 #define YYINITSTACKSIZE 500
572 typedef struct {
573 unsigned stacksize;
574 short *s_base;
575 short *s_mark;
576 short *s_last;
577 YYSTYPE *l_base;
578 YYSTYPE *l_mark;
579 } YYSTACKDATA;
580 /* variables for the parser stack */
581 static YYSTACKDATA yystack;
582 #line 733 "ftp.y"
584 #ifdef YYBYACC
585 extern int YYLEX_DECL();
586 #endif
588 extern jmp_buf errcatch;
590 static void upper(char *);
592 #define CMD 0 /* beginning of command */
593 #define ARGS 1 /* expect miscellaneous arguments */
594 #define STR1 2 /* expect SP followed by STRING */
595 #define STR2 3 /* expect STRING */
596 #define OSTR 4 /* optional SP then STRING */
597 #define ZSTR1 5 /* SP then optional STRING */
598 #define ZSTR2 6 /* optional STRING after SP */
599 #define SITECMD 7 /* SITE command */
600 #define NSTR 8 /* Number followed by a string */
602 struct tab cmdtab[] = { /* In order defined in RFC 765 */
603 { "USER", USER, STR1, 1, "<sp> username" },
604 { "PASS", PASS, ZSTR1, 1, "<sp> password" },
605 { "ACCT", ACCT, STR1, 0, "(specify account)" },
606 { "SMNT", SMNT, ARGS, 0, "(structure mount)" },
607 { "REIN", REIN, ARGS, 0, "(reinitialize server state)" },
608 { "QUIT", QUIT, ARGS, 1, "(terminate service)", },
609 { "PORT", PORT, ARGS, 1, "<sp> b0, b1, b2, b3, b4" },
610 { "PASV", PASV, ARGS, 1, "(set server in passive mode)" },
611 { "TYPE", TYPE, ARGS, 1, "<sp> [ A | E | I | L ]" },
612 { "STRU", STRU, ARGS, 1, "(specify file structure)" },
613 { "MODE", MODE, ARGS, 1, "(specify transfer mode)" },
614 { "RETR", RETR, STR1, 1, "<sp> file-name" },
615 { "STOR", STOR, STR1, 1, "<sp> file-name" },
616 { "APPE", APPE, STR1, 1, "<sp> file-name" },
617 { "MLFL", MLFL, OSTR, 0, "(mail file)" },
618 { "MAIL", MAIL, OSTR, 0, "(mail to user)" },
619 { "MSND", MSND, OSTR, 0, "(mail send to terminal)" },
620 { "MSOM", MSOM, OSTR, 0, "(mail send to terminal or mailbox)" },
621 { "MSAM", MSAM, OSTR, 0, "(mail send to terminal and mailbox)" },
622 { "MRSQ", MRSQ, OSTR, 0, "(mail recipient scheme question)" },
623 { "MRCP", MRCP, STR1, 0, "(mail recipient)" },
624 { "ALLO", ALLO, ARGS, 1, "allocate storage (vacuously)" },
625 { "REST", REST, ARGS, 0, "(restart command)" },
626 { "RNFR", RNFR, STR1, 1, "<sp> file-name" },
627 { "RNTO", RNTO, STR1, 1, "<sp> file-name" },
628 { "ABOR", ABOR, ARGS, 1, "(abort operation)" },
629 { "DELE", DELE, STR1, 1, "<sp> file-name" },
630 { "CWD", CWD, OSTR, 1, "[ <sp> directory-name ]" },
631 { "XCWD", CWD, OSTR, 1, "[ <sp> directory-name ]" },
632 { "LIST", LIST, OSTR, 1, "[ <sp> path-name ]" },
633 { "NLST", NLST, OSTR, 1, "[ <sp> path-name ]" },
634 { "SITE", SITE, SITECMD, 1, "site-cmd [ <sp> arguments ]" },
635 { "SYST", SYST, ARGS, 1, "(get type of operating system)" },
636 { "STAT", STAT, OSTR, 1, "[ <sp> path-name ]" },
637 { "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" },
638 { "NOOP", NOOP, ARGS, 1, "" },
639 { "MKD", MKD, STR1, 1, "<sp> path-name" },
640 { "XMKD", MKD, STR1, 1, "<sp> path-name" },
641 { "RMD", RMD, STR1, 1, "<sp> path-name" },
642 { "XRMD", RMD, STR1, 1, "<sp> path-name" },
643 { "PWD", PWD, ARGS, 1, "(return current directory)" },
644 { "XPWD", PWD, ARGS, 1, "(return current directory)" },
645 { "CDUP", CDUP, ARGS, 1, "(change to parent directory)" },
646 { "XCUP", CDUP, ARGS, 1, "(change to parent directory)" },
647 { "STOU", STOU, STR1, 1, "<sp> file-name" },
648 { "SIZE", SIZE, OSTR, 1, "<sp> path-name" },
649 { "MDTM", MDTM, OSTR, 1, "<sp> path-name" },
650 { 0, 0, 0, 0, 0 }
653 struct tab sitetab[] = {
654 { "UMASK", UMASK, ARGS, 1, "[ <sp> umask ]" },
655 { "IDLE", IDLE, ARGS, 1, "[ <sp> maximum-idle-time ]" },
656 { "CHMOD", CHMOD, NSTR, 1, "<sp> mode <sp> file-name" },
657 { "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" },
658 { 0, 0, 0, 0, 0 }
661 static struct tab *
662 lookup(struct tab *p, char *cmd)
665 for (; p->name != 0; p++)
666 if (strcmp(cmd, p->name) == 0)
667 return (p);
668 return (0);
671 #include <arpa/telnet.h>
674 * get_line - a hacked up version of fgets to ignore TELNET escape codes.
676 static char *
677 get_line(char *s, int n, FILE *iop)
679 register int c;
680 register char *cs;
682 cs = s;
683 /* tmpline may contain saved command from urgent mode interruption */
684 for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) {
685 *cs++ = tmpline[c];
686 if (tmpline[c] == '\n') {
687 *cs = '\0';
688 if (debug)
689 syslog(LOG_DEBUG, "command: %s", s);
690 tmpline[0] = '\0';
691 return(s);
693 if (c == 0)
694 tmpline[0] = '\0';
696 while ((c = getc(iop)) != EOF) {
697 c &= 0377;
698 if (c == IAC) {
699 if ((c = getc(iop)) != EOF) {
700 c &= 0377;
701 switch (c) {
702 case WILL:
703 case WONT:
704 c = getc(iop);
705 printf("%c%c%c", IAC, DONT, 0377&c);
706 (void) fflush(stdout);
707 continue;
708 case DO:
709 case DONT:
710 c = getc(iop);
711 printf("%c%c%c", IAC, WONT, 0377&c);
712 (void) fflush(stdout);
713 continue;
714 case IAC:
715 break;
716 default:
717 continue; /* ignore command */
721 *cs++ = (char) c;
722 if (--n <= 0 || c == '\n')
723 break;
725 if (c == EOF && cs == s)
726 return (0);
727 *cs = '\0';
728 if (debug)
729 syslog(LOG_DEBUG, "command: %s", s);
730 return (s);
733 static void
734 toolong(int sig)
736 time_t now;
738 (void) sig;
739 reply(421,
740 "Timeout (%d seconds): closing control connection.", timeout);
741 (void) time(&now);
742 if (logging) {
743 syslog(LOG_INFO,
744 "User %s timed out after %d seconds at %s",
745 (pw ? pw -> pw_name : "unknown"), timeout, ctime(&now));
747 dologout(1);
751 yylex(void)
753 static int cpos, state;
754 register char *cp, *cp2;
755 register struct tab *p;
756 int n;
757 char c;
759 for (;;) {
760 switch (state) {
762 case CMD:
763 (void) signal(SIGALRM, toolong);
764 (void) alarm((unsigned) timeout);
765 if (get_line(cbuf, sizeof(cbuf)-1, stdin) == 0) {
766 reply(221, "You could at least say goodbye.");
767 dologout(0);
769 (void) alarm(0);
770 #ifdef SETPROCTITLE
771 if (strncasecmp(cbuf, "PASS", 4) != 0)
772 setproctitle("%s: %s", proctitle, cbuf);
773 #endif /* SETPROCTITLE */
774 if ((cp = strchr(cbuf, '\r'))) {
775 *cp++ = '\n';
776 *cp = '\0';
778 if ((cp = strpbrk(cbuf, " \n")))
779 cpos = (int) (cp - cbuf);
780 if (cpos == 0)
781 cpos = 4;
782 c = cbuf[cpos];
783 cbuf[cpos] = '\0';
784 upper(cbuf);
785 p = lookup(cmdtab, cbuf);
786 cbuf[cpos] = c;
787 if (p != 0) {
788 if (p->implemented == 0) {
789 nack(p->name);
790 longjmp(errcatch,0);
791 /* NOTREACHED */
793 state = p->state;
794 *(const char **)(&yylval) = p->name;
795 return (p->token);
797 break;
799 case SITECMD:
800 if (cbuf[cpos] == ' ') {
801 cpos++;
802 return (SP);
804 cp = &cbuf[cpos];
805 if ((cp2 = strpbrk(cp, " \n")))
806 cpos = (int) (cp2 - cbuf);
807 c = cbuf[cpos];
808 cbuf[cpos] = '\0';
809 upper(cp);
810 p = lookup(sitetab, cp);
811 cbuf[cpos] = c;
812 if (p != 0) {
813 if (p->implemented == 0) {
814 state = CMD;
815 nack(p->name);
816 longjmp(errcatch,0);
817 /* NOTREACHED */
819 state = p->state;
820 *(const char **)(&yylval) = p->name;
821 return (p->token);
823 state = CMD;
824 break;
826 case OSTR:
827 if (cbuf[cpos] == '\n') {
828 state = CMD;
829 return (CRLF);
831 /* FALLTHROUGH */
833 case STR1:
834 case ZSTR1:
835 dostr1:
836 if (cbuf[cpos] == ' ') {
837 cpos++;
838 if (state == OSTR)
839 state = STR2;
840 else
841 ++state;
842 return (SP);
844 break;
846 case ZSTR2:
847 if (cbuf[cpos] == '\n') {
848 state = CMD;
849 return (CRLF);
851 /* FALLTHROUGH */
853 case STR2:
854 cp = &cbuf[cpos];
855 n = (int) strlen(cp);
856 cpos += n - 1;
858 * Make sure the string is nonempty and \n terminated.
860 if (n > 1 && cbuf[cpos] == '\n') {
861 cbuf[cpos] = '\0';
862 *(char **)&yylval = copy(cp);
863 cbuf[cpos] = '\n';
864 state = ARGS;
865 return (STRING);
867 break;
869 case NSTR:
870 if (cbuf[cpos] == ' ') {
871 cpos++;
872 return (SP);
874 if (isdigit(cbuf[cpos])) {
875 cp = &cbuf[cpos];
876 while (isdigit(cbuf[++cpos]))
878 c = cbuf[cpos];
879 cbuf[cpos] = '\0';
880 yylval.ival = atoi(cp);
881 cbuf[cpos] = c;
882 state = STR1;
883 return (NUMBER);
885 state = STR1;
886 goto dostr1;
888 case ARGS:
889 if (isdigit(cbuf[cpos])) {
890 cp = &cbuf[cpos];
891 while (isdigit(cbuf[++cpos]))
893 c = cbuf[cpos];
894 cbuf[cpos] = '\0';
895 yylval.ival = atoi(cp);
896 cbuf[cpos] = c;
897 return (NUMBER);
899 switch (cbuf[cpos++]) {
901 case '\n':
902 state = CMD;
903 return (CRLF);
905 case ' ':
906 return (SP);
908 case ',':
909 return (COMMA);
911 case 'A':
912 case 'a':
913 return (A);
915 case 'B':
916 case 'b':
917 return (B);
919 case 'C':
920 case 'c':
921 return (C);
923 case 'E':
924 case 'e':
925 return (E);
927 case 'F':
928 case 'f':
929 return (F);
931 case 'I':
932 case 'i':
933 return (I);
935 case 'L':
936 case 'l':
937 return (L);
939 case 'N':
940 case 'n':
941 return (N);
943 case 'P':
944 case 'p':
945 return (P);
947 case 'R':
948 case 'r':
949 return (R);
951 case 'S':
952 case 's':
953 return (S);
955 case 'T':
956 case 't':
957 return (T);
960 break;
962 default:
963 fatal("Unknown state in scanner.");
965 yyerror((char *) 0);
966 state = CMD;
967 longjmp(errcatch,0);
971 static void
972 upper(char *s)
974 while (*s != '\0') {
975 if (islower(*s))
976 *s = toupper(*s);
977 s++;
981 static char *
982 copy(const char *s)
984 char *p;
986 p = (char * )malloc(strlen(s) + 1);
987 if (p == 0)
988 fatal("Ran out of memory.");
989 else
990 (void) strcpy(p, s);
991 return (p);
994 static void
995 help(struct tab *ctab, char *s)
997 register struct tab *c;
998 register int width, NCMDS;
999 const char *help_type;
1001 if (ctab == sitetab)
1002 help_type = "SITE ";
1003 else
1004 help_type = "";
1005 width = 0, NCMDS = 0;
1006 for (c = ctab; c->name != 0; c++) {
1007 int len = (int) strlen(c->name);
1009 if (len > width)
1010 width = len;
1011 NCMDS++;
1013 width = (width + 8) &~ 7;
1014 if (s == 0) {
1015 register int i, j, w;
1016 int columns, lines;
1018 lreply(214, "The following %scommands are recognized %s.",
1019 help_type, "(* =>'s unimplemented)");
1020 columns = 76 / width;
1021 if (columns == 0)
1022 columns = 1;
1023 lines = (NCMDS + columns - 1) / columns;
1024 for (i = 0; i < lines; i++) {
1025 printf(" ");
1026 for (j = 0; j < columns; j++) {
1027 c = ctab + j * lines + i;
1028 assert(c->name != 0);
1029 printf("%s%c", c->name,
1030 c->implemented ? ' ' : '*');
1031 if (c + lines >= &ctab[NCMDS])
1032 break;
1033 w = (int) strlen(c->name) + 1;
1034 while (w < width) {
1035 putchar(' ');
1036 w++;
1039 printf("\r\n");
1041 (void) fflush(stdout);
1042 reply(214, "Direct comments to ftp-bugs@%s.", hostname);
1043 return;
1045 upper(s);
1046 c = lookup(ctab, s);
1047 if (c == (struct tab *)0) {
1048 reply(502, "Unknown command %s.", s);
1049 return;
1051 if (c->implemented)
1052 reply(214, "Syntax: %s%s %s", help_type, c->name, c->help);
1053 else
1054 reply(214, "%s%-*s\t%s; unimplemented.", help_type, width,
1055 c->name, c->help);
1058 static void
1059 sizecmd(char *filename)
1061 switch (type) {
1062 case TYPE_L:
1063 case TYPE_I: {
1064 struct stat stbuf;
1065 if (stat(filename, &stbuf) < 0 ||
1066 (stbuf.st_mode&S_IFMT) != S_IFREG)
1067 reply(550, "%s: not a plain file.", filename);
1068 else
1069 #ifdef HAVE_LONG_LONG
1070 reply(213, "%llu", (long long) stbuf.st_size);
1071 #else
1072 reply(213, "%lu", stbuf.st_size);
1073 #endif
1074 break;}
1075 case TYPE_A: {
1076 FILE *fin;
1077 register int c, count;
1078 struct stat stbuf;
1079 fin = fopen(filename, "r");
1080 if (fin == 0) {
1081 perror_reply(550, filename);
1082 return;
1084 if (fstat(fileno(fin), &stbuf) < 0 ||
1085 (stbuf.st_mode&S_IFMT) != S_IFREG) {
1086 reply(550, "%s: not a plain file.", filename);
1087 (void) fclose(fin);
1088 return;
1091 count = 0;
1092 while((c=getc(fin)) != EOF) {
1093 if (c == '\n') /* will get expanded to \r\n */
1094 count++;
1095 count++;
1097 (void) fclose(fin);
1099 reply(213, "%ld", count);
1100 break;}
1101 default:
1102 reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]);
1105 #line 1103 "ftp.tab.c"
1107 #if YYDEBUG
1108 #include <stdio.h> /* needed for printf */
1109 #endif
1111 #include <stdlib.h> /* needed for malloc, etc */
1112 #include <string.h> /* needed for memset */
1114 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
1115 static int yygrowstack(YYSTACKDATA *data)
1117 int i;
1118 unsigned newsize;
1119 short *newss;
1120 YYSTYPE *newvs;
1122 if ((newsize = data->stacksize) == 0)
1123 newsize = YYINITSTACKSIZE;
1124 else if (newsize >= YYMAXDEPTH)
1125 return -1;
1126 else if ((newsize *= 2) > YYMAXDEPTH)
1127 newsize = YYMAXDEPTH;
1129 i = (int) (data->s_mark - data->s_base);
1130 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
1131 if (newss == 0)
1132 return -1;
1134 data->s_base = newss;
1135 data->s_mark = newss + i;
1137 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
1138 if (newvs == 0)
1139 return -1;
1141 data->l_base = newvs;
1142 data->l_mark = newvs + i;
1144 data->stacksize = newsize;
1145 data->s_last = data->s_base + newsize - 1;
1146 return 0;
1149 #if YYPURE || defined(YY_NO_LEAKS)
1150 static void yyfreestack(YYSTACKDATA *data)
1152 free(data->s_base);
1153 free(data->l_base);
1154 memset(data, 0, sizeof(*data));
1156 #else
1157 #define yyfreestack(data) /* nothing */
1158 #endif
1160 #define YYABORT goto yyabort
1161 #define YYREJECT goto yyabort
1162 #define YYACCEPT goto yyaccept
1163 #define YYERROR goto yyerrlab
1166 YYPARSE_DECL()
1168 int yym, yyn, yystate;
1169 #if YYDEBUG
1170 const char *yys;
1172 if ((yys = getenv("YYDEBUG")) != 0)
1174 yyn = *yys;
1175 if (yyn >= '0' && yyn <= '9')
1176 yydebug = yyn - '0';
1178 #endif
1180 yynerrs = 0;
1181 yyerrflag = 0;
1182 yychar = YYEMPTY;
1183 yystate = 0;
1185 #if YYPURE
1186 memset(&yystack, 0, sizeof(yystack));
1187 #endif
1189 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
1190 yystack.s_mark = yystack.s_base;
1191 yystack.l_mark = yystack.l_base;
1192 yystate = 0;
1193 *yystack.s_mark = 0;
1195 yyloop:
1196 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
1197 if (yychar < 0)
1199 if ((yychar = YYLEX) < 0) yychar = 0;
1200 #if YYDEBUG
1201 if (yydebug)
1203 yys = 0;
1204 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1205 if (!yys) yys = "illegal-symbol";
1206 printf("%sdebug: state %d, reading %d (%s)\n",
1207 YYPREFIX, yystate, yychar, yys);
1209 #endif
1211 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
1212 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1214 #if YYDEBUG
1215 if (yydebug)
1216 printf("%sdebug: state %d, shifting to state %d\n",
1217 YYPREFIX, yystate, yytable[yyn]);
1218 #endif
1219 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
1221 goto yyoverflow;
1223 yystate = yytable[yyn];
1224 *++yystack.s_mark = yytable[yyn];
1225 *++yystack.l_mark = yylval;
1226 yychar = YYEMPTY;
1227 if (yyerrflag > 0) --yyerrflag;
1228 goto yyloop;
1230 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
1231 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1233 yyn = yytable[yyn];
1234 goto yyreduce;
1236 if (yyerrflag) goto yyinrecovery;
1238 yyerror("syntax error");
1240 goto yyerrlab;
1242 yyerrlab:
1243 ++yynerrs;
1245 yyinrecovery:
1246 if (yyerrflag < 3)
1248 yyerrflag = 3;
1249 for (;;)
1251 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
1252 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
1254 #if YYDEBUG
1255 if (yydebug)
1256 printf("%sdebug: state %d, error recovery shifting\
1257 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
1258 #endif
1259 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
1261 goto yyoverflow;
1263 yystate = yytable[yyn];
1264 *++yystack.s_mark = yytable[yyn];
1265 *++yystack.l_mark = yylval;
1266 goto yyloop;
1268 else
1270 #if YYDEBUG
1271 if (yydebug)
1272 printf("%sdebug: error recovery discarding state %d\n",
1273 YYPREFIX, *yystack.s_mark);
1274 #endif
1275 if (yystack.s_mark <= yystack.s_base) goto yyabort;
1276 --yystack.s_mark;
1277 --yystack.l_mark;
1281 else
1283 if (yychar == 0) goto yyabort;
1284 #if YYDEBUG
1285 if (yydebug)
1287 yys = 0;
1288 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1289 if (!yys) yys = "illegal-symbol";
1290 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1291 YYPREFIX, yystate, yychar, yys);
1293 #endif
1294 yychar = YYEMPTY;
1295 goto yyloop;
1298 yyreduce:
1299 #if YYDEBUG
1300 if (yydebug)
1301 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1302 YYPREFIX, yystate, yyn, yyrule[yyn]);
1303 #endif
1304 yym = yylen[yyn];
1305 if (yym)
1306 yyval = yystack.l_mark[1-yym];
1307 else
1308 memset(&yyval, 0, sizeof yyval);
1309 switch (yyn)
1311 case 2:
1312 #line 172 "ftp.y"
1314 fromname = (char *) 0;
1316 break;
1317 case 4:
1318 #line 179 "ftp.y"
1320 user(yystack.l_mark[-1].sval);
1321 free(yystack.l_mark[-1].sval);
1323 break;
1324 case 5:
1325 #line 184 "ftp.y"
1327 pass(yystack.l_mark[-1].sval);
1328 free(yystack.l_mark[-1].sval);
1330 break;
1331 case 6:
1332 #line 189 "ftp.y"
1334 usedefault = 0;
1335 if (pdata >= 0) {
1336 (void) close(pdata);
1337 pdata = -1;
1339 reply(200, "PORT command successful.");
1341 break;
1342 case 7:
1343 #line 198 "ftp.y"
1345 passive();
1347 break;
1348 case 8:
1349 #line 202 "ftp.y"
1351 switch (cmd_type) {
1353 case TYPE_A:
1354 if (cmd_form == FORM_N) {
1355 reply(200, "Type set to A.");
1356 type = cmd_type;
1357 form = cmd_form;
1358 } else
1359 reply(504, "Form must be N.");
1360 break;
1362 case TYPE_E:
1363 reply(504, "Type E not implemented.");
1364 break;
1366 case TYPE_I:
1367 reply(200, "Type set to I.");
1368 type = cmd_type;
1369 break;
1371 case TYPE_L:
1372 #if NBBY == 8
1373 if (cmd_bytesz == 8) {
1374 reply(200,
1375 "Type set to L (byte size 8).");
1376 type = cmd_type;
1377 } else
1378 reply(504, "Byte size must be 8.");
1379 #else /* NBBY == 8 */
1380 UNIMPLEMENTED for NBBY != 8
1381 #endif /* NBBY == 8 */
1384 break;
1385 case 9:
1386 #line 237 "ftp.y"
1388 switch (yystack.l_mark[-1].ival) {
1390 case STRU_F:
1391 reply(200, "STRU F ok.");
1392 break;
1394 default:
1395 reply(504, "Unimplemented STRU type.");
1398 break;
1399 case 10:
1400 #line 249 "ftp.y"
1402 switch (yystack.l_mark[-1].ival) {
1404 case MODE_S:
1405 reply(200, "MODE S ok.");
1406 break;
1408 default:
1409 reply(502, "Unimplemented MODE type.");
1412 break;
1413 case 11:
1414 #line 261 "ftp.y"
1416 reply(202, "ALLO command ignored.");
1418 break;
1419 case 12:
1420 #line 265 "ftp.y"
1422 reply(202, "ALLO command ignored.");
1424 break;
1425 case 13:
1426 #line 269 "ftp.y"
1428 if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0)
1429 retrieve((char *) 0, yystack.l_mark[-1].sval);
1430 if (yystack.l_mark[-1].sval != 0)
1431 free(yystack.l_mark[-1].sval);
1433 break;
1434 case 14:
1435 #line 276 "ftp.y"
1437 if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0)
1438 store(yystack.l_mark[-1].sval, "w", 0);
1439 if (yystack.l_mark[-1].sval != 0)
1440 free(yystack.l_mark[-1].sval);
1442 break;
1443 case 15:
1444 #line 283 "ftp.y"
1446 if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0)
1447 store(yystack.l_mark[-1].sval, "a", 0);
1448 if (yystack.l_mark[-1].sval != 0)
1449 free(yystack.l_mark[-1].sval);
1451 break;
1452 case 16:
1453 #line 290 "ftp.y"
1455 if (yystack.l_mark[-1].ival)
1456 send_file_list(".");
1458 break;
1459 case 17:
1460 #line 295 "ftp.y"
1462 if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0)
1463 send_file_list((char *) yystack.l_mark[-1].sval);
1464 if (yystack.l_mark[-1].sval != 0)
1465 free((char *) yystack.l_mark[-1].sval);
1467 break;
1468 case 18:
1469 #line 302 "ftp.y"
1471 if (yystack.l_mark[-1].ival)
1472 retrieve("/bin/ls -lgA", "");
1474 break;
1475 case 19:
1476 #line 307 "ftp.y"
1478 if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0)
1479 retrieve("/bin/ls -lgA %s", yystack.l_mark[-1].sval);
1480 if (yystack.l_mark[-1].sval != 0)
1481 free(yystack.l_mark[-1].sval);
1483 break;
1484 case 20:
1485 #line 314 "ftp.y"
1487 if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0)
1488 statfilecmd(yystack.l_mark[-1].sval);
1489 if (yystack.l_mark[-1].sval != 0)
1490 free(yystack.l_mark[-1].sval);
1492 break;
1493 case 21:
1494 #line 321 "ftp.y"
1496 statcmd();
1498 break;
1499 case 22:
1500 #line 325 "ftp.y"
1502 if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0)
1503 remove((char *) yystack.l_mark[-1].sval);
1504 if (yystack.l_mark[-1].sval != 0)
1505 free((char *) yystack.l_mark[-1].sval);
1507 break;
1508 case 23:
1509 #line 332 "ftp.y"
1511 if (fromname) {
1512 renamecmd(fromname, (char *) yystack.l_mark[-1].sval);
1513 free(fromname);
1514 fromname = (char *) 0;
1515 } else {
1516 reply(503, "Bad sequence of commands.");
1518 free((char *) yystack.l_mark[-1].sval);
1520 break;
1521 case 24:
1522 #line 343 "ftp.y"
1524 reply(225, "ABOR command successful.");
1526 break;
1527 case 25:
1528 #line 347 "ftp.y"
1530 if (yystack.l_mark[-1].ival)
1531 cwd(pw->pw_dir);
1533 break;
1534 case 26:
1535 #line 352 "ftp.y"
1537 if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0)
1538 cwd((char *) yystack.l_mark[-1].sval);
1539 if (yystack.l_mark[-1].sval != 0)
1540 free((char *) yystack.l_mark[-1].sval);
1542 break;
1543 case 27:
1544 #line 359 "ftp.y"
1546 help(cmdtab, (char *) 0);
1548 break;
1549 case 28:
1550 #line 363 "ftp.y"
1552 register char *cp = (char *)yystack.l_mark[-1].sval;
1554 if (strncasecmp(cp, "SITE", 4) == 0) {
1555 cp = (char *)yystack.l_mark[-1].sval + 4;
1556 if (*cp == ' ')
1557 cp++;
1558 if (*cp)
1559 help(sitetab, cp);
1560 else
1561 help(sitetab, (char *) 0);
1562 } else
1563 help(cmdtab, (char *) yystack.l_mark[-1].sval);
1565 break;
1566 case 29:
1567 #line 378 "ftp.y"
1569 reply(200, "NOOP command successful.");
1571 break;
1572 case 30:
1573 #line 382 "ftp.y"
1575 if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0)
1576 makedir((char *) yystack.l_mark[-1].sval);
1577 if (yystack.l_mark[-1].sval != 0)
1578 free((char *) yystack.l_mark[-1].sval);
1580 break;
1581 case 31:
1582 #line 389 "ftp.y"
1584 if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0)
1585 removedir((char *) yystack.l_mark[-1].sval);
1586 if (yystack.l_mark[-1].sval != 0)
1587 free((char *) yystack.l_mark[-1].sval);
1589 break;
1590 case 32:
1591 #line 396 "ftp.y"
1593 if (yystack.l_mark[-1].ival)
1594 pwd();
1596 break;
1597 case 33:
1598 #line 401 "ftp.y"
1600 if (yystack.l_mark[-1].ival)
1601 cwd("..");
1603 break;
1604 case 34:
1605 #line 406 "ftp.y"
1607 help(sitetab, (char *) 0);
1609 break;
1610 case 35:
1611 #line 410 "ftp.y"
1613 help(sitetab, (char *) yystack.l_mark[-1].sval);
1615 break;
1616 case 36:
1617 #line 414 "ftp.y"
1619 int oldmask;
1621 if (yystack.l_mark[-1].ival) {
1622 oldmask = umask(0);
1623 (void) umask(oldmask);
1624 reply(200, "Current UMASK is %03o", oldmask);
1627 break;
1628 case 37:
1629 #line 424 "ftp.y"
1631 int oldmask;
1633 if (yystack.l_mark[-3].ival) {
1634 if ((yystack.l_mark[-1].ival == -1) || (yystack.l_mark[-1].ival > 0777)) {
1635 reply(501, "Bad UMASK value");
1636 } else {
1637 oldmask = umask(yystack.l_mark[-1].ival);
1638 reply(200,
1639 "UMASK set to %03o (was %03o)",
1640 yystack.l_mark[-1].ival, oldmask);
1644 break;
1645 case 38:
1646 #line 439 "ftp.y"
1648 if (yystack.l_mark[-5].ival && (yystack.l_mark[-1].sval != 0)) {
1649 if (yystack.l_mark[-3].ival > 0777)
1650 reply(501,
1651 "CHMOD: Mode value must be between 0 and 0777");
1652 else if (chmod((char *) yystack.l_mark[-1].sval, yystack.l_mark[-3].ival) < 0)
1653 perror_reply(550, (char *) yystack.l_mark[-1].sval);
1654 else
1655 reply(200, "CHMOD command successful.");
1657 if (yystack.l_mark[-1].sval != 0)
1658 free((char *) yystack.l_mark[-1].sval);
1660 break;
1661 case 39:
1662 #line 453 "ftp.y"
1664 reply(200,
1665 "Current IDLE time limit is %d seconds; max %d",
1666 timeout, maxtimeout);
1668 break;
1669 case 40:
1670 #line 459 "ftp.y"
1672 if (yystack.l_mark[-1].ival < 30 || yystack.l_mark[-1].ival > maxtimeout) {
1673 reply(501,
1674 "Maximum IDLE time must be between 30 and %d seconds",
1675 maxtimeout);
1676 } else {
1677 timeout = yystack.l_mark[-1].ival;
1678 (void) alarm((unsigned) timeout);
1679 reply(200,
1680 "Maximum IDLE time set to %d seconds",
1681 timeout);
1684 break;
1685 case 41:
1686 #line 473 "ftp.y"
1688 if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0)
1689 store((char *) yystack.l_mark[-1].sval, "w", 1);
1690 if (yystack.l_mark[-1].sval != 0)
1691 free((char *) yystack.l_mark[-1].sval);
1693 break;
1694 case 42:
1695 #line 480 "ftp.y"
1697 #ifdef unix
1698 #ifdef BSD
1699 reply(215, "UNIX Type: L%d Version: BSD-%d",
1700 NBBY, BSD);
1701 #else /* BSD */
1702 reply(215, "UNIX Type: L%d", NBBY);
1703 #endif /* BSD */
1704 #else /* unix */
1705 reply(215, "UNKNOWN Type: L%d", NBBY);
1706 #endif /* unix */
1708 break;
1709 case 43:
1710 #line 501 "ftp.y"
1712 if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0)
1713 sizecmd((char *) yystack.l_mark[-1].sval);
1714 if (yystack.l_mark[-1].sval != 0)
1715 free((char *) yystack.l_mark[-1].sval);
1717 break;
1718 case 44:
1719 #line 518 "ftp.y"
1721 if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0) {
1722 struct stat stbuf;
1723 if (stat((char *) yystack.l_mark[-1].sval, &stbuf) < 0)
1724 perror_reply(550, "%s", (char *) yystack.l_mark[-1].sval);
1725 else if ((stbuf.st_mode&S_IFMT) != S_IFREG) {
1726 reply(550, "%s: not a plain file.",
1727 (char *) yystack.l_mark[-1].sval);
1728 } else {
1729 register struct tm *t;
1730 t = gmtime(&stbuf.st_mtime);
1731 reply(213,
1732 "%04d%02d%02d%02d%02d%02d",
1733 1900 + t->tm_year,
1734 t->tm_mon+1, t->tm_mday,
1735 t->tm_hour, t->tm_min, t->tm_sec);
1738 if (yystack.l_mark[-1].sval != 0)
1739 free((char *) yystack.l_mark[-1].sval);
1741 break;
1742 case 45:
1743 #line 540 "ftp.y"
1745 reply(221, "Goodbye.");
1746 dologout(0);
1748 break;
1749 case 46:
1750 #line 545 "ftp.y"
1752 yyerrok;
1754 break;
1755 case 47:
1756 #line 550 "ftp.y"
1758 if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval) {
1759 fromname = renamefrom((char *) yystack.l_mark[-1].sval);
1760 if (fromname == (char *) 0 && yystack.l_mark[-1].sval) {
1761 free((char *) yystack.l_mark[-1].sval);
1765 break;
1766 case 49:
1767 #line 564 "ftp.y"
1769 *(const char **)(&(yyval.sval)) = "";
1771 break;
1772 case 52:
1773 #line 575 "ftp.y"
1775 register char *a, *p;
1777 a = (char *)&data_dest.sin_addr;
1778 a[0] = (char) yystack.l_mark[-10].ival;
1779 a[1] = (char) yystack.l_mark[-8].ival;
1780 a[2] = (char) yystack.l_mark[-6].ival;
1781 a[3] = (char) yystack.l_mark[-4].ival;
1782 p = (char *)&data_dest.sin_port;
1783 p[0] = (char) yystack.l_mark[-2].ival;
1784 p[1] = (char) yystack.l_mark[0].ival;
1785 data_dest.sin_family = AF_INET;
1787 break;
1788 case 53:
1789 #line 591 "ftp.y"
1791 yyval.ival = FORM_N;
1793 break;
1794 case 54:
1795 #line 595 "ftp.y"
1797 yyval.ival = FORM_T;
1799 break;
1800 case 55:
1801 #line 599 "ftp.y"
1803 yyval.ival = FORM_C;
1805 break;
1806 case 56:
1807 #line 605 "ftp.y"
1809 cmd_type = TYPE_A;
1810 cmd_form = FORM_N;
1812 break;
1813 case 57:
1814 #line 610 "ftp.y"
1816 cmd_type = TYPE_A;
1817 cmd_form = yystack.l_mark[0].ival;
1819 break;
1820 case 58:
1821 #line 615 "ftp.y"
1823 cmd_type = TYPE_E;
1824 cmd_form = FORM_N;
1826 break;
1827 case 59:
1828 #line 620 "ftp.y"
1830 cmd_type = TYPE_E;
1831 cmd_form = yystack.l_mark[0].ival;
1833 break;
1834 case 60:
1835 #line 625 "ftp.y"
1837 cmd_type = TYPE_I;
1839 break;
1840 case 61:
1841 #line 629 "ftp.y"
1843 cmd_type = TYPE_L;
1844 cmd_bytesz = NBBY;
1846 break;
1847 case 62:
1848 #line 634 "ftp.y"
1850 cmd_type = TYPE_L;
1851 cmd_bytesz = yystack.l_mark[0].ival;
1853 break;
1854 case 63:
1855 #line 640 "ftp.y"
1857 cmd_type = TYPE_L;
1858 cmd_bytesz = yystack.l_mark[0].ival;
1860 break;
1861 case 64:
1862 #line 647 "ftp.y"
1864 yyval.ival = STRU_F;
1866 break;
1867 case 65:
1868 #line 651 "ftp.y"
1870 yyval.ival = STRU_R;
1872 break;
1873 case 66:
1874 #line 655 "ftp.y"
1876 yyval.ival = STRU_P;
1878 break;
1879 case 67:
1880 #line 661 "ftp.y"
1882 yyval.ival = MODE_S;
1884 break;
1885 case 68:
1886 #line 665 "ftp.y"
1888 yyval.ival = MODE_B;
1890 break;
1891 case 69:
1892 #line 669 "ftp.y"
1894 yyval.ival = MODE_C;
1896 break;
1897 case 70:
1898 #line 675 "ftp.y"
1901 * Problem: this production is used for all pathname
1902 * processing, but only gives a 550 error reply.
1903 * This is a valid reply in some cases but not in others.
1905 if (logged_in && yystack.l_mark[0].sval && strncmp((char *) yystack.l_mark[0].sval, "~", 1) == 0) {
1906 *(char **)&(yyval.sval) = *glob((char *) yystack.l_mark[0].sval);
1907 if (globerr != 0) {
1908 reply(550, globerr);
1909 yyval.sval = 0;
1911 free((char *) yystack.l_mark[0].sval);
1912 } else
1913 yyval.sval = yystack.l_mark[0].sval;
1915 break;
1916 case 72:
1917 #line 697 "ftp.y"
1919 register int ret, dec, multby, digit;
1922 * Convert a number that was read as decimal number
1923 * to what it would be if it had been read as octal.
1925 dec = yystack.l_mark[0].ival;
1926 multby = 1;
1927 ret = 0;
1928 while (dec) {
1929 digit = dec%10;
1930 if (digit > 7) {
1931 ret = -1;
1932 break;
1934 ret += digit * multby;
1935 multby *= 8;
1936 dec /= 10;
1938 yyval.ival = ret;
1940 break;
1941 case 73:
1942 #line 722 "ftp.y"
1944 if (logged_in)
1945 yyval.ival = 1;
1946 else {
1947 reply(530, "Please login with USER and PASS.");
1948 yyval.ival = 0;
1951 break;
1952 #line 1950 "ftp.tab.c"
1954 yystack.s_mark -= yym;
1955 yystate = *yystack.s_mark;
1956 yystack.l_mark -= yym;
1957 yym = yylhs[yyn];
1958 if (yystate == 0 && yym == 0)
1960 #if YYDEBUG
1961 if (yydebug)
1962 printf("%sdebug: after reduction, shifting from state 0 to\
1963 state %d\n", YYPREFIX, YYFINAL);
1964 #endif
1965 yystate = YYFINAL;
1966 *++yystack.s_mark = YYFINAL;
1967 *++yystack.l_mark = yyval;
1968 if (yychar < 0)
1970 if ((yychar = YYLEX) < 0) yychar = 0;
1971 #if YYDEBUG
1972 if (yydebug)
1974 yys = 0;
1975 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1976 if (!yys) yys = "illegal-symbol";
1977 printf("%sdebug: state %d, reading %d (%s)\n",
1978 YYPREFIX, YYFINAL, yychar, yys);
1980 #endif
1982 if (yychar == 0) goto yyaccept;
1983 goto yyloop;
1985 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
1986 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
1987 yystate = yytable[yyn];
1988 else
1989 yystate = yydgoto[yym];
1990 #if YYDEBUG
1991 if (yydebug)
1992 printf("%sdebug: after reduction, shifting from state %d \
1993 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
1994 #endif
1995 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
1997 goto yyoverflow;
1999 *++yystack.s_mark = (short) yystate;
2000 *++yystack.l_mark = yyval;
2001 goto yyloop;
2003 yyoverflow:
2004 yyerror("yacc stack overflow");
2006 yyabort:
2007 yyfreestack(&yystack);
2008 return (1);
2010 yyaccept:
2011 yyfreestack(&yystack);
2012 return (0);