Debian Codegraph @

ftpd/ftpcmd.c

raw
1 /* A Bison parser, made by GNU Bison 3.8.2. */
2
3 /* Bison implementation for Yacc-like parsers in C
4
5 Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
6 Inc.
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <https://www.gnu.org/licenses/>. */
20
21 /* As a special exception, you may create a larger work that contains
22 part or all of the Bison parser skeleton and distribute that work
23 under terms of your choice, so long as that work isn't itself a
24 parser generator using the skeleton or a modified version thereof
25 as a parser skeleton. Alternatively, if you modify or redistribute
26 the parser skeleton itself, you may (at your option) remove this
27 special exception, which will cause the skeleton and the resulting
28 Bison output files to be licensed under the GNU General Public
29 License without this special exception.
30
31 This special exception was added by the Free Software Foundation in
32 version 2.2 of Bison. */
33
34 /* C LALR(1) parser skeleton written by Richard Stallman, by
35 simplifying the original so-called "semantic" parser. */
36
37 /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
38 especially those whose name start with YY_ or yy_. They are
39 private implementation details that can be changed or removed. */
40
41 /* All symbols defined below should begin with yy or YY, to avoid
42 infringing on user name space. This should be done even for local
43 variables, as they might otherwise be expanded by user macros.
44 There are some unavoidable exceptions within include files to
45 define necessary library symbols; they are noted "INFRINGES ON
46 USER NAME SPACE" below. */
47
48 /* Identify Bison output, and Bison version. */
49 #define YYBISON 30802
50
51 /* Bison version string. */
52 #define YYBISON_VERSION "3.8.2"
53
54 /* Skeleton name. */
55 #define YYSKELETON_NAME "yacc.c"
56
57 /* Pure parsers. */
58 #define YYPURE 0
59
60 /* Push parsers. */
61 #define YYPUSH 0
62
63 /* Pull parsers. */
64 #define YYPULL 1
65
66
67
68
69 /* First part of user prologue. */
70 #line 70 "ftpcmd.y"
71
72
73 #include <config.h>
74
75 #include <sys/types.h>
76 #include <sys/param.h>
77 #include <sys/socket.h>
78 #include <sys/stat.h>
79
80 #include <netinet/in.h>
81 #include <netdb.h>
82 #include <arpa/ftp.h>
83
84 #include <ctype.h>
85 #include <errno.h>
86 #include <pwd.h>
87 #include <setjmp.h>
88 #include <signal.h>
89 #ifdef HAVE_INTTYPES_H
90 # include <inttypes.h> /* strtoimax */
91 #elif defined HAVE_STDINT_H
92 # include <stdint.h>
93 #endif
94 #include <stdio.h>
95 #include <stdlib.h>
96 #include <string.h>
97 #include <syslog.h>
98 #include <sys/time.h>
99 #include <time.h>
100 #include <unistd.h>
101 #include <limits.h>
102 #include <sys/utsname.h>
103 /* Include glob.h last, because it may define "const" which breaks
104 system headers on some platforms. */
105 #include <glob.h>
106
107 #include "extern.h"
108
109 off_t restart_point;
110
111 static char cbuf[512]; /* Command Buffer. */
112 static char *fromname;
113 static int cmd_type;
114 static int cmd_form;
115 static int cmd_bytesz;
116
117 struct tab
118 {
119 const char *name;
120 short token;
121 short state;
122 short implemented; /* 1 if command is implemented */
123 const char *help;
124 };
125
126 static struct tab cmdtab[];
127 static struct tab sitetab[];
128 static char *extlist[];
129 static char *copy (char *);
130 static void help (struct tab *, char *);
131 static struct tab *lookup (struct tab *, char *);
132 static void sizecmd (char *);
133 static int yylex (void);
134 static void yyerror (const char *s);
135
136
137 #line 138 "ftpcmd.c"
138
139 # ifndef YY_CAST
140 # ifdef __cplusplus
141 # define YY_CAST(Type, Val) static_cast<Type> (Val)
142 # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
143 # else
144 # define YY_CAST(Type, Val) ((Type) (Val))
145 # define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
146 # endif
147 # endif
148 # ifndef YY_NULLPTR
149 # if defined __cplusplus
150 # if 201103L <= __cplusplus
151 # define YY_NULLPTR nullptr
152 # else
153 # define YY_NULLPTR 0
154 # endif
155 # else
156 # define YY_NULLPTR ((void*)0)
157 # endif
158 # endif
159
160
161 /* Debug traces. */
162 #ifndef YYDEBUG
163 # define YYDEBUG 0
164 #endif
165 #if YYDEBUG
166 extern int yydebug;
167 #endif
168
169 /* Token kinds. */
170 #ifndef YYTOKENTYPE
171 # define YYTOKENTYPE
172 enum yytokentype
173 {
174 YYEMPTY = -2,
175 YYEOF = 0, /* "end of file" */
176 YYerror = 256, /* error */
177 YYUNDEF = 257, /* "invalid token" */
178 A = 258, /* A */
179 B = 259, /* B */
180 C = 260, /* C */
181 E = 261, /* E */
182 F = 262, /* F */
183 I = 263, /* I */
184 L = 264, /* L */
185 N = 265, /* N */
186 P = 266, /* P */
187 R = 267, /* R */
188 S = 268, /* S */
189 T = 269, /* T */
190 SP = 270, /* SP */
191 CRLF = 271, /* CRLF */
192 COMMA = 272, /* COMMA */
193 USER = 273, /* USER */
194 PASS = 274, /* PASS */
195 ACCT = 275, /* ACCT */
196 REIN = 276, /* REIN */
197 QUIT = 277, /* QUIT */
198 PORT = 278, /* PORT */
199 PASV = 279, /* PASV */
200 TYPE = 280, /* TYPE */
201 STRU = 281, /* STRU */
202 MODE = 282, /* MODE */
203 RETR = 283, /* RETR */
204 STOR = 284, /* STOR */
205 APPE = 285, /* APPE */
206 MLFL = 286, /* MLFL */
207 MAIL = 287, /* MAIL */
208 MSND = 288, /* MSND */
209 MSOM = 289, /* MSOM */
210 MSAM = 290, /* MSAM */
211 MRSQ = 291, /* MRSQ */
212 MRCP = 292, /* MRCP */
213 ALLO = 293, /* ALLO */
214 REST = 294, /* REST */
215 RNFR = 295, /* RNFR */
216 RNTO = 296, /* RNTO */
217 ABOR = 297, /* ABOR */
218 DELE = 298, /* DELE */
219 CWD = 299, /* CWD */
220 LIST = 300, /* LIST */
221 NLST = 301, /* NLST */
222 SITE = 302, /* SITE */
223 STAT = 303, /* STAT */
224 HELP = 304, /* HELP */
225 NOOP = 305, /* NOOP */
226 MKD = 306, /* MKD */
227 RMD = 307, /* RMD */
228 PWD = 308, /* PWD */
229 CDUP = 309, /* CDUP */
230 STOU = 310, /* STOU */
231 SMNT = 311, /* SMNT */
232 SYST = 312, /* SYST */
233 SIZE = 313, /* SIZE */
234 MDTM = 314, /* MDTM */
235 FEAT = 315, /* FEAT */
236 OPTS = 316, /* OPTS */
237 EPRT = 317, /* EPRT */
238 EPSV = 318, /* EPSV */
239 LPRT = 319, /* LPRT */
240 LPSV = 320, /* LPSV */
241 ADAT = 321, /* ADAT */
242 AUTH = 322, /* AUTH */
243 CCC = 323, /* CCC */
244 CONF = 324, /* CONF */
245 ENC = 325, /* ENC */
246 MIC = 326, /* MIC */
247 PBSZ = 327, /* PBSZ */
248 PROT = 328, /* PROT */
249 UMASK = 329, /* UMASK */
250 IDLE = 330, /* IDLE */
251 CHMOD = 331, /* CHMOD */
252 LEXERR = 332, /* LEXERR */
253 STRING = 333, /* STRING */
254 NUMBER = 334, /* NUMBER */
255 CHAR = 335 /* CHAR */
256 };
257 typedef enum yytokentype yytoken_kind_t;
258 #endif
259 /* Token kinds. */
260 #define YYEMPTY -2
261 #define YYEOF 0
262 #define YYerror 256
263 #define YYUNDEF 257
264 #define A 258
265 #define B 259
266 #define C 260
267 #define E 261
268 #define F 262
269 #define I 263
270 #define L 264
271 #define N 265
272 #define P 266
273 #define R 267
274 #define S 268
275 #define T 269
276 #define SP 270
277 #define CRLF 271
278 #define COMMA 272
279 #define USER 273
280 #define PASS 274
281 #define ACCT 275
282 #define REIN 276
283 #define QUIT 277
284 #define PORT 278
285 #define PASV 279
286 #define TYPE 280
287 #define STRU 281
288 #define MODE 282
289 #define RETR 283
290 #define STOR 284
291 #define APPE 285
292 #define MLFL 286
293 #define MAIL 287
294 #define MSND 288
295 #define MSOM 289
296 #define MSAM 290
297 #define MRSQ 291
298 #define MRCP 292
299 #define ALLO 293
300 #define REST 294
301 #define RNFR 295
302 #define RNTO 296
303 #define ABOR 297
304 #define DELE 298
305 #define CWD 299
306 #define LIST 300
307 #define NLST 301
308 #define SITE 302
309 #define STAT 303
310 #define HELP 304
311 #define NOOP 305
312 #define MKD 306
313 #define RMD 307
314 #define PWD 308
315 #define CDUP 309
316 #define STOU 310
317 #define SMNT 311
318 #define SYST 312
319 #define SIZE 313
320 #define MDTM 314
321 #define FEAT 315
322 #define OPTS 316
323 #define EPRT 317
324 #define EPSV 318
325 #define LPRT 319
326 #define LPSV 320
327 #define ADAT 321
328 #define AUTH 322
329 #define CCC 323
330 #define CONF 324
331 #define ENC 325
332 #define MIC 326
333 #define PBSZ 327
334 #define PROT 328
335 #define UMASK 329
336 #define IDLE 330
337 #define CHMOD 331
338 #define LEXERR 332
339 #define STRING 333
340 #define NUMBER 334
341 #define CHAR 335
342
343 /* Value type. */
344 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
345 union YYSTYPE
346 {
347 #line 137 "ftpcmd.y"
348
349 intmax_t i;
350 char *s;
351
352 #line 353 "ftpcmd.c"
353
354 };
355 typedef union YYSTYPE YYSTYPE;
356 # define YYSTYPE_IS_TRIVIAL 1
357 # define YYSTYPE_IS_DECLARED 1
358 #endif
359
360
361 extern YYSTYPE yylval;
362
363
364 int yyparse (void);
365
366
367
368 /* Symbol kind. */
369 enum yysymbol_kind_t
370 {
371 YYSYMBOL_YYEMPTY = -2,
372 YYSYMBOL_YYEOF = 0, /* "end of file" */
373 YYSYMBOL_YYerror = 1, /* error */
374 YYSYMBOL_YYUNDEF = 2, /* "invalid token" */
375 YYSYMBOL_A = 3, /* A */
376 YYSYMBOL_B = 4, /* B */
377 YYSYMBOL_C = 5, /* C */
378 YYSYMBOL_E = 6, /* E */
379 YYSYMBOL_F = 7, /* F */
380 YYSYMBOL_I = 8, /* I */
381 YYSYMBOL_L = 9, /* L */
382 YYSYMBOL_N = 10, /* N */
383 YYSYMBOL_P = 11, /* P */
384 YYSYMBOL_R = 12, /* R */
385 YYSYMBOL_S = 13, /* S */
386 YYSYMBOL_T = 14, /* T */
387 YYSYMBOL_SP = 15, /* SP */
388 YYSYMBOL_CRLF = 16, /* CRLF */
389 YYSYMBOL_COMMA = 17, /* COMMA */
390 YYSYMBOL_USER = 18, /* USER */
391 YYSYMBOL_PASS = 19, /* PASS */
392 YYSYMBOL_ACCT = 20, /* ACCT */
393 YYSYMBOL_REIN = 21, /* REIN */
394 YYSYMBOL_QUIT = 22, /* QUIT */
395 YYSYMBOL_PORT = 23, /* PORT */
396 YYSYMBOL_PASV = 24, /* PASV */
397 YYSYMBOL_TYPE = 25, /* TYPE */
398 YYSYMBOL_STRU = 26, /* STRU */
399 YYSYMBOL_MODE = 27, /* MODE */
400 YYSYMBOL_RETR = 28, /* RETR */
401 YYSYMBOL_STOR = 29, /* STOR */
402 YYSYMBOL_APPE = 30, /* APPE */
403 YYSYMBOL_MLFL = 31, /* MLFL */
404 YYSYMBOL_MAIL = 32, /* MAIL */
405 YYSYMBOL_MSND = 33, /* MSND */
406 YYSYMBOL_MSOM = 34, /* MSOM */
407 YYSYMBOL_MSAM = 35, /* MSAM */
408 YYSYMBOL_MRSQ = 36, /* MRSQ */
409 YYSYMBOL_MRCP = 37, /* MRCP */
410 YYSYMBOL_ALLO = 38, /* ALLO */
411 YYSYMBOL_REST = 39, /* REST */
412 YYSYMBOL_RNFR = 40, /* RNFR */
413 YYSYMBOL_RNTO = 41, /* RNTO */
414 YYSYMBOL_ABOR = 42, /* ABOR */
415 YYSYMBOL_DELE = 43, /* DELE */
416 YYSYMBOL_CWD = 44, /* CWD */
417 YYSYMBOL_LIST = 45, /* LIST */
418 YYSYMBOL_NLST = 46, /* NLST */
419 YYSYMBOL_SITE = 47, /* SITE */
420 YYSYMBOL_STAT = 48, /* STAT */
421 YYSYMBOL_HELP = 49, /* HELP */
422 YYSYMBOL_NOOP = 50, /* NOOP */
423 YYSYMBOL_MKD = 51, /* MKD */
424 YYSYMBOL_RMD = 52, /* RMD */
425 YYSYMBOL_PWD = 53, /* PWD */
426 YYSYMBOL_CDUP = 54, /* CDUP */
427 YYSYMBOL_STOU = 55, /* STOU */
428 YYSYMBOL_SMNT = 56, /* SMNT */
429 YYSYMBOL_SYST = 57, /* SYST */
430 YYSYMBOL_SIZE = 58, /* SIZE */
431 YYSYMBOL_MDTM = 59, /* MDTM */
432 YYSYMBOL_FEAT = 60, /* FEAT */
433 YYSYMBOL_OPTS = 61, /* OPTS */
434 YYSYMBOL_EPRT = 62, /* EPRT */
435 YYSYMBOL_EPSV = 63, /* EPSV */
436 YYSYMBOL_LPRT = 64, /* LPRT */
437 YYSYMBOL_LPSV = 65, /* LPSV */
438 YYSYMBOL_ADAT = 66, /* ADAT */
439 YYSYMBOL_AUTH = 67, /* AUTH */
440 YYSYMBOL_CCC = 68, /* CCC */
441 YYSYMBOL_CONF = 69, /* CONF */
442 YYSYMBOL_ENC = 70, /* ENC */
443 YYSYMBOL_MIC = 71, /* MIC */
444 YYSYMBOL_PBSZ = 72, /* PBSZ */
445 YYSYMBOL_PROT = 73, /* PROT */
446 YYSYMBOL_UMASK = 74, /* UMASK */
447 YYSYMBOL_IDLE = 75, /* IDLE */
448 YYSYMBOL_CHMOD = 76, /* CHMOD */
449 YYSYMBOL_LEXERR = 77, /* LEXERR */
450 YYSYMBOL_STRING = 78, /* STRING */
451 YYSYMBOL_NUMBER = 79, /* NUMBER */
452 YYSYMBOL_CHAR = 80, /* CHAR */
453 YYSYMBOL_YYACCEPT = 81, /* $accept */
454 YYSYMBOL_cmd_list = 82, /* cmd_list */
455 YYSYMBOL_cmd = 83, /* cmd */
456 YYSYMBOL_rcmd = 84, /* rcmd */
457 YYSYMBOL_username = 85, /* username */
458 YYSYMBOL_password = 86, /* password */
459 YYSYMBOL_byte_size = 87, /* byte_size */
460 YYSYMBOL_net_proto = 88, /* net_proto */
461 YYSYMBOL_tcp_port = 89, /* tcp_port */
462 YYSYMBOL_net_addr = 90, /* net_addr */
463 YYSYMBOL_host_port = 91, /* host_port */
464 YYSYMBOL_long_host_port = 92, /* long_host_port */
465 YYSYMBOL_form_code = 93, /* form_code */
466 YYSYMBOL_type_code = 94, /* type_code */
467 YYSYMBOL_struct_code = 95, /* struct_code */
468 YYSYMBOL_mode_code = 96, /* mode_code */
469 YYSYMBOL_pathname = 97, /* pathname */
470 YYSYMBOL_pathstring = 98, /* pathstring */
471 YYSYMBOL_octal_number = 99, /* octal_number */
472 YYSYMBOL_check_login = 100 /* check_login */
473 };
474 typedef enum yysymbol_kind_t yysymbol_kind_t;
475
476
477
478
479 #ifdef short
480 # undef short
481 #endif
482
483 /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
484 <limits.h> and (if available) <stdint.h> are included
485 so that the code can choose integer types of a good width. */
486
487 #ifndef __PTRDIFF_MAX__
488 # include <limits.h> /* INFRINGES ON USER NAME SPACE */
489 # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
490 # include <stdint.h> /* INFRINGES ON USER NAME SPACE */
491 # define YY_STDINT_H
492 # endif
493 #endif
494
495 /* Narrow types that promote to a signed type and that can represent a
496 signed or unsigned integer of at least N bits. In tables they can
497 save space and decrease cache pressure. Promoting to a signed type
498 helps avoid bugs in integer arithmetic. */
499
500 #ifdef __INT_LEAST8_MAX__
501 typedef __INT_LEAST8_TYPE__ yytype_int8;
502 #elif defined YY_STDINT_H
503 typedef int_least8_t yytype_int8;
504 #else
505 typedef signed char yytype_int8;
506 #endif
507
508 #ifdef __INT_LEAST16_MAX__
509 typedef __INT_LEAST16_TYPE__ yytype_int16;
510 #elif defined YY_STDINT_H
511 typedef int_least16_t yytype_int16;
512 #else
513 typedef short yytype_int16;
514 #endif
515
516 /* Work around bug in HP-UX 11.23, which defines these macros
517 incorrectly for preprocessor constants. This workaround can likely
518 be removed in 2023, as HPE has promised support for HP-UX 11.23
519 (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
520 <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>. */
521 #ifdef __hpux
522 # undef UINT_LEAST8_MAX
523 # undef UINT_LEAST16_MAX
524 # define UINT_LEAST8_MAX 255
525 # define UINT_LEAST16_MAX 65535
526 #endif
527
528 #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
529 typedef __UINT_LEAST8_TYPE__ yytype_uint8;
530 #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
531 && UINT_LEAST8_MAX <= INT_MAX)
532 typedef uint_least8_t yytype_uint8;
533 #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
534 typedef unsigned char yytype_uint8;
535 #else
536 typedef short yytype_uint8;
537 #endif
538
539 #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
540 typedef __UINT_LEAST16_TYPE__ yytype_uint16;
541 #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
542 && UINT_LEAST16_MAX <= INT_MAX)
543 typedef uint_least16_t yytype_uint16;
544 #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
545 typedef unsigned short yytype_uint16;
546 #else
547 typedef int yytype_uint16;
548 #endif
549
550 #ifndef YYPTRDIFF_T
551 # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
552 # define YYPTRDIFF_T __PTRDIFF_TYPE__
553 # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
554 # elif defined PTRDIFF_MAX
555 # ifndef ptrdiff_t
556 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
557 # endif
558 # define YYPTRDIFF_T ptrdiff_t
559 # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
560 # else
561 # define YYPTRDIFF_T long
562 # define YYPTRDIFF_MAXIMUM LONG_MAX
563 # endif
564 #endif
565
566 #ifndef YYSIZE_T
567 # ifdef __SIZE_TYPE__
568 # define YYSIZE_T __SIZE_TYPE__
569 # elif defined size_t
570 # define YYSIZE_T size_t
571 # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
572 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
573 # define YYSIZE_T size_t
574 # else
575 # define YYSIZE_T unsigned
576 # endif
577 #endif
578
579 #define YYSIZE_MAXIMUM \
580 YY_CAST (YYPTRDIFF_T, \
581 (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
582 ? YYPTRDIFF_MAXIMUM \
583 : YY_CAST (YYSIZE_T, -1)))
584
585 #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
586
587
588 /* Stored state numbers (used for stacks). */
589 typedef yytype_int16 yy_state_t;
590
591 /* State numbers in computations. */
592 typedef int yy_state_fast_t;
593
594 #ifndef YY_
595 # if defined YYENABLE_NLS && YYENABLE_NLS
596 # if ENABLE_NLS
597 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
598 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
599 # endif
600 # endif
601 # ifndef YY_
602 # define YY_(Msgid) Msgid
603 # endif
604 #endif
605
606
607 #ifndef YY_ATTRIBUTE_PURE
608 # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
609 # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
610 # else
611 # define YY_ATTRIBUTE_PURE
612 # endif
613 #endif
614
615 #ifndef YY_ATTRIBUTE_UNUSED
616 # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
617 # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
618 # else
619 # define YY_ATTRIBUTE_UNUSED
620 # endif
621 #endif
622
623 /* Suppress unused-variable warnings by "using" E. */
624 #if ! defined lint || defined __GNUC__
625 # define YY_USE(E) ((void) (E))
626 #else
627 # define YY_USE(E) /* empty */
628 #endif
629
630 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
631 #if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
632 # if __GNUC__ * 100 + __GNUC_MINOR__ < 407
633 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
634 _Pragma ("GCC diagnostic push") \
635 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")
636 # else
637 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
638 _Pragma ("GCC diagnostic push") \
639 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
640 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
641 # endif
642 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
643 _Pragma ("GCC diagnostic pop")
644 #else
645 # define YY_INITIAL_VALUE(Value) Value
646 #endif
647 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
648 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
649 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
650 #endif
651 #ifndef YY_INITIAL_VALUE
652 # define YY_INITIAL_VALUE(Value) /* Nothing. */
653 #endif
654
655 #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
656 # define YY_IGNORE_USELESS_CAST_BEGIN \
657 _Pragma ("GCC diagnostic push") \
658 _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
659 # define YY_IGNORE_USELESS_CAST_END \
660 _Pragma ("GCC diagnostic pop")
661 #endif
662 #ifndef YY_IGNORE_USELESS_CAST_BEGIN
663 # define YY_IGNORE_USELESS_CAST_BEGIN
664 # define YY_IGNORE_USELESS_CAST_END
665 #endif
666
667
668 #define YY_ASSERT(E) ((void) (0 && (E)))
669
670 #if !defined yyoverflow
671
672 /* The parser invokes alloca or malloc; define the necessary symbols. */
673
674 # ifdef YYSTACK_USE_ALLOCA
675 # if YYSTACK_USE_ALLOCA
676 # ifdef __GNUC__
677 # define YYSTACK_ALLOC __builtin_alloca
678 # elif defined __BUILTIN_VA_ARG_INCR
679 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
680 # elif defined _AIX
681 # define YYSTACK_ALLOC __alloca
682 # elif defined _MSC_VER
683 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
684 # define alloca _alloca
685 # else
686 # define YYSTACK_ALLOC alloca
687 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
688 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
689 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
690 # ifndef EXIT_SUCCESS
691 # define EXIT_SUCCESS 0
692 # endif
693 # endif
694 # endif
695 # endif
696 # endif
697
698 # ifdef YYSTACK_ALLOC
699 /* Pacify GCC's 'empty if-body' warning. */
700 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
701 # ifndef YYSTACK_ALLOC_MAXIMUM
702 /* The OS might guarantee only one guard page at the bottom of the stack,
703 and a page size can be as small as 4096 bytes. So we cannot safely
704 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
705 to allow for a few compiler-allocated temporary stack slots. */
706 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
707 # endif
708 # else
709 # define YYSTACK_ALLOC YYMALLOC
710 # define YYSTACK_FREE YYFREE
711 # ifndef YYSTACK_ALLOC_MAXIMUM
712 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
713 # endif
714 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
715 && ! ((defined YYMALLOC || defined malloc) \
716 && (defined YYFREE || defined free)))
717 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
718 # ifndef EXIT_SUCCESS
719 # define EXIT_SUCCESS 0
720 # endif
721 # endif
722 # ifndef YYMALLOC
723 # define YYMALLOC malloc
724 # if ! defined malloc && ! defined EXIT_SUCCESS
725 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
726 # endif
727 # endif
728 # ifndef YYFREE
729 # define YYFREE free
730 # if ! defined free && ! defined EXIT_SUCCESS
731 void free (void *); /* INFRINGES ON USER NAME SPACE */
732 # endif
733 # endif
734 # endif
735 #endif /* !defined yyoverflow */
736
737 #if (! defined yyoverflow \
738 && (! defined __cplusplus \
739 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
740
741 /* A type that is properly aligned for any stack member. */
742 union yyalloc
743 {
744 yy_state_t yyss_alloc;
745 YYSTYPE yyvs_alloc;
746 };
747
748 /* The size of the maximum gap between one aligned stack and the next. */
749 # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
750
751 /* The size of an array large to enough to hold all stacks, each with
752 N elements. */
753 # define YYSTACK_BYTES(N) \
754 ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
755 + YYSTACK_GAP_MAXIMUM)
756
757 # define YYCOPY_NEEDED 1
758
759 /* Relocate STACK from its old location to the new one. The
760 local variables YYSIZE and YYSTACKSIZE give the old and new number of
761 elements in the stack, and YYPTR gives the new location of the
762 stack. Advance YYPTR to a properly aligned location for the next
763 stack. */
764 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
765 do \
766 { \
767 YYPTRDIFF_T yynewbytes; \
768 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
769 Stack = &yyptr->Stack_alloc; \
770 yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
771 yyptr += yynewbytes / YYSIZEOF (*yyptr); \
772 } \
773 while (0)
774
775 #endif
776
777 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
778 /* Copy COUNT objects from SRC to DST. The source and destination do
779 not overlap. */
780 # ifndef YYCOPY
781 # if defined __GNUC__ && 1 < __GNUC__
782 # define YYCOPY(Dst, Src, Count) \
783 __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
784 # else
785 # define YYCOPY(Dst, Src, Count) \
786 do \
787 { \
788 YYPTRDIFF_T yyi; \
789 for (yyi = 0; yyi < (Count); yyi++) \
790 (Dst)[yyi] = (Src)[yyi]; \
791 } \
792 while (0)
793 # endif
794 # endif
795 #endif /* !YYCOPY_NEEDED */
796
797 /* YYFINAL -- State number of the termination state. */
798 #define YYFINAL 2
799 /* YYLAST -- Last index in YYTABLE. */
800 #define YYLAST 319
801
802 /* YYNTOKENS -- Number of terminals. */
803 #define YYNTOKENS 81
804 /* YYNNTS -- Number of nonterminals. */
805 #define YYNNTS 20
806 /* YYNRULES -- Number of rules. */
807 #define YYNRULES 89
808 /* YYNSTATES -- Number of states. */
809 #define YYNSTATES 290
810
811 /* YYMAXUTOK -- Last valid token kind. */
812 #define YYMAXUTOK 335
813
814
815 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
816 as returned by yylex, with out-of-bounds checking. */
817 #define YYTRANSLATE(YYX) \
818 (0 <= (YYX) && (YYX) <= YYMAXUTOK \
819 ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \
820 : YYSYMBOL_YYUNDEF)
821
822 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
823 as returned by yylex. */
824 static const yytype_int8 yytranslate[] =
825 {
826 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
827 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
828 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
829 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
830 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
831 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
832 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
833 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
834 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
835 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
836 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
837 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
838 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
839 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
840 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
841 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
842 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
843 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
844 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
845 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
846 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
847 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
848 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
849 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
850 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
851 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
852 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
853 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
854 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
855 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
856 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
857 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
858 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
859 75, 76, 77, 78, 79, 80
860 };
861
862 #if YYDEBUG
863 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
864 static const yytype_int16 yyrline[] =
865 {
866 0, 181, 181, 182, 188, 192, 197, 203, 242, 247,
867 281, 293, 305, 309, 313, 319, 325, 331, 336, 342,
868 347, 353, 359, 363, 369, 384, 388, 393, 399, 403,
869 421, 425, 431, 437, 442, 447, 460, 472, 479, 487,
870 491, 496, 507, 523, 537, 543, 561, 567, 611, 626,
871 654, 805, 810, 825, 866, 872, 877, 883, 898, 910,
872 915, 918, 922, 926, 939, 943, 947, 996, 1058, 1127,
873 1131, 1135, 1142, 1147, 1152, 1157, 1162, 1166, 1171, 1177,
874 1185, 1189, 1193, 1200, 1204, 1208, 1215, 1256, 1260, 1289
875 };
876 #endif
877
878 /** Accessing symbol of state STATE. */
879 #define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])
880
881 #if YYDEBUG || 0
882 /* The user-facing name of the symbol whose (internal) number is
883 YYSYMBOL. No bounds checking. */
884 static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED;
885
886 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
887 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
888 static const char *const yytname[] =
889 {
890 "\"end of file\"", "error", "\"invalid token\"", "A", "B", "C", "E",
891 "F", "I", "L", "N", "P", "R", "S", "T", "SP", "CRLF", "COMMA", "USER",
892 "PASS", "ACCT", "REIN", "QUIT", "PORT", "PASV", "TYPE", "STRU", "MODE",
893 "RETR", "STOR", "APPE", "MLFL", "MAIL", "MSND", "MSOM", "MSAM", "MRSQ",
894 "MRCP", "ALLO", "REST", "RNFR", "RNTO", "ABOR", "DELE", "CWD", "LIST",
895 "NLST", "SITE", "STAT", "HELP", "NOOP", "MKD", "RMD", "PWD", "CDUP",
896 "STOU", "SMNT", "SYST", "SIZE", "MDTM", "FEAT", "OPTS", "EPRT", "EPSV",
897 "LPRT", "LPSV", "ADAT", "AUTH", "CCC", "CONF", "ENC", "MIC", "PBSZ",
898 "PROT", "UMASK", "IDLE", "CHMOD", "LEXERR", "STRING", "NUMBER", "CHAR",
899 "$accept", "cmd_list", "cmd", "rcmd", "username", "password",
900 "byte_size", "net_proto", "tcp_port", "net_addr", "host_port",
901 "long_host_port", "form_code", "type_code", "struct_code", "mode_code",
902 "pathname", "pathstring", "octal_number", "check_login", YY_NULLPTR
903 };
904
905 static const char *
906 yysymbol_name (yysymbol_kind_t yysymbol)
907 {
908 return yytname[yysymbol];
909 }
910 #endif
911
912 #define YYPACT_NINF (-106)
913
914 #define yypact_value_is_default(Yyn) \
915 ((Yyn) == YYPACT_NINF)
916
917 #define YYTABLE_NINF (-1)
918
919 #define yytable_value_is_error(Yyn) \
920 0
921
922 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
923 STATE-NUM. */
924 static const yytype_int16 yypact[] =
925 {
926 -106, 41, -106, -3, 4, 7, 14, -106, -106, 16,
927 19, 24, -106, -106, -106, 33, 43, -106, -106, 58,
928 -106, -106, -106, -106, 61, 99, -1, 101, -106, -106,
929 -106, -106, -106, 116, -106, -106, -106, -106, -106, -106,
930 -106, -106, -106, -106, -106, 55, 56, -106, 123, 124,
931 69, 5, -2, 126, 127, 128, 60, 65, 130, 131,
932 -106, 132, 46, 93, 95, 48, -106, 133, 71, -106,
933 -106, 135, 136, 137, 138, 140, -106, 141, 142, 98,
934 103, 143, 105, 144, 145, -106, 146, -106, 147, 73,
935 -106, 149, 150, -106, -6, 151, -106, -106, -106, 152,
936 -106, -106, -106, 153, 82, 82, 82, 110, -106, 154,
937 82, 82, 82, 82, -106, 82, -106, 88, -106, 112,
938 -106, 155, -106, 82, 156, 82, 82, -106, -106, 82,
939 82, 82, 96, -106, 97, -106, 100, 94, -106, 104,
940 -106, -106, -106, 159, 161, 102, 102, 65, -106, -106,
941 -106, -106, -106, 162, -106, 163, 165, 170, -106, -106,
942 168, 169, 171, 172, 173, 174, 108, -106, 115, -106,
943 176, 177, 178, -106, 179, 180, 181, 182, 183, 184,
944 185, 94, -106, 186, 187, 189, 114, -106, -106, -106,
945 -106, -106, -106, -106, -106, -106, -106, 188, -106, -106,
946 -106, -106, -106, -106, 190, 129, -106, 134, 129, -106,
947 -106, -106, -106, -106, -106, -106, -106, 139, -106, 148,
948 -106, 192, 157, -106, -106, 191, 194, 196, 160, 195,
949 158, 198, -106, -106, 82, -106, 164, 166, 199, -106,
950 201, 167, 203, 175, -106, -106, 193, 197, 204, 202,
951 205, 200, -106, 206, 207, 208, 209, 210, -106, 211,
952 212, 213, 214, 215, 216, 217, 218, 222, 219, 223,
953 220, 224, 221, 225, 226, 230, 227, 231, 228, 232,
954 229, 233, 234, 235, 236, 238, 237, 239, 240, -106
955 };
956
957 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
958 Performed when YYTABLE does not specify something else to do. Zero
959 means the default is an error. */
960 static const yytype_int8 yydefact[] =
961 {
962 2, 0, 1, 0, 0, 0, 0, 89, 89, 0,
963 0, 0, 89, 89, 89, 0, 0, 89, 89, 0,
964 89, 89, 89, 89, 0, 89, 0, 0, 89, 89,
965 89, 89, 89, 0, 89, 89, 89, 89, 89, 89,
966 89, 89, 3, 4, 56, 0, 60, 55, 0, 0,
967 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
968 25, 0, 0, 0, 0, 0, 22, 0, 0, 28,
969 30, 0, 0, 0, 0, 0, 47, 0, 0, 0,
970 0, 0, 0, 0, 0, 59, 0, 61, 0, 0,
971 8, 72, 74, 76, 77, 0, 80, 82, 81, 0,
972 84, 85, 83, 0, 0, 0, 0, 0, 62, 0,
973 0, 0, 0, 0, 26, 0, 19, 0, 17, 0,
974 89, 89, 89, 0, 0, 0, 0, 33, 34, 0,
975 0, 0, 0, 35, 0, 37, 0, 0, 51, 0,
976 54, 5, 6, 0, 0, 0, 0, 0, 79, 9,
977 10, 11, 87, 0, 86, 0, 0, 0, 12, 58,
978 0, 0, 0, 0, 0, 0, 0, 39, 0, 44,
979 0, 0, 0, 29, 0, 0, 0, 0, 0, 0,
980 0, 0, 63, 0, 0, 0, 0, 7, 71, 69,
981 70, 73, 75, 78, 14, 15, 16, 0, 57, 24,
982 23, 27, 20, 18, 0, 0, 41, 0, 0, 21,
983 31, 32, 46, 48, 49, 36, 38, 0, 52, 0,
984 53, 0, 0, 40, 88, 0, 0, 0, 0, 0,
985 0, 0, 42, 45, 0, 65, 0, 0, 0, 13,
986 0, 0, 0, 0, 43, 64, 0, 0, 0, 0,
987 0, 0, 50, 0, 0, 0, 0, 0, 66, 0,
988 0, 0, 0, 0, 0, 67, 0, 0, 0, 0,
989 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
990 0, 0, 0, 0, 0, 0, 0, 0, 0, 68
991 };
992
993 /* YYPGOTO[NTERM-NUM]. */
994 static const yytype_int8 yypgoto[] =
995 {
996 -106, -106, -106, -106, -106, -106, -90, 34, -106, -106,
997 -106, -106, 77, -106, -106, -106, -105, -106, 18, 15
998 };
999
1000 /* YYDEFGOTO[NTERM-NUM]. */
1001 static const yytype_uint8 yydefgoto[] =
1002 {
1003 0, 1, 42, 43, 86, 88, 109, 183, 246, 236,
1004 144, 185, 191, 95, 99, 103, 153, 154, 225, 48
1005 };
1006
1007 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
1008 positive, shift that token. If negative, reduce the rule whose
1009 number is the opposite. If YYTABLE_NINF, syntax error. */
1010 static const yytype_int16 yytable[] =
1011 {
1012 155, 156, 100, 101, 148, 160, 161, 162, 163, 147,
1013 164, 102, 96, 44, 68, 69, 97, 98, 172, 45,
1014 174, 175, 46, 49, 176, 177, 178, 53, 54, 55,
1015 47, 50, 58, 59, 51, 61, 62, 63, 64, 52,
1016 67, 2, 3, 71, 72, 73, 74, 75, 56, 77,
1017 78, 79, 80, 81, 82, 83, 84, 193, 57, 4,
1018 5, 113, 114, 6, 7, 8, 9, 10, 11, 12,
1019 13, 14, 91, 108, 60, 92, 65, 93, 94, 15,
1020 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
1021 26, 27, 28, 29, 30, 31, 32, 119, 33, 34,
1022 35, 36, 37, 38, 39, 40, 41, 188, 115, 116,
1023 117, 118, 189, 132, 133, 66, 190, 70, 134, 135,
1024 137, 138, 120, 121, 122, 157, 158, 166, 167, 240,
1025 205, 206, 76, 85, 87, 168, 170, 171, 89, 107,
1026 90, 104, 105, 106, 108, 110, 111, 112, 123, 124,
1027 125, 126, 143, 127, 128, 129, 130, 131, 136, 139,
1028 152, 140, 141, 142, 145, 146, 165, 149, 150, 151,
1029 159, 169, 173, 182, 179, 180, 186, 187, 194, 195,
1030 181, 196, 197, 184, 198, 199, 204, 200, 201, 202,
1031 203, 207, 208, 221, 209, 210, 211, 212, 213, 214,
1032 215, 216, 218, 222, 219, 220, 223, 232, 224, 230,
1033 233, 234, 237, 226, 239, 217, 243, 244, 252, 228,
1034 247, 251, 253, 192, 256, 257, 227, 229, 260, 0,
1035 262, 0, 264, 0, 266, 0, 231, 238, 235, 268,
1036 270, 272, 274, 0, 241, 242, 245, 276, 278, 280,
1037 282, 0, 284, 0, 248, 286, 288, 0, 0, 0,
1038 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1039 0, 0, 0, 249, 0, 0, 250, 0, 0, 254,
1040 0, 0, 0, 0, 0, 255, 0, 0, 258, 259,
1041 0, 261, 0, 263, 0, 265, 0, 267, 269, 271,
1042 273, 0, 0, 0, 0, 275, 277, 279, 281, 0,
1043 0, 0, 0, 283, 0, 285, 287, 0, 0, 289
1044 };
1045
1046 static const yytype_int16 yycheck[] =
1047 {
1048 105, 106, 4, 5, 94, 110, 111, 112, 113, 15,
1049 115, 13, 7, 16, 15, 16, 11, 12, 123, 15,
1050 125, 126, 15, 8, 129, 130, 131, 12, 13, 14,
1051 16, 15, 17, 18, 15, 20, 21, 22, 23, 15,
1052 25, 0, 1, 28, 29, 30, 31, 32, 15, 34,
1053 35, 36, 37, 38, 39, 40, 41, 147, 15, 18,
1054 19, 15, 16, 22, 23, 24, 25, 26, 27, 28,
1055 29, 30, 3, 79, 16, 6, 15, 8, 9, 38,
1056 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
1057 49, 50, 51, 52, 53, 54, 55, 49, 57, 58,
1058 59, 60, 61, 62, 63, 64, 65, 5, 15, 16,
1059 15, 16, 10, 15, 16, 16, 14, 16, 15, 16,
1060 15, 16, 74, 75, 76, 15, 16, 15, 16, 234,
1061 15, 16, 16, 78, 78, 120, 121, 122, 15, 79,
1062 16, 15, 15, 15, 79, 15, 15, 15, 15, 78,
1063 15, 15, 79, 16, 16, 15, 15, 15, 15, 15,
1064 78, 16, 16, 16, 15, 15, 78, 16, 16, 16,
1065 16, 16, 16, 79, 78, 78, 17, 16, 16, 16,
1066 80, 16, 12, 79, 16, 16, 78, 16, 16, 16,
1067 16, 15, 15, 79, 16, 16, 16, 16, 16, 16,
1068 16, 16, 16, 15, 17, 16, 16, 16, 79, 17,
1069 16, 15, 17, 79, 16, 181, 17, 16, 16, 80,
1070 17, 17, 17, 146, 17, 17, 208, 79, 17, -1,
1071 17, -1, 17, -1, 17, -1, 79, 79, 78, 17,
1072 17, 17, 17, -1, 80, 79, 79, 17, 17, 17,
1073 17, -1, 17, -1, 79, 17, 17, -1, -1, -1,
1074 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1075 -1, -1, -1, 80, -1, -1, 79, -1, -1, 79,
1076 -1, -1, -1, -1, -1, 79, -1, -1, 79, 79,
1077 -1, 79, -1, 79, -1, 79, -1, 79, 79, 79,
1078 79, -1, -1, -1, -1, 79, 79, 79, 79, -1,
1079 -1, -1, -1, 79, -1, 79, 79, -1, -1, 79
1080 };
1081
1082 /* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
1083 state STATE-NUM. */
1084 static const yytype_int8 yystos[] =
1085 {
1086 0, 82, 0, 1, 18, 19, 22, 23, 24, 25,
1087 26, 27, 28, 29, 30, 38, 39, 40, 41, 42,
1088 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
1089 53, 54, 55, 57, 58, 59, 60, 61, 62, 63,
1090 64, 65, 83, 84, 16, 15, 15, 16, 100, 100,
1091 15, 15, 15, 100, 100, 100, 15, 15, 100, 100,
1092 16, 100, 100, 100, 100, 15, 16, 100, 15, 16,
1093 16, 100, 100, 100, 100, 100, 16, 100, 100, 100,
1094 100, 100, 100, 100, 100, 78, 85, 78, 86, 15,
1095 16, 3, 6, 8, 9, 94, 7, 11, 12, 95,
1096 4, 5, 13, 96, 15, 15, 15, 79, 79, 87,
1097 15, 15, 15, 15, 16, 15, 16, 15, 16, 49,
1098 74, 75, 76, 15, 78, 15, 15, 16, 16, 15,
1099 15, 15, 15, 16, 15, 16, 15, 15, 16, 15,
1100 16, 16, 16, 79, 91, 15, 15, 15, 87, 16,
1101 16, 16, 78, 97, 98, 97, 97, 15, 16, 16,
1102 97, 97, 97, 97, 97, 78, 15, 16, 100, 16,
1103 100, 100, 97, 16, 97, 97, 97, 97, 97, 78,
1104 78, 80, 79, 88, 79, 92, 17, 16, 5, 10,
1105 14, 93, 93, 87, 16, 16, 16, 12, 16, 16,
1106 16, 16, 16, 16, 78, 15, 16, 15, 15, 16,
1107 16, 16, 16, 16, 16, 16, 16, 88, 16, 17,
1108 16, 79, 15, 16, 79, 99, 79, 99, 80, 79,
1109 17, 79, 16, 16, 15, 78, 90, 17, 79, 16,
1110 97, 80, 79, 17, 16, 79, 89, 17, 79, 80,
1111 79, 17, 16, 17, 79, 79, 17, 17, 79, 79,
1112 17, 79, 17, 79, 17, 79, 17, 79, 17, 79,
1113 17, 79, 17, 79, 17, 79, 17, 79, 17, 79,
1114 17, 79, 17, 79, 17, 79, 17, 79, 17, 79
1115 };
1116
1117 /* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */
1118 static const yytype_int8 yyr1[] =
1119 {
1120 0, 81, 82, 82, 82, 83, 83, 83, 83, 83,
1121 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
1122 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
1123 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
1124 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
1125 83, 83, 83, 83, 83, 83, 83, 84, 84, 85,
1126 86, 86, 87, 88, 89, 90, 91, 92, 92, 93,
1127 93, 93, 94, 94, 94, 94, 94, 94, 94, 94,
1128 95, 95, 95, 96, 96, 96, 97, 98, 99, 100
1129 };
1130
1131 /* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */
1132 static const yytype_int8 yyr2[] =
1133 {
1134 0, 2, 0, 2, 2, 4, 4, 5, 3, 4,
1135 4, 4, 4, 8, 5, 5, 5, 3, 5, 3,
1136 5, 5, 2, 5, 5, 2, 3, 5, 2, 4,
1137 2, 5, 5, 3, 3, 3, 5, 3, 5, 4,
1138 6, 5, 7, 9, 4, 7, 5, 2, 5, 5,
1139 11, 3, 5, 5, 3, 2, 2, 5, 4, 1,
1140 0, 1, 1, 1, 1, 1, 11, 17, 41, 1,
1141 1, 1, 1, 3, 1, 3, 1, 1, 3, 2,
1142 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
1143 };
1144
1145
1146 enum { YYENOMEM = -2 };
1147
1148 #define yyerrok (yyerrstatus = 0)
1149 #define yyclearin (yychar = YYEMPTY)
1150
1151 #define YYACCEPT goto yyacceptlab
1152 #define YYABORT goto yyabortlab
1153 #define YYERROR goto yyerrorlab
1154 #define YYNOMEM goto yyexhaustedlab
1155
1156
1157 #define YYRECOVERING() (!!yyerrstatus)
1158
1159 #define YYBACKUP(Token, Value) \
1160 do \
1161 if (yychar == YYEMPTY) \
1162 { \
1163 yychar = (Token); \
1164 yylval = (Value); \
1165 YYPOPSTACK (yylen); \
1166 yystate = *yyssp; \
1167 goto yybackup; \
1168 } \
1169 else \
1170 { \
1171 yyerror (YY_("syntax error: cannot back up")); \
1172 YYERROR; \
1173 } \
1174 while (0)
1175
1176 /* Backward compatibility with an undocumented macro.
1177 Use YYerror or YYUNDEF. */
1178 #define YYERRCODE YYUNDEF
1179
1180
1181 /* Enable debugging if requested. */
1182 #if YYDEBUG
1183
1184 # ifndef YYFPRINTF
1185 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1186 # define YYFPRINTF fprintf
1187 # endif
1188
1189 # define YYDPRINTF(Args) \
1190 do { \
1191 if (yydebug) \
1192 YYFPRINTF Args; \
1193 } while (0)
1194
1195
1196
1197
1198 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
1199 do { \
1200 if (yydebug) \
1201 { \
1202 YYFPRINTF (stderr, "%s ", Title); \
1203 yy_symbol_print (stderr, \
1204 Kind, Value); \
1205 YYFPRINTF (stderr, "\n"); \
1206 } \
1207 } while (0)
1208
1209
1210 /*-----------------------------------.
1211 | Print this symbol's value on YYO. |
1212 `-----------------------------------*/
1213
1214 static void
1215 yy_symbol_value_print (FILE *yyo,
1216 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep)
1217 {
1218 FILE *yyoutput = yyo;
1219 YY_USE (yyoutput);
1220 if (!yyvaluep)
1221 return;
1222 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1223 YY_USE (yykind);
1224 YY_IGNORE_MAYBE_UNINITIALIZED_END
1225 }
1226
1227
1228 /*---------------------------.
1229 | Print this symbol on YYO. |
1230 `---------------------------*/
1231
1232 static void
1233 yy_symbol_print (FILE *yyo,
1234 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep)
1235 {
1236 YYFPRINTF (yyo, "%s %s (",
1237 yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
1238
1239 yy_symbol_value_print (yyo, yykind, yyvaluep);
1240 YYFPRINTF (yyo, ")");
1241 }
1242
1243 /*------------------------------------------------------------------.
1244 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1245 | TOP (included). |
1246 `------------------------------------------------------------------*/
1247
1248 static void
1249 yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
1250 {
1251 YYFPRINTF (stderr, "Stack now");
1252 for (; yybottom <= yytop; yybottom++)
1253 {
1254 int yybot = *yybottom;
1255 YYFPRINTF (stderr, " %d", yybot);
1256 }
1257 YYFPRINTF (stderr, "\n");
1258 }
1259
1260 # define YY_STACK_PRINT(Bottom, Top) \
1261 do { \
1262 if (yydebug) \
1263 yy_stack_print ((Bottom), (Top)); \
1264 } while (0)
1265
1266
1267 /*------------------------------------------------.
1268 | Report that the YYRULE is going to be reduced. |
1269 `------------------------------------------------*/
1270
1271 static void
1272 yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,
1273 int yyrule)
1274 {
1275 int yylno = yyrline[yyrule];
1276 int yynrhs = yyr2[yyrule];
1277 int yyi;
1278 YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
1279 yyrule - 1, yylno);
1280 /* The symbols being reduced. */
1281 for (yyi = 0; yyi < yynrhs; yyi++)
1282 {
1283 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1284 yy_symbol_print (stderr,
1285 YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
1286 &yyvsp[(yyi + 1) - (yynrhs)]);
1287 YYFPRINTF (stderr, "\n");
1288 }
1289 }
1290
1291 # define YY_REDUCE_PRINT(Rule) \
1292 do { \
1293 if (yydebug) \
1294 yy_reduce_print (yyssp, yyvsp, Rule); \
1295 } while (0)
1296
1297 /* Nonzero means print parse trace. It is left uninitialized so that
1298 multiple parsers can coexist. */
1299 int yydebug;
1300 #else /* !YYDEBUG */
1301 # define YYDPRINTF(Args) ((void) 0)
1302 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
1303 # define YY_STACK_PRINT(Bottom, Top)
1304 # define YY_REDUCE_PRINT(Rule)
1305 #endif /* !YYDEBUG */
1306
1307
1308 /* YYINITDEPTH -- initial size of the parser's stacks. */
1309 #ifndef YYINITDEPTH
1310 # define YYINITDEPTH 200
1311 #endif
1312
1313 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1314 if the built-in stack extension method is used).
1315
1316 Do not make this value too large; the results are undefined if
1317 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1318 evaluated with infinite-precision integer arithmetic. */
1319
1320 #ifndef YYMAXDEPTH
1321 # define YYMAXDEPTH 10000
1322 #endif
1323
1324
1325
1326
1327
1328
1329 /*-----------------------------------------------.
1330 | Release the memory associated to this symbol. |
1331 `-----------------------------------------------*/
1332
1333 static void
1334 yydestruct (const char *yymsg,
1335 yysymbol_kind_t yykind, YYSTYPE *yyvaluep)
1336 {
1337 YY_USE (yyvaluep);
1338 if (!yymsg)
1339 yymsg = "Deleting";
1340 YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
1341
1342 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1343 YY_USE (yykind);
1344 YY_IGNORE_MAYBE_UNINITIALIZED_END
1345 }
1346
1347
1348 /* Lookahead token kind. */
1349 int yychar;
1350
1351 /* The semantic value of the lookahead symbol. */
1352 YYSTYPE yylval;
1353 /* Number of syntax errors so far. */
1354 int yynerrs;
1355
1356
1357
1358
1359 /*----------.
1360 | yyparse. |
1361 `----------*/
1362
1363 int
1364 yyparse (void)
1365 {
1366 yy_state_fast_t yystate = 0;
1367 /* Number of tokens to shift before error messages enabled. */
1368 int yyerrstatus = 0;
1369
1370 /* Refer to the stacks through separate pointers, to allow yyoverflow
1371 to reallocate them elsewhere. */
1372
1373 /* Their size. */
1374 YYPTRDIFF_T yystacksize = YYINITDEPTH;
1375
1376 /* The state stack: array, bottom, top. */
1377 yy_state_t yyssa[YYINITDEPTH];
1378 yy_state_t *yyss = yyssa;
1379 yy_state_t *yyssp = yyss;
1380
1381 /* The semantic value stack: array, bottom, top. */
1382 YYSTYPE yyvsa[YYINITDEPTH];
1383 YYSTYPE *yyvs = yyvsa;
1384 YYSTYPE *yyvsp = yyvs;
1385
1386 int yyn;
1387 /* The return value of yyparse. */
1388 int yyresult;
1389 /* Lookahead symbol kind. */
1390 yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
1391 /* The variables used to return semantic value and location from the
1392 action routines. */
1393 YYSTYPE yyval;
1394
1395
1396
1397 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1398
1399 /* The number of symbols on the RHS of the reduced rule.
1400 Keep to zero when no symbol should be popped. */
1401 int yylen = 0;
1402
1403 YYDPRINTF ((stderr, "Starting parse\n"));
1404
1405 yychar = YYEMPTY; /* Cause a token to be read. */
1406
1407 goto yysetstate;
1408
1409
1410 /*------------------------------------------------------------.
1411 | yynewstate -- push a new state, which is found in yystate. |
1412 `------------------------------------------------------------*/
1413 yynewstate:
1414 /* In all cases, when you get here, the value and location stacks
1415 have just been pushed. So pushing a state here evens the stacks. */
1416 yyssp++;
1417
1418
1419 /*--------------------------------------------------------------------.
1420 | yysetstate -- set current state (the top of the stack) to yystate. |
1421 `--------------------------------------------------------------------*/
1422 yysetstate:
1423 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1424 YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
1425 YY_IGNORE_USELESS_CAST_BEGIN
1426 *yyssp = YY_CAST (yy_state_t, yystate);
1427 YY_IGNORE_USELESS_CAST_END
1428 YY_STACK_PRINT (yyss, yyssp);
1429
1430 if (yyss + yystacksize - 1 <= yyssp)
1431 #if !defined yyoverflow && !defined YYSTACK_RELOCATE
1432 YYNOMEM;
1433 #else
1434 {
1435 /* Get the current used size of the three stacks, in elements. */
1436 YYPTRDIFF_T yysize = yyssp - yyss + 1;
1437
1438 # if defined yyoverflow
1439 {
1440 /* Give user a chance to reallocate the stack. Use copies of
1441 these so that the &'s don't force the real ones into
1442 memory. */
1443 yy_state_t *yyss1 = yyss;
1444 YYSTYPE *yyvs1 = yyvs;
1445
1446 /* Each stack pointer address is followed by the size of the
1447 data in use in that stack, in bytes. This used to be a
1448 conditional around just the two extra args, but that might
1449 be undefined if yyoverflow is a macro. */
1450 yyoverflow (YY_("memory exhausted"),
1451 &yyss1, yysize * YYSIZEOF (*yyssp),
1452 &yyvs1, yysize * YYSIZEOF (*yyvsp),
1453 &yystacksize);
1454 yyss = yyss1;
1455 yyvs = yyvs1;
1456 }
1457 # else /* defined YYSTACK_RELOCATE */
1458 /* Extend the stack our own way. */
1459 if (YYMAXDEPTH <= yystacksize)
1460 YYNOMEM;
1461 yystacksize *= 2;
1462 if (YYMAXDEPTH < yystacksize)
1463 yystacksize = YYMAXDEPTH;
1464
1465 {
1466 yy_state_t *yyss1 = yyss;
1467 union yyalloc *yyptr =
1468 YY_CAST (union yyalloc *,
1469 YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
1470 if (! yyptr)
1471 YYNOMEM;
1472 YYSTACK_RELOCATE (yyss_alloc, yyss);
1473 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1474 # undef YYSTACK_RELOCATE
1475 if (yyss1 != yyssa)
1476 YYSTACK_FREE (yyss1);
1477 }
1478 # endif
1479
1480 yyssp = yyss + yysize - 1;
1481 yyvsp = yyvs + yysize - 1;
1482
1483 YY_IGNORE_USELESS_CAST_BEGIN
1484 YYDPRINTF ((stderr, "Stack size increased to %ld\n",
1485 YY_CAST (long, yystacksize)));
1486 YY_IGNORE_USELESS_CAST_END
1487
1488 if (yyss + yystacksize - 1 <= yyssp)
1489 YYABORT;
1490 }
1491 #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1492
1493
1494 if (yystate == YYFINAL)
1495 YYACCEPT;
1496
1497 goto yybackup;
1498
1499
1500 /*-----------.
1501 | yybackup. |
1502 `-----------*/
1503 yybackup:
1504 /* Do appropriate processing given the current state. Read a
1505 lookahead token if we need one and don't already have one. */
1506
1507 /* First try to decide what to do without reference to lookahead token. */
1508 yyn = yypact[yystate];
1509 if (yypact_value_is_default (yyn))
1510 goto yydefault;
1511
1512 /* Not known => get a lookahead token if don't already have one. */
1513
1514 /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */
1515 if (yychar == YYEMPTY)
1516 {
1517 YYDPRINTF ((stderr, "Reading a token\n"));
1518 yychar = yylex ();
1519 }
1520
1521 if (yychar <= YYEOF)
1522 {
1523 yychar = YYEOF;
1524 yytoken = YYSYMBOL_YYEOF;
1525 YYDPRINTF ((stderr, "Now at end of input.\n"));
1526 }
1527 else if (yychar == YYerror)
1528 {
1529 /* The scanner already issued an error message, process directly
1530 to error recovery. But do not keep the error token as
1531 lookahead, it is too special and may lead us to an endless
1532 loop in error recovery. */
1533 yychar = YYUNDEF;
1534 yytoken = YYSYMBOL_YYerror;
1535 goto yyerrlab1;
1536 }
1537 else
1538 {
1539 yytoken = YYTRANSLATE (yychar);
1540 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1541 }
1542
1543 /* If the proper action on seeing token YYTOKEN is to reduce or to
1544 detect an error, take that action. */
1545 yyn += yytoken;
1546 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1547 goto yydefault;
1548 yyn = yytable[yyn];
1549 if (yyn <= 0)
1550 {
1551 if (yytable_value_is_error (yyn))
1552 goto yyerrlab;
1553 yyn = -yyn;
1554 goto yyreduce;
1555 }
1556
1557 /* Count tokens shifted since error; after three, turn off error
1558 status. */
1559 if (yyerrstatus)
1560 yyerrstatus--;
1561
1562 /* Shift the lookahead token. */
1563 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1564 yystate = yyn;
1565 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1566 *++yyvsp = yylval;
1567 YY_IGNORE_MAYBE_UNINITIALIZED_END
1568
1569 /* Discard the shifted token. */
1570 yychar = YYEMPTY;
1571 goto yynewstate;
1572
1573
1574 /*-----------------------------------------------------------.
1575 | yydefault -- do the default action for the current state. |
1576 `-----------------------------------------------------------*/
1577 yydefault:
1578 yyn = yydefact[yystate];
1579 if (yyn == 0)
1580 goto yyerrlab;
1581 goto yyreduce;
1582
1583
1584 /*-----------------------------.
1585 | yyreduce -- do a reduction. |
1586 `-----------------------------*/
1587 yyreduce:
1588 /* yyn is the number of a rule to reduce with. */
1589 yylen = yyr2[yyn];
1590
1591 /* If YYLEN is nonzero, implement the default value of the action:
1592 '$$ = $1'.
1593
1594 Otherwise, the following line sets YYVAL to garbage.
1595 This behavior is undocumented and Bison
1596 users should not rely upon it. Assigning to YYVAL
1597 unconditionally makes the parser a bit smaller, and it avoids a
1598 GCC warning that YYVAL may be used uninitialized. */
1599 yyval = yyvsp[1-yylen];
1600
1601
1602 YY_REDUCE_PRINT (yyn);
1603 switch (yyn)
1604 {
1605 case 3: /* cmd_list: cmd_list cmd */
1606 #line 183 "ftpcmd.y"
1607 {
1608 free (fromname);
1609 fromname = (char *) 0;
1610 restart_point = (off_t) 0;
1611 }
1612 #line 1613 "ftpcmd.c"
1613 break;
1614
1615 case 5: /* cmd: USER SP username CRLF */
1616 #line 193 "ftpcmd.y"
1617 {
1618 user ((yyvsp[-1].s));
1619 free ((yyvsp[-1].s));
1620 }
1621 #line 1622 "ftpcmd.c"
1622 break;
1623
1624 case 6: /* cmd: PASS SP password CRLF */
1625 #line 198 "ftpcmd.y"
1626 {
1627 pass ((yyvsp[-1].s));
1628 memset ((yyvsp[-1].s), 0, strlen ((yyvsp[-1].s)));
1629 free ((yyvsp[-1].s));
1630 }
1631 #line 1632 "ftpcmd.c"
1632 break;
1633
1634 case 7: /* cmd: PORT check_login SP host_port CRLF */
1635 #line 204 "ftpcmd.y"
1636 {
1637 if ((yyvsp[-3].i))
1638 {
1639 if ((yyvsp[-1].i)
1640 && ((his_addr.ss_family == AF_INET
1641 && memcmp (&((struct sockaddr_in *) &his_addr)->sin_addr,
1642 &((struct sockaddr_in *) &data_dest)->sin_addr,
1643 sizeof (struct in_addr))
1644 == 0
1645 && ntohs (((struct sockaddr_in *) &data_dest)->sin_port)
1646 > IPPORT_RESERVED)
1647 ||
1648 (his_addr.ss_family == AF_INET6
1649 && memcmp (&((struct sockaddr_in6 *) &his_addr)->sin6_addr,
1650 &((struct sockaddr_in6 *) &data_dest)->sin6_addr,
1651 sizeof (struct in6_addr))
1652 == 0
1653 && ntohs (((struct sockaddr_in6 *) &data_dest)->sin6_port)
1654 > IPPORT_RESERVED)
1655 )
1656 )
1657 {
1658 usedefault = 0;
1659 if (pdata >= 0)
1660 {
1661 close (pdata);
1662 pdata = -1;
1663 }
1664 reply (200, "PORT command successful.");
1665 }
1666 else
1667 {
1668 usedefault = 1;
1669 memset (&data_dest, 0, sizeof (data_dest));
1670 reply (500, "Illegal PORT Command");
1671 }
1672 }
1673 }
1674 #line 1675 "ftpcmd.c"
1675 break;
1676
1677 case 8: /* cmd: PASV check_login CRLF */
1678 #line 243 "ftpcmd.y"
1679 {
1680 if ((yyvsp[-1].i))
1681 passive (PASSIVE_PASV, AF_INET);
1682 }
1683 #line 1684 "ftpcmd.c"
1684 break;
1685
1686 case 9: /* cmd: TYPE SP type_code CRLF */
1687 #line 248 "ftpcmd.y"
1688 {
1689 switch (cmd_type)
1690 {
1691 case TYPE_A:
1692 if (cmd_form == FORM_N)
1693 {
1694 reply (200, "Type set to A.");
1695 type = cmd_type;
1696 form = cmd_form;
1697 }
1698 else
1699 reply (504, "Form must be N.");
1700 break;
1701
1702 case TYPE_E:
1703 reply (504, "Type E not implemented.");
1704 break;
1705
1706 case TYPE_I:
1707 reply (200, "Type set to I.");
1708 type = cmd_type;
1709 break;
1710
1711 case TYPE_L:
1712 if (cmd_bytesz == 8)
1713 {
1714 reply (200, "Type set to L (byte size 8).");
1715 type = cmd_type;
1716 }
1717 else
1718 reply (504, "Byte size must be 8.");
1719 }
1720 }
1721 #line 1722 "ftpcmd.c"
1722 break;
1723
1724 case 10: /* cmd: STRU SP struct_code CRLF */
1725 #line 282 "ftpcmd.y"
1726 {
1727 switch ((yyvsp[-1].i))
1728 {
1729 case STRU_F:
1730 reply (200, "STRU F ok.");
1731 break;
1732
1733 default:
1734 reply (504, "Unimplemented STRU type.");
1735 }
1736 }
1737 #line 1738 "ftpcmd.c"
1738 break;
1739
1740 case 11: /* cmd: MODE SP mode_code CRLF */
1741 #line 294 "ftpcmd.y"
1742 {
1743 switch ((yyvsp[-1].i))
1744 {
1745 case MODE_S:
1746 reply (200, "MODE S ok.");
1747 break;
1748
1749 default:
1750 reply (502, "Unimplemented MODE type.");
1751 }
1752 }
1753 #line 1754 "ftpcmd.c"
1754 break;
1755
1756 case 12: /* cmd: ALLO SP NUMBER CRLF */
1757 #line 306 "ftpcmd.y"
1758 {
1759 reply (202, "ALLO command ignored.");
1760 }
1761 #line 1762 "ftpcmd.c"
1762 break;
1763
1764 case 13: /* cmd: ALLO SP NUMBER SP R SP NUMBER CRLF */
1765 #line 310 "ftpcmd.y"
1766 {
1767 reply (202, "ALLO command ignored.");
1768 }
1769 #line 1770 "ftpcmd.c"
1770 break;
1771
1772 case 14: /* cmd: RETR check_login SP pathname CRLF */
1773 #line 314 "ftpcmd.y"
1774 {
1775 if ((yyvsp[-3].i) && (yyvsp[-1].s) != NULL)
1776 retrieve ((char *) 0, (yyvsp[-1].s));
1777 free ((yyvsp[-1].s));
1778 }
1779 #line 1780 "ftpcmd.c"
1780 break;
1781
1782 case 15: /* cmd: STOR check_login SP pathname CRLF */
1783 #line 320 "ftpcmd.y"
1784 {
1785 if ((yyvsp[-3].i) && (yyvsp[-1].s) != NULL)
1786 store ((yyvsp[-1].s), "w", 0);
1787 free ((yyvsp[-1].s));
1788 }
1789 #line 1790 "ftpcmd.c"
1790 break;
1791
1792 case 16: /* cmd: APPE check_login SP pathname CRLF */
1793 #line 326 "ftpcmd.y"
1794 {
1795 if ((yyvsp[-3].i) && (yyvsp[-1].s) != NULL)
1796 store ((yyvsp[-1].s), "a", 0);
1797 free ((yyvsp[-1].s));
1798 }
1799 #line 1800 "ftpcmd.c"
1800 break;
1801
1802 case 17: /* cmd: NLST check_login CRLF */
1803 #line 332 "ftpcmd.y"
1804 {
1805 if ((yyvsp[-1].i))
1806 send_file_list (".");
1807 }
1808 #line 1809 "ftpcmd.c"
1809 break;
1810
1811 case 18: /* cmd: NLST check_login SP STRING CRLF */
1812 #line 337 "ftpcmd.y"
1813 {
1814 if ((yyvsp[-3].i) && (yyvsp[-1].s) != NULL)
1815 send_file_list ((yyvsp[-1].s));
1816 free ((yyvsp[-1].s));
1817 }
1818 #line 1819 "ftpcmd.c"
1819 break;
1820
1821 case 19: /* cmd: LIST check_login CRLF */
1822 #line 343 "ftpcmd.y"
1823 {
1824 if ((yyvsp[-1].i))
1825 retrieve ("/bin/ls -lgA", "");
1826 }
1827 #line 1828 "ftpcmd.c"
1828 break;
1829
1830 case 20: /* cmd: LIST check_login SP pathname CRLF */
1831 #line 348 "ftpcmd.y"
1832 {
1833 if ((yyvsp[-3].i) && (yyvsp[-1].s) != NULL)
1834 retrieve ("/bin/ls -lgA %s", (yyvsp[-1].s));
1835 free ((yyvsp[-1].s));
1836 }
1837 #line 1838 "ftpcmd.c"
1838 break;
1839
1840 case 21: /* cmd: STAT check_login SP pathname CRLF */
1841 #line 354 "ftpcmd.y"
1842 {
1843 if ((yyvsp[-3].i) && (yyvsp[-1].s) != NULL)
1844 statfilecmd ((yyvsp[-1].s));
1845 free ((yyvsp[-1].s));
1846 }
1847 #line 1848 "ftpcmd.c"
1848 break;
1849
1850 case 22: /* cmd: STAT CRLF */
1851 #line 360 "ftpcmd.y"
1852 {
1853 statcmd ();
1854 }
1855 #line 1856 "ftpcmd.c"
1856 break;
1857
1858 case 23: /* cmd: DELE check_login SP pathname CRLF */
1859 #line 364 "ftpcmd.y"
1860 {
1861 if ((yyvsp[-3].i) && (yyvsp[-1].s) != NULL)
1862 delete ((yyvsp[-1].s));
1863 free ((yyvsp[-1].s));
1864 }
1865 #line 1866 "ftpcmd.c"
1866 break;
1867
1868 case 24: /* cmd: RNTO check_login SP pathname CRLF */
1869 #line 370 "ftpcmd.y"
1870 {
1871 if ((yyvsp[-3].i))
1872 {
1873 if (fromname)
1874 {
1875 renamecmd (fromname, (yyvsp[-1].s));
1876 free (fromname);
1877 fromname = (char *) 0;
1878 }
1879 else
1880 reply (503, "Bad sequence of commands.");
1881 }
1882 free ((yyvsp[-1].s));
1883 }
1884 #line 1885 "ftpcmd.c"
1885 break;
1886
1887 case 25: /* cmd: ABOR CRLF */
1888 #line 385 "ftpcmd.y"
1889 {
1890 reply (225, "ABOR command successful.");
1891 }
1892 #line 1893 "ftpcmd.c"
1893 break;
1894
1895 case 26: /* cmd: CWD check_login CRLF */
1896 #line 389 "ftpcmd.y"
1897 {
1898 if ((yyvsp[-1].i))
1899 cwd (cred.homedir);
1900 }
1901 #line 1902 "ftpcmd.c"
1902 break;
1903
1904 case 27: /* cmd: CWD check_login SP pathname CRLF */
1905 #line 394 "ftpcmd.y"
1906 {
1907 if ((yyvsp[-3].i) && (yyvsp[-1].s) != NULL)
1908 cwd ((yyvsp[-1].s));
1909 free ((yyvsp[-1].s));
1910 }
1911 #line 1912 "ftpcmd.c"
1912 break;
1913
1914 case 28: /* cmd: HELP CRLF */
1915 #line 400 "ftpcmd.y"
1916 {
1917 help (cmdtab, (char *) 0);
1918 }
1919 #line 1920 "ftpcmd.c"
1920 break;
1921
1922 case 29: /* cmd: HELP SP STRING CRLF */
1923 #line 404 "ftpcmd.y"
1924 {
1925 char *cp = (yyvsp[-1].s);
1926
1927 if (strncasecmp (cp, "SITE", 4) == 0)
1928 {
1929 cp = (yyvsp[-1].s) + 4;
1930 if (*cp == ' ')
1931 cp++;
1932 if (*cp)
1933 help (sitetab, cp);
1934 else
1935 help (sitetab, (char *) 0);
1936 }
1937 else
1938 help (cmdtab, (yyvsp[-1].s));
1939 free ((yyvsp[-1].s));
1940 }
1941 #line 1942 "ftpcmd.c"
1942 break;
1943
1944 case 30: /* cmd: NOOP CRLF */
1945 #line 422 "ftpcmd.y"
1946 {
1947 reply (200, "NOOP command successful.");
1948 }
1949 #line 1950 "ftpcmd.c"
1950 break;
1951
1952 case 31: /* cmd: MKD check_login SP pathname CRLF */
1953 #line 426 "ftpcmd.y"
1954 {
1955 if ((yyvsp[-3].i) && (yyvsp[-1].s) != NULL)
1956 makedir ((yyvsp[-1].s));
1957 free ((yyvsp[-1].s));
1958 }
1959 #line 1960 "ftpcmd.c"
1960 break;
1961
1962 case 32: /* cmd: RMD check_login SP pathname CRLF */
1963 #line 432 "ftpcmd.y"
1964 {
1965 if ((yyvsp[-3].i) && (yyvsp[-1].s) != NULL)
1966 removedir ((yyvsp[-1].s));
1967 free ((yyvsp[-1].s));
1968 }
1969 #line 1970 "ftpcmd.c"
1970 break;
1971
1972 case 33: /* cmd: PWD check_login CRLF */
1973 #line 438 "ftpcmd.y"
1974 {
1975 if ((yyvsp[-1].i))
1976 pwd ();
1977 }
1978 #line 1979 "ftpcmd.c"
1979 break;
1980
1981 case 34: /* cmd: CDUP check_login CRLF */
1982 #line 443 "ftpcmd.y"
1983 {
1984 if ((yyvsp[-1].i))
1985 cwd ("..");
1986 }
1987 #line 1988 "ftpcmd.c"
1988 break;
1989
1990 case 35: /* cmd: FEAT check_login CRLF */
1991 #line 448 "ftpcmd.y"
1992 {
1993 if ((yyvsp[-1].i))
1994 {
1995 char **name;
1996
1997 lreply (211, "Supported extensions:");
1998 for (name = extlist; *name; name++)
1999 printf (" %s\r\n", *name);
2000 reply (211, "End");
2001 }
2002 }
2003 #line 2004 "ftpcmd.c"
2004 break;
2005
2006 case 36: /* cmd: FEAT check_login SP STRING CRLF */
2007 #line 461 "ftpcmd.y"
2008 {
2009 if ((yyvsp[-3].i))
2010 {
2011 reply (501, "Not accepting arguments.");
2012 free ((yyvsp[-1].s));
2013 }
2014 }
2015 #line 2016 "ftpcmd.c"
2016 break;
2017
2018 case 37: /* cmd: OPTS check_login CRLF */
2019 #line 473 "ftpcmd.y"
2020 {
2021 if ((yyvsp[-1].i))
2022 {
2023 reply (501, "Must have an argument.");
2024 }
2025 }
2026 #line 2027 "ftpcmd.c"
2027 break;
2028
2029 case 38: /* cmd: OPTS check_login SP STRING CRLF */
2030 #line 480 "ftpcmd.y"
2031 {
2032 if ((yyvsp[-3].i))
2033 {
2034 reply (501, "No options are available.");
2035 free ((yyvsp[-1].s));
2036 }
2037 }
2038 #line 2039 "ftpcmd.c"
2039 break;
2040
2041 case 39: /* cmd: SITE SP HELP CRLF */
2042 #line 488 "ftpcmd.y"
2043 {
2044 help (sitetab, (char *) 0);
2045 }
2046 #line 2047 "ftpcmd.c"
2047 break;
2048
2049 case 40: /* cmd: SITE SP HELP SP STRING CRLF */
2050 #line 492 "ftpcmd.y"
2051 {
2052 help (sitetab, (yyvsp[-1].s));
2053 free ((yyvsp[-1].s));
2054 }
2055 #line 2056 "ftpcmd.c"
2056 break;
2057
2058 case 41: /* cmd: SITE SP UMASK check_login CRLF */
2059 #line 497 "ftpcmd.y"
2060 {
2061 int oldmask;
2062
2063 if ((yyvsp[-1].i))
2064 {
2065 oldmask = umask (0);
2066 umask (oldmask);
2067 reply (200, "Current UMASK is %03o", oldmask);
2068 }
2069 }
2070 #line 2071 "ftpcmd.c"
2071 break;
2072
2073 case 42: /* cmd: SITE SP UMASK check_login SP octal_number CRLF */
2074 #line 508 "ftpcmd.y"
2075 {
2076 int oldmask;
2077
2078 if ((yyvsp[-3].i))
2079 {
2080 if (((yyvsp[-1].i) == -1) || ((yyvsp[-1].i) > 0777))
2081 reply (501, "Bad UMASK value");
2082 else
2083 {
2084 oldmask = umask ((yyvsp[-1].i));
2085 reply (200, "UMASK set to %03o (was %03o)",
2086 (yyvsp[-1].i), oldmask);
2087 }
2088 }
2089 }
2090 #line 2091 "ftpcmd.c"
2091 break;
2092
2093 case 43: /* cmd: SITE SP CHMOD check_login SP octal_number SP pathname CRLF */
2094 #line 524 "ftpcmd.y"
2095 {
2096 if ((yyvsp[-5].i) && ((yyvsp[-1].s) != NULL))
2097 {
2098 if ((yyvsp[-3].i) > 0777)
2099 reply (501,
2100 "CHMOD: Mode value must be between 0 and 0777");
2101 else if (chmod ((yyvsp[-1].s), (yyvsp[-3].i)) < 0)
2102 perror_reply (550, (yyvsp[-1].s));
2103 else
2104 reply (200, "CHMOD command successful.");
2105 }
2106 free ((yyvsp[-1].s));
2107 }
2108 #line 2109 "ftpcmd.c"
2109 break;
2110
2111 case 44: /* cmd: SITE SP IDLE CRLF */
2112 #line 538 "ftpcmd.y"
2113 {
2114 reply (200,
2115 "Current IDLE time limit is %d seconds; max %d",
2116 timeout, maxtimeout);
2117 }
2118 #line 2119 "ftpcmd.c"
2119 break;
2120
2121 case 45: /* cmd: SITE SP IDLE check_login SP NUMBER CRLF */
2122 #line 544 "ftpcmd.y"
2123 {
2124 if ((yyvsp[-3].i))
2125 {
2126 if ((yyvsp[-1].i) < 30 || (yyvsp[-1].i) > maxtimeout)
2127 reply (501,
2128 "Maximum IDLE time must be between 30 and %d seconds",
2129 maxtimeout);
2130 else
2131 {
2132 timeout = (yyvsp[-1].i);
2133 alarm ((unsigned) timeout);
2134 reply (200,
2135 "Maximum IDLE time set to %d seconds",
2136 timeout);
2137 }
2138 }
2139 }
2140 #line 2141 "ftpcmd.c"
2141 break;
2142
2143 case 46: /* cmd: STOU check_login SP pathname CRLF */
2144 #line 562 "ftpcmd.y"
2145 {
2146 if ((yyvsp[-3].i) && (yyvsp[-1].s) != NULL)
2147 store ((yyvsp[-1].s), "w", 1);
2148 free ((yyvsp[-1].s));
2149 }
2150 #line 2151 "ftpcmd.c"
2151 break;
2152
2153 case 47: /* cmd: SYST CRLF */
2154 #line 568 "ftpcmd.y"
2155 {
2156 const char *sys_type; /* Official rfc-defined os type. */
2157 char *version = 0; /* A more specific type. */
2158
2159 #ifdef HAVE_UNAME
2160 struct utsname u;
2161
2162 if (uname (&u) >= 0)
2163 {
2164 version = malloc (strlen (u.sysname) + 1
2165 + strlen (u.release) + 1);
2166 if (version)
2167 sprintf (version, "%s %s", u.sysname, u.release);
2168 }
2169 #else /* !HAVE_UNAME */
2170 # ifdef BSD
2171 version = "BSD";
2172 # endif /* BSD */
2173 #endif /* !HAVE_UNAME */
2174
2175 #if defined unix || defined __unix || defined __unix__
2176 sys_type = "UNIX";
2177 #else
2178 sys_type = "UNKNOWN";
2179 #endif
2180
2181 if (!no_version && version)
2182 reply (215, "%s Type: L%d Version: %s",
2183 sys_type, CHAR_BIT, version);
2184 else
2185 reply (215, "%s Type: L%d", sys_type, CHAR_BIT);
2186
2187 #ifdef HAVE_UNAME
2188 free (version);
2189 #endif
2190 }
2191 #line 2192 "ftpcmd.c"
2192 break;
2193
2194 case 48: /* cmd: SIZE check_login SP pathname CRLF */
2195 #line 612 "ftpcmd.y"
2196 {
2197 if ((yyvsp[-3].i) && (yyvsp[-1].s) != NULL)
2198 sizecmd ((yyvsp[-1].s));
2199 free ((yyvsp[-1].s));
2200 }
2201 #line 2202 "ftpcmd.c"
2202 break;
2203
2204 case 49: /* cmd: MDTM check_login SP pathname CRLF */
2205 #line 627 "ftpcmd.y"
2206 {
2207 if ((yyvsp[-3].i) && (yyvsp[-1].s) != NULL)
2208 {
2209 struct stat stbuf;
2210
2211 if (stat ((yyvsp[-1].s), &stbuf) < 0)
2212 reply (550, "%s: %s", (yyvsp[-1].s), strerror (errno));
2213 else if (!S_ISREG (stbuf.st_mode))
2214 reply (550, "%s: not a plain file.", (yyvsp[-1].s));
2215 else
2216 {
2217 struct tm *t;
2218
2219 t = gmtime (&stbuf.st_mtime);
2220 reply (213,
2221 "%04d%02d%02d%02d%02d%02d",
2222 1900 + t->tm_year, t->tm_mon+1,
2223 t->tm_mday, t->tm_hour,
2224 t->tm_min, t->tm_sec);
2225 }
2226 }
2227 free ((yyvsp[-1].s));
2228 }
2229 #line 2230 "ftpcmd.c"
2230 break;
2231
2232 case 50: /* cmd: EPRT check_login SP CHAR net_proto CHAR net_addr CHAR tcp_port CHAR CRLF */
2233 #line 655 "ftpcmd.y"
2234 {
2235 usedefault = 0;
2236 if (pdata >= 0)
2237 {
2238 close (pdata);
2239 pdata = -1;
2240 }
2241 /* A first sanity check. */
2242 if ((yyvsp[-9].i) /* valid login */
2243 && ((yyvsp[-6].i) > 0) /* valid protocols */
2244 && ((yyvsp[-7].i) > 32 && (yyvsp[-7].i) < 127) /* legal first delimiter */
2245 /* identical delimiters */
2246 && ((yyvsp[-7].i) == (yyvsp[-5].i) && (yyvsp[-7].i) == (yyvsp[-3].i) && (yyvsp[-7].i) == (yyvsp[-1].i)))
2247 {
2248 /* We only accept connections using
2249 * the same address family as is
2250 * currently in use, unless we
2251 * detect IPv4-mapped-to-IPv6.
2252 */
2253 if (his_addr.ss_family == (yyvsp[-6].i)
2254 || ((yyvsp[-6].i) == AF_INET6
2255 && his_addr.ss_family == AF_INET)
2256 || ((yyvsp[-6].i) == AF_INET
2257 && his_addr.ss_family == AF_INET6))
2258 {
2259 int err;
2260 char p[8];
2261 struct addrinfo hints, *res;
2262
2263 memset (&hints, 0, sizeof (hints));
2264 snprintf (p, sizeof (p), "%jd", (yyvsp[-2].i) & 0xffff);
2265 hints.ai_family = (yyvsp[-6].i);
2266 hints.ai_socktype = SOCK_STREAM;
2267 hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV;
2268
2269 err = getaddrinfo ((yyvsp[-4].s), p, &hints, &res);
2270 if (err)
2271 reply (500, "Illegal EPRT Command");
2272 else if (/* sanity check */
2273 (his_addr.ss_family == AF_INET
2274 && memcmp (&((struct sockaddr_in *) &his_addr)->sin_addr,
2275 &((struct sockaddr_in *) res->ai_addr)->sin_addr,
2276 sizeof (struct in_addr))
2277 == 0
2278 && ntohs (((struct sockaddr_in *) res->ai_addr)->sin_port)
2279 > IPPORT_RESERVED
2280 )
2281 ||
2282 (his_addr.ss_family == AF_INET6
2283 && memcmp (&((struct sockaddr_in6 *) &his_addr)->sin6_addr,
2284 &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr,
2285 sizeof (struct in6_addr))
2286 == 0
2287 && ntohs (((struct sockaddr_in6 *) res->ai_addr)->sin6_port)
2288 > IPPORT_RESERVED
2289 )
2290 ||
2291 (his_addr.ss_family == AF_INET
2292 && res->ai_family == AF_INET6
2293 && IN6_IS_ADDR_V4MAPPED (&((struct sockaddr_in6 *) res->ai_addr)->sin6_addr)
2294 && memcmp (&((struct sockaddr_in *) &his_addr)->sin_addr,
2295 &((struct in_addr *) &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr)[3],
2296 sizeof (struct in_addr))
2297 == 0
2298 && ntohs (((struct sockaddr_in6 *) res->ai_addr)->sin6_port)
2299 > IPPORT_RESERVED
2300 )
2301 ||
2302 (his_addr.ss_family == AF_INET6
2303 && res->ai_family == AF_INET
2304 && IN6_IS_ADDR_V4MAPPED (&((struct sockaddr_in6 *) &his_addr)->sin6_addr)
2305 && memcmp (&((struct in_addr *) &((struct sockaddr_in6 *) &his_addr)->sin6_addr)[3],
2306 &((struct sockaddr_in *) res->ai_addr)->sin_addr,
2307 sizeof (struct in_addr))
2308 == 0
2309 && ntohs (((struct sockaddr_in *) res->ai_addr)->sin_port)
2310 > IPPORT_RESERVED
2311 )
2312 )
2313 {
2314 /* In the case of IPv4 mapped as IPv6,
2315 * the addresses were proven to coincide,
2316 * only the extraction remains.
2317 * Since non-mapped is the standard,
2318 * test that situation first.
2319 */
2320 if (his_addr.ss_family == res->ai_family)
2321 {
2322 memcpy (&data_dest, res->ai_addr,
2323 res->ai_addrlen);
2324 data_dest_len = res->ai_addrlen;
2325 }
2326 else if (his_addr.ss_family == AF_INET
2327 && res->ai_family == AF_INET6)
2328 {
2329 /* `his_addr' contains the reduced
2330 * IPv4 address.
2331 */
2332 memcpy (&data_dest, &his_addr,
2333 sizeof (struct sockaddr_in));
2334 data_dest_len =
2335 sizeof (struct sockaddr_in);
2336 ((struct sockaddr_in *) &data_dest)->sin_port =
2337 ((struct sockaddr_in6 *) res->ai_addr)->sin6_port;
2338 }
2339 else
2340 {
2341 /* `res->ai_addr' contains the reduced
2342 * IPv4 address, but the connection
2343 * stands on `his_addr', which is
2344 * an IPv4-to-IPv6-mapped address.
2345 */
2346 memcpy (&data_dest, &his_addr,
2347 sizeof (struct sockaddr_in6));
2348 data_dest_len =
2349 sizeof (struct sockaddr_in6);
2350 ((struct sockaddr_in6 *) &data_dest)->sin6_port =
2351 ((struct sockaddr_in *) res->ai_addr)->sin_port;
2352 }
2353
2354 freeaddrinfo (res);
2355 reply (200, "EPRT command successful.");
2356 }
2357 else
2358 {
2359 /* failed identity check */
2360 if (res)
2361 freeaddrinfo (res);
2362 reply (500, "Illegal EPRT Command");
2363 }
2364 }
2365 else
2366 /* Not fit for established connection. */
2367 reply (522,
2368 "Network protocol not supported, use (%d)",
2369 ((yyvsp[-6].i) == 1) ? 2 : 1);
2370 }
2371 else if ((yyvsp[-9].i) && ((yyvsp[-6].i) <= 0))
2372 reply (522,
2373 "Network protocol not supported, use (1,2)");
2374 else if ((yyvsp[-9].i))
2375 /* Incorrect delimiters detected,
2376 * the other conditions are met.
2377 */
2378 reply (500, "Illegal EPRT Command");
2379 }
2380 #line 2381 "ftpcmd.c"
2381 break;
2382
2383 case 51: /* cmd: EPSV check_login CRLF */
2384 #line 806 "ftpcmd.y"
2385 {
2386 if ((yyvsp[-1].i))
2387 passive (PASSIVE_EPSV, AF_UNSPEC);
2388 }
2389 #line 2390 "ftpcmd.c"
2390 break;
2391
2392 case 52: /* cmd: EPSV check_login SP net_proto CRLF */
2393 #line 811 "ftpcmd.y"
2394 {
2395 if ((yyvsp[-3].i))
2396 {
2397 if ((yyvsp[-1].i) > 0)
2398 passive (PASSIVE_EPSV, (yyvsp[-1].i));
2399 else
2400 reply (522,
2401 "Network protocol not supported, use (1,2)");
2402 }
2403 }
2404 #line 2405 "ftpcmd.c"
2405 break;
2406
2407 case 53: /* cmd: LPRT check_login SP long_host_port CRLF */
2408 #line 826 "ftpcmd.y"
2409 {
2410 if ((yyvsp[-3].i))
2411 {
2412 if ((yyvsp[-1].i) &&
2413 ((his_addr.ss_family == AF_INET
2414 && memcmp (&((struct sockaddr_in *) &his_addr)->sin_addr,
2415 &((struct sockaddr_in *) &data_dest)->sin_addr,
2416 sizeof (struct in_addr)) == 0
2417 && ntohs (((struct sockaddr_in *) &data_dest)->sin_port)
2418 > IPPORT_RESERVED)
2419 ||
2420 (his_addr.ss_family == AF_INET6
2421 && memcmp (&((struct sockaddr_in6 *) &his_addr)->sin6_addr,
2422 &((struct sockaddr_in6 *) &data_dest)->sin6_addr,
2423 sizeof (struct in6_addr)) == 0
2424 && ntohs (((struct sockaddr_in6 *) &data_dest)->sin6_port)
2425 > IPPORT_RESERVED)
2426 )
2427 )
2428 {
2429 usedefault = 0;
2430 if (pdata >= 0)
2431 {
2432 close (pdata);
2433 pdata = -1;
2434 }
2435 reply (200, "LPRT command successful.");
2436 }
2437 else
2438 {
2439 usedefault = 1;
2440 memset (&data_dest, 0, sizeof (data_dest));
2441 reply (500, "Illegal LPRT Command");
2442 }
2443 } /* check_login */
2444 }
2445 #line 2446 "ftpcmd.c"
2446 break;
2447
2448 case 54: /* cmd: LPSV check_login CRLF */
2449 #line 867 "ftpcmd.y"
2450 {
2451 if ((yyvsp[-1].i))
2452 passive (PASSIVE_LPSV, 0 /* not used */);
2453 }
2454 #line 2455 "ftpcmd.c"
2455 break;
2456
2457 case 55: /* cmd: QUIT CRLF */
2458 #line 873 "ftpcmd.y"
2459 {
2460 reply (221, "Goodbye.");
2461 dologout (0);
2462 }
2463 #line 2464 "ftpcmd.c"
2464 break;
2465
2466 case 56: /* cmd: error CRLF */
2467 #line 878 "ftpcmd.y"
2468 {
2469 yyerrok;
2470 }
2471 #line 2472 "ftpcmd.c"
2472 break;
2473
2474 case 57: /* rcmd: RNFR check_login SP pathname CRLF */
2475 #line 884 "ftpcmd.y"
2476 {
2477 restart_point = (off_t) 0;
2478 if ((yyvsp[-3].i) && (yyvsp[-1].s))
2479 {
2480 free (fromname);
2481 fromname = renamefrom ((yyvsp[-1].s));
2482 }
2483 if (fromname == (char *) 0 && (yyvsp[-1].s))
2484 free ((yyvsp[-1].s));
2485 }
2486 #line 2487 "ftpcmd.c"
2487 break;
2488
2489 case 58: /* rcmd: REST SP byte_size CRLF */
2490 #line 899 "ftpcmd.y"
2491 {
2492 free (fromname);
2493 fromname = (char *) 0;
2494 restart_point = (yyvsp[-1].i);
2495 reply (350, "Restarting at %jd. %s",
2496 (intmax_t) restart_point,
2497 "Send STORE or RETRIEVE to initiate transfer.");
2498 }
2499 #line 2500 "ftpcmd.c"
2500 break;
2501
2502 case 60: /* password: %empty */
2503 #line 915 "ftpcmd.y"
2504 {
2505 (yyval.s) = (char *) calloc (1, sizeof (char));
2506 }
2507 #line 2508 "ftpcmd.c"
2508 break;
2509
2510 case 63: /* net_proto: NUMBER */
2511 #line 927 "ftpcmd.y"
2512 {
2513 /* Rewrite as valid address family. */
2514 if ((yyvsp[0].i) == 1)
2515 (yyval.i) = AF_INET;
2516 else if ((yyvsp[0].i) == 2)
2517 (yyval.i) = AF_INET6;
2518 else
2519 (yyval.i) = -1; /* Invalid protocol. */
2520 }
2521 #line 2522 "ftpcmd.c"
2522 break;
2523
2524 case 66: /* host_port: NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER */
2525 #line 949 "ftpcmd.y"
2526 {
2527 int err;
2528 char a[INET6_ADDRSTRLEN], p[8];
2529 struct addrinfo hints, *res;
2530
2531 snprintf (a, sizeof (a), "%jd.%jd.%jd.%jd",
2532 (yyvsp[-10].i) & 0xff, (yyvsp[-8].i) & 0xff,
2533 (yyvsp[-6].i) & 0xff, (yyvsp[-4].i) & 0xff);
2534 snprintf (p, sizeof (p), "%jd",
2535 (((yyvsp[-2].i) & 0xff) << 8) + ((yyvsp[0].i) & 0xff));
2536 memset (&hints, 0, sizeof (hints));
2537 hints.ai_family = his_addr.ss_family;
2538 hints.ai_socktype = SOCK_STREAM;
2539 hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV;
2540
2541 if (his_addr.ss_family == AF_INET6)
2542 {
2543 /* IPv4 mapped to IPv6. */
2544 hints.ai_family = AF_INET6;
2545 #ifdef AI_V4MAPPED
2546 hints.ai_flags |= AI_V4MAPPED;
2547 #endif
2548 snprintf (a, sizeof (a),
2549 "::ffff:%jd.%jd.%jd.%jd",
2550 (yyvsp[-10].i) & 0xff, (yyvsp[-8].i) & 0xff,
2551 (yyvsp[-6].i) & 0xff, (yyvsp[-4].i) & 0xff);
2552 }
2553
2554 err = getaddrinfo (a, p, &hints, &res);
2555 if (err)
2556 {
2557 reply (550, "Address failure: %s,%s", a, p);
2558 memset (&data_dest, 0, sizeof (data_dest));
2559 data_dest_len = 0;
2560 (yyval.i) = 0;
2561 }
2562 else
2563 {
2564 memcpy (&data_dest, res->ai_addr, res->ai_addrlen);
2565 data_dest_len = res->ai_addrlen;
2566 freeaddrinfo (res);
2567 (yyval.i) = 1;
2568 }
2569 }
2570 #line 2571 "ftpcmd.c"
2571 break;
2572
2573 case 67: /* long_host_port: NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER */
2574 #line 999 "ftpcmd.y"
2575 {
2576 int err;
2577 char a[INET6_ADDRSTRLEN], p[8];
2578 struct addrinfo hints, *res;
2579
2580 /* Well formed input for IPv4? */
2581 if ((yyvsp[-16].i) != 4 || (yyvsp[-14].i) != 4 || (yyvsp[-4].i) != 2
2582 || (yyvsp[-12].i) < 0 || (yyvsp[-12].i) > 255 || (yyvsp[-10].i) < 0 || (yyvsp[-10].i) > 255
2583 || (yyvsp[-8].i) < 0 || (yyvsp[-8].i) > 255 || (yyvsp[-6].i) < 0 || (yyvsp[-6].i) > 255
2584 || (yyvsp[-2].i) < 0 || (yyvsp[-2].i) > 255
2585 || (yyvsp[0].i) < 0 || (yyvsp[0].i) > 255)
2586 {
2587 reply (500, "Invalid address.");
2588 memset (&data_dest, 0, sizeof (data_dest));
2589 data_dest_len = 0;
2590 (yyval.i) = 0;
2591 }
2592 else
2593 {
2594 snprintf (a, sizeof (a), "%jd.%jd.%jd.%jd",
2595 (yyvsp[-12].i), (yyvsp[-10].i), (yyvsp[-8].i), (yyvsp[-6].i));
2596 snprintf (p, sizeof (p), "%jd", ((yyvsp[-2].i) << 8) + (yyvsp[0].i));
2597
2598 memset (&hints, 0, sizeof (hints));
2599 hints.ai_family = his_addr.ss_family;
2600 hints.ai_socktype = SOCK_STREAM;
2601 hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV;
2602
2603 if (his_addr.ss_family == AF_INET6)
2604 {
2605 /* IPv4 mapped to IPv6. */
2606 hints.ai_family = AF_INET6;
2607 #ifdef AI_V4MAPPED
2608 hints.ai_flags |= AI_V4MAPPED;
2609 #endif
2610 snprintf (a, sizeof (a),
2611 "::ffff:%jd.%jd.%jd.%jd",
2612 (yyvsp[-12].i), (yyvsp[-10].i), (yyvsp[-8].i), (yyvsp[-6].i));
2613 }
2614
2615 err = getaddrinfo (a, p, &hints, &res);
2616 if (err)
2617 {
2618 reply (550, "LPRT address failure: %s,%s",
2619 a, p);
2620 memset (&data_dest, 0, sizeof (data_dest));
2621 data_dest_len = 0;
2622 (yyval.i) = 0;
2623 }
2624 else
2625 {
2626 memcpy (&data_dest, res->ai_addr,
2627 res->ai_addrlen);
2628 data_dest_len = res->ai_addrlen;
2629 freeaddrinfo (res);
2630 (yyval.i) = 1;
2631 }
2632 }
2633 }
2634 #line 2635 "ftpcmd.c"
2635 break;
2636
2637 case 68: /* long_host_port: NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER */
2638 #line 1064 "ftpcmd.y"
2639 {
2640 int err;
2641 char a[INET6_ADDRSTRLEN], p[8];
2642 struct addrinfo hints, *res;
2643
2644 /* Well formed input for IPv6? */
2645 if ((yyvsp[-40].i) != 6 || (yyvsp[-38].i) != 16 || (yyvsp[-4].i) != 2
2646 || (yyvsp[-36].i) < 0 || (yyvsp[-36].i) > 255 || (yyvsp[-34].i) < 0 || (yyvsp[-34].i) > 255
2647 || (yyvsp[-32].i) < 0 || (yyvsp[-32].i) > 255 || (yyvsp[-30].i) < 0 || (yyvsp[-30].i) > 255
2648 || (yyvsp[-28].i) < 0 || (yyvsp[-28].i) > 255 || (yyvsp[-26].i) < 0 || (yyvsp[-26].i) > 255
2649 || (yyvsp[-24].i) < 0 || (yyvsp[-24].i) > 255 || (yyvsp[-22].i) < 0 || (yyvsp[-22].i) > 255
2650 || (yyvsp[-20].i) < 0 || (yyvsp[-20].i) > 255 || (yyvsp[-18].i) < 0 || (yyvsp[-18].i) > 255
2651 || (yyvsp[-16].i) < 0 || (yyvsp[-16].i) > 255 || (yyvsp[-14].i) < 0 || (yyvsp[-14].i) > 255
2652 || (yyvsp[-12].i) < 0 || (yyvsp[-12].i) > 255 || (yyvsp[-10].i) < 0 || (yyvsp[-10].i) > 255
2653 || (yyvsp[-8].i) < 0 || (yyvsp[-8].i) > 255 || (yyvsp[-6].i) < 0 || (yyvsp[-6].i) > 255
2654 || (yyvsp[-2].i) < 0 || (yyvsp[-2].i) > 255 || (yyvsp[0].i) < 0 || (yyvsp[0].i) > 255)
2655 {
2656 reply (500, "Invalid address.");
2657 memset (&data_dest, 0, sizeof (data_dest));
2658 data_dest_len = 0;
2659 (yyval.i) = 0;
2660 }
2661 else
2662 {
2663 snprintf (a, sizeof (a),
2664 "%02jx%02jx:%02jx%02jx:"
2665 "%02jx%02jx:%02jx%02jx:"
2666 "%02jx%02jx:%02jx%02jx:"
2667 "%02jx%02jx:%02jx%02jx",
2668 (yyvsp[-36].i), (yyvsp[-34].i), (yyvsp[-32].i), (yyvsp[-30].i),
2669 (yyvsp[-28].i), (yyvsp[-26].i), (yyvsp[-24].i), (yyvsp[-22].i),
2670 (yyvsp[-20].i), (yyvsp[-18].i), (yyvsp[-16].i), (yyvsp[-14].i),
2671 (yyvsp[-12].i), (yyvsp[-10].i), (yyvsp[-8].i), (yyvsp[-6].i));
2672 snprintf (p, sizeof (p), "%jd",
2673 ((yyvsp[-2].i) << 8) + (yyvsp[0].i));
2674
2675 memset (&hints, 0, sizeof (hints));
2676 hints.ai_family = his_addr.ss_family;
2677 hints.ai_socktype = SOCK_STREAM;
2678 hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV;
2679
2680 err = getaddrinfo (a, p, &hints, &res);
2681 if (err)
2682 {
2683 reply (550, "LPRT address failure: %s,%s",
2684 a, p);
2685 memset (&data_dest, 0, sizeof (data_dest));
2686 data_dest_len = 0;
2687 (yyval.i) = 0;
2688 }
2689 else
2690 {
2691 memcpy (&data_dest, res->ai_addr,
2692 res->ai_addrlen);
2693 data_dest_len = res->ai_addrlen;
2694 freeaddrinfo (res);
2695 (yyval.i) = 1;
2696 }
2697 }
2698 }
2699 #line 2700 "ftpcmd.c"
2700 break;
2701
2702 case 69: /* form_code: N */
2703 #line 1128 "ftpcmd.y"
2704 {
2705 (yyval.i) = FORM_N;
2706 }
2707 #line 2708 "ftpcmd.c"
2708 break;
2709
2710 case 70: /* form_code: T */
2711 #line 1132 "ftpcmd.y"
2712 {
2713 (yyval.i) = FORM_T;
2714 }
2715 #line 2716 "ftpcmd.c"
2716 break;
2717
2718 case 71: /* form_code: C */
2719 #line 1136 "ftpcmd.y"
2720 {
2721 (yyval.i) = FORM_C;
2722 }
2723 #line 2724 "ftpcmd.c"
2724 break;
2725
2726 case 72: /* type_code: A */
2727 #line 1143 "ftpcmd.y"
2728 {
2729 cmd_type = TYPE_A;
2730 cmd_form = FORM_N;
2731 }
2732 #line 2733 "ftpcmd.c"
2733 break;
2734
2735 case 73: /* type_code: A SP form_code */
2736 #line 1148 "ftpcmd.y"
2737 {
2738 cmd_type = TYPE_A;
2739 cmd_form = (yyvsp[0].i);
2740 }
2741 #line 2742 "ftpcmd.c"
2742 break;
2743
2744 case 74: /* type_code: E */
2745 #line 1153 "ftpcmd.y"
2746 {
2747 cmd_type = TYPE_E;
2748 cmd_form = FORM_N;
2749 }
2750 #line 2751 "ftpcmd.c"
2751 break;
2752
2753 case 75: /* type_code: E SP form_code */
2754 #line 1158 "ftpcmd.y"
2755 {
2756 cmd_type = TYPE_E;
2757 cmd_form = (yyvsp[0].i);
2758 }
2759 #line 2760 "ftpcmd.c"
2760 break;
2761
2762 case 76: /* type_code: I */
2763 #line 1163 "ftpcmd.y"
2764 {
2765 cmd_type = TYPE_I;
2766 }
2767 #line 2768 "ftpcmd.c"
2768 break;
2769
2770 case 77: /* type_code: L */
2771 #line 1167 "ftpcmd.y"
2772 {
2773 cmd_type = TYPE_L;
2774 cmd_bytesz = CHAR_BIT;
2775 }
2776 #line 2777 "ftpcmd.c"
2777 break;
2778
2779 case 78: /* type_code: L SP byte_size */
2780 #line 1172 "ftpcmd.y"
2781 {
2782 cmd_type = TYPE_L;
2783 cmd_bytesz = (yyvsp[0].i);
2784 }
2785 #line 2786 "ftpcmd.c"
2786 break;
2787
2788 case 79: /* type_code: L byte_size */
2789 #line 1178 "ftpcmd.y"
2790 {
2791 cmd_type = TYPE_L;
2792 cmd_bytesz = (yyvsp[0].i);
2793 }
2794 #line 2795 "ftpcmd.c"
2795 break;
2796
2797 case 80: /* struct_code: F */
2798 #line 1186 "ftpcmd.y"
2799 {
2800 (yyval.i) = STRU_F;
2801 }
2802 #line 2803 "ftpcmd.c"
2803 break;
2804
2805 case 81: /* struct_code: R */
2806 #line 1190 "ftpcmd.y"
2807 {
2808 (yyval.i) = STRU_R;
2809 }
2810 #line 2811 "ftpcmd.c"
2811 break;
2812
2813 case 82: /* struct_code: P */
2814 #line 1194 "ftpcmd.y"
2815 {
2816 (yyval.i) = STRU_P;
2817 }
2818 #line 2819 "ftpcmd.c"
2819 break;
2820
2821 case 83: /* mode_code: S */
2822 #line 1201 "ftpcmd.y"
2823 {
2824 (yyval.i) = MODE_S;
2825 }
2826 #line 2827 "ftpcmd.c"
2827 break;
2828
2829 case 84: /* mode_code: B */
2830 #line 1205 "ftpcmd.y"
2831 {
2832 (yyval.i) = MODE_B;
2833 }
2834 #line 2835 "ftpcmd.c"
2835 break;
2836
2837 case 85: /* mode_code: C */
2838 #line 1209 "ftpcmd.y"
2839 {
2840 (yyval.i) = MODE_C;
2841 }
2842 #line 2843 "ftpcmd.c"
2843 break;
2844
2845 case 86: /* pathname: pathstring */
2846 #line 1216 "ftpcmd.y"
2847 {
2848 /*
2849 * Problem: this production is used for all pathname
2850 * processing, but only gives a 550 error reply.
2851 * This is a valid reply in some cases but not in others.
2852 */
2853 if (cred.logged_in && (yyvsp[0].s) && *(yyvsp[0].s) == '~')
2854 {
2855 glob_t gl;
2856 int flags = GLOB_NOCHECK;
2857
2858 #ifdef GLOB_BRACE
2859 flags |= GLOB_BRACE;
2860 #endif
2861 #ifdef GLOB_QUOTE
2862 flags |= GLOB_QUOTE;
2863 #endif
2864 #ifdef GLOB_TILDE
2865 flags |= GLOB_TILDE;
2866 #endif
2867
2868 memset (&gl, 0, sizeof (gl));
2869 if (glob ((yyvsp[0].s), flags, NULL, &gl)
2870 || gl.gl_pathc == 0)
2871 {
2872 reply (550, "not found");
2873 (yyval.s) = NULL;
2874 }
2875 else
2876 (yyval.s) = strdup (gl.gl_pathv[0]);
2877
2878 globfree (&gl);
2879 free ((yyvsp[0].s));
2880 }
2881 else
2882 (yyval.s) = (yyvsp[0].s);
2883 }
2884 #line 2885 "ftpcmd.c"
2885 break;
2886
2887 case 88: /* octal_number: NUMBER */
2888 #line 1261 "ftpcmd.y"
2889 {
2890 int ret, dec, multby, digit;
2891
2892 /*
2893 * Convert a number that was read as decimal number
2894 * to what it would be if it had been read as octal.
2895 */
2896 dec = (yyvsp[0].i);
2897 multby = 1;
2898 ret = 0;
2899 while (dec)
2900 {
2901 digit = dec % 10;
2902 if (digit > 7)
2903 {
2904 ret = -1;
2905 break;
2906 }
2907 ret += digit * multby;
2908 multby *= 8;
2909 dec /= 10;
2910 }
2911 (yyval.i) = ret;
2912 }
2913 #line 2914 "ftpcmd.c"
2914 break;
2915
2916 case 89: /* check_login: %empty */
2917 #line 1289 "ftpcmd.y"
2918 {
2919 if (cred.logged_in)
2920 (yyval.i) = 1;
2921 else
2922 {
2923 reply (530, "Please login with USER and PASS.");
2924 (yyval.i) = 0;
2925 }
2926 }
2927 #line 2928 "ftpcmd.c"
2928 break;
2929
2930
2931 #line 2932 "ftpcmd.c"
2932
2933 default: break;
2934 }
2935 /* User semantic actions sometimes alter yychar, and that requires
2936 that yytoken be updated with the new translation. We take the
2937 approach of translating immediately before every use of yytoken.
2938 One alternative is translating here after every semantic action,
2939 but that translation would be missed if the semantic action invokes
2940 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
2941 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
2942 incorrect destructor might then be invoked immediately. In the
2943 case of YYERROR or YYBACKUP, subsequent parser actions might lead
2944 to an incorrect destructor call or verbose syntax error message
2945 before the lookahead is translated. */
2946 YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
2947
2948 YYPOPSTACK (yylen);
2949 yylen = 0;
2950
2951 *++yyvsp = yyval;
2952
2953 /* Now 'shift' the result of the reduction. Determine what state
2954 that goes to, based on the state we popped back to and the rule
2955 number reduced by. */
2956 {
2957 const int yylhs = yyr1[yyn] - YYNTOKENS;
2958 const int yyi = yypgoto[yylhs] + *yyssp;
2959 yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
2960 ? yytable[yyi]
2961 : yydefgoto[yylhs]);
2962 }
2963
2964 goto yynewstate;
2965
2966
2967 /*--------------------------------------.
2968 | yyerrlab -- here on detecting error. |
2969 `--------------------------------------*/
2970 yyerrlab:
2971 /* Make sure we have latest lookahead translation. See comments at
2972 user semantic actions for why this is necessary. */
2973 yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
2974 /* If not already recovering from an error, report this error. */
2975 if (!yyerrstatus)
2976 {
2977 ++yynerrs;
2978 yyerror (YY_("syntax error"));
2979 }
2980
2981 if (yyerrstatus == 3)
2982 {
2983 /* If just tried and failed to reuse lookahead token after an
2984 error, discard it. */
2985
2986 if (yychar <= YYEOF)
2987 {
2988 /* Return failure if at end of input. */
2989 if (yychar == YYEOF)
2990 YYABORT;
2991 }
2992 else
2993 {
2994 yydestruct ("Error: discarding",
2995 yytoken, &yylval);
2996 yychar = YYEMPTY;
2997 }
2998 }
2999
3000 /* Else will try to reuse lookahead token after shifting the error
3001 token. */
3002 goto yyerrlab1;
3003
3004
3005 /*---------------------------------------------------.
3006 | yyerrorlab -- error raised explicitly by YYERROR. |
3007 `---------------------------------------------------*/
3008 yyerrorlab:
3009 /* Pacify compilers when the user code never invokes YYERROR and the
3010 label yyerrorlab therefore never appears in user code. */
3011 if (0)
3012 YYERROR;
3013 ++yynerrs;
3014
3015 /* Do not reclaim the symbols of the rule whose action triggered
3016 this YYERROR. */
3017 YYPOPSTACK (yylen);
3018 yylen = 0;
3019 YY_STACK_PRINT (yyss, yyssp);
3020 yystate = *yyssp;
3021 goto yyerrlab1;
3022
3023
3024 /*-------------------------------------------------------------.
3025 | yyerrlab1 -- common code for both syntax error and YYERROR. |
3026 `-------------------------------------------------------------*/
3027 yyerrlab1:
3028 yyerrstatus = 3; /* Each real token shifted decrements this. */
3029
3030 /* Pop stack until we find a state that shifts the error token. */
3031 for (;;)
3032 {
3033 yyn = yypact[yystate];
3034 if (!yypact_value_is_default (yyn))
3035 {
3036 yyn += YYSYMBOL_YYerror;
3037 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
3038 {
3039 yyn = yytable[yyn];
3040 if (0 < yyn)
3041 break;
3042 }
3043 }
3044
3045 /* Pop the current state because it cannot handle the error token. */
3046 if (yyssp == yyss)
3047 YYABORT;
3048
3049
3050 yydestruct ("Error: popping",
3051 YY_ACCESSING_SYMBOL (yystate), yyvsp);
3052 YYPOPSTACK (1);
3053 yystate = *yyssp;
3054 YY_STACK_PRINT (yyss, yyssp);
3055 }
3056
3057 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
3058 *++yyvsp = yylval;
3059 YY_IGNORE_MAYBE_UNINITIALIZED_END
3060
3061
3062 /* Shift the error token. */
3063 YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
3064
3065 yystate = yyn;
3066 goto yynewstate;
3067
3068
3069 /*-------------------------------------.
3070 | yyacceptlab -- YYACCEPT comes here. |
3071 `-------------------------------------*/
3072 yyacceptlab:
3073 yyresult = 0;
3074 goto yyreturnlab;
3075
3076
3077 /*-----------------------------------.
3078 | yyabortlab -- YYABORT comes here. |
3079 `-----------------------------------*/
3080 yyabortlab:
3081 yyresult = 1;
3082 goto yyreturnlab;
3083
3084
3085 /*-----------------------------------------------------------.
3086 | yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. |
3087 `-----------------------------------------------------------*/
3088 yyexhaustedlab:
3089 yyerror (YY_("memory exhausted"));
3090 yyresult = 2;
3091 goto yyreturnlab;
3092
3093
3094 /*----------------------------------------------------------.
3095 | yyreturnlab -- parsing is finished, clean up and return. |
3096 `----------------------------------------------------------*/
3097 yyreturnlab:
3098 if (yychar != YYEMPTY)
3099 {
3100 /* Make sure we have latest lookahead translation. See comments at
3101 user semantic actions for why this is necessary. */
3102 yytoken = YYTRANSLATE (yychar);
3103 yydestruct ("Cleanup: discarding lookahead",
3104 yytoken, &yylval);
3105 }
3106 /* Do not reclaim the symbols of the rule whose action triggered
3107 this YYABORT or YYACCEPT. */
3108 YYPOPSTACK (yylen);
3109 YY_STACK_PRINT (yyss, yyssp);
3110 while (yyssp != yyss)
3111 {
3112 yydestruct ("Cleanup: popping",
3113 YY_ACCESSING_SYMBOL (+*yyssp), yyvsp);
3114 YYPOPSTACK (1);
3115 }
3116 #ifndef yyoverflow
3117 if (yyss != yyssa)
3118 YYSTACK_FREE (yyss);
3119 #endif
3120
3121 return yyresult;
3122 }
3123
3124 #line 1300 "ftpcmd.y"
3125
3126
3127 #define CMD 0 /* beginning of command */
3128 #define ARGS 1 /* expect miscellaneous arguments */
3129 #define STR1 2 /* expect SP followed by STRING */
3130 #define STR2 3 /* expect STRING (must be STR2 + 1)*/
3131 #define OSTR 4 /* optional SP then STRING */
3132 #define ZSTR1 5 /* SP then optional STRING */
3133 #define ZSTR2 6 /* optional STRING after SP (must be ZSTR1 + 1) */
3134 #define SITECMD 7 /* SITE command */
3135 #define NSTR 8 /* Number followed by a string */
3136 #define DLIST 9 /* SP and delimited list for EPRT/EPSV */
3137
3138 static struct tab cmdtab[] = {
3139 /* In the order defined by RFC 959. See also RFC 1123. */
3140 /* Access control commands. */
3141 { "USER", USER, STR1, 1, "<sp> username" },
3142 { "PASS", PASS, ZSTR1, 1, "<sp> password" },
3143 { "ACCT", ACCT, STR1, 0, "(specify account)" },
3144 { "CWD", CWD, OSTR, 1, "[ <sp> directory-name ]" },
3145 { "CDUP", CDUP, ARGS, 1, "(change to parent directory)" },
3146 { "SMNT", SMNT, ARGS, 0, "(structure mount)" },
3147 { "REIN", REIN, ARGS, 0, "(reinitialize server state)" },
3148 { "QUIT", QUIT, ARGS, 1, "(terminate service)", },
3149 /* Transfer parameter commands. */
3150 { "PORT", PORT, ARGS, 1, "<sp> b0, b1, b2, b3, b4" },
3151 { "PASV", PASV, ARGS, 1, "(set server in passive mode)" },
3152 { "TYPE", TYPE, ARGS, 1, "<sp> [ A | E | I | L ]" },
3153 { "STRU", STRU, ARGS, 1, "(specify file structure)" },
3154 { "MODE", MODE, ARGS, 1, "(specify transfer mode)" },
3155 /* FTP service commands. */
3156 { "RETR", RETR, STR1, 1, "<sp> file-name" },
3157 { "STOR", STOR, STR1, 1, "<sp> file-name" },
3158 { "STOU", STOU, STR1, 1, "<sp> file-name" },
3159 { "APPE", APPE, STR1, 1, "<sp> file-name" },
3160 { "ALLO", ALLO, ARGS, 1, "allocate storage (vacuously)" },
3161 { "REST", REST, ARGS, 1, "<sp> offset (restart command)" },
3162 { "RNFR", RNFR, STR1, 1, "<sp> file-name" },
3163 { "RNTO", RNTO, STR1, 1, "<sp> file-name" },
3164 { "ABOR", ABOR, ARGS, 1, "(abort operation)" },
3165 { "DELE", DELE, STR1, 1, "<sp> file-name" },
3166 { "RMD", RMD, STR1, 1, "<sp> path-name" },
3167 { "MKD", MKD, STR1, 1, "<sp> path-name" },
3168 { "PWD", PWD, ARGS, 1, "(return current directory)" },
3169 { "LIST", LIST, OSTR, 1, "[ <sp> path-name ]" },
3170 { "NLST", NLST, OSTR, 1, "[ <sp> path-name ]" },
3171 { "SITE", SITE, SITECMD, 1, "site-cmd [ <sp> arguments ]" },
3172 { "SYST", SYST, ARGS, 1, "(get type of operating system)" },
3173 { "STAT", STAT, OSTR, 1, "[ <sp> path-name ]" },
3174 { "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" },
3175 { "NOOP", NOOP, ARGS, 1, "" },
3176 /* Experimental commands, as mentioned in RFC 1123. Now obsolete. */
3177 { "XMKD", MKD, STR1, 1, "<sp> path-name" },
3178 { "XRMD", RMD, STR1, 1, "<sp> path-name" },
3179 { "XPWD", PWD, ARGS, 1, "(return current directory)" },
3180 { "XCUP", CDUP, ARGS, 1, "(change to parent directory)" },
3181 { "XCWD", CWD, OSTR, 1, "[ <sp> directory-name ]" },
3182 /* Commands in RFC 2389. */
3183 { "FEAT", FEAT, OSTR, 1, "(display command extensions)" },
3184 /* XXX: Replace OSTR once some functionality exists. */
3185 { "OPTS", OPTS, OSTR, 1, "<sp> cmd-name [ <sp> options ]" },
3186 /* Commands in RFC 3659. */
3187 { "SIZE", SIZE, OSTR, 1, "<sp> path-name" },
3188 { "MDTM", MDTM, OSTR, 1, "<sp> path-name" },
3189 /* Unimplemented, but reserved in RFC ???. */
3190 { "MLFL", MLFL, OSTR, 0, "(mail file)" },
3191 { "MAIL", MAIL, OSTR, 0, "(mail to user)" },
3192 { "MSND", MSND, OSTR, 0, "(mail send to terminal)" },
3193 { "MSOM", MSOM, OSTR, 0, "(mail send to terminal or mailbox)" },
3194 { "MSAM", MSAM, OSTR, 0, "(mail send to terminal and mailbox)" },
3195 { "MRSQ", MRSQ, OSTR, 0, "(mail recipient scheme question)" },
3196 { "MRCP", MRCP, STR1, 0, "(mail recipient)" },
3197 /* Extended addressing in RFC 2428. */
3198 { "EPRT", EPRT, DLIST, 1, "<sp> <d> proto <d> addr <d> port <d>" },
3199 { "EPSV", EPSV, ARGS, 1, "[ <sp> af ]" },
3200 /* Long addressing in RFC 1639. Obsoleted in RFC 5797. */
3201 { "LPRT", LPRT, ARGS, 1, "<sp> af,hal,h0..hn,2,p0,p1" },
3202 { "LPSV", LPSV, ARGS, 1, "(set server in long passive mode)" },
3203 /* Security extensions in RFC 2228. */
3204 { "ADAT", ADAT, OSTR, 0, "<sp> security-data" },
3205 { "AUTH", AUTH, OSTR, 0, "<sp> mechanism" },
3206 { "CCC", CCC, ARGS, 0, "(clear command channel)" },
3207 { "CONF", CONF, OSTR, 0, "<sp> confidential-msg" },
3208 { "ENC", ENC, OSTR, 0, "<sp> private-message" },
3209 { "MIC", MIC, OSTR, 0, "<sp> safe-message" },
3210 { "PBSZ", PBSZ, OSTR, 0, "<sp> buf-size" },
3211 { "PROT", PROT, OSTR, 0, "<sp> char" },
3212 /* End of list. */
3213 { NULL, 0, 0, 0, NULL }
3214 };
3215
3216 static struct tab sitetab[] = {
3217 { "CHMOD", CHMOD, NSTR, 1, "<sp> mode <sp> file-name" },
3218 { "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" },
3219 { "IDLE", IDLE, ARGS, 1, "[ <sp> maximum-idle-time ]" },
3220 { "UMASK", UMASK, ARGS, 1, "[ <sp> umask ]" },
3221 { NULL, 0, 0, 0, NULL }
3222 };
3223
3224 /* Extensions beyond RFC 959 and RFC 2389. Ordered as implemented. */
3225 static char *extlist[] = {
3226 "MDTM", "SIZE", "REST STREAM",
3227 "EPRT", "EPSV", "LPRT", "LPSV",
3228 NULL };
3229
3230 static struct tab *
3231 lookup (struct tab *p, char *cmd)
3232 {
3233 for (; p->name != NULL; p++)
3234 if (strcmp (cmd, p->name) == 0)
3235 return (p);
3236 return (0);
3237 }
3238
3239 #include <arpa/telnet.h>
3240
3241 /*
3242 * getline - a hacked up version of fgets to ignore TELNET escape codes.
3243 */
3244 char *
3245 telnet_fgets (char *s, int n, FILE *iop)
3246 {
3247 int c;
3248 register char *cs;
3249
3250 cs = s;
3251 /* tmpline may contain saved command from urgent mode interruption */
3252 for (c = 0; tmpline[c] != '\0' && --n > 0; ++c)
3253 {
3254 *cs++ = tmpline[c];
3255 if (tmpline[c] == '\n')
3256 {
3257 *cs++ = '\0';
3258 if (debug)
3259 syslog (LOG_DEBUG, "command: %s", s);
3260 tmpline[0] = '\0';
3261 return (s);
3262 }
3263
3264 if (c == 0)
3265 tmpline[0] = '\0';
3266 }
3267
3268 while ((c = getc (iop)) != EOF)
3269 {
3270 c &= 0377;
3271 if (c == IAC)
3272 {
3273 c = getc (iop);
3274 if (c != EOF)
3275 {
3276 c &= 0377;
3277 switch (c)
3278 {
3279 case WILL:
3280 case WONT:
3281 c = getc (iop);
3282 printf ("%c%c%c", IAC, DONT, 0377 & c);
3283 fflush (stdout);
3284 continue;
3285
3286 case DO:
3287 case DONT:
3288 c = getc (iop);
3289 printf ("%c%c%c", IAC, WONT, 0377 & c);
3290 fflush (stdout);
3291 continue;
3292
3293 case IAC:
3294 break;
3295
3296 default:
3297 continue; /* ignore command */
3298 }
3299 }
3300 }
3301
3302 *cs++ = c;
3303 if (--n <= 0 || c == '\n')
3304 break;
3305 }
3306
3307 if (c == EOF && cs == s)
3308 return (NULL);
3309
3310 *cs++ = '\0';
3311
3312 if (debug)
3313 {
3314 if (!cred.guest && strncasecmp ("pass ", s, 5) == 0)
3315 {
3316 /* Don't syslog passwords. */
3317 syslog (LOG_DEBUG, "command: %.5s ???", s);
3318 }
3319 else
3320 {
3321 register char *cp;
3322 register int len;
3323
3324 /* Don't syslog trailing CR-LF. */
3325 len = strlen (s);
3326 cp = s + len - 1;
3327
3328 while (cp >= s && (*cp == '\n' || *cp == '\r'))
3329 {
3330 --cp;
3331 --len;
3332 }
3333
3334 syslog (LOG_DEBUG, "command: %.*s", len, s);
3335 }
3336 }
3337 return (s);
3338 }
3339
3340 void
3341 toolong (int signo)
3342 {
3343 (void) signo;
3344 reply (421, "Timeout (%d seconds): closing control connection.",
3345 timeout);
3346 if (logging)
3347 syslog (LOG_INFO, "User %s timed out after %d seconds",
3348 (cred.name ? cred.name : "unknown"), timeout);
3349 dologout (1);
3350 }
3351
3352 static int
3353 yylex (void)
3354 {
3355 static int cpos, state;
3356 char *cp, *cp2;
3357 struct tab *p;
3358 int n;
3359 char c;
3360
3361 for (;;)
3362 {
3363 switch (state)
3364 {
3365 case CMD:
3366 signal (SIGALRM, toolong);
3367 alarm ((unsigned) timeout);
3368 if (telnet_fgets (cbuf, sizeof (cbuf)-1, stdin) == NULL)
3369 {
3370 reply (221, "You could at least say goodbye.");
3371 dologout (0);
3372 }
3373 alarm (0);
3374
3375 #ifdef HAVE_SETPROCTITLE
3376 if (strncasecmp (cbuf, "PASS", 4) != 0)
3377 setproctitle ("%s: %s", proctitle, cbuf);
3378 #endif /* HAVE_SETPROCTITLE */
3379
3380 cp = strchr (cbuf, '\r');
3381 if (cp)
3382 {
3383 *cp++ = '\n';
3384 *cp = '\0';
3385 }
3386
3387 cp = strpbrk (cbuf, " \n");
3388 if (cp)
3389 cpos = cp - cbuf;
3390
3391 if (cpos == 0)
3392 cpos = 4;
3393
3394 c = cbuf[cpos];
3395 cbuf[cpos] = '\0';
3396 upper (cbuf);
3397 p = lookup (cmdtab, cbuf);
3398 cbuf[cpos] = c;
3399
3400 if (p != 0)
3401 {
3402 if (p->implemented == 0)
3403 {
3404 nack (p->name);
3405 longjmp (errcatch, 0);
3406 /* NOTREACHED */
3407 }
3408 state = p->state;
3409 yylval.s = (char*) p->name;
3410 return (p->token);
3411 }
3412 break; /* Command not known. */
3413
3414 case SITECMD:
3415 if (cbuf[cpos] == ' ')
3416 {
3417 cpos++;
3418 return (SP);
3419 }
3420 cp = &cbuf[cpos];
3421
3422 cp2 = strpbrk (cp, " \n");
3423 if (cp2)
3424 cpos = cp2 - cbuf;
3425
3426 c = cbuf[cpos];
3427 cbuf[cpos] = '\0';
3428 upper (cp);
3429 p = lookup (sitetab, cp);
3430 cbuf[cpos] = c;
3431
3432 if (p != 0)
3433 {
3434 if (p->implemented == 0)
3435 {
3436 state = CMD;
3437 nack (p->name);
3438 longjmp (errcatch, 0);
3439 /* NOTREACHED */
3440 }
3441
3442 state = p->state;
3443 yylval.s = (char*) p->name;
3444 return (p->token);
3445 }
3446 state = CMD;
3447 break; /* Command not known. */
3448
3449 case OSTR:
3450 if (cbuf[cpos] == '\n')
3451 {
3452 state = CMD;
3453 return (CRLF);
3454 }
3455
3456 case STR1:
3457 case ZSTR1:
3458 dostr1:
3459 if (cbuf[cpos] == ' ')
3460 {
3461 cpos++;
3462 if (state == OSTR)
3463 state = STR2;
3464 else
3465 ++state;
3466
3467 return (SP);
3468 }
3469 /* Intentional continuation. */
3470
3471 case ZSTR2:
3472 if (cbuf[cpos] == '\n')
3473 {
3474 state = CMD;
3475 return (CRLF);
3476 }
3477
3478 case STR2:
3479 cp = &cbuf[cpos];
3480 n = strlen (cp);
3481 cpos += n - 1;
3482 /*
3483 * Make sure the string is nonempty and newline terminated.
3484 */
3485 if (n > 1 && cbuf[cpos] == '\n')
3486 {
3487 cbuf[cpos] = '\0';
3488 yylval.s = copy (cp);
3489 cbuf[cpos] = '\n';
3490 state = ARGS;
3491 return (STRING);
3492 }
3493 break; /* Empty string, missing NL. */
3494
3495 case NSTR:
3496 if (cbuf[cpos] == ' ')
3497 {
3498 cpos++;
3499 return (SP);
3500 }
3501 if (isdigit (cbuf[cpos]))
3502 {
3503 cp = &cbuf[cpos];
3504 while (isdigit (cbuf[++cpos]))
3505 ;
3506
3507 c = cbuf[cpos];
3508 cbuf[cpos] = '\0';
3509 yylval.i = atoi (cp);
3510 cbuf[cpos] = c;
3511 state = STR1;
3512 return (NUMBER);
3513 }
3514 state = STR1;
3515 goto dostr1;
3516
3517 case DLIST:
3518 /* Either numerical strings or
3519 * address strings for IPv4 and IPv6.
3520 * The consist of hexadecimal chars,
3521 * colon and periods. A period can
3522 * not begin a valid address. */
3523 if (isxdigit (cbuf[cpos]) || cbuf[cpos] == ':')
3524 {
3525 int is_num = 1; /* Only to turn off. */
3526
3527 cp = &cbuf[cpos];
3528 while (isxdigit (cbuf[cpos])
3529 || cbuf[cpos] == ':'
3530 || cbuf[cpos] == '.')
3531 {
3532 if (!isdigit (cbuf[cpos]))
3533 is_num = 0;
3534 cpos++;
3535 }
3536
3537 c = cbuf[cpos];
3538 cbuf[cpos] = '\0';
3539 if (is_num)
3540 {
3541 yylval.i = atoi (cp);
3542 cbuf[cpos] = c;
3543 return (NUMBER);
3544 }
3545 else
3546 {
3547 yylval.s = copy (cp);
3548 cbuf[cpos] = c;
3549 return (STRING);
3550 }
3551 }
3552
3553 c = cbuf[cpos++];
3554 switch (c)
3555 {
3556 case ' ':
3557 return (SP);
3558
3559 case '\n':
3560 state = CMD;
3561 return (CRLF);
3562
3563 default:
3564 yylval.i = c;
3565 return (CHAR);
3566 }
3567 break; /* Not reachable. */
3568
3569 case ARGS:
3570 if (isdigit (cbuf[cpos]))
3571 {
3572 cp = &cbuf[cpos];
3573 while (isdigit (cbuf[++cpos]))
3574 ;
3575
3576 c = cbuf[cpos];
3577 cbuf[cpos] = '\0';
3578 yylval.i = strtoimax (cp, NULL, 10); /* off_t */
3579 cbuf[cpos] = c;
3580 return (NUMBER);
3581 }
3582
3583 switch (cbuf[cpos++])
3584 {
3585 case '\n':
3586 state = CMD;
3587 return (CRLF);
3588
3589 case ' ':
3590 return (SP);
3591
3592 case ',':
3593 return (COMMA);
3594
3595 case 'A':
3596 case 'a':
3597 return (A);
3598
3599 case 'B':
3600 case 'b':
3601 return (B);
3602
3603 case 'C':
3604 case 'c':
3605 return (C);
3606
3607 case 'E':
3608 case 'e':
3609 return (E);
3610
3611 case 'F':
3612 case 'f':
3613 return (F);
3614
3615 case 'I':
3616 case 'i':
3617 return (I);
3618
3619 case 'L':
3620 case 'l':
3621 return (L);
3622
3623 case 'N':
3624 case 'n':
3625 return (N);
3626
3627 case 'P':
3628 case 'p':
3629 return (P);
3630
3631 case 'R':
3632 case 'r':
3633 return (R);
3634
3635 case 'S':
3636 case 's':
3637 return (S);
3638
3639 case 'T':
3640 case 't':
3641 return (T);
3642 }
3643 break; /* No number, not in [\n ,aAbBcCeEfFiIlLnNpPrRsSttT] */
3644
3645 default:
3646 fatal ("Unknown state in scanner.");
3647 }
3648
3649 /*
3650 * Analysis: Cases when this point is reached.
3651 *
3652 * CMD: command not known
3653 * SITECMD: site command not known (state changed to CMD)
3654 *
3655 * OSTR, STR1, ZSTR1, STR2, ZSTR2, NSTR:
3656 * empty string or string without NL
3657 *
3658 * ARGS: not a number, not a special character
3659 */
3660
3661 /*
3662 * Issue a new error message only if the parser has not
3663 * yet reported a complaint. Without this precaution
3664 * two messages would be directed to the client, thus
3665 * upsetting all following exchange.
3666 */
3667 if (!yynerrs)
3668 yyerror ("command not recognized");
3669
3670 state = CMD;
3671 longjmp (errcatch, 0);
3672 } /* for (;;) */
3673 }
3674
3675 void
3676 upper (char *s)
3677 {
3678 while (*s != '\0')
3679 {
3680 if (islower (*s))
3681 *s = toupper (*s);
3682 s++;
3683 }
3684 }
3685
3686 static char *
3687 copy (char *s)
3688 {
3689 char *p;
3690
3691 p = malloc (strlen (s) + 1);
3692 if (p == NULL)
3693 fatal ("Ran out of memory.");
3694
3695 strcpy (p, s);
3696 return (p);
3697 }
3698
3699 static void
3700 help (struct tab *ctab, char *s)
3701 {
3702 struct tab *c;
3703 int width, NCMDS;
3704 const char *help_type;
3705
3706 if (ctab == sitetab)
3707 help_type = "SITE ";
3708 else
3709 help_type = "";
3710
3711 width = 0, NCMDS = 0;
3712 for (c = ctab; c->name != NULL; c++)
3713 {
3714 int len = strlen (c->name);
3715
3716 if (len > width)
3717 width = len;
3718
3719 NCMDS++;
3720 }
3721
3722 width = (width + 8) &~ 7;
3723
3724 if (s == 0)
3725 {
3726 int i, j, w;
3727 int columns, lines;
3728
3729 lreply (214, "The following %scommands are recognized %s.",
3730 help_type, "(* =>'s unimplemented)");
3731
3732 columns = 76 / width;
3733 if (columns == 0)
3734 columns = 1;
3735
3736 lines = (NCMDS + columns - 1) / columns;
3737
3738 for (i = 0; i < lines; i++)
3739 {
3740 printf (" ");
3741 for (j = 0; j < columns; j++)
3742 {
3743 c = ctab + j * lines + i;
3744 printf ("%s%c", c->name, c->implemented ? ' ' : '*');
3745
3746 if (c + lines >= &ctab[NCMDS])
3747 break;
3748
3749 w = strlen (c->name) + 1;
3750 while (w < width)
3751 {
3752 putchar (' ');
3753 w++;
3754 }
3755 }
3756 printf ("\r\n");
3757 }
3758 fflush (stdout);
3759 reply (214, "Direct comments to ftp-bugs@%s.", hostname);
3760 return;
3761 }
3762
3763 upper (s);
3764
3765 c = lookup (ctab, s);
3766 if (c == (struct tab *) 0)
3767 {
3768 reply (502, "Unknown command %s.", s);
3769 return;
3770 }
3771
3772 if (c->implemented)
3773 reply (214, "Syntax: %s%s %s", help_type, c->name, c->help);
3774 else
3775 reply (214, "%s%-*s\t%s; unimplemented.", help_type,
3776 width, c->name, c->help);
3777 }
3778
3779 static void
3780 sizecmd (char *filename)
3781 {
3782 switch (type)
3783 {
3784 case TYPE_L:
3785 case TYPE_I:
3786 {
3787 struct stat stbuf;
3788
3789 if (stat (filename, &stbuf) < 0 || !S_ISREG (stbuf.st_mode))
3790 reply (550, "%s: not a plain file.", filename);
3791 else
3792 reply (213, "%ju", (uintmax_t) stbuf.st_size);
3793 break;
3794 }
3795
3796 case TYPE_A:
3797 {
3798 FILE *fin;
3799 int c;
3800 off_t count;
3801 struct stat stbuf;
3802
3803 fin = fopen (filename, "r");
3804 if (fin == NULL)
3805 {
3806 perror_reply (550, filename);
3807 return;
3808 }
3809
3810 if (fstat (fileno (fin), &stbuf) < 0 || !S_ISREG (stbuf.st_mode))
3811 {
3812 reply (550, "%s: not a plain file.", filename);
3813 fclose (fin);
3814 return;
3815 }
3816
3817 count = 0;
3818 while ((c = getc (fin)) != EOF)
3819 {
3820 if (c == '\n') /* will get expanded to \r\n */
3821 count++;
3822 count++;
3823 }
3824 fclose (fin);
3825
3826 reply (213, "%jd", (intmax_t) count);
3827 break;
3828 }
3829
3830 default:
3831 reply (504, "SIZE not implemented for Type %c.", "?AEIL"[type]);
3832 }
3833 }
3834
3835 static void
3836 yyerror (const char *s)
3837 {
3838 char *cp;
3839
3840 cp = strchr (cbuf, '\n');
3841 if (cp != NULL)
3842 *cp = '\0';
3843
3844 reply (500, "'%s': %s", cbuf, (s ? s : "command not understood."));
3845 }