Rechten op folders en bestanden
- Microsoft gebruikt ACLs
- Lijsten die bepalen wie ergens toegang toe heeft:
- Gebruiker A heeft lees- en schrijfrechten
- Gebruiker B heeft leesrechten
- Gebruiker C heeft lees-, schrijf- en verwijderrechten
Objecten
- Alles is een object
- Dus de ACL (list) is een object
- Maar elke rule in de lijst is ook een object
- Je hebt objecten in objecten
ACL properties
$DocACL | Get-Member -MemberType Property
TypeName: System.Security.AccessControl.FileSecurity
Name MemberType Definition
---- ---------- ----------
AccessRightType Property type AccessRightType {get;}
AccessRuleType Property type AccessRuleType {get;}
AreAccessRulesCanonical Property bool AreAccessRulesCanonical {get;}
AreAccessRulesProtected Property bool AreAccessRulesProtected {get;}
AreAuditRulesCanonical Property bool AreAuditRulesCanonical {get;}
AreAuditRulesProtected Property bool AreAuditRulesProtected {get;}
AuditRuleType Property type AuditRuleType {get;}
ACL methods
$DocACL | Get-Member -MemberType Method
TypeName: System.Security.AccessControl.FileSecurity
Name MemberType Definition
---- ---------- ----------
AddAccessRule Method void AddAccessRule(System.Security.AccessControl.FileSystemAccessRule rule)
ModifyAccessRule Method bool ModifyAccessRule(System.Security.AccessControl.AccessControlModifica...
PurgeAccessRules Method void PurgeAccessRules(System.Security.Principal.IdentityReference identity)
RemoveAccessRule Method bool RemoveAccessRule(System.Security.AccessControl.FileSystemAccessRule ...
RemoveAccessRuleAll Method void RemoveAccessRuleAll(System.Security.AccessControl.FileSystemAccessRu...
RemoveAccessRuleSpecific Method void RemoveAccessRuleSpecific(System.Security.AccessControl.FileSystemAcc...
ResetAccessRule Method void ResetAccessRule(System.Security.AccessControl.FileSystemAccessRule r...
SetAccessRule Method void SetAccessRule(System.Security.AccessControl.FileSystemAccessRule rule)
SetGroup Method void SetGroup(System.Security.Principal.IdentityReference identity)
SetOwner Method void SetOwner(System.Security.Principal.IdentityReference identity)
Wijzigen Owner
Opvragen eigen gegevens:
whoami
denniswin11\dleeu
Wijzigen ACL owner:
$NewOwner = New-Object \
System.Security.Principal.NTAccount("denniswin11", "dleeu")
$DocACL.SetOwner($NewOwner)
Wijzigen ACLs
# Files to work on
$Source = "C:\Pets\Dog.txt"
$Destination = "C:\Pets\Dog.txt"
# Haal de ACLs op
$NewAcl = Get-Acl -Path $Source
# New properties
$identity = "BUILTIN\Administrators"
$fileSystemRights = "FullControl"
$type = "Allow"
# Create new rule
$newParams = @{
TypeName = 'System.Security.AccessControl.FileSystemAccessRule'
ArgumentList = $identity, $fileSystemRights, $type
}
$fileSystemAccessRule = New-Object @newParams
# Apply new rule
$NewAcl.SetAccessRule($fileSystemAccessRule)
Set-Acl -Path $Destination -AclObject $NewAcl