Esempio n. 1
0
		int Win32SetHelper (SetSecurityInfoNativeCall nativeCall,
				    AccessControlSections includeSections)
		{
			// SE_REGISTRY_KEY will fail UnauthorizedAccessException without this check.
			if (AccessControlSections.None == includeSections) return 0;
			
			SecurityInfos securityInfos = 0;
			byte[] owner = null, group = null, dacl = null, sacl = null;
			
			if (0 != (includeSections & AccessControlSections.Owner)) {
				securityInfos |= SecurityInfos.Owner;
				SecurityIdentifier ownerSid = (SecurityIdentifier)GetOwner (typeof (SecurityIdentifier));
				if (null != ownerSid) {
					owner = new byte[ownerSid.BinaryLength];
					ownerSid.GetBinaryForm (owner, 0);
				}
			}
			
			if (0 != (includeSections & AccessControlSections.Group)) {
				securityInfos |= SecurityInfos.Group;
				SecurityIdentifier groupSid = (SecurityIdentifier)GetGroup (typeof (SecurityIdentifier));
				if (null != groupSid) {
					group = new byte[groupSid.BinaryLength];
					groupSid.GetBinaryForm (group, 0);
				}
			}
			
			if (0 != (includeSections & AccessControlSections.Access)) {
				securityInfos |= SecurityInfos.DiscretionaryAcl;
				if (AreAccessRulesProtected)
					securityInfos |= unchecked((SecurityInfos)0x80000000);
				else
					securityInfos |= (SecurityInfos)0x20000000;
				dacl = new byte[descriptor.DiscretionaryAcl.BinaryLength];
				descriptor.DiscretionaryAcl.GetBinaryForm (dacl, 0);
			}
			
			if (0 != (includeSections & AccessControlSections.Audit)) {
				if (null != descriptor.SystemAcl) {
					securityInfos |= SecurityInfos.SystemAcl;
					if (AreAuditRulesProtected)
						securityInfos |= (SecurityInfos)0x40000000;
					else
						securityInfos |= (SecurityInfos)0x10000000;
					sacl = new byte[descriptor.SystemAcl.BinaryLength];
					descriptor.SystemAcl.GetBinaryForm (sacl, 0);
				}
			}
			
			return nativeCall (securityInfos, owner, group, dacl, sacl);
		}
Esempio n. 2
0
        int Win32SetHelper(SetSecurityInfoNativeCall nativeCall,
                           AccessControlSections includeSections)
        {
            // SE_REGISTRY_KEY will fail UnauthorizedAccessException without this check.
            if (AccessControlSections.None == includeSections)
            {
                return(0);
            }

            SecurityInfos securityInfos = 0;

            byte[] owner = null, group = null, dacl = null, sacl = null;

            if (0 != (includeSections & AccessControlSections.Owner))
            {
                securityInfos |= SecurityInfos.Owner;
                SecurityIdentifier ownerSid = (SecurityIdentifier)GetOwner(typeof(SecurityIdentifier));
                if (null != ownerSid)
                {
                    owner = new byte[ownerSid.BinaryLength];
                    ownerSid.GetBinaryForm(owner, 0);
                }
            }

            if (0 != (includeSections & AccessControlSections.Group))
            {
                securityInfos |= SecurityInfos.Group;
                SecurityIdentifier groupSid = (SecurityIdentifier)GetGroup(typeof(SecurityIdentifier));
                if (null != groupSid)
                {
                    group = new byte[groupSid.BinaryLength];
                    groupSid.GetBinaryForm(group, 0);
                }
            }

            if (0 != (includeSections & AccessControlSections.Access))
            {
                securityInfos |= SecurityInfos.DiscretionaryAcl;
                if (AreAccessRulesProtected)
                {
                    securityInfos |= unchecked ((SecurityInfos)0x80000000);
                }
                else
                {
                    securityInfos |= (SecurityInfos)0x20000000;
                }
                dacl = new byte[descriptor.DiscretionaryAcl.BinaryLength];
                descriptor.DiscretionaryAcl.GetBinaryForm(dacl, 0);
            }

            if (0 != (includeSections & AccessControlSections.Audit))
            {
                if (null != descriptor.SystemAcl)
                {
                    securityInfos |= SecurityInfos.SystemAcl;
                    if (AreAuditRulesProtected)
                    {
                        securityInfos |= (SecurityInfos)0x40000000;
                    }
                    else
                    {
                        securityInfos |= (SecurityInfos)0x10000000;
                    }
                    sacl = new byte[descriptor.SystemAcl.BinaryLength];
                    descriptor.SystemAcl.GetBinaryForm(sacl, 0);
                }
            }

            return(nativeCall(securityInfos, owner, group, dacl, sacl));
        }