#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct Uac {
pub script: bool,
pub account_disable: bool,
pub homedir_required: bool,
pub lockout: bool,
pub passwd_notreqd: bool,
pub passwd_cant_change: bool,
pub encrypted_text_pwd_allowed: bool,
pub temp_duplicate_account: bool,
pub normal_account: bool,
pub interdomain_trust_account: bool,
pub workstation_trust_account: bool,
pub server_trust_account: bool,
pub dont_expire_password: bool,
pub mns_logon_account: bool,
pub smartcard_required: bool,
pub trusted_for_delegation: bool,
pub not_delegated: bool,
pub use_des_key_only: bool,
pub dont_req_preauth: bool,
pub password_expired: bool,
pub trusted_to_auth_for_delegation: bool,
pub partial_secrets_account: bool,
}
impl Uac {
pub fn from_bits(v: u32) -> Self {
Uac {
script: v & 0x0000_0001 != 0,
account_disable: v & 0x0000_0002 != 0,
homedir_required: v & 0x0000_0008 != 0,
lockout: v & 0x0000_0010 != 0,
passwd_notreqd: v & 0x0000_0020 != 0,
passwd_cant_change: v & 0x0000_0040 != 0,
encrypted_text_pwd_allowed: v & 0x0000_0080 != 0,
temp_duplicate_account: v & 0x0000_0100 != 0,
normal_account: v & 0x0000_0200 != 0,
interdomain_trust_account: v & 0x0000_0800 != 0,
workstation_trust_account: v & 0x0000_1000 != 0,
server_trust_account: v & 0x0000_2000 != 0,
dont_expire_password: v & 0x0001_0000 != 0,
mns_logon_account: v & 0x0002_0000 != 0,
smartcard_required: v & 0x0004_0000 != 0,
trusted_for_delegation: v & 0x0008_0000 != 0,
not_delegated: v & 0x0010_0000 != 0,
use_des_key_only: v & 0x0020_0000 != 0,
dont_req_preauth: v & 0x0040_0000 != 0,
password_expired: v & 0x0080_0000 != 0,
trusted_to_auth_for_delegation: v & 0x0100_0000 != 0,
partial_secrets_account: v & 0x0400_0000 != 0,
}
}
pub fn not_smartcard_only(&self) -> bool {
!self.smartcard_required
}
pub fn asreproast_eligible(&self) -> bool {
self.dont_req_preauth
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn typical_normal_user_bits() {
let u = Uac::from_bits(0x10200);
assert!(u.normal_account);
assert!(u.dont_expire_password);
assert!(!u.account_disable);
assert!(!u.dont_req_preauth);
}
#[test]
fn disabled_and_asreproast_ready() {
let u = Uac::from_bits(0x400002);
assert!(u.account_disable);
assert!(u.dont_req_preauth);
assert!(u.asreproast_eligible());
}
#[test]
fn dc_computer_account() {
let u = Uac::from_bits(0x82000);
assert!(u.server_trust_account);
assert!(u.trusted_for_delegation);
}
#[test]
fn not_smartcard_only_gate() {
let normal = Uac::from_bits(0x200);
assert!(normal.not_smartcard_only());
let sc_only = Uac::from_bits(0x200 | 0x40000);
assert!(!sc_only.not_smartcard_only());
}
}