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