Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / byacc / dist / test / ftp.tab.c
blob23f43dd60e2bea7d230314a034421d2b36204b5e
1 /* $NetBSD$ */
2 #ifndef lint
3 /* static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; */
4 static char rcsid[] = "$NetBSD: ftp.tab.c,v 1.7 2001/01/04 23:05:57 lukem Exp $";
5 #endif
7 #include <stdlib.h>
8 #include <string.h>
10 #define YYBYACC 1
11 #define YYMAJOR 1
12 #define YYMINOR 9
14 #define YYEMPTY (-1)
15 #define yyclearin (yychar = YYEMPTY)
16 #define yyerrok (yyerrflag = 0)
17 #define YYRECOVERING() (yyerrflag != 0)
19 /* compatibility with bison */
20 #ifdef YYPARSE_PARAM
21 /* compatibility with FreeBSD */
22 #ifdef YYPARSE_PARAM_TYPE
23 #define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
24 #else
25 #define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
26 #endif
27 #else
28 #define YYPARSE_DECL() yyparse(void)
29 #endif /* YYPARSE_PARAM */
31 extern int YYPARSE_DECL();
33 static int yygrowstack(void);
34 #define yyparse ftp_parse
35 #define yylex ftp_lex
36 #define yyerror ftp_error
37 #define yychar ftp_char
38 #define yyval ftp_val
39 #define yylval ftp_lval
40 #define yydebug ftp_debug
41 #define yynerrs ftp_nerrs
42 #define yyerrflag ftp_errflag
43 #define yyss ftp_ss
44 #define yyssp ftp_ssp
45 #define yyvs ftp_vs
46 #define yyvsp ftp_vsp
47 #define yylhs ftp_lhs
48 #define yylen ftp_len
49 #define yydefred ftp_defred
50 #define yydgoto ftp_dgoto
51 #define yysindex ftp_sindex
52 #define yyrindex ftp_rindex
53 #define yygindex ftp_gindex
54 #define yytable ftp_table
55 #define yycheck ftp_check
56 #define yyname ftp_name
57 #define yyrule ftp_rule
58 #define YYPREFIX "ftp_"
59 #line 26 "ftp.y"
61 #ifndef lint
62 static char sccsid[] = "@(#)ftpcmd.y 5.20.1.1 (Berkeley) 3/2/89";
63 #endif /* not lint */
65 #include <sys/param.h>
66 #include <sys/socket.h>
68 #include <netinet/in.h>
70 #include <arpa/ftp.h>
72 #include <stdio.h>
73 #include <signal.h>
74 #include <ctype.h>
75 #include <pwd.h>
76 #include <setjmp.h>
77 #include <syslog.h>
78 #include <sys/stat.h>
79 #include <time.h>
81 extern struct sockaddr_in data_dest;
82 extern int logged_in;
83 extern struct passwd *pw;
84 extern int guest;
85 extern int logging;
86 extern int type;
87 extern int form;
88 extern int debug;
89 extern int timeout;
90 extern int maxtimeout;
91 extern int pdata;
92 extern char hostname[], remotehost[];
93 extern char proctitle[];
94 extern char *globerr;
95 extern int usedefault;
96 extern int transflag;
97 extern char tmpline[];
98 char **glob();
100 static int cmd_type;
101 static int cmd_form;
102 static int cmd_bytesz;
103 char cbuf[512];
104 char *fromname;
106 char *index();
107 #line 106 "ftp.tab.c"
108 #define A 257
109 #define B 258
110 #define C 259
111 #define E 260
112 #define F 261
113 #define I 262
114 #define L 263
115 #define N 264
116 #define P 265
117 #define R 266
118 #define S 267
119 #define T 268
120 #define SP 269
121 #define CRLF 270
122 #define COMMA 271
123 #define STRING 272
124 #define NUMBER 273
125 #define USER 274
126 #define PASS 275
127 #define ACCT 276
128 #define REIN 277
129 #define QUIT 278
130 #define PORT 279
131 #define PASV 280
132 #define TYPE 281
133 #define STRU 282
134 #define MODE 283
135 #define RETR 284
136 #define STOR 285
137 #define APPE 286
138 #define MLFL 287
139 #define MAIL 288
140 #define MSND 289
141 #define MSOM 290
142 #define MSAM 291
143 #define MRSQ 292
144 #define MRCP 293
145 #define ALLO 294
146 #define REST 295
147 #define RNFR 296
148 #define RNTO 297
149 #define ABOR 298
150 #define DELE 299
151 #define CWD 300
152 #define LIST 301
153 #define NLST 302
154 #define SITE 303
155 #define STAT 304
156 #define HELP 305
157 #define NOOP 306
158 #define MKD 307
159 #define RMD 308
160 #define PWD 309
161 #define CDUP 310
162 #define STOU 311
163 #define SMNT 312
164 #define SYST 313
165 #define SIZE 314
166 #define MDTM 315
167 #define UMASK 316
168 #define IDLE 317
169 #define CHMOD 318
170 #define LEXERR 319
171 #define YYERRCODE 256
172 static const short ftp_lhs[] = { -1,
173 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
174 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
175 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
176 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
177 1, 1, 1, 1, 1, 1, 2, 3, 4, 4,
178 12, 5, 13, 13, 13, 6, 6, 6, 6, 6,
179 6, 6, 6, 7, 7, 7, 8, 8, 8, 10,
180 14, 11, 9,
182 static const short ftp_len[] = { 2,
183 0, 2, 2, 4, 4, 4, 2, 4, 4, 4,
184 4, 8, 5, 5, 5, 3, 5, 3, 5, 5,
185 2, 5, 4, 2, 3, 5, 2, 4, 2, 5,
186 5, 3, 3, 4, 6, 5, 7, 9, 4, 6,
187 5, 2, 5, 5, 2, 2, 5, 1, 0, 1,
188 1, 11, 1, 1, 1, 1, 3, 1, 3, 1,
189 1, 3, 2, 1, 1, 1, 1, 1, 1, 1,
190 1, 1, 0,
192 static const short ftp_defred[] = { 1,
193 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
194 73, 73, 73, 0, 73, 0, 0, 73, 73, 73,
195 73, 0, 0, 0, 0, 73, 73, 73, 73, 73,
196 0, 73, 73, 2, 3, 46, 0, 0, 45, 0,
197 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
198 24, 0, 0, 0, 0, 0, 21, 0, 0, 27,
199 29, 0, 0, 0, 0, 0, 42, 0, 0, 48,
200 0, 50, 0, 0, 0, 0, 0, 60, 0, 0,
201 64, 66, 65, 0, 68, 69, 67, 0, 0, 0,
202 0, 0, 0, 71, 0, 70, 0, 0, 25, 0,
203 18, 0, 16, 0, 73, 0, 73, 0, 0, 0,
204 0, 32, 33, 0, 0, 0, 4, 5, 0, 6,
205 0, 0, 0, 51, 63, 8, 9, 10, 0, 0,
206 0, 0, 11, 0, 23, 0, 0, 0, 0, 0,
207 34, 0, 0, 39, 0, 0, 28, 0, 0, 0,
208 0, 0, 0, 55, 53, 54, 57, 59, 62, 13,
209 14, 15, 0, 47, 22, 26, 19, 17, 0, 0,
210 36, 0, 0, 20, 30, 31, 41, 43, 44, 0,
211 0, 35, 72, 0, 40, 0, 0, 0, 37, 0,
212 0, 12, 0, 0, 38, 0, 0, 0, 52,
214 static const short ftp_dgoto[] = { 1,
215 34, 35, 71, 73, 75, 80, 84, 88, 45, 95,
216 184, 125, 157, 96,
218 static const short ftp_sindex[] = { 0,
219 -224, -247, -239, -236, -232, -222, -204, -200, -181, -177,
220 0, 0, 0, -166, 0, -161, -199, 0, 0, 0,
221 0, -160, -159, -264, -158, 0, 0, 0, 0, 0,
222 -157, 0, 0, 0, 0, 0, -167, -162, 0, -156,
223 0, -250, -198, -165, -155, -154, -153, -151, -150, -152,
224 0, -145, -252, -229, -217, -302, 0, -144, -146, 0,
225 0, -142, -141, -140, -139, -137, 0, -136, -135, 0,
226 -134, 0, -133, -132, -130, -131, -128, 0, -249, -127,
227 0, 0, 0, -126, 0, 0, 0, -125, -152, -152,
228 -152, -205, -152, 0, -124, 0, -152, -152, 0, -152,
229 0, -143, 0, -173, 0, -171, 0, -152, -123, -152,
230 -152, 0, 0, -152, -152, -152, 0, 0, -138, 0,
231 -164, -164, -122, 0, 0, 0, 0, 0, -121, -120,
232 -118, -148, 0, -117, 0, -116, -115, -114, -113, -112,
233 0, -163, -111, 0, -110, -109, 0, -107, -106, -105,
234 -104, -103, -129, 0, 0, 0, 0, 0, 0, 0,
235 0, 0, -101, 0, 0, 0, 0, 0, -100, -102,
236 0, -98, -102, 0, 0, 0, 0, 0, 0, -99,
237 -97, 0, 0, -95, 0, -96, -94, -92, 0, -152,
238 -93, 0, -91, -90, 0, -88, -87, -86, 0,
240 static const short ftp_rindex[] = { 0,
241 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
242 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
243 0, 0, -83, 0, 0, 0, 0, 0, 0, 0,
244 0, 0, 0, 0, 0, 0, 0, -82, 0, 0,
245 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
246 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
247 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
248 0, 0, 0, 0, 0, -81, -80, 0, -158, 0,
249 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
250 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
251 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
252 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
253 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
254 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
255 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
256 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
257 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
258 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
259 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
260 0, 0, 0, 0, 0, 0, 0, 0, 0,
262 static const short ftp_gindex[] = { 0,
263 0, 0, 0, 0, 0, 0, 0, 0, 16, -89,
264 -25, 35, 47, 0,
266 #define YYTABLESIZE 190
267 static const short ftp_table[] = { 129,
268 130, 131, 104, 134, 59, 60, 76, 136, 137, 77,
269 138, 78, 79, 105, 106, 107, 98, 99, 146, 123,
270 148, 149, 36, 124, 150, 151, 152, 46, 47, 37,
271 49, 2, 38, 52, 53, 54, 55, 39, 58, 100,
272 101, 62, 63, 64, 65, 66, 40, 68, 69, 3,
273 4, 102, 103, 5, 6, 7, 8, 9, 10, 11,
274 12, 13, 81, 132, 133, 41, 82, 83, 42, 14,
275 51, 15, 16, 17, 18, 19, 20, 21, 22, 23,
276 24, 25, 26, 27, 28, 29, 30, 43, 31, 32,
277 33, 44, 85, 86, 154, 140, 141, 143, 144, 155,
278 193, 87, 48, 156, 70, 170, 171, 50, 56, 72,
279 57, 61, 67, 89, 90, 91, 74, 163, 93, 94,
280 142, 92, 145, 97, 108, 109, 110, 111, 139, 112,
281 113, 114, 115, 116, 153, 117, 118, 121, 119, 120,
282 122, 180, 126, 127, 128, 135, 147, 186, 160, 161,
283 124, 162, 164, 165, 166, 167, 168, 159, 173, 169,
284 174, 172, 175, 176, 177, 178, 179, 181, 158, 182,
285 183, 185, 190, 187, 189, 188, 191, 192, 195, 194,
286 196, 0, 0, 198, 197, 73, 199, 49, 56, 58,
288 static const short ftp_check[] = { 89,
289 90, 91, 305, 93, 269, 270, 257, 97, 98, 260,
290 100, 262, 263, 316, 317, 318, 269, 270, 108, 269,
291 110, 111, 270, 273, 114, 115, 116, 12, 13, 269,
292 15, 256, 269, 18, 19, 20, 21, 270, 23, 269,
293 270, 26, 27, 28, 29, 30, 269, 32, 33, 274,
294 275, 269, 270, 278, 279, 280, 281, 282, 283, 284,
295 285, 286, 261, 269, 270, 270, 265, 266, 269, 294,
296 270, 296, 297, 298, 299, 300, 301, 302, 303, 304,
297 305, 306, 307, 308, 309, 310, 311, 269, 313, 314,
298 315, 269, 258, 259, 259, 269, 270, 269, 270, 264,
299 190, 267, 269, 268, 272, 269, 270, 269, 269, 272,
300 270, 270, 270, 269, 269, 269, 273, 266, 269, 272,
301 105, 273, 107, 269, 269, 272, 269, 269, 272, 270,
302 270, 269, 269, 269, 273, 270, 270, 269, 271, 270,
303 269, 271, 270, 270, 270, 270, 270, 173, 270, 270,
304 273, 270, 270, 270, 270, 270, 270, 123, 269, 272,
305 270, 273, 270, 270, 270, 270, 270, 269, 122, 270,
306 273, 270, 269, 273, 270, 273, 271, 270, 270, 273,
307 271, -1, -1, 271, 273, 269, 273, 270, 270, 270,
309 #define YYFINAL 1
310 #ifndef YYDEBUG
311 #define YYDEBUG 0
312 #endif
313 #define YYMAXTOKEN 319
314 #if YYDEBUG
315 static const char *ftp_name[] = {
317 "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,
318 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,
319 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,
320 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,
321 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,
322 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,
323 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",
324 "P","R","S","T","SP","CRLF","COMMA","STRING","NUMBER","USER","PASS","ACCT",
325 "REIN","QUIT","PORT","PASV","TYPE","STRU","MODE","RETR","STOR","APPE","MLFL",
326 "MAIL","MSND","MSOM","MSAM","MRSQ","MRCP","ALLO","REST","RNFR","RNTO","ABOR",
327 "DELE","CWD","LIST","NLST","SITE","STAT","HELP","NOOP","MKD","RMD","PWD","CDUP",
328 "STOU","SMNT","SYST","SIZE","MDTM","UMASK","IDLE","CHMOD","LEXERR",
330 static const char *ftp_rule[] = {
331 "$accept : cmd_list",
332 "cmd_list :",
333 "cmd_list : cmd_list cmd",
334 "cmd_list : cmd_list rcmd",
335 "cmd : USER SP username CRLF",
336 "cmd : PASS SP password CRLF",
337 "cmd : PORT SP host_port CRLF",
338 "cmd : PASV CRLF",
339 "cmd : TYPE SP type_code CRLF",
340 "cmd : STRU SP struct_code CRLF",
341 "cmd : MODE SP mode_code CRLF",
342 "cmd : ALLO SP NUMBER CRLF",
343 "cmd : ALLO SP NUMBER SP R SP NUMBER CRLF",
344 "cmd : RETR check_login SP pathname CRLF",
345 "cmd : STOR check_login SP pathname CRLF",
346 "cmd : APPE check_login SP pathname CRLF",
347 "cmd : NLST check_login CRLF",
348 "cmd : NLST check_login SP STRING CRLF",
349 "cmd : LIST check_login CRLF",
350 "cmd : LIST check_login SP pathname CRLF",
351 "cmd : STAT check_login SP pathname CRLF",
352 "cmd : STAT CRLF",
353 "cmd : DELE check_login SP pathname CRLF",
354 "cmd : RNTO SP pathname CRLF",
355 "cmd : ABOR CRLF",
356 "cmd : CWD check_login CRLF",
357 "cmd : CWD check_login SP pathname CRLF",
358 "cmd : HELP CRLF",
359 "cmd : HELP SP STRING CRLF",
360 "cmd : NOOP CRLF",
361 "cmd : MKD check_login SP pathname CRLF",
362 "cmd : RMD check_login SP pathname CRLF",
363 "cmd : PWD check_login CRLF",
364 "cmd : CDUP check_login CRLF",
365 "cmd : SITE SP HELP CRLF",
366 "cmd : SITE SP HELP SP STRING CRLF",
367 "cmd : SITE SP UMASK check_login CRLF",
368 "cmd : SITE SP UMASK check_login SP octal_number CRLF",
369 "cmd : SITE SP CHMOD check_login SP octal_number SP pathname CRLF",
370 "cmd : SITE SP IDLE CRLF",
371 "cmd : SITE SP IDLE SP NUMBER CRLF",
372 "cmd : STOU check_login SP pathname CRLF",
373 "cmd : SYST CRLF",
374 "cmd : SIZE check_login SP pathname CRLF",
375 "cmd : MDTM check_login SP pathname CRLF",
376 "cmd : QUIT CRLF",
377 "cmd : error CRLF",
378 "rcmd : RNFR check_login SP pathname CRLF",
379 "username : STRING",
380 "password :",
381 "password : STRING",
382 "byte_size : NUMBER",
383 "host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER",
384 "form_code : N",
385 "form_code : T",
386 "form_code : C",
387 "type_code : A",
388 "type_code : A SP form_code",
389 "type_code : E",
390 "type_code : E SP form_code",
391 "type_code : I",
392 "type_code : L",
393 "type_code : L SP byte_size",
394 "type_code : L byte_size",
395 "struct_code : F",
396 "struct_code : R",
397 "struct_code : P",
398 "mode_code : S",
399 "mode_code : B",
400 "mode_code : C",
401 "pathname : pathstring",
402 "pathstring : STRING",
403 "octal_number : NUMBER",
404 "check_login :",
407 #endif
408 #ifndef YYSTYPE
409 typedef int YYSTYPE;
410 #endif
411 #if YYDEBUG
412 #include <stdio.h>
413 #endif
415 /* define the initial stack-sizes */
416 #ifdef YYSTACKSIZE
417 #undef YYMAXDEPTH
418 #define YYMAXDEPTH YYSTACKSIZE
419 #else
420 #ifdef YYMAXDEPTH
421 #define YYSTACKSIZE YYMAXDEPTH
422 #else
423 #define YYSTACKSIZE 500
424 #define YYMAXDEPTH 500
425 #endif
426 #endif
428 #define YYINITSTACKSIZE 500
430 int yydebug;
431 int yynerrs;
432 int yyerrflag;
433 int yychar;
434 short *yyssp;
435 YYSTYPE *yyvsp;
436 YYSTYPE yyval;
437 YYSTYPE yylval;
439 /* variables for the parser stack */
440 static short *yyss;
441 static short *yysslim;
442 static YYSTYPE *yyvs;
443 static unsigned yystacksize;
444 #line 658 "ftp.y"
446 extern jmp_buf errcatch;
448 #define CMD 0 /* beginning of command */
449 #define ARGS 1 /* expect miscellaneous arguments */
450 #define STR1 2 /* expect SP followed by STRING */
451 #define STR2 3 /* expect STRING */
452 #define OSTR 4 /* optional SP then STRING */
453 #define ZSTR1 5 /* SP then optional STRING */
454 #define ZSTR2 6 /* optional STRING after SP */
455 #define SITECMD 7 /* SITE command */
456 #define NSTR 8 /* Number followed by a string */
458 struct tab {
459 char *name;
460 short token;
461 short state;
462 short implemented; /* 1 if command is implemented */
463 char *help;
466 struct tab cmdtab[] = { /* In order defined in RFC 765 */
467 { "USER", USER, STR1, 1, "<sp> username" },
468 { "PASS", PASS, ZSTR1, 1, "<sp> password" },
469 { "ACCT", ACCT, STR1, 0, "(specify account)" },
470 { "SMNT", SMNT, ARGS, 0, "(structure mount)" },
471 { "REIN", REIN, ARGS, 0, "(reinitialize server state)" },
472 { "QUIT", QUIT, ARGS, 1, "(terminate service)", },
473 { "PORT", PORT, ARGS, 1, "<sp> b0, b1, b2, b3, b4" },
474 { "PASV", PASV, ARGS, 1, "(set server in passive mode)" },
475 { "TYPE", TYPE, ARGS, 1, "<sp> [ A | E | I | L ]" },
476 { "STRU", STRU, ARGS, 1, "(specify file structure)" },
477 { "MODE", MODE, ARGS, 1, "(specify transfer mode)" },
478 { "RETR", RETR, STR1, 1, "<sp> file-name" },
479 { "STOR", STOR, STR1, 1, "<sp> file-name" },
480 { "APPE", APPE, STR1, 1, "<sp> file-name" },
481 { "MLFL", MLFL, OSTR, 0, "(mail file)" },
482 { "MAIL", MAIL, OSTR, 0, "(mail to user)" },
483 { "MSND", MSND, OSTR, 0, "(mail send to terminal)" },
484 { "MSOM", MSOM, OSTR, 0, "(mail send to terminal or mailbox)" },
485 { "MSAM", MSAM, OSTR, 0, "(mail send to terminal and mailbox)" },
486 { "MRSQ", MRSQ, OSTR, 0, "(mail recipient scheme question)" },
487 { "MRCP", MRCP, STR1, 0, "(mail recipient)" },
488 { "ALLO", ALLO, ARGS, 1, "allocate storage (vacuously)" },
489 { "REST", REST, ARGS, 0, "(restart command)" },
490 { "RNFR", RNFR, STR1, 1, "<sp> file-name" },
491 { "RNTO", RNTO, STR1, 1, "<sp> file-name" },
492 { "ABOR", ABOR, ARGS, 1, "(abort operation)" },
493 { "DELE", DELE, STR1, 1, "<sp> file-name" },
494 { "CWD", CWD, OSTR, 1, "[ <sp> directory-name ]" },
495 { "XCWD", CWD, OSTR, 1, "[ <sp> directory-name ]" },
496 { "LIST", LIST, OSTR, 1, "[ <sp> path-name ]" },
497 { "NLST", NLST, OSTR, 1, "[ <sp> path-name ]" },
498 { "SITE", SITE, SITECMD, 1, "site-cmd [ <sp> arguments ]" },
499 { "SYST", SYST, ARGS, 1, "(get type of operating system)" },
500 { "STAT", STAT, OSTR, 1, "[ <sp> path-name ]" },
501 { "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" },
502 { "NOOP", NOOP, ARGS, 1, "" },
503 { "MKD", MKD, STR1, 1, "<sp> path-name" },
504 { "XMKD", MKD, STR1, 1, "<sp> path-name" },
505 { "RMD", RMD, STR1, 1, "<sp> path-name" },
506 { "XRMD", RMD, STR1, 1, "<sp> path-name" },
507 { "PWD", PWD, ARGS, 1, "(return current directory)" },
508 { "XPWD", PWD, ARGS, 1, "(return current directory)" },
509 { "CDUP", CDUP, ARGS, 1, "(change to parent directory)" },
510 { "XCUP", CDUP, ARGS, 1, "(change to parent directory)" },
511 { "STOU", STOU, STR1, 1, "<sp> file-name" },
512 { "SIZE", SIZE, OSTR, 1, "<sp> path-name" },
513 { "MDTM", MDTM, OSTR, 1, "<sp> path-name" },
514 { NULL, 0, 0, 0, 0 }
517 struct tab sitetab[] = {
518 { "UMASK", UMASK, ARGS, 1, "[ <sp> umask ]" },
519 { "IDLE", IDLE, ARGS, 1, "[ <sp> maximum-idle-time ]" },
520 { "CHMOD", CHMOD, NSTR, 1, "<sp> mode <sp> file-name" },
521 { "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" },
522 { NULL, 0, 0, 0, 0 }
525 struct tab *
526 lookup(p, cmd)
527 register struct tab *p;
528 char *cmd;
531 for (; p->name != NULL; p++)
532 if (strcmp(cmd, p->name) == 0)
533 return (p);
534 return (0);
537 #include <arpa/telnet.h>
540 * getline - a hacked up version of fgets to ignore TELNET escape codes.
542 char *
543 getline(s, n, iop)
544 char *s;
545 register FILE *iop;
547 register c;
548 register char *cs;
550 cs = s;
551 /* tmpline may contain saved command from urgent mode interruption */
552 for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) {
553 *cs++ = tmpline[c];
554 if (tmpline[c] == '\n') {
555 *cs++ = '\0';
556 if (debug)
557 syslog(LOG_DEBUG, "command: %s", s);
558 tmpline[0] = '\0';
559 return(s);
561 if (c == 0)
562 tmpline[0] = '\0';
564 while ((c = getc(iop)) != EOF) {
565 c &= 0377;
566 if (c == IAC) {
567 if ((c = getc(iop)) != EOF) {
568 c &= 0377;
569 switch (c) {
570 case WILL:
571 case WONT:
572 c = getc(iop);
573 printf("%c%c%c", IAC, DONT, 0377&c);
574 (void) fflush(stdout);
575 continue;
576 case DO:
577 case DONT:
578 c = getc(iop);
579 printf("%c%c%c", IAC, WONT, 0377&c);
580 (void) fflush(stdout);
581 continue;
582 case IAC:
583 break;
584 default:
585 continue; /* ignore command */
589 *cs++ = c;
590 if (--n <= 0 || c == '\n')
591 break;
593 if (c == EOF && cs == s)
594 return (NULL);
595 *cs++ = '\0';
596 if (debug)
597 syslog(LOG_DEBUG, "command: %s", s);
598 return (s);
601 static int
602 toolong()
604 time_t now;
605 extern char *ctime();
606 extern time_t time();
608 reply(421,
609 "Timeout (%d seconds): closing control connection.", timeout);
610 (void) time(&now);
611 if (logging) {
612 syslog(LOG_INFO,
613 "User %s timed out after %d seconds at %s",
614 (pw ? pw -> pw_name : "unknown"), timeout, ctime(&now));
616 dologout(1);
619 yylex()
621 static int cpos, state;
622 register char *cp, *cp2;
623 register struct tab *p;
624 int n;
625 char c, *strpbrk();
626 char *copy();
628 for (;;) {
629 switch (state) {
631 case CMD:
632 (void) signal(SIGALRM, toolong);
633 (void) alarm((unsigned) timeout);
634 if (getline(cbuf, sizeof(cbuf)-1, stdin) == NULL) {
635 reply(221, "You could at least say goodbye.");
636 dologout(0);
638 (void) alarm(0);
639 #ifdef SETPROCTITLE
640 if (strncasecmp(cbuf, "PASS", 4) != NULL)
641 setproctitle("%s: %s", proctitle, cbuf);
642 #endif /* SETPROCTITLE */
643 if ((cp = index(cbuf, '\r'))) {
644 *cp++ = '\n';
645 *cp = '\0';
647 if ((cp = strpbrk(cbuf, " \n")))
648 cpos = cp - cbuf;
649 if (cpos == 0)
650 cpos = 4;
651 c = cbuf[cpos];
652 cbuf[cpos] = '\0';
653 upper(cbuf);
654 p = lookup(cmdtab, cbuf);
655 cbuf[cpos] = c;
656 if (p != 0) {
657 if (p->implemented == 0) {
658 nack(p->name);
659 longjmp(errcatch,0);
660 /* NOTREACHED */
662 state = p->state;
663 *(char **)&yylval = p->name;
664 return (p->token);
666 break;
668 case SITECMD:
669 if (cbuf[cpos] == ' ') {
670 cpos++;
671 return (SP);
673 cp = &cbuf[cpos];
674 if ((cp2 = strpbrk(cp, " \n")))
675 cpos = cp2 - cbuf;
676 c = cbuf[cpos];
677 cbuf[cpos] = '\0';
678 upper(cp);
679 p = lookup(sitetab, cp);
680 cbuf[cpos] = c;
681 if (p != 0) {
682 if (p->implemented == 0) {
683 state = CMD;
684 nack(p->name);
685 longjmp(errcatch,0);
686 /* NOTREACHED */
688 state = p->state;
689 *(char **)&yylval = p->name;
690 return (p->token);
692 state = CMD;
693 break;
695 case OSTR:
696 if (cbuf[cpos] == '\n') {
697 state = CMD;
698 return (CRLF);
700 /* FALLTHROUGH */
702 case STR1:
703 case ZSTR1:
704 dostr1:
705 if (cbuf[cpos] == ' ') {
706 cpos++;
707 state = state == OSTR ? STR2 : ++state;
708 return (SP);
710 break;
712 case ZSTR2:
713 if (cbuf[cpos] == '\n') {
714 state = CMD;
715 return (CRLF);
717 /* FALLTHROUGH */
719 case STR2:
720 cp = &cbuf[cpos];
721 n = strlen(cp);
722 cpos += n - 1;
724 * Make sure the string is nonempty and \n terminated.
726 if (n > 1 && cbuf[cpos] == '\n') {
727 cbuf[cpos] = '\0';
728 *(char **)&yylval = copy(cp);
729 cbuf[cpos] = '\n';
730 state = ARGS;
731 return (STRING);
733 break;
735 case NSTR:
736 if (cbuf[cpos] == ' ') {
737 cpos++;
738 return (SP);
740 if (isdigit(cbuf[cpos])) {
741 cp = &cbuf[cpos];
742 while (isdigit(cbuf[++cpos]))
744 c = cbuf[cpos];
745 cbuf[cpos] = '\0';
746 yylval = atoi(cp);
747 cbuf[cpos] = c;
748 state = STR1;
749 return (NUMBER);
751 state = STR1;
752 goto dostr1;
754 case ARGS:
755 if (isdigit(cbuf[cpos])) {
756 cp = &cbuf[cpos];
757 while (isdigit(cbuf[++cpos]))
759 c = cbuf[cpos];
760 cbuf[cpos] = '\0';
761 yylval = atoi(cp);
762 cbuf[cpos] = c;
763 return (NUMBER);
765 switch (cbuf[cpos++]) {
767 case '\n':
768 state = CMD;
769 return (CRLF);
771 case ' ':
772 return (SP);
774 case ',':
775 return (COMMA);
777 case 'A':
778 case 'a':
779 return (A);
781 case 'B':
782 case 'b':
783 return (B);
785 case 'C':
786 case 'c':
787 return (C);
789 case 'E':
790 case 'e':
791 return (E);
793 case 'F':
794 case 'f':
795 return (F);
797 case 'I':
798 case 'i':
799 return (I);
801 case 'L':
802 case 'l':
803 return (L);
805 case 'N':
806 case 'n':
807 return (N);
809 case 'P':
810 case 'p':
811 return (P);
813 case 'R':
814 case 'r':
815 return (R);
817 case 'S':
818 case 's':
819 return (S);
821 case 'T':
822 case 't':
823 return (T);
826 break;
828 default:
829 fatal("Unknown state in scanner.");
831 yyerror((char *) 0);
832 state = CMD;
833 longjmp(errcatch,0);
837 upper(s)
838 register char *s;
840 while (*s != '\0') {
841 if (islower(*s))
842 *s = toupper(*s);
843 s++;
847 char *
848 copy(s)
849 char *s;
851 char *p;
852 extern char *malloc(), *strcpy();
854 p = malloc((unsigned) strlen(s) + 1);
855 if (p == NULL)
856 fatal("Ran out of memory.");
857 (void) strcpy(p, s);
858 return (p);
861 help(ctab, s)
862 struct tab *ctab;
863 char *s;
865 register struct tab *c;
866 register int width, NCMDS;
867 char *type;
869 if (ctab == sitetab)
870 type = "SITE ";
871 else
872 type = "";
873 width = 0, NCMDS = 0;
874 for (c = ctab; c->name != NULL; c++) {
875 int len = strlen(c->name);
877 if (len > width)
878 width = len;
879 NCMDS++;
881 width = (width + 8) &~ 7;
882 if (s == 0) {
883 register int i, j, w;
884 int columns, lines;
886 lreply(214, "The following %scommands are recognized %s.",
887 type, "(* =>'s unimplemented)");
888 columns = 76 / width;
889 if (columns == 0)
890 columns = 1;
891 lines = (NCMDS + columns - 1) / columns;
892 for (i = 0; i < lines; i++) {
893 printf(" ");
894 for (j = 0; j < columns; j++) {
895 c = ctab + j * lines + i;
896 printf("%s%c", c->name,
897 c->implemented ? ' ' : '*');
898 if (c + lines >= &ctab[NCMDS])
899 break;
900 w = strlen(c->name) + 1;
901 while (w < width) {
902 putchar(' ');
903 w++;
906 printf("\r\n");
908 (void) fflush(stdout);
909 reply(214, "Direct comments to ftp-bugs@%s.", hostname);
910 return;
912 upper(s);
913 c = lookup(ctab, s);
914 if (c == (struct tab *)0) {
915 reply(502, "Unknown command %s.", s);
916 return;
918 if (c->implemented)
919 reply(214, "Syntax: %s%s %s", type, c->name, c->help);
920 else
921 reply(214, "%s%-*s\t%s; unimplemented.", type, width,
922 c->name, c->help);
925 sizecmd(filename)
926 char *filename;
928 switch (type) {
929 case TYPE_L:
930 case TYPE_I: {
931 struct stat stbuf;
932 if (stat(filename, &stbuf) < 0 ||
933 (stbuf.st_mode&S_IFMT) != S_IFREG)
934 reply(550, "%s: not a plain file.", filename);
935 else
936 reply(213, "%lu", stbuf.st_size);
937 break;}
938 case TYPE_A: {
939 FILE *fin;
940 register int c, count;
941 struct stat stbuf;
942 fin = fopen(filename, "r");
943 if (fin == NULL) {
944 perror_reply(550, filename);
945 return;
947 if (fstat(fileno(fin), &stbuf) < 0 ||
948 (stbuf.st_mode&S_IFMT) != S_IFREG) {
949 reply(550, "%s: not a plain file.", filename);
950 (void) fclose(fin);
951 return;
954 count = 0;
955 while((c=getc(fin)) != EOF) {
956 if (c == '\n') /* will get expanded to \r\n */
957 count++;
958 count++;
960 (void) fclose(fin);
962 reply(213, "%ld", count);
963 break;}
964 default:
965 reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]);
968 #line 967 "ftp.tab.c"
969 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
970 static int yygrowstack(void)
972 int i;
973 unsigned newsize;
974 short *newss;
975 YYSTYPE *newvs;
977 if ((newsize = yystacksize) == 0)
978 newsize = YYINITSTACKSIZE;
979 else if (newsize >= YYMAXDEPTH)
980 return -1;
981 else if ((newsize *= 2) > YYMAXDEPTH)
982 newsize = YYMAXDEPTH;
984 i = yyssp - yyss;
985 newss = (yyss != 0)
986 ? (short *)realloc(yyss, newsize * sizeof(*newss))
987 : (short *)malloc(newsize * sizeof(*newss));
988 if (newss == 0)
989 return -1;
991 yyss = newss;
992 yyssp = newss + i;
993 newvs = (yyvs != 0)
994 ? (YYSTYPE *)realloc(yyvs, newsize * sizeof(*newvs))
995 : (YYSTYPE *)malloc(newsize * sizeof(*newvs));
996 if (newvs == 0)
997 return -1;
999 yyvs = newvs;
1000 yyvsp = newvs + i;
1001 yystacksize = newsize;
1002 yysslim = yyss + newsize - 1;
1003 return 0;
1006 #define YYABORT goto yyabort
1007 #define YYREJECT goto yyabort
1008 #define YYACCEPT goto yyaccept
1009 #define YYERROR goto yyerrlab
1012 YYPARSE_DECL()
1014 int yym, yyn, yystate;
1015 #if YYDEBUG
1016 const char *yys;
1018 if ((yys = getenv("YYDEBUG")) != 0)
1020 yyn = *yys;
1021 if (yyn >= '0' && yyn <= '9')
1022 yydebug = yyn - '0';
1024 #endif
1026 yynerrs = 0;
1027 yyerrflag = 0;
1028 yychar = YYEMPTY;
1029 yystate = 0;
1031 if (yyss == NULL && yygrowstack()) goto yyoverflow;
1032 yyssp = yyss;
1033 yyvsp = yyvs;
1034 yystate = 0;
1035 *yyssp = 0;
1037 yyloop:
1038 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
1039 if (yychar < 0)
1041 if ((yychar = yylex()) < 0) yychar = 0;
1042 #if YYDEBUG
1043 if (yydebug)
1045 yys = 0;
1046 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1047 if (!yys) yys = "illegal-symbol";
1048 printf("%sdebug: state %d, reading %d (%s)\n",
1049 YYPREFIX, yystate, yychar, yys);
1051 #endif
1053 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
1054 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1056 #if YYDEBUG
1057 if (yydebug)
1058 printf("%sdebug: state %d, shifting to state %d\n",
1059 YYPREFIX, yystate, yytable[yyn]);
1060 #endif
1061 if (yyssp >= yysslim && yygrowstack())
1063 goto yyoverflow;
1065 yystate = yytable[yyn];
1066 *++yyssp = yytable[yyn];
1067 *++yyvsp = yylval;
1068 yychar = YYEMPTY;
1069 if (yyerrflag > 0) --yyerrflag;
1070 goto yyloop;
1072 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
1073 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1075 yyn = yytable[yyn];
1076 goto yyreduce;
1078 if (yyerrflag) goto yyinrecovery;
1080 yyerror("syntax error");
1082 goto yyerrlab;
1084 yyerrlab:
1085 ++yynerrs;
1087 yyinrecovery:
1088 if (yyerrflag < 3)
1090 yyerrflag = 3;
1091 for (;;)
1093 if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
1094 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
1096 #if YYDEBUG
1097 if (yydebug)
1098 printf("%sdebug: state %d, error recovery shifting\
1099 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
1100 #endif
1101 if (yyssp >= yysslim && yygrowstack())
1103 goto yyoverflow;
1105 yystate = yytable[yyn];
1106 *++yyssp = yytable[yyn];
1107 *++yyvsp = yylval;
1108 goto yyloop;
1110 else
1112 #if YYDEBUG
1113 if (yydebug)
1114 printf("%sdebug: error recovery discarding state %d\n",
1115 YYPREFIX, *yyssp);
1116 #endif
1117 if (yyssp <= yyss) goto yyabort;
1118 --yyssp;
1119 --yyvsp;
1123 else
1125 if (yychar == 0) goto yyabort;
1126 #if YYDEBUG
1127 if (yydebug)
1129 yys = 0;
1130 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1131 if (!yys) yys = "illegal-symbol";
1132 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1133 YYPREFIX, yystate, yychar, yys);
1135 #endif
1136 yychar = YYEMPTY;
1137 goto yyloop;
1140 yyreduce:
1141 #if YYDEBUG
1142 if (yydebug)
1143 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1144 YYPREFIX, yystate, yyn, yyrule[yyn]);
1145 #endif
1146 yym = yylen[yyn];
1147 if (yym)
1148 yyval = yyvsp[1-yym];
1149 else
1150 memset(&yyval, 0, sizeof yyval);
1151 switch (yyn)
1153 case 2:
1154 #line 99 "ftp.y"
1156 fromname = (char *) 0;
1158 break;
1159 case 4:
1160 #line 106 "ftp.y"
1162 user((char *) yyvsp[-1]);
1163 free((char *) yyvsp[-1]);
1165 break;
1166 case 5:
1167 #line 111 "ftp.y"
1169 pass((char *) yyvsp[-1]);
1170 free((char *) yyvsp[-1]);
1172 break;
1173 case 6:
1174 #line 116 "ftp.y"
1176 usedefault = 0;
1177 if (pdata >= 0) {
1178 (void) close(pdata);
1179 pdata = -1;
1181 reply(200, "PORT command successful.");
1183 break;
1184 case 7:
1185 #line 125 "ftp.y"
1187 passive();
1189 break;
1190 case 8:
1191 #line 129 "ftp.y"
1193 switch (cmd_type) {
1195 case TYPE_A:
1196 if (cmd_form == FORM_N) {
1197 reply(200, "Type set to A.");
1198 type = cmd_type;
1199 form = cmd_form;
1200 } else
1201 reply(504, "Form must be N.");
1202 break;
1204 case TYPE_E:
1205 reply(504, "Type E not implemented.");
1206 break;
1208 case TYPE_I:
1209 reply(200, "Type set to I.");
1210 type = cmd_type;
1211 break;
1213 case TYPE_L:
1214 #if NBBY == 8
1215 if (cmd_bytesz == 8) {
1216 reply(200,
1217 "Type set to L (byte size 8).");
1218 type = cmd_type;
1219 } else
1220 reply(504, "Byte size must be 8.");
1221 #else /* NBBY == 8 */
1222 UNIMPLEMENTED for NBBY != 8
1223 #endif /* NBBY == 8 */
1226 break;
1227 case 9:
1228 #line 164 "ftp.y"
1230 switch (yyvsp[-1]) {
1232 case STRU_F:
1233 reply(200, "STRU F ok.");
1234 break;
1236 default:
1237 reply(504, "Unimplemented STRU type.");
1240 break;
1241 case 10:
1242 #line 176 "ftp.y"
1244 switch (yyvsp[-1]) {
1246 case MODE_S:
1247 reply(200, "MODE S ok.");
1248 break;
1250 default:
1251 reply(502, "Unimplemented MODE type.");
1254 break;
1255 case 11:
1256 #line 188 "ftp.y"
1258 reply(202, "ALLO command ignored.");
1260 break;
1261 case 12:
1262 #line 192 "ftp.y"
1264 reply(202, "ALLO command ignored.");
1266 break;
1267 case 13:
1268 #line 196 "ftp.y"
1270 if (yyvsp[-3] && yyvsp[-1] != NULL)
1271 retrieve((char *) 0, (char *) yyvsp[-1]);
1272 if (yyvsp[-1] != NULL)
1273 free((char *) yyvsp[-1]);
1275 break;
1276 case 14:
1277 #line 203 "ftp.y"
1279 if (yyvsp[-3] && yyvsp[-1] != NULL)
1280 store((char *) yyvsp[-1], "w", 0);
1281 if (yyvsp[-1] != NULL)
1282 free((char *) yyvsp[-1]);
1284 break;
1285 case 15:
1286 #line 210 "ftp.y"
1288 if (yyvsp[-3] && yyvsp[-1] != NULL)
1289 store((char *) yyvsp[-1], "a", 0);
1290 if (yyvsp[-1] != NULL)
1291 free((char *) yyvsp[-1]);
1293 break;
1294 case 16:
1295 #line 217 "ftp.y"
1297 if (yyvsp[-1])
1298 send_file_list(".");
1300 break;
1301 case 17:
1302 #line 222 "ftp.y"
1304 if (yyvsp[-3] && yyvsp[-1] != NULL)
1305 send_file_list((char *) yyvsp[-1]);
1306 if (yyvsp[-1] != NULL)
1307 free((char *) yyvsp[-1]);
1309 break;
1310 case 18:
1311 #line 229 "ftp.y"
1313 if (yyvsp[-1])
1314 retrieve("/bin/ls -lgA", "");
1316 break;
1317 case 19:
1318 #line 234 "ftp.y"
1320 if (yyvsp[-3] && yyvsp[-1] != NULL)
1321 retrieve("/bin/ls -lgA %s", (char *) yyvsp[-1]);
1322 if (yyvsp[-1] != NULL)
1323 free((char *) yyvsp[-1]);
1325 break;
1326 case 20:
1327 #line 241 "ftp.y"
1329 if (yyvsp[-3] && yyvsp[-1] != NULL)
1330 statfilecmd((char *) yyvsp[-1]);
1331 if (yyvsp[-1] != NULL)
1332 free((char *) yyvsp[-1]);
1334 break;
1335 case 21:
1336 #line 248 "ftp.y"
1338 statcmd();
1340 break;
1341 case 22:
1342 #line 252 "ftp.y"
1344 if (yyvsp[-3] && yyvsp[-1] != NULL)
1345 delete((char *) yyvsp[-1]);
1346 if (yyvsp[-1] != NULL)
1347 free((char *) yyvsp[-1]);
1349 break;
1350 case 23:
1351 #line 259 "ftp.y"
1353 if (fromname) {
1354 renamecmd(fromname, (char *) yyvsp[-1]);
1355 free(fromname);
1356 fromname = (char *) 0;
1357 } else {
1358 reply(503, "Bad sequence of commands.");
1360 free((char *) yyvsp[-1]);
1362 break;
1363 case 24:
1364 #line 270 "ftp.y"
1366 reply(225, "ABOR command successful.");
1368 break;
1369 case 25:
1370 #line 274 "ftp.y"
1372 if (yyvsp[-1])
1373 cwd(pw->pw_dir);
1375 break;
1376 case 26:
1377 #line 279 "ftp.y"
1379 if (yyvsp[-3] && yyvsp[-1] != NULL)
1380 cwd((char *) yyvsp[-1]);
1381 if (yyvsp[-1] != NULL)
1382 free((char *) yyvsp[-1]);
1384 break;
1385 case 27:
1386 #line 286 "ftp.y"
1388 help(cmdtab, (char *) 0);
1390 break;
1391 case 28:
1392 #line 290 "ftp.y"
1394 register char *cp = (char *)yyvsp[-1];
1396 if (strncasecmp(cp, "SITE", 4) == 0) {
1397 cp = (char *)yyvsp[-1] + 4;
1398 if (*cp == ' ')
1399 cp++;
1400 if (*cp)
1401 help(sitetab, cp);
1402 else
1403 help(sitetab, (char *) 0);
1404 } else
1405 help(cmdtab, (char *) yyvsp[-1]);
1407 break;
1408 case 29:
1409 #line 305 "ftp.y"
1411 reply(200, "NOOP command successful.");
1413 break;
1414 case 30:
1415 #line 309 "ftp.y"
1417 if (yyvsp[-3] && yyvsp[-1] != NULL)
1418 makedir((char *) yyvsp[-1]);
1419 if (yyvsp[-1] != NULL)
1420 free((char *) yyvsp[-1]);
1422 break;
1423 case 31:
1424 #line 316 "ftp.y"
1426 if (yyvsp[-3] && yyvsp[-1] != NULL)
1427 removedir((char *) yyvsp[-1]);
1428 if (yyvsp[-1] != NULL)
1429 free((char *) yyvsp[-1]);
1431 break;
1432 case 32:
1433 #line 323 "ftp.y"
1435 if (yyvsp[-1])
1436 pwd();
1438 break;
1439 case 33:
1440 #line 328 "ftp.y"
1442 if (yyvsp[-1])
1443 cwd("..");
1445 break;
1446 case 34:
1447 #line 333 "ftp.y"
1449 help(sitetab, (char *) 0);
1451 break;
1452 case 35:
1453 #line 337 "ftp.y"
1455 help(sitetab, (char *) yyvsp[-1]);
1457 break;
1458 case 36:
1459 #line 341 "ftp.y"
1461 int oldmask;
1463 if (yyvsp[-1]) {
1464 oldmask = umask(0);
1465 (void) umask(oldmask);
1466 reply(200, "Current UMASK is %03o", oldmask);
1469 break;
1470 case 37:
1471 #line 351 "ftp.y"
1473 int oldmask;
1475 if (yyvsp[-3]) {
1476 if ((yyvsp[-1] == -1) || (yyvsp[-1] > 0777)) {
1477 reply(501, "Bad UMASK value");
1478 } else {
1479 oldmask = umask(yyvsp[-1]);
1480 reply(200,
1481 "UMASK set to %03o (was %03o)",
1482 yyvsp[-1], oldmask);
1486 break;
1487 case 38:
1488 #line 366 "ftp.y"
1490 if (yyvsp[-5] && (yyvsp[-1] != NULL)) {
1491 if (yyvsp[-3] > 0777)
1492 reply(501,
1493 "CHMOD: Mode value must be between 0 and 0777");
1494 else if (chmod((char *) yyvsp[-1], yyvsp[-3]) < 0)
1495 perror_reply(550, (char *) yyvsp[-1]);
1496 else
1497 reply(200, "CHMOD command successful.");
1499 if (yyvsp[-1] != NULL)
1500 free((char *) yyvsp[-1]);
1502 break;
1503 case 39:
1504 #line 380 "ftp.y"
1506 reply(200,
1507 "Current IDLE time limit is %d seconds; max %d",
1508 timeout, maxtimeout);
1510 break;
1511 case 40:
1512 #line 386 "ftp.y"
1514 if (yyvsp[-1] < 30 || yyvsp[-1] > maxtimeout) {
1515 reply(501,
1516 "Maximum IDLE time must be between 30 and %d seconds",
1517 maxtimeout);
1518 } else {
1519 timeout = yyvsp[-1];
1520 (void) alarm((unsigned) timeout);
1521 reply(200,
1522 "Maximum IDLE time set to %d seconds",
1523 timeout);
1526 break;
1527 case 41:
1528 #line 400 "ftp.y"
1530 if (yyvsp[-3] && yyvsp[-1] != NULL)
1531 store((char *) yyvsp[-1], "w", 1);
1532 if (yyvsp[-1] != NULL)
1533 free((char *) yyvsp[-1]);
1535 break;
1536 case 42:
1537 #line 407 "ftp.y"
1539 #ifdef unix
1540 #ifdef BSD
1541 reply(215, "UNIX Type: L%d Version: BSD-%d",
1542 NBBY, BSD);
1543 #else /* BSD */
1544 reply(215, "UNIX Type: L%d", NBBY);
1545 #endif /* BSD */
1546 #else /* unix */
1547 reply(215, "UNKNOWN Type: L%d", NBBY);
1548 #endif /* unix */
1550 break;
1551 case 43:
1552 #line 428 "ftp.y"
1554 if (yyvsp[-3] && yyvsp[-1] != NULL)
1555 sizecmd((char *) yyvsp[-1]);
1556 if (yyvsp[-1] != NULL)
1557 free((char *) yyvsp[-1]);
1559 break;
1560 case 44:
1561 #line 445 "ftp.y"
1563 if (yyvsp[-3] && yyvsp[-1] != NULL) {
1564 struct stat stbuf;
1565 if (stat((char *) yyvsp[-1], &stbuf) < 0)
1566 perror_reply(550, "%s", (char *) yyvsp[-1]);
1567 else if ((stbuf.st_mode&S_IFMT) != S_IFREG) {
1568 reply(550, "%s: not a plain file.",
1569 (char *) yyvsp[-1]);
1570 } else {
1571 register struct tm *t;
1572 struct tm *gmtime();
1573 t = gmtime(&stbuf.st_mtime);
1574 reply(213,
1575 "19%02d%02d%02d%02d%02d%02d",
1576 t->tm_year, t->tm_mon+1, t->tm_mday,
1577 t->tm_hour, t->tm_min, t->tm_sec);
1580 if (yyvsp[-1] != NULL)
1581 free((char *) yyvsp[-1]);
1583 break;
1584 case 45:
1585 #line 467 "ftp.y"
1587 reply(221, "Goodbye.");
1588 dologout(0);
1590 break;
1591 case 46:
1592 #line 472 "ftp.y"
1594 yyerrok;
1596 break;
1597 case 47:
1598 #line 477 "ftp.y"
1600 char *renamefrom();
1602 if (yyvsp[-3] && yyvsp[-1]) {
1603 fromname = renamefrom((char *) yyvsp[-1]);
1604 if (fromname == (char *) 0 && yyvsp[-1]) {
1605 free((char *) yyvsp[-1]);
1609 break;
1610 case 49:
1611 #line 493 "ftp.y"
1613 *(char **)&(yyval) = "";
1615 break;
1616 case 52:
1617 #line 504 "ftp.y"
1619 register char *a, *p;
1621 a = (char *)&data_dest.sin_addr;
1622 a[0] = yyvsp[-10]; a[1] = yyvsp[-8]; a[2] = yyvsp[-6]; a[3] = yyvsp[-4];
1623 p = (char *)&data_dest.sin_port;
1624 p[0] = yyvsp[-2]; p[1] = yyvsp[0];
1625 data_dest.sin_family = AF_INET;
1627 break;
1628 case 53:
1629 #line 516 "ftp.y"
1631 yyval = FORM_N;
1633 break;
1634 case 54:
1635 #line 520 "ftp.y"
1637 yyval = FORM_T;
1639 break;
1640 case 55:
1641 #line 524 "ftp.y"
1643 yyval = FORM_C;
1645 break;
1646 case 56:
1647 #line 530 "ftp.y"
1649 cmd_type = TYPE_A;
1650 cmd_form = FORM_N;
1652 break;
1653 case 57:
1654 #line 535 "ftp.y"
1656 cmd_type = TYPE_A;
1657 cmd_form = yyvsp[0];
1659 break;
1660 case 58:
1661 #line 540 "ftp.y"
1663 cmd_type = TYPE_E;
1664 cmd_form = FORM_N;
1666 break;
1667 case 59:
1668 #line 545 "ftp.y"
1670 cmd_type = TYPE_E;
1671 cmd_form = yyvsp[0];
1673 break;
1674 case 60:
1675 #line 550 "ftp.y"
1677 cmd_type = TYPE_I;
1679 break;
1680 case 61:
1681 #line 554 "ftp.y"
1683 cmd_type = TYPE_L;
1684 cmd_bytesz = NBBY;
1686 break;
1687 case 62:
1688 #line 559 "ftp.y"
1690 cmd_type = TYPE_L;
1691 cmd_bytesz = yyvsp[0];
1693 break;
1694 case 63:
1695 #line 565 "ftp.y"
1697 cmd_type = TYPE_L;
1698 cmd_bytesz = yyvsp[0];
1700 break;
1701 case 64:
1702 #line 572 "ftp.y"
1704 yyval = STRU_F;
1706 break;
1707 case 65:
1708 #line 576 "ftp.y"
1710 yyval = STRU_R;
1712 break;
1713 case 66:
1714 #line 580 "ftp.y"
1716 yyval = STRU_P;
1718 break;
1719 case 67:
1720 #line 586 "ftp.y"
1722 yyval = MODE_S;
1724 break;
1725 case 68:
1726 #line 590 "ftp.y"
1728 yyval = MODE_B;
1730 break;
1731 case 69:
1732 #line 594 "ftp.y"
1734 yyval = MODE_C;
1736 break;
1737 case 70:
1738 #line 600 "ftp.y"
1741 * Problem: this production is used for all pathname
1742 * processing, but only gives a 550 error reply.
1743 * This is a valid reply in some cases but not in others.
1745 if (logged_in && yyvsp[0] && strncmp((char *) yyvsp[0], "~", 1) == 0) {
1746 *(char **)&(yyval) = *glob((char *) yyvsp[0]);
1747 if (globerr != NULL) {
1748 reply(550, globerr);
1749 yyval = NULL;
1751 free((char *) yyvsp[0]);
1752 } else
1753 yyval = yyvsp[0];
1755 break;
1756 case 72:
1757 #line 622 "ftp.y"
1759 register int ret, dec, multby, digit;
1762 * Convert a number that was read as decimal number
1763 * to what it would be if it had been read as octal.
1765 dec = yyvsp[0];
1766 multby = 1;
1767 ret = 0;
1768 while (dec) {
1769 digit = dec%10;
1770 if (digit > 7) {
1771 ret = -1;
1772 break;
1774 ret += digit * multby;
1775 multby *= 8;
1776 dec /= 10;
1778 yyval = ret;
1780 break;
1781 case 73:
1782 #line 647 "ftp.y"
1784 if (logged_in)
1785 yyval = 1;
1786 else {
1787 reply(530, "Please login with USER and PASS.");
1788 yyval = 0;
1791 break;
1792 #line 1791 "ftp.tab.c"
1794 yyssp -= yym;
1795 yystate = *yyssp;
1796 yyvsp -= yym;
1797 yym = yylhs[yyn];
1798 if (yystate == 0 && yym == 0)
1800 #if YYDEBUG
1801 if (yydebug)
1802 printf("%sdebug: after reduction, shifting from state 0 to\
1803 state %d\n", YYPREFIX, YYFINAL);
1804 #endif
1805 yystate = YYFINAL;
1806 *++yyssp = YYFINAL;
1807 *++yyvsp = yyval;
1808 if (yychar < 0)
1810 if ((yychar = yylex()) < 0) yychar = 0;
1811 #if YYDEBUG
1812 if (yydebug)
1814 yys = 0;
1815 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1816 if (!yys) yys = "illegal-symbol";
1817 printf("%sdebug: state %d, reading %d (%s)\n",
1818 YYPREFIX, YYFINAL, yychar, yys);
1820 #endif
1822 if (yychar == 0) goto yyaccept;
1823 goto yyloop;
1825 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
1826 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
1827 yystate = yytable[yyn];
1828 else
1829 yystate = yydgoto[yym];
1830 #if YYDEBUG
1831 if (yydebug)
1832 printf("%sdebug: after reduction, shifting from state %d \
1833 to state %d\n", YYPREFIX, *yyssp, yystate);
1834 #endif
1835 if (yyssp >= yysslim && yygrowstack())
1837 goto yyoverflow;
1839 *++yyssp = (short) yystate;
1840 *++yyvsp = yyval;
1841 goto yyloop;
1843 yyoverflow:
1844 yyerror("yacc stack overflow");
1846 yyabort:
1847 return (1);
1849 yyaccept:
1850 return (0);