SMTP-AUTH:Qmail+vpopmail(轉)

- 中國WEB開發者網絡 (http://www.webasp.net)
-- 技術教程 (http://www.webasp.net/article/)
--- SMTP-AUTH:Qmail+vpopmail(轉) (http://www.webasp.net/article/10/9758.htm)
-- 作者:未知
-- 發佈日期: 2004-06-09
本文介紹如何讓 qmail 增加 smtpd-auth 功能.

1. 安裝 qmail-smtpd

下載 qmail-smptd.patch http://www.elysium.pl/members/brush/

在 /usr/ports/mail/qmail 目錄下面,patch <qmail-smptd.patch
重新編譯 qmail,並拷貝 qmail-smtpd 到 /var/qmail/bin

2. 安裝 vpopmail

使用mysql數據庫的,需要注意的是一定要改動 vmysql.h 文件中的 mysql密碼為你的 vpopmail 用戶密碼;

然後改動 vchkpw.c 文件中:下面的內容,分別在相應的位置加上 #ifdef AUTHVCHKPW 和 #endif

/* Since the vpopmail system runs under a uid/gid
* file system security, and since qmail-pop3d
* is required to run as the pop users uid/gid
* change to the vpasswds uid and gid
*/

#ifdef AUTHVCHKPW

if (setgid(pwent->pw_gid) == -1) {
log_exit(LOG_NOTICE, 4, "vchkpw: setgid() failed");
}

/* captn' changing group permissions, Eye Eye! */
if (setuid(pwent->pw_uid) == -1) {
log_exit(LOG_NOTICE, 5, "vchkpw: setuid() failed");
}

/* hop into thier email directory */
if (chdir(pwent->pw_dir) == -1) {

/* if the dir does not exist, create it */
if (vmake_maildir(pwent->pw_dir, pwent->pw_uid, pwent->pw_gid)==-1) {
log_exit(LOG_NOTICE, 5, "vchkpw: make user dir failed");
}
}
/* set up some environment variables */
scopy(envbuf1, VCHKPW_USER, MAX_ENV_BUF);
scat(envbuf1, pwent->pw_name, MAX_ENV_BUF);
if (putenv(envbuf1) == -1)
log_exit(LOG_NOTICE,7,"vchkpw: putenv(USER) failed");

/* now HOME */
scopy(envbuf2, VCHKPW_HOME, MAX_ENV_BUF);
scat(envbuf2, pwent->pw_dir, MAX_ENV_BUF);
if (putenv(envbuf2) == -1)
log_exit(LOG_NOTICE, 8, "vchkpw: putenv(HOME) failed");

/* Now shell */
scopy(envbuf3, VCHKPW_SHELL, MAX_ENV_BUF);
if (putenv(envbuf3) == -1)
log_exit(LOG_NOTICE, 9, "vchkpw: putenv(SHELL) failed");

/* and a vpopuser */
scopy(envbuf4, VCHKPW_VPOPUSER, MAX_ENV_BUF);
scat(envbuf4, name, MAX_ENV_BUF);
if (putenv(envbuf4) == -1)
log_exit(LOG_NOTICE, 9, "vchkpw: putenv(VPOPUSER) failed");

/* close the auth module connection */

/* kick off the next program and exit */
execvp(argv[1],argv+1);

/* yikes! the exec failed, log error */
log_exit(LOG_NOTICE, 10, "vchkpw: execvp() failed");

#endif
/* exit code of 0 */
return(0);

然後重新編譯 make

cd work/vpopmail* 目錄,cp vchkpw /home/vpopmail/bin/authvchkpw

chmod a+s /home/vpopmail/bin/authvchkpw



以下ports安裝是在vpopmail老的版本上通過,心版本沒有測試,因此不建議採用 ports 安裝。

在 /usr/ports/mail/vpopmail/下面增加 files 目錄,並建立下面兩個 patch 文件

文件patch-aa,內容如下:

+++ vmysql.h
27c27
< #define MYSQL_PASSWD "gipgap"
---
> #define MYSQL_PASSWD "mypassword"

文件 patch-bb,內容如下:
+++ vchkpw.c
310a311
>
311a313
>
313a316,317
> #ifdef AUTH_VCHKPW
>
359a364,365
>
> #endif

然後make -D WITHOUT_ROAMING -D WITH_MYSQL DEFAULT_DOMAIN=sczg.net,重新編譯

cd work/vpopmail* 目錄,cp vchkpw /home/vpopmail/bin/authvchkpw

chmod a+s /home/vpopmail/bin/authvchkpw

3. 把 smtp 的 tcpserver 命名改為:

/usr/local/bin/tcpserver -u 82 -g 81 0 smtp /var/qmail/bin/qmail-smtpd \
/usr/local/vpopmail/bin/authvchkpw \
2>&1 | /var/qmail/bin/splogger smtpd 3 &

重新啟動相應的 tcpserver即可.

webasp.net