chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fsckd daemon for inter-fsckd communication
[elogind.git]
/
src
/
nss-myhostname
/
nss-myhostname.c
diff --git
a/src/nss-myhostname/nss-myhostname.c
b/src/nss-myhostname/nss-myhostname.c
index 86e7be2aa132d4ca9e9ecc8590d41e63022e6a23..a939bb267cbe1c2f8a2c10d53b101db7adc45829 100644
(file)
--- a/
src/nss-myhostname/nss-myhostname.c
+++ b/
src/nss-myhostname/nss-myhostname.c
@@
-38,7
+38,7
@@
/* We use 127.0.0.2 as IPv4 address. This has the advantage over
* 127.0.0.1 that it can be translated back to the local hostname. For
* IPv6 we use ::1 which unfortunately will not translate back to the
/* We use 127.0.0.2 as IPv4 address. This has the advantage over
* 127.0.0.1 that it can be translated back to the local hostname. For
* IPv6 we use ::1 which unfortunately will not translate back to the
- * hostname but instead something like "localhost
6
" or so. */
+ * hostname but instead something like "localhost" or so. */
#define LOCALADDRESS_IPV4 (htonl(0x7F000002))
#define LOCALADDRESS_IPV6 &in6addr_loopback
#define LOCALADDRESS_IPV4 (htonl(0x7F000002))
#define LOCALADDRESS_IPV6 &in6addr_loopback
@@
-47,6
+47,13
@@
NSS_GETHOSTBYNAME_PROTOTYPES(myhostname);
NSS_GETHOSTBYADDR_PROTOTYPES(myhostname);
NSS_GETHOSTBYNAME_PROTOTYPES(myhostname);
NSS_GETHOSTBYADDR_PROTOTYPES(myhostname);
+static bool is_gateway(const char *hostname) {
+ assert(hostname);
+
+ return streq(hostname, "gateway") ||
+ streq(hostname, "gateway.");
+}
+
enum nss_status _nss_myhostname_gethostbyname4_r(
const char *name,
struct gaih_addrtuple **pat,
enum nss_status _nss_myhostname_gethostbyname4_r(
const char *name,
struct gaih_addrtuple **pat,
@@
-77,6
+84,18
@@
enum nss_status _nss_myhostname_gethostbyname4_r(
canonical = "localhost";
local_address_ipv4 = htonl(INADDR_LOOPBACK);
canonical = "localhost";
local_address_ipv4 = htonl(INADDR_LOOPBACK);
+
+ } else if (is_gateway(name)) {
+
+ n_addresses = local_gateways(NULL, 0, AF_UNSPEC, &addresses);
+ if (n_addresses <= 0) {
+ *errnop = ENOENT;
+ *h_errnop = HOST_NOT_FOUND;
+ return NSS_STATUS_NOTFOUND;
+ }
+
+ canonical = "gateway";
+
} else {
hn = gethostname_malloc();
if (!hn) {
} else {
hn = gethostname_malloc();
if (!hn) {
@@
-92,7
+111,7
@@
enum nss_status _nss_myhostname_gethostbyname4_r(
return NSS_STATUS_NOTFOUND;
}
return NSS_STATUS_NOTFOUND;
}
- n_addresses = local_addresses(NULL, 0, &addresses);
+ n_addresses = local_addresses(NULL, 0,
AF_UNSPEC,
&addresses);
if (n_addresses < 0)
n_addresses = 0;
if (n_addresses < 0)
n_addresses = 0;
@@
-314,7
+333,7
@@
enum nss_status _nss_myhostname_gethostbyname3_r(
_cleanup_free_ struct local_address *addresses = NULL;
const char *canonical, *additional = NULL;
_cleanup_free_ char *hn = NULL;
_cleanup_free_ struct local_address *addresses = NULL;
const char *canonical, *additional = NULL;
_cleanup_free_ char *hn = NULL;
- uint32_t local_address_ipv4;
+ uint32_t local_address_ipv4
= 0
;
int n_addresses = 0;
assert(name);
int n_addresses = 0;
assert(name);
@@
-335,6
+354,18
@@
enum nss_status _nss_myhostname_gethostbyname3_r(
if (is_localhost(name)) {
canonical = "localhost";
local_address_ipv4 = htonl(INADDR_LOOPBACK);
if (is_localhost(name)) {
canonical = "localhost";
local_address_ipv4 = htonl(INADDR_LOOPBACK);
+
+ } else if (is_gateway(name)) {
+
+ n_addresses = local_gateways(NULL, 0, af, &addresses);
+ if (n_addresses <= 0) {
+ *errnop = ENOENT;
+ *h_errnop = HOST_NOT_FOUND;
+ return NSS_STATUS_NOTFOUND;
+ }
+
+ canonical = "gateway";
+
} else {
hn = gethostname_malloc();
if (!hn) {
} else {
hn = gethostname_malloc();
if (!hn) {
@@
-349,7
+380,7
@@
enum nss_status _nss_myhostname_gethostbyname3_r(
return NSS_STATUS_NOTFOUND;
}
return NSS_STATUS_NOTFOUND;
}
- n_addresses = local_addresses(NULL, 0, &addresses);
+ n_addresses = local_addresses(NULL, 0,
af,
&addresses);
if (n_addresses < 0)
n_addresses = 0;
if (n_addresses < 0)
n_addresses = 0;
@@
-384,6
+415,7
@@
enum nss_status _nss_myhostname_gethostbyaddr2_r(
_cleanup_free_ char *hn = NULL;
int n_addresses = 0;
struct local_address *a;
_cleanup_free_ char *hn = NULL;
int n_addresses = 0;
struct local_address *a;
+ bool additional_from_hostname = false;
unsigned n;
assert(addr);
unsigned n;
assert(addr);
@@
-405,7
+437,6
@@
enum nss_status _nss_myhostname_gethostbyaddr2_r(
}
if (af == AF_INET) {
}
if (af == AF_INET) {
-
if ((*(uint32_t*) addr) == LOCALADDRESS_IPV4)
goto found;
if ((*(uint32_t*) addr) == LOCALADDRESS_IPV4)
goto found;
@@
-419,22
+450,37
@@
enum nss_status _nss_myhostname_gethostbyaddr2_r(
assert(af == AF_INET6);
if (memcmp(addr, LOCALADDRESS_IPV6, 16) == 0) {
assert(af == AF_INET6);
if (memcmp(addr, LOCALADDRESS_IPV6, 16) == 0) {
- additional = "localhost";
+ canonical = "localhost";
+ additional_from_hostname = true;
goto found;
}
goto found;
}
+ }
+
+ n_addresses = local_addresses(NULL, 0, AF_UNSPEC, &addresses);
+ if (n_addresses > 0) {
+ for (a = addresses, n = 0; (int) n < n_addresses; n++, a++) {
+ if (af != a->family)
+ continue;
+ if (memcmp(addr, &a->address, FAMILY_ADDRESS_SIZE(af)) == 0)
+ goto found;
+ }
}
}
- n_addresses = local_addresses(NULL, 0, &addresses);
- if (n_addresses < 0)
- n_addresses = 0;
+ free(addresses);
+ addresses = NULL;
- for (a = addresses, n = 0; (int) n < n_addresses; n++, a++) {
- if (af != a->family)
- continue;
+ n_addresses = local_gateways(NULL, 0, AF_UNSPEC, &addresses);
+ if (n_addresses > 0) {
+ for (a = addresses, n = 0; (int) n < n_addresses; n++, a++) {
+ if (af != a->family)
+ continue;
- if (memcmp(addr, &a->address, FAMILY_ADDRESS_SIZE(af)) == 0)
- goto found;
+ if (memcmp(addr, &a->address, FAMILY_ADDRESS_SIZE(af)) == 0) {
+ canonical = "gateway";
+ goto found;
+ }
+ }
}
*errnop = ENOENT;
}
*errnop = ENOENT;
@@
-443,7
+489,7
@@
enum nss_status _nss_myhostname_gethostbyaddr2_r(
return NSS_STATUS_NOTFOUND;
found:
return NSS_STATUS_NOTFOUND;
found:
- if (!canonical) {
+ if (!canonical
|| (!additional && additional_from_hostname)
) {
hn = gethostname_malloc();
if (!hn) {
*errnop = ENOMEM;
hn = gethostname_malloc();
if (!hn) {
*errnop = ENOMEM;
@@
-451,7
+497,11
@@
found:
return NSS_STATUS_TRYAGAIN;
}
return NSS_STATUS_TRYAGAIN;
}
- canonical = hn;
+ if (!canonical)
+ canonical = hn;
+
+ if (!additional && additional_from_hostname)
+ additional = hn;
}
return fill_in_hostent(
}
return fill_in_hostent(
@@
-464,7
+514,6
@@
found:
errnop, h_errnop,
ttlp,
NULL);
errnop, h_errnop,
ttlp,
NULL);
-
}
NSS_GETHOSTBYNAME_FALLBACKS(myhostname);
}
NSS_GETHOSTBYNAME_FALLBACKS(myhostname);