From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id C7D411FF13A for ; Wed, 27 May 2026 15:06:48 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 34FD51CC33; Wed, 27 May 2026 15:06:46 +0200 (CEST) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Subject: [PATCH proxmox 1/3] installer types: move email validation from proxmox-installer-common Date: Wed, 27 May 2026 15:05:57 +0200 Message-ID: <20260527130611.2995147-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260527130611.2995147-1-d.csapak@proxmox.com> References: <20260527130611.2995147-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.101 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 POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_1 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes 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. [whatwg.org,answer.rs] Message-ID-Hash: KQZHYZHPOCIHT2KP64W4D76TQYI5T3OO X-Message-ID-Hash: KQZHYZHPOCIHT2KP64W4D76TQYI5T3OO X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: we want to use this not only in the installer itself but also e.g. in PDM which can generate answer files. Since we don't only want this when we have the api types, move the proxmox-schema and regex dependencies from the api-types feature. Signed-off-by: Dominik Csapak --- proxmox-installer-types/Cargo.toml | 6 +++--- proxmox-installer-types/src/answer.rs | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/proxmox-installer-types/Cargo.toml b/proxmox-installer-types/Cargo.toml index 4526b47f..5b0b489c 100644 --- a/proxmox-installer-types/Cargo.toml +++ b/proxmox-installer-types/Cargo.toml @@ -15,15 +15,15 @@ rust-version.workspace = true anyhow.workspace = true serde = { workspace = true, features = ["derive"] } serde_plain.workspace = true -regex = { workspace = true, optional = true } +regex = { workspace = true } proxmox-network-types.workspace = true -proxmox-schema = { workspace = true, optional = true, features = ["api-macro"] } +proxmox-schema = { workspace = true, features = ["api-macro"] } proxmox-section-config = { workspace = true, optional = true } proxmox-node-status.workspace = true [features] default = [] -api-types = ["dep:regex", "dep:proxmox-schema", "dep:proxmox-section-config", "proxmox-network-types/api-types"] +api-types = ["dep:proxmox-section-config", "proxmox-network-types/api-types"] # enable old-style answer file keys with underscores for backwards compatibility legacy = [] diff --git a/proxmox-installer-types/src/answer.rs b/proxmox-installer-types/src/answer.rs index 9c6317ae..8bb9f0dd 100644 --- a/proxmox-installer-types/src/answer.rs +++ b/proxmox-installer-types/src/answer.rs @@ -41,6 +41,17 @@ proxmox_schema::const_regex! { pub SUBSCRIPTION_KEY_REGEX = r"^(?:pve[0-9]+|pbs|pmg)[cbsp]-[0-9a-f]{10}$"; } +proxmox_schema::const_regex! { + /// An email address using the regex for `` elements + /// as defined in the [HTML specification]. + /// Using that /should/ cover all possible cases that are encountered in the wild. + /// + /// It additionally checks whether the email our default email placeholder value. + /// + /// [HTML specification]: + pub EMAIL_REGEX = r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"; +} + /// Schema for an optional Proxmox subscription key. #[cfg(feature = "api-types")] pub const SUBSCRIPTION_KEY_SCHEMA: proxmox_schema::Schema = @@ -1229,3 +1240,14 @@ where _ => Ok(None), } } + +/// Validates an email address according to [EMAIL_REGEX] +pub fn email_validate(email: &str) -> Result<()> { + if !EMAIL_REGEX.is_match(email) { + bail!("Email does not look like a valid address (user@domain.tld)") + } else if email == crate::EMAIL_DEFAULT_PLACEHOLDER { + bail!("Invalid (default) email address") + } + + Ok(()) +} -- 2.47.3