From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id AA61920EC88 for ; Wed, 24 Apr 2024 11:21:09 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id F1B767C70; Wed, 24 Apr 2024 11:21:13 +0200 (CEST) Date: Wed, 24 Apr 2024 11:20:39 +0200 From: Stoiko Ivanov To: Christian Ebner Message-ID: <20240424112039.41c06de2@rosa.proxmox.com> In-Reply-To: <20240424084850.204194-1-c.ebner@proxmox.com> References: <20240424084850.204194-1-c.ebner@proxmox.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.076 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [country.pl, answer.rs, utils.rs] Subject: Re: [pve-devel] [PATCH pve-installer] answer: perform basic input validation for keyboard 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: , Reply-To: Proxmox VE development discussion Cc: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" On Wed, 24 Apr 2024 10:48:50 +0200 Christian Ebner wrote: > Currently it is possible to validate and create an iso with an > invalid keyboad layout, only failing later during installation. > > Add a basic check for correct keyboard layout by defining an enum > with allowed variants. > > Signed-off-by: Christian Ebner > --- > proxmox-auto-installer/src/answer.rs | 39 +++++++++++++++++++++++++++- > proxmox-auto-installer/src/utils.rs | 8 ++++-- > 2 files changed, 44 insertions(+), 3 deletions(-) > > diff --git a/proxmox-auto-installer/src/answer.rs b/proxmox-auto-installer/src/answer.rs > index a6cf8b7..af7485a 100644 > --- a/proxmox-auto-installer/src/answer.rs > +++ b/proxmox-auto-installer/src/answer.rs > @@ -23,7 +23,7 @@ pub struct Answer { > pub struct Global { > pub country: String, > pub fqdn: Fqdn, > - pub keyboard: String, > + pub keyboard: KeyboardLayout, > pub mailto: String, > pub timezone: String, > pub root_password: String, > @@ -270,3 +270,40 @@ pub struct BtrfsOptions { > pub hdsize: Option, > pub raid: Option, > } > + > +#[derive(Clone, Deserialize, Serialize, Debug, PartialEq)] > +#[serde(rename_all = "kebab-case", deny_unknown_fields)] > +pub enum KeyboardLayout { > + De, > + DeCh, > + Dk, > + EnGb, > + EnUs, > + Es, > + Fi, > + Fr, > + FrBe, > + FrCa, > + FrCh, > + Hu, > + Is, > + It, > + Jp, > + Lt, > + Mk, > + Nl, > + No, > + Pl, > + Pt, > + PtBr, > + Se, > + Si, > + Tr, > +} > + quickly looked at that as well yesterday - and I also ran into the issue that we get the relevant data in the installer itself (where actual validation takes place). with the target to have the auto-install-assistant available as single static binary - I think your approach works well enough - the one thing that might be an improvment is to get the data from country.dat (a build-artefact output from country.pl based on /usr/share/iso-codes/json/iso_3166-1.json ) at build-time and embed it in the binary. (but I did not get around to checking how this is done sensibly in rust) additionally we could verify the country selection as well with that. > +impl std::fmt::Display for KeyboardLayout { > + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { > + let keyboard_layout = serde_json::to_value(self).unwrap().to_string(); > + write!(f, "{}", keyboard_layout.trim_matches('\"')) > + } > +} > diff --git a/proxmox-auto-installer/src/utils.rs b/proxmox-auto-installer/src/utils.rs > index 7e1366c..202ad41 100644 > --- a/proxmox-auto-installer/src/utils.rs > +++ b/proxmox-auto-installer/src/utils.rs > @@ -281,7 +281,11 @@ pub fn verify_locale_settings(answer: &Answer, locales: &LocaleInfo) -> Result<( > { > bail!("country code '{}' is not valid", &answer.global.country); > } > - if !locales.kmap.keys().any(|i| i == &answer.global.keyboard) { > + if !locales > + .kmap > + .keys() > + .any(|i| i == &answer.global.keyboard.to_string()) > + { > bail!("keyboard layout '{}' is not valid", &answer.global.keyboard); > } > > @@ -328,7 +332,7 @@ pub fn parse_answer( > > country: answer.global.country.clone(), > timezone: answer.global.timezone.clone(), > - keymap: answer.global.keyboard.clone(), > + keymap: answer.global.keyboard.to_string(), > > password: answer.global.root_password.clone(), > mailto: answer.global.mailto.clone(), _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel