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 EF1C1846C for ; Wed, 21 Jun 2023 14:31:03 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D011D1D0D6 for ; Wed, 21 Jun 2023 14:30:33 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 21 Jun 2023 14:30:33 +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 D13034229C for ; Wed, 21 Jun 2023 14:30:32 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Wed, 21 Jun 2023 14:30:32 +0200 Message-Id: <20230621123032.744374-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230621123032.744374-1-d.csapak@proxmox.com> References: <20230621123032.744374-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.016 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [main.rs, proxmox.com] Subject: [pve-devel] [PATCH 2/2] tui: verify email with basic regex 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: Wed, 21 Jun 2023 12:31:04 -0000 regex copied from perl gui installer Signed-off-by: Dominik Csapak --- this needs librust-regex-dev as build-dependency proxmox-tui-installer/Cargo.toml | 1 + proxmox-tui-installer/src/main.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/proxmox-tui-installer/Cargo.toml b/proxmox-tui-installer/Cargo.toml index 9d57b5b..5a50c69 100644 --- a/proxmox-tui-installer/Cargo.toml +++ b/proxmox-tui-installer/Cargo.toml @@ -11,5 +11,6 @@ homepage = "https://www.proxmox.com" cursive = { version = "0.20.0", default-features = false, features = ["termion-backend"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" +regex = "1.7" proxmox-sys = "0.5.0" diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs index 77cfb63..2d048f0 100644 --- a/proxmox-tui-installer/src/main.rs +++ b/proxmox-tui-installer/src/main.rs @@ -25,6 +25,8 @@ use cursive::{ Cursive, CursiveRunnable, ScreenId, View, XY, }; +use regex::Regex; + use proxmox_sys::linux::procfs; mod options; @@ -484,12 +486,18 @@ fn password_dialog(siv: &mut Cursive) -> InstallerView { .get_value::(2) .ok_or("failed to retrieve email")?; + let email_regex = + Regex::new(r"^[\w\+\-\~]+(\.[\w\+\-\~]+)*@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*$") + .unwrap(); + if root_password.len() < 5 { Err("password too short") } else if root_password != confirm_password { Err("passwords do not match") } else if email == "mail@example.invalid" { Err("invalid email address") + } else if !email_regex.is_match(&email) { + Err("Email does not look like a valid address (user@domain.tld)") } else { Ok(PasswordOptions { root_password, -- 2.30.2