⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftpcmd.y

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 Y
📖 第 1 页 / 共 2 页
字号:
/************************************************************************ *									* *			Copyright (c) 1984,1988 by			* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any  other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   This software is  derived  from  software  received  from  the	* *   University    of   California,   Berkeley,   and   from   Bell	* *   Laboratories.  Use, duplication, or disclosure is  subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or  reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************//* * Copyright (c) 1985 Regents of the University of California. * All rights reserved.  The Berkeley software License Agreement * specifies the terms and conditions for redistribution. *//* * Grammar for FTP commands. * See RFC 765. */%{/*#ifndef lintstatic	char sccsid[] = "ftpcmd.y	5.9 (Berkeley) 5/15/87";#endif*/#ifndef lintstatic	char sccsid[] = "@(#)ftpcmd.y	4.1	(ULTRIX)	7/2/90";#endif#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/ftp.h>#include <stdio.h>#include <signal.h>#include <ctype.h>#include <pwd.h>#include <setjmp.h>#include <syslog.h>extern	struct sockaddr_in data_dest;extern	int logged_in;extern	struct passwd *pw;extern	int guest;extern	int logging;extern	int type;extern	int form;extern	int debug;extern	int timeout;extern  int pdata;extern	char hostname[];extern	char *globerr;extern	int usedefault;extern	int unique;extern  int transflag;extern  char tmpline[];char	**glob();static	int cmd_type;static	int cmd_form;static	int cmd_bytesz;char cbuf[512];char *fromname;char	*index();%}%token	A	B	C	E	F	I	L	N	P	R	S	T	SP	CRLF	COMMA	STRING	NUMBER	USER	PASS	ACCT	REIN	QUIT	PORT	PASV	TYPE	STRU	MODE	RETR	STOR	APPE	MLFL	MAIL	MSND	MSOM	MSAM	MRSQ	MRCP	ALLO	REST	RNFR	RNTO	ABOR	DELE	CWD	LIST	NLST	SITE	STAT	HELP	NOOP	XMKD	XRMD	XPWD	XCUP	STOU	LEXERR%start	cmd_list%%cmd_list:	/* empty */	|	cmd_list cmd		= {			fromname = (char *) 0;		}	|	cmd_list rcmd	;cmd:		USER SP username CRLF		= {			extern struct passwd *sgetpwnam();			logged_in = 0;			if (strcmp((char *) $3, "ftp") == 0 ||			  strcmp((char *) $3, "anonymous") == 0) {				if ((pw = sgetpwnam("ftp")) != NULL) {					guest = 1;					reply(331,				  "Guest login ok, send ident as password.");				}				else {					reply(530, "User %s unknown.", $3);				}			} else if (checkuser((char *) $3)) {				guest = 0;				pw = sgetpwnam((char *) $3);				if (pw == NULL) {					reply(530, "User %s unknown.", $3);				}				else {				    reply(331, "Password required for %s.", $3);				}			} else {				reply(530, "User %s access denied.", $3);			}			free((char *) $3);		}	|	PASS SP password CRLF		= {			pass((char *) $3);			free((char *) $3);		}	|	PORT SP host_port CRLF		= {			usedefault = 0;			if (pdata > 0) {				(void) close(pdata);			}			pdata = -1;			reply(200, "PORT command successful.");		}	|	PASV CRLF		= {			passive();		}	|	TYPE SP type_code CRLF		= {			switch (cmd_type) {			case TYPE_A:				if (cmd_form == FORM_N) {					reply(200, "Type set to A.");					type = cmd_type;					form = cmd_form;				} else					reply(504, "Form must be N.");				break;			case TYPE_E:				reply(504, "Type E not implemented.");				break;			case TYPE_I:				reply(200, "Type set to I.");				type = cmd_type;				break;			case TYPE_L:				if (cmd_bytesz == 8) {					reply(200,					    "Type set to L (byte size 8).");					type = cmd_type;				} else					reply(504, "Byte size must be 8.");			}		}	|	STRU SP struct_code CRLF		= {			switch ($3) {			case STRU_F:				reply(200, "STRU F ok.");				break;			default:				reply(504, "Unimplemented STRU type.");			}		}	|	MODE SP mode_code CRLF		= {			switch ($3) {			case MODE_S:				reply(200, "MODE S ok.");				break;			default:				reply(502, "Unimplemented MODE type.");			}		}	|	ALLO SP NUMBER CRLF		= {			reply(202, "ALLO command ignored.");		}	|	RETR check_login SP pathname CRLF		= {			if ($2 && $4 != NULL)				retrieve((char *) 0, (char *) $4);			if ($4 != NULL)				free((char *) $4);		}	|	STOR check_login SP pathname CRLF		= {			if ($2 && $4 != NULL)				store((char *) $4, "w");			if ($4 != NULL)				free((char *) $4);		}	|	APPE check_login SP pathname CRLF		= {			if ($2 && $4 != NULL)				store((char *) $4, "a");			if ($4 != NULL)				free((char *) $4);		}	|	NLST check_login CRLF		= {			if ($2)				retrieve("/bin/ls", "");		}	|	NLST check_login SP pathname CRLF		= {			if ($2 && $4 != NULL)				retrieve("/bin/ls %s", (char *) $4);			if ($4 != NULL)				free((char *) $4);		}	|	LIST check_login CRLF		= {			if ($2)				retrieve("/bin/ls -lg", "");		}	|	LIST check_login SP pathname CRLF		= {			if ($2 && $4 != NULL)				retrieve("/bin/ls -lg %s", (char *) $4);			if ($4 != NULL)				free((char *) $4);		}	|	DELE check_login SP pathname CRLF		= {			if ($2 && $4 != NULL)				delete((char *) $4);			if ($4 != NULL)				free((char *) $4);		}	|	RNTO SP pathname CRLF		= {			if (fromname) {				renamecmd(fromname, (char *) $3);				free(fromname);				fromname = (char *) 0;			} else {				reply(503, "Bad sequence of commands.");			}			free((char *) $3);		}	|	ABOR CRLF		= {			reply(225, "ABOR command successful.");		}	|	CWD check_login CRLF		= {			if ($2)				cwd(pw->pw_dir);		}	|	CWD check_login SP pathname CRLF		= {			if ($2 && $4 != NULL)				cwd((char *) $4);			if ($4 != NULL)				free((char *) $4);		}	|	HELP CRLF		= {			help((char *) 0);		}	|	HELP SP STRING CRLF		= {			help((char *) $3);		}	|	NOOP CRLF		= {			reply(200, "NOOP command successful.");		}	|	XMKD check_login SP pathname CRLF		= {			if ($2 && $4 != NULL)				makedir((char *) $4);			if ($4 != NULL)				free((char *) $4);		}	|	XRMD check_login SP pathname CRLF		= {			if ($2 && $4 != NULL)				removedir((char *) $4);			if ($4 != NULL)				free((char *) $4);		}	|	XPWD check_login CRLF		= {			if ($2)				pwd();		}	|	XCUP check_login CRLF		= {			if ($2)				cwd("..");		}	|	STOU check_login SP pathname CRLF		= {			if ($2 && $4 != NULL) {				unique++;				store((char *) $4, "w");				unique = 0;			}			if ($4 != NULL)				free((char *) $4);		}	|	QUIT CRLF		= {			reply(221, "Goodbye.");			dologout(0);		}	|	error CRLF		= {			yyerrok;		}	;rcmd:		RNFR check_login SP pathname CRLF		= {			char *renamefrom();			if ($2 && $4) {				fromname = renamefrom((char *) $4);				if (fromname == (char *) 0 && $4) {					free((char *) $4);				}			}		}	;		username:	STRING	;password:	STRING	;byte_size:	NUMBER	;host_port:	NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA 		NUMBER COMMA NUMBER		= {			register char *a, *p;			a = (char *)&data_dest.sin_addr;			a[0] = $1; a[1] = $3; a[2] = $5; a[3] = $7;			p = (char *)&data_dest.sin_port;			p[0] = $9; p[1] = $11;			data_dest.sin_family = AF_INET;		}	;form_code:	N	= {		$$ = FORM_N;	}	|	T	= {		$$ = FORM_T;	}	|	C	= {		$$ = FORM_C;	}	;type_code:	A	= {		cmd_type = TYPE_A;		cmd_form = FORM_N;	}	|	A SP form_code	= {		cmd_type = TYPE_A;		cmd_form = $3;	}	|	E	= {		cmd_type = TYPE_E;		cmd_form = FORM_N;	}	|	E SP form_code	= {		cmd_type = TYPE_E;		cmd_form = $3;	}	|	I	= {		cmd_type = TYPE_I;	}	|	L	= {		cmd_type = TYPE_L;		cmd_bytesz = 8;	}	|	L SP byte_size	= {		cmd_type = TYPE_L;		cmd_bytesz = $3;	}	/* this is for a bug in the BBN ftp */	|	L byte_size	= {		cmd_type = TYPE_L;		cmd_bytesz = $2;	}	;struct_code:	F	= {		$$ = STRU_F;	}	|	R

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -