Last active
August 29, 2015 14:00
-
-
Save nauzilus/56aab1602928481714e2 to your computer and use it in GitHub Desktop.
Inconvenient AnonymousPermMask64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$web = get-spweb $url | |
$list = $web.Lists["Documents"] | |
# get ready for some sneaky backdoor business | |
$flags=[Reflection.BindingFlags] "NonPublic,Instance" | |
$arr =[Microsoft.SharePoint.SPList].GetField("m_arrListProps", $flags).GetValue($list) | |
$i =[Microsoft.SharePoint.SPList].GetField("m_iRow", $flags).GetValue($list) | |
# make sure we're going to set some new value | |
$newMask = $null | |
$oldMask = $list.AnonymousPermMask64 | |
if ( $oldMask -eq "BrowseUserInfo" ) { | |
$newMask = [Microsoft.SharePoint.SPBasePermissions]::OpenItems | |
} | |
else { | |
$newMask = [Microsoft.SharePoint.SPBasePermissions]::BrowseUserInfo | |
} | |
function Dump([string]$msg) { | |
Write-Host "========== $msg" | |
Write-Host "Value " $list.AnonymousPermMask64 | |
Write-Host "IsNull " ($list.AnonymousPermMask64 -eq $null) | |
Write-Host "RawValue " $arr.Get(21,$i) | |
Write-Host "RawType " $arr.Get(21,$i).GetType() | |
Write-Host "RawAsLong " ([long] $arr.Get(21,$i)) | |
Write-Host "RawAsSPBP " ([Microsoft.SharePoint.SPBasePermissions]([long]$arr.Get(21,$i))) | |
} | |
Dump "Initial" | |
$list.AnonymousPermMask64 = $newMask | |
Dump "Set new value $($newMask)" | |
$list.Update() | |
Dump "SPList.Update()" | |
$arr.Set(21,$i,[long]$oldMask) | |
Dump "Raw set cast new value $([long]$oldMask) ($oldMask)" | |
$list.AnonymousPermMask64 = $newMask # cleapup (raw-set leaves in consistent state) | |
$list.Update() | |
$list.AnonymousPermMask64 = $oldMask | |
$web = Get-SPWeb $web.Url | |
$list = $web.Lists[$list.ID] | |
Dump "Set ($oldMask), reload web/list without Update()" | |
<# | |
========== Initial | |
Value BrowseUserInfo | |
IsNull False | |
RawValue 134217728 | |
RawType System.Int64 | |
RawAsLong 134217728 | |
RawAsSPBP BrowseUserInfo | |
========== Set new value OpenItems | |
Value | |
IsNull True | |
RawValue OpenItems | |
RawType Microsoft.SharePoint.SPBasePermissions | |
RawAsLong 32 | |
RawAsSPBP OpenItems | |
========== SPList.Update() | |
Value OpenItems | |
IsNull False | |
RawValue 32 | |
RawType System.Int64 | |
RawAsLong 32 | |
RawAsSPBP OpenItems | |
========== Raw set cast new value 134217728 (BrowseUserInfo) | |
Value BrowseUserInfo | |
IsNull False | |
RawValue 134217728 | |
RawType System.Int64 | |
RawAsLong 134217728 | |
RawAsSPBP BrowseUserInfo | |
========== Set (BrowseUserInfo), reload web/list without Update() | |
Value BrowseUserInfo | |
IsNull False | |
RawValue BrowseUserInfo | |
RawType Microsoft.SharePoint.SPBasePermissions | |
RawAsLong 134217728 | |
RawAsSPBP BrowseUserInfo | |
#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment