mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-03-08 20:58:20 +03:00
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.
This commit is contained in:
parent
478f5aac07
commit
07e4a8dc23
@ -1795,6 +1795,7 @@ static int bus_method_register_service(sd_bus_message *message, void *userdata,
|
||||
_cleanup_(dnssd_service_freep) DnssdService *service = NULL;
|
||||
_cleanup_(sd_bus_track_unrefp) sd_bus_track *bus_track = NULL;
|
||||
_cleanup_free_ char *path = NULL;
|
||||
_cleanup_free_ char *instance_name = NULL;
|
||||
Manager *m = userdata;
|
||||
DnssdService *s = NULL;
|
||||
const char *name;
|
||||
@ -1835,10 +1836,6 @@ static int bus_method_register_service(sd_bus_message *message, void *userdata,
|
||||
if (!dnssd_srv_type_is_valid(type))
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "DNS-SD service type '%s' is invalid", type);
|
||||
|
||||
r = dnssd_render_instance_name(name_template, NULL);
|
||||
if (r < 0)
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "DNS-SD service name '%s' is invalid", name_template);
|
||||
|
||||
service->name = strdup(name);
|
||||
if (!service->name)
|
||||
return log_oom();
|
||||
@ -1851,6 +1848,10 @@ static int bus_method_register_service(sd_bus_message *message, void *userdata,
|
||||
if (!service->type)
|
||||
return log_oom();
|
||||
|
||||
r = dnssd_render_instance_name(service, &instance_name);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_message_enter_container(message, SD_BUS_TYPE_ARRAY, "a{say}");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ static int specifier_dnssd_host_name(char specifier, const void *data, const voi
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dnssd_render_instance_name(const char *name_template, char **ret_name) {
|
||||
int dnssd_render_instance_name(DnssdService *s, char **ret_name) {
|
||||
static const Specifier specifier_table[] = {
|
||||
{ 'm', specifier_machine_id, NULL },
|
||||
{ 'b', specifier_boot_id, NULL },
|
||||
@ -171,17 +171,19 @@ int dnssd_render_instance_name(const char *name_template, char **ret_name) {
|
||||
_cleanup_free_ char *name = NULL;
|
||||
int r;
|
||||
|
||||
assert(name_template);
|
||||
assert(s);
|
||||
assert(s->name_template);
|
||||
|
||||
r = specifier_printf(name_template, specifier_table, NULL, &name);
|
||||
r = specifier_printf(s->name_template, specifier_table, s, &name);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return log_debug_errno(r, "Failed to replace specifiers: %m");
|
||||
|
||||
if (!dns_service_name_is_valid(name))
|
||||
return -EINVAL;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Service instance name '%s' is invalid.",
|
||||
name);
|
||||
|
||||
if (ret_name)
|
||||
*ret_name = TAKE_PTR(name);
|
||||
*ret_name = TAKE_PTR(name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -225,7 +227,7 @@ int dnssd_update_rrs(DnssdService *s) {
|
||||
LIST_FOREACH(items, txt_data, s->txt_data_items)
|
||||
txt_data->rr = dns_resource_record_unref(txt_data->rr);
|
||||
|
||||
r = dnssd_render_instance_name(s->name_template, &n);
|
||||
r = dnssd_render_instance_name(s, &n);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -53,7 +53,7 @@ DnssdTxtData *dnssd_txtdata_free_all(DnssdTxtData *txt_data);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(DnssdService*, dnssd_service_free);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(DnssdTxtData*, dnssd_txtdata_free);
|
||||
|
||||
int dnssd_render_instance_name(const char *name_template, char **ret_name);
|
||||
int dnssd_render_instance_name(DnssdService *s, char **ret_name);
|
||||
int dnssd_load(Manager *manager);
|
||||
int dnssd_txt_item_new_from_string(const char *key, const char *value, DnsTxtItem **ret_item);
|
||||
int dnssd_txt_item_new_from_data(const char *key, const void *value, const size_t size, DnsTxtItem **ret_item);
|
||||
|
Loading…
x
Reference in New Issue
Block a user