監視、備份所有通過 sendmail 的郵件

来源:百度文库 编辑:神马文学网 时间:2024/06/03 08:18:54
監視、備份所有通過 sendmail 的郵件
目的: 修改 sendmail 原始程式碼, 讓所有通過 sendmail 的郵件另外轉寄到指定的信箱, 以達到監視、備份的目的.
由於 sendmail 的原始碼安裝過程相當繁複, 本篇以安裝備忘為出發點, 主要內容有:
1. 在 Trustix 2.2 安裝 sendmail + dovecot
2. 讓原本的 sendmail 加上自動轉寄功能
Trustix 2.2 安裝 sendmail + dovecot 前置動作
(若要更新原本的 sendmail 程式請從 "下載 sendmail source" 開始閱讀)
停用 Postfix
service postfix stop
chkconfig postfix off
使用 swup 安裝以下套件
cyrus-sasl
cyrus-sasl-devel
cyrus-sasl-plain
db4-devel
tcp_wrappers
procmail
vi /etc/sysconfig/saslauthd
修改: SASL_AUTHMECH=shadow
vi /usr/lib/sasl2/Sendmail.conf
加入: pwcheck_method:saslauthd
下載 sendmail source
ftp://ftp.nctu.edu.tw/network/mail/sendmail/
解壓縮至 /usr/local/src
若只想更新原有的 sendmail, 請下載相同的版本
修改程式碼, 讓 sendmail 自動轉寄郵件至指定 e-mail address
cd /usr/local/src/sendmail-x.xx.x/sendmail
vi srvrsmtp.c
尋找字串: smtp(
在 "bool ok;" 底下新增: int spydone = 0;
尋找字串: case CMDRCPT
在 case CMDRCPT 這行再往下尋找字串: case
在上一列的 "break;" 之前插入以下程式碼:
if (!spydone) {
a = parseaddr("指定的@e-mail.address", NULLADDR, RF_COPYALL, ‘ ‘, &delimptr, e, true);
a = recipient(a, &e->e_sendqueue, 0, e);
e->e_to = a->q_paddr;
smtp.sm_nrcpts++;
spydone = 1;
}
修改完畢, 存檔離開
產生安裝設定檔 (site.config.m4)
cd /usr/local/src/sendmail-x.xx.x/devtools/Site
vi site.config.m4
PREPENDDEF(`confMAPDEF‘, `-DMAP_REGEX‘)
APPENDDEF(`confENVDEF‘, `-DTCPWRAPPERS -DSASL=2‘)
APPENDDEF(`conf_sendmail_LIBS‘, `-lwrap -lsasl2‘)
APPENDDEF(`confLIBDIRS‘, `-L/usr/lib‘)
APPENDDEF(`confINCDIRS‘, `-I/usr/include‘)
define(`confMANROOT‘, `/usr/share/man/man‘)
其中, /usr/lib 和 /usr/include 視 sasl 套件安裝位置而定
而 ` 和 ‘ 請分清楚: 字串左邊的是 ` (在標準鍵盤的 Tab 鍵上方); 字串右邊的是 ‘ (在標準鍵盤的 Enter 鍵左方)
若原本已有 sendmail + saslauthd 的環境在運行, 只想讓 sendmail 加上自動轉寄的功能
(若要完整安裝 sendmail 請先跳過這個步驟)
cd /usr/local/src/sendmail-x.xx.x/sendmail
sh Build -c install
執行到這個步驟, 再重新啟動 sendmail 就可以了
產生基本設定檔
cd /usr/local/src/sendmail-x.xx.x/cf/cf
cp generic-linux.mc sendmail.mc
cat ../feature/access_db.m4 >> sendmail.mc
cat ../feature/delay_checks.m4 >> sendmail.mc
cat ../feature/virtusertable.m4 >> sendmail.mc
vi sendmail.mc
於最後加入:
TRUST_AUTH_MECH(`LOGIN PLAIN‘)dnl
define(`confAUTH_MECHANISMS‘, `LOGIN PLAIN‘)dnl
sh Build sendmail.cf
mkdir -p /etc/mail
sh Build install-cf
產生必要帳號與路徑
groupadd smmsp
useradd -M -g smmsp -d /var/spool/clientmqueue -s /bin/false smmsp
mkdir -p /var/spool/clientmqueue
chown -R smmsp:smmsp /var/spool/clientmqueue
chmod -R 770 /var/spool/clientmqueue
安裝主程式與相關工具
cd /usr/local/src/sendmail-x.xx.x/sendmail
sh Build -c install
cd ../makemap
sh Build install
cd ../mailstats
sh Build install
cd ../
sh Bulid install
修改設定檔
cd /etc/mail
vi access
加入以下內容:
localhost.localdomain RELAY
localhost RELAY
127.0.0.1 RELAY
vi local-host-names
加入: your.domain.name
vi aliases (原始檔案在 /usr/local/src/sendmail-x.xx.x/sendmail/aliases)
touch virtusertable
makemap hash access.db < access
makemap hash virtusertable.db < virtusertable
newaliases
測試 sendmail 是否能正常運作
/usr/sbin/sendmail -bd -q30m
telnet localhost 25
安裝 dovecot
wgethttp://dovecot.org/nightly/stable/dovecot-stable-latest.tar.gz
解壓縮至 /usr/local/src
groupadd -g 143 dovecot
useradd -M -g 143 -s /bin/false dovecot
cd /usr/local/src/dovecot-x.x
./configure
make
make install
vi /usr/local/etc/dovecot-example.conf
取消註解、修改內容如下:
base_dir = /var/run/dovecot/
protocols = imap imaps pop3 pop3s
disable_plaintext_auth = no
log_path = /dev/stderr
login_dir = /var/run/dovecot/login
passdb = shadow
其中, log_path = /dev/stderr 會將 log 訊息顯示在螢幕上, 以方便除錯; 等一切正常後, 再將它註解掉.
修改後另存成 /usr/local/etc/dovecot.conf
啟動服務
啟動 saslauthd
service saslauthd start
啟動 dovecot
/usr/local/sbin/dovecot -c /usr/local/etc/dovecot.conf
啟動 sendmail
/usr/sbin/sendmail -bd -q30m
參考資料:
鳥哥的 Linux 私房菜: 簡易 Mail Server 架設 -- Sendmail 設定: 以 Tarball 完整安裝 Sendmail (含 SMTP 郵件認證、procmail 與 ORGB 的完全安裝! ) 鳥哥的 Linux 私房菜: 郵件主機在寄信時的 SMTP 認證問題酷! 學園討論區: Sendmail 中E-mail用戶信件備份监控你E-mail用户的邮件(sendmail篇)
本站相關文章:
ASSP (Anti-Spam SMTP Proxy) 使用手札Sendmail + MailScanner + ClamAV 安裝實錄Sendmail: localhost.localdomain 的問題Fedora Core Sendmail 開放遠端收發信件
Posted by Jamyy at 2005年12月15日 14:08
from: http://cha.homeip.net/blog/archives/2005/12/_sendmail.html#more