smb_dtyp/security/
security_descriptor.rs

1//! MS-DTYP 2.4.6: Security Descriptor
2
3use binrw::prelude::*;
4use modular_bitfield::prelude::*;
5
6use crate::binrw_util::prelude::*;
7
8use super::{ACL, SID};
9
10/// Security Descriptor - [MS-DTYP 2.4.6](<https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-dtyp/7d4dac05-9cef-4563-a058-f108abecce1d>)
11#[binrw::binrw]
12#[derive(Debug, PartialEq, Eq, Clone)]
13#[brw(little)]
14pub struct SecurityDescriptor {
15    #[bw(calc = PosMarker::default())]
16    _sd_begin: PosMarker<()>,
17
18    #[bw(calc = 1)]
19    #[br(assert(_revision == 1))]
20    _revision: u8,
21    pub sbz1: u8,
22    #[brw(assert(control.self_relative()))]
23    pub control: SecurityDescriptorControl,
24
25    #[bw(calc = PosMarker::default())]
26    offset_owner: PosMarker<u32>,
27    #[bw(calc = PosMarker::default())]
28    offset_group: PosMarker<u32>,
29    #[bw(calc = PosMarker::default())]
30    offset_sacl: PosMarker<u32>,
31    #[bw(calc = PosMarker::default())]
32    offset_dacl: PosMarker<u32>,
33
34    #[br(if(offset_owner.value != 0))]
35    #[bw(if(owner_sid.is_some()))]
36    #[bw(write_with = PosMarker::write_roff_b, args(&offset_owner, &_sd_begin))]
37    pub owner_sid: Option<SID>,
38
39    #[br(if(offset_group.value != 0))]
40    #[bw(if(group_sid.is_some()))]
41    #[bw(write_with = PosMarker::write_roff_b, args(&offset_group, &_sd_begin))]
42    pub group_sid: Option<SID>,
43
44    #[bw(assert(sacl.is_some() == control.sacl_present()))]
45    #[br(assert((offset_sacl.value != 0) == (control.sacl_present())))]
46    #[bw(if(sacl.is_some()))]
47    #[bw(write_with = PosMarker::write_roff_b, args(&offset_sacl, &_sd_begin))]
48    #[br(if(offset_sacl.value != 0))]
49    pub sacl: Option<ACL>,
50
51    #[bw(assert(dacl.is_some() == control.dacl_present()))]
52    #[br(assert((offset_dacl.value != 0) == control.dacl_present()))]
53    #[bw(if(dacl.is_some()))]
54    #[bw(write_with = PosMarker::write_roff_b, args(&offset_dacl, &_sd_begin))]
55    #[br(if(offset_dacl.value != 0))]
56    pub dacl: Option<ACL>,
57}
58
59#[bitfield]
60#[derive(BinWrite, BinRead, Debug, Default, Clone, Copy, PartialEq, Eq)]
61#[bw(map = |&x| Self::into_bytes(x))]
62#[br(map = Self::from_bytes)]
63pub struct SecurityDescriptorControl {
64    pub owner_defaulted: bool,
65    pub group_defaulted: bool,
66    pub dacl_present: bool,
67    pub dacl_defaulted: bool,
68
69    pub sacl_present: bool,
70    pub sacl_defaulted: bool,
71    pub dacl_trusted: bool,
72    pub server_security: bool,
73
74    pub dacl_computed: bool,
75    pub sacl_computed: bool,
76    pub dacl_auto_inherited: bool,
77    pub sacl_auto_inherited: bool,
78
79    pub dacl_protected: bool,
80    pub sacl_protected: bool,
81    pub rm_control_valid: bool,
82    pub self_relative: bool,
83}