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

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

本文简介:

+#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, "@") )
+      {
+        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 +699,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);

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

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

go top