[systemd-commits] 6 commits - Makefile.am TODO src/nss-myhostname src/nss-mymachines src/nss-resolve src/resolve src/shared
Lennart Poettering
lennart at kemper.freedesktop.org
Tue Jul 15 18:33:02 PDT 2014
Makefile.am | 20 +
TODO | 3
src/nss-myhostname/nss-myhostname.c | 13
src/nss-mymachines/nss-mymachines.c | 9
src/nss-resolve/Makefile | 1
src/nss-resolve/nss-resolve.c | 585 ++++++++++++++++++++++++++++++++++++
src/nss-resolve/nss-resolve.sym | 19 +
src/resolve/resolved-bus.c | 14
src/resolve/resolved-dns-domain.c | 20 -
src/resolve/resolved-dns-query.c | 9
src/shared/bus-errors.h | 1
11 files changed, 670 insertions(+), 24 deletions(-)
New commits:
commit f1f520e8dfe2072a6d8c50d35bc9f2f145596aa5
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jul 16 03:32:29 2014 +0200
update TODO
diff --git a/TODO b/TODO
index 4c457bb..8141d9f 100644
--- a/TODO
+++ b/TODO
@@ -31,8 +31,9 @@ Features:
- DNSSEC
- LLMNR
- mDNS/DNS-SD
- - nss client module
- DNS-SD service registration from socket units
+ - port sd-resolve to direct bus calls
+ - nss module: fallback to glibc dns modules if resolved cannot be contacted
* Allow multiple ExecStart= for all Type= settings, so that we can cover rescue.service nicely
commit 4d1cf1e229c9bdbc44778c0863eaad918f5724e7
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jul 16 03:31:30 2014 +0200
resolved: add small NSS module that uses resolved to resolve DNS names
diff --git a/Makefile.am b/Makefile.am
index ee7066e..34289fb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4605,6 +4605,26 @@ test_dns_domain_LDADD = \
libsystemd-internal.la \
libsystemd-shared.la
+libnss_resolve_la_SOURCES = \
+ src/nss-resolve/nss-resolve.sym \
+ src/nss-resolve/nss-resolve.c
+
+libnss_resolve_la_LDFLAGS = \
+ $(AM_LDFLAGS) \
+ -module \
+ -export-dynamic \
+ -avoid-version \
+ -shared \
+ -shrext .so.2 \
+ -Wl,--version-script=$(top_srcdir)/src/nss-resolve/nss-resolve.sym
+
+libnss_resolve_la_LIBADD = \
+ libsystemd-shared.la \
+ libsystemd-internal.la
+
+lib_LTLIBRARIES += \
+ libnss_resolve.la
+
endif
# ------------------------------------------------------------------------------
diff --git a/src/nss-resolve/Makefile b/src/nss-resolve/Makefile
new file mode 120000
index 0000000..d0b0e8e
--- /dev/null
+++ b/src/nss-resolve/Makefile
@@ -0,0 +1 @@
+../Makefile
\ No newline at end of file
diff --git a/src/nss-resolve/nss-resolve.c b/src/nss-resolve/nss-resolve.c
new file mode 100644
index 0000000..7b0c24f
--- /dev/null
+++ b/src/nss-resolve/nss-resolve.c
@@ -0,0 +1,585 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Lennart Poettering
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <limits.h>
+#include <nss.h>
+#include <sys/types.h>
+#include <netdb.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <net/if.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+
+#include "sd-bus.h"
+#include "bus-util.h"
+#include "bus-errors.h"
+#include "macro.h"
+#include "nss-util.h"
+#include "util.h"
+#include "in-addr-util.h"
+
+NSS_GETHOSTBYNAME_PROTOTYPES(resolve);
+NSS_GETHOSTBYADDR_PROTOTYPES(resolve);
+
+#define DNS_CALL_TIMEOUT_USEC (45*USEC_PER_SEC)
+
+static int count_addresses(sd_bus_message *m, unsigned af, unsigned *ret) {
+ unsigned c = 0;
+ int r;
+
+ assert(m);
+ assert(ret);
+
+ while ((r = sd_bus_message_enter_container(m, 'r', "yayi")) > 0) {
+ unsigned char family;
+
+ r = sd_bus_message_read(m, "y", &family);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_skip(m, "ayi");
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_exit_container(m);
+ if (r < 0)
+ return r;
+
+ if (af != AF_UNSPEC && family != af)
+ continue;
+
+ c ++;
+ }
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_rewind(m, false);
+ if (r < 0)
+ return r;
+
+ *ret = c;
+ return 0;
+}
+
+enum nss_status _nss_resolve_gethostbyname4_r(
+ const char *name,
+ struct gaih_addrtuple **pat,
+ char *buffer, size_t buflen,
+ int *errnop, int *h_errnop,
+ int32_t *ttlp) {
+
+ _cleanup_bus_message_unref_ sd_bus_message *req = NULL, *reply = NULL;
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+ struct gaih_addrtuple *r_tuple, *r_tuple_first = NULL;
+ _cleanup_bus_unref_ sd_bus *bus = NULL;
+ size_t l, ms, idx;
+ char *r_name;
+ unsigned i = 0, c = 0;
+ int r;
+
+ assert(name);
+ assert(pat);
+ assert(buffer);
+ assert(errnop);
+ assert(h_errnop);
+
+ r = sd_bus_open_system(&bus);
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_message_new_method_call(
+ bus,
+ &req,
+ "org.freedesktop.resolve1",
+ "/org/freedesktop/resolve1",
+ "org.freedesktop.resolve1.Manager",
+ "ResolveHostname");
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_message_set_auto_start(req, false);
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_message_append(req, "sy", name, AF_UNSPEC);
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_call(bus, req, DNS_CALL_TIMEOUT_USEC, &error, &reply);
+ if (r < 0) {
+ if (sd_bus_error_has_name(&error, _BUS_ERROR_DNS "NXDOMAIN")) {
+ *errnop = ESRCH;
+ *h_errnop = HOST_NOT_FOUND;
+ return NSS_STATUS_NOTFOUND;
+ }
+
+ *errnop = -r;
+ *h_errnop = NO_RECOVERY;
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ r = sd_bus_message_enter_container(reply, 'a', "(yayi)");
+ if (r < 0)
+ goto fail;
+
+ r = count_addresses(reply, AF_UNSPEC, &c);
+ if (r < 0)
+ goto fail;
+
+ if (c <= 0) {
+ *errnop = ESRCH;
+ *h_errnop = HOST_NOT_FOUND;
+ return NSS_STATUS_NOTFOUND;
+ }
+
+ l = strlen(name);
+ ms = ALIGN(l+1) + ALIGN(sizeof(struct gaih_addrtuple)) * c;
+ if (buflen < ms) {
+ *errnop = ENOMEM;
+ *h_errnop = TRY_AGAIN;
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ /* First, append name */
+ r_name = buffer;
+ memcpy(r_name, name, l+1);
+ idx = ALIGN(l+1);
+
+ /* Second, append addresses */
+ r_tuple_first = (struct gaih_addrtuple*) (buffer + idx);
+ while ((r = sd_bus_message_enter_container(reply, 'r', "yayi")) > 0) {
+ unsigned char family;
+ const void *a;
+ int ifindex;
+ size_t sz;
+
+ r = sd_bus_message_read(reply, "y", &family);
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_message_read_array(reply, 'y', &a, &sz);
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_message_read(reply, "i", &ifindex);
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_message_exit_container(reply);
+ if (r < 0)
+ goto fail;
+
+ if (!IN_SET(family, AF_INET, AF_INET6))
+ continue;
+
+ if (sz != PROTO_ADDRESS_SIZE(family)) {
+ r = -EINVAL;
+ goto fail;
+ }
+
+ if (ifindex < 0) {
+ r = -EINVAL;
+ goto fail;
+ }
+
+ r_tuple = (struct gaih_addrtuple*) (buffer + idx);
+ r_tuple->next = i == c-1 ? NULL : (struct gaih_addrtuple*) ((char*) r_tuple + ALIGN(sizeof(struct gaih_addrtuple)));
+ r_tuple->name = r_name;
+ r_tuple->family = family;
+ r_tuple->scopeid = ifindex;
+ memcpy(r_tuple->addr, a, sz);
+
+ idx += ALIGN(sizeof(struct gaih_addrtuple));
+ i++;
+ }
+
+ assert(i == c);
+
+ r = sd_bus_message_exit_container(reply);
+ if (r < 0)
+ goto fail;
+
+ assert(idx == ms);
+
+ if (*pat)
+ **pat = *r_tuple_first;
+ else
+ *pat = r_tuple_first;
+
+ if (ttlp)
+ *ttlp = 0;
+
+ return NSS_STATUS_SUCCESS;
+
+fail:
+ *errnop = -r;
+ *h_errnop = NO_DATA;
+ return NSS_STATUS_UNAVAIL;
+}
+
+enum nss_status _nss_resolve_gethostbyname3_r(
+ const char *name,
+ int af,
+ struct hostent *result,
+ char *buffer, size_t buflen,
+ int *errnop, int *h_errnop,
+ int32_t *ttlp,
+ char **canonp) {
+
+ _cleanup_bus_message_unref_ sd_bus_message *req = NULL, *reply = NULL;
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+ char *r_name, *r_aliases, *r_addr, *r_addr_list;
+ _cleanup_bus_unref_ sd_bus *bus = NULL;
+ unsigned c = 0, i = 0;
+ size_t l, idx, ms, alen;
+ int r;
+
+ assert(name);
+ assert(result);
+ assert(buffer);
+ assert(errnop);
+ assert(h_errnop);
+
+ if (af == AF_UNSPEC)
+ af = AF_INET;
+
+ if (af != AF_INET && af != AF_INET6) {
+ r = -EAFNOSUPPORT;
+ goto fail;
+ }
+
+ r = sd_bus_open_system(&bus);
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_message_new_method_call(
+ bus,
+ &req,
+ "org.freedesktop.resolve1",
+ "/org/freedesktop/resolve1",
+ "org.freedesktop.resolve1.Manager",
+ "ResolveHostname");
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_message_set_auto_start(req, false);
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_message_append(req, "sy", name, af);
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_call(bus, req, DNS_CALL_TIMEOUT_USEC, &error, &reply);
+ if (r < 0) {
+ if (sd_bus_error_has_name(&error, _BUS_ERROR_DNS "NXDOMAIN")) {
+ *errnop = ESRCH;
+ *h_errnop = HOST_NOT_FOUND;
+ return NSS_STATUS_NOTFOUND;
+ }
+
+ *errnop = -r;
+ *h_errnop = NO_RECOVERY;
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ r = sd_bus_message_enter_container(reply, 'a', "(yayi)");
+ if (r < 0)
+ goto fail;
+
+ r = count_addresses(reply, af, &c);
+ if (r < 0)
+ goto fail;
+
+ if (c <= 0) {
+ *errnop = ESRCH;
+ *h_errnop = HOST_NOT_FOUND;
+ return NSS_STATUS_NOTFOUND;
+ }
+
+ alen = PROTO_ADDRESS_SIZE(af);
+ l = strlen(name);
+
+ ms = ALIGN(l+1) +
+ sizeof(char*) +
+ (c > 0 ? c : 1) * ALIGN(alen) +
+ (c > 0 ? c+1 : 2) * sizeof(char*);
+
+ if (buflen < ms) {
+ *errnop = ENOMEM;
+ *h_errnop = TRY_AGAIN;
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ /* First, append name */
+ r_name = buffer;
+ memcpy(r_name, name, l+1);
+ idx = ALIGN(l+1);
+
+ /* Second, create aliases array */
+ r_aliases = buffer + idx;
+ ((char**) r_aliases)[0] = NULL;
+ idx += sizeof(char*);
+
+ /* Third, append addresses */
+ r_addr = buffer + idx;
+ while ((r = sd_bus_message_enter_container(reply, 'r', "yayi")) > 0) {
+ unsigned char family;
+ const void *a;
+ int ifindex;
+ size_t sz;
+
+ r = sd_bus_message_read(reply, "y", &family);
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_message_read_array(reply, 'y', &a, &sz);
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_message_read(reply, "i", &ifindex);
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_message_exit_container(reply);
+ if (r < 0)
+ goto fail;
+
+ if (family != af)
+ continue;
+
+ if (sz != alen) {
+ r = -EINVAL;
+ goto fail;
+ }
+
+ if (ifindex < 0) {
+ r = -EINVAL;
+ goto fail;
+ }
+
+ memcpy(r_addr + i*ALIGN(alen), a, alen);
+ i++;
+ }
+
+ assert(i == c);
+ idx += c * ALIGN(alen);
+
+ r = sd_bus_message_exit_container(reply);
+ if (r < 0)
+ goto fail;
+
+ /* Third, append address pointer array */
+ r_addr_list = buffer + idx;
+ for (i = 0; i < c; i++)
+ ((char**) r_addr_list)[i] = r_addr + i*ALIGN(alen);
+
+ ((char**) r_addr_list)[i] = NULL;
+ idx += (c+1) * sizeof(char*);
+
+ assert(idx == ms);
+
+ result->h_name = r_name;
+ result->h_aliases = (char**) r_aliases;
+ result->h_addrtype = af;
+ result->h_length = alen;
+ result->h_addr_list = (char**) r_addr_list;
+
+ if (ttlp)
+ *ttlp = 0;
+
+ if (canonp)
+ *canonp = r_name;
+
+ return NSS_STATUS_SUCCESS;
+
+fail:
+ *errnop = -r;
+ *h_errnop = NO_DATA;
+ return NSS_STATUS_UNAVAIL;
+}
+
+enum nss_status _nss_resolve_gethostbyaddr2_r(
+ const void* addr, socklen_t len,
+ int af,
+ struct hostent *result,
+ char *buffer, size_t buflen,
+ int *errnop, int *h_errnop,
+ int32_t *ttlp) {
+
+ _cleanup_bus_message_unref_ sd_bus_message *req = NULL, *reply = NULL;
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+ char *r_name, *r_aliases, *r_addr, *r_addr_list;
+ _cleanup_bus_unref_ sd_bus *bus = NULL;
+ unsigned c = 0, i = 0;
+ size_t ms = 0, idx;
+ const char *n;
+ int r;
+
+ assert(addr);
+ assert(result);
+ assert(buffer);
+ assert(errnop);
+ assert(h_errnop);
+
+ if (!IN_SET(af, AF_INET, AF_INET6)) {
+ *errnop = EAFNOSUPPORT;
+ *h_errnop = NO_DATA;
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ if (len != PROTO_ADDRESS_SIZE(af)) {
+ *errnop = EINVAL;
+ *h_errnop = NO_RECOVERY;
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ r = sd_bus_open_system(&bus);
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_message_new_method_call(
+ bus,
+ &req,
+ "org.freedesktop.resolve1",
+ "/org/freedesktop/resolve1",
+ "org.freedesktop.resolve1.Manager",
+ "ResolveAddress");
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_message_set_auto_start(req, false);
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_message_append(req, "y", af);
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_message_append_array(req, 'y', addr, len);
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_message_append(req, "i", 0);
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_call(bus, req, DNS_CALL_TIMEOUT_USEC, &error, &reply);
+ if (r < 0) {
+ if (sd_bus_error_has_name(&error, _BUS_ERROR_DNS "NXDOMAIN")) {
+ *errnop = ESRCH;
+ *h_errnop = HOST_NOT_FOUND;
+ return NSS_STATUS_NOTFOUND;
+ }
+
+ *errnop = -r;
+ *h_errnop = NO_RECOVERY;
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ r = sd_bus_message_enter_container(reply, 'a', "s");
+ if (r < 0)
+ goto fail;
+
+ while ((r = sd_bus_message_read(reply, "s", &n)) > 0) {
+ c++;
+ ms += ALIGN(strlen(n) + 1);
+ }
+ if (r < 0)
+ goto fail;
+
+ r = sd_bus_message_rewind(reply, false);
+ if (r < 0)
+ return r;
+
+ if (c <= 0) {
+ *errnop = ESRCH;
+ *h_errnop = HOST_NOT_FOUND;
+ return NSS_STATUS_NOTFOUND;
+ }
+
+ ms += ALIGN(len) + /* the address */
+ 2 * sizeof(char*) + /* pointers to the address, plus trailing NULL */
+ c * sizeof(char*); /* pointers to aliases, plus trailing NULL */
+
+ if (buflen < ms) {
+ *errnop = ENOMEM;
+ *h_errnop = TRY_AGAIN;
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ /* First, place address */
+ r_addr = buffer;
+ memcpy(r_addr, addr, len);
+ idx = ALIGN(len);
+
+ /* Second, place address list */
+ r_addr_list = buffer + idx;
+ ((char**) r_addr_list)[0] = r_addr;
+ ((char**) r_addr_list)[1] = NULL;
+ idx += sizeof(char*) * 2;
+
+ /* Third, reserve space for the aliases array */
+ r_aliases = buffer + idx;
+ idx += sizeof(char*) * c;
+
+ /* Fourth, place aliases */
+ i = 0;
+ r_name = buffer + idx;
+ while ((r = sd_bus_message_read(reply, "s", &n)) > 0) {
+ char *p;
+ size_t l;
+
+ l = strlen(n);
+ p = buffer + idx;
+ memcpy(p, n, l+1);
+
+ if (i > 1)
+ ((char**) r_aliases)[i-1] = p;
+ i++;
+
+ idx += ALIGN(l+1);
+ }
+
+ ((char**) r_aliases)[c-1] = NULL;
+ assert(idx == ms);
+
+ result->h_name = r_name;
+ result->h_aliases = (char**) r_aliases;
+ result->h_addrtype = af;
+ result->h_length = len;
+ result->h_addr_list = (char**) r_addr_list;
+
+ if (ttlp)
+ *ttlp = 0;
+
+ return NSS_STATUS_SUCCESS;
+
+fail:
+ *errnop = -r;
+ *h_errnop = NO_DATA;
+ return NSS_STATUS_UNAVAIL;
+}
+
+NSS_GETHOSTBYNAME_FALLBACKS(resolve);
+NSS_GETHOSTBYADDR_FALLBACKS(resolve);
diff --git a/src/nss-resolve/nss-resolve.sym b/src/nss-resolve/nss-resolve.sym
new file mode 100644
index 0000000..df8dff2
--- /dev/null
+++ b/src/nss-resolve/nss-resolve.sym
@@ -0,0 +1,19 @@
+/***
+ This file is part of systemd.
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+***/
+
+{
+global:
+ _nss_resolve_gethostbyname_r;
+ _nss_resolve_gethostbyname2_r;
+ _nss_resolve_gethostbyname3_r;
+ _nss_resolve_gethostbyname4_r;
+ _nss_resolve_gethostbyaddr_r;
+ _nss_resolve_gethostbyaddr2_r;
+local: *;
+};
diff --git a/src/resolve/resolved-bus.c b/src/resolve/resolved-bus.c
index 50eb012..e73bdac 100644
--- a/src/resolve/resolved-bus.c
+++ b/src/resolve/resolved-bus.c
@@ -450,7 +450,7 @@ int manager_connect_bus(Manager *m) {
return 0;
}
- r = sd_bus_add_object_vtable(m->bus, NULL, "/org/freedesktop/resolve1", "org.freedesktop.resolve1", resolve_vtable, m);
+ r = sd_bus_add_object_vtable(m->bus, NULL, "/org/freedesktop/resolve1", "org.freedesktop.resolve1.Manager", resolve_vtable, m);
if (r < 0) {
log_error("Failed to register object: %s", strerror(-r));
return r;
commit 555bd6e95bf2b469306d9cd86e126c0122d0895b
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jul 16 03:30:40 2014 +0200
nss: various minor fixes to nss-myhostname + nss-mymachines
diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c
index 23646e6..f5dadb6 100644
--- a/src/nss-myhostname/nss-myhostname.c
+++ b/src/nss-myhostname/nss-myhostname.c
@@ -387,6 +387,12 @@ enum nss_status _nss_myhostname_gethostbyaddr2_r(
assert(errnop);
assert(h_errnop);
+ if (!IN_SET(af, AF_INET, AF_INET6)) {
+ *errnop = EAFNOSUPPORT;
+ *h_errnop = NO_DATA;
+ return NSS_STATUS_UNAVAIL;
+ }
+
if (len != PROTO_ADDRESS_SIZE(af)) {
*errnop = EINVAL;
*h_errnop = NO_RECOVERY;
@@ -404,17 +410,14 @@ enum nss_status _nss_myhostname_gethostbyaddr2_r(
goto found;
}
- } else if (af == AF_INET6) {
+ } else {
+ assert(af == AF_INET6);
if (memcmp(addr, LOCALADDRESS_IPV6, 16) == 0) {
additional = "localhost";
goto found;
}
- } else {
- *errnop = EAFNOSUPPORT;
- *h_errnop = NO_DATA;
- return NSS_STATUS_UNAVAIL;
}
n_addresses = local_addresses(&addresses);
diff --git a/src/nss-mymachines/nss-mymachines.c b/src/nss-mymachines/nss-mymachines.c
index 2d3e542..5327499 100644
--- a/src/nss-mymachines/nss-mymachines.c
+++ b/src/nss-mymachines/nss-mymachines.c
@@ -131,7 +131,7 @@ enum nss_status _nss_mymachines_gethostbyname4_r(
goto fail;
if (c <= 0) {
- *errnop = ENOENT;
+ *errnop = ESRCH;
*h_errnop = HOST_NOT_FOUND;
return NSS_STATUS_NOTFOUND;
}
@@ -140,7 +140,7 @@ enum nss_status _nss_mymachines_gethostbyname4_r(
ms = ALIGN(l+1) + ALIGN(sizeof(struct gaih_addrtuple)) * c;
if (buflen < ms) {
*errnop = ENOMEM;
- *h_errnop = NO_RECOVERY;
+ *h_errnop = TRY_AGAIN;
return NSS_STATUS_TRYAGAIN;
}
@@ -168,6 +168,11 @@ enum nss_status _nss_mymachines_gethostbyname4_r(
if (r < 0)
goto fail;
+ if (!IN_SET(family, AF_INET, AF_INET6)) {
+ r = -EAFNOSUPPORT;
+ goto fail;
+ }
+
if (sz != PROTO_ADDRESS_SIZE(family)) {
r = -EINVAL;
goto fail;
commit 1fa65c593c6d2fbafe9d0f7caa6eb1c8034da2e0
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jul 16 03:29:20 2014 +0200
dns-domain: never allow labels that are larger than 63 chars
diff --git a/src/resolve/resolved-dns-domain.c b/src/resolve/resolved-dns-domain.c
index 33ae261..27739c1 100644
--- a/src/resolve/resolved-dns-domain.c
+++ b/src/resolve/resolved-dns-domain.c
@@ -45,6 +45,9 @@ int dns_label_unescape(const char **name, char *dest, size_t sz) {
if (sz <= 0)
return -ENOSPC;
+ if (r >= DNS_LABEL_MAX)
+ return -EINVAL;
+
if (*n == '\\') {
/* Escaped character */
@@ -114,6 +117,9 @@ int dns_label_escape(const char *p, size_t l, char **ret) {
assert(p);
assert(ret);
+ if (l > DNS_LABEL_MAX)
+ return -EINVAL;
+
s = malloc(l * 4 + 1);
if (!s)
return -ENOMEM;
commit 3fe1169fe3a692b8416848abc451bd1e4cbc4e4a
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jul 16 03:28:52 2014 +0200
dns-domain: fix generation of reverse IP address lookup name
diff --git a/src/resolve/resolved-dns-domain.c b/src/resolve/resolved-dns-domain.c
index 94ffc0f..33ae261 100644
--- a/src/resolve/resolved-dns-domain.c
+++ b/src/resolve/resolved-dns-domain.c
@@ -334,11 +334,15 @@ int dns_name_reverse(int family, const union in_addr_union *a, char **ret) {
if (family == AF_INET)
r = asprintf(ret, "%u.%u.%u.%u.in-addr.arpa", p[3], p[2], p[1], p[0]);
else if (family == AF_INET6)
- r = asprintf(ret, "%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.ip6.arpa",
- hexchar(p[15]), hexchar(p[14]), hexchar(p[13]), hexchar(p[12]),
- hexchar(p[11]), hexchar(p[10]), hexchar(p[ 9]), hexchar(p[ 8]),
- hexchar(p[ 7]), hexchar(p[ 6]), hexchar(p[ 5]), hexchar(p[ 4]),
- hexchar(p[ 3]), hexchar(p[ 2]), hexchar(p[ 1]), hexchar(p[ 0]));
+ r = asprintf(ret, "%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.%c.ip6.arpa",
+ hexchar(p[15] & 0xF), hexchar(p[15] >> 4), hexchar(p[14] & 0xF), hexchar(p[14] >> 4),
+ hexchar(p[13] & 0xF), hexchar(p[13] >> 4), hexchar(p[12] & 0xF), hexchar(p[12] >> 4),
+ hexchar(p[11] & 0xF), hexchar(p[11] >> 4), hexchar(p[10] & 0xF), hexchar(p[10] >> 4),
+ hexchar(p[ 9] & 0xF), hexchar(p[ 9] >> 4), hexchar(p[ 8] & 0xF), hexchar(p[ 8] >> 4),
+ hexchar(p[ 7] & 0xF), hexchar(p[ 7] >> 4), hexchar(p[ 6] & 0xF), hexchar(p[ 6] >> 4),
+ hexchar(p[ 5] & 0xF), hexchar(p[ 5] >> 4), hexchar(p[ 4] & 0xF), hexchar(p[ 4] >> 4),
+ hexchar(p[ 3] & 0xF), hexchar(p[ 3] >> 4), hexchar(p[ 2] & 0xF), hexchar(p[ 2] >> 4),
+ hexchar(p[ 1] & 0xF), hexchar(p[ 1] >> 4), hexchar(p[ 0] & 0xF), hexchar(p[ 0] >> 4));
else
return -EAFNOSUPPORT;
if (r < 0)
commit b9d394ea565fd742bcdd34e8dd61ae07c58a9565
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jul 16 03:28:18 2014 +0200
resolve: add distinct bus error code for hosts that exist but lack A or AAAA records
diff --git a/src/resolve/resolved-bus.c b/src/resolve/resolved-bus.c
index 4a011ef..50eb012 100644
--- a/src/resolve/resolved-bus.c
+++ b/src/resolve/resolved-bus.c
@@ -138,8 +138,10 @@ static void bus_method_resolve_hostname_complete(DnsQuery *q) {
added ++;
}
- if (added <= 0)
- goto parse_fail;
+ if (added <= 0) {
+ r = sd_bus_reply_method_errorf(q->request, BUS_ERROR_NO_SUCH_RR, "Hostname %s does not have RR of this type", q->request_hostname);
+ break;
+ }
r = sd_bus_message_close_container(reply);
if (r < 0)
@@ -315,8 +317,10 @@ static void bus_method_resolve_address_complete(DnsQuery *q) {
added ++;
}
- if (added <= 0)
- goto parse_fail;
+ if (added <= 0) {
+ r = sd_bus_reply_method_errorf(q->request, BUS_ERROR_NO_SUCH_RR, "Address %s does not have RR of this type", ip);
+ break;
+ }
r = sd_bus_message_close_container(reply);
if (r < 0)
diff --git a/src/resolve/resolved-dns-query.c b/src/resolve/resolved-dns-query.c
index a988052..dd81215 100644
--- a/src/resolve/resolved-dns-query.c
+++ b/src/resolve/resolved-dns-query.c
@@ -107,12 +107,9 @@ int dns_query_transaction_reply(DnsQueryTransaction *t, DnsPacket *p) {
t->packet = dns_packet_ref(p);
- if (DNS_PACKET_RCODE(p) == DNS_RCODE_SUCCESS) {
- if( be16toh(DNS_PACKET_HEADER(p)->ancount) > 0)
- dns_query_transaction_set_state(t, DNS_QUERY_SUCCESS);
- else
- dns_query_transaction_set_state(t, DNS_QUERY_INVALID_REPLY);
- } else
+ if (DNS_PACKET_RCODE(p) == DNS_RCODE_SUCCESS)
+ dns_query_transaction_set_state(t, DNS_QUERY_SUCCESS);
+ else
dns_query_transaction_set_state(t, DNS_QUERY_FAILURE);
return 0;
diff --git a/src/shared/bus-errors.h b/src/shared/bus-errors.h
index 388b42b..08a7acc 100644
--- a/src/shared/bus-errors.h
+++ b/src/shared/bus-errors.h
@@ -62,4 +62,5 @@
#define BUS_ERROR_NO_NAME_SERVERS "org.freedesktop.resolve1.NoNameServers"
#define BUS_ERROR_INVALID_REPLY "org.freedesktop.resolve1.InvalidReply"
+#define BUS_ERROR_NO_SUCH_RR "org.freedesktop.resolve1.NoSuchRR"
#define _BUS_ERROR_DNS "org.freedesktop.resolve1.DnsError."
More information about the systemd-commits
mailing list