Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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; 
like image 927
KSM Avatar asked Dec 04 '25 01:12

KSM


1 Answers

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
like image 158
KSM Avatar answered Dec 08 '25 07:12

KSM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!