1# Copyright (C) 1996-2021 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
59tests			= test-netdb test-digits-dots tst-nss-getpwent bug17079 \
60			  tst-nss-test1 \
61			  tst-nss-test2 \
62			  tst-nss-test4 \
63			  tst-nss-test5
64xtests			= bug-erange
65
66tests-container = \
67			  tst-nss-compat1 \
68			  tst-nss-test3 \
69			  tst-nss-files-hosts-long \
70			  tst-nss-db-endpwent \
71			  tst-nss-db-endgrent \
72			  tst-reload1 tst-reload2
73
74# Tests which need libdl
75ifeq (yes,$(build-shared))
76tests += tst-nss-files-hosts-erange
77tests += tst-nss-files-hosts-multi
78tests += tst-nss-files-hosts-getent
79tests += tst-nss-files-alias-leak
80tests += tst-nss-files-alias-truncated
81endif
82
83# If we have a thread library then we can test cancellation against
84# some routines like getpwuid_r.
85ifeq (yes,$(have-thread-library))
86tests += tst-cancel-getpwuid_r
87endif
88
89# Specify rules for the nss_* modules.  We have some services.
90services		:= files db compat
91
92extra-libs		= $(services:%=libnss_%)
93# These libraries will be built in the `others' pass rather than
94# the `lib' pass, because they depend on libc.so being built already.
95extra-libs-others	= $(extra-libs)
96
97# The sources are found in the appropriate subdir.
98subdir-dirs = $(services:%=nss_%)
99vpath %.c $(subdir-dirs) ../locale/programs ../intl
100
101
102routines += \
103  $(addprefix files-, $(filter-out key, $(databases))) \
104  files-init \
105  files-initgroups \
106  # routines
107
108# Build only an empty shared libnss_files.
109libnss_files-inhibit-o = $(filter-out .os,$(object-suffixes))
110
111# Pretend that libnss_files.so is a linker script, so that the symbolic link
112# is not installed.
113install-lib-ldscripts = libnss_files.so
114$(inst_libdir)/libnss_files.so:
115
116libnss_db-dbs		:= $(addprefix db-,\
117				       $(filter-out hosts network key alias,\
118						    $(databases))) \
119			   db-initgroups
120libnss_db-routines	:= $(libnss_db-dbs) db-open db-init hash-string
121generated		+= $(filter-out db-alias.c db-netgrp.c, \
122					$(addsuffix .c,$(libnss_db-dbs)))
123
124libnss_compat-routines	:= $(addprefix compat-,grp pwd spwd initgroups) \
125			   nisdomain
126
127install-others		+= $(inst_vardbdir)/Makefile
128
129# Build static module into libc if requested
130libnss_db-inhibit-o	= $(filter-out .os,$(object-suffixes))
131libnss_compat-inhibit-o	= $(filter-out .os,$(object-suffixes))
132ifeq ($(build-static-nss),yes)
133tests-static		+= tst-nss-static
134endif
135extra-test-objs		+= nss_test1.os nss_test2.os
136
137include ../Rules
138
139ifeq (yes,$(have-selinux))
140LDLIBS-makedb		:= -lselinux
141endif
142
143libnss-libc = $(common-objpfx)linkobj/libc.so
144# Target-specific variable setting to link objects using deprecated
145# RPC interfaces with the version of libc.so that makes them available
146# for new links:
147$(services:%=$(objpfx)libnss_%.so): libc-for-link = $(libnss-libc)
148
149$(libnss_db-dbs:%=$(objpfx)%.c): $(objpfx)db-%.c: nss_files/files-%.c
150	@rm -f $@.new
151	(echo '#define EXTERN_PARSER';\
152	 echo '#define GENERIC "../nss_db/db-XXX.c"';\
153	 echo '#include "$<"') > $@.new
154	mv -f $@.new $@
155
156
157$(objpfx)makedb: $(makedb-modules:%=$(objpfx)%.o)
158
159$(inst_vardbdir)/Makefile: db-Makefile $(+force)
160	$(do-install)
161
162libnss_test1.so-no-z-defs = 1
163libnss_test2.so-no-z-defs = 1
164
165rtld-tests-LDFLAGS += -Wl,--dynamic-list=nss_test.ver
166
167libof-nss_test1 = extramodules
168libof-nss_test2 = extramodules
169$(objpfx)/libnss_test1.so: $(objpfx)nss_test1.os $(link-libc-deps)
170	$(build-module)
171$(objpfx)/libnss_test2.so: $(objpfx)nss_test2.os $(link-libc-deps)
172	$(build-module)
173$(objpfx)nss_test2.os : nss_test1.c
174ifdef libnss_test1.so-version
175$(objpfx)/libnss_test1.so$(libnss_test1.so-version): $(objpfx)/libnss_test1.so
176	$(make-link)
177endif
178ifdef libnss_test2.so-version
179$(objpfx)/libnss_test2.so$(libnss_test2.so-version): $(objpfx)/libnss_test2.so
180	$(make-link)
181endif
182$(patsubst %,$(objpfx)%.out,$(tests) $(tests-container)) : \
183	$(objpfx)/libnss_test1.so$(libnss_test1.so-version) \
184	$(objpfx)/libnss_test2.so$(libnss_test2.so-version)
185
186ifeq (yes,$(have-thread-library))
187$(objpfx)tst-cancel-getpwuid_r: $(shared-thread-library)
188endif
189
190$(objpfx)tst-nss-files-alias-leak.out: $(objpfx)/libnss_files.so
191$(objpfx)tst-nss-files-alias-truncated.out: $(objpfx)/libnss_files.so
192
193# Disable DT_RUNPATH on NSS tests so that the glibc internal NSS
194# functions can load testing NSS modules via DT_RPATH.
195LDFLAGS-tst-nss-test1 = -Wl,--disable-new-dtags
196LDFLAGS-tst-nss-test2 = -Wl,--disable-new-dtags
197LDFLAGS-tst-nss-test3 = -Wl,--disable-new-dtags
198LDFLAGS-tst-nss-test4 = -Wl,--disable-new-dtags
199LDFLAGS-tst-nss-test5 = -Wl,--disable-new-dtags
200