Bug 209718 - -DNO_ROOT+WITHOUT_NIS results in an invalid nsswitch.conf
Summary: -DNO_ROOT+WITHOUT_NIS results in an invalid nsswitch.conf
Status: In Progress
Alias: None
Product: Base System
Classification: Unclassified
Component: conf (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Mark Johnston
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-05-23 18:06 UTC by Mark Johnston
Modified: 2025-04-07 13:20 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Johnston freebsd_committer freebsd_triage 2016-05-23 18:06:08 UTC
When WITHOUT_NIS is set, some code in /etc/Makefile will edit the installed nsswitch.conf to remove NIS compat DBs and sources. When building with -DNO_ROOT, the size of nsswitch.conf is recorded in the mtree log before this edit is performed, so the logged size is different (smaller) than that of the edited nsswitch.conf. This results in a truncated nsswitch.conf if the mtree file is used with makefs to create a filesystem image, for example.
Comment 1 Brooks Davis freebsd_committer freebsd_triage 2016-05-24 00:09:31 UTC
Eww.  This is definitely a bug.  nsswitch.conf should be generated under the all target  so the right thing can be installed.
Comment 2 Gleb Popov freebsd_committer freebsd_triage 2024-10-16 09:29:47 UTC
nsswitch.conf is not generated anymore, so this can be closed, most likely.
Comment 3 Mark Johnston freebsd_committer freebsd_triage 2024-10-16 13:01:32 UTC
(In reply to Gleb Popov from comment #2)
The problem is still there.  It's caused by this bit at the end of lib/libc/net/Makefile.inc:

179 afterinstallconfig: modify-nsswitch-conf                                                                                                                                                                                                                                                                                  
180 modify-nsswitch-conf: .PHONY                                                                                                                                                                                                                                                                                              
181 .if ${MK_NIS} == "no"                                                                                                                                                                                                                                                                                                     
182         sed -i "" -e 's/.*_compat:/# &/' -e 's/compat$$/files/' \                                                                                                                                                                                                                                                         
183                 ${DESTDIR}/etc/nsswitch.conf                                                                                                                                                                                                                                                                              
184 .endif

Modifying installed files is a bad idea.  It should be done before installation.
Comment 4 commit-hook freebsd_committer freebsd_triage 2025-04-07 13:14:58 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=49bc071f40886af46eb90467dfef6cba5f95beec

commit 49bc071f40886af46eb90467dfef6cba5f95beec
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-04-07 12:42:08 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-04-07 12:42:08 +0000

    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

 lib/libc/net/Makefile.inc | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)