KSM
KSM

Reputation: 252

How to read msExchMailboxSecurityDescriptor attribute in C#

I am trying to read all the user attributes in AD.

How to read msExchMailboxSecurityDescriptor attribute in C# ?

I used the following code but I got a cast error. Any suggestions would be welcome.

  DirectoryObjectSecurity oSec = new ActiveDirectorySecurity();
  oSec.SetSecurityDescriptorBinaryForm((byte[])val);

  String m_Value = oSec.GetSecurityDescriptorSddlForm(AccessControlSections.All); 
  return m_Value; 

Upvotes: 3

Views: 4851

Answers (1)

KSM
KSM

Reputation: 252

Ok. I was able to figure it out. The code is given below for anyone interested. I wish Microsoft had put out some code samples so that people do not have to break their heads.

     SecurityDescriptor sd = (SecurityDescriptor) p_InputValue;
           AccessControlList acl = (AccessControlList)sd.DiscretionaryAcl;
              String m_Trustee = "";
              String m_AccessMask = "";
              String m_AceType = "";
              String m_ReturnValue="";

                  foreach (AccessControlEntry ace in (IEnumerable)acl)
                    {
                      m_Trustee = m_Trustee + "," + ace.Trustee;
                     m_AccessMask = m_AccessMask + "," + ace.AccessMask.ToString();
                      m_AceType = m_AceType + "," +ace.AceType.ToString();

                     }
         m_ReturnValue="Trustee: " + m_Trustee + " " + "AccessMask: " + m_AccessMask + "AceType: " + m_AceType;
         return m_ReturnValue

Upvotes: 3

Related Questions