]> git.meshlink.io Git - catta/blobdiff - avahi-daemon/dbus-protocol.c
* Limit the number of loops in consume_labels() (Closes: #84)
[catta] / avahi-daemon / dbus-protocol.c
index 3de5845407dfaac0901267e71193deeabef870a5..caa2e19eb7fe27758ad9bfbec39208152379d140 100644 (file)
@@ -346,9 +346,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH
 
     } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetNetworkInterfaceNameByIndex")) {
         int32_t idx;
-        int fd;
        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");
@@ -358,29 +356,17 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH
 #ifdef VALGRIND_WORKAROUND
         return respond_string(c, m, "blah");
 #else
-        
-        if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) 
-            if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
-                char txt[256];
-                snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
-                return avahi_dbus_respond_error(c, m, AVAHI_ERR_OS, txt);
-            }
-
         if ((!if_indextoname(idx, name))) {
             char txt[256];
             snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
-            close(fd);
             return avahi_dbus_respond_error(c, m, AVAHI_ERR_OS, txt);
         }
-
-        close(fd);
         
         return avahi_dbus_respond_string(c, m, name);
 #endif
         
     } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetNetworkInterfaceIndexByName")) {
         char *n;
-        int fd;
         int32_t idx;
         
         if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) {
@@ -391,21 +377,11 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH
 #ifdef VALGRIND_WORKAROUND
         return respond_int32(c, m, 1);
 #else
-        if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) 
-            if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
-                char txt[256];
-                snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
-                return avahi_dbus_respond_error(c, m, AVAHI_ERR_OS, txt);
-            }
-
         if (!(idx = if_nametoindex(n))) {
             char txt[256];
             snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
-            close(fd);
             return avahi_dbus_respond_error(c, m, AVAHI_ERR_OS, txt);
         }
-
-        close(fd);
         
         return avahi_dbus_respond_int32(c, m, idx);
 #endif
@@ -1091,10 +1067,10 @@ static int dbus_connect(void) {
     if (dbus_bus_request_name(
             server->bus,
             AVAHI_DBUS_NAME,
-#if (DBUS_VERSION_MAJOR == 0) && (DBUS_VERSION_MINOR >= 60)
-            DBUS_NAME_FLAG_DO_NOT_QUEUE,
-#else
+#if (DBUS_VERSION_MAJOR == 0) && (DBUS_VERSION_MINOR < 60)
             DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT,
+#else
+            DBUS_NAME_FLAG_DO_NOT_QUEUE,
 #endif
             &error) != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
         if (dbus_error_is_set(&error)) {
@@ -1130,11 +1106,6 @@ fail:
         dbus_error_free(&error);
 
     if (server->bus) {
-#ifdef HAVE_DBUS_CONNECTION_CLOSE
-        dbus_connection_close(server->bus);
-#else
-        dbus_connection_disconnect(server->bus);
-#endif
         dbus_connection_unref(server->bus);
         server->bus = NULL;
     }
@@ -1151,11 +1122,6 @@ static void dbus_disconnect(void) {
     assert(server->n_clients == 0);
 
     if (server->bus) {
-#ifdef HAVE_DBUS_CONNECTION_CLOSE
-        dbus_connection_close(server->bus);
-#else
-        dbus_connection_disconnect(server->bus);
-#endif
         dbus_connection_unref(server->bus);
         server->bus = NULL;
     }
@@ -1190,11 +1156,6 @@ int dbus_protocol_setup(const AvahiPoll *poll_api, int _disable_user_service_pub
 
 fail:
     if (server->bus) {
-#ifdef HAVE_DBUS_CONNECTION_CLOSE
-        dbus_connection_close(server->bus);
-#else
-        dbus_connection_disconnect(server->bus);
-#endif
         dbus_connection_unref(server->bus);
     }