summaryrefslogtreecommitdiff
path: root/src/nss-resolve/nss-resolve.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nss-resolve/nss-resolve.c')
-rw-r--r--src/nss-resolve/nss-resolve.c78
1 files changed, 48 insertions, 30 deletions
diff --git a/src/nss-resolve/nss-resolve.c b/src/nss-resolve/nss-resolve.c
index ccbc7317f6..bc55acf8dd 100644
--- a/src/nss-resolve/nss-resolve.c
+++ b/src/nss-resolve/nss-resolve.c
@@ -66,23 +66,27 @@ static bool bus_error_shall_fallback(sd_bus_error *e) {
}
static int count_addresses(sd_bus_message *m, int af, const char **canonical) {
- int c = 0, r;
+ int c = 0, r, ifindex;
assert(m);
assert(canonical);
- r = sd_bus_message_enter_container(m, 'a', "(iayi)");
+ r = sd_bus_message_read(m, "i", &ifindex);
if (r < 0)
return r;
- while ((r = sd_bus_message_enter_container(m, 'r', "iayi")) > 0) {
+ r = sd_bus_message_enter_container(m, 'a', "(iay)");
+ if (r < 0)
+ return r;
+
+ while ((r = sd_bus_message_enter_container(m, 'r', "iay")) > 0) {
int family;
r = sd_bus_message_read(m, "i", &family);
if (r < 0)
return r;
- r = sd_bus_message_skip(m, "ayi");
+ r = sd_bus_message_skip(m, "ay");
if (r < 0)
return r;
@@ -127,7 +131,7 @@ enum nss_status _nss_resolve_gethostbyname4_r(
const char *canonical = NULL;
size_t l, ms, idx;
char *r_name;
- int c, r, i = 0;
+ int c, r, i = 0, ifindex;
assert(name);
assert(pat);
@@ -153,7 +157,7 @@ enum nss_status _nss_resolve_gethostbyname4_r(
if (r < 0)
goto fail;
- r = sd_bus_message_append(req, "si", name, AF_UNSPEC);
+ r = sd_bus_message_append(req, "isit", 0, name, AF_UNSPEC, (uint64_t) 0);
if (r < 0)
goto fail;
@@ -219,12 +223,21 @@ enum nss_status _nss_resolve_gethostbyname4_r(
/* Second, append addresses */
r_tuple_first = (struct gaih_addrtuple*) (buffer + idx);
- r = sd_bus_message_enter_container(reply, 'a', "(iayi)");
+ r = sd_bus_message_read(reply, "i", &ifindex);
+ if (r < 0)
+ goto fail;
+
+ if (ifindex < 0) {
+ r = -EINVAL;
+ goto fail;
+ }
+
+ r = sd_bus_message_enter_container(reply, 'a', "(iay)");
if (r < 0)
goto fail;
- while ((r = sd_bus_message_enter_container(reply, 'r', "iayi")) > 0) {
- int family, ifindex;
+ while ((r = sd_bus_message_enter_container(reply, 'r', "iay")) > 0) {
+ int family;
const void *a;
size_t sz;
@@ -236,10 +249,6 @@ enum nss_status _nss_resolve_gethostbyname4_r(
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;
@@ -252,11 +261,6 @@ enum nss_status _nss_resolve_gethostbyname4_r(
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;
@@ -309,7 +313,7 @@ enum nss_status _nss_resolve_gethostbyname3_r(
_cleanup_bus_close_unref_ sd_bus *bus = NULL;
size_t l, idx, ms, alen;
const char *canonical;
- int c, r, i = 0;
+ int c, r, i = 0, ifindex;
assert(name);
assert(result);
@@ -343,7 +347,7 @@ enum nss_status _nss_resolve_gethostbyname3_r(
if (r < 0)
goto fail;
- r = sd_bus_message_append(req, "si", name, af);
+ r = sd_bus_message_append(req, "isit", 0, name, af, (uint64_t) 0);
if (r < 0)
goto fail;
@@ -424,12 +428,21 @@ enum nss_status _nss_resolve_gethostbyname3_r(
/* Third, append addresses */
r_addr = buffer + idx;
- r = sd_bus_message_enter_container(reply, 'a', "(iayi)");
+ r = sd_bus_message_read(reply, "i", &ifindex);
if (r < 0)
goto fail;
- while ((r = sd_bus_message_enter_container(reply, 'r', "iayi")) > 0) {
- int family, ifindex;
+ if (ifindex < 0) {
+ r = -EINVAL;
+ goto fail;
+ }
+
+ r = sd_bus_message_enter_container(reply, 'a', "(iay)");
+ if (r < 0)
+ goto fail;
+
+ while ((r = sd_bus_message_enter_container(reply, 'r', "iay")) > 0) {
+ int family;
const void *a;
size_t sz;
@@ -441,10 +454,6 @@ enum nss_status _nss_resolve_gethostbyname3_r(
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;
@@ -521,7 +530,7 @@ enum nss_status _nss_resolve_gethostbyaddr2_r(
unsigned c = 0, i = 0;
size_t ms = 0, idx;
const char *n;
- int r;
+ int r, ifindex;
assert(addr);
assert(result);
@@ -559,7 +568,7 @@ enum nss_status _nss_resolve_gethostbyaddr2_r(
if (r < 0)
goto fail;
- r = sd_bus_message_append(req, "i", af);
+ r = sd_bus_message_append(req, "ii", 0, af);
if (r < 0)
goto fail;
@@ -567,7 +576,7 @@ enum nss_status _nss_resolve_gethostbyaddr2_r(
if (r < 0)
goto fail;
- r = sd_bus_message_append(req, "i", 0);
+ r = sd_bus_message_append(req, "t", (uint64_t) 0);
if (r < 0)
goto fail;
@@ -607,6 +616,15 @@ enum nss_status _nss_resolve_gethostbyaddr2_r(
return NSS_STATUS_UNAVAIL;
}
+ r = sd_bus_message_read(reply, "i", &ifindex);
+ if (r < 0)
+ goto fail;
+
+ if (ifindex < 0) {
+ r = -EINVAL;
+ goto fail;
+ }
+
r = sd_bus_message_enter_container(reply, 'a', "s");
if (r < 0)
goto fail;