1999-08-29  Thorsten Kukuk  <kukuk@suse.de>

	* nis/Versions: Add _nss_*_getipnodebyname_r.
	* nis/nss_nis/nis-hosts.c: Add _nss_nis_getipnodebyname_r.
	* nis/nss_nisplus/nisplus-hosts.c: Add _nss_nisplus_getipnodebyname_r.
	* nss/Versions: Add _nss_files_getipnodebyname_r.
This commit is contained in:
Ulrich Drepper 1999-08-30 19:23:15 +00:00
parent 74bced63c5
commit 1e275b9e9b
7 changed files with 144 additions and 67 deletions

View File

@ -1,3 +1,10 @@
1999-08-29 Thorsten Kukuk <kukuk@suse.de>
* nis/Versions: Add _nss_*_getipnodebyname_r.
* nis/nss_nis/nis-hosts.c: Add _nss_nis_getipnodebyname_r.
* nis/nss_nisplus/nisplus-hosts.c: Add _nss_nisplus_getipnodebyname_r.
* nss/Versions: Add _nss_files_getipnodebyname_r.
1999-08-28 H.J. Lu <hjl@gnu.org> 1999-08-28 H.J. Lu <hjl@gnu.org>
* nscd/nscd_getgr_r.c (nscd_getgr_r): Don't count the alloca'ed * nscd/nscd_getgr_r.c (nscd_getgr_r): Don't count the alloca'ed

View File

@ -91,6 +91,9 @@ libnss_nis {
_nss_nis_setnetgrent; _nss_nis_setprotoent; _nss_nis_setpwent; _nss_nis_setnetgrent; _nss_nis_setprotoent; _nss_nis_setpwent;
_nss_nis_setrpcent; _nss_nis_setservent; _nss_nis_setspent; _nss_nis_setrpcent; _nss_nis_setservent; _nss_nis_setspent;
} }
GLIBC_2.2 {
_nss_nis_getipnodebyname_r;
}
} }
libnss_nisplus { libnss_nisplus {
@ -122,4 +125,7 @@ libnss_nisplus {
_nss_nisplus_setpwent; _nss_nisplus_setrpcent; _nss_nisplus_setservent; _nss_nisplus_setpwent; _nss_nisplus_setrpcent; _nss_nisplus_setservent;
_nss_nisplus_setspent; _nss_nisplus_setspent;
} }
GLIBC_2.2 {
_nss_nisplus_getipnodebyname_r;
}
} }

View File

@ -1,6 +1,6 @@
/* Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. /* Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996. Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
The GNU C Library is free software; you can redistribute it and/or 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 modify it under the terms of the GNU Library General Public License as
@ -37,6 +37,9 @@
#define DATABASE "hosts" #define DATABASE "hosts"
#define NEED_H_ERRNO #define NEED_H_ERRNO
#define EXTRA_ARGS , af, flags
#define EXTRA_ARGS_DECL , int af, int flags
#define ENTDATA hostent_data #define ENTDATA hostent_data
struct hostent_data struct hostent_data
{ {
@ -55,30 +58,30 @@ LINE_PARSER
STRING_FIELD (addr, isspace, 1); STRING_FIELD (addr, isspace, 1);
/* Parse address. */ /* Parse address. */
if (inet_pton (AF_INET6, addr, entdata->host_addr) > 0) if (af == AF_INET && inet_pton (AF_INET, addr, entdata->host_addr) > 0)
{
if (flags & AI_V4MAPPED)
{
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 if (af == AF_INET6
&& inet_pton (AF_INET6, addr, entdata->host_addr) > 0)
{ {
result->h_addrtype = AF_INET6; result->h_addrtype = AF_INET6;
result->h_length = IN6ADDRSZ; result->h_length = IN6ADDRSZ;
} }
else else
if (inet_pton (AF_INET, addr, entdata->host_addr) > 0) /* Illegal address: ignore line. */
{ return 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. */ /* Store a pointer to the address in the expected form. */
entdata->h_addr_ptrs[0] = entdata->host_addr; entdata->h_addr_ptrs[0] = entdata->host_addr;
@ -86,8 +89,8 @@ LINE_PARSER
result->h_addr_list = entdata->h_addr_ptrs; result->h_addr_list = entdata->h_addr_ptrs;
STRING_FIELD (result->h_name, isspace, 1); STRING_FIELD (result->h_name, isspace, 1);
} })
)
__libc_lock_define_initialized (static, lock) __libc_lock_define_initialized (static, lock)
@ -131,9 +134,11 @@ _nss_nis_endhostent (void)
return NSS_STATUS_SUCCESS; return NSS_STATUS_SUCCESS;
} }
/* The calling function always need to get a lock first. */
static enum nss_status static enum nss_status
internal_nis_gethostent_r (struct hostent *host, char *buffer, internal_nis_gethostent_r (struct hostent *host, char *buffer,
size_t buflen, int *errnop, int *h_errnop) size_t buflen, int *errnop, int *h_errnop,
int af, int flags)
{ {
char *domain; char *domain;
char *result; char *result;
@ -200,7 +205,7 @@ internal_nis_gethostent_r (struct hostent *host, char *buffer,
++p; ++p;
free (result); free (result);
parse_res = parse_line (p, host, data, buflen, errnop); parse_res = parse_line (p, host, data, buflen, errnop, af, flags);
if (parse_res == -1) if (parse_res == -1)
{ {
free (outkey); free (outkey);
@ -219,25 +224,27 @@ internal_nis_gethostent_r (struct hostent *host, char *buffer,
return NSS_STATUS_SUCCESS; return NSS_STATUS_SUCCESS;
} }
int enum nss_status
_nss_nis_gethostent_r (struct hostent *host, char *buffer, size_t buflen, _nss_nis_gethostent_r (struct hostent *host, char *buffer, size_t buflen,
int *errnop, int *h_errnop) int *errnop, int *h_errnop)
{ {
int status; enum nss_status status;
__libc_lock_lock (lock); __libc_lock_lock (lock);
status = internal_nis_gethostent_r (host, buffer, buflen, errnop, h_errnop); status = internal_nis_gethostent_r (host, buffer, buflen, errnop, h_errnop,
((_res.options & RES_USE_INET6) ? AF_INET6 : AF_INET),
((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0 ));
__libc_lock_unlock (lock); __libc_lock_unlock (lock);
return status; return status;
} }
enum nss_status static enum nss_status
_nss_nis_gethostbyname2_r (const char *name, int af, struct hostent *host, internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
char *buffer, size_t buflen, int *errnop, char *buffer, size_t buflen, int *errnop,
int *h_errnop) int *h_errnop, int flags)
{ {
enum nss_status retval; enum nss_status retval;
char *domain, *result, *p; char *domain, *result, *p;
@ -302,7 +309,7 @@ _nss_nis_gethostbyname2_r (const char *name, int af, struct hostent *host,
++p; ++p;
free (result); free (result);
parse_res = parse_line (p, host, data, buflen, errnop); parse_res = parse_line (p, host, data, buflen, errnop, af, flags);
if (parse_res < 1 || host->h_addrtype != af) if (parse_res < 1 || host->h_addrtype != af)
{ {
@ -322,6 +329,16 @@ _nss_nis_gethostbyname2_r (const char *name, int af, struct hostent *host,
return NSS_STATUS_SUCCESS; return NSS_STATUS_SUCCESS;
} }
enum nss_status
_nss_nis_gethostbyname2_r (const char *name, int af, struct hostent *host,
char *buffer, size_t buflen, int *errnop,
int *h_errnop)
{
return internal_gethostbyname2_r (name, af, host, buffer, buflen, errnop,
h_errnop,
((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0));
}
enum nss_status enum nss_status
_nss_nis_gethostbyname_r (const char *name, struct hostent *host, char *buffer, _nss_nis_gethostbyname_r (const char *name, struct hostent *host, char *buffer,
size_t buflen, int *errnop, int *h_errnop) size_t buflen, int *errnop, int *h_errnop)
@ -330,18 +347,18 @@ _nss_nis_gethostbyname_r (const char *name, struct hostent *host, char *buffer,
{ {
enum nss_status status; enum nss_status status;
status = _nss_nis_gethostbyname2_r (name, AF_INET6, host, buffer, buflen, status = internal_gethostbyname2_r (name, AF_INET6, host, buffer, buflen,
errnop, h_errnop); errnop, h_errnop, AI_V4MAPPED);
if (status == NSS_STATUS_SUCCESS) if (status == NSS_STATUS_SUCCESS)
return status; return status;
} }
return _nss_nis_gethostbyname2_r (name, AF_INET, host, buffer, buflen, return internal_gethostbyname2_r (name, AF_INET, host, buffer, buflen,
errnop, h_errnop); errnop, h_errnop, 0);
} }
enum nss_status enum nss_status
_nss_nis_gethostbyaddr_r (char *addr, size_t addrlen, int type, _nss_nis_gethostbyaddr_r (char *addr, size_t addrlen, int af,
struct hostent *host, char *buffer, size_t buflen, struct hostent *host, char *buffer, size_t buflen,
int *errnop, int *h_errnop) int *errnop, int *h_errnop)
{ {
@ -393,7 +410,8 @@ _nss_nis_gethostbyaddr_r (char *addr, size_t addrlen, int type,
++p; ++p;
free (result); free (result);
parse_res = parse_line (p, host, data, buflen, errnop); parse_res = parse_line (p, host, data, buflen, errnop, af,
((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0));
if (parse_res < 1) if (parse_res < 1)
{ {
if (parse_res == -1) if (parse_res == -1)
@ -411,3 +429,12 @@ _nss_nis_gethostbyaddr_r (char *addr, size_t addrlen, int type,
*h_errnop = NETDB_SUCCESS; *h_errnop = NETDB_SUCCESS;
return NSS_STATUS_SUCCESS; return NSS_STATUS_SUCCESS;
} }
enum nss_status
_nss_nis_getipnodebyname_r (const char *name, int af, int flags,
struct hostent *result, char *buffer,
size_t buflen, int *errnop, int *herrnop)
{
return internal_gethostbyname2_r (name, af, result, buffer, buflen,
errnop, herrnop, flags);
}

View File

@ -1,6 +1,6 @@
/* Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc. /* Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997. Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
The GNU C Library is free software; you can redistribute it and/or 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 modify it under the terms of the GNU Library General Public License as
@ -46,7 +46,8 @@ static u_long tablename_len = 0;
static int static int
_nss_nisplus_parse_hostent (nis_result *result, int af, struct hostent *host, _nss_nisplus_parse_hostent (nis_result *result, int af, struct hostent *host,
char *buffer, size_t buflen, int *errnop) char *buffer, size_t buflen, int *errnop,
int flags)
{ {
unsigned int i; unsigned int i;
char *first_unused = buffer; char *first_unused = buffer;
@ -71,16 +72,11 @@ _nss_nisplus_parse_hostent (nis_result *result, int af, struct hostent *host,
} }
data = first_unused; data = first_unused;
if (inet_pton (af, NISENTRYVAL (0, 2, result), data) < 1)
/* Illegal address: ignore line. */
return 0;
host->h_addrtype = af; /* Parse address. */
if (af == AF_INET6) if (af == AF_INET && inet_pton (af, NISENTRYVAL (0, 2, result), data) > 0)
host->h_length = IN6ADDRSZ;
else
{ {
if (_res.options & RES_USE_INET6) if (flags & AI_V4MAPPED)
{ {
map_v4v6_address (data, data); map_v4v6_address (data, data);
host->h_addrtype = AF_INET6; host->h_addrtype = AF_INET6;
@ -92,6 +88,16 @@ _nss_nisplus_parse_hostent (nis_result *result, int af, struct hostent *host,
host->h_length = INADDRSZ; host->h_length = INADDRSZ;
} }
} }
else if (af == AF_INET6
&& inet_pton (AF_INET6, NISENTRYVAL (0, 2, result), data) > 0)
{
host->h_addrtype = AF_INET6;
host->h_length = IN6ADDRSZ;
}
else
/* Illegal address: ignore line. */
return 0;
first_unused+=host->h_length; first_unused+=host->h_length;
room_left-=host->h_length; room_left-=host->h_length;
@ -281,11 +287,13 @@ internal_nisplus_gethostent_r (struct hostent *host, char *buffer,
} }
} }
parse_res = _nss_nisplus_parse_hostent (result, AF_INET6, host, buffer, if (_res.options & RES_USE_INET6)
buflen, errnop); parse_res = _nss_nisplus_parse_hostent (result, AF_INET6, host, buffer,
if (parse_res < 1 && *errnop != ERANGE) buflen, errnop, AI_V4MAPPED);
parse_res = _nss_nisplus_parse_hostent (result, AF_INET, host, else
buffer, buflen, errnop); parse_res = _nss_nisplus_parse_hostent (result, AF_INET, host, buffer,
buflen, errnop, 0);
if (parse_res == -1) if (parse_res == -1)
{ {
nis_freeresult (result); nis_freeresult (result);
@ -318,10 +326,10 @@ _nss_nisplus_gethostent_r (struct hostent *result, char *buffer,
return status; return status;
} }
enum nss_status static enum nss_status
_nss_nisplus_gethostbyname2_r (const char *name, int af, struct hostent *host, internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
char *buffer, size_t buflen, int *errnop, char *buffer, size_t buflen, int *errnop,
int *herrnop) int *herrnop, int flags)
{ {
int parse_res, retval; int parse_res, retval;
@ -380,7 +388,7 @@ _nss_nisplus_gethostbyname2_r (const char *name, int af, struct hostent *host,
} }
parse_res = _nss_nisplus_parse_hostent (result, af, host, buffer, parse_res = _nss_nisplus_parse_hostent (result, af, host, buffer,
buflen, errnop); buflen, errnop, flags);
nis_freeresult (result); nis_freeresult (result);
@ -398,6 +406,25 @@ _nss_nisplus_gethostbyname2_r (const char *name, int af, struct hostent *host,
} }
} }
enum nss_status
_nss_nisplus_gethostbyname2_r (const char *name, int af, struct hostent *host,
char *buffer, size_t buflen, int *errnop,
int *herrnop)
{
return internal_gethostbyname2_r (name, af, host, buffer, buflen, errnop,
herrnop,
((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0));
}
enum nss_status
_nss_nisplus_getipnodebyname_r (const char *name, int af, int flags,
struct hostent *result, char *buffer,
size_t buflen, int *errnop, int *herrnop)
{
return internal_gethostbyname2_r (name, af, result, buffer, buflen,
errnop, herrnop, flags);
}
enum nss_status enum nss_status
_nss_nisplus_gethostbyname_r (const char *name, struct hostent *host, _nss_nisplus_gethostbyname_r (const char *name, struct hostent *host,
char *buffer, size_t buflen, int *errnop, char *buffer, size_t buflen, int *errnop,
@ -407,18 +434,19 @@ _nss_nisplus_gethostbyname_r (const char *name, struct hostent *host,
{ {
enum nss_status status; enum nss_status status;
status = _nss_nisplus_gethostbyname2_r (name, AF_INET6, host, buffer, status = internal_gethostbyname2_r (name, AF_INET6, host, buffer,
buflen, errnop, h_errnop); buflen, errnop, h_errnop,
AI_V4MAPPED);
if (status == NSS_STATUS_SUCCESS) if (status == NSS_STATUS_SUCCESS)
return status; return status;
} }
return _nss_nisplus_gethostbyname2_r (name, AF_INET, host, buffer, return internal_gethostbyname2_r (name, AF_INET, host, buffer,
buflen, errnop, h_errnop); buflen, errnop, h_errnop, 0);
} }
enum nss_status enum nss_status
_nss_nisplus_gethostbyaddr_r (const char *addr, size_t addrlen, int type, _nss_nisplus_gethostbyaddr_r (const char *addr, size_t addrlen, int af,
struct hostent *host, char *buffer, struct hostent *host, char *buffer,
size_t buflen, int *errnop, int *herrnop) size_t buflen, int *errnop, int *herrnop)
{ {
@ -454,8 +482,9 @@ _nss_nisplus_gethostbyaddr_r (const char *addr, size_t addrlen, int type,
return retval; return retval;
} }
parse_res = _nss_nisplus_parse_hostent (result, type, host, parse_res = _nss_nisplus_parse_hostent (result, af, host,
buffer, buflen, errnop); buffer, buflen, errnop,
((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0));
nis_freeresult (result); nis_freeresult (result);
if (parse_res > 0) if (parse_res > 0)

View File

@ -102,4 +102,7 @@ libnss_files {
_nss_files_getpublickey; _nss_files_getpublickey;
_nss_files_getsecretkey; _nss_files_getsecretkey;
} }
GLIBC_2.2 {
_nss_files_getipnodebyname_r;
}
} }

View File

@ -1,6 +1,7 @@
#include <error.h> #include <error.h>
#include <sys/types.h> #include <sys/types.h>
#include <regex.h> #include <regex.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
int int

View File

@ -49,6 +49,8 @@ static const struct test_times tests[] =
{ NULL, 0, 0 } { NULL, 0, 0 }
}; };
/* This string will be used for `putenv' calls. */
char envstring[100];
void void
print_tzvars (void) print_tzvars (void)
@ -123,7 +125,8 @@ main (int argc, char ** argv)
{ {
struct tm tmBuf = {0, 0, 0, 10, 3, 98, 0, 0, -1}; struct tm tmBuf = {0, 0, 0, 10, 3, 98, 0, 0, -1};
char buf[200]; char buf[200];
putenv ("TZ=Europe/London"); strcpy (envstring, "TZ=Europe/London");
putenv (envstring);
t = mktime (&tmBuf); t = mktime (&tmBuf);
snprintf (buf, sizeof (buf), "TZ=%s %ld %d %d %d %d %d %d %d %d %d", snprintf (buf, sizeof (buf), "TZ=%s %ld %d %d %d %d %d %d %d %d %d",
getenv ("TZ"), t, getenv ("TZ"), t,
@ -145,7 +148,8 @@ main (int argc, char ** argv)
{ {
struct tm tmBuf = {0, 0, 0, 10, 3, 98, 0, 0, -1}; struct tm tmBuf = {0, 0, 0, 10, 3, 98, 0, 0, -1};
char buf[200]; char buf[200];
putenv ("TZ=GMT"); strcpy (envstring, "TZ=GMT");
/* No putenv call needed! */
t = mktime (&tmBuf); t = mktime (&tmBuf);
snprintf (buf, sizeof (buf), "TZ=%s %ld %d %d %d %d %d %d %d %d %d", snprintf (buf, sizeof (buf), "TZ=%s %ld %d %d %d %d %d %d %d %d %d",
getenv ("TZ"), t, getenv ("TZ"), t,