chiark / gitweb /
resolved: destroy outstanding queries if the clients that initiated them die
[elogind.git] / src / resolve / resolved-bus.c
index bfb060d86bcdca5541a1645aad16681d55132ad0..6a3343e0006f680ec8e71ff5d0017cc4cdc96dbe 100644 (file)
@@ -22,8 +22,8 @@
 #include "bus-errors.h"
 #include "bus-util.h"
 
-#include "resolved.h"
 #include "resolved-dns-domain.h"
+#include "resolved-bus.h"
 
 static int reply_query_state(DnsQuery *q) {
         _cleanup_free_ char *ip = NULL;
@@ -51,11 +51,14 @@ static int reply_query_state(DnsQuery *q) {
         case DNS_TRANSACTION_ATTEMPTS_MAX_REACHED:
                 return sd_bus_reply_method_errorf(q->request, SD_BUS_ERROR_TIMEOUT, "All attempts to contact name servers or networks failed");
 
+        case DNS_TRANSACTION_INVALID_REPLY:
+                return sd_bus_reply_method_errorf(q->request, BUS_ERROR_INVALID_REPLY, "Received invalid reply");
+
         case DNS_TRANSACTION_RESOURCES:
                 return sd_bus_reply_method_errorf(q->request, BUS_ERROR_NO_RESOURCES, "Not enough resources");
 
-        case DNS_TRANSACTION_INVALID_REPLY:
-                return sd_bus_reply_method_errorf(q->request, BUS_ERROR_INVALID_REPLY, "Received invalid reply");
+        case DNS_TRANSACTION_ABORTED:
+                return sd_bus_reply_method_errorf(q->request, BUS_ERROR_ABORTED, "Query aborted");
 
         case DNS_TRANSACTION_FAILURE: {
                 _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
@@ -275,7 +278,8 @@ static int bus_method_resolve_hostname(sd_bus *bus, sd_bus_message *message, voi
         if (!IN_SET(family, AF_INET, AF_INET6, AF_UNSPEC))
                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown address family %i", family);
 
-        if (!hostname_is_valid(hostname))
+        r = dns_name_normalize(hostname, NULL);
+        if (r < 0)
                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid hostname '%s'", hostname);
 
         question = dns_question_new(family == AF_UNSPEC ? 2 : 1);
@@ -315,6 +319,10 @@ static int bus_method_resolve_hostname(sd_bus *bus, sd_bus_message *message, voi
         q->request_hostname = hostname;
         q->complete = bus_method_resolve_hostname_complete;
 
+        r = dns_query_bus_track(q, bus, message);
+        if (r < 0)
+                return r;
+
         r = dns_query_go(q);
         if (r < 0) {
                 dns_query_free(q);
@@ -453,6 +461,10 @@ static int bus_method_resolve_address(sd_bus *bus, sd_bus_message *message, void
         memcpy(&q->request_address, d, sz);
         q->complete = bus_method_resolve_address_complete;
 
+        r = dns_query_bus_track(q, bus, message);
+        if (r < 0)
+                return r;
+
         r = dns_query_go(q);
         if (r < 0) {
                 dns_query_free(q);
@@ -551,7 +563,6 @@ finish:
 static int bus_method_resolve_record(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
         _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
         _cleanup_(dns_question_unrefp) DnsQuestion *question = NULL;
-        _cleanup_free_ char *reverse = NULL;
         Manager *m = userdata;
         DnsQuery *q;
         int r;
@@ -566,6 +577,10 @@ static int bus_method_resolve_record(sd_bus *bus, sd_bus_message *message, void
         if (r < 0)
                 return r;
 
+        r = dns_name_normalize(name, NULL);
+        if (r < 0)
+                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid name '%s'", name);
+
         question = dns_question_new(1);
         if (!question)
                 return -ENOMEM;
@@ -586,6 +601,10 @@ static int bus_method_resolve_record(sd_bus *bus, sd_bus_message *message, void
         q->request_hostname = name;
         q->complete = bus_method_resolve_record_complete;
 
+        r = dns_query_bus_track(q, bus, message);
+        if (r < 0)
+                return r;
+
         r = dns_query_go(q);
         if (r < 0) {
                 dns_query_free(q);