diff options
author | Lennart Poettering <lennart@poettering.net> | 2019-04-11 15:21:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-11 15:21:45 +0200 |
commit | a3a1f24f81e15869b3f39ffb0d84f43b190f514e (patch) | |
tree | fea05455a61a81d7894f1fe440120989760af33a | |
parent | Merge pull request #12271 from poettering/errno-accept-again (diff) | |
parent | nss-resolve: list more errors as cause for fallback (diff) | |
download | systemd-a3a1f24f81e15869b3f39ffb0d84f43b190f514e.tar.xz systemd-a3a1f24f81e15869b3f39ffb0d84f43b190f514e.zip |
Merge pull request #12274 from poettering/nss-fixlets
some nss module fixlets
-rw-r--r-- | src/nss-myhostname/nss-myhostname.c | 32 | ||||
-rw-r--r-- | src/nss-mymachines/nss-mymachines.c | 4 | ||||
-rw-r--r-- | src/nss-resolve/nss-resolve.c | 30 |
3 files changed, 30 insertions, 36 deletions
diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c index 707caaa321..90de140a9d 100644 --- a/src/nss-myhostname/nss-myhostname.c +++ b/src/nss-myhostname/nss-myhostname.c @@ -64,10 +64,8 @@ enum nss_status _nss_myhostname_gethostbyname4_r( } else if (is_gateway_hostname(name)) { n_addresses = local_gateways(NULL, 0, AF_UNSPEC, &addresses); - if (n_addresses <= 0) { - *h_errnop = HOST_NOT_FOUND; - return NSS_STATUS_NOTFOUND; - } + if (n_addresses <= 0) + goto not_found; canonical = "_gateway"; @@ -81,10 +79,8 @@ enum nss_status _nss_myhostname_gethostbyname4_r( } /* We respond to our local host name, our hostname suffixed with a single dot. */ - if (!streq(name, hn) && !streq_ptr(startswith(name, hn), ".")) { - *h_errnop = HOST_NOT_FOUND; - return NSS_STATUS_NOTFOUND; - } + if (!streq(name, hn) && !streq_ptr(startswith(name, hn), ".")) + goto not_found; n_addresses = local_addresses(NULL, 0, AF_UNSPEC, &addresses); if (n_addresses < 0) @@ -164,6 +160,10 @@ enum nss_status _nss_myhostname_gethostbyname4_r( h_errno = 0; return NSS_STATUS_SUCCESS; + +not_found: + *h_errnop = HOST_NOT_FOUND; + return NSS_STATUS_NOTFOUND; } static enum nss_status fill_in_hostent( @@ -339,10 +339,8 @@ enum nss_status _nss_myhostname_gethostbyname3_r( } else if (is_gateway_hostname(name)) { n_addresses = local_gateways(NULL, 0, af, &addresses); - if (n_addresses <= 0) { - *h_errnop = HOST_NOT_FOUND; - return NSS_STATUS_NOTFOUND; - } + if (n_addresses <= 0) + goto not_found; canonical = "_gateway"; @@ -355,10 +353,8 @@ enum nss_status _nss_myhostname_gethostbyname3_r( return NSS_STATUS_TRYAGAIN; } - if (!streq(name, hn) && !streq_ptr(startswith(name, hn), ".")) { - *h_errnop = HOST_NOT_FOUND; - return NSS_STATUS_NOTFOUND; - } + if (!streq(name, hn) && !streq_ptr(startswith(name, hn), ".")) + goto not_found; n_addresses = local_addresses(NULL, 0, af, &addresses); if (n_addresses < 0) @@ -381,6 +377,10 @@ enum nss_status _nss_myhostname_gethostbyname3_r( errnop, h_errnop, ttlp, canonp); + +not_found: + *h_errnop = HOST_NOT_FOUND; + return NSS_STATUS_NOTFOUND; } enum nss_status _nss_myhostname_gethostbyaddr2_r( diff --git a/src/nss-mymachines/nss-mymachines.c b/src/nss-mymachines/nss-mymachines.c index da3efb960a..0e76c43172 100644 --- a/src/nss-mymachines/nss-mymachines.c +++ b/src/nss-mymachines/nss-mymachines.c @@ -232,7 +232,7 @@ enum nss_status _nss_mymachines_gethostbyname4_r( fail: UNPROTECT_ERRNO; *errnop = -r; - *h_errnop = NO_DATA; + *h_errnop = NO_RECOVERY; return NSS_STATUS_UNAVAIL; } @@ -403,7 +403,7 @@ enum nss_status _nss_mymachines_gethostbyname3_r( fail: UNPROTECT_ERRNO; *errnop = -r; - *h_errnop = NO_DATA; + *h_errnop = NO_RECOVERY; return NSS_STATUS_UNAVAIL; } diff --git a/src/nss-resolve/nss-resolve.c b/src/nss-resolve/nss-resolve.c index 0aa56c0882..ac5fff523b 100644 --- a/src/nss-resolve/nss-resolve.c +++ b/src/nss-resolve/nss-resolve.c @@ -26,7 +26,9 @@ static bool bus_error_shall_fallback(sd_bus_error *e) { return sd_bus_error_has_name(e, SD_BUS_ERROR_SERVICE_UNKNOWN) || sd_bus_error_has_name(e, SD_BUS_ERROR_NAME_HAS_NO_OWNER) || sd_bus_error_has_name(e, SD_BUS_ERROR_NO_REPLY) || - sd_bus_error_has_name(e, SD_BUS_ERROR_ACCESS_DENIED); + sd_bus_error_has_name(e, SD_BUS_ERROR_ACCESS_DENIED) || + sd_bus_error_has_name(e, SD_BUS_ERROR_DISCONNECTED) || + sd_bus_error_has_name(e, SD_BUS_ERROR_TIMEOUT); } static int count_addresses(sd_bus_message *m, int af, const char **canonical) { @@ -118,7 +120,6 @@ enum nss_status _nss_resolve_gethostbyname4_r( _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; struct gaih_addrtuple *r_tuple, *r_tuple_first = NULL; _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; - enum nss_status ret = NSS_STATUS_UNAVAIL; const char *canonical = NULL; size_t l, ms, idx; char *r_name; @@ -162,8 +163,7 @@ enum nss_status _nss_resolve_gethostbyname4_r( r = sd_bus_call(bus, req, SD_RESOLVED_QUERY_TIMEOUT_USEC, &error, &reply); if (r < 0) { - if (sd_bus_error_has_name(&error, _BUS_ERROR_DNS "NXDOMAIN") || - !bus_error_shall_fallback(&error)) + if (!bus_error_shall_fallback(&error)) goto not_found; /* Return NSS_STATUS_UNAVAIL when communication with systemd-resolved fails, @@ -273,7 +273,7 @@ fail: UNPROTECT_ERRNO; *errnop = -r; *h_errnop = NO_RECOVERY; - return ret; + return NSS_STATUS_UNAVAIL; not_found: *h_errnop = HOST_NOT_FOUND; @@ -293,7 +293,6 @@ enum nss_status _nss_resolve_gethostbyname3_r( _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; char *r_name, *r_aliases, *r_addr, *r_addr_list; _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; - enum nss_status ret = NSS_STATUS_UNAVAIL; size_t l, idx, ms, alen; const char *canonical; int c, r, i = 0; @@ -344,8 +343,7 @@ enum nss_status _nss_resolve_gethostbyname3_r( r = sd_bus_call(bus, req, SD_RESOLVED_QUERY_TIMEOUT_USEC, &error, &reply); if (r < 0) { - if (sd_bus_error_has_name(&error, _BUS_ERROR_DNS "NXDOMAIN") || - !bus_error_shall_fallback(&error)) + if (!bus_error_shall_fallback(&error)) goto not_found; goto fail; @@ -463,7 +461,7 @@ fail: UNPROTECT_ERRNO; *errnop = -r; *h_errnop = NO_RECOVERY; - return ret; + return NSS_STATUS_UNAVAIL; not_found: *h_errnop = HOST_NOT_FOUND; @@ -482,7 +480,6 @@ enum nss_status _nss_resolve_gethostbyaddr2_r( _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; char *r_name, *r_aliases, *r_addr, *r_addr_list; _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; - enum nss_status ret = NSS_STATUS_UNAVAIL; unsigned c = 0, i = 0; size_t ms = 0, idx; const char *n; @@ -505,10 +502,8 @@ enum nss_status _nss_resolve_gethostbyaddr2_r( } if (len != FAMILY_ADDRESS_SIZE(af)) { - UNPROTECT_ERRNO; - *errnop = EINVAL; - *h_errnop = NO_RECOVERY; - return NSS_STATUS_UNAVAIL; + r = -EINVAL; + goto fail; } if (avoid_deadlock()) { @@ -548,8 +543,7 @@ enum nss_status _nss_resolve_gethostbyaddr2_r( r = sd_bus_call(bus, req, SD_RESOLVED_QUERY_TIMEOUT_USEC, &error, &reply); if (r < 0) { - if (sd_bus_error_has_name(&error, _BUS_ERROR_DNS "NXDOMAIN") || - !bus_error_shall_fallback(&error)) + if (!bus_error_shall_fallback(&error)) goto not_found; goto fail; @@ -574,7 +568,7 @@ enum nss_status _nss_resolve_gethostbyaddr2_r( r = sd_bus_message_rewind(reply, false); if (r < 0) - return r; + goto fail; if (c <= 0) goto not_found; @@ -648,7 +642,7 @@ fail: UNPROTECT_ERRNO; *errnop = -r; *h_errnop = NO_RECOVERY; - return ret; + return NSS_STATUS_UNAVAIL; not_found: *h_errnop = HOST_NOT_FOUND; |