diff -ruw courier-0.36.1/courier/libs/comctlfile.h courier-0.36.1-export-env/courier/libs/comctlfile.h --- courier-0.36.1/courier/libs/comctlfile.h Sun Apr 15 10:12:54 2001 +++ courier-0.36.1-export-env/courier/libs/comctlfile.h Sun Dec 16 20:33:30 2001 @@ -111,6 +111,12 @@ #define COMCTLFILE_SECURITY 'U' /* +** ENV HACK: Save the environment variables set by the TCPD server in the +** control file so that they can be restored later, during delivery. +*/ +#define COMCTLFILE_ACCESS_ENV 'a' + +/* ** HACK ALERT: We want to log the last line of SMTP replies, ** showing the remote relay that we delivered to, to syslog, but not to the ** message log, because it is not part of the SMTP reply received (and it diff -ruw courier-0.36.1/courier/submit2.C courier-0.36.1-export-env/courier/submit2.C --- courier-0.36.1/courier/submit2.C Thu Nov 29 19:41:24 2001 +++ courier-0.36.1-export-env/courier/submit2.C Mon Dec 17 00:50:38 2001 @@ -400,6 +400,25 @@ if (submitdelay) ctlfile << COMCTLFILE_SUBMITDELAY << submitdelay << endl; + +/* TCPD's smtpaccess environment saving hack. */ +char *accessenv; + accessenv = getenv("ACCESSENV"); + if (accessenv) + { + char *e, *v, *vl, *n; + e = accessenv = strdup(accessenv); + while ((v = strsep(&accessenv, ","))) + { + vl = getenv(v); + if (!vl) continue; + vl = strdup(vl); + while ((n=strchr(vl,'\n'))) *n = '!'; + ctlfile << COMCTLFILE_ACCESS_ENV << v << "=" << vl << endl; + free(vl); + } + free(e); + } ctlfile << flush; } diff -ruw courier-0.36.1/tcpd/tcpd.c courier-0.36.1-export-env/tcpd/tcpd.c --- courier-0.36.1/tcpd/tcpd.c Fri Nov 23 07:00:38 2001 +++ courier-0.36.1-export-env/tcpd/tcpd.c Mon Dec 17 21:37:53 2001 @@ -133,6 +133,7 @@ extern int openaccess(const char *); extern void closeaccess(); extern char *chkaccess(const char *); +static void updateaccessenv(const char *name); static void setup_block(const char *blockinfo) { @@ -920,6 +921,7 @@ while (l=strlen(q)-1, isspace((int)(unsigned char)q[l-1])) q[--l]=0; putenv(q); + updateaccessenv(q); } return (1); } @@ -1198,6 +1200,30 @@ putenv(strcat(strcat(strcpy(p, name), "="), val)); } +static void updateaccessenv(const char *name) +{ +static char *accessenv = NULL; +int namelen; + if (strchr(name,'=')) + namelen=strchr(name,'=') - name; + else + namelen=strlen(name); + if (!accessenv) + { + accessenv = strdup("ACCESSENV="); + } + accessenv = realloc (accessenv, (strlen(accessenv) + namelen + 2)); + if (!accessenv) + { + perror("malloc"); + return (0); + } + if (strlen(accessenv) >= sizeof("ACCESSENV=")) + strcat(accessenv, ","); + strncat(accessenv, name, namelen); + putenv(accessenv); +} + /* ** Convert IP address to host name. Make sure the IP address resolves ** backwards and forwards. @@ -1381,6 +1407,7 @@ rfc1035_rr_gettxt(replyp->allrrs[i], 0, hostname); mysetenv(varname, hostname); + updateaccessenv(varname); } } else @@ -1399,6 +1426,7 @@ RFC1035_CLASS_IN, &replyp)) >= 0) { mkmymsg(varname, p->msg); + updateaccessenv(varname); } } @@ -1470,6 +1498,7 @@ if (pp->msg && *pp->msg) { mkmymsg(vvarname, pp->msg); + updateaccessenv(vvarname); continue; } @@ -1481,8 +1510,13 @@ { rfc1035_rr_gettxt(replyp->allrrs[j], 0, buf); mysetenv(vvarname, buf); + updateaccessenv(vvarname); + } + else + { + mysetenv(vvarname, "Access denied."); + updateaccessenv(vvarname); } - else mysetenv(vvarname, "Access denied."); } } rfc1035_replyfree(replyp);