home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 4 / CDPD_IV.bin / networking / tcpip / amitcp-support / wustl-ftpdaemon / src / ftpcmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-29  |  74.3 KB  |  2,630 lines

  1.  
  2. /*  A Bison parser, made from ftpcmd.y with Bison version GNU Bison version 1.22
  3.   */
  4.  
  5. #define YYBISON 1  /* Identify Bison output.  */
  6.  
  7. #define    A    258
  8. #define    B    259
  9. #define    C    260
  10. #define    E    261
  11. #define    F    262
  12. #define    I    263
  13. #define    L    264
  14. #define    N    265
  15. #define    P    266
  16. #define    R    267
  17. #define    S    268
  18. #define    T    269
  19. #define    SP    270
  20. #define    CRLF    271
  21. #define    COMMA    272
  22. #define    STRING    273
  23. #define    NUMBER    274
  24. #define    USER    275
  25. #define    PASS    276
  26. #define    ACCT    277
  27. #define    REIN    278
  28. #define    QUIT    279
  29. #define    PORT    280
  30. #define    PASV    281
  31. #define    TYPE    282
  32. #define    STRU    283
  33. #define    MODE    284
  34. #define    RETR    285
  35. #define    STOR    286
  36. #define    APPE    287
  37. #define    MLFL    288
  38. #define    MAIL    289
  39. #define    MSND    290
  40. #define    MSOM    291
  41. #define    MSAM    292
  42. #define    MRSQ    293
  43. #define    MRCP    294
  44. #define    ALLO    295
  45. #define    REST    296
  46. #define    RNFR    297
  47. #define    RNTO    298
  48. #define    ABOR    299
  49. #define    DELE    300
  50. #define    CWD    301
  51. #define    LIST    302
  52. #define    NLST    303
  53. #define    SITE    304
  54. #define    STAT    305
  55. #define    HELP    306
  56. #define    NOOP    307
  57. #define    MKD    308
  58. #define    RMD    309
  59. #define    PWD    310
  60. #define    CDUP    311
  61. #define    STOU    312
  62. #define    SMNT    313
  63. #define    SYST    314
  64. #define    SIZE    315
  65. #define    MDTM    316
  66. #define    UMASK    317
  67. #define    IDLE    318
  68. #define    CHMOD    319
  69. #define    GROUP    320
  70. #define    GPASS    321
  71. #define    NEWER    322
  72. #define    MINFO    323
  73. #define    INDEX    324
  74. #define    EXEC    325
  75. #define    ALIAS    326
  76. #define    CDPATH    327
  77. #define    GROUPS    328
  78. #define    LEXERR    329
  79.  
  80. #line 41 "ftpcmd.y"
  81.  
  82.  
  83. #ifndef lint
  84. static char sccsid[] = "@(#)ftpcmd.y    5.24 (Berkeley) 2/25/91";
  85. #endif /* not lint */
  86.  
  87. #include "config.h"
  88. #include <sys/param.h>
  89. #include <sys/types.h>
  90. #include <sys/socket.h>
  91. #include <sys/stat.h>
  92. #include <netinet/in.h>
  93. #include <arpa/ftp.h>
  94. #include <stdio.h>
  95. #include <signal.h>
  96. #include <ctype.h>
  97. #include <pwd.h>
  98. #include <setjmp.h>
  99. #ifdef SYSSYSLOG
  100. #include <sys/syslog.h>
  101. #else
  102. #include <syslog.h>
  103. #endif
  104. #include <time.h>
  105. #include <string.h>
  106. #include <limits.h>
  107. #include "ftw.h"
  108. #include "extensions.h"
  109. #include "pathnames.h"
  110.  
  111. extern  int dolreplies;
  112. extern  char ls_long[50];
  113. extern  char ls_short[50];
  114. extern  struct sockaddr_in data_dest;
  115. extern  int logged_in;
  116. extern  struct passwd *pw;
  117. extern  int anonymous;
  118. extern  int logging;
  119. extern  int log_commands;
  120. extern  int type;
  121. extern  int form;
  122. extern  int debug;
  123. extern  int timeout;
  124. extern  int maxtimeout;
  125. extern  int pdata;
  126. extern  char hostname[], remotehost[];
  127. #ifdef SETPROCTITLE
  128. extern  char proctitle[];
  129. #endif
  130. extern  char *globerr;
  131. extern  int usedefault;
  132. extern  int transflag;
  133. extern  char tmpline[];
  134. extern  int data;
  135. char    **ftpglob();
  136. off_t   restart_point;
  137. void    print_groups(void);
  138.  
  139. extern  char    *strunames[];
  140. extern  char    *typenames[];
  141. extern  char    *modenames[];
  142. extern  char    *formnames[];
  143.  
  144. static  int cmd_type;
  145. static  int cmd_form;
  146. static  int cmd_bytesz;
  147. char    cbuf[512];
  148. char    *fromname;
  149.  
  150.  
  151. struct tab {
  152.     char    *name;
  153.     short   token;
  154.     short   state;
  155.     short   implemented;    /* 1 if command is implemented */
  156.     char    *help;
  157. } cmdtab[], sitetab[];
  158.  
  159. static void toolong();
  160.  
  161.  
  162. #line 142 "ftpcmd.y"
  163. typedef union {
  164.     char    *String;
  165.     int     Number;
  166. } YYSTYPE;
  167.  
  168. #ifndef YYLTYPE
  169. typedef
  170.   struct yyltype
  171.     {
  172.       int timestamp;
  173.       int first_line;
  174.       int first_column;
  175.       int last_line;
  176.       int last_column;
  177.       char *text;
  178.    }
  179.   yyltype;
  180.  
  181. #define YYLTYPE yyltype
  182. #endif
  183.  
  184. #include <stdio.h>
  185.  
  186. #ifndef __cplusplus
  187. #ifndef __STDC__
  188. #define const
  189. #endif
  190. #endif
  191.  
  192.  
  193.  
  194. #define    YYFINAL        249
  195. #define    YYFLAG        -32768
  196. #define    YYNTBASE    75
  197.  
  198. #define YYTRANSLATE(x) ((unsigned)(x) <= 329 ? yytranslate[x] : 90)
  199.  
  200. static const char yytranslate[] = {     0,
  201.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  202.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  203.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  204.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  205.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  206.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  207.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  208.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  209.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  210.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  211.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  212.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  213.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  214.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  215.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  216.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  217.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  218.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  219.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  220.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  221.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  222.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  223.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  224.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  225.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  226.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  227.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
  228.     16,    17,    18,    19,    20,    21,    22,    23,    24,    25,
  229.     26,    27,    28,    29,    30,    31,    32,    33,    34,    35,
  230.     36,    37,    38,    39,    40,    41,    42,    43,    44,    45,
  231.     46,    47,    48,    49,    50,    51,    52,    53,    54,    55,
  232.     56,    57,    58,    59,    60,    61,    62,    63,    64,    65,
  233.     66,    67,    68,    69,    70,    71,    72,    73,    74
  234. };
  235.  
  236. #if YYDEBUG != 0
  237. static const short yyprhs[] = {     0,
  238.      0,     1,     4,     7,    12,    17,    22,    25,    30,    35,
  239.     40,    45,    54,    60,    66,    72,    76,    82,    86,    92,
  240.     98,   101,   107,   112,   115,   119,   125,   128,   133,   136,
  241.    142,   148,   152,   156,   161,   168,   174,   182,   192,   197,
  242.    204,   212,   220,   228,   238,   248,   256,   264,   270,   273,
  243.    279,   285,   288,   291,   297,   302,   307,   314,   319,   324,
  244.    326,   327,   329,   331,   343,   345,   347,   349,   351,   355,
  245.    357,   361,   363,   365,   369,   372,   374,   376,   378,   380,
  246.    382,   384,   386,   388,   390
  247. };
  248.  
  249. static const short yyrhs[] = {    -1,
  250.     75,    76,     0,    75,    77,     0,    20,    15,    78,    16,
  251.      0,    21,    15,    79,    16,     0,    25,    15,    81,    16,
  252.      0,    26,    16,     0,    27,    15,    83,    16,     0,    28,
  253.     15,    84,    16,     0,    29,    15,    85,    16,     0,    40,
  254.     15,    19,    16,     0,    40,    15,    19,    15,    12,    15,
  255.     19,    16,     0,    30,    89,    15,    86,    16,     0,    31,
  256.     89,    15,    86,    16,     0,    32,    89,    15,    86,    16,
  257.      0,    48,    89,    16,     0,    48,    89,    15,    18,    16,
  258.      0,    47,    89,    16,     0,    47,    89,    15,    86,    16,
  259.      0,    50,    89,    15,    86,    16,     0,    50,    16,     0,
  260.     45,    89,    15,    86,    16,     0,    43,    15,    86,    16,
  261.      0,    44,    16,     0,    46,    89,    16,     0,    46,    89,
  262.     15,    86,    16,     0,    51,    16,     0,    51,    15,    18,
  263.     16,     0,    52,    16,     0,    53,    89,    15,    86,    16,
  264.      0,    54,    89,    15,    86,    16,     0,    55,    89,    16,
  265.      0,    56,    89,    16,     0,    49,    15,    51,    16,     0,
  266.     49,    15,    51,    15,    18,    16,     0,    49,    15,    62,
  267.     89,    16,     0,    49,    15,    62,    89,    15,    88,    16,
  268.      0,    49,    15,    64,    89,    15,    88,    15,    86,    16,
  269.      0,    49,    15,    63,    16,     0,    49,    15,    63,    15,
  270.     19,    16,     0,    49,    15,    65,    89,    15,    78,    16,
  271.      0,    49,    15,    66,    89,    15,    79,    16,     0,    49,
  272.     15,    67,    89,    15,    18,    16,     0,    49,    15,    67,
  273.     89,    15,    18,    15,    86,    16,     0,    49,    15,    68,
  274.     89,    15,    18,    15,    86,    16,     0,    49,    15,    69,
  275.     89,    15,    18,    16,     0,    49,    15,    70,    89,    15,
  276.     18,    16,     0,    57,    89,    15,    86,    16,     0,    59,
  277.     16,     0,    60,    89,    15,    86,    16,     0,    61,    89,
  278.     15,    86,    16,     0,    24,    16,     0,     1,    16,     0,
  279.     42,    89,    15,    86,    16,     0,    41,    15,    80,    16,
  280.      0,    49,    15,    71,    16,     0,    49,    15,    71,    15,
  281.     18,    16,     0,    49,    15,    73,    16,     0,    49,    15,
  282.     72,    16,     0,    18,     0,     0,    18,     0,    19,     0,
  283.     19,    17,    19,    17,    19,    17,    19,    17,    19,    17,
  284.     19,     0,    10,     0,    14,     0,     5,     0,     3,     0,
  285.      3,    15,    82,     0,     6,     0,     6,    15,    82,     0,
  286.      8,     0,     9,     0,     9,    15,    80,     0,     9,    80,
  287.      0,     7,     0,    12,     0,    11,     0,    13,     0,     4,
  288.      0,     5,     0,    87,     0,    18,     0,    19,     0,     0
  289. };
  290.  
  291. #endif
  292.  
  293. #if YYDEBUG != 0
  294. static const short yyrline[] = { 0,
  295.    155,   156,   161,   164,   170,   181,   191,   196,   232,   245,
  296.    258,   263,   268,   276,   284,   292,   298,   306,   315,   326,
  297.    334,   339,   347,   359,   364,   370,   378,   383,   399,   404,
  298.    412,   420,   426,   432,   437,   442,   453,   477,   502,   509,
  299.    524,   532,   540,   545,   551,   557,   570,   576,   584,   606,
  300.    624,   647,   653,   658,   671,   682,   687,   692,   697,   704,
  301.    707,   712,   715,   718,   731,   735,   739,   745,   750,   755,
  302.    760,   765,   769,   774,   780,   787,   791,   795,   801,   805,
  303.    809,   815,   834,   837,   862
  304. };
  305.  
  306. static const char * const yytname[] = {   "$","error","$illegal.","A","B","C",
  307. "E","F","I","L","N","P","R","S","T","SP","CRLF","COMMA","STRING","NUMBER","USER",
  308. "PASS","ACCT","REIN","QUIT","PORT","PASV","TYPE","STRU","MODE","RETR","STOR",
  309. "APPE","MLFL","MAIL","MSND","MSOM","MSAM","MRSQ","MRCP","ALLO","REST","RNFR",
  310. "RNTO","ABOR","DELE","CWD","LIST","NLST","SITE","STAT","HELP","NOOP","MKD","RMD",
  311. "PWD","CDUP","STOU","SMNT","SYST","SIZE","MDTM","UMASK","IDLE","CHMOD","GROUP",
  312. "GPASS","NEWER","MINFO","INDEX","EXEC","ALIAS","CDPATH","GROUPS","LEXERR","cmd_list",
  313. "cmd","rcmd","username","password","byte_size","host_port","form_code","type_code",
  314. "struct_code","mode_code","pathname","pathstring","octal_number","check_login",
  315. ""
  316. };
  317. #endif
  318.  
  319. static const short yyr1[] = {     0,
  320.     75,    75,    75,    76,    76,    76,    76,    76,    76,    76,
  321.     76,    76,    76,    76,    76,    76,    76,    76,    76,    76,
  322.     76,    76,    76,    76,    76,    76,    76,    76,    76,    76,
  323.     76,    76,    76,    76,    76,    76,    76,    76,    76,    76,
  324.     76,    76,    76,    76,    76,    76,    76,    76,    76,    76,
  325.     76,    76,    76,    77,    77,    77,    77,    77,    77,    78,
  326.     79,    79,    80,    81,    82,    82,    82,    83,    83,    83,
  327.     83,    83,    83,    83,    83,    84,    84,    84,    85,    85,
  328.     85,    86,    87,    88,    89
  329. };
  330.  
  331. static const short yyr2[] = {     0,
  332.      0,     2,     2,     4,     4,     4,     2,     4,     4,     4,
  333.      4,     8,     5,     5,     5,     3,     5,     3,     5,     5,
  334.      2,     5,     4,     2,     3,     5,     2,     4,     2,     5,
  335.      5,     3,     3,     4,     6,     5,     7,     9,     4,     6,
  336.      7,     7,     7,     9,     9,     7,     7,     5,     2,     5,
  337.      5,     2,     2,     5,     4,     4,     6,     4,     4,     1,
  338.      0,     1,     1,    11,     1,     1,     1,     1,     3,     1,
  339.      3,     1,     1,     3,     2,     1,     1,     1,     1,     1,
  340.      1,     1,     1,     1,     0
  341. };
  342.  
  343. static const short yydefact[] = {     1,
  344.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  345.     85,    85,    85,     0,     0,    85,     0,     0,    85,    85,
  346.     85,    85,     0,    85,     0,     0,    85,    85,    85,    85,
  347.     85,     0,    85,    85,     2,     3,    53,     0,    61,    52,
  348.      0,     7,     0,     0,     0,     0,     0,     0,     0,     0,
  349.      0,     0,    24,     0,     0,     0,     0,     0,    21,     0,
  350.      0,    27,    29,     0,     0,     0,     0,     0,    49,     0,
  351.      0,    60,     0,    62,     0,     0,     0,    68,    70,    72,
  352.     73,     0,    76,    78,    77,     0,    80,    81,    79,     0,
  353.      0,     0,     0,     0,    63,     0,     0,    83,     0,    82,
  354.      0,     0,    25,     0,    18,     0,    16,     0,    85,     0,
  355.     85,    85,    85,    85,    85,    85,    85,     0,     0,     0,
  356.      0,     0,     0,     0,    32,    33,     0,     0,     0,     4,
  357.      5,     0,     6,     0,     0,     0,    75,     8,     9,    10,
  358.      0,     0,     0,     0,    11,    55,     0,    23,     0,     0,
  359.      0,     0,     0,    34,     0,     0,    39,     0,     0,     0,
  360.      0,     0,     0,     0,     0,    56,    59,    58,     0,    28,
  361.      0,     0,     0,     0,     0,     0,    67,    65,    66,    69,
  362.     71,    74,    13,    14,    15,     0,    54,    22,    26,    19,
  363.     17,     0,     0,    36,     0,     0,     0,    61,     0,     0,
  364.      0,     0,     0,    20,    30,    31,    48,    50,    51,     0,
  365.      0,    35,    84,     0,    40,     0,     0,     0,     0,     0,
  366.      0,     0,    57,     0,     0,    37,     0,    41,    42,     0,
  367.     43,     0,    46,    47,     0,    12,     0,     0,     0,     0,
  368.     38,    44,    45,     0,     0,     0,    64,     0,     0
  369. };
  370.  
  371. static const short yydefgoto[] = {     1,
  372.     35,    36,    73,    75,    96,    77,   180,    82,    86,    90,
  373.     99,   100,   214,    46
  374. };
  375.  
  376. static const short yypact[] = {-32768,
  377.     48,   -12,    -8,    -3,    15,    19,    26,    39,    70,    95,
  378. -32768,-32768,-32768,    99,   108,-32768,   109,   100,-32768,-32768,
  379. -32768,-32768,   110,   111,    13,   112,-32768,-32768,-32768,-32768,
  380. -32768,   113,-32768,-32768,-32768,-32768,-32768,   114,   115,-32768,
  381.    107,-32768,    78,    34,    22,   116,   119,   120,   118,   130,
  382.    123,   132,-32768,   136,    24,    41,    51,   -48,-32768,   137,
  383.    135,-32768,-32768,   139,   140,   141,   142,   144,-32768,   145,
  384.    146,-32768,   147,-32768,   148,   149,   151,   150,   153,-32768,
  385.    -10,   154,-32768,-32768,-32768,   155,-32768,-32768,-32768,   156,
  386.    132,   132,   132,    55,-32768,   157,   132,-32768,   158,-32768,
  387.    132,   132,-32768,   132,-32768,   138,-32768,    67,-32768,    97,
  388. -32768,-32768,-32768,-32768,-32768,-32768,-32768,   102,   159,   160,
  389.    132,   161,   132,   132,-32768,-32768,   132,   132,   132,-32768,
  390. -32768,   143,-32768,   101,   101,   130,-32768,-32768,-32768,-32768,
  391.    162,   163,   164,   169,-32768,-32768,   166,-32768,   167,   168,
  392.    170,   171,   172,-32768,   104,   173,-32768,   174,   176,   178,
  393.    179,   180,   181,   182,   183,-32768,-32768,-32768,   184,-32768,
  394.    186,   187,   188,   189,   190,   152,-32768,-32768,-32768,-32768,
  395. -32768,-32768,-32768,-32768,-32768,   192,-32768,-32768,-32768,-32768,
  396. -32768,   193,   191,-32768,   195,   191,   114,   115,   194,   196,
  397.    197,   198,   201,-32768,-32768,-32768,-32768,-32768,-32768,   199,
  398.    200,-32768,-32768,   204,-32768,   206,   207,   208,   106,   210,
  399.    211,   212,-32768,   205,   213,-32768,   132,-32768,-32768,   132,
  400. -32768,   132,-32768,-32768,   214,-32768,   215,   216,   218,   209,
  401. -32768,-32768,-32768,   217,   220,   219,-32768,   185,-32768
  402. };
  403.  
  404. static const short yypgoto[] = {-32768,
  405. -32768,-32768,   -67,     0,   -73,-32768,    53,-32768,-32768,-32768,
  406.    -91,-32768,     3,    31
  407. };
  408.  
  409.  
  410. #define    YYLAST        238
  411.  
  412.  
  413. static const short yytable[] = {   141,
  414.    142,   143,   108,    37,   136,   147,    38,   137,    95,   149,
  415.    150,    39,   151,   109,   110,   111,   112,   113,   114,   115,
  416.    116,   117,   118,   119,   120,    87,    88,    61,    62,   169,
  417.     40,   171,   172,    41,    89,   173,   174,   175,   102,   103,
  418.     83,    42,    47,    48,    84,    85,    51,   248,     2,    54,
  419.     55,    56,    57,    43,    60,   104,   105,    64,    65,    66,
  420.     67,    68,   182,    70,    71,   106,   107,     3,     4,   144,
  421.    145,     5,     6,     7,     8,     9,    10,    11,    12,    13,
  422.     78,   153,   154,    79,    44,    80,    81,    14,    15,    16,
  423.     17,    18,    19,    20,    21,    22,    23,    24,    25,    26,
  424.     27,    28,    29,    30,    31,   177,    32,    33,    34,    45,
  425.    178,   156,   157,    49,   179,    53,   165,   166,   193,   194,
  426.    230,   231,    50,    52,    58,    76,    59,    63,    69,   217,
  427.     91,    72,    74,    92,    93,   237,    94,    97,   238,   155,
  428.    239,   158,   159,   160,   161,   162,   163,   164,    95,    98,
  429.    101,   121,   122,   123,   124,   152,   125,   126,   127,   128,
  430.    129,   176,   130,   131,   134,   132,   133,   135,   210,   138,
  431.    139,   140,   146,   148,   167,   168,   170,   183,   184,   185,
  432.    186,   187,   188,   189,   249,   190,   191,   181,   196,   192,
  433.    197,   195,   198,   199,   200,   201,   202,   218,   216,   204,
  434.    203,   205,   206,   207,   208,   209,   211,     0,   212,   213,
  435.    215,   219,     0,   220,   221,   222,   223,   224,   225,   226,
  436.    227,   235,   228,   229,   232,   244,   233,   234,   236,     0,
  437.    241,   242,   240,   243,     0,   245,   246,   247
  438. };
  439.  
  440. static const short yycheck[] = {    91,
  441.     92,    93,    51,    16,    15,    97,    15,    81,    19,   101,
  442.    102,    15,   104,    62,    63,    64,    65,    66,    67,    68,
  443.     69,    70,    71,    72,    73,     4,     5,    15,    16,   121,
  444.     16,   123,   124,    15,    13,   127,   128,   129,    15,    16,
  445.      7,    16,    12,    13,    11,    12,    16,     0,     1,    19,
  446.     20,    21,    22,    15,    24,    15,    16,    27,    28,    29,
  447.     30,    31,   136,    33,    34,    15,    16,    20,    21,    15,
  448.     16,    24,    25,    26,    27,    28,    29,    30,    31,    32,
  449.      3,    15,    16,     6,    15,     8,     9,    40,    41,    42,
  450.     43,    44,    45,    46,    47,    48,    49,    50,    51,    52,
  451.     53,    54,    55,    56,    57,     5,    59,    60,    61,    15,
  452.     10,    15,    16,    15,    14,    16,    15,    16,    15,    16,
  453.     15,    16,    15,    15,    15,    19,    16,    16,    16,   197,
  454.     15,    18,    18,    15,    15,   227,    19,    15,   230,   109,
  455.    232,   111,   112,   113,   114,   115,   116,   117,    19,    18,
  456.     15,    15,    18,    15,    15,    18,    16,    16,    15,    15,
  457.     15,    19,    16,    16,    15,    17,    16,    15,    17,    16,
  458.     16,    16,    16,    16,    16,    16,    16,    16,    16,    16,
  459.     12,    16,    16,    16,     0,    16,    16,   135,    15,    18,
  460.     15,    19,    15,    15,    15,    15,    15,   198,   196,    16,
  461.     18,    16,    16,    16,    16,    16,    15,    -1,    16,    19,
  462.     16,    18,    -1,    18,    18,    18,    16,    19,    19,    16,
  463.     15,    17,    16,    16,    15,    17,    16,    16,    16,    -1,
  464.     16,    16,    19,    16,    -1,    19,    17,    19
  465. };
  466. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  467. #line 3 "/usr/lib/bison.simple"
  468.  
  469. /* Skeleton output parser for bison,
  470.    Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  471.  
  472.    This program is free software; you can redistribute it and/or modify
  473.    it under the terms of the GNU General Public License as published by
  474.    the Free Software Foundation; either version 1, or (at your option)
  475.    any later version.
  476.  
  477.    This program is distributed in the hope that it will be useful,
  478.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  479.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  480.    GNU General Public License for more details.
  481.  
  482.    You should have received a copy of the GNU General Public License
  483.    along with this program; if not, write to the Free Software
  484.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  485.  
  486.  
  487. #ifndef alloca
  488. #ifdef __GNUC__
  489. #define alloca __builtin_alloca
  490. #else /* not GNU C.  */
  491. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
  492. #include <alloca.h>
  493. #else /* not sparc */
  494. #if defined (MSDOS) && !defined (__TURBOC__)
  495. #include <malloc.h>
  496. #else /* not MSDOS, or __TURBOC__ */
  497. #if defined(_AIX)
  498. #include <malloc.h>
  499.  #pragma alloca
  500. #else /* not MSDOS, __TURBOC__, or _AIX */
  501. #ifdef __hpux
  502. #ifdef __cplusplus
  503. extern "C" {
  504. void *alloca (unsigned int);
  505. };
  506. #else /* not __cplusplus */
  507. void *alloca ();
  508. #endif /* not __cplusplus */
  509. #endif /* __hpux */
  510. #endif /* not _AIX */
  511. #endif /* not MSDOS, or __TURBOC__ */
  512. #endif /* not sparc.  */
  513. #endif /* not GNU C.  */
  514. #endif /* alloca not defined.  */
  515.  
  516. /* This is the parser code that is written into each bison parser
  517.   when the %semantic_parser declaration is not specified in the grammar.
  518.   It was written by Richard Stallman by simplifying the hairy parser
  519.   used when %semantic_parser is specified.  */
  520.  
  521. /* Note: there must be only one dollar sign in this file.
  522.    It is replaced by the list of actions, each action
  523.    as one case of the switch.  */
  524.  
  525. #define yyerrok        (yyerrstatus = 0)
  526. #define yyclearin    (yychar = YYEMPTY)
  527. #define YYEMPTY        -2
  528. #define YYEOF        0
  529. #define YYACCEPT    return(0)
  530. #define YYABORT     return(1)
  531. #define YYERROR        goto yyerrlab1
  532. /* Like YYERROR except do call yyerror.
  533.    This remains here temporarily to ease the
  534.    transition to the new meaning of YYERROR, for GCC.
  535.    Once GCC version 2 has supplanted version 1, this can go.  */
  536. #define YYFAIL        goto yyerrlab
  537. #define YYRECOVERING()  (!!yyerrstatus)
  538. #define YYBACKUP(token, value) \
  539. do                                \
  540.   if (yychar == YYEMPTY && yylen == 1)                \
  541.     { yychar = (token), yylval = (value);            \
  542.       yychar1 = YYTRANSLATE (yychar);                \
  543.       YYPOPSTACK;                        \
  544.       goto yybackup;                        \
  545.     }                                \
  546.   else                                \
  547.     { yyerror ("syntax error: cannot back up"); YYERROR; }    \
  548. while (0)
  549.  
  550. #define YYTERROR    1
  551. #define YYERRCODE    256
  552.  
  553. #ifndef YYPURE
  554. #define YYLEX        yylex()
  555. #endif
  556.  
  557. #ifdef YYPURE
  558. #ifdef YYLSP_NEEDED
  559. #define YYLEX        yylex(&yylval, &yylloc)
  560. #else
  561. #define YYLEX        yylex(&yylval)
  562. #endif
  563. #endif
  564.  
  565. /* If nonreentrant, generate the variables here */
  566.  
  567. #ifndef YYPURE
  568.  
  569. int    yychar;            /*  the lookahead symbol        */
  570. YYSTYPE    yylval;            /*  the semantic value of the        */
  571.                 /*  lookahead symbol            */
  572.  
  573. #ifdef YYLSP_NEEDED
  574. YYLTYPE yylloc;            /*  location data for the lookahead    */
  575.                 /*  symbol                */
  576. #endif
  577.  
  578. int yynerrs;            /*  number of parse errors so far       */
  579. #endif  /* not YYPURE */
  580.  
  581. #if YYDEBUG != 0
  582. int yydebug;            /*  nonzero means print parse trace    */
  583. /* Since this is uninitialized, it does not stop multiple parsers
  584.    from coexisting.  */
  585. #endif
  586.  
  587. /*  YYINITDEPTH indicates the initial size of the parser's stacks    */
  588.  
  589. #ifndef    YYINITDEPTH
  590. #define YYINITDEPTH 200
  591. #endif
  592.  
  593. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  594.     (effective only if the built-in stack extension method is used).  */
  595.  
  596. #if YYMAXDEPTH == 0
  597. #undef YYMAXDEPTH
  598. #endif
  599.  
  600. #ifndef YYMAXDEPTH
  601. #define YYMAXDEPTH 10000
  602. #endif
  603.  
  604. /* Prevent warning if -Wstrict-prototypes.  */
  605. #ifdef __GNUC__
  606. int yyparse (void);
  607. #endif
  608.  
  609. #if __GNUC__ > 1        /* GNU C and GNU C++ define this.  */
  610. #define __yy_bcopy(FROM,TO,COUNT)    __builtin_memcpy(TO,FROM,COUNT)
  611. #else                /* not GNU C or C++ */
  612. #ifndef __cplusplus
  613.  
  614. /* This is the most reliable way to avoid incompatibilities
  615.    in available built-in functions on various systems.  */
  616. static void
  617. __yy_bcopy (from, to, count)
  618.      char *from;
  619.      char *to;
  620.      int count;
  621. {
  622.   register char *f = from;
  623.   register char *t = to;
  624.   register int i = count;
  625.  
  626.   while (i-- > 0)
  627.     *t++ = *f++;
  628. }
  629.  
  630. #else /* __cplusplus */
  631.  
  632. /* This is the most reliable way to avoid incompatibilities
  633.    in available built-in functions on various systems.  */
  634. static void
  635. __yy_bcopy (char *from, char *to, int count)
  636. {
  637.   register char *f = from;
  638.   register char *t = to;
  639.   register int i = count;
  640.  
  641.   while (i-- > 0)
  642.     *t++ = *f++;
  643. }
  644.  
  645. #endif
  646. #endif
  647.  
  648. #line 184 "/usr/lib/bison.simple"
  649. int
  650. yyparse()
  651. {
  652.   register int yystate;
  653.   register int yyn;
  654.   register short *yyssp;
  655.   register YYSTYPE *yyvsp;
  656.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  657.   int yychar1 = 0;        /*  lookahead token as an internal (translated) token number */
  658.  
  659.   short    yyssa[YYINITDEPTH];    /*  the state stack            */
  660.   YYSTYPE yyvsa[YYINITDEPTH];    /*  the semantic value stack        */
  661.  
  662.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  663.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  664.  
  665. #ifdef YYLSP_NEEDED
  666.   YYLTYPE yylsa[YYINITDEPTH];    /*  the location stack            */
  667.   YYLTYPE *yyls = yylsa;
  668.   YYLTYPE *yylsp;
  669.  
  670. #define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
  671. #else
  672. #define YYPOPSTACK   (yyvsp--, yyssp--)
  673. #endif
  674.  
  675.   int yystacksize = YYINITDEPTH;
  676.  
  677. #ifdef YYPURE
  678.   int yychar;
  679.   YYSTYPE yylval;
  680.   int yynerrs;
  681. #ifdef YYLSP_NEEDED
  682.   YYLTYPE yylloc;
  683. #endif
  684. #endif
  685.  
  686.   YYSTYPE yyval;        /*  the variable used to return        */
  687.                 /*  semantic values from the action    */
  688.                 /*  routines                */
  689.  
  690.   int yylen;
  691.  
  692. #if YYDEBUG != 0
  693.   if (yydebug)
  694.     fprintf(stderr, "Starting parse\n");
  695. #endif
  696.  
  697.   yystate = 0;
  698.   yyerrstatus = 0;
  699.   yynerrs = 0;
  700.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  701.  
  702.   /* Initialize stack pointers.
  703.      Waste one element of value and location stack
  704.      so that they stay on the same level as the state stack.
  705.      The wasted elements are never initialized.  */
  706.  
  707.   yyssp = yyss - 1;
  708.   yyvsp = yyvs;
  709. #ifdef YYLSP_NEEDED
  710.   yylsp = yyls;
  711. #endif
  712.  
  713. /* Push a new state, which is found in  yystate  .  */
  714. /* In all cases, when you get here, the value and location stacks
  715.    have just been pushed. so pushing a state here evens the stacks.  */
  716. yynewstate:
  717.  
  718.   *++yyssp = yystate;
  719.  
  720.   if (yyssp >= yyss + yystacksize - 1)
  721.     {
  722.       /* Give user a chance to reallocate the stack */
  723.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  724.       YYSTYPE *yyvs1 = yyvs;
  725.       short *yyss1 = yyss;
  726. #ifdef YYLSP_NEEDED
  727.       YYLTYPE *yyls1 = yyls;
  728. #endif
  729.  
  730.       /* Get the current used size of the three stacks, in elements.  */
  731.       int size = yyssp - yyss + 1;
  732.  
  733. #ifdef yyoverflow
  734.       /* Each stack pointer address is followed by the size of
  735.      the data in use in that stack, in bytes.  */
  736. #ifdef YYLSP_NEEDED
  737.       /* This used to be a conditional around just the two extra args,
  738.      but that might be undefined if yyoverflow is a macro.  */
  739.       yyoverflow("parser stack overflow",
  740.          &yyss1, size * sizeof (*yyssp),
  741.          &yyvs1, size * sizeof (*yyvsp),
  742.          &yyls1, size * sizeof (*yylsp),
  743.          &yystacksize);
  744. #else
  745.       yyoverflow("parser stack overflow",
  746.          &yyss1, size * sizeof (*yyssp),
  747.          &yyvs1, size * sizeof (*yyvsp),
  748.          &yystacksize);
  749. #endif
  750.  
  751.       yyss = yyss1; yyvs = yyvs1;
  752. #ifdef YYLSP_NEEDED
  753.       yyls = yyls1;
  754. #endif
  755. #else /* no yyoverflow */
  756.       /* Extend the stack our own way.  */
  757.       if (yystacksize >= YYMAXDEPTH)
  758.     {
  759.       yyerror("parser stack overflow");
  760.       return 2;
  761.     }
  762.       yystacksize *= 2;
  763.       if (yystacksize > YYMAXDEPTH)
  764.     yystacksize = YYMAXDEPTH;
  765.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  766.       __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  767.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  768.       __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  769. #ifdef YYLSP_NEEDED
  770.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  771.       __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  772. #endif
  773. #endif /* no yyoverflow */
  774.  
  775.       yyssp = yyss + size - 1;
  776.       yyvsp = yyvs + size - 1;
  777. #ifdef YYLSP_NEEDED
  778.       yylsp = yyls + size - 1;
  779. #endif
  780.  
  781. #if YYDEBUG != 0
  782.       if (yydebug)
  783.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  784. #endif
  785.  
  786.       if (yyssp >= yyss + yystacksize - 1)
  787.     YYABORT;
  788.     }
  789.  
  790. #if YYDEBUG != 0
  791.   if (yydebug)
  792.     fprintf(stderr, "Entering state %d\n", yystate);
  793. #endif
  794.  
  795.   goto yybackup;
  796.  yybackup:
  797.  
  798. /* Do appropriate processing given the current state.  */
  799. /* Read a lookahead token if we need one and don't already have one.  */
  800. /* yyresume: */
  801.  
  802.   /* First try to decide what to do without reference to lookahead token.  */
  803.  
  804.   yyn = yypact[yystate];
  805.   if (yyn == YYFLAG)
  806.     goto yydefault;
  807.  
  808.   /* Not known => get a lookahead token if don't already have one.  */
  809.  
  810.   /* yychar is either YYEMPTY or YYEOF
  811.      or a valid token in external form.  */
  812.  
  813.   if (yychar == YYEMPTY)
  814.     {
  815. #if YYDEBUG != 0
  816.       if (yydebug)
  817.     fprintf(stderr, "Reading a token: ");
  818. #endif
  819.       yychar = YYLEX;
  820.     }
  821.  
  822.   /* Convert token to internal form (in yychar1) for indexing tables with */
  823.  
  824.   if (yychar <= 0)        /* This means end of input. */
  825.     {
  826.       yychar1 = 0;
  827.       yychar = YYEOF;        /* Don't call YYLEX any more */
  828.  
  829. #if YYDEBUG != 0
  830.       if (yydebug)
  831.     fprintf(stderr, "Now at end of input.\n");
  832. #endif
  833.     }
  834.   else
  835.     {
  836.       yychar1 = YYTRANSLATE(yychar);
  837.  
  838. #if YYDEBUG != 0
  839.       if (yydebug)
  840.     {
  841.       fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
  842.       /* Give the individual parser a way to print the precise meaning
  843.          of a token, for further debugging info.  */
  844. #ifdef YYPRINT
  845.       YYPRINT (stderr, yychar, yylval);
  846. #endif
  847.       fprintf (stderr, ")\n");
  848.     }
  849. #endif
  850.     }
  851.  
  852.   yyn += yychar1;
  853.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  854.     goto yydefault;
  855.  
  856.   yyn = yytable[yyn];
  857.  
  858.   /* yyn is what to do for this token type in this state.
  859.      Negative => reduce, -yyn is rule number.
  860.      Positive => shift, yyn is new state.
  861.        New state is final state => don't bother to shift,
  862.        just return success.
  863.      0, or most negative number => error.  */
  864.  
  865.   if (yyn < 0)
  866.     {
  867.       if (yyn == YYFLAG)
  868.     goto yyerrlab;
  869.       yyn = -yyn;
  870.       goto yyreduce;
  871.     }
  872.   else if (yyn == 0)
  873.     goto yyerrlab;
  874.  
  875.   if (yyn == YYFINAL)
  876.     YYACCEPT;
  877.  
  878.   /* Shift the lookahead token.  */
  879.  
  880. #if YYDEBUG != 0
  881.   if (yydebug)
  882.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  883. #endif
  884.  
  885.   /* Discard the token being shifted unless it is eof.  */
  886.   if (yychar != YYEOF)
  887.     yychar = YYEMPTY;
  888.  
  889.   *++yyvsp = yylval;
  890. #ifdef YYLSP_NEEDED
  891.   *++yylsp = yylloc;
  892. #endif
  893.  
  894.   /* count tokens shifted since error; after three, turn off error status.  */
  895.   if (yyerrstatus) yyerrstatus--;
  896.  
  897.   yystate = yyn;
  898.   goto yynewstate;
  899.  
  900. /* Do the default action for the current state.  */
  901. yydefault:
  902.  
  903.   yyn = yydefact[yystate];
  904.   if (yyn == 0)
  905.     goto yyerrlab;
  906.  
  907. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  908. yyreduce:
  909.   yylen = yyr2[yyn];
  910.   if (yylen > 0)
  911.     yyval = yyvsp[1-yylen]; /* implement default value of the action */
  912.  
  913. #if YYDEBUG != 0
  914.   if (yydebug)
  915.     {
  916.       int i;
  917.  
  918.       fprintf (stderr, "Reducing via rule %d (line %d), ",
  919.            yyn, yyrline[yyn]);
  920.  
  921.       /* Print the symbols being reduced, and their result.  */
  922.       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
  923.     fprintf (stderr, "%s ", yytname[yyrhs[i]]);
  924.       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
  925.     }
  926. #endif
  927.  
  928.  
  929.   switch (yyn) {
  930.  
  931. case 2:
  932. #line 157 "ftpcmd.y"
  933. {
  934.             fromname = 0;
  935.             restart_point = 0;
  936.         ;
  937.     break;}
  938. case 4:
  939. #line 165 "ftpcmd.y"
  940. {
  941.             user(yyvsp[-1].String);
  942.             if (log_commands) syslog(LOG_INFO, "USER %s", yyvsp[-1].String);
  943.             free(yyvsp[-1].String);
  944.         ;
  945.     break;}
  946. case 5:
  947. #line 171 "ftpcmd.y"
  948. {
  949.             if (log_commands)
  950.                 if (anonymous)
  951.                     syslog(LOG_INFO, "PASS %s", yyvsp[-1].String);
  952.                 else
  953.                     syslog(LOG_INFO, "PASS password");
  954.  
  955.             pass(yyvsp[-1].String);
  956.             free(yyvsp[-1].String);
  957.         ;
  958.     break;}
  959. case 6:
  960. #line 182 "ftpcmd.y"
  961. {
  962.             if (log_commands) syslog(LOG_INFO, "PORT");
  963.             usedefault = 0;
  964.             if (pdata >= 0) {
  965.                 (void) close(pdata);
  966.                 pdata = -1;
  967.             }
  968.             reply(200, "PORT command successful.");
  969.         ;
  970.     break;}
  971. case 7:
  972. #line 192 "ftpcmd.y"
  973. {
  974.             if (log_commands) syslog(LOG_INFO, "PASV");
  975.             passive();
  976.         ;
  977.     break;}
  978. case 8:
  979. #line 197 "ftpcmd.y"
  980. {
  981.             if (log_commands) syslog(LOG_INFO, "TYPE %s", typenames[cmd_type]);
  982.             switch (cmd_type) {
  983.  
  984.             case TYPE_A:
  985.                 if (cmd_form == FORM_N) {
  986.                     reply(200, "Type set to A.");
  987.                     type = cmd_type;
  988.                     form = cmd_form;
  989.                 } else
  990.                     reply(504, "Form must be N.");
  991.                 break;
  992.  
  993.             case TYPE_E:
  994.                 reply(504, "Type E not implemented.");
  995.                 break;
  996.  
  997.             case TYPE_I:
  998.                 reply(200, "Type set to I.");
  999.                 type = cmd_type;
  1000.                 break;
  1001.  
  1002.             case TYPE_L:
  1003. #if NBBY == 8
  1004.                 if (cmd_bytesz == 8) {
  1005.                     reply(200,
  1006.                         "Type set to L (byte size 8).");
  1007.                     type = cmd_type;
  1008.                 } else
  1009.                     reply(504, "Byte size must be 8.");
  1010. #else /* NBBY == 8 */
  1011.                 UNIMPLEMENTED for NBBY != 8
  1012. #endif /* NBBY == 8 */
  1013.             }
  1014.         ;
  1015.     break;}
  1016. case 9:
  1017. #line 233 "ftpcmd.y"
  1018. {
  1019.             if (log_commands) syslog(LOG_INFO, "STRU %s", strunames[yyvsp[-1].Number]);
  1020.             switch (yyvsp[-1].Number) {
  1021.  
  1022.             case STRU_F:
  1023.                 reply(200, "STRU F ok.");
  1024.                 break;
  1025.  
  1026.             default:
  1027.                 reply(504, "Unimplemented STRU type.");
  1028.             }
  1029.         ;
  1030.     break;}
  1031. case 10:
  1032. #line 246 "ftpcmd.y"
  1033. {
  1034.             if (log_commands) syslog(LOG_INFO, "MODE %s", modenames[yyvsp[-1].Number]);
  1035.             switch (yyvsp[-1].Number) {
  1036.  
  1037.             case MODE_S:
  1038.                 reply(200, "MODE S ok.");
  1039.                 break;
  1040.  
  1041.             default:
  1042.                 reply(502, "Unimplemented MODE type.");
  1043.             }
  1044.         ;
  1045.     break;}
  1046. case 11:
  1047. #line 259 "ftpcmd.y"
  1048. {
  1049.             if (log_commands) syslog(LOG_INFO, "ALLO %d", yyvsp[-1].Number);
  1050.             reply(202, "ALLO command ignored.");
  1051.         ;
  1052.     break;}
  1053. case 12:
  1054. #line 264 "ftpcmd.y"
  1055. {
  1056.             if (log_commands) syslog(LOG_INFO, "ALLO %d R %d", yyvsp[-5].Number, yyvsp[-1].Number);
  1057.             reply(202, "ALLO command ignored.");
  1058.         ;
  1059.     break;}
  1060. case 13:
  1061. #line 269 "ftpcmd.y"
  1062. {
  1063.             if (log_commands) syslog(LOG_INFO, "RETR %s", yyvsp[-1].String);
  1064.             if (yyvsp[-3].Number && yyvsp[-1].String != NULL)
  1065.                 retrieve((char *) NULL, yyvsp[-1].String);
  1066.             if (yyvsp[-1].String != NULL)
  1067.                 free(yyvsp[-1].String);
  1068.         ;
  1069.     break;}
  1070. case 14:
  1071. #line 277 "ftpcmd.y"
  1072. {
  1073.             if (log_commands) syslog(LOG_INFO, "STOR %s", yyvsp[-1].String);
  1074.             if (yyvsp[-3].Number && yyvsp[-1].String != NULL)
  1075.                 store(yyvsp[-1].String, "w", 0);
  1076.             if (yyvsp[-1].String != NULL)
  1077.                 free(yyvsp[-1].String);
  1078.         ;
  1079.     break;}
  1080. case 15:
  1081. #line 285 "ftpcmd.y"
  1082. {
  1083.             if (log_commands) syslog(LOG_INFO, "APPE %s", yyvsp[-1].String);
  1084.             if (yyvsp[-3].Number && yyvsp[-1].String != NULL)
  1085.                 store(yyvsp[-1].String, "a", 0);
  1086.             if (yyvsp[-1].String != NULL)
  1087.                 free(yyvsp[-1].String);
  1088.         ;
  1089.     break;}
  1090. case 16:
  1091. #line 293 "ftpcmd.y"
  1092. {
  1093.             if (log_commands) syslog(LOG_INFO, "NLST");
  1094.             if (yyvsp[-1].Number)
  1095. #ifndef AMIGA
  1096.                 send_file_list(".");
  1097. #else
  1098.                 send_file_list("");
  1099. #endif
  1100.         ;
  1101.     break;}
  1102. case 17:
  1103. #line 299 "ftpcmd.y"
  1104. {
  1105.             if (log_commands) syslog(LOG_INFO, "NLST %s", yyvsp[-1].String);
  1106.             if (yyvsp[-3].Number && yyvsp[-1].String) {
  1107.                 send_file_list(yyvsp[-1].String);
  1108.                 free(yyvsp[-1].String);
  1109.             }
  1110.         ;
  1111.     break;}
  1112. case 18:
  1113. #line 307 "ftpcmd.y"
  1114. {
  1115.             if (log_commands) syslog(LOG_INFO, "LIST");
  1116.             if (yyvsp[-1].Number)
  1117.         if (anonymous && dolreplies)
  1118.                 retrieve(ls_long, "");
  1119.             else
  1120.                 retrieve(ls_short, "");
  1121.         ;
  1122.     break;}
  1123. case 19:
  1124. #line 316 "ftpcmd.y"
  1125. {
  1126.             if (log_commands) syslog(LOG_INFO, "LIST %s", yyvsp[-1].String);
  1127.             if (yyvsp[-3].Number && yyvsp[-1].String != NULL)
  1128.         if (anonymous && dolreplies)
  1129.                 retrieve(ls_long, yyvsp[-1].String);
  1130.             else
  1131.                 retrieve(ls_short, yyvsp[-1].String);
  1132.             if (yyvsp[-1].String != NULL)
  1133.                 free(yyvsp[-1].String);
  1134.         ;
  1135.     break;}
  1136. case 20:
  1137. #line 327 "ftpcmd.y"
  1138. {
  1139.             if (log_commands) syslog(LOG_INFO, "STAT %s", yyvsp[-1].String);
  1140.             if (yyvsp[-3].Number && yyvsp[-1].String != NULL)
  1141.                 statfilecmd(yyvsp[-1].String);
  1142.             if (yyvsp[-1].String != NULL)
  1143.                 free(yyvsp[-1].String);
  1144.         ;
  1145.     break;}
  1146. case 21:
  1147. #line 335 "ftpcmd.y"
  1148. {
  1149.             if (log_commands) syslog(LOG_INFO, "STAT");
  1150.             statcmd();
  1151.         ;
  1152.     break;}
  1153. case 22:
  1154. #line 340 "ftpcmd.y"
  1155. {
  1156.             if (log_commands) syslog(LOG_INFO, "DELE %s", yyvsp[-1].String);
  1157.             if (yyvsp[-3].Number && yyvsp[-1].String != NULL)
  1158.                 delete(yyvsp[-1].String);
  1159.             if (yyvsp[-1].String != NULL)
  1160.                 free(yyvsp[-1].String);
  1161.         ;
  1162.     break;}
  1163. case 23:
  1164. #line 348 "ftpcmd.y"
  1165. {
  1166.             if (log_commands) syslog(LOG_INFO, "RNTO %s", yyvsp[-1].String);
  1167.             if (fromname) {
  1168.                 renamecmd(fromname, yyvsp[-1].String);
  1169.                 free(fromname);
  1170.                 fromname = (char *) NULL;
  1171.             } else {
  1172.                 reply(503, "Bad sequence of commands.");
  1173.             }
  1174.             free(yyvsp[-1].String);
  1175.         ;
  1176.     break;}
  1177. case 24:
  1178. #line 360 "ftpcmd.y"
  1179. {
  1180.             if (log_commands) syslog(LOG_INFO, "ABOR");
  1181.             reply(225, "ABOR command successful.");
  1182.         ;
  1183.     break;}
  1184. case 25:
  1185. #line 365 "ftpcmd.y"
  1186. {
  1187.             if (log_commands) syslog(LOG_INFO, "CWD");
  1188.             if (yyvsp[-1].Number)
  1189.                 cwd(pw->pw_dir);
  1190.         ;
  1191.     break;}
  1192. case 26:
  1193. #line 371 "ftpcmd.y"
  1194. {
  1195.             if (log_commands) syslog(LOG_INFO, "CWD %s", yyvsp[-1].String);
  1196.             if (yyvsp[-3].Number && yyvsp[-1].String != NULL)
  1197.                 cwd(yyvsp[-1].String);
  1198.             if (yyvsp[-1].String != NULL)
  1199.                 free(yyvsp[-1].String);
  1200.         ;
  1201.     break;}
  1202. case 27:
  1203. #line 379 "ftpcmd.y"
  1204. {
  1205.             if (log_commands) syslog(LOG_INFO, "HELP");
  1206.             help(cmdtab, (char *) NULL);
  1207.         ;
  1208.     break;}
  1209. case 28:
  1210. #line 384 "ftpcmd.y"
  1211. {
  1212.             register char *cp = (char *)yyvsp[-1].String;
  1213.  
  1214.             if (log_commands) syslog(LOG_INFO, "HELP %s", yyvsp[-1].String);
  1215.             if (strncasecmp(cp, "SITE", 4) == 0) {
  1216.                 cp = (char *)yyvsp[-1].String + 4;
  1217.                 if (*cp == ' ')
  1218.                     cp++;
  1219.                 if (*cp)
  1220.                     help(sitetab, cp);
  1221.                 else
  1222.                     help(sitetab, (char *) NULL);
  1223.             } else
  1224.                 help(cmdtab, yyvsp[-1].String);
  1225.         ;
  1226.     break;}
  1227. case 29:
  1228. #line 400 "ftpcmd.y"
  1229. {
  1230.             if (log_commands) syslog(LOG_INFO, "NOOP");
  1231.             reply(200, "NOOP command successful.");
  1232.         ;
  1233.     break;}
  1234. case 30:
  1235. #line 405 "ftpcmd.y"
  1236. {
  1237.             if (log_commands) syslog(LOG_INFO, "MKD %s", yyvsp[-1].String);
  1238.             if (yyvsp[-3].Number && yyvsp[-1].String != NULL)
  1239.                 makedir(yyvsp[-1].String);
  1240.             if (yyvsp[-1].String != NULL)
  1241.                 free(yyvsp[-1].String);
  1242.         ;
  1243.     break;}
  1244. case 31:
  1245. #line 413 "ftpcmd.y"
  1246. {
  1247.             if (log_commands) syslog(LOG_INFO, "RMD %s", yyvsp[-1].String);
  1248.             if (yyvsp[-3].Number && yyvsp[-1].String != NULL)
  1249.                 removedir(yyvsp[-1].String);
  1250.             if (yyvsp[-1].String != NULL)
  1251.                 free(yyvsp[-1].String);
  1252.         ;
  1253.     break;}
  1254. case 32:
  1255. #line 421 "ftpcmd.y"
  1256. {
  1257.             if (log_commands) syslog(LOG_INFO, "PWD");
  1258.             if (yyvsp[-1].Number)
  1259.                 pwd();
  1260.         ;
  1261.     break;}
  1262. case 33:
  1263. #line 427 "ftpcmd.y"
  1264. {
  1265.             if (log_commands) syslog(LOG_INFO, "CDUP");
  1266.             if (yyvsp[-1].Number)
  1267.                 cwd("..");
  1268.         ;
  1269.     break;}
  1270. case 34:
  1271. #line 433 "ftpcmd.y"
  1272. {
  1273.             if (log_commands) syslog(LOG_INFO, "SITE HELP");
  1274.             help(sitetab, (char *) NULL);
  1275.         ;
  1276.     break;}
  1277. case 35:
  1278. #line 438 "ftpcmd.y"
  1279. {
  1280.             if (log_commands) syslog(LOG_INFO, "SITE HELP %s", yyvsp[-1].String);
  1281.             help(sitetab, yyvsp[-1].String);
  1282.         ;
  1283.     break;}
  1284. case 36:
  1285. #line 443 "ftpcmd.y"
  1286. {
  1287.             mode_t oldmask;
  1288.  
  1289.             if (log_commands) syslog(LOG_INFO, "SITE UMASK");
  1290.             if (yyvsp[-1].Number) {
  1291.                 oldmask = umask(0);
  1292.                 (void) umask(oldmask);
  1293.                 reply(200, "Current UMASK is %03o", oldmask);
  1294.             }
  1295.         ;
  1296.     break;}
  1297. case 37:
  1298. #line 454 "ftpcmd.y"
  1299. {
  1300.             mode_t oldmask;
  1301.             struct aclmember *entry = NULL;
  1302.             int ok = 1;
  1303.  
  1304.             if (log_commands) syslog(LOG_INFO, "SITE UMASK %d", yyvsp[-1].Number);
  1305.             if (yyvsp[-3].Number) {
  1306.                 /* check for umask permission */
  1307.                 while (getaclentry("umask", &entry) && ARG0 && ARG1 != NULL) {
  1308.                     if (type_match(ARG1)) 
  1309.                         if (*ARG0 == 'n')  ok = 0;
  1310.                 }
  1311.                 if (ok) {
  1312.                     if ((yyvsp[-1].Number == -1) || (yyvsp[-1].Number > 0777)) {
  1313.                         reply(501, "Bad UMASK value");
  1314.                     } else {
  1315.                         oldmask = umask((mode_t)yyvsp[-1].Number);
  1316.                         reply(200, "UMASK set to %03o (was %03o)", yyvsp[-1].Number, oldmask);
  1317.                     }
  1318.                 } else 
  1319.                     reply(553, "Permission denied. (umask)");
  1320.             }
  1321.         ;
  1322.     break;}
  1323. case 38:
  1324. #line 478 "ftpcmd.y"
  1325. {
  1326.             struct aclmember *entry = NULL;
  1327.             int ok = 1;
  1328.  
  1329.             if (log_commands) syslog(LOG_INFO, "SITE CHMOD %d %s", yyvsp[-3].Number, yyvsp[-1].String);
  1330.             if (yyvsp[-5].Number && yyvsp[-3].Number && yyvsp[-1].String) {
  1331.                 /* check for chmod permission */
  1332.                 while (getaclentry("chmod", &entry) && ARG0 && ARG1 != NULL) {
  1333.                     if (type_match(ARG1)) 
  1334.                         if (*ARG0 == 'n')  ok = 0;
  1335.                 }
  1336.                 if (ok) {
  1337.                     if (yyvsp[-3].Number > 0777)
  1338.                         reply(501, 
  1339.                             "CHMOD: Mode value must be between 0 and 0777");
  1340.                     else if (chmod(yyvsp[-1].String, (mode_t) yyvsp[-3].Number) < 0)
  1341.                         perror_reply(550, yyvsp[-1].String);
  1342.                     else
  1343.                         reply(200, "CHMOD command successful.");
  1344.                     free(yyvsp[-1].String);
  1345.                 } else
  1346.                     reply(553, "Permission denied. (chmod)");
  1347.             }
  1348.         ;
  1349.     break;}
  1350. case 39:
  1351. #line 503 "ftpcmd.y"
  1352. {
  1353.             if (log_commands) syslog(LOG_INFO, "SITE IDLE");
  1354.             reply(200,
  1355.                 "Current IDLE time limit is %d seconds; max %d",
  1356.                 timeout, maxtimeout);
  1357.         ;
  1358.     break;}
  1359. case 40:
  1360. #line 510 "ftpcmd.y"
  1361. {
  1362.             if (log_commands) syslog(LOG_INFO, "SITE IDLE %d", yyvsp[-1].Number);
  1363.             if (yyvsp[-1].Number < 30 || yyvsp[-1].Number > maxtimeout) {
  1364.                 reply(501,
  1365.             "Maximum IDLE time must be between 30 and %d seconds",
  1366.                     maxtimeout);
  1367.             } else {
  1368.                 timeout = yyvsp[-1].Number;
  1369. #ifndef AMIGA
  1370.                 (void) alarm((unsigned) timeout);
  1371. #endif
  1372.                 reply(200, "Maximum IDLE time set to %d seconds", timeout);
  1373.             }
  1374.         ;
  1375.     break;}
  1376. case 41:
  1377. #line 525 "ftpcmd.y"
  1378. {
  1379. #ifndef NO_PRIVATE
  1380.             if (log_commands) syslog(LOG_INFO, "SITE GROUP %s", yyvsp[-1].String);
  1381.             if (yyvsp[-3].Number && yyvsp[-1].String) priv_group(yyvsp[-1].String);
  1382.             free(yyvsp[-1].String);
  1383. #endif /* !NO_PRIVATE */
  1384.         ;
  1385.     break;}
  1386. case 42:
  1387. #line 533 "ftpcmd.y"
  1388. {
  1389. #ifndef NO_PRIVATE
  1390.             if (log_commands) syslog(LOG_INFO, "SITE GPASS password");
  1391.             if (yyvsp[-3].Number && yyvsp[-1].String) priv_gpass(yyvsp[-1].String);
  1392.             free(yyvsp[-1].String);
  1393. #endif /* !NO_PRIVATE */
  1394.         ;
  1395.     break;}
  1396. case 43:
  1397. #line 541 "ftpcmd.y"
  1398. {
  1399. #ifndef AMIGA
  1400.             if (yyvsp[-3].Number && yyvsp[-1].String) newer(yyvsp[-1].String, ".", 0);
  1401. #else
  1402.             if (yyvsp[-3].Number && yyvsp[-1].String) newer(yyvsp[-1].String, "", 0);
  1403. #endif
  1404.             free(yyvsp[-1].String);
  1405.         ;
  1406.     break;}
  1407. case 44:
  1408. #line 546 "ftpcmd.y"
  1409. {
  1410.             if (yyvsp[-5].Number && yyvsp[-3].String && yyvsp[-1].String) newer(yyvsp[-3].String, yyvsp[-1].String, 0);
  1411.             free(yyvsp[-3].String);
  1412.             free(yyvsp[-1].String);
  1413.         ;
  1414.     break;}
  1415. case 45:
  1416. #line 552 "ftpcmd.y"
  1417. {
  1418.             if (yyvsp[-5].Number && yyvsp[-3].String && yyvsp[-1].String) newer(yyvsp[-3].String, yyvsp[-1].String, 1);
  1419.             free(yyvsp[-3].String);
  1420.             free(yyvsp[-1].String);
  1421.         ;
  1422.     break;}
  1423. case 46:
  1424. #line 558 "ftpcmd.y"
  1425. {
  1426.             /* this is just for backward compatibility since we
  1427.              * thought of INDEX before we thought of EXEC
  1428.              */
  1429.             if (yyvsp[-3].Number != 0 && yyvsp[-1].String != NULL) {
  1430.                 char buf[MAXPATHLEN];
  1431.                 if (strlen(yyvsp[-1].String) + 7 <= sizeof(buf)) {
  1432.                     sprintf(buf, "index %s", (char*)yyvsp[-1].String);
  1433.                     (void) site_exec(buf);
  1434.                 }
  1435.             }
  1436.         ;
  1437.     break;}
  1438. case 47:
  1439. #line 571 "ftpcmd.y"
  1440. {
  1441.             if (yyvsp[-3].Number != 0 && yyvsp[-1].String != NULL) {
  1442.                 (void) site_exec((char*)yyvsp[-1].String);
  1443.             }
  1444.         ;
  1445.     break;}
  1446. case 48:
  1447. #line 577 "ftpcmd.y"
  1448. {
  1449.             if (log_commands) syslog(LOG_INFO, "STOU %s", yyvsp[-1].String);
  1450.             if (yyvsp[-3].Number && yyvsp[-1].String) {
  1451.                 store(yyvsp[-1].String, "w", 1);
  1452.                 free(yyvsp[-1].String);
  1453.             }
  1454.         ;
  1455.     break;}
  1456. case 49:
  1457. #line 585 "ftpcmd.y"
  1458. {
  1459.             if (log_commands) syslog(LOG_INFO, "SYST");
  1460. #ifdef unix
  1461. #ifdef BSD
  1462.             reply(215, "UNIX Type: L%d Version: BSD-%d",
  1463.                 NBBY, BSD);
  1464. #else  /* BSD */
  1465.             reply(215, "UNIX Type: L%d", NBBY);
  1466. #endif /* BSD */
  1467. #else  /* unix */
  1468.             reply(215, "UNKNOWN Type: L%d", NBBY);
  1469. #endif /* unix */
  1470.         ;
  1471.     break;}
  1472. case 50:
  1473. #line 607 "ftpcmd.y"
  1474. {
  1475.             if (log_commands) syslog(LOG_INFO, "SIZE %s", yyvsp[-1].String);
  1476.             if (yyvsp[-3].Number && yyvsp[-1].String) {
  1477.                 sizecmd(yyvsp[-1].String);
  1478.                 free(yyvsp[-1].String);
  1479.             }
  1480.         ;
  1481.     break;}
  1482. case 51:
  1483. #line 625 "ftpcmd.y"
  1484. {
  1485.             if (log_commands) syslog(LOG_INFO, "MDTM %s", yyvsp[-1].String);
  1486.             if (yyvsp[-3].Number && yyvsp[-1].String) {
  1487.                 struct stat stbuf;
  1488.  
  1489.                 if (stat(yyvsp[-1].String, &stbuf) < 0)
  1490.                     perror_reply(550, yyvsp[-1].String);
  1491.                 else if ((stbuf.st_mode&S_IFMT) != S_IFREG) {
  1492.                     reply(550, "%s: not a plain file.",
  1493.                         yyvsp[-1].String);
  1494.                 } else {
  1495.                     register struct tm *t;
  1496.                     struct tm *gmtime();
  1497.                     t = gmtime(&stbuf.st_mtime);
  1498.                     reply(213,
  1499.                         "19%02d%02d%02d%02d%02d%02d",
  1500.                         t->tm_year, t->tm_mon+1, t->tm_mday,
  1501.                         t->tm_hour, t->tm_min, t->tm_sec);
  1502.                 }
  1503.                 free(yyvsp[-1].String);
  1504.             }
  1505.         ;
  1506.     break;}
  1507. case 52:
  1508. #line 648 "ftpcmd.y"
  1509. {
  1510.             if (log_commands) syslog(LOG_INFO, "QUIT");
  1511.             reply(221, "Goodbye.");
  1512.             dologout(0);
  1513.         ;
  1514.     break;}
  1515. case 53:
  1516. #line 654 "ftpcmd.y"
  1517. {
  1518.             yyerrok;
  1519.         ;
  1520.     break;}
  1521. case 54:
  1522. #line 659 "ftpcmd.y"
  1523. {
  1524.             char *renamefrom();
  1525.  
  1526.             if (log_commands) syslog(LOG_INFO, "RNFR %s", yyvsp[-1].String);
  1527.             restart_point = (off_t) 0;
  1528.             if (yyvsp[-3].Number && yyvsp[-1].String) {
  1529.                 fromname = renamefrom(yyvsp[-1].String);
  1530.                 if (fromname == 0 && yyvsp[-1].String) {
  1531.                     free(yyvsp[-1].String);
  1532.                 }
  1533.             }
  1534.         ;
  1535.     break;}
  1536. case 55:
  1537. #line 672 "ftpcmd.y"
  1538. {
  1539.             long atol();
  1540.  
  1541.             fromname = 0;
  1542.             restart_point = yyvsp[-1].Number;
  1543.             if (log_commands) syslog(LOG_INFO, "REST %d", restart_point);
  1544.             reply(350, "Restarting at %ld. %s", restart_point,
  1545.                 "Send STORE or RETRIEVE to initiate transfer.");
  1546.         ;
  1547.     break;}
  1548. case 56:
  1549. #line 683 "ftpcmd.y"
  1550. {
  1551.            if (log_commands) syslog(LOG_INFO, "SITE ALIAS");
  1552.            alias ((char *)NULL);
  1553.         ;
  1554.     break;}
  1555. case 57:
  1556. #line 688 "ftpcmd.y"
  1557. {
  1558.            if (log_commands) syslog(LOG_INFO, "SITE ALIAS %s", yyvsp[-1].String);
  1559.            alias (yyvsp[-1].String);
  1560.         ;
  1561.     break;}
  1562. case 58:
  1563. #line 693 "ftpcmd.y"
  1564. {
  1565.            if (log_commands) syslog(LOG_INFO, "SITE GROUPS");
  1566.            print_groups () ;
  1567.         ;
  1568.     break;}
  1569. case 59:
  1570. #line 698 "ftpcmd.y"
  1571. {
  1572.            if (log_commands) syslog(LOG_INFO, "SITE CDPATH");
  1573.            cdpath () ;
  1574.         ;
  1575.     break;}
  1576. case 61:
  1577. #line 708 "ftpcmd.y"
  1578. {
  1579.             yyval.String = malloc(1);
  1580.             yyval.String[0] = '\0';
  1581.         ;
  1582.     break;}
  1583. case 64:
  1584. #line 720 "ftpcmd.y"
  1585. {
  1586.             register char *a, *p;
  1587.  
  1588.             a = (char *)&data_dest.sin_addr;
  1589.             a[0] = yyvsp[-10].Number; a[1] = yyvsp[-8].Number; a[2] = yyvsp[-6].Number; a[3] = yyvsp[-4].Number;
  1590.             p = (char *)&data_dest.sin_port;
  1591.             p[0] = yyvsp[-2].Number; p[1] = yyvsp[0].Number;
  1592.             data_dest.sin_family = AF_INET;
  1593.         ;
  1594.     break;}
  1595. case 65:
  1596. #line 732 "ftpcmd.y"
  1597. {
  1598.         yyval.Number = FORM_N;
  1599.     ;
  1600.     break;}
  1601. case 66:
  1602. #line 736 "ftpcmd.y"
  1603. {
  1604.         yyval.Number = FORM_T;
  1605.     ;
  1606.     break;}
  1607. case 67:
  1608. #line 740 "ftpcmd.y"
  1609. {
  1610.         yyval.Number = FORM_C;
  1611.     ;
  1612.     break;}
  1613. case 68:
  1614. #line 746 "ftpcmd.y"
  1615. {
  1616.         cmd_type = TYPE_A;
  1617.         cmd_form = FORM_N;
  1618.     ;
  1619.     break;}
  1620. case 69:
  1621. #line 751 "ftpcmd.y"
  1622. {
  1623.         cmd_type = TYPE_A;
  1624.         cmd_form = yyvsp[0].Number;
  1625.     ;
  1626.     break;}
  1627. case 70:
  1628. #line 756 "ftpcmd.y"
  1629. {
  1630.         cmd_type = TYPE_E;
  1631.         cmd_form = FORM_N;
  1632.     ;
  1633.     break;}
  1634. case 71:
  1635. #line 761 "ftpcmd.y"
  1636. {
  1637.         cmd_type = TYPE_E;
  1638.         cmd_form = yyvsp[0].Number;
  1639.     ;
  1640.     break;}
  1641. case 72:
  1642. #line 766 "ftpcmd.y"
  1643. {
  1644.         cmd_type = TYPE_I;
  1645.     ;
  1646.     break;}
  1647. case 73:
  1648. #line 770 "ftpcmd.y"
  1649. {
  1650.         cmd_type = TYPE_L;
  1651.         cmd_bytesz = NBBY;
  1652.     ;
  1653.     break;}
  1654. case 74:
  1655. #line 775 "ftpcmd.y"
  1656. {
  1657.         cmd_type = TYPE_L;
  1658.         cmd_bytesz = yyvsp[0].Number;
  1659.     ;
  1660.     break;}
  1661. case 75:
  1662. #line 781 "ftpcmd.y"
  1663. {
  1664.         cmd_type = TYPE_L;
  1665.         cmd_bytesz = yyvsp[0].Number;
  1666.     ;
  1667.     break;}
  1668. case 76:
  1669. #line 788 "ftpcmd.y"
  1670. {
  1671.         yyval.Number = STRU_F;
  1672.     ;
  1673.     break;}
  1674. case 77:
  1675. #line 792 "ftpcmd.y"
  1676. {
  1677.         yyval.Number = STRU_R;
  1678.     ;
  1679.     break;}
  1680. case 78:
  1681. #line 796 "ftpcmd.y"
  1682. {
  1683.         yyval.Number = STRU_P;
  1684.     ;
  1685.     break;}
  1686. case 79:
  1687. #line 802 "ftpcmd.y"
  1688. {
  1689.         yyval.Number = MODE_S;
  1690.     ;
  1691.     break;}
  1692. case 80:
  1693. #line 806 "ftpcmd.y"
  1694. {
  1695.         yyval.Number = MODE_B;
  1696.     ;
  1697.     break;}
  1698. case 81:
  1699. #line 810 "ftpcmd.y"
  1700. {
  1701.         yyval.Number = MODE_C;
  1702.     ;
  1703.     break;}
  1704. case 82:
  1705. #line 816 "ftpcmd.y"
  1706. {
  1707.         /*
  1708.          * Problem: this production is used for all pathname
  1709.          * processing, but only gives a 550 error reply.
  1710.          * This is a valid reply in some cases but not in others.
  1711.          */
  1712.         if (logged_in && yyvsp[0].String && strncmp(yyvsp[0].String, "~", 1) == 0) {
  1713.             yyval.String = *ftpglob(yyvsp[0].String);
  1714.             if (globerr) {
  1715.                 reply(550, globerr);
  1716.                 yyval.String = NULL;
  1717.             }
  1718.             free(yyvsp[0].String);
  1719.         } else
  1720.             yyval.String = yyvsp[0].String;
  1721.     ;
  1722.     break;}
  1723. case 84:
  1724. #line 838 "ftpcmd.y"
  1725. {
  1726.         register int ret, dec, multby, digit;
  1727.  
  1728.         /*
  1729.          * Convert a number that was read as decimal number
  1730.          * to what it would be if it had been read as octal.
  1731.          */
  1732.         dec = yyvsp[0].Number;
  1733.         multby = 1;
  1734.         ret = 0;
  1735.         while (dec) {
  1736.             digit = dec%10;
  1737.             if (digit > 7) {
  1738.                 ret = -1;
  1739.                 break;
  1740.             }
  1741.             ret += digit * multby;
  1742.             multby *= 8;
  1743.             dec /= 10;
  1744.         }
  1745.         yyval.Number = ret;
  1746.     ;
  1747.     break;}
  1748. case 85:
  1749. #line 863 "ftpcmd.y"
  1750. {
  1751.         if (logged_in)
  1752.             yyval.Number = 1;
  1753.         else {
  1754.             if (log_commands) syslog(LOG_INFO, "cmd failure - not logged in");
  1755.             reply(530, "Please login with USER and PASS.");
  1756.             yyval.Number = 0;
  1757.         }
  1758.     ;
  1759.     break;}
  1760. }
  1761.    /* the action file gets copied in in place of this dollarsign */
  1762. #line 465 "/usr/lib/bison.simple"
  1763.  
  1764.   yyvsp -= yylen;
  1765.   yyssp -= yylen;
  1766. #ifdef YYLSP_NEEDED
  1767.   yylsp -= yylen;
  1768. #endif
  1769.  
  1770. #if YYDEBUG != 0
  1771.   if (yydebug)
  1772.     {
  1773.       short *ssp1 = yyss - 1;
  1774.       fprintf (stderr, "state stack now");
  1775.       while (ssp1 != yyssp)
  1776.     fprintf (stderr, " %d", *++ssp1);
  1777.       fprintf (stderr, "\n");
  1778.     }
  1779. #endif
  1780.  
  1781.   *++yyvsp = yyval;
  1782.  
  1783. #ifdef YYLSP_NEEDED
  1784.   yylsp++;
  1785.   if (yylen == 0)
  1786.     {
  1787.       yylsp->first_line = yylloc.first_line;
  1788.       yylsp->first_column = yylloc.first_column;
  1789.       yylsp->last_line = (yylsp-1)->last_line;
  1790.       yylsp->last_column = (yylsp-1)->last_column;
  1791.       yylsp->text = 0;
  1792.     }
  1793.   else
  1794.     {
  1795.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  1796.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  1797.     }
  1798. #endif
  1799.  
  1800.   /* Now "shift" the result of the reduction.
  1801.      Determine what state that goes to,
  1802.      based on the state we popped back to
  1803.      and the rule number reduced by.  */
  1804.  
  1805.   yyn = yyr1[yyn];
  1806.  
  1807.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  1808.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1809.     yystate = yytable[yystate];
  1810.   else
  1811.     yystate = yydefgoto[yyn - YYNTBASE];
  1812.  
  1813.   goto yynewstate;
  1814.  
  1815. yyerrlab:   /* here on detecting error */
  1816.  
  1817.   if (! yyerrstatus)
  1818.     /* If not already recovering from an error, report this error.  */
  1819.     {
  1820.       ++yynerrs;
  1821.  
  1822. #ifdef YYERROR_VERBOSE
  1823.       yyn = yypact[yystate];
  1824.  
  1825.       if (yyn > YYFLAG && yyn < YYLAST)
  1826.     {
  1827.       int size = 0;
  1828.       char *msg;
  1829.       int x, count;
  1830.  
  1831.       count = 0;
  1832.       /* Start X at -yyn if nec to avoid negative indexes in yycheck.  */
  1833.       for (x = (yyn < 0 ? -yyn : 0);
  1834.            x < (sizeof(yytname) / sizeof(char *)); x++)
  1835.         if (yycheck[x + yyn] == x)
  1836.           size += strlen(yytname[x]) + 15, count++;
  1837.       msg = (char *) malloc(size + 15);
  1838.       if (msg != 0)
  1839.         {
  1840.           strcpy(msg, "parse error");
  1841.  
  1842.           if (count < 5)
  1843.         {
  1844.           count = 0;
  1845.           for (x = (yyn < 0 ? -yyn : 0);
  1846.                x < (sizeof(yytname) / sizeof(char *)); x++)
  1847.             if (yycheck[x + yyn] == x)
  1848.               {
  1849.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  1850.             strcat(msg, yytname[x]);
  1851.             strcat(msg, "'");
  1852.             count++;
  1853.               }
  1854.         }
  1855.           yyerror(msg);
  1856.           free(msg);
  1857.         }
  1858.       else
  1859.         yyerror ("parse error; also virtual memory exceeded");
  1860.     }
  1861.       else
  1862. #endif /* YYERROR_VERBOSE */
  1863.     yyerror("parse error");
  1864.     }
  1865.  
  1866.   goto yyerrlab1;
  1867. yyerrlab1:   /* here on error raised explicitly by an action */
  1868.  
  1869.   if (yyerrstatus == 3)
  1870.     {
  1871.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  1872.  
  1873.       /* return failure if at end of input */
  1874.       if (yychar == YYEOF)
  1875.     YYABORT;
  1876.  
  1877. #if YYDEBUG != 0
  1878.       if (yydebug)
  1879.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  1880. #endif
  1881.  
  1882.       yychar = YYEMPTY;
  1883.     }
  1884.  
  1885.   /* Else will try to reuse lookahead token
  1886.      after shifting the error token.  */
  1887.  
  1888.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  1889.  
  1890.   goto yyerrhandle;
  1891.  
  1892. yyerrdefault:  /* current state does not do anything special for the error token. */
  1893.  
  1894. #if 0
  1895.   /* This is wrong; only states that explicitly want error tokens
  1896.      should shift them.  */
  1897.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1898.   if (yyn) goto yydefault;
  1899. #endif
  1900.  
  1901. yyerrpop:   /* pop the current state because it cannot handle the error token */
  1902.  
  1903.   if (yyssp == yyss) YYABORT;
  1904.   yyvsp--;
  1905.   yystate = *--yyssp;
  1906. #ifdef YYLSP_NEEDED
  1907.   yylsp--;
  1908. #endif
  1909.  
  1910. #if YYDEBUG != 0
  1911.   if (yydebug)
  1912.     {
  1913.       short *ssp1 = yyss - 1;
  1914.       fprintf (stderr, "Error: state stack now");
  1915.       while (ssp1 != yyssp)
  1916.     fprintf (stderr, " %d", *++ssp1);
  1917.       fprintf (stderr, "\n");
  1918.     }
  1919. #endif
  1920.  
  1921. yyerrhandle:
  1922.  
  1923.   yyn = yypact[yystate];
  1924.   if (yyn == YYFLAG)
  1925.     goto yyerrdefault;
  1926.  
  1927.   yyn += YYTERROR;
  1928.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  1929.     goto yyerrdefault;
  1930.  
  1931.   yyn = yytable[yyn];
  1932.   if (yyn < 0)
  1933.     {
  1934.       if (yyn == YYFLAG)
  1935.     goto yyerrpop;
  1936.       yyn = -yyn;
  1937.       goto yyreduce;
  1938.     }
  1939.   else if (yyn == 0)
  1940.     goto yyerrpop;
  1941.  
  1942.   if (yyn == YYFINAL)
  1943.     YYACCEPT;
  1944.  
  1945. #if YYDEBUG != 0
  1946.   if (yydebug)
  1947.     fprintf(stderr, "Shifting error token, ");
  1948. #endif
  1949.  
  1950.   *++yyvsp = yylval;
  1951. #ifdef YYLSP_NEEDED
  1952.   *++yylsp = yylloc;
  1953. #endif
  1954.  
  1955.   yystate = yyn;
  1956.   goto yynewstate;
  1957. }
  1958. #line 874 "ftpcmd.y"
  1959.  
  1960.  
  1961. extern jmp_buf errcatch;
  1962.  
  1963. #define CMD 0   /* beginning of command */
  1964. #define ARGS    1   /* expect miscellaneous arguments */
  1965. #define STR1    2   /* expect SP followed by STRING */
  1966. #define STR2    3   /* expect STRING */
  1967. #define OSTR    4   /* optional SP then STRING */
  1968. #define ZSTR1   5   /* SP then optional STRING */
  1969. #define ZSTR2   6   /* optional STRING after SP */
  1970. #define SITECMD 7   /* SITE command */
  1971. #define NSTR    8   /* Number followed by a string */
  1972. #define STR3    9   /* expect STRING followed by optional SP then STRING */
  1973.  
  1974. struct tab cmdtab[] = {     /* In order defined in RFC 765 */
  1975.     { "USER", USER, STR1, 1,    "<sp> username" },
  1976.     { "PASS", PASS, ZSTR1, 1,   "<sp> password" },
  1977.     { "ACCT", ACCT, STR1, 0,    "(specify account)" },
  1978.     { "SMNT", SMNT, ARGS, 0,    "(structure mount)" },
  1979.     { "REIN", REIN, ARGS, 0,    "(reinitialize server state)" },
  1980.     { "QUIT", QUIT, ARGS, 1,    "(terminate service)", },
  1981.     { "PORT", PORT, ARGS, 1,    "<sp> b0, b1, b2, b3, b4" },
  1982.     { "PASV", PASV, ARGS, 1,    "(set server in passive mode)" },
  1983.     { "TYPE", TYPE, ARGS, 1,    "<sp> [ A | E | I | L ]" },
  1984.     { "STRU", STRU, ARGS, 1,    "(specify file structure)" },
  1985.     { "MODE", MODE, ARGS, 1,    "(specify transfer mode)" },
  1986.     { "RETR", RETR, STR1, 1,    "<sp> file-name" },
  1987.     { "STOR", STOR, STR1, 1,    "<sp> file-name" },
  1988.     { "APPE", APPE, STR1, 1,    "<sp> file-name" },
  1989.     { "MLFL", MLFL, OSTR, 0,    "(mail file)" },
  1990.     { "MAIL", MAIL, OSTR, 0,    "(mail to user)" },
  1991.     { "MSND", MSND, OSTR, 0,    "(mail send to terminal)" },
  1992.     { "MSOM", MSOM, OSTR, 0,    "(mail send to terminal or mailbox)" },
  1993.     { "MSAM", MSAM, OSTR, 0,    "(mail send to terminal and mailbox)" },
  1994.     { "MRSQ", MRSQ, OSTR, 0,    "(mail recipient scheme question)" },
  1995.     { "MRCP", MRCP, STR1, 0,    "(mail recipient)" },
  1996.     { "ALLO", ALLO, ARGS, 1,    "allocate storage (vacuously)" },
  1997.     { "REST", REST, ARGS, 1,    "(restart command)" },
  1998.     { "RNFR", RNFR, STR1, 1,    "<sp> file-name" },
  1999.     { "RNTO", RNTO, STR1, 1,    "<sp> file-name" },
  2000.     { "ABOR", ABOR, ARGS, 1,    "(abort operation)" },
  2001.     { "DELE", DELE, STR1, 1,    "<sp> file-name" },
  2002.     { "CWD",  CWD,  OSTR, 1,    "[ <sp> directory-name ]" },
  2003.     { "XCWD", CWD,  OSTR, 1,    "[ <sp> directory-name ]" },
  2004.     { "LIST", LIST, OSTR, 1,    "[ <sp> path-name ]" },
  2005.     { "NLST", NLST, OSTR, 1,    "[ <sp> path-name ]" },
  2006.     { "SITE", SITE, SITECMD, 1, "site-cmd [ <sp> arguments ]" },
  2007.     { "SYST", SYST, ARGS, 1,    "(get type of operating system)" },
  2008.     { "STAT", STAT, OSTR, 1,    "[ <sp> path-name ]" },
  2009.     { "HELP", HELP, OSTR, 1,    "[ <sp> <string> ]" },
  2010.     { "NOOP", NOOP, ARGS, 1,    "" },
  2011.     { "MKD",  MKD,  STR1, 1,    "<sp> path-name" },
  2012.     { "XMKD", MKD,  STR1, 1,    "<sp> path-name" },
  2013.     { "RMD",  RMD,  STR1, 1,    "<sp> path-name" },
  2014.     { "XRMD", RMD,  STR1, 1,    "<sp> path-name" },
  2015.     { "PWD",  PWD,  ARGS, 1,    "(return current directory)" },
  2016.     { "XPWD", PWD,  ARGS, 1,    "(return current directory)" },
  2017.     { "CDUP", CDUP, ARGS, 1,    "(change to parent directory)" },
  2018.     { "XCUP", CDUP, ARGS, 1,    "(change to parent directory)" },
  2019.     { "STOU", STOU, STR1, 1,    "<sp> file-name" },
  2020.     { "SIZE", SIZE, OSTR, 1,    "<sp> path-name" },
  2021.     { "MDTM", MDTM, OSTR, 1,    "<sp> path-name" },
  2022.     { NULL,   0,    0,    0,    0 }
  2023. };
  2024.  
  2025. struct tab sitetab[] = {
  2026.     { "UMASK", UMASK, ARGS, 1,  "[ <sp> umask ]" },
  2027.     { "IDLE",  IDLE,  ARGS, 1,  "[ <sp> maximum-idle-time ]" },
  2028.     { "CHMOD", CHMOD, NSTR, 1,  "<sp> mode <sp> file-name" },
  2029.     { "HELP",  HELP,  OSTR, 1,  "[ <sp> <string> ]" },
  2030.     { "GROUP", GROUP, STR1, 1,  "<sp> access-group" },
  2031.     { "GPASS", GPASS, STR1, 1,  "<sp> access-password" },
  2032.     { "NEWER", NEWER, STR3, 1,  "<sp> YYYYMMDDHHMMSS [ <sp> path-name ]" },
  2033.     { "MINFO", MINFO, STR3, 1,  "<sp> YYYYMMDDHHMMSS [ <sp> path-name ]" },
  2034.     { "INDEX", INDEX, STR1, 1,  "<sp> pattern" },
  2035.     { "EXEC",  EXEC,  STR1, 1,  "<sp> command [ <sp> arguments ]" },
  2036.     { "ALIAS", ALIAS, OSTR, 1,  "[ <sp> alias ] " },
  2037.     { "CDPATH", CDPATH, OSTR, 1,  "[ <sp> ] " },
  2038.     { "GROUPS", GROUPS, OSTR, 1,  "[ <sp> ] " },
  2039.     { NULL,    0,     0,    0,  0 }
  2040. };
  2041.  
  2042. struct tab *
  2043. lookup(p, cmd)
  2044.     register struct tab *p;
  2045.     char *cmd;
  2046. {
  2047.  
  2048.     for (; p->name != NULL; p++)
  2049.         if (strcmp(cmd, p->name) == 0)
  2050.             return (p);
  2051.     return (0);
  2052. }
  2053.  
  2054. #include <arpa/telnet.h>
  2055.  
  2056. /*
  2057.  * getline - a hacked up version of fgets to ignore TELNET escape codes.
  2058.  */
  2059. char *
  2060. getline(s, n, iop)
  2061.     char *s;
  2062.     register FILE *iop;
  2063. {
  2064.     register c;
  2065.     register char *cs;
  2066.  
  2067.     cs = s;
  2068. /* tmpline may contain saved command from urgent mode interruption */
  2069.     for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) {
  2070.         *cs++ = tmpline[c];
  2071.         if (tmpline[c] == '\n') {
  2072.             *cs++ = '\0';
  2073.             if (debug)
  2074.                 syslog(LOG_DEBUG, "command: %s", s);
  2075.             tmpline[0] = '\0';
  2076.             return(s);
  2077.         }
  2078.         if (c == 0)
  2079.             tmpline[0] = '\0';
  2080.     }
  2081.     while ((c = getc(iop)) != EOF) {
  2082.         c &= 0377;
  2083.         if (c == IAC) {
  2084.             if ((c = getc(iop)) != EOF) {
  2085.             c &= 0377;
  2086.             switch (c) {
  2087.             case WILL:
  2088.             case WONT:
  2089.                 c = getc(iop);
  2090.                 printf("%c%c%c", IAC, DONT, 0377&c);
  2091.                 (void) fflush(stdout);
  2092.                 continue;
  2093.             case DO:
  2094.             case DONT:
  2095.                 c = getc(iop);
  2096.                 printf("%c%c%c", IAC, WONT, 0377&c);
  2097.                 (void) fflush(stdout);
  2098.                 continue;
  2099.             case IAC:
  2100.                 break;
  2101.             default:
  2102.                 continue;   /* ignore command */
  2103.             }
  2104.             }
  2105.         }
  2106.         *cs++ = c;
  2107.         if (--n <= 0 || c == '\n')
  2108.             break;
  2109.     }
  2110.     if (c == EOF && cs == s)
  2111.         return (NULL);
  2112.     *cs++ = '\0';
  2113.     if (debug)
  2114.         syslog(LOG_DEBUG, "command: %s", s);
  2115.     return (s);
  2116. }
  2117.  
  2118. static void
  2119. toolong()
  2120. {
  2121.     time_t now;
  2122.  
  2123.     reply(421,
  2124.       "Timeout (%d seconds): closing control connection.", timeout);
  2125.     (void) time(&now);
  2126.     if (logging) {
  2127.         syslog(LOG_INFO,
  2128.             "User %s timed out after %d seconds at %.24s",
  2129.             (pw ? pw -> pw_name : "unknown"), timeout, ctime(&now));
  2130.     }
  2131.     dologout(1);
  2132. }
  2133.  
  2134. yylex()
  2135. {
  2136.     static int cpos, state;
  2137.     register char *cp, *cp2;
  2138.     register struct tab *p;
  2139.     int n;
  2140.     char c, *copy();
  2141.  
  2142.     for (;;) {
  2143.         switch (state) {
  2144.  
  2145.         case CMD:
  2146. #ifndef AMIGA
  2147.             (void) signal(SIGALRM, toolong);
  2148.             (void) alarm((unsigned) timeout);
  2149. #endif
  2150.             if (is_shutdown(!logged_in) != 0) {
  2151.                 reply(221, "Server shutting down.  Goodbye.");
  2152.                 dologout(0);
  2153.             }
  2154. #ifdef SETPROCTITLE
  2155.             setproctitle("%s: IDLE", proctitle);
  2156. #endif
  2157.             if (getline(cbuf, sizeof(cbuf)-1, stdin) == NULL) {
  2158.                 reply(221, "You could at least say goodbye.");
  2159.                 dologout(0);
  2160.             }
  2161. #ifndef AMIGA
  2162.             (void) alarm(0);
  2163. #endif
  2164. #ifdef SETPROCTITLE
  2165.             if (strncasecmp(cbuf, "PASS", 4) != 0 &&
  2166.                 strncasecmp(cbuf, "SITE GPASS", 10) != 0)
  2167.                 setproctitle("%s: %s", proctitle, cbuf);
  2168. #endif /* SETPROCTITLE */
  2169.             if ((cp = strchr(cbuf, '\r'))) {
  2170.                 *cp++ = '\n';
  2171.                 *cp = '\0';
  2172.             }
  2173.             if ((cp = strpbrk(cbuf, " \n")))
  2174.                 cpos = cp - cbuf;
  2175.             if (cpos == 0)
  2176.                 cpos = 4;
  2177.             c = cbuf[cpos];
  2178.             cbuf[cpos] = '\0';
  2179.             upper(cbuf);
  2180.             p = lookup(cmdtab, cbuf);
  2181.             cbuf[cpos] = c;
  2182.             if (p != 0) {
  2183.                 if (p->implemented == 0) {
  2184.                     nack(p->name);
  2185.                     longjmp(errcatch,0);
  2186.                     /* NOTREACHED */
  2187.                 }
  2188.                 state = p->state;
  2189.                 yylval.String = p->name;
  2190.                 return (p->token);
  2191.             }
  2192.             break;
  2193.  
  2194.         case SITECMD:
  2195.             if (cbuf[cpos] == ' ') {
  2196.                 cpos++;
  2197.                 return (SP);
  2198.             }
  2199.             cp = &cbuf[cpos];
  2200.             if ((cp2 = strpbrk(cp, " \n")))
  2201.                 cpos = cp2 - cbuf;
  2202.             c = cbuf[cpos];
  2203.             cbuf[cpos] = '\0';
  2204.             upper(cp);
  2205.             p = lookup(sitetab, cp);
  2206.             cbuf[cpos] = c;
  2207.             if (p != 0) {
  2208.                 if (p->implemented == 0) {
  2209.                     state = CMD;
  2210.                     nack(p->name);
  2211.                     longjmp(errcatch,0);
  2212.                     /* NOTREACHED */
  2213.                 }
  2214.                 state = p->state;
  2215.                 yylval.String = p->name;
  2216.                 return (p->token);
  2217.             }
  2218.             state = CMD;
  2219.             break;
  2220.  
  2221.         case OSTR:
  2222.             if (cbuf[cpos] == '\n') {
  2223.                 state = CMD;
  2224.                 return (CRLF);
  2225.             }
  2226.             /* FALLTHROUGH */
  2227.  
  2228.         case STR1:
  2229.         case ZSTR1:
  2230.         dostr1:
  2231.             if (cbuf[cpos] == ' ') {
  2232.                 cpos++;
  2233.                 state = state == OSTR ? STR2 : ++state;
  2234.                 return (SP);
  2235.             }
  2236.             break;
  2237.  
  2238.         case ZSTR2:
  2239.             if (cbuf[cpos] == '\n') {
  2240.                 state = CMD;
  2241.                 return (CRLF);
  2242.             }
  2243.             /* FALLTHROUGH */
  2244.  
  2245.         case STR2:
  2246.             cp = &cbuf[cpos];
  2247.             n = strlen(cp);
  2248.             cpos += n - 1;
  2249.             /*
  2250.              * Make sure the string is nonempty and \n terminated.
  2251.              */
  2252.             if (n > 1 && cbuf[cpos] == '\n') {
  2253.                 cbuf[cpos] = '\0';
  2254.                 yylval.String = copy(cp);
  2255.                 cbuf[cpos] = '\n';
  2256.                 state = ARGS;
  2257.                 return (STRING);
  2258.             }
  2259.             break;
  2260.  
  2261.         case NSTR:
  2262.             if (cbuf[cpos] == ' ') {
  2263.                 cpos++;
  2264.                 return (SP);
  2265.             }
  2266.             if (isdigit(cbuf[cpos])) {
  2267.                 cp = &cbuf[cpos];
  2268.                 while (isdigit(cbuf[++cpos]))
  2269.                     ;
  2270.                 c = cbuf[cpos];
  2271.                 cbuf[cpos] = '\0';
  2272.                 yylval.Number = atoi(cp);
  2273.                 cbuf[cpos] = c;
  2274.                 state = STR1;
  2275.                 return (NUMBER);
  2276.             }
  2277.             state = STR1;
  2278.             goto dostr1;
  2279.  
  2280.         case STR3:
  2281.             if (cbuf[cpos] == ' ') {
  2282.                 cpos++;
  2283.                 return (SP);
  2284.             }
  2285.  
  2286.             cp = &cbuf[cpos];
  2287.             cp2 = strpbrk(cp, " \n");
  2288.             if (cp2 != NULL) {
  2289.                 c = *cp2;
  2290.                 *cp2 = '\0';
  2291.             }
  2292.             n = strlen(cp);
  2293.             cpos += n;
  2294.             /*
  2295.              * Make sure the string is nonempty and SP terminated.
  2296.              */
  2297.             if ((cp2 - cp) > 1) {
  2298.                 yylval.String = copy(cp);
  2299.                 cbuf[cpos] = c;
  2300.                 state = OSTR;
  2301.                 return (STRING);
  2302.             }
  2303.             break;
  2304.  
  2305.         case ARGS:
  2306.             if (isdigit(cbuf[cpos])) {
  2307.                 cp = &cbuf[cpos];
  2308.                 while (isdigit(cbuf[++cpos]))
  2309.                     ;
  2310.                 c = cbuf[cpos];
  2311.                 cbuf[cpos] = '\0';
  2312.                 yylval.Number = atoi(cp);
  2313.                 cbuf[cpos] = c;
  2314.                 return (NUMBER);
  2315.             }
  2316.             switch (cbuf[cpos++]) {
  2317.  
  2318.             case '\n':
  2319.                 state = CMD;
  2320.                 return (CRLF);
  2321.  
  2322.             case ' ':
  2323.                 return (SP);
  2324.  
  2325.             case ',':
  2326.                 return (COMMA);
  2327.  
  2328.             case 'A':
  2329.             case 'a':
  2330.                 return (A);
  2331.  
  2332.             case 'B':
  2333.             case 'b':
  2334.                 return (B);
  2335.  
  2336.             case 'C':
  2337.             case 'c':
  2338.                 return (C);
  2339.  
  2340.             case 'E':
  2341.             case 'e':
  2342.                 return (E);
  2343.  
  2344.             case 'F':
  2345.             case 'f':
  2346.                 return (F);
  2347.  
  2348.             case 'I':
  2349.             case 'i':
  2350.                 return (I);
  2351.  
  2352.             case 'L':
  2353.             case 'l':
  2354.                 return (L);
  2355.  
  2356.             case 'N':
  2357.             case 'n':
  2358.                 return (N);
  2359.  
  2360.             case 'P':
  2361.             case 'p':
  2362.                 return (P);
  2363.  
  2364.             case 'R':
  2365.             case 'r':
  2366.                 return (R);
  2367.  
  2368.             case 'S':
  2369.             case 's':
  2370.                 return (S);
  2371.  
  2372.             case 'T':
  2373.             case 't':
  2374.                 return (T);
  2375.  
  2376.             }
  2377.             break;
  2378.  
  2379.         default:
  2380.             fatal("Unknown state in scanner.");
  2381.         }
  2382.         yyerror((char *)NULL);
  2383.         state = CMD;
  2384.         longjmp(errcatch,0);
  2385.     }
  2386. }
  2387.  
  2388. upper(s)
  2389.     register char *s;
  2390. {
  2391.     while (*s != '\0') {
  2392.         if (islower(*s))
  2393.             *s = toupper(*s);
  2394.         s++;
  2395.     }
  2396. }
  2397.  
  2398. char *
  2399. copy(s)
  2400.     char *s;
  2401. {
  2402.     char *p;
  2403.  
  2404.     p = malloc((unsigned) strlen(s) + 1);
  2405.     if (p == NULL)
  2406.         fatal("Ran out of memory.");
  2407.     (void) strcpy(p, s);
  2408.     return (p);
  2409. }
  2410.  
  2411. help(ctab, s)
  2412.     struct tab *ctab;
  2413.     char *s;
  2414. {
  2415.     register struct tab *c;
  2416.     register int width, NCMDS;
  2417.     char *type;
  2418.  
  2419.     if (ctab == sitetab)
  2420.         type = "SITE ";
  2421.     else
  2422.         type = "";
  2423.     width = 0, NCMDS = 0;
  2424.     for (c = ctab; c->name != NULL; c++) {
  2425.         int len = strlen(c->name);
  2426.  
  2427.         if (len > width)
  2428.             width = len;
  2429.         NCMDS++;
  2430.     }
  2431.     width = (width + 8) &~ 7;
  2432.     if (s == 0) {
  2433.         register int i, j, w;
  2434.         int columns, lines;
  2435.  
  2436.         lreply(214, "The following %scommands are recognized %s.",
  2437.             type, "(* =>'s unimplemented)");
  2438.         columns = 76 / width;
  2439.         if (columns == 0)
  2440.             columns = 1;
  2441.         lines = (NCMDS + columns - 1) / columns;
  2442.         for (i = 0; i < lines; i++) {
  2443.             printf("   ");
  2444.             for (j = 0; j < columns; j++) {
  2445.                 c = ctab + j * lines + i;
  2446.                 printf("%s%c", c->name,
  2447.                     c->implemented ? ' ' : '*');
  2448.                 if (c + lines >= &ctab[NCMDS])
  2449.                     break;
  2450.                 w = strlen(c->name) + 1;
  2451.                 while (w < width) {
  2452.                     putchar(' ');
  2453.                     w++;
  2454.                 }
  2455.             }
  2456.             printf("\r\n");
  2457.         }
  2458.         (void) fflush(stdout);
  2459.         reply(214, "Direct comments to ftp-bugs@%s.", hostname);
  2460.         return;
  2461.     }
  2462.     upper(s);
  2463.     c = lookup(ctab, s);
  2464.     if (c == (struct tab *)NULL) {
  2465.         reply(502, "Unknown command %s.", s);
  2466.         return;
  2467.     }
  2468.     if (c->implemented)
  2469.         reply(214, "Syntax: %s%s %s", type, c->name, c->help);
  2470.     else
  2471.         reply(214, "%s%-*s\t%s; unimplemented.", type, width,
  2472.             c->name, c->help);
  2473. }
  2474.  
  2475. sizecmd(filename)
  2476. char *filename;
  2477. {
  2478.     switch (type) {
  2479.     case TYPE_L:
  2480.     case TYPE_I: {
  2481.         struct stat stbuf;
  2482.         if (stat(filename, &stbuf) < 0 ||
  2483.             (stbuf.st_mode&S_IFMT) != S_IFREG)
  2484.             reply(550, "%s: not a plain file.", filename);
  2485.         else
  2486.             reply(213, "%lu", stbuf.st_size);
  2487.         break;}
  2488.     case TYPE_A: {
  2489.         FILE *fin;
  2490.         register int c;
  2491.         register long count;
  2492.         struct stat stbuf;
  2493.         fin = fopen(filename, "r");
  2494.         if (fin == NULL) {
  2495.             perror_reply(550, filename);
  2496.             return;
  2497.         }
  2498.         if (fstat(fileno(fin), &stbuf) < 0 ||
  2499.             (stbuf.st_mode&S_IFMT) != S_IFREG) {
  2500.             reply(550, "%s: not a plain file.", filename);
  2501.             (void) fclose(fin);
  2502.             return;
  2503.         }
  2504.  
  2505.         count = 0;
  2506.         while((c=getc(fin)) != EOF) {
  2507.             if (c == '\n')  /* will get expanded to \r\n */
  2508.                 count++;
  2509.             count++;
  2510.         }
  2511.         (void) fclose(fin);
  2512.  
  2513.         reply(213, "%ld", count);
  2514.         break;}
  2515.     default:
  2516.         reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]);
  2517.     }
  2518. }
  2519.  
  2520. site_exec(cmd)
  2521. char *cmd;
  2522. {
  2523.     char buf[MAXPATHLEN];
  2524.     char *sp = (char *) strchr(cmd, ' '), *slash, *t;
  2525.     FILE *cmdf, *ftpd_popen();
  2526.  
  2527.     /* sanitize the command-string */
  2528.     
  2529.     if (sp == 0)  {
  2530.         while ((slash = strchr (cmd, '/')) != 0)
  2531.             cmd = slash + 1;
  2532.     } else {
  2533.         while (sp && (slash = (char *) strchr(cmd, '/')) 
  2534.                && (slash < sp))
  2535.             cmd = slash+1;
  2536.     }
  2537.     
  2538.     for (t = cmd;  *t && !isspace(*t);  t++) {
  2539.         if (isupper(*t)) {
  2540.             *t = tolower(*t);
  2541.         }
  2542.     }
  2543.  
  2544.     /* build the command */
  2545.     if (strlen(_PATH_EXECPATH) + strlen(cmd) + 1 > sizeof(buf))
  2546.         return;
  2547.     sprintf(buf, "%s/%s", _PATH_EXECPATH, cmd);
  2548.  
  2549.     cmdf = ftpd_popen(buf, "r", 0);
  2550.     if (!cmdf) {
  2551.         perror_reply(550, cmd);
  2552.         if (log_commands)
  2553.             syslog(LOG_INFO, "SITE EXEC (FAIL: %m): %s", cmd);
  2554.     } else {
  2555.         int lines = 0;
  2556.  
  2557.         lreply(200, cmd);
  2558.         while (fgets(buf, sizeof buf, cmdf)) {
  2559.             int len = strlen(buf);
  2560.  
  2561.             if (len>0 && buf[len-1]=='\n')
  2562.                 buf[--len] = '\0';
  2563.             lreply(200, buf);
  2564.             if (++lines >= 20) {
  2565.                 lreply(200, "*** Truncated ***");
  2566.                 break;
  2567.             }
  2568.         }
  2569.         reply(200, " (end of '%s')", cmd);
  2570.         if (log_commands)
  2571.             syslog(LOG_INFO, "SITE EXEC (lines: %d): %s", lines, cmd);
  2572.         ftpd_pclose(cmdf);
  2573.     }
  2574. }
  2575.  
  2576. alias (s)
  2577. char *s;
  2578. {
  2579.     struct aclmember *entry = NULL;
  2580.  
  2581.     if (s != (char *)NULL) {
  2582.         while (getaclentry("alias", &entry) && ARG0 && ARG1 != NULL)
  2583.             if (!strcmp(ARG0, s)) {
  2584.                 reply (214, "%s is an alias for %s.", ARG0, ARG1);
  2585.                 return;
  2586.             }
  2587.         reply (502, "Unknown alias %s.", s);
  2588.         return;
  2589.     }
  2590.  
  2591.     lreply(214, "The following aliases are available.");
  2592.  
  2593.     while (getaclentry("alias", &entry) && ARG0 && ARG1 != NULL)
  2594.         printf ("   %-8s %s\r\n", ARG0, ARG1);
  2595.     (void) fflush (stdout);
  2596.  
  2597.     reply(214, "");
  2598. }
  2599.  
  2600. cdpath ()
  2601. {
  2602.     struct aclmember *entry = NULL;
  2603.  
  2604.     lreply(214, "The cdpath is:");
  2605.     while (getaclentry("cdpath", &entry) && ARG0 != NULL)
  2606.         printf ("  %s\r\n", ARG0);
  2607.     (void) fflush (stdout);
  2608.     reply(214, "");
  2609. }
  2610.  
  2611. void
  2612. print_groups()
  2613. {
  2614.     gid_t  groups[NGROUPS_MAX];
  2615.     int    ngroups = 0;
  2616.  
  2617.     if ( (ngroups = getgroups(NGROUPS_MAX, groups)) < 0 ) {
  2618.         return;
  2619.     }
  2620.  
  2621.     lreply(214, "Group membership is:");
  2622.     ngroups--;
  2623.  
  2624.     for (; ngroups >= 0; ngroups--)
  2625.         lreply(214, "  %d", groups[ngroups]);
  2626.  
  2627.     (void) fflush (stdout);
  2628.     reply(214, "");
  2629. }
  2630.