glibc/nss/nss_files/files-hosts.c
Roland McGrath 96bda0ea44 * nss/nss_files/files-network.c: Pass empty for new DB_LOOKUP args.
(DATABASE): Define this instead of DATAFILE.
	* nss/nss_files/files-hosts.c: Likewise.
	(hostbyname): Use LOOKUP_NAME macro.

	* nss/nss_db/db-XXX.c: New file.
	* nss/Makefile (services): Add db.
	(libnss_db-inhibit-o): New variable.
	(libnss_db-routines): New variable.
	(distribute): Append db-XXX.c.
	(libnss_db.so): Depend on libdb.so and libnss_files.so.
	($(libnss_db-routines:%=$(objpfx)%.c)): New static pattern rule.

	* nss/nss_files/files-XXX.c (DB_LOOKUP): Add KEYSIZE and KEYPATTERN
	args, ignored.
	(DATAFILE): New macro.
	* nss/nss_files/files-parse.c (GENERIC): If undefined, define to
	"files-XXX.c".
	* nss/nss_files/files-rpc.c: Include GENERIC instead of "files-XXX.c".
	Pass db key args to DB_LOOKUP.
	(DATAFILE): Macro removed.
	(DATABASE): New macro replaces it, lacks "/etc/" prefix.
	* nss/nss_files/files-service.c: Likewise.
	* nss/nss_files/files-pwd.c: Likewise.
	* nss/nss_files/files-proto.c: Likewise.
	* nss/nss_files/files-grp.c: Likewise.
	* nss/nss_files/files-ethers.c: Likewise.

	* elf/linux-compat.c: File removed.
	* elf/Makefile (distribute): Remove linux-compat.c.
	(ld-linux.so.1): Remove target and associated variables.

	* sunrpc/xdr.c: Remove malloc decl.
	* sunrpc/portmap.c: Likewise.

	* sunrpc/svc_tcp.c (abort): Don't declare.  Instead define as macro
	casting abort to fn returning bool_t.

	* nss/nss_files/files-parse.c [EXTERN_PARSER]: Do an extern decl of
	the parser function.
	[EXTERN_PARSER] (LINE_PARSER): Define to empty.
	* nss/nss_files/files-pwd.c (EXTERN_PARSER): Define it.
	* nss/nss_files/files-grp.c: Likewise.

	* Makeconfig (BUILD_CC): If undefined, define to $(CC).

	* sunrpc/rpc/types.h: Include stdlib.h instead of declaring malloc.

	* Makeconfig (built-program-cmd): Use $(rtld-installed-name) in place
	of ld.so so lookups for that soname find it.

	* nss/Makefile (libnss_dns.so): Depend on libresolv.so.
	(resobjdir, LDLIBS-nss_dns.so): Variables removed.
1996-07-02 19:35:40 +00:00

106 lines
2.9 KiB
C

/* Hosts file parser in nss_files module.
Copyright (C) 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <netdb.h>
#include <resolv.h>
/* Get implementation for some internal functions. */
#include "../resolv/mapv4v6addr.h"
#include "../resolv/mapv4v6hostent.h"
#define ENTNAME hostent
#define DATABASE "hosts"
#define ENTDATA hostent_data
struct hostent_data
{
unsigned char host_addr[16]; /* IPv4 or IPv6 address. */
char *h_addr_ptrs[2]; /* Points to that and null terminator. */
};
#define TRAILING_LIST_MEMBER h_aliases
#define TRAILING_LIST_SEPARATOR_P isspace
#include "files-parse.c"
LINE_PARSER
("#",
{
char *addr;
STRING_FIELD (addr, isspace, 1);
/* Parse address. */
if ((_res.options & RES_USE_INET6)
&& inet_pton (AF_INET6, addr, entdata->host_addr) > 0)
{
result->h_addrtype = AF_INET6;
result->h_length = IN6ADDRSZ;
}
else if (inet_pton (AF_INET, addr, entdata->host_addr) > 0)
{
if (_res.options & RES_USE_INET6)
{
map_v4v6_address ((char *) entdata->host_addr,
(char *) entdata->host_addr);
result->h_addrtype = AF_INET6;
result->h_length = IN6ADDRSZ;
}
else
{
result->h_addrtype = AF_INET;
result->h_length = INADDRSZ;
}
}
else
/* Illegal address: ignore line. */
return 0;
/* Store a pointer to the address in the expected form. */
entdata->h_addr_ptrs[0] = entdata->host_addr;
entdata->h_addr_ptrs[1] = NULL;
result->h_addr_list = entdata->h_addr_ptrs;
/* If we need the host entry in IPv6 form change it now. */
if (_res.options & RES_USE_INET6)
{
char *bufptr = data->linebuffer;
int buflen = (char *) data + datalen - bufptr;
map_v4v6_hostent (result, &bufptr, &buflen);
}
STRING_FIELD (result->h_name, isspace, 1);
})
#include "files-XXX.c"
DB_LOOKUP (hostbyname, ,,
LOOKUP_NAME (h_name, h_aliases),
const char *name)
DB_LOOKUP (hostbyaddr, ,,
{
if (result->h_addrtype == type && result->h_length == len &&
! memcmp (addr, result->h_addr_list[0], len))
break;
}, const char *addr, int len, int type)