Skip to main content

Displaying a Public Folders Creator and Folder Contacts via WebDAV

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

Popular posts from this blog

The MailboxConcurrency limit and using Batching in the Microsoft Graph API

If your getting an error such as Application is over its MailboxConcurrency limit while using the Microsoft Graph API this post may help you understand why. Background   The Mailbox  concurrency limit when your using the Graph API is 4 as per https://docs.microsoft.com/en-us/graph/throttling#outlook-service-limits . This is evaluated for each app ID and mailbox combination so this means you can have different apps running under the same credentials and the poor behavior of one won't cause the other to be throttled. If you compared that to EWS you could have up to 27 concurrent connections but they are shared across all apps on a first come first served basis. Batching Batching in the Graph API is a way of combining multiple requests into a single HTTP request. Batching in the Exchange Mail API's EWS and MAPI has been around for a long time and its common, for email Apps to process large numbers of smaller items for a variety of reasons.  Batching in the Graph is limited to a m

Sending a Message in Exchange Online via REST from an Arduino MKR1000

This is part 2 of my MKR1000 article, in this previous post  I looked at sending a Message via EWS using Basic Authentication.  In this Post I'll look at using the new Outlook REST API  which requires using OAuth authentication to get an Access Token. The prerequisites for this sketch are the same as in the other post with the addition of the ArduinoJson library  https://github.com/bblanchon/ArduinoJson  which is used to parse the Authentication Results to extract the Access Token. Also the SSL certificates for the login.windows.net  and outlook.office365.com need to be uploaded to the devices using the wifi101 Firmware updater. To use Token Authentication you need to register an Application in Azure https://msdn.microsoft.com/en-us/office/office365/howto/add-common-consent-manually  with the Mail.Send permission. The application should be a Native Client app that use the Out of Band Callback urn:ietf:wg:oauth:2.0:oob. You need to authorize it in you tenant (eg build a small ap

How to test SMTP using Opportunistic TLS with Powershell and grab the public certificate a SMTP server is using

Most email services these day employ Opportunistic TLS when trying to send Messages which means that wherever possible the Messages will be encrypted rather then the plain text legacy of SMTP.  This method was defined in RFC 3207 "SMTP Service Extension for Secure SMTP over Transport Layer Security" and  there's a quite a good explanation of Opportunistic TLS on Wikipedia  https://en.wikipedia.org/wiki/Opportunistic_TLS .  This is used for both Server to Server (eg MTA to MTA) and Client to server (Eg a Message client like Outlook which acts as a MSA) the later being generally Authenticated. Basically it allows you to have a normal plain text SMTP conversation that is then upgraded to TLS using the STARTTLS verb. Not all servers will support this verb so if its not supported then a message is just sent as Plain text. TLS relies on PKI certificates and the administrative issue s that come around certificate management like expired certificates which is why I wrote th
All sample scripts and source code is provided by for illustrative purposes only. All examples are untested in different environments and therefore, I cannot guarantee or imply reliability, serviceability, or function of these programs.

All code contained herein is provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.