Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2803996rda; Wed, 25 Oct 2023 12:48:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHx7dwKq+bZcYvIizcMRgS9GL47911pjCoWa8hSKp+f9N085i/uljxjuyj1czc+bJmIiuhA X-Received: by 2002:a25:9008:0:b0:d9a:55ae:b290 with SMTP id s8-20020a259008000000b00d9a55aeb290mr15928253ybl.29.1698263286411; Wed, 25 Oct 2023 12:48:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698263286; cv=none; d=google.com; s=arc-20160816; b=U7V/U7XW11HBaDXq94V9TYA214wG0m8IBSQ3eK9yZvTBcIozcJVq6EV8zfjzpiqA5o ZmFcTLv0p+KUhE0PKAgY17mwwkU016DU45BWKhQdyYx12xMJTN3/McpzkJfNYSjQaXQt Fxgl+SDa8AYhZqwDyvk9KQoJOUX8cmx9cpMgoA3b6V+F5DEZHvtWEqsuoudV52MCH/cE Yf3KumbfWrIAvrfoa29nVTiKpUiKHsFv02KldGeAtll4ZEy+8HtYhSfSeAX7WBuTjkW/ apAvFkeOmj4v7zSLz8gDhFJFr+x6Mxojgj1Be1SoyLR7nbNK3uhsMjWUouv460PKScEp Q8Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=gljzIdmLP8BYQ/heFOwqk/coLY1U9+Mw6Vt9T9/FimM=; fh=CVjco16l+rn9WuojOAFRrLmIbadgdvLhVt4bh5ADZuU=; b=PnWGOLh7oRUtkagr+xGyshYOhfCw6GUR8t63iVUWwDokZOoJ5FgFsPBovxPwvQTzEZ Nm3ZpZb76HJW0I5RPaA1M2Ehq+uZsAmRIMJv0em2moUkt6khWUaRzOzmIBtKHqAcOR5X dRNTe/94WBfQ9D9MdGkDFBNzJUf2LPfwW8kr+lkCML6iPoLx9OilKv0H2R1V9Cjziuo+ jh7CV2tekUigmsBnKCmetkeTGblvbkRTg2JSm1i0LIXYPP0Z4OxaL4/VuJf51kfyXL/I COLnSM08VKB+kiBp2FJoYFFC5+yWhbIdig7yMDGHF4kZ0dXF6mrKlK8V7gU8780xHmJ6 oJaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="xsCct/Gx"; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id 187-20020a2503c4000000b00da05f6bc29fsi3881785ybd.509.2023.10.25.12.47.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 12:48:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="xsCct/Gx"; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 9F59180DCA6E; Wed, 25 Oct 2023 12:47:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229441AbjJYTrk (ORCPT + 99 others); Wed, 25 Oct 2023 15:47:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbjJYTrj (ORCPT ); Wed, 25 Oct 2023 15:47:39 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DE1693 for ; Wed, 25 Oct 2023 12:47:36 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2FD6E2199B; Wed, 25 Oct 2023 19:47:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1698263251; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gljzIdmLP8BYQ/heFOwqk/coLY1U9+Mw6Vt9T9/FimM=; b=xsCct/GxlU9A8YHYCOVncSFFNdy2vAHxlNgetB5p8SzdSnoZeJovC3j6SVcSyb+Nc0Huhp kRjd8btDRdOtDcwJUFgKcw84aoqOyf7sKqxyVWB01MVmyHxh8kBpkng/MIbdDTkE8KPfh4 xOTP2FPdAjFoKbn4OJPcjyaVyxmrb+4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1698263251; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gljzIdmLP8BYQ/heFOwqk/coLY1U9+Mw6Vt9T9/FimM=; b=tNPfnzpmt/2KRl9uQNsa9zh3bY7QdNrys3TAtw8MdJaC8pGqCP8sQocD+VSvRdELq8JYh0 Bx/SWmS7hw6MYvBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id CFFC313A9B; Wed, 25 Oct 2023 19:47:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2L9ML9JwOWVwFQAAMHmgww (envelope-from ); Wed, 25 Oct 2023 19:47:30 +0000 From: Petr Vorel To: linux-nfs@vger.kernel.org Cc: Petr Vorel , Richard Weinberger , Steve Dickson Subject: [PATCH 3/3] support/backend_sqlite.c: Add getrandom() fallback Date: Wed, 25 Oct 2023 21:47:01 +0200 Message-ID: <20231025194701.456031-4-pvorel@suse.cz> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231025194701.456031-1-pvorel@suse.cz> References: <20231025194701.456031-1-pvorel@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: 0.82 X-Spamd-Result: default: False [0.82 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-3.00)[-1.000]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_HAM_SHORT(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.08)[63.94%] X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 25 Oct 2023 12:47:40 -0700 (PDT) Allow to compile reexport on systems with older libc. (getrandom() wrapper is supported on glibc 2.25+ and musl 1.1.20+, uclibc-ng does not yet support it). getrandom() syscall is supported Linux 3.17+ (old enough to bother with a check). Signed-off-by: Petr Vorel --- Makefile.am | 1 + aclocal/getrandom.m4 | 16 ++++++++++++++++ configure.ac | 3 +++ support/reexport/backend_sqlite.c | 18 +++++++++++++++++- 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 aclocal/getrandom.m4 diff --git a/Makefile.am b/Makefile.am index 00220842..72ad4ba7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,6 +10,7 @@ EXTRA_DIST = \ autogen.sh \ \ aclocal/bsdsignals.m4 \ + aclocal/getrandom.m4 \ aclocal/nfs-utils.m4 \ aclocal/kerberos5.m4 \ aclocal/tcp-wrappers.m4 \ diff --git a/aclocal/getrandom.m4 b/aclocal/getrandom.m4 new file mode 100644 index 00000000..bc0fe16a --- /dev/null +++ b/aclocal/getrandom.m4 @@ -0,0 +1,16 @@ +dnl Checks for getrandom support (glibc 2.25+, musl 1.1.20+) +dnl +AC_DEFUN([AC_GETRANDOM], [ + AC_MSG_CHECKING(for getrandom()) + AC_LINK_IFELSE( + [AC_LANG_PROGRAM([[ + #include /* for NULL */ + #include + ]], + [[ return getrandom(NULL, 0U, 0U); ]] )], + [AC_DEFINE([HAVE_GETRANDOM], [1], [Define to 1 if you have the `getrandom' function.]) + AC_MSG_RESULT([yes])], + [AC_MSG_RESULT([no])]) + + AC_SUBST(HAVE_GETRANDOM) +]) diff --git a/configure.ac b/configure.ac index 6fbcb974..4bff679d 100644 --- a/configure.ac +++ b/configure.ac @@ -277,6 +277,9 @@ AC_TCP_WRAPPERS # Arrange for large-file support AC_SYS_LARGEFILE +dnl Check for getrandom() libc support +AC_GETRANDOM + AC_CONFIG_SRCDIR([support/include/config.h.in]) AC_CONFIG_HEADERS([support/include/config.h]) diff --git a/support/reexport/backend_sqlite.c b/support/reexport/backend_sqlite.c index 132f30c4..0eb5ea37 100644 --- a/support/reexport/backend_sqlite.c +++ b/support/reexport/backend_sqlite.c @@ -7,9 +7,16 @@ #include #include #include -#include #include +#ifdef HAVE_GETRANDOM +# include +# if !defined(SYS_getrandom) && defined(__NR_getrandom) + /* usable kernel-headers, but old glibc-headers */ +# define SYS_getrandom __NR_getrandom +# endif +#endif + #include "conffile.h" #include "reexport_backend.h" #include "xlog.h" @@ -20,6 +27,15 @@ static sqlite3 *db; static int init_done; +#if !defined(HAVE_GETRANDOM) && defined(SYS_getrandom) +/* libc without function, but we have syscall */ +static int getrandom(void *buf, size_t buflen, unsigned int flags) +{ + return (syscall(SYS_getrandom, buf, buflen, flags)); +} +# define HAVE_GETRANDOM +#endif + static int prng_init(void) { int seed; -- 2.42.0