1# Copyright (C) 1996-2022 Free Software Foundation, Inc.
2# This file is part of the GNU C Library.
3
4# The GNU C Library is free software; you can redistribute it and/or
5# modify it under the terms of the GNU Lesser General Public
6# License as published by the Free Software Foundation; either
7# version 2.1 of the License, or (at your option) any later version.
8
9# The GNU C Library is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12# Lesser General Public License for more details.
13
14# You should have received a copy of the GNU Lesser General Public
15# License along with the GNU C Library; if not, see
16# <https://www.gnu.org/licenses/>.
17
18#
19#	Makefile for name service switch.
20#
21subdir	:= nss
22
23include ../Makeconfig
24
25headers			:= nss.h
26
27# This is the trivial part which goes into libc itself.
28routines		= nsswitch getnssent getnssent_r digits_dots \
29			  valid_field valid_list_field rewrite_field \
30			  $(addsuffix -lookup,$(databases)) \
31			  compat-lookup nss_hash nss_files_fopen \
32			  nss_readline nss_parse_line_result \
33			  nss_fgetent_r nss_module nss_action \
34			  nss_action_parse nss_database nss_files_data \
35			  nss_files_functions
36
37# These are the databases that go through nss dispatch.
38# Caution: if you add a database here, you must add its real name
39# in databases.def, too.
40databases		= proto service hosts network grp pwd ethers \
41			  spwd netgrp alias sgrp
42
43ifneq (,$(filter sunrpc,$(subdirs)))
44databases		+= key rpc
45have-sunrpc		:= 1
46else
47have-sunrpc		:= 0
48endif
49CPPFLAGS-getent.c	= -DHAVE_SUNRPC=$(have-sunrpc)
50
51others                  := getent makedb
52install-bin             := getent makedb
53makedb-modules = xmalloc hash-string
54others-extras		= $(makedb-modules)
55extra-objs		+= $(makedb-modules:=.o)
56
57tests-static            = tst-field
58tests-internal		= tst-field
59
60tests := \
61  bug17079 \
62  test-digits-dots \
63  test-netdb \
64  tst-nss-getpwent \
65  tst-nss-hash \
66  tst-nss-test1 \
67  tst-nss-test2 \
68  tst-nss-test4 \
69  tst-nss-test5 \
70  tst-nss-test_errno \
71# tests
72
73xtests = bug-erange
74
75tests-container := \
76  tst-nss-compat1 \
77  tst-nss-db-endgrent \
78  tst-nss-db-endpwent \
79  tst-nss-files-hosts-long \
80  tst-nss-gai-actions \
81  tst-nss-test3 \
82  tst-reload1 \
83  tst-reload2 \
84# tests-container
85
86# Tests which need libdl
87ifeq (yes,$(build-shared))
88tests += tst-nss-files-hosts-erange
89tests += tst-nss-files-hosts-multi
90tests += tst-nss-files-hosts-getent
91tests += tst-nss-files-alias-leak
92tests += tst-nss-files-alias-truncated
93endif
94
95# If we have a thread library then we can test cancellation against
96# some routines like getpwuid_r.
97ifeq (yes,$(have-thread-library))
98tests += tst-cancel-getpwuid_r
99endif
100
101# Specify rules for the nss_* modules.  We have some services.
102services		:= files db compat
103
104extra-libs		= $(services:%=libnss_%)
105# These libraries will be built in the `others' pass rather than
106# the `lib' pass, because they depend on libc.so being built already.
107extra-libs-others	= $(extra-libs)
108
109# The sources are found in the appropriate subdir.
110subdir-dirs = $(services:%=nss_%)
111vpath %.c $(subdir-dirs) ../locale/programs ../intl
112
113
114routines += \
115  $(addprefix files-, $(filter-out key, $(databases))) \
116  files-init \
117  files-initgroups \
118  # routines
119
120# Build only an empty shared libnss_files.
121libnss_files-inhibit-o = $(filter-out .os,$(object-suffixes))
122
123# Pretend that libnss_files.so is a linker script, so that the symbolic link
124# is not installed.
125install-lib-ldscripts = libnss_files.so
126$(inst_libdir)/libnss_files.so:
127
128libnss_db-dbs		:= $(addprefix db-,\
129				       $(filter-out hosts network key alias,\
130						    $(databases))) \
131			   db-initgroups
132libnss_db-routines	:= $(libnss_db-dbs) db-open db-init hash-string
133generated		+= $(filter-out db-alias.c db-netgrp.c, \
134					$(addsuffix .c,$(libnss_db-dbs)))
135
136libnss_compat-routines	:= $(addprefix compat-,grp pwd spwd initgroups) \
137			   nisdomain
138
139install-others		+= $(inst_vardbdir)/Makefile
140
141# Build static module into libc if requested
142libnss_db-inhibit-o	= $(filter-out .os,$(object-suffixes))
143libnss_compat-inhibit-o	= $(filter-out .os,$(object-suffixes))
144ifeq ($(build-static-nss),yes)
145tests-static		+= tst-nss-static
146endif
147extra-test-objs		+= nss_test1.os nss_test2.os nss_test_errno.os
148
149include ../Rules
150
151ifeq (yes,$(have-selinux))
152LDLIBS-makedb		:= -lselinux
153endif
154
155libnss-libc = $(common-objpfx)linkobj/libc.so
156# Target-specific variable setting to link objects using deprecated
157# RPC interfaces with the version of libc.so that makes them available
158# for new links:
159$(services:%=$(objpfx)libnss_%.so): libc-for-link = $(libnss-libc)
160
161$(libnss_db-dbs:%=$(objpfx)%.c): $(objpfx)db-%.c: nss_files/files-%.c
162	@rm -f $@.new
163	(echo '#define EXTERN_PARSER';\
164	 echo '#define GENERIC "../nss_db/db-XXX.c"';\
165	 echo '#include "$<"') > $@.new
166	mv -f $@.new $@
167
168
169$(objpfx)makedb: $(makedb-modules:%=$(objpfx)%.o)
170
171$(inst_vardbdir)/Makefile: db-Makefile $(+force)
172	$(do-install)
173
174libnss_test1.so-no-z-defs = 1
175libnss_test2.so-no-z-defs = 1
176
177rtld-tests-LDFLAGS += -Wl,--dynamic-list=nss_test.ver
178
179libof-nss_test1 = extramodules
180libof-nss_test2 = extramodules
181libof-nss_test_errno = extramodules
182$(objpfx)/libnss_test1.so: $(objpfx)nss_test1.os $(link-libc-deps)
183	$(build-module)
184$(objpfx)/libnss_test2.so: $(objpfx)nss_test2.os $(link-libc-deps)
185	$(build-module)
186$(objpfx)/libnss_test_errno.so: $(objpfx)nss_test_errno.os $(link-libc-deps)
187	$(build-module)
188$(objpfx)nss_test2.os : nss_test1.c
189# Use the nss_files suffix for these objects as well.
190$(objpfx)/libnss_test1.so$(libnss_files.so-version): $(objpfx)/libnss_test1.so
191	$(make-link)
192$(objpfx)/libnss_test2.so$(libnss_files.so-version): $(objpfx)/libnss_test2.so
193	$(make-link)
194$(objpfx)/libnss_test_errno.so$(libnss_files.so-version): \
195  $(objpfx)/libnss_test_errno.so
196	$(make-link)
197$(patsubst %,$(objpfx)%.out,$(tests) $(tests-container)) : \
198	$(objpfx)/libnss_test1.so$(libnss_files.so-version) \
199	$(objpfx)/libnss_test2.so$(libnss_files.so-version) \
200	$(objpfx)/libnss_test_errno.so$(libnss_files.so-version)
201
202ifeq (yes,$(have-thread-library))
203$(objpfx)tst-cancel-getpwuid_r: $(shared-thread-library)
204endif
205
206$(objpfx)tst-nss-files-alias-leak.out: $(objpfx)/libnss_files.so
207$(objpfx)tst-nss-files-alias-truncated.out: $(objpfx)/libnss_files.so
208
209# Disable DT_RUNPATH on NSS tests so that the glibc internal NSS
210# functions can load testing NSS modules via DT_RPATH.
211LDFLAGS-tst-nss-test1 = -Wl,--disable-new-dtags
212LDFLAGS-tst-nss-test2 = -Wl,--disable-new-dtags
213LDFLAGS-tst-nss-test3 = -Wl,--disable-new-dtags
214LDFLAGS-tst-nss-test4 = -Wl,--disable-new-dtags
215LDFLAGS-tst-nss-test5 = -Wl,--disable-new-dtags
216LDFLAGS-tst-nss-test_errno = -Wl,--disable-new-dtags
217