Beispiel #1
0
        private void SetNamedSecurityInfo()
        {
            bool do_callback = ShowProgress || PassThru;

            if (Type == SeObjectType.Service)
            {
                SecurityInformation &= SecurityInformation.Owner |
                                       SecurityInformation.Group | SecurityInformation.Dacl |
                                       SecurityInformation.Label | SecurityInformation.Sacl;
            }

            string path = Name;

            if (Type == SeObjectType.File)
            {
                path = PSUtils.ResolveWin32Path(SessionState, path, false);
            }

            if (do_callback || Action != TreeSecInfo.Set)
            {
                TreeProgressFunction fn     = ProgressFunction;
                NtStatus             status = Win32Security.SetSecurityInfo(path, Type, SecurityInformation, SecurityDescriptor, Action, do_callback ? fn : null,
                                                                            ShowProgress ? ProgressInvokeSetting.PrePostError : ProgressInvokeSetting.EveryObject, !PassThru);
                if (!PassThru)
                {
                    status.ToNtException();
                }
            }
            else
            {
                Win32Security.SetSecurityInfo(path, Type, SecurityInformation, SecurityDescriptor);
            }
        }
        /// <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();
            }
        }
 private static TreeSetNamedSecurityProgress CreateCallback(TreeProgressFunction progress_function)
 {
     if (progress_function != null)
     {
         return((string n, Win32Error s,
                 ref ProgressInvokeSetting p, IntPtr a, bool t)
                => p = progress_function(n, s, p, t));
     }
     return(null);
 }
 /// <summary>
 /// Set security using a named object.
 /// </summary>
 /// <param name="name">The name of the object.</param>
 /// <param name="type">The type of named object.</param>
 /// <param name="security_information">The security information to set.</param>
 /// <param name="security_descriptor">The security descriptor to set.</param>
 /// <param name="invoke_setting">Specify to indicate when to execute progress function.</param>
 /// <param name="action">The security operation to perform on the tree.</param>
 /// <param name="progress_function">Progress function.</param>
 public static void SetSecurityInfo(string name, SeObjectType type,
                                    SecurityInformation security_information,
                                    SecurityDescriptor security_descriptor,
                                    TreeSecInfo action,
                                    TreeProgressFunction progress_function,
                                    ProgressInvokeSetting invoke_setting
                                    )
 {
     SetSecurityInfo(name, type, security_information, security_descriptor, action, progress_function, invoke_setting, true);
 }
        /// <summary>
        /// Reset security using a named object.
        /// </summary>
        /// <param name="name">The name of the object.</param>
        /// <param name="type">The type of named object.</param>
        /// <param name="security_information">The security information to set.</param>
        /// <param name="security_descriptor">The security descriptor to set.</param>
        /// <param name="keep_explicit">True to keep explicit ACEs.</param>
        /// <param name="invoke_setting">Specify to indicate when to execute progress function.</param>

        /// <param name="progress_function">Progress function.</param>
        public static void ResetSecurityInfo(string name, SeObjectType type,
                                             SecurityInformation security_information,
                                             SecurityDescriptor security_descriptor,
                                             TreeProgressFunction progress_function,
                                             ProgressInvokeSetting invoke_setting,
                                             bool keep_explicit
                                             )
        {
            ResetSecurityInfo(name, type, security_information, security_descriptor,
                              progress_function, invoke_setting, keep_explicit, true);
        }
Beispiel #6
0
        private void SetNamedSecurityInfo()
        {
            bool do_callback = ShowProgress || PassThru;

            if (do_callback || Action != TreeSecInfo.Set)
            {
                TreeProgressFunction fn     = ProgressFunction;
                NtStatus             status = Win32Security.SetSecurityInfo(Name, Type, SecurityInformation, SecurityDescriptor, Action, do_callback ? fn : null,
                                                                            ShowProgress ? ProgressInvokeSetting.PrePostError : ProgressInvokeSetting.EveryObject, !PassThru);
                if (!PassThru)
                {
                    status.ToNtException();
                }
            }
            else
            {
                Win32Security.SetSecurityInfo(Name, Type, SecurityInformation, SecurityDescriptor);
            }
        }
 /// <summary>
 /// Reset security using a named object.
 /// </summary>
 /// <param name="name">The name of the object.</param>
 /// <param name="type">The type of named object.</param>
 /// <param name="security_information">The security information to set.</param>
 /// <param name="security_descriptor">The security descriptor to set.</param>
 /// <param name="invoke_setting">Specify to indicate when to execute progress function.</param>
 /// <param name="keep_explicit">True to keep explicit ACEs.</param>
 /// <param name="progress_function">Progress function.</param>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>The NT status code.</returns>
 public static NtStatus ResetSecurityInfo(string name, SeObjectType type,
                                          SecurityInformation security_information,
                                          SecurityDescriptor security_descriptor,
                                          TreeProgressFunction progress_function,
                                          ProgressInvokeSetting invoke_setting,
                                          bool keep_explicit,
                                          bool throw_on_error)
 {
     return(Win32NativeMethods.TreeResetNamedSecurityInfo(
                name, type, security_information,
                security_descriptor.Owner?.Sid.ToArray(),
                security_descriptor.Group?.Sid.ToArray(),
                security_descriptor.Dacl?.ToByteArray(),
                security_descriptor.Sacl?.ToByteArray(),
                keep_explicit,
                CreateCallback(progress_function),
                invoke_setting,
                IntPtr.Zero
                ).ToNtException(throw_on_error));
 }