• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# AccessControl.FileSecurity类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Security.AccessControl.FileSecurity的典型用法代码示例。如果您正苦于以下问题:C# FileSecurity类的具体用法?C# FileSecurity怎么用?C# FileSecurity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FileSecurity类属于System.Security.AccessControl命名空间,在下文中一共展示了FileSecurity类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetOwnershipTest2

        public void GetOwnershipTest2()
        {
            // Arrange
            var tmpDir = Path.Combine(Path.GetTempPath(), "dirtools-test-" + Guid.NewGuid().ToString());
            Directory.CreateDirectory(tmpDir);

            var tmpFile = Path.Combine(tmpDir, "asdf");

            var localSystem = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);

            var fileSec = new FileSecurity();
            fileSec.SetOwner(localSystem);

            File.Create(tmpFile, 1, FileOptions.None, fileSec).Dispose();

            // Act
            var curIdentity = new NTAccount(Environment.UserDomainName, Environment.UserName);
            DirectoryTools.GetOwnershipForDirectory(tmpFile, curIdentity);

            // Assert
            var curFilesec = new FileSecurity(tmpFile, AccessControlSections.Owner);
            IdentityReference owner = curFilesec.GetOwner(typeof(NTAccount));
            Assert.IsTrue(curIdentity == owner);
        }
开发者ID:solakian,项目名称:windows-isolation,代码行数:24,代码来源:TestDirectoryTools.cs


示例2: SetAccessControl

		public static void SetAccessControl(this FileInfo fileInfo, FileSecurity fileSecurity)
		{
			if (fileInfo == null)
				throw new ArgumentNullException (nameof (fileInfo));

			fileInfo.SetAccessControl (fileSecurity);
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:7,代码来源:FileSystemAclExtensions.cs


示例3: CreateFileOperation

 public CreateFileOperation( string path, int bufferSize, FileOptions options, FileSecurity fileSecurity )
 {
     this.path = path;
     this.bufferSize = bufferSize;
     this.options = options;
     this.fileSecurity = fileSecurity;
     tempFilePath = Path.Combine( Path.GetTempPath(), Path.GetRandomFileName() );
 }
开发者ID:dbremner,项目名称:TransactionalFileManager,代码行数:8,代码来源:CreateFileOperation.cs


示例4: ExecuteOnFile

        protected override void ExecuteOnFile(FileInfo file)
        {
            FileSecurity fileSec = new FileSecurity(file.FullName, AccessControlSections.Access);

            Log(Level.Info, Resources.AddAccessRuleAdding, Rights, NTAccount, file.FullName);
            FileSystemAccessRule newRule = new FileSystemAccessRule(new NTAccount(NTAccount), Rights, AccessControlType);
            fileSec.AddAccessRule(newRule);
            file.SetAccessControl(fileSec);
        }
开发者ID:jcde,项目名称:NAntWithContrib,代码行数:9,代码来源:AddAccessRuleTask.cs


示例5: SetAccessControl

        public static void SetAccessControl(this FileInfo fileInfo, FileSecurity fileSecurity)
        {
            if (fileSecurity == null)
                throw new ArgumentNullException(nameof(fileSecurity));
            Contract.EndContractBlock();

            String fullPath = Path.GetFullPath(fileInfo.FullName);
            // Appropriate security check should be done for us by FileSecurity.
            fileSecurity.Persist(fullPath);
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:10,代码来源:FileSystemAclExtensions.cs


示例6: SecureFile

        public SecureFile(string filePath)
        {
            Condition.Requires(filePath).IsNotNullOrEmpty();

            this.FilePath = filePath;
            FileSecurity fs = new FileSecurity();

            // Create a file using the FileStream class.
            this.Stream = FileUtil.GetLockedStream(this.FilePath);
            this.Stream.Lock(0, this.Stream.Length);
        }
开发者ID:Piirtaa,项目名称:Decoratid,代码行数:11,代码来源:SecureFile.cs


示例7: getFileOwner

 private string getFileOwner(string filename)
 {
     FileSecurity tmp = new FileSecurity(filename, AccessControlSections.Owner);
     string owner = "<unknown>";
     try
     {
         owner = tmp.GetOwner(System.Type.GetType("System.Security.Principal.SecurityIdentifier")).Value;
     }
     catch { }
     return owner;
 }
开发者ID:GreysonT,项目名称:Script__,代码行数:11,代码来源:Tree.cs


示例8: Main

        static void Main(string[] args)
        {
            DirectorySecurity ds = new DirectorySecurity();
            ds.AddAccessRule(new FileSystemAccessRule("Rafa&Pri", FileSystemRights.Read, AccessControlType.Allow));
            string newFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Rafa&Pri");
            Directory.CreateDirectory(newFolder, ds);

            FileSecurity fs = new FileSecurity();
            fs.AddAccessRule(new FileSystemAccessRule("Rafa&Pri", FileSystemRights.FullControl, AccessControlType.Allow));
            string newFile = Path.Combine(newFolder, "Data.dat");
            File.Create(newFile, 100, FileOptions.None, fs);
        }
开发者ID:Rafael-Miceli,项目名称:ProjectStudiesCert70-536,代码行数:12,代码来源:Program.cs


示例9: AllowFileAccess

 public static bool AllowFileAccess(string path, FileSystemRights rights)
 {
     try
     {
         var security = new System.Security.AccessControl.FileSecurity();
         var usersSid = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
         security.AddAccessRule(new FileSystemAccessRule(usersSid, rights, AccessControlType.Allow));
         File.SetAccessControl(path, security);
         return true;
     }
     catch
     {
         return false;
     }
 }
开发者ID:Healix,项目名称:Gw2Launcher,代码行数:15,代码来源:FileUtil.cs


示例10: ExecuteOnFile

 protected override void ExecuteOnFile(FileInfo file)
 {
     FileSecurity fileSec = new FileSecurity(file.FullName, AccessControlSections.Access);
     IList<FileSystemAccessRule> targetRules = FindAccessRules(fileSec);
     if (targetRules.Count == 0)
     {
         Log(Level.Info, Resources.RemoveAccessRuleEmpty, NTAccount, file.FullName);
     }
     else
     {
         foreach (FileSystemAccessRule fileSystemAccessRule in targetRules)
         {
             Log(Level.Info, Resources.RemoveAccessRuleRemoving, NTAccount, file.FullName);
             fileSec.RemoveAccessRule(fileSystemAccessRule);
         }
         file.SetAccessControl(fileSec);
     }
 }
开发者ID:jcde,项目名称:NAntWithContrib,代码行数:18,代码来源:RemoveAccessRuleTask.cs


示例11: CreateFile

 public IFile CreateFile(string file, FileMode fileMode, FileAccess fileAccess, FileShare fileShare,
     FileSystemRights fileSystemRights, FileOptions fileOptions, FileSecurity fileSecurity)
 {
     using (var tranHandle = GetKtmTransactionHandle())
     {
         int dwFlagsAndAttributes = (int) fileOptions;
         dwFlagsAndAttributes |= 0x100000;
         NativeMethods.FileAccess faccess = NativeFileEnums.TranslateFileAccess(fileAccess);
         NativeMethods.FileShare fshare = NativeFileEnums.TranslateFileShare(fileShare);
         NativeMethods.FileMode fmode = NativeFileEnums.TranslateFileMode(fileMode);
         using (SafeFileHandle fileHandle = NativeMethods.CreateFileTransacted(file, faccess, fshare, IntPtr.Zero, fmode,
                                                                               dwFlagsAndAttributes, IntPtr.Zero, tranHandle,
                                                                               IntPtr.Zero, IntPtr.Zero))
         {
             if (fileHandle.IsInvalid)
                 throw new InvalidOperationException();
         }
         return GetFile(file);
     }
 }
开发者ID:BlogSharp,项目名称:Blogsharp,代码行数:20,代码来源:TransactionalFileService.cs


示例12: GetSecurityDescriptor

        /// <summary>
        /// Gets the SecurityDescriptor at the specified path, including only the specified
        /// AccessControlSections.
        /// </summary>
        ///
        /// <param name="path">
        /// The path of the item to retrieve. It may be a drive or provider-qualified path and may include.
        /// glob characters.
        /// </param>
        /// 
        /// <param name="sections">
        /// The sections of the security descriptor to include.
        /// </param>
        /// 
        /// <returns>
        /// Nothing. An object that represents the security descriptor for the item
        /// specified by path is written to the context's pipeline.
        /// </returns>
        /// 
        /// <exception cref="System.ArgumentException">
        ///     path is null or empty.
        ///     path doesn't exist
        ///     sections is not valid.
        /// </exception>
        public void GetSecurityDescriptor(string path,
                                          AccessControlSections sections)
        {
            ObjectSecurity sd = null;
            path = NormalizePath(path);

            if (String.IsNullOrEmpty(path))
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }

            if ((sections & ~AccessControlSections.All) != 0)
            {
                throw PSTraceSource.NewArgumentException("sections");
            }

            var currentPrivilegeState = new PlatformInvokes.TOKEN_PRIVILEGE();
            try
            {
                PlatformInvokes.EnableTokenPrivilege("SeBackupPrivilege", ref currentPrivilegeState);

                if (Directory.Exists(path))
                {
                    sd = new DirectorySecurity(path, sections);
                }
                else
                {
                    sd = new FileSecurity(path, sections);
                }
            }
            catch (System.Security.SecurityException e)
            {
                WriteError(new ErrorRecord(e, e.GetType().FullName, ErrorCategory.PermissionDenied, path));
            }
            finally
            {
                PlatformInvokes.RestoreTokenPrivilege("SeBackupPrivilege", ref currentPrivilegeState);
            }

            WriteSecurityDescriptorObject(sd, path);
        }
开发者ID:40a,项目名称:PowerShell,代码行数:65,代码来源:FileSystemSecurity.cs


示例13: Create

		public static FileStream Create (string path, int bufferSize,
						 FileOptions options,
						 FileSecurity fileSecurity)
		{
			return new FileStream (path, FileMode.Create, FileAccess.ReadWrite,
				FileShare.None, bufferSize, options);
		}
开发者ID:ngraziano,项目名称:mono,代码行数:7,代码来源:File.cs


示例14: Create

 public FileStream Create(string path, int bufferSize, FileOptions options, FileSecurity fileSecurity)
 {
     return File.Create(path, bufferSize, options, fileSecurity);
 }
开发者ID:faktumsoftware,项目名称:Cloney,代码行数:4,代码来源:FileFacade.cs


示例15: SetAccessControl

 public void SetAccessControl(string path, FileSecurity fileSecurity)
 {
     File.SetAccessControl(path, fileSecurity);
 }
开发者ID:faktumsoftware,项目名称:Cloney,代码行数:4,代码来源:FileFacade.cs


示例16: SetAccessControl

 public abstract void SetAccessControl(string path, FileSecurity fileSecurity);
开发者ID:parshim,项目名称:System.IO.Abstractions,代码行数:1,代码来源:FileBase.cs


示例17: Create

 public abstract Stream Create(string path, int bufferSize, FileOptions options, FileSecurity fileSecurity);
开发者ID:parshim,项目名称:System.IO.Abstractions,代码行数:1,代码来源:FileBase.cs


示例18: SetAccessControl

 /// <summary>
 /// Sets the access control.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <param name="fileSecurity">The file security.</param>
 public static void SetAccessControl(string path, FileSecurity fileSecurity)
 {
     _mock.SetAccessControl(path, fileSecurity);
 }
开发者ID:BclEx,项目名称:BclEx-Abstract,代码行数:9,代码来源:FileEx2.cs


示例19: CopyAccessControlList

        /// <summary>
        /// Copies the Access Control List (ACL) from one file to another and specify additional ACL rules on the destination file.
        /// </summary>
        /// <param name="pathToSourceFile">The path to the source file.</param>
        /// <param name="pathToDestinationFile">The path to the destination file.</param>
        /// <param name="additionalFileSystemAccessRules">An array of <see cref="FileSystemAccessRule"/>. The additional ACLs.</param>
        public static void CopyAccessControlList(string pathToSourceFile, string pathToDestinationFile, FileSystemAccessRule[] additionalFileSystemAccessRules)
        {
            if (additionalFileSystemAccessRules == null)
            {
                throw new ArgumentNullException("additionalFileSystemAccessRules");
            }

            CheckFilePathParameter("pathToSourceFile", pathToSourceFile);
            CheckFilePathParameter("pathToDestinationFile", pathToDestinationFile);
            FileSecurity sourceFileSecurity = File.GetAccessControl(pathToSourceFile);
            FileSecurity destinationFileSecurity = new FileSecurity();
            byte[] securityDescriptor = sourceFileSecurity.GetSecurityDescriptorBinaryForm();
            destinationFileSecurity.SetSecurityDescriptorBinaryForm(securityDescriptor);
            foreach (FileSystemAccessRule fileSystemAccessRule in additionalFileSystemAccessRules)
            {
                destinationFileSecurity.AddAccessRule(fileSystemAccessRule);
            }

            File.SetAccessControl(pathToDestinationFile, destinationFileSecurity);
        }
开发者ID:StealFocus,项目名称:Core,代码行数:26,代码来源:FileSystem.cs


示例20: setAccessControl

 public static bool setAccessControl(this FileInfo fileInfo, string targetUser, FileSystemRights fileSystemRights, AccessControlType accessControlType)
 {
     if (fileInfo.notNull() && targetUser.notNull())
     {
         try
         {
             var fileSystemAccessRule = new FileSystemAccessRule(targetUser, fileSystemRights, accessControlType);
             var fileSecurity = new FileSecurity();
             fileSecurity.AddAccessRule(fileSystemAccessRule);
             fileInfo.SetAccessControl(fileSecurity);
             return true;
         }
         catch (Exception ex)
         {
             ex.log();
         }
     }
     return false;
 }
开发者ID:SergeTruth,项目名称:OxyChart,代码行数:19,代码来源:IO_ExtensionMethods_FileInfo.cs



注:本文中的System.Security.AccessControl.FileSecurity类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# AccessControl.FileSystemAccessRule类代码示例发布时间:2022-05-26
下一篇:
C# AccessControl.DiscretionaryAcl类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap