nss-mymachines.c revision 555bd6e95bf2b469306d9cd86e126c0122d0895b
/*-*- 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 "in-addr-util.h"
unsigned c = 0;
int r;
assert(m);
unsigned char 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_ifindexes, r;
if (r < 0)
goto fail;
r = -ENOTTY;
goto fail;
}
if (n_ifindexes < 0) {
r = n_ifindexes;
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 */
unsigned char 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;
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;
}
sizeof(char*) +
(c > 0 ? c+1 : 2) * sizeof(char*);
*h_errnop = NO_RECOVERY;
return NSS_STATUS_TRYAGAIN;
}
/* First, append name */
/* Second, create aliases array */
idx += sizeof(char*);
/* Third, append addresses */
unsigned char 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)
return NSS_STATUS_SUCCESS;
fail:
*errnop = -r;
return NSS_STATUS_UNAVAIL;
}