2015-01-02 17:28:19 +01:00
|
|
|
|
/* Copyright (C) 2000-2015 Free Software Foundation, Inc.
|
2000-12-08 23:39:54 +01:00
|
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 06:58:11 +02:00
|
|
|
|
modify it 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.
|
2000-12-08 23:39:54 +01:00
|
|
|
|
|
|
|
|
|
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
|
2001-07-06 06:58:11 +02:00
|
|
|
|
Lesser General Public License for more details.
|
2000-12-08 23:39:54 +01:00
|
|
|
|
|
2001-07-06 06:58:11 +02:00
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-10 00:18:22 +01:00
|
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
2000-12-08 23:39:54 +01:00
|
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <netdb.h>
|
|
|
|
|
#include "nsswitch.h"
|
|
|
|
|
|
|
|
|
|
/* Set up NIP to run through the services. If ALL is zero, use NIP's
|
|
|
|
|
current location if it's not nil. Return nonzero if there are no
|
|
|
|
|
services (left). */
|
|
|
|
|
static int
|
|
|
|
|
setup (const char *func_name, db_lookup_function lookup_fct,
|
|
|
|
|
void **fctp, service_user **nip, service_user **startp, int all)
|
|
|
|
|
{
|
|
|
|
|
int no_more;
|
|
|
|
|
if (*startp == NULL)
|
|
|
|
|
{
|
2007-10-30 01:48:09 +01:00
|
|
|
|
no_more = lookup_fct (nip, func_name, NULL, fctp);
|
2000-12-08 23:39:54 +01:00
|
|
|
|
*startp = no_more ? (service_user *) -1l : *nip;
|
|
|
|
|
}
|
|
|
|
|
else if (*startp == (service_user *) -1l)
|
|
|
|
|
/* No services at all. */
|
|
|
|
|
return 1;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (all || !*nip)
|
|
|
|
|
/* Reset to the beginning of the service list. */
|
|
|
|
|
*nip = *startp;
|
|
|
|
|
/* Look up the first function. */
|
2007-10-30 01:48:09 +01:00
|
|
|
|
no_more = __nss_lookup (nip, func_name, NULL, fctp);
|
2000-12-08 23:39:54 +01:00
|
|
|
|
}
|
|
|
|
|
return no_more;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
__nss_setent (const char *func_name, db_lookup_function lookup_fct,
|
|
|
|
|
service_user **nip, service_user **startp,
|
|
|
|
|
service_user **last_nip, int stayopen, int *stayopen_tmp,
|
|
|
|
|
int res)
|
|
|
|
|
{
|
2002-11-10 12:06:36 +01:00
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
setent_function f;
|
|
|
|
|
void *ptr;
|
|
|
|
|
} fct;
|
2000-12-08 23:39:54 +01:00
|
|
|
|
int no_more;
|
|
|
|
|
|
Update.
2004-08-04 Jakub Jelinek <jakub@redhat.com>
* hesiod/hesiod.c (__hesiod_res_get): Use calloc instead of malloc +
memset.
(__hesiod_res_set): Free nsaddrs.
* include/resolv.h (__res_maybe_init): Add prototype.
* resolv/resolv.h (struct __res_state): Add _u._ext.initstamp field.
* resolv/Versions (libc): Add __res_maybe_init@@GLIBC_PRIVATE.
* resolv/res_libc.c (__res_initstamp, lock): New variables.
(res_init): Increase __res_initstamp.
(__res_maybe_init): New function.
* resolv/res_init.c (__res_vinit): Initialize _u._ext.initstamp.
* hesiod/hesiod.c (__hesiod_res_get): Use __res_maybe_init instead
of RES_INIT check and {res_ninit,__res_ninit,res_init} call.
* sysdeps/posix/getaddrinfo.c (gaih_inet): Likewise.
* resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname2_r,
_nss_dns_gethostbyaddr_r): Likewise.
* resolv/nss_dns/dns-network.c (_nss_dns_getnetbyname_r,
_nss_dns_getnetbyaddr_r): Likewise.
* resolv/gethnamaddr.c (gethostbyname, gethostbyname2,
gethostbyaddr): Likewise.
* resolv/res_data.c (fp_nquery, res_mkquery, res_mkupdate,
res_isourserver, res_sendsigned, res_update, res_search,
res_querydomain): Likewise.
* nss/getXXbyYY_r.c (INTERNAL (REENTRANT_NAME)): Likewise.
* nss/digits_dots.c (__nss_hostname_digits_dots): Likewise.
* nss/getnssent_r.c (__nss_setent, __nss_endent, __nss_getent_r):
Likewise.
* sysdeps/posix/getaddrinfo.c (gaih_inet): Set ai_family for
V4-mapped IPv6 addresses and req->ai_family==AF_INET.
Reported by A. Guru <a.guru@sympatico.ca>.
* po/pl.po: Likewise.
characters than necessary.
2004-08-06 01:32:24 +02:00
|
|
|
|
if (res && __res_maybe_init (&_res, 0) == -1)
|
2000-12-08 23:39:54 +01:00
|
|
|
|
{
|
|
|
|
|
__set_h_errno (NETDB_INTERNAL);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Cycle through the services and run their `setXXent' functions until
|
|
|
|
|
we find an available service. */
|
2002-11-10 12:06:36 +01:00
|
|
|
|
no_more = setup (func_name, lookup_fct, &fct.ptr, nip,
|
2000-12-08 23:39:54 +01:00
|
|
|
|
startp, 1);
|
|
|
|
|
while (! no_more)
|
|
|
|
|
{
|
|
|
|
|
int is_last_nip = *nip == *last_nip;
|
|
|
|
|
enum nss_status status;
|
2002-08-31 02:02:18 +02:00
|
|
|
|
|
2000-12-08 23:39:54 +01:00
|
|
|
|
if (stayopen_tmp)
|
2002-11-10 12:06:36 +01:00
|
|
|
|
status = DL_CALL_FCT (fct.f, (*stayopen_tmp));
|
2000-12-08 23:39:54 +01:00
|
|
|
|
else
|
2002-11-10 12:06:36 +01:00
|
|
|
|
status = DL_CALL_FCT (fct.f, (0));
|
2000-12-08 23:39:54 +01:00
|
|
|
|
|
2007-10-30 01:48:09 +01:00
|
|
|
|
no_more = __nss_next2 (nip, func_name, NULL, &fct.ptr, status, 0);
|
2000-12-08 23:39:54 +01:00
|
|
|
|
if (is_last_nip)
|
|
|
|
|
*last_nip = *nip;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stayopen_tmp)
|
|
|
|
|
*stayopen_tmp = stayopen;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
__nss_endent (const char *func_name, db_lookup_function lookup_fct,
|
|
|
|
|
service_user **nip, service_user **startp,
|
|
|
|
|
service_user **last_nip, int res)
|
|
|
|
|
{
|
2002-11-10 12:06:36 +01:00
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
endent_function f;
|
|
|
|
|
void *ptr;
|
|
|
|
|
} fct;
|
2000-12-08 23:39:54 +01:00
|
|
|
|
int no_more;
|
|
|
|
|
|
Update.
2004-08-04 Jakub Jelinek <jakub@redhat.com>
* hesiod/hesiod.c (__hesiod_res_get): Use calloc instead of malloc +
memset.
(__hesiod_res_set): Free nsaddrs.
* include/resolv.h (__res_maybe_init): Add prototype.
* resolv/resolv.h (struct __res_state): Add _u._ext.initstamp field.
* resolv/Versions (libc): Add __res_maybe_init@@GLIBC_PRIVATE.
* resolv/res_libc.c (__res_initstamp, lock): New variables.
(res_init): Increase __res_initstamp.
(__res_maybe_init): New function.
* resolv/res_init.c (__res_vinit): Initialize _u._ext.initstamp.
* hesiod/hesiod.c (__hesiod_res_get): Use __res_maybe_init instead
of RES_INIT check and {res_ninit,__res_ninit,res_init} call.
* sysdeps/posix/getaddrinfo.c (gaih_inet): Likewise.
* resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname2_r,
_nss_dns_gethostbyaddr_r): Likewise.
* resolv/nss_dns/dns-network.c (_nss_dns_getnetbyname_r,
_nss_dns_getnetbyaddr_r): Likewise.
* resolv/gethnamaddr.c (gethostbyname, gethostbyname2,
gethostbyaddr): Likewise.
* resolv/res_data.c (fp_nquery, res_mkquery, res_mkupdate,
res_isourserver, res_sendsigned, res_update, res_search,
res_querydomain): Likewise.
* nss/getXXbyYY_r.c (INTERNAL (REENTRANT_NAME)): Likewise.
* nss/digits_dots.c (__nss_hostname_digits_dots): Likewise.
* nss/getnssent_r.c (__nss_setent, __nss_endent, __nss_getent_r):
Likewise.
* sysdeps/posix/getaddrinfo.c (gaih_inet): Set ai_family for
V4-mapped IPv6 addresses and req->ai_family==AF_INET.
Reported by A. Guru <a.guru@sympatico.ca>.
* po/pl.po: Likewise.
characters than necessary.
2004-08-06 01:32:24 +02:00
|
|
|
|
if (res && __res_maybe_init (&_res, 0) == -1)
|
2000-12-08 23:39:54 +01:00
|
|
|
|
{
|
|
|
|
|
__set_h_errno (NETDB_INTERNAL);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Cycle through all the services and run their endXXent functions. */
|
2002-11-10 12:06:36 +01:00
|
|
|
|
no_more = setup (func_name, lookup_fct, &fct.ptr, nip, startp, 1);
|
2000-12-08 23:39:54 +01:00
|
|
|
|
while (! no_more)
|
|
|
|
|
{
|
|
|
|
|
/* Ignore status, we force check in __NSS_NEXT. */
|
2002-11-10 12:06:36 +01:00
|
|
|
|
DL_CALL_FCT (fct.f, ());
|
2000-12-08 23:39:54 +01:00
|
|
|
|
|
|
|
|
|
if (*nip == *last_nip)
|
|
|
|
|
/* We have processed all services which were used. */
|
|
|
|
|
break;
|
|
|
|
|
|
2007-10-30 01:48:09 +01:00
|
|
|
|
no_more = __nss_next2 (nip, func_name, NULL, &fct.ptr, 0, 1);
|
2000-12-08 23:39:54 +01:00
|
|
|
|
}
|
|
|
|
|
*last_nip = *nip = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
__nss_getent_r (const char *getent_func_name,
|
|
|
|
|
const char *setent_func_name,
|
|
|
|
|
db_lookup_function lookup_fct,
|
|
|
|
|
service_user **nip, service_user **startp,
|
|
|
|
|
service_user **last_nip, int *stayopen_tmp, int res,
|
|
|
|
|
void *resbuf, char *buffer, size_t buflen,
|
|
|
|
|
void **result, int *h_errnop)
|
|
|
|
|
{
|
2002-11-10 12:06:36 +01:00
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
getent_function f;
|
|
|
|
|
void *ptr;
|
|
|
|
|
} fct;
|
2000-12-08 23:39:54 +01:00
|
|
|
|
int no_more;
|
|
|
|
|
enum nss_status status;
|
|
|
|
|
|
Update.
2004-08-04 Jakub Jelinek <jakub@redhat.com>
* hesiod/hesiod.c (__hesiod_res_get): Use calloc instead of malloc +
memset.
(__hesiod_res_set): Free nsaddrs.
* include/resolv.h (__res_maybe_init): Add prototype.
* resolv/resolv.h (struct __res_state): Add _u._ext.initstamp field.
* resolv/Versions (libc): Add __res_maybe_init@@GLIBC_PRIVATE.
* resolv/res_libc.c (__res_initstamp, lock): New variables.
(res_init): Increase __res_initstamp.
(__res_maybe_init): New function.
* resolv/res_init.c (__res_vinit): Initialize _u._ext.initstamp.
* hesiod/hesiod.c (__hesiod_res_get): Use __res_maybe_init instead
of RES_INIT check and {res_ninit,__res_ninit,res_init} call.
* sysdeps/posix/getaddrinfo.c (gaih_inet): Likewise.
* resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname2_r,
_nss_dns_gethostbyaddr_r): Likewise.
* resolv/nss_dns/dns-network.c (_nss_dns_getnetbyname_r,
_nss_dns_getnetbyaddr_r): Likewise.
* resolv/gethnamaddr.c (gethostbyname, gethostbyname2,
gethostbyaddr): Likewise.
* resolv/res_data.c (fp_nquery, res_mkquery, res_mkupdate,
res_isourserver, res_sendsigned, res_update, res_search,
res_querydomain): Likewise.
* nss/getXXbyYY_r.c (INTERNAL (REENTRANT_NAME)): Likewise.
* nss/digits_dots.c (__nss_hostname_digits_dots): Likewise.
* nss/getnssent_r.c (__nss_setent, __nss_endent, __nss_getent_r):
Likewise.
* sysdeps/posix/getaddrinfo.c (gaih_inet): Set ai_family for
V4-mapped IPv6 addresses and req->ai_family==AF_INET.
Reported by A. Guru <a.guru@sympatico.ca>.
* po/pl.po: Likewise.
characters than necessary.
2004-08-06 01:32:24 +02:00
|
|
|
|
if (res && __res_maybe_init (&_res, 0) == -1)
|
2000-12-08 23:39:54 +01:00
|
|
|
|
{
|
2002-08-31 02:02:18 +02:00
|
|
|
|
*h_errnop = NETDB_INTERNAL;
|
2000-12-08 23:39:54 +01:00
|
|
|
|
*result = NULL;
|
|
|
|
|
return errno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Initialize status to return if no more functions are found. */
|
|
|
|
|
status = NSS_STATUS_NOTFOUND;
|
|
|
|
|
|
|
|
|
|
/* Run through available functions, starting with the same function last
|
|
|
|
|
run. We will repeat each function as long as it succeeds, and then go
|
|
|
|
|
on to the next service action. */
|
2002-11-10 12:06:36 +01:00
|
|
|
|
no_more = setup (getent_func_name, lookup_fct, &fct.ptr, nip,
|
2000-12-08 23:39:54 +01:00
|
|
|
|
startp, 0);
|
|
|
|
|
while (! no_more)
|
|
|
|
|
{
|
|
|
|
|
int is_last_nip = *nip == *last_nip;
|
|
|
|
|
|
2002-11-10 12:06:36 +01:00
|
|
|
|
status = DL_CALL_FCT (fct.f,
|
|
|
|
|
(resbuf, buffer, buflen, &errno, &h_errno));
|
2000-12-08 23:39:54 +01:00
|
|
|
|
|
2011-04-23 03:34:32 +02:00
|
|
|
|
/* The status is NSS_STATUS_TRYAGAIN and errno is ERANGE the
|
2000-12-08 23:39:54 +01:00
|
|
|
|
provided buffer is too small. In this case we should give
|
|
|
|
|
the user the possibility to enlarge the buffer and we should
|
|
|
|
|
not simply go on with the next service (even if the TRYAGAIN
|
|
|
|
|
action tells us so). */
|
|
|
|
|
if (status == NSS_STATUS_TRYAGAIN
|
|
|
|
|
&& (h_errnop == NULL || *h_errnop == NETDB_INTERNAL)
|
|
|
|
|
&& errno == ERANGE)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
2007-10-30 01:48:09 +01:00
|
|
|
|
no_more = __nss_next2 (nip, getent_func_name, NULL, &fct.ptr,
|
|
|
|
|
status, 0);
|
2000-12-08 23:39:54 +01:00
|
|
|
|
|
|
|
|
|
if (is_last_nip)
|
|
|
|
|
*last_nip = *nip;
|
|
|
|
|
|
|
|
|
|
if (! no_more)
|
|
|
|
|
{
|
|
|
|
|
/* Call the `setXXent' function. This wasn't done before. */
|
2002-11-10 12:06:36 +01:00
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
setent_function f;
|
|
|
|
|
void *ptr;
|
|
|
|
|
} sfct;
|
2000-12-08 23:39:54 +01:00
|
|
|
|
|
2007-10-30 01:48:09 +01:00
|
|
|
|
no_more = __nss_lookup (nip, setent_func_name, NULL, &sfct.ptr);
|
2000-12-08 23:39:54 +01:00
|
|
|
|
|
|
|
|
|
if (! no_more)
|
|
|
|
|
{
|
|
|
|
|
if (stayopen_tmp)
|
2002-11-10 12:06:36 +01:00
|
|
|
|
status = DL_CALL_FCT (sfct.f, (*stayopen_tmp));
|
2000-12-08 23:39:54 +01:00
|
|
|
|
else
|
2002-11-10 12:06:36 +01:00
|
|
|
|
status = DL_CALL_FCT (sfct.f, (0));
|
2000-12-08 23:39:54 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
status = NSS_STATUS_NOTFOUND;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while (! no_more && status != NSS_STATUS_SUCCESS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*result = status == NSS_STATUS_SUCCESS ? resbuf : NULL;
|
2002-09-12 04:58:43 +02:00
|
|
|
|
return (status == NSS_STATUS_SUCCESS ? 0
|
|
|
|
|
: status != NSS_STATUS_TRYAGAIN ? ENOENT
|
|
|
|
|
/* h_errno functions only set errno if h_errno is NETDB_INTERNAL. */
|
|
|
|
|
: (h_errnop == NULL || *h_errnop == NETDB_INTERNAL) ? errno
|
|
|
|
|
: EAGAIN);
|
2000-12-08 23:39:54 +01:00
|
|
|
|
}
|