forked from proxmox-mirrors/proxmox
proxmox-auth-api: use const_format to define static strings
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
parent
0c5e2640d0
commit
a6f1b36fa6
@ -14,7 +14,7 @@ required-features = [ "pam-authenticator" ]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
|
const_format = { workspace = true, optional = true }
|
||||||
base64 = { workspace = true, optional = true }
|
base64 = { workspace = true, optional = true }
|
||||||
lazy_static = { workspace = true, optional = true }
|
lazy_static = { workspace = true, optional = true }
|
||||||
libc = { workspace = true, optional = true }
|
libc = { workspace = true, optional = true }
|
||||||
@ -37,7 +37,7 @@ proxmox-tfa = { workspace = true, optional = true, features = [ "api" ] }
|
|||||||
default = []
|
default = []
|
||||||
|
|
||||||
ticket = [ "dep:base64", "dep:percent-encoding", "dep:openssl" ]
|
ticket = [ "dep:base64", "dep:percent-encoding", "dep:openssl" ]
|
||||||
api-types = [ "dep:lazy_static", "dep:regex", "dep:serde", "dep:serde_plain", "dep:proxmox-schema" ]
|
api-types = [ "dep:const_format", "dep:lazy_static", "dep:regex", "dep:serde", "dep:serde_plain", "dep:proxmox-schema" ]
|
||||||
api = [
|
api = [
|
||||||
"api-types",
|
"api-types",
|
||||||
"ticket",
|
"ticket",
|
||||||
|
@ -27,62 +27,36 @@ use std::fmt;
|
|||||||
use anyhow::{bail, format_err, Error};
|
use anyhow::{bail, format_err, Error};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use const_format::concatcp;
|
||||||
|
|
||||||
use proxmox_schema::{
|
use proxmox_schema::{
|
||||||
api, const_regex, ApiStringFormat, ApiType, Schema, StringSchema, UpdaterType,
|
api, const_regex, ApiStringFormat, ApiType, Schema, StringSchema, UpdaterType,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use proxmox_schema::api_types::SAFE_ID_REGEX_STR;
|
||||||
|
|
||||||
// we only allow a limited set of characters
|
// we only allow a limited set of characters
|
||||||
// colon is not allowed, because we store usernames in
|
// colon is not allowed, because we store usernames in
|
||||||
// colon separated lists)!
|
// colon separated lists)!
|
||||||
// slash is not allowed because it is used as pve API delimiter
|
// slash is not allowed because it is used as pve API delimiter
|
||||||
// also see "man useradd"
|
// also see "man useradd"
|
||||||
#[macro_export]
|
pub const USER_NAME_REGEX_STR: &str = r"(?:[^\s:/[:cntrl:]]+)";
|
||||||
macro_rules! USER_NAME_REGEX_STR {
|
|
||||||
() => {
|
pub const GROUP_NAME_REGEX_STR: &str = USER_NAME_REGEX_STR;
|
||||||
r"(?:[^\s:/[:cntrl:]]+)"
|
|
||||||
};
|
pub const TOKEN_NAME_REGEX_STR: &str = SAFE_ID_REGEX_STR;
|
||||||
}
|
|
||||||
#[macro_export]
|
pub const USER_ID_REGEX_STR: &str = concatcp!(USER_NAME_REGEX_STR, r"@", SAFE_ID_REGEX_STR);
|
||||||
macro_rules! GROUP_NAME_REGEX_STR {
|
|
||||||
() => {
|
pub const APITOKEN_ID_REGEX_STR: &str = concatcp!(USER_ID_REGEX_STR, r"!", TOKEN_NAME_REGEX_STR);
|
||||||
$crate::USER_NAME_REGEX_STR!()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! TOKEN_NAME_REGEX_STR {
|
|
||||||
() => {
|
|
||||||
proxmox_schema::SAFE_ID_REGEX_STR!()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! USER_ID_REGEX_STR {
|
|
||||||
() => {
|
|
||||||
concat!(
|
|
||||||
$crate::USER_NAME_REGEX_STR!(),
|
|
||||||
r"@",
|
|
||||||
proxmox_schema::SAFE_ID_REGEX_STR!()
|
|
||||||
)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! APITOKEN_ID_REGEX_STR {
|
|
||||||
() => {
|
|
||||||
concat!(
|
|
||||||
$crate::USER_ID_REGEX_STR!(),
|
|
||||||
r"!",
|
|
||||||
$crate::TOKEN_NAME_REGEX_STR!()
|
|
||||||
)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const_regex! {
|
const_regex! {
|
||||||
pub PROXMOX_USER_NAME_REGEX = concat!(r"^", USER_NAME_REGEX_STR!(), r"$");
|
pub PROXMOX_USER_NAME_REGEX = concatcp!(r"^", USER_NAME_REGEX_STR, r"$");
|
||||||
pub PROXMOX_TOKEN_NAME_REGEX = concat!(r"^", TOKEN_NAME_REGEX_STR!(), r"$");
|
pub PROXMOX_TOKEN_NAME_REGEX = concatcp!(r"^", TOKEN_NAME_REGEX_STR, r"$");
|
||||||
pub PROXMOX_USER_ID_REGEX = concat!(r"^", USER_ID_REGEX_STR!(), r"$");
|
pub PROXMOX_USER_ID_REGEX = concatcp!(r"^", USER_ID_REGEX_STR, r"$");
|
||||||
pub PROXMOX_APITOKEN_ID_REGEX = concat!(r"^", APITOKEN_ID_REGEX_STR!(), r"$");
|
pub PROXMOX_APITOKEN_ID_REGEX = concatcp!(r"^", APITOKEN_ID_REGEX_STR, r"$");
|
||||||
pub PROXMOX_AUTH_ID_REGEX = concat!(r"^", r"(?:", USER_ID_REGEX_STR!(), r"|", APITOKEN_ID_REGEX_STR!(), r")$");
|
pub PROXMOX_AUTH_ID_REGEX = concatcp!(r"^", r"(?:", USER_ID_REGEX_STR, r"|", APITOKEN_ID_REGEX_STR, r")$");
|
||||||
pub PROXMOX_GROUP_ID_REGEX = concat!(r"^", GROUP_NAME_REGEX_STR!(), r"$");
|
pub PROXMOX_GROUP_ID_REGEX = concatcp!(r"^", GROUP_NAME_REGEX_STR, r"$");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const PROXMOX_USER_NAME_FORMAT: ApiStringFormat =
|
pub const PROXMOX_USER_NAME_FORMAT: ApiStringFormat =
|
||||||
|
Loading…
Reference in New Issue
Block a user