Esempio n. 1
0
        internal IntPtr MakeAcl(IntPtr oldAcl)
        {
            int    ACECount = List.Count;
            IntPtr newAcl;

            NativeMethods.ExplicitAccess[] entries = new NativeMethods.ExplicitAccess[ACECount];

            GCHandle mem = GCHandle.Alloc(entries, GCHandleType.Pinned);

            try {
                for (int i = 0; i < ACECount; i++)
                {
                    int sidSize = 0;
                    int sidtype;
                    int domainSize = 0;

                    AccessControlEntry ace = (AccessControlEntry)List[i];

                    if (ace.Trustee == null)
                    {
                        throw new InvalidOperationException(Res.GetString(Res.InvalidTrustee));
                    }

                    string name = ace.Trustee.Name;
                    if (name == null)
                    {
                        throw new InvalidOperationException(Res.GetString(Res.InvalidTrusteeName));
                    }

                    if ((ace.Trustee.TrusteeType == TrusteeType.Computer) && !name.EndsWith("$"))
                    {
                        name += "$";
                    }

                    if (!UnsafeNativeMethods.LookupAccountName(ace.Trustee.SystemName, name, (IntPtr)0, ref sidSize, null, ref domainSize, out sidtype))
                    {
                        int errval = Marshal.GetLastWin32Error();
                        if (errval != 122)
                        {
                            throw new InvalidOperationException(Res.GetString(Res.CouldntResolve, ace.Trustee.Name, errval));
                        }
                    }

                    entries[i].data = (IntPtr)Marshal.AllocHGlobal(sidSize);

                    StringBuilder domainName = new StringBuilder(domainSize);
                    if (!UnsafeNativeMethods.LookupAccountName(ace.Trustee.SystemName, name, entries[i].data, ref sidSize, domainName, ref domainSize, out sidtype))
                    {
                        throw new InvalidOperationException(Res.GetString(Res.CouldntResolveName, ace.Trustee.Name));
                    }

                    entries[i].grfAccessPermissions     = ace.accessFlags;
                    entries[i].grfAccessMode            = (int)ace.EntryType;
                    entries[i].grfInheritance           = 0;
                    entries[i].pMultipleTrustees        = (IntPtr)0;
                    entries[i].MultipleTrusteeOperation = NativeMethods.NO_MULTIPLE_TRUSTEE;
                    entries[i].TrusteeForm = NativeMethods.TRUSTEE_IS_SID;
                    entries[i].TrusteeType = (int)ace.Trustee.TrusteeType;
                }

                int err = SafeNativeMethods.SetEntriesInAclW(ACECount, (IntPtr)mem.AddrOfPinnedObject(), oldAcl, out newAcl);

                if (err != NativeMethods.ERROR_SUCCESS)
                {
                    throw new Win32Exception(err);
                }
            }
            finally {
                mem.Free();

                for (int i = 0; i < ACECount; i++)
                {
                    if (entries[i].data != (IntPtr)0)
                    {
                        Marshal.FreeHGlobal(entries[i].data);
                    }
                }
            }


            return(newAcl);
        }
Esempio n. 2
0
 /// <include file='doc\AccessControlList.uex' path='docs/doc[@for="AccessControlList.Remove"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public void Remove(AccessControlEntry entry)
 {
     List.Remove(entry);
 }
Esempio n. 3
0
 /// <include file='doc\AccessControlList.uex' path='docs/doc[@for="AccessControlList.Contains"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public bool Contains(AccessControlEntry entry)
 {
     return(List.Contains(entry));
 }
Esempio n. 4
0
 /// <include file='doc\AccessControlList.uex' path='docs/doc[@for="AccessControlList.IndexOf"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public int IndexOf(AccessControlEntry entry)
 {
     return(List.IndexOf(entry));
 }
Esempio n. 5
0
 /// <include file='doc\AccessControlList.uex' path='docs/doc[@for="AccessControlList.Insert"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public void Insert(int index, AccessControlEntry entry)
 {
     List.Insert(index, entry);
 }
Esempio n. 6
0
 /// <include file='doc\AccessControlList.uex' path='docs/doc[@for="AccessControlList.Add"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public int Add(AccessControlEntry entry)
 {
     return(List.Add(entry));
 }