* support SMTP-AUTH for outbound connection to smart-host
authorArt Cancro <ajc@citadel.org>
Thu, 19 Jan 2006 22:49:55 +0000 (22:49 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 19 Jan 2006 22:49:55 +0000 (22:49 +0000)
citadel/ChangeLog
citadel/docs/citadel.html
citadel/serv_smtp.c

index a6a27a8e705227f6a724dc6acc6866016d0e48d0..220acb244ee45926c35159fc8833fdb2e9d8c73e 100644 (file)
@@ -1,5 +1,8 @@
 $Id$
 
+Thu Jan 19 17:49:29 EST 2006 ajc
+* support SMTP-AUTH for outbound connection to smart-host
+
 Thu Jan 19 16:40:57 EST 2006 ajc
 * Change to journaling code to include an Internet email address for local
   recipients.
index 77b5d0ecdb12504dac7d399f31b87104a68ba8e1..5d8685d96e5b3c0bb4291143192d965ff2da155c 100644 (file)
@@ -1882,9 +1882,13 @@ sites; you may require (due to local convention, security policy, or
 whatever) that all outbound mail be sent to an SMTP relay or forwarder.
 To configure this
 functionality, simply enter the domain name or IP address of your relay
-as a 'smart-host' entry.  If your relay server is running on a port other
+as a 'smart-host' entry.</p>
+<p>If your relay server is running on a port other
 than the standard SMTP port 25, you can also specify the port number
 using &quot;host:port&quot; syntax; i.e. <tt>relay99.myisp.com:2525</tt></p>
+<p>Furthermore, if your relay server requires authentication, you can
+specify it using username:password@host or username:password@host:port
+syntax; i.e. <tt>jsmith:pass123@relay99.myisp.com:25</tt></p>
 <p><b>directory:</b> a domain for which you are participating in
 directory services across any number of Citadel nodes. For example, if
 users who have addresses in the domain <tt>citadel.org</tt> are spread
index b16d7804f4ce67c7eb5c712ea5cfba63789410e5..23a690db8ef925b1830f0509faa682289d726f96 100644 (file)
@@ -942,6 +942,8 @@ void smtp_try(const char *key, const char *addr, int *status,
        char user[1024], node[1024], name[1024];
        char buf[1024];
        char mailfrom[1024];
+       char mx_user[256];
+       char mx_pass[256];
        char mx_host[256];
        char mx_port[256];
        int lp, rp;
@@ -1026,11 +1028,23 @@ void smtp_try(const char *key, const char *addr, int *status,
        sock = (-1);
        for (mx=0; (mx<num_mxhosts && sock < 0); ++mx) {
                extract_token(buf, mxhosts, mx, '|', sizeof buf);
+               strcpy(mx_user, "");
+               strcpy(mx_pass, "");
+               if (num_tokens(buf, '@') > 1) {
+                       extract_token(mx_user, buf, 0, '@', sizeof mx_user);
+                       if (num_tokens(mx_user, ':') > 1) {
+                               extract_token(mx_pass, mx_user, 1, ':', sizeof mx_pass);
+                               remove_token(mx_user, 1, ':');
+                       }
+                       remove_token(buf, 0, '@');
+               }
                extract_token(mx_host, buf, 0, ':', sizeof mx_host);
                extract_token(mx_port, buf, 1, ':', sizeof mx_port);
                if (!mx_port[0]) {
                        strcpy(mx_port, "25");
                }
+               lprintf(CTDL_DEBUG, "FIXME user<%s> pass<%s> host<%s> port<%s>\n",
+                       mx_user, mx_pass, mx_host, mx_port);
                lprintf(CTDL_DEBUG, "Trying %s : %s ...\n", mx_host, mx_port);
                sock = sock_connect(mx_host, mx_port, "tcp");
                snprintf(dsn, SIZ, "Could not connect: %s", strerror(errno));
@@ -1088,7 +1102,34 @@ void smtp_try(const char *key, const char *addr, int *status,
                }
        }
 
-       /* HELO succeeded, now try the MAIL From: command */
+       /* Do an AUTH command if necessary */
+       if (strlen(mx_user) > 0) {
+               sprintf(buf, "%s%c%s%c%s%c", mx_user, 0, mx_user, 0, mx_pass, 0);
+               CtdlEncodeBase64(mailfrom, buf, strlen(mx_user) + strlen(mx_user) + strlen(mx_pass) + 3);
+               snprintf(buf, sizeof buf, "AUTH PLAIN %s\r\n", mailfrom);
+               lprintf(CTDL_DEBUG, ">%s", buf);
+               sock_write(sock, buf, strlen(buf));
+               if (ml_sock_gets(sock, buf) < 0) {
+                       *status = 4;
+                       strcpy(dsn, "Connection broken during SMTP AUTH");
+                       goto bail;
+               }
+               lprintf(CTDL_DEBUG, "<%s\n", buf);
+               if (buf[0] != '2') {
+                       if (buf[0] == '4') {
+                               *status = 4;
+                               safestrncpy(dsn, &buf[4], 1023);
+                               goto bail;
+                       }
+                       else {
+                               *status = 5;
+                               safestrncpy(dsn, &buf[4], 1023);
+                               goto bail;
+                       }
+               }
+       }
+
+       /* previous command succeeded, now try the MAIL From: command */
        snprintf(buf, sizeof buf, "MAIL From: <%s>\r\n", mailfrom);
        lprintf(CTDL_DEBUG, ">%s", buf);
        sock_write(sock, buf, strlen(buf));