From patchwork Mon Jun 7 17:38:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1488845 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=ua4dfIts; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FzLGh153vz9sCD for ; Tue, 8 Jun 2021 03:39:40 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A8FA73896C08 for ; Mon, 7 Jun 2021 17:39:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8FA73896C08 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623087577; bh=PctsBgnO1sUhD5BMAYLH4btw8VKTFa5K5Umuco6DLhw=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ua4dfItsuuZ4Q38mgBcgvfi4pbwMiaFmrFdVRCox6IKxXfYK7aTwP4bGCqoM9jLlF gK6hX+1GYVFW7aFn8va+rueedcdiz4PmvvxhoiMWvtmLgXvbv6AYrhKE+V/nOdfTwF UzfTLoMm3HaDoAu+ULsl7EfwIw7UtastSaHGEGd8= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 7CD1E3938C08 for ; Mon, 7 Jun 2021 17:38:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7CD1E3938C08 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-319-F_rQ_QaLP1i_z8hmq-xgrg-1; Mon, 07 Jun 2021 13:38:05 -0400 X-MC-Unique: F_rQ_QaLP1i_z8hmq-xgrg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C333980ED96 for ; Mon, 7 Jun 2021 17:38:04 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-115-60.ams2.redhat.com [10.36.115.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1B67619C66 for ; Mon, 7 Jun 2021 17:38:03 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 1/8] nss: Fix NSS_DECLARE_MODULE_FUNCTIONS handling of _nss_*_endnetgrent In-Reply-To: References: X-From-Line: f12db7afceb1274a2be7c46fc2da50de1e02a01f Mon Sep 17 00:00:00 2001 Message-Id: Date: Mon, 07 Jun 2021 19:38:02 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 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_H4, 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-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" The old version had an additional underscore, making the declaration ineffective. --- nss/nss.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nss/nss.h b/nss/nss.h index ae213f9a6c..c6d62adc0f 100644 --- a/nss/nss.h +++ b/nss/nss.h @@ -196,7 +196,7 @@ typedef enum nss_status nss_setspent (int); extern nss_endgrent _nss_##module##_endgrent; \ extern nss_endhostent _nss_##module##_endhostent; \ extern nss_endnetent _nss_##module##_endnetent; \ - extern nss_endnetgrent _nss_##module##__endnetgrent; \ + extern nss_endnetgrent _nss_##module##_endnetgrent; \ extern nss_endprotoent _nss_##module##_endprotoent; \ extern nss_endpwent _nss_##module##_endpwent; \ extern nss_endrpcent _nss_##module##_endrpcent; \ From patchwork Mon Jun 7 17:38:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1488846 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=hx0IGAIB; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FzLHW53PWz9sCD for ; Tue, 8 Jun 2021 03:40:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AF58C3893640 for ; Mon, 7 Jun 2021 17:40:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AF58C3893640 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623087621; bh=jUm/LYjj0ocT3GdHKUH4cPi1H0Oj/hOcji0ToSffhMM=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=hx0IGAIBTT4xnXz/sR2+VLxHJ0suq9VM2R3ef2lPYsvNwstLLPfSiqCPgIEagayf2 k3eF92VbySPU7JQgiVU5cNQ36EjdRtcGs3b7wZvmLEZoO1TB6/zdExiymXz99FFszE HlDhpTamAjTPAHV+9nRHjqI6X7C/AeIyACGw5wOc= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 47978389683E for ; Mon, 7 Jun 2021 17:38:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 47978389683E 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-323-0HWJw-kVPFK51inx4oyl9w-1; Mon, 07 Jun 2021 13:38:09 -0400 X-MC-Unique: 0HWJw-kVPFK51inx4oyl9w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8CB2188E3C1 for ; Mon, 7 Jun 2021 17:38:08 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-115-60.ams2.redhat.com [10.36.115.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 57AB85D6D3 for ; Mon, 7 Jun 2021 17:38:08 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 2/8] inet: Add hidden prototype for __inet_network In-Reply-To: References: X-From-Line: a18e0d764885de7297ea417252e49892c0a54edb Mon Sep 17 00:00:00 2001 Message-Id: Date: Mon, 07 Jun 2021 19:38:06 +0200 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.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 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_H4, 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-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" --- include/arpa/inet.h | 2 ++ inet/inet_net.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/arpa/inet.h b/include/arpa/inet.h index 19aec74275..df9472ba3b 100644 --- a/include/arpa/inet.h +++ b/include/arpa/inet.h @@ -12,4 +12,6 @@ libc_hidden_proto (__inet_pton) extern __typeof (inet_makeaddr) __inet_makeaddr; libc_hidden_proto (__inet_makeaddr) libc_hidden_proto (inet_netof) +extern __typeof (inet_network) __inet_network; +libc_hidden_proto (__inet_network) #endif diff --git a/inet/inet_net.c b/inet/inet_net.c index a0855e8bd2..b98634c33b 100644 --- a/inet/inet_net.c +++ b/inet/inet_net.c @@ -55,7 +55,7 @@ * network numbers. */ uint32_t -inet_network (const char *cp) +__inet_network (const char *cp) { uint32_t val, base, n, i; char c; @@ -107,3 +107,5 @@ again: } return (val); } +libc_hidden_def (__inet_network) +weak_alias (__inet_network, inet_network) From patchwork Mon Jun 7 17:38:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1488849 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=nBPLp46j; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FzLJM4t1kz9sCD for ; Tue, 8 Jun 2021 03:41:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A2CFD3896802 for ; Mon, 7 Jun 2021 17:41:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A2CFD3896802 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623087665; bh=lqO1dfdgReY+8axtUF8GAlZ4Co6pAfjqSK74HX8XD8U=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=nBPLp46jnIcedx19qf+Db+Fn9l1gJdHyjTf5PkfHjY9RiMm1j+lTCc9TKkNErAedD uSgQSqzxhAqFZ8U/IUBcm7j4CTcmG+fmpWa3J2TzmHgPskfJVl1cKKjOk821wHrB/k nEsbSYGsAkGf1aDQv7632hP1zyAhVYR8GYoJZYVs= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 59373393C84C for ; Mon, 7 Jun 2021 17:38:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 59373393C84C 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-533-5Dgp6uWuPwOFPCtz2LUf_w-1; Mon, 07 Jun 2021 13:38:14 -0400 X-MC-Unique: 5Dgp6uWuPwOFPCtz2LUf_w-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AE29A501EE for ; Mon, 7 Jun 2021 17:38:13 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-115-60.ams2.redhat.com [10.36.115.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 111A819714 for ; Mon, 7 Jun 2021 17:38:12 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 3/8] libio: Add hidden prototype for ungetc In-Reply-To: References: X-From-Line: aa8b88a4167fe0685140a487b9723a875f4f0a9c Mon Sep 17 00:00:00 2001 Message-Id: Date: Mon, 07 Jun 2021 19:38:10 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 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_H4, 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-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" And make ungetc the primary symbol, with _IO_ungetc as an alias. --- include/stdio.h | 1 + libio/ioungetc.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/stdio.h b/include/stdio.h index 2e0dc80c16..311adcf953 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -212,6 +212,7 @@ libc_hidden_ldbl_proto (dprintf) libc_hidden_ldbl_proto (fprintf) libc_hidden_ldbl_proto (vfprintf) libc_hidden_ldbl_proto (sprintf) +libc_hidden_proto (ungetc) libc_hidden_proto (fwrite) libc_hidden_proto (perror) libc_hidden_proto (remove) diff --git a/libio/ioungetc.c b/libio/ioungetc.c index dcf1c4ca9e..e68a4aaca8 100644 --- a/libio/ioungetc.c +++ b/libio/ioungetc.c @@ -27,7 +27,7 @@ #include "libioP.h" int -_IO_ungetc (int c, FILE *fp) +ungetc (int c, FILE *fp) { int result; CHECK_FILE (fp, EOF); @@ -40,5 +40,5 @@ _IO_ungetc (int c, FILE *fp) _IO_release_lock (fp); return result; } - -weak_alias (_IO_ungetc, ungetc) +libc_hidden_def (ungetc) +strong_alias (ungetc, _IO_ungetc) From patchwork Mon Jun 7 17:38:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1488850 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=TfTjJ22Z; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FzLKC6jjSz9sVt for ; Tue, 8 Jun 2021 03:41:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D30053890038 for ; Mon, 7 Jun 2021 17:41:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D30053890038 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623087709; bh=bGW8F9XgZ8bYE+6B0y4Fmp15izyjyEPAv/6mz0i8FxM=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=TfTjJ22ZFa3ExtkXKoUqLlzOoqHRkWJqmagDZCwn8rWDApN0OsT4EQ6CuEi4zDgP+ TsOXAV0dTgYhJP7TFf4YMrG2nXFKPvJUB+ZP+NfGj27IdunPobIPBdSPiMGK4wonhv BTKeMmbHpGxDsbslr1CtHkzogTihpxohFniEmU5k= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 43291393D013 for ; Mon, 7 Jun 2021 17:38:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 43291393D013 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-87-lPw0zijhP_qAXnvOyEFPig-1; Mon, 07 Jun 2021 13:38:22 -0400 X-MC-Unique: lPw0zijhP_qAXnvOyEFPig-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C21D21020C33 for ; Mon, 7 Jun 2021 17:38:21 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-115-60.ams2.redhat.com [10.36.115.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 269B45D9C0 for ; Mon, 7 Jun 2021 17:38:20 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 4/8] libio: Replace internal _IO_getdelim symbol with __getdelim In-Reply-To: References: X-From-Line: ec83a56fc2507ce754cf7493134a839e703ddc80 Mon Sep 17 00:00:00 2001 Message-Id: Date: Mon, 07 Jun 2021 19:38:19 +0200 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.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 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_H4, 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-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" __getdelim is exported, _IO_getdelim is not. Add a hidden prototype for __getdelim. --- iconv/gconv_conf.c | 4 ---- include/stdio.h | 1 + libio/iogetdelim.c | 7 +++---- libio/libioP.h | 1 - stdio-common/getline.c | 2 +- sysdeps/unix/sysv/linux/readonly-area.c | 2 +- 6 files changed, 6 insertions(+), 11 deletions(-) diff --git a/iconv/gconv_conf.c b/iconv/gconv_conf.c index 682f949834..bb2c1d04ea 100644 --- a/iconv/gconv_conf.c +++ b/iconv/gconv_conf.c @@ -96,10 +96,6 @@ static const char builtin_aliases[] = #undef BUILTIN_ALIAS }; -#include -#define __getdelim(line, len, c, fp) _IO_getdelim (line, len, c, fp) - - /* Value of the GCONV_PATH environment variable. */ const char *__gconv_path_envvar; diff --git a/include/stdio.h b/include/stdio.h index 311adcf953..23b7fd288c 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -213,6 +213,7 @@ libc_hidden_ldbl_proto (fprintf) libc_hidden_ldbl_proto (vfprintf) libc_hidden_ldbl_proto (sprintf) libc_hidden_proto (ungetc) +libc_hidden_proto (__getdelim) libc_hidden_proto (fwrite) libc_hidden_proto (perror) libc_hidden_proto (remove) diff --git a/libio/iogetdelim.c b/libio/iogetdelim.c index 06450ca96c..3b1253bae8 100644 --- a/libio/iogetdelim.c +++ b/libio/iogetdelim.c @@ -37,7 +37,7 @@ null terminator), or -1 on error or EOF. */ ssize_t -_IO_getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) +__getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) { ssize_t result; ssize_t cur_len = 0; @@ -122,6 +122,5 @@ unlock_return: _IO_release_lock (fp); return result; } - -weak_alias (_IO_getdelim, __getdelim) -weak_alias (_IO_getdelim, getdelim) +libc_hidden_def (__getdelim) +weak_alias (__getdelim, getdelim) diff --git a/libio/libioP.h b/libio/libioP.h index 4bad7f3c06..dc9a2ce9c8 100644 --- a/libio/libioP.h +++ b/libio/libioP.h @@ -734,7 +734,6 @@ libc_hidden_proto (_IO_getline) extern size_t _IO_getline_info (FILE *,char *, size_t, int, int, int *); libc_hidden_proto (_IO_getline_info) -extern ssize_t _IO_getdelim (char **, size_t *, int, FILE *); extern size_t _IO_getwline (FILE *,wchar_t *, size_t, wint_t, int); extern size_t _IO_getwline_info (FILE *,wchar_t *, size_t, wint_t, int, wint_t *); diff --git a/stdio-common/getline.c b/stdio-common/getline.c index de212243bb..52dfc58f2b 100644 --- a/stdio-common/getline.c +++ b/stdio-common/getline.c @@ -25,7 +25,7 @@ ssize_t __getline (char **lineptr, size_t *n, FILE *stream) { - return _IO_getdelim (lineptr, n, '\n', stream); + return __getdelim (lineptr, n, '\n', stream); } weak_alias (__getline, getline) diff --git a/sysdeps/unix/sysv/linux/readonly-area.c b/sysdeps/unix/sysv/linux/readonly-area.c index b42ec6ef3e..fa407d2f05 100644 --- a/sysdeps/unix/sysv/linux/readonly-area.c +++ b/sysdeps/unix/sysv/linux/readonly-area.c @@ -55,7 +55,7 @@ __readonly_area (const char *ptr, size_t size) while (! __feof_unlocked (fp)) { - if (_IO_getdelim (&line, &linelen, '\n', fp) <= 0) + if (__getdelim (&line, &linelen, '\n', fp) <= 0) break; char *p; From patchwork Mon Jun 7 17:38:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1488851 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=wgyIBX3w; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FzLL364fGz9sCD for ; Tue, 8 Jun 2021 03:42:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BA070389365F for ; Mon, 7 Jun 2021 17:42:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA070389365F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623087753; bh=Wf9no1j811w6litDT3xaCRb2kh0G0U7KT7TMAnC8+c4=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=wgyIBX3wvI6jVgjQXU56mIXvhCweAqCzs4KrkzQAIhzN5X/UH2AdpJXIGdLHmIzmP ubpn4tPyB1k6I05wkiEi95SIl2nMXvnE1fomUvx/vag6fUXn6gZEs3q3kMo8cbE9Ur DmZqv9EvQkP8IxhSHjov7nr4K0V0SLaO5HDgmVps= 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.133.124]) by sourceware.org (Postfix) with ESMTP id BB928393A405 for ; Mon, 7 Jun 2021 17:38:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BB928393A405 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-132-AShUg9mBNkOo0kHwQ6b3dQ-1; Mon, 07 Jun 2021 13:38:27 -0400 X-MC-Unique: AShUg9mBNkOo0kHwQ6b3dQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 95C08188E3C1 for ; Mon, 7 Jun 2021 17:38:26 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-115-60.ams2.redhat.com [10.36.115.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ED3B619714 for ; Mon, 7 Jun 2021 17:38:25 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 5/8] nss_files: Allocate nscd file registration data on the heap In-Reply-To: References: X-From-Line: 24aa5f885958838168cf5ac5c55bdd214938b431 Mon Sep 17 00:00:00 2001 Message-Id: <24aa5f885958838168cf5ac5c55bdd214938b431.1623085295.git.fweimer@redhat.com> Date: Mon, 07 Jun 2021 19:38:24 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 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_H4, 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-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" This is only needed if nss_files is loaded by nscd. Before: text data bss dec hex filename 767 0 24952 25719 6477 nss/files-init.os After: text data bss dec hex filename 666 0 0 666 29a nss/files-init.os Using PATH_MAX bytes unconditionally for the directory name is wasteful, but fixing that would constitute another break of this semi-public ABI. (The other issue is that with symbolic links, an arbitrary set of parent directories may need watching, not just a single one.) --- nss/nss_files/files-init.c | 54 ++++++++++++++------------------------ 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/nss/nss_files/files-init.c b/nss/nss_files/files-init.c index cc22330640..36d5ebce1f 100644 --- a/nss/nss_files/files-init.c +++ b/nss/nss_files/files-init.c @@ -24,44 +24,30 @@ NSS_DECLARE_MODULE_FUNCTIONS (files) -#define PWD_FILENAME "/etc/passwd" -define_traced_file (pwd, PWD_FILENAME); - -#define GRP_FILENAME "/etc/group" -define_traced_file (grp, GRP_FILENAME); - -#define HST_FILENAME "/etc/hosts" -define_traced_file (hst, HST_FILENAME); - -#define RESOLV_FILENAME "/etc/resolv.conf" -define_traced_file (resolv, RESOLV_FILENAME); - -#define SERV_FILENAME "/etc/services" -define_traced_file (serv, SERV_FILENAME); - -#define NETGR_FILENAME "/etc/netgroup" -define_traced_file (netgr, NETGR_FILENAME); +static void +register_file (void (*cb) (size_t, struct traced_file *), + int db, const char *path, int crinit) +{ + size_t pathlen = strlen (path) + 1; + struct traced_file *file = malloc (sizeof (struct traced_file) + pathlen); + /* Do not register anything on memory allocation file. nscd will + fail soon anyway. */ + if (file != NULL) + { + init_traced_file (file, path, crinit); + cb (db, file); + } +} void _nss_files_init (void (*cb) (size_t, struct traced_file *)) { - init_traced_file (&pwd_traced_file.file, PWD_FILENAME, 0); - cb (pwddb, &pwd_traced_file.file); - - init_traced_file (&grp_traced_file.file, GRP_FILENAME, 0); - cb (grpdb, &grp_traced_file.file); - - init_traced_file (&hst_traced_file.file, HST_FILENAME, 0); - cb (hstdb, &hst_traced_file.file); - - init_traced_file (&resolv_traced_file.file, RESOLV_FILENAME, 1); - cb (hstdb, &resolv_traced_file.file); - - init_traced_file (&serv_traced_file.file, SERV_FILENAME, 0); - cb (servdb, &serv_traced_file.file); - - init_traced_file (&netgr_traced_file.file, NETGR_FILENAME, 0); - cb (netgrdb, &netgr_traced_file.file); + register_file (cb, pwddb, "/etc/passwd", 0); + register_file (cb, grpdb, "/etc/group", 0); + register_file (cb, hstdb, "/etc/hosts", 0); + register_file (cb, hstdb, "/etc/resolv.conf", 1); + register_file (cb, servdb, "/etc/services", 0); + register_file (cb, netgrdb, "/etc/netgroup", 0); } #endif From patchwork Mon Jun 7 17:38:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1488855 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=whhGZSHh; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FzLM116Ppz9sT6 for ; Tue, 8 Jun 2021 03:43:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 293333893662 for ; Mon, 7 Jun 2021 17:43:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 293333893662 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623087803; bh=s3KbogsPPzVDoVkTj39RGI2FpGymf8EeH85Kn4CFoto=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=whhGZSHhssaBwKrdnJ9eO+Hz1/5N0Na6Se7DGUp7AZzAXcOnVwl9Xp2DumqYbZ0BU HFYxsGfkbaQzvR/2BbVNGSdvYE3UvwNPcHQFtqhfGum2hJTCZBZBLXP4LWfsc5Yab9 0PyHRP8OSV6nK0JQhkv74NNfeE/64cG6bJTtKTD0= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 37BB13938C37 for ; Mon, 7 Jun 2021 17:38:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 37BB13938C37 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-47--vT7Ic0GOEqwbmbTN7AzuA-1; Mon, 07 Jun 2021 13:38:34 -0400 X-MC-Unique: -vT7Ic0GOEqwbmbTN7AzuA-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 27A901020C2E for ; Mon, 7 Jun 2021 17:38:33 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-115-60.ams2.redhat.com [10.36.115.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C5D9F60CC6 for ; Mon, 7 Jun 2021 17:38:31 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 6/8] nss_files: Add generic code for set*ent, end*ent and file open In-Reply-To: References: X-From-Line: 57ca5e485125e23e1adeeec22213d2871ed287e7 Mon Sep 17 00:00:00 2001 Message-Id: <57ca5e485125e23e1adeeec22213d2871ed287e7.1623085295.git.fweimer@redhat.com> Date: Mon, 07 Jun 2021 19:38:30 +0200 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, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, 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-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" This reduces RSS usage if nss_files is not actually used, and can be used later to make NSS data thread-specific. It also results in a small code size reduction. Before: text data bss dec hex filename 2288 0 72 2360 938 nss/files-alias.os 1807 0 72 1879 757 nss/files-ethers.os 1371 0 72 1443 5a3 nss/files-grp.os 6246 0 72 6318 18ae nss/files-hosts.os 869 0 0 869 365 nss/files-initgroups.os 666 0 0 666 29a nss/files-init.os 1934 0 0 1934 78e nss/files-netgrp.os 2353 0 72 2425 979 nss/files-network.os 2130 0 72 2202 89a nss/files-proto.os 1372 0 72 1444 5a4 nss/files-pwd.os 2124 0 72 2196 894 nss/files-rpc.os 2265 0 72 2337 921 nss/files-service.os 1125 0 72 1197 4ad nss/files-sgrp.os 1124 0 72 1196 4ac nss/files-spwd.os After: text data bss dec hex filename 2040 0 0 2040 7f8 nss/files-alias.os 1599 0 0 1599 63f nss/files-ethers.os 1155 0 0 1155 483 nss/files-grp.os 6010 0 0 6010 177a nss/files-hosts.os 869 0 0 869 365 nss/files-initgroups.os 666 0 0 666 29a nss/files-init.os 1934 0 0 1934 78e nss/files-netgrp.os 2129 0 0 2129 851 nss/files-network.os 1914 0 0 1914 77a nss/files-proto.os 1156 0 0 1156 484 nss/files-pwd.os 1908 0 0 1908 774 nss/files-rpc.os 2057 0 0 2057 809 nss/files-service.os 909 0 0 909 38d nss/files-sgrp.os 908 0 0 908 38c nss/files-spwd.os 1090 0 8 1098 44a nss/nss_files_data.os 27674 code bytes before, 26344 code bytes after, so it is an overall win despite the extra initialization code. --- include/nss_files.h | 60 ++++++++++++++ nss/Makefile | 2 +- nss/Versions | 4 + nss/nss_files/files-XXX.c | 67 ++++----------- nss/nss_files/files-alias.c | 69 ++++------------ nss/nss_files/files-hosts.c | 4 +- nss/nss_files_data.c | 159 ++++++++++++++++++++++++++++++++++++ 7 files changed, 257 insertions(+), 108 deletions(-) create mode 100644 nss/nss_files_data.c diff --git a/include/nss_files.h b/include/nss_files.h index 6a0dcdb85b..7bf1951496 100644 --- a/include/nss_files.h +++ b/include/nss_files.h @@ -20,6 +20,9 @@ #define _NSS_FILES_H #include +#if IS_IN (libc) +#include +#endif /* Open PATH for reading, as a data source for nss_files. */ FILE *__nss_files_fopen (const char *path); @@ -47,6 +50,63 @@ int __nss_readline_seek (FILE *fp, off64_t offset) attribute_hidden; int __nss_parse_line_result (FILE *fp, off64_t offset, int parse_line_result); libc_hidden_proto (__nss_parse_line_result) +/* Per-file data. Used by the *ent functions that need to preserve + state across calls. */ +struct nss_files_per_file_data +{ + FILE *stream; +#if IS_IN (libc) + /* The size of locks changes between libc and nss_files, so this + member must be last and is only available in libc. */ + __libc_lock_define (, lock); +#endif +}; + +/* File index for __nss_files_data_get. */ +enum nss_files_file + { + nss_file_aliasent, + nss_file_etherent, + nss_file_grent, + nss_file_hostent, + nss_file_netent, + nss_file_protoent, + nss_file_pwent, + nss_file_rpcent, + nss_file_servent, + nss_file_sgent, + nss_file_spent, + + nss_file_count + }; + +/* Obtains a pointer to the per-file data for FILE, which is written + to *PDATA, and tries to open the file at PATH for it. On success, + returns NSS_STATUS_SUCCESS, and the caller must later call + __nss_files_data_put. On failure, NSS_STATUS_TRYAGAIN is returned, + and *ERRNOP and *HERRNOP are updated if these pointers are not + null. */ +enum nss_status __nss_files_data_open (struct nss_files_per_file_data **pdata, + enum nss_files_file file, + const char *path, + int *errnop, int *herrnop); +libc_hidden_proto (__nss_files_data_open) + +/* Unlock the per-file data, previously obtained by + __nss_files_data_open. */ +void __nss_files_data_put (struct nss_files_per_file_data *data); +libc_hidden_proto (__nss_files_data_put) + +/* Performs the set*ent operation for FILE. PATH is the file to + open. */ +enum nss_status __nss_files_data_setent (enum nss_files_file file, + const char *path); +libc_hidden_proto (__nss_files_data_setent) + +/* Performs the end*ent operation for FILE. */ +enum nss_status __nss_files_data_endent (enum nss_files_file file); +libc_hidden_proto (__nss_files_data_endent) + struct parser_data; /* Instances of the parse_line function from diff --git a/nss/Makefile b/nss/Makefile index 9682a31e20..271a0e7716 100644 --- a/nss/Makefile +++ b/nss/Makefile @@ -31,7 +31,7 @@ routines = nsswitch getnssent getnssent_r digits_dots \ compat-lookup nss_hash nss_files_fopen \ nss_readline nss_parse_line_result \ nss_fgetent_r nss_module nss_action \ - nss_action_parse nss_database + nss_action_parse nss_database nss_files_data # These are the databases that go through nss dispatch. # Caution: if you add a database here, you must add its real name diff --git a/nss/Versions b/nss/Versions index fdddea104c..7b040b4786 100644 --- a/nss/Versions +++ b/nss/Versions @@ -19,6 +19,10 @@ libc { __nss_services_lookup2; __nss_next2; __nss_lookup; __nss_hash; __nss_database_get; __nss_files_fopen; __nss_readline; __nss_parse_line_result; + __nss_files_data_endent; + __nss_files_data_open; + __nss_files_data_put; + __nss_files_data_setent; } } diff --git a/nss/nss_files/files-XXX.c b/nss/nss_files/files-XXX.c index b4b989d9bb..91553d7ca5 100644 --- a/nss/nss_files/files-XXX.c +++ b/nss/nss_files/files-XXX.c @@ -45,10 +45,12 @@ # include # define H_ERRNO_PROTO , int *herrnop # define H_ERRNO_ARG , herrnop +# define H_ERRNO_ARG_OR_NULL herrnop # define H_ERRNO_SET(val) (*herrnop = (val)) #else # define H_ERRNO_PROTO # define H_ERRNO_ARG +# define H_ERRNO_ARG_OR_NULL NULL # define H_ERRNO_SET(val) ((void) 0) #endif @@ -58,15 +60,11 @@ # define EXTRA_ARGS_VALUE #endif -/* Locks the static variables in this file. */ -__libc_lock_define_initialized (static, lock) /* Maintenance of the stream open on the database file. For getXXent operations the stream needs to be held open across calls, the other getXXbyYY operations all use their own stream. */ -static FILE *stream; - /* Open database file if not already opened. */ static enum nss_status internal_setent (FILE **stream) @@ -91,41 +89,13 @@ internal_setent (FILE **stream) enum nss_status CONCAT(_nss_files_set,ENTNAME) (int stayopen) { - enum nss_status status; - - __libc_lock_lock (lock); - - status = internal_setent (&stream); - - __libc_lock_unlock (lock); - - return status; -} - - -/* Close the database file. */ -static void -internal_endent (FILE **stream) -{ - if (*stream != NULL) - { - fclose (*stream); - *stream = NULL; - } + return __nss_files_data_setent (CONCAT (nss_file_, ENTNAME), DATAFILE); } - -/* Thread-safe, exported version of that. */ enum nss_status CONCAT(_nss_files_end,ENTNAME) (void) { - __libc_lock_lock (lock); - - internal_endent (&stream); - - __libc_lock_unlock (lock); - - return NSS_STATUS_SUCCESS; + return __nss_files_data_endent (CONCAT (nss_file_, ENTNAME)); } @@ -194,26 +164,19 @@ CONCAT(_nss_files_get,ENTNAME_r) (struct STRUCTURE *result, char *buffer, size_t buflen, int *errnop H_ERRNO_PROTO) { /* Return next entry in host file. */ - enum nss_status status = NSS_STATUS_SUCCESS; - - __libc_lock_lock (lock); - - /* Be prepared that the set*ent function was not called before. */ - if (stream == NULL) - { - int save_errno = errno; - - status = internal_setent (&stream); - - __set_errno (save_errno); - } - if (status == NSS_STATUS_SUCCESS) - status = internal_getent (stream, result, buffer, buflen, errnop - H_ERRNO_ARG EXTRA_ARGS_VALUE); + struct nss_files_per_file_data *data; + enum nss_status status = __nss_files_data_open (&data, + CONCAT (nss_file_, ENTNAME), + DATAFILE, + errnop, H_ERRNO_ARG_OR_NULL); + if (status != NSS_STATUS_SUCCESS) + return status; - __libc_lock_unlock (lock); + status = internal_getent (data->stream, result, buffer, buflen, errnop + H_ERRNO_ARG EXTRA_ARGS_VALUE); + __nss_files_data_put (data); return status; } @@ -248,7 +211,7 @@ _nss_files_get##name##_r (proto, \ == NSS_STATUS_SUCCESS) \ { break_if_match } \ \ - internal_endent (&stream); \ + fclose (stream); \ } \ \ return status; \ diff --git a/nss/nss_files/files-alias.c b/nss/nss_files/files-alias.c index 30971bfe56..9624b6224c 100644 --- a/nss/nss_files/files-alias.c +++ b/nss/nss_files/files-alias.c @@ -33,16 +33,11 @@ NSS_DECLARE_MODULE_FUNCTIONS (files) -/* Locks the static variables in this file. */ -__libc_lock_define_initialized (static, lock) /* Maintenance of the stream open on the database file. For getXXent operations the stream needs to be held open across calls, the other getXXbyYY operations all use their own stream. */ -static FILE *stream; - - static enum nss_status internal_setent (FILE **stream) { @@ -66,41 +61,13 @@ internal_setent (FILE **stream) enum nss_status _nss_files_setaliasent (void) { - enum nss_status status; - - __libc_lock_lock (lock); - - status = internal_setent (&stream); - - __libc_lock_unlock (lock); - - return status; -} - - -/* Close the database file. */ -static void -internal_endent (FILE **stream) -{ - if (*stream != NULL) - { - fclose (*stream); - *stream = NULL; - } + return __nss_files_data_setent (nss_file_aliasent, "/etc/aliases"); } - -/* Thread-safe, exported version of that. */ enum nss_status _nss_files_endaliasent (void) { - __libc_lock_lock (lock); - - internal_endent (&stream); - - __libc_lock_unlock (lock); - - return NSS_STATUS_SUCCESS; + return __nss_files_data_endent (nss_file_aliasent); } /* Parsing the database file into `struct aliasent' data structures. */ @@ -369,26 +336,22 @@ _nss_files_getaliasent_r (struct aliasent *result, char *buffer, size_t buflen, int *errnop) { /* Return next entry in host file. */ - enum nss_status status = NSS_STATUS_SUCCESS; - __libc_lock_lock (lock); + struct nss_files_per_file_data *data; + enum nss_status status = __nss_files_data_open (&data, nss_file_aliasent, + "/etc/aliases", errnop, NULL); + if (status != NSS_STATUS_SUCCESS) + return status; - /* Be prepared that the set*ent function was not called before. */ - if (stream == NULL) - status = internal_setent (&stream); + result->alias_local = 1; - if (status == NSS_STATUS_SUCCESS) - { - result->alias_local = 1; - - /* Read lines until we get a definite result. */ - do - status = get_next_alias (stream, NULL, result, buffer, buflen, errnop); - while (status == NSS_STATUS_RETURN); - } - - __libc_lock_unlock (lock); + /* Read lines until we get a definite result. */ + do + status = get_next_alias (data->stream, NULL, result, buffer, buflen, + errnop); + while (status == NSS_STATUS_RETURN); + __nss_files_data_put (data); return status; } @@ -418,9 +381,9 @@ _nss_files_getaliasbyname_r (const char *name, struct aliasent *result, do status = get_next_alias (stream, name, result, buffer, buflen, errnop); while (status == NSS_STATUS_RETURN); - } - internal_endent (&stream); + fclose (stream); + } return status; } diff --git a/nss/nss_files/files-hosts.c b/nss/nss_files/files-hosts.c index 2b47ec3e53..1dd51d1db9 100644 --- a/nss/nss_files/files-hosts.c +++ b/nss/nss_files/files-hosts.c @@ -349,7 +349,7 @@ _nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result, status = gethostbyname3_multi (stream, name, af, result, buffer, buflen, errnop, herrnop); - internal_endent (&stream); + fclose (stream); } if (canonp && status == NSS_STATUS_SUCCESS) @@ -475,7 +475,7 @@ _nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat, status = NSS_STATUS_SUCCESS; } - internal_endent (&stream); + fclose (stream); } else if (status == NSS_STATUS_TRYAGAIN) { diff --git a/nss/nss_files_data.c b/nss/nss_files_data.c new file mode 100644 index 0000000000..7b7662abf1 --- /dev/null +++ b/nss/nss_files_data.c @@ -0,0 +1,159 @@ +/* Returns a pointer to the global nss_files data structure. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +#include +#include +#include +#include +#include + +/* This collects all per file-data. */ +struct nss_files_data +{ + struct nss_files_per_file_data files[nss_file_count]; +}; + +/* For use with allocate_once. */ +static void *nss_files_global; +static void * +nss_files_global_allocate (void *closure) +{ + struct nss_files_data *result = malloc (sizeof (*result)); + if (result != NULL) + for (int i = 0; i < nss_file_count; ++i) + { + result->files[i].stream = NULL; + __libc_lock_init (result->files[i].lock); + } + return result; +} +/* Like __nss_files_data_open, but does not perform the open call. */ +static enum nss_status +__nss_files_data_get (struct nss_files_per_file_data **pdata, + enum nss_files_file file, int *errnop, int *herrnop) +{ + struct nss_files_data *data = allocate_once (&nss_files_global, + nss_files_global_allocate, + NULL, NULL); + if (data == NULL) + { + if (errnop != NULL) + *errnop = errno; + if (herrnop != NULL) + { + __set_h_errno (NETDB_INTERNAL); + *herrnop = NETDB_INTERNAL; + } + return NSS_STATUS_TRYAGAIN; + } + + *pdata = &data->files[file]; + __libc_lock_lock ((*pdata)->lock); + return NSS_STATUS_SUCCESS; +} + +/* Helper function for opening the backing file at PATH. */ +static enum nss_status +__nss_files_data_internal_open (struct nss_files_per_file_data *data, + const char *path) +{ + enum nss_status status = NSS_STATUS_SUCCESS; + + if (data->stream == NULL) + { + data->stream = __nss_files_fopen (path); + + if (data->stream == NULL) + status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL; + } + + return status; +} + + +enum nss_status +__nss_files_data_open (struct nss_files_per_file_data **pdata, + enum nss_files_file file, const char *path, + int *errnop, int *herrnop) +{ + enum nss_status status = __nss_files_data_get (pdata, file, errnop, herrnop); + if (status != NSS_STATUS_SUCCESS) + return status; + + /* Be prepared that the set*ent function was not called before. */ + if ((*pdata)->stream == NULL) + { + int saved_errno = errno; + status = __nss_files_data_internal_open (*pdata, path); + __set_errno (saved_errno); + if (status != NSS_STATUS_SUCCESS) + __nss_files_data_put (*pdata); + } + + return status; +} + +libc_hidden_def (__nss_files_data_open) + +void +__nss_files_data_put (struct nss_files_per_file_data *data) +{ + __libc_lock_unlock (data->lock); +} +libc_hidden_def (__nss_files_data_put) + +enum nss_status +__nss_files_data_setent (enum nss_files_file file, const char *path) +{ + struct nss_files_per_file_data *data; + enum nss_status status = __nss_files_data_get (&data, file, NULL, NULL); + if (status != NSS_STATUS_SUCCESS) + return status; + + if (data->stream == NULL) + status = __nss_files_data_internal_open (data, path); + else + rewind (data->stream); + + __nss_files_data_put (data); + return status; +} +libc_hidden_def (__nss_files_data_setent) + +enum nss_status +__nss_files_data_endent (enum nss_files_file file) +{ + /* No cleanup is necessary if not initialized. */ + struct nss_files_data *data = atomic_load_acquire (&nss_files_global); + if (data == NULL) + return NSS_STATUS_SUCCESS; + + struct nss_files_per_file_data *fdata = &data->files[file]; + __libc_lock_lock (fdata->lock); + if (fdata->stream != NULL) + { + fclose (fdata->stream); + fdata->stream = NULL; + } + __libc_lock_unlock (fdata->lock); + + return NSS_STATUS_SUCCESS; +} +libc_hidden_def (__nss_files_data_endent) From patchwork Mon Jun 7 17:38:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1488857 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=RLvoJrMZ; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FzLMs4B40z9sCD for ; Tue, 8 Jun 2021 03:44:09 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 81D6E38930CE for ; Mon, 7 Jun 2021 17:44:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 81D6E38930CE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623087847; bh=awKoAJWFxJNiobkwIMZGJ1OFqrXr/kSzsVv+r584U9U=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=RLvoJrMZMCTeB3GzwDeC/MbPkGUtcZeA5ZmfJsy4rw1bmup/w7kgrnhdBpuT5HaCH pMb9NhK3t1mzRT8JnX+im+uAhWFntKf6I8FoMY8w5GM06sowWUYd8P5tNILfvz0uSw zgq1+sKtG24x8bN7AkgRtv0eXkFCK7m1wWcZ03a8= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 8B1663938C2D for ; Mon, 7 Jun 2021 17:38:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8B1663938C2D 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-13-kcYHSfXOMYSpMp99mQb0-w-1; Mon, 07 Jun 2021 13:38:41 -0400 X-MC-Unique: kcYHSfXOMYSpMp99mQb0-w-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 228EF107ACCD for ; Mon, 7 Jun 2021 17:38:40 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-115-60.ams2.redhat.com [10.36.115.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C24B60862 for ; Mon, 7 Jun 2021 17:38:39 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 7/8] nss_files: Move into libc In-Reply-To: References: X-From-Line: 492539c60380229368ed8d07209fc1db4f0eb96d Mon Sep 17 00:00:00 2001 Message-Id: <492539c60380229368ed8d07209fc1db4f0eb96d.1623085295.git.fweimer@redhat.com> Date: Mon, 07 Jun 2021 19:38:37 +0200 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.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLACK 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-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" This is the first step towards fixing bug 27959. --- include/libc-symbols.h | 23 ----------------------- include/netdb.h | 2 +- include/nss_files.h | 10 +++++----- nss/Makefile | 11 +++-------- nss/Versions | 13 +++++++++---- nss/nss_files/files-alias.c | 10 +++++----- nss/nss_files/files-hosts.c | 7 ++++--- nss/nss_files/files-netgrp.c | 6 +++--- nss/nss_files/files-network.c | 5 ++--- nss/nss_files/files-parse.c | 8 +------- nss/nss_readline.c | 4 ++-- 11 files changed, 35 insertions(+), 64 deletions(-) diff --git a/include/libc-symbols.h b/include/libc-symbols.h index 127ea656c2..d41ecf4384 100644 --- a/include/libc-symbols.h +++ b/include/libc-symbols.h @@ -798,29 +798,6 @@ for linking") # define libdl_hidden_data_ver(local, name) #endif -#if IS_IN (libnss_files) -# define libnss_files_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) -# define libnss_files_hidden_tls_proto(name, attrs...) \ - hidden_tls_proto (name, ##attrs) -# define libnss_files_hidden_def(name) hidden_def (name) -# define libnss_files_hidden_weak(name) hidden_weak (name) -# define libnss_files_hidden_ver(local, name) hidden_ver (local, name) -# define libnss_files_hidden_data_def(name) hidden_data_def (name) -# define libnss_files_hidden_tls_def(name) hidden_tls_def (name) -# define libnss_files_hidden_data_weak(name) hidden_data_weak (name) -# define libnss_files_hidden_data_ver(local, name) hidden_data_ver(local, name) -#else -# define libnss_files_hidden_proto(name, attrs...) -# define libnss_files_hidden_tls_proto(name, attrs...) -# define libnss_files_hidden_def(name) -# define libnss_files_hidden_weak(name) -# define libnss_files_hidden_ver(local, name) -# define libnss_files_hidden_data_def(name) -# define libnss_files_hidden_tls_def(name) -# define libnss_files_hidden_data_weak(name) -# define libnss_files_hidden_data_ver(local, name) -#endif - #if IS_IN (libnsl) # define libnsl_hidden_proto(name, attrs...) hidden_proto (name, ##attrs) # define libnsl_hidden_tls_proto(name, attrs...) \ diff --git a/include/netdb.h b/include/netdb.h index 645b85dc62..76edd65f9a 100644 --- a/include/netdb.h +++ b/include/netdb.h @@ -213,7 +213,7 @@ extern enum nss_status _nss_netgroup_parseline (char **cursor, struct __netgrent *result, char *buffer, size_t buflen, int *errnop); -libnss_files_hidden_proto (_nss_netgroup_parseline) +libc_hidden_proto (_nss_netgroup_parseline) #define DECLARE_NSS_PROTOTYPES(service) \ extern enum nss_status _nss_ ## service ## _setprotoent (int); \ diff --git a/include/nss_files.h b/include/nss_files.h index 7bf1951496..dd0081a0f1 100644 --- a/include/nss_files.h +++ b/include/nss_files.h @@ -124,13 +124,13 @@ extern nss_files_parse_line _nss_files_parse_servent; extern nss_files_parse_line _nss_files_parse_sgent; extern nss_files_parse_line _nss_files_parse_spent; -libnss_files_hidden_proto (_nss_files_parse_etherent) +libc_hidden_proto (_nss_files_parse_etherent) libc_hidden_proto (_nss_files_parse_grent) -libnss_files_hidden_proto (_nss_files_parse_netent) -libnss_files_hidden_proto (_nss_files_parse_protoent) +libc_hidden_proto (_nss_files_parse_netent) +libc_hidden_proto (_nss_files_parse_protoent) libc_hidden_proto (_nss_files_parse_pwent) -libnss_files_hidden_proto (_nss_files_parse_rpcent) -libnss_files_hidden_proto (_nss_files_parse_servent) +libc_hidden_proto (_nss_files_parse_rpcent) +libc_hidden_proto (_nss_files_parse_servent) libc_hidden_proto (_nss_files_parse_sgent) libc_hidden_proto (_nss_files_parse_spent) diff --git a/nss/Makefile b/nss/Makefile index 271a0e7716..8905a5fd9b 100644 --- a/nss/Makefile +++ b/nss/Makefile @@ -98,9 +98,9 @@ subdir-dirs = $(services:%=nss_%) vpath %.c $(subdir-dirs) ../locale/programs ../intl -libnss_files-routines := $(addprefix files-, \ - $(filter-out key, $(databases))) \ - files-initgroups files-init +routines += \ + $(addprefix files-, $(filter-out key, $(databases))) \ + files-initgroups files-init libnss_db-dbs := $(addprefix db-,\ $(filter-out hosts network key alias,\ @@ -116,12 +116,9 @@ libnss_compat-routines := $(addprefix compat-,grp pwd spwd initgroups) \ install-others += $(inst_vardbdir)/Makefile # Build static module into libc if requested -libnss_files-inhibit-o = $(filter-out .os,$(object-suffixes)) libnss_db-inhibit-o = $(filter-out .os,$(object-suffixes)) libnss_compat-inhibit-o = $(filter-out .os,$(object-suffixes)) ifeq ($(build-static-nss),yes) -routines += $(libnss_files-routines) -static-only-routines += $(libnss_files-routines) tests-static += tst-nss-static endif extra-test-objs += nss_test1.os nss_test2.os @@ -138,8 +135,6 @@ libnss-libc = $(common-objpfx)linkobj/libc.so # for new links: $(services:%=$(objpfx)libnss_%.so): libc-for-link = $(libnss-libc) -$(objpfx)libnss_db.so: $(objpfx)libnss_files.so - $(libnss_db-dbs:%=$(objpfx)%.c): $(objpfx)db-%.c: nss_files/files-%.c @rm -f $@.new (echo '#define EXTERN_PARSER';\ diff --git a/nss/Versions b/nss/Versions index 7b040b4786..e551524aa9 100644 --- a/nss/Versions +++ b/nss/Versions @@ -23,11 +23,8 @@ libc { __nss_files_data_open; __nss_files_data_put; __nss_files_data_setent; - } -} -libnss_files { - GLIBC_PRIVATE { + # Routines formerly in libnss_files.so.2. _nss_files_setaliasent; _nss_files_endaliasent; _nss_files_getaliasbyname_r; @@ -113,6 +110,14 @@ libnss_files { } } +libnss_files { + GLIBC_PRIVATE { + # Keep a version node (with a synthesized local: * directive) so that + # __bss_* symbols are hidden on targets that need it. + __libnss_files_version_placeholder; + } +} + libnss_db { GLIBC_PRIVATE { _nss_db_setetherent; diff --git a/nss/nss_files/files-alias.c b/nss/nss_files/files-alias.c index 9624b6224c..75d91e0b0a 100644 --- a/nss/nss_files/files-alias.c +++ b/nss/nss_files/files-alias.c @@ -98,7 +98,7 @@ get_next_alias (FILE *stream, const char *match, struct aliasent *result, /* Read the first line. It must contain the alias name and possibly some alias names. */ first_unused[room_left - 1] = '\xff'; - line = fgets_unlocked (first_unused, room_left, stream); + line = __fgets_unlocked (first_unused, room_left, stream); if (line == NULL) /* Nothing to read. */ break; @@ -187,7 +187,7 @@ get_next_alias (FILE *stream, const char *match, struct aliasent *result, /* If the file does not exist we simply ignore the statement. */ if (listfile != NULL - && (old_line = strdup (line)) != NULL) + && (old_line = __strdup (line)) != NULL) { while (! feof_unlocked (listfile)) { @@ -199,8 +199,8 @@ get_next_alias (FILE *stream, const char *match, struct aliasent *result, } first_unused[room_left - 1] = '\xff'; - line = fgets_unlocked (first_unused, room_left, - listfile); + line = __fgets_unlocked (first_unused, room_left, + listfile); if (line == NULL) break; if (first_unused[room_left - 1] != '\xff') @@ -302,7 +302,7 @@ get_next_alias (FILE *stream, const char *match, struct aliasent *result, /* The just read character is a white space and so can be ignored. */ first_unused[room_left - 1] = '\xff'; - line = fgets_unlocked (first_unused, room_left, stream); + line = __fgets_unlocked (first_unused, room_left, stream); if (line == NULL) { /* Continuation line without any data and diff --git a/nss/nss_files/files-hosts.c b/nss/nss_files/files-hosts.c index 1dd51d1db9..894b85d501 100644 --- a/nss/nss_files/files-hosts.c +++ b/nss/nss_files/files-hosts.c @@ -57,12 +57,13 @@ LINE_PARSER STRING_FIELD (addr, isspace, 1); /* Parse address. */ - if (inet_pton (af == AF_UNSPEC ? AF_INET : af, addr, entdata->host_addr) + if (__inet_pton (af == AF_UNSPEC ? AF_INET : af, addr, entdata->host_addr) > 0) af = af == AF_UNSPEC ? AF_INET : af; else { - if (af == AF_INET && inet_pton (AF_INET6, addr, entdata->host_addr) > 0) + if (af == AF_INET + && __inet_pton (AF_INET6, addr, entdata->host_addr) > 0) { if (IN6_IS_ADDR_V4MAPPED (entdata->host_addr)) memcpy (entdata->host_addr, entdata->host_addr + 12, INADDRSZ); @@ -76,7 +77,7 @@ LINE_PARSER return 0; } else if (af == AF_UNSPEC - && inet_pton (AF_INET6, addr, entdata->host_addr) > 0) + && __inet_pton (AF_INET6, addr, entdata->host_addr) > 0) af = AF_INET6; else /* Illegal address: ignore line. */ diff --git a/nss/nss_files/files-netgrp.c b/nss/nss_files/files-netgrp.c index f8c821c2f0..be9c72accf 100644 --- a/nss/nss_files/files-netgrp.c +++ b/nss/nss_files/files-netgrp.c @@ -32,7 +32,7 @@ NSS_DECLARE_MODULE_FUNCTIONS (files) #define DATAFILE "/etc/netgroup" -libnss_files_hidden_proto (_nss_files_endnetgrent) +libc_hidden_proto (_nss_files_endnetgrent) #define EXPAND(needed) \ do \ @@ -164,7 +164,7 @@ _nss_files_endnetgrent (struct __netgrent *result) result->cursor = NULL; return NSS_STATUS_SUCCESS; } -libnss_files_hidden_def (_nss_files_endnetgrent) +libc_hidden_def (_nss_files_endnetgrent) static char * strip_whitespace (char *str) @@ -279,7 +279,7 @@ _nss_netgroup_parseline (char **cursor, struct __netgrent *result, return status; } -libnss_files_hidden_def (_nss_netgroup_parseline) +libc_hidden_def (_nss_netgroup_parseline) enum nss_status diff --git a/nss/nss_files/files-network.c b/nss/nss_files/files-network.c index 9cd7d7dc79..75c9f8a57e 100644 --- a/nss/nss_files/files-network.c +++ b/nss/nss_files/files-network.c @@ -21,8 +21,7 @@ #include #include #include - -NSS_DECLARE_MODULE_FUNCTIONS (files) +#include #define ENTNAME netent #define DATABASE "networks" @@ -71,7 +70,7 @@ LINE_PARSER *cp = '\0'; addr = newp; } - result->n_net = inet_network (addr); + result->n_net = __inet_network (addr); result->n_addrtype = AF_INET; }) diff --git a/nss/nss_files/files-parse.c b/nss/nss_files/files-parse.c index 68c51c7cbf..997eac573a 100644 --- a/nss/nss_files/files-parse.c +++ b/nss/nss_files/files-parse.c @@ -74,13 +74,7 @@ struct parser_data /* Export the line parser function so it can be used in nss_db. */ # define parser_stclass /* Global */ # define parse_line CONCAT(_nss_files_parse_,ENTNAME) -# if IS_IN (libc) -/* We are defining one of the functions that actually lives in libc - because it is used to implement fget*ent and suchlike. */ -# define nss_files_parse_hidden_def(name) libc_hidden_def (name) -# else -# define nss_files_parse_hidden_def(name) libnss_files_hidden_def (name) -# endif +# define nss_files_parse_hidden_def(name) libc_hidden_def (name) #endif diff --git a/nss/nss_readline.c b/nss/nss_readline.c index 4b3ecbccc8..a2f397a11f 100644 --- a/nss/nss_readline.c +++ b/nss/nss_readline.c @@ -40,7 +40,7 @@ __nss_readline (FILE *fp, char *buf, size_t len, off64_t *poffset) *poffset = __ftello64 (fp); buf[len - 1] = '\xff'; /* Marker to recognize truncation. */ - if (fgets_unlocked (buf, len, fp) == NULL) + if (__fgets_unlocked (buf, len, fp) == NULL) { if (feof_unlocked (fp)) { @@ -61,7 +61,7 @@ __nss_readline (FILE *fp, char *buf, size_t len, off64_t *poffset) line on the next call. */ return __nss_readline_seek (fp, *poffset); - /* fgets_unlocked succeeded. */ + /* __fgets_unlocked succeeded. */ /* Remove leading whitespace. */ char *p = buf; From patchwork Mon Jun 7 17:38:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1488858 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=b0E7tn3Q; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FzLNq1K0Rz9sVt for ; Tue, 8 Jun 2021 03:44:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 466C93894C1B for ; Mon, 7 Jun 2021 17:44:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 466C93894C1B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623087897; bh=UYx/w0GT0QhmlzRmMnPH/uEozxYlFZdkebiyFUaZleQ=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=b0E7tn3QTA7TjlKGZxaqOrFpniM8GywM5TKZp0W7S1eQVCsP6t9lpjjk91ndfxUWB 68WMWe8nkIg3y9JirsnzOc2nvLBDYqCrIwAkiLS7pkgEHWXtr7OlipVSnOC8rIXiCg 5huT4XfEznfvMpEyWxsIEuJY5u+zkh7QAKqrwCj0= 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.133.124]) by sourceware.org (Postfix) with ESMTP id EF7953898520 for ; Mon, 7 Jun 2021 17:38:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EF7953898520 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-178-9FI_4w58POqWdIWY9fC25Q-1; Mon, 07 Jun 2021 13:38:49 -0400 X-MC-Unique: 9FI_4w58POqWdIWY9fC25Q-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A395D107ACC7 for ; Mon, 7 Jun 2021 17:38:48 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-115-60.ams2.redhat.com [10.36.115.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 58BCF5D9C0 for ; Mon, 7 Jun 2021 17:38:47 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 8/8] nss: Access nss_files through direct references In-Reply-To: References: X-From-Line: 54b3b560dbb5fd8e9b5d61c347c4300ceed7659e Mon Sep 17 00:00:00 2001 Message-Id: <54b3b560dbb5fd8e9b5d61c347c4300ceed7659e.1623085295.git.fweimer@redhat.com> Date: Mon, 07 Jun 2021 19:38:45 +0200 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.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, 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-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" This partially fixes static-only NSS support (bug 27959): The files module no longer needs dlopen. Support for the dns module remains to be added, and also support for disabling dlopen altogher. --- include/nss_files.h | 10 ++++++++ nss/Makefile | 3 ++- nss/nss_files/files-XXX.c | 6 ++++- nss/nss_files/files-alias.c | 7 +++--- nss/nss_files/files-ethers.c | 2 -- nss/nss_files/files-grp.c | 2 -- nss/nss_files/files-hosts.c | 6 +++-- nss/nss_files/files-init.c | 4 +-- nss/nss_files/files-initgroups.c | 3 +-- nss/nss_files/files-netgrp.c | 5 ++-- nss/nss_files/files-network.c | 1 - nss/nss_files/files-proto.c | 2 -- nss/nss_files/files-pwd.c | 2 -- nss/nss_files/files-rpc.c | 2 -- nss/nss_files/files-service.c | 2 -- nss/nss_files/files-sgrp.c | 2 -- nss/nss_files/files-spwd.c | 2 -- nss/nss_files_functions.c | 43 ++++++++++++++++++++++++++++++++ nss/nss_module.c | 38 +++++++++++++++++++++++++++- nss/nss_module.h | 4 +++ 20 files changed, 114 insertions(+), 32 deletions(-) create mode 100644 nss/nss_files_functions.c diff --git a/include/nss_files.h b/include/nss_files.h index dd0081a0f1..6190cac6be 100644 --- a/include/nss_files.h +++ b/include/nss_files.h @@ -19,6 +19,7 @@ #ifndef _NSS_FILES_H #define _NSS_FILES_H +#include #include #if IS_IN (libc) #include @@ -134,6 +135,15 @@ libc_hidden_proto (_nss_files_parse_servent) libc_hidden_proto (_nss_files_parse_sgent) libc_hidden_proto (_nss_files_parse_spent) +NSS_DECLARE_MODULE_FUNCTIONS (files) +#undef DEFINE_NSS_FUNCTION +#define DEFINE_NSS_FUNCTION(x) libc_hidden_proto (_nss_files_##x) +#include +#undef DEFINE_NSS_FUNCTION + +void _nss_files_init (void (*cb) (size_t, struct traced_file *)); +libc_hidden_proto (_nss_files_init) + /* Generic implementation of fget*ent_r. Reads lines from FP until EOF or a successful parse into *RESULT using PARSER. Returns 0 on success, ENOENT on EOF, ERANGE on too-small buffer. */ diff --git a/nss/Makefile b/nss/Makefile index 8905a5fd9b..75afb22cb3 100644 --- a/nss/Makefile +++ b/nss/Makefile @@ -31,7 +31,8 @@ routines = nsswitch getnssent getnssent_r digits_dots \ compat-lookup nss_hash nss_files_fopen \ nss_readline nss_parse_line_result \ nss_fgetent_r nss_module nss_action \ - nss_action_parse nss_database nss_files_data + nss_action_parse nss_database nss_files_data \ + nss_files_functions # These are the databases that go through nss dispatch. # Caution: if you add a database here, you must add its real name diff --git a/nss/nss_files/files-XXX.c b/nss/nss_files/files-XXX.c index 91553d7ca5..c158a891bd 100644 --- a/nss/nss_files/files-XXX.c +++ b/nss/nss_files/files-XXX.c @@ -91,12 +91,14 @@ CONCAT(_nss_files_set,ENTNAME) (int stayopen) { return __nss_files_data_setent (CONCAT (nss_file_, ENTNAME), DATAFILE); } +libc_hidden_def (CONCAT (_nss_files_set,ENTNAME)) enum nss_status CONCAT(_nss_files_end,ENTNAME) (void) { return __nss_files_data_endent (CONCAT (nss_file_, ENTNAME)); } +libc_hidden_def (CONCAT (_nss_files_end,ENTNAME)) /* Parsing the database file into `struct STRUCTURE' data structures. */ @@ -179,6 +181,7 @@ CONCAT(_nss_files_get,ENTNAME_r) (struct STRUCTURE *result, char *buffer, __nss_files_data_put (data); return status; } +libc_hidden_def (CONCAT (_nss_files_get,ENTNAME_r)) /* Macro for defining lookup functions for this file-based database. @@ -215,4 +218,5 @@ _nss_files_get##name##_r (proto, \ } \ \ return status; \ -} +} \ +libc_hidden_def (_nss_files_get##name##_r) diff --git a/nss/nss_files/files-alias.c b/nss/nss_files/files-alias.c index 75d91e0b0a..8c6e176ff6 100644 --- a/nss/nss_files/files-alias.c +++ b/nss/nss_files/files-alias.c @@ -31,8 +31,6 @@ #include "nsswitch.h" #include -NSS_DECLARE_MODULE_FUNCTIONS (files) - /* Maintenance of the stream open on the database file. For getXXent operations the stream needs to be held open across calls, the other @@ -63,12 +61,14 @@ _nss_files_setaliasent (void) { return __nss_files_data_setent (nss_file_aliasent, "/etc/aliases"); } +libc_hidden_def (_nss_files_setaliasent) enum nss_status _nss_files_endaliasent (void) { return __nss_files_data_endent (nss_file_aliasent); } +libc_hidden_def (_nss_files_endaliasent) /* Parsing the database file into `struct aliasent' data structures. */ static enum nss_status @@ -354,7 +354,7 @@ _nss_files_getaliasent_r (struct aliasent *result, char *buffer, size_t buflen, __nss_files_data_put (data); return status; } - +libc_hidden_def (_nss_files_getaliasent_r) enum nss_status _nss_files_getaliasbyname_r (const char *name, struct aliasent *result, @@ -387,3 +387,4 @@ _nss_files_getaliasbyname_r (const char *name, struct aliasent *result, return status; } +libc_hidden_def (_nss_files_getaliasbyname_r) diff --git a/nss/nss_files/files-ethers.c b/nss/nss_files/files-ethers.c index 2fe7f81e4b..7c2c2b9833 100644 --- a/nss/nss_files/files-ethers.c +++ b/nss/nss_files/files-ethers.c @@ -20,8 +20,6 @@ #include #include -NSS_DECLARE_MODULE_FUNCTIONS (files) - struct etherent_data {}; #define ENTNAME etherent diff --git a/nss/nss_files/files-grp.c b/nss/nss_files/files-grp.c index 49be38e8b1..a716d948e2 100644 --- a/nss/nss_files/files-grp.c +++ b/nss/nss_files/files-grp.c @@ -19,8 +19,6 @@ #include #include -NSS_DECLARE_MODULE_FUNCTIONS (files) - #define STRUCTURE group #define ENTNAME grent #define DATABASE "group" diff --git a/nss/nss_files/files-hosts.c b/nss/nss_files/files-hosts.c index 894b85d501..d54d91d038 100644 --- a/nss/nss_files/files-hosts.c +++ b/nss/nss_files/files-hosts.c @@ -26,8 +26,6 @@ #include #include -NSS_DECLARE_MODULE_FUNCTIONS (files) - /* Get implementation for some internal functions. */ #include "../resolv/res_hconf.h" @@ -358,6 +356,7 @@ _nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result, return status; } +libc_hidden_def (_nss_files_gethostbyname3_r) enum nss_status _nss_files_gethostbyname_r (const char *name, struct hostent *result, @@ -367,6 +366,7 @@ _nss_files_gethostbyname_r (const char *name, struct hostent *result, return _nss_files_gethostbyname3_r (name, AF_INET, result, buffer, buflen, errnop, herrnop, NULL, NULL); } +libc_hidden_def (_nss_files_gethostbyname_r) enum nss_status _nss_files_gethostbyname2_r (const char *name, int af, struct hostent *result, @@ -376,6 +376,7 @@ _nss_files_gethostbyname2_r (const char *name, int af, struct hostent *result, return _nss_files_gethostbyname3_r (name, af, result, buffer, buflen, errnop, herrnop, NULL, NULL); } +libc_hidden_def (_nss_files_gethostbyname2_r) enum nss_status _nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat, @@ -491,3 +492,4 @@ _nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat, return status; } +libc_hidden_def (_nss_files_gethostbyname4_r) diff --git a/nss/nss_files/files-init.c b/nss/nss_files/files-init.c index 36d5ebce1f..18d48168e8 100644 --- a/nss/nss_files/files-init.c +++ b/nss/nss_files/files-init.c @@ -21,8 +21,7 @@ #include #include #include - -NSS_DECLARE_MODULE_FUNCTIONS (files) +#include static void register_file (void (*cb) (size_t, struct traced_file *), @@ -49,5 +48,6 @@ _nss_files_init (void (*cb) (size_t, struct traced_file *)) register_file (cb, servdb, "/etc/services", 0); register_file (cb, netgrdb, "/etc/netgroup", 0); } +libc_hidden_def (_nss_files_init) #endif diff --git a/nss/nss_files/files-initgroups.c b/nss/nss_files/files-initgroups.c index 6fcea40b55..b44211e50b 100644 --- a/nss/nss_files/files-initgroups.c +++ b/nss/nss_files/files-initgroups.c @@ -28,8 +28,6 @@ #include #include -NSS_DECLARE_MODULE_FUNCTIONS (files) - enum nss_status _nss_files_initgroups_dyn (const char *user, gid_t group, long int *start, long int *size, gid_t **groupsp, long int limit, @@ -129,3 +127,4 @@ _nss_files_initgroups_dyn (const char *user, gid_t group, long int *start, return status == NSS_STATUS_SUCCESS && !any ? NSS_STATUS_NOTFOUND : status; } +libc_hidden_def (_nss_files_initgroups_dyn) diff --git a/nss/nss_files/files-netgrp.c b/nss/nss_files/files-netgrp.c index be9c72accf..75bfbd9e44 100644 --- a/nss/nss_files/files-netgrp.c +++ b/nss/nss_files/files-netgrp.c @@ -28,8 +28,6 @@ #include "netgroup.h" #include -NSS_DECLARE_MODULE_FUNCTIONS (files) - #define DATAFILE "/etc/netgroup" libc_hidden_proto (_nss_files_endnetgrent) @@ -152,7 +150,7 @@ _nss_files_setnetgrent (const char *group, struct __netgrent *result) return status; } - +libc_hidden_def (_nss_files_setnetgrent) enum nss_status _nss_files_endnetgrent (struct __netgrent *result) @@ -293,3 +291,4 @@ _nss_files_getnetgrent_r (struct __netgrent *result, char *buffer, return status; } +libc_hidden_def (_nss_files_getnetgrent_r) diff --git a/nss/nss_files/files-network.c b/nss/nss_files/files-network.c index 75c9f8a57e..217ed78609 100644 --- a/nss/nss_files/files-network.c +++ b/nss/nss_files/files-network.c @@ -21,7 +21,6 @@ #include #include #include -#include #define ENTNAME netent #define DATABASE "networks" diff --git a/nss/nss_files/files-proto.c b/nss/nss_files/files-proto.c index 98d082c642..13072692c1 100644 --- a/nss/nss_files/files-proto.c +++ b/nss/nss_files/files-proto.c @@ -19,8 +19,6 @@ #include #include -NSS_DECLARE_MODULE_FUNCTIONS (files) - #define ENTNAME protoent #define DATABASE "protocols" diff --git a/nss/nss_files/files-pwd.c b/nss/nss_files/files-pwd.c index b04165ddde..5c74c6da9b 100644 --- a/nss/nss_files/files-pwd.c +++ b/nss/nss_files/files-pwd.c @@ -19,8 +19,6 @@ #include #include -NSS_DECLARE_MODULE_FUNCTIONS (files) - #define STRUCTURE passwd #define ENTNAME pwent #define DATABASE "passwd" diff --git a/nss/nss_files/files-rpc.c b/nss/nss_files/files-rpc.c index eeb2725d2c..3dea8f18f2 100644 --- a/nss/nss_files/files-rpc.c +++ b/nss/nss_files/files-rpc.c @@ -19,8 +19,6 @@ #include #include -NSS_DECLARE_MODULE_FUNCTIONS (files) - #define ENTNAME rpcent #define DATABASE "rpc" diff --git a/nss/nss_files/files-service.c b/nss/nss_files/files-service.c index f4f0985377..a8d83e094e 100644 --- a/nss/nss_files/files-service.c +++ b/nss/nss_files/files-service.c @@ -20,8 +20,6 @@ #include #include -NSS_DECLARE_MODULE_FUNCTIONS (files) - #define ENTNAME servent #define DATABASE "services" diff --git a/nss/nss_files/files-sgrp.c b/nss/nss_files/files-sgrp.c index 6b1c9eac02..213a408e7b 100644 --- a/nss/nss_files/files-sgrp.c +++ b/nss/nss_files/files-sgrp.c @@ -19,8 +19,6 @@ #include #include -NSS_DECLARE_MODULE_FUNCTIONS (files) - #define STRUCTURE sgrp #define ENTNAME sgent #define DATABASE "gshadow" diff --git a/nss/nss_files/files-spwd.c b/nss/nss_files/files-spwd.c index 976deaf918..d031257a20 100644 --- a/nss/nss_files/files-spwd.c +++ b/nss/nss_files/files-spwd.c @@ -19,8 +19,6 @@ #include #include -NSS_DECLARE_MODULE_FUNCTIONS (files) - #define STRUCTURE spwd #define ENTNAME spent #define DATABASE "shadow" diff --git a/nss/nss_files_functions.c b/nss/nss_files_functions.c new file mode 100644 index 0000000000..85720b4311 --- /dev/null +++ b/nss/nss_files_functions.c @@ -0,0 +1,43 @@ +/* Direct access for nss_files functions for NSS module loading. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +void +__nss_files_functions (nss_module_functions_untyped pointers) +{ + void **fptr = pointers; + + /* Functions which are not implemented. */ +#define _nss_files_getcanonname_r NULL +#define _nss_files_gethostbyaddr2_r NULL +#define _nss_files_getpublickey NULL +#define _nss_files_getsecretkey NULL +#define _nss_files_netname2user NULL + +#undef DEFINE_NSS_FUNCTION +#define DEFINE_NSS_FUNCTION(x) *fptr++ = _nss_files_##x; +#include "function.def" + +#ifdef PTR_MANGLE + void **end = fptr; + for (fptr = pointers; fptr != end; ++fptr) + PTR_MANGLE (*fptr); +#endif +} diff --git a/nss/nss_module.c b/nss/nss_module.c index 60c070c851..7b42c585a4 100644 --- a/nss/nss_module.c +++ b/nss/nss_module.c @@ -30,6 +30,7 @@ #include #include #include +#include /* Suffix after .so of NSS service modules. This is a bit of magic, but we assume LIBNSS_FILES_SO looks like "libnss_files.so.2" and we @@ -110,10 +111,45 @@ static const function_name nss_function_name_array[] = #include "function.def" }; +static bool +module_load_nss_files (struct nss_module *module) +{ + if (is_nscd) + { + void (*cb) (size_t, struct traced_file *) = nscd_init_cb; +# ifdef PTR_DEMANGLE + PTR_DEMANGLE (cb); +# endif + _nss_files_init (cb); + } + + /* Initialize the function pointers, following the double-checked + locking idiom. */ + __libc_lock_lock (nss_module_list_lock); + switch ((enum nss_module_state) atomic_load_acquire (&module->state)) + { + case nss_module_uninitialized: + case nss_module_failed: + __nss_files_functions (module->functions.untyped); + module->handle = NULL; + /* Synchronizes with unlocked __nss_module_load atomic_load_acquire. */ + atomic_store_release (&module->state, nss_module_loaded); + break; + case nss_module_loaded: + /* Nothing to clean up. */ + break; + } + __libc_lock_unlock (nss_module_list_lock); + return true; +} + /* Internal implementation of __nss_module_load. */ static bool module_load (struct nss_module *module) { + if (strcmp (module->name, "files") == 0) + return module_load_nss_files (module); + void *handle; { char *shlib_name; @@ -360,7 +396,7 @@ __nss_module_freeres (void) struct nss_module *current = nss_module_list; while (current != NULL) { - if (current->state == nss_module_loaded) + if (current->state == nss_module_loaded && current->handle != NULL) __libc_dlclose (current->handle); struct nss_module *next = current->next; diff --git a/nss/nss_module.h b/nss/nss_module.h index 05c4791d11..c1a1d90b60 100644 --- a/nss/nss_module.h +++ b/nss/nss_module.h @@ -38,6 +38,10 @@ struct nss_module_functions typedef void *nss_module_functions_untyped[sizeof (struct nss_module_functions) / sizeof (void *)]; +/* Locate the nss_files functions, as if by dlopen/dlsym. */ +void __nss_files_functions (nss_module_functions_untyped pointers) + attribute_hidden; + /* Initialization state of a NSS module. */ enum nss_module_state {