]>
Commit | Line | Data |
---|---|---|
4e945a6f LP |
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 "conf-parser.h" | |
23 | ||
24 | #include "resolved-conf.h" | |
25 | ||
26 | int manager_parse_dns_server(Manager *m, DnsServerType type, const char *string) { | |
27 | const char *word, *state; | |
28 | size_t length; | |
29 | DnsServer *first; | |
30 | int r; | |
31 | ||
32 | assert(m); | |
33 | assert(string); | |
34 | ||
35 | first = type == DNS_SERVER_FALLBACK ? m->fallback_dns_servers : m->dns_servers; | |
36 | ||
37 | FOREACH_WORD_QUOTED(word, length, string, state) { | |
38 | char buffer[length+1]; | |
39 | int family; | |
40 | union in_addr_union addr; | |
41 | bool found = false; | |
42 | DnsServer *s; | |
43 | ||
44 | memcpy(buffer, word, length); | |
45 | buffer[length] = 0; | |
46 | ||
47 | r = in_addr_from_string_auto(buffer, &family, &addr); | |
48 | if (r < 0) { | |
49 | log_warning("Ignoring invalid DNS address '%s'", buffer); | |
50 | continue; | |
51 | } | |
52 | ||
53 | /* Filter out duplicates */ | |
54 | LIST_FOREACH(servers, s, first) | |
55 | if (s->family == family && in_addr_equal(family, &s->address, &addr)) { | |
56 | found = true; | |
57 | break; | |
58 | } | |
59 | ||
60 | if (found) | |
61 | continue; | |
62 | ||
63 | r = dns_server_new(m, NULL, type, NULL, family, &addr); | |
64 | if (r < 0) | |
65 | return r; | |
66 | } | |
67 | ||
68 | return 0; | |
69 | } | |
70 | ||
71 | int config_parse_dnsv( | |
72 | const char *unit, | |
73 | const char *filename, | |
74 | unsigned line, | |
75 | const char *section, | |
76 | unsigned section_line, | |
77 | const char *lvalue, | |
78 | int ltype, | |
79 | const char *rvalue, | |
80 | void *data, | |
81 | void *userdata) { | |
82 | ||
83 | Manager *m = userdata; | |
4e945a6f LP |
84 | int r; |
85 | ||
86 | assert(filename); | |
87 | assert(lvalue); | |
88 | assert(rvalue); | |
89 | assert(m); | |
90 | ||
3e684349 | 91 | if (isempty(rvalue)) |
5cb36f41 | 92 | /* Empty assignment means clear the list */ |
3e684349 LP |
93 | manager_flush_dns_servers(m, ltype); |
94 | else { | |
5cb36f41 LP |
95 | /* Otherwise add to the list */ |
96 | r = manager_parse_dns_server(m, ltype, rvalue); | |
97 | if (r < 0) { | |
98 | log_syntax(unit, LOG_ERR, filename, line, -r, "Failed to parse DNS server string '%s'. Ignoring.", rvalue); | |
99 | return 0; | |
100 | } | |
4e945a6f LP |
101 | } |
102 | ||
5cb36f41 LP |
103 | /* If we have a manual setting, then we stop reading |
104 | * /etc/resolv.conf */ | |
105 | if (ltype == DNS_SERVER_SYSTEM) | |
106 | m->read_resolv_conf = false; | |
107 | ||
4e945a6f LP |
108 | return 0; |
109 | } | |
110 | ||
111 | int config_parse_support( | |
112 | const char *unit, | |
113 | const char *filename, | |
114 | unsigned line, | |
115 | const char *section, | |
116 | unsigned section_line, | |
117 | const char *lvalue, | |
118 | int ltype, | |
119 | const char *rvalue, | |
120 | void *data, | |
121 | void *userdata) { | |
122 | ||
4e945a6f LP |
123 | Support support, *v = data; |
124 | int r; | |
125 | ||
126 | assert(filename); | |
127 | assert(lvalue); | |
128 | assert(rvalue); | |
4e945a6f LP |
129 | |
130 | support = support_from_string(rvalue); | |
131 | if (support < 0) { | |
132 | r = parse_boolean(rvalue); | |
133 | if (r < 0) { | |
134 | log_syntax(unit, LOG_ERR, filename, line, -r, "Failed to parse support level '%s'. Ignoring.", rvalue); | |
135 | return 0; | |
136 | } | |
137 | ||
138 | support = r ? SUPPORT_YES : SUPPORT_NO; | |
139 | } | |
140 | ||
141 | *v = support; | |
142 | return 0; | |
143 | } | |
144 | ||
145 | int manager_parse_config_file(Manager *m) { | |
146 | assert(m); | |
147 | ||
f2dacc96 JT |
148 | return config_parse_many("/etc/systemd/resolved.conf", |
149 | CONF_DIRS_NULSTR("systemd/resolved.conf"), | |
150 | "Resolve\0", | |
151 | config_item_perf_lookup, resolved_gperf_lookup, | |
152 | false, m); | |
4e945a6f | 153 | } |