diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-10-20 15:33:36 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-10-20 15:33:36 +0300 |
commit | 19cd80155ca451dbbfabd5f6d7084a6fcc737dbb (patch) | |
tree | 056ec30078928f178f133314c1a72388270c854b /src | |
parent | 5cf28509ada303e8995113af9390d10553c60bef (diff) | |
download | mailfromd-19cd80155ca451dbbfabd5f6d7084a6fcc737dbb.tar.gz mailfromd-19cd80155ca451dbbfabd5f6d7084a6fcc737dbb.tar.bz2 |
Unify DNS reply types.
* lib/dns.h (mxbuf): Remove
(mxbuf_init, mxbuf_free): Remove protos.
(dns_get_mx_records): Remove the maxdepth parameter. Return
MX names in struct dns_reply. All uses changed.
(getmx,getmxip): Return MX names in struct dns_reply. All uses changed.
Diffstat (limited to 'src')
-rw-r--r-- | src/builtin/dns.bi | 43 | ||||
-rw-r--r-- | src/callout.c | 12 | ||||
-rw-r--r-- | src/mailfromd.h | 3 | ||||
-rw-r--r-- | src/prog.c | 10 | ||||
-rw-r--r-- | src/spf.c | 10 |
5 files changed, 33 insertions, 45 deletions
diff --git a/src/builtin/dns.bi b/src/builtin/dns.bi index c23aaf31..f63a2361 100644 --- a/src/builtin/dns.bi +++ b/src/builtin/dns.bi | |||
@@ -149,17 +149,16 @@ END | |||
149 | 149 | ||
150 | MF_DEFUN(primitive_hasmx, NUMBER, STRING string) | 150 | MF_DEFUN(primitive_hasmx, NUMBER, STRING string) |
151 | { | 151 | { |
152 | struct mxbuf mxbuf; | 152 | struct dns_reply repl; |
153 | mf_status mxstat; | 153 | mf_status mxstat; |
154 | 154 | ||
155 | mxbuf.mx_flags = 0; | 155 | mxstat = getmx(string, &repl); |
156 | mxstat = getmx(string, &mxbuf); | ||
157 | 156 | ||
158 | MF_ASSERT(mxstat == mf_success || mxstat == mf_not_found, | 157 | MF_ASSERT(mxstat == mf_success || mxstat == mf_not_found, |
159 | mf_status_to_exception(mxstat), | 158 | mf_status_to_exception(mxstat), |
160 | _("cannot get MX records for %s"), | 159 | _("cannot get MX records for %s"), |
161 | string); | 160 | string); |
162 | mxbuf_free(&mxbuf); | 161 | dns_reply_free(&repl); |
163 | if (mxstat == mf_success) { | 162 | if (mxstat == mf_success) { |
164 | MF_RETURN(1); | 163 | MF_RETURN(1); |
165 | } | 164 | } |
@@ -170,12 +169,10 @@ END | |||
170 | MF_DEFUN(getmx, STRING, STRING domain, OPTIONAL, NUMBER no_resolve) | 169 | MF_DEFUN(getmx, STRING, STRING domain, OPTIONAL, NUMBER no_resolve) |
171 | { | 170 | { |
172 | mf_status mxstat; | 171 | mf_status mxstat; |
172 | struct dns_reply repl; | ||
173 | 173 | ||
174 | if (MF_OPTVAL(no_resolve)) { | 174 | if (MF_OPTVAL(no_resolve)) { |
175 | GACOPYZ_UINT32_T *ipbuf; | 175 | mxstat = getmxip(domain, &repl); |
176 | size_t ipcount; | ||
177 | |||
178 | mxstat = getmxip(domain, &ipbuf, &ipcount); | ||
179 | if (!mf_resolved(mxstat)) { | 176 | if (!mf_resolved(mxstat)) { |
180 | MF_THROW(mf_status_to_exception(mxstat), | 177 | MF_THROW(mf_status_to_exception(mxstat), |
181 | _("cannot get MX records for %s"), domain); | 178 | _("cannot get MX records for %s"), domain); |
@@ -186,41 +183,37 @@ MF_DEFUN(getmx, STRING, STRING domain, OPTIONAL, NUMBER no_resolve) | |||
186 | int i; | 183 | int i; |
187 | 184 | ||
188 | MF_OBSTACK_BEGIN(); | 185 | MF_OBSTACK_BEGIN(); |
189 | for (i = 0; i < ipcount; i++) { | 186 | for (i = 0; i < repl.count; i++) { |
190 | struct in_addr s; | 187 | struct in_addr s; |
191 | s.s_addr = htonl(ipbuf[i]); | 188 | s.s_addr = htonl(repl.data.ip[i]); |
192 | 189 | ||
193 | if (i > 0) | 190 | if (i > 0) |
194 | MF_OBSTACK_1GROW(' '); | 191 | MF_OBSTACK_1GROW(' '); |
195 | MF_OBSTACK_GROW(inet_ntoa(s)); | 192 | MF_OBSTACK_GROW(inet_ntoa(s)); |
196 | } | 193 | } |
197 | free(ipbuf); | ||
198 | MF_OBSTACK_1GROW(0); | 194 | MF_OBSTACK_1GROW(0); |
195 | dns_reply_free(&repl); | ||
199 | MF_RETURN_OBSTACK(); | 196 | MF_RETURN_OBSTACK(); |
200 | } | 197 | } |
201 | } else { | 198 | } else { |
202 | struct mxbuf mxbuf; | 199 | mxstat = getmx(domain, &repl); |
203 | |||
204 | mxstat = getmx(domain, &mxbuf); | ||
205 | if (!mf_resolved(mxstat)) { | 200 | if (!mf_resolved(mxstat)) { |
206 | mxbuf_free(&mxbuf); | ||
207 | MF_THROW(mf_status_to_exception(mxstat), | 201 | MF_THROW(mf_status_to_exception(mxstat), |
208 | _("cannot get MX records for %s"), domain); | 202 | _("cannot get MX records for %s"), domain); |
209 | } | 203 | } |
210 | if (mxstat == mf_not_found) { | 204 | if (mxstat == mf_not_found) { |
211 | mxbuf_free(&mxbuf); | ||
212 | MF_RETURN(""); | 205 | MF_RETURN(""); |
213 | } else { | 206 | } else { |
214 | int i; | 207 | int i; |
215 | 208 | ||
216 | MF_OBSTACK_BEGIN(); | 209 | MF_OBSTACK_BEGIN(); |
217 | for (i = 0; i < mxbuf.mx_cnt; i++) { | 210 | for (i = 0; i < repl.count; i++) { |
218 | if (i > 0) | 211 | if (i > 0) |
219 | MF_OBSTACK_1GROW(' '); | 212 | MF_OBSTACK_1GROW(' '); |
220 | MF_OBSTACK_GROW(mxbuf.mx_buf[i]); | 213 | MF_OBSTACK_GROW(repl.data.str[i]); |
221 | } | 214 | } |
222 | MF_OBSTACK_1GROW(0); | 215 | MF_OBSTACK_1GROW(0); |
223 | mxbuf_free(&mxbuf); | 216 | dns_reply_free(&repl); |
224 | MF_RETURN_OBSTACK(); | 217 | MF_RETURN_OBSTACK(); |
225 | } | 218 | } |
226 | } | 219 | } |
@@ -256,8 +249,7 @@ resolve_host(const char *string, unsigned long *ip) | |||
256 | 249 | ||
257 | MF_DEFUN(primitive_ismx, NUMBER, STRING domain, STRING ipstr) | 250 | MF_DEFUN(primitive_ismx, NUMBER, STRING domain, STRING ipstr) |
258 | { | 251 | { |
259 | GACOPYZ_UINT32_T *ipbuf; | 252 | struct dns_reply reply; |
260 | size_t ipcount; | ||
261 | mf_status mxstat; | 253 | mf_status mxstat; |
262 | unsigned long ip; | 254 | unsigned long ip; |
263 | int rc = 0; | 255 | int rc = 0; |
@@ -267,21 +259,20 @@ MF_DEFUN(primitive_ismx, NUMBER, STRING domain, STRING ipstr) | |||
267 | _("cannot resolve host name %s"), ipstr); | 259 | _("cannot resolve host name %s"), ipstr); |
268 | ip = ntohl(ip); | 260 | ip = ntohl(ip); |
269 | 261 | ||
270 | mxstat = getmxip(domain, &ipbuf, &ipcount); | 262 | mxstat = getmxip(domain, &reply); |
271 | 263 | ||
272 | if (mxstat != mf_success) { | 264 | if (mxstat != mf_success) { |
273 | MF_THROW(mf_status_to_exception(mxstat), | 265 | MF_THROW(mf_status_to_exception(mxstat), |
274 | _("cannot get MXs for %s"), domain); | 266 | _("cannot get MXs for %s"), domain); |
275 | } | 267 | } |
276 | 268 | ||
277 | for (i = 0; i < ipcount; i++) { | 269 | for (i = 0; i < reply.count; i++) { |
278 | if (ipbuf[i] == ip) { | 270 | if (reply.data.ip[i] == ip) { |
279 | rc = 1; | 271 | rc = 1; |
280 | break; | 272 | break; |
281 | } | 273 | } |
282 | } | 274 | } |
283 | 275 | dns_reply_free(&reply); | |
284 | free(ipbuf); | ||
285 | MF_RETURN(rc); | 276 | MF_RETURN(rc); |
286 | } | 277 | } |
287 | END | 278 | END |
diff --git a/src/callout.c b/src/callout.c index 633a33b7..1d46bc70 100644 --- a/src/callout.c +++ b/src/callout.c | |||
@@ -634,10 +634,10 @@ mf_status | |||
634 | callout_mx(struct smtp_io_data *iop, const char *hostname, int *pcount) | 634 | callout_mx(struct smtp_io_data *iop, const char *hostname, int *pcount) |
635 | { | 635 | { |
636 | int i; | 636 | int i; |
637 | struct mxbuf mxbuf; | 637 | struct dns_reply reply; |
638 | mf_status rc, mxstat; | 638 | mf_status rc, mxstat; |
639 | 639 | ||
640 | mxstat = getmx(hostname, &mxbuf); | 640 | mxstat = getmx(hostname, &reply); |
641 | 641 | ||
642 | if (pcount) | 642 | if (pcount) |
643 | *pcount = 0; | 643 | *pcount = 0; |
@@ -646,20 +646,20 @@ callout_mx(struct smtp_io_data *iop, const char *hostname, int *pcount) | |||
646 | mu_debug(MF_SOURCE_CALLOUT, MU_DEBUG_TRACE1, | 646 | mu_debug(MF_SOURCE_CALLOUT, MU_DEBUG_TRACE1, |
647 | ("Checking MX servers for %s", iop->email)); | 647 | ("Checking MX servers for %s", iop->email)); |
648 | rc = mf_not_found; | 648 | rc = mf_not_found; |
649 | for (i = 0; i < mxbuf.mx_cnt; i++) { | 649 | for (i = 0; i < reply.count; i++) { |
650 | rc = callout_host(iop, mxbuf.mx_buf[i]); | 650 | rc = callout_host(iop, reply.data.str[i]); |
651 | if (mf_resolved(rc)) | 651 | if (mf_resolved(rc)) |
652 | break; | 652 | break; |
653 | } | 653 | } |
654 | if (pcount) | 654 | if (pcount) |
655 | *pcount = mxbuf.mx_cnt; | 655 | *pcount = reply.count; |
656 | dns_reply_free(&reply); | ||
656 | break; | 657 | break; |
657 | 658 | ||
658 | default: | 659 | default: |
659 | rc = mxstat; | 660 | rc = mxstat; |
660 | break; | 661 | break; |
661 | } | 662 | } |
662 | mxbuf_free(&mxbuf); | ||
663 | return rc; | 663 | return rc; |
664 | } | 664 | } |
665 | 665 | ||
diff --git a/src/mailfromd.h b/src/mailfromd.h index 7f21e360..efea11ab 100644 --- a/src/mailfromd.h +++ b/src/mailfromd.h | |||
@@ -75,9 +75,6 @@ mf_status resolve_ipstr_domain(const char *ipstr, const char *domain, | |||
75 | char **phbuf); | 75 | char **phbuf); |
76 | mf_status resolve_hostname(const char *host, char **pipbuf); | 76 | mf_status resolve_hostname(const char *host, char **pipbuf); |
77 | 77 | ||
78 | mf_status getmx(const char *ipstr, struct mxbuf *mxbuf); | ||
79 | mf_status getmxip(char *host, GACOPYZ_UINT32_T **ipbuf, size_t *pcount); | ||
80 | |||
81 | 78 | ||