本文介绍如何让 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即可.