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


C# FileIOPermission.AddPathList方法代码示例

本文整理汇总了C#中System.Security.Permissions.FileIOPermission.AddPathList方法的典型用法代码示例。如果您正苦于以下问题:C# FileIOPermission.AddPathList方法的具体用法?C# FileIOPermission.AddPathList怎么用?C# FileIOPermission.AddPathList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Permissions.FileIOPermission的用法示例。


在下文中一共展示了FileIOPermission.AddPathList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateAnalyzerDomain

        private AppDomain CreateAnalyzerDomain()
        {
            AppDomainSetup ads = new AppDomainSetup();
            AppDomain result;
            PermissionSet perms;
            ads.ApplicationBase = Environment.CurrentDirectory;
            ads.ShadowCopyDirectories = "shadow";
            ads.ShadowCopyFiles = "shadow";
            ads.DisallowCodeDownload = true;

            perms = new PermissionSet(PermissionState.None);
            FileIOPermission fiop = new FileIOPermission(PermissionState.Unrestricted);
            perms.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
            perms.AddPermission(new SecurityPermission(SecurityPermissionFlag.AllFlags));
            fiop.AddPathList(FileIOPermissionAccess.PathDiscovery, Environment.CurrentDirectory);
            fiop.AddPathList(FileIOPermissionAccess.Read, Environment.CurrentDirectory);
            fiop.AddPathList(FileIOPermissionAccess.PathDiscovery, Environment.CurrentDirectory + "Extensions\\");
            fiop.AddPathList(FileIOPermissionAccess.Read, Environment.CurrentDirectory + "Extensions\\");
            //fiop.AllLocalFiles = FileIOPermissionAccess.AllAccess
            //fiop.AllFiles = FileIOPermissionAccess.AllAccess
            perms.AddPermission(fiop);
            perms.AddPermission(new UIPermission(UIPermissionWindow.AllWindows, UIPermissionClipboard.OwnClipboard));
            perms.AddPermission(new ReflectionPermission(PermissionState.Unrestricted));

            PolicyLevel policy = PolicyLevel.CreateAppDomainLevel();
            policy.RootCodeGroup.PolicyStatement = new PolicyStatement(perms);

            // create the Domain
            result = AppDomain.CreateDomain("analyzer", null, ads);
            result.SetAppDomainPolicy(policy);
            return result;
        }
开发者ID:hapm,项目名称:IrcShark,代码行数:32,代码来源:ExtensionAnalyzer.cs

示例2: Init

    /// <summary>
    ///   Initializes the permissions manager with the permissions required by an install script.
    /// </summary>
    internal static void Init()
    {
      permissions = new PermissionSet(PermissionState.None);
      //do the following paths need to add to this?
      // savesPath - fallout 3
      var fipFilePermission = new FileIOPermission(FileIOPermissionAccess.AllAccess, new[]
      {
        Program.tmpPath,
        Path.GetTempPath(),
        Program.GameMode.InstallInfoDirectory,
        Program.GameMode.PluginsPath
      });

      var lstPaths = new List<string>(Program.GameMode.SettingsFiles.Values);
      lstPaths.AddRange(Program.GameMode.AdditionalPaths.Values);
      fipFilePermission.AddPathList(FileIOPermissionAccess.AllAccess, lstPaths.ToArray());
      fipFilePermission.AddPathList(FileIOPermissionAccess.Read, Environment.CurrentDirectory);

      permissions.AddPermission(fipFilePermission);
      permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));
      permissions.AddPermission(new UIPermission(UIPermissionWindow.AllWindows));

      // Not sure what permissions are needed for GetTempFileName() to work, so we add them all.
      permissions.AddPermission(new EnvironmentPermission(PermissionState.Unrestricted));
    }
开发者ID:IntegralLee,项目名称:fomm,代码行数:28,代码来源:PermissionsManager.cs

示例3: CreateRWAPFileIOPermission

 private static FileIOPermission CreateRWAPFileIOPermission (params string[] paths)
 {
   var permission = new FileIOPermission (PermissionState.None);
   permission.AddPathList (FileIOPermissionAccess.Read, paths);
   permission.AddPathList (FileIOPermissionAccess.Write, paths);
   permission.AddPathList (FileIOPermissionAccess.Append, paths);
   permission.AddPathList (FileIOPermissionAccess.PathDiscovery, paths);
   return permission;
 }
开发者ID:natemcmaster,项目名称:Relinq,代码行数:9,代码来源:PermissionSets.cs

示例4: Parse

        public IPermission Parse(JToken token)
        {
            var accessList = token as JArray;

            if (accessList == null)
            {
                return null;
            }

            var result = new FileIOPermission(PermissionState.None);

            foreach (var item in accessList)
            {
                var obj = item as JObject;
                if (obj == null)
                {
                    continue;
                }

                var access = obj["access"].ToObject<string[]>();
                var paths = obj["paths"].ToObject<string[]>();

                var fileAccess = FileIOPermissionAccess.NoAccess;
                if (access.Contains("read")) fileAccess |= FileIOPermissionAccess.Read;
                if (access.Contains("write")) fileAccess |= FileIOPermissionAccess.Write;
                if (access.Contains("discover")) fileAccess |= FileIOPermissionAccess.PathDiscovery;
                if (access.Contains("append")) fileAccess |= FileIOPermissionAccess.Append;

                result.AddPathList(fileAccess, paths);
            }

            return result;
        }
开发者ID:renini,项目名称:hadouken,代码行数:33,代码来源:FileIoPermissionItemParser.cs

示例5: CopyFile

        public static bool CopyFile(string newFile, string oldFile)
        {
            var newfile = new FileInfo(newFile);
            var oldfile = new FileInfo(oldFile);
            string errorMsg = "";
            var f2 = new FileIOPermission(FileIOPermissionAccess.AllAccess, oldFile);
            f2.AddPathList(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, newFile);

            try
            {
                f2.Demand();
            }
            catch (SecurityException s)
            {
                Console.WriteLine(s.Message);
            }

               for (int x = 0; x < 100; x++)
               {
                    try
                    {
                       File.Delete(oldfile.FullName);
                       newfile.CopyTo(oldfile.FullName, true);
                       return true;
                    }
                    catch(Exception e)
                    {
                        errorMsg = e.Message + " :   " + e.InnerException;
                        Thread.Sleep(200);
                    }
               }
            Data.Logger(errorMsg);
               return false;
        }
开发者ID:cengonurozkan,项目名称:vFenseAgent-win,代码行数:34,代码来源:Tools.cs

示例6: AllowRead

 public static bool AllowRead(params string[] files)
 {
     FileIOPermission f2 = new FileIOPermission(PermissionState.None);
     for (int i = 0; i < files.Length; i++)
     {
         f2.AddPathList(FileIOPermissionAccess.Read, files[i]);
     }
     try
     {
         f2.Demand();
         return true;
     }
     catch
     {
         return false;
     }
 }
开发者ID:huntintiger1004,项目名称:nucleuscoop,代码行数:17,代码来源:WinAPI.cs

示例7: CreatePermission

		// Methods
		public override IPermission CreatePermission ()
		{
#if NET_2_1
			return null;
#else
			FileIOPermission perm = null;
			if (this.Unrestricted)
				perm = new FileIOPermission (PermissionState.Unrestricted);
			else {
				perm = new FileIOPermission (PermissionState.None);
				if (append != null)
					perm.AddPathList (FileIOPermissionAccess.Append, append);
				if (path != null)
					perm.AddPathList (FileIOPermissionAccess.PathDiscovery, path);
				if (read != null)
					perm.AddPathList (FileIOPermissionAccess.Read, read);
				if (write != null)
					perm.AddPathList (FileIOPermissionAccess.Write, write);
			}
			return perm;
#endif
		}
开发者ID:runefs,项目名称:Marvin,代码行数:23,代码来源:FileIOPermissionAttribute.cs

示例8: setPermissions

        //Generate permissions for the execution in the new domain, according to the permission file givan as parameter
        private static PermissionSet setPermissions(string permissionPath, string executablePath)
        {
            string[] permissions = File.ReadAllLines(permissionPath);
            string UntrustedCodeFolderAbsolutePath = permissionPath.Substring(0, permissionPath.LastIndexOf('\\'));
            PermissionSet set = new PermissionSet(PermissionState.None);

            foreach (string perm in permissions)
            {
                switch (perm.ToUpper())
                {
                    case "WRITE":
                        FileIOPermission f2 = new FileIOPermission(FileIOPermissionAccess.Read, UntrustedCodeFolderAbsolutePath);
                        f2.AddPathList(FileIOPermissionAccess.Write, UntrustedCodeFolderAbsolutePath);
                        set.AddPermission(f2);
                        break;
                    case "READ":
                        FileIOPermission f3 = new FileIOPermission(FileIOPermissionAccess.Read, UntrustedCodeFolderAbsolutePath);
                        f3.AddPathList(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, UntrustedCodeFolderAbsolutePath);
                        set.AddPermission(f3);
                        break;
                    case "CREATEFILE":
                        FileIOPermission f4 = new FileIOPermission(FileIOPermissionAccess.Read, UntrustedCodeFolderAbsolutePath);
                        f4.AddPathList(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, UntrustedCodeFolderAbsolutePath);
                        set.AddPermission(f4);
                        break;
                }
            }
            set.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
            set.AddPermission(new UIPermission(PermissionState.Unrestricted));
            set.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read, executablePath));
            set.AddPermission(new FileIOPermission(FileIOPermissionAccess.PathDiscovery, executablePath));
            set.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read, executablePath + ".result.txt"));
            set.AddPermission(new FileIOPermission(FileIOPermissionAccess.PathDiscovery, executablePath + ".result.txt"));
            set.AddPermission(new FileIOPermission(FileIOPermissionAccess.Write, executablePath + ".result.txt"));
            set.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));
            return set;
        }
开发者ID:uqar-ludic,项目名称:ludic,代码行数:38,代码来源:Program.cs

示例9: canReadWrite

 private static Boolean canReadWrite(String path)
 {
     FileIOPermission f = new FileIOPermission(FileIOPermissionAccess.Read, path);
     f.AddPathList(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, path);
     try
     {
         f.Demand();
         return true;
     }
     catch (SecurityException s)
     {
         //Console.WriteLine(s.Message);
         return false;
     }
 }
开发者ID:ninjacharlee,项目名称:tempracer,代码行数:15,代码来源:tempracer.cs

示例10: InternalReplace

 private static void InternalReplace(string sourceFileName, string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors)
 {
     string fullPathInternal = Path.GetFullPathInternal(sourceFileName);
     string replacedFileName = Path.GetFullPathInternal(destinationFileName);
     string path = null;
     if (destinationBackupFileName != null)
     {
         path = Path.GetFullPathInternal(destinationBackupFileName);
     }
     FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, new string[] { fullPathInternal, replacedFileName });
     if (destinationBackupFileName != null)
     {
         permission.AddPathList(FileIOPermissionAccess.Write, path);
     }
     permission.Demand();
     int dwReplaceFlags = 1;
     if (ignoreMetadataErrors)
     {
         dwReplaceFlags |= 2;
     }
     if (!Win32Native.ReplaceFile(replacedFileName, fullPathInternal, path, dwReplaceFlags, IntPtr.Zero, IntPtr.Zero))
     {
         __Error.WinIOError();
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:25,代码来源:File.cs

示例11: Replace

        public static void Replace(String sourceFileName, String destinationFileName, String destinationBackupFileName, bool ignoreMetadataErrors)
        {
            if (sourceFileName == null)
                throw new ArgumentNullException("sourceFileName");
            if (destinationFileName == null)
                throw new ArgumentNullException("destinationFileName");

            // Write permission to all three files, read permission to source 
            // and dest.
            String fullSrcPath = Path.GetFullPathInternal(sourceFileName);
            String fullDestPath = Path.GetFullPathInternal(destinationFileName);
            String fullBackupPath = null;
            if (destinationBackupFileName != null)
                fullBackupPath = Path.GetFullPathInternal(destinationBackupFileName);
            FileIOPermission perm = new FileIOPermission(FileIOPermissionAccess.Read | FileIOPermissionAccess.Write, new String[] { fullSrcPath, fullDestPath});
            if (destinationBackupFileName != null)
                perm.AddPathList(FileIOPermissionAccess.Write, fullBackupPath);
            perm.Demand();


            int flags = Win32Native.REPLACEFILE_WRITE_THROUGH;
            if (ignoreMetadataErrors)
                flags |= Win32Native.REPLACEFILE_IGNORE_MERGE_ERRORS;

            bool r = Win32Native.ReplaceFile(fullDestPath, fullSrcPath, fullBackupPath, flags, IntPtr.Zero, IntPtr.Zero);
            if (!r)
                __Error.WinIOError();
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:28,代码来源:file.cs

示例12: Init

        /// <summary>
        /// Initializes the permissions manager with the permissions required by an install script.
        /// </summary>
        internal static void Init()
        {
            #if TRACE
            Trace.WriteLine("");
            Trace.WriteLine("Setting up File IO Permissions for: ");
            Trace.Indent();
            Trace.Write("     FOMM tmp Dir: ");
            Trace.WriteLine(Program.tmpPath);
            Trace.Write(" Install Info Dir: ");
            Trace.WriteLine(Program.GameMode.InstallInfoDirectory);
            Trace.Write("   System tmp Dir: ");
            Trace.WriteLine(Path.GetTempPath());
            Directory.GetAccessControl(Path.GetTempPath());
            Trace.WriteLine("   Settings Files: ");
            Trace.Indent();
            foreach (string strValue in Program.GameMode.SettingsFiles.Values)
                Trace.WriteLine(strValue);
            Trace.Unindent();
            Trace.WriteLine("      Other Paths: ");
            Trace.Indent();
            foreach (string strValue in Program.GameMode.AdditionalPaths.Values)
                Trace.WriteLine(strValue);
            Trace.Unindent();
            Trace.Unindent();
            Trace.Flush();
            #endif
            permissions = new PermissionSet(PermissionState.None);
            //do the following paths need to add to this?
            // savesPath - fallout 3
            FileIOPermission fipFilePermission = new FileIOPermission(FileIOPermissionAccess.AllAccess, new string[] {
                Program.tmpPath, Path.GetTempPath(),
                Program.GameMode.InstallInfoDirectory,
                Program.GameMode.PluginsPath
            });

            List<string> lstPaths = new List<string>(Program.GameMode.SettingsFiles.Values);
            lstPaths.AddRange(Program.GameMode.AdditionalPaths.Values);
            fipFilePermission.AddPathList(FileIOPermissionAccess.AllAccess, lstPaths.ToArray());
            fipFilePermission.AddPathList(FileIOPermissionAccess.Read, Environment.CurrentDirectory);

            permissions.AddPermission(fipFilePermission);
            permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));
            permissions.AddPermission(new UIPermission(UIPermissionWindow.AllWindows));
            #if TRACE
            Trace.Write("Demanding access to System tmp Dir...");
            try
            {
                permissions.Demand();
                Trace.WriteLine("Succeeded.");
            }
            catch (Exception e)
            {
                Trace.WriteLine("Failed:");
                Program.TraceException(e);
            }
            Trace.WriteLine("   System tmp Dir Permissions:");
            Trace.Indent();
            DirectorySecurity drsPermissions = Directory.GetAccessControl(Path.GetTempPath());
            Dictionary<string, List<FileSystemRights>> dicRights = new Dictionary<string, List<FileSystemRights>>();
            foreach (FileSystemAccessRule fsrRule in drsPermissions.GetAccessRules(true, true, typeof(NTAccount)))
            {
                if (!dicRights.ContainsKey(fsrRule.IdentityReference.Value))
                    dicRights[fsrRule.IdentityReference.Value] = new List<FileSystemRights>();
                dicRights[fsrRule.IdentityReference.Value].Add(fsrRule.FileSystemRights);
            }
            foreach (KeyValuePair<string, List<FileSystemRights>> kvpRight in dicRights)
            {
                Trace.WriteLine(kvpRight.Key + " =>");
                Trace.Indent();
                foreach (FileSystemRights fsrRight in kvpRight.Value)
                    Trace.WriteLine(fsrRight.ToString());
                Trace.Unindent();
            }
            Trace.Unindent();
            Trace.Write("Testing access to System tmp Dir...");
            try
            {
                File.WriteAllText(Path.Combine(Path.GetTempPath(), "testFile.txt"), "This is fun.");
                Trace.WriteLine("Passed: " + File.ReadAllText(Path.Combine(Path.GetTempPath(), "testFile.txt")));
                File.Delete(Path.Combine(Path.GetTempPath(), "testFile.txt"));
            }
            catch (Exception e)
            {
                Trace.WriteLine("Failed: ");
                Program.TraceException(e);
            }
            #endif
        }
开发者ID:BioBrainX,项目名称:fomm,代码行数:91,代码来源:PermissionsManager.cs

示例13: LoadPolicyLevelFromFile

        static public PolicyLevel LoadPolicyLevelFromFile( String path, PolicyLevelType type )
        {
			 if (path == null)
               throw new ArgumentNullException( "path" );

            ConfigId id = SharedStatics.GetNextConfigId();

            ConfigRetval retval = Config.InitData( id, path );

            if ((retval & ConfigRetval.ConfigFile) == 0)
                throw new ArgumentException( Environment.GetResourceString( "Argument_PolicyFileDoesNotExist" ) );

            String name = Enum.GetName( typeof( PolicyLevelType ), type );

            if (name == null)
                return null;

            String fullPath = Path.GetFullPath( path );

            FileIOPermission perm = new FileIOPermission( PermissionState.None );
            perm.AddPathList( FileIOPermissionAccess.Read, fullPath );
            perm.AddPathList( FileIOPermissionAccess.Write, fullPath );
            perm.Demand();

            PolicyLevel level = new PolicyLevel( name, id, type == PolicyLevelType.Machine );
            level.ThrowOnLoadError = true;
            level.CheckLoaded( false );
            return level;
        }
开发者ID:ArildF,项目名称:masters,代码行数:29,代码来源:securitymanager.cs

示例14: DemandPathDiscovery

 internal static void DemandPathDiscovery(string path)
 {
     FileIOPermission permobj = new FileIOPermission(PermissionState.None);
     permobj.AddPathList(FileIOPermissionAccess.PathDiscovery, path);
     permobj.Demand();
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:6,代码来源:SecurityHelper.cs

示例15: LoadPolicyLevelFromFile

        static public PolicyLevel LoadPolicyLevelFromFile(string path, PolicyLevelType type)
        {
            if (path == null)
               throw new ArgumentNullException( "path" );
            Contract.EndContractBlock();

            if (!AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled)
            {
                throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyExplicit"));
            }

            // We need to retain V1.x compatibility by throwing the same exception type.
            if (!File.InternalExists(path))
                throw new ArgumentException( Environment.GetResourceString("Argument_PolicyFileDoesNotExist"));

            String fullPath = Path.GetFullPath( path );

            FileIOPermission perm = new FileIOPermission( PermissionState.None );
            perm.AddPathList( FileIOPermissionAccess.Read, fullPath );
            perm.AddPathList( FileIOPermissionAccess.Write, fullPath );
            perm.Demand();

            using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) {
                using (StreamReader reader = new StreamReader(stream)) {
                    return LoadPolicyLevelFromStringHelper(reader.ReadToEnd(), path, type);
                }
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:28,代码来源:SecurityManager.cs


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