resolved-conf.c revision f2dacc96b25528ca1b0caca6364a69d656cf1569
97a9a944b5887e91042b019776c41d5dd74557aferikabele/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
97a9a944b5887e91042b019776c41d5dd74557aferikabele
97a9a944b5887e91042b019776c41d5dd74557aferikabele/***
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive This file is part of systemd.
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive Copyright 2014 Tom Gundersen <teg@jklm.no>
5a58787efeb02a1c3f06569d019ad81fd2efa06end
5a58787efeb02a1c3f06569d019ad81fd2efa06end systemd is free software; you can redistribute it and/or modify it
5a58787efeb02a1c3f06569d019ad81fd2efa06end under the terms of the GNU Lesser General Public License as published by
5a58787efeb02a1c3f06569d019ad81fd2efa06end the Free Software Foundation; either version 2.1 of the License, or
5a58787efeb02a1c3f06569d019ad81fd2efa06end (at your option) any later version.
5a58787efeb02a1c3f06569d019ad81fd2efa06end
5a58787efeb02a1c3f06569d019ad81fd2efa06end systemd is distributed in the hope that it will be useful, but
5a58787efeb02a1c3f06569d019ad81fd2efa06end WITHOUT ANY WARRANTY; without even the implied warranty of
5a58787efeb02a1c3f06569d019ad81fd2efa06end MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
52fff662005b1866a3ff09bb6c902800c5cc6dedjerenkrantz Lesser General Public License for more details.
5a58787efeb02a1c3f06569d019ad81fd2efa06end
5a58787efeb02a1c3f06569d019ad81fd2efa06end You should have received a copy of the GNU Lesser General Public License
5a58787efeb02a1c3f06569d019ad81fd2efa06end along with systemd; If not, see <http://www.gnu.org/licenses/>.
4b5981e276e93df97c34e4da05ca5cf8bbd937dand ***/
5a58787efeb02a1c3f06569d019ad81fd2efa06end
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd#include "conf-parser.h"
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd#include "resolved-conf.h"
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd
e1e8390280254f7f0580d701e583f670643d4f3fnilgunint manager_parse_dns_server(Manager *m, DnsServerType type, const char *string) {
e1e8390280254f7f0580d701e583f670643d4f3fnilgun const char *word, *state;
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd size_t length;
5a58787efeb02a1c3f06569d019ad81fd2efa06end DnsServer *first;
5a58787efeb02a1c3f06569d019ad81fd2efa06end int r;
5a58787efeb02a1c3f06569d019ad81fd2efa06end
5a58787efeb02a1c3f06569d019ad81fd2efa06end assert(m);
5a58787efeb02a1c3f06569d019ad81fd2efa06end assert(string);
5a58787efeb02a1c3f06569d019ad81fd2efa06end
5a58787efeb02a1c3f06569d019ad81fd2efa06end first = type == DNS_SERVER_FALLBACK ? m->fallback_dns_servers : m->dns_servers;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
ced7ef1f8c0df1805da0e87dbc5a1b6282910573nd FOREACH_WORD_QUOTED(word, length, string, state) {
9b6a3a558cc90ffdaa0b50bd02546ffec424ded7slive char buffer[length+1];
ced7ef1f8c0df1805da0e87dbc5a1b6282910573nd int family;
b21197dc8e6b8c764fdcc24d4bae8b0eebb6bc4end union in_addr_union addr;
9b6a3a558cc90ffdaa0b50bd02546ffec424ded7slive bool found = false;
9b6a3a558cc90ffdaa0b50bd02546ffec424ded7slive DnsServer *s;
9b6a3a558cc90ffdaa0b50bd02546ffec424ded7slive
97a9a944b5887e91042b019776c41d5dd74557aferikabele memcpy(buffer, word, length);
f8396ed8364b56ec8adeaa49cac35a929758a29eslive buffer[length] = 0;
97a9a944b5887e91042b019776c41d5dd74557aferikabele
f8396ed8364b56ec8adeaa49cac35a929758a29eslive r = in_addr_from_string_auto(buffer, &family, &addr);
f8396ed8364b56ec8adeaa49cac35a929758a29eslive if (r < 0) {
5a58787efeb02a1c3f06569d019ad81fd2efa06end log_warning("Ignoring invalid DNS address '%s'", buffer);
5a58787efeb02a1c3f06569d019ad81fd2efa06end continue;
5a58787efeb02a1c3f06569d019ad81fd2efa06end }
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd
5a58787efeb02a1c3f06569d019ad81fd2efa06end /* Filter out duplicates */
deeee6bb6fd94c0ba5f3730b58abd9d299c89ccdnd LIST_FOREACH(servers, s, first)
4db28ee269aa06f7c6232e11cd01f58c3349af23noodl if (s->family == family && in_addr_equal(family, &s->address, &addr)) {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd found = true;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd break;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (found)
117c1f888a14e73cdd821dc6c23eb0411144a41cnd continue;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd r = dns_server_new(m, NULL, type, NULL, family, &addr);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (r < 0)
2bc7f1cf720973a67f8ff7a8d523e40569ae5b6cnd return r;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd return 0;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd}
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cndint config_parse_dnsv(
87ffb6e33f3cbef3b9bb406cc2d27039fa336eaatrawick const char *unit,
4db28ee269aa06f7c6232e11cd01f58c3349af23noodl const char *filename,
5a58787efeb02a1c3f06569d019ad81fd2efa06end unsigned line,
5a58787efeb02a1c3f06569d019ad81fd2efa06end const char *section,
5a58787efeb02a1c3f06569d019ad81fd2efa06end unsigned section_line,
5a58787efeb02a1c3f06569d019ad81fd2efa06end const char *lvalue,
5a58787efeb02a1c3f06569d019ad81fd2efa06end int ltype,
5a58787efeb02a1c3f06569d019ad81fd2efa06end const char *rvalue,
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd void *data,
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd void *userdata) {
5a58787efeb02a1c3f06569d019ad81fd2efa06end
5a58787efeb02a1c3f06569d019ad81fd2efa06end Manager *m = userdata;
5a58787efeb02a1c3f06569d019ad81fd2efa06end int r;
5a58787efeb02a1c3f06569d019ad81fd2efa06end
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick assert(filename);
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick assert(lvalue);
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick assert(rvalue);
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick assert(m);
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (isempty(rvalue))
ea8a727ff298d2f5368b55b7ae8d87091ae106e7nd /* Empty assignment means clear the list */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive manager_flush_dns_servers(m, ltype);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive else {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Otherwise add to the list */
92510838f2eb125726e15c5eb4f7a23c7a0396e4slive r = manager_parse_dns_server(m, ltype, rvalue);
97a9a944b5887e91042b019776c41d5dd74557aferikabele if (r < 0) {
ced7ef1f8c0df1805da0e87dbc5a1b6282910573nd log_syntax(unit, LOG_ERR, filename, line, -r, "Failed to parse DNS server string '%s'. Ignoring.", rvalue);
92510838f2eb125726e15c5eb4f7a23c7a0396e4slive return 0;
97a9a944b5887e91042b019776c41d5dd74557aferikabele }
9b6a3a558cc90ffdaa0b50bd02546ffec424ded7slive }
9b6a3a558cc90ffdaa0b50bd02546ffec424ded7slive
92510838f2eb125726e15c5eb4f7a23c7a0396e4slive /* If we have a manual setting, then we stop reading
92510838f2eb125726e15c5eb4f7a23c7a0396e4slive * /etc/resolv.conf */
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick if (ltype == DNS_SERVER_SYSTEM)
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick m->read_resolv_conf = false;
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick return 0;
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick}
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawickint config_parse_support(
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick const char *unit,
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick const char *filename,
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick unsigned line,
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick const char *section,
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick unsigned section_line,
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick const char *lvalue,
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick int ltype,
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick const char *rvalue,
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick void *data,
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick void *userdata) {
77c77cf89621f21c8e2bbad63058b5eaa5f88d4ajim
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick Manager *m = userdata;
ced7ef1f8c0df1805da0e87dbc5a1b6282910573nd Support support, *v = data;
ced7ef1f8c0df1805da0e87dbc5a1b6282910573nd int r;
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick
e7131afdda636994bf3c7a6b2e77e5960fb62633nd assert(filename);
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick assert(lvalue);
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick assert(rvalue);
ced7ef1f8c0df1805da0e87dbc5a1b6282910573nd assert(m);
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick support = support_from_string(rvalue);
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick if (support < 0) {
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick r = parse_boolean(rvalue);
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick if (r < 0) {
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick log_syntax(unit, LOG_ERR, filename, line, -r, "Failed to parse support level '%s'. Ignoring.", rvalue);
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick return 0;
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick }
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick support = r ? SUPPORT_YES : SUPPORT_NO;
92510838f2eb125726e15c5eb4f7a23c7a0396e4slive }
92510838f2eb125726e15c5eb4f7a23c7a0396e4slive
97a9a944b5887e91042b019776c41d5dd74557aferikabele *v = support;
92510838f2eb125726e15c5eb4f7a23c7a0396e4slive return 0;
ea8a727ff298d2f5368b55b7ae8d87091ae106e7nd}
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick
ea8a727ff298d2f5368b55b7ae8d87091ae106e7ndint manager_parse_config_file(Manager *m) {
ea8a727ff298d2f5368b55b7ae8d87091ae106e7nd assert(m);
ea8a727ff298d2f5368b55b7ae8d87091ae106e7nd
ea8a727ff298d2f5368b55b7ae8d87091ae106e7nd return config_parse_many("/etc/systemd/resolved.conf",
8a6d5edcb07aeccca7afba02a17dd6904d6b206ctrawick CONF_DIRS_NULSTR("systemd/resolved.conf"),
ea8a727ff298d2f5368b55b7ae8d87091ae106e7nd "Resolve\0",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive config_item_perf_lookup, resolved_gperf_lookup,
e8d485701957d5c6de870111c112e168a894d49and false, m);
e8d485701957d5c6de870111c112e168a894d49and}
4db28ee269aa06f7c6232e11cd01f58c3349af23noodl