internal IEnumerable <NetworkShareInfo> GetSharesWithSecurity()
        {
            IntPtr zero = IntPtr.Zero;
            IntPtr bufptr;
            uint   entriesread;
            uint   totalentries;
            uint   num1 = NetworkShareAdapter.NetShareEnum((string)null, Environment.OSVersion.IsWindows2008OrLater() ? 503U : 502U, out bufptr, 4294967294U, out entriesread, out totalentries, ref zero);

            if ((int)num1 != 0)
            {
                throw new Win32Exception((int)num1, string.Format("Error getting shares: {0}", (object)num1));
            }
            IList <NetworkShareInfo> networkShareInfoList = (IList <NetworkShareInfo>) new List <NetworkShareInfo>();

            try
            {
                NetworkShareAdapter._tracer.TraceInformation("Found {0} shares", (object)entriesread);
                for (int index = 0; (long)entriesread > (long)index; ++index)
                {
                    NetworkShareAdapter.ShareInfoAdapter share = new NetworkShareAdapter.ShareInfoAdapter(bufptr, index, Environment.OSVersion);
                    NetworkShareAdapter._tracer.TraceInformation("Enumerating share {0}", (object)share.netname);
                    networkShareInfoList.Add(new NetworkShareInfo(share.netname, (int)share.type, share.path, this.GetAces(share), 0 > (int)share.max_uses ? new int?() : new int?((int)share.max_uses), share.servername));
                }
            }
            finally
            {
                int num2 = (int)NetworkShareAdapter.NetApiBufferFree(bufptr);
            }
            return((IEnumerable <NetworkShareInfo>)networkShareInfoList);
        }
        private IEnumerable <Ace> GetAces(NetworkShareAdapter.ShareInfoAdapter share)
        {
            IntPtr zero = IntPtr.Zero;

            try
            {
                if (!NetworkShareAdapter.IsValidSecurityDescriptor(share.security_descriptor))
                {
                    NetworkShareAdapter._tracer.TraceInformation("Invalid security descriptor for share {0}", (object)share.netname);
                    return((IEnumerable <Ace>)null);
                }
                bool lpbDaclPresent;
                bool lpbDaclDefaulted;
                if (!NetworkShareAdapter.GetSecurityDescriptorDacl(share.security_descriptor, out lpbDaclPresent, ref zero, out lpbDaclDefaulted))
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error(), string.Format("Error getting DACL for share {0}", (object)share.netname));
                }
            }
            catch (Win32Exception ex)
            {
                NetworkShareAdapter._tracer.TraceInformation("Unable to obtain DACL for share {0}: {1}", (object)share.netname, (object)ex);
                return((IEnumerable <Ace>)null);
            }
            IList <Ace> aceList = (IList <Ace>) new List <Ace>();

            if (IntPtr.Zero == zero)
            {
                NetworkShareAdapter._tracer.TraceInformation("Security descriptor does not contain a DACL");
                return((IEnumerable <Ace>)aceList);
            }
            NetworkShareAdapter.ACL structure1 = (NetworkShareAdapter.ACL)Marshal.PtrToStructure(zero, typeof(NetworkShareAdapter.ACL));
            NetworkShareAdapter._tracer.TraceInformation("ACE count: {0}", (object)structure1.AceCount);
            for (uint dwAceIndex = 0; (uint)structure1.AceCount > dwAceIndex; ++dwAceIndex)
            {
                NetworkShareAdapter._tracer.TraceInformation("Iterating ACE: {0}", (object)dwAceIndex);
                try
                {
                    IntPtr pAce;
                    if (!NetworkShareAdapter.GetAce(zero, dwAceIndex, out pAce))
                    {
                        throw new Win32Exception(Marshal.GetLastWin32Error(), string.Format("Error getting ACE for share {0}", (object)share.netname));
                    }
                    NetworkShareAdapter.ACE structure2 = (NetworkShareAdapter.ACE)Marshal.PtrToStructure(pAce, typeof(NetworkShareAdapter.ACE));
                    IntPtr        num     = new IntPtr(pAce.ToInt64() + Marshal.OffsetOf(typeof(NetworkShareAdapter.ACE), "SidStart").ToInt64());
                    uint          cchName = 0;
                    uint          cchReferencedDomainName = 0;
                    StringBuilder lpName = new StringBuilder((int)cchName);
                    StringBuilder lpReferencedDomainName = new StringBuilder((int)cchReferencedDomainName);
                    NetworkShareAdapter.SID_NAME_USE peUse;
                    if (NetworkShareAdapter.LookupAccountSid((string)null, num, (StringBuilder)null, ref cchName, (StringBuilder)null, ref cchReferencedDomainName, out peUse) || 122L == (long)Marshal.GetLastWin32Error() || 203L == (long)Marshal.GetLastWin32Error())
                    {
                        lpName.EnsureCapacity((int)cchName);
                        lpReferencedDomainName.EnsureCapacity((int)cchReferencedDomainName);
                        if (!NetworkShareAdapter.LookupAccountSid((string)null, num, lpName, ref cchName, lpReferencedDomainName, ref cchReferencedDomainName, out peUse))
                        {
                            NetworkShareAdapter._tracer.TraceInformation("Unable to lookup account name for SID {0}: {1}", (object)new SecurityIdentifier(num), (object)Marshal.GetLastWin32Error());
                        }
                    }
                    else
                    {
                        NetworkShareAdapter._tracer.TraceInformation("Unable to determine account name capacity for SID {0}: {1}", (object)new SecurityIdentifier(num), (object)Marshal.GetLastWin32Error());
                    }
                    NetworkShareAdapter._tracer.TraceInformation("Share {0}: ACE type: {1}, flags: {2}, mask: {3}, user: {4}\\{5}, server: {6}", (object)share.netname, (object)structure2.Header.AceType, (object)structure2.Header.AceFlags, (object)structure2.Mask, (object)lpReferencedDomainName.ToString(), (object)(lpName.Length == 0 ? new SecurityIdentifier(num).ToString() : lpName.ToString()), (object)share.servername);
                    uint   lengthSid   = NetworkShareAdapter.GetLengthSid(num);
                    byte[] destination = new byte[(int)lengthSid];
                    Marshal.Copy(num, destination, 0, (int)lengthSid);
                    aceList.Add(new Ace()
                    {
                        accessMask = (int)structure2.Mask,
                        aceFlags   = (AceFlags)structure2.Header.AceFlags,
                        aceType    = (AceType)structure2.Header.AceType,
                        domain     = lpReferencedDomainName.Length == 0 ? (string)null : lpReferencedDomainName.ToString(),
                        name       = lpName.Length == 0 ? (string)null : lpName.ToString(),
                        sid        = destination
                    });
                }
                catch (Win32Exception ex)
                {
                    NetworkShareAdapter._tracer.TraceInformation("Unable to obtain ACE for share {0}: {1}", (object)share.netname, (object)ex);
                    aceList.Add((Ace)null);
                }
            }
            return((IEnumerable <Ace>)aceList);
        }