use windows_sddl::sid::Guid;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum GuidClass {
ExtendedRight,
Attribute,
ValidatedWrite,
}
pub struct KnownGuid {
pub name: &'static str,
pub class: GuidClass,
guid: &'static str,
}
impl KnownGuid {
const fn new(name: &'static str, class: GuidClass, guid: &'static str) -> Self {
KnownGuid { name, class, guid }
}
pub fn guid(&self) -> Guid {
Guid::parse(self.guid).expect("static catalog GUID is valid")
}
pub fn matches(&self, g: &Guid) -> bool {
self.guid() == *g
}
}
use GuidClass::{Attribute, ExtendedRight, ValidatedWrite};
pub const REPL_GET_CHANGES: KnownGuid = KnownGuid::new(
"DS-Replication-Get-Changes",
ExtendedRight,
"1131f6aa-9c07-11d1-f79f-00c04fc2dcd2",
);
pub const REPL_GET_CHANGES_ALL: KnownGuid = KnownGuid::new(
"DS-Replication-Get-Changes-All",
ExtendedRight,
"1131f6ad-9c07-11d1-f79f-00c04fc2dcd2",
);
pub const REPL_GET_CHANGES_FILTERED: KnownGuid = KnownGuid::new(
"DS-Replication-Get-Changes-In-Filtered-Set",
ExtendedRight,
"89e95b76-444d-4c62-991a-0facbeda640c",
);
pub const FORCE_CHANGE_PASSWORD: KnownGuid = KnownGuid::new(
"User-Force-Change-Password",
ExtendedRight,
"00299570-246d-11d0-a768-00aa006e0529",
);
pub const REANIMATE_TOMBSTONES: KnownGuid = KnownGuid::new(
"Reanimate-Tombstones",
ExtendedRight,
"45ec5156-db7e-47bb-b53f-dbeb2d03c40f",
);
pub const ENROLLMENT: KnownGuid = KnownGuid::new(
"Certificate-Enrollment",
ExtendedRight,
"0e10c968-78fb-11d2-90d4-00c04f79dc55",
);
pub const AUTO_ENROLLMENT: KnownGuid = KnownGuid::new(
"Certificate-AutoEnrollment",
ExtendedRight,
"a05b8cc2-17bc-4802-a710-e7c15ab866a2",
);
pub const MEMBER: KnownGuid =
KnownGuid::new("member", Attribute, "bf9679c0-0de6-11d0-a285-00aa003049e2");
pub const KEY_CREDENTIAL_LINK: KnownGuid = KnownGuid::new(
"msDS-KeyCredentialLink",
Attribute,
"5b47d60f-6090-40b2-9f37-2a4de88f3063",
);
pub const RBCD: KnownGuid = KnownGuid::new(
"msDS-AllowedToActOnBehalfOfOtherIdentity",
Attribute,
"3f78c3e5-f79a-46bd-a0b8-9d18116ddc79",
);
pub const SPN: KnownGuid = KnownGuid::new(
"servicePrincipalName",
Attribute,
"f3a64788-5306-11d1-a9c5-0000f80367c1",
);
pub const ALT_SECURITY_IDENTITIES: KnownGuid = KnownGuid::new(
"altSecurityIdentities",
Attribute,
"00fbf30c-91fe-11d1-aebc-0000f80367c1",
);
pub const ALLOWED_TO_DELEGATE_TO: KnownGuid = KnownGuid::new(
"msDS-AllowedToDelegateTo",
Attribute,
"800d94d7-b7a1-42a1-b14d-7cae1423d07f",
);
pub const GP_LINK: KnownGuid =
KnownGuid::new("gPLink", Attribute, "f30e3bbe-9ff0-11d1-b603-0000f80367c1");
pub const SELF_MEMBERSHIP: KnownGuid = KnownGuid::new(
"Self-Membership",
ValidatedWrite,
"bf9679c0-0de6-11d0-a285-00aa003049e2",
);
pub const VALIDATED_SPN: KnownGuid = KnownGuid::new(
"Validated-SPN",
ValidatedWrite,
"f3a64788-5306-11d1-a9c5-0000f80367c1",
);
pub const ALL: &[&KnownGuid] = &[
&REPL_GET_CHANGES,
&REPL_GET_CHANGES_ALL,
&REPL_GET_CHANGES_FILTERED,
&FORCE_CHANGE_PASSWORD,
&REANIMATE_TOMBSTONES,
&ENROLLMENT,
&AUTO_ENROLLMENT,
&MEMBER,
&KEY_CREDENTIAL_LINK,
&RBCD,
&SPN,
&ALT_SECURITY_IDENTITIES,
&ALLOWED_TO_DELEGATE_TO,
&GP_LINK,
];
pub fn name_of(g: &Guid, class: GuidClass) -> Option<&'static str> {
if class == ValidatedWrite {
for k in [&SELF_MEMBERSHIP, &VALIDATED_SPN] {
if k.matches(g) {
return Some(k.name);
}
}
}
ALL.iter()
.find(|k| k.class == class && k.matches(g))
.map(|k| k.name)
}
pub fn is_replication_right(g: &Guid) -> bool {
REPL_GET_CHANGES.matches(g)
|| REPL_GET_CHANGES_ALL.matches(g)
|| REPL_GET_CHANGES_FILTERED.matches(g)
}
pub fn is_enrollment_right(g: &Guid) -> bool {
ENROLLMENT.matches(g) || AUTO_ENROLLMENT.matches(g)
}