]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-conf.c
Merge pull request #1880 from fsateler/sysctl-doc
[thirdparty/systemd.git] / src / resolve / resolved-conf.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2014 Tom Gundersen <teg@jklm.no>
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include "alloc-util.h"
23 #include "conf-parser.h"
24 #include "def.h"
25 #include "extract-word.h"
26 #include "parse-util.h"
27 #include "resolved-conf.h"
28 #include "string-util.h"
29
30 int manager_parse_dns_server(Manager *m, DnsServerType type, const char *string) {
31 DnsServer *first;
32 int r;
33
34 assert(m);
35 assert(string);
36
37 first = type == DNS_SERVER_FALLBACK ? m->fallback_dns_servers : m->dns_servers;
38
39 for(;;) {
40 _cleanup_free_ char *word = NULL;
41 union in_addr_union addr;
42 bool found = false;
43 DnsServer *s;
44 int family;
45
46 r = extract_first_word(&string, &word, NULL, 0);
47 if (r < 0)
48 return log_error_errno(r, "Failed to parse resolved dns server syntax \"%s\": %m", string);
49 if (r == 0)
50 break;
51
52 r = in_addr_from_string_auto(word, &family, &addr);
53 if (r < 0) {
54 log_warning("Ignoring invalid DNS address '%s'", word);
55 continue;
56 }
57
58 /* Filter out duplicates */
59 LIST_FOREACH(servers, s, first)
60 if (s->family == family && in_addr_equal(family, &s->address, &addr)) {
61 found = true;
62 break;
63 }
64
65 if (found)
66 continue;
67
68 r = dns_server_new(m, NULL, type, NULL, family, &addr);
69 if (r < 0)
70 return r;
71 }
72
73 return 0;
74 }
75
76 int config_parse_dnsv(
77 const char *unit,
78 const char *filename,
79 unsigned line,
80 const char *section,
81 unsigned section_line,
82 const char *lvalue,
83 int ltype,
84 const char *rvalue,
85 void *data,
86 void *userdata) {
87
88 Manager *m = userdata;
89 int r;
90
91 assert(filename);
92 assert(lvalue);
93 assert(rvalue);
94 assert(m);
95
96 if (isempty(rvalue))
97 /* Empty assignment means clear the list */
98 manager_flush_dns_servers(m, ltype);
99 else {
100 /* Otherwise, add to the list */
101 r = manager_parse_dns_server(m, ltype, rvalue);
102 if (r < 0) {
103 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse DNS server string '%s'. Ignoring.", rvalue);
104 return 0;
105 }
106 }
107
108 /* If we have a manual setting, then we stop reading
109 * /etc/resolv.conf */
110 if (ltype == DNS_SERVER_SYSTEM)
111 m->read_resolv_conf = false;
112
113 return 0;
114 }
115
116 int config_parse_support(
117 const char *unit,
118 const char *filename,
119 unsigned line,
120 const char *section,
121 unsigned section_line,
122 const char *lvalue,
123 int ltype,
124 const char *rvalue,
125 void *data,
126 void *userdata) {
127
128 Support support, *v = data;
129 int r;
130
131 assert(filename);
132 assert(lvalue);
133 assert(rvalue);
134
135 support = support_from_string(rvalue);
136 if (support < 0) {
137 r = parse_boolean(rvalue);
138 if (r < 0) {
139 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse support level '%s'. Ignoring.", rvalue);
140 return 0;
141 }
142
143 support = r ? SUPPORT_YES : SUPPORT_NO;
144 }
145
146 *v = support;
147 return 0;
148 }
149
150 int manager_parse_config_file(Manager *m) {
151 assert(m);
152
153 return config_parse_many(PKGSYSCONFDIR "/resolved.conf",
154 CONF_PATHS_NULSTR("systemd/resolved.conf.d"),
155 "Resolve\0",
156 config_item_perf_lookup, resolved_gperf_lookup,
157 false, m);
158 }