1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7#[non_exhaustive]
8pub enum SamAccountType {
9 DomainObject,
11 GroupObject,
13 NonSecurityGroupObject,
15 AliasObject,
17 NonSecurityAliasObject,
19 NormalUserAccount,
21 MachineAccount,
23 TrustAccount,
25 AppBasicGroup,
27 AppQueryGroup,
29 Unknown(u32),
31}
32
33impl SamAccountType {
34 pub fn from_bits(v: u32) -> Self {
36 match v {
37 0x0000_0000 => SamAccountType::DomainObject,
38 0x1000_0000 => SamAccountType::GroupObject,
39 0x1000_0001 => SamAccountType::NonSecurityGroupObject,
40 0x2000_0000 => SamAccountType::AliasObject,
41 0x2000_0001 => SamAccountType::NonSecurityAliasObject,
42 0x3000_0000 => SamAccountType::NormalUserAccount,
43 0x3000_0001 => SamAccountType::MachineAccount,
44 0x3000_0002 => SamAccountType::TrustAccount,
45 0x4000_0000 => SamAccountType::AppBasicGroup,
46 0x4000_0001 => SamAccountType::AppQueryGroup,
47 other => SamAccountType::Unknown(other),
48 }
49 }
50
51 pub fn has_password(self) -> bool {
53 matches!(
54 self,
55 SamAccountType::NormalUserAccount
56 | SamAccountType::MachineAccount
57 | SamAccountType::TrustAccount
58 )
59 }
60}
61
62#[cfg(test)]
63mod tests {
64 use super::*;
65
66 #[test]
67 fn decode_common_values() {
68 assert_eq!(
69 SamAccountType::from_bits(0x3000_0000),
70 SamAccountType::NormalUserAccount
71 );
72 assert_eq!(
73 SamAccountType::from_bits(0x3000_0001),
74 SamAccountType::MachineAccount
75 );
76 assert_eq!(
77 SamAccountType::from_bits(0x1000_0000),
78 SamAccountType::GroupObject
79 );
80 }
81
82 #[test]
83 fn unknown_preserved() {
84 let v = 0xdead_beef;
85 assert_eq!(SamAccountType::from_bits(v), SamAccountType::Unknown(v));
86 }
87
88 #[test]
89 fn only_user_computer_trust_have_password() {
90 assert!(SamAccountType::NormalUserAccount.has_password());
91 assert!(SamAccountType::MachineAccount.has_password());
92 assert!(SamAccountType::TrustAccount.has_password());
93 assert!(!SamAccountType::GroupObject.has_password());
94 assert!(!SamAccountType::AliasObject.has_password());
95 }
96}