Example #1
0
		// internal stuff
		internal bool Equals (CompressedStack cs)
		{
			if (IsEmpty ())
				return cs.IsEmpty ();
			if (cs.IsEmpty ())
				return false;
			if (_list.Count != cs._list.Count)
				return false;

			for (int i=0; i < _list.Count; i++) {
				SecurityFrame sf1 = (SecurityFrame) _list [i];
				SecurityFrame sf2 = (SecurityFrame) cs._list [i];
				if (!sf1.Equals (sf2))
					return false;
			}
			return true;
		}
Example #2
0
        static CompressedStack Capture()
        {
            CompressedStack cs = new CompressedStack(0);

            cs._list = SecurityFrame.GetStack(1);

            // include any current CompressedStack inside the new Capture
            CompressedStack currentCs = Thread.CurrentThread.GetCompressedStack();

            if (currentCs != null)
            {
                for (int i = 0; i < currentCs._list.Count; i++)
                {
                    cs._list.Add(currentCs._list [i]);
                }
            }
            return(cs);
        }
        public static void RevertPermitOnly()
        {
            if (!SecurityManager.SecurityEnabled)
            {
                return;
            }

            SecurityFrame sf = new SecurityFrame(1);

            if ((sf.PermitOnly != null) && sf.PermitOnly.DeclarativeSecurity)
            {
                throw new NotSupportedException("Currently only declarative PermitOnly are supported.");
            }
            else
            {
                // we can't revert declarative security (or an empty frame) imperatively
                ThrowExecutionEngineException(SecurityAction.PermitOnly);
            }
        }
        internal bool ProcessFrame(SecurityFrame frame)
        {
            // 1. CheckPermitOnly
            if (frame.PermitOnly != null)
            {
                // the demanded permission must be in one of the permitted...
                bool permit = frame.PermitOnly.IsUnrestricted();
                if (!permit)
                {
                    // check individual permissions
                    foreach (IPermission p in frame.PermitOnly)
                    {
                        if (CheckPermitOnly(p as CodeAccessPermission))
                        {
                            permit = true;
                            break;
                        }
                    }
                }
                if (!permit)
                {
                    // ...or else we throw
                    ThrowSecurityException(this, "PermitOnly", frame, SecurityAction.Demand, null);
                }
            }

            // 2. CheckDeny
            if (frame.Deny != null)
            {
                // special case where everything is denied (i.e. no child to be processed)
                if (frame.Deny.IsUnrestricted())
                {
                    ThrowSecurityException(this, "Deny", frame, SecurityAction.Demand, null);
                }
                foreach (IPermission p in frame.Deny)
                {
                    if (!CheckDeny(p as CodeAccessPermission))
                    {
                        ThrowSecurityException(this, "Deny", frame, SecurityAction.Demand, p);
                    }
                }
            }

            // 3. CheckAssert
            if (frame.Assert != null)
            {
                if (frame.Assert.IsUnrestricted())
                {
                    return(true);                    // remove permission and continue stack walk
                }
                foreach (IPermission p in frame.Assert)
                {
                    if (CheckAssert(p as CodeAccessPermission))
                    {
                        return(true);                        // remove permission and continue stack walk
                    }
                }
            }

            // continue the stack walk
            return(false);
        }