Sam and anybody interested,
rfc3848 compliant "with" clause,
opaque authentication address in Received, and
trailing spaces on SMTP commands.
*rfc3848 compliant "with" clause*
This is the use of "ESMTP", "ESMTPA", "ESMTPS", "ESMTPSA" instead of
the module name in Received lines. Complying with a standard may
improve clarity. For example, SpamAssassin can cope with non-standard
Received lines, such as Courier, but then would fail to match in those
rare cases where an IDENT id is also present besides the AUTH.
*opaque authentication address in Received*
This is the "AUTH: [email protected]" snippet of the Received line.
This patch provides an option to avoid disclosing that address, by
reusing the /fullname/ field, that is not otherwise used in STMP-AUTH.
Before enabling this option, the relevant auth modules have to be
configured so as to fill this field with an ASCII token, e.g. the
record number. Possibly, users concerned with privacy never filled
that field anyway. At any rate, some modules allow to select
different data according to the service. When the option is enabled,
invalid fullname values cause a fall back to the address and a log line.
*trailing spaces on SMTP commands*
It is known that some clients write "DATA " and "QUIT ". The reason
to fix Courier rather than those buggy clients is that they may be
installed on cameras or similar devices that don't provide for easy
upgrades. The patch discards all trailing whitespace received on the
command. I can see no cases where trailing spaces may be relevant; if
there are any, we should file an errata for rfc5321.
--
--- ./courier/module.esmtp/esmtpd.dist.original.in 2010-04-11
21:20:29.000000000 +0200
+++ ./courier/module.esmtp/esmtpd.dist.in 2010-10-10 17:33:37.000000000
+0200
@@ -72,6 +72,19 @@
NOADDDATE=1
+##NAME: NOAUTHADDRINRECEIVED:0
+#
+# Normally, Courier reports AUTH and IDENT details in Received lines,
+# thereby disclosing the address used for authentication. Setting this
+# variable to 1, the user's fullname is set instead of the address.
+# NOTE: for this to work, the fullname field (at least for service "esmtpd")
+# MUST BE COMPOSED OF ALPHANUMERIC ASCII, "@", "-", and "." CHARS ONLY.
+# In case a fullname does not satisfy that requirement, the address will be
+# used instead. The authentication library setup may need to be revised in
+# order to return a suitable opaque token in this case.
+
+NOAUTHADDRINRECEIVED=0
+
##NAME: ESMTP_LOG_DIALOG:0
#
# If set, log the esmtp dialog.
--- ./courier/submit.original.C 2009-02-22 17:24:25.000000000 +0100
+++ ./courier/submit.C 2010-10-10 13:29:29.000000000 +0200
@@ -61,6 +61,8 @@
const char *authname=0;
+static const char *rfc3848_receivedwith=0;
+
const char *msgsource=0;
int suppressbackscatter=0;
@@ -79,6 +81,7 @@
{"src", &msgsource},
{"delay", &submitdelay},
{"auth", &authname},
+ {"rfc3848", &rfc3848_receivedwith},
{0}
} ;
@@ -1566,9 +1569,13 @@
line += config_me();
line += " with ";
-
- line += mf->module->name;
+
+ if (rfc3848_receivedwith && *rfc3848_receivedwith)
+ line += rfc3848_receivedwith;
+ else
+ line += mf->module->name;
line += "; ";
+
line += rfc822_mkdate(submit_time);
// Add unique id here.
--- ./courier/module.esmtp/courieresmtpd.original.c 2010-02-02
23:30:00.000000000 +0100
+++ ./courier/module.esmtp/courieresmtpd.c 2010-10-11 10:21:26.000000000
+0200
@@ -44,7 +44,10 @@
static const char rcsid[]="$Id: courieresmtpd.c,v 1.57 2010/02/02 22:30:00
mrsam Exp $";
static char helobuf[256];
-static char authuserbuf[256];
+static char authuserbuf[320];
+static struct authuserbufinfo /* content reliable if authuserbuf[0] != 0 */
+ { char *va, *address, *fullname; } authuserbufinfo;
+static int extended;
static char tlsbuf[128+NUMBUFSIZE];
static unsigned long sizelimit;
@@ -146,8 +149,7 @@
} while (*banner);
}
-static void ehlo(const char *heloname, int hastls, int tls,
- int extended)
+static void ehlo(const char *heloname, int hastls, int tls)
{
static const char e[]=
COURIER_EXTENSIONS
@@ -287,12 +289,18 @@
fclose(fromsubmit);
}
+static int noauthaddrinreceived(void)
+{
+ static char *noaddr = getenv("NOAUTHADDRINRECEIVED");
+ return noaddr && *noaddr == '1';
+}
+
static void startsubmit(int tls)
{
-char *argv[13];
+char *argv[14];
const char *ident;
char *identbuf=0;
-int n;
+int n, exid_ndx = 0;
const char *host;
char *buf;
@@ -303,22 +311,30 @@
argv[1]=getenv("RELAYCLIENT") ? "-src=authsmtp":"-src=smtp";
n=2;
- if (authuserbuf[0])
+ if (authuserbuf[0] && *authuserbufinfo.address)
{
- char *p;
-
static char authbuf[sizeof(authuserbuf)+sizeof("-auth=")];
+ strcat(strcpy(authbuf, "-auth="), authuserbufinfo.address);
+ argv[n++]=authbuf;
+ exid_ndx = 1;
+ }
- p=strchr(authuserbuf, ' ');
- if (p)
- {
- strcat(strcpy(authbuf, "-auth="), p+1);
- argv[n++]=authbuf;
- }
+ /* pass additional rfc3848 "with" identifier */
+ if (extended)
+ {
+ static char *exid[] = {"ESMTP", "ESMTPA", "ESMTPS", "ESMTPSA"};
+
+ if (tls) exid_ndx += 2;
+ buf = exid[exid_ndx];
}
+ else
+ buf="SMTP";
+ argv[n++]=strcat(strcpy(
+ courier_malloc(sizeof("-rfc3848=") + strlen(buf)),
+ "-rfc3848="), buf);
argv[n++]="esmtp";
-
+
host=tcpremotehost;
if (!host) host="";
@@ -340,7 +356,7 @@
argv[n]=identbuf=courier_malloc(sizeof("IDENT: , AUTH: , ")+
strlen(tlsbuf)+
strlen(ident)+
- strlen(authuserbuf));
+ sizeof(authuserbuf));
++n;
*identbuf=0;
if (*ident)
@@ -348,12 +364,23 @@
if (authuserbuf[0])
{
if (*identbuf) strcat(identbuf, ", ");
- strcat(strcat(identbuf, "AUTH: "), authuserbuf);
- putenv(strcat(
+ strcat(strcat(identbuf, "AUTH: "), authuserbufinfo.va);
+
+ strcat(strcat(identbuf, " "),
+ noauthaddrinreceived()?
+ authuserbufinfo.fullname:
+ authuserbufinfo.address);
+
+ putenv(strcat(strcat(strcat(
strcpy(
courier_malloc(sizeof("SENDERAUTH=") +
- strlen(authuserbuf)),
- "SENDERAUTH="), authuserbuf));
+ strlen(authuserbufinfo.va) +
+ 1 +
+
strlen(authuserbufinfo.address)),
+ "SENDERAUTH="),
+ authuserbufinfo.va),
+ " "),
+ authuserbufinfo.address));
}
if (tls)
@@ -951,20 +978,66 @@
static int auth_callback_func(struct authinfo *a, void *va)
{
- char *p;
+ char *p = &authuserbuf[0], *q;
+ size_t left = sizeof(authuserbuf), len;
+ int ch;
+
+ /* va is the authmetod, already validated by successful sasl */
+ *p = 0;
+ authuserbufinfo.va = p =
+ strncat(p, va? (const char *)va: "", 20);
+ len = strlen(p) + 1;
+ p += len;
+ left -= len;
+ *p = 0;
+
+ /* address, the original function checks > ' ' and != 127 */
+ authuserbufinfo.address = p = q =
+ strncat(p, a->address? a->address: "", left - 10);
+ len = strlen(p) + 1;
+ p += len;
+ left -= len;
+ *p = 0;
+ for (; *q; q++)
+ if ((int)(unsigned char)*q < ' ' || *q >= 127)
+ *q=' ';
+
+ /* check fullname is an acceptable token, otherwise use address */
+ authuserbufinfo.fullname = p =
+ strncat(p, a->fullname? a->fullname: "", left - 1);
+
+ for (; (ch = *(unsigned char*)p) != 0; ++p)
+ if (!(isalnum(ch) || strchr("@-.", ch)))
+ break;
+
+ if (ch != 0 || p == authuserbufinfo.fullname)
+ {
+ if (noauthaddrinreceived())
+ {
+ clog_msg_start_info();
+ clog_msg_str("discard fullname ");
+ clog_msg_str(authuserbufinfo.fullname);
+ clog_msg_str(" and use address ");
+ clog_msg_str(authuserbufinfo.address);
+ clog_msg_send();
+ }
+ authuserbufinfo.fullname = authuserbufinfo.address;
+ }
- strcpy(authuserbuf, "");
- strncat(authuserbuf, (const char *)va, 20);
- strcat(authuserbuf, " ");
- strncat(authuserbuf, a->address,
- sizeof(authuserbuf)-10-strlen(a->address));
-
- for (p=authuserbuf; *p; p++)
- if ((int)(unsigned char)*p < ' ' || *p >= 127)
- *p=' ';
return 0;
}
+static char *rtrim(char *s)
+{
+ char *end = s + strlen(s);
+ while (s < end)
+ if (isspace(*(unsigned char*)--end))
+ *end = 0;
+ else
+ break;
+ return s;
+}
+
/*****************************************************************************
courieresmtpd can be started in two situations:
@@ -1117,12 +1190,15 @@
*p=toupper(*p);
}
+ rtrim(line);
+
if (strcmp(line, "QUIT") == 0) break;
if ((strncmp(line, "EHLO ", 5) == 0 ||
strncmp(line, "HELO ", 5) == 0) &&
line[5])
{
- ehlo(line+5, starttls, tls, line[0] == 'E');
+ extended = line[0] == 'E';
+ ehlo(line+5, starttls, tls);
iovflush();
cancelsubmit();
startsubmit(tls);
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3.
Spend less time writing and rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
courier-users mailing list
[email protected]
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users