2 This file is part of systemd.
4 Copyright 2017 Dmitry Rozhkov
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 #include "alloc-util.h"
22 #include "resolved-dnssd.h"
23 #include "resolved-dnssd-bus.h"
24 #include "resolved-link.h"
26 #include "user-util.h"
28 int bus_dnssd_method_unregister(sd_bus_message
*message
, void *userdata
, sd_bus_error
*error
) {
29 DnssdService
*s
= userdata
;
30 DnssdTxtData
*txt_data
;
41 r
= bus_verify_polkit_async(message
, CAP_SYS_ADMIN
,
42 "org.freedesktop.resolve1.unregister-service",
43 NULL
, false, s
->originator
,
44 &m
->polkit_registry
, error
);
48 return 1; /* Polkit will call us back */
50 HASHMAP_FOREACH(l
, m
->links
, i
) {
51 if (l
->mdns_ipv4_scope
) {
52 r
= dns_scope_announce(l
->mdns_ipv4_scope
, true);
54 log_warning_errno(r
, "Failed to send goodbye messages in IPv4 scope: %m");
56 dns_zone_remove_rr(&l
->mdns_ipv4_scope
->zone
, s
->ptr_rr
);
57 dns_zone_remove_rr(&l
->mdns_ipv4_scope
->zone
, s
->srv_rr
);
58 LIST_FOREACH(items
, txt_data
, s
->txt_data_items
)
59 dns_zone_remove_rr(&l
->mdns_ipv4_scope
->zone
, txt_data
->rr
);
62 if (l
->mdns_ipv6_scope
) {
63 r
= dns_scope_announce(l
->mdns_ipv6_scope
, true);
65 log_warning_errno(r
, "Failed to send goodbye messages in IPv6 scope: %m");
67 dns_zone_remove_rr(&l
->mdns_ipv6_scope
->zone
, s
->ptr_rr
);
68 dns_zone_remove_rr(&l
->mdns_ipv6_scope
->zone
, s
->srv_rr
);
69 LIST_FOREACH(items
, txt_data
, s
->txt_data_items
)
70 dns_zone_remove_rr(&l
->mdns_ipv6_scope
->zone
, txt_data
->rr
);
74 dnssd_service_free(s
);
76 manager_refresh_rrs(m
);
78 return sd_bus_reply_method_return(message
, NULL
);
81 const sd_bus_vtable dnssd_vtable
[] = {
82 SD_BUS_VTABLE_START(0),
84 SD_BUS_METHOD("Unregister", NULL
, NULL
, bus_dnssd_method_unregister
, SD_BUS_VTABLE_UNPRIVILEGED
),
85 SD_BUS_SIGNAL("Conflicted", NULL
, 0),
90 int dnssd_object_find(sd_bus
*bus
, const char *path
, const char *interface
, void *userdata
, void **found
, sd_bus_error
*error
) {
91 _cleanup_free_
char *name
= NULL
;
92 Manager
*m
= userdata
;
93 DnssdService
*service
;
102 r
= sd_bus_path_decode(path
, "/org/freedesktop/resolve1/dnssd", &name
);
106 service
= hashmap_get(m
->dnssd_services
, name
);
114 int dnssd_node_enumerator(sd_bus
*bus
, const char *path
, void *userdata
, char ***nodes
, sd_bus_error
*error
) {
115 _cleanup_strv_free_
char **l
= NULL
;
116 Manager
*m
= userdata
;
117 DnssdService
*service
;
127 l
= new0(char*, hashmap_size(m
->dnssd_services
) + 1);
131 HASHMAP_FOREACH(service
, m
->dnssd_services
, i
) {
134 r
= sd_bus_path_encode("/org/freedesktop/resolve1/dnssd", service
->name
, &p
);