nsswitch.conf: Avoid modification after installation

To implement WITHOUT_NIS, we have a hack in the build which modifies the
installed nsswitch.conf to remove NIS compat providers and databases.
This hack operates on the installed nsswitch.conf, which means that the
installed file size won't match that listed in the metalog.

One option would be to maintain two copies of nsswitch.conf, one for
each configuration, but that would result in duplication and I don't see
a clear way around that.

Instead, stage a copy of nsswitch.conf in the libc objdir, and modify
that one before installing, so that the version recorded in the metalog
matches what actually gets installed.

PR:		209718
Reviewed by:	kevans, emaste
Sponsored by:	Klara, Inc.
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D49300
This commit is contained in:
Mark Johnston 2025-04-07 12:42:08 +00:00
parent 82d8c609cf
commit 49bc071f40

View file

@ -1,7 +1,7 @@
# machine-independent net sources
.PATH: ${LIBC_SRCTOP}/net
CONFS+= net/hosts net/hosts.equiv net/networks net/nsswitch.conf net/protocols
CONFS+= net/hosts net/hosts.equiv net/networks ${.OBJDIR}/nsswitch.conf net/protocols
SRCS+= base64.c ether_addr.c eui64.c \
gai_strerror.c getaddrinfo.c \
gethostbydns.c gethostbyht.c gethostbynis.c gethostnamadr.c \
@ -176,9 +176,13 @@ MLINKS+=hesiod.3 hesiod_init.3 \
hesiod.3 hesiod_end.3
.endif
afterinstallconfig: modify-nsswitch-conf
modify-nsswitch-conf: .PHONY
all: ${.OBJDIR}/nsswitch.conf
# Manually stage nsswitch.conf in the object directory so that we can edit it
# before installing.
${.OBJDIR}/nsswitch.conf: ${LIBC_SRCTOP}/net/nsswitch.conf
cp -f ${LIBC_SRCTOP}/net/nsswitch.conf ${.TARGET}
.if ${MK_NIS} == "no"
sed -i "" -e 's/.*_compat:/# &/' -e 's/compat$$/files/' \
${DESTDIR}/etc/nsswitch.conf
${.TARGET}
.endif