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 01EEBF9A0 for ; Mon, 24 Jul 2023 11:04:21 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D8B6DBDAF for ; Mon, 24 Jul 2023 11:04:20 +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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Mon, 24 Jul 2023 11:04: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 28F2743A7D for ; Mon, 24 Jul 2023 11:04:20 +0200 (CEST) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Mon, 24 Jul 2023 11:03:46 +0200 Message-ID: <20230724090408.221672-2-c.heiss@proxmox.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230724090408.221672-1-c.heiss@proxmox.com> References: <20230724090408.221672-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.055 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 - Subject: [pve-devel] [PATCH common v2 1/5] schema: add `ldap-dn` format for validating LDAP distinguished names 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: Mon, 24 Jul 2023 09:04:21 -0000 The Net::LDAP library conveniently provides a canonical_dn() function, which can be used to (roughly) check if a DN is valid or not. This will be used in future changes to replace the current dreaded regex to validate DNs. pve-common previously already (silently) depended on the Net::LDAP library (see PVE::LDAP), but `libnet-ldap-perl` was missing in the control file - fix it while at it. Signed-off-by: Christoph Heiss --- Changes v1 -> v2: * No changes debian/control | 1 + src/PVE/JSONSchema.pm | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/debian/control b/debian/control index ac4cd66..53cbb57 100644 --- a/debian/control +++ b/debian/control @@ -34,6 +34,7 @@ Depends: libanyevent-perl, libmime-base32-perl, libnet-dbus-perl, libnet-ip-perl, + libnet-ldap-perl, libnetaddr-ip-perl, libproxmox-acme-perl, libproxmox-rs-perl, diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm index 7589bba..8238281 100644 --- a/src/PVE/JSONSchema.pm +++ b/src/PVE/JSONSchema.pm @@ -12,6 +12,7 @@ use PVE::Exception qw(raise); use HTTP::Status qw(:constants); use JSON; use Net::IP qw(:PROC); +use Net::LDAP::Util; use Data::Dumper; use base 'Exporter'; @@ -414,6 +415,17 @@ sub verify_ldap_simple_attr { return undef; } +PVE::JSONSchema::register_format('ldap-dn', \&verify_ldap_dn); +sub verify_ldap_dn { + my ($attr, $noerr) = @_; + + # canonical_dn() considers emtpy strings as valid DNs, so reject them explicitly. + return $attr if $attr ne '' && defined(Net::LDAP::Util::canonical_dn($attr)); + + die "value '$attr' does not look like a valid LDAP distinguished name\n" if !$noerr; + return undef; +} + my $ipv4_mask_hash = { '0.0.0.0' => 0, '128.0.0.0' => 1, -- 2.41.0