Beispiel #1
0
 internal void SetPathList(FileIOPermissionAccess access, AccessControlActions control, string[] pathList, bool checkForDuplicates)
 {
     FileIOPermission.VerifyAccess(access);
     if ((access & FileIOPermissionAccess.Read) != FileIOPermissionAccess.NoAccess)
     {
         this.m_read = (FileIOAccess)null;
     }
     if ((access & FileIOPermissionAccess.Write) != FileIOPermissionAccess.NoAccess)
     {
         this.m_write = (FileIOAccess)null;
     }
     if ((access & FileIOPermissionAccess.Append) != FileIOPermissionAccess.NoAccess)
     {
         this.m_append = (FileIOAccess)null;
     }
     if ((access & FileIOPermissionAccess.PathDiscovery) != FileIOPermissionAccess.NoAccess)
     {
         this.m_pathDiscovery = (FileIOAccess)null;
     }
     if ((control & AccessControlActions.View) != AccessControlActions.None)
     {
         this.m_viewAcl = (FileIOAccess)null;
     }
     if ((control & AccessControlActions.Change) != AccessControlActions.None)
     {
         this.m_changeAcl = (FileIOAccess)null;
     }
     this.m_unrestricted = false;
     this.AddPathList(access, control, pathList, checkForDuplicates, true, true);
 }
Beispiel #2
0
        /// <summary>创建一个权限,该权限是当前权限与指定权限的并集。</summary>
        /// <returns>一个新权限,它表示当前权限与指定权限的并集。</returns>
        /// <param name="other">将与当前权限合并的权限。它必须与当前权限属于同一类型。</param>
        /// <exception cref="T:System.ArgumentException">
        /// <paramref name="other" /> 参数不是 null,而且与当前权限不是同一类型。</exception>
        public override IPermission Union(IPermission other)
        {
            if (other == null)
            {
                return(this.Copy());
            }
            FileIOPermission fileIoPermission = other as FileIOPermission;

            if (fileIoPermission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName));
            }
            if (this.IsUnrestricted() || fileIoPermission.IsUnrestricted())
            {
                return((IPermission) new FileIOPermission(PermissionState.Unrestricted));
            }
            FileIOAccess fileIoAccess1 = this.m_read == null ? fileIoPermission.m_read : this.m_read.Union(fileIoPermission.m_read);
            FileIOAccess fileIoAccess2 = this.m_write == null ? fileIoPermission.m_write : this.m_write.Union(fileIoPermission.m_write);
            FileIOAccess fileIoAccess3 = this.m_append == null ? fileIoPermission.m_append : this.m_append.Union(fileIoPermission.m_append);
            FileIOAccess fileIoAccess4 = this.m_pathDiscovery == null ? fileIoPermission.m_pathDiscovery : this.m_pathDiscovery.Union(fileIoPermission.m_pathDiscovery);
            FileIOAccess fileIoAccess5 = this.m_viewAcl == null ? fileIoPermission.m_viewAcl : this.m_viewAcl.Union(fileIoPermission.m_viewAcl);
            FileIOAccess fileIoAccess6 = this.m_changeAcl == null ? fileIoPermission.m_changeAcl : this.m_changeAcl.Union(fileIoPermission.m_changeAcl);

            if ((fileIoAccess1 == null || fileIoAccess1.IsEmpty()) && (fileIoAccess2 == null || fileIoAccess2.IsEmpty()) && ((fileIoAccess3 == null || fileIoAccess3.IsEmpty()) && (fileIoAccess4 == null || fileIoAccess4.IsEmpty())) && ((fileIoAccess5 == null || fileIoAccess5.IsEmpty()) && (fileIoAccess6 == null || fileIoAccess6.IsEmpty())))
            {
                return((IPermission)null);
            }
            return((IPermission) new FileIOPermission(PermissionState.None)
            {
                m_unrestricted = false, m_read = fileIoAccess1, m_write = fileIoAccess2, m_append = fileIoAccess3, m_pathDiscovery = fileIoAccess4, m_viewAcl = fileIoAccess5, m_changeAcl = fileIoAccess6
            });
        }
Beispiel #3
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        internal void SetPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathList, bool checkForDuplicates)
        {
            VerifyAccess(access);

            if ((access & FileIOPermissionAccess.Read) != 0)
            {
                m_read = null;
            }

            if ((access & FileIOPermissionAccess.Write) != 0)
            {
                m_write = null;
            }

            if ((access & FileIOPermissionAccess.Append) != 0)
            {
                m_append = null;
            }

            if ((access & FileIOPermissionAccess.PathDiscovery) != 0)
            {
                m_pathDiscovery = null;
            }

            m_viewAcl      = null;
            m_changeAcl    = null;
            m_unrestricted = false;

            AddPathList(access, pathList, checkForDuplicates, true, true);
        }
Beispiel #4
0
 private FileIOAccess(FileIOAccess operand)
 {
     m_set           = operand.m_set.Copy();
     m_allFiles      = operand.m_allFiles;
     m_allLocalFiles = operand.m_allLocalFiles;
     m_pathDiscovery = operand.m_pathDiscovery;
 }
 public bool IsSubsetOf(FileIOAccess operand)
 {
     if (operand == null)
     {
         return(this.IsEmpty());
     }
     if (operand.m_allFiles)
     {
         return(true);
     }
     if ((!this.m_pathDiscovery || !this.m_set.IsSubsetOfPathDiscovery(operand.m_set)) && !this.m_set.IsSubsetOf(operand.m_set))
     {
         if (!operand.m_allLocalFiles)
         {
             return(false);
         }
         string[] array = this.m_set.UnsafeToStringArray();
         for (int i = 0; i < array.Length; i++)
         {
             string root = FileIOAccess.GetRoot(array[i]);
             if (root == null || !FileIOAccess.IsLocalDrive(FileIOAccess.GetRoot(root)))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
        public override IPermission Union(IPermission other)
        {
            if (other == null)
            {
                return(this.Copy());
            }
            FileIOPermission permission = other as FileIOPermission;

            if (permission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName }));
            }
            if (this.IsUnrestricted() || permission.IsUnrestricted())
            {
                return(new FileIOPermission(PermissionState.Unrestricted));
            }
            FileIOAccess access  = (this.m_read == null) ? permission.m_read : this.m_read.Union(permission.m_read);
            FileIOAccess access2 = (this.m_write == null) ? permission.m_write : this.m_write.Union(permission.m_write);
            FileIOAccess access3 = (this.m_append == null) ? permission.m_append : this.m_append.Union(permission.m_append);
            FileIOAccess access4 = (this.m_pathDiscovery == null) ? permission.m_pathDiscovery : this.m_pathDiscovery.Union(permission.m_pathDiscovery);
            FileIOAccess access5 = (this.m_viewAcl == null) ? permission.m_viewAcl : this.m_viewAcl.Union(permission.m_viewAcl);
            FileIOAccess access6 = (this.m_changeAcl == null) ? permission.m_changeAcl : this.m_changeAcl.Union(permission.m_changeAcl);

            if (((((access == null) || access.IsEmpty()) && ((access2 == null) || access2.IsEmpty())) && (((access3 == null) || access3.IsEmpty()) && ((access4 == null) || access4.IsEmpty()))) && (((access5 == null) || access5.IsEmpty()) && ((access6 == null) || access6.IsEmpty())))
            {
                return(null);
            }
            return(new FileIOPermission(PermissionState.None)
            {
                m_unrestricted = false, m_read = access, m_write = access2, m_append = access3, m_pathDiscovery = access4, m_viewAcl = access5, m_changeAcl = access6
            });
        }
Beispiel #7
0
        internal void SetPathList(FileIOPermissionAccess access, String[] pathList, bool checkForDuplicates)
        {
            VerifyAccess(access);

            if ((access & FileIOPermissionAccess.Read) != 0)
            {
                m_read = null;
            }

            if ((access & FileIOPermissionAccess.Write) != 0)
            {
                m_write = null;
            }

            if ((access & FileIOPermissionAccess.Append) != 0)
            {
                m_append = null;
            }

            if ((access & FileIOPermissionAccess.PathDiscovery) != 0)
            {
                m_pathDiscovery = null;
            }

            AddPathList(access, pathList, checkForDuplicates, true, true);
        }
 private FileIOAccess(FileIOAccess operand)
 {
     this.m_ignoreCase = true;
     this.m_set = operand.m_set.Copy();
     this.m_allFiles = operand.m_allFiles;
     this.m_allLocalFiles = operand.m_allLocalFiles;
     this.m_pathDiscovery = operand.m_pathDiscovery;
 }
 private FileIOAccess(FileIOAccess operand)
 {
     this.m_ignoreCase    = true;
     this.m_set           = operand.m_set.Copy();
     this.m_allFiles      = operand.m_allFiles;
     this.m_allLocalFiles = operand.m_allLocalFiles;
     this.m_pathDiscovery = operand.m_pathDiscovery;
 }
        public FileIOAccess Intersect(FileIOAccess operand)
        {
            if (operand == null)
            {
                return(null);
            }
            if (this.m_allFiles)
            {
                if (operand.m_allFiles)
                {
                    return(new FileIOAccess(true, false, this.m_pathDiscovery));
                }
                return(new FileIOAccess(operand.m_set.Copy(), false, operand.m_allLocalFiles, this.m_pathDiscovery));
            }
            if (operand.m_allFiles)
            {
                return(new FileIOAccess(this.m_set.Copy(), false, this.m_allLocalFiles, this.m_pathDiscovery));
            }
            StringExpressionSet set = new StringExpressionSet(this.m_ignoreCase, true);

            if (this.m_allLocalFiles)
            {
                string[] strArray = operand.m_set.ToStringArray();
                if (strArray != null)
                {
                    for (int i = 0; i < strArray.Length; i++)
                    {
                        string root = GetRoot(strArray[i]);
                        if ((root != null) && IsLocalDrive(GetRoot(root)))
                        {
                            set.AddExpressions(new string[] { strArray[i] }, true, false);
                        }
                    }
                }
            }
            if (operand.m_allLocalFiles)
            {
                string[] strArray2 = this.m_set.ToStringArray();
                if (strArray2 != null)
                {
                    for (int j = 0; j < strArray2.Length; j++)
                    {
                        string path = GetRoot(strArray2[j]);
                        if ((path != null) && IsLocalDrive(GetRoot(path)))
                        {
                            set.AddExpressions(new string[] { strArray2[j] }, true, false);
                        }
                    }
                }
            }
            string[] strArray3 = this.m_set.Intersect(operand.m_set).ToStringArray();
            if (strArray3 != null)
            {
                set.AddExpressions(strArray3, !set.IsEmpty(), false);
            }
            return(new FileIOAccess(set, false, this.m_allLocalFiles && operand.m_allLocalFiles, this.m_pathDiscovery));
        }
Beispiel #11
0
        /// <include file='doc\FileIOPermission.uex' path='docs/doc[@for="FileIOPermission.FromXml"]/*' />
        public override void FromXml(SecurityElement esd)
        {
            CodeAccessPermission.ValidateElement(esd, this);
            String et;

            if (XMLUtil.IsUnrestricted(esd))
            {
                m_unrestricted = true;
                return;
            }


            m_unrestricted = false;

            et = esd.Attribute("Read");
            if (et != null)
            {
                m_read = new FileIOAccess(et);
            }
            else
            {
                m_read = null;
            }

            et = esd.Attribute("Write");
            if (et != null)
            {
                m_write = new FileIOAccess(et);
            }
            else
            {
                m_write = null;
            }

            et = esd.Attribute("Append");
            if (et != null)
            {
                m_append = new FileIOAccess(et);
            }
            else
            {
                m_append = null;
            }

            et = esd.Attribute("PathDiscovery");
            if (et != null)
            {
                m_pathDiscovery = new FileIOAccess(et);
                m_pathDiscovery.PathDiscovery = true;
            }
            else
            {
                m_pathDiscovery = null;
            }
        }
        internal void AddPathList(FileIOPermissionAccess access, String[] pathList, bool checkForDuplicates, bool needFullPath)
        {
            VerifyAccess(access);

            if (pathList == null)
            {
                throw new ArgumentNullException("pathList");
            }
            if (pathList.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"));
            }

            HasIllegalCharacters(pathList);

            m_unrestricted = false;

            if ((access & FileIOPermissionAccess.Read) != 0)
            {
                if (m_read == null)
                {
                    m_read = new FileIOAccess();
                }
                m_read.AddExpressions(pathList, checkForDuplicates, needFullPath);
            }

            if ((access & FileIOPermissionAccess.Write) != 0)
            {
                if (m_write == null)
                {
                    m_write = new FileIOAccess();
                }
                m_write.AddExpressions(pathList, checkForDuplicates, needFullPath);
            }

            if ((access & FileIOPermissionAccess.Append) != 0)
            {
                if (m_append == null)
                {
                    m_append = new FileIOAccess();
                }
                m_append.AddExpressions(pathList, checkForDuplicates, needFullPath);
            }

            if ((access & FileIOPermissionAccess.PathDiscovery) != 0)
            {
                if (m_pathDiscovery == null)
                {
                    m_pathDiscovery = new FileIOAccess(true);
                }
                m_pathDiscovery.AddExpressions(pathList, checkForDuplicates, needFullPath);
            }
        }
Beispiel #13
0
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }

            FileIOPermission operand = target as FileIOPermission;

            if (operand == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
            }
            else if (this.IsUnrestricted())
            {
                return(target.Copy());
            }

            if (operand.IsUnrestricted())
            {
                return(this.Copy());
            }

            FileIOAccess intersectRead          = this.m_read == null ? null : this.m_read.Intersect(operand.m_read);
            FileIOAccess intersectWrite         = this.m_write == null ? null : this.m_write.Intersect(operand.m_write);
            FileIOAccess intersectAppend        = this.m_append == null ? null : this.m_append.Intersect(operand.m_append);
            FileIOAccess intersectPathDiscovery = this.m_pathDiscovery == null ? null : this.m_pathDiscovery.Intersect(operand.m_pathDiscovery);
            FileIOAccess intersectViewAcl       = this.m_viewAcl == null ? null : this.m_viewAcl.Intersect(operand.m_viewAcl);
            FileIOAccess intersectChangeAcl     = this.m_changeAcl == null ? null : this.m_changeAcl.Intersect(operand.m_changeAcl);

            if ((intersectRead == null || intersectRead.IsEmpty()) &&
                (intersectWrite == null || intersectWrite.IsEmpty()) &&
                (intersectAppend == null || intersectAppend.IsEmpty()) &&
                (intersectPathDiscovery == null || intersectPathDiscovery.IsEmpty()) &&
                (intersectViewAcl == null || intersectViewAcl.IsEmpty()) &&
                (intersectChangeAcl == null || intersectChangeAcl.IsEmpty()))
            {
                return(null);
            }

            FileIOPermission intersectPermission = new FileIOPermission(PermissionState.None);

            intersectPermission.m_unrestricted  = false;
            intersectPermission.m_read          = intersectRead;
            intersectPermission.m_write         = intersectWrite;
            intersectPermission.m_append        = intersectAppend;
            intersectPermission.m_pathDiscovery = intersectPathDiscovery;
            intersectPermission.m_viewAcl       = intersectViewAcl;
            intersectPermission.m_changeAcl     = intersectChangeAcl;

            return(intersectPermission);
        }
        public override bool Equals(object obj)
        {
            FileIOAccess fileIOAccess = obj as FileIOAccess;

            if (fileIOAccess == null)
            {
                return(this.IsEmpty() && obj == null);
            }
            if (this.m_pathDiscovery)
            {
                return((this.m_allFiles && fileIOAccess.m_allFiles) || (this.m_allLocalFiles == fileIOAccess.m_allLocalFiles && this.m_set.IsSubsetOf(fileIOAccess.m_set) && fileIOAccess.m_set.IsSubsetOf(this.m_set)));
            }
            return(this.IsSubsetOf(fileIOAccess) && fileIOAccess.IsSubsetOf(this));
        }
Beispiel #15
0
        public override IPermission Union(IPermission other)
        {
            if (other == null)
            {
                return(this.Copy());
            }

            FileIOPermission operand = other as FileIOPermission;

            if (operand == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
            }

            if (this.IsUnrestricted() || operand.IsUnrestricted())
            {
                return(new FileIOPermission(PermissionState.Unrestricted));
            }

            FileIOAccess unionRead          = this.m_read == null ? operand.m_read : this.m_read.Union(operand.m_read);
            FileIOAccess unionWrite         = this.m_write == null ? operand.m_write : this.m_write.Union(operand.m_write);
            FileIOAccess unionAppend        = this.m_append == null ? operand.m_append : this.m_append.Union(operand.m_append);
            FileIOAccess unionPathDiscovery = this.m_pathDiscovery == null ? operand.m_pathDiscovery : this.m_pathDiscovery.Union(operand.m_pathDiscovery);
            FileIOAccess unionViewAcl       = this.m_viewAcl == null ? operand.m_viewAcl : this.m_viewAcl.Union(operand.m_viewAcl);
            FileIOAccess unionChangeAcl     = this.m_changeAcl == null ? operand.m_changeAcl : this.m_changeAcl.Union(operand.m_changeAcl);

            if ((unionRead == null || unionRead.IsEmpty()) &&
                (unionWrite == null || unionWrite.IsEmpty()) &&
                (unionAppend == null || unionAppend.IsEmpty()) &&
                (unionPathDiscovery == null || unionPathDiscovery.IsEmpty()) &&
                (unionViewAcl == null || unionViewAcl.IsEmpty()) &&
                (unionChangeAcl == null || unionChangeAcl.IsEmpty()))
            {
                return(null);
            }

            FileIOPermission unionPermission = new FileIOPermission(PermissionState.None);

            unionPermission.m_unrestricted  = false;
            unionPermission.m_read          = unionRead;
            unionPermission.m_write         = unionWrite;
            unionPermission.m_append        = unionAppend;
            unionPermission.m_pathDiscovery = unionPathDiscovery;
            unionPermission.m_viewAcl       = unionViewAcl;
            unionPermission.m_changeAcl     = unionChangeAcl;

            return(unionPermission);
        }
Beispiel #16
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public FileIOAccess Union(FileIOAccess operand)
        {
            if (operand == null)
            {
                return(this.IsEmpty() ? null : this.Copy());
            }

            Contract.Assert(this.m_pathDiscovery == operand.m_pathDiscovery, "Path discovery settings must match");

            if (this.m_allFiles || operand.m_allFiles)
            {
                return(new FileIOAccess(true, false, this.m_pathDiscovery));
            }

            return(new FileIOAccess(this.m_set.Union(operand.m_set), false, this.m_allLocalFiles || operand.m_allLocalFiles, this.m_pathDiscovery));
        }
Beispiel #17
0
 public FileIOAccess Union(FileIOAccess operand)
 {
     if (operand == null)
     {
         if (!this.IsEmpty())
         {
             return(this.Copy());
         }
         return((FileIOAccess)null);
     }
     if (this.m_allFiles || operand.m_allFiles)
     {
         return(new FileIOAccess(true, false, this.m_pathDiscovery));
     }
     return(new FileIOAccess(this.m_set.Union(operand.m_set), false, this.m_allLocalFiles || operand.m_allLocalFiles, this.m_pathDiscovery));
 }
Beispiel #18
0
        public override bool Equals(object obj)
        {
            FileIOAccess operand = obj as FileIOAccess;

            if (operand == null)
            {
                if (this.IsEmpty())
                {
                    return(obj == null);
                }
                return(false);
            }
            if (this.m_pathDiscovery)
            {
                return(this.m_allFiles && operand.m_allFiles || this.m_allLocalFiles == operand.m_allLocalFiles && this.m_set.IsSubsetOf(operand.m_set) && operand.m_set.IsSubsetOf(this.m_set));
            }
            return(this.IsSubsetOf(operand) && operand.IsSubsetOf(this));
        }
Beispiel #19
0
 public override void FromXml(SecurityElement esd)
 {
     CodeAccessPermission.ValidateElement(esd, (IPermission)this);
     if (XMLUtil.IsUnrestricted(esd))
     {
         this.m_unrestricted = true;
     }
     else
     {
         this.m_unrestricted = false;
         string str1 = esd.Attribute("Read");
         this.m_read = str1 == null ? (FileIOAccess)null : new FileIOAccess(str1);
         string str2 = esd.Attribute("Write");
         this.m_write = str2 == null ? (FileIOAccess)null : new FileIOAccess(str2);
         string str3 = esd.Attribute("Append");
         this.m_append = str3 == null ? (FileIOAccess)null : new FileIOAccess(str3);
         string str4 = esd.Attribute("PathDiscovery");
         if (str4 != null)
         {
             this.m_pathDiscovery = new FileIOAccess(str4);
             this.m_pathDiscovery.PathDiscovery = true;
         }
         else
         {
             this.m_pathDiscovery = (FileIOAccess)null;
         }
         string str5 = esd.Attribute("ViewAcl");
         this.m_viewAcl = str5 == null ? (FileIOAccess)null : new FileIOAccess(str5);
         string str6 = esd.Attribute("ChangeAcl");
         if (str6 != null)
         {
             this.m_changeAcl = new FileIOAccess(str6);
         }
         else
         {
             this.m_changeAcl = (FileIOAccess)null;
         }
     }
 }
Beispiel #20
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public bool IsSubsetOf(FileIOAccess operand)
        {
            if (operand == null)
            {
                return(this.IsEmpty());
            }

            if (operand.m_allFiles)
            {
                return(true);
            }

            Contract.Assert(this.m_pathDiscovery == operand.m_pathDiscovery, "Path discovery settings must match");

            if (!((m_pathDiscovery && this.m_set.IsSubsetOfPathDiscovery(operand.m_set)) || this.m_set.IsSubsetOf(operand.m_set)))
            {
                if (operand.m_allLocalFiles)
                {
                    String[] expressions = m_set.UnsafeToStringArray();

                    for (int i = 0; i < expressions.Length; ++i)
                    {
                        String root = GetRoot(expressions[i]);
                        if (root == null || !IsLocalDrive(GetRoot(root)))
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #21
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public override bool Equals(Object obj)
        {
            FileIOAccess operand = obj as FileIOAccess;

            if (operand == null)
            {
                return(IsEmpty() && obj == null);
            }
            Contract.Assert(this.m_pathDiscovery == operand.m_pathDiscovery, "Path discovery settings must match");
            if (m_pathDiscovery)
            {
                if (this.m_allFiles && operand.m_allFiles)
                {
                    return(true);
                }
                if (this.m_allLocalFiles == operand.m_allLocalFiles &&
                    m_set.IsSubsetOf(operand.m_set) &&
                    operand.m_set.IsSubsetOf(m_set)) // Watch Out: This calls StringExpressionSet.IsSubsetOf, unlike below
                {
                    return(true);
                }
                return(false);
            }
            else
            {
                if (!this.IsSubsetOf(operand)) // Watch Out: This calls FileIOAccess.IsSubsetOf, unlike above
                {
                    return(false);
                }
                if (!operand.IsSubsetOf(this))
                {
                    return(false);
                }
                return(true);
            }
        }
Beispiel #22
0
 public bool IsSubsetOf(FileIOAccess operand)
 {
     if (operand == null)
     {
         return(this.IsEmpty());
     }
     if (operand.m_allFiles || this.m_pathDiscovery && this.m_set.IsSubsetOfPathDiscovery(operand.m_set) || this.m_set.IsSubsetOf(operand.m_set))
     {
         return(true);
     }
     if (!operand.m_allLocalFiles)
     {
         return(false);
     }
     foreach (string @string in this.m_set.UnsafeToStringArray())
     {
         string root = FileIOAccess.GetRoot(@string);
         if (root == null || !FileIOAccess.IsLocalDrive(FileIOAccess.GetRoot(root)))
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #23
0
        [System.Security.SecurityCritical]  // auto-generated
        internal void AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, bool checkForDuplicates, bool needFullPath, bool copyPathList)
        {
            if (pathListOrig == null)
            {
                throw new ArgumentNullException("pathList");
            }
            if (pathListOrig.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"));
            }
            Contract.EndContractBlock();

            VerifyAccess(access);

            if (m_unrestricted)
            {
                return;
            }

            String[] pathList = pathListOrig;
            if (copyPathList)
            {
                // Make a copy of pathList (in case its value changes after we check for illegal chars)
                pathList = new String[pathListOrig.Length];
                Array.Copy(pathListOrig, pathList, pathListOrig.Length);
            }

            CheckIllegalCharacters(pathList);
            ArrayList pathArrayList = StringExpressionSet.CreateListFromExpressions(pathList, needFullPath);

            if ((access & FileIOPermissionAccess.Read) != 0)
            {
                if (m_read == null)
                {
                    m_read = new FileIOAccess();
                }
                m_read.AddExpressions(pathArrayList, checkForDuplicates);
            }

            if ((access & FileIOPermissionAccess.Write) != 0)
            {
                if (m_write == null)
                {
                    m_write = new FileIOAccess();
                }
                m_write.AddExpressions(pathArrayList, checkForDuplicates);
            }

            if ((access & FileIOPermissionAccess.Append) != 0)
            {
                if (m_append == null)
                {
                    m_append = new FileIOAccess();
                }
                m_append.AddExpressions(pathArrayList, checkForDuplicates);
            }

            if ((access & FileIOPermissionAccess.PathDiscovery) != 0)
            {
                if (m_pathDiscovery == null)
                {
                    m_pathDiscovery = new FileIOAccess(true);
                }
                m_pathDiscovery.AddExpressions(pathArrayList, checkForDuplicates);
            }

#if FEATURE_MACL
            if ((control & AccessControlActions.View) != 0)
            {
                if (m_viewAcl == null)
                {
                    m_viewAcl = new FileIOAccess();
                }
                m_viewAcl.AddExpressions(pathArrayList, checkForDuplicates);
            }

            if ((control & AccessControlActions.Change) != 0)
            {
                if (m_changeAcl == null)
                {
                    m_changeAcl = new FileIOAccess();
                }
                m_changeAcl.AddExpressions(pathArrayList, checkForDuplicates);
            }
#endif
        }
Beispiel #24
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public FileIOAccess Intersect(FileIOAccess operand)
        {
            if (operand == null)
            {
                return(null);
            }

            Contract.Assert(this.m_pathDiscovery == operand.m_pathDiscovery, "Path discovery settings must match");

            if (this.m_allFiles)
            {
                if (operand.m_allFiles)
                {
                    return(new FileIOAccess(true, false, this.m_pathDiscovery));
                }
                else
                {
                    return(new FileIOAccess(operand.m_set.Copy(), false, operand.m_allLocalFiles, this.m_pathDiscovery));
                }
            }
            else if (operand.m_allFiles)
            {
                return(new FileIOAccess(this.m_set.Copy(), false, this.m_allLocalFiles, this.m_pathDiscovery));
            }

            StringExpressionSet intersectionSet = new StringExpressionSet(m_ignoreCase, true);

            if (this.m_allLocalFiles)
            {
                String[] expressions = operand.m_set.UnsafeToStringArray();

                if (expressions != null)
                {
                    for (int i = 0; i < expressions.Length; ++i)
                    {
                        String root = GetRoot(expressions[i]);
                        if (root != null && IsLocalDrive(GetRoot(root)))
                        {
                            intersectionSet.AddExpressions(new String[] { expressions[i] }, true, false);
                        }
                    }
                }
            }

            if (operand.m_allLocalFiles)
            {
                String[] expressions = this.m_set.UnsafeToStringArray();

                if (expressions != null)
                {
                    for (int i = 0; i < expressions.Length; ++i)
                    {
                        String root = GetRoot(expressions[i]);
                        if (root != null && IsLocalDrive(GetRoot(root)))
                        {
                            intersectionSet.AddExpressions(new String[] { expressions[i] }, true, false);
                        }
                    }
                }
            }

            String[] regularIntersection = this.m_set.Intersect(operand.m_set).UnsafeToStringArray();

            if (regularIntersection != null)
            {
                intersectionSet.AddExpressions(regularIntersection, !intersectionSet.IsEmpty(), false);
            }

            return(new FileIOAccess(intersectionSet, false, this.m_allLocalFiles && operand.m_allLocalFiles, this.m_pathDiscovery));
        }
        internal void SetPathList( FileIOPermissionAccess access, 
            String[] pathList, bool checkForDuplicates )
        {
            VerifyAccess( access );
            
            if ((access & FileIOPermissionAccess.Read) != 0)
                m_read = null;
            
            if ((access & FileIOPermissionAccess.Write) != 0)
                m_write = null;
    
            if ((access & FileIOPermissionAccess.Append) != 0)
                m_append = null;

            if ((access & FileIOPermissionAccess.PathDiscovery) != 0)
                m_pathDiscovery = null;

            m_viewAcl = null;
            m_changeAcl = null;
            
            m_unrestricted = false;
            AddPathList( access, pathList, checkForDuplicates, true, true );
        }
 private bool IsAssemblyUnderAppBase()
 {
     string location = this.Location;
     if (string.IsNullOrEmpty(location))
     {
         return true;
     }
     FileIOAccess access = new FileIOAccess(Path.GetFullPathInternal(location));
     FileIOAccess operand = new FileIOAccess(Path.GetFullPathInternal(AppDomain.CurrentDomain.BaseDirectory));
     return access.IsSubsetOf(operand);
 }
 public FileIOAccess Intersect(FileIOAccess operand)
 {
     if (operand == null)
     {
         return null;
     }
     if (this.m_allFiles)
     {
         if (operand.m_allFiles)
         {
             return new FileIOAccess(true, false, this.m_pathDiscovery);
         }
         return new FileIOAccess(operand.m_set.Copy(), false, operand.m_allLocalFiles, this.m_pathDiscovery);
     }
     if (operand.m_allFiles)
     {
         return new FileIOAccess(this.m_set.Copy(), false, this.m_allLocalFiles, this.m_pathDiscovery);
     }
     StringExpressionSet set = new StringExpressionSet(this.m_ignoreCase, true);
     if (this.m_allLocalFiles)
     {
         string[] strArray = operand.m_set.ToStringArray();
         if (strArray != null)
         {
             for (int i = 0; i < strArray.Length; i++)
             {
                 string root = GetRoot(strArray[i]);
                 if ((root != null) && IsLocalDrive(GetRoot(root)))
                 {
                     set.AddExpressions(new string[] { strArray[i] }, true, false);
                 }
             }
         }
     }
     if (operand.m_allLocalFiles)
     {
         string[] strArray2 = this.m_set.ToStringArray();
         if (strArray2 != null)
         {
             for (int j = 0; j < strArray2.Length; j++)
             {
                 string path = GetRoot(strArray2[j]);
                 if ((path != null) && IsLocalDrive(GetRoot(path)))
                 {
                     set.AddExpressions(new string[] { strArray2[j] }, true, false);
                 }
             }
         }
     }
     string[] strArray3 = this.m_set.Intersect(operand.m_set).ToStringArray();
     if (strArray3 != null)
     {
         set.AddExpressions(strArray3, !set.IsEmpty(), false);
     }
     return new FileIOAccess(set, false, this.m_allLocalFiles && operand.m_allLocalFiles, this.m_pathDiscovery);
 }
Beispiel #28
0
        internal void AddPathList(FileIOPermissionAccess access, String[] pathListOrig, bool checkForDuplicates, bool needFullPath, bool copyPathList)
        {
            VerifyAccess(access);

            if (pathListOrig == null)
            {
                throw new ArgumentNullException("pathList");
            }
            if (pathListOrig.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"));
            }

            String[] pathList = pathListOrig;
            if (copyPathList)
            {
                // Make a copy of pathList (in case its value changes after we check for illegal chars)
                pathList = new String[pathListOrig.Length];
                Array.Copy(pathListOrig, pathList, pathListOrig.Length);
            }

            HasIllegalCharacters(pathList);

            m_unrestricted = false;

            if ((access & FileIOPermissionAccess.Read) != 0)
            {
                if (m_read == null)
                {
                    m_read = new FileIOAccess();
                }
                m_read.AddExpressions(pathList, checkForDuplicates, needFullPath);
            }

            if ((access & FileIOPermissionAccess.Write) != 0)
            {
                if (m_write == null)
                {
                    m_write = new FileIOAccess();
                }
                m_write.AddExpressions(pathList, checkForDuplicates, needFullPath);
            }

            if ((access & FileIOPermissionAccess.Append) != 0)
            {
                if (m_append == null)
                {
                    m_append = new FileIOAccess();
                }
                m_append.AddExpressions(pathList, checkForDuplicates, needFullPath);
            }

            if ((access & FileIOPermissionAccess.PathDiscovery) != 0)
            {
                if (m_pathDiscovery == null)
                {
                    m_pathDiscovery = new FileIOAccess(true);
                }
                m_pathDiscovery.AddExpressions(pathList, checkForDuplicates, needFullPath);
            }
        }
        private static FileIOAccess FileIOAccessFromPath(string fullPath) {
            FileIOAccess access = new FileIOAccess();

#if FEATURE_WINDOWSPHONE
            // Due to an interaction between the ACLs on the phone for the directories isolated storage lives in
            // and GetLongPathNameW (which StringExpressionSet.CreateListFromExpressions ends up calling if the
            // path name has a ~ in it), we remove all ~'s before constructing the path to demand.
            //
            // The risk here is the case where there's a short file name that resolves to a path not under the root
            // of Isolated Storage, but in that case either the Win32 ACLs will prevent access or the user could
            // have accessed the files anyway.  Since Isolated Storage is not a security boundary in Windows Phone
            // we are not concerned about this case.
            fullPath = fullPath.Replace("~", "");
#endif

            ArrayList expressions = StringExpressionSet.CreateListFromExpressions(new string[] { fullPath }, true);
            access.AddExpressions(expressions, false);
            return access;
        }
 public FileIOAccess Intersect(FileIOAccess operand)
 {
     if (operand == null)
     {
         return(null);
     }
     if (this.m_allFiles)
     {
         if (operand.m_allFiles)
         {
             return(new FileIOAccess(true, false, this.m_pathDiscovery));
         }
         return(new FileIOAccess(operand.m_set.Copy(), false, operand.m_allLocalFiles, this.m_pathDiscovery));
     }
     else
     {
         if (operand.m_allFiles)
         {
             return(new FileIOAccess(this.m_set.Copy(), false, this.m_allLocalFiles, this.m_pathDiscovery));
         }
         StringExpressionSet stringExpressionSet = new StringExpressionSet(this.m_ignoreCase, true);
         if (this.m_allLocalFiles)
         {
             string[] array = operand.m_set.UnsafeToStringArray();
             if (array != null)
             {
                 for (int i = 0; i < array.Length; i++)
                 {
                     string root = FileIOAccess.GetRoot(array[i]);
                     if (root != null && FileIOAccess.IsLocalDrive(FileIOAccess.GetRoot(root)))
                     {
                         stringExpressionSet.AddExpressions(new string[]
                         {
                             array[i]
                         }, true, false);
                     }
                 }
             }
         }
         if (operand.m_allLocalFiles)
         {
             string[] array2 = this.m_set.UnsafeToStringArray();
             if (array2 != null)
             {
                 for (int j = 0; j < array2.Length; j++)
                 {
                     string root2 = FileIOAccess.GetRoot(array2[j]);
                     if (root2 != null && FileIOAccess.IsLocalDrive(FileIOAccess.GetRoot(root2)))
                     {
                         stringExpressionSet.AddExpressions(new string[]
                         {
                             array2[j]
                         }, true, false);
                     }
                 }
             }
         }
         string[] array3 = this.m_set.Intersect(operand.m_set).UnsafeToStringArray();
         if (array3 != null)
         {
             stringExpressionSet.AddExpressions(array3, !stringExpressionSet.IsEmpty(), false);
         }
         return(new FileIOAccess(stringExpressionSet, false, this.m_allLocalFiles && operand.m_allLocalFiles, this.m_pathDiscovery));
     }
 }
 public FileIOAccess Union(FileIOAccess operand)
 {
     if (operand == null)
     {
         if (!this.IsEmpty())
         {
             return this.Copy();
         }
         return null;
     }
     if (this.m_allFiles || operand.m_allFiles)
     {
         return new FileIOAccess(true, false, this.m_pathDiscovery);
     }
     return new FileIOAccess(this.m_set.Union(operand.m_set), false, this.m_allLocalFiles || operand.m_allLocalFiles, this.m_pathDiscovery);
 }
 internal void AddPathList(FileIOPermissionAccess access, AccessControlActions control, string[] pathListOrig, bool checkForDuplicates, bool needFullPath, bool copyPathList)
 {
     if (pathListOrig == null)
     {
         throw new ArgumentNullException("pathList");
     }
     if (pathListOrig.Length == 0)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"));
     }
     VerifyAccess(access);
     if (!this.m_unrestricted)
     {
         string[] destinationArray = pathListOrig;
         if (copyPathList)
         {
             destinationArray = new string[pathListOrig.Length];
             Array.Copy(pathListOrig, destinationArray, pathListOrig.Length);
         }
         HasIllegalCharacters(destinationArray);
         ArrayList values = StringExpressionSet.CreateListFromExpressions(destinationArray, needFullPath);
         if ((access & FileIOPermissionAccess.Read) != FileIOPermissionAccess.NoAccess)
         {
             if (this.m_read == null)
             {
                 this.m_read = new FileIOAccess();
             }
             this.m_read.AddExpressions(values, checkForDuplicates);
         }
         if ((access & FileIOPermissionAccess.Write) != FileIOPermissionAccess.NoAccess)
         {
             if (this.m_write == null)
             {
                 this.m_write = new FileIOAccess();
             }
             this.m_write.AddExpressions(values, checkForDuplicates);
         }
         if ((access & FileIOPermissionAccess.Append) != FileIOPermissionAccess.NoAccess)
         {
             if (this.m_append == null)
             {
                 this.m_append = new FileIOAccess();
             }
             this.m_append.AddExpressions(values, checkForDuplicates);
         }
         if ((access & FileIOPermissionAccess.PathDiscovery) != FileIOPermissionAccess.NoAccess)
         {
             if (this.m_pathDiscovery == null)
             {
                 this.m_pathDiscovery = new FileIOAccess(true);
             }
             this.m_pathDiscovery.AddExpressions(values, checkForDuplicates);
         }
         if ((control & AccessControlActions.View) != AccessControlActions.None)
         {
             if (this.m_viewAcl == null)
             {
                 this.m_viewAcl = new FileIOAccess();
             }
             this.m_viewAcl.AddExpressions(values, checkForDuplicates);
         }
         if ((control & AccessControlActions.Change) != AccessControlActions.None)
         {
             if (this.m_changeAcl == null)
             {
                 this.m_changeAcl = new FileIOAccess();
             }
             this.m_changeAcl.AddExpressions(values, checkForDuplicates);
         }
     }
 }
 public bool IsSubsetOf(FileIOAccess operand)
 {
     if (operand == null)
     {
         return this.IsEmpty();
     }
     if (!operand.m_allFiles && ((!this.m_pathDiscovery || !this.m_set.IsSubsetOfPathDiscovery(operand.m_set)) && !this.m_set.IsSubsetOf(operand.m_set)))
     {
         if (!operand.m_allLocalFiles)
         {
             return false;
         }
         string[] strArray = this.m_set.ToStringArray();
         for (int i = 0; i < strArray.Length; i++)
         {
             string root = GetRoot(strArray[i]);
             if ((root == null) || !IsLocalDrive(GetRoot(root)))
             {
                 return false;
             }
         }
     }
     return true;
 }
Beispiel #34
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public FileIOAccess Union( FileIOAccess operand )
        {
            if (operand == null)
            {
                return this.IsEmpty() ? null : this.Copy();
            }
            
            Contract.Assert( this.m_pathDiscovery == operand.m_pathDiscovery, "Path discovery settings must match" );

            if (this.m_allFiles || operand.m_allFiles)
            {
                return new FileIOAccess( true, false, this.m_pathDiscovery );
            }

            return new FileIOAccess( this.m_set.Union( operand.m_set ), false, this.m_allLocalFiles || operand.m_allLocalFiles, this.m_pathDiscovery );
        }
Beispiel #35
0
        [System.Security.SecurityCritical]  // auto-generated
        internal void AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, bool checkForDuplicates, bool needFullPath, bool copyPathList)
        {
            if (pathListOrig == null)
            {
                throw new ArgumentNullException( "pathList" );    
            }
            if (pathListOrig.Length == 0)
            {
                throw new ArgumentException( Environment.GetResourceString("Argument_EmptyPath" ));    
            }
            Contract.EndContractBlock();

            VerifyAccess(access);
                
            if (m_unrestricted)
                return;

            String[] pathList = pathListOrig;
            if(copyPathList)
            {
                // Make a copy of pathList (in case its value changes after we check for illegal chars)
                pathList = new String[pathListOrig.Length];
                Array.Copy(pathListOrig, pathList, pathListOrig.Length);
            }

            CheckIllegalCharacters( pathList );
            ArrayList pathArrayList = StringExpressionSet.CreateListFromExpressions(pathList, needFullPath);
            
            if ((access & FileIOPermissionAccess.Read) != 0)
            {
                if (m_read == null)
                {
                    m_read = new FileIOAccess();
                }
                m_read.AddExpressions( pathArrayList, checkForDuplicates);
            }
            
            if ((access & FileIOPermissionAccess.Write) != 0)
            {
                if (m_write == null)
                {
                    m_write = new FileIOAccess();
                }
                m_write.AddExpressions( pathArrayList, checkForDuplicates);
            }
    
            if ((access & FileIOPermissionAccess.Append) != 0)
            {
                if (m_append == null)
                {
                    m_append = new FileIOAccess();
                }
                m_append.AddExpressions( pathArrayList, checkForDuplicates);
            }

            if ((access & FileIOPermissionAccess.PathDiscovery) != 0)
            {
                if (m_pathDiscovery == null)
                {
                    m_pathDiscovery = new FileIOAccess( true );
                }
                m_pathDiscovery.AddExpressions( pathArrayList, checkForDuplicates);
            }

#if FEATURE_MACL
            if ((control & AccessControlActions.View) != 0)
            {
                if (m_viewAcl == null)
                {
                    m_viewAcl = new FileIOAccess();
                }
                m_viewAcl.AddExpressions( pathArrayList, checkForDuplicates);
            }

            if ((control & AccessControlActions.Change) != 0)
            {
                if (m_changeAcl == null)
                {
                    m_changeAcl = new FileIOAccess();
                }
                m_changeAcl.AddExpressions( pathArrayList, checkForDuplicates);
            }
#endif
        }
Beispiel #36
0
        [System.Security.SecurityCritical]  // auto-generated
        internal void AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, bool checkForDuplicates, bool needFullPath, bool copyPathList)
        {
            if (pathListOrig == null)
            {
                throw new ArgumentNullException("pathList");
            }
            if (pathListOrig.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"));
            }
            Contract.EndContractBlock();

            VerifyAccess(access);

            if (m_unrestricted)
            {
                return;
            }

            String[] pathList = pathListOrig;
            if (copyPathList)
            {
                // Make a copy of pathList (in case its value changes after we check for illegal chars)
                pathList = new String[pathListOrig.Length];
                Array.Copy(pathListOrig, pathList, pathListOrig.Length);
            }

            ArrayList pathArrayList = StringExpressionSet.CreateListFromExpressions(pathList, needFullPath);

            // If we need the full path the standard illegal characters will be checked in StringExpressionSet.
            CheckIllegalCharacters(pathList, onlyCheckExtras: needFullPath);

            // StringExpressionSet will do minor normalization, trimming spaces and replacing alternate
            // directory separators. It will make an attemt to expand short file names and will check
            // for standard colon placement.
            //
            // If needFullPath is true it will call NormalizePath- which performs short name expansion
            // and does the normal validity checks.

            if ((access & FileIOPermissionAccess.Read) != 0)
            {
                if (m_read == null)
                {
                    m_read = new FileIOAccess();
                }
                m_read.AddExpressions(pathArrayList, checkForDuplicates);
            }

            if ((access & FileIOPermissionAccess.Write) != 0)
            {
                if (m_write == null)
                {
                    m_write = new FileIOAccess();
                }
                m_write.AddExpressions(pathArrayList, checkForDuplicates);
            }

            if ((access & FileIOPermissionAccess.Append) != 0)
            {
                if (m_append == null)
                {
                    m_append = new FileIOAccess();
                }
                m_append.AddExpressions(pathArrayList, checkForDuplicates);
            }

            if ((access & FileIOPermissionAccess.PathDiscovery) != 0)
            {
                if (m_pathDiscovery == null)
                {
                    m_pathDiscovery = new FileIOAccess(true);
                }
                m_pathDiscovery.AddExpressions(pathArrayList, checkForDuplicates);
            }
        }
Beispiel #37
0
        public FileIOAccess Intersect(FileIOAccess operand)
        {
            if (operand == null)
            {
                return((FileIOAccess)null);
            }
            if (this.m_allFiles)
            {
                if (operand.m_allFiles)
                {
                    return(new FileIOAccess(true, false, this.m_pathDiscovery));
                }
                return(new FileIOAccess(operand.m_set.Copy(), false, operand.m_allLocalFiles, this.m_pathDiscovery));
            }
            if (operand.m_allFiles)
            {
                return(new FileIOAccess(this.m_set.Copy(), false, this.m_allLocalFiles, this.m_pathDiscovery));
            }
            StringExpressionSet set = new StringExpressionSet(this.m_ignoreCase, true);

            if (this.m_allLocalFiles)
            {
                string[] stringArray = operand.m_set.UnsafeToStringArray();
                if (stringArray != null)
                {
                    for (int index = 0; index < stringArray.Length; ++index)
                    {
                        string root = FileIOAccess.GetRoot(stringArray[index]);
                        if (root != null && FileIOAccess.IsLocalDrive(FileIOAccess.GetRoot(root)))
                        {
                            set.AddExpressions(new string[1]
                            {
                                stringArray[index]
                            }, 1 != 0, 0 != 0);
                        }
                    }
                }
            }
            if (operand.m_allLocalFiles)
            {
                string[] stringArray = this.m_set.UnsafeToStringArray();
                if (stringArray != null)
                {
                    for (int index = 0; index < stringArray.Length; ++index)
                    {
                        string root = FileIOAccess.GetRoot(stringArray[index]);
                        if (root != null && FileIOAccess.IsLocalDrive(FileIOAccess.GetRoot(root)))
                        {
                            set.AddExpressions(new string[1]
                            {
                                stringArray[index]
                            }, 1 != 0, 0 != 0);
                        }
                    }
                }
            }
            string[] stringArray1 = this.m_set.Intersect(operand.m_set).UnsafeToStringArray();
            if (stringArray1 != null)
            {
                set.AddExpressions(stringArray1, !set.IsEmpty(), false);
            }
            return(new FileIOAccess(set, false, this.m_allLocalFiles && operand.m_allLocalFiles, this.m_pathDiscovery));
        }
Beispiel #38
0
        public bool IsSubsetOf( FileIOAccess operand )
        {
            if (operand == null)
            {
                return this.IsEmpty();
            }
            
            if (operand.m_allFiles)
            {
                return true;
            }
            
            Contract.Assert( this.m_pathDiscovery == operand.m_pathDiscovery, "Path discovery settings must match" );

            if (!((m_pathDiscovery && this.m_set.IsSubsetOfPathDiscovery( operand.m_set )) || this.m_set.IsSubsetOf( operand.m_set )))
            {
                if (operand.m_allLocalFiles)
                {
                    String[] expressions = m_set.UnsafeToStringArray();
                
                    for (int i = 0; i < expressions.Length; ++i)
                    {
                        String root = GetRoot( expressions[i] );
                        if (root == null || !IsLocalDrive(GetRoot(root)))
                        {
                            return false;
                        }
                    }
                }
                else
                {
                    return false;
                }
            }
            
            return true;
        }
 public override void FromXml(SecurityElement esd)
 {
     CodeAccessPermission.ValidateElement(esd, this);
     if (XMLUtil.IsUnrestricted(esd))
     {
         this.m_unrestricted = true;
     }
     else
     {
         this.m_unrestricted = false;
         string str = esd.Attribute("Read");
         if (str != null)
         {
             this.m_read = new FileIOAccess(str);
         }
         else
         {
             this.m_read = null;
         }
         str = esd.Attribute("Write");
         if (str != null)
         {
             this.m_write = new FileIOAccess(str);
         }
         else
         {
             this.m_write = null;
         }
         str = esd.Attribute("Append");
         if (str != null)
         {
             this.m_append = new FileIOAccess(str);
         }
         else
         {
             this.m_append = null;
         }
         str = esd.Attribute("PathDiscovery");
         if (str != null)
         {
             this.m_pathDiscovery = new FileIOAccess(str);
             this.m_pathDiscovery.PathDiscovery = true;
         }
         else
         {
             this.m_pathDiscovery = null;
         }
         str = esd.Attribute("ViewAcl");
         if (str != null)
         {
             this.m_viewAcl = new FileIOAccess(str);
         }
         else
         {
             this.m_viewAcl = null;
         }
         str = esd.Attribute("ChangeAcl");
         if (str != null)
         {
             this.m_changeAcl = new FileIOAccess(str);
         }
         else
         {
             this.m_changeAcl = null;
         }
     }
 }
Beispiel #40
0
 private FileIOAccess( FileIOAccess operand )
 {
     m_set = operand.m_set.Copy();
     m_allFiles = operand.m_allFiles;
     m_allLocalFiles = operand.m_allLocalFiles;
     m_pathDiscovery = operand.m_pathDiscovery;
 }
Beispiel #41
0
        [System.Security.SecurityCritical]  // auto-generated
        internal void AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, bool checkForDuplicates, bool needFullPath, bool copyPathList)
        {
            if (pathListOrig == null)
            {
                throw new ArgumentNullException("pathList");
            }
            if (pathListOrig.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"));
            }
            Contract.EndContractBlock();
            // @

            VerifyAccess(access);

            if (m_unrestricted)
                return;

            String[] pathList = pathListOrig;
            if (copyPathList)
            {
                // Make a copy of pathList (in case its value changes after we check for illegal chars)
                pathList = new String[pathListOrig.Length];
                Array.Copy(pathListOrig, pathList, pathListOrig.Length);
            }

            // If we need the full path the standard illegal characters will be checked in StringExpressionSet.
            CheckIllegalCharacters(pathList, onlyCheckExtras: needFullPath);

            // StringExpressionSet will do minor normalization, trimming spaces and replacing alternate
            // directory separators. It will make an attemt to expand short file names and will check
            // for standard colon placement.
            //
            // If needFullPath is true it will call NormalizePath- which performs short name expansion
            // and does the normal validity checks.
            ArrayList pathArrayList = StringExpressionSet.CreateListFromExpressions(pathList, needFullPath);

            if ((access & FileIOPermissionAccess.Read) != 0)
            {
                if (m_read == null)
                {
                    m_read = new FileIOAccess();
                }
                m_read.AddExpressions(pathArrayList, checkForDuplicates);
            }

            if ((access & FileIOPermissionAccess.Write) != 0)
            {
                if (m_write == null)
                {
                    m_write = new FileIOAccess();
                }
                m_write.AddExpressions(pathArrayList, checkForDuplicates);
            }

            if ((access & FileIOPermissionAccess.Append) != 0)
            {
                if (m_append == null)
                {
                    m_append = new FileIOAccess();
                }
                m_append.AddExpressions(pathArrayList, checkForDuplicates);
            }

            if ((access & FileIOPermissionAccess.PathDiscovery) != 0)
            {
                if (m_pathDiscovery == null)
                {
                    m_pathDiscovery = new FileIOAccess(true);
                }
                m_pathDiscovery.AddExpressions(pathArrayList, checkForDuplicates);
            }

#if FEATURE_MACL
            if ((control & AccessControlActions.View) != 0)
            {
                if (m_viewAcl == null)
                {
                    m_viewAcl = new FileIOAccess();
                }
                m_viewAcl.AddExpressions(pathArrayList, checkForDuplicates);
            }

            if ((control & AccessControlActions.Change) != 0)
            {
                if (m_changeAcl == null)
                {
                    m_changeAcl = new FileIOAccess();
                }
                m_changeAcl.AddExpressions(pathArrayList, checkForDuplicates);
            }
#endif
        }
Beispiel #42
0
        public FileIOAccess Intersect( FileIOAccess operand )
        {
            if (operand == null)
            {
                return null;
            }
            
            Contract.Assert( this.m_pathDiscovery == operand.m_pathDiscovery, "Path discovery settings must match" );

            if (this.m_allFiles)
            {
                if (operand.m_allFiles)
                {
                    return new FileIOAccess( true, false, this.m_pathDiscovery );
                }
                else
                {
                    return new FileIOAccess( operand.m_set.Copy(), false, operand.m_allLocalFiles, this.m_pathDiscovery );
                }
            }
            else if (operand.m_allFiles)
            {
                return new FileIOAccess( this.m_set.Copy(), false, this.m_allLocalFiles, this.m_pathDiscovery );
            }

            StringExpressionSet intersectionSet = new StringExpressionSet( m_ignoreCase, true );

            if (this.m_allLocalFiles)
            {
                String[] expressions = operand.m_set.UnsafeToStringArray();
                
                if (expressions != null)
                {
                    for (int i = 0; i < expressions.Length; ++i)
                    {
                        String root = GetRoot( expressions[i] );
                        if (root != null && IsLocalDrive( GetRoot( root ) ) )
                        {
                            intersectionSet.AddExpressions( new String[] { expressions[i] }, true, false );
                        }
                    }
                }
            }

            if (operand.m_allLocalFiles)
            {
                String[] expressions = this.m_set.UnsafeToStringArray();

                if (expressions != null)
                {
                    for (int i = 0; i < expressions.Length; ++i)
                    {
                        String root = GetRoot( expressions[i] );
                        if (root != null && IsLocalDrive(GetRoot(root)))
                        {
                            intersectionSet.AddExpressions( new String[] { expressions[i] }, true, false );
                        }
                    }
                }
            }

            String[] regularIntersection = this.m_set.Intersect( operand.m_set ).UnsafeToStringArray();

            if (regularIntersection != null)
                intersectionSet.AddExpressions( regularIntersection, !intersectionSet.IsEmpty(), false );

            return new FileIOAccess( intersectionSet, false, this.m_allLocalFiles && operand.m_allLocalFiles, this.m_pathDiscovery );
        }
 internal void SetPathList(FileIOPermissionAccess access, AccessControlActions control, string[] pathList, bool checkForDuplicates)
 {
     VerifyAccess(access);
     if ((access & FileIOPermissionAccess.Read) != FileIOPermissionAccess.NoAccess)
     {
         this.m_read = null;
     }
     if ((access & FileIOPermissionAccess.Write) != FileIOPermissionAccess.NoAccess)
     {
         this.m_write = null;
     }
     if ((access & FileIOPermissionAccess.Append) != FileIOPermissionAccess.NoAccess)
     {
         this.m_append = null;
     }
     if ((access & FileIOPermissionAccess.PathDiscovery) != FileIOPermissionAccess.NoAccess)
     {
         this.m_pathDiscovery = null;
     }
     if ((control & AccessControlActions.View) != AccessControlActions.None)
     {
         this.m_viewAcl = null;
     }
     if ((control & AccessControlActions.Change) != AccessControlActions.None)
     {
         this.m_changeAcl = null;
     }
     this.m_unrestricted = false;
     this.AddPathList(access, control, pathList, checkForDuplicates, true, true);
 }
Beispiel #44
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        internal void SetPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathList, bool checkForDuplicates)
        {
            VerifyAccess(access);

            if ((access & FileIOPermissionAccess.Read) != 0)
                m_read = null;

            if ((access & FileIOPermissionAccess.Write) != 0)
                m_write = null;

            if ((access & FileIOPermissionAccess.Append) != 0)
                m_append = null;

            if ((access & FileIOPermissionAccess.PathDiscovery) != 0)
                m_pathDiscovery = null;

#if FEATURE_MACL
            if ((control & AccessControlActions.View) != 0)
                m_viewAcl = null;

            if ((control & AccessControlActions.Change) != 0)
                m_changeAcl = null;
#else
            m_viewAcl = null;
            m_changeAcl = null;
#endif

            m_unrestricted = false;
#if FEATURE_MACL
            AddPathList(access, control, pathList, checkForDuplicates, true, true);
#else
            AddPathList( access, pathList, checkForDuplicates, true, true );
#endif
        }
Beispiel #45
0
        internal void AddPathList(FileIOPermissionAccess access, AccessControlActions control, string[] pathListOrig, bool checkForDuplicates, bool needFullPath, bool copyPathList)
        {
            if (pathListOrig == null)
            {
                throw new ArgumentNullException("pathList");
            }
            if (pathListOrig.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"));
            }
            FileIOPermission.VerifyAccess(access);
            if (this.m_unrestricted)
            {
                return;
            }
            string[] str = pathListOrig;
            if (copyPathList)
            {
                str = new string[pathListOrig.Length];
                Array.Copy((Array)pathListOrig, (Array)str, pathListOrig.Length);
            }
            FileIOPermission.CheckIllegalCharacters(str);
            ArrayList listFromExpressions = StringExpressionSet.CreateListFromExpressions(str, needFullPath);

            if ((access & FileIOPermissionAccess.Read) != FileIOPermissionAccess.NoAccess)
            {
                if (this.m_read == null)
                {
                    this.m_read = new FileIOAccess();
                }
                this.m_read.AddExpressions(listFromExpressions, checkForDuplicates);
            }
            if ((access & FileIOPermissionAccess.Write) != FileIOPermissionAccess.NoAccess)
            {
                if (this.m_write == null)
                {
                    this.m_write = new FileIOAccess();
                }
                this.m_write.AddExpressions(listFromExpressions, checkForDuplicates);
            }
            if ((access & FileIOPermissionAccess.Append) != FileIOPermissionAccess.NoAccess)
            {
                if (this.m_append == null)
                {
                    this.m_append = new FileIOAccess();
                }
                this.m_append.AddExpressions(listFromExpressions, checkForDuplicates);
            }
            if ((access & FileIOPermissionAccess.PathDiscovery) != FileIOPermissionAccess.NoAccess)
            {
                if (this.m_pathDiscovery == null)
                {
                    this.m_pathDiscovery = new FileIOAccess(true);
                }
                this.m_pathDiscovery.AddExpressions(listFromExpressions, checkForDuplicates);
            }
            if ((control & AccessControlActions.View) != AccessControlActions.None)
            {
                if (this.m_viewAcl == null)
                {
                    this.m_viewAcl = new FileIOAccess();
                }
                this.m_viewAcl.AddExpressions(listFromExpressions, checkForDuplicates);
            }
            if ((control & AccessControlActions.Change) == AccessControlActions.None)
            {
                return;
            }
            if (this.m_changeAcl == null)
            {
                this.m_changeAcl = new FileIOAccess();
            }
            this.m_changeAcl.AddExpressions(listFromExpressions, checkForDuplicates);
        }
Beispiel #46
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public override void FromXml(SecurityElement esd)
        {
            CodeAccessPermission.ValidateElement(esd, this);
            String et;

            if (XMLUtil.IsUnrestricted(esd))
            {
                m_unrestricted = true;
                return;
            }


            m_unrestricted = false;

            et = esd.Attribute("Read");
            if (et != null)
            {
                m_read = new FileIOAccess(et);
            }
            else
            {
                m_read = null;
            }

            et = esd.Attribute("Write");
            if (et != null)
            {
                m_write = new FileIOAccess(et);
            }
            else
            {
                m_write = null;
            }

            et = esd.Attribute("Append");
            if (et != null)
            {
                m_append = new FileIOAccess(et);
            }
            else
            {
                m_append = null;
            }

            et = esd.Attribute("PathDiscovery");
            if (et != null)
            {
                m_pathDiscovery = new FileIOAccess(et);
                m_pathDiscovery.PathDiscovery = true;
            }
            else
            {
                m_pathDiscovery = null;
            }

            et = esd.Attribute("ViewAcl");
            if (et != null)
            {
                m_viewAcl = new FileIOAccess(et);
            }
            else
            {
                m_viewAcl = null;
            }

            et = esd.Attribute("ChangeAcl");
            if (et != null)
            {
                m_changeAcl = new FileIOAccess(et);
            }
            else
            {
                m_changeAcl = null;
            }
        }
Beispiel #47
0
        internal void AddPathList( FileIOPermissionAccess access, String[] pathList, bool checkForDuplicates, bool needFullPath )
        {
            VerifyAccess( access );
            
            if (pathList == null)
            {
                throw new ArgumentNullException( "pathList" );    
            }
            if (pathList.Length == 0)
            {
                throw new ArgumentException( Environment.GetResourceString("Argument_EmptyPath" ));    
            }
            
            HasIllegalCharacters( pathList );
            
            m_unrestricted = false;
            
            if ((access & FileIOPermissionAccess.Read) != 0)
            {
                if (m_read == null)
                {
                    m_read = new FileIOAccess();
                }
                m_read.AddExpressions( pathList, checkForDuplicates, needFullPath );
            }
            
            if ((access & FileIOPermissionAccess.Write) != 0)
            {
                if (m_write == null)
                {
                    m_write = new FileIOAccess();
                }
                m_write.AddExpressions( pathList, checkForDuplicates, needFullPath );
            }
    
            if ((access & FileIOPermissionAccess.Append) != 0)
            {
                if (m_append == null)
                {
                    m_append = new FileIOAccess();
                }
                m_append.AddExpressions( pathList, checkForDuplicates, needFullPath );
            }

            if ((access & FileIOPermissionAccess.PathDiscovery) != 0)
            {
                if (m_pathDiscovery == null)
                {
                    m_pathDiscovery = new FileIOAccess( true );
                }
                m_pathDiscovery.AddExpressions( pathList, checkForDuplicates, needFullPath );
            }

        }