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

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

本文简介:

谢谢xmubeta的指正。

至于为什么原来的patch在linux不出错,在solaris上出错。
我理解是linux上将结构传入参数,转化成char *的时候,实际上是将第一个结构成员转化了,而这个正好是mailfrom.s。所以没有问题。

而solaris上就有所不同了,所以造成错误。

iceblood, patch我给你重发了。

 gadfly 回复于:2003-06-02 18:51:47 应一些朋友的要求,加了本地发信人发给本地,也需要auth的功能。

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

我稍微测试了一下。各位测恻看吧。

[code:1:e9fa54356d]
--- 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>
+
+#define SMTP_AUTH_SUCCESS     0
+#define SMTP_AUTH_FAILED      1
+
+int localauthd() {
+
+  if (rcpthosts(mailfrom.s, strlen(mailfrom.s)) && !authd) return 0;
+  return 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, "@") )
+      {

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

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

go top