상속: CodeAccessPermission, IUnrestrictedPermission, IBuiltInPermission
예제 #1
0
        // Methods
        public override IPermission CreatePermission()
        {
#if NET_2_1
            return(null);
#else
            EnvironmentPermission perm = null;
            if (this.Unrestricted)
            {
                perm = new EnvironmentPermission(PermissionState.Unrestricted);
            }
            else
            {
                perm = new EnvironmentPermission(PermissionState.None);
                if (read != null)
                {
                    perm.AddPathList(EnvironmentPermissionAccess.Read, read);
                }
                if (write != null)
                {
                    perm.AddPathList(EnvironmentPermissionAccess.Write, write);
                }
            }
            return(perm);
#endif
        }
        public override bool IsSubsetOf(IPermission target)
        {
            bool flag;

            if (target == null)
            {
                return(this.IsEmpty());
            }
            try
            {
                EnvironmentPermission permission = (EnvironmentPermission)target;
                if (permission.IsUnrestricted())
                {
                    return(true);
                }
                if (this.IsUnrestricted())
                {
                    return(false);
                }
                flag = ((this.m_read == null) || this.m_read.IsSubsetOf(permission.m_read)) && ((this.m_write == null) || this.m_write.IsSubsetOf(permission.m_write));
            }
            catch (InvalidCastException)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName }));
            }
            return(flag);
        }
        public override IPermission Union(IPermission other)
        {
            if (other == null)
            {
                return(this.Copy());
            }
            if (!base.VerifyType(other))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName }));
            }
            EnvironmentPermission permission = (EnvironmentPermission)other;

            if (this.IsUnrestricted() || permission.IsUnrestricted())
            {
                return(new EnvironmentPermission(PermissionState.Unrestricted));
            }
            StringExpressionSet set  = (this.m_read == null) ? permission.m_read : this.m_read.Union(permission.m_read);
            StringExpressionSet set2 = (this.m_write == null) ? permission.m_write : this.m_write.Union(permission.m_write);

            if (((set == null) || set.IsEmpty()) && ((set2 == null) || set2.IsEmpty()))
            {
                return(null);
            }
            return(new EnvironmentPermission(PermissionState.None)
            {
                m_unrestricted = false, m_read = set, m_write = set2
            });
        }
예제 #4
0
        /// <summary>Determines whether the current permission is a subset of the specified permission.</summary>
        /// <returns>true if the current permission is a subset of the specified permission; otherwise, false.</returns>
        /// <param name="target">A permission that is to be tested for the subset relationship. This permission must be of the same type as the current permission. </param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. </exception>
        public override bool IsSubsetOf(IPermission target)
        {
            EnvironmentPermission environmentPermission = this.Cast(target);

            if (environmentPermission == null)
            {
                return(false);
            }
            if (this.IsUnrestricted())
            {
                return(environmentPermission.IsUnrestricted());
            }
            if (environmentPermission.IsUnrestricted())
            {
                return(true);
            }
            foreach (object obj in this.readList)
            {
                string item = (string)obj;
                if (!environmentPermission.readList.Contains(item))
                {
                    return(false);
                }
            }
            foreach (object obj2 in this.writeList)
            {
                string item2 = (string)obj2;
                if (!environmentPermission.writeList.Contains(item2))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #5
0
        //------------------------------------------------------
        //
        // IPERMISSION IMPLEMENTATION
        //
        //------------------------------------------------------

        /// <include file='doc\EnvironmentPermission.uex' path='docs/doc[@for="EnvironmentPermission.IsSubsetOf"]/*' />
        public override bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                return(this.IsEmpty());
            }

            try
            {
                EnvironmentPermission operand = (EnvironmentPermission)target;
                if (operand.IsUnrestricted())
                {
                    return(true);
                }
                else if (this.IsUnrestricted())
                {
                    return(false);
                }
                else
                {
                    return((this.m_read == null || this.m_read.IsSubsetOf(operand.m_read)) &&
                           (this.m_write == null || this.m_write.IsSubsetOf(operand.m_write)));
                }
            }
            catch (InvalidCastException)
            {
                throw new
                      ArgumentException(
                          String.Format(Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName)
                          );
            }
        }
예제 #6
0
        /// <summary>Creates a permission that is the union of the current permission and the specified permission.</summary>
        /// <returns>A new permission that represents the union of the current permission and the specified permission.</returns>
        /// <param name="other">A permission to combine with the current permission. It must be of the same type as the current permission. </param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="other" /> parameter is not null and is not of the same type as the current permission. </exception>
        public override IPermission Union(IPermission other)
        {
            EnvironmentPermission environmentPermission = this.Cast(other);

            if (environmentPermission == null)
            {
                return(this.Copy());
            }
            if (this.IsUnrestricted() || environmentPermission.IsUnrestricted())
            {
                return(new EnvironmentPermission(PermissionState.Unrestricted));
            }
            if (this.IsEmpty() && environmentPermission.IsEmpty())
            {
                return(null);
            }
            EnvironmentPermission environmentPermission2 = (EnvironmentPermission)this.Copy();
            string pathList = environmentPermission.GetPathList(EnvironmentPermissionAccess.Read);

            if (pathList != null)
            {
                environmentPermission2.AddPathList(EnvironmentPermissionAccess.Read, pathList);
            }
            pathList = environmentPermission.GetPathList(EnvironmentPermissionAccess.Write);
            if (pathList != null)
            {
                environmentPermission2.AddPathList(EnvironmentPermissionAccess.Write, pathList);
            }
            return(environmentPermission2);
        }
        public static void Main()
        {
            TestMethodLevelSecurity me = new TestMethodLevelSecurity();

             me.dataHolder = new MyClassWithTypeSecurity(1964,06,16);

             // Local computer zone starts with all environment permissions.
             me.RetrievePersonalInformation("[All permissions]");

             // Deny the write permission required by the type.
             EnvironmentPermission epw = new EnvironmentPermission(
            EnvironmentPermissionAccess.Write,"PersonalInfo");
             epw.Deny();

             // Even though the type requires write permission,
             // and you do not have it; you can get the data.
             me.RetrievePersonalInformation(
            "[No write permission (demanded by type)]");

             // Reset the permissions and try to get
             // data without read permission.
             CodeAccessPermission.RevertAll();

             // Deny the read permission required by the method.
             EnvironmentPermission epr = new EnvironmentPermission(
            EnvironmentPermissionAccess.Read,"PersonalInfo");
             epr.Deny();

             // The method requires read permission, and you
             // do not have it; you cannot get the data.
             me.RetrievePersonalInformation(
            "[No read permission (demanded by method)]");
        }
        public static void Main()
        {
            EnvironmentPermission envPermission = new EnvironmentPermission(
            EnvironmentPermissionAccess.Read,
            "COMPUTERNAME;USERNAME;USERDOMAIN");
             envPermission.Deny();

             //Test Deny and Assert interaction for LinkDemands and Demands.
             TestAssertAndDeny();

             //Test Deny's effects on code in different stack frame.
             TestDenyAndLinkDemand();

             //Test Deny's effect on code in same frame as deny.
             try
             {
            SomeSecuredMethods.MethodProtectedByLinkDemand();
            Console.WriteLine(
               "This Deny has no effect with LinkDemand-protected code.");
             }
             catch (SecurityException e)
             {
            Console.WriteLine("This Deny protected the library.{0}",e);
             }
        }
예제 #9
0
        public override bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                return(this.IsEmpty());
            }
            bool result;

            try
            {
                EnvironmentPermission environmentPermission = (EnvironmentPermission)target;
                if (environmentPermission.IsUnrestricted())
                {
                    result = true;
                }
                else if (this.IsUnrestricted())
                {
                    result = false;
                }
                else
                {
                    result = ((this.m_read == null || this.m_read.IsSubsetOf(environmentPermission.m_read)) && (this.m_write == null || this.m_write.IsSubsetOf(environmentPermission.m_write)));
                }
            }
            catch (InvalidCastException)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[]
                {
                    base.GetType().FullName
                }));
            }
            return(result);
        }
        public static string EnvironmentSetting(string environmentVariable)
        {
            EnvironmentPermission envPermission = new EnvironmentPermission( EnvironmentPermissionAccess.Read,environmentVariable);
             envPermission.Assert();

             return Environment.GetEnvironmentVariable(environmentVariable);
        }
예제 #11
0
        public override IPermission Union(IPermission other)
        {
            EnvironmentPermission ep = Cast(other);

            if (ep == null)
            {
                return(Copy());
            }

            if (IsUnrestricted() || ep.IsUnrestricted())
            {
                return(new EnvironmentPermission(PermissionState.Unrestricted));
            }

            if (IsEmpty() && ep.IsEmpty())
            {
                return(null);
            }

            EnvironmentPermission result = (EnvironmentPermission)Copy();
            string path = ep.GetPathList(EnvironmentPermissionAccess.Read);

            if (path != null)
            {
                result.AddPathList(EnvironmentPermissionAccess.Read, path);
            }
            path = ep.GetPathList(EnvironmentPermissionAccess.Write);
            if (path != null)
            {
                result.AddPathList(EnvironmentPermissionAccess.Write, path);
            }
            return(result);
        }
예제 #12
0
		public void PermissionStateUnrestricted () 
		{
			EnvironmentPermission ep = new EnvironmentPermission (PermissionState.Unrestricted);
			Assert.IsNotNull (ep, "EnvironmentPermission(PermissionState.Unrestricted)");
			Assert.IsTrue (ep.IsUnrestricted (), "IsUnrestricted");
			EnvironmentPermission copy = (EnvironmentPermission) ep.Copy ();
			Assert.AreEqual (ep.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted");
			SecurityElement se = ep.ToXml ();
			Assert.AreEqual ("true", (se.Attributes ["Unrestricted"] as string), "ToXml-Unrestricted");
		}
 void InitializePart1() {
     if (m_environmentUserNamePermission == null) {
         lock(lockingObject) {
             if (m_environmentUserNamePermission == null) {
                 m_environmentDomainNamePermission = new EnvironmentPermission(EnvironmentPermissionAccess.Read, "USERDOMAIN");
                 m_environmentUserNamePermission = new EnvironmentPermission(EnvironmentPermissionAccess.Read, "USERNAME");
             }
         }
     }
 }
		public void PermissionStateUnrestricted () 
		{
			EnvironmentPermission ep = new EnvironmentPermission (PermissionState.Unrestricted);
			AssertNotNull ("EnvironmentPermission(PermissionState.Unrestricted)", ep);
			Assert ("IsUnrestricted", ep.IsUnrestricted ());
			EnvironmentPermission copy = (EnvironmentPermission) ep.Copy ();
			AssertEquals ("Copy.IsUnrestricted", ep.IsUnrestricted (), copy.IsUnrestricted ());
			SecurityElement se = ep.ToXml ();
			AssertEquals ("ToXml-Unrestricted", "true", (se.Attributes ["Unrestricted"] as string));
		}
 internal static PermissionSet _UnsafeGetAssertPermSet()
 {
     PermissionSet set = new PermissionSet(PermissionState.None);
     RegistryPermission perm = new RegistryPermission(PermissionState.Unrestricted);
     set.AddPermission(perm);
     EnvironmentPermission permission2 = new EnvironmentPermission(PermissionState.Unrestricted);
     set.AddPermission(permission2);
     SecurityPermission permission3 = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
     set.AddPermission(permission3);
     return set;
 }
예제 #16
0
        /// <summary>Creates and returns a permission that is the intersection of the current permission and the specified permission.</summary>
        /// <returns>A new permission that represents the intersection of the current permission and the specified permission. This new permission is null if the intersection is empty.</returns>
        /// <param name="target">A permission to intersect with the current permission. It must be of the same type as the current permission. </param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. </exception>
        public override IPermission Intersect(IPermission target)
        {
            EnvironmentPermission environmentPermission = this.Cast(target);

            if (environmentPermission == null)
            {
                return(null);
            }
            if (this.IsUnrestricted())
            {
                return(environmentPermission.Copy());
            }
            if (environmentPermission.IsUnrestricted())
            {
                return(this.Copy());
            }
            int num = 0;
            EnvironmentPermission environmentPermission2 = new EnvironmentPermission(PermissionState.None);
            string pathList = environmentPermission.GetPathList(EnvironmentPermissionAccess.Read);

            if (pathList != null)
            {
                string[] array = pathList.Split(new char[]
                {
                    ';'
                });
                foreach (string text in array)
                {
                    if (this.readList.Contains(text))
                    {
                        environmentPermission2.AddPathList(EnvironmentPermissionAccess.Read, text);
                        num++;
                    }
                }
            }
            string pathList2 = environmentPermission.GetPathList(EnvironmentPermissionAccess.Write);

            if (pathList2 != null)
            {
                string[] array3 = pathList2.Split(new char[]
                {
                    ';'
                });
                foreach (string text2 in array3)
                {
                    if (this.writeList.Contains(text2))
                    {
                        environmentPermission2.AddPathList(EnvironmentPermissionAccess.Write, text2);
                        num++;
                    }
                }
            }
            return((num <= 0) ? null : environmentPermission2);
        }
		public void PermissionStateNone () 
		{
			EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
			AssertNotNull ("EnvironmentPermission(PermissionState.None)", ep);
			Assert ("IsUnrestricted", !ep.IsUnrestricted ());
			EnvironmentPermission copy = (EnvironmentPermission) ep.Copy ();
			AssertEquals ("Copy.IsUnrestricted", ep.IsUnrestricted (), copy.IsUnrestricted ());
			SecurityElement se = ep.ToXml ();
			Assert ("ToXml-class", (se.Attributes ["class"] as string).StartsWith (className));
			AssertEquals ("ToXml-version", "1", (se.Attributes ["version"] as string));
		}
예제 #18
0
		public void PermissionStateNone () 
		{
			EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
			Assert.IsNotNull (ep, "EnvironmentPermission(PermissionState.None)");
			Assert.IsTrue (!ep.IsUnrestricted (), "IsUnrestricted");
			EnvironmentPermission copy = (EnvironmentPermission) ep.Copy ();
			Assert.AreEqual (ep.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted");
			SecurityElement se = ep.ToXml ();
			Assert.IsTrue ((se.Attributes ["class"] as string).StartsWith (className), "ToXml-class");
			Assert.AreEqual ("1", (se.Attributes ["version"] as string), "ToXml-version");
		}
        public override IPermission Intersect(IPermission target)
        {
            EnvironmentPermission ep = Cast(target);

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

            if (IsUnrestricted())
            {
                return(ep.Copy());
            }
            if (ep.IsUnrestricted())
            {
                return(Copy());
            }

            int n = 0;
            EnvironmentPermission result = new EnvironmentPermission(PermissionState.None);
            string readTarget            = ep.GetPathList(EnvironmentPermissionAccess.Read);

            if (readTarget != null)
            {
                string[] targets = readTarget.Split(';');
                foreach (string t in targets)
                {
                    if (readList.Contains(t))
                    {
                        result.AddPathList(EnvironmentPermissionAccess.Read, t);
                        n++;
                    }
                }
            }

            string writeTarget = ep.GetPathList(EnvironmentPermissionAccess.Write);

            if (writeTarget != null)
            {
                string[] targets = writeTarget.Split(';');
                foreach (string t in targets)
                {
                    if (writeList.Contains(t))
                    {
                        result.AddPathList(EnvironmentPermissionAccess.Write, t);
                        n++;
                    }
                }
            }
            return((n > 0) ? result : null);
        }
예제 #20
0
        private EnvironmentPermission Cast(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            EnvironmentPermission environmentPermission = target as EnvironmentPermission;

            if (environmentPermission == null)
            {
                CodeAccessPermission.ThrowInvalidPermission(target, typeof(EnvironmentPermission));
            }
            return(environmentPermission);
        }
예제 #21
0
 // Create a permission object that corresponds to this attribute.
 public override IPermission CreatePermission()
 {
     if (Unrestricted)
     {
         return(new EnvironmentPermission
                    (PermissionState.Unrestricted));
     }
     else
     {
         return(new EnvironmentPermission
                    (PermissionState.None,
                    EnvironmentPermission.SplitPath(read),
                    EnvironmentPermission.SplitPath(write)));
     }
 }
예제 #22
0
 static XamlSourceInfoHelper()
 {
     // Check environment variable
     const string environmentVariable = "ENABLE_XAML_DIAGNOSTICS_SOURCE_INFO";
     EnvironmentPermission environmentPermission = new EnvironmentPermission(EnvironmentPermissionAccess.Read, environmentVariable);
     environmentPermission.Assert();
     try
     {
         InitializeEnableXamlSourceInfo(Environment.GetEnvironmentVariable(environmentVariable));
     }
     finally
     {
         EnvironmentPermission.RevertAssert();
     }
 }
        private EnvironmentPermission Cast(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }

            EnvironmentPermission ep = (target as EnvironmentPermission);

            if (ep == null)
            {
                ThrowInvalidPermission(target, typeof(EnvironmentPermission));
            }

            return(ep);
        }
예제 #24
0
 public override bool IsSubsetOf(IPermission target)
 {
     if (target == null)
     {
         return(sites == null || sites.Length == 0);
     }
     else if (!(target is SiteIdentityPermission))
     {
         throw new ArgumentException(_("Arg_PermissionMismatch"));
     }
     else
     {
         return(EnvironmentPermission.IsSubsetOf
                    (sites, ((SiteIdentityPermission)target).sites));
     }
 }
예제 #25
0
        /// <summary>Creates and returns an identical copy of the current permission.</summary>
        /// <returns>A copy of the current permission.</returns>
        public override IPermission Copy()
        {
            EnvironmentPermission environmentPermission = new EnvironmentPermission(this._state);
            string pathList = this.GetPathList(EnvironmentPermissionAccess.Read);

            if (pathList != null)
            {
                environmentPermission.SetPathList(EnvironmentPermissionAccess.Read, pathList);
            }
            pathList = this.GetPathList(EnvironmentPermissionAccess.Write);
            if (pathList != null)
            {
                environmentPermission.SetPathList(EnvironmentPermissionAccess.Write, pathList);
            }
            return(environmentPermission);
        }
        public override IPermission Copy()
        {
            EnvironmentPermission ep = new EnvironmentPermission(_state);
            string path = GetPathList(EnvironmentPermissionAccess.Read);

            if (path != null)
            {
                ep.SetPathList(EnvironmentPermissionAccess.Read, path);
            }
            path = GetPathList(EnvironmentPermissionAccess.Write);
            if (path != null)
            {
                ep.SetPathList(EnvironmentPermissionAccess.Write, path);
            }
            return(ep);
        }
예제 #27
0
        /// <summary>
        /// Try/finally is completely unnecessary. Permissions are associated with stack frames
        /// and go out of scope once stack frame returns.
        /// </summary>
        private string GetMachineNameWithoutPermissions()
        {
            EnvironmentPermission denyPermission = new EnvironmentPermission(PermissionState.None);

            PermissionSet permissions = new PermissionSet(PermissionState.None);
            permissions.AddPermission(denyPermission);
            permissions.Deny();

            try
            {
                return Environment.MachineName;
            }
            finally
            {
                CodeAccessPermission.RevertDeny();
            }
        }
예제 #28
0
 public override IPermission Intersect(IPermission target)
 {
     if (target == null)
     {
         return(target);
     }
     else if (!(target is SiteIdentityPermission))
     {
         throw new ArgumentException(_("Arg_PermissionMismatch"));
     }
     else
     {
         return(new SiteIdentityPermission
                    (EnvironmentPermission.Intersect
                        (sites, ((SiteIdentityPermission)target).sites)));
     }
 }
 public override IPermission CreatePermission()
 {
     if (base.m_unrestricted)
     {
         return new EnvironmentPermission(PermissionState.Unrestricted);
     }
     EnvironmentPermission permission = new EnvironmentPermission(PermissionState.None);
     if (this.m_read != null)
     {
         permission.SetPathList(EnvironmentPermissionAccess.Read, this.m_read);
     }
     if (this.m_write != null)
     {
         permission.SetPathList(EnvironmentPermissionAccess.Write, this.m_write);
     }
     return permission;
 }
예제 #30
0
        public override IPermission CreatePermission()
        {
            if (base.m_unrestricted)
            {
                return(new EnvironmentPermission(PermissionState.Unrestricted));
            }
            EnvironmentPermission permission = new EnvironmentPermission(PermissionState.None);

            if (this.m_read != null)
            {
                permission.SetPathList(EnvironmentPermissionAccess.Read, this.m_read);
            }
            if (this.m_write != null)
            {
                permission.SetPathList(EnvironmentPermissionAccess.Write, this.m_write);
            }
            return(permission);
        }
		// Methods
		public override IPermission CreatePermission ()
		{
#if NET_2_1
			return null;
#else
			EnvironmentPermission perm = null;
			if (this.Unrestricted)
				perm = new EnvironmentPermission (PermissionState.Unrestricted);
			else {
				perm = new EnvironmentPermission (PermissionState.None);
				if (read != null)
					perm.AddPathList (EnvironmentPermissionAccess.Read, read);
				if (write != null)
					perm.AddPathList (EnvironmentPermissionAccess.Write, write);
			}
			return perm;
#endif
		}
예제 #32
0
        internal static PermissionSet _UnsafeGetAssertPermSet() {
            // SEC_NOTE: All callers should already be guarded by EventLogPermission demand.
            PermissionSet permissionSet = new PermissionSet(PermissionState.None);

            // We need RegistryPermission 
            RegistryPermission registryPermission = new RegistryPermission(PermissionState.Unrestricted);
            permissionSet.AddPermission(registryPermission);

            // It is not enough to just assert RegistryPermission, for some regkeys
            // we need to assert EnvironmentPermission too
            EnvironmentPermission environmentPermission = new EnvironmentPermission(PermissionState.Unrestricted);
            permissionSet.AddPermission(environmentPermission);

            // For remote machine registry access UnmanagdCodePermission is required.
            SecurityPermission securityPermission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
            permissionSet.AddPermission(securityPermission);

            return permissionSet;
        }
예제 #33
0
 // Create a permission object that corresponds to this attribute.
 public override IPermission CreatePermission()
 {
     if (Unrestricted)
     {
         return(new FileIOPermission
                    (PermissionState.Unrestricted));
     }
     else
     {
         return(new FileIOPermission
                    (PermissionState.None,
                    EnvironmentPermission.SplitPath(read),
                    EnvironmentPermission.SplitPath(write),
                    EnvironmentPermission.SplitPath(append),
                    EnvironmentPermission.SplitPath(pathDiscovery),
                    FileIOPermissionAccess.NoAccess,
                    FileIOPermissionAccess.NoAccess));
     }
 }
 public override IPermission Copy()
 {
     EnvironmentPermission permission = new EnvironmentPermission(PermissionState.None);
     if (this.m_unrestricted)
     {
         permission.m_unrestricted = true;
         return permission;
     }
     permission.m_unrestricted = false;
     if (this.m_read != null)
     {
         permission.m_read = this.m_read.Copy();
     }
     if (this.m_write != null)
     {
         permission.m_write = this.m_write.Copy();
     }
     return permission;
 }
예제 #35
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            else if (!VerifyType(target))
            {
                throw new
                      ArgumentException(
                          Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)
                          );
            }
            else if (this.IsUnrestricted())
            {
                return(target.Copy());
            }

            EnvironmentPermission operand = (EnvironmentPermission)target;

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

            StringExpressionSet intersectRead  = this.m_read == null ? null : this.m_read.Intersect(operand.m_read);
            StringExpressionSet intersectWrite = this.m_write == null ? null : this.m_write.Intersect(operand.m_write);

            if ((intersectRead == null || intersectRead.IsEmpty()) &&
                (intersectWrite == null || intersectWrite.IsEmpty()))
            {
                return(null);
            }

            EnvironmentPermission intersectPermission = new EnvironmentPermission(PermissionState.None);

            intersectPermission.m_unrestricted = false;
            intersectPermission.m_read         = intersectRead;
            intersectPermission.m_write        = intersectWrite;

            return(intersectPermission);
        }
예제 #36
0
 public override IPermission CreatePermission()
 {
     if (m_unrestricted)
     {
         return(new EnvironmentPermission(PermissionState.Unrestricted));
     }
     else
     {
         EnvironmentPermission perm = new EnvironmentPermission(PermissionState.None);
         if (m_read != null)
         {
             perm.SetPathList(EnvironmentPermissionAccess.Read, m_read);
         }
         if (m_write != null)
         {
             perm.SetPathList(EnvironmentPermissionAccess.Write, m_write);
         }
         return(perm);
     }
 }
        public override IPermission Copy()
        {
            EnvironmentPermission permission = new EnvironmentPermission(PermissionState.None);

            if (this.m_unrestricted)
            {
                permission.m_unrestricted = true;
                return(permission);
            }
            permission.m_unrestricted = false;
            if (this.m_read != null)
            {
                permission.m_read = this.m_read.Copy();
            }
            if (this.m_write != null)
            {
                permission.m_write = this.m_write.Copy();
            }
            return(permission);
        }
        public void RollingFlatFileTraceListenerReplacedEnviromentVariablesWillFallBackIfNotPrivilegesToRead()
        {
            string environmentVariable = "%USERPROFILE%";
            string fileName = Path.Combine(environmentVariable, "foo.log");

            EnvironmentPermission denyPermission = new EnvironmentPermission(PermissionState.Unrestricted);
            denyPermission.Deny();

            try
            {
                RollingFlatFileTraceListener listener = new RollingFlatFileTraceListener(fileName, "header", "footer", null, 1, "", RollFileExistsBehavior.Increment, RollInterval.Day);
                listener.TraceData(new TraceEventCache(), "source", TraceEventType.Error, 1, "This is a test");
                listener.Dispose();
            }
            finally
            {
                EnvironmentPermission.RevertAll();
            }

            Assert.Fail("Permission was not denied.");
        }
예제 #39
0
 public override bool IsSubsetOf(IPermission target)
 {
     if (target == null)
     {
         return(state == PermissionState.None &&
                readList == null && writeList == null &&
                appendList == null && discoveryList == null);
     }
     else if (!(target is FileIOPermission))
     {
         throw new ArgumentException(_("Arg_PermissionMismatch"));
     }
     else if (((FileIOPermission)target).IsUnrestricted())
     {
         return(true);
     }
     else if (IsUnrestricted())
     {
         return(false);
     }
     else
     {
         return(EnvironmentPermission.IsSubsetOf
                    (readList, ((FileIOPermission)target).readList) &&
                EnvironmentPermission.IsSubsetOf
                    (writeList, ((FileIOPermission)target).writeList) &&
                EnvironmentPermission.IsSubsetOf
                    (appendList, ((FileIOPermission)target).appendList) &&
                EnvironmentPermission.IsSubsetOf
                    (discoveryList,
                    ((FileIOPermission)target).discoveryList) &&
                ((allLocalFiles &
                  ((FileIOPermission)target).allLocalFiles) ==
                 allLocalFiles) &&
                ((allFiles &
                  ((FileIOPermission)target).allFiles) ==
                 allFiles));
     }
 }
예제 #40
0
        public MainWindow()
        {
            this.MoveToOtherContextMenuHeader = "Move to Machine";

            InitializeComponent();

            var permissions = new EnvironmentPermission(EnvironmentPermissionAccess.AllAccess, "PATH");
            permissions.Demand();

            this.DataContext = this;
            uxPaths.ItemsSource = paths;

            this.AddShortcut(new KeyGesture(Key.Z, ModifierKeys.Control), Undo);
            this.AddShortcut(new KeyGesture(Key.Y, ModifierKeys.Control), Redo);
            uxPaths.AddShortcut(new KeyGesture(Key.Up, ModifierKeys.Control), MoveUp);
            uxPaths.AddShortcut(new KeyGesture(Key.Down, ModifierKeys.Control), MoveDown);
            uxPaths.AddShortcut(new KeyGesture(Key.Delete), Delete);

            GongSolutions.Wpf.DragDrop.DragDrop.SetIsDragSource(uxPaths, true);
            GongSolutions.Wpf.DragDrop.DragDrop.SetIsDropTarget(uxPaths, true);
            GongSolutions.Wpf.DragDrop.DragDrop.SetDropHandler(uxPaths, this);
        }
예제 #41
0
        public override IPermission Copy()
        {
            EnvironmentPermission copy = new EnvironmentPermission(PermissionState.None);

            if (this.m_unrestricted)
            {
                copy.m_unrestricted = true;
            }
            else
            {
                copy.m_unrestricted = false;
                if (this.m_read != null)
                {
                    copy.m_read = this.m_read.Copy();
                }
                if (this.m_write != null)
                {
                    copy.m_write = this.m_write.Copy();
                }
            }
            return(copy);
        }
예제 #42
0
 public void AddPathList(FileIOPermissionAccess access, String[] pathList)
 {
     if (pathList == null)
     {
         throw new ArgumentNullException("pathList");
     }
     if ((access & ~(FileIOPermissionAccess.AllAccess)) != 0)
     {
         throw new ArgumentException(_("Arg_FileIOAccess"));
     }
     foreach (String s in pathList)
     {
         if (s == null)
         {
             throw new ArgumentNullException("pathList element");
         }
     }
     if ((access & FileIOPermissionAccess.Read) != 0)
     {
         readList = EnvironmentPermission.Union
                        (readList, pathList, true);
     }
     if ((access & FileIOPermissionAccess.Write) != 0)
     {
         writeList = EnvironmentPermission.Union
                         (writeList, pathList, true);
     }
     if ((access & FileIOPermissionAccess.Append) != 0)
     {
         appendList = EnvironmentPermission.Union
                          (appendList, pathList, true);
     }
     if ((access & FileIOPermissionAccess.PathDiscovery) != 0)
     {
         discoveryList = EnvironmentPermission.Union
                             (discoveryList, pathList, true);
     }
 }
예제 #43
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public override IPermission Union(IPermission other)
        {
            if (other == null)
            {
                return(this.Copy());
            }
            else if (!VerifyType(other))
            {
                throw new
                      ArgumentException(
                          Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)
                          );
            }

            EnvironmentPermission operand = (EnvironmentPermission)other;

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

            StringExpressionSet unionRead  = this.m_read == null ? operand.m_read : this.m_read.Union(operand.m_read);
            StringExpressionSet unionWrite = this.m_write == null ? operand.m_write : this.m_write.Union(operand.m_write);

            if ((unionRead == null || unionRead.IsEmpty()) &&
                (unionWrite == null || unionWrite.IsEmpty()))
            {
                return(null);
            }

            EnvironmentPermission unionPermission = new EnvironmentPermission(PermissionState.None);

            unionPermission.m_unrestricted = false;
            unionPermission.m_read         = unionRead;
            unionPermission.m_write        = unionWrite;

            return(unionPermission);
        }
예제 #44
0
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            if (!base.VerifyType(target))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[]
                {
                    base.GetType().FullName
                }));
            }
            if (this.IsUnrestricted())
            {
                return(target.Copy());
            }
            EnvironmentPermission environmentPermission = (EnvironmentPermission)target;

            if (environmentPermission.IsUnrestricted())
            {
                return(this.Copy());
            }
            StringExpressionSet stringExpressionSet  = (this.m_read == null) ? null : this.m_read.Intersect(environmentPermission.m_read);
            StringExpressionSet stringExpressionSet2 = (this.m_write == null) ? null : this.m_write.Intersect(environmentPermission.m_write);

            if ((stringExpressionSet == null || stringExpressionSet.IsEmpty()) && (stringExpressionSet2 == null || stringExpressionSet2.IsEmpty()))
            {
                return(null);
            }
            return(new EnvironmentPermission(PermissionState.None)
            {
                m_unrestricted = false,
                m_read = stringExpressionSet,
                m_write = stringExpressionSet2
            });
        }
        public override bool IsSubsetOf(IPermission target)
        {
            EnvironmentPermission ep = Cast(target);

            if (ep == null)
            {
                return(false);
            }

            if (IsUnrestricted())
            {
                return(ep.IsUnrestricted());
            }
            else if (ep.IsUnrestricted())
            {
                return(true);
            }

            foreach (string s in readList)
            {
                if (!ep.readList.Contains(s))
                {
                    return(false);
                }
            }

            foreach (string s in writeList)
            {
                if (!ep.writeList.Contains(s))
                {
                    return(false);
                }
            }

            return(true);
        }
        public static void TestAssertAndDeny()
        {
            EnvironmentPermission envPermission = new EnvironmentPermission(
               EnvironmentPermissionAccess.Read,
               "COMPUTERNAME;USERNAME;USERDOMAIN");
             envPermission.Assert();
             try
             {
            SomeSecuredMethods.MethodProtectedByDemand();
            Console.WriteLine(
               "Caller's Deny has no effect on Demand " +
               "with the asserted permission.");

            SomeSecuredMethods.MethodProtectedByLinkDemand();
            Console.WriteLine(
               "Caller's Deny has no effect on LinkDemand " +
               "with the asserted permission.");
             }
             catch (SecurityException e)
             {
            Console.WriteLine(
               "Caller's Deny protected the library.{0}", e);
             }
        }
		public void IsSubsetOfBadPermission () 
		{
			EnvironmentPermission ep1 = new EnvironmentPermission (EnvironmentPermissionAccess.Read, envVariables);
			FileDialogPermission fdp2 = new FileDialogPermission (PermissionState.Unrestricted);
			Assert ("IsSubsetOf(FileDialogPermission)", ep1.IsSubsetOf (fdp2));
		}
예제 #48
0
     public override IPermission Copy()
     {
         EnvironmentPermission copy = new EnvironmentPermission(PermissionState.None);
         if (this.m_unrestricted)
         {
             copy.m_unrestricted = true;
         }
         else
         {
             copy.m_unrestricted = false;
             if (this.m_read != null)
             {
                 copy.m_read = this.m_read.Copy();
             }
             if (this.m_write != null)
             {
                 copy.m_write = this.m_write.Copy();
             }
 
         }
         return copy;   
     }
예제 #49
0
		public override IPermission Copy ()
		{
			EnvironmentPermission ep = new EnvironmentPermission (_state);
			string path = GetPathList (EnvironmentPermissionAccess.Read);
			if (path != null)
				ep.SetPathList (EnvironmentPermissionAccess.Read, path);
			path = GetPathList (EnvironmentPermissionAccess.Write);
			if (path != null)
				ep.SetPathList (EnvironmentPermissionAccess.Write, path);
			return ep;
		}
예제 #50
0
		public override IPermission Intersect (IPermission target)
		{
			EnvironmentPermission ep = Cast (target);
			if (ep == null)
				return null;

			if (IsUnrestricted ())
				return ep.Copy ();
			if (ep.IsUnrestricted ())
				return Copy ();

			int n = 0;
			EnvironmentPermission result = new EnvironmentPermission (PermissionState.None);
			string readTarget = ep.GetPathList (EnvironmentPermissionAccess.Read);
			if (readTarget != null) {
				string[] targets = readTarget.Split (';');
				foreach (string t in targets) {
					if (readList.Contains (t)) {
						result.AddPathList (EnvironmentPermissionAccess.Read, t);
						n++;
					}
				}
			}

			string writeTarget = ep.GetPathList (EnvironmentPermissionAccess.Write);
			if (writeTarget != null) {
				string[] targets = writeTarget.Split (';');
				foreach (string t in targets) {
					if (writeList.Contains (t)) {
						result.AddPathList (EnvironmentPermissionAccess.Write, t);
						n++;
					}
				}
			}
			return ((n > 0) ? result : null);
		}
		public void IsSubsetOfBadPermission () 
		{
			PrincipalPermission p1 = new PrincipalPermission ("user", null);
			EnvironmentPermission ep2 = new EnvironmentPermission (PermissionState.Unrestricted);
			Assert ("IsSubsetOf(EnvironmentPermission)", p1.IsSubsetOf (ep2));
		}
예제 #52
0
 public override IPermission CreatePermission()
 {
     if (m_unrestricted)
     {
         return new EnvironmentPermission(PermissionState.Unrestricted);
     }
     else
     {
         EnvironmentPermission perm = new EnvironmentPermission(PermissionState.None);
         if (m_read != null)
             perm.SetPathList( EnvironmentPermissionAccess.Read, m_read );
         if (m_write != null)
             perm.SetPathList( EnvironmentPermissionAccess.Write, m_write );
         return perm;
     }
 }
		public void IntersectWithBadPermission () 
		{
			PrincipalPermission p1 = new PrincipalPermission ("user", null);
			EnvironmentPermission ep2 = new EnvironmentPermission (PermissionState.Unrestricted);
			PrincipalPermission p3 = (PrincipalPermission) p1.Intersect (ep2);
		}
		public void NullPathList () 
		{
			EnvironmentPermission ep = new EnvironmentPermission (EnvironmentPermissionAccess.AllAccess, null);
		}
예제 #55
0
파일: ListView.cs 프로젝트: JianwenSun/cc
        private void SetBackgroundImage() {
            // needed for OleInitialize
            Application.OleRequired();

            NativeMethods.LVBKIMAGE lvbkImage = new NativeMethods.LVBKIMAGE();
            lvbkImage.xOffset = 0;
            lvbkImage.yOffset = 0;

            // first, is there an existing temporary file to delete, remember its name
            // so that we can delete it if the list control doesn't...
            string fileNameToDelete = this.backgroundImageFileName;

            if (this.BackgroundImage != null) {

                // the list view needs these permissions when the app runs on an UNC share
                // and the list view creates / destroys temporary files for its background image

                // SECREVIEW : Safe to assert FileIO & Environment permissions here, just creating/deleting temp files.
                //
                EnvironmentPermission envPermission = new EnvironmentPermission(EnvironmentPermissionAccess.Read, "TEMP");
                FileIOPermission fiop = new FileIOPermission(PermissionState.Unrestricted);
                System.Security.PermissionSet permSet = new System.Security.PermissionSet(PermissionState.Unrestricted);
                permSet.AddPermission(envPermission);
                permSet.AddPermission(fiop);
                permSet.Assert();

                // save the image to a temporary file name
                try {
                    string tempDirName = System.IO.Path.GetTempPath();
                    System.Text.StringBuilder sb = new System.Text.StringBuilder(1024);
                    UnsafeNativeMethods.GetTempFileName(tempDirName, this.GenerateRandomName(), 0, sb);

                    this.backgroundImageFileName = sb.ToString();

                    this.BackgroundImage.Save(this.backgroundImageFileName, System.Drawing.Imaging.ImageFormat.Bmp);
                } finally {
                    System.Security.PermissionSet.RevertAssert();
                }

                lvbkImage.pszImage = this.backgroundImageFileName;
                lvbkImage.cchImageMax = this.backgroundImageFileName.Length + 1;
                lvbkImage.ulFlags = NativeMethods.LVBKIF_SOURCE_URL;
                if (BackgroundImageTiled)
                    lvbkImage.ulFlags |= NativeMethods.LVBKIF_STYLE_TILE;
                else
                    lvbkImage.ulFlags |= NativeMethods.LVBKIF_STYLE_NORMAL;

            } else {
                lvbkImage.ulFlags = NativeMethods.LVBKIF_SOURCE_NONE;
                this.backgroundImageFileName = String.Empty;
            }

            UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), NativeMethods.LVM_SETBKIMAGE, 0, lvbkImage);

            if (String.IsNullOrEmpty(fileNameToDelete)) {
                return;
            }

            // we need to cause a paint message on the win32 list view. This way the win 32 list view gives up
            // its reference to the previous image file it was hanging on to.
            // vsWhidbey 243708

            // 8 strings should be good enough for us
            if (this.bkImgFileNames == null) {
                this.bkImgFileNames = new string[BKIMGARRAYSIZE];
                this.bkImgFileNamesCount = -1;
            }

            if (this.bkImgFileNamesCount == BKIMGARRAYSIZE - 1) {
                // it should be fine to delete the file name that was added first.
                // if it's not fine, then increase BKIMGARRAYSIZE
                this.DeleteFileName(this.bkImgFileNames[0]);
                this.bkImgFileNames[0] = this.bkImgFileNames[1];
                this.bkImgFileNames[1] = this.bkImgFileNames[2];
                this.bkImgFileNames[2] = this.bkImgFileNames[3];
                this.bkImgFileNames[3] = this.bkImgFileNames[4];
                this.bkImgFileNames[4] = this.bkImgFileNames[5];
                this.bkImgFileNames[5] = this.bkImgFileNames[6];
                this.bkImgFileNames[6] = this.bkImgFileNames[7];
                this.bkImgFileNames[7] = null;

                this.bkImgFileNamesCount --;
            }

            this.bkImgFileNamesCount ++;
            this.bkImgFileNames[this.bkImgFileNamesCount] = fileNameToDelete;

            // now force the paint
            this.Refresh();
        }
예제 #56
0
     [System.Security.SecuritySafeCritical]  // auto-generated
     public override IPermission Union(IPermission other)
     {
         if (other == null)
         {
             return this.Copy();
         }
         else if (!VerifyType(other))
         {
             throw new 
                 ArgumentException(
                                 Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)
                                  );
         }
 
         EnvironmentPermission operand = (EnvironmentPermission)other;
        
         if (this.IsUnrestricted() || operand.IsUnrestricted())
         {
             return new EnvironmentPermission( PermissionState.Unrestricted );
         }
 
         StringExpressionSet unionRead = this.m_read == null ? operand.m_read : this.m_read.Union( operand.m_read );
         StringExpressionSet unionWrite = this.m_write == null ? operand.m_write : this.m_write.Union( operand.m_write );
         
         if ((unionRead == null || unionRead.IsEmpty()) &&
             (unionWrite == null || unionWrite.IsEmpty()))
         {
             return null;
         }
         
         EnvironmentPermission unionPermission = new EnvironmentPermission(PermissionState.None);
         unionPermission.m_unrestricted = false;
         unionPermission.m_read = unionRead;
         unionPermission.m_write = unionWrite;
         
         return unionPermission;
     }    
예제 #57
0
     [System.Security.SecuritySafeCritical]  // auto-generated
     public override IPermission Intersect(IPermission target)
     {
         if (target == null)
         {
             return null;
         }
         else if (!VerifyType(target))
         {
             throw new 
                 ArgumentException(
                                 Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)
                                  );
         }
         else if (this.IsUnrestricted())
         {
             return target.Copy();
         }
 
         EnvironmentPermission operand = (EnvironmentPermission)target;
 
         if (operand.IsUnrestricted())
         {
             return this.Copy();
         }
         
         StringExpressionSet intersectRead = this.m_read == null ? null : this.m_read.Intersect( operand.m_read );
         StringExpressionSet intersectWrite = this.m_write == null ? null : this.m_write.Intersect( operand.m_write );
         
         if ((intersectRead == null || intersectRead.IsEmpty()) &&
             (intersectWrite == null || intersectWrite.IsEmpty()))
         {
             return null;
         }
         
         EnvironmentPermission intersectPermission = new EnvironmentPermission(PermissionState.None);
         intersectPermission.m_unrestricted = false;
         intersectPermission.m_read = intersectRead;
         intersectPermission.m_write = intersectWrite;
         
         return intersectPermission;
     }
예제 #58
0
 /// <internalonly/>
 int IBuiltInPermission.GetTokenIndex()
 {
     return(EnvironmentPermission.GetTokenIndex());
 }
		public void WriteAccess () 
		{
			EnvironmentPermission ep = new EnvironmentPermission (EnvironmentPermissionAccess.Write, envVariables);
			Assert ("IsUnrestricted", !ep.IsUnrestricted ());
		}