/* SPDX-License-Identifier: LGPL-2.1+ */
-/***
- Copyright 2014 Lennart Poettering
-***/
#include "alloc-util.h"
#include "bus-common-errors.h"
+#include "bus-polkit.h"
#include "bus-util.h"
#include "dns-domain.h"
+#include "memory-util.h"
+#include "missing_capability.h"
#include "resolved-bus.h"
#include "resolved-def.h"
#include "resolved-dns-synthesize.h"
-#include "resolved-dnssd.h"
#include "resolved-dnssd-bus.h"
+#include "resolved-dnssd.h"
#include "resolved-link-bus.h"
+#include "socket-netlink.h"
+#include "stdio-util.h"
+#include "strv.h"
+#include "syslog-util.h"
#include "user-util.h"
#include "utf8.h"
rc = dns_rcode_to_string(q->answer_rcode);
if (!rc) {
- sprintf(p, "%i", q->answer_rcode);
+ xsprintf(p, "%i", q->answer_rcode);
rc = p;
}
/* The key names are not necessarily normalized, make sure that they are when we return them to our bus
* clients. */
- r = dns_name_normalize(dns_resource_key_name(canonical->key), &normalized);
+ r = dns_name_normalize(dns_resource_key_name(canonical->key), 0, &normalized);
if (r < 0)
goto finish;
if (r == 0)
continue;
- r = dns_name_normalize(rr->ptr.name, &normalized);
+ r = dns_name_normalize(rr->ptr.name, 0, &normalized);
if (r < 0)
goto finish;
if (r < 0)
return r;
- r = dns_name_normalize(rr->srv.name, &normalized);
+ r = dns_name_normalize(rr->srv.name, 0, &normalized);
if (r < 0)
return r;
if (canonical) {
normalized = mfree(normalized);
- r = dns_name_normalize(dns_resource_key_name(canonical->key), &normalized);
+ r = dns_name_normalize(dns_resource_key_name(canonical->key), 0, &normalized);
if (r < 0)
return r;
}
if (has_root_domain && found <= 0) {
/* If there's exactly one SRV RR and it uses
- * the root domain as host name, then the
+ * the root domain as hostname, then the
* service is explicitly not offered on the
* domain. Report this as a recognizable
* error. See RFC 2782, Section "Usage
return r;
}
- HASHMAP_FOREACH(l, m->links, i) {
+ HASHMAP_FOREACH(l, m->links, i)
LIST_FOREACH(servers, s, l->dns_servers) {
r = bus_dns_server_append(reply, s, true);
if (r < 0)
return r;
}
- }
return sd_bus_message_close_container(reply);
}
return call_link_method(userdata, message, bus_link_method_set_domains, error);
}
+static int bus_method_set_link_default_route(sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ return call_link_method(userdata, message, bus_link_method_set_default_route, error);
+}
+
static int bus_method_set_link_llmnr(sd_bus_message *message, void *userdata, sd_bus_error *error) {
return call_link_method(userdata, message, bus_link_method_set_llmnr, error);
}
if (m->mdns_support != RESOLVE_SUPPORT_YES)
return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Support for MulticastDNS is disabled");
- r = bus_verify_polkit_async(message, CAP_SYS_ADMIN,
- "org.freedesktop.resolve1.register-service",
- NULL, false, UID_INVALID,
- &m->polkit_registry, error);
- if (r < 0)
- return r;
- if (r == 0)
- return 1; /* Polkit will call us back */
-
service = new0(DnssdService, 1);
if (!service)
return log_oom();
if (r < 0)
return r;
+ r = bus_verify_polkit_async(message, CAP_SYS_ADMIN,
+ "org.freedesktop.resolve1.register-service",
+ NULL, false, UID_INVALID,
+ &m->polkit_registry, error);
+ if (r < 0)
+ return r;
+ if (r == 0)
+ return 1; /* Polkit will call us back */
+
r = hashmap_ensure_allocated(&m->dnssd_services, &string_hash_ops);
if (r < 0)
return r;
return call_dnssd_method(m, message, bus_dnssd_method_unregister, error);
}
+static int property_get_log_level(
+ sd_bus *bus,
+ const char *path,
+ const char *interface,
+ const char *property,
+ sd_bus_message *reply,
+ void *userdata,
+ sd_bus_error *error) {
+
+ _cleanup_free_ char *t = NULL;
+ int r;
+
+ assert(bus);
+ assert(reply);
+
+ r = log_level_to_string_alloc(log_get_max_level(), &t);
+ if (r < 0)
+ return r;
+
+ return sd_bus_message_append(reply, "s", t);
+}
+
+static int property_set_log_level(
+ sd_bus *bus,
+ const char *path,
+ const char *interface,
+ const char *property,
+ sd_bus_message *value,
+ void *userdata,
+ sd_bus_error *error) {
+
+ const char *t;
+ int r;
+
+ assert(bus);
+ assert(value);
+
+ r = sd_bus_message_read(value, "s", &t);
+ if (r < 0)
+ return r;
+
+ r = log_level_from_string(t);
+ if (r < 0)
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid log level '%s'", t);
+
+ log_info("Setting log level to %s.", t);
+ log_set_max_level(r);
+
+ return 0;
+}
+
static const sd_bus_vtable resolve_vtable[] = {
SD_BUS_VTABLE_START(0),
- SD_BUS_PROPERTY("LLMNRHostname", "s", NULL, offsetof(Manager, llmnr_hostname), 0),
+ SD_BUS_PROPERTY("LLMNRHostname", "s", NULL, offsetof(Manager, llmnr_hostname), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("LLMNR", "s", bus_property_get_resolve_support, offsetof(Manager, llmnr_support), 0),
SD_BUS_PROPERTY("MulticastDNS", "s", bus_property_get_resolve_support, offsetof(Manager, mdns_support), 0),
SD_BUS_PROPERTY("DNSOverTLS", "s", bus_property_get_dns_over_tls_mode, 0, 0),
- SD_BUS_PROPERTY("DNS", "a(iiay)", bus_property_get_dns_servers, 0, 0),
+ SD_BUS_PROPERTY("DNS", "a(iiay)", bus_property_get_dns_servers, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("FallbackDNS", "a(iiay)", bus_property_get_fallback_dns_servers, offsetof(Manager, fallback_dns_servers), SD_BUS_VTABLE_PROPERTY_CONST),
- SD_BUS_PROPERTY("CurrentDNSServer", "(iiay)", bus_property_get_current_dns_server, offsetof(Manager, current_dns_server), 0),
+ SD_BUS_PROPERTY("CurrentDNSServer", "(iiay)", bus_property_get_current_dns_server, offsetof(Manager, current_dns_server), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("Domains", "a(isb)", bus_property_get_domains, 0, 0),
SD_BUS_PROPERTY("TransactionStatistics", "(tt)", bus_property_get_transaction_statistics, 0, 0),
SD_BUS_PROPERTY("CacheStatistics", "(ttt)", bus_property_get_cache_statistics, 0, 0),
SD_BUS_PROPERTY("DNSSECNegativeTrustAnchors", "as", bus_property_get_ntas, 0, 0),
SD_BUS_PROPERTY("DNSStubListener", "s", bus_property_get_dns_stub_listener_mode, offsetof(Manager, dns_stub_listener_mode), 0),
- SD_BUS_METHOD("ResolveHostname", "isit", "a(iiay)st", bus_method_resolve_hostname, SD_BUS_VTABLE_UNPRIVILEGED),
- SD_BUS_METHOD("ResolveAddress", "iiayt", "a(is)t", bus_method_resolve_address, SD_BUS_VTABLE_UNPRIVILEGED),
- SD_BUS_METHOD("ResolveRecord", "isqqt", "a(iqqay)t", bus_method_resolve_record, SD_BUS_VTABLE_UNPRIVILEGED),
- SD_BUS_METHOD("ResolveService", "isssit", "a(qqqsa(iiay)s)aayssst", bus_method_resolve_service, SD_BUS_VTABLE_UNPRIVILEGED),
- SD_BUS_METHOD("ResetStatistics", NULL, NULL, bus_method_reset_statistics, 0),
- SD_BUS_METHOD("FlushCaches", NULL, NULL, bus_method_flush_caches, 0),
- SD_BUS_METHOD("ResetServerFeatures", NULL, NULL, bus_method_reset_server_features, 0),
- SD_BUS_METHOD("GetLink", "i", "o", bus_method_get_link, SD_BUS_VTABLE_UNPRIVILEGED),
- SD_BUS_METHOD("SetLinkDNS", "ia(iay)", NULL, bus_method_set_link_dns_servers, 0),
- SD_BUS_METHOD("SetLinkDomains", "ia(sb)", NULL, bus_method_set_link_domains, 0),
- SD_BUS_METHOD("SetLinkLLMNR", "is", NULL, bus_method_set_link_llmnr, 0),
- SD_BUS_METHOD("SetLinkMulticastDNS", "is", NULL, bus_method_set_link_mdns, 0),
- SD_BUS_METHOD("SetLinkDNSOverTLS", "is", NULL, bus_method_set_link_dns_over_tls, 0),
- SD_BUS_METHOD("SetLinkDNSSEC", "is", NULL, bus_method_set_link_dnssec, 0),
- SD_BUS_METHOD("SetLinkDNSSECNegativeTrustAnchors", "ias", NULL, bus_method_set_link_dnssec_negative_trust_anchors, 0),
- SD_BUS_METHOD("RevertLink", "i", NULL, bus_method_revert_link, 0),
-
- SD_BUS_METHOD("RegisterService", "sssqqqaa{say}", "o", bus_method_register_service, SD_BUS_VTABLE_UNPRIVILEGED),
- SD_BUS_METHOD("UnregisterService", "o", NULL, bus_method_unregister_service, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_WRITABLE_PROPERTY("LogLevel", "s", property_get_log_level, property_set_log_level, 0, 0),
+
+ SD_BUS_METHOD_WITH_NAMES("ResolveHostname",
+ "isit",
+ SD_BUS_PARAM(ifindex)
+ SD_BUS_PARAM(name)
+ SD_BUS_PARAM(family)
+ SD_BUS_PARAM(flags),
+ "a(iiay)st",
+ SD_BUS_PARAM(addresses)
+ SD_BUS_PARAM(canonical)
+ SD_BUS_PARAM(flags),
+ bus_method_resolve_hostname,
+ SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD_WITH_NAMES("ResolveAddress",
+ "iiayt",
+ SD_BUS_PARAM(ifindex)
+ SD_BUS_PARAM(family)
+ SD_BUS_PARAM(address)
+ SD_BUS_PARAM(flags),
+ "a(is)t",
+ SD_BUS_PARAM(names)
+ SD_BUS_PARAM(flags),
+ bus_method_resolve_address,
+ SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD_WITH_NAMES("ResolveRecord",
+ "isqqt",
+ SD_BUS_PARAM(ifindex)
+ SD_BUS_PARAM(name)
+ SD_BUS_PARAM(class)
+ SD_BUS_PARAM(type)
+ SD_BUS_PARAM(flags),
+ "a(iqqay)t",
+ SD_BUS_PARAM(records)
+ SD_BUS_PARAM(flags),
+ bus_method_resolve_record,
+ SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD_WITH_NAMES("ResolveService",
+ "isssit",
+ SD_BUS_PARAM(ifindex)
+ SD_BUS_PARAM(name)
+ SD_BUS_PARAM(type)
+ SD_BUS_PARAM(domain)
+ SD_BUS_PARAM(family)
+ SD_BUS_PARAM(flags),
+ "a(qqqsa(iiay)s)aayssst",
+ SD_BUS_PARAM(srv_data)
+ SD_BUS_PARAM(txt_data)
+ SD_BUS_PARAM(canonical_name)
+ SD_BUS_PARAM(canonical_type)
+ SD_BUS_PARAM(canonical_domain)
+ SD_BUS_PARAM(flags),
+ bus_method_resolve_service,
+ SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD_WITH_NAMES("GetLink",
+ "i",
+ SD_BUS_PARAM(ifindex),
+ "o",
+ SD_BUS_PARAM(path),
+ bus_method_get_link,
+ SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD_WITH_NAMES("SetLinkDNS",
+ "ia(iay)",
+ SD_BUS_PARAM(ifindex)
+ SD_BUS_PARAM(addresses),
+ NULL,,
+ bus_method_set_link_dns_servers,
+ SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD_WITH_NAMES("SetLinkDomains",
+ "ia(sb)",
+ SD_BUS_PARAM(ifindex)
+ SD_BUS_PARAM(domains),
+ NULL,,
+ bus_method_set_link_domains,
+ SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD_WITH_NAMES("SetLinkDefaultRoute",
+ "ib",
+ SD_BUS_PARAM(ifindex)
+ SD_BUS_PARAM(enable),
+ NULL,,
+ bus_method_set_link_default_route,
+ SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD_WITH_NAMES("SetLinkLLMNR",
+ "is",
+ SD_BUS_PARAM(ifindex)
+ SD_BUS_PARAM(mode),
+ NULL,,
+ bus_method_set_link_llmnr,
+ SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD_WITH_NAMES("SetLinkMulticastDNS",
+ "is",
+ SD_BUS_PARAM(ifindex)
+ SD_BUS_PARAM(mode),
+ NULL,,
+ bus_method_set_link_mdns,
+ SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD_WITH_NAMES("SetLinkDNSOverTLS",
+ "is",
+ SD_BUS_PARAM(ifindex)
+ SD_BUS_PARAM(mode),
+ NULL,,
+ bus_method_set_link_dns_over_tls,
+ SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD_WITH_NAMES("SetLinkDNSSEC",
+ "is",
+ SD_BUS_PARAM(ifindex)
+ SD_BUS_PARAM(mode),
+ NULL,,
+ bus_method_set_link_dnssec,
+ SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD_WITH_NAMES("SetLinkDNSSECNegativeTrustAnchors",
+ "ias",
+ SD_BUS_PARAM(ifindex)
+ SD_BUS_PARAM(names),
+ NULL,,
+ bus_method_set_link_dnssec_negative_trust_anchors,
+ SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD_WITH_NAMES("RevertLink",
+ "i",
+ SD_BUS_PARAM(ifindex),
+ NULL,,
+ bus_method_revert_link,
+ SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD_WITH_NAMES("RegisterService",
+ "sssqqqaa{say}",
+ SD_BUS_PARAM(name)
+ SD_BUS_PARAM(name_template)
+ SD_BUS_PARAM(type)
+ SD_BUS_PARAM(service_port)
+ SD_BUS_PARAM(service_priority)
+ SD_BUS_PARAM(serwise_weight)
+ SD_BUS_PARAM(txt_datas),
+ "o",
+ SD_BUS_PARAM(service_path),
+ bus_method_register_service,
+ SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD_WITH_NAMES("UnregisterService",
+ "o",
+ SD_BUS_PARAM(service_path),
+ NULL,,
+ bus_method_unregister_service,
+ SD_BUS_VTABLE_UNPRIVILEGED),
+
+ SD_BUS_METHOD("ResetStatistics",
+ NULL,
+ NULL,
+ bus_method_reset_statistics,
+ SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("FlushCaches",
+ NULL,
+ NULL,
+ bus_method_flush_caches,
+ SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("ResetServerFeatures",
+ NULL,
+ NULL,
+ bus_method_reset_server_features,
+ SD_BUS_VTABLE_UNPRIVILEGED),
+
SD_BUS_VTABLE_END,
};
if (r < 0)
return log_error_errno(r, "Failed to register dnssd enumerator: %m");
- r = bus_request_name_async_may_reload_dbus(m->bus, NULL, "org.freedesktop.resolve1", 0, NULL);
+ r = sd_bus_request_name_async(m->bus, NULL, "org.freedesktop.resolve1", 0, NULL, NULL);
if (r < 0)
return log_error_errno(r, "Failed to request name: %m");
r = sd_bus_match_signal_async(
m->bus,
- &m->prepare_for_sleep_slot,
+ NULL,
"org.freedesktop.login1",
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
return 0;
}
+
+int _manager_send_changed(Manager *manager, const char *property, ...) {
+ assert(manager);
+
+ char **l = strv_from_stdarg_alloca(property);
+
+ int r = sd_bus_emit_properties_changed_strv(
+ manager->bus,
+ "/org/freedesktop/resolve1",
+ "org.freedesktop.resolve1.Manager",
+ l);
+ if (r < 0)
+ log_notice_errno(r, "Failed to emit notification about changed property %s: %m", property);
+ return r;
+}