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

📄 ftpd.c

📁 wu-ftpd类unix下的ftp服务器,可用于嵌入式系统
💻 C
📖 第 1 页 / 共 5 页
字号:
/****************************************************************************     Copyright (c) 1999,2000,2001 WU-FTPD Development Group.    All rights reserved.    Portions Copyright (c) 1980, 1985, 1988, 1989, 1990, 1991, 1993, 1994    The Regents of the University of California.  Portions Copyright (c) 1993, 1994 Washington University in Saint Louis.  Portions Copyright (c) 1996, 1998 Berkeley Software Design, Inc.  Portions Copyright (c) 1989 Massachusetts Institute of Technology.  Portions Copyright (c) 1998 Sendmail, Inc.  Portions Copyright (c) 1983, 1995, 1996, 1997 Eric P.  Allman.  Portions Copyright (c) 1997 by Stan Barber.  Portions Copyright (c) 1997 by Kent Landfield.  Portions Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997    Free Software Foundation, Inc.     Use and distribution of this software and its source code are governed   by the terms and conditions of the WU-FTPD Software License ("LICENSE").   If you did not receive a copy of the license, it may be obtained online  at http://www.wu-ftpd.org/license.html.   $Id: ftpd.c,v 1.111.2.1 2001/11/29 16:56:11 wuftpd Exp $ ****************************************************************************//* FTP server. */#include "config.h"#include <sys/types.h>#include <sys/param.h>#include <sys/stat.h>#include <sys/ioctl.h>#include <sys/socket.h>#include <sys/file.h>#include <sys/wait.h>#ifdef AIX#include <sys/id.h>#include <sys/priv.h>#include <netinet/if_ether.h>#include <net/if_dl.h>#endif#ifdef AUX#include <compat.h>#endif#include <netinet/in.h>#include <netinet/in_systm.h>#include <netinet/ip.h>#define FTP_NAMES#include "../support/ftp.h"#include <arpa/inet.h>#include <arpa/telnet.h>#include <ctype.h>#include <stdio.h>#include <stdlib.h>#include <signal.h>#include <pwd.h>#include <grp.h>#include <setjmp.h>#include <errno.h>#include <string.h>#ifdef INTERNAL_LS#ifdef HAVE_GLOB_H#include <glob.h>#else#include <wuftpd_glob.h>#endif#endif#ifdef HAVE_GRP_H#include <grp.h>#endif#include <sys/stat.h>#define VA_LOCAL_DECL	va_list ap;#define VA_START(f)	va_start(ap, f)#define VA_END		va_end(ap)#include "proto.h"#ifdef HAVE_UFS_QUOTA_H#include <ufs/quota.h>#endif#ifdef HAVE_SYS_FS_UFS_QUOTA_H#include <sys/fs/ufs_quota.h>#endif#ifdef HAVE_SYS_SYSLOG_H#include <sys/syslog.h>#endif#if defined(HAVE_SYSLOG_H) || (!defined(AUTOCONF) && !defined(HAVE_SYS_SYSLOG_H))#include <syslog.h>#endif#ifdef TIME_WITH_SYS_TIME#include <time.h>#include <sys/time.h>#else#ifdef HAVE_SYS_TIME_H#include <sys/time.h>#else#include <time.h>#endif#endif#include "conversions.h"#include "extensions.h"#ifdef SHADOW_PASSWORD#include <shadow.h>#endif#include "pathnames.h"#ifdef M_UNIX#include <arpa/nameser.h>#include <resolv.h>#endif#if defined(HAVE_FCNTL_H)#include <fcntl.h>#endif#ifdef HAVE_SYSINFO#include <sys/systeminfo.h>#endif#ifdef KERBEROS#include <sys/types.h>#include <auth.h>#include <krb.h>#endif#ifdef ULTRIX_AUTH#include <auth.h>#include <sys/svcinfo.h>#endif#ifndef HAVE_LSTAT#define lstat stat#endif#ifdef AFS_AUTH#include <afs/stds.h>#include <afs/kautils.h>#endif#ifdef DCE_AUTH#include <dce/rpc.h>#include <dce/sec_login.h>#include <dce/dce_error.h>#endif#ifdef HAVE_DIRENT_H#include <dirent.h>#else#include <sys/dir.h>#endif#ifdef HAVE_GETRLIMIT#include <sys/resource.h>#endif#if defined(USE_LONGJMP)#define wu_longjmp(x, y)	longjmp((x), (y))#define wu_setjmp(x)		setjmp(x)#ifndef JMP_BUF#define JMP_BUF			jmp_buf#endif#else#define wu_longjmp(x, y)	siglongjmp((x), (y))#define wu_setjmp(x)		sigsetjmp((x), 1)#ifndef JMP_BUF#define JMP_BUF			sigjmp_buf#endif#endif#ifndef MAXHOSTNAMELEN#define MAXHOSTNAMELEN 64	/* may be too big */#endif#ifndef TRUE#define  TRUE   1#endif#ifndef FALSE#define  FALSE  !TRUE#endif#ifdef MAIL_ADMIN#define MAILSERVERS 10#define INCMAILS 10int mailservers = 0;char *mailserver[MAILSERVERS];int incmails = 0;char *incmail[INCMAILS];char *mailfrom;char *email(char *full_address);FILE *SockOpen(char *host, int clientPort);char *SockGets(FILE *sockfp, char *buf, int len);int SockWrite(char *buf, int size, int nels, FILE *sockfp);int SockPrintf(FILE *sockfp, char *format,...);int SockPuts(FILE *sockfp, char *buf);int Reply(FILE *sockfp);int Send(FILE *sockfp, char *format,...);#endif /* MAIL_ADMIN */#if defined(_SCO_DS) && !defined(SIGURG)#define SIGURG	SIGUSR1#endif/* File containing login names NOT to be used on this machine. Commonly used * to disallow uucp. */extern int errno;extern int pidfd;extern char *ctime(const time_t *);#ifndef NO_CRYPT_PROTOextern char *crypt(const char *, const char *);#endifextern char version[];extern char *home;		/* pointer to home directory for glob */extern char cbuf[];extern off_t restart_point;extern int yyerrorcalled;struct sockaddr_in ctrl_addr;struct sockaddr_in data_source;struct sockaddr_in data_dest;struct sockaddr_in his_addr;struct sockaddr_in pasv_addr;struct sockaddr_in vect_addr;int route_vectored = 0;int passive_port_min = -1;int passive_port_max = -1;int restricted_user = 0;#ifdef VIRTUALchar virtual_root[MAXPATHLEN];char virtual_banner[MAXPATHLEN];char virtual_email[MAXPATHLEN];char virtual_hostname[MAXHOSTNAMELEN];char virtual_address[MAXHOSTNAMELEN];char hostaddress[32];extern int virtual_mode;extern int virtual_ftpaccess;#endif#ifdef QUOTAextern struct dqblk quota;#endifint data;jmp_buf errcatch;JMP_BUF urgcatch;int logged_in = 0;struct passwd *pw;char chroot_path[MAXPATHLEN];int debug = 0;int disable_rfc931 = 0;extern unsigned int timeout_idle;extern unsigned int timeout_maxidle;extern unsigned int timeout_data;extern unsigned int timeout_accept;extern unsigned int timeout_connect;/* previously defaulted to 1, and -l or -L set them to 1, so that there was   no way to turn them *off*!  Changed so that the manpage reflects common   sense.  -L is way noisy; -l we'll change to be "just right".  _H */int logging = 0;int log_commands = 0;int log_security = 0;int syslogmsg = 0;static int wtmp_logging = 1;#ifdef SECUREOSF#define SecureWare		/* Does this mean it works for all SecureWare? */#endif#ifdef HPUX_10_TRUSTED#include <hpsecurity.h>#endif#if defined(SecureWare) || defined(HPUX_10_TRUSTED)#include <prot.h>#endifint anonymous = 1;int guest;int type;int form;int stru;			/* avoid C keyword */int mode;int usedefault = 1;		/* for data transfers */int pdata = -1;			/* for passive mode */int transflag;int ftwflag;off_t file_size;off_t byte_count;int TCPwindowsize = 0;		/* 0 = use system default */#ifdef TRANSFER_COUNTint data_count_total = 0;	/* total number of data bytes */int data_count_in = 0;int data_count_out = 0;int byte_count_total = 0;	/* total number of general traffic */int byte_count_in = 0;int byte_count_out = 0;int file_count_total = 0;	/* total number of data files */int file_count_in = 0;int file_count_out = 0;int xfer_count_total = 0;	/* total number of transfers */int xfer_count_in = 0;int xfer_count_out = 0;#ifdef TRANSFER_LIMITint file_limit_raw_in = 0;int file_limit_raw_out = 0;int file_limit_raw_total = 0;int file_limit_data_in = 0;int file_limit_data_out = 0;int file_limit_data_total = 0;int data_limit_raw_in = 0;int data_limit_raw_out = 0;int data_limit_raw_total = 0;int data_limit_data_in = 0;int data_limit_data_out = 0;int data_limit_data_total = 0;#ifdef RATIO /* 1998/08/04 K.Wakui */#define TRUNC_KB(n)   ((n)/1024+(((n)%1024)?1:0))off_t   total_free_dl = 0;int     upload_download_rate = 0;int     freefile;int     is_downloadfree( char * );#endif /* RATIO */#endif#endifint retrieve_is_data = 1;	/* !0=data, 0=general traffic -- for 'ls' */char LastFileTransferred[MAXPATHLEN] = "";static char *RootDirectory = NULL;#if !defined(CMASK) || CMASK == 0#undef CMASK#define CMASK 022#endifmode_t defumask = CMASK;	/* default umask value */#ifdef ALTERNATE_CDchar defhome[] = "/";#endifchar tmpline[7];char hostname[MAXHOSTNAMELEN];char remotehost[MAXHOSTNAMELEN];char remoteaddr[MAXHOSTNAMELEN];char *remoteident = "[nowhere yet]";/* log failures         27-apr-93 ehk/bm */#ifdef LOG_FAILED#define MAXUSERNAMELEN	256char the_user[MAXUSERNAMELEN];#endif/* Access control and logging passwords *//* OFF by default.  _H */int use_accessfile = 0;char guestpw[MAXHOSTNAMELEN];char privatepw[MAXHOSTNAMELEN];int nameserved = 0;extern char authuser[];extern int authenticated;extern int keepalive;/* File transfer logging */int xferlog = 0;int log_outbound_xfers = 0;int log_incoming_xfers = 0;char logfile[MAXPATHLEN];/* Allow use of lreply(); this is here since some older FTP clients don't * support continuation messages.  In violation of the RFCs... */int dolreplies = 1;/* Spontaneous reply text.  To be sent along with next reply to user */char *autospout = NULL;int autospout_free = 0;/* allowed on-the-fly file manipulations (compress, tar) */int mangleopts = 0;/* number of login failures before attempts are logged and FTP *EXITS* */int lgi_failure_threshold = 5;/* Timeout intervals for retrying connections to hosts that don't accept PORT * cmds.  This is a kludge, but given the problems with TCP... */#define SWAITMAX    90		/* wait at most 90 seconds */#define SWAITINT    5		/* interval between retries */int swaitmax = SWAITMAX;int swaitint = SWAITINT;SIGNAL_TYPE lostconn(int sig);SIGNAL_TYPE randomsig(int sig);SIGNAL_TYPE myoob(int sig);FILE *getdatasock(char *mode);FILE *dataconn(char *name, off_t size, char *mode);void setproctitle(const char *fmt,...);void initsetproctitle(int, char **, char **);void reply(int, char *fmt,...);void lreply(int, char *fmt,...);#ifndef HAVE_VSNPRINTFextern int vsnprintf(char *, size_t, const char *, va_list);#endif#ifndef HAVE_SNPRINTFextern int snprintf(char *, size_t, const char *,...);#endif#ifdef HAVE_LIBRESOLVint initialize_dns(struct sockaddr_in *remote_socket);int check_reverse_dns(void);int check_matching_dns(void);#endif#ifdef NEED_SIGFIXextern sigset_t block_sigmask;	/* defined in sigfix.c */#endifchar proctitle[BUFSIZ];		/* initial part of title */#if defined(SKEY) && defined(OPIE)#error YOU SHOULD NOT HAVE BOTH SKEY AND OPIE DEFINED!!!!!#endif#ifdef SKEY#include <skey.h>int pwok = 0;#endif#ifdef OPIE#include <opie.h>int pwok = 0;int af_pwok = 0;struct opie opiestate;#endif#ifdef KERBEROSvoid init_krb();void end_krb();char krb_ticket_name[100];#endif /* KERBEROS */#ifdef ULTRIX_AUTHint ultrix_check_pass(char *passwd, char *xpasswd);#endif#ifdef USE_PAM#if defined(ULTRIX_AUTH) || defined(SECUREOSF) || defined(KERBEROS) || defined(SKEY) || defined (OPIE) || defined (BSD_AUTH)#error No other auth methods are allowed with PAM.#endifstatic int pam_check_pass(char *user, char *passwd);#endif#ifndef INTERNAL_LS/* ls program commands and options for lreplies on and off */char ls_long[1024];char ls_short[1024];char ls_plain[1024];#endif#ifdef DAEMONint be_daemon = 0;		/* Run standalone? */int daemon_port = 0;void do_daemon(int argc, char **argv, char **envp);#endifint Bypass_PID_Files = 0;#ifdef OTHER_PASSWD#include "getpwnam.h"char _path_passwd[MAXPATHLEN];#ifdef SHADOW_PASSWORDchar _path_shadow[MAXPATHLEN];#endif#endif#if defined(USE_PAM) && defined(OTHER_PASSWD)int use_pam = 1;#elseint use_pam = 0;#endifvoid end_login(void);void print_copyright(void);char *mapping_getcwd(char *path, size_t size);#ifdef THROUGHPUTint send_data(char *name, FILE *, FILE *, off_t);#elseint send_data(FILE *, FILE *, off_t);#endifvoid dolog(struct sockaddr_in *);void dologout(int);void perror_reply(int, char *);int denieduid(uid_t);int alloweduid(uid_t);int deniedgid(gid_t);int allowedgid(gid_t);int restricteduid(uid_t);int unrestricteduid(uid_t);int restrictedgid(gid_t);int unrestrictedgid(gid_t);#ifdef THROUGHPUTextern void throughput_calc(char *, int *, double *);extern void throughput_adjust(char *);#endiftime_t login_time;time_t limit_time = 0;int regexmatch(char *name, char *rgexp);int pasv_allowed(char *remoteaddr);int port_allowed(char *remoteaddr);#if sparc && !__svr4__

⌨️ 快捷键说明

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