From d63542bc02829500405dd9d29c5d7324db11b09e Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 18 Nov 2020 03:20:30 +0900 Subject: [PATCH 1/4] resolve: wrap long line --- src/resolve/resolved-conf.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c index d8646094c0..2d68e38450 100644 --- a/src/resolve/resolved-conf.c +++ b/src/resolve/resolved-conf.c @@ -217,7 +217,18 @@ 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 }, From a37eb63ffa2ec786035956258d93df247263f2bd Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 18 Nov 2020 03:22:56 +0900 Subject: [PATCH 2/4] resolve: add a short comment about difference between dnssd_render_instance_name() and config_parse_dnssd_service_name() --- src/resolve/resolved-conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c index 2d68e38450..b454472e63 100644 --- a/src/resolve/resolved-conf.c +++ b/src/resolve/resolved-conf.c @@ -232,7 +232,7 @@ int config_parse_dnssd_service_name( static const Specifier specifier_table[] = { { 'm', specifier_machine_id, NULL }, { 'b', specifier_boot_id, NULL }, - { 'H', specifier_host_name, NULL }, + { 'H', specifier_host_name, NULL }, /* We will use specifier_dnssd_host_name(). */ { 'v', specifier_kernel_release, NULL }, { 'a', specifier_architecture, NULL }, { 'o', specifier_os_id, NULL }, From 0c949643b8f4550159b9d3ce8efbcd8e6e2263ce Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 18 Nov 2020 03:23:32 +0900 Subject: [PATCH 3/4] resolve: make config_parse_dnssd_service_name() accepts an empty string --- src/resolve/resolved-conf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c index b454472e63..fd3c1bfecd 100644 --- a/src/resolve/resolved-conf.c +++ b/src/resolve/resolved-conf.c @@ -251,8 +251,8 @@ int config_parse_dnssd_service_name( 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); From dd2e9e1d0e8297677a0642b4a2ed8580acf002bb Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 18 Nov 2020 03:32:37 +0900 Subject: [PATCH 4/4] resolve: ignore invalid service template name Let's fiest test the template name, and then assign it. --- src/resolve/resolved-conf.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c index fd3c1bfecd..92a7b168c2 100644 --- a/src/resolve/resolved-conf.c +++ b/src/resolve/resolved-conf.c @@ -255,20 +255,21 @@ int config_parse_dnssd_service_name( 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"); - - 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; + r = specifier_printf(rvalue, specifier_table, 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; } - return 0; + if (!dns_service_name_is_valid(name)) { + 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 free_and_strdup_warn(&s->name_template, rvalue); } int config_parse_dnssd_service_type(