From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <g.goller@proxmox.com>
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) server-digest SHA256)
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id DA27E913C1
 for <pmg-devel@lists.proxmox.com>; Wed, 14 Feb 2024 10:15:08 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id C28494D6
 for <pmg-devel@lists.proxmox.com>; Wed, 14 Feb 2024 10:15:08 +0100 (CET)
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 <pmg-devel@lists.proxmox.com>; Wed, 14 Feb 2024 10:15:08 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id CC49D48104
 for <pmg-devel@lists.proxmox.com>; Wed, 14 Feb 2024 10:15:07 +0100 (CET)
From: Gabriel Goller <g.goller@proxmox.com>
To: pmg-devel@lists.proxmox.com
Date: Wed, 14 Feb 2024 10:15:01 +0100
Message-ID: <20240214091503.16979-1-g.goller@proxmox.com>
X-Mailer: git-send-email 2.43.0
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.104 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. [utils.pm, proxmox.com]
Subject: [pmg-devel] [PATCH] utils: cleanup username/userid regex and verify
X-BeenThere: pmg-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Mail Gateway development discussion
 <pmg-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pmg-devel>, 
 <mailto:pmg-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pmg-devel/>
List-Post: <mailto:pmg-devel@lists.proxmox.com>
List-Help: <mailto:pmg-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel>, 
 <mailto:pmg-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Wed, 14 Feb 2024 09:15:08 -0000

Cleaned up the verify_username function and userid regex after the
recent changes to minLength have been applied [0].

[0]: https://lists.proxmox.com/pipermail/pmg-devel/2023-September/002521.html

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
 src/PMG/Utils.pm | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/PMG/Utils.pm b/src/PMG/Utils.pm
index 12b3ed5..8f7d438 100644
--- a/src/PMG/Utils.pm
+++ b/src/PMG/Utils.pm
@@ -72,13 +72,12 @@ PVE::JSONSchema::register_standard_option('pmg-endtime', {
     optional => 1,
 });
 
-PVE::JSONSchema::register_format('pmg-userid', \&verify_username);
 sub verify_username {
     my ($username, $noerr) = @_;
 
     $username = '' if !$username;
     my $len = length($username);
-    if ($len < 3) {
+    if ($len < 1) {
 	die "user name '$username' is too short\n" if !$noerr;
 	return undef;
     }
@@ -102,8 +101,8 @@ sub verify_username {
 
 PVE::JSONSchema::register_standard_option('userid', {
     description => "User ID",
-    type => 'string', format => 'pmg-userid',
-    minLength => 4,
+    type => 'string',
+    pattern => '[^\s:\/]{1,60}',
     maxLength => 64,
 });
 
-- 
2.43.0