--- qmail-smtpd.c 2003-04-05 17:55:20.000000000 -0500
+++ qmail-smtpd.c.new 2003-04-05 17:50:58.000000000 -0500
@@ -304,7 +304,11 @@
if (!stralloc_copys(&rcptto,"") die_nomem();
if (!stralloc_copys(&mailfrom,addr.s)) die_nomem();
if (!stralloc_0(&mailfrom)) die_nomem();
+ if (smtp_auth_validfrom(mailfrom.s)) {
out("250 ok\r\n"
+ } else {
+ out("must use username as From authenticated! (#5.7.1)\r\n"
+ }
}
void smtp_rcpt(arg) char *arg; {
if (!seenmail) { err_wantmail(); return; }
@@ -527,6 +531,82 @@
static stralloc smtpauth = {0};
static char smtpauthlogin[65];
static char smtpauthpass[65];
+static int authd = 0;
+
+/* Author: gadfly@163.com.
+ * 1. Check consistent between auth user and 'From' user.
+ * 2. Read the LOG_AUTH enviroment variable to determine whether logging the auth info.
+ * LOG_AUTH=1, write the auth smtp info into syslog.
+ */
+#include <syslog.h>;
+
+#define SMTP_AUTH_SUCCESS 0
+#define SMTP_AUTH_FAILED 1
+
+int smtp_auth_validfrom(from) char * from;
+{
+ stralloc tmplogin={0},mydefaultdomain={0};
+ char authusername[256];
+ int k, userlen;
+
+ if (!authd) return 1;
+
+ authusername[255] = '\0';
+ userlen = k = str_len(smtpauthlogin);
+ k = byte_rchr(smtpauthlogin, k, '@');
+
+ if (k == userlen)
+ {
+ k = byte_rchr(smtpauthlogin, userlen, '%');
+
+ if (k == userlen)
+ {
+ if (control_readfile(&mydefaultdomain,"/var/qmail/control/me",1) != 1)
+ {
+ die_nomem();
+ }
+ if (!stralloc_copys(&tmplogin, smtpauthlogin) )
+ {
+ die_nomem();
+ }
+ if (!stralloc_cats(&tmplogin, "@")
+ {
+ die_nomem();
+ }
+ if (!stralloc_cat(&tmplogin, &mydefaultdomain))
+ {
+ die_nomem();
+ }
+ strncpy(authusername, tmplogin.s, sizeof(authusername));
+ }
+ else
+ {
+ strcpy(authusername, smtpauthlogin);
+ authusername[k]='@';
+ }
+ }
+ else {
+ strcpy(authusername, smtpauthlogin);
+ }
+ return !strcasecmp(from, authusername);
+}
+
+
+void auth_smtplog(authlogin, authresult)
+char * authlogin;
+int authresult;
+{
+ char * x = env_get("LOG_AUTH"
+
+ if (!x || (*x != '1')) return;
+
+ if (authresult == SMTP_AUTH_SUCCESS) {
+ syslog(LOG_MAIL | LOG_INFO, "smtp auth: user name is %s, success!", authlogin);
+ } else {
+ syslog(LOG_MAIL | LOG_INFO, "smtp auth: user name is %s, failed!", authlogin);
+ }
+}
+
static int smtpauth_getl(void) {
int i;
if (!stralloc_copys(&smtpauth, "") return -1;
@@ -611,11 +691,14 @@
wait_pid(&st, pid);
if (wait_exitcode(st) == 0) {
out("235 go ahead\r\n"
+ authd = 1;
+ auth_smtplog(smtpauthlogin, SMTP_AUTH_SUCCESS);
flush();
relayclient="";
return;
}
sleep(2);
+ auth_smtplog(smtpauthlogin, SMTP_AUTH_FAILED);
out("535 auth failure\r\n" flush(); _exit(0);
/* done */
}
Hunk #1 succeeded at 252 (offset -52 lines).
Hunk #2 succeeded at 498 (offset -33 lines).
Hunk #3 succeeded at 633 (offset -58 lines).
原帖由 "netloafer" 发表:
gadfly真是强呀~~
有关资料可以上传到linux版的FTP服务器上~~~~
原帖由 "夜未眠"] 发表:
首先你要打补丁,然后照下面的方法修改qmail-smtpd.c源代码.
1.增加全局变量:
stralloc authusername={0}; //全局变量用于记录认证的email地址
2.在认证成功后将mailfrom存入上面的authusern..........
就是如果远程连接到服务器25号端口,不通过认证。一样可以向control/rcpthosts中列出的地址发邮件(就象是别的MTA与你对话一样,别人的MTA不可能知道你的用户名和密码)因为不通过认证那么relayclient将会是null,那么就会进行rcpthosts的比较,如果rcpt 指定的email地址在rcpthosts中列出,qmail会接收并转发该邮件,如果一个快速请求对一个慢速服务器,那是什么情况?
这个patch是基于www.nimh.org/hacks/qmail-smtpd.c,iceblood版本中实际上也是的这个。因此,用iceblood版本的可以直接使用。
安装方法,如下,将下面这些内容存到qmail-smtpd.patch。放到qmail的源码目录。然后
1. patch < qmail-smtpd.patch
2. make qmail-smtpd
3. 替换qmail-smtpd
原帖由 "microcao" 发表:
http://www.cuni.cz/~vhor/qmail/smtpauth-en.html
这个补丁是在 http://nimh.org/ 基础上改进来的, 他解决了楼主说的问题
增加了系统认证的日志应该是比较完善的!
原帖由 "gadfly" 发表:
你说的这个问题,不少的网友都遇到过。iceblood的
包中带的qmail-smtpd-auth*.tar.gz就是这个patch。
我没有仔细研究,反正其它问题排除,我帮他们改用了qmail-smtpd.c,也就是http://nimh.org/ 上的,这个问题?.........
默认方式只列出: 3月内的帖子
注意:回复这个时间段以外的普通帖子不能被按默认方式浏览的朋友看到!
原帖由 vyouzhi 于 2006-2-18 11:18 发表
留个印
过些时候有用
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |