/// <summary> /// Process Record. /// </summary> protected override void ProcessRecord() { if (SecurityDescriptor == null) { SecurityDescriptor = new SecurityDescriptor(); if (SecurityInformation.HasFlag(SecurityInformation.Dacl)) { SecurityDescriptor.Dacl = new Acl(); } if (SecurityInformation.HasFlag(SecurityInformation.Sacl)) { SecurityDescriptor.Sacl = new Acl(); } } bool do_callback = ShowProgress || PassThru; TreeProgressFunction fn = ProgressFunction; NtStatus status = Win32Security.ResetSecurityInfo(Name, Type, SecurityInformation, SecurityDescriptor, do_callback ? fn : null, ShowProgress ? ProgressInvokeSetting.PrePostError : ProgressInvokeSetting.EveryObject, KeepExplicit, !PassThru); if (!PassThru) { status.ToNtException(); } }
/// <summary> /// Sets the security descriptor of an object. /// </summary> /// <param name="handle">A handle to an object.</param> /// <param name="objectType">The type of the object.</param> /// <param name="securityInformation">The information to modify.</param> /// <param name="securityDescriptor">The security descriptor.</param> public static void SetSecurity(IntPtr handle, SeObjectType objectType, SecurityInformation securityInformation, SecurityDescriptor securityDescriptor) { Win32Error result; IntPtr dacl = IntPtr.Zero; IntPtr group = IntPtr.Zero; IntPtr owner = IntPtr.Zero; IntPtr sacl = IntPtr.Zero; if (securityInformation.HasFlag(SecurityInformation.Dacl)) { dacl = securityDescriptor.Dacl ?? IntPtr.Zero; } if (securityInformation.HasFlag(SecurityInformation.Group)) { group = securityDescriptor.Group; } if (securityInformation.HasFlag(SecurityInformation.Owner)) { owner = securityDescriptor.Owner; } if (securityInformation.HasFlag(SecurityInformation.Sacl)) { sacl = securityDescriptor.Sacl ?? IntPtr.Zero; } if ((result = Win32.SetSecurityInfo( handle, objectType, securityInformation, owner, group, dacl, sacl )) != 0) { Win32.Throw(result); } }
/// <summary> /// Sets the security descriptor of an object. /// </summary> /// <param name="handle">A handle to an object.</param> /// <param name="objectType">The type of the object.</param> /// <param name="securityInformation">The information to modify.</param> /// <param name="securityDescriptor">The security descriptor.</param> public static void SetSecurity(IntPtr handle, SeObjectType objectType, SecurityInformation securityInformation, SecurityDescriptor securityDescriptor) { Win32Error result; IntPtr dacl = IntPtr.Zero; IntPtr group = IntPtr.Zero; IntPtr owner = IntPtr.Zero; IntPtr sacl = IntPtr.Zero; if (securityInformation.HasFlag(SecurityInformation.Dacl)) dacl = securityDescriptor.Dacl ?? IntPtr.Zero; if (securityInformation.HasFlag(SecurityInformation.Group)) group = securityDescriptor.Group; if (securityInformation.HasFlag(SecurityInformation.Owner)) owner = securityDescriptor.Owner; if (securityInformation.HasFlag(SecurityInformation.Sacl)) sacl = securityDescriptor.Sacl ?? IntPtr.Zero; if ((result = Win32.SetSecurityInfo( handle, objectType, securityInformation, owner, group, dacl, sacl )) != 0) Win32.Throw(result); }