From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 438C4389245C for ; Wed, 17 Feb 2021 05:42:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 438C4389245C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-497-YuhtkWGBNo2OuZ-n8NqEdg-1; Wed, 17 Feb 2021 00:42:28 -0500 X-MC-Unique: YuhtkWGBNo2OuZ-n8NqEdg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A0C12107ACE3; Wed, 17 Feb 2021 05:42:27 +0000 (UTC) Received: from greed.delorie.com (ovpn-116-4.rdu2.redhat.com [10.10.116.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6D3891349A; Wed, 17 Feb 2021 05:42:27 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.14.7/8.14.7) with ESMTP id 11H5gQpf032490; Wed, 17 Feb 2021 00:42:26 -0500 From: DJ Delorie To: Andreas Schwab Cc: libc-alpha@sourceware.org Subject: Re: v5 [PATCH 6/6] nsswitch: use new internal API (callers) In-Reply-To: <87r1lgquew.fsf@igel.home> (message from Andreas Schwab on Tue, 16 Feb 2021 09:38:31 +0100) Date: Wed, 17 Feb 2021 00:42:26 -0500 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.7 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_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Wed, 17 Feb 2021 05:42:32 -0000 Andreas Schwab writes: > nss_compat needs the {passwd,group,shadow}_compat databases, which > __nss_database_lookup2 doesn't recognize. Added. >> + /* Primary name not found, try alternate. */ >> + for (database_id = 0; database_names[database_id]; database_id++) >> + if (strcmp (database_names[database_id], alternate_name) == 0) >> + if (__nss_database_get (database_id, ni) && *ni != NULL) >> + return 0; > > That crashes if alternate_name is NULL. It looks like alternate_name is only used by the shadow/gshadow databases, though. New patch; has a debug printf so you can validate what nss_database_lookup2 calls happen; remove if you like. >From cabd86ff35008957d9dc3818c5e2a43d247962cb Mon Sep 17 00:00:00 2001 From: DJ Delorie Date: Mon, 15 Feb 2021 21:34:23 -0500 Subject: nss: fix nss_database_lookup2's alternate handling [27416] diff --git a/nss/databases.def b/nss/databases.def index df5fab4168..3dc95648a8 100644 --- a/nss/databases.def +++ b/nss/databases.def @@ -23,17 +23,20 @@ DEFINE_DATABASE (aliases) DEFINE_DATABASE (ethers) DEFINE_DATABASE (group) +DEFINE_DATABASE (group_compat) DEFINE_DATABASE (gshadow) DEFINE_DATABASE (hosts) DEFINE_DATABASE (initgroups) DEFINE_DATABASE (netgroup) DEFINE_DATABASE (networks) DEFINE_DATABASE (passwd) +DEFINE_DATABASE (passwd_compat) DEFINE_DATABASE (protocols) DEFINE_DATABASE (publickey) DEFINE_DATABASE (rpc) DEFINE_DATABASE (services) DEFINE_DATABASE (shadow) +DEFINE_DATABASE (shadow_compat) /* Local Variables: diff --git a/nss/nss_database.c b/nss/nss_database.c index e1bef6bd75..162800cda3 100644 --- a/nss/nss_database.c +++ b/nss/nss_database.c @@ -172,7 +172,7 @@ nss_database_select_default (struct nss_database_default_cache *cache, /* database_name must be large enough for each individual name plus a null terminator. */ -typedef char database_name[11]; +typedef char database_name[14]; #define DEFINE_DATABASE(name) \ _Static_assert (sizeof (#name) <= sizeof (database_name), #name); #include "databases.def" diff --git a/nss/nsswitch.c b/nss/nsswitch.c index 46f232d720..aa59d426bc 100644 --- a/nss/nsswitch.c +++ b/nss/nsswitch.c @@ -74,26 +74,33 @@ __nss_database_lookup2 (const char *database, const char *alternate_name, { int database_id; + printf("lookup2 %s %s %s\n", + database?database:"no-dname", + alternate_name?alternate_name:"no-alt", + defconfig?defconfig:"no-def"); + for (database_id = 0; database_names[database_id]; database_id++) if (strcmp (database_names[database_id], database) == 0) - break; - - if (database_names[database_id] == NULL) - return -1; - - /* If *NI is NULL, the database was not mentioned in nsswitch.conf. - If *NI is not NULL, but *NI->module is NULL, the database was in - nsswitch.conf but listed no actions. We test for the former. */ - if (__nss_database_get (database_id, ni) && *ni != NULL) - { - /* Success. */ - return 0; - } - else - { - /* Failure. */ - return -1; - } + /* If *NI is NULL, the database was not mentioned in nsswitch.conf. + If *NI is not NULL, but *NI->module is NULL, the database was in + nsswitch.conf but listed no actions. We test for the former. */ + if (__nss_database_get (database_id, ni) && *ni != NULL) + return 0; + + /* Primary name not found, try alternate. */ + if (alternate_name) + for (database_id = 0; database_names[database_id]; database_id++) + if (strcmp (database_names[database_id], alternate_name) == 0) + if (__nss_database_get (database_id, ni) && *ni != NULL) + return 0; + + /* Neither found, use default config. */ + *ni = __nss_action_parse (defconfig); + if (*ni != NULL) + return 0; + + /* Failure. */ + return -1; } libc_hidden_def (__nss_database_lookup2)