]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/resolve/resolve-tool.c
resolve-tool: propagate sensible errors from due to dns_name_is_valid() check failures
[thirdparty/systemd.git] / src / resolve / resolve-tool.c
index 0252bdfcd7259640be606558e1fa9e366e3ed43d..d4aac244be92d14a35b2a0dbeb1e8a2a5ac0d720 100644 (file)
@@ -41,8 +41,6 @@
 #include "strv.h"
 #include "terminal-util.h"
 
-#define DNS_CALL_TIMEOUT_USEC (90*USEC_PER_SEC)
-
 static int arg_family = AF_UNSPEC;
 static int arg_ifindex = 0;
 static uint16_t arg_type = 0;
@@ -90,7 +88,7 @@ static char *arg_set_dnssec = NULL;
 static char **arg_set_nta = NULL;
 
 static ServiceFamily service_family_from_string(const char *s) {
-        if (s == NULL || streq(s, "tcp"))
+        if (!s || streq(s, "tcp"))
                 return SERVICE_FAMILY_TCP;
         if (streq(s, "udp"))
                 return SERVICE_FAMILY_UDP;
@@ -175,7 +173,7 @@ static int resolve_host(sd_bus *bus, const char *name) {
 
         ts = now(CLOCK_MONOTONIC);
 
-        r = sd_bus_call(bus, req, DNS_CALL_TIMEOUT_USEC, &error, &reply);
+        r = sd_bus_call(bus, req, SD_RESOLVED_QUERY_TIMEOUT_USEC, &error, &reply);
         if (r < 0)
                 return log_error_errno(r, "%s: resolve call failed: %s", name, bus_error_message(&error, r));
 
@@ -306,7 +304,7 @@ static int resolve_address(sd_bus *bus, int family, const union in_addr_union *a
 
         ts = now(CLOCK_MONOTONIC);
 
-        r = sd_bus_call(bus, req, DNS_CALL_TIMEOUT_USEC, &error, &reply);
+        r = sd_bus_call(bus, req, SD_RESOLVED_QUERY_TIMEOUT_USEC, &error, &reply);
         if (r < 0) {
                 log_error("%s: resolve call failed: %s", pretty, bus_error_message(&error, r));
                 return r;
@@ -442,7 +440,7 @@ static int resolve_record(sd_bus *bus, const char *name, uint16_t class, uint16_
 
         ts = now(CLOCK_MONOTONIC);
 
-        r = sd_bus_call(bus, req, DNS_CALL_TIMEOUT_USEC, &error, &reply);
+        r = sd_bus_call(bus, req, SD_RESOLVED_QUERY_TIMEOUT_USEC, &error, &reply);
         if (r < 0) {
                 if (warn_missing || r != -ENXIO)
                         log_error("%s: resolve call failed: %s", name, bus_error_message(&error, r));
@@ -685,7 +683,7 @@ static int resolve_service(sd_bus *bus, const char *name, const char *type, cons
 
         ts = now(CLOCK_MONOTONIC);
 
-        r = sd_bus_call(bus, req, DNS_CALL_TIMEOUT_USEC, &error, &reply);
+        r = sd_bus_call(bus, req, SD_RESOLVED_QUERY_TIMEOUT_USEC, &error, &reply);
         if (r < 0)
                 return log_error_errno(r, "Resolve call failed: %s", bus_error_message(&error, r));
 
@@ -1942,12 +1940,10 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_family = AF_INET6;
                         break;
 
-                case 'i': {
-                        int ifi;
+                case 'i':
+                        if (parse_ifindex(optarg, &arg_ifindex) < 0) {
+                                int ifi;
 
-                        if (parse_ifindex(optarg, &ifi) >= 0)
-                                arg_ifindex = ifi;
-                        else {
                                 ifi = if_nametoindex(optarg);
                                 if (ifi <= 0)
                                         return log_error_errno(errno, "Unknown interface %s: %m", optarg);
@@ -1956,7 +1952,6 @@ static int parse_argv(int argc, char *argv[]) {
                         }
 
                         break;
-                }
 
                 case 't':
                         if (streq(optarg, "help")) {
@@ -2136,8 +2131,10 @@ static int parse_argv(int argc, char *argv[]) {
                         r = dns_name_is_valid(p);
                         if (r < 0)
                                 return log_error_errno(r, "Failed to validate specified domain %s: %m", p);
-                        if (r == 0)
-                                return log_error_errno(r, "Domain not valid: %s", p);
+                        if (r == 0) {
+                                log_error("Domain not valid: %s", p);
+                                return -EINVAL;
+                        }
 
                         r = strv_extend(&arg_set_domain, optarg);
                         if (r < 0)
@@ -2175,8 +2172,10 @@ static int parse_argv(int argc, char *argv[]) {
                         r = dns_name_is_valid(optarg);
                         if (r < 0)
                                 return log_error_errno(r, "Failed to validate specified domain %s: %m", optarg);
-                        if (r == 0)
-                                return log_error_errno(r, "Domain not valid: %s", optarg);
+                        if (r == 0) {
+                                log_error("Domain not valid: %s", optarg);
+                                return -EINVAL;
+                        }
 
                         r = strv_extend(&arg_set_nta, optarg);
                         if (r < 0)
@@ -2417,7 +2416,6 @@ int main(int argc, char **argv) {
 
                 break;
 
-
         case MODE_SET_LINK:
                 if (argc > optind) {
                         log_error("Too many arguments.");