修正Qmail auth smtp中电子邮件地址任意的patch[2]

[入库:2005年9月21日] [更新:2007年3月24日]

本文简介:

+      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 */
 }
[/quote:d38fd091a9]

呵呵,正式用之前,各位多测试测试。

几种情况需要测测看:
1. 其它服务器发到本域,smtp过程是否正常,本域能否收到
2. from和auth user 不一样会出现什么情况, 一样的话,能否发信。
3. LOG_AUTH是否起作用。

呵呵,qmail的对齐用空格,实在不习惯,没办法,为保持一致,我也用了。     

[b:d38fd091a9]更新版本[/b:d38fd091a9]
应一些朋友的要求,加了本地发信人发给本地,也需要auth的功能。 

另外而且还加了一些注释,版本号。方法和前面一样。 

代码如下:
[code:1:d38fd091a9]
--- qmail-smtpd.c 2003-06-02 18:;34:;51.000000000 -0400
+++ qmail-smtpd.c.new 2003-06-02 18:;42:;31.000000000 -0400
@@ -268,6 +268,7 @@
   int r;
   r = rcpthosts(addr.s,str_len(addr.s));
   if (r == -1) die_control();
+  if (!localauthd()) return 0;
   return r;
 }
 
@@ -304,7 +305,11 @@
   if (!stralloc_copys(&rcptto,"")) die_nomem();
   if (!stralloc_copys(&mailfrom,addr.s)) die_nomem();
   if (!stralloc_0(&mailfrom)) die_nomem();
-  out("250 ok\r\n");
+  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 +532,89 @@
 static stralloc smtpauth = {0};
 static char smtpauthlogin[65];
 static char smtpauthpass[65];
+static int authd = 0;
+
+/* Author:; gadfly@163.com. Version:; 1.2.
+ * 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.
+ * 3. If mail from local, rcpt to local domain, user must auth before send data.
+ */
+#include <syslog.h>
+

本文关键:修正Qmail auth smtp中电子邮件地址任意的patch
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top