chiark / gitweb /
networkd: add and expose per-link LLMNR config option
[elogind.git] / src / resolve / resolved-bus.c
index 0b8ecf1b82f2c827e1c42b903f175aec5f32a5e7..e158fdc22b188bd5f36d9f338f27fd5771b0f947 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;
@@ -42,22 +42,22 @@ static int reply_query_state(DnsQuery *q) {
 
         switch (q->state) {
 
-        case DNS_QUERY_NO_SERVERS:
+        case DNS_TRANSACTION_NO_SERVERS:
                 return sd_bus_reply_method_errorf(q->request, BUS_ERROR_NO_NAME_SERVERS, "No appropriate name servers or networks for name found");
 
-        case DNS_QUERY_TIMEOUT:
+        case DNS_TRANSACTION_TIMEOUT:
                 return sd_bus_reply_method_errorf(q->request, SD_BUS_ERROR_TIMEOUT, "Query timed out");
 
-        case DNS_QUERY_ATTEMPTS_MAX:
+        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_QUERY_RESOURCES:
+        case DNS_TRANSACTION_RESOURCES:
                 return sd_bus_reply_method_errorf(q->request, BUS_ERROR_NO_RESOURCES, "Not enough resources");
 
-        case DNS_QUERY_INVALID_REPLY:
+        case DNS_TRANSACTION_INVALID_REPLY:
                 return sd_bus_reply_method_errorf(q->request, BUS_ERROR_INVALID_REPLY, "Received invalid reply");
 
-        case DNS_QUERY_FAILURE: {
+        case DNS_TRANSACTION_FAILURE: {
                 _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
 
                 if (q->answer_rcode == DNS_RCODE_NXDOMAIN)
@@ -79,9 +79,9 @@ static int reply_query_state(DnsQuery *q) {
                 return sd_bus_reply_method_error(q->request, &error);
         }
 
-        case DNS_QUERY_NULL:
-        case DNS_QUERY_PENDING:
-        case DNS_QUERY_SUCCESS:
+        case DNS_TRANSACTION_NULL:
+        case DNS_TRANSACTION_PENDING:
+        case DNS_TRANSACTION_SUCCESS:
         default:
                 assert_not_reached("Impossible state");
         }
@@ -136,7 +136,7 @@ static void bus_method_resolve_hostname_complete(DnsQuery *q) {
 
         assert(q);
 
-        if (q->state != DNS_QUERY_SUCCESS) {
+        if (q->state != DNS_TRANSACTION_SUCCESS) {
                 r = reply_query_state(q);
                 goto finish;
         }
@@ -275,7 +275,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);
@@ -336,7 +337,7 @@ static void bus_method_resolve_address_complete(DnsQuery *q) {
 
         assert(q);
 
-        if (q->state != DNS_QUERY_SUCCESS) {
+        if (q->state != DNS_TRANSACTION_SUCCESS) {
                 r = reply_query_state(q);
                 goto finish;
         }
@@ -474,7 +475,7 @@ static void bus_method_resolve_record_complete(DnsQuery *q) {
 
         assert(q);
 
-        if (q->state != DNS_QUERY_SUCCESS) {
+        if (q->state != DNS_TRANSACTION_SUCCESS) {
                 r = reply_query_state(q);
                 goto finish;
         }
@@ -551,7 +552,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 +566,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;