]>
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 | ||
b5efdb8a | 22 | #include "alloc-util.h" |
4e945a6f | 23 | #include "conf-parser.h" |
a0f29c76 | 24 | #include "def.h" |
b5efdb8a | 25 | #include "extract-word.h" |
6bedfcbb | 26 | #include "parse-util.h" |
4e945a6f | 27 | #include "resolved-conf.h" |
6bedfcbb | 28 | #include "string-util.h" |
4e945a6f LP |
29 | |
30 | int manager_parse_dns_server(Manager *m, DnsServerType type, const char *string) { | |
4e945a6f LP |
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 | ||
880603a1 | 39 | for(;;) { |
b5efdb8a | 40 | _cleanup_free_ char *word = NULL; |
4e945a6f LP |
41 | union in_addr_union addr; |
42 | bool found = false; | |
43 | DnsServer *s; | |
880603a1 SS |
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); | |
880603a1 SS |
49 | if (r == 0) |
50 | break; | |
4e945a6f | 51 | |
880603a1 | 52 | r = in_addr_from_string_auto(word, &family, &addr); |
4e945a6f | 53 | if (r < 0) { |
880603a1 | 54 | log_warning("Ignoring invalid DNS address '%s'", word); |
4e945a6f LP |
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; | |
4e945a6f LP |
89 | int r; |
90 | ||
91 | assert(filename); | |
92 | assert(lvalue); | |
93 | assert(rvalue); | |
94 | assert(m); | |
95 | ||
3e684349 | 96 | if (isempty(rvalue)) |
5cb36f41 | 97 | /* Empty assignment means clear the list */ |
3e684349 LP |
98 | manager_flush_dns_servers(m, ltype); |
99 | else { | |
5cb36f41 LP |
100 | /* Otherwise add to the list */ |
101 | r = manager_parse_dns_server(m, ltype, rvalue); | |
102 | if (r < 0) { | |
12ca818f | 103 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse DNS server string '%s'. Ignoring.", rvalue); |
5cb36f41 LP |
104 | return 0; |
105 | } | |
4e945a6f LP |
106 | } |
107 | ||
5cb36f41 LP |
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 | ||
4e945a6f LP |
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 | ||
4e945a6f LP |
128 | Support support, *v = data; |
129 | int r; | |
130 | ||
131 | assert(filename); | |
132 | assert(lvalue); | |
133 | assert(rvalue); | |
4e945a6f LP |
134 | |
135 | support = support_from_string(rvalue); | |
136 | if (support < 0) { | |
137 | r = parse_boolean(rvalue); | |
138 | if (r < 0) { | |
12ca818f | 139 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse support level '%s'. Ignoring.", rvalue); |
4e945a6f LP |
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 | ||
f2dacc96 JT |
153 | return config_parse_many("/etc/systemd/resolved.conf", |
154 | CONF_DIRS_NULSTR("systemd/resolved.conf"), | |
155 | "Resolve\0", | |
156 | config_item_perf_lookup, resolved_gperf_lookup, | |
157 | false, m); | |
4e945a6f | 158 | } |