View | Details | Raw Unified | Return to bug 239334 | Differences between
and this patch

Collapse All | Expand All

(-)Makefile (-3 / +6 lines)
Lines 15-21 Link Here
15
15
16
MAKE_JOBS_UNSAFE=	yes
16
MAKE_JOBS_UNSAFE=	yes
17
17
18
USES=		tar:tgz
18
USES=		tar:tgz autoreconf
19
19
20
##
20
##
21
# Use the following quirks to choose which sendmail to use (ports or system):
21
# Use the following quirks to choose which sendmail to use (ports or system):
Lines 28-37 Link Here
28
# installed port preference over it.
28
# installed port preference over it.
29
##
29
##
30
30
31
OPTIONS_DEFINE=		DKIM SPF CURL LDAP P0F POSTFIX DOCS EXAMPLES
31
OPTIONS_DEFINE=		DKIM SPF MAXMINDDB CURL LDAP P0F POSTFIX DOCS EXAMPLES
32
OPTIONS_DEFAULT=	DKIM SPF CURL
32
OPTIONS_DEFAULT=	DKIM SPF MAXMINDDB
33
DKIM_DESC=		DKIM support
33
DKIM_DESC=		DKIM support
34
SPF_DESC=		SPF support
34
SPF_DESC=		SPF support
35
MAXMINDDB_DESC=		Enable GeoIP1 + GeoIP2 Support
35
CURL_DESC=		curl support
36
CURL_DESC=		curl support
36
P0F_DESC=		P0F support
37
P0F_DESC=		P0F support
37
POSTFIX_DESC=		Use Postfix instead of Sendmail
38
POSTFIX_DESC=		Use Postfix instead of Sendmail
Lines 39-44 Link Here
39
DKIM_LIB_DEPENDS=	libopendkim.so:mail/opendkim
40
DKIM_LIB_DEPENDS=	libopendkim.so:mail/opendkim
40
P0F_RUN_DEPENDS=	p0f:net-mgmt/p0f
41
P0F_RUN_DEPENDS=	p0f:net-mgmt/p0f
41
SPF_LIB_DEPENDS=	libspf2.so:mail/libspf2
42
SPF_LIB_DEPENDS=	libspf2.so:mail/libspf2
43
MAXMINDDB_LIB_DEPENDS=	libmaxminddb.so:net/libmaxminddb
42
CURL_LIB_DEPENDS=	libcurl.so:ftp/curl
44
CURL_LIB_DEPENDS=	libcurl.so:ftp/curl
43
45
44
POSTFIX_CONFIGURE_ENABLE=	postfix
46
POSTFIX_CONFIGURE_ENABLE=	postfix
Lines 50-55 Link Here
50
DKIM_CONFIGURE_ON=		--with-libopendkim=${LOCALBASE}
52
DKIM_CONFIGURE_ON=		--with-libopendkim=${LOCALBASE}
51
DKIM_USES=			ssl
53
DKIM_USES=			ssl
52
SPF_CONFIGURE_ON=		--with-libspf2=${LOCALBASE}
54
SPF_CONFIGURE_ON=		--with-libspf2=${LOCALBASE}
55
MAXMINDDB_CONFIGURE_ON=		--with-libmaxminddb=${LOCALBASE}
53
CURL_CONFIGURE_ON=		--with-libcurl=${LOCALBASE}
56
CURL_CONFIGURE_ON=		--with-libcurl=${LOCALBASE}
54
LDAP_CONFIGURE_ON=		--with-openldap=${LOCALBASE}
57
LDAP_CONFIGURE_ON=		--with-openldap=${LOCALBASE}
55
LDAP_LDFLAGS=			-L${LOCALBASE}/lib
58
LDAP_LDFLAGS=			-L${LOCALBASE}/lib
(-)files/patch-configure (-12 lines)
Lines 1-12 Link Here
1
Index: configure
2
--- configure.orig	2016-07-12 03:09:29 UTC
3
+++ configure
4
@@ -6083,7 +6083,7 @@ if test "${ac_cv_lib_pthread_pthread_cre
5
   $as_echo_n "(cached) " >&6
6
 else
7
   ac_check_lib_save_LIBS=$LIBS
8
-LIBS="-lpthread  $LIBS"
9
+true; #LIBS="-lpthread  $LIBS"
10
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
11
 /* end confdefs.h.  */
12
 
(-)files/patch-libmaxminddb-support_from_GH-geoip2-fork (+240 lines)
Line 0 Link Here
1
--- README
2
+++ README
3
@@ -60,7 +60,7 @@ Build dependencies:
4
 Optional dependencies: 
5
 - libspf2, libspf_alt or libspf, for SPF support
6
 - libcurl, for URL checks support
7
-- libGeoIP, for GeoIP support
8
+- libmaxminddb, for GeoIP2 support
9
 - libbind from BIND 9, for DNSRBL support, except if your system has a 
10
   thread-safe DNS resolver built-in.
11
 
12
--- conf_yacc.y
13
+++ conf_yacc.y
14
@@ -57,7 +57,7 @@ __RCSID("$Id: conf_yacc.y,v 1.129 2016/11/24 04:11:37 manu Exp $");
15
 #endif
16
 #include "prop.h"
17
 #ifdef USE_GEOIP
18
-#include "geoip.h"
19
+#include "maxminddb.h"
20
 #endif
21
 #ifdef USE_P0F
22
 #include "p0f.h"
23
@@ -149,7 +149,6 @@ lines	:	lines netblock '\n'
24
 	|	lines socket '\n'
25
 	|	lines user '\n'
26
 	|	lines geoipdb '\n'
27
-	|	lines geoipv6db '\n'
28
 	|	lines nodetach '\n'
29
 	|	lines lazyaw '\n'
30
 	|	lines report '\n'
31
@@ -772,19 +771,6 @@ geoipdb:	GEOIPDB QSTRING	{
32
 #endif
33
 				}
34
 	;
35
-geoipv6db:	GEOIPV6DB QSTRING	{
36
-#ifdef USE_GEOIP
37
-				char path[QSTRLEN + 1];
38
-
39
-				geoip_set_db_v6(quotepath(path, $2, QSTRLEN));
40
-#else
41
-				mg_log(LOG_INFO, 
42
-				    "GeoIP support not compiled in, "
43
-				    "ignore line %d", 
44
-				    conf_line);
45
-#endif
46
-				}
47
-	;
48
 report:		REPORT NONE	{ conf.c_report = C_GLNONE; }
49
 	|	REPORT DELAYS	{ conf.c_report = C_DELAYS; }
50
 	|	REPORT NODELAYS	{ conf.c_report = C_NODELAYS; }
51
--- configure.ac
52
+++ configure.ac
53
@@ -455,10 +455,10 @@ LDFLAGS=$SAVEDLDFLAGS
54
 CFLAGS=$SAVEDCFLAGS
55
 LIBS=$SAVEDLIBS
56
 
57
-AC_ARG_WITH(libGeoIP, 
58
-	[  --with-libGeoIP=DIR  Find libGeoIP in DIR],
59
+AC_ARG_WITH(libmaxminddb, 
60
+	[  --with-libmaxminddb=DIR  Find GeoIP2 libmaxminddb in DIR],
61
 	[CFLAGS=$CFLAGS" -I$withval/include -DUSE_GEOIP" 
62
-	    LIBS="-lGeoIP $LIBS"
63
+	    LIBS="-lmaxminddb $LIBS"
64
 	    LDFLAGS=$LDFLAGS" -L$withval/lib -Wl,$rpath$withval/lib"])
65
 AC_ARG_WITH(libdmalloc,
66
 	[  --with-libdmalloc=DIR  Find libdmalloc in DIR],
67
--- greylist.conf.5
68
+++ greylist.conf.5
69
@@ -198,8 +198,6 @@ is used when the country cannot be determined (this happens for private
70
 addresses, for instance). The 
71
 .I geoipdb 
72
 statement can be used to specify the location of GeoIP database. 
73
-.I geoipv6db
74
-statement can be used to specify the location of GeoIPv6 database.
75
 .TP
76
 .I p0f
77
 This is used to match against the remote system OS fingerprint genre and
78
--- milter-greylist.spec
79
+++ milter-greylist.spec
80
@@ -19,8 +19,8 @@
81
 %define libspf2 0
82
 %{?build_libspf2:%define libspf2 1}
83
 
84
-%define libGeoIP 0
85
-%{?build_libGeoIP:%define libGeoIP 1}
86
+%define libmaxminddb 0
87
+%{?build_libmaxminddb:%define libmaxminddb 1}
88
 
89
 %define libcurl 0
90
 %{?build_libcurl:%define libcurl 1}
91
@@ -66,8 +66,8 @@ BuildRequires: libspf2-devel
92
 %if %{libcurl}
93
 BuildRequires: curl-devel
94
 %endif
95
-%if %{libGeoIP}
96
-BuildRequires: GeoIP-devel
97
+%if %{libmaxminddb}
98
+BuildRequires: libmaxminddb-devel
99
 %endif
100
 
101
 %description
102
@@ -111,8 +111,8 @@ before the second attempt.
103
 %if %{libcurl}
104
 	--with-libcurl \
105
 %endif
106
-%if %{libGeoIP}
107
-	--with-libGeoIP \
108
+%if %{libmaxminddb}
109
+	--with-libmaxminddb \
110
 %endif
111
 %if %{libdkim}
112
         --with-libdkim=/usr/include \
113
--- geoip.c.orig	2016-11-24 04:11:37.000000000 +0000
114
+++ geoip.c	2019-07-20 10:40:23.804734000 +0000
115
@@ -48,7 +48,7 @@
116
 #include <sysexits.h>
117
 #include <sys/param.h>
118
 
119
-#include <GeoIP.h>
120
+#include <maxminddb.h>
121
 
122
 #include "milter-greylist.h"
123
 #include "conf.h"
124
@@ -58,10 +58,9 @@
125
 #include <dmalloc.h> 
126
 #endif
127
 
128
-static GeoIP *geoip_handle = NULL;
129
-static GeoIP *geoip_handle_v6 = NULL;
130
+static MMDB_s mmdb;
131
+static MMDB_s *geoip_handle = &mmdb;
132
 static char geoip_database[MAXPATHLEN + 1];
133
-static char geoip_database_v6[MAXPATHLEN + 1];
134
 static pthread_rwlock_t geoip_lock;
135
 
136
 void
137
@@ -83,43 +82,21 @@
138
 	char *name;
139
 {
140
 	if (geoip_handle != NULL) {
141
-		GeoIP_delete(geoip_handle);
142
-		geoip_handle = NULL;
143
+		MMDB_close(geoip_handle);
144
 	}
145
 	
146
 	strncpy(geoip_database, name, MAXPATHLEN);
147
 	geoip_database[MAXPATHLEN] = '\0';
148
 
149
-	geoip_handle = GeoIP_open(geoip_database, GEOIP_STANDARD);
150
-	if (geoip_handle == NULL) {
151
+	int status = MMDB_open(geoip_database, MMDB_MODE_MMAP, geoip_handle);
152
+	if (status != MMDB_SUCCESS) {
153
 		mg_log(LOG_WARNING, 
154
-		    "GeoIP databade \"%s\" cannot be used",
155
+		    "GeoIP database \"%s\" cannot be used",
156
 		    geoip_database);
157
 		return;
158
 	}
159
 }
160
 
161
-void
162
-geoip_set_db_v6(name)
163
-	char *name;
164
-{
165
-	if (geoip_handle_v6 != NULL) {
166
-		GeoIP_delete(geoip_handle_v6);
167
-		geoip_handle_v6 = NULL;
168
-	}
169
-
170
-	strncpy(geoip_database_v6, name, MAXPATHLEN);
171
-	geoip_database_v6[MAXPATHLEN] = '\0';
172
-
173
-	geoip_handle_v6 = GeoIP_open(geoip_database_v6, GEOIP_STANDARD);
174
-	if (geoip_handle_v6 == NULL) {
175
-		mg_log(LOG_WARNING,
176
-		    "GeoIPv6 databade \"%s\" cannot be used",
177
-		    geoip_database_v6);
178
-		return;
179
-	}
180
-}
181
-
182
 int
183
 geoip_filter(ad, stage, ap, priv)
184
 	acl_data_t *ad;
185
@@ -142,33 +119,9 @@
186
 geoip_set_ccode(priv)
187
 	struct mlfi_priv *priv;
188
 {
189
-	GEOIP_API const char *(*country_code_by_addr)(GeoIP *, const char *);
190
-	GeoIP *handle;
191
 	char ipstr[IPADDRSTRLEN];
192
+        int gai_error, mmdb_error;
193
 
194
-	switch (SA(&priv->priv_addr)->sa_family) {
195
-	case AF_INET:
196
-		country_code_by_addr = GeoIP_country_code_by_addr;
197
-		handle = geoip_handle;
198
-		break;
199
-#ifdef AF_INET6
200
-	case AF_INET6:
201
-		country_code_by_addr = GeoIP_country_code_by_addr_v6;
202
-		handle = geoip_handle_v6;
203
-		break;
204
-#endif
205
-	default:
206
-		mg_log(LOG_DEBUG, "GeoIP not supported address family");
207
-		priv->priv_ccode = NULL;
208
-		return;
209
-	}
210
-
211
-	if (geoip_handle == NULL) {
212
-		mg_log(LOG_DEBUG, "GeoIP is not available");
213
-		priv->priv_ccode = NULL;
214
-		return;
215
-	}
216
-
217
 	if (iptostring(SA(&priv->priv_addr),
218
 	    priv->priv_addrlen, ipstr, sizeof(ipstr)) == NULL) {
219
 		mg_log(LOG_DEBUG, "GeoIP iptostring failed");
220
@@ -177,7 +130,19 @@
221
 	}
222
 
223
 	WRLOCK(geoip_lock);
224
-	priv->priv_ccode = country_code_by_addr(handle, ipstr);
225
+	MMDB_lookup_result_s result = MMDB_lookup_string(geoip_handle, ipstr, &gai_error, &mmdb_error);
226
+	if (gai_error == 0) {
227
+		if (mmdb_error == MMDB_SUCCESS) {
228
+			MMDB_entry_data_s entry_data;
229
+			int status = MMDB_get_value(&result.entry, &entry_data, "country", "iso_code", NULL);
230
+			if (status == MMDB_SUCCESS) {
231
+				if (entry_data.has_data) {
232
+					priv->priv_ccode = strndup(entry_data.utf8_string, entry_data.data_size);
233
+				}
234
+			}
235
+		}
236
+        }
237
+
238
 	UNLOCK(geoip_lock);
239
 
240
 	if (priv->priv_ccode == NULL)

Return to bug 239334