nss-resolve.c revision 0dd25fb9f005d8ab7ac4bc10a609d00569f8c56a
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2014 Lennart Poettering
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 <netdb.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.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"
int c = 0, r;
assert(m);
if (r < 0)
return r;
int 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;
continue;
c ++;
}
if (r < 0)
return r;
r = sd_bus_message_exit_container(m);
if (r < 0)
return r;
if (r < 0)
return r;
r = sd_bus_message_rewind(m, true);
if (r < 0)
return r;
return c;
}
const char *name,
struct gaih_addrtuple **pat,
char *r_name;
int c, r, i = 0;
r = sd_bus_open_system(&bus);
if (r < 0)
goto fail;
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;
if (r < 0)
goto fail;
if (r < 0) {
return NSS_STATUS_NOTFOUND;
}
*errnop = -r;
*h_errnop = NO_RECOVERY;
return NSS_STATUS_UNAVAIL;
}
if (c < 0) {
r = c;
goto fail;
}
if (c == 0) {
return NSS_STATUS_NOTFOUND;
}
return NSS_STATUS_TRYAGAIN;
}
/* First, append name */
/* Second, append addresses */
if (r < 0)
goto fail;
const void *a;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
continue;
r = -EINVAL;
goto fail;
}
if (ifindex < 0) {
r = -EINVAL;
goto fail;
}
r_tuple->next = i == c-1 ? NULL : (struct gaih_addrtuple*) ((char*) r_tuple + ALIGN(sizeof(struct gaih_addrtuple)));
i++;
}
if (r < 0)
goto fail;
assert(i == c);
if (*pat)
**pat = *r_tuple_first;
else
*pat = r_tuple_first;
if (ttlp)
*ttlp = 0;
return NSS_STATUS_SUCCESS;
fail:
*errnop = -r;
return NSS_STATUS_UNAVAIL;
}
const char *name,
int af,
char **canonp) {
const char *canonical;
int c, r, i = 0;
r = -EAFNOSUPPORT;
goto fail;
}
r = sd_bus_open_system(&bus);
if (r < 0)
goto fail;
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;
if (r < 0)
goto fail;
if (r < 0) {
return NSS_STATUS_NOTFOUND;
}
*errnop = -r;
*h_errnop = NO_RECOVERY;
return NSS_STATUS_UNAVAIL;
}
if (c < 0) {
r = c;
goto fail;
}
if (c == 0) {
return NSS_STATUS_NOTFOUND;
}
sizeof(char*) +
(c > 0 ? c+1 : 2) * sizeof(char*);
return NSS_STATUS_TRYAGAIN;
}
/* First, append name */
/* Second, create empty aliases array */
idx += sizeof(char*);
/* Third, append addresses */
if (r < 0)
goto fail;
const void *a;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
continue;
r = -EINVAL;
goto fail;
}
if (ifindex < 0) {
r = -EINVAL;
goto fail;
}
i++;
}
if (r < 0)
goto fail;
assert(i == c);
/* Fourth, append address pointer array */
for (i = 0; i < c; i++)
((char**) r_addr_list)[i] = NULL;
idx += (c+1) * sizeof(char*);
if (ttlp)
*ttlp = 0;
if (canonp)
return NSS_STATUS_SUCCESS;
fail:
*errnop = -r;
return NSS_STATUS_UNAVAIL;
}
int af,
unsigned c = 0, i = 0;
const char *n;
int r;
*errnop = EAFNOSUPPORT;
return NSS_STATUS_UNAVAIL;
}
*h_errnop = NO_RECOVERY;
return NSS_STATUS_UNAVAIL;
}
r = sd_bus_open_system(&bus);
if (r < 0)
goto fail;
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;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
if (r < 0) {
return NSS_STATUS_NOTFOUND;
}
*errnop = -r;
*h_errnop = NO_RECOVERY;
return NSS_STATUS_UNAVAIL;
}
if (r < 0)
goto fail;
c++;
}
if (r < 0)
goto fail;
r = sd_bus_message_rewind(reply, false);
if (r < 0)
return r;
if (c <= 0) {
return NSS_STATUS_NOTFOUND;
}
2 * sizeof(char*) + /* pointers to the address, plus trailing NULL */
c * sizeof(char*); /* pointers to aliases, plus trailing NULL */
return NSS_STATUS_TRYAGAIN;
}
/* First, place address */
/* Second, place address list */
((char**) r_addr_list)[0] = r_addr;
idx += sizeof(char*) * 2;
/* Third, reserve space for the aliases array */
idx += sizeof(char*) * c;
/* Fourth, place aliases */
i = 0;
char *p;
size_t l;
l = strlen(n);
memcpy(p, n, l+1);
if (i > 1)
((char**) r_aliases)[i-1] = p;
i++;
}
if (r < 0)
goto fail;
if (ttlp)
*ttlp = 0;
return NSS_STATUS_SUCCESS;
fail:
*errnop = -r;
return NSS_STATUS_UNAVAIL;
}