summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-06-13 21:01:24 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-06-13 21:01:24 +0100
commit3d8045cdcc4740a0ffa78e64976fc1fd3e44fe76 (patch)
tree91eceab99165242186cbedb5ae632fe1d9deabe6 /src
parent527119290db9e79cf4be11511c378f9704dd1fb6 (diff)
downloadrspamd-3d8045cdcc4740a0ffa78e64976fc1fd3e44fe76.tar.gz
rspamd-3d8045cdcc4740a0ffa78e64976fc1fd3e44fe76.zip
[Fix] Allow to init resolver without rspamd_config
Diffstat (limited to 'src')
-rw-r--r--src/libserver/dns.c88
1 files changed, 42 insertions, 46 deletions
diff --git a/src/libserver/dns.c b/src/libserver/dns.c
index 9aeb24306..21a15297c 100644
--- a/src/libserver/dns.c
+++ b/src/libserver/dns.c
@@ -269,60 +269,56 @@ dns_resolver_init (rspamd_logger_t *logger,
rdns_resolver_set_log_level (dns_resolver->r, cfg->log_level);
dns_resolver->cfg = cfg;
rdns_resolver_set_dnssec (dns_resolver->r, cfg->enable_dnssec);
- }
-
- rdns_resolver_set_logger (dns_resolver->r, rspamd_rnds_log_bridge, logger);
- if (cfg == NULL || cfg->nameservers == NULL) {
- /* Parse resolv.conf */
- dns_resolver->ups = rspamd_upstreams_create (cfg->ups_ctx);
- rspamd_upstreams_set_flags (dns_resolver->ups,
- RSPAMD_UPSTREAM_FLAG_NORESOLVE);
- rspamd_upstreams_set_rotation (dns_resolver->ups,
- RSPAMD_UPSTREAM_MASTER_SLAVE);
-
- if (!rdns_resolver_parse_resolv_conf_cb (dns_resolver->r,
- "/etc/resolv.conf",
- rspamd_dns_resolv_conf_on_server,
- dns_resolver)) {
- msg_err ("cannot parse resolv.conf and no nameservers defined, "
- "so no ways to resolve addresses");
- rdns_resolver_release (dns_resolver->r);
- dns_resolver->r = NULL;
-
- return dns_resolver;
+ if (cfg->nameservers == NULL) {
+ /* Parse resolv.conf */
+ dns_resolver->ups = rspamd_upstreams_create (cfg->ups_ctx);
+ rspamd_upstreams_set_flags (dns_resolver->ups,
+ RSPAMD_UPSTREAM_FLAG_NORESOLVE);
+ rspamd_upstreams_set_rotation (dns_resolver->ups,
+ RSPAMD_UPSTREAM_MASTER_SLAVE);
+
+ if (!rdns_resolver_parse_resolv_conf_cb (dns_resolver->r,
+ "/etc/resolv.conf",
+ rspamd_dns_resolv_conf_on_server,
+ dns_resolver)) {
+ msg_err ("cannot parse resolv.conf and no nameservers defined, "
+ "so no ways to resolve addresses");
+ rdns_resolver_release (dns_resolver->r);
+ dns_resolver->r = NULL;
+
+ return dns_resolver;
+ }
+
+ /* Use normal resolv.conf rules */
+ rspamd_upstreams_foreach (dns_resolver->ups, rspamd_dns_server_reorder,
+ dns_resolver);
+ }
+ else {
+ dns_resolver->ups = rspamd_upstreams_create (cfg->ups_ctx);
+ rspamd_upstreams_set_flags (dns_resolver->ups,
+ RSPAMD_UPSTREAM_FLAG_NORESOLVE);
+
+ if (!rspamd_upstreams_from_ucl (dns_resolver->ups, cfg->nameservers,
+ 53, dns_resolver)) {
+ msg_err_config ("cannot parse DNS nameservers definitions");
+ rdns_resolver_release (dns_resolver->r);
+ dns_resolver->r = NULL;
+
+ return dns_resolver;
+ }
}
- /* Use normal resolv.conf rules */
- rspamd_upstreams_foreach (dns_resolver->ups, rspamd_dns_server_reorder,
+ rspamd_upstreams_foreach (dns_resolver->ups, rspamd_dns_server_init,
dns_resolver);
- }
- else {
- dns_resolver->ups = rspamd_upstreams_create (cfg->ups_ctx);
- rspamd_upstreams_set_flags (dns_resolver->ups,
- RSPAMD_UPSTREAM_FLAG_NORESOLVE);
-
- if (!rspamd_upstreams_from_ucl (dns_resolver->ups, cfg->nameservers,
- 53, dns_resolver)) {
- msg_err_config ("cannot parse DNS nameservers definitions");
- rdns_resolver_release (dns_resolver->r);
- dns_resolver->r = NULL;
-
- return dns_resolver;
- }
+ rdns_resolver_set_upstream_lib (dns_resolver->r, &rspamd_ups_ctx,
+ dns_resolver->ups);
+ cfg->dns_resolver = dns_resolver;
}
- rspamd_upstreams_foreach (dns_resolver->ups, rspamd_dns_server_init,
- dns_resolver);
- rdns_resolver_set_upstream_lib (dns_resolver->r, &rspamd_ups_ctx,
- dns_resolver->ups);
-
+ rdns_resolver_set_logger (dns_resolver->r, rspamd_rnds_log_bridge, logger);
rdns_resolver_init (dns_resolver->r);
- if (cfg != NULL) {
- cfg->dns_resolver = dns_resolver;
- }
-
return dns_resolver;
}