/*
* Copyright (c) 1998-2004 Sendmail, Inc. and its suppliers.
* All rights reserved.
* Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the sendmail distribution.
*
*/
#include <sendmail.h>
#if MILTER
# include <libmilter/mfapi.h>
# include <libmilter/mfdef.h>
#endif /* MILTER */
SM_RCSID("@(#)$Id: srvrsmtp.c,v 8.900 2004/07/08 23:29:33 ca Exp $")
#include <sys/time.h>
#include <sm/fdset.h>
#if SASL || STARTTLS
# include "sfsasl.h"
#endif /* SASL || STARTTLS */
#if SASL
# define ENC64LEN(l) (((l) + 2) * 4 / 3 + 1)
static int saslmechs __P((sasl_conn_t *, char **));
#endif /* SASL */
#if STARTTLS
# include <sysexits.h>
static SSL_CTX *srv_ctx = NULL; /* TLS server context */
static SSL *srv_ssl = NULL; /* per connection context */
static bool tls_ok_srv = false;
extern void tls_set_verify __P((SSL_CTX *, SSL *, bool));
# define TLS_VERIFY_CLIENT() tls_set_verify(srv_ctx, srv_ssl, \
bitset(SRV_VRFY_CLT, features))
#endif /* STARTTLS */
/* server features */
#define SRV_NONE 0x0000 /* none... */
#define SRV_OFFER_TLS 0x0001 /* offer STARTTLS */
#define SRV_VRFY_CLT 0x0002 /* request a cert */
#define SRV_OFFER_AUTH 0x0004 /* offer AUTH */
#define SRV_OFFER_ETRN 0x0008 /* offer ETRN */
#define SRV_OFFER_VRFY 0x0010 /* offer VRFY (not yet used) */
#define SRV_OFFER_EXPN 0x0020 /* offer EXPN */
#define SRV_OFFER_VERB 0x0040 /* offer VERB */
#define SRV_OFFER_DSN 0x0080 /* offer DSN */
#if PIPELINING
# define SRV_OFFER_PIPE 0x0100 /* offer PIPELINING */
# if _FFR_NO_PIPE
# define SRV_NO_PIPE 0x0200 /* disable PIPELINING, sleep if used */
# endif /* _FFR_NO_PIPE */
#endif /* PIPELINING */
#define SRV_REQ_AUTH 0x0400 /* require AUTH */
#define SRV_REQ_SEC 0x0800 /* require security - equiv to AuthOptions=p */
#define SRV_TMP_FAIL 0x1000 /* ruleset caused a temporary failure */
static unsigned int srvfeatures __P((ENVELOPE *, char *, unsigned int));
#define STOP_ATTACK ((time_t) -1)
static time_t checksmtpattack __P((volatile unsigned int *, unsigned int,
bool, char *, ENVELOPE *));
static void mail_esmtp_args __P((char *, char *, ENVELOPE *));
static void printvrfyaddr __P((ADDRESS *, bool, bool));
static void rcpt_esmtp_args __P((ADDRESS *, char *, char *, ENVELOPE *));
static char *skipword __P((char *volatile, char *));
static void setup_smtpd_io __P((void));
#if SASL
# if SASL >= 20000
static int reset_saslconn __P((sasl_conn_t **_conn, char *_hostname,
char *_remoteip, char *_localip,
char *_auth_id, sasl_ssf_t *_ext_ssf));
# define RESET_SASLCONN \
result = reset_saslconn(&conn, AuthRealm, remoteip, localip, auth_id, \
&ext_ssf); \
if (result != SASL_OK) \
{ \
/* This is pretty fatal */ \
goto doquit; \
}
# else /* SASL >= 20000 */
static int reset_saslconn __P((sasl_conn_t **_conn, char *_hostname,
struct sockaddr_in *_saddr_r,
struct sockaddr_in *_saddr_l,
sasl_external_properties_t *_ext_ssf));
# define RESET_SASLCONN \
result = reset_saslconn(&conn, AuthRealm, &saddr_r, &saddr_l, &ext_ssf); \
if (result != SASL_OK) \
{ \
/* This is pretty fatal */ \
goto doquit; \
}
# endif /* SASL >= 20000 */
#endif /* SASL */
extern ENVELOPE BlankEnvelope;
#define NBADRCPTS \
do \
{ \
char buf[16]; \
(void) sm_snprintf(buf, sizeof buf, "%d", \
BadRcptThrottle > 0 && n_badrcpts > BadRcptThrottle \
? n_badrcpts - 1 : n_badrcpts); \
macdefine(&e->e_macro, A_TEMP, macid("{nbadrcpts}"), buf); \
} while (0)
#define SKIP_SPACE(s) while (isascii(*s) && isspace(*s)) \
(s)++
/*
** SMTP -- run the SMTP protocol.
**
** Parameters:
** nullserver -- if non-NULL, rejection message for
** (almost) all SMTP commands.
** d_flags -- daemon flags
** e -- the envelope.
**
** Returns:
** never.
**
** Side Effects:
** Reads commands from the input channel and processes them.
*/
/*
** Notice: The smtp server doesn't have a session context like the client
** side has (mci). Therefore some data (session oriented) is allocated
** or assigned to the "wrong" structure (esp. STARTTLS, AUTH).
** This should be fixed in a successor version.
*/
struct cmd
{
char *cmd_name; /* command name */
int cmd_code; /* internal code, see below */
};
/* values for cmd_code */
#define CMDERROR 0 /* bad command */
#define CMDMAIL 1 /* mail -- designate sender */
#define CMDRCPT 2 /* rcpt -- designate recipient */
#define CMDDATA 3 /* data -- send message text */
#define CMDRSET 4 /* rset -- reset state */
#define CMDVRFY 5 /* vrfy -- verify address */
#define CMDEXPN 6 /* expn -- expand address */
#define CMDNOOP 7 /* noop -- do nothing */
#define CMDQUIT 8 /* quit -- close connection and die */
#define CMDHELO 9 /* helo -- be polite */
#define CMDHELP 10 /* help -- give usage info */
#define CMDEHLO 11 /* ehlo -- extended helo (RFC 1425) */
#define CMDETRN 12 /* etrn -- flush queue */
#if SASL
# define CMDAUTH 13 /* auth -- SASL authenticate */
#endif /* SASL */
#if STARTTLS
# define CMDSTLS 14 /* STARTTLS -- start TLS session */
#endif /* STARTTLS */
/* non-standard commands */
#define CMDVERB 17 /* verb -- go into verbose mode */
/* unimplemented commands from RFC 821 */
#define CMDUNIMPL 19 /* unimplemented rfc821 commands */
/* use this to catch and log "door handle" attempts on your system */
#define CMDLOGBOGUS 23 /* bogus command that should be logged */
/* debugging-only commands, only enabled if SMTPDEBUG is defined */
#define CMDDBGQSHOW 24 /* showq -- show send queue */
#define CMDDBGDEBUG 25 /* debug -- set debug mode */
/*
** Note: If you change this list, remember to update 'helpfile'
*/
static struct cmd CmdTab[] =
{
{ "mail", CMDMAIL },
{ "rcpt", CMDRCPT },
{ "data", CMDDATA },
{ "rset", CMDRSET },
{ "vrfy", CMDVRFY },
{ "expn", CMDEXPN },
{ "help", CMDHELP },
{ "noop", CMDNOOP },
{ "quit", CMDQUIT },
{ "helo", CMDHELO },
{ "ehlo", CMDEHLO },
{ "etrn", CMDETRN },
{ "verb", CMDVERB },
{ "send", CMDUNIMPL },
{ "saml", CMDUNIMPL },
{ "soml", CMDUNIMPL },
{ "turn", CMDUNIMPL },
#if SASL
{ "auth", CMDAUTH, },
#endif /* SASL */
#if STARTTLS
{ "starttls", CMDSTLS, },
#endif /* STARTTLS */
/* remaining commands are here only to trap and log attempts to use them */
{ "showq", CMDDBGQSHOW },
{ "debug", CMDDBGDEBUG },
{ "wiz", CMDLOGBOGUS },
{ NULL, CMDERROR }
};
static char *CurSmtpClient; /* who's at the other end of channel */
#ifndef MAXBADCOMMANDS
# define MAXBADCOMMANDS 25 /* maximum number of bad commands */
#endif /* ! MAXBADCOMMANDS */
#ifndef MAXNOOPCOMMANDS
# define MAXNOOPCOMMANDS 20 /* max "noise" commands before slowdown */
#endif /* ! MAXNOOPCOMMANDS */
#ifndef MAXHELOCOMMANDS
# define MAXHELOCOMMANDS 3 /* max HELO/EHLO commands before slowdown */
#endif /* ! MAXHELOCOMMANDS */
#ifndef MAXVRFYCOMMANDS
# define MAXVRFYCOMMANDS 6 /* max VRFY/EXPN commands before slowdown */
#endif /* ! MAXVRFYCOMMANDS */
#ifndef MAXETRNCOMMANDS
# define MAXETRNCOMMANDS 8 /* max ETRN commands before slowdown */
#endif /* ! MAXETRNCOMMANDS */
#ifndef MAXTIMEOUT
# define MAXTIMEOUT (4 * 60) /* max timeout for bad commands */
#endif /* ! MAXTIMEOUT */
/*
** Maximum shift value to compute timeout for bad commands.
** This introduces an upper limit of 2^MAXSHIFT for the timeout.
*/
#ifndef MAXSHIFT
# define MAXSHIFT 8
#endif /* ! MAXSHIFT */
#if MAXSHIFT > 31
ERROR _MAXSHIFT > 31 is invalid
#endif /* MAXSHIFT */
#if MAXBADCOMMANDS > 0
# define STOP_IF_ATTACK(r) do \
{ \
if ((r) == STOP_ATTACK) \
goto
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
站长,你好,可否给我开放,我提供的是基于uCOSII代码,包含有Http服务器,SMTP,DDNS,FTP网络方面的代码,我很需要一些MP3,MPEG4的算法原理资料
资源推荐
资源详情
资源评论
收起资源包目录
Net_apps.rar (71个子文件)
Net_apps
TurnData.c.bak 11KB
ethernetif.asm 20KB
TurnData.c 11KB
ftp
vssver.scc 48B
ftp.c 26KB
IoEnv.c 89KB
sntp
vssver.scc 48B
sntp.bak 15KB
sntp.c 15KB
modem
splc.c 19KB
splc.bak 19KB
srvrsmtp.c 114KB
ethernetif.bak 20KB
IoEnv.c.bak 86KB
IoEnv.bak 89KB
netswitch.bak 5KB
usersmtp.c 78KB
dns
dns.c 9KB
vssver.scc 48B
back_image
backimage.c 11KB
backimage.bak 11KB
temp
tcpecho.c 3KB
shell.h 2KB
udpecho.h 2KB
tcpecho.h 2KB
shell.c 31KB
httpdTestSend.c 7KB
fs.h 2KB
fs.c 2KB
vssver.scc 208B
udpecho.c 3KB
fsdata.c 20KB
chargen.c 10KB
NetSwitch.c 5KB
ddns
ddns.c 10KB
vssver.scc 48B
str_function.c 6KB
smtp
smtp.c 29KB
vssver.scc 48B
httpd
HttpServer_0_0_1_.bak 21KB
HttpServerSelectTest.c 8KB
HttpServer_0_0_1_.c 21KB
httpd.c 6KB
api
HttpSolRequest.c 14KB
HttpEvent.c 12KB
HttpSolRequest.c.bak 14KB
HttpFileSystem.c.bak 15KB
HttpStream.bak 19KB
HttpApi.bak 12KB
HttpFileSystem.c 16KB
HttpFileSystem.bak 16KB
HttpEvent.c.bak 11KB
HttpStream00.c 15KB
HttpSolRequest.bak 14KB
vssver.scc 128B
HttpStream.c.bak 16KB
HttpApi.c 12KB
HttpEvent.bak 12KB
HttpStream.c 19KB
vssver.scc 96B
HttpServerTestSendPerformance.c 12KB
TurnData.bak 11KB
vssver.scc 128B
NetSwitch.c.bak 5KB
demo
Tx6Rx6DisplayTv.c 10KB
vssver.scc 48B
audio
UdpServer.c.bak 9KB
vssver.scc 48B
UdpServer.c 9KB
UdpServer.bak 9KB
www.pudn.com.txt 218B
共 71 条
- 1
资源评论
四散
- 粉丝: 52
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功