예제 #1
0
        int Win32GetHelper(GetSecurityInfoNativeCall nativeCall,
                           AccessControlSections includeSections)
        {
            bool getOwner = 0 != (includeSections & AccessControlSections.Owner);
            bool getGroup = 0 != (includeSections & AccessControlSections.Group);
            bool getDacl  = 0 != (includeSections & AccessControlSections.Access);
            bool getSacl  = 0 != (includeSections & AccessControlSections.Audit);

            SecurityInfos securityInfos = 0;

            if (getOwner)
            {
                securityInfos |= SecurityInfos.Owner;
            }
            if (getGroup)
            {
                securityInfos |= SecurityInfos.Group;
            }
            if (getDacl)
            {
                securityInfos |= SecurityInfos.DiscretionaryAcl;
            }
            if (getSacl)
            {
                securityInfos |= SecurityInfos.SystemAcl;
            }

            IntPtr owner, group, dacl, sacl, descriptor;
            int    result = nativeCall(securityInfos,
                                       out owner, out group, out dacl, out sacl, out descriptor);

            if (0 != result)
            {
                return(result);
            }

            try {
                int binaryLength = 0;
                if (IsValidSecurityDescriptor(descriptor))
                {
                    binaryLength = GetSecurityDescriptorLength(descriptor);
                }

                byte[] binaryForm = new byte[binaryLength];
                Marshal.Copy(descriptor, binaryForm, 0, binaryLength);
                SetSecurityDescriptorBinaryForm(binaryForm, includeSections);
            } finally {
                LocalFree(descriptor);
            }
            return(0);
        }
예제 #2
0
		int Win32GetHelper (GetSecurityInfoNativeCall nativeCall,
				    AccessControlSections includeSections)
		{
			bool getOwner = 0 != (includeSections & AccessControlSections.Owner);
			bool getGroup = 0 != (includeSections & AccessControlSections.Group);
			bool getDacl = 0 != (includeSections & AccessControlSections.Access);
			bool getSacl = 0 != (includeSections & AccessControlSections.Audit);
			
			SecurityInfos securityInfos = 0;
			if (getOwner) securityInfos |= SecurityInfos.Owner;
			if (getGroup) securityInfos |= SecurityInfos.Group;
			if (getDacl ) securityInfos |= SecurityInfos.DiscretionaryAcl;
			if (getSacl ) securityInfos |= SecurityInfos.SystemAcl;
			
			IntPtr owner, group, dacl, sacl, descriptor;
			int result = nativeCall (securityInfos,
						 out owner, out group, out dacl, out sacl, out descriptor);
			if (0 != result) return result;
			
			try {
				int binaryLength = 0;
				if (IsValidSecurityDescriptor (descriptor))
					binaryLength = GetSecurityDescriptorLength (descriptor);
					
				byte[] binaryForm = new byte[binaryLength];
				Marshal.Copy (descriptor, binaryForm, 0, binaryLength);
				SetSecurityDescriptorBinaryForm (binaryForm, includeSections);
			} finally {
				LocalFree (descriptor);
			}
			return 0;
		}