]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/resolve/resolved-conf.c
Merge pull request #20303 from andir/sysconfig-example
[thirdparty/systemd.git] / src / resolve / resolved-conf.c
index 6caae5d1110ec91c841b0617d65285efded74a68..3afaaad9372cdf9a9d7d643fb25ab2683ae71663 100644 (file)
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #include "alloc-util.h"
 #include "conf-parser.h"
@@ -35,9 +35,6 @@ static int manager_add_dns_server_by_string(Manager *m, DnsServerType type, cons
         if (r < 0)
                 return r;
 
-        if (IN_SET(port, 53, 853))
-                port = 0;
-
         /* Silently filter out 0.0.0.0 and 127.0.0.53 (our own stub DNS listener) */
         if (!dns_server_address_valid(family, &address))
                 return 0;
@@ -50,12 +47,8 @@ static int manager_add_dns_server_by_string(Manager *m, DnsServerType type, cons
         /* Filter out duplicates */
         s = dns_server_find(manager_get_first_dns_server(m, type), family, &address, port, ifindex, server_name);
         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().
-                 */
+                /* 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(). */
                 dns_server_move_back_and_unmark(s);
                 return 0;
         }
@@ -168,7 +161,8 @@ int config_parse_dns_servers(
                 /* Otherwise, add to the list */
                 r = manager_parse_dns_server_string_and_warn(m, ltype, rvalue);
                 if (r < 0) {
-                        log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse DNS server string '%s'. Ignoring.", rvalue);
+                        log_syntax(unit, LOG_WARNING, filename, line, r,
+                                   "Failed to parse DNS server string '%s', ignoring.", rvalue);
                         return 0;
                 }
         }
@@ -210,7 +204,8 @@ int config_parse_search_domains(
                 /* Otherwise, add to the list */
                 r = manager_parse_search_domains_and_warn(m, rvalue);
                 if (r < 0) {
-                        log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse search domains string '%s'. Ignoring.", rvalue);
+                        log_syntax(unit, LOG_WARNING, filename, line, r,
+                                   "Failed to parse search domains string '%s', ignoring.", rvalue);
                         return 0;
                 }
         }
@@ -222,16 +217,27 @@ int config_parse_search_domains(
         return 0;
 }
 
-int config_parse_dnssd_service_name(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) {
+int config_parse_dnssd_service_name(
+                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) {
+
         static const Specifier specifier_table[] = {
-                { 'm', specifier_machine_id,      NULL },
-                { 'b', specifier_boot_id,         NULL },
-                { 'H', specifier_host_name,       NULL },
-                { 'v', specifier_kernel_release,  NULL },
                 { 'a', specifier_architecture,    NULL },
+                { 'b', specifier_boot_id,         NULL },
+                { 'B', specifier_os_build_id,     NULL },
+                { 'H', specifier_host_name,       NULL }, /* We will use specifier_dnssd_host_name(). */
+                { 'm', specifier_machine_id,      NULL },
                 { 'o', specifier_os_id,           NULL },
+                { 'v', specifier_kernel_release,  NULL },
                 { 'w', specifier_os_version_id,   NULL },
-                { 'B', specifier_os_build_id,     NULL },
                 { 'W', specifier_os_variant_id,   NULL },
                 {}
         };
@@ -245,27 +251,39 @@ int config_parse_dnssd_service_name(const char *unit, const char *filename, unsi
         assert(s);
 
         if (isempty(rvalue)) {
-                log_syntax(unit, LOG_ERR, filename, line, 0, "Service instance name can't be empty. Ignoring.");
-                return -EINVAL;
+                s->name_template = mfree(s->name_template);
+                return 0;
         }
 
-        r = free_and_strdup(&s->name_template, rvalue);
-        if (r < 0)
-                return log_oom();
-
-        r = specifier_printf(s->name_template, specifier_table, NULL, &name);
-        if (r < 0)
-                return log_debug_errno(r, "Failed to replace specifiers: %m");
+        r = specifier_printf(rvalue, DNS_LABEL_MAX, specifier_table, NULL, NULL, &name);
+        if (r < 0) {
+                log_syntax(unit, LOG_WARNING, filename, line, r,
+                           "Invalid service instance name template '%s', ignoring assignment: %m", rvalue);
+                return 0;
+        }
 
         if (!dns_service_name_is_valid(name)) {
-                log_syntax(unit, LOG_ERR, filename, line, 0, "Service instance name template renders to invalid name '%s'. Ignoring.", name);
-                return -EINVAL;
+                log_syntax(unit, LOG_WARNING, filename, line, 0,
+                           "Service instance name template '%s' renders to invalid name '%s'. Ignoring assignment.",
+                           rvalue, name);
+                return 0;
         }
 
-        return 0;
+        return free_and_strdup_warn(&s->name_template, rvalue);
 }
 
-int config_parse_dnssd_service_type(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) {
+int config_parse_dnssd_service_type(
+                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) {
+
         DnssdService *s = userdata;
         int r;
 
@@ -275,13 +293,13 @@ int config_parse_dnssd_service_type(const char *unit, const char *filename, unsi
         assert(s);
 
         if (isempty(rvalue)) {
-                log_syntax(unit, LOG_ERR, filename, line, 0, "Service type can't be empty. Ignoring.");
-                return -EINVAL;
+                s->type = mfree(s->type);
+                return 0;
         }
 
         if (!dnssd_srv_type_is_valid(rvalue)) {
-                log_syntax(unit, LOG_ERR, filename, line, 0, "Service type is invalid. Ignoring.");
-                return -EINVAL;
+                log_syntax(unit, LOG_WARNING, filename, line, 0, "Service type is invalid. Ignoring.");
+                return 0;
         }
 
         r = free_and_strdup(&s->type, rvalue);
@@ -291,7 +309,18 @@ int config_parse_dnssd_service_type(const char *unit, const char *filename, unsi
         return 0;
 }
 
-int config_parse_dnssd_txt(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) {
+int config_parse_dnssd_txt(
+                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) {
+
         _cleanup_(dnssd_txtdata_freep) DnssdTxtData *txt_data = NULL;
         DnssdService *s = userdata;
         DnsTxtItem *last = NULL;
@@ -312,22 +341,22 @@ int config_parse_dnssd_txt(const char *unit, const char *filename, unsigned line
                 return log_oom();
 
         for (;;) {
-                _cleanup_free_ char *word = NULL;
-                _cleanup_free_ char *key = NULL;
-                _cleanup_free_ char *value = NULL;
+                _cleanup_free_ char *word = NULL, *key = NULL, *value = NULL;
                 _cleanup_free_ void *decoded = NULL;
                 size_t length = 0;
                 DnsTxtItem *i;
                 int r;
 
                 r = extract_first_word(&rvalue, &word, NULL,
-                                       EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_CUNESCAPE_RELAX);
+                                       EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_RELAX);
                 if (r == 0)
                         break;
                 if (r == -ENOMEM)
                         return log_oom();
-                if (r < 0)
-                        return log_syntax(unit, LOG_ERR, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
+                if (r < 0) {
+                        log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
+                        return 0;
+                }
 
                 r = split_pair(word, "=", &key, &value);
                 if (r == -ENOMEM)
@@ -336,8 +365,8 @@ int config_parse_dnssd_txt(const char *unit, const char *filename, unsigned line
                         key = TAKE_PTR(word);
 
                 if (!ascii_is_valid(key)) {
-                        log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid syntax, ignoring: %s", key);
-                        return -EINVAL;
+                        log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid key, ignoring: %s", key);
+                        continue;
                 }
 
                 switch (ltype) {
@@ -347,9 +376,11 @@ int config_parse_dnssd_txt(const char *unit, const char *filename, unsigned line
                                 r = unbase64mem(value, strlen(value), &decoded, &length);
                                 if (r == -ENOMEM)
                                         return log_oom();
-                                if (r < 0)
-                                        return log_syntax(unit, LOG_ERR, filename, line, r,
-                                                          "Invalid base64 encoding, ignoring: %s", value);
+                                if (r < 0) {
+                                        log_syntax(unit, LOG_WARNING, filename, line, r,
+                                                   "Invalid base64 encoding, ignoring: %s", value);
+                                        continue;
+                                }
                         }
 
                         r = dnssd_txt_item_new_from_data(key, decoded, length, &i);
@@ -364,7 +395,7 @@ int config_parse_dnssd_txt(const char *unit, const char *filename, unsigned line
                         break;
 
                 default:
-                        assert_not_reached("Unknown type of Txt config");
+                        assert_not_reached();
                 }
 
                 LIST_INSERT_AFTER(items, txt_data->txt, last, i);
@@ -373,7 +404,7 @@ int config_parse_dnssd_txt(const char *unit, const char *filename, unsigned line
 
         if (!LIST_IS_EMPTY(txt_data->txt)) {
                 LIST_PREPEND(items, s->txt_data_items, txt_data);
-                txt_data = NULL;
+                TAKE_PTR(txt_data);
         }
 
         return 0;
@@ -406,7 +437,7 @@ int config_parse_dns_stub_listener_extra(
                 return 0;
         }
 
-        r = dns_stub_listener_extra_new(&stub);
+        r = dns_stub_listener_extra_new(m, &stub);
         if (r < 0)
                 return log_oom();
 
@@ -423,7 +454,7 @@ int config_parse_dns_stub_listener_extra(
                 }
         }
 
-        r = in_addr_port_from_string_auto(p, &stub->family, &stub->address, &stub->port);
+        r = in_addr_port_ifindex_name_from_string_auto(p, &stub->family, &stub->address, &stub->port, NULL, NULL);
         if (r < 0) {
                 log_syntax(unit, LOG_WARNING, filename, line, r,
                            "Failed to parse address in %s=%s, ignoring assignment: %m",