2014-08-01 16:04:12 +02:00
|
|
|
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
|
|
|
|
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
Copyright 2014 Tom Gundersen <teg@jklm.no>
|
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
2015-10-27 03:01:06 +01:00
|
|
|
#include "alloc-util.h"
|
2014-08-01 16:04:12 +02:00
|
|
|
#include "conf-parser.h"
|
2015-11-03 12:26:12 +01:00
|
|
|
#include "def.h"
|
2015-10-27 03:01:06 +01:00
|
|
|
#include "extract-word.h"
|
2015-10-26 16:18:16 +01:00
|
|
|
#include "parse-util.h"
|
2014-08-01 16:04:12 +02:00
|
|
|
#include "resolved-conf.h"
|
2015-10-26 16:18:16 +01:00
|
|
|
#include "string-util.h"
|
2014-08-01 16:04:12 +02:00
|
|
|
|
2015-11-24 16:48:13 +01:00
|
|
|
int manager_add_dns_server_by_string(Manager *m, DnsServerType type, const char *word) {
|
|
|
|
union in_addr_union address;
|
|
|
|
int family, r;
|
2015-11-24 17:59:40 +01:00
|
|
|
DnsServer *s;
|
2014-08-01 16:04:12 +02:00
|
|
|
|
|
|
|
assert(m);
|
2015-11-24 16:48:13 +01:00
|
|
|
assert(word);
|
|
|
|
|
|
|
|
r = in_addr_from_string_auto(word, &family, &address);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2014-08-01 16:04:12 +02:00
|
|
|
|
2015-11-24 16:48:13 +01:00
|
|
|
/* Filter out duplicates */
|
2015-11-24 17:59:40 +01:00
|
|
|
s = manager_find_dns_server(m, type, family, &address);
|
2015-11-24 16:48:13 +01:00
|
|
|
if (s) {
|
|
|
|
/*
|
|
|
|
* Drop the marker. This is used to find the servers
|
|
|
|
* that ceased to exist, see
|
|
|
|
* manager_mark_dns_servers() and
|
|
|
|
* manager_flush_marked_dns_servers().
|
|
|
|
*/
|
|
|
|
s->marked = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dns_server_new(m, NULL, type, NULL, family, &address);
|
|
|
|
}
|
|
|
|
|
|
|
|
int manager_parse_dns_server_string_and_warn(Manager *m, DnsServerType type, const char *string) {
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(m);
|
|
|
|
assert(string);
|
|
|
|
|
2015-10-27 04:54:23 +01:00
|
|
|
for(;;) {
|
2015-10-27 03:01:06 +01:00
|
|
|
_cleanup_free_ char *word = NULL;
|
2015-10-27 04:54:23 +01:00
|
|
|
|
|
|
|
r = extract_first_word(&string, &word, NULL, 0);
|
|
|
|
if (r < 0)
|
2015-11-24 16:48:13 +01:00
|
|
|
return r;
|
2015-10-27 04:54:23 +01:00
|
|
|
if (r == 0)
|
|
|
|
break;
|
2014-08-01 16:04:12 +02:00
|
|
|
|
2015-11-24 16:48:13 +01:00
|
|
|
r = manager_add_dns_server_by_string(m, type, word);
|
2014-08-01 16:04:12 +02:00
|
|
|
if (r < 0) {
|
2015-11-24 16:48:13 +01:00
|
|
|
log_warning_errno(r, "Failed to add DNS server address '%s', ignoring.", word);
|
2014-08-01 16:04:12 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-24 16:48:13 +01:00
|
|
|
int config_parse_dns_servers(
|
2014-08-01 16:04:12 +02:00
|
|
|
const char *unit,
|
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
unsigned section_line,
|
|
|
|
const char *lvalue,
|
|
|
|
int ltype,
|
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Manager *m = userdata;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(m);
|
|
|
|
|
2014-08-12 19:32:55 +02:00
|
|
|
if (isempty(rvalue))
|
2014-08-01 17:03:28 +02:00
|
|
|
/* Empty assignment means clear the list */
|
2014-08-12 19:32:55 +02:00
|
|
|
manager_flush_dns_servers(m, ltype);
|
|
|
|
else {
|
2014-08-03 07:11:12 +02:00
|
|
|
/* Otherwise, add to the list */
|
2015-11-24 16:48:13 +01:00
|
|
|
r = manager_parse_dns_server_string_and_warn(m, ltype, rvalue);
|
2014-08-01 17:03:28 +02:00
|
|
|
if (r < 0) {
|
2015-09-30 18:22:42 +02:00
|
|
|
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse DNS server string '%s'. Ignoring.", rvalue);
|
2014-08-01 17:03:28 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2014-08-01 16:04:12 +02:00
|
|
|
}
|
|
|
|
|
2014-08-01 17:03:28 +02:00
|
|
|
/* If we have a manual setting, then we stop reading
|
|
|
|
* /etc/resolv.conf */
|
|
|
|
if (ltype == DNS_SERVER_SYSTEM)
|
|
|
|
m->read_resolv_conf = false;
|
|
|
|
|
2014-08-01 16:04:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int config_parse_support(
|
|
|
|
const char *unit,
|
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
unsigned section_line,
|
|
|
|
const char *lvalue,
|
|
|
|
int ltype,
|
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Support support, *v = data;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
|
|
|
|
support = support_from_string(rvalue);
|
|
|
|
if (support < 0) {
|
|
|
|
r = parse_boolean(rvalue);
|
|
|
|
if (r < 0) {
|
2015-09-30 18:22:42 +02:00
|
|
|
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse support level '%s'. Ignoring.", rvalue);
|
2014-08-01 16:04:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
support = r ? SUPPORT_YES : SUPPORT_NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
*v = support;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int manager_parse_config_file(Manager *m) {
|
|
|
|
assert(m);
|
|
|
|
|
2015-11-10 15:57:21 +01:00
|
|
|
return config_parse_many(PKGSYSCONFDIR "/resolved.conf",
|
|
|
|
CONF_PATHS_NULSTR("systemd/resolved.conf.d"),
|
2014-11-29 10:07:11 +01:00
|
|
|
"Resolve\0",
|
|
|
|
config_item_perf_lookup, resolved_gperf_lookup,
|
|
|
|
false, m);
|
2014-08-01 16:04:12 +02:00
|
|
|
}
|