当前位置: 首页>>代码示例>>C#>>正文


C# AccessControl.FileSecurity类代码示例

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


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


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