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