diff options
Diffstat (limited to 'avahi-daemon')
56 files changed, 1635 insertions, 719 deletions
diff --git a/avahi-daemon/.gitignore b/avahi-daemon/.gitignore index bb2aeab..f1a6f8d 100644 --- a/avahi-daemon/.gitignore +++ b/avahi-daemon/.gitignore @@ -1,3 +1,5 @@ +avahi-daemon.service +avahi-daemon.socket avahi-daemon avahi-dbus.conf ini-file-parser-test diff --git a/avahi-daemon/Makefile.am b/avahi-daemon/Makefile.am index 0aac0fc..b5d2bf4 100644 --- a/avahi-daemon/Makefile.am +++ b/avahi-daemon/Makefile.am @@ -1,7 +1,5 @@ -# $Id$ -# # This file is part of avahi. -# +# # avahi is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2 of the @@ -27,7 +25,8 @@ if HAVE_XML pkgsysconfdir=$(sysconfdir)/avahi servicedir=$(pkgsysconfdir)/services -introspectiondir=$(pkgdatadir)/introspection +introspectiondir=$(datadir)/dbus-1/interfaces +dbussystemservicesdir=$(datadir)/dbus-1/system-services AM_CFLAGS+= \ -DAVAHI_DAEMON_RUNTIME_DIR=\"$(avahi_runtime_dir)/avahi-daemon/\" \ @@ -53,6 +52,7 @@ avahi_daemon_SOURCES = \ static-hosts.c static-hosts.h \ ini-file-parser.c ini-file-parser.h \ setproctitle.c setproctitle.h \ + sd-daemon.h sd-daemon.c \ ../avahi-client/check-nss.c avahi_daemon_CFLAGS = $(AM_CFLAGS) $(LIBDAEMON_CFLAGS) $(XML_CFLAGS) @@ -63,19 +63,37 @@ ini_file_parser_test_SOURCES = \ ini-file-parser-test.c ini_file_parser_test_CFLAGS = $(AM_CFLAGS) -ini_file_parser_test_LDADD = $(AM_LDADD) ../avahi-common/libavahi-common.la ../avahi-core/libavahi-core.la +ini_file_parser_test_LDADD = $(AM_LDADD) ../avahi-common/libavahi-common.la ../avahi-core/libavahi-core.la pkgsysconf_DATA = \ avahi-daemon.conf \ hosts -service_DATA = \ +dist_service_DATA = \ ssh.service \ sftp-ssh.service -pkgdata_DATA = \ +dist_pkgdata_DATA = \ avahi-service.dtd +%.service: %.service.in + $(AM_V_GEN)sed -e 's,@sbindir\@,$(sbindir),g' $< > $@ + +%.socket: %.socket.in + $(AM_V_GEN)sed -e 's,@sbindir\@,$(sbindir),g' \ + -e 's,@avahi_runtime_dir\@,$(avahi_runtime_dir),g' $< > $@ + +if HAVE_SYSTEMD +systemdsystemunit_DATA = \ + avahi-daemon.service \ + avahi-daemon.socket + +dist_dbussystemservices_DATA = \ + org.freedesktop.Avahi.service +endif + +CLEANFILES = $(systemdsystemunit_DATA) + if ENABLE_CHROOT avahi_daemon_SOURCES += \ @@ -117,43 +135,32 @@ avahi_daemon_LDADD += \ avahi_daemon_CFLAGS += $(DBUS_CFLAGS) -DDBUS_SYSTEM_BUS_DEFAULT_ADDRESS=\"$(DBUS_SYSTEM_BUS_DEFAULT_ADDRESS)\" -dbusservice_DATA = avahi-dbus.conf +dist_dbusservice_DATA = avahi-dbus.conf -introspection_DATA = \ - Server.introspect \ - EntryGroup.introspect \ - DomainBrowser.introspect \ - ServiceTypeBrowser.introspect \ - ServiceBrowser.introspect \ - ServiceResolver.introspect \ - AddressResolver.introspect \ - HostNameResolver.introspect \ - RecordBrowser.introspect +dist_introspection_DATA = \ + org.freedesktop.Avahi.Server.xml \ + org.freedesktop.Avahi.EntryGroup.xml \ + org.freedesktop.Avahi.DomainBrowser.xml \ + org.freedesktop.Avahi.ServiceTypeBrowser.xml \ + org.freedesktop.Avahi.ServiceBrowser.xml \ + org.freedesktop.Avahi.ServiceResolver.xml \ + org.freedesktop.Avahi.AddressResolver.xml \ + org.freedesktop.Avahi.HostNameResolver.xml \ + org.freedesktop.Avahi.RecordBrowser.xml endif endif endif EXTRA_DIST = \ - avahi-service.dtd \ avahi-daemon.conf \ example.service \ - avahi-dbus.conf \ - Server.introspect \ - EntryGroup.introspect \ - DomainBrowser.introspect \ - ServiceTypeBrowser.introspect \ - ServiceBrowser.introspect \ - ServiceResolver.introspect \ - AddressResolver.introspect \ - HostNameResolver.introspect \ - RecordBrowser.introspect \ - ssh.service \ - sftp-ssh.service \ hosts \ example.service \ introspect.dtd \ - introspect.xsl + introspect.xsl \ + avahi-daemon.service.in \ + avahi-daemon.socket.in xmllint: xmllint --noout --valid example.service @@ -163,3 +170,7 @@ xmllint: install-data-local: test -z "$(localstatedir)/run" || $(mkdir_p) "$(DESTDIR)$(localstatedir)/run" + +update-systemd: + curl http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.c > sd-daemon.c + curl http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.h > sd-daemon.h diff --git a/avahi-daemon/avahi-daemon.conf b/avahi-daemon/avahi-daemon.conf index ad69c73..456f330 100644 --- a/avahi-daemon/avahi-daemon.conf +++ b/avahi-daemon/avahi-daemon.conf @@ -1,7 +1,5 @@ -# $Id$ -# # This file is part of avahi. -# +# # avahi is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2 of the @@ -33,6 +31,10 @@ use-ipv6=no #enable-dbus=yes #disallow-other-stacks=no #allow-point-to-point=no +#cache-entries-max=4096 +#clients-max=4096 +#objects-per-client-max=1024 +#entries-per-entry-group-max=32 [wide-area] enable-wide-area=yes diff --git a/avahi-daemon/avahi-daemon.service.in b/avahi-daemon/avahi-daemon.service.in new file mode 100644 index 0000000..d5a9dd4 --- /dev/null +++ b/avahi-daemon/avahi-daemon.service.in @@ -0,0 +1,31 @@ +# This file is part of avahi. +# +# avahi is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# avahi is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +# License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with avahi; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. + +[Unit] +Requires=basic.target avahi-daemon.socket +After=basic.target syslog.target avahi-daemon.socket +Conflicts=shutdown.target + +[Service] +Type=dbus +BusName=org.freedesktop.Avahi +ExecStart=@sbindir@/avahi-daemon -s +ExecReload=@sbindir@/avahi-daemon -r + +[Install] +WantedBy=multi-user.target +Also=avahi-daemon.socket diff --git a/avahi-daemon/avahi-daemon.socket.in b/avahi-daemon/avahi-daemon.socket.in new file mode 100644 index 0000000..b8e6b79 --- /dev/null +++ b/avahi-daemon/avahi-daemon.socket.in @@ -0,0 +1,27 @@ +# This file is part of avahi. +# +# avahi is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# avahi is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +# License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with avahi; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. + +[Unit] +After=sysinit.target +Before=sockets.target +Conflicts=shutdown.target + +[Socket] +ListenStream=@avahi_runtime_dir@/avahi-daemon/socket + +[Install] +WantedBy=sockets.target diff --git a/avahi-daemon/avahi-service.dtd b/avahi-daemon/avahi-service.dtd index c3c25e2..daf9637 100644 --- a/avahi-daemon/avahi-service.dtd +++ b/avahi-daemon/avahi-service.dtd @@ -1,5 +1,3 @@ -<!-- $Id$ --> - <!ELEMENT service-group (name,service+)> <!ATTLIST service-group> <!ELEMENT name (#PCDATA)> diff --git a/avahi-daemon/caps.c b/avahi-daemon/caps.c index fbb9d7a..0e21acf 100644 --- a/avahi-daemon/caps.c +++ b/avahi-daemon/caps.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -38,18 +36,18 @@ int avahi_caps_reduce(void) { int ret = 0; cap_t caps; static cap_value_t cap_values[] = { CAP_SYS_CHROOT, CAP_SETUID, CAP_SETGID }; - + /* Let's reduce our caps to the minimum set and tell Linux to keep * them across setuid(). This is called before we drop * privileges. */ - + caps = cap_init(); assert(caps); cap_clear(caps); cap_set_flag(caps, CAP_EFFECTIVE, 3, cap_values, CAP_SET); cap_set_flag(caps, CAP_PERMITTED, 3, cap_values, CAP_SET); - + if (cap_set_proc(caps) < 0) { avahi_log_error("cap_set_proc() failed: %s", strerror(errno)); ret = -1; @@ -73,7 +71,7 @@ int avahi_caps_reduce2(void) { /* Reduce our caps to the bare minimum and tell Linux not to keep * them across setuid(). This is called after we drop * privileges. */ - + /* No longer retain caps across setuid() */ if (prctl(PR_SET_KEEPCAPS, 0, 0, 0, 0) < 0) { avahi_log_error("prctl(PR_SET_KEEPCAPS) failed: %s", strerror(errno)); @@ -106,12 +104,12 @@ int avahi_caps_drop_all(void) { caps = cap_init(); assert(caps); cap_clear(caps); - + if (cap_set_proc(caps) < 0) { avahi_log_error("cap_set_proc() failed: %s", strerror(errno)); ret = -1; } cap_free(caps); - + return ret; } diff --git a/avahi-daemon/caps.h b/avahi-daemon/caps.h index 788aceb..5119bd0 100644 --- a/avahi-daemon/caps.h +++ b/avahi-daemon/caps.h @@ -1,21 +1,19 @@ #ifndef foocapshfoo #define foocapshfoo -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 diff --git a/avahi-daemon/chroot.c b/avahi-daemon/chroot.c index 20e2f03..d796a39 100644 --- a/avahi-daemon/chroot.c +++ b/avahi-daemon/chroot.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -66,15 +64,15 @@ static const char* const get_file_name_table[AVAHI_CHROOT_MAX] = { NULL, "/etc/resolv.conf", #ifdef HAVE_DBUS - AVAHI_DBUS_INTROSPECTION_DIR"/Server.introspect", - AVAHI_DBUS_INTROSPECTION_DIR"/EntryGroup.introspect", - AVAHI_DBUS_INTROSPECTION_DIR"/AddressResolver.introspect", - AVAHI_DBUS_INTROSPECTION_DIR"/DomainBrowser.introspect", - AVAHI_DBUS_INTROSPECTION_DIR"/HostNameResolver.introspect", - AVAHI_DBUS_INTROSPECTION_DIR"/ServiceBrowser.introspect", - AVAHI_DBUS_INTROSPECTION_DIR"/ServiceResolver.introspect", - AVAHI_DBUS_INTROSPECTION_DIR"/ServiceTypeBrowser.introspect", - AVAHI_DBUS_INTROSPECTION_DIR"/RecordBrowser.introspect", + AVAHI_DBUS_INTROSPECTION_DIR"/org.freedesktop.Avahi.Server.xml", + AVAHI_DBUS_INTROSPECTION_DIR"/org.freedesktop.Avahi.EntryGroup.xml", + AVAHI_DBUS_INTROSPECTION_DIR"/org.freedesktop.Avahi.AddressResolver.xml", + AVAHI_DBUS_INTROSPECTION_DIR"/org.freedesktop.Avahi.DomainBrowser.xml", + AVAHI_DBUS_INTROSPECTION_DIR"/org.freedesktop.Avahi.HostNameResolver.xml", + AVAHI_DBUS_INTROSPECTION_DIR"/org.freedesktop.Avahi.ServiceBrowser.xml", + AVAHI_DBUS_INTROSPECTION_DIR"/org.freedesktop.Avahi.ServiceResolver.xml", + AVAHI_DBUS_INTROSPECTION_DIR"/org.freedesktop.Avahi.ServiceTypeBrowser.xml", + AVAHI_DBUS_INTROSPECTION_DIR"/org.freedesktop.Avahi.RecordBrowser.xml", #endif NULL, NULL @@ -106,19 +104,19 @@ static int send_fd(int fd, int payload_fd) { struct iovec iov; struct msghdr msg; union { - struct cmsghdr hdr; - char buf[CMSG_SPACE(sizeof(int))]; + struct cmsghdr hdr; + char buf[CMSG_SPACE(sizeof(int))]; } cmsg; /* Send a file descriptor over the socket */ - + memset(&iov, 0, sizeof(iov)); memset(&msg, 0, sizeof(msg)); memset(&cmsg, 0, sizeof(cmsg)); - - iov.iov_base = &dummy; + + iov.iov_base = &dummy; iov.iov_len = sizeof(dummy); - + msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_name = NULL; @@ -127,7 +125,7 @@ static int send_fd(int fd, int payload_fd) { msg.msg_control = &cmsg; msg.msg_controllen = sizeof(cmsg); msg.msg_flags = 0; - + cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(int)); cmsg.hdr.cmsg_level = SOL_SOCKET; cmsg.hdr.cmsg_type = SCM_RIGHTS; @@ -146,8 +144,8 @@ static int recv_fd(int fd) { struct iovec iov; struct msghdr msg; union { - struct cmsghdr hdr; - char buf[CMSG_SPACE(sizeof(int))]; + struct cmsghdr hdr; + char buf[CMSG_SPACE(sizeof(int))]; } cmsg; /* Receive a file descriptor from a socket */ @@ -155,10 +153,10 @@ static int recv_fd(int fd) { memset(&iov, 0, sizeof(iov)); memset(&msg, 0, sizeof(msg)); memset(&cmsg, 0, sizeof(cmsg)); - + iov.iov_base = &dummy; iov.iov_len = sizeof(dummy); - + msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_name = NULL; @@ -167,12 +165,12 @@ static int recv_fd(int fd) { msg.msg_control = cmsg.buf; msg.msg_controllen = sizeof(cmsg); msg.msg_flags = 0; - + cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(int)); cmsg.hdr.cmsg_level = SOL_SOCKET; cmsg.hdr.cmsg_type = SCM_RIGHTS; *((int*) CMSG_DATA(&cmsg.hdr)) = -1; - + if (recvmsg(fd, &msg, 0) <= 0) { avahi_log_error("recvmsg() failed: %s", strerror(errno)); return -1; @@ -183,7 +181,7 @@ static int recv_fd(int fd) { errno = EINVAL; return -1; } - + if (!(h = CMSG_FIRSTHDR(&msg))) { avahi_log_error("recvmsg() sent no fd."); errno = EINVAL; @@ -197,7 +195,7 @@ static int recv_fd(int fd) { return *((int*)CMSG_DATA(h)); } } - + static int helper_main(int fd) { int ret = 1; assert(fd >= 0); @@ -207,7 +205,7 @@ static int helper_main(int fd) { * mind that this code is security sensitive! */ avahi_log_debug(__FILE__": chroot() helper started"); - + for (;;) { uint8_t command; ssize_t r; @@ -217,7 +215,7 @@ static int helper_main(int fd) { /* EOF? */ if (r == 0) break; - + avahi_log_error(__FILE__": read() failed: %s", strerror(errno)); goto fail; } @@ -250,7 +248,7 @@ static int helper_main(int fd) { avahi_log_error(__FILE__": write() failed: %s\n", strerror(errno)); goto fail; } - + break; } @@ -258,24 +256,24 @@ static int helper_main(int fd) { goto fail; close(payload); - + break; } case AVAHI_CHROOT_UNLINK_SOCKET: case AVAHI_CHROOT_UNLINK_PID: { uint8_t c = AVAHI_CHROOT_SUCCESS; - + unlink(unlink_file_name_table[(int) command]); if (write(fd, &c, sizeof(c)) != sizeof(c)) { avahi_log_error(__FILE__": write() failed: %s\n", strerror(errno)); goto fail; } - + break; } - + default: avahi_log_error(__FILE__": Unknown command %02x.", command); break; @@ -283,11 +281,11 @@ static int helper_main(int fd) { } ret = 0; - + fail: avahi_log_debug(__FILE__": chroot() helper exiting with return value %i", ret); - + return ret; } @@ -296,12 +294,12 @@ int avahi_chroot_helper_start(const char *argv0) { pid_t pid; assert(helper_fd < 0); - + if (socketpair(AF_UNIX, SOCK_STREAM, 0, sock) < 0) { avahi_log_error("socketpair() failed: %s", strerror(errno)); return -1; } - + if ((pid = fork()) < 0) { close(sock[0]); close(sock[1]); @@ -309,15 +307,13 @@ int avahi_chroot_helper_start(const char *argv0) { return -1; } else if (pid == 0) { - setsid(); - /* Drop all remaining capabilities */ avahi_caps_drop_all(); avahi_set_proc_title(argv0, "%s: chroot helper", argv0); daemon_retval_done(); - + close(sock[0]); helper_main(sock[1]); _exit(0); @@ -342,7 +338,7 @@ int avahi_chroot_helper_get_fd(const char *fname) { if (helper_fd >= 0) { uint8_t command; - + for (command = 2; command < AVAHI_CHROOT_MAX; command++) if (get_file_name_table[(int) command] && strcmp(fname, get_file_name_table[(int) command]) == 0) @@ -355,7 +351,7 @@ int avahi_chroot_helper_get_fd(const char *fname) { } assert(get_file_name_table[(int) command]); - + if (write(helper_fd, &command, sizeof(command)) < 0) { avahi_log_error("write() failed: %s\n", strerror(errno)); return -1; @@ -386,7 +382,7 @@ int avahi_chroot_helper_unlink(const char *fname) { if (helper_fd >= 0) { uint8_t c, command; ssize_t r; - + for (command = 2; command < AVAHI_CHROOT_MAX; command++) if (unlink_file_name_table[(int) command] && strcmp(fname, unlink_file_name_table[(int) command]) == 0) @@ -407,11 +403,11 @@ int avahi_chroot_helper_unlink(const char *fname) { avahi_log_error("read() failed: %s\n", r < 0 ? strerror(errno) : "EOF"); return -1; } - + return 0; - + } else - + return unlink(fname); - + } diff --git a/avahi-daemon/chroot.h b/avahi-daemon/chroot.h index ea61c5a..2828d54 100644 --- a/avahi-daemon/chroot.h +++ b/avahi-daemon/chroot.h @@ -1,21 +1,19 @@ #ifndef foochroothelperhfoo #define foochroothelperhfoo -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 diff --git a/avahi-daemon/dbus-async-address-resolver.c b/avahi-daemon/dbus-async-address-resolver.c index f05af8f..a77e03c 100644 --- a/avahi-daemon/dbus-async-address-resolver.c +++ b/avahi-daemon/dbus-async-address-resolver.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -43,11 +41,11 @@ void avahi_dbus_async_address_resolver_free(AsyncAddressResolverInfo *i) { dbus_connection_unregister_object_path(server->bus, i->path); avahi_free(i->path); } - + AVAHI_LLIST_REMOVE(AsyncAddressResolverInfo, async_address_resolvers, i->client->async_address_resolvers, i); + assert(i->client->n_objects >= 1); i->client->n_objects--; - assert(i->client->n_objects >= 0); avahi_free(i); } @@ -55,12 +53,17 @@ void avahi_dbus_async_address_resolver_free(AsyncAddressResolverInfo *i) { void avahi_dbus_async_address_resolver_callback(AvahiSAddressResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const AvahiAddress *address, const char *host_name, AvahiLookupResultFlags flags, void* userdata) { AsyncAddressResolverInfo *i = userdata; DBusMessage *reply; - + assert(r); assert(i); reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, avahi_dbus_map_resolve_signal_name(event)); - + + if (!reply) { + avahi_log_error("Failed allocate message"); + return; + } + if (event == AVAHI_RESOLVER_FOUND) { char t[AVAHI_ADDRESS_STR_MAX], *pt = t; int32_t i_interface, i_protocol, i_aprotocol; @@ -74,7 +77,7 @@ void avahi_dbus_async_address_resolver_callback(AvahiSAddressResolver *r, AvahiI i_protocol = (int32_t) protocol; i_aprotocol = (int32_t) address->proto; u_flags = (uint32_t) flags; - + dbus_message_append_args( reply, DBUS_TYPE_INT32, &i_interface, @@ -90,7 +93,7 @@ void avahi_dbus_async_address_resolver_callback(AvahiSAddressResolver *r, AvahiI avahi_dbus_append_server_error(reply); } - dbus_message_set_destination(reply, i->client->name); + dbus_message_set_destination(reply, i->client->name); dbus_connection_send(server->bus, reply, NULL); dbus_message_unref(reply); } @@ -102,7 +105,7 @@ DBusHandlerResult avahi_dbus_msg_async_address_resolver_impl(DBusConnection *c, assert(c); assert(m); assert(i); - + dbus_error_init(&error); avahi_log_debug(__FILE__": interface=%s, path=%s, member=%s", @@ -112,12 +115,12 @@ DBusHandlerResult avahi_dbus_msg_async_address_resolver_impl(DBusConnection *c, /* Introspection */ if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) - return avahi_dbus_handle_introspect(c, m, "AddressResolver.introspect"); - + return avahi_dbus_handle_introspect(c, m, "org.freedesktop.Avahi.AddressResolver.xml"); + /* Access control */ - if (strcmp(dbus_message_get_sender(m), i->client->name)) + if (strcmp(dbus_message_get_sender(m), i->client->name)) return avahi_dbus_respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL); - + if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, "Free")) { if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) { @@ -128,12 +131,12 @@ DBusHandlerResult avahi_dbus_msg_async_address_resolver_impl(DBusConnection *c, avahi_dbus_async_address_resolver_free(i); return avahi_dbus_respond_ok(c, m); } - + avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m)); fail: if (dbus_error_is_set(&error)) dbus_error_free(&error); - + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } diff --git a/avahi-daemon/dbus-async-host-name-resolver.c b/avahi-daemon/dbus-async-host-name-resolver.c index a2c99a7..7c2d063 100644 --- a/avahi-daemon/dbus-async-host-name-resolver.c +++ b/avahi-daemon/dbus-async-host-name-resolver.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -45,8 +43,8 @@ void avahi_dbus_async_host_name_resolver_free(AsyncHostNameResolverInfo *i) { } AVAHI_LLIST_REMOVE(AsyncHostNameResolverInfo, async_host_name_resolvers, i->client->async_host_name_resolvers, i); + assert(i->client->n_objects >= 1); i->client->n_objects--; - assert(i->client->n_objects >= 0); avahi_free(i); } @@ -54,12 +52,17 @@ void avahi_dbus_async_host_name_resolver_free(AsyncHostNameResolverInfo *i) { void avahi_dbus_async_host_name_resolver_callback(AvahiSHostNameResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const char *host_name, const AvahiAddress *a, AvahiLookupResultFlags flags, void* userdata) { AsyncHostNameResolverInfo *i = userdata; DBusMessage *reply; - + assert(r); assert(i); reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_HOST_NAME_RESOLVER, avahi_dbus_map_resolve_signal_name(event)); - + + if (!reply) { + avahi_log_error("Failed allocate message"); + return; + } + if (event == AVAHI_RESOLVER_FOUND) { char t[AVAHI_ADDRESS_STR_MAX], *pt = t; int32_t i_interface, i_protocol, i_aprotocol; @@ -73,7 +76,7 @@ void avahi_dbus_async_host_name_resolver_callback(AvahiSHostNameResolver *r, Ava i_protocol = (int32_t) protocol; i_aprotocol = (int32_t) a->proto; u_flags = (uint32_t) flags; - + dbus_message_append_args( reply, DBUS_TYPE_INT32, &i_interface, @@ -88,7 +91,7 @@ void avahi_dbus_async_host_name_resolver_callback(AvahiSHostNameResolver *r, Ava avahi_dbus_append_server_error(reply); } - dbus_message_set_destination(reply, i->client->name); + dbus_message_set_destination(reply, i->client->name); dbus_connection_send(server->bus, reply, NULL); dbus_message_unref(reply); } @@ -100,7 +103,7 @@ DBusHandlerResult avahi_dbus_msg_async_host_name_resolver_impl(DBusConnection *c assert(c); assert(m); assert(i); - + dbus_error_init(&error); avahi_log_debug(__FILE__": interface=%s, path=%s, member=%s", @@ -110,12 +113,12 @@ DBusHandlerResult avahi_dbus_msg_async_host_name_resolver_impl(DBusConnection *c /* Introspection */ if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) - return avahi_dbus_handle_introspect(c, m, "HostNameResolver.introspect"); - + return avahi_dbus_handle_introspect(c, m, "org.freedesktop.Avahi.HostNameResolver.xml"); + /* Access control */ - if (strcmp(dbus_message_get_sender(m), i->client->name)) + if (strcmp(dbus_message_get_sender(m), i->client->name)) return avahi_dbus_respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL); - + if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_HOST_NAME_RESOLVER, "Free")) { if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) { @@ -126,13 +129,12 @@ DBusHandlerResult avahi_dbus_msg_async_host_name_resolver_impl(DBusConnection *c avahi_dbus_async_host_name_resolver_free(i); return avahi_dbus_respond_ok(c, m); } - + avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m)); fail: if (dbus_error_is_set(&error)) dbus_error_free(&error); - + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } - diff --git a/avahi-daemon/dbus-async-service-resolver.c b/avahi-daemon/dbus-async-service-resolver.c index a9a1364..2b58e2d 100644 --- a/avahi-daemon/dbus-async-service-resolver.c +++ b/avahi-daemon/dbus-async-service-resolver.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -43,11 +41,11 @@ void avahi_dbus_async_service_resolver_free(AsyncServiceResolverInfo *i) { dbus_connection_unregister_object_path(server->bus, i->path); avahi_free(i->path); } - + AVAHI_LLIST_REMOVE(AsyncServiceResolverInfo, async_service_resolvers, i->client->async_service_resolvers, i); + assert(i->client->n_objects >= 1); i->client->n_objects--; - assert(i->client->n_objects >= 0); avahi_free(i); } @@ -64,26 +62,31 @@ void avahi_dbus_async_service_resolver_callback( const AvahiAddress *a, uint16_t port, AvahiStringList *txt, - AvahiLookupResultFlags flags, + AvahiLookupResultFlags flags, void* userdata) { AsyncServiceResolverInfo *i = userdata; DBusMessage *reply; - + assert(r); assert(i); reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_SERVICE_RESOLVER, avahi_dbus_map_resolve_signal_name(event)); - + + if (!reply) { + avahi_log_error("Failed allocate message"); + return; + } + if (event == AVAHI_RESOLVER_FOUND) { char t[AVAHI_ADDRESS_STR_MAX], *pt = t; int32_t i_interface, i_protocol, i_aprotocol; uint32_t u_flags; - + assert(host_name); /* avahi_log_debug(__FILE__": [%s] Successfully resolved service <%s.%s.%s>", i->path, name, type, domain); */ - + if (a) avahi_address_snprint(t, sizeof(t), a); else @@ -97,9 +100,9 @@ void avahi_dbus_async_service_resolver_callback( i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; - if (a) + if (a) i_aprotocol = (int32_t) a->proto; - else + else i_aprotocol = AVAHI_PROTO_UNSPEC; u_flags = (uint32_t) flags; @@ -127,7 +130,7 @@ void avahi_dbus_async_service_resolver_callback( avahi_dbus_append_server_error(reply); } - dbus_message_set_destination(reply, i->client->name); + dbus_message_set_destination(reply, i->client->name); dbus_connection_send(server->bus, reply, NULL); dbus_message_unref(reply); } @@ -139,7 +142,7 @@ DBusHandlerResult avahi_dbus_msg_async_service_resolver_impl(DBusConnection *c, assert(c); assert(m); assert(i); - + dbus_error_init(&error); avahi_log_debug(__FILE__": interface=%s, path=%s, member=%s", @@ -149,12 +152,12 @@ DBusHandlerResult avahi_dbus_msg_async_service_resolver_impl(DBusConnection *c, /* Introspection */ if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) - return avahi_dbus_handle_introspect(c, m, "ServiceResolver.introspect"); - + return avahi_dbus_handle_introspect(c, m, "org.freedesktop.Avahi.ServiceResolver.xml"); + /* Access control */ - if (strcmp(dbus_message_get_sender(m), i->client->name)) + if (strcmp(dbus_message_get_sender(m), i->client->name)) return avahi_dbus_respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL); - + if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVICE_RESOLVER, "Free")) { if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) { @@ -165,13 +168,12 @@ DBusHandlerResult avahi_dbus_msg_async_service_resolver_impl(DBusConnection *c, avahi_dbus_async_service_resolver_free(i); return avahi_dbus_respond_ok(c, m); } - + avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m)); fail: if (dbus_error_is_set(&error)) dbus_error_free(&error); - + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } - diff --git a/avahi-daemon/dbus-domain-browser.c b/avahi-daemon/dbus-domain-browser.c index b529ede..e51996f 100644 --- a/avahi-daemon/dbus-domain-browser.c +++ b/avahi-daemon/dbus-domain-browser.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -43,11 +41,11 @@ void avahi_dbus_domain_browser_free(DomainBrowserInfo *i) { dbus_connection_unregister_object_path(server->bus, i->path); avahi_free(i->path); } - + AVAHI_LLIST_REMOVE(DomainBrowserInfo, domain_browsers, i->client->domain_browsers, i); + assert(i->client->n_objects >= 1); i->client->n_objects--; - assert(i->client->n_objects >= 0); avahi_free(i); } @@ -59,7 +57,7 @@ DBusHandlerResult avahi_dbus_msg_domain_browser_impl(DBusConnection *c, DBusMess assert(c); assert(m); assert(i); - + dbus_error_init(&error); avahi_log_debug(__FILE__": interface=%s, path=%s, member=%s", @@ -69,12 +67,12 @@ DBusHandlerResult avahi_dbus_msg_domain_browser_impl(DBusConnection *c, DBusMess /* Introspection */ if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) - return avahi_dbus_handle_introspect(c, m, "DomainBrowser.introspect"); - + return avahi_dbus_handle_introspect(c, m, "org.freedesktop.Avahi.DomainBrowser.xml"); + /* Access control */ - if (strcmp(dbus_message_get_sender(m), i->client->name)) + if (strcmp(dbus_message_get_sender(m), i->client->name)) return avahi_dbus_respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL); - + if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "Free")) { if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) { @@ -84,15 +82,15 @@ DBusHandlerResult avahi_dbus_msg_domain_browser_impl(DBusConnection *c, DBusMess avahi_dbus_domain_browser_free(i); return avahi_dbus_respond_ok(c, m); - + } - + avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m)); fail: if (dbus_error_is_set(&error)) dbus_error_free(&error); - + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } @@ -101,7 +99,7 @@ void avahi_dbus_domain_browser_callback(AvahiSDomainBrowser *b, AvahiIfIndex int DBusMessage *m; int32_t i_interface, i_protocol; uint32_t u_flags; - + assert(b); assert(i); @@ -111,6 +109,11 @@ void avahi_dbus_domain_browser_callback(AvahiSDomainBrowser *b, AvahiIfIndex int m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, avahi_dbus_map_browse_signal_name(event)); + if (!m) { + avahi_log_error("Failed allocate message"); + return; + } + if (event == AVAHI_BROWSER_NEW || event == AVAHI_BROWSER_REMOVE) { assert(domain); dbus_message_append_args( @@ -122,9 +125,8 @@ void avahi_dbus_domain_browser_callback(AvahiSDomainBrowser *b, AvahiIfIndex int DBUS_TYPE_INVALID); } else if (event == AVAHI_BROWSER_FAILURE) avahi_dbus_append_server_error(m); - - dbus_message_set_destination(m, i->client->name); + + dbus_message_set_destination(m, i->client->name); dbus_connection_send(server->bus, m, NULL); dbus_message_unref(m); } - diff --git a/avahi-daemon/dbus-entry-group.c b/avahi-daemon/dbus-entry-group.c index 0e1a21c..4e879a5 100644 --- a/avahi-daemon/dbus-entry-group.c +++ b/avahi-daemon/dbus-entry-group.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -47,9 +45,9 @@ void avahi_dbus_entry_group_free(EntryGroupInfo *i) { } AVAHI_LLIST_REMOVE(EntryGroupInfo, entry_groups, i->client->entry_groups, i); + assert(i->client->n_objects >= 1); i->client->n_objects--; - assert(i->client->n_objects >= 0); - + avahi_free(i); } @@ -58,13 +56,18 @@ void avahi_dbus_entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiE DBusMessage *m; int32_t t; const char *e; - + assert(s); assert(g); assert(i); m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "StateChanged"); - + + if (!m) { + avahi_log_error("Failed allocate message"); + return; + } + t = (int32_t) state; if (state == AVAHI_ENTRY_GROUP_FAILURE) e = avahi_error_number_to_dbus(avahi_server_errno(s)); @@ -72,13 +75,13 @@ void avahi_dbus_entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiE e = AVAHI_DBUS_ERR_COLLISION; else e = AVAHI_DBUS_ERR_OK; - + dbus_message_append_args( m, DBUS_TYPE_INT32, &t, DBUS_TYPE_STRING, &e, DBUS_TYPE_INVALID); - dbus_message_set_destination(m, i->client->name); + dbus_message_set_destination(m, i->client->name); dbus_connection_send(server->bus, m, NULL); dbus_message_unref(m); } @@ -90,7 +93,7 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage assert(c); assert(m); assert(i); - + dbus_error_init(&error); avahi_log_debug(__FILE__": interface=%s, path=%s, member=%s", @@ -100,12 +103,12 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage /* Introspection */ if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) - return avahi_dbus_handle_introspect(c, m, "EntryGroup.introspect"); - + return avahi_dbus_handle_introspect(c, m, "org.freedesktop.Avahi.EntryGroup.xml"); + /* Access control */ - if (strcmp(dbus_message_get_sender(m), i->client->name)) + if (strcmp(dbus_message_get_sender(m), i->client->name)) return avahi_dbus_respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL); - + if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "Free")) { if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) { @@ -115,7 +118,7 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage avahi_dbus_entry_group_free(i); return avahi_dbus_respond_ok(c, m); - + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "Commit")) { if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) { @@ -125,21 +128,21 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage if (avahi_s_entry_group_commit(i->entry_group) < 0) return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL); - + return avahi_dbus_respond_ok(c, m); - - + + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "Reset")) { - + if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) { avahi_log_warn("Error parsing EntryGroup::Reset message"); goto fail; } avahi_s_entry_group_reset(i->entry_group); - i->n_entries = 0; + i->n_entries = 0; return avahi_dbus_respond_ok(c, m); - + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "IsEmpty")) { if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) { @@ -148,10 +151,10 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage } return avahi_dbus_respond_boolean(c, m, !!avahi_s_entry_group_is_empty(i->entry_group)); - + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "GetState")) { AvahiEntryGroupState state; - + if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) { avahi_log_warn("Error parsing EntryGroup::GetState message"); goto fail; @@ -159,14 +162,14 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage state = avahi_s_entry_group_get_state(i->entry_group); return avahi_dbus_respond_int32(c, m, (int32_t) state); - + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddService")) { int32_t interface, protocol; uint32_t flags; char *type, *name, *domain, *host; uint16_t port; AvahiStringList *strlst = NULL; - + if (!dbus_message_get_args( m, &error, DBUS_TYPE_INT32, &interface, @@ -176,7 +179,7 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage DBUS_TYPE_STRING, &type, DBUS_TYPE_STRING, &domain, DBUS_TYPE_STRING, &host, - DBUS_TYPE_UINT16, &port, + DBUS_TYPE_UINT16, &port, DBUS_TYPE_INVALID) || !type || !name || avahi_dbus_read_strlst(m, 8, &strlst) < 0) { @@ -184,7 +187,7 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage goto fail; } - if (!(flags & AVAHI_PUBLISH_UPDATE) && i->n_entries >= ENTRIES_PER_ENTRY_GROUP_MAX) { + if (!(flags & AVAHI_PUBLISH_UPDATE) && i->n_entries >= server->n_entries_per_entry_group_max) { avahi_string_list_free(strlst); return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_ENTRIES, NULL); } @@ -202,17 +205,17 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage if (!(flags & AVAHI_PUBLISH_UPDATE)) i->n_entries ++; - + avahi_string_list_free(strlst); - + return avahi_dbus_respond_ok(c, m); - + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddServiceSubtype")) { int32_t interface, protocol; uint32_t flags; char *type, *name, *domain, *subtype; - + if (!dbus_message_get_args( m, &error, DBUS_TYPE_INT32, &interface, @@ -227,18 +230,18 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage goto fail; } - if (!(flags & AVAHI_PUBLISH_UPDATE) && i->n_entries >= ENTRIES_PER_ENTRY_GROUP_MAX) + if (!(flags & AVAHI_PUBLISH_UPDATE) && i->n_entries >= server->n_entries_per_entry_group_max) return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_ENTRIES, NULL); if (domain && !*domain) domain = NULL; - if (avahi_server_add_service_subtype(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, (AvahiPublishFlags) flags, name, type, domain, subtype) < 0) + if (avahi_server_add_service_subtype(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, (AvahiPublishFlags) flags, name, type, domain, subtype) < 0) return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL); if (!(flags & AVAHI_PUBLISH_UPDATE)) i->n_entries ++; - + return avahi_dbus_respond_ok(c, m); } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "UpdateServiceTxt")) { @@ -246,7 +249,7 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage uint32_t flags; char *type, *name, *domain; AvahiStringList *strlst; - + if (!dbus_message_get_args( m, &error, DBUS_TYPE_INT32, &interface, @@ -271,15 +274,15 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage } avahi_string_list_free(strlst); - + return avahi_dbus_respond_ok(c, m); - + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddAddress")) { int32_t interface, protocol; uint32_t flags; char *name, *address; AvahiAddress a; - + if (!dbus_message_get_args( m, &error, DBUS_TYPE_INT32, &interface, @@ -292,9 +295,9 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage goto fail; } - if (!(flags & AVAHI_PUBLISH_UPDATE) && i->n_entries >= ENTRIES_PER_ENTRY_GROUP_MAX) + if (!(flags & AVAHI_PUBLISH_UPDATE) && i->n_entries >= server->n_entries_per_entry_group_max) return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_ENTRIES, NULL); - + if (!(avahi_address_parse(address, AVAHI_PROTO_UNSPEC, &a))) return avahi_dbus_respond_error(c, m, AVAHI_ERR_INVALID_ADDRESS, NULL); @@ -303,7 +306,7 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage if (!(flags & AVAHI_PUBLISH_UPDATE)) i->n_entries ++; - + return avahi_dbus_respond_ok(c, m); } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddRecord")) { int32_t interface, protocol; @@ -312,7 +315,7 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage char *name; void *rdata; AvahiRecord *r; - + if (!dbus_message_get_args( m, &error, DBUS_TYPE_INT32, &interface, @@ -328,7 +331,7 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage goto fail; } - if (!(flags & AVAHI_PUBLISH_UPDATE) && i->n_entries >= ENTRIES_PER_ENTRY_GROUP_MAX) + if (!(flags & AVAHI_PUBLISH_UPDATE) && i->n_entries >= server->n_entries_per_entry_group_max) return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_ENTRIES, NULL); if (!avahi_is_valid_domain_name (name)) @@ -341,7 +344,7 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage avahi_record_unref (r); return avahi_dbus_respond_error(c, m, AVAHI_ERR_INVALID_RDATA, NULL); } - + if (avahi_server_add(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, (AvahiPublishFlags) flags, r) < 0) { avahi_record_unref (r); return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL); @@ -349,18 +352,18 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage if (!(flags & AVAHI_PUBLISH_UPDATE)) i->n_entries ++; - - avahi_record_unref (r); + + avahi_record_unref (r); return avahi_dbus_respond_ok(c, m); - } - - + } + + avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m)); fail: if (dbus_error_is_set(&error)) dbus_error_free(&error); - + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } diff --git a/avahi-daemon/dbus-internal.h b/avahi-daemon/dbus-internal.h index 11c1094..0b86578 100644 --- a/avahi-daemon/dbus-internal.h +++ b/avahi-daemon/dbus-internal.h @@ -1,21 +1,19 @@ #ifndef foodbusinternalhfoo #define foodbusinternalhfoo -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -45,9 +43,9 @@ typedef struct SyncServiceResolverInfo SyncServiceResolverInfo; typedef struct AsyncServiceResolverInfo AsyncServiceResolverInfo; typedef struct RecordBrowserInfo RecordBrowserInfo; -#define CLIENTS_MAX 256 -#define OBJECTS_PER_CLIENT_MAX 250 -#define ENTRIES_PER_ENTRY_GROUP_MAX 20 +#define DEFAULT_CLIENTS_MAX 4096 +#define DEFAULT_OBJECTS_PER_CLIENT_MAX 1024 +#define DEFAULT_ENTRIES_PER_ENTRY_GROUP_MAX 32 struct EntryGroupInfo { unsigned id; @@ -55,8 +53,8 @@ struct EntryGroupInfo { AvahiSEntryGroup *entry_group; char *path; - int n_entries; - + unsigned n_entries; + AVAHI_LLIST_FIELDS(EntryGroupInfo, entry_groups); }; @@ -151,8 +149,8 @@ struct Client { unsigned id; char *name; unsigned current_id; - int n_objects; - + unsigned n_objects; + AVAHI_LLIST_FIELDS(Client, clients); AVAHI_LLIST_HEAD(EntryGroupInfo, entry_groups); AVAHI_LLIST_HEAD(SyncHostNameResolverInfo, sync_host_name_resolvers); @@ -171,11 +169,17 @@ struct Server { const AvahiPoll *poll_api; DBusConnection *bus; AVAHI_LLIST_HEAD(Client, clients); - int n_clients; + unsigned n_clients; unsigned current_id; AvahiTimeout *reconnect_timeout; int reconnect; + + unsigned n_clients_max; + unsigned n_objects_per_client_max; + unsigned n_entries_per_entry_group_max; + + int disable_user_service_publishing; }; extern Server *server; @@ -224,7 +228,7 @@ void avahi_dbus_sync_service_resolver_callback( const AvahiAddress *a, uint16_t port, AvahiStringList *txt, - AvahiLookupResultFlags flags, + AvahiLookupResultFlags flags, void* userdata); void avahi_dbus_async_service_resolver_free(AsyncServiceResolverInfo *i); @@ -240,7 +244,7 @@ void avahi_dbus_async_service_resolver_callback( const AvahiAddress *a, uint16_t port, AvahiStringList *txt, - AvahiLookupResultFlags flags, + AvahiLookupResultFlags flags, void* userdata); DBusHandlerResult avahi_dbus_msg_async_service_resolver_impl(DBusConnection *c, DBusMessage *m, void *userdata); diff --git a/avahi-daemon/dbus-protocol.c b/avahi-daemon/dbus-protocol.c index d61935a..91ea8fa 100644 --- a/avahi-daemon/dbus-protocol.c +++ b/avahi-daemon/dbus-protocol.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -65,13 +63,11 @@ Server *server = NULL; -static int disable_user_service_publishing = 0; - static int dbus_connect(void); static void dbus_disconnect(void); static void client_free(Client *c) { - + assert(server); assert(c); @@ -83,7 +79,7 @@ static void client_free(Client *c) { while (c->async_host_name_resolvers) avahi_dbus_async_host_name_resolver_free(c->async_host_name_resolvers); - + while (c->sync_address_resolvers) avahi_dbus_sync_address_resolver_free(c->sync_address_resolvers); @@ -109,13 +105,13 @@ static void client_free(Client *c) { avahi_dbus_record_browser_free(c->record_browsers); assert(c->n_objects == 0); - + avahi_free(c->name); AVAHI_LLIST_REMOVE(Client, clients, server->clients, c); avahi_free(c); + assert(server->n_clients >= 1); server->n_clients --; - assert(server->n_clients >= 0); } static Client *client_get(const char *name, int create) { @@ -131,16 +127,16 @@ static Client *client_get(const char *name, int create) { if (!create) return NULL; - if (server->n_clients >= CLIENTS_MAX) + if (server->n_clients >= server->n_clients_max) return NULL; - + /* If not existent yet, create a new entry */ client = avahi_new(Client, 1); client->id = server->current_id++; client->name = avahi_strdup(name); client->current_id = 0; client->n_objects = 0; - + AVAHI_LLIST_HEAD_INIT(EntryGroupInfo, client->entry_groups); AVAHI_LLIST_HEAD_INIT(SyncHostNameResolverInfo, client->sync_host_name_resolvers); AVAHI_LLIST_HEAD_INIT(AsyncHostNameResolverInfo, client->async_host_name_resolvers); @@ -157,7 +153,7 @@ static Client *client_get(const char *name, int create) { server->n_clients++; assert(server->n_clients > 0); - + return client; } @@ -190,11 +186,11 @@ static DBusHandlerResult msg_signal_filter_impl(AVAHI_GCC_UNUSED DBusConnection if (server->reconnect) { avahi_log_warn("Disconnected from D-Bus, trying to reconnect in %ims...", RECONNECT_MSEC); - + dbus_disconnect(); - + avahi_elapse_time(&tv, RECONNECT_MSEC, 0); - + if (server->reconnect_timeout) server->poll_api->timeout_update(server->reconnect_timeout, &tv); else @@ -203,9 +199,9 @@ static DBusHandlerResult msg_signal_filter_impl(AVAHI_GCC_UNUSED DBusConnection avahi_log_warn("Disconnected from D-Bus, exiting."); raise(SIGQUIT); } - + return DBUS_HANDLER_RESULT_HANDLED; - + } else if (dbus_message_is_signal(m, DBUS_INTERFACE_DBUS, "NameAcquired")) { char *name; @@ -216,7 +212,7 @@ static DBusHandlerResult msg_signal_filter_impl(AVAHI_GCC_UNUSED DBusConnection /* avahi_log_info(__FILE__": name acquired (%s)", name); */ return DBUS_HANDLER_RESULT_HANDLED; - + } else if (dbus_message_is_signal(m, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) { char *name, *old, *new; @@ -229,7 +225,7 @@ static DBusHandlerResult msg_signal_filter_impl(AVAHI_GCC_UNUSED DBusConnection Client *client; if ((client = client_get(name, FALSE))) { - avahi_log_debug(__FILE__": client %s vanished.", name); + avahi_log_debug(__FILE__": client %s vanished.", name); client_free(client); } } @@ -238,7 +234,7 @@ static DBusHandlerResult msg_signal_filter_impl(AVAHI_GCC_UNUSED DBusConnection fail: if (dbus_error_is_set(&error)) dbus_error_free(&error); - + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } @@ -253,8 +249,8 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH dbus_message_get_member(m)); if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) - return avahi_dbus_handle_introspect(c, m, "Server.introspect"); - + return avahi_dbus_handle_introspect(c, m, "org.freedesktop.Avahi.Server.xml"); + else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetHostName")) { if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) { @@ -263,23 +259,23 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH } return avahi_dbus_respond_string(c, m, avahi_server_get_host_name(avahi_server)); - + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "SetHostName")) { char *name; - + if (!dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) { avahi_log_warn("Error parsing Server::SetHostName message"); goto fail; } - - if (avahi_server_set_host_name(avahi_server, name) < 0) + + if (avahi_server_set_host_name(avahi_server, name) < 0) return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL); avahi_log_info("Changing host name to '%s'.", name); - + return avahi_dbus_respond_ok(c, m); - + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetDomainName")) { if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) { @@ -295,9 +291,9 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH avahi_log_warn("Error parsing Server::GetHostNameFqdn message"); goto fail; } - + return avahi_dbus_respond_string(c, m, avahi_server_get_host_name_fqdn(avahi_server)); - + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "IsNSSSupportAvailable")) { if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) { avahi_log_warn("Error parsing Server::IsNSSSupportAvailable message"); @@ -305,14 +301,14 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH } return avahi_dbus_respond_boolean(c, m, nss_support); - + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetVersionString")) { if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) { avahi_log_warn("Error parsing Server::GetVersionString message"); goto fail; } - + return avahi_dbus_respond_string(c, m, PACKAGE_STRING); } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetAPIVersion")) { @@ -321,17 +317,17 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH avahi_log_warn("Error parsing Server::GetAPIVersion message"); goto fail; } - + return avahi_dbus_respond_uint32(c, m, AVAHI_DBUS_API_VERSION); } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetState")) { AvahiServerState state; - + if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) { avahi_log_warn("Error parsing Server::GetState message"); goto fail; } - + state = avahi_server_get_state(avahi_server); return avahi_dbus_respond_int32(c, m, (int32_t) state); @@ -341,13 +337,13 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH avahi_log_warn("Error parsing Server::GetLocalServiceCookie message"); goto fail; } - + return avahi_dbus_respond_uint32(c, m, avahi_server_get_local_service_cookie(avahi_server)); } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetNetworkInterfaceNameByIndex")) { int32_t idx; - char name[IF_NAMESIZE]; - + char name[IF_NAMESIZE]; + if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INT32, &idx, DBUS_TYPE_INVALID))) { avahi_log_warn("Error parsing Server::GetNetworkInterfaceNameByIndex message"); goto fail; @@ -361,14 +357,14 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno)); return avahi_dbus_respond_error(c, m, AVAHI_ERR_OS, txt); } - + return avahi_dbus_respond_string(c, m, name); #endif - + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetNetworkInterfaceIndexByName")) { char *n; int32_t idx; - + if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) { avahi_log_warn("Error parsing Server::GetNetworkInterfaceIndexByName message"); goto fail; @@ -382,13 +378,13 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno)); return avahi_dbus_respond_error(c, m, AVAHI_ERR_OS, txt); } - + return avahi_dbus_respond_int32(c, m, idx); #endif } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetAlternativeHostName")) { char *n, * t; - + if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) { avahi_log_warn("Error parsing Server::GetAlternativeHostName message"); goto fail; @@ -402,7 +398,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetAlternativeServiceName")) { char *n, *t; - + if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) { avahi_log_warn("Error parsing Server::GetAlternativeServiceName message"); goto fail; @@ -413,7 +409,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH avahi_free(t); return DBUS_HANDLER_RESULT_HANDLED; - + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "EntryGroupNew")) { Client *client; EntryGroupInfo *i; @@ -431,15 +427,15 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH goto fail; } - if (disable_user_service_publishing) + if (server->disable_user_service_publishing) return avahi_dbus_respond_error(c, m, AVAHI_ERR_NOT_PERMITTED, NULL); - + if (!(client = client_get(dbus_message_get_sender(m), TRUE))) { avahi_log_warn("Too many clients, client request failed."); return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL); } - if (client->n_objects >= OBJECTS_PER_CLIENT_MAX) { + if (client->n_objects >= server->n_objects_per_client_max) { avahi_log_warn("Too many objects for client '%s', client request failed.", client->name); return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL); } @@ -451,7 +447,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH i->n_entries = 0; AVAHI_LLIST_PREPEND(EntryGroupInfo, entry_groups, client->entry_groups, i); client->n_objects++; - + if (!(i->entry_group = avahi_s_entry_group_new(avahi_server, avahi_dbus_entry_group_callback, i))) { avahi_dbus_entry_group_free(i); return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL); @@ -460,14 +456,14 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH i->path = avahi_strdup_printf("/Client%u/EntryGroup%u", client->id, i->id); dbus_connection_register_object_path(c, i->path, &vtable, i); return avahi_dbus_respond_path(c, m, i->path); - + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ResolveHostName")) { Client *client; int32_t interface, protocol, aprotocol; uint32_t flags; char *name; SyncHostNameResolverInfo *i; - + if (!dbus_message_get_args( m, &error, DBUS_TYPE_INT32, &interface, @@ -485,7 +481,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL); } - if (client->n_objects >= OBJECTS_PER_CLIENT_MAX) { + if (client->n_objects >= server->n_objects_per_client_max) { avahi_log_warn("Too many objects for client '%s', client request failed.", client->name); return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL); } @@ -500,9 +496,9 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH avahi_dbus_sync_host_name_resolver_free(i); return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL); } - + return DBUS_HANDLER_RESULT_HANDLED; - + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ResolveAddress")) { Client *client; int32_t interface, protocol; @@ -510,13 +506,13 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH char *address; SyncAddressResolverInfo *i; AvahiAddress a; - + if (!dbus_message_get_args( m, &error, DBUS_TYPE_INT32, &interface, DBUS_TYPE_INT32, &protocol, DBUS_TYPE_STRING, &address, - DBUS_TYPE_UINT32, &flags, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID) || !address) { avahi_log_warn("Error parsing Server::ResolveAddress message"); goto fail; @@ -530,7 +526,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL); } - if (client->n_objects >= OBJECTS_PER_CLIENT_MAX) { + if (client->n_objects >= server->n_objects_per_client_max) { avahi_log_warn("Too many objects for client '%s', client request failed.", client->name); return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL); } @@ -545,9 +541,9 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH avahi_dbus_sync_address_resolver_free(i); return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL); } - + return DBUS_HANDLER_RESULT_HANDLED; - + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "DomainBrowserNew")) { Client *client; DomainBrowserInfo *i; @@ -562,7 +558,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH int32_t interface, protocol, type; uint32_t flags; char *domain; - + if (!dbus_message_get_args( m, &error, DBUS_TYPE_INT32, &interface, @@ -580,7 +576,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL); } - if (client->n_objects >= OBJECTS_PER_CLIENT_MAX) { + if (client->n_objects >= server->n_objects_per_client_max) { avahi_log_warn("Too many objects for client '%s', client request failed.", client->name); return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL); } @@ -618,7 +614,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH int32_t interface, protocol; uint32_t flags; char *domain; - + if (!dbus_message_get_args( m, &error, DBUS_TYPE_INT32, &interface, @@ -635,7 +631,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL); } - if (client->n_objects >= OBJECTS_PER_CLIENT_MAX) { + if (client->n_objects >= server->n_objects_per_client_max) { avahi_log_warn("Too many objects for client '%s', client request failed.", client->name); return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL); } @@ -654,11 +650,11 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH avahi_dbus_service_type_browser_free(i); return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL); } - + i->path = avahi_strdup_printf("/Client%u/ServiceTypeBrowser%u", client->id, i->id); dbus_connection_register_object_path(c, i->path, &vtable, i); return avahi_dbus_respond_path(c, m, i->path); - + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ServiceBrowserNew")) { Client *client; ServiceBrowserInfo *i; @@ -673,7 +669,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH int32_t interface, protocol; uint32_t flags; char *domain, *type; - + if (!dbus_message_get_args( m, &error, DBUS_TYPE_INT32, &interface, @@ -691,7 +687,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL); } - if (client->n_objects >= OBJECTS_PER_CLIENT_MAX) { + if (client->n_objects >= server->n_objects_per_client_max) { avahi_log_warn("Too many objects for client '%s', client request failed.", client->name); return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL); } @@ -714,14 +710,14 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH i->path = avahi_strdup_printf("/Client%u/ServiceBrowser%u", client->id, i->id); dbus_connection_register_object_path(c, i->path, &vtable, i); return avahi_dbus_respond_path(c, m, i->path); - + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ResolveService")) { Client *client; int32_t interface, protocol, aprotocol; uint32_t flags; char *name, *type, *domain; SyncServiceResolverInfo *i; - + if (!dbus_message_get_args( m, &error, DBUS_TYPE_INT32, &interface, @@ -740,8 +736,8 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH avahi_log_warn("Too many clients, client request failed."); return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL); } - - if (client->n_objects >= OBJECTS_PER_CLIENT_MAX) { + + if (client->n_objects >= server->n_objects_per_client_max) { avahi_log_warn("Too many objects for client '%s', client request failed.", client->name); return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL); } @@ -751,7 +747,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH if (!*name) name = NULL; - + i = avahi_new(SyncServiceResolverInfo, 1); i->client = client; i->message = dbus_message_ref(m); @@ -762,9 +758,9 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH avahi_dbus_sync_service_resolver_free(i); return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL); } - + return DBUS_HANDLER_RESULT_HANDLED; - + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ServiceResolverNew")) { Client *client; int32_t interface, protocol, aprotocol; @@ -793,13 +789,13 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH avahi_log_warn("Error parsing Server::ServiceResolverNew message"); goto fail; } - + if (!(client = client_get(dbus_message_get_sender(m), TRUE))) { avahi_log_warn(__FILE__": Too many clients, client request failed."); return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL); } - if (client->n_objects >= OBJECTS_PER_CLIENT_MAX) { + if (client->n_objects >= server->n_objects_per_client_max) { avahi_log_warn(__FILE__": Too many objects for client '%s', client request failed.", client->name); return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL); } @@ -809,7 +805,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH if (!*name) name = NULL; - + i = avahi_new(AsyncServiceResolverInfo, 1); i->id = ++client->current_id; i->client = client; @@ -823,7 +819,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH } /* avahi_log_debug(__FILE__": [%s], new service resolver for <%s.%s.%s>", i->path, name, type, domain); */ - + i->path = avahi_strdup_printf("/Client%u/ServiceResolver%u", client->id, i->id); dbus_connection_register_object_path(c, i->path, &vtable, i); return avahi_dbus_respond_path(c, m, i->path); @@ -842,7 +838,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH NULL, NULL }; - + if (!dbus_message_get_args( m, &error, DBUS_TYPE_INT32, &interface, @@ -854,13 +850,13 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH avahi_log_warn("Error parsing Server::HostNameResolverNew message"); goto fail; } - + if (!(client = client_get(dbus_message_get_sender(m), TRUE))) { avahi_log_warn(__FILE__": Too many clients, client request failed."); return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL); } - if (client->n_objects >= OBJECTS_PER_CLIENT_MAX) { + if (client->n_objects >= server->n_objects_per_client_max) { avahi_log_warn(__FILE__": Too many objects for client '%s', client request failed.", client->name); return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL); } @@ -896,7 +892,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH NULL, NULL }; - + if (!dbus_message_get_args( m, &error, DBUS_TYPE_INT32, &interface, @@ -916,7 +912,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL); } - if (client->n_objects >= OBJECTS_PER_CLIENT_MAX) { + if (client->n_objects >= server->n_objects_per_client_max) { avahi_log_warn(__FILE__": Too many objects for client '%s', client request failed.", client->name); return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL); } @@ -936,7 +932,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH i->path = avahi_strdup_printf("/Client%u/AddressResolver%u", client->id, i->id); dbus_connection_register_object_path(c, i->path, &vtable, i); return avahi_dbus_respond_path(c, m, i->path); - + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "RecordBrowserNew")) { Client *client; RecordBrowserInfo *i; @@ -953,7 +949,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH char *name; uint16_t type, clazz; AvahiKey *key; - + if (!dbus_message_get_args( m, &error, DBUS_TYPE_INT32, &interface, @@ -967,7 +963,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH goto fail; } - if (!avahi_is_valid_domain_name(name)) + if (!avahi_is_valid_domain_name(name)) return avahi_dbus_respond_error(c, m, AVAHI_ERR_INVALID_DOMAIN_NAME, NULL); if (!(client = client_get(dbus_message_get_sender(m), TRUE))) { @@ -975,7 +971,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL); } - if (client->n_objects >= OBJECTS_PER_CLIENT_MAX) { + if (client->n_objects >= server->n_objects_per_client_max) { avahi_log_warn("Too many objects for client '%s', client request failed.", client->name); return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL); } @@ -997,7 +993,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH } avahi_key_unref(key); - + i->path = avahi_strdup_printf("/Client%u/RecordBrowser%u", client->id, i->id); dbus_connection_register_object_path(c, i->path, &vtable, i); return avahi_dbus_respond_path(c, m, i->path); @@ -1008,7 +1004,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH fail: if (dbus_error_is_set(&error)) dbus_error_free(&error); - + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } @@ -1016,11 +1012,17 @@ void dbus_protocol_server_state_changed(AvahiServerState state) { DBusMessage *m; int32_t t; const char *e; - + if (!server || !server->bus) return; m = dbus_message_new_signal(AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "StateChanged"); + + if (!m) { + avahi_log_error("Failed allocate message"); + return; + } + t = (int32_t) state; if (state == AVAHI_SERVER_COLLISION) @@ -1029,7 +1031,7 @@ void dbus_protocol_server_state_changed(AvahiServerState state) { e = avahi_error_number_to_dbus(avahi_server_errno(avahi_server)); else e = AVAHI_DBUS_ERR_OK; - + dbus_message_append_args(m, DBUS_TYPE_INT32, &t, DBUS_TYPE_STRING, &e, DBUS_TYPE_INVALID); dbus_connection_send(server->bus, m, NULL); dbus_message_unref(m); @@ -1052,7 +1054,7 @@ static int dbus_connect(void) { dbus_error_init(&error); -#ifdef HAVE_DBUS_BUS_GET_PRIVATE +#ifdef HAVE_DBUS_BUS_GET_PRIVATE if (!(server->bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error))) { assert(dbus_error_is_set(&error)); avahi_log_error("dbus_bus_get_private(): %s", error.message); @@ -1064,7 +1066,7 @@ static int dbus_connect(void) { if (!(a = getenv("DBUS_SYSTEM_BUS_ADDRESS")) || !*a) a = DBUS_SYSTEM_BUS_DEFAULT_ADDRESS; - + if (!(server->bus = dbus_connection_open_private(a, &error))) { assert(dbus_error_is_set(&error)); avahi_log_error("dbus_bus_open_private(): %s", error.message); @@ -1078,14 +1080,14 @@ static int dbus_connect(void) { } } #endif - + if (avahi_dbus_connection_glue(server->bus, server->poll_api) < 0) { avahi_log_error("avahi_dbus_connection_glue() failed"); goto fail; } dbus_connection_set_exit_on_disconnect(server->bus, FALSE); - + if (dbus_bus_request_name( server->bus, AVAHI_DBUS_NAME, @@ -1108,14 +1110,14 @@ static int dbus_connect(void) { avahi_log_error("dbus_connection_add_filter() failed"); goto fail; } - + dbus_bus_add_match(server->bus, "type='signal',""interface='" DBUS_INTERFACE_DBUS "'", &error); if (dbus_error_is_set(&error)) { avahi_log_error("dbus_bus_add_match(): %s", error.message); goto fail; } - + if (!(dbus_connection_register_object_path(server->bus, AVAHI_DBUS_PATH_SERVER, &server_vtable, NULL))) { avahi_log_error("dbus_connection_register_object_path() failed"); goto fail; @@ -1145,7 +1147,7 @@ static void dbus_disconnect(void) { while (server->clients) client_free(server->clients); - + assert(server->n_clients == 0); if (server->bus) { @@ -1159,9 +1161,13 @@ static void dbus_disconnect(void) { } } -int dbus_protocol_setup(const AvahiPoll *poll_api, int _disable_user_service_publishing, int force) { +int dbus_protocol_setup(const AvahiPoll *poll_api, + int _disable_user_service_publishing, + int _n_clients_max, + int _n_objects_per_client_max, + int _n_entries_per_entry_group_max, + int force) { - disable_user_service_publishing = _disable_user_service_publishing; server = avahi_new(Server, 1); AVAHI_LLIST_HEAD_INIT(Clients, server->clients); @@ -1171,6 +1177,10 @@ int dbus_protocol_setup(const AvahiPoll *poll_api, int _disable_user_service_pub server->poll_api = poll_api; server->reconnect_timeout = NULL; server->reconnect = force; + server->disable_user_service_publishing = _disable_user_service_publishing; + server->n_clients_max = _n_clients_max > 0 ? _n_clients_max : DEFAULT_CLIENTS_MAX; + server->n_objects_per_client_max = _n_objects_per_client_max > 0 ? _n_objects_per_client_max : DEFAULT_OBJECTS_PER_CLIENT_MAX; + server->n_entries_per_entry_group_max = _n_entries_per_entry_group_max > 0 ? _n_entries_per_entry_group_max : DEFAULT_ENTRIES_PER_ENTRY_GROUP_MAX; if (dbus_connect() < 0) { struct timeval tv; @@ -1179,11 +1189,11 @@ int dbus_protocol_setup(const AvahiPoll *poll_api, int _disable_user_service_pub goto fail; avahi_log_warn("WARNING: Failed to contact D-Bus daemon, retrying in %ims.", RECONNECT_MSEC); - + avahi_elapse_time(&tv, RECONNECT_MSEC, 0); server->reconnect_timeout = server->poll_api->timeout_new(server->poll_api, &tv, reconnect_callback, NULL); } - + return 0; fail: @@ -1209,7 +1219,7 @@ void dbus_protocol_shutdown(void) { if (server->reconnect_timeout) server->poll_api->timeout_free(server->reconnect_timeout); - + avahi_free(server); server = NULL; } diff --git a/avahi-daemon/dbus-protocol.h b/avahi-daemon/dbus-protocol.h index d4404f2..2184487 100644 --- a/avahi-daemon/dbus-protocol.h +++ b/avahi-daemon/dbus-protocol.h @@ -1,28 +1,31 @@ #ifndef foodbusprotocolhfoo #define foodbusprotocolhfoo -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ -int dbus_protocol_setup(const AvahiPoll *poll_api, int disable_user_service_publishing, int force); +int dbus_protocol_setup(const AvahiPoll *poll_api, + int _disable_user_service_publishing, + int _n_clients_max, + int _n_objects_per_client_max, + int _n_entries_per_entry_group_max, + int force); void dbus_protocol_shutdown(void); void dbus_protocol_server_state_changed(AvahiServerState state); diff --git a/avahi-daemon/dbus-record-browser.c b/avahi-daemon/dbus-record-browser.c index ea23fe4..c0337cf 100644 --- a/avahi-daemon/dbus-record-browser.c +++ b/avahi-daemon/dbus-record-browser.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -45,8 +43,8 @@ void avahi_dbus_record_browser_free(RecordBrowserInfo *i) { } AVAHI_LLIST_REMOVE(RecordBrowserInfo, record_browsers, i->client->record_browsers, i); + assert(i->client->n_objects >= 1); i->client->n_objects--; - assert(i->client->n_objects >= 0); avahi_free(i); } @@ -58,7 +56,7 @@ DBusHandlerResult avahi_dbus_msg_record_browser_impl(DBusConnection *c, DBusMess assert(c); assert(m); assert(i); - + dbus_error_init(&error); avahi_log_debug(__FILE__": interface=%s, path=%s, member=%s", @@ -68,12 +66,12 @@ DBusHandlerResult avahi_dbus_msg_record_browser_impl(DBusConnection *c, DBusMess /* Introspection */ if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) - return avahi_dbus_handle_introspect(c, m, "RecordBrowser.introspect"); - + return avahi_dbus_handle_introspect(c, m, "org.freedesktop.Avahi.RecordBrowser.xml"); + /* Access control */ - if (strcmp(dbus_message_get_sender(m), i->client->name)) + if (strcmp(dbus_message_get_sender(m), i->client->name)) return avahi_dbus_respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL); - + if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_RECORD_BROWSER, "Free")) { if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) { @@ -83,15 +81,15 @@ DBusHandlerResult avahi_dbus_msg_record_browser_impl(DBusConnection *c, DBusMess avahi_dbus_record_browser_free(i); return avahi_dbus_respond_ok(c, m); - + } - + avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m)); fail: if (dbus_error_is_set(&error)) dbus_error_free(&error); - + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } @@ -103,12 +101,12 @@ void avahi_dbus_record_browser_callback( AvahiRecord *record, AvahiLookupResultFlags flags, void* userdata) { - + RecordBrowserInfo *i = userdata; DBusMessage *m = NULL; int32_t i_interface, i_protocol; uint32_t u_flags; - + assert(b); assert(i); @@ -118,11 +116,16 @@ void avahi_dbus_record_browser_callback( m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_RECORD_BROWSER, avahi_dbus_map_browse_signal_name(event)); + if (!m) { + avahi_log_error("Failed allocate message"); + return; + } + if (event == AVAHI_BROWSER_NEW || event == AVAHI_BROWSER_REMOVE) { uint8_t rdata[0xFFFF]; size_t size; assert(record); - + if (!(dbus_message_append_args( m, DBUS_TYPE_INT32, &i_interface, @@ -132,28 +135,28 @@ void avahi_dbus_record_browser_callback( DBUS_TYPE_UINT16, &record->key->type, DBUS_TYPE_INVALID))) goto fail; - + if ((size = avahi_rdata_serialize(record, rdata, sizeof(rdata))) == (size_t) -1 || avahi_dbus_append_rdata(m, rdata, size) < 0) { avahi_log_debug(__FILE__": Failed to append rdata"); dbus_message_unref(m); return; } - + dbus_message_append_args( m, DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID); - + } else if (event == AVAHI_BROWSER_FAILURE) avahi_dbus_append_server_error(m); - - dbus_message_set_destination(m, i->client->name); + + dbus_message_set_destination(m, i->client->name); dbus_connection_send(server->bus, m, NULL); dbus_message_unref(m); return; - + fail: if (m) diff --git a/avahi-daemon/dbus-service-browser.c b/avahi-daemon/dbus-service-browser.c index 1515ddf..962dca0 100644 --- a/avahi-daemon/dbus-service-browser.c +++ b/avahi-daemon/dbus-service-browser.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -43,11 +41,11 @@ void avahi_dbus_service_browser_free(ServiceBrowserInfo *i) { dbus_connection_unregister_object_path(server->bus, i->path); avahi_free(i->path); } - + AVAHI_LLIST_REMOVE(ServiceBrowserInfo, service_browsers, i->client->service_browsers, i); + assert(i->client->n_objects >= 1); i->client->n_objects--; - assert(i->client->n_objects >= 0); avahi_free(i); } @@ -59,7 +57,7 @@ DBusHandlerResult avahi_dbus_msg_service_browser_impl(DBusConnection *c, DBusMes assert(c); assert(m); assert(i); - + dbus_error_init(&error); avahi_log_debug(__FILE__": interface=%s, path=%s, member=%s", @@ -69,12 +67,12 @@ DBusHandlerResult avahi_dbus_msg_service_browser_impl(DBusConnection *c, DBusMes /* Introspection */ if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) - return avahi_dbus_handle_introspect(c, m, "ServiceBrowser.introspect"); - + return avahi_dbus_handle_introspect(c, m, "org.freedesktop.Avahi.ServiceBrowser.xml"); + /* Access control */ - if (strcmp(dbus_message_get_sender(m), i->client->name)) + if (strcmp(dbus_message_get_sender(m), i->client->name)) return avahi_dbus_respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL); - + if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, "Free")) { if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) { @@ -84,15 +82,15 @@ DBusHandlerResult avahi_dbus_msg_service_browser_impl(DBusConnection *c, DBusMes avahi_dbus_service_browser_free(i); return avahi_dbus_respond_ok(c, m); - + } - + avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m)); fail: if (dbus_error_is_set(&error)) dbus_error_free(&error); - + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } @@ -101,28 +99,33 @@ void avahi_dbus_service_browser_callback(AvahiSServiceBrowser *b, AvahiIfIndex i DBusMessage *m; int32_t i_interface, i_protocol; uint32_t u_flags; - + assert(b); assert(i); m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, avahi_dbus_map_browse_signal_name(event)); + if (!m) { + avahi_log_error("Failed allocate message"); + return; + } + if (event == AVAHI_BROWSER_NEW) { /* Patch in AVAHI_LOOKUP_RESULT_OUR_OWN */ if (avahi_dbus_is_our_own_service(i->client, interface, protocol, name, type, domain) > 0) flags |= AVAHI_LOOKUP_RESULT_OUR_OWN; } - + i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; u_flags = (uint32_t) flags; - + if (event == AVAHI_BROWSER_NEW || event == AVAHI_BROWSER_REMOVE) { assert(name); assert(type); assert(domain); - + dbus_message_append_args( m, DBUS_TYPE_INT32, &i_interface, @@ -134,8 +137,8 @@ void avahi_dbus_service_browser_callback(AvahiSServiceBrowser *b, AvahiIfIndex i DBUS_TYPE_INVALID); } else if (event == AVAHI_BROWSER_FAILURE) avahi_dbus_append_server_error(m); - - dbus_message_set_destination(m, i->client->name); + + dbus_message_set_destination(m, i->client->name); dbus_connection_send(server->bus, m, NULL); dbus_message_unref(m); } diff --git a/avahi-daemon/dbus-service-type-browser.c b/avahi-daemon/dbus-service-type-browser.c index 9207a74..20afdbe 100644 --- a/avahi-daemon/dbus-service-type-browser.c +++ b/avahi-daemon/dbus-service-type-browser.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -43,11 +41,11 @@ void avahi_dbus_service_type_browser_free(ServiceTypeBrowserInfo *i) { dbus_connection_unregister_object_path(server->bus, i->path); avahi_free(i->path); } - + AVAHI_LLIST_REMOVE(ServiceTypeBrowserInfo, service_type_browsers, i->client->service_type_browsers, i); + assert(i->client->n_objects >= 1); i->client->n_objects--; - assert(i->client->n_objects >= 0); avahi_free(i); } @@ -59,7 +57,7 @@ DBusHandlerResult avahi_dbus_msg_service_type_browser_impl(DBusConnection *c, DB assert(c); assert(m); assert(i); - + dbus_error_init(&error); avahi_log_debug(__FILE__": interface=%s, path=%s, member=%s", @@ -69,12 +67,12 @@ DBusHandlerResult avahi_dbus_msg_service_type_browser_impl(DBusConnection *c, DB /* Introspection */ if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) - return avahi_dbus_handle_introspect(c, m, "ServiceTypeBrowser.introspect"); - + return avahi_dbus_handle_introspect(c, m, "org.freedesktop.Avahi.ServiceTypeBrowser.xml"); + /* Access control */ - if (strcmp(dbus_message_get_sender(m), i->client->name)) + if (strcmp(dbus_message_get_sender(m), i->client->name)) return avahi_dbus_respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL); - + if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "Free")) { if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) { @@ -84,15 +82,15 @@ DBusHandlerResult avahi_dbus_msg_service_type_browser_impl(DBusConnection *c, DB avahi_dbus_service_type_browser_free(i); return avahi_dbus_respond_ok(c, m); - + } - + avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m)); fail: if (dbus_error_is_set(&error)) dbus_error_free(&error); - + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } @@ -101,7 +99,7 @@ void avahi_dbus_service_type_browser_callback(AvahiSServiceTypeBrowser *b, Avahi DBusMessage *m; int32_t i_interface, i_protocol; uint32_t u_flags; - + assert(b); assert(i); @@ -111,6 +109,11 @@ void avahi_dbus_service_type_browser_callback(AvahiSServiceTypeBrowser *b, Avahi m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, avahi_dbus_map_browse_signal_name(event)); + if (!m) { + avahi_log_error("Failed allocate message"); + return; + } + if (event == AVAHI_BROWSER_NEW || event == AVAHI_BROWSER_REMOVE) { assert(type); assert(domain); @@ -124,10 +127,8 @@ void avahi_dbus_service_type_browser_callback(AvahiSServiceTypeBrowser *b, Avahi DBUS_TYPE_INVALID); } else if (event == AVAHI_BROWSER_FAILURE) avahi_dbus_append_server_error(m); - - dbus_message_set_destination(m, i->client->name); + + dbus_message_set_destination(m, i->client->name); dbus_connection_send(server->bus, m, NULL); dbus_message_unref(m); } - - diff --git a/avahi-daemon/dbus-sync-address-resolver.c b/avahi-daemon/dbus-sync-address-resolver.c index 0a5fa59..9845420 100644 --- a/avahi-daemon/dbus-sync-address-resolver.c +++ b/avahi-daemon/dbus-sync-address-resolver.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -42,15 +40,15 @@ void avahi_dbus_sync_address_resolver_free(SyncAddressResolverInfo *i) { dbus_message_unref(i->message); AVAHI_LLIST_REMOVE(SyncAddressResolverInfo, sync_address_resolvers, i->client->sync_address_resolvers, i); + assert(i->client->n_objects >= 1); i->client->n_objects--; - assert(i->client->n_objects >= 0); avahi_free(i); } void avahi_dbus_sync_address_resolver_callback(AvahiSAddressResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const AvahiAddress *address, const char *host_name, AvahiLookupResultFlags flags, void* userdata) { SyncAddressResolverInfo *i = userdata; - + assert(r); assert(address); assert(i); @@ -68,8 +66,14 @@ void avahi_dbus_sync_address_resolver_callback(AvahiSAddressResolver *r, AvahiIf i_protocol = (int32_t) protocol; i_aprotocol = (int32_t) address->proto; u_flags = (uint32_t) flags; - + reply = dbus_message_new_method_return(i->message); + + if (!reply) { + avahi_log_error("Failed allocate message"); + goto finish; + } + dbus_message_append_args( reply, DBUS_TYPE_INT32, &i_interface, @@ -87,6 +91,6 @@ void avahi_dbus_sync_address_resolver_callback(AvahiSAddressResolver *r, AvahiIf avahi_dbus_respond_error(server->bus, i->message, avahi_server_errno(avahi_server), NULL); } +finish: avahi_dbus_sync_address_resolver_free(i); } - diff --git a/avahi-daemon/dbus-sync-host-name-resolver.c b/avahi-daemon/dbus-sync-host-name-resolver.c index 9750dd4..e511327 100644 --- a/avahi-daemon/dbus-sync-host-name-resolver.c +++ b/avahi-daemon/dbus-sync-host-name-resolver.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -42,15 +40,15 @@ void avahi_dbus_sync_host_name_resolver_free(SyncHostNameResolverInfo *i) { dbus_message_unref(i->message); AVAHI_LLIST_REMOVE(SyncHostNameResolverInfo, sync_host_name_resolvers, i->client->sync_host_name_resolvers, i); + assert(i->client->n_objects >= 1); i->client->n_objects--; - assert(i->client->n_objects >= 0); avahi_free(i); } void avahi_dbus_sync_host_name_resolver_callback(AvahiSHostNameResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const char *host_name, const AvahiAddress *a, AvahiLookupResultFlags flags, void* userdata) { SyncHostNameResolverInfo *i = userdata; - + assert(r); assert(host_name); assert(i); @@ -68,8 +66,14 @@ void avahi_dbus_sync_host_name_resolver_callback(AvahiSHostNameResolver *r, Avah i_protocol = (int32_t) protocol; i_aprotocol = (int32_t) a->proto; u_flags = (uint32_t) flags; - + reply = dbus_message_new_method_return(i->message); + + if (!reply) { + avahi_log_error("Failed allocate message"); + goto finish; + } + dbus_message_append_args( reply, DBUS_TYPE_INT32, &i_interface, @@ -87,6 +91,6 @@ void avahi_dbus_sync_host_name_resolver_callback(AvahiSHostNameResolver *r, Avah avahi_dbus_respond_error(server->bus, i->message, avahi_server_errno(avahi_server), NULL); } +finish: avahi_dbus_sync_host_name_resolver_free(i); } - diff --git a/avahi-daemon/dbus-sync-service-resolver.c b/avahi-daemon/dbus-sync-service-resolver.c index 21ae481..ed7276a 100644 --- a/avahi-daemon/dbus-sync-service-resolver.c +++ b/avahi-daemon/dbus-sync-service-resolver.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -42,8 +40,8 @@ void avahi_dbus_sync_service_resolver_free(SyncServiceResolverInfo *i) { dbus_message_unref(i->message); AVAHI_LLIST_REMOVE(SyncServiceResolverInfo, sync_service_resolvers, i->client->sync_service_resolvers, i); + assert(i->client->n_objects >= 1); i->client->n_objects--; - assert(i->client->n_objects >= 0); avahi_free(i); } @@ -60,11 +58,11 @@ void avahi_dbus_sync_service_resolver_callback( const AvahiAddress *a, uint16_t port, AvahiStringList *txt, - AvahiLookupResultFlags flags, + AvahiLookupResultFlags flags, void* userdata) { - + SyncServiceResolverInfo *i = userdata; - + assert(r); assert(i); @@ -73,13 +71,13 @@ void avahi_dbus_sync_service_resolver_callback( int32_t i_interface, i_protocol, i_aprotocol; uint32_t u_flags; DBusMessage *reply; - + assert(host_name); if (!name) name = ""; - if (a) + if (a) avahi_address_snprint(t, sizeof(t), a); else t[0] = 0; @@ -88,16 +86,22 @@ void avahi_dbus_sync_service_resolver_callback( if (avahi_dbus_is_our_own_service(i->client, interface, protocol, name, type, domain) > 0) flags |= AVAHI_LOOKUP_RESULT_OUR_OWN; - + i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; - if (a) - i_aprotocol = (int32_t) a->proto; - else - i_aprotocol = AVAHI_PROTO_UNSPEC; + if (a) + i_aprotocol = (int32_t) a->proto; + else + i_aprotocol = AVAHI_PROTO_UNSPEC; u_flags = (uint32_t) flags; reply = dbus_message_new_method_return(i->message); + + if (!reply) { + avahi_log_error("Failed allocate message"); + goto finish; + } + dbus_message_append_args( reply, DBUS_TYPE_INT32, &i_interface, @@ -112,7 +116,7 @@ void avahi_dbus_sync_service_resolver_callback( DBUS_TYPE_INVALID); avahi_dbus_append_string_list(reply, txt); - + dbus_message_append_args( reply, DBUS_TYPE_UINT32, &u_flags, @@ -122,9 +126,10 @@ void avahi_dbus_sync_service_resolver_callback( dbus_message_unref(reply); } else { assert(event == AVAHI_RESOLVER_FAILURE); - + avahi_dbus_respond_error(server->bus, i->message, avahi_server_errno(avahi_server), NULL); } +finish: avahi_dbus_sync_service_resolver_free(i); } diff --git a/avahi-daemon/dbus-util.c b/avahi-daemon/dbus-util.c index ca08d7b..2983b29 100644 --- a/avahi-daemon/dbus-util.c +++ b/avahi-daemon/dbus-util.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -52,13 +50,19 @@ DBusHandlerResult avahi_dbus_respond_error(DBusConnection *c, DBusMessage *m, in if (!text) text = avahi_strerror(error); - + reply = dbus_message_new_error(m, avahi_error_number_to_dbus(error), text); + + if (!reply) { + avahi_log_error("Failed allocate message"); + return DBUS_HANDLER_RESULT_NEED_MEMORY; + } + dbus_connection_send(c, reply, NULL); dbus_message_unref(reply); avahi_log_debug(__FILE__": Responding error '%s' (%i)", text, error); - + return DBUS_HANDLER_RESULT_HANDLED; } @@ -66,10 +70,16 @@ DBusHandlerResult avahi_dbus_respond_string(DBusConnection *c, DBusMessage *m, c DBusMessage *reply; reply = dbus_message_new_method_return(m); + + if (!reply) { + avahi_log_error("Failed allocate message"); + return DBUS_HANDLER_RESULT_NEED_MEMORY; + } + dbus_message_append_args(reply, DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID); dbus_connection_send(c, reply, NULL); dbus_message_unref(reply); - + return DBUS_HANDLER_RESULT_HANDLED; } @@ -77,10 +87,16 @@ DBusHandlerResult avahi_dbus_respond_int32(DBusConnection *c, DBusMessage *m, in DBusMessage *reply; reply = dbus_message_new_method_return(m); + + if (!reply) { + avahi_log_error("Failed allocate message"); + return DBUS_HANDLER_RESULT_NEED_MEMORY; + } + dbus_message_append_args(reply, DBUS_TYPE_INT32, &i, DBUS_TYPE_INVALID); dbus_connection_send(c, reply, NULL); dbus_message_unref(reply); - + return DBUS_HANDLER_RESULT_HANDLED; } @@ -88,10 +104,16 @@ DBusHandlerResult avahi_dbus_respond_uint32(DBusConnection *c, DBusMessage *m, u DBusMessage *reply; reply = dbus_message_new_method_return(m); + + if (!reply) { + avahi_log_error("Failed allocate message"); + return DBUS_HANDLER_RESULT_NEED_MEMORY; + } + dbus_message_append_args(reply, DBUS_TYPE_UINT32, &u, DBUS_TYPE_INVALID); dbus_connection_send(c, reply, NULL); dbus_message_unref(reply); - + return DBUS_HANDLER_RESULT_HANDLED; } @@ -99,10 +121,16 @@ DBusHandlerResult avahi_dbus_respond_boolean(DBusConnection *c, DBusMessage *m, DBusMessage *reply; reply = dbus_message_new_method_return(m); + + if (!reply) { + avahi_log_error("Failed allocate message"); + return DBUS_HANDLER_RESULT_NEED_MEMORY; + } + dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &b, DBUS_TYPE_INVALID); dbus_connection_send(c, reply, NULL); dbus_message_unref(reply); - + return DBUS_HANDLER_RESULT_HANDLED; } @@ -110,9 +138,15 @@ DBusHandlerResult avahi_dbus_respond_ok(DBusConnection *c, DBusMessage *m) { DBusMessage *reply; reply = dbus_message_new_method_return(m); + + if (!reply) { + avahi_log_error("Failed allocate message"); + return DBUS_HANDLER_RESULT_NEED_MEMORY; + } + dbus_connection_send(c, reply, NULL); dbus_message_unref(reply); - + return DBUS_HANDLER_RESULT_HANDLED; } @@ -120,10 +154,16 @@ DBusHandlerResult avahi_dbus_respond_path(DBusConnection *c, DBusMessage *m, con DBusMessage *reply; reply = dbus_message_new_method_return(m); + + if (!reply) { + avahi_log_error("Failed allocate message"); + return DBUS_HANDLER_RESULT_NEED_MEMORY; + } + dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); dbus_connection_send(c, reply, NULL); dbus_message_unref(reply); - + return DBUS_HANDLER_RESULT_HANDLED; } @@ -131,7 +171,7 @@ void avahi_dbus_append_server_error(DBusMessage *reply) { const char *t; t = avahi_error_number_to_dbus(avahi_server_errno(avahi_server)); - + dbus_message_append_args( reply, DBUS_TYPE_STRING, &t, @@ -166,7 +206,7 @@ static char *file_get_contents(const char *fname) { char *buf = NULL; assert(fname); - + #ifdef ENABLE_CHROOT fd = avahi_chroot_helper_get_fd(fname); #else @@ -205,22 +245,22 @@ static char *file_get_contents(const char *fname) { close(fd); return buf; - + fail: if (fd >= 0) close(fd); - + if (buf) avahi_free(buf); return NULL; - + } DBusHandlerResult avahi_dbus_handle_introspect(DBusConnection *c, DBusMessage *m, const char *fname) { char *contents, *path; DBusError error; - + assert(c); assert(m); assert(fname); @@ -235,21 +275,21 @@ DBusHandlerResult avahi_dbus_handle_introspect(DBusConnection *c, DBusMessage *m path = avahi_strdup_printf("%s/%s", AVAHI_DBUS_INTROSPECTION_DIR, fname); contents = file_get_contents(path); avahi_free(path); - + if (!contents) { avahi_log_error("Failed to load introspection data."); goto fail; } - + avahi_dbus_respond_string(c, m, contents); avahi_free(contents); - + return DBUS_HANDLER_RESULT_HANDLED; fail: if (dbus_error_is_set(&error)) dbus_error_free(&error); - + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } @@ -257,20 +297,20 @@ fail: void avahi_dbus_append_string_list(DBusMessage *reply, AvahiStringList *txt) { AvahiStringList *p; DBusMessageIter iter, sub; - + assert(reply); dbus_message_iter_init_append(reply, &iter); dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "ay", &sub); - + for (p = txt; p; p = p->next) { DBusMessageIter sub2; const uint8_t *data = p->text; - + dbus_message_iter_open_container(&sub, DBUS_TYPE_ARRAY, "y", &sub2); - dbus_message_iter_append_fixed_array(&sub2, DBUS_TYPE_BYTE, &data, p->size); + dbus_message_iter_append_fixed_array(&sub2, DBUS_TYPE_BYTE, &data, p->size); dbus_message_iter_close_container(&sub, &sub2); - + } dbus_message_iter_close_container(&iter, &sub); } @@ -281,12 +321,12 @@ int avahi_dbus_read_rdata(DBusMessage *m, int idx, void **rdata, uint32_t *size) uint8_t *k; assert(m); - + dbus_message_iter_init(m, &iter); for (j = 0; j < idx; j++) dbus_message_iter_next(&iter); - + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY || dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_BYTE) goto fail; @@ -296,9 +336,9 @@ int avahi_dbus_read_rdata(DBusMessage *m, int idx, void **rdata, uint32_t *size) *rdata = k; *size = n; - + return 0; - + fail: avahi_log_warn("Error parsing data"); @@ -314,49 +354,49 @@ int avahi_dbus_read_strlst(DBusMessage *m, int idx, AvahiStringList **l) { assert(m); assert(l); - + dbus_message_iter_init(m, &iter); for (j = 0; j < idx; j++) dbus_message_iter_next(&iter); - + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY || dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_ARRAY) goto fail; dbus_message_iter_recurse(&iter, &sub); - + for (;;) { int at, n; const uint8_t *k; DBusMessageIter sub2; - + if ((at = dbus_message_iter_get_arg_type(&sub)) == DBUS_TYPE_INVALID) break; - + assert(at == DBUS_TYPE_ARRAY); - + if (dbus_message_iter_get_element_type(&sub) != DBUS_TYPE_BYTE) goto fail; dbus_message_iter_recurse(&sub, &sub2); - + k = (const uint8_t*) ""; n = 0; dbus_message_iter_get_fixed_array(&sub2, &k, &n); if (!k) k = (const uint8_t*) ""; - + strlst = avahi_string_list_add_arbitrary(strlst, k, n); - + dbus_message_iter_next(&sub); } *l = strlst; - + return 0; - + fail: avahi_log_warn("Error parsing TXT data"); @@ -381,15 +421,15 @@ int avahi_dbus_is_our_own_service(Client *c, AvahiIfIndex interface, AvahiProtoc int avahi_dbus_append_rdata(DBusMessage *message, const void *rdata, size_t size) { DBusMessageIter iter, sub; - + assert(message); - + dbus_message_iter_init_append(message, &iter); - + if (!(dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING, &sub)) || !(dbus_message_iter_append_fixed_array(&sub, DBUS_TYPE_BYTE, &rdata, size)) || !(dbus_message_iter_close_container(&iter, &sub))) return -1; - + return 0; } diff --git a/avahi-daemon/dbus-util.h b/avahi-daemon/dbus-util.h index e994915..a513367 100644 --- a/avahi-daemon/dbus-util.h +++ b/avahi-daemon/dbus-util.h @@ -1,21 +1,19 @@ #ifndef foodbusutilhfoo #define foodbusutilhfoo -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 diff --git a/avahi-daemon/example.service b/avahi-daemon/example.service index 7d6c6b8..46db2ae 100644 --- a/avahi-daemon/example.service +++ b/avahi-daemon/example.service @@ -1,8 +1,6 @@ <?xml version="1.0" standalone='no'?><!--*-nxml-*--> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> -<!-- $Id$ --> - <!-- This file is part of avahi. diff --git a/avahi-daemon/hosts b/avahi-daemon/hosts index 495daa7..4483340 100644 --- a/avahi-daemon/hosts +++ b/avahi-daemon/hosts @@ -1,5 +1,3 @@ -# $Id$ -# # This file is part of avahi. # # avahi is free software; you can redistribute it and/or modify it diff --git a/avahi-daemon/ini-file-parser-test.c b/avahi-daemon/ini-file-parser-test.c index 6560ab9..6ca6641 100644 --- a/avahi-daemon/ini-file-parser-test.c +++ b/avahi-daemon/ini-file-parser-test.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -52,7 +50,7 @@ int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) { for (i = split; *i; i++) printf("<%s> ", *i); - + avahi_strfreev(split); printf("\n"); diff --git a/avahi-daemon/ini-file-parser.c b/avahi-daemon/ini-file-parser.c index 1b50335..0a99ce3 100644 --- a/avahi-daemon/ini-file-parser.c +++ b/avahi-daemon/ini-file-parser.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -38,14 +36,14 @@ AvahiIniFile* avahi_ini_file_load(const char *fname) { FILE *fo; AvahiIniFileGroup *group = NULL; unsigned line; - + assert(fname); if (!(fo = fopen(fname, "r"))) { avahi_log_error("Failed to open file '%s': %s", fname, strerror(errno)); return NULL; } - + f = avahi_new(AvahiIniFile, 1); AVAHI_LLIST_HEAD_INIT(AvahiIniFileGroup, f->groups); f->n_groups = 0; @@ -54,12 +52,12 @@ AvahiIniFile* avahi_ini_file_load(const char *fname) { while (!feof(fo)) { char ln[256], *s, *e; AvahiIniFilePair *pair; - + if (!(fgets(ln, sizeof(ln), fo))) break; line++; - + s = ln + strspn(ln, " \t"); s[strcspn(s, "\r\n")] = 0; @@ -69,19 +67,19 @@ AvahiIniFile* avahi_ini_file_load(const char *fname) { if (*s == '[') { /* new group */ - + if (!(e = strchr(s, ']'))) { avahi_log_error("Unclosed group header in %s:%u: <%s>", fname, line, s); goto fail; } *e = 0; - + group = avahi_new(AvahiIniFileGroup, 1); group->name = avahi_strdup(s+1); group->n_pairs = 0; AVAHI_LLIST_HEAD_INIT(AvahiIniFilePair, group->pairs); - + AVAHI_LLIST_PREPEND(AvahiIniFileGroup, groups, f->groups, group); f->n_groups++; } else { @@ -91,26 +89,26 @@ AvahiIniFile* avahi_ini_file_load(const char *fname) { avahi_log_error("Missing assignment in %s:%u: <%s>", fname, line, s); goto fail; } - + if (!group) { avahi_log_error("Assignment outside group in %s:%u <%s>", fname, line, s); goto fail; } - + /* Split the key and the value */ *(e++) = 0; - + pair = avahi_new(AvahiIniFilePair, 1); pair->key = avahi_strdup(s); pair->value = avahi_strdup(e); - + AVAHI_LLIST_PREPEND(AvahiIniFilePair, pairs, group->pairs, pair); group->n_pairs++; } } - + fclose(fo); - + return f; fail: @@ -130,7 +128,7 @@ void avahi_ini_file_free(AvahiIniFile *f) { while ((g = f->groups)) { AvahiIniFilePair *p; - + while ((p = g->pairs)) { avahi_free(p->key); avahi_free(p->value); @@ -190,7 +188,7 @@ void avahi_strfreev(char **p) { if (!p) return; - + for (i = p; *i; i++) avahi_free(*i); diff --git a/avahi-daemon/ini-file-parser.h b/avahi-daemon/ini-file-parser.h index 82c5acf..dd3aace 100644 --- a/avahi-daemon/ini-file-parser.h +++ b/avahi-daemon/ini-file-parser.h @@ -1,21 +1,19 @@ #ifndef fooinifileparserhfoo #define fooinifileparserhfoo -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 diff --git a/avahi-daemon/introspect.xsl b/avahi-daemon/introspect.xsl index 32a371c..5d68560 100644 --- a/avahi-daemon/introspect.xsl +++ b/avahi-daemon/introspect.xsl @@ -19,8 +19,6 @@ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. --> -<!-- $Id$ --> - <xsl:output method="xml" version="1.0" encoding="iso-8859-15" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" indent="yes"/> <xsl:template match="/"> diff --git a/avahi-daemon/main.c b/avahi-daemon/main.c index c3cbb0e..d1a3b3e 100644 --- a/avahi-daemon/main.c +++ b/avahi-daemon/main.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of avahi. @@ -79,6 +77,7 @@ #include "static-services.h" #include "static-hosts.h" #include "ini-file-parser.h" +#include "sd-daemon.h" #ifdef HAVE_DBUS #include "dbus-protocol.h" @@ -107,6 +106,9 @@ typedef struct { #ifdef HAVE_DBUS int enable_dbus; int fail_on_missing_dbus; + unsigned n_clients_max; + unsigned n_objects_per_client_max; + unsigned n_entries_per_entry_group_max; #endif int drop_root; int set_rlimits; @@ -528,6 +530,26 @@ static int is_yes(const char *s) { return *s == 'y' || *s == 'Y' || *s == '1' || *s == 't' || *s == 'T'; } +static int parse_unsigned(const char *s, unsigned *u) { + char *e = NULL; + unsigned long ul; + unsigned k; + + errno = 0; + ul = strtoul(s, &e, 0); + + if (!e || *e || errno != 0) + return -1; + + k = (unsigned) ul; + + if ((unsigned long) k != ul) + return -1; + + *u = k; + return 0; +} + static int load_config_file(DaemonConfig *c) { int r = -1; AvahiIniFile *f; @@ -619,6 +641,44 @@ static int load_config_file(DaemonConfig *c) { c->server_config.deny_interfaces = avahi_string_list_add(c->server_config.deny_interfaces, *t); avahi_strfreev(e); + } else if (strcasecmp(p->key, "cache-entries-max") == 0) { + unsigned k; + + if (parse_unsigned(p->value, &k) < 0) { + avahi_log_error("Invalid cache-entries-max setting %s", p->value); + goto finish; + } + + c->server_config.n_cache_entries_max = k; +#ifdef HAVE_DBUS + } else if (strcasecmp(p->key, "clients-max") == 0) { + unsigned k; + + if (parse_unsigned(p->value, &k) < 0) { + avahi_log_error("Invalid clients-max setting %s", p->value); + goto finish; + } + + c->n_clients_max = k; + } else if (strcasecmp(p->key, "objects-per-client-max") == 0) { + unsigned k; + + if (parse_unsigned(p->value, &k) < 0) { + avahi_log_error("Invalid objects-per-client-max setting %s", p->value); + goto finish; + } + + c->n_objects_per_client_max = k; + } else if (strcasecmp(p->key, "entries-per-entry-group-max") == 0) { + unsigned k; + + if (parse_unsigned(p->value, &k) < 0) { + avahi_log_error("Invalid entries-per-entry-group-max setting %s", p->value); + goto finish; + } + + c->n_entries_per_entry_group_max = k; +#endif } else { avahi_log_error("Invalid configuration key \"%s\" in group \"%s\"\n", p->key, g->name); goto finish; @@ -1010,7 +1070,12 @@ static int run_server(DaemonConfig *c) { #ifdef HAVE_DBUS if (c->enable_dbus) { - if (dbus_protocol_setup(poll_api, config.disable_user_service_publishing, !c->fail_on_missing_dbus + if (dbus_protocol_setup(poll_api, + config.disable_user_service_publishing, + config.n_clients_max, + config.n_objects_per_client_max, + config.n_entries_per_entry_group_max, + !c->fail_on_missing_dbus #ifdef ENABLE_CHROOT && !config.use_chroot #endif @@ -1307,7 +1372,7 @@ static void enforce_rlimits(void) { #endif /* the sysctl() call from iface-pfroute.c needs locked memory on FreeBSD */ -#if defined(RLIMIT_MEMLOCK) && !defined(__FreeBSD__) +#if defined(RLIMIT_MEMLOCK) && !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) /* We don't need locked memory */ set_one_rlimit(RLIMIT_MEMLOCK, 0, "RLIMIT_MEMLOCK"); #endif @@ -1348,6 +1413,9 @@ int main(int argc, char *argv[]) { #ifdef HAVE_DBUS config.enable_dbus = 1; config.fail_on_missing_dbus = 1; + config.n_clients_max = 0; + config.n_objects_per_client_max = 0; + config.n_entries_per_entry_group_max = 0; #endif config.drop_root = 1; @@ -1455,10 +1523,11 @@ int main(int argc, char *argv[]) { if (config.use_syslog || config.daemonize) daemon_log_use = DAEMON_LOG_SYSLOG; - if (daemon_close_all(-1) < 0) { - avahi_log_error("Failed to close remaining file descriptors: %s", strerror(errno)); - goto finish; - } + if (sd_listen_fds(0) <= 0) + if (daemon_close_all(-1) < 0) { + avahi_log_error("Failed to close remaining file descriptors: %s", strerror(errno)); + goto finish; + } if (make_runtime_dir() < 0) goto finish; diff --git a/avahi-daemon/main.h b/avahi-daemon/main.h index 77af0d0..ef04c2d 100644 --- a/avahi-daemon/main.h +++ b/avahi-daemon/main.h @@ -1,21 +1,19 @@ #ifndef foomainhfoo #define foomainhfoo -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 diff --git a/avahi-daemon/AddressResolver.introspect b/avahi-daemon/org.freedesktop.Avahi.AddressResolver.xml index 3550ecd..bae9c2f 100644 --- a/avahi-daemon/AddressResolver.introspect +++ b/avahi-daemon/org.freedesktop.Avahi.AddressResolver.xml @@ -2,11 +2,9 @@ <?xml-stylesheet type="text/xsl" href="introspect.xsl"?> <!DOCTYPE node SYSTEM "introspect.dtd"> -<!-- $Id$ --> - <!-- This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the @@ -34,7 +32,7 @@ <interface name="org.freedesktop.Avahi.AddressResolver"> <method name="Free"/> - + <signal name="Found"> <arg name="interface" type="i" direction="out"/> <arg name="protocol" type="i" direction="out"/> @@ -48,5 +46,5 @@ <arg name="error" type="s"/> </signal> - </interface> + </interface> </node> diff --git a/avahi-daemon/DomainBrowser.introspect b/avahi-daemon/org.freedesktop.Avahi.DomainBrowser.xml index 5840060..22c614e 100644 --- a/avahi-daemon/DomainBrowser.introspect +++ b/avahi-daemon/org.freedesktop.Avahi.DomainBrowser.xml @@ -2,11 +2,9 @@ <?xml-stylesheet type="text/xsl" href="introspect.xsl"?> <!DOCTYPE node SYSTEM "introspect.dtd"> -<!-- $Id$ --> - <!-- This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the @@ -24,7 +22,7 @@ --> <node> - + <interface name="org.freedesktop.DBus.Introspectable"> <method name="Introspect"> <arg name="data" type="s" direction="out" /> @@ -34,7 +32,7 @@ <interface name="org.freedesktop.Avahi.DomainBrowser"> <method name="Free"/> - + <signal name="ItemNew"> <arg name="interface" type="i"/> <arg name="protocol" type="i"/> @@ -57,6 +55,5 @@ <signal name="CacheExhausted"/> - </interface> + </interface> </node> - diff --git a/avahi-daemon/EntryGroup.introspect b/avahi-daemon/org.freedesktop.Avahi.EntryGroup.xml index e49bbe6..43fd63c 100644 --- a/avahi-daemon/EntryGroup.introspect +++ b/avahi-daemon/org.freedesktop.Avahi.EntryGroup.xml @@ -1,12 +1,10 @@ <?xml version="1.0" standalone='no'?><!--*-nxml-*--> <?xml-stylesheet type="text/xsl" href="introspect.xsl"?> <!DOCTYPE node SYSTEM "introspect.dtd"> - -<!-- $Id$ --> <!-- This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the diff --git a/avahi-daemon/HostNameResolver.introspect b/avahi-daemon/org.freedesktop.Avahi.HostNameResolver.xml index 9ac2e36..0b43752 100644 --- a/avahi-daemon/HostNameResolver.introspect +++ b/avahi-daemon/org.freedesktop.Avahi.HostNameResolver.xml @@ -2,8 +2,6 @@ <?xml-stylesheet type="text/xsl" href="introspect.xsl"?> <!DOCTYPE node SYSTEM "introspect.dtd"> -<!-- $Id$ --> - <!-- This file is part of avahi. diff --git a/avahi-daemon/RecordBrowser.introspect b/avahi-daemon/org.freedesktop.Avahi.RecordBrowser.xml index 57c1e66..9ba86f4 100644 --- a/avahi-daemon/RecordBrowser.introspect +++ b/avahi-daemon/org.freedesktop.Avahi.RecordBrowser.xml @@ -2,11 +2,9 @@ <?xml-stylesheet type="text/xsl" href="introspect.xsl"?> <!DOCTYPE node SYSTEM "introspect.dtd"> -<!-- $Id$ --> - <!-- This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the @@ -24,7 +22,7 @@ --> <node> - + <interface name="org.freedesktop.DBus.Introspectable"> <method name="Introspect"> <arg name="data" type="s" direction="out" /> @@ -34,7 +32,7 @@ <interface name="org.freedesktop.Avahi.RecordBrowser"> <method name="Free"/> - + <signal name="ItemNew"> <arg name="interface" type="i"/> <arg name="protocol" type="i"/> @@ -63,5 +61,5 @@ <signal name="CacheExhausted"/> - </interface> + </interface> </node> diff --git a/avahi-daemon/Server.introspect b/avahi-daemon/org.freedesktop.Avahi.Server.xml index 9d743ba..c291274 100644 --- a/avahi-daemon/Server.introspect +++ b/avahi-daemon/org.freedesktop.Avahi.Server.xml @@ -2,11 +2,9 @@ <?xml-stylesheet type="text/xsl" href="introspect.xsl"?> <!DOCTYPE node SYSTEM "introspect.dtd"> -<!-- $Id$ --> - <!-- This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the diff --git a/avahi-daemon/ServiceBrowser.introspect b/avahi-daemon/org.freedesktop.Avahi.ServiceBrowser.xml index 4a7b430..d80298d 100644 --- a/avahi-daemon/ServiceBrowser.introspect +++ b/avahi-daemon/org.freedesktop.Avahi.ServiceBrowser.xml @@ -2,11 +2,9 @@ <?xml-stylesheet type="text/xsl" href="introspect.xsl"?> <!DOCTYPE node SYSTEM "introspect.dtd"> -<!-- $Id$ --> - <!-- This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the @@ -24,7 +22,7 @@ --> <node> - + <interface name="org.freedesktop.DBus.Introspectable"> <method name="Introspect"> <arg name="data" type="s" direction="out" /> @@ -34,7 +32,7 @@ <interface name="org.freedesktop.Avahi.ServiceBrowser"> <method name="Free"/> - + <signal name="ItemNew"> <arg name="interface" type="i"/> <arg name="protocol" type="i"/> @@ -61,5 +59,5 @@ <signal name="CacheExhausted"/> - </interface> + </interface> </node> diff --git a/avahi-daemon/ServiceResolver.introspect b/avahi-daemon/org.freedesktop.Avahi.ServiceResolver.xml index 2be9347..623f209 100644 --- a/avahi-daemon/ServiceResolver.introspect +++ b/avahi-daemon/org.freedesktop.Avahi.ServiceResolver.xml @@ -2,11 +2,9 @@ <?xml-stylesheet type="text/xsl" href="introspect.xsl"?> <!DOCTYPE node SYSTEM "introspect.dtd"> -<!-- $Id$ --> - <!-- This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the @@ -34,7 +32,7 @@ <interface name="org.freedesktop.Avahi.ServiceResolver"> <method name="Free"/> - + <signal name="Found"> <arg name="interface" type="i" direction="out"/> <arg name="protocol" type="i" direction="out"/> @@ -53,5 +51,5 @@ <arg name="error" type="s"/> </signal> - </interface> + </interface> </node> diff --git a/avahi-daemon/ServiceTypeBrowser.introspect b/avahi-daemon/org.freedesktop.Avahi.ServiceTypeBrowser.xml index cb07f24..4efec82 100644 --- a/avahi-daemon/ServiceTypeBrowser.introspect +++ b/avahi-daemon/org.freedesktop.Avahi.ServiceTypeBrowser.xml @@ -2,11 +2,9 @@ <?xml-stylesheet type="text/xsl" href="introspect.xsl"?> <!DOCTYPE node SYSTEM "introspect.dtd"> -<!-- $Id$ --> - <!-- This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the @@ -24,7 +22,7 @@ --> <node> - + <interface name="org.freedesktop.DBus.Introspectable"> <method name="Introspect"> <arg name="data" type="s" direction="out" /> @@ -34,7 +32,7 @@ <interface name="org.freedesktop.Avahi.ServiceTypeBrowser"> <method name="Free"/> - + <signal name="ItemNew"> <arg name="interface" type="i"/> <arg name="protocol" type="i"/> @@ -59,5 +57,5 @@ <signal name="CacheExhausted"/> - </interface> + </interface> </node> diff --git a/avahi-daemon/org.freedesktop.Avahi.service b/avahi-daemon/org.freedesktop.Avahi.service new file mode 100644 index 0000000..ebc5f31 --- /dev/null +++ b/avahi-daemon/org.freedesktop.Avahi.service @@ -0,0 +1,24 @@ +# This file is part of avahi. +# +# avahi is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# avahi is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +# License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with avahi; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. + +[D-BUS Service] +Name=org.freedesktop.Avahi +SystemdService=avahi-daemon.service + +# This service should not be bus activated if systemd isn't running, +# so that activation won't conflict with the init script startup. +Exec=/bin/false diff --git a/avahi-daemon/sd-daemon.c b/avahi-daemon/sd-daemon.c new file mode 100644 index 0000000..cb568b5 --- /dev/null +++ b/avahi-daemon/sd-daemon.c @@ -0,0 +1,448 @@ +/*-*- Mode: C; c-basic-offset: 8 -*-*/ + +/*** + Copyright 2010 Lennart Poettering + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +***/ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <sys/fcntl.h> +#include <netinet/in.h> +#include <stdlib.h> +#include <errno.h> +#include <unistd.h> +#include <string.h> +#include <stdarg.h> +#include <stdio.h> + +#include "sd-daemon.h" + +int sd_listen_fds(int unset_environment) { + +#if defined(DISABLE_SYSTEMD) || !defined(__linux__) + return 0; +#else + int r, fd; + const char *e; + char *p = NULL; + unsigned long l; + + if (!(e = getenv("LISTEN_PID"))) { + r = 0; + goto finish; + } + + errno = 0; + l = strtoul(e, &p, 10); + + if (errno != 0) { + r = -errno; + goto finish; + } + + if (!p || *p || l <= 0) { + r = -EINVAL; + goto finish; + } + + /* Is this for us? */ + if (getpid() != (pid_t) l) { + r = 0; + goto finish; + } + + if (!(e = getenv("LISTEN_FDS"))) { + r = 0; + goto finish; + } + + errno = 0; + l = strtoul(e, &p, 10); + + if (errno != 0) { + r = -errno; + goto finish; + } + + if (!p || *p) { + r = -EINVAL; + goto finish; + } + + for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + (int) l; fd ++) { + int flags; + + if ((flags = fcntl(fd, F_GETFD)) < 0) { + r = -errno; + goto finish; + } + + if (flags & FD_CLOEXEC) + continue; + + if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) { + r = -errno; + goto finish; + } + } + + r = (int) l; + +finish: + if (unset_environment) { + unsetenv("LISTEN_PID"); + unsetenv("LISTEN_FDS"); + } + + return r; +#endif +} + +int sd_is_fifo(int fd, const char *path) { + struct stat st_fd; + + if (fd < 0) + return -EINVAL; + + memset(&st_fd, 0, sizeof(st_fd)); + if (fstat(fd, &st_fd) < 0) + return -errno; + + if (!S_ISFIFO(st_fd.st_mode)) + return 0; + + if (path) { + struct stat st_path; + + memset(&st_path, 0, sizeof(st_path)); + if (fstat(fd, &st_path) < 0) { + + if (errno == ENOENT || errno == ENOTDIR) + return 0; + + return -errno; + } + + return + st_path.st_dev == st_fd.st_dev && + st_path.st_ino == st_fd.st_ino; + } + + return 1; +} + +static int sd_is_socket_internal(int fd, int type, int listening) { + struct stat st_fd; + + if (fd < 0 || type < 0) + return -EINVAL; + + if (fstat(fd, &st_fd) < 0) + return -errno; + + if (!S_ISSOCK(st_fd.st_mode)) + return 0; + + if (type != 0) { + int other_type = 0; + socklen_t l = sizeof(other_type); + + if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &other_type, &l) < 0) + return -errno; + + if (l != sizeof(other_type)) + return -EINVAL; + + if (other_type != type) + return 0; + } + + if (listening >= 0) { + int accepting = 0; + socklen_t l = sizeof(accepting); + + if (getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &accepting, &l) < 0) + return -errno; + + if (l != sizeof(accepting)) + return -EINVAL; + + if (!accepting != !listening) + return 0; + } + + return 1; +} + +union sockaddr_union { + struct sockaddr sa; + struct sockaddr_in in4; + struct sockaddr_in6 in6; + struct sockaddr_un un; + struct sockaddr_storage storage; +}; + +int sd_is_socket(int fd, int family, int type, int listening) { + int r; + + if (family < 0) + return -EINVAL; + + if ((r = sd_is_socket_internal(fd, type, listening)) <= 0) + return r; + + if (family > 0) { + union sockaddr_union sockaddr; + socklen_t l; + + memset(&sockaddr, 0, sizeof(sockaddr)); + l = sizeof(sockaddr); + + if (getsockname(fd, &sockaddr.sa, &l) < 0) + return -errno; + + if (l < sizeof(sa_family_t)) + return -EINVAL; + + return sockaddr.sa.sa_family == family; + } + + return 1; +} + +int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port) { + union sockaddr_union sockaddr; + socklen_t l; + int r; + + if (family != 0 && family != AF_INET && family != AF_INET6) + return -EINVAL; + + if ((r = sd_is_socket_internal(fd, type, listening)) <= 0) + return r; + + memset(&sockaddr, 0, sizeof(sockaddr)); + l = sizeof(sockaddr); + + if (getsockname(fd, &sockaddr.sa, &l) < 0) + return -errno; + + if (l < sizeof(sa_family_t)) + return -EINVAL; + + if (sockaddr.sa.sa_family != AF_INET && + sockaddr.sa.sa_family != AF_INET6) + return 0; + + if (family > 0) + if (sockaddr.sa.sa_family != family) + return 0; + + if (port > 0) { + if (sockaddr.sa.sa_family == AF_INET) { + if (l < sizeof(struct sockaddr_in)) + return -EINVAL; + + return htons(port) == sockaddr.in4.sin_port; + } else { + if (l < sizeof(struct sockaddr_in6)) + return -EINVAL; + + return htons(port) == sockaddr.in6.sin6_port; + } + } + + return 1; +} + +int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length) { + union sockaddr_union sockaddr; + socklen_t l; + int r; + + if ((r = sd_is_socket_internal(fd, type, listening)) <= 0) + return r; + + memset(&sockaddr, 0, sizeof(sockaddr)); + l = sizeof(sockaddr); + + if (getsockname(fd, &sockaddr.sa, &l) < 0) + return -errno; + + if (l < sizeof(sa_family_t)) + return -EINVAL; + + if (sockaddr.sa.sa_family != AF_UNIX) + return 0; + + if (path) { + if (length <= 0) + length = strlen(path); + + if (length <= 0) + /* Unnamed socket */ + return l == sizeof(sa_family_t); + + if (path[0]) + /* Normal path socket */ + return + (l >= sizeof(sa_family_t) + length + 1) && + memcmp(path, sockaddr.un.sun_path, length+1) == 0; + else + /* Abstract namespace socket */ + return + (l == sizeof(sa_family_t) + length) && + memcmp(path, sockaddr.un.sun_path, length) == 0; + } + + return 1; +} + +int sd_notify(int unset_environment, const char *state) { +#if defined(DISABLE_SYSTEMD) || !defined(__linux__) + return 0; +#else + int fd = -1, r; + struct msghdr msghdr; + struct iovec iovec; + union sockaddr_union sockaddr; + struct ucred *ucred; + union { + struct cmsghdr cmsghdr; + uint8_t buf[CMSG_SPACE(sizeof(struct ucred))]; + } control; + const char *e; + + if (!state) { + r = -EINVAL; + goto finish; + } + + if (!(e = getenv("NOTIFY_SOCKET"))) + return 0; + + /* Must be an abstract socket, or an absolute path */ + if ((e[0] != '@' && e[0] != '/') || e[1] == 0) { + r = -EINVAL; + goto finish; + } + + if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) { + r = -errno; + goto finish; + } + + memset(&sockaddr, 0, sizeof(sockaddr)); + sockaddr.sa.sa_family = AF_UNIX; + strncpy(sockaddr.un.sun_path, e, sizeof(sockaddr.un.sun_path)); + + if (sockaddr.un.sun_path[0] == '@') + sockaddr.un.sun_path[0] = 0; + + memset(&iovec, 0, sizeof(iovec)); + iovec.iov_base = (char*) state; + iovec.iov_len = strlen(state); + + memset(&control, 0, sizeof(control)); + control.cmsghdr.cmsg_level = SOL_SOCKET; + control.cmsghdr.cmsg_type = SCM_CREDENTIALS; + control.cmsghdr.cmsg_len = CMSG_LEN(sizeof(struct ucred)); + + ucred = (struct ucred*) CMSG_DATA(&control.cmsghdr); + ucred->pid = getpid(); + ucred->uid = getuid(); + ucred->gid = getgid(); + + memset(&msghdr, 0, sizeof(msghdr)); + msghdr.msg_name = &sockaddr; + msghdr.msg_namelen = sizeof(struct sockaddr_un); + msghdr.msg_iov = &iovec; + msghdr.msg_iovlen = 1; + msghdr.msg_control = &control; + msghdr.msg_controllen = control.cmsghdr.cmsg_len; + + if (sendmsg(fd, &msghdr, MSG_NOSIGNAL) < 0) { + r = -errno; + goto finish; + } + + r = 1; + +finish: + if (unset_environment) + unsetenv("NOTIFY_SOCKET"); + + if (fd >= 0) + close(fd); + + return r; +#endif +} + +int sd_notifyf(int unset_environment, const char *format, ...) { +#if defined(DISABLE_SYSTEMD) || !defined(__linux__) + return 0; +#else + va_list ap; + char *p = NULL; + int r; + + va_start(ap, format); + r = vasprintf(&p, format, ap); + va_end(ap); + + if (r < 0 || !p) + return -ENOMEM; + + r = sd_notify(unset_environment, p); + free(p); + + return r; +#endif +} + +int sd_booted(void) { +#if defined(DISABLE_SYSTEMD) || !defined(__linux__) + return 0; +#else + + struct stat a, b; + + /* We simply test whether the systemd cgroup hierarchy is + * mounted */ + + if (lstat("/cgroup", &a) < 0) + return 0; + + if (lstat("/cgroup/systemd", &b) < 0) + return 0; + + return a.st_dev != b.st_dev; +#endif +} diff --git a/avahi-daemon/sd-daemon.h b/avahi-daemon/sd-daemon.h new file mode 100644 index 0000000..fd6221f --- /dev/null +++ b/avahi-daemon/sd-daemon.h @@ -0,0 +1,257 @@ +/*-*- Mode: C; c-basic-offset: 8 -*-*/ + +#ifndef foosddaemonhfoo +#define foosddaemonhfoo + +/*** + Copyright 2010 Lennart Poettering + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +***/ + +#include <sys/types.h> +#include <inttypes.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* + Reference implementation of a few systemd related interfaces for + writing daemons. These interfaces are trivial to implement. To + simplify porting we provide this reference implementation. + Applications are welcome to reimplement the algorithms described + here if they do not want to include these two source files. + + The following functionality is provided: + + - Support for logging with log levels on stderr + - File descriptor passing for socket-based activation + - Daemon startup and status notification + - Detection of systemd boots + + You may compile this with -DDISABLE_SYSTEMD to disable systemd + support. This makes all those calls NOPs that are directly related to + systemd (i.e. only sd_is_xxx() will stay useful). + + Since this is drop-in code we don't want any of our symbols to be + exported in any case. Hence we declare hidden visibility for all of + them. + + You may find an up-to-date version of these source files online: + + http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.h + http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.c + + This should compile on non-Linux systems, too, but with the + exception of the sd_is_xxx() calls all functions will become NOPs. + + See sd-daemon(7) for more information. +*/ + +#if __GNUC__ >= 4 +#define _sd_printf_attr_(a,b) __attribute__ ((format (printf, a, b))) +#define _sd_hidden_ __attribute__ ((visibility("hidden"))) +#else +#define _sd_printf_attr_(a,b) +#define _sd_hidden_ +#endif + +/* + Log levels for usage on stderr: + + fprintf(stderr, SD_NOTICE "Hello World!\n"); + + This is similar to printk() usage in the kernel. +*/ +#define SD_EMERG "<0>" /* system is unusable */ +#define SD_ALERT "<1>" /* action must be taken immediately */ +#define SD_CRIT "<2>" /* critical conditions */ +#define SD_ERR "<3>" /* error conditions */ +#define SD_WARNING "<4>" /* warning conditions */ +#define SD_NOTICE "<5>" /* normal but significant condition */ +#define SD_INFO "<6>" /* informational */ +#define SD_DEBUG "<7>" /* debug-level messages */ + +/* The first passed file descriptor is fd 3 */ +#define SD_LISTEN_FDS_START 3 + +/* + Returns how many file descriptors have been passed, or a negative + errno code on failure. Optionally, removes the $LISTEN_FDS and + $LISTEN_PID file descriptors from the environment (recommended, but + problematic in threaded environments). If r is the return value of + this function you'll find the file descriptors passed as fds + SD_LISTEN_FDS_START to SD_LISTEN_FDS_START+r-1. Returns a negative + errno style error code on failure. This function call ensures that + the FD_CLOEXEC flag is set for the passed file descriptors, to make + sure they are not passed on to child processes. If FD_CLOEXEC shall + not be set, the caller needs to unset it after this call for all file + descriptors that are used. + + See sd_listen_fds(3) for more information. +*/ +int sd_listen_fds(int unset_environment) _sd_hidden_; + +/* + Helper call for identifying a passed file descriptor. Returns 1 if + the file descriptor is a FIFO in the file system stored under the + specified path, 0 otherwise. If path is NULL a path name check will + not be done and the call only verifies if the file descriptor + refers to a FIFO. Returns a negative errno style error code on + failure. + + See sd_is_fifo(3) for more information. +*/ +int sd_is_fifo(int fd, const char *path) _sd_hidden_; + +/* + Helper call for identifying a passed file descriptor. Returns 1 if + the file descriptor is a socket of the specified family (AF_INET, + ...) and type (SOCK_DGRAM, SOCK_STREAM, ...), 0 otherwise. If + family is 0 a socket family check will not be done. If type is 0 a + socket type check will not be done and the call only verifies if + the file descriptor refers to a socket. If listening is > 0 it is + verified that the socket is in listening mode. (i.e. listen() has + been called) If listening is == 0 it is verified that the socket is + not in listening mode. If listening is < 0 no listening mode check + is done. Returns a negative errno style error code on failure. + + See sd_is_socket(3) for more information. +*/ +int sd_is_socket(int fd, int family, int type, int listening) _sd_hidden_; + +/* + Helper call for identifying a passed file descriptor. Returns 1 if + the file descriptor is an Internet socket, of the specified family + (either AF_INET or AF_INET6) and the specified type (SOCK_DGRAM, + SOCK_STREAM, ...), 0 otherwise. If version is 0 a protocol version + check is not done. If type is 0 a socket type check will not be + done. If port is 0 a socket port check will not be done. The + listening flag is used the same way as in sd_is_socket(). Returns a + negative errno style error code on failure. + + See sd_is_socket_inet(3) for more information. +*/ +int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port) _sd_hidden_; + +/* + Helper call for identifying a passed file descriptor. Returns 1 if + the file descriptor is an AF_UNIX socket of the specified type + (SOCK_DGRAM, SOCK_STREAM, ...) and path, 0 otherwise. If type is 0 + a socket type check will not be done. If path is NULL a socket path + check will not be done. For normal AF_UNIX sockets set length to + 0. For abstract namespace sockets set length to the length of the + socket name (including the initial 0 byte), and pass the full + socket path in path (including the initial 0 byte). The listening + flag is used the same way as in sd_is_socket(). Returns a negative + errno style error code on failure. + + See sd_is_socket_unix(3) for more information. +*/ +int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length) _sd_hidden_; + +/* + Informs systemd about changed daemon state. This takes a number of + newline seperated environment-style variable assignments in a + string. The following variables are known: + + READY=1 Tells systemd that daemon startup is finished (only + relevant for services of Type=notify). The passed + argument is a boolean "1" or "0". Since there is + little value in signalling non-readiness the only + value daemons should send is "READY=1". + + STATUS=... Passes a single-line status string back to systemd + that describes the daemon state. This is free-from + and can be used for various purposes: general state + feedback, fsck-like programs could pass completion + percentages and failing programs could pass a human + readable error message. Example: "STATUS=Completed + 66% of file system check..." + + ERRNO=... If a daemon fails, the errno-style error code, + formatted as string. Example: "ERRNO=2" for ENOENT. + + BUSERROR=... If a daemon fails, the D-Bus error-style error + code. Example: "BUSERROR=org.freedesktop.DBus.Error.TimedOut" + + MAINPID=... The main pid of a daemon, in case systemd did not + fork off the process itself. Example: "MAINPID=4711" + + Daemons can choose to send additional variables. However, it is + recommened to prefix variable names not listed above with X_. + + Returns a negative errno-style error code on failure. Returns > 0 + if systemd could be notified, 0 if it couldn't possibly because + systemd is not running. + + Example: When a daemon finished starting up, it could issue this + call to notify systemd about it: + + sd_notify(0, "READY=1"); + + See sd_notifyf() for more complete examples. + + See sd_notify(3) for more information. +*/ +int sd_notify(int unset_environment, const char *state) _sd_hidden_; + +/* + Similar to sd_notify() but takes a format string. + + Example 1: A daemon could send the following after initialization: + + sd_notifyf(0, "READY=1\n" + "STATUS=Processing requests...\n" + "MAINPID=%lu", + (unsigned long) getpid()); + + Example 2: A daemon could send the following shortly before + exiting, on failure: + + sd_notifyf(0, "STATUS=Failed to start up: %s\n" + "ERRNO=%i", + strerror(errno), + errno); + + See sd_notifyf(3) for more information. +*/ +int sd_notifyf(int unset_environment, const char *format, ...) _sd_printf_attr_(2,3) _sd_hidden_; + +/* + Returns > 0 if the system was booted with systemd. Returns < 0 on + error. Returns 0 if the system was not booted with systemd. Note + that all of the functions above handle non-systemd boots just + fine. You should NOT protect them with a call to this function. Also + note that this function checks whether the system, not the user + session is controlled by systemd. However the functions above work + for both session and system services. + + See sd_booted(3) for more information. +*/ +int sd_booted(void) _sd_hidden_; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/avahi-daemon/setproctitle.c b/avahi-daemon/setproctitle.c index 09b7f65..aef3555 100644 --- a/avahi-daemon/setproctitle.c +++ b/avahi-daemon/setproctitle.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -66,7 +64,7 @@ void avahi_init_proc_title(int argc, char **argv) { argv_size = endptr - argv_buffer[0]; /* Make a copy of environ */ - + new_environ = avahi_malloc(sizeof(char*) * (i + 1)); for (i = 0; environ[i]; i++) new_environ[i] = avahi_strdup(environ[i]); @@ -75,7 +73,7 @@ void avahi_init_proc_title(int argc, char **argv) { environ = new_environ; #endif -} +} void avahi_set_proc_title(const char *name, const char *fmt,...) { #ifdef HAVE_SETPROCTITLE @@ -90,16 +88,16 @@ void avahi_set_proc_title(const char *name, const char *fmt,...) { #elif __linux__ size_t l; va_list ap; - + if (!argv_buffer) return; - + va_start(ap, fmt); vsnprintf(argv_buffer[0], argv_size, fmt, ap); va_end(ap); l = strlen(argv_buffer[0]); - + memset(argv_buffer[0] + l, 0, argv_size - l); argv_buffer[1] = NULL; #endif @@ -108,6 +106,6 @@ void avahi_set_proc_title(const char *name, const char *fmt,...) { if (name) prctl(PR_SET_NAME, (unsigned long) name, 0, 0, 0); - + #endif } diff --git a/avahi-daemon/setproctitle.h b/avahi-daemon/setproctitle.h index a8f2a1a..3499e2e 100644 --- a/avahi-daemon/setproctitle.h +++ b/avahi-daemon/setproctitle.h @@ -1,21 +1,19 @@ #ifndef foosetproctitlehfoo #define foosetproctitlehfoo -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 diff --git a/avahi-daemon/sftp-ssh.service b/avahi-daemon/sftp-ssh.service index c65535a..dfae4f1 100644 --- a/avahi-daemon/sftp-ssh.service +++ b/avahi-daemon/sftp-ssh.service @@ -1,11 +1,9 @@ <?xml version="1.0" standalone='no'?><!--*-nxml-*--> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> -<!-- $Id$ --> - <!-- This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the @@ -26,7 +24,7 @@ <service-group> - <name replace-wildcards="yes">SFTP File Transfer on %h</name> + <name replace-wildcards="yes">%h</name> <service> <type>_sftp-ssh._tcp</type> diff --git a/avahi-daemon/simple-protocol.c b/avahi-daemon/simple-protocol.c index 33e5db3..7f75562 100644 --- a/avahi-daemon/simple-protocol.c +++ b/avahi-daemon/simple-protocol.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -44,6 +42,7 @@ #include "simple-protocol.h" #include "main.h" +#include "sd-daemon.h" #ifdef ENABLE_CHROOT #include "chroot.h" @@ -75,7 +74,7 @@ struct Client { Server *server; ClientState state; - + int fd; AvahiWatch *watch; @@ -87,7 +86,7 @@ struct Client { AvahiSDNSServerBrowser *dns_server_browser; AvahiProtocol afquery; - + AVAHI_LLIST_FIELDS(Client, clients); }; @@ -98,7 +97,7 @@ struct Server { AVAHI_LLIST_HEAD(Client, clients); unsigned n_clients; - int bind_successful; + int remove_socket; }; static Server *server = NULL; @@ -122,7 +121,7 @@ static void client_free(Client *c) { c->server->poll_api->watch_free(c->watch); close(c->fd); - + AVAHI_LLIST_REMOVE(Client, clients, c->server->clients, c); avahi_free(c); } @@ -151,7 +150,7 @@ static void client_new(Server *s, int fd) { static void client_output(Client *c, const uint8_t*data, size_t size) { size_t k, m; - + assert(c); assert(data); @@ -170,7 +169,7 @@ static void client_output(Client *c, const uint8_t*data, size_t size) { static void client_output_printf(Client *c, const char *format, ...) { char *t; va_list ap; - + va_start(ap, format); t = avahi_strdup_vprintf(format, ap); va_end(ap); @@ -186,11 +185,11 @@ static void host_name_resolver_callback( AvahiResolverEvent event, const char *hostname, const AvahiAddress *a, - AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, + AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, void* userdata) { Client *c = userdata; - + assert(c); if (event == AVAHI_RESOLVER_FAILURE) @@ -213,9 +212,9 @@ static void address_resolver_callback( const char *hostname, AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, void* userdata) { - + Client *c = userdata; - + assert(c); if (event == AVAHI_RESOLVER_FAILURE) @@ -236,10 +235,10 @@ static void dns_server_browser_callback( uint16_t port, AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, void* userdata) { - + Client *c = userdata; char t[AVAHI_ADDRESS_STR_MAX]; - + assert(c); if (!a) @@ -257,7 +256,7 @@ static void dns_server_browser_callback( case AVAHI_BROWSER_NEW: case AVAHI_BROWSER_REMOVE: - + avahi_address_snprint(t, sizeof(t), a); client_output_printf(c, "%c %i %u %s %u\n", event == AVAHI_BROWSER_NEW ? '>' : '<', interface, protocol, t, port); break; @@ -314,7 +313,7 @@ static void handle_line(Client *c, const char *s) { avahi_log_debug(__FILE__": Got %s request for '%s'.", cmd, arg); } else if (strcmp(cmd, "RESOLVE-ADDRESS") == 0 && n_args == 2) { AvahiAddress addr; - + if (!(avahi_address_parse(arg, AVAHI_PROTO_UNSPEC, &addr))) { client_output_printf(c, "%+i Failed to parse address \"%s\".\n", AVAHI_ERR_INVALID_ADDRESS, arg); c->state = CLIENT_DEAD; @@ -376,7 +375,7 @@ static void handle_input(Client *c) { k = e - (char*) c->inbuf; *e = 0; - + handle_line(c, c->inbuf); c->inbuf_length -= k + 1; memmove(c->inbuf, e+1, c->inbuf_length); @@ -390,7 +389,7 @@ static void client_work(AvahiWatch *watch, AVAHI_GCC_UNUSED int fd, AvahiWatchEv if ((events & AVAHI_WATCH_IN) && c->inbuf_length < sizeof(c->inbuf)) { ssize_t r; - + if ((r = read(c->fd, c->inbuf + c->inbuf_length, sizeof(c->inbuf) - c->inbuf_length)) <= 0) { if (r < 0) avahi_log_warn("read(): %s", strerror(errno)); @@ -415,7 +414,7 @@ static void client_work(AvahiWatch *watch, AVAHI_GCC_UNUSED int fd, AvahiWatchEv assert((size_t) r <= c->outbuf_length); c->outbuf_length -= r; - + if (c->outbuf_length) memmove(c->outbuf, c->outbuf + r, c->outbuf_length - r); @@ -426,7 +425,7 @@ static void client_work(AvahiWatch *watch, AVAHI_GCC_UNUSED int fd, AvahiWatchEv } c->server->poll_api->watch_update( - watch, + watch, (c->outbuf_length > 0 ? AVAHI_WATCH_OUT : 0) | (c->inbuf_length < sizeof(c->inbuf) ? AVAHI_WATCH_IN : 0)); } @@ -445,59 +444,83 @@ static void server_work(AVAHI_GCC_UNUSED AvahiWatch *watch, int fd, AvahiWatchEv client_new(s, cfd); } } - + int simple_protocol_setup(const AvahiPoll *poll_api) { struct sockaddr_un sa; mode_t u; + int n; assert(!server); server = avahi_new(Server, 1); server->poll_api = poll_api; - server->bind_successful = 0; + server->remove_socket = 0; server->fd = -1; server->n_clients = 0; AVAHI_LLIST_HEAD_INIT(Client, server->clients); server->watch = NULL; - + u = umask(0000); - if ((server->fd = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) { - avahi_log_warn("socket(PF_LOCAL, SOCK_STREAM, 0): %s", strerror(errno)); + if ((n = sd_listen_fds(1)) < 0) { + avahi_log_warn("Failed to acquire systemd file descriptors: %s", strerror(-n)); goto fail; } - memset(&sa, 0, sizeof(sa)); - sa.sun_family = AF_LOCAL; - strncpy(sa.sun_path, AVAHI_SOCKET, sizeof(sa.sun_path)-1); - - /* We simply remove existing UNIX sockets under this name. The - Avahi daemon makes sure that it runs only once on a host, - therefore sockets that already exist are stale and may be - removed without any ill effects */ - - unlink(AVAHI_SOCKET); - - if (bind(server->fd, (struct sockaddr*) &sa, sizeof(sa)) < 0) { - avahi_log_warn("bind(): %s", strerror(errno)); + if (n > 1) { + avahi_log_warn("Too many systemd file descriptors passed."); goto fail; } - server->bind_successful = 1; - - if (listen(server->fd, 2) < 0) { - avahi_log_warn("listen(): %s", strerror(errno)); - goto fail; + if (n == 1) { + int r; + + if ((r = sd_is_socket(AF_LOCAL, SOCK_STREAM, 1, 0)) < 0) { + avahi_log_warn("Passed systemd file descriptor is of wrong type: %s", strerror(-r)); + goto fail; + } + + server->fd = SD_LISTEN_FDS_START; + + } else { + + if ((server->fd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0) { + avahi_log_warn("socket(AF_LOCAL, SOCK_STREAM, 0): %s", strerror(errno)); + goto fail; + } + + memset(&sa, 0, sizeof(sa)); + sa.sun_family = AF_LOCAL; + strncpy(sa.sun_path, AVAHI_SOCKET, sizeof(sa.sun_path)-1); + + /* We simply remove existing UNIX sockets under this name. The + Avahi daemon makes sure that it runs only once on a host, + therefore sockets that already exist are stale and may be + removed without any ill effects */ + + unlink(AVAHI_SOCKET); + + if (bind(server->fd, (struct sockaddr*) &sa, sizeof(sa)) < 0) { + avahi_log_warn("bind(): %s", strerror(errno)); + goto fail; + } + + server->remove_socket = 1; + + if (listen(server->fd, SOMAXCONN) < 0) { + avahi_log_warn("listen(): %s", strerror(errno)); + goto fail; + } } umask(u); server->watch = poll_api->watch_new(poll_api, server->fd, AVAHI_WATCH_IN, server_work, server); - + return 0; fail: - + umask(u); simple_protocol_shutdown(); @@ -508,7 +531,7 @@ void simple_protocol_shutdown(void) { if (server) { - if (server->bind_successful) + if (server->remove_socket) #ifdef ENABLE_CHROOT avahi_chroot_helper_unlink(AVAHI_SOCKET); #else @@ -520,12 +543,12 @@ void simple_protocol_shutdown(void) { if (server->watch) server->poll_api->watch_free(server->watch); - + if (server->fd >= 0) close(server->fd); avahi_free(server); - + server = NULL; } } @@ -534,7 +557,7 @@ void simple_protocol_restart_queries(void) { Client *c; /* Restart queries in case of local domain name changes */ - + assert(server); for (c = server->clients; c; c = c->clients_next) @@ -543,5 +566,3 @@ void simple_protocol_restart_queries(void) { c->dns_server_browser = avahi_s_dns_server_browser_new(avahi_server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, NULL, AVAHI_DNS_SERVER_RESOLVE, c->afquery, AVAHI_LOOKUP_USE_MULTICAST, dns_server_browser_callback, c); } } - - diff --git a/avahi-daemon/simple-protocol.h b/avahi-daemon/simple-protocol.h index 1e64036..bcbffc3 100644 --- a/avahi-daemon/simple-protocol.h +++ b/avahi-daemon/simple-protocol.h @@ -1,21 +1,19 @@ #ifndef foosimpleprotocolhfoo #define foosimpleprotocolhfoo -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 diff --git a/avahi-daemon/ssh.service b/avahi-daemon/ssh.service index a493444..c66e0c1 100644 --- a/avahi-daemon/ssh.service +++ b/avahi-daemon/ssh.service @@ -1,8 +1,6 @@ <?xml version="1.0" standalone='no'?><!--*-nxml-*--> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> -<!-- $Id$ --> - <!-- This file is part of avahi. diff --git a/avahi-daemon/static-hosts.c b/avahi-daemon/static-hosts.c index c0a5952..34f531f 100644 --- a/avahi-daemon/static-hosts.c +++ b/avahi-daemon/static-hosts.c @@ -1,18 +1,16 @@ -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -75,7 +73,7 @@ static void entry_group_callback(AvahiServer *s, AVAHI_GCC_UNUSED AvahiSEntryGro case AVAHI_ENTRY_GROUP_FAILURE: avahi_log_notice ("Failed to establish static host name \"%s\": %s.", h->host, avahi_strerror (avahi_server_errno (s))); break; - + case AVAHI_ENTRY_GROUP_UNCOMMITED: case AVAHI_ENTRY_GROUP_REGISTERING: ; @@ -84,7 +82,7 @@ static void entry_group_callback(AvahiServer *s, AVAHI_GCC_UNUSED AvahiSEntryGro static StaticHost *static_host_new(void) { StaticHost *s; - + s = avahi_new(StaticHost, 1); s->group = NULL; @@ -105,7 +103,7 @@ static void static_host_free(StaticHost *s) { avahi_s_entry_group_free (s->group); avahi_free(s->host); - + avahi_free(s); } @@ -114,7 +112,7 @@ static StaticHost *static_host_find(const char *host, const AvahiAddress *a) { assert(host); assert(a); - + for (h = hosts; h; h = h->hosts_next) if (!strcmp(h->host, host) && !avahi_address_cmp(a, &h->address)) return h; @@ -136,10 +134,10 @@ static void add_static_host_to_server(StaticHost *h) int err; const AvahiServerConfig *config; config = avahi_server_get_config(avahi_server); - + p = (h->address.proto == AVAHI_PROTO_INET && config->publish_a_on_ipv6) || (h->address.proto == AVAHI_PROTO_INET6 && config->publish_aaaa_on_ipv4) ? AVAHI_PROTO_UNSPEC : h->address.proto; - + if ((err = avahi_server_add_address(avahi_server, h->group, AVAHI_IF_UNSPEC, p, 0, h->host, &h->address)) < 0) { avahi_log_error ("Static host name %s: avahi_server_add_address failure: %s", h->host, avahi_strerror(err)); return; @@ -154,7 +152,7 @@ static void remove_static_host_from_server(StaticHost *h) if (h->group) avahi_s_entry_group_reset (h->group); } - + void static_hosts_add_to_server(void) { StaticHost *h; @@ -182,7 +180,7 @@ void static_hosts_load(int in_chroot) { } current_iteration++; - + while (!feof(f)) { unsigned int len; char ln[256], *s; @@ -228,7 +226,7 @@ void static_hosts_load(int in_chroot) { /* Skip past any more spaces */ s += strspn(s, " \t"); - + /* Anything left? */ if (*s != 0) { avahi_log_error ("%s:%d: Junk on the end of the line!", filename, line); @@ -261,7 +259,7 @@ void static_hosts_load(int in_chroot) { for (h = hosts; h; h = next) { next = h->hosts_next; - + if (h->iteration != current_iteration) { avahi_log_info("Static hostname %s vanished, removing.", h->host); static_host_free(h); @@ -269,7 +267,7 @@ void static_hosts_load(int in_chroot) { } fail: - + fclose(f); } diff --git a/avahi-daemon/static-hosts.h b/avahi-daemon/static-hosts.h index 2fdb0bd..5d63995 100644 --- a/avahi-daemon/static-hosts.h +++ b/avahi-daemon/static-hosts.h @@ -1,21 +1,19 @@ #ifndef foostatichostshfoo #define foostatichostshfoo -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 diff --git a/avahi-daemon/static-services.c b/avahi-daemon/static-services.c index 0c160f2..588ff8a 100644 --- a/avahi-daemon/static-services.c +++ b/avahi-daemon/static-services.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of avahi. diff --git a/avahi-daemon/static-services.h b/avahi-daemon/static-services.h index a2bc355..62edc36 100644 --- a/avahi-daemon/static-services.h +++ b/avahi-daemon/static-services.h @@ -1,21 +1,19 @@ #ifndef foostaticserviceshfoo #define foostaticserviceshfoo -/* $Id$ */ - /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
