1234949Sbapt#ifndef lint 2234949Sbaptstatic const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; 3234949Sbapt#endif 4234949Sbapt 5234949Sbapt#define YYBYACC 1 6234949Sbapt#define YYMAJOR 1 7234949Sbapt#define YYMINOR 9 8234949Sbapt 9234949Sbapt#define YYEMPTY (-1) 10234949Sbapt#define yyclearin (yychar = YYEMPTY) 11234949Sbapt#define yyerrok (yyerrflag = 0) 12234949Sbapt#define YYRECOVERING() (yyerrflag != 0) 13234949Sbapt 14234949Sbapt 15234949Sbapt#ifndef yyparse 16234949Sbapt#define yyparse ftp_parse 17234949Sbapt#endif /* yyparse */ 18234949Sbapt 19234949Sbapt#ifndef yylex 20234949Sbapt#define yylex ftp_lex 21234949Sbapt#endif /* yylex */ 22234949Sbapt 23234949Sbapt#ifndef yyerror 24234949Sbapt#define yyerror ftp_error 25234949Sbapt#endif /* yyerror */ 26234949Sbapt 27234949Sbapt#ifndef yychar 28234949Sbapt#define yychar ftp_char 29234949Sbapt#endif /* yychar */ 30234949Sbapt 31234949Sbapt#ifndef yyval 32234949Sbapt#define yyval ftp_val 33234949Sbapt#endif /* yyval */ 34234949Sbapt 35234949Sbapt#ifndef yylval 36234949Sbapt#define yylval ftp_lval 37234949Sbapt#endif /* yylval */ 38234949Sbapt 39234949Sbapt#ifndef yydebug 40234949Sbapt#define yydebug ftp_debug 41234949Sbapt#endif /* yydebug */ 42234949Sbapt 43234949Sbapt#ifndef yynerrs 44234949Sbapt#define yynerrs ftp_nerrs 45234949Sbapt#endif /* yynerrs */ 46234949Sbapt 47234949Sbapt#ifndef yyerrflag 48234949Sbapt#define yyerrflag ftp_errflag 49234949Sbapt#endif /* yyerrflag */ 50234949Sbapt 51234949Sbapt#ifndef yylhs 52234949Sbapt#define yylhs ftp_lhs 53234949Sbapt#endif /* yylhs */ 54234949Sbapt 55234949Sbapt#ifndef yylen 56234949Sbapt#define yylen ftp_len 57234949Sbapt#endif /* yylen */ 58234949Sbapt 59234949Sbapt#ifndef yydefred 60234949Sbapt#define yydefred ftp_defred 61234949Sbapt#endif /* yydefred */ 62234949Sbapt 63234949Sbapt#ifndef yydgoto 64234949Sbapt#define yydgoto ftp_dgoto 65234949Sbapt#endif /* yydgoto */ 66234949Sbapt 67234949Sbapt#ifndef yysindex 68234949Sbapt#define yysindex ftp_sindex 69234949Sbapt#endif /* yysindex */ 70234949Sbapt 71234949Sbapt#ifndef yyrindex 72234949Sbapt#define yyrindex ftp_rindex 73234949Sbapt#endif /* yyrindex */ 74234949Sbapt 75234949Sbapt#ifndef yygindex 76234949Sbapt#define yygindex ftp_gindex 77234949Sbapt#endif /* yygindex */ 78234949Sbapt 79234949Sbapt#ifndef yytable 80234949Sbapt#define yytable ftp_table 81234949Sbapt#endif /* yytable */ 82234949Sbapt 83234949Sbapt#ifndef yycheck 84234949Sbapt#define yycheck ftp_check 85234949Sbapt#endif /* yycheck */ 86234949Sbapt 87234949Sbapt#ifndef yyname 88234949Sbapt#define yyname ftp_name 89234949Sbapt#endif /* yyname */ 90234949Sbapt 91234949Sbapt#ifndef yyrule 92234949Sbapt#define yyrule ftp_rule 93234949Sbapt#endif /* yyrule */ 94234949Sbapt#define YYPREFIX "ftp_" 95234949Sbapt 96234949Sbapt#define YYPURE 0 97234949Sbapt 98234949Sbapt#line 26 "ftp.y" 99234949Sbapt 100234949Sbapt/* sccsid[] = "@(#)ftpcmd.y 5.20.1.1 (Berkeley) 3/2/89"; */ 101234949Sbapt 102234949Sbapt#include <sys/param.h> 103234949Sbapt#include <sys/socket.h> 104234949Sbapt 105234949Sbapt#include <netinet/in.h> 106234949Sbapt 107234949Sbapt#include <arpa/ftp.h> 108234949Sbapt 109234949Sbapt#include <stdlib.h> 110234949Sbapt#include <unistd.h> 111234949Sbapt#include <stdio.h> 112234949Sbapt#include <signal.h> 113234949Sbapt#include <ctype.h> 114234949Sbapt#include <pwd.h> 115234949Sbapt#include <setjmp.h> 116234949Sbapt#include <syslog.h> 117234949Sbapt#include <sys/stat.h> 118234949Sbapt#include <string.h> 119234949Sbapt#include <time.h> 120234949Sbapt#include <assert.h> 121234949Sbapt 122234949Sbapt#ifdef YYBISON 123234949Sbaptint yylex(void); 124234949Sbaptstatic void yyerror(const char *); 125234949Sbapt#endif 126234949Sbapt 127234949Sbaptextern struct sockaddr_in data_dest; 128234949Sbaptextern int logged_in; 129234949Sbaptextern struct passwd *pw; 130234949Sbaptextern int guest; 131234949Sbaptextern int logging; 132234949Sbaptextern int type; 133234949Sbaptextern int form; 134234949Sbaptextern int debug; 135234949Sbaptextern int timeout; 136234949Sbaptextern int maxtimeout; 137234949Sbaptextern int pdata; 138234949Sbaptextern char hostname[], remotehost[]; 139234949Sbaptextern char proctitle[]; 140234949Sbaptextern char *globerr; 141234949Sbaptextern int usedefault; 142234949Sbaptextern int transflag; 143234949Sbaptextern char tmpline[]; 144234949Sbapt 145234949Sbaptextern char **glob(char *); 146234949Sbaptextern char *renamefrom(char *); 147234949Sbaptextern void cwd(const char *); 148234949Sbapt 149234949Sbaptextern void dologout(int); 150234949Sbaptextern void fatal(const char *); 151234949Sbaptextern void makedir(const char *); 152234949Sbaptextern void nack(const char *); 153234949Sbaptextern void pass(const char *); 154234949Sbaptextern void passive(void); 155234949Sbaptextern void pwd(void); 156234949Sbaptextern void removedir(char *); 157234949Sbaptextern void renamecmd(char *, char *); 158234949Sbaptextern void retrieve(const char *, const char *); 159234949Sbaptextern void send_file_list(const char *); 160234949Sbaptextern void statcmd(void); 161234949Sbaptextern void statfilecmd(const char *); 162234949Sbaptextern void store(char *, const char *, int); 163234949Sbaptextern void user(const char *); 164234949Sbapt 165234949Sbaptextern void perror_reply(int, const char *, ...); 166234949Sbaptextern void reply(int, const char *, ...); 167234949Sbaptextern void lreply(int, const char *, ...); 168234949Sbapt 169234949Sbaptstatic int cmd_type; 170234949Sbaptstatic int cmd_form; 171234949Sbaptstatic int cmd_bytesz; 172234949Sbaptchar cbuf[512]; 173234949Sbaptchar *fromname; 174234949Sbapt 175234949Sbaptstruct tab { 176234949Sbapt const char *name; 177234949Sbapt short token; 178234949Sbapt short state; 179234949Sbapt short implemented; /* 1 if command is implemented */ 180234949Sbapt const char *help; 181234949Sbapt}; 182234949Sbapt 183234949Sbaptstatic char * copy(const char *); 184234949Sbapt 185234949Sbapt#ifdef YYBISON 186234949Sbaptstatic void sizecmd(char *filename); 187234949Sbaptstatic void help(struct tab *ctab, char *s); 188234949Sbaptstruct tab cmdtab[]; 189234949Sbaptstruct tab sitetab[]; 190234949Sbapt#endif 191234949Sbapt 192234949Sbaptstatic void 193234949Sbaptyyerror(const char *msg) 194234949Sbapt{ 195234949Sbapt perror(msg); 196234949Sbapt} 197251143Sbapt#line 126 "ftp.y" 198251143Sbapt#ifdef YYSTYPE 199251143Sbapt#undef YYSTYPE_IS_DECLARED 200251143Sbapt#define YYSTYPE_IS_DECLARED 1 201234949Sbapt#endif 202251143Sbapt#ifndef YYSTYPE_IS_DECLARED 203251143Sbapt#define YYSTYPE_IS_DECLARED 1 204251143Sbapttypedef union 205251143Sbapt{ 206251143Sbapt int ival; 207251143Sbapt char *sval; 208251143Sbapt} YYSTYPE; 209251143Sbapt#endif /* !YYSTYPE_IS_DECLARED */ 210251143Sbapt#line 211 "ftp.tab.c" 211234949Sbapt 212234949Sbapt/* compatibility with bison */ 213234949Sbapt#ifdef YYPARSE_PARAM 214234949Sbapt/* compatibility with FreeBSD */ 215234949Sbapt# ifdef YYPARSE_PARAM_TYPE 216234949Sbapt# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) 217234949Sbapt# else 218234949Sbapt# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) 219234949Sbapt# endif 220234949Sbapt#else 221234949Sbapt# define YYPARSE_DECL() yyparse(void) 222234949Sbapt#endif 223234949Sbapt 224234949Sbapt/* Parameters sent to lex. */ 225234949Sbapt#ifdef YYLEX_PARAM 226234949Sbapt# define YYLEX_DECL() yylex(void *YYLEX_PARAM) 227234949Sbapt# define YYLEX yylex(YYLEX_PARAM) 228234949Sbapt#else 229234949Sbapt# define YYLEX_DECL() yylex(void) 230234949Sbapt# define YYLEX yylex() 231234949Sbapt#endif 232234949Sbapt 233234949Sbapt/* Parameters sent to yyerror. */ 234234949Sbapt#ifndef YYERROR_DECL 235234949Sbapt#define YYERROR_DECL() yyerror(const char *s) 236234949Sbapt#endif 237234949Sbapt#ifndef YYERROR_CALL 238234949Sbapt#define YYERROR_CALL(msg) yyerror(msg) 239234949Sbapt#endif 240234949Sbapt 241234949Sbaptextern int YYPARSE_DECL(); 242234949Sbapt 243251143Sbapt#define NUMBER 257 244251143Sbapt#define STRING 258 245251143Sbapt#define A 259 246251143Sbapt#define B 260 247251143Sbapt#define C 261 248251143Sbapt#define E 262 249251143Sbapt#define F 263 250251143Sbapt#define I 264 251251143Sbapt#define L 265 252251143Sbapt#define N 266 253251143Sbapt#define P 267 254251143Sbapt#define R 268 255251143Sbapt#define S 269 256251143Sbapt#define T 270 257251143Sbapt#define SP 271 258251143Sbapt#define CRLF 272 259251143Sbapt#define COMMA 273 260234949Sbapt#define USER 274 261234949Sbapt#define PASS 275 262234949Sbapt#define ACCT 276 263234949Sbapt#define REIN 277 264234949Sbapt#define QUIT 278 265234949Sbapt#define PORT 279 266234949Sbapt#define PASV 280 267234949Sbapt#define TYPE 281 268234949Sbapt#define STRU 282 269234949Sbapt#define MODE 283 270234949Sbapt#define RETR 284 271234949Sbapt#define STOR 285 272234949Sbapt#define APPE 286 273234949Sbapt#define MLFL 287 274234949Sbapt#define MAIL 288 275234949Sbapt#define MSND 289 276234949Sbapt#define MSOM 290 277234949Sbapt#define MSAM 291 278234949Sbapt#define MRSQ 292 279234949Sbapt#define MRCP 293 280234949Sbapt#define ALLO 294 281234949Sbapt#define REST 295 282234949Sbapt#define RNFR 296 283234949Sbapt#define RNTO 297 284234949Sbapt#define ABOR 298 285234949Sbapt#define DELE 299 286234949Sbapt#define CWD 300 287234949Sbapt#define LIST 301 288234949Sbapt#define NLST 302 289234949Sbapt#define SITE 303 290234949Sbapt#define STAT 304 291234949Sbapt#define HELP 305 292234949Sbapt#define NOOP 306 293234949Sbapt#define MKD 307 294234949Sbapt#define RMD 308 295234949Sbapt#define PWD 309 296234949Sbapt#define CDUP 310 297234949Sbapt#define STOU 311 298234949Sbapt#define SMNT 312 299234949Sbapt#define SYST 313 300234949Sbapt#define SIZE 314 301234949Sbapt#define MDTM 315 302234949Sbapt#define UMASK 316 303234949Sbapt#define IDLE 317 304234949Sbapt#define CHMOD 318 305234949Sbapt#define LEXERR 319 306234949Sbapt#define YYERRCODE 256 307234949Sbaptstatic const short ftp_lhs[] = { -1, 308251143Sbapt 0, 0, 0, 11, 11, 11, 11, 11, 11, 11, 309251143Sbapt 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 310251143Sbapt 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 311251143Sbapt 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 312251143Sbapt 11, 11, 11, 11, 11, 11, 12, 10, 7, 7, 313251143Sbapt 1, 13, 3, 3, 3, 14, 14, 14, 14, 14, 314251143Sbapt 14, 14, 14, 6, 6, 6, 4, 4, 4, 8, 315251143Sbapt 9, 5, 2, 316234949Sbapt}; 317234949Sbaptstatic const short ftp_len[] = { 2, 318234949Sbapt 0, 2, 2, 4, 4, 4, 2, 4, 4, 4, 319234949Sbapt 4, 8, 5, 5, 5, 3, 5, 3, 5, 5, 320234949Sbapt 2, 5, 4, 2, 3, 5, 2, 4, 2, 5, 321234949Sbapt 5, 3, 3, 4, 6, 5, 7, 9, 4, 6, 322234949Sbapt 5, 2, 5, 5, 2, 2, 5, 1, 0, 1, 323234949Sbapt 1, 11, 1, 1, 1, 1, 3, 1, 3, 1, 324234949Sbapt 1, 3, 2, 1, 1, 1, 1, 1, 1, 1, 325234949Sbapt 1, 1, 0, 326234949Sbapt}; 327234949Sbaptstatic const short ftp_defred[] = { 1, 328234949Sbapt 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 329234949Sbapt 73, 73, 73, 0, 73, 0, 0, 73, 73, 73, 330234949Sbapt 73, 0, 0, 0, 0, 73, 73, 73, 73, 73, 331234949Sbapt 0, 73, 73, 2, 3, 46, 0, 0, 45, 0, 332234949Sbapt 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 333234949Sbapt 24, 0, 0, 0, 0, 0, 21, 0, 0, 27, 334234949Sbapt 29, 0, 0, 0, 0, 0, 42, 0, 0, 48, 335234949Sbapt 0, 50, 0, 0, 0, 0, 0, 60, 0, 0, 336234949Sbapt 64, 66, 65, 0, 68, 69, 67, 0, 0, 0, 337234949Sbapt 0, 0, 0, 71, 0, 70, 0, 0, 25, 0, 338234949Sbapt 18, 0, 16, 0, 73, 0, 73, 0, 0, 0, 339234949Sbapt 0, 32, 33, 0, 0, 0, 4, 5, 0, 6, 340251143Sbapt 0, 0, 51, 0, 63, 8, 9, 10, 0, 0, 341234949Sbapt 0, 0, 11, 0, 23, 0, 0, 0, 0, 0, 342234949Sbapt 34, 0, 0, 39, 0, 0, 28, 0, 0, 0, 343234949Sbapt 0, 0, 0, 55, 53, 54, 57, 59, 62, 13, 344234949Sbapt 14, 15, 0, 47, 22, 26, 19, 17, 0, 0, 345234949Sbapt 36, 0, 0, 20, 30, 31, 41, 43, 44, 0, 346234949Sbapt 0, 35, 72, 0, 40, 0, 0, 0, 37, 0, 347234949Sbapt 0, 12, 0, 0, 38, 0, 0, 0, 52, 348234949Sbapt}; 349234949Sbaptstatic const short ftp_dgoto[] = { 1, 350251143Sbapt 125, 45, 157, 88, 184, 84, 73, 95, 96, 71, 351251143Sbapt 34, 35, 75, 80, 352234949Sbapt}; 353234949Sbaptstatic const short ftp_sindex[] = { 0, 354251143Sbapt -224, -256, -248, -241, -239, -233, -225, -218, -200, -165, 355251143Sbapt 0, 0, 0, -164, 0, -163, -176, 0, 0, 0, 356251143Sbapt 0, -162, -161, -231, -160, 0, 0, 0, 0, 0, 357251143Sbapt -159, 0, 0, 0, 0, 0, -240, -148, 0, -143, 358251143Sbapt 0, -252, -175, -255, -156, -155, -154, -139, -152, -138, 359251143Sbapt 0, -149, -205, -203, -177, -253, 0, -147, -133, 0, 360251143Sbapt 0, -145, -144, -142, -141, -137, 0, -136, -135, 0, 361251143Sbapt -140, 0, -134, -132, -130, -131, -128, 0, -254, -127, 362251143Sbapt 0, 0, 0, -126, 0, 0, 0, -125, -138, -138, 363251143Sbapt -138, -174, -138, 0, -124, 0, -138, -138, 0, -138, 364251143Sbapt 0, -129, 0, -172, 0, -169, 0, -138, -123, -138, 365251143Sbapt -138, 0, 0, -138, -138, -138, 0, 0, -120, 0, 366251143Sbapt -246, -246, 0, -118, 0, 0, 0, 0, -122, -121, 367251143Sbapt -119, -116, 0, -117, 0, -115, -114, -113, -112, -104, 368251143Sbapt 0, -167, -101, 0, -110, -109, 0, -108, -107, -106, 369251143Sbapt -105, -103, -111, 0, 0, 0, 0, 0, 0, 0, 370251143Sbapt 0, 0, -100, 0, 0, 0, 0, 0, -102, -85, 371251143Sbapt 0, -99, -85, 0, 0, 0, 0, 0, 0, -83, 372251143Sbapt -82, 0, 0, -96, 0, -94, -95, -93, 0, -138, 373251143Sbapt -77, 0, -91, -90, 0, -75, -88, -73, 0, 374234949Sbapt}; 375234949Sbaptstatic const short ftp_rindex[] = { 0, 376234949Sbapt 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 377234949Sbapt 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 378251143Sbapt 0, 0, -84, 0, 0, 0, 0, 0, 0, 0, 379251143Sbapt 0, 0, 0, 0, 0, 0, 0, -86, 0, 0, 380234949Sbapt 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 381234949Sbapt 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 382234949Sbapt 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 383251143Sbapt 0, 0, 0, 0, 0, -81, -80, 0, -160, 0, 384234949Sbapt 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 385234949Sbapt 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 386234949Sbapt 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 387234949Sbapt 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 388234949Sbapt 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 389234949Sbapt 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 390234949Sbapt 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 391234949Sbapt 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 392234949Sbapt 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 393234949Sbapt 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 394234949Sbapt 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 395234949Sbapt 0, 0, 0, 0, 0, 0, 0, 0, 0, 396234949Sbapt}; 397234949Sbaptstatic const short ftp_gindex[] = { 0, 398251143Sbapt 4, 16, 11, 0, -29, 0, 0, -89, 0, 0, 399251143Sbapt 0, 0, 0, 0, 400234949Sbapt}; 401251143Sbapt#define YYTABLESIZE 192 402234949Sbaptstatic const short ftp_table[] = { 129, 403251143Sbapt 130, 131, 123, 134, 85, 86, 76, 136, 137, 77, 404251143Sbapt 138, 78, 79, 87, 154, 36, 124, 70, 146, 155, 405251143Sbapt 148, 149, 37, 156, 150, 151, 152, 46, 47, 38, 406251143Sbapt 49, 2, 39, 52, 53, 54, 55, 40, 58, 59, 407251143Sbapt 60, 62, 63, 64, 65, 66, 41, 68, 69, 3, 408251143Sbapt 4, 104, 42, 5, 6, 7, 8, 9, 10, 11, 409251143Sbapt 12, 13, 105, 106, 107, 98, 99, 100, 101, 14, 410251143Sbapt 43, 15, 16, 17, 18, 19, 20, 21, 22, 23, 411251143Sbapt 24, 25, 26, 27, 28, 29, 30, 81, 31, 32, 412251143Sbapt 33, 82, 83, 102, 103, 51, 132, 133, 140, 141, 413251143Sbapt 193, 143, 144, 170, 171, 44, 48, 50, 56, 72, 414251143Sbapt 57, 61, 67, 74, 89, 90, 91, 92, 93, 94, 415251143Sbapt 142, 97, 145, 108, 109, 110, 111, 159, 139, 112, 416251143Sbapt 113, 117, 158, 114, 115, 116, 153, 118, 123, 121, 417251143Sbapt 119, 120, 122, 186, 126, 127, 128, 135, 147, 160, 418251143Sbapt 161, 163, 162, 169, 164, 172, 165, 166, 167, 168, 419251143Sbapt 173, 180, 174, 175, 176, 177, 178, 0, 179, 182, 420251143Sbapt 181, 183, 185, 187, 188, 189, 190, 191, 192, 194, 421251143Sbapt 195, 197, 196, 199, 198, 49, 73, 0, 0, 0, 422251143Sbapt 56, 58, 423234949Sbapt}; 424234949Sbaptstatic const short ftp_check[] = { 89, 425251143Sbapt 90, 91, 257, 93, 260, 261, 259, 97, 98, 262, 426251143Sbapt 100, 264, 265, 269, 261, 272, 271, 258, 108, 266, 427251143Sbapt 110, 111, 271, 270, 114, 115, 116, 12, 13, 271, 428251143Sbapt 15, 256, 272, 18, 19, 20, 21, 271, 23, 271, 429251143Sbapt 272, 26, 27, 28, 29, 30, 272, 32, 33, 274, 430251143Sbapt 275, 305, 271, 278, 279, 280, 281, 282, 283, 284, 431251143Sbapt 285, 286, 316, 317, 318, 271, 272, 271, 272, 294, 432251143Sbapt 271, 296, 297, 298, 299, 300, 301, 302, 303, 304, 433251143Sbapt 305, 306, 307, 308, 309, 310, 311, 263, 313, 314, 434251143Sbapt 315, 267, 268, 271, 272, 272, 271, 272, 271, 272, 435251143Sbapt 190, 271, 272, 271, 272, 271, 271, 271, 271, 258, 436251143Sbapt 272, 272, 272, 257, 271, 271, 271, 257, 271, 258, 437251143Sbapt 105, 271, 107, 271, 258, 271, 271, 124, 258, 272, 438251143Sbapt 272, 272, 122, 271, 271, 271, 257, 272, 257, 271, 439251143Sbapt 273, 272, 271, 173, 272, 272, 272, 272, 272, 272, 440251143Sbapt 272, 268, 272, 258, 272, 257, 272, 272, 272, 272, 441251143Sbapt 271, 273, 272, 272, 272, 272, 272, -1, 272, 272, 442251143Sbapt 271, 257, 272, 257, 257, 272, 271, 273, 272, 257, 443251143Sbapt 272, 257, 273, 257, 273, 272, 271, -1, -1, -1, 444251143Sbapt 272, 272, 445234949Sbapt}; 446234949Sbapt#define YYFINAL 1 447234949Sbapt#ifndef YYDEBUG 448234949Sbapt#define YYDEBUG 0 449234949Sbapt#endif 450234949Sbapt#define YYMAXTOKEN 319 451234949Sbapt#if YYDEBUG 452234949Sbaptstatic const char *yyname[] = { 453234949Sbapt 454234949Sbapt"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, 455234949Sbapt0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 456234949Sbapt0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 457234949Sbapt0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 458234949Sbapt0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 459234949Sbapt0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 460251143Sbapt0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"NUMBER","STRING","A","B","C","E", 461251143Sbapt"F","I","L","N","P","R","S","T","SP","CRLF","COMMA","USER","PASS","ACCT","REIN", 462251143Sbapt"QUIT","PORT","PASV","TYPE","STRU","MODE","RETR","STOR","APPE","MLFL","MAIL", 463251143Sbapt"MSND","MSOM","MSAM","MRSQ","MRCP","ALLO","REST","RNFR","RNTO","ABOR","DELE", 464251143Sbapt"CWD","LIST","NLST","SITE","STAT","HELP","NOOP","MKD","RMD","PWD","CDUP","STOU", 465251143Sbapt"SMNT","SYST","SIZE","MDTM","UMASK","IDLE","CHMOD","LEXERR", 466234949Sbapt}; 467234949Sbaptstatic const char *yyrule[] = { 468234949Sbapt"$accept : cmd_list", 469234949Sbapt"cmd_list :", 470234949Sbapt"cmd_list : cmd_list cmd", 471234949Sbapt"cmd_list : cmd_list rcmd", 472234949Sbapt"cmd : USER SP username CRLF", 473234949Sbapt"cmd : PASS SP password CRLF", 474234949Sbapt"cmd : PORT SP host_port CRLF", 475234949Sbapt"cmd : PASV CRLF", 476234949Sbapt"cmd : TYPE SP type_code CRLF", 477234949Sbapt"cmd : STRU SP struct_code CRLF", 478234949Sbapt"cmd : MODE SP mode_code CRLF", 479234949Sbapt"cmd : ALLO SP NUMBER CRLF", 480234949Sbapt"cmd : ALLO SP NUMBER SP R SP NUMBER CRLF", 481234949Sbapt"cmd : RETR check_login SP pathname CRLF", 482234949Sbapt"cmd : STOR check_login SP pathname CRLF", 483234949Sbapt"cmd : APPE check_login SP pathname CRLF", 484234949Sbapt"cmd : NLST check_login CRLF", 485234949Sbapt"cmd : NLST check_login SP STRING CRLF", 486234949Sbapt"cmd : LIST check_login CRLF", 487234949Sbapt"cmd : LIST check_login SP pathname CRLF", 488234949Sbapt"cmd : STAT check_login SP pathname CRLF", 489234949Sbapt"cmd : STAT CRLF", 490234949Sbapt"cmd : DELE check_login SP pathname CRLF", 491234949Sbapt"cmd : RNTO SP pathname CRLF", 492234949Sbapt"cmd : ABOR CRLF", 493234949Sbapt"cmd : CWD check_login CRLF", 494234949Sbapt"cmd : CWD check_login SP pathname CRLF", 495234949Sbapt"cmd : HELP CRLF", 496234949Sbapt"cmd : HELP SP STRING CRLF", 497234949Sbapt"cmd : NOOP CRLF", 498234949Sbapt"cmd : MKD check_login SP pathname CRLF", 499234949Sbapt"cmd : RMD check_login SP pathname CRLF", 500234949Sbapt"cmd : PWD check_login CRLF", 501234949Sbapt"cmd : CDUP check_login CRLF", 502234949Sbapt"cmd : SITE SP HELP CRLF", 503234949Sbapt"cmd : SITE SP HELP SP STRING CRLF", 504234949Sbapt"cmd : SITE SP UMASK check_login CRLF", 505234949Sbapt"cmd : SITE SP UMASK check_login SP octal_number CRLF", 506234949Sbapt"cmd : SITE SP CHMOD check_login SP octal_number SP pathname CRLF", 507234949Sbapt"cmd : SITE SP IDLE CRLF", 508234949Sbapt"cmd : SITE SP IDLE SP NUMBER CRLF", 509234949Sbapt"cmd : STOU check_login SP pathname CRLF", 510234949Sbapt"cmd : SYST CRLF", 511234949Sbapt"cmd : SIZE check_login SP pathname CRLF", 512234949Sbapt"cmd : MDTM check_login SP pathname CRLF", 513234949Sbapt"cmd : QUIT CRLF", 514234949Sbapt"cmd : error CRLF", 515234949Sbapt"rcmd : RNFR check_login SP pathname CRLF", 516234949Sbapt"username : STRING", 517234949Sbapt"password :", 518234949Sbapt"password : STRING", 519234949Sbapt"byte_size : NUMBER", 520234949Sbapt"host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER", 521234949Sbapt"form_code : N", 522234949Sbapt"form_code : T", 523234949Sbapt"form_code : C", 524234949Sbapt"type_code : A", 525234949Sbapt"type_code : A SP form_code", 526234949Sbapt"type_code : E", 527234949Sbapt"type_code : E SP form_code", 528234949Sbapt"type_code : I", 529234949Sbapt"type_code : L", 530234949Sbapt"type_code : L SP byte_size", 531234949Sbapt"type_code : L byte_size", 532234949Sbapt"struct_code : F", 533234949Sbapt"struct_code : R", 534234949Sbapt"struct_code : P", 535234949Sbapt"mode_code : S", 536234949Sbapt"mode_code : B", 537234949Sbapt"mode_code : C", 538234949Sbapt"pathname : pathstring", 539234949Sbapt"pathstring : STRING", 540234949Sbapt"octal_number : NUMBER", 541234949Sbapt"check_login :", 542234949Sbapt 543234949Sbapt}; 544234949Sbapt#endif 545234949Sbapt 546234949Sbaptint yydebug; 547234949Sbaptint yynerrs; 548234949Sbapt 549234949Sbaptint yyerrflag; 550234949Sbaptint yychar; 551234949SbaptYYSTYPE yyval; 552234949SbaptYYSTYPE yylval; 553234949Sbapt 554234949Sbapt/* define the initial stack-sizes */ 555234949Sbapt#ifdef YYSTACKSIZE 556234949Sbapt#undef YYMAXDEPTH 557234949Sbapt#define YYMAXDEPTH YYSTACKSIZE 558234949Sbapt#else 559234949Sbapt#ifdef YYMAXDEPTH 560234949Sbapt#define YYSTACKSIZE YYMAXDEPTH 561234949Sbapt#else 562234949Sbapt#define YYSTACKSIZE 500 563234949Sbapt#define YYMAXDEPTH 500 564234949Sbapt#endif 565234949Sbapt#endif 566234949Sbapt 567234949Sbapt#define YYINITSTACKSIZE 500 568234949Sbapt 569234949Sbapttypedef struct { 570234949Sbapt unsigned stacksize; 571234949Sbapt short *s_base; 572234949Sbapt short *s_mark; 573234949Sbapt short *s_last; 574234949Sbapt YYSTYPE *l_base; 575234949Sbapt YYSTYPE *l_mark; 576234949Sbapt} YYSTACKDATA; 577234949Sbapt/* variables for the parser stack */ 578234949Sbaptstatic YYSTACKDATA yystack; 579251143Sbapt#line 733 "ftp.y" 580234949Sbapt 581234949Sbapt#ifdef YYBYACC 582234949Sbaptextern int YYLEX_DECL(); 583234949Sbapt#endif 584234949Sbapt 585234949Sbaptextern jmp_buf errcatch; 586234949Sbapt 587234949Sbaptstatic void upper(char *); 588234949Sbapt 589234949Sbapt#define CMD 0 /* beginning of command */ 590234949Sbapt#define ARGS 1 /* expect miscellaneous arguments */ 591234949Sbapt#define STR1 2 /* expect SP followed by STRING */ 592234949Sbapt#define STR2 3 /* expect STRING */ 593234949Sbapt#define OSTR 4 /* optional SP then STRING */ 594234949Sbapt#define ZSTR1 5 /* SP then optional STRING */ 595234949Sbapt#define ZSTR2 6 /* optional STRING after SP */ 596234949Sbapt#define SITECMD 7 /* SITE command */ 597234949Sbapt#define NSTR 8 /* Number followed by a string */ 598234949Sbapt 599234949Sbaptstruct tab cmdtab[] = { /* In order defined in RFC 765 */ 600234949Sbapt { "USER", USER, STR1, 1, "<sp> username" }, 601234949Sbapt { "PASS", PASS, ZSTR1, 1, "<sp> password" }, 602234949Sbapt { "ACCT", ACCT, STR1, 0, "(specify account)" }, 603234949Sbapt { "SMNT", SMNT, ARGS, 0, "(structure mount)" }, 604234949Sbapt { "REIN", REIN, ARGS, 0, "(reinitialize server state)" }, 605234949Sbapt { "QUIT", QUIT, ARGS, 1, "(terminate service)", }, 606234949Sbapt { "PORT", PORT, ARGS, 1, "<sp> b0, b1, b2, b3, b4" }, 607234949Sbapt { "PASV", PASV, ARGS, 1, "(set server in passive mode)" }, 608234949Sbapt { "TYPE", TYPE, ARGS, 1, "<sp> [ A | E | I | L ]" }, 609234949Sbapt { "STRU", STRU, ARGS, 1, "(specify file structure)" }, 610234949Sbapt { "MODE", MODE, ARGS, 1, "(specify transfer mode)" }, 611234949Sbapt { "RETR", RETR, STR1, 1, "<sp> file-name" }, 612234949Sbapt { "STOR", STOR, STR1, 1, "<sp> file-name" }, 613234949Sbapt { "APPE", APPE, STR1, 1, "<sp> file-name" }, 614234949Sbapt { "MLFL", MLFL, OSTR, 0, "(mail file)" }, 615234949Sbapt { "MAIL", MAIL, OSTR, 0, "(mail to user)" }, 616234949Sbapt { "MSND", MSND, OSTR, 0, "(mail send to terminal)" }, 617234949Sbapt { "MSOM", MSOM, OSTR, 0, "(mail send to terminal or mailbox)" }, 618234949Sbapt { "MSAM", MSAM, OSTR, 0, "(mail send to terminal and mailbox)" }, 619234949Sbapt { "MRSQ", MRSQ, OSTR, 0, "(mail recipient scheme question)" }, 620234949Sbapt { "MRCP", MRCP, STR1, 0, "(mail recipient)" }, 621234949Sbapt { "ALLO", ALLO, ARGS, 1, "allocate storage (vacuously)" }, 622234949Sbapt { "REST", REST, ARGS, 0, "(restart command)" }, 623234949Sbapt { "RNFR", RNFR, STR1, 1, "<sp> file-name" }, 624234949Sbapt { "RNTO", RNTO, STR1, 1, "<sp> file-name" }, 625234949Sbapt { "ABOR", ABOR, ARGS, 1, "(abort operation)" }, 626234949Sbapt { "DELE", DELE, STR1, 1, "<sp> file-name" }, 627234949Sbapt { "CWD", CWD, OSTR, 1, "[ <sp> directory-name ]" }, 628234949Sbapt { "XCWD", CWD, OSTR, 1, "[ <sp> directory-name ]" }, 629234949Sbapt { "LIST", LIST, OSTR, 1, "[ <sp> path-name ]" }, 630234949Sbapt { "NLST", NLST, OSTR, 1, "[ <sp> path-name ]" }, 631234949Sbapt { "SITE", SITE, SITECMD, 1, "site-cmd [ <sp> arguments ]" }, 632234949Sbapt { "SYST", SYST, ARGS, 1, "(get type of operating system)" }, 633234949Sbapt { "STAT", STAT, OSTR, 1, "[ <sp> path-name ]" }, 634234949Sbapt { "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" }, 635234949Sbapt { "NOOP", NOOP, ARGS, 1, "" }, 636234949Sbapt { "MKD", MKD, STR1, 1, "<sp> path-name" }, 637234949Sbapt { "XMKD", MKD, STR1, 1, "<sp> path-name" }, 638234949Sbapt { "RMD", RMD, STR1, 1, "<sp> path-name" }, 639234949Sbapt { "XRMD", RMD, STR1, 1, "<sp> path-name" }, 640234949Sbapt { "PWD", PWD, ARGS, 1, "(return current directory)" }, 641234949Sbapt { "XPWD", PWD, ARGS, 1, "(return current directory)" }, 642234949Sbapt { "CDUP", CDUP, ARGS, 1, "(change to parent directory)" }, 643234949Sbapt { "XCUP", CDUP, ARGS, 1, "(change to parent directory)" }, 644234949Sbapt { "STOU", STOU, STR1, 1, "<sp> file-name" }, 645234949Sbapt { "SIZE", SIZE, OSTR, 1, "<sp> path-name" }, 646234949Sbapt { "MDTM", MDTM, OSTR, 1, "<sp> path-name" }, 647234949Sbapt { 0, 0, 0, 0, 0 } 648234949Sbapt}; 649234949Sbapt 650234949Sbaptstruct tab sitetab[] = { 651234949Sbapt { "UMASK", UMASK, ARGS, 1, "[ <sp> umask ]" }, 652234949Sbapt { "IDLE", IDLE, ARGS, 1, "[ <sp> maximum-idle-time ]" }, 653234949Sbapt { "CHMOD", CHMOD, NSTR, 1, "<sp> mode <sp> file-name" }, 654234949Sbapt { "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" }, 655234949Sbapt { 0, 0, 0, 0, 0 } 656234949Sbapt}; 657234949Sbapt 658234949Sbaptstatic struct tab * 659234949Sbaptlookup(struct tab *p, char *cmd) 660234949Sbapt{ 661234949Sbapt 662234949Sbapt for (; p->name != 0; p++) 663234949Sbapt if (strcmp(cmd, p->name) == 0) 664234949Sbapt return (p); 665234949Sbapt return (0); 666234949Sbapt} 667234949Sbapt 668234949Sbapt#include <arpa/telnet.h> 669234949Sbapt 670234949Sbapt/* 671234949Sbapt * get_line - a hacked up version of fgets to ignore TELNET escape codes. 672234949Sbapt */ 673234949Sbaptstatic char * 674234949Sbaptget_line(char *s, int n, FILE *iop) 675234949Sbapt{ 676234949Sbapt register int c; 677234949Sbapt register char *cs; 678234949Sbapt 679234949Sbapt cs = s; 680234949Sbapt/* tmpline may contain saved command from urgent mode interruption */ 681234949Sbapt for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) { 682234949Sbapt *cs++ = tmpline[c]; 683234949Sbapt if (tmpline[c] == '\n') { 684234949Sbapt *cs = '\0'; 685234949Sbapt if (debug) 686234949Sbapt syslog(LOG_DEBUG, "command: %s", s); 687234949Sbapt tmpline[0] = '\0'; 688234949Sbapt return(s); 689234949Sbapt } 690234949Sbapt if (c == 0) 691234949Sbapt tmpline[0] = '\0'; 692234949Sbapt } 693234949Sbapt while ((c = getc(iop)) != EOF) { 694234949Sbapt c &= 0377; 695234949Sbapt if (c == IAC) { 696234949Sbapt if ((c = getc(iop)) != EOF) { 697234949Sbapt c &= 0377; 698234949Sbapt switch (c) { 699234949Sbapt case WILL: 700234949Sbapt case WONT: 701234949Sbapt c = getc(iop); 702234949Sbapt printf("%c%c%c", IAC, DONT, 0377&c); 703234949Sbapt (void) fflush(stdout); 704234949Sbapt continue; 705234949Sbapt case DO: 706234949Sbapt case DONT: 707234949Sbapt c = getc(iop); 708234949Sbapt printf("%c%c%c", IAC, WONT, 0377&c); 709234949Sbapt (void) fflush(stdout); 710234949Sbapt continue; 711234949Sbapt case IAC: 712234949Sbapt break; 713234949Sbapt default: 714234949Sbapt continue; /* ignore command */ 715234949Sbapt } 716234949Sbapt } 717234949Sbapt } 718251143Sbapt *cs++ = (char) c; 719234949Sbapt if (--n <= 0 || c == '\n') 720234949Sbapt break; 721234949Sbapt } 722234949Sbapt if (c == EOF && cs == s) 723234949Sbapt return (0); 724234949Sbapt *cs = '\0'; 725234949Sbapt if (debug) 726234949Sbapt syslog(LOG_DEBUG, "command: %s", s); 727234949Sbapt return (s); 728234949Sbapt} 729234949Sbapt 730234949Sbaptstatic void 731234949Sbapttoolong(int sig) 732234949Sbapt{ 733234949Sbapt time_t now; 734234949Sbapt 735234949Sbapt (void) sig; 736234949Sbapt reply(421, 737234949Sbapt "Timeout (%d seconds): closing control connection.", timeout); 738234949Sbapt (void) time(&now); 739234949Sbapt if (logging) { 740234949Sbapt syslog(LOG_INFO, 741234949Sbapt "User %s timed out after %d seconds at %s", 742234949Sbapt (pw ? pw -> pw_name : "unknown"), timeout, ctime(&now)); 743234949Sbapt } 744234949Sbapt dologout(1); 745234949Sbapt} 746234949Sbapt 747234949Sbaptint 748234949Sbaptyylex(void) 749234949Sbapt{ 750234949Sbapt static int cpos, state; 751234949Sbapt register char *cp, *cp2; 752234949Sbapt register struct tab *p; 753234949Sbapt int n; 754234949Sbapt char c; 755234949Sbapt 756234949Sbapt for (;;) { 757234949Sbapt switch (state) { 758234949Sbapt 759234949Sbapt case CMD: 760234949Sbapt (void) signal(SIGALRM, toolong); 761234949Sbapt (void) alarm((unsigned) timeout); 762234949Sbapt if (get_line(cbuf, sizeof(cbuf)-1, stdin) == 0) { 763234949Sbapt reply(221, "You could at least say goodbye."); 764234949Sbapt dologout(0); 765234949Sbapt } 766234949Sbapt (void) alarm(0); 767234949Sbapt#ifdef SETPROCTITLE 768234949Sbapt if (strncasecmp(cbuf, "PASS", 4) != 0) 769234949Sbapt setproctitle("%s: %s", proctitle, cbuf); 770234949Sbapt#endif /* SETPROCTITLE */ 771234949Sbapt if ((cp = strchr(cbuf, '\r'))) { 772234949Sbapt *cp++ = '\n'; 773234949Sbapt *cp = '\0'; 774234949Sbapt } 775234949Sbapt if ((cp = strpbrk(cbuf, " \n"))) 776251143Sbapt cpos = (int) (cp - cbuf); 777234949Sbapt if (cpos == 0) 778234949Sbapt cpos = 4; 779234949Sbapt c = cbuf[cpos]; 780234949Sbapt cbuf[cpos] = '\0'; 781234949Sbapt upper(cbuf); 782234949Sbapt p = lookup(cmdtab, cbuf); 783234949Sbapt cbuf[cpos] = c; 784234949Sbapt if (p != 0) { 785234949Sbapt if (p->implemented == 0) { 786234949Sbapt nack(p->name); 787234949Sbapt longjmp(errcatch,0); 788234949Sbapt /* NOTREACHED */ 789234949Sbapt } 790234949Sbapt state = p->state; 791234949Sbapt *(const char **)(&yylval) = p->name; 792234949Sbapt return (p->token); 793234949Sbapt } 794234949Sbapt break; 795234949Sbapt 796234949Sbapt case SITECMD: 797234949Sbapt if (cbuf[cpos] == ' ') { 798234949Sbapt cpos++; 799234949Sbapt return (SP); 800234949Sbapt } 801234949Sbapt cp = &cbuf[cpos]; 802234949Sbapt if ((cp2 = strpbrk(cp, " \n"))) 803251143Sbapt cpos = (int) (cp2 - cbuf); 804234949Sbapt c = cbuf[cpos]; 805234949Sbapt cbuf[cpos] = '\0'; 806234949Sbapt upper(cp); 807234949Sbapt p = lookup(sitetab, cp); 808234949Sbapt cbuf[cpos] = c; 809234949Sbapt if (p != 0) { 810234949Sbapt if (p->implemented == 0) { 811234949Sbapt state = CMD; 812234949Sbapt nack(p->name); 813234949Sbapt longjmp(errcatch,0); 814234949Sbapt /* NOTREACHED */ 815234949Sbapt } 816234949Sbapt state = p->state; 817234949Sbapt *(const char **)(&yylval) = p->name; 818234949Sbapt return (p->token); 819234949Sbapt } 820234949Sbapt state = CMD; 821234949Sbapt break; 822234949Sbapt 823234949Sbapt case OSTR: 824234949Sbapt if (cbuf[cpos] == '\n') { 825234949Sbapt state = CMD; 826234949Sbapt return (CRLF); 827234949Sbapt } 828234949Sbapt /* FALLTHROUGH */ 829234949Sbapt 830234949Sbapt case STR1: 831234949Sbapt case ZSTR1: 832234949Sbapt dostr1: 833234949Sbapt if (cbuf[cpos] == ' ') { 834234949Sbapt cpos++; 835234949Sbapt if (state == OSTR) 836234949Sbapt state = STR2; 837234949Sbapt else 838234949Sbapt ++state; 839234949Sbapt return (SP); 840234949Sbapt } 841234949Sbapt break; 842234949Sbapt 843234949Sbapt case ZSTR2: 844234949Sbapt if (cbuf[cpos] == '\n') { 845234949Sbapt state = CMD; 846234949Sbapt return (CRLF); 847234949Sbapt } 848234949Sbapt /* FALLTHROUGH */ 849234949Sbapt 850234949Sbapt case STR2: 851234949Sbapt cp = &cbuf[cpos]; 852251143Sbapt n = (int) strlen(cp); 853234949Sbapt cpos += n - 1; 854234949Sbapt /* 855234949Sbapt * Make sure the string is nonempty and \n terminated. 856234949Sbapt */ 857234949Sbapt if (n > 1 && cbuf[cpos] == '\n') { 858234949Sbapt cbuf[cpos] = '\0'; 859234949Sbapt *(char **)&yylval = copy(cp); 860234949Sbapt cbuf[cpos] = '\n'; 861234949Sbapt state = ARGS; 862234949Sbapt return (STRING); 863234949Sbapt } 864234949Sbapt break; 865234949Sbapt 866234949Sbapt case NSTR: 867234949Sbapt if (cbuf[cpos] == ' ') { 868234949Sbapt cpos++; 869234949Sbapt return (SP); 870234949Sbapt } 871234949Sbapt if (isdigit(cbuf[cpos])) { 872234949Sbapt cp = &cbuf[cpos]; 873234949Sbapt while (isdigit(cbuf[++cpos])) 874234949Sbapt ; 875234949Sbapt c = cbuf[cpos]; 876234949Sbapt cbuf[cpos] = '\0'; 877251143Sbapt yylval.ival = atoi(cp); 878234949Sbapt cbuf[cpos] = c; 879234949Sbapt state = STR1; 880234949Sbapt return (NUMBER); 881234949Sbapt } 882234949Sbapt state = STR1; 883234949Sbapt goto dostr1; 884234949Sbapt 885234949Sbapt case ARGS: 886234949Sbapt if (isdigit(cbuf[cpos])) { 887234949Sbapt cp = &cbuf[cpos]; 888234949Sbapt while (isdigit(cbuf[++cpos])) 889234949Sbapt ; 890234949Sbapt c = cbuf[cpos]; 891234949Sbapt cbuf[cpos] = '\0'; 892251143Sbapt yylval.ival = atoi(cp); 893234949Sbapt cbuf[cpos] = c; 894234949Sbapt return (NUMBER); 895234949Sbapt } 896234949Sbapt switch (cbuf[cpos++]) { 897234949Sbapt 898234949Sbapt case '\n': 899234949Sbapt state = CMD; 900234949Sbapt return (CRLF); 901234949Sbapt 902234949Sbapt case ' ': 903234949Sbapt return (SP); 904234949Sbapt 905234949Sbapt case ',': 906234949Sbapt return (COMMA); 907234949Sbapt 908234949Sbapt case 'A': 909234949Sbapt case 'a': 910234949Sbapt return (A); 911234949Sbapt 912234949Sbapt case 'B': 913234949Sbapt case 'b': 914234949Sbapt return (B); 915234949Sbapt 916234949Sbapt case 'C': 917234949Sbapt case 'c': 918234949Sbapt return (C); 919234949Sbapt 920234949Sbapt case 'E': 921234949Sbapt case 'e': 922234949Sbapt return (E); 923234949Sbapt 924234949Sbapt case 'F': 925234949Sbapt case 'f': 926234949Sbapt return (F); 927234949Sbapt 928234949Sbapt case 'I': 929234949Sbapt case 'i': 930234949Sbapt return (I); 931234949Sbapt 932234949Sbapt case 'L': 933234949Sbapt case 'l': 934234949Sbapt return (L); 935234949Sbapt 936234949Sbapt case 'N': 937234949Sbapt case 'n': 938234949Sbapt return (N); 939234949Sbapt 940234949Sbapt case 'P': 941234949Sbapt case 'p': 942234949Sbapt return (P); 943234949Sbapt 944234949Sbapt case 'R': 945234949Sbapt case 'r': 946234949Sbapt return (R); 947234949Sbapt 948234949Sbapt case 'S': 949234949Sbapt case 's': 950234949Sbapt return (S); 951234949Sbapt 952234949Sbapt case 'T': 953234949Sbapt case 't': 954234949Sbapt return (T); 955234949Sbapt 956234949Sbapt } 957234949Sbapt break; 958234949Sbapt 959234949Sbapt default: 960234949Sbapt fatal("Unknown state in scanner."); 961234949Sbapt } 962234949Sbapt yyerror((char *) 0); 963234949Sbapt state = CMD; 964234949Sbapt longjmp(errcatch,0); 965234949Sbapt } 966234949Sbapt} 967234949Sbapt 968234949Sbaptstatic void 969234949Sbaptupper(char *s) 970234949Sbapt{ 971234949Sbapt while (*s != '\0') { 972234949Sbapt if (islower(*s)) 973234949Sbapt *s = toupper(*s); 974234949Sbapt s++; 975234949Sbapt } 976234949Sbapt} 977234949Sbapt 978234949Sbaptstatic char * 979234949Sbaptcopy(const char *s) 980234949Sbapt{ 981234949Sbapt char *p; 982234949Sbapt 983234949Sbapt p = (char * )malloc(strlen(s) + 1); 984234949Sbapt if (p == 0) 985234949Sbapt fatal("Ran out of memory."); 986234949Sbapt else 987234949Sbapt (void) strcpy(p, s); 988234949Sbapt return (p); 989234949Sbapt} 990234949Sbapt 991234949Sbaptstatic void 992234949Sbapthelp(struct tab *ctab, char *s) 993234949Sbapt{ 994234949Sbapt register struct tab *c; 995234949Sbapt register int width, NCMDS; 996234949Sbapt const char *help_type; 997234949Sbapt 998234949Sbapt if (ctab == sitetab) 999234949Sbapt help_type = "SITE "; 1000234949Sbapt else 1001234949Sbapt help_type = ""; 1002234949Sbapt width = 0, NCMDS = 0; 1003234949Sbapt for (c = ctab; c->name != 0; c++) { 1004251143Sbapt int len = (int) strlen(c->name); 1005234949Sbapt 1006234949Sbapt if (len > width) 1007234949Sbapt width = len; 1008234949Sbapt NCMDS++; 1009234949Sbapt } 1010234949Sbapt width = (width + 8) &~ 7; 1011234949Sbapt if (s == 0) { 1012234949Sbapt register int i, j, w; 1013234949Sbapt int columns, lines; 1014234949Sbapt 1015234949Sbapt lreply(214, "The following %scommands are recognized %s.", 1016234949Sbapt help_type, "(* =>'s unimplemented)"); 1017234949Sbapt columns = 76 / width; 1018234949Sbapt if (columns == 0) 1019234949Sbapt columns = 1; 1020234949Sbapt lines = (NCMDS + columns - 1) / columns; 1021234949Sbapt for (i = 0; i < lines; i++) { 1022234949Sbapt printf(" "); 1023234949Sbapt for (j = 0; j < columns; j++) { 1024234949Sbapt c = ctab + j * lines + i; 1025234949Sbapt assert(c->name != 0); 1026234949Sbapt printf("%s%c", c->name, 1027234949Sbapt c->implemented ? ' ' : '*'); 1028234949Sbapt if (c + lines >= &ctab[NCMDS]) 1029234949Sbapt break; 1030251143Sbapt w = (int) strlen(c->name) + 1; 1031234949Sbapt while (w < width) { 1032234949Sbapt putchar(' '); 1033234949Sbapt w++; 1034234949Sbapt } 1035234949Sbapt } 1036234949Sbapt printf("\r\n"); 1037234949Sbapt } 1038234949Sbapt (void) fflush(stdout); 1039234949Sbapt reply(214, "Direct comments to ftp-bugs@%s.", hostname); 1040234949Sbapt return; 1041234949Sbapt } 1042234949Sbapt upper(s); 1043234949Sbapt c = lookup(ctab, s); 1044234949Sbapt if (c == (struct tab *)0) { 1045234949Sbapt reply(502, "Unknown command %s.", s); 1046234949Sbapt return; 1047234949Sbapt } 1048234949Sbapt if (c->implemented) 1049234949Sbapt reply(214, "Syntax: %s%s %s", help_type, c->name, c->help); 1050234949Sbapt else 1051234949Sbapt reply(214, "%s%-*s\t%s; unimplemented.", help_type, width, 1052234949Sbapt c->name, c->help); 1053234949Sbapt} 1054234949Sbapt 1055234949Sbaptstatic void 1056234949Sbaptsizecmd(char *filename) 1057234949Sbapt{ 1058234949Sbapt switch (type) { 1059234949Sbapt case TYPE_L: 1060234949Sbapt case TYPE_I: { 1061234949Sbapt struct stat stbuf; 1062234949Sbapt if (stat(filename, &stbuf) < 0 || 1063234949Sbapt (stbuf.st_mode&S_IFMT) != S_IFREG) 1064234949Sbapt reply(550, "%s: not a plain file.", filename); 1065234949Sbapt else 1066234949Sbapt#ifdef HAVE_LONG_LONG 1067234949Sbapt reply(213, "%llu", (long long) stbuf.st_size); 1068234949Sbapt#else 1069234949Sbapt reply(213, "%lu", stbuf.st_size); 1070234949Sbapt#endif 1071234949Sbapt break;} 1072234949Sbapt case TYPE_A: { 1073234949Sbapt FILE *fin; 1074234949Sbapt register int c, count; 1075234949Sbapt struct stat stbuf; 1076234949Sbapt fin = fopen(filename, "r"); 1077234949Sbapt if (fin == 0) { 1078234949Sbapt perror_reply(550, filename); 1079234949Sbapt return; 1080234949Sbapt } 1081234949Sbapt if (fstat(fileno(fin), &stbuf) < 0 || 1082234949Sbapt (stbuf.st_mode&S_IFMT) != S_IFREG) { 1083234949Sbapt reply(550, "%s: not a plain file.", filename); 1084234949Sbapt (void) fclose(fin); 1085234949Sbapt return; 1086234949Sbapt } 1087234949Sbapt 1088234949Sbapt count = 0; 1089234949Sbapt while((c=getc(fin)) != EOF) { 1090234949Sbapt if (c == '\n') /* will get expanded to \r\n */ 1091234949Sbapt count++; 1092234949Sbapt count++; 1093234949Sbapt } 1094234949Sbapt (void) fclose(fin); 1095234949Sbapt 1096234949Sbapt reply(213, "%ld", count); 1097234949Sbapt break;} 1098234949Sbapt default: 1099234949Sbapt reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]); 1100234949Sbapt } 1101234949Sbapt} 1102251143Sbapt#line 1103 "ftp.tab.c" 1103234949Sbapt 1104234949Sbapt#if YYDEBUG 1105234949Sbapt#include <stdio.h> /* needed for printf */ 1106234949Sbapt#endif 1107234949Sbapt 1108234949Sbapt#include <stdlib.h> /* needed for malloc, etc */ 1109234949Sbapt#include <string.h> /* needed for memset */ 1110234949Sbapt 1111234949Sbapt/* allocate initial stack or double stack size, up to YYMAXDEPTH */ 1112234949Sbaptstatic int yygrowstack(YYSTACKDATA *data) 1113234949Sbapt{ 1114234949Sbapt int i; 1115234949Sbapt unsigned newsize; 1116234949Sbapt short *newss; 1117234949Sbapt YYSTYPE *newvs; 1118234949Sbapt 1119234949Sbapt if ((newsize = data->stacksize) == 0) 1120234949Sbapt newsize = YYINITSTACKSIZE; 1121234949Sbapt else if (newsize >= YYMAXDEPTH) 1122234949Sbapt return -1; 1123234949Sbapt else if ((newsize *= 2) > YYMAXDEPTH) 1124234949Sbapt newsize = YYMAXDEPTH; 1125234949Sbapt 1126251143Sbapt i = (int) (data->s_mark - data->s_base); 1127234949Sbapt newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); 1128234949Sbapt if (newss == 0) 1129234949Sbapt return -1; 1130234949Sbapt 1131234949Sbapt data->s_base = newss; 1132234949Sbapt data->s_mark = newss + i; 1133234949Sbapt 1134234949Sbapt newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); 1135234949Sbapt if (newvs == 0) 1136234949Sbapt return -1; 1137234949Sbapt 1138234949Sbapt data->l_base = newvs; 1139234949Sbapt data->l_mark = newvs + i; 1140234949Sbapt 1141234949Sbapt data->stacksize = newsize; 1142234949Sbapt data->s_last = data->s_base + newsize - 1; 1143234949Sbapt return 0; 1144234949Sbapt} 1145234949Sbapt 1146234949Sbapt#if YYPURE || defined(YY_NO_LEAKS) 1147234949Sbaptstatic void yyfreestack(YYSTACKDATA *data) 1148234949Sbapt{ 1149234949Sbapt free(data->s_base); 1150234949Sbapt free(data->l_base); 1151234949Sbapt memset(data, 0, sizeof(*data)); 1152234949Sbapt} 1153234949Sbapt#else 1154234949Sbapt#define yyfreestack(data) /* nothing */ 1155234949Sbapt#endif 1156234949Sbapt 1157234949Sbapt#define YYABORT goto yyabort 1158234949Sbapt#define YYREJECT goto yyabort 1159234949Sbapt#define YYACCEPT goto yyaccept 1160234949Sbapt#define YYERROR goto yyerrlab 1161234949Sbapt 1162234949Sbaptint 1163234949SbaptYYPARSE_DECL() 1164234949Sbapt{ 1165234949Sbapt int yym, yyn, yystate; 1166234949Sbapt#if YYDEBUG 1167234949Sbapt const char *yys; 1168234949Sbapt 1169234949Sbapt if ((yys = getenv("YYDEBUG")) != 0) 1170234949Sbapt { 1171234949Sbapt yyn = *yys; 1172234949Sbapt if (yyn >= '0' && yyn <= '9') 1173234949Sbapt yydebug = yyn - '0'; 1174234949Sbapt } 1175234949Sbapt#endif 1176234949Sbapt 1177234949Sbapt yynerrs = 0; 1178234949Sbapt yyerrflag = 0; 1179234949Sbapt yychar = YYEMPTY; 1180234949Sbapt yystate = 0; 1181234949Sbapt 1182234949Sbapt#if YYPURE 1183234949Sbapt memset(&yystack, 0, sizeof(yystack)); 1184234949Sbapt#endif 1185234949Sbapt 1186234949Sbapt if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow; 1187234949Sbapt yystack.s_mark = yystack.s_base; 1188234949Sbapt yystack.l_mark = yystack.l_base; 1189234949Sbapt yystate = 0; 1190234949Sbapt *yystack.s_mark = 0; 1191234949Sbapt 1192234949Sbaptyyloop: 1193234949Sbapt if ((yyn = yydefred[yystate]) != 0) goto yyreduce; 1194234949Sbapt if (yychar < 0) 1195234949Sbapt { 1196234949Sbapt if ((yychar = YYLEX) < 0) yychar = 0; 1197234949Sbapt#if YYDEBUG 1198234949Sbapt if (yydebug) 1199234949Sbapt { 1200234949Sbapt yys = 0; 1201234949Sbapt if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; 1202234949Sbapt if (!yys) yys = "illegal-symbol"; 1203234949Sbapt printf("%sdebug: state %d, reading %d (%s)\n", 1204234949Sbapt YYPREFIX, yystate, yychar, yys); 1205234949Sbapt } 1206234949Sbapt#endif 1207234949Sbapt } 1208234949Sbapt if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && 1209234949Sbapt yyn <= YYTABLESIZE && yycheck[yyn] == yychar) 1210234949Sbapt { 1211234949Sbapt#if YYDEBUG 1212234949Sbapt if (yydebug) 1213234949Sbapt printf("%sdebug: state %d, shifting to state %d\n", 1214234949Sbapt YYPREFIX, yystate, yytable[yyn]); 1215234949Sbapt#endif 1216234949Sbapt if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) 1217234949Sbapt { 1218234949Sbapt goto yyoverflow; 1219234949Sbapt } 1220234949Sbapt yystate = yytable[yyn]; 1221234949Sbapt *++yystack.s_mark = yytable[yyn]; 1222234949Sbapt *++yystack.l_mark = yylval; 1223234949Sbapt yychar = YYEMPTY; 1224234949Sbapt if (yyerrflag > 0) --yyerrflag; 1225234949Sbapt goto yyloop; 1226234949Sbapt } 1227234949Sbapt if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && 1228234949Sbapt yyn <= YYTABLESIZE && yycheck[yyn] == yychar) 1229234949Sbapt { 1230234949Sbapt yyn = yytable[yyn]; 1231234949Sbapt goto yyreduce; 1232234949Sbapt } 1233234949Sbapt if (yyerrflag) goto yyinrecovery; 1234234949Sbapt 1235234949Sbapt yyerror("syntax error"); 1236234949Sbapt 1237234949Sbapt goto yyerrlab; 1238234949Sbapt 1239234949Sbaptyyerrlab: 1240234949Sbapt ++yynerrs; 1241234949Sbapt 1242234949Sbaptyyinrecovery: 1243234949Sbapt if (yyerrflag < 3) 1244234949Sbapt { 1245234949Sbapt yyerrflag = 3; 1246234949Sbapt for (;;) 1247234949Sbapt { 1248234949Sbapt if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && 1249234949Sbapt yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) 1250234949Sbapt { 1251234949Sbapt#if YYDEBUG 1252234949Sbapt if (yydebug) 1253234949Sbapt printf("%sdebug: state %d, error recovery shifting\ 1254234949Sbapt to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); 1255234949Sbapt#endif 1256234949Sbapt if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) 1257234949Sbapt { 1258234949Sbapt goto yyoverflow; 1259234949Sbapt } 1260234949Sbapt yystate = yytable[yyn]; 1261234949Sbapt *++yystack.s_mark = yytable[yyn]; 1262234949Sbapt *++yystack.l_mark = yylval; 1263234949Sbapt goto yyloop; 1264234949Sbapt } 1265234949Sbapt else 1266234949Sbapt { 1267234949Sbapt#if YYDEBUG 1268234949Sbapt if (yydebug) 1269234949Sbapt printf("%sdebug: error recovery discarding state %d\n", 1270234949Sbapt YYPREFIX, *yystack.s_mark); 1271234949Sbapt#endif 1272234949Sbapt if (yystack.s_mark <= yystack.s_base) goto yyabort; 1273234949Sbapt --yystack.s_mark; 1274234949Sbapt --yystack.l_mark; 1275234949Sbapt } 1276234949Sbapt } 1277234949Sbapt } 1278234949Sbapt else 1279234949Sbapt { 1280234949Sbapt if (yychar == 0) goto yyabort; 1281234949Sbapt#if YYDEBUG 1282234949Sbapt if (yydebug) 1283234949Sbapt { 1284234949Sbapt yys = 0; 1285234949Sbapt if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; 1286234949Sbapt if (!yys) yys = "illegal-symbol"; 1287234949Sbapt printf("%sdebug: state %d, error recovery discards token %d (%s)\n", 1288234949Sbapt YYPREFIX, yystate, yychar, yys); 1289234949Sbapt } 1290234949Sbapt#endif 1291234949Sbapt yychar = YYEMPTY; 1292234949Sbapt goto yyloop; 1293234949Sbapt } 1294234949Sbapt 1295234949Sbaptyyreduce: 1296234949Sbapt#if YYDEBUG 1297234949Sbapt if (yydebug) 1298234949Sbapt printf("%sdebug: state %d, reducing by rule %d (%s)\n", 1299234949Sbapt YYPREFIX, yystate, yyn, yyrule[yyn]); 1300234949Sbapt#endif 1301234949Sbapt yym = yylen[yyn]; 1302234949Sbapt if (yym) 1303234949Sbapt yyval = yystack.l_mark[1-yym]; 1304234949Sbapt else 1305234949Sbapt memset(&yyval, 0, sizeof yyval); 1306234949Sbapt switch (yyn) 1307234949Sbapt { 1308234949Sbaptcase 2: 1309251143Sbapt#line 172 "ftp.y" 1310234949Sbapt { 1311234949Sbapt fromname = (char *) 0; 1312234949Sbapt } 1313234949Sbaptbreak; 1314234949Sbaptcase 4: 1315251143Sbapt#line 179 "ftp.y" 1316234949Sbapt { 1317251143Sbapt user(yystack.l_mark[-1].sval); 1318251143Sbapt free(yystack.l_mark[-1].sval); 1319234949Sbapt } 1320234949Sbaptbreak; 1321234949Sbaptcase 5: 1322251143Sbapt#line 184 "ftp.y" 1323234949Sbapt { 1324251143Sbapt pass(yystack.l_mark[-1].sval); 1325251143Sbapt free(yystack.l_mark[-1].sval); 1326234949Sbapt } 1327234949Sbaptbreak; 1328234949Sbaptcase 6: 1329251143Sbapt#line 189 "ftp.y" 1330234949Sbapt { 1331234949Sbapt usedefault = 0; 1332234949Sbapt if (pdata >= 0) { 1333234949Sbapt (void) close(pdata); 1334234949Sbapt pdata = -1; 1335234949Sbapt } 1336234949Sbapt reply(200, "PORT command successful."); 1337234949Sbapt } 1338234949Sbaptbreak; 1339234949Sbaptcase 7: 1340251143Sbapt#line 198 "ftp.y" 1341234949Sbapt { 1342234949Sbapt passive(); 1343234949Sbapt } 1344234949Sbaptbreak; 1345234949Sbaptcase 8: 1346251143Sbapt#line 202 "ftp.y" 1347234949Sbapt { 1348234949Sbapt switch (cmd_type) { 1349234949Sbapt 1350234949Sbapt case TYPE_A: 1351234949Sbapt if (cmd_form == FORM_N) { 1352234949Sbapt reply(200, "Type set to A."); 1353234949Sbapt type = cmd_type; 1354234949Sbapt form = cmd_form; 1355234949Sbapt } else 1356234949Sbapt reply(504, "Form must be N."); 1357234949Sbapt break; 1358234949Sbapt 1359234949Sbapt case TYPE_E: 1360234949Sbapt reply(504, "Type E not implemented."); 1361234949Sbapt break; 1362234949Sbapt 1363234949Sbapt case TYPE_I: 1364234949Sbapt reply(200, "Type set to I."); 1365234949Sbapt type = cmd_type; 1366234949Sbapt break; 1367234949Sbapt 1368234949Sbapt case TYPE_L: 1369234949Sbapt#if NBBY == 8 1370234949Sbapt if (cmd_bytesz == 8) { 1371234949Sbapt reply(200, 1372234949Sbapt "Type set to L (byte size 8)."); 1373234949Sbapt type = cmd_type; 1374234949Sbapt } else 1375234949Sbapt reply(504, "Byte size must be 8."); 1376234949Sbapt#else /* NBBY == 8 */ 1377234949Sbapt UNIMPLEMENTED for NBBY != 8 1378234949Sbapt#endif /* NBBY == 8 */ 1379234949Sbapt } 1380234949Sbapt } 1381234949Sbaptbreak; 1382234949Sbaptcase 9: 1383251143Sbapt#line 237 "ftp.y" 1384234949Sbapt { 1385251143Sbapt switch (yystack.l_mark[-1].ival) { 1386234949Sbapt 1387234949Sbapt case STRU_F: 1388234949Sbapt reply(200, "STRU F ok."); 1389234949Sbapt break; 1390234949Sbapt 1391234949Sbapt default: 1392234949Sbapt reply(504, "Unimplemented STRU type."); 1393234949Sbapt } 1394234949Sbapt } 1395234949Sbaptbreak; 1396234949Sbaptcase 10: 1397251143Sbapt#line 249 "ftp.y" 1398234949Sbapt { 1399251143Sbapt switch (yystack.l_mark[-1].ival) { 1400234949Sbapt 1401234949Sbapt case MODE_S: 1402234949Sbapt reply(200, "MODE S ok."); 1403234949Sbapt break; 1404234949Sbapt 1405234949Sbapt default: 1406234949Sbapt reply(502, "Unimplemented MODE type."); 1407234949Sbapt } 1408234949Sbapt } 1409234949Sbaptbreak; 1410234949Sbaptcase 11: 1411251143Sbapt#line 261 "ftp.y" 1412234949Sbapt { 1413234949Sbapt reply(202, "ALLO command ignored."); 1414234949Sbapt } 1415234949Sbaptbreak; 1416234949Sbaptcase 12: 1417251143Sbapt#line 265 "ftp.y" 1418234949Sbapt { 1419234949Sbapt reply(202, "ALLO command ignored."); 1420234949Sbapt } 1421234949Sbaptbreak; 1422234949Sbaptcase 13: 1423251143Sbapt#line 269 "ftp.y" 1424234949Sbapt { 1425251143Sbapt if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0) 1426251143Sbapt retrieve((char *) 0, yystack.l_mark[-1].sval); 1427251143Sbapt if (yystack.l_mark[-1].sval != 0) 1428251143Sbapt free(yystack.l_mark[-1].sval); 1429234949Sbapt } 1430234949Sbaptbreak; 1431234949Sbaptcase 14: 1432251143Sbapt#line 276 "ftp.y" 1433234949Sbapt { 1434251143Sbapt if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0) 1435251143Sbapt store(yystack.l_mark[-1].sval, "w", 0); 1436251143Sbapt if (yystack.l_mark[-1].sval != 0) 1437251143Sbapt free(yystack.l_mark[-1].sval); 1438234949Sbapt } 1439234949Sbaptbreak; 1440234949Sbaptcase 15: 1441251143Sbapt#line 283 "ftp.y" 1442234949Sbapt { 1443251143Sbapt if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0) 1444251143Sbapt store(yystack.l_mark[-1].sval, "a", 0); 1445251143Sbapt if (yystack.l_mark[-1].sval != 0) 1446251143Sbapt free(yystack.l_mark[-1].sval); 1447234949Sbapt } 1448234949Sbaptbreak; 1449234949Sbaptcase 16: 1450251143Sbapt#line 290 "ftp.y" 1451234949Sbapt { 1452251143Sbapt if (yystack.l_mark[-1].ival) 1453234949Sbapt send_file_list("."); 1454234949Sbapt } 1455234949Sbaptbreak; 1456234949Sbaptcase 17: 1457251143Sbapt#line 295 "ftp.y" 1458234949Sbapt { 1459251143Sbapt if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0) 1460251143Sbapt send_file_list((char *) yystack.l_mark[-1].sval); 1461251143Sbapt if (yystack.l_mark[-1].sval != 0) 1462251143Sbapt free((char *) yystack.l_mark[-1].sval); 1463234949Sbapt } 1464234949Sbaptbreak; 1465234949Sbaptcase 18: 1466251143Sbapt#line 302 "ftp.y" 1467234949Sbapt { 1468251143Sbapt if (yystack.l_mark[-1].ival) 1469234949Sbapt retrieve("/bin/ls -lgA", ""); 1470234949Sbapt } 1471234949Sbaptbreak; 1472234949Sbaptcase 19: 1473251143Sbapt#line 307 "ftp.y" 1474234949Sbapt { 1475251143Sbapt if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0) 1476251143Sbapt retrieve("/bin/ls -lgA %s", yystack.l_mark[-1].sval); 1477251143Sbapt if (yystack.l_mark[-1].sval != 0) 1478251143Sbapt free(yystack.l_mark[-1].sval); 1479234949Sbapt } 1480234949Sbaptbreak; 1481234949Sbaptcase 20: 1482251143Sbapt#line 314 "ftp.y" 1483234949Sbapt { 1484251143Sbapt if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0) 1485251143Sbapt statfilecmd(yystack.l_mark[-1].sval); 1486251143Sbapt if (yystack.l_mark[-1].sval != 0) 1487251143Sbapt free(yystack.l_mark[-1].sval); 1488234949Sbapt } 1489234949Sbaptbreak; 1490234949Sbaptcase 21: 1491251143Sbapt#line 321 "ftp.y" 1492234949Sbapt { 1493234949Sbapt statcmd(); 1494234949Sbapt } 1495234949Sbaptbreak; 1496234949Sbaptcase 22: 1497251143Sbapt#line 325 "ftp.y" 1498234949Sbapt { 1499251143Sbapt if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0) 1500251143Sbapt remove((char *) yystack.l_mark[-1].sval); 1501251143Sbapt if (yystack.l_mark[-1].sval != 0) 1502251143Sbapt free((char *) yystack.l_mark[-1].sval); 1503234949Sbapt } 1504234949Sbaptbreak; 1505234949Sbaptcase 23: 1506251143Sbapt#line 332 "ftp.y" 1507234949Sbapt { 1508234949Sbapt if (fromname) { 1509251143Sbapt renamecmd(fromname, (char *) yystack.l_mark[-1].sval); 1510234949Sbapt free(fromname); 1511234949Sbapt fromname = (char *) 0; 1512234949Sbapt } else { 1513234949Sbapt reply(503, "Bad sequence of commands."); 1514234949Sbapt } 1515251143Sbapt free((char *) yystack.l_mark[-1].sval); 1516234949Sbapt } 1517234949Sbaptbreak; 1518234949Sbaptcase 24: 1519251143Sbapt#line 343 "ftp.y" 1520234949Sbapt { 1521234949Sbapt reply(225, "ABOR command successful."); 1522234949Sbapt } 1523234949Sbaptbreak; 1524234949Sbaptcase 25: 1525251143Sbapt#line 347 "ftp.y" 1526234949Sbapt { 1527251143Sbapt if (yystack.l_mark[-1].ival) 1528234949Sbapt cwd(pw->pw_dir); 1529234949Sbapt } 1530234949Sbaptbreak; 1531234949Sbaptcase 26: 1532251143Sbapt#line 352 "ftp.y" 1533234949Sbapt { 1534251143Sbapt if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0) 1535251143Sbapt cwd((char *) yystack.l_mark[-1].sval); 1536251143Sbapt if (yystack.l_mark[-1].sval != 0) 1537251143Sbapt free((char *) yystack.l_mark[-1].sval); 1538234949Sbapt } 1539234949Sbaptbreak; 1540234949Sbaptcase 27: 1541251143Sbapt#line 359 "ftp.y" 1542234949Sbapt { 1543234949Sbapt help(cmdtab, (char *) 0); 1544234949Sbapt } 1545234949Sbaptbreak; 1546234949Sbaptcase 28: 1547251143Sbapt#line 363 "ftp.y" 1548234949Sbapt { 1549251143Sbapt register char *cp = (char *)yystack.l_mark[-1].sval; 1550234949Sbapt 1551234949Sbapt if (strncasecmp(cp, "SITE", 4) == 0) { 1552251143Sbapt cp = (char *)yystack.l_mark[-1].sval + 4; 1553234949Sbapt if (*cp == ' ') 1554234949Sbapt cp++; 1555234949Sbapt if (*cp) 1556234949Sbapt help(sitetab, cp); 1557234949Sbapt else 1558234949Sbapt help(sitetab, (char *) 0); 1559234949Sbapt } else 1560251143Sbapt help(cmdtab, (char *) yystack.l_mark[-1].sval); 1561234949Sbapt } 1562234949Sbaptbreak; 1563234949Sbaptcase 29: 1564251143Sbapt#line 378 "ftp.y" 1565234949Sbapt { 1566234949Sbapt reply(200, "NOOP command successful."); 1567234949Sbapt } 1568234949Sbaptbreak; 1569234949Sbaptcase 30: 1570251143Sbapt#line 382 "ftp.y" 1571234949Sbapt { 1572251143Sbapt if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0) 1573251143Sbapt makedir((char *) yystack.l_mark[-1].sval); 1574251143Sbapt if (yystack.l_mark[-1].sval != 0) 1575251143Sbapt free((char *) yystack.l_mark[-1].sval); 1576234949Sbapt } 1577234949Sbaptbreak; 1578234949Sbaptcase 31: 1579251143Sbapt#line 389 "ftp.y" 1580234949Sbapt { 1581251143Sbapt if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0) 1582251143Sbapt removedir((char *) yystack.l_mark[-1].sval); 1583251143Sbapt if (yystack.l_mark[-1].sval != 0) 1584251143Sbapt free((char *) yystack.l_mark[-1].sval); 1585234949Sbapt } 1586234949Sbaptbreak; 1587234949Sbaptcase 32: 1588251143Sbapt#line 396 "ftp.y" 1589234949Sbapt { 1590251143Sbapt if (yystack.l_mark[-1].ival) 1591234949Sbapt pwd(); 1592234949Sbapt } 1593234949Sbaptbreak; 1594234949Sbaptcase 33: 1595251143Sbapt#line 401 "ftp.y" 1596234949Sbapt { 1597251143Sbapt if (yystack.l_mark[-1].ival) 1598234949Sbapt cwd(".."); 1599234949Sbapt } 1600234949Sbaptbreak; 1601234949Sbaptcase 34: 1602251143Sbapt#line 406 "ftp.y" 1603234949Sbapt { 1604234949Sbapt help(sitetab, (char *) 0); 1605234949Sbapt } 1606234949Sbaptbreak; 1607234949Sbaptcase 35: 1608251143Sbapt#line 410 "ftp.y" 1609234949Sbapt { 1610251143Sbapt help(sitetab, (char *) yystack.l_mark[-1].sval); 1611234949Sbapt } 1612234949Sbaptbreak; 1613234949Sbaptcase 36: 1614251143Sbapt#line 414 "ftp.y" 1615234949Sbapt { 1616234949Sbapt int oldmask; 1617234949Sbapt 1618251143Sbapt if (yystack.l_mark[-1].ival) { 1619234949Sbapt oldmask = umask(0); 1620234949Sbapt (void) umask(oldmask); 1621234949Sbapt reply(200, "Current UMASK is %03o", oldmask); 1622234949Sbapt } 1623234949Sbapt } 1624234949Sbaptbreak; 1625234949Sbaptcase 37: 1626251143Sbapt#line 424 "ftp.y" 1627234949Sbapt { 1628234949Sbapt int oldmask; 1629234949Sbapt 1630251143Sbapt if (yystack.l_mark[-3].ival) { 1631251143Sbapt if ((yystack.l_mark[-1].ival == -1) || (yystack.l_mark[-1].ival > 0777)) { 1632234949Sbapt reply(501, "Bad UMASK value"); 1633234949Sbapt } else { 1634251143Sbapt oldmask = umask(yystack.l_mark[-1].ival); 1635234949Sbapt reply(200, 1636234949Sbapt "UMASK set to %03o (was %03o)", 1637251143Sbapt yystack.l_mark[-1].ival, oldmask); 1638234949Sbapt } 1639234949Sbapt } 1640234949Sbapt } 1641234949Sbaptbreak; 1642234949Sbaptcase 38: 1643251143Sbapt#line 439 "ftp.y" 1644234949Sbapt { 1645251143Sbapt if (yystack.l_mark[-5].ival && (yystack.l_mark[-1].sval != 0)) { 1646251143Sbapt if (yystack.l_mark[-3].ival > 0777) 1647234949Sbapt reply(501, 1648234949Sbapt "CHMOD: Mode value must be between 0 and 0777"); 1649251143Sbapt else if (chmod((char *) yystack.l_mark[-1].sval, yystack.l_mark[-3].ival) < 0) 1650251143Sbapt perror_reply(550, (char *) yystack.l_mark[-1].sval); 1651234949Sbapt else 1652234949Sbapt reply(200, "CHMOD command successful."); 1653234949Sbapt } 1654251143Sbapt if (yystack.l_mark[-1].sval != 0) 1655251143Sbapt free((char *) yystack.l_mark[-1].sval); 1656234949Sbapt } 1657234949Sbaptbreak; 1658234949Sbaptcase 39: 1659251143Sbapt#line 453 "ftp.y" 1660234949Sbapt { 1661234949Sbapt reply(200, 1662234949Sbapt "Current IDLE time limit is %d seconds; max %d", 1663234949Sbapt timeout, maxtimeout); 1664234949Sbapt } 1665234949Sbaptbreak; 1666234949Sbaptcase 40: 1667251143Sbapt#line 459 "ftp.y" 1668234949Sbapt { 1669251143Sbapt if (yystack.l_mark[-1].ival < 30 || yystack.l_mark[-1].ival > maxtimeout) { 1670234949Sbapt reply(501, 1671234949Sbapt "Maximum IDLE time must be between 30 and %d seconds", 1672234949Sbapt maxtimeout); 1673234949Sbapt } else { 1674251143Sbapt timeout = yystack.l_mark[-1].ival; 1675234949Sbapt (void) alarm((unsigned) timeout); 1676234949Sbapt reply(200, 1677234949Sbapt "Maximum IDLE time set to %d seconds", 1678234949Sbapt timeout); 1679234949Sbapt } 1680234949Sbapt } 1681234949Sbaptbreak; 1682234949Sbaptcase 41: 1683251143Sbapt#line 473 "ftp.y" 1684234949Sbapt { 1685251143Sbapt if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0) 1686251143Sbapt store((char *) yystack.l_mark[-1].sval, "w", 1); 1687251143Sbapt if (yystack.l_mark[-1].sval != 0) 1688251143Sbapt free((char *) yystack.l_mark[-1].sval); 1689234949Sbapt } 1690234949Sbaptbreak; 1691234949Sbaptcase 42: 1692251143Sbapt#line 480 "ftp.y" 1693234949Sbapt { 1694234949Sbapt#ifdef unix 1695234949Sbapt#ifdef BSD 1696234949Sbapt reply(215, "UNIX Type: L%d Version: BSD-%d", 1697234949Sbapt NBBY, BSD); 1698234949Sbapt#else /* BSD */ 1699234949Sbapt reply(215, "UNIX Type: L%d", NBBY); 1700234949Sbapt#endif /* BSD */ 1701234949Sbapt#else /* unix */ 1702234949Sbapt reply(215, "UNKNOWN Type: L%d", NBBY); 1703234949Sbapt#endif /* unix */ 1704234949Sbapt } 1705234949Sbaptbreak; 1706234949Sbaptcase 43: 1707251143Sbapt#line 501 "ftp.y" 1708234949Sbapt { 1709251143Sbapt if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0) 1710251143Sbapt sizecmd((char *) yystack.l_mark[-1].sval); 1711251143Sbapt if (yystack.l_mark[-1].sval != 0) 1712251143Sbapt free((char *) yystack.l_mark[-1].sval); 1713234949Sbapt } 1714234949Sbaptbreak; 1715234949Sbaptcase 44: 1716251143Sbapt#line 518 "ftp.y" 1717234949Sbapt { 1718251143Sbapt if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval != 0) { 1719234949Sbapt struct stat stbuf; 1720251143Sbapt if (stat((char *) yystack.l_mark[-1].sval, &stbuf) < 0) 1721251143Sbapt perror_reply(550, "%s", (char *) yystack.l_mark[-1].sval); 1722234949Sbapt else if ((stbuf.st_mode&S_IFMT) != S_IFREG) { 1723234949Sbapt reply(550, "%s: not a plain file.", 1724251143Sbapt (char *) yystack.l_mark[-1].sval); 1725234949Sbapt } else { 1726234949Sbapt register struct tm *t; 1727234949Sbapt t = gmtime(&stbuf.st_mtime); 1728234949Sbapt reply(213, 1729234949Sbapt "%04d%02d%02d%02d%02d%02d", 1730234949Sbapt 1900 + t->tm_year, 1731234949Sbapt t->tm_mon+1, t->tm_mday, 1732234949Sbapt t->tm_hour, t->tm_min, t->tm_sec); 1733234949Sbapt } 1734234949Sbapt } 1735251143Sbapt if (yystack.l_mark[-1].sval != 0) 1736251143Sbapt free((char *) yystack.l_mark[-1].sval); 1737234949Sbapt } 1738234949Sbaptbreak; 1739234949Sbaptcase 45: 1740251143Sbapt#line 540 "ftp.y" 1741234949Sbapt { 1742234949Sbapt reply(221, "Goodbye."); 1743234949Sbapt dologout(0); 1744234949Sbapt } 1745234949Sbaptbreak; 1746234949Sbaptcase 46: 1747251143Sbapt#line 545 "ftp.y" 1748234949Sbapt { 1749234949Sbapt yyerrok; 1750234949Sbapt } 1751234949Sbaptbreak; 1752234949Sbaptcase 47: 1753251143Sbapt#line 550 "ftp.y" 1754234949Sbapt { 1755251143Sbapt if (yystack.l_mark[-3].ival && yystack.l_mark[-1].sval) { 1756251143Sbapt fromname = renamefrom((char *) yystack.l_mark[-1].sval); 1757251143Sbapt if (fromname == (char *) 0 && yystack.l_mark[-1].sval) { 1758251143Sbapt free((char *) yystack.l_mark[-1].sval); 1759234949Sbapt } 1760234949Sbapt } 1761234949Sbapt } 1762234949Sbaptbreak; 1763234949Sbaptcase 49: 1764251143Sbapt#line 564 "ftp.y" 1765234949Sbapt { 1766251143Sbapt *(const char **)(&(yyval.sval)) = ""; 1767234949Sbapt } 1768234949Sbaptbreak; 1769234949Sbaptcase 52: 1770251143Sbapt#line 575 "ftp.y" 1771234949Sbapt { 1772234949Sbapt register char *a, *p; 1773234949Sbapt 1774234949Sbapt a = (char *)&data_dest.sin_addr; 1775251143Sbapt a[0] = (char) yystack.l_mark[-10].ival; 1776251143Sbapt a[1] = (char) yystack.l_mark[-8].ival; 1777251143Sbapt a[2] = (char) yystack.l_mark[-6].ival; 1778251143Sbapt a[3] = (char) yystack.l_mark[-4].ival; 1779234949Sbapt p = (char *)&data_dest.sin_port; 1780251143Sbapt p[0] = (char) yystack.l_mark[-2].ival; 1781251143Sbapt p[1] = (char) yystack.l_mark[0].ival; 1782234949Sbapt data_dest.sin_family = AF_INET; 1783234949Sbapt } 1784234949Sbaptbreak; 1785234949Sbaptcase 53: 1786251143Sbapt#line 591 "ftp.y" 1787234949Sbapt { 1788251143Sbapt yyval.ival = FORM_N; 1789234949Sbapt } 1790234949Sbaptbreak; 1791234949Sbaptcase 54: 1792251143Sbapt#line 595 "ftp.y" 1793234949Sbapt { 1794251143Sbapt yyval.ival = FORM_T; 1795234949Sbapt } 1796234949Sbaptbreak; 1797234949Sbaptcase 55: 1798251143Sbapt#line 599 "ftp.y" 1799234949Sbapt { 1800251143Sbapt yyval.ival = FORM_C; 1801234949Sbapt } 1802234949Sbaptbreak; 1803234949Sbaptcase 56: 1804251143Sbapt#line 605 "ftp.y" 1805234949Sbapt { 1806234949Sbapt cmd_type = TYPE_A; 1807234949Sbapt cmd_form = FORM_N; 1808234949Sbapt } 1809234949Sbaptbreak; 1810234949Sbaptcase 57: 1811251143Sbapt#line 610 "ftp.y" 1812234949Sbapt { 1813234949Sbapt cmd_type = TYPE_A; 1814251143Sbapt cmd_form = yystack.l_mark[0].ival; 1815234949Sbapt } 1816234949Sbaptbreak; 1817234949Sbaptcase 58: 1818251143Sbapt#line 615 "ftp.y" 1819234949Sbapt { 1820234949Sbapt cmd_type = TYPE_E; 1821234949Sbapt cmd_form = FORM_N; 1822234949Sbapt } 1823234949Sbaptbreak; 1824234949Sbaptcase 59: 1825251143Sbapt#line 620 "ftp.y" 1826234949Sbapt { 1827234949Sbapt cmd_type = TYPE_E; 1828251143Sbapt cmd_form = yystack.l_mark[0].ival; 1829234949Sbapt } 1830234949Sbaptbreak; 1831234949Sbaptcase 60: 1832251143Sbapt#line 625 "ftp.y" 1833234949Sbapt { 1834234949Sbapt cmd_type = TYPE_I; 1835234949Sbapt } 1836234949Sbaptbreak; 1837234949Sbaptcase 61: 1838251143Sbapt#line 629 "ftp.y" 1839234949Sbapt { 1840234949Sbapt cmd_type = TYPE_L; 1841234949Sbapt cmd_bytesz = NBBY; 1842234949Sbapt } 1843234949Sbaptbreak; 1844234949Sbaptcase 62: 1845251143Sbapt#line 634 "ftp.y" 1846234949Sbapt { 1847234949Sbapt cmd_type = TYPE_L; 1848251143Sbapt cmd_bytesz = yystack.l_mark[0].ival; 1849234949Sbapt } 1850234949Sbaptbreak; 1851234949Sbaptcase 63: 1852251143Sbapt#line 640 "ftp.y" 1853234949Sbapt { 1854234949Sbapt cmd_type = TYPE_L; 1855251143Sbapt cmd_bytesz = yystack.l_mark[0].ival; 1856234949Sbapt } 1857234949Sbaptbreak; 1858234949Sbaptcase 64: 1859251143Sbapt#line 647 "ftp.y" 1860234949Sbapt { 1861251143Sbapt yyval.ival = STRU_F; 1862234949Sbapt } 1863234949Sbaptbreak; 1864234949Sbaptcase 65: 1865251143Sbapt#line 651 "ftp.y" 1866234949Sbapt { 1867251143Sbapt yyval.ival = STRU_R; 1868234949Sbapt } 1869234949Sbaptbreak; 1870234949Sbaptcase 66: 1871251143Sbapt#line 655 "ftp.y" 1872234949Sbapt { 1873251143Sbapt yyval.ival = STRU_P; 1874234949Sbapt } 1875234949Sbaptbreak; 1876234949Sbaptcase 67: 1877251143Sbapt#line 661 "ftp.y" 1878234949Sbapt { 1879251143Sbapt yyval.ival = MODE_S; 1880234949Sbapt } 1881234949Sbaptbreak; 1882234949Sbaptcase 68: 1883251143Sbapt#line 665 "ftp.y" 1884234949Sbapt { 1885251143Sbapt yyval.ival = MODE_B; 1886234949Sbapt } 1887234949Sbaptbreak; 1888234949Sbaptcase 69: 1889251143Sbapt#line 669 "ftp.y" 1890234949Sbapt { 1891251143Sbapt yyval.ival = MODE_C; 1892234949Sbapt } 1893234949Sbaptbreak; 1894234949Sbaptcase 70: 1895251143Sbapt#line 675 "ftp.y" 1896234949Sbapt { 1897234949Sbapt /* 1898234949Sbapt * Problem: this production is used for all pathname 1899234949Sbapt * processing, but only gives a 550 error reply. 1900234949Sbapt * This is a valid reply in some cases but not in others. 1901234949Sbapt */ 1902251143Sbapt if (logged_in && yystack.l_mark[0].sval && strncmp((char *) yystack.l_mark[0].sval, "~", 1) == 0) { 1903251143Sbapt *(char **)&(yyval.sval) = *glob((char *) yystack.l_mark[0].sval); 1904234949Sbapt if (globerr != 0) { 1905234949Sbapt reply(550, globerr); 1906251143Sbapt yyval.sval = 0; 1907234949Sbapt } 1908251143Sbapt free((char *) yystack.l_mark[0].sval); 1909234949Sbapt } else 1910251143Sbapt yyval.sval = yystack.l_mark[0].sval; 1911234949Sbapt } 1912234949Sbaptbreak; 1913234949Sbaptcase 72: 1914251143Sbapt#line 697 "ftp.y" 1915234949Sbapt { 1916234949Sbapt register int ret, dec, multby, digit; 1917234949Sbapt 1918234949Sbapt /* 1919234949Sbapt * Convert a number that was read as decimal number 1920234949Sbapt * to what it would be if it had been read as octal. 1921234949Sbapt */ 1922251143Sbapt dec = yystack.l_mark[0].ival; 1923234949Sbapt multby = 1; 1924234949Sbapt ret = 0; 1925234949Sbapt while (dec) { 1926234949Sbapt digit = dec%10; 1927234949Sbapt if (digit > 7) { 1928234949Sbapt ret = -1; 1929234949Sbapt break; 1930234949Sbapt } 1931234949Sbapt ret += digit * multby; 1932234949Sbapt multby *= 8; 1933234949Sbapt dec /= 10; 1934234949Sbapt } 1935251143Sbapt yyval.ival = ret; 1936234949Sbapt } 1937234949Sbaptbreak; 1938234949Sbaptcase 73: 1939251143Sbapt#line 722 "ftp.y" 1940234949Sbapt { 1941234949Sbapt if (logged_in) 1942251143Sbapt yyval.ival = 1; 1943234949Sbapt else { 1944234949Sbapt reply(530, "Please login with USER and PASS."); 1945251143Sbapt yyval.ival = 0; 1946234949Sbapt } 1947234949Sbapt } 1948234949Sbaptbreak; 1949251143Sbapt#line 1950 "ftp.tab.c" 1950234949Sbapt } 1951234949Sbapt yystack.s_mark -= yym; 1952234949Sbapt yystate = *yystack.s_mark; 1953234949Sbapt yystack.l_mark -= yym; 1954234949Sbapt yym = yylhs[yyn]; 1955234949Sbapt if (yystate == 0 && yym == 0) 1956234949Sbapt { 1957234949Sbapt#if YYDEBUG 1958234949Sbapt if (yydebug) 1959234949Sbapt printf("%sdebug: after reduction, shifting from state 0 to\ 1960234949Sbapt state %d\n", YYPREFIX, YYFINAL); 1961234949Sbapt#endif 1962234949Sbapt yystate = YYFINAL; 1963234949Sbapt *++yystack.s_mark = YYFINAL; 1964234949Sbapt *++yystack.l_mark = yyval; 1965234949Sbapt if (yychar < 0) 1966234949Sbapt { 1967234949Sbapt if ((yychar = YYLEX) < 0) yychar = 0; 1968234949Sbapt#if YYDEBUG 1969234949Sbapt if (yydebug) 1970234949Sbapt { 1971234949Sbapt yys = 0; 1972234949Sbapt if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; 1973234949Sbapt if (!yys) yys = "illegal-symbol"; 1974234949Sbapt printf("%sdebug: state %d, reading %d (%s)\n", 1975234949Sbapt YYPREFIX, YYFINAL, yychar, yys); 1976234949Sbapt } 1977234949Sbapt#endif 1978234949Sbapt } 1979234949Sbapt if (yychar == 0) goto yyaccept; 1980234949Sbapt goto yyloop; 1981234949Sbapt } 1982234949Sbapt if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && 1983234949Sbapt yyn <= YYTABLESIZE && yycheck[yyn] == yystate) 1984234949Sbapt yystate = yytable[yyn]; 1985234949Sbapt else 1986234949Sbapt yystate = yydgoto[yym]; 1987234949Sbapt#if YYDEBUG 1988234949Sbapt if (yydebug) 1989234949Sbapt printf("%sdebug: after reduction, shifting from state %d \ 1990234949Sbaptto state %d\n", YYPREFIX, *yystack.s_mark, yystate); 1991234949Sbapt#endif 1992234949Sbapt if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack)) 1993234949Sbapt { 1994234949Sbapt goto yyoverflow; 1995234949Sbapt } 1996234949Sbapt *++yystack.s_mark = (short) yystate; 1997234949Sbapt *++yystack.l_mark = yyval; 1998234949Sbapt goto yyloop; 1999234949Sbapt 2000234949Sbaptyyoverflow: 2001234949Sbapt yyerror("yacc stack overflow"); 2002234949Sbapt 2003234949Sbaptyyabort: 2004234949Sbapt yyfreestack(&yystack); 2005234949Sbapt return (1); 2006234949Sbapt 2007234949Sbaptyyaccept: 2008234949Sbapt yyfreestack(&yystack); 2009234949Sbapt return (0); 2010234949Sbapt} 2011