summaryrefslogtreecommitdiff
path: root/src/resolve/resolved-conf.c
diff options
context:
space:
mode:
authorRoman Beranek <roman.beranek@prusa3d.com>2020-11-17 05:37:58 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2020-11-18 03:16:57 +0900
commit07e4a8dc2353e410020245aa5f448f41a4ef2b57 (patch)
tree497a5dc0db5164d2b53fcea53067ae3aff09ceea /src/resolve/resolved-conf.c
parent478f5aac079ee29d59887d08c03962dd4ee42cc2 (diff)
downloadsystemd-07e4a8dc2353e410020245aa5f448f41a4ef2b57.tar.gz
Revert "resolve: check DNSSD service name template before assigning it"
This reverts commit 34136e1503cf60852051adbd8b9a002d6282b750. Having the "%H" host name specifier in a DNSSD service name template triggers a failed assertion during name template instantiation as specifier_dnssd_host_name expects DnssdService in its userdata pointer but finds NULL instead.
Diffstat (limited to 'src/resolve/resolved-conf.c')
-rw-r--r--src/resolve/resolved-conf.c48
1 files changed, 25 insertions, 23 deletions
diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c
index 476060ad25..d8646094c0 100644
--- a/src/resolve/resolved-conf.c
+++ b/src/resolve/resolved-conf.c
@@ -217,19 +217,21 @@ 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 },
+ { 'o', specifier_os_id, NULL },
+ { 'w', specifier_os_version_id, NULL },
+ { 'B', specifier_os_build_id, NULL },
+ { 'W', specifier_os_variant_id, NULL },
+ {}
+ };
DnssdService *s = userdata;
+ _cleanup_free_ char *name = NULL;
int r;
assert(filename);
@@ -238,23 +240,23 @@ int config_parse_dnssd_service_name(
assert(s);
if (isempty(rvalue)) {
- s->name_template = mfree(s->name_template);
- return 0;
- }
-
- r = dnssd_render_instance_name(rvalue, NULL);
- if (r == -ENOMEM)
- return log_oom();
- if (r < 0) {
- log_syntax(unit, LOG_WARNING, filename, line, r,
- "Invalid service instance name template '%s', ignoring: %m", rvalue);
- return 0;
+ log_syntax(unit, LOG_ERR, filename, line, 0, "Service instance name can't be empty. Ignoring.");
+ return -EINVAL;
}
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;
+ }
+
return 0;
}