From a7e8d0b90bc400b4d57afb01c1a54236a5c4754c Mon Sep 17 00:00:00 2001 From: Arjun Shankar Date: Mon, 2 Oct 2023 14:55:21 +0200 Subject: 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 --- nss/Makefile | 24 +++++++++++++++++++ nss/Versions | 2 ++ nss/gethstbyad.c | 29 +++++++++++++++++++++++ nss/gethstbyad_r.c | 50 +++++++++++++++++++++++++++++++++++++++ nss/gethstbynm.c | 36 ++++++++++++++++++++++++++++ nss/gethstbynm2.c | 37 +++++++++++++++++++++++++++++ nss/gethstbynm2_r.c | 44 +++++++++++++++++++++++++++++++++++ nss/gethstbynm_r.c | 43 ++++++++++++++++++++++++++++++++++ nss/gethstent.c | 26 +++++++++++++++++++++ nss/gethstent_r.c | 34 +++++++++++++++++++++++++++ nss/tst-gethnm.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 392 insertions(+) create mode 100644 nss/gethstbyad.c create mode 100644 nss/gethstbyad_r.c create mode 100644 nss/gethstbynm.c create mode 100644 nss/gethstbynm2.c create mode 100644 nss/gethstbynm2_r.c create mode 100644 nss/gethstbynm_r.c create mode 100644 nss/gethstent.c create mode 100644 nss/gethstent_r.c create mode 100644 nss/tst-gethnm.c (limited to 'nss') diff --git a/nss/Makefile b/nss/Makefile index 148c6dc1cf..d0b564a033 100644 --- a/nss/Makefile +++ b/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 \ diff --git a/nss/Versions b/nss/Versions index 99208cb9df..74ba4470d8 100644 --- a/nss/Versions +++ b/nss/Versions @@ -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; diff --git a/nss/gethstbyad.c b/nss/gethstbyad.c new file mode 100644 index 0000000000..1b0fc982e4 --- /dev/null +++ b/nss/gethstbyad.c @@ -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 + . */ + +#include + + +#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" diff --git a/nss/gethstbyad_r.c b/nss/gethstbyad_r.c new file mode 100644 index 0000000000..ee1b1d12ee --- /dev/null +++ b/nss/gethstbyad_r.c @@ -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 + . */ + +#include +#include +#include + +#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" diff --git a/nss/gethstbynm.c b/nss/gethstbynm.c new file mode 100644 index 0000000000..6134dec455 --- /dev/null +++ b/nss/gethstbynm.c @@ -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 + . */ + +#include +#include +#include +#include +#include +#include + + +#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 diff --git a/nss/gethstbynm2.c b/nss/gethstbynm2.c new file mode 100644 index 0000000000..6d1421b06a --- /dev/null +++ b/nss/gethstbynm2.c @@ -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 + . */ + +#include +#include +#include +#include +#include +#include + + +#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" diff --git a/nss/gethstbynm2_r.c b/nss/gethstbynm2_r.c new file mode 100644 index 0000000000..e0c373513d --- /dev/null +++ b/nss/gethstbynm2_r.c @@ -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 + . */ + +#include +#include +#include +#include +#include +#include +#include + +#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" diff --git a/nss/gethstbynm_r.c b/nss/gethstbynm_r.c new file mode 100644 index 0000000000..c224673544 --- /dev/null +++ b/nss/gethstbynm_r.c @@ -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 + . */ + +#include +#include +#include +#include +#include +#include +#include + +#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" diff --git a/nss/gethstent.c b/nss/gethstent.c new file mode 100644 index 0000000000..2bfe27443d --- /dev/null +++ b/nss/gethstent.c @@ -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 + . */ + +#include + + +#define LOOKUP_TYPE struct hostent +#define GETFUNC_NAME gethostent +#define BUFLEN 1024 +#define NEED_H_ERRNO 1 + +#include "../nss/getXXent.c" diff --git a/nss/gethstent_r.c b/nss/gethstent_r.c new file mode 100644 index 0000000000..00957fc1c1 --- /dev/null +++ b/nss/gethstent_r.c @@ -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 + . */ + +#include + + +#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" diff --git a/nss/tst-gethnm.c b/nss/tst-gethnm.c new file mode 100644 index 0000000000..dd3a547811 --- /dev/null +++ b/nss/tst-gethnm.c @@ -0,0 +1,67 @@ +/* Based on a test case by grd@algonet.se. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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" -- cgit 1.4.1