aboutsummaryrefslogtreecommitdiff
path: root/nss
diff options
context:
space:
mode:
Diffstat (limited to 'nss')
-rw-r--r--nss/Makefile24
-rw-r--r--nss/Versions2
-rw-r--r--nss/gethstbyad.c29
-rw-r--r--nss/gethstbyad_r.c50
-rw-r--r--nss/gethstbynm.c36
-rw-r--r--nss/gethstbynm2.c37
-rw-r--r--nss/gethstbynm2_r.c44
-rw-r--r--nss/gethstbynm_r.c43
-rw-r--r--nss/gethstent.c26
-rw-r--r--nss/gethstent_r.c34
-rw-r--r--nss/tst-gethnm.c67
11 files changed, 392 insertions, 0 deletions
diff --git a/nss/Makefile b/nss/Makefile
index 148c6dc..d0b564a 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 99208cb..74ba447 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 0000000..1b0fc98
--- /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
+ <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"
diff --git a/nss/gethstbyad_r.c b/nss/gethstbyad_r.c
new file mode 100644
index 0000000..ee1b1d1
--- /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
+ <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"
diff --git a/nss/gethstbynm.c b/nss/gethstbynm.c
new file mode 100644
index 0000000..6134dec
--- /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
+ <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>
diff --git a/nss/gethstbynm2.c b/nss/gethstbynm2.c
new file mode 100644
index 0000000..6d1421b
--- /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
+ <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"
diff --git a/nss/gethstbynm2_r.c b/nss/gethstbynm2_r.c
new file mode 100644
index 0000000..e0c3735
--- /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
+ <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"
diff --git a/nss/gethstbynm_r.c b/nss/gethstbynm_r.c
new file mode 100644
index 0000000..c224673
--- /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
+ <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"
diff --git a/nss/gethstent.c b/nss/gethstent.c
new file mode 100644
index 0000000..2bfe274
--- /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
+ <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"
diff --git a/nss/gethstent_r.c b/nss/gethstent_r.c
new file mode 100644
index 0000000..00957fc
--- /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
+ <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"
diff --git a/nss/tst-gethnm.c b/nss/tst-gethnm.c
new file mode 100644
index 0000000..dd3a547
--- /dev/null
+++ b/nss/tst-gethnm.c
@@ -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"