From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id B10B369E5B for ; Tue, 1 Sep 2020 11:18:51 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id AE2941AAF9 for ; Tue, 1 Sep 2020 11:18:21 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id DB9D01AAE9 for ; Tue, 1 Sep 2020 11:18:20 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 9EE53449A6 for ; Tue, 1 Sep 2020 11:18:20 +0200 (CEST) From: Stoiko Ivanov To: pve-devel@lists.proxmox.com Date: Tue, 1 Sep 2020 11:18:03 +0200 Message-Id: <20200901091804.23647-2-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200901091804.23647-1-s.ivanov@proxmox.com> References: <20200901091804.23647-1-s.ivanov@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [tools.pm, jsonschema.pm] Subject: [pve-devel] [PATCH common 1/2] move email regex from JSONSchema to Tools X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Sep 2020 09:18:51 -0000 Move the Regular expression used for matching e-mail addresses from the verify sub in PVE::JSONSchema to PVE::Tools, so that it can be reused in PVE::Tools::sendmail. This ensures that both uses have the same definition of valid email addresses. Signed-off-by: Stoiko Ivanov --- src/PVE/JSONSchema.pm | 4 ++-- src/PVE/Tools.pm | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm index 2ceb1bd..b27ffa7 100644 --- a/src/PVE/JSONSchema.pm +++ b/src/PVE/JSONSchema.pm @@ -7,7 +7,7 @@ use Getopt::Long; use Encode::Locale; use Encode; use Devel::Cycle -quiet; # todo: remove? -use PVE::Tools qw(split_list $IPV6RE $IPV4RE); +use PVE::Tools qw(split_list $IPV6RE $IPV4RE $EMAILRE); use PVE::Exception qw(raise); use HTTP::Status qw(:constants); use Net::IP qw(:PROC); @@ -469,7 +469,7 @@ register_format('email', \&pve_verify_email); sub pve_verify_email { my ($email, $noerr) = @_; - if ($email !~ /^[\w\+\-\~]+(\.[\w\+\-\~]+)*@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*$/) { + if ($email !~ /^${EMAILRE}$/) { return undef if $noerr; die "value does not look like a valid email address\n"; } diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm index f9270d9..e849bdf 100644 --- a/src/PVE/Tools.pm +++ b/src/PVE/Tools.pm @@ -33,6 +33,7 @@ no warnings 'portable'; # Support for 64-bit ints required our @EXPORT_OK = qw( $IPV6RE $IPV4RE +$EMAILRE lock_file lock_file_full run_command @@ -84,6 +85,8 @@ our $IPV6RE = "(?:" . our $IPRE = "(?:$IPV4RE|$IPV6RE)"; +our $EMAILRE = qr{[\w\+\-\~]+(\.[\w\+\-\~]+)*@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*}; + use constant {CLONE_NEWNS => 0x00020000, CLONE_NEWUTS => 0x04000000, CLONE_NEWIPC => 0x08000000, -- 2.20.1