aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-07-21 14:33:19 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2010-07-21 14:33:19 +0300
commit48c6ea21f359dd1a262c71a79726d29882530ee2 (patch)
tree3fca8d7bf2854ea9a1162065df6baee177b6d33d
parentf5caaa1b756ebb9d30d69fb01b3b65e65ab3e2f4 (diff)
downloadmailfromd-48c6ea21f359dd1a262c71a79726d29882530ee2.tar.gz
mailfromd-48c6ea21f359dd1a262c71a79726d29882530ee2.tar.bz2
Remove hardcoded limits on the number of A and PTR records in DNS replies.
* mfd/main.c (mf_runtime_param_finish): Fix. * doc/functions.texi: Document changes to DNS functions. * doc/mailfromd.texi (conf-runtime): Document max-dns-reply-a and max-dns-reply-ptr. * doc/values.texi (MAX_DNS_A, MAX_DNS_PTR): New values. * mfd/builtin/dns.bi (dns_cfg_param): Define new configuration statements in runtime block: max-dns-reply-a, max-dns-reply-ptr. (dns_getaddr, dns_getname): Do not use hardcoded limits. (MF_INIT): Register new configuration statements.
-rw-r--r--doc/functions.texi10
-rw-r--r--doc/mailfromd.texi12
-rw-r--r--doc/values.texi2
-rw-r--r--mfd/builtin/dns.bi34
-rw-r--r--mfd/main.c2
5 files changed, 48 insertions, 12 deletions
diff --git a/doc/functions.texi b/doc/functions.texi
index 23595f43..51b4a8ff 100644
--- a/doc/functions.texi
+++ b/doc/functions.texi
@@ -1407,16 +1407,18 @@ require dns
@deftypefn {Built-in Function} string dns_getaddr (string @var{domain})
Returns a whitespace-separated list of @acronym{IP} addresses (@code{A}
-records) for @var{domain}. At most 64 addresses are
-returned. @FIXME{This limit should be configurable.}
+records) for @var{domain}. At most @value{MAX_DNS_A} addresses are
+returned. @xref{conf-runtime, max-dns-reply-a}, for a description of how
+to change this limit.
This function does not use the @acronym{DNS} cache.
@end deftypefn
@deftypefn {Built-in Function} string dns_getname (string @var{ipstr})
Returns a whitespace-separated list of domain names (@code{PTR}
-records) for the @acronym{IP}v4 address @var{ipstr}. At most 64 names are
-returned. @FIXME{This limit should be configurable.}
+records) for the @acronym{IP}v4 address @var{ipstr}. At most
+@value{MAX_DNS_PTR} names are returned. @xref{conf-runtime,
+max-dns-reply-ptr}, for a description of how to change this limit.
This function does not use the @acronym{DNS} cache.
@end deftypefn
diff --git a/doc/mailfromd.texi b/doc/mailfromd.texi
index 651ab913..57e2fbb6 100644
--- a/doc/mailfromd.texi
+++ b/doc/mailfromd.texi
@@ -9176,6 +9176,18 @@ using the @code{mailbox_get_message} function. @xref{Message
functions}, for details.
@end deffn
+@deffn {runtime} max-dns-reply-a number
+Sets the maximum number of @acronym{DNS} @samp{A} records to be
+returned in a reply. This affects the @code{dns_getaddr} function
+(@pxref{DNS functions, dns_getaddr}). The default value is @value{MAX_DNS_A}.
+@end deffn
+
+@deffn {runtime} max-dns-reply-ptr number
+Sets the maximum number of @acronym{DNS} @samp{PTR} records to be
+returned in a reply. This affects the @code{dns_getname} function
+(@pxref{DNS functions, dns_getname}). The default value is @value{MAX_DNS_PTR}.
+@end deffn
+
@node conf-mailutils
@section Standard Mailutils Statements
diff --git a/doc/values.texi b/doc/values.texi
index e3007459..6d83ef47 100644
--- a/doc/values.texi
+++ b/doc/values.texi
@@ -14,3 +14,5 @@
@set NSTREAMS 1024
@set NMBOXES 64
@set NMSGS 1024
+@set MAX_DNS_A 64
+@set MAX_DNS_PTR 64
diff --git a/mfd/builtin/dns.bi b/mfd/builtin/dns.bi
index 74842b0a..9f4eed65 100644
--- a/mfd/builtin/dns.bi
+++ b/mfd/builtin/dns.bi
@@ -19,6 +19,17 @@
#include <netdb.h>
#include <arpa/inet.h>
+static size_t max_ptr = 64;
+static size_t max_a = 64;
+static struct mu_cfg_param dns_cfg_param[] = {
+ { "max-dns-reply-a", mu_cfg_size, &max_a, 0, NULL,
+ N_("Maximum number of A records in a DNS reply.") },
+ { "max-dns-reply-ptr", mu_cfg_size, &max_a, 0, NULL,
+ N_("Maximum number of PTR records in a DNS reply.") },
+ { NULL }
+};
+
+
MF_DEFUN(primitive_hostname, STRING, STRING string)
{
char *hbuf;
@@ -70,12 +81,13 @@ ipaddr_cmp(const void *a, const void *b)
MF_DEFUN(dns_getaddr, STRING, STRING string)
{
- GACOPYZ_UINT32_T ipbuf[64]; /* FIXME: arbitrary limit */
+ GACOPYZ_UINT32_T *ipbuf;
size_t i, ipcount;
unsigned long ttl;
dns_status dnstat;
- dnstat = a_lookup(string, ipbuf, NELEMS(ipbuf), &ipcount,
+ ipbuf = xcalloc(max_a, sizeof(ipbuf[0]));
+ dnstat = a_lookup(string, ipbuf, max_a, &ipcount,
&ttl, NULL, 0);
switch (dnstat) {
case dns_success: {
@@ -91,12 +103,15 @@ MF_DEFUN(dns_getaddr, STRING, STRING string)
MF_OBSTACK_1GROW(' ');
MF_OBSTACK_GROW(q);
}
+ free(ipbuf);
MF_OBSTACK_1GROW(0);
MF_RETURN_OBSTACK();
}
case dns_not_found:
+ free(ipbuf);
MF_RETURN_STRING("");
default:
+ free(ipbuf);
MF_THROW(dns_to_mf_status(dnstat),
_("failed to get A record for %s"), string);
}
@@ -114,19 +129,20 @@ MF_DEFUN(dns_getname, STRING, STRING ipstr)
dns_status dnstat;
struct in_addr addr;
unsigned long ttl;
- char *names[64];
+ char **names;
MF_ASSERT(inet_aton(ipstr, &addr),
mfe_invip,
_("invalid IP: %s"), ipstr);
- dnstat = ptr_lookup(addr, names, NELEMS(names), &ttl, NULL, 0);
+ names = xcalloc(max_ptr, sizeof(names[0]));
+ dnstat = ptr_lookup(addr, names, max_ptr, &ttl, NULL, 0);
switch (dnstat) {
case dns_success: {
size_t i;
size_t ncount;
- for (ncount = 0; ncount < NELEMS(names) && names[ncount];
+ for (ncount = 0; ncount < max_ptr && names[ncount];
ncount++);
qsort(names, ncount, sizeof names[0], hostname_cmp);
@@ -141,12 +157,14 @@ MF_DEFUN(dns_getname, STRING, STRING ipstr)
for (; i < ncount; i++)
free(names[i]);
-
+ free(names);
MF_RETURN_OBSTACK();
}
case dns_not_found:
+ free(names);
MF_RETURN_STRING("");
default:
+ free(names);
MF_THROW(dns_to_mf_status(dnstat),
_("failed to get PTR record for %s"), ipstr);
}
@@ -296,4 +314,6 @@ MF_DEFUN(listens, NUMBER, STRING s, OPTIONAL, NUMBER port)
}
END
-MF_INIT
+MF_INIT([<
+ mf_add_runtime_params(dns_cfg_param);
+ >])
diff --git a/mfd/main.c b/mfd/main.c
index b6ad8ff8..1211965a 100644
--- a/mfd/main.c
+++ b/mfd/main.c
@@ -2357,7 +2357,7 @@ mf_runtime_param_finish()
_add_runtime_param_entry(&term);
if (mu_create_canned_section ("runtime", &section) == 0) {
- section->parser = server_section_parser;
+ section->parser = NULL;
section->docstring = N_("Configure MFL runtime values.");
section->label = NULL;
mu_cfg_section_add_params(section, runtime_param);

Return to:

Send suggestions and report system problems to the System administrator.