nss_files: Refactor gethostbyname3 multi case into separate function

This is in preparation of further cleanup work.
This commit is contained in:
Florian Weimer 2017-10-10 11:50:41 +02:00
parent a8dce6197a
commit 8ed70de2fa
2 changed files with 208 additions and 193 deletions

View File

@ -1,3 +1,9 @@
2017-10-10 Florian Weimer <fweimer@redhat.com>
* nss/nss_files/files-hosts.c (gethostbyname3_multi): New
function.
(_nss_files_gethostbyname3_r): Call it.
2017-10-09 Joseph Myers <joseph@codesourcery.com>
* sysdeps/generic/math-type-macros.h [!declare_mgen_alias]: Give

View File

@ -115,34 +115,10 @@ DB_LOOKUP (hostbyaddr, ,,,
}, const void *addr, socklen_t len, int af)
#undef EXTRA_ARGS_VALUE
enum nss_status
_nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result,
char *buffer, size_t buflen, int *errnop,
int *herrnop, int32_t *ttlp, char **canonp)
{
FILE *stream = NULL;
uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct hostent_data);
buffer += pad;
buflen = buflen > pad ? buflen - pad : 0;
/* Open file. */
enum nss_status status = internal_setent (&stream);
if (status == NSS_STATUS_SUCCESS)
{
/* XXX Is using _res to determine whether we want to convert IPv4
addresses to IPv6 addresses really the right thing to do? */
int flags = (res_use_inet6 () ? AI_V4MAPPED : 0);
while ((status = internal_getent (stream, result, buffer, buflen, errnop,
herrnop, af, flags))
== NSS_STATUS_SUCCESS)
{
LOOKUP_NAME_CASE (h_name, h_aliases)
}
if (status == NSS_STATUS_SUCCESS
&& _res_hconf.flags & HCONF_FLAG_MULTI)
static enum nss_status
gethostbyname3_multi (FILE * stream, const char *name, int af,
struct hostent *result, char *buffer, size_t buflen,
int *errnop, int *herrnop, int flags)
{
/* We have to get all host entries from the file. */
size_t tmp_buflen = MIN (buflen, 4096);
@ -154,6 +130,7 @@ _nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result,
int naliases = 0;
char *bufferend;
bool tmp_buffer_malloced = false;
enum nss_status status;
while (result->h_aliases[naliases] != NULL)
++naliases;
@ -335,8 +312,40 @@ _nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result,
out:
if (tmp_buffer_malloced)
free (tmp_buffer);
return status;
}
enum nss_status
_nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result,
char *buffer, size_t buflen, int *errnop,
int *herrnop, int32_t *ttlp, char **canonp)
{
FILE *stream = NULL;
uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct hostent_data);
buffer += pad;
buflen = buflen > pad ? buflen - pad : 0;
/* Open file. */
enum nss_status status = internal_setent (&stream);
if (status == NSS_STATUS_SUCCESS)
{
/* XXX Is using _res to determine whether we want to convert IPv4
addresses to IPv6 addresses really the right thing to do? */
int flags = (res_use_inet6 () ? AI_V4MAPPED : 0);
while ((status = internal_getent (stream, result, buffer, buflen, errnop,
herrnop, af, flags))
== NSS_STATUS_SUCCESS)
{
LOOKUP_NAME_CASE (h_name, h_aliases)
}
if (status == NSS_STATUS_SUCCESS
&& _res_hconf.flags & HCONF_FLAG_MULTI)
status = gethostbyname3_multi
(stream, name, af, result, buffer, buflen, errnop, herrnop, flags);
internal_endent (&stream);
}