nss-mymachines.c revision c077529ba6852192c464772ce907670850210dfe
/*-*- 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 <nss.h>
#include <netdb.h>
#include "sd-bus.h"
#include "sd-login.h"
#include "macro.h"
#include "util.h"
#include "nss-util.h"
#include "bus-util.h"
#include "bus-common-errors.h"
#include "in-addr-util.h"
#include "hostname-util.h"
unsigned c = 0;
int r;
assert(m);
int family;
if (r < 0)
return r;
r = sd_bus_message_skip(m, "ay");
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_rewind(m, false);
if (r < 0)
return r;
*ret = c;
return 0;
}
const char *name,
struct gaih_addrtuple **pat,
unsigned i = 0, c = 0;
char *r_name;
int n_ifindices, r;
if (r < 0)
goto fail;
r = -ENOTTY;
goto fail;
}
if (n_ifindices < 0) {
r = n_ifindices;
goto fail;
}
r = sd_bus_open_system(&bus);
if (r < 0)
goto fail;
r = sd_bus_call_method(bus,
"org.freedesktop.machine1",
"/org/freedesktop/machine1",
"org.freedesktop.machine1.Manager",
"GetMachineAddresses",
NULL,
&reply,
"s", name);
if (r < 0)
goto fail;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
if (c <= 0) {
return NSS_STATUS_NOTFOUND;
}
return NSS_STATUS_TRYAGAIN;
}
/* First, append name */
/* Second, append addresses */
int family;
const void *a;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
r = -EAFNOSUPPORT;
goto fail;
}
r = -EINVAL;
goto fail;
}
r_tuple->next = i == c-1 ? NULL : (struct gaih_addrtuple*) ((char*) r_tuple + ALIGN(sizeof(struct gaih_addrtuple)));
i++;
}
assert(i == c);
if (r < 0)
goto fail;
if (*pat)
**pat = *r_tuple_first;
else
*pat = r_tuple_first;
if (ttlp)
*ttlp = 0;
/* Explicitly reset all error variables */
*errnop = 0;
h_errno = 0;
return NSS_STATUS_SUCCESS;
fail:
*errnop = -r;
return NSS_STATUS_UNAVAIL;
}
const char *name,
int af,
char **canonp) {
unsigned c = 0, i = 0;
int r;
r = -EAFNOSUPPORT;
goto fail;
}
if (r < 0)
goto fail;
r = -ENOTTY;
goto fail;
}
r = sd_bus_open_system(&bus);
if (r < 0)
goto fail;
r = sd_bus_call_method(bus,
"org.freedesktop.machine1",
"/org/freedesktop/machine1",
"org.freedesktop.machine1.Manager",
"GetMachineAddresses",
NULL,
&reply,
"s", name);
if (r < 0)
goto fail;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
if (c <= 0) {
return NSS_STATUS_NOTFOUND;
}
*h_errnop = NO_RECOVERY;
return NSS_STATUS_TRYAGAIN;
}
/* First, append name */
/* Second, create aliases array */
idx += sizeof(char*);
/* Third, append addresses */
int family;
const void *a;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
continue;
r = -EINVAL;
goto fail;
}
i++;
}
assert(i == c);
if (r < 0)
goto fail;
/* Third, 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)
/* Explicitly reset all error variables */
*errnop = 0;
h_errno = 0;
return NSS_STATUS_SUCCESS;
fail:
*errnop = -r;
return NSS_STATUS_UNAVAIL;
}
const char *name,
int *errnop) {
const char *p, *e, *machine;
size_t l;
int r;
if (!p)
goto not_found;
e = strrchr(p, '-');
if (!e || e == p)
goto not_found;
if (r < 0)
goto not_found;
if (!machine_name_is_valid(machine))
goto not_found;
r = sd_bus_open_system(&bus);
if (r < 0)
goto fail;
r = sd_bus_call_method(bus,
"org.freedesktop.machine1",
"/org/freedesktop/machine1",
"org.freedesktop.machine1.Manager",
"MapFromMachineUser",
&error,
&reply,
"su",
if (r < 0) {
goto not_found;
goto fail;
}
if (r < 0)
goto fail;
if (buflen < l+1) {
return NSS_STATUS_TRYAGAIN;
}
*errnop = 0;
return NSS_STATUS_SUCCESS;
*errnop = 0;
return NSS_STATUS_NOTFOUND;
fail:
*errnop = -r;
return NSS_STATUS_UNAVAIL;
}
int *errnop) {
int r;
if (!uid_is_valid(uid)) {
r = -EINVAL;
goto fail;
}
/* We consider all uids < 65536 host uids */
if (uid < 0x10000)
goto not_found;
r = sd_bus_open_system(&bus);
if (r < 0)
goto fail;
r = sd_bus_call_method(bus,
"org.freedesktop.machine1",
"/org/freedesktop/machine1",
"org.freedesktop.machine1.Manager",
"MapToMachineUser",
&error,
&reply,
"u",
if (r < 0) {
goto not_found;
goto fail;
}
if (r < 0)
goto fail;
return NSS_STATUS_TRYAGAIN;
}
*errnop = 0;
return NSS_STATUS_SUCCESS;
*errnop = 0;
return NSS_STATUS_NOTFOUND;
fail:
*errnop = -r;
return NSS_STATUS_UNAVAIL;
}
const char *name,
int *errnop) {
const char *p, *e, *machine;
size_t l;
int r;
if (!p)
goto not_found;
e = strrchr(p, '-');
if (!e || e == p)
goto not_found;
if (r < 0)
goto not_found;
if (!machine_name_is_valid(machine))
goto not_found;
r = sd_bus_open_system(&bus);
if (r < 0)
goto fail;
r = sd_bus_call_method(bus,
"org.freedesktop.machine1",
"/org/freedesktop/machine1",
"org.freedesktop.machine1.Manager",
"MapFromMachineGroup",
&error,
&reply,
"su",
if (r < 0) {
goto not_found;
goto fail;
}
if (r < 0)
goto fail;
if (buflen < l) {
return NSS_STATUS_TRYAGAIN;
}
*errnop = 0;
return NSS_STATUS_SUCCESS;
*errnop = 0;
return NSS_STATUS_NOTFOUND;
fail:
*errnop = -r;
return NSS_STATUS_UNAVAIL;
}
int *errnop) {
int r;
if (!gid_is_valid(gid)) {
r = -EINVAL;
goto fail;
}
/* We consider all gids < 65536 host gids */
if (gid < 0x10000)
goto not_found;
r = sd_bus_open_system(&bus);
if (r < 0)
goto fail;
r = sd_bus_call_method(bus,
"org.freedesktop.machine1",
"/org/freedesktop/machine1",
"org.freedesktop.machine1.Manager",
"MapToMachineGroup",
&error,
&reply,
"u",
if (r < 0) {
goto not_found;
goto fail;
}
if (r < 0)
goto fail;
if (buflen < sizeof(char*) + 1) {
return NSS_STATUS_TRYAGAIN;
}
if (snprintf(buffer + sizeof(char*), buflen - sizeof(char*), "vg-%s-" GID_FMT, machine, (gid_t) mapped) >= (int) buflen) {
return NSS_STATUS_TRYAGAIN;
}
*errnop = 0;
return NSS_STATUS_SUCCESS;
*errnop = 0;
return NSS_STATUS_NOTFOUND;
fail:
*errnop = -r;
return NSS_STATUS_UNAVAIL;
}