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