]> git.proxmox.com Git - pve-access-control.git/commitdiff
auth: pull username REs into variables
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Thu, 21 Nov 2019 14:43:24 +0000 (15:43 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 14 Jan 2020 11:28:13 +0000 (12:28 +0100)
for reusage in API token ID format/verification

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
PVE/Auth/Plugin.pm

index 5c11991b8735d3dd7cd084b460eebda5dd76ced9..6d59b720d5580d58805091041ad2ef53f89deadb 100755 (executable)
@@ -27,7 +27,8 @@ sub lock_domain_config {
     }
 }
 
-my $realm_regex = qr/[A-Za-z][A-Za-z0-9\.\-_]+/;
+our $realm_regex = qr/[A-Za-z][A-Za-z0-9\.\-_]+/;
+our $user_regex = qr![^\s:/]+!;
 
 PVE::JSONSchema::register_format('pve-realm', \&pve_verify_realm);
 sub pve_verify_realm {
@@ -66,7 +67,7 @@ sub verify_username {
     # colon separated lists)!
     # slash is not allowed because it is used as pve API delimiter
     # also see "man useradd"
-    if ($username =~ m!^([^\s:/]+)\@(${realm_regex})$!) {
+    if ($username =~ m!^(${user_regex})\@(${realm_regex})$!) {
        return wantarray ? ($username, $1, $2) : $username;
     }