void ISecurityDescriptorCmdletProvider.GetSecurityDescriptor(string path, AccessControlSections includeSections)
        {
            string relative_path = GetRelativePath(PSPathToNT(path));

            using (NtDirectory dir = GetPathDirectory(relative_path))
            {
                if (relative_path.Length == 0)
                {
                    WriteItemObject(new GenericObjectSecurity(dir, includeSections), path, true);
                }
                else
                {
                    ObjectDirectoryInformation dir_info = GetEntry(dir, relative_path);
                    if (dir_info == null)
                    {
                        throw new NtException(NtStatus.STATUS_OBJECT_NAME_NOT_FOUND);
                    }

                    using (NtObject obj = dir_info.Open(GenericAccessRights.ReadControl))
                    {
                        WriteItemObject(new GenericObjectSecurity(obj, includeSections), path, obj is NtDirectory);
                    }
                }
            }
        }
        public void GetSecurityDescriptor(string path, AccessControlSections includeSections)
        {
            using (NtDirectory dir = GetPathDirectory(path))
            {
                ObjectDirectoryInformation dir_info = GetEntry(dir, path);
                if (dir_info == null)
                {
                    throw new NtException(NtStatus.STATUS_OBJECT_NAME_NOT_FOUND);
                }

                using (NtObject obj = dir_info.Open(GenericAccessRights.ReadControl))
                {
                    WriteItemObject(new GenericObjectSecurity(obj, includeSections), path, false);
                }
            }
        }
Exemple #3
0
        void ISecurityDescriptorCmdletProvider.SetSecurityDescriptor(string path, ObjectSecurity securityDescriptor)
        {
            if (securityDescriptor is GenericObjectSecurity obj_security)
            {
                string relative_path = GetRelativePath(PSPathToNT(path));
                using (NtDirectory dir = GetPathDirectory(relative_path))
                {
                    ObjectDirectoryInformation dir_info = GetEntry(dir, relative_path);
                    if (dir_info == null)
                    {
                        throw new NtException(NtStatus.STATUS_OBJECT_NAME_NOT_FOUND);
                    }

                    using (NtObject obj = dir_info.Open(GenericAccessRights.WriteDac))
                    {
                        obj_security.PersistHandle(obj.Handle);
                    }
                }
            }
        }
        public void SetSecurityDescriptor(string path, ObjectSecurity securityDescriptor)
        {
            GenericObjectSecurity obj_security = securityDescriptor as GenericObjectSecurity;

            if (obj_security != null)
            {
                using (NtDirectory dir = GetPathDirectory(path))
                {
                    ObjectDirectoryInformation dir_info = GetEntry(dir, path);
                    if (dir_info == null)
                    {
                        throw new NtException(NtStatus.STATUS_OBJECT_NAME_NOT_FOUND);
                    }

                    using (NtObject obj = dir_info.Open(GenericAccessRights.WriteDac))
                    {
                        obj_security.PersistHandle(obj.Handle);
                    }
                }
            }
        }