]> git.proxmox.com Git - proxmox.git/commitdiff
tfa: include lockout status in the tfa user list
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 1 Jun 2023 10:22:18 +0000 (12:22 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 1 Jun 2023 10:22:18 +0000 (12:22 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
proxmox-tfa/src/api/methods.rs
proxmox-tfa/src/api/mod.rs

index 452c7d4dc60a016e090523a6cee02c6d050c7cec..a7d5deebbe069f121744fa24ba7eff77b73be1d0 100644 (file)
@@ -203,7 +203,7 @@ pub fn unlock_tfa(config: &mut TfaConfig, userid: &str) -> Result<bool, Error> {
     },
 ))]
 #[derive(Deserialize, Serialize)]
-#[serde(deny_unknown_fields)]
+#[serde(deny_unknown_fields, rename_all = "kebab-case")]
 /// Over the API we only provide the descriptions for TFA data.
 pub struct TfaUser {
     /// The user this entry belongs to.
@@ -211,6 +211,14 @@ pub struct TfaUser {
 
     /// TFA entries.
     entries: Vec<TypedTfaInfo>,
+
+    /// The user is locked out of TOTP authentication.
+    #[serde(skip_serializing_if = "super::bool_is_false")]
+    totp_locked: bool,
+
+    /// If a user's second factor is blocked, this contains the block's expiration time.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    tfa_locked_until: Option<i64>,
 }
 
 /// API call implementation for `GET /access/tfa`.
@@ -223,18 +231,24 @@ pub fn list_tfa(
 ) -> Result<Vec<TfaUser>, Error> {
     let tfa_data = &config.users;
 
+    let now = proxmox_time::epoch_i64();
+
     let mut out = Vec::<TfaUser>::new();
     if top_level_allowed {
         for (user, data) in tfa_data {
             out.push(TfaUser {
                 userid: user.clone(),
                 entries: to_data(data),
+                totp_locked: data.totp_locked,
+                tfa_locked_until: data.tfa_locked_until.filter(|&t| t > now),
             });
         }
     } else if let Some(data) = { tfa_data }.get(authid) {
         out.push(TfaUser {
             userid: authid.into(),
             entries: to_data(data),
+            totp_locked: data.totp_locked,
+            tfa_locked_until: data.tfa_locked_until.filter(|&t| t > now),
         });
     }
 
index 9c0227dabbcd59a0942fbfac70664bf1ce16909d..bf5d888e7cc0d8a02bf89ff8ca6c989503a6a74e 100644 (file)
@@ -1211,7 +1211,7 @@ impl TfaChallenge {
     }
 }
 
-fn bool_is_false(v: &bool) -> bool {
+pub(self) fn bool_is_false(v: &bool) -> bool {
     !v
 }