mirror of
https://sourceware.org/git/glibc.git
synced 2025-08-07 06:43:00 +03:00
Move 'hosts' routines from 'inet' into 'nss'
The gethostby* and gethostent* routines are entry points for nss functionality. This commit moves them from the 'inet' subdirectory to 'nss'. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
This commit is contained in:
24
nss/Makefile
24
nss/Makefile
@@ -125,6 +125,29 @@ CFLAGS-getsgnam.c += -fexceptions
|
||||
CFLAGS-getsgnam_r.c += -fexceptions
|
||||
endif
|
||||
|
||||
# hosts routines:
|
||||
routines += \
|
||||
gethstbyad \
|
||||
gethstbyad_r \
|
||||
gethstbynm \
|
||||
gethstbynm2 \
|
||||
gethstbynm2_r \
|
||||
gethstbynm_r \
|
||||
gethstent \
|
||||
gethstent_r \
|
||||
# routines
|
||||
|
||||
ifeq ($(have-thread-library),yes)
|
||||
CFLAGS-gethstbyad.c += -fexceptions
|
||||
CFLAGS-gethstbyad_r.c += -fexceptions
|
||||
CFLAGS-gethstbynm.c += -fexceptions
|
||||
CFLAGS-gethstbynm_r.c += -fexceptions
|
||||
CFLAGS-gethstbynm2.c += -fexceptions
|
||||
CFLAGS-gethstbynm2_r.c += -fexceptions
|
||||
CFLAGS-gethstent.c += -fexceptions
|
||||
CFLAGS-gethstent_r.c += -fexceptions
|
||||
endif
|
||||
|
||||
# pwd routines:
|
||||
routines += \
|
||||
fgetpwent \
|
||||
@@ -210,6 +233,7 @@ tests := \
|
||||
test-netdb \
|
||||
testgrp \
|
||||
tst-fgetsgent_r \
|
||||
tst-gethnm \
|
||||
tst-getpw \
|
||||
tst-gshadow \
|
||||
tst-nss-getpwent \
|
||||
|
@@ -21,6 +21,8 @@ libc {
|
||||
getaliasbyname; getaliasbyname_r; getaliasent; getaliasent_r;
|
||||
getgrent; getgrent_r; getgrgid; getgrgid_r; getgrnam; getgrnam_r;
|
||||
getgroups;
|
||||
gethostbyaddr; gethostbyaddr_r; gethostbyname; gethostbyname2;
|
||||
gethostbyname2_r; gethostbyname_r; gethostent; gethostent_r;
|
||||
getpw; getpwent; getpwent_r; getpwnam; getpwnam_r; getpwuid; getpwuid_r;
|
||||
getspent; getspent_r; getspnam; getspnam_r;
|
||||
|
||||
|
29
nss/gethstbyad.c
Normal file
29
nss/gethstbyad.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/* Copyright (C) 1996-2023 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 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.
|
||||
|
||||
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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <netdb.h>
|
||||
|
||||
|
||||
#define LOOKUP_TYPE struct hostent
|
||||
#define FUNCTION_NAME gethostbyaddr
|
||||
#define DATABASE_NAME hosts
|
||||
#define ADD_PARAMS const void *addr, socklen_t len, int type
|
||||
#define ADD_VARIABLES addr, len, type
|
||||
#define BUFLEN 1024
|
||||
#define NEED_H_ERRNO 1
|
||||
|
||||
#include "../nss/getXXbyYY.c"
|
50
nss/gethstbyad_r.c
Normal file
50
nss/gethstbyad_r.c
Normal file
@@ -0,0 +1,50 @@
|
||||
/* Copyright (C) 1996-2023 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 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.
|
||||
|
||||
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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <netdb.h>
|
||||
#include <string.h>
|
||||
#include <resolv/res_hconf.h>
|
||||
|
||||
#define LOOKUP_TYPE struct hostent
|
||||
#define FUNCTION_NAME gethostbyaddr
|
||||
#define DATABASE_NAME hosts
|
||||
#define ADD_PARAMS const void *addr, socklen_t len, int type
|
||||
#define ADD_VARIABLES addr, len, type
|
||||
#define NEED_H_ERRNO 1
|
||||
#define NEED__RES 1
|
||||
/* If the addr parameter is the IPv6 unspecified address no query must
|
||||
be performed. */
|
||||
#define PREPROCESS \
|
||||
if (len == sizeof (struct in6_addr) \
|
||||
&& __builtin_expect (memcmp (&__in6addr_any, addr, \
|
||||
sizeof (struct in6_addr)), 1) == 0) \
|
||||
{ \
|
||||
*h_errnop = HOST_NOT_FOUND; \
|
||||
*result = NULL; \
|
||||
return ENOENT; \
|
||||
}
|
||||
#define POSTPROCESS \
|
||||
if (status == NSS_STATUS_SUCCESS) \
|
||||
{ \
|
||||
_res_hconf_reorder_addrs (resbuf); \
|
||||
_res_hconf_trim_domains (resbuf); \
|
||||
}
|
||||
|
||||
/* Special name for the lookup function. */
|
||||
#define DB_LOOKUP_FCT __nss_hosts_lookup2
|
||||
|
||||
#include "../nss/getXXbyYY_r.c"
|
36
nss/gethstbynm.c
Normal file
36
nss/gethstbynm.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/* Copyright (C) 1996-2023 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 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.
|
||||
|
||||
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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
|
||||
#define LOOKUP_TYPE struct hostent
|
||||
#define FUNCTION_NAME gethostbyname
|
||||
#define DATABASE_NAME hosts
|
||||
#define ADD_PARAMS const char *name
|
||||
#define ADD_VARIABLES name
|
||||
#define BUFLEN 1024
|
||||
#define NEED_H_ERRNO 1
|
||||
|
||||
#define HANDLE_DIGITS_DOTS 1
|
||||
|
||||
#include <nss/getXXbyYY.c>
|
37
nss/gethstbynm2.c
Normal file
37
nss/gethstbynm2.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/* Copyright (C) 1996-2023 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 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.
|
||||
|
||||
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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
|
||||
#define LOOKUP_TYPE struct hostent
|
||||
#define FUNCTION_NAME gethostbyname2
|
||||
#define DATABASE_NAME hosts
|
||||
#define ADD_PARAMS const char *name, int af
|
||||
#define ADD_VARIABLES name, af
|
||||
#define BUFLEN 1024
|
||||
#define NEED_H_ERRNO 1
|
||||
|
||||
#define HANDLE_DIGITS_DOTS 1
|
||||
#define HAVE_AF 1
|
||||
|
||||
#include "../nss/getXXbyYY.c"
|
44
nss/gethstbynm2_r.c
Normal file
44
nss/gethstbynm2_r.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/* Copyright (C) 1996-2023 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 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.
|
||||
|
||||
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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <resolv/res_hconf.h>
|
||||
|
||||
#define LOOKUP_TYPE struct hostent
|
||||
#define FUNCTION_NAME gethostbyname2
|
||||
#define DATABASE_NAME hosts
|
||||
#define ADD_PARAMS const char *name, int af
|
||||
#define ADD_VARIABLES name, af
|
||||
#define NEED_H_ERRNO 1
|
||||
#define NEED__RES 1
|
||||
#define POSTPROCESS \
|
||||
if (status == NSS_STATUS_SUCCESS) \
|
||||
_res_hconf_reorder_addrs (resbuf);
|
||||
|
||||
#define HANDLE_DIGITS_DOTS 1
|
||||
#define HAVE_LOOKUP_BUFFER 1
|
||||
#define HAVE_AF 1
|
||||
|
||||
/* Special name for the lookup function. */
|
||||
#define DB_LOOKUP_FCT __nss_hosts_lookup2
|
||||
|
||||
#include "../nss/getXXbyYY_r.c"
|
43
nss/gethstbynm_r.c
Normal file
43
nss/gethstbynm_r.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/* Copyright (C) 1996-2023 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 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.
|
||||
|
||||
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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <resolv/res_hconf.h>
|
||||
|
||||
#define LOOKUP_TYPE struct hostent
|
||||
#define FUNCTION_NAME gethostbyname
|
||||
#define DATABASE_NAME hosts
|
||||
#define ADD_PARAMS const char *name
|
||||
#define ADD_VARIABLES name
|
||||
#define NEED_H_ERRNO 1
|
||||
#define NEED__RES 1
|
||||
#define POSTPROCESS \
|
||||
if (status == NSS_STATUS_SUCCESS) \
|
||||
_res_hconf_reorder_addrs (resbuf);
|
||||
|
||||
#define HANDLE_DIGITS_DOTS 1
|
||||
#define HAVE_LOOKUP_BUFFER 1
|
||||
|
||||
/* Special name for the lookup function. */
|
||||
#define DB_LOOKUP_FCT __nss_hosts_lookup2
|
||||
|
||||
#include "../nss/getXXbyYY_r.c"
|
26
nss/gethstent.c
Normal file
26
nss/gethstent.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* Copyright (C) 1996-2023 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 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.
|
||||
|
||||
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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <netdb.h>
|
||||
|
||||
|
||||
#define LOOKUP_TYPE struct hostent
|
||||
#define GETFUNC_NAME gethostent
|
||||
#define BUFLEN 1024
|
||||
#define NEED_H_ERRNO 1
|
||||
|
||||
#include "../nss/getXXent.c"
|
34
nss/gethstent_r.c
Normal file
34
nss/gethstent_r.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/* Copyright (C) 1996-2023 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 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.
|
||||
|
||||
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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <netdb.h>
|
||||
|
||||
|
||||
#define LOOKUP_TYPE struct hostent
|
||||
#define SETFUNC_NAME sethostent
|
||||
#define GETFUNC_NAME gethostent
|
||||
#define ENDFUNC_NAME endhostent
|
||||
#define DATABASE_NAME hosts
|
||||
#define STAYOPEN int stayopen
|
||||
#define STAYOPEN_VAR stayopen
|
||||
#define NEED_H_ERRNO 1
|
||||
#define NEED__RES 1
|
||||
|
||||
/* Special name for the lookup function. */
|
||||
#define DB_LOOKUP_FCT __nss_hosts_lookup2
|
||||
|
||||
#include "../nss/getXXent_r.c"
|
67
nss/tst-gethnm.c
Normal file
67
nss/tst-gethnm.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/* Based on a test case by grd@algonet.se. */
|
||||
|
||||
#include <netdb.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
static int
|
||||
do_test (void)
|
||||
{
|
||||
struct hostent *ent;
|
||||
struct in_addr hostaddr;
|
||||
int result = 0;
|
||||
|
||||
inet_aton ("127.0.0.1", (struct in_addr *) &hostaddr.s_addr);
|
||||
ent = gethostbyaddr (&hostaddr, sizeof (hostaddr), AF_INET);
|
||||
if (ent == NULL)
|
||||
puts ("gethostbyaddr (...) == NULL");
|
||||
else
|
||||
{
|
||||
puts ("Using gethostbyaddr(..):");
|
||||
printf ("h_name: %s\n", ent->h_name);
|
||||
|
||||
if (ent->h_aliases == NULL)
|
||||
puts ("ent->h_aliases == NULL");
|
||||
else
|
||||
printf ("h_aliases[0]: %s\n", ent->h_aliases[0]);
|
||||
}
|
||||
|
||||
ent = gethostbyname ("127.0.0.1");
|
||||
if (ent == NULL)
|
||||
{
|
||||
puts ("gethostbyname (\"127.0.0.1\") == NULL");
|
||||
result = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("\nNow using gethostbyname(..):\n");
|
||||
printf ("h_name: %s\n", ent->h_name);
|
||||
if (strcmp (ent->h_name, "127.0.0.1") != 0)
|
||||
{
|
||||
puts ("ent->h_name != \"127.0.0.1\"");
|
||||
result = 1;
|
||||
}
|
||||
|
||||
if (ent->h_aliases == NULL)
|
||||
{
|
||||
puts ("ent->h_aliases == NULL");
|
||||
result = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("h_aliases[0]: %s\n", ent->h_aliases[0]);
|
||||
result |= ent->h_aliases[0] != NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#define TEST_FUNCTION do_test ()
|
||||
#include "../test-skeleton.c"
|
Reference in New Issue
Block a user