From patchwork Wed Dec 15 18:33:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 48984 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8921C3858416 for ; Wed, 15 Dec 2021 18:34:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8921C3858416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1639593251; bh=ZbspTJCHJ5ZYOQDKasxCDwcXtKpjam3rORvCOuvNN9I=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=om4rTHP8QzijsHwHeekpKIg6UtZxjWt8/u1b6jhNNxg0K12DDX0k54OnCT9Iq2pas MHJU9hiR+4T7wc0RZwomMk5pCxI30HeuJeYGxCfjGoNlVCHOM982cv6Om6j+m/N0U5 xVujyHnhE2ibyvzusK+a9x5jk+30hBRZEd3BJuFM= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id DAED03858419 for ; Wed, 15 Dec 2021 18:33:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DAED03858419 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-557-hRyRdHv9MQGOO_K1zPWLcA-1; Wed, 15 Dec 2021 13:33:36 -0500 X-MC-Unique: hRyRdHv9MQGOO_K1zPWLcA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DC3AB36393 for ; Wed, 15 Dec 2021 18:33:35 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.17.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 510C378DD5 for ; Wed, 15 Dec 2021 18:33:35 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH] nss: Use "files dns" as the default for the hosts database (bug 28700) Date: Wed, 15 Dec 2021 19:33:33 +0100 Message-ID: <87zgp1pvk2.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This matches what is currently in nss/nsswitch.conf. The new ordering matches what most distributions use in their installed configuration files. It is common to add localhost to /etc/hosts because the name does not exist in the DNS, but is commonly used as a host name. With the built-in "dns [!UNAVAIL=return] files" default, dns is searched first and provides an answer for "localhost" (NXDOMAIN). We never look at the files database as a result, so the contents of /etc/hosts is ignored. This means that "getent hosts localhost" fail without a /etc/nsswitch.conf file, even though the host name is listed in /etc/hosts. Tested on i686-linux-gnu and x86_64-linux-gnu. Thanks, Florian Reviewed-by: Carlos O'Donell --- manual/nss.texi | 5 ++--- nss/XXX-lookup.c | 2 +- nss/nss_database.c | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/manual/nss.texi b/manual/nss.texi index 3aaa7786f8..524d22ad1e 100644 --- a/manual/nss.texi +++ b/manual/nss.texi @@ -324,9 +324,8 @@ missing. @cindex default value, and NSS For the @code{hosts} and @code{networks} databases the default value is -@code{dns [!UNAVAIL=return] files}. I.e., the system is prepared for -the DNS service not to be available but if it is available the answer it -returns is definitive. +@code{files dns}. I.e., local configuration will override the contents +of the domain name system (DNS). The @code{passwd}, @code{group}, and @code{shadow} databases was traditionally handled in a special way. The appropriate files in the diff --git a/nss/XXX-lookup.c b/nss/XXX-lookup.c index 302c6361e0..e129f699fa 100644 --- a/nss/XXX-lookup.c +++ b/nss/XXX-lookup.c @@ -28,7 +28,7 @@ |* ALTERNATE_NAME - name of another service which is examined in *| |* case DATABASE_NAME is not found *| |* *| -|* DEFAULT_CONFIG - string for default conf (e.g. "dns files") *| +|* DEFAULT_CONFIG - string for default conf (e.g. "files dns") *| |* *| \*******************************************************************/ diff --git a/nss/nss_database.c b/nss/nss_database.c index ab121cb371..54561f0328 100644 --- a/nss/nss_database.c +++ b/nss/nss_database.c @@ -80,7 +80,7 @@ enum nss_database_default { nss_database_default_defconfig = 0, /* "nis [NOTFOUND=return] files". */ nss_database_default_compat, /* "compat [NOTFOUND=return] files". */ - nss_database_default_dns, /* "dns [!UNAVAIL=return] files". */ + nss_database_default_dns, /* "files dns". */ nss_database_default_files, /* "files". */ nss_database_default_nis, /* "nis". */ nss_database_default_nis_nisplus, /* "nis nisplus". */ @@ -133,7 +133,7 @@ nss_database_select_default (struct nss_database_default_cache *cache, #endif case nss_database_default_dns: - line = "dns [!UNAVAIL=return] files"; + line = "files dns"; break; case nss_database_default_files: