It seems I’m on a bit of a public folder theme of late. This script came up when I was working on the public folder audit log script unfortunately it was a little wasted but its still a useful sample of how you might go about finding the creator and public folder contacts of a public folder via WebDAV (or it should also work with Exoledb) using the XML security descriptors provided though the http://schemas.microsoft.com/exchange/security/ namespace. Documentation for the XML security descriptor can be found here . Also the appendix of the documentation that comes with Pfdavadmin is also very good if you trying to decode the descriptor.
Getting the Folder Creator
To get the folder creator via webdav this involves doing a propfind on the http://schemas.microsoft.com/exchange/security/creator property. You should then be able to parse the nt4_compatible_name from the XML that is returned to display the account that created the public folder. If you can’t get the nt4_compatible_name then you’ll have to work with the SID instead and do a resolution of this.
Get the Folder Contacts
This was the most challenging part of the script to determine if someone is a folder contact or not you have to check the DACL on the public folder itself. Although the folder_contact is not a security right in itself it still is part of the DACL acessmask. So to get this information via WebDAV you do a propfind on the http://schemas.microsoft.com/exchange/security/descriptor property which will return a XML representation of the DACL for that folder. You can use Pfdavadmin to have a look at what this will look like. The DACL contains the acessmasks that determine what rights a user has to a folder. Exchange DACL’s aren’t that straightforward however a really good description of the format that is used can be found in the pfdavadmin documentation. But basically you have 3 parts to the DACL usually the effective and subcontainer rights are the same and these make up the folder rights. And you also have the subitem rights. To work out if someone is a folder contact all you need to do is check on one of the folder rights parts. But within each of these parts there is a Allow access mask and a deny access mask which complicates things a little more. So you must remember to check both the allow and deny masks to come up with the right answer. When you retrieve the ACE’s themselves via WebDAV you get a Access Mask which represents that rights a user has on the folder. The format of an access mask is explained here . I never seen an explanation of what each of the bit values are for Exchange permissions but from what I can work out the bit that controls whether are user is a contact on the folder is 1000000000000000. So what I’ve made the script do is first convert the accessmask back into a 32 binary representation and then treating it like a string check to see if this bit is set in this string. The Deny access mask is also checked to see if this bit is set which would override any allow. This method is a little bit out there but does seem to work I would never however recommend you go about trying to set a DACL via this method which could spell very bad things for your store. You can use the XML descriptor to set permission but always use the documented access masks.
So the script to check the folder creator and contacts look like this I’ve put a downloadable copy here
set req = createobject("microsoft.xmlhttp")
folderurl = "http://servername/public/folder"
xmlreqtxt = "<?xml version='1.0'?><a:propfind xmlns:a='DAV:' xmlns:s='http://schemas.microsoft.com/exchange/security/'><a:prop><s:creator/></a:prop
></a:propfind>"
req.open "
PROPFIND", folderurl, false, "", ""
req.setRequestHeader "Content-Type", "text/xml; charset=""UTF-8"""
req.setRequestHeader "Depth", "0"
req.setRequestHeader "Translate", "f"
req.send xmlreqtxt
If req.status >= 500 Then
ElseIf req.status = 207 Then
set oResponseDoc = req.responseXML
set oNodeList = oResponseDoc.getElementsByTagName("S:nt4_compatible_name")
For i = 0 To (oNodeList.length -1)
set oNode = oNodeList.nextNode
wscript.echo "Folder Created By : " & oNode.text
next
end if
xmlreqtxt = "<?xml version='1.0'?><a:propfind xmlns:a='DAV:'
xmlns:s='http://schemas.microsoft.com/exchange/security/'
><a:prop><s:descriptor/></a:prop
></a:propfind>"
req.open "
PROPFIND", folderurl, false, "", ""
req.setRequestHeader "Content-Type", "text/xml; charset=""UTF-8"""
req.setRequestHeader "Depth", "0"
req.setRequestHeader "Translate", "f"
req.send xmlreqtxt
set oResponseDoc = req.responseXML
set oNodeList = oResponseDoc.getElementsByTagName("S:effective_aces")
set oNode = oNodeList.nextnode
set oNodeList1 =
oNode.selectnodes("S:access_allowed_ace/S:sid/S:nt4_compatible_name")
set oNodeList2 = oNode.selectnodes("S:access_allowed_ace/S:access_mask")
For nl = 1 To oNodeList1.length
set oNode1 = oNodeList1.nextnode
set oNode2 = oNodeList2.nextnode
binmask = getbinval(oNode2.Text)
if len(binmask) > 16 then
if mid(right(binmask,16),1,1) = 1 then
Contacts = Contacts & oNode1.Text & ","
end if
end if
Next
set oNodeList3 =
oNode.selectnodes("S:access_denied_ace/S:sid/S:nt4_compatible_name")
set oNodeList4 = oNode.selectnodes("S:access_denied_ace/S:access_mask")
For nl1 = 1 To oNodeList3.length
set oNode3 = oNodeList3.nextnode
set oNode4 = oNodeList4.nextnode
binmask = getbinval(oNode4.Text)
if len(binmask) > 16 then
if mid(right(binmask,16),1,1) = 1 then
Contacts = replace(Contacts,oNode3.Text & ",","")
end if
end if
Next
wscript.echo "Folder Contacts : " & Contacts
function getbinval(mask)
binval = " "
for bv = 1 to len(mask)
select case mid(mask,bv,1)
case "f" binval = binval & "1111"
case "e" binval = binval & "1110"
case "d" binval = binval & "1101"
case "c" binval = binval & "1100"
case "b" binval = binval & "1011"
case "a" binval = binval & "1010"
case "9" binval = binval & "1001"
case "8" binval = binval & "1000"
case "7" binval = binval & "0111"
case "6" binval = binval & "0110"
case "5" binval = binval & "0101"
case "4" binval = binval & "0100"
case "3" binval = binval & "0011"
case "2" binval = binval & "0010"
case "1" binval = binval & "0001"
case "0" binval = binval & "0000"
end select
next
getbinval = binval
end function
Getting the Folder Creator
To get the folder creator via webdav this involves doing a propfind on the http://schemas.microsoft.com/exchange/security/creator property. You should then be able to parse the nt4_compatible_name from the XML that is returned to display the account that created the public folder. If you can’t get the nt4_compatible_name then you’ll have to work with the SID instead and do a resolution of this.
Get the Folder Contacts
This was the most challenging part of the script to determine if someone is a folder contact or not you have to check the DACL on the public folder itself. Although the folder_contact is not a security right in itself it still is part of the DACL acessmask. So to get this information via WebDAV you do a propfind on the http://schemas.microsoft.com/exchange/security/descriptor property which will return a XML representation of the DACL for that folder. You can use Pfdavadmin to have a look at what this will look like. The DACL contains the acessmasks that determine what rights a user has to a folder. Exchange DACL’s aren’t that straightforward however a really good description of the format that is used can be found in the pfdavadmin documentation. But basically you have 3 parts to the DACL usually the effective and subcontainer rights are the same and these make up the folder rights. And you also have the subitem rights. To work out if someone is a folder contact all you need to do is check on one of the folder rights parts. But within each of these parts there is a Allow access mask and a deny access mask which complicates things a little more. So you must remember to check both the allow and deny masks to come up with the right answer. When you retrieve the ACE’s themselves via WebDAV you get a Access Mask which represents that rights a user has on the folder. The format of an access mask is explained here . I never seen an explanation of what each of the bit values are for Exchange permissions but from what I can work out the bit that controls whether are user is a contact on the folder is 1000000000000000. So what I’ve made the script do is first convert the accessmask back into a 32 binary representation and then treating it like a string check to see if this bit is set in this string. The Deny access mask is also checked to see if this bit is set which would override any allow. This method is a little bit out there but does seem to work I would never however recommend you go about trying to set a DACL via this method which could spell very bad things for your store. You can use the XML descriptor to set permission but always use the documented access masks.
So the script to check the folder creator and contacts look like this I’ve put a downloadable copy here
set req = createobject("microsoft.xmlhttp")
folderurl = "http://servername/public/folder"
xmlreqtxt = "<?xml version='1.0'?><a:propfind xmlns:a='DAV:' xmlns:s='http://schemas.microsoft.com/exchange/security/'><a:prop><s:creator/></a:prop
></a:propfind>"
req.open "
PROPFIND", folderurl, false, "", ""
req.setRequestHeader "Content-Type", "text/xml; charset=""UTF-8"""
req.setRequestHeader "Depth", "0"
req.setRequestHeader "Translate", "f"
req.send xmlreqtxt
If req.status >= 500 Then
ElseIf req.status = 207 Then
set oResponseDoc = req.responseXML
set oNodeList = oResponseDoc.getElementsByTagName("S:nt4_compatible_name")
For i = 0 To (oNodeList.length -1)
set oNode = oNodeList.nextNode
wscript.echo "Folder Created By : " & oNode.text
next
end if
xmlreqtxt = "<?xml version='1.0'?><a:propfind xmlns:a='DAV:'
xmlns:s='http://schemas.microsoft.com/exchange/security/'
><a:prop><s:descriptor/></a:prop
></a:propfind>"
req.open "
PROPFIND", folderurl, false, "", ""
req.setRequestHeader "Content-Type", "text/xml; charset=""UTF-8"""
req.setRequestHeader "Depth", "0"
req.setRequestHeader "Translate", "f"
req.send xmlreqtxt
set oResponseDoc = req.responseXML
set oNodeList = oResponseDoc.getElementsByTagName("S:effective_aces")
set oNode = oNodeList.nextnode
set oNodeList1 =
oNode.selectnodes("S:access_allowed_ace/S:sid/S:nt4_compatible_name")
set oNodeList2 = oNode.selectnodes("S:access_allowed_ace/S:access_mask")
For nl = 1 To oNodeList1.length
set oNode1 = oNodeList1.nextnode
set oNode2 = oNodeList2.nextnode
binmask = getbinval(oNode2.Text)
if len(binmask) > 16 then
if mid(right(binmask,16),1,1) = 1 then
Contacts = Contacts & oNode1.Text & ","
end if
end if
Next
set oNodeList3 =
oNode.selectnodes("S:access_denied_ace/S:sid/S:nt4_compatible_name")
set oNodeList4 = oNode.selectnodes("S:access_denied_ace/S:access_mask")
For nl1 = 1 To oNodeList3.length
set oNode3 = oNodeList3.nextnode
set oNode4 = oNodeList4.nextnode
binmask = getbinval(oNode4.Text)
if len(binmask) > 16 then
if mid(right(binmask,16),1,1) = 1 then
Contacts = replace(Contacts,oNode3.Text & ",","")
end if
end if
Next
wscript.echo "Folder Contacts : " & Contacts
function getbinval(mask)
binval = " "
for bv = 1 to len(mask)
select case mid(mask,bv,1)
case "f" binval = binval & "1111"
case "e" binval = binval & "1110"
case "d" binval = binval & "1101"
case "c" binval = binval & "1100"
case "b" binval = binval & "1011"
case "a" binval = binval & "1010"
case "9" binval = binval & "1001"
case "8" binval = binval & "1000"
case "7" binval = binval & "0111"
case "6" binval = binval & "0110"
case "5" binval = binval & "0101"
case "4" binval = binval & "0100"
case "3" binval = binval & "0011"
case "2" binval = binval & "0010"
case "1" binval = binval & "0001"
case "0" binval = binval & "0000"
end select
next
getbinval = binval
end function