X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;ds=sidebyside;f=avahi-daemon%2Fdbus-util.c;h=76a6b73c5984f1d97f0973c40a9a3007b54a8b54;hb=0449977b92d08726abde0cd5c38473435c8228d3;hp=09826d335afecd070e0011ad40deb72186303760;hpb=05dc243bdf89aae26c72434ddd7c27ab9143fec1;p=catta diff --git a/avahi-daemon/dbus-util.c b/avahi-daemon/dbus-util.c index 09826d3..76a6b73 100644 --- a/avahi-daemon/dbus-util.c +++ b/avahi-daemon/dbus-util.c @@ -37,6 +37,10 @@ #include #include +#ifdef ENABLE_CHROOT +#include "chroot.h" +#endif + #include "main.h" #include "dbus-util.h" @@ -155,15 +159,21 @@ const char *avahi_dbus_map_resolve_signal_name(AvahiResolverEvent e) { abort(); } -static char *file_get_contents(char *fname) { +static char *file_get_contents(const char *fname) { int fd = -1; struct stat st; ssize_t size; char *buf = NULL; - + assert(fname); + +#ifdef ENABLE_CHROOT + fd = avahi_chroot_helper_get_fd(fname); +#else + fd = open(fname, O_RDONLY); +#endif - if (!(fd = open(fname, O_RDONLY))) { + if (fd < 0) { avahi_log_error("Failed to open %s: %s", fname, strerror(errno)); goto fail; } @@ -193,12 +203,13 @@ static char *file_get_contents(char *fname) { buf[size] = 0; close(fd); + return buf; fail: if (fd >= 0) close(fd); - + if (buf) avahi_free(buf); @@ -207,7 +218,7 @@ fail: } DBusHandlerResult avahi_dbus_handle_introspect(DBusConnection *c, DBusMessage *m, const char *fname) { - char *path, *contents; + char *contents, *path; DBusError error; assert(c); @@ -220,7 +231,7 @@ DBusHandlerResult avahi_dbus_handle_introspect(DBusConnection *c, DBusMessage *m avahi_log_error("Error parsing Introspect message: %s", error.message); goto fail; } - + path = avahi_strdup_printf("%s/%s", AVAHI_DBUS_INTROSPECTION_DIR, fname); contents = file_get_contents(path); avahi_free(path); @@ -361,3 +372,17 @@ int avahi_dbus_is_our_own_service(Client *c, AvahiIfIndex interface, AvahiProtoc return 0; } +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; +}