ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libspf/patches/Courier-MTA/courier-0.45.4-spf.diff
Revision: 1.1
Committed: Tue Nov 13 00:51:35 2007 UTC (16 years, 6 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Log Message:
initial import of libspf-1.0.0-p5 from freebsd ports

File Contents

# Content
1 # Angel Fraguela (afraguela@euronippon.es) 2004
2 # For courier-MTA 0.45.4 and libspf.25
3 #
4 # usage
5 # ------
6 # From the directory where courier sources are:
7 # patch -p0 < courier-0.45.4-spf.diff
8 # cd courier-0.45.4
9 # ./confugure --without-ipv6 etc....
10 # make, make install, etc ... (as usual)
11 #
12 # ATTENTION
13 # May work with diferent versions of courier and libspf.
14 #
15 #
16 --- courier-0.45.4/courier/module.esmtp/courieresmtpd.c Sun Feb 1 05:46:28 2004
17 +++ courier-0.45.4-spf/courier/module.esmtp/courieresmtpd.c Mon May 17 14:30:53 2004
18 @@ -2,6 +2,7 @@
19 ** Copyright 1998 - 2002 Double Precision, Inc.
20 ** See COPYING for distribution information.
21 */
22 +#include "spf.h"
23
24 #if HAVE_CONFIG_H
25 #include "config.h"
26 @@ -38,6 +39,7 @@
27 #include "numlib/numlib.h"
28 #include "tcpd/spipe.h"
29 #include "tcpd/tlsclient.h"
30 +
31 static const char rcsid[]="$Id: courier-0.45.4-spf.diff,v 1.1.1.1 2004/08/28 17:53:34 jcouzens Exp $";
32
33 static char helobuf[256];
34 @@ -58,6 +60,7 @@
35 static time_t data_timeout;
36
37 static const char *tcpremoteip, *tcpremotehost;
38 +static int checkspf=0;
39
40 #define INIT_TEERGRUBE 8
41 #define MAX_TEERGRUBE 128
42 @@ -434,21 +437,66 @@
43
44 static int domailfrom(const char *, const char *);
45
46 +
47 +static int spfquery(const char* from, const char* ip, const char* helo){
48 +
49 + //helo - domain ext ...
50 + int res;
51 + char *p=(char*)helo;
52 + char *domain;
53 + peer_info_t* peer_info;
54 +
55 + while ((*p != ' ') && *p) p++;
56 +
57 + domain=(char*)malloc(p-helo);
58 + memcpy(domain,helo,(p-helo)-1);
59 + memset(domain+(p-helo),1,0);
60 +
61 + peer_info = SPF_init("courier-mta", ip, NULL, NULL, NULL, FALSE, FALSE);
62 + SPF_smtp_helo(peer_info, domain);
63 + SPF_smtp_from(peer_info, from);
64 + peer_info->RES = SPF_policy_main(peer_info);
65 + res = peer_info->RES;
66 +
67 + SPF_close(peer_info);
68 +
69 + free(domain);
70 + return res;
71 +}
72 +
73 +
74 static int mailfrom(const char *p)
75 {
76 -const char *q=skipaddress(&p);
77 + const char *q=skipaddress(&p);
78 + char *addr;
79
80 set_submit_error(0, 0);
81 if (q)
82 {
83 /* Save <address> in mailfroms */
84
85 - if (mailfroms) free(mailfroms);
86 - mailfroms=courier_malloc(q-p+3);
87 - memcpy(mailfroms, p-1, q-p+2);
88 - mailfroms[q-p+2]=0;
89 - set_submit_error(0, 0);
90 - return (domailfrom(p, q));
91 + if (mailfroms)
92 + free(mailfroms);
93 +
94 + mailfroms=courier_malloc(q-p+3);
95 + memcpy(mailfroms, p-1, q-p+2);
96 + mailfroms[q-p+2]=0;
97 + set_submit_error(0, 0);
98 +
99 + if(checkspf == 1){
100 + addr=(char*)malloc(q-p);
101 + memcpy(addr, p+1, (q-p)-1);
102 + memset(addr+(q-p),1,0);
103 +
104 + if( spfquery(addr,tcpremoteip, helobuf) > 1 ){
105 + // 0=ok, 1=no spf support in dns, else ERROR
106 + addiovec_error(NULL, "513 Relaying denied - Probably SPAM.");
107 + return -1;
108 + }
109 + free(addr);
110 + }
111 +
112 + return (domailfrom(p, q));
113 }
114 addiovec_error(NULL, "554 Syntax error - your mail software violates RFC 821.");
115 return (-1);
116 @@ -467,6 +515,7 @@
117 hasverp=0;
118 hasstarttls=0;
119
120 +
121 for (r=q+1; *r; r++)
122 {
123 if (isspace((int)(unsigned char)*r)) continue;
124 @@ -932,7 +981,8 @@
125 ** When called via -bs to sendmail, dump log to /dev/null via stderr,
126 ** else record everything via syslog.
127 */
128 -
129 + checkspf=atoi(getenv("BOFCHECKSPF"));
130 +
131 if (chdir(courierdir()))
132 clog_msg_errno();
133
134 @@ -1040,7 +1090,6 @@
135
136 *p=toupper(*p);
137 }
138 -
139 if (strcmp(line, "QUIT") == 0) break;
140 if ((strncmp(line, "EHLO ", 5) == 0 ||
141 strncmp(line, "HELO ", 5) == 0) &&
142 --- courier-0.45.4/courier/module.esmtp/Makefile.in Sun Feb 1 05:49:10 2004
143 +++ courier-0.45.4-spf/courier/module.esmtp/Makefile.in Sat May 15 20:32:07 2004
144 @@ -83,7 +83,7 @@
145 LIBDL = @LIBDL@
146 LIBGDBM = @LIBGDBM@
147 LIBOBJS = @LIBOBJS@
148 -LIBS = @LIBS@
149 +LIBS = @LIBS@ -lspf
150 LIBTOOL = @LIBTOOL@
151 LN_S = @LN_S@
152 LTLIBOBJS = @LTLIBOBJS@
153 --- courier-0.45.4/courier/module.esmtp/esmtpd.dist.in Sun Feb 1 05:46:28 2004
154 +++ courier-0.45.4-spf/courier/module.esmtp/esmtpd.dist.in Sun May 16 20:44:40 2004
155 @@ -39,6 +39,13 @@
156
157 BOFHCHECKDNS=1
158
159 +##NAME: BOFHCHECKSPF:0
160 +#
161 +# Comment out the following line in order to accept mail with a bad
162 +# return address.
163 +
164 +BOFHCHECKSPF=1
165 +
166 ##NAME: BOFHNOEXPN:1
167 #
168 # Set BOFHNOEXP to 1 to disable EXPN