Inheritance: CodeGroup, IUnionSemanticCodeGroup
Example #1
0
        /// <summary>Determines whether the specified code group is equivalent to the current code group.</summary>
        /// <returns>true if the specified code group is equivalent to the current code group; otherwise, false.</returns>
        /// <param name="o">The <see cref="T:System.Security.Policy.NetCodeGroup" /> object to compare with the current code group.</param>
        public override bool Equals(object o)
        {
            if (!base.Equals(o))
            {
                return(false);
            }
            NetCodeGroup netCodeGroup = o as NetCodeGroup;

            if (netCodeGroup == null)
            {
                return(false);
            }
            foreach (object obj in this._rules)
            {
                DictionaryEntry     dictionaryEntry = (DictionaryEntry)obj;
                CodeConnectAccess[] array           = (CodeConnectAccess[])netCodeGroup._rules[dictionaryEntry.Key];
                bool flag;
                if (array != null)
                {
                    flag = this.Equals((CodeConnectAccess[])dictionaryEntry.Value, array);
                }
                else
                {
                    flag = (dictionaryEntry.Value == null);
                }
                if (!flag)
                {
                    return(false);
                }
            }
            return(true);
        }
Example #2
0
        public override CodeGroup Copy()
        {
            NetCodeGroup group = new NetCodeGroup(this.MembershipCondition);

            group.Name        = this.Name;
            group.Description = this.Description;
            if (m_schemesList != null)
            {
                group.m_schemesList = (ArrayList)this.m_schemesList.Clone();
                group.m_accessList  = new ArrayList(this.m_accessList.Count);
                for (int i = 0; i < this.m_accessList.Count; ++i)
                {
                    group.m_accessList.Add(((ArrayList)this.m_accessList[i]).Clone());
                }
            }

            IEnumerator enumerator = this.Children.GetEnumerator();

            while (enumerator.MoveNext())
            {
                group.AddChild((CodeGroup)enumerator.Current);
            }


            return(group);
        }
Example #3
0
        // Resolve code groups that match specific evidence.
        public override CodeGroup ResolveMatchingCodeGroups(Evidence evidence)
        {
            NetCodeGroup newGroup;
            CodeGroup    child;

            // Validate the parameter.
            if (evidence == null)
            {
                throw new ArgumentNullException("evidence");
            }

            // Check the membership condition.
            if (!MembershipCondition.Check(evidence))
            {
                return(null);
            }

            // Clone this group, except for the children.
            newGroup             = new NetCodeGroup(MembershipCondition);
            newGroup.Name        = Name;
            newGroup.Description = Description;

            // Resolve and add the children.
            foreach (CodeGroup group in Children)
            {
                child = group.ResolveMatchingCodeGroups(evidence);
                if (child != null)
                {
                    newGroup.AddChild(child);
                }
            }

            // Return the result.
            return(newGroup);
        }
Example #4
0
        public override bool Equals(object o)
        {
            if (!base.Equals(o))
            {
                return(false);
            }
            NetCodeGroup ncg = (o as NetCodeGroup);

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

            // check rules
            foreach (DictionaryEntry de in _rules)
            {
                bool found = false;
                CodeConnectAccess[] ccas = (CodeConnectAccess[])ncg._rules [de.Key];
                if (ccas != null)
                {
                    found = Equals((CodeConnectAccess[])de.Value, ccas);
                }
                else
                {
                    found = (de.Value == null);
                }

                if (!found)
                {
                    return(false);
                }
            }
            return(true);
        }
Example #5
0
		public void CopyWithChildren () 
		{
			NetCodeGroup cgChild = new NetCodeGroup (new AllMembershipCondition ());
			NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
			cg.AddChild (cgChild);
			NetCodeGroup cg2 = (NetCodeGroup) cg.Copy ();
			Assert.AreEqual (cg.Children.Count, cg2.Children.Count, "Children");
			Assert.AreEqual (cg.ToXml ().ToString (), cg2.ToXml ().ToString (), "ToXml");
		}
Example #6
0
        //
        public override bool Equals(Object o)
        {
            if ((object)this == (object)o)
            {
                return(true);
            }

            NetCodeGroup that = (o as NetCodeGroup);

            if (that == null || !base.Equals(that))
            {
                return(false);
            }

            if ((this.m_schemesList == null) != (that.m_schemesList == null))
            {
                return(false);
            }

            if (this.m_schemesList == null)
            {
                return(true);
            }

            if (this.m_schemesList.Count != that.m_schemesList.Count)
            {
                return(false);
            }


            for (int i = 0; i < this.m_schemesList.Count; ++i)
            {
                int idx = that.m_schemesList.IndexOf(this.m_schemesList[i]);
                if (idx == -1)
                {
                    return(false);
                }

                ArrayList thisList = (ArrayList)this.m_accessList[i];
                ArrayList thatList = (ArrayList)that.m_accessList[idx];
                if (thisList.Count != thatList.Count)
                {
                    return(false);
                }

                for (int k = 0; k < thisList.Count; ++k)
                {
                    if (!thatList.Contains(thisList[k]))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Example #7
0
		public void Constructor () 
		{
			NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
			Assert.IsNotNull (cg.MembershipCondition, "MembershipCondition");
			Assert.IsNull (cg.PolicyStatement, "PolicyStatement");
			// documented as always null
			Assert.IsNull (cg.AttributeString, "AttributeString");
			// seems it's easier to change code than to change code ;)
			Assert.AreEqual ("Same site Web", cg.PermissionSetName, "PermissionSetName");
		}
		public void Copy () 
		{
			NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
			NetCodeGroup cg2 = (NetCodeGroup) cg.Copy ();
			AssertEquals ("AttributeString", cg.AttributeString, cg2.AttributeString);
			AssertEquals ("Children", cg.Children.Count, cg2.Children.Count);
			AssertEquals ("Description", cg.Description, cg2.Description);
			AssertEquals ("MergeLogic", cg.MergeLogic, cg2.MergeLogic);
			AssertEquals ("Name", cg.Name, cg2.Name);
			AssertEquals ("PermissionSetName", cg.PermissionSetName, cg2.PermissionSetName);
			AssertEquals ("ToXml", cg.ToXml ().ToString (), cg2.ToXml ().ToString ());
		}
Example #9
0
		public void Copy () 
		{
			NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
			NetCodeGroup cg2 = (NetCodeGroup) cg.Copy ();
			Assert.AreEqual (cg.AttributeString, cg2.AttributeString, "AttributeString");
			Assert.AreEqual (cg.Children.Count, cg2.Children.Count, "Children");
			Assert.AreEqual (cg.Description, cg2.Description, "Description");
			Assert.AreEqual (cg.MergeLogic, cg2.MergeLogic, "MergeLogic");
			Assert.AreEqual (cg.Name, cg2.Name, "Name");
			Assert.AreEqual (cg.PermissionSetName, cg2.PermissionSetName, "PermissionSetName");
			Assert.AreEqual (cg.ToXml ().ToString (), cg2.ToXml ().ToString (), "ToXml");
		}
Example #10
0
 public static void NetCodeGroupCallMethods()
 {
     NetCodeGroup ncg = new NetCodeGroup(new GacMembershipCondition());
     string teststring = NetCodeGroup.AbsentOriginScheme;
     teststring = NetCodeGroup.AnyOtherOriginScheme;
     ncg.AddConnectAccess("test", new CodeConnectAccess("test", 0));
     CodeGroup cg = ncg.Copy();
     bool equals = ncg.Equals(new object());
     System.Collections.DictionaryEntry[] de = ncg.GetConnectAccessRules();
     int hash = ncg.GetHashCode();
     ncg.ResetConnectAccess();
     PolicyStatement ps = ncg.Resolve(new Evidence());
     cg = ncg.ResolveMatchingCodeGroups(new Evidence());
 }
Example #11
0
        /// <summary>Makes a deep copy of the current code group.</summary>
        /// <returns>An equivalent copy of the current code group, including its membership conditions and child code groups.</returns>
        public override CodeGroup Copy()
        {
            NetCodeGroup netCodeGroup = new NetCodeGroup(base.MembershipCondition);

            netCodeGroup.Name            = base.Name;
            netCodeGroup.Description     = base.Description;
            netCodeGroup.PolicyStatement = base.PolicyStatement;
            foreach (object obj in base.Children)
            {
                CodeGroup codeGroup = (CodeGroup)obj;
                netCodeGroup.AddChild(codeGroup.Copy());
            }
            return(netCodeGroup);
        }
Example #12
0
        public override CodeGroup Copy()
        {
            NetCodeGroup copy = new NetCodeGroup(MembershipCondition);

            copy.Name            = Name;
            copy.Description     = Description;
            copy.PolicyStatement = PolicyStatement;

            foreach (CodeGroup child in Children)
            {
                copy.AddChild(child.Copy());    // deep copy
            }
            return(copy);
        }
		public void Constructor () 
		{
			NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
			AssertNotNull ("MembershipCondition", cg.MembershipCondition);
			AssertNull ("PolicyStatement", cg.PolicyStatement);
			// documented as always null
			AssertNull ("AttributeString", cg.AttributeString);
#if NET_2_0
			// seems it's easier to change code than to change code ;)
			AssertEquals ("PermissionSetName", "Same site Web", cg.PermissionSetName);
#else
			// documented as always "Same site Web" but it's "Same site Web." (missing .)
			AssertEquals ("PermissionSetName", "Same site Web.", cg.PermissionSetName);
#endif
		}
	// Make a copy of this code group.
	public override CodeGroup Copy()
			{
				NetCodeGroup group;
				group = new NetCodeGroup(MembershipCondition);
				group.Name = Name;
				group.Description = Description;
				IList children = Children;
				if(children != null)
				{
					foreach(CodeGroup child in children)
					{
						group.AddChild(child);
					}
				}
				return group;
			}
        /// <summary>Determines whether the specified code group is equivalent to the current code group.</summary>
        /// <param name="o">The <see cref="T:System.Security.Policy.NetCodeGroup" /> object to compare with the current code group.</param>
        /// <returns>
        ///     <see langword="true" /> if the specified code group is equivalent to the current code group; otherwise, <see langword="false" />.</returns>
        // Token: 0x06002990 RID: 10640 RVA: 0x00099560 File Offset: 0x00097760
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            NetCodeGroup netCodeGroup = o as NetCodeGroup;

            if (netCodeGroup == null || !base.Equals(netCodeGroup))
            {
                return(false);
            }
            if (this.m_schemesList == null != (netCodeGroup.m_schemesList == null))
            {
                return(false);
            }
            if (this.m_schemesList == null)
            {
                return(true);
            }
            if (this.m_schemesList.Count != netCodeGroup.m_schemesList.Count)
            {
                return(false);
            }
            for (int i = 0; i < this.m_schemesList.Count; i++)
            {
                int num = netCodeGroup.m_schemesList.IndexOf(this.m_schemesList[i]);
                if (num == -1)
                {
                    return(false);
                }
                ArrayList arrayList  = (ArrayList)this.m_accessList[i];
                ArrayList arrayList2 = (ArrayList)netCodeGroup.m_accessList[num];
                if (arrayList.Count != arrayList2.Count)
                {
                    return(false);
                }
                for (int j = 0; j < arrayList.Count; j++)
                {
                    if (!arrayList2.Contains(arrayList[j]))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #16
0
        /// <include file='doc\NetCodeGroup.uex' path='docs/doc[@for="NetCodeGroup.Copy"]/*' />
        public override CodeGroup Copy()
        {
            NetCodeGroup group = new NetCodeGroup(this.MembershipCondition);

            group.Name        = this.Name;
            group.Description = this.Description;

            IEnumerator enumerator = this.Children.GetEnumerator();

            while (enumerator.MoveNext())
            {
                group.AddChild((CodeGroup)enumerator.Current);
            }


            return(group);
        }
Example #17
0
        // Make a copy of this code group.
        public override CodeGroup Copy()
        {
            NetCodeGroup group;

            group             = new NetCodeGroup(MembershipCondition);
            group.Name        = Name;
            group.Description = Description;
            IList children = Children;

            if (children != null)
            {
                foreach (CodeGroup child in children)
                {
                    group.AddChild(child);
                }
            }
            return(group);
        }
Example #18
0
 public override bool Equals(object o)
 {
     if (this != o)
     {
         NetCodeGroup group = o as NetCodeGroup;
         if ((group == null) || !base.Equals(group))
         {
             return(false);
         }
         if ((this.m_schemesList == null) != (group.m_schemesList == null))
         {
             return(false);
         }
         if (this.m_schemesList != null)
         {
             if (this.m_schemesList.Count != group.m_schemesList.Count)
             {
                 return(false);
             }
             for (int i = 0; i < this.m_schemesList.Count; i++)
             {
                 int index = group.m_schemesList.IndexOf(this.m_schemesList[i]);
                 if (index == -1)
                 {
                     return(false);
                 }
                 ArrayList list  = (ArrayList)this.m_accessList[i];
                 ArrayList list2 = (ArrayList)group.m_accessList[index];
                 if (list.Count != list2.Count)
                 {
                     return(false);
                 }
                 for (int j = 0; j < list.Count; j++)
                 {
                     if (!list2.Contains(list[j]))
                     {
                         return(false);
                     }
                 }
             }
         }
     }
     return(true);
 }
Example #19
0
        /// <summary>确定指定的代码组是否等效于当前代码组。</summary>
        /// <returns>如果指定的代码组等效于当前代码组,则为 true;否则为 false。</returns>
        /// <param name="o">要与当前代码组进行比较的 <see cref="T:System.Security.Policy.NetCodeGroup" /> 对象。</param>
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            NetCodeGroup netCodeGroup = o as NetCodeGroup;

            if (netCodeGroup == null || !base.Equals((object)netCodeGroup) || this.m_schemesList == null != (netCodeGroup.m_schemesList == null))
            {
                return(false);
            }
            if (this.m_schemesList == null)
            {
                return(true);
            }
            if (this.m_schemesList.Count != netCodeGroup.m_schemesList.Count)
            {
                return(false);
            }
            for (int index1 = 0; index1 < this.m_schemesList.Count; ++index1)
            {
                int index2 = netCodeGroup.m_schemesList.IndexOf(this.m_schemesList[index1]);
                if (index2 == -1)
                {
                    return(false);
                }
                ArrayList arrayList1 = (ArrayList)this.m_accessList[index1];
                ArrayList arrayList2 = (ArrayList)netCodeGroup.m_accessList[index2];
                if (arrayList1.Count != arrayList2.Count)
                {
                    return(false);
                }
                for (int index3 = 0; index3 < arrayList1.Count; ++index3)
                {
                    if (!arrayList2.Contains(arrayList1[index3]))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #20
0
        /// <summary>生成当前代码组的深层副本。</summary>
        /// <returns>当前代码组(包括其成员条件和子代码组)的等效副本。</returns>
        public override CodeGroup Copy()
        {
            NetCodeGroup netCodeGroup = new NetCodeGroup(this.MembershipCondition);

            netCodeGroup.Name        = this.Name;
            netCodeGroup.Description = this.Description;
            if (this.m_schemesList != null)
            {
                netCodeGroup.m_schemesList = (ArrayList)this.m_schemesList.Clone();
                netCodeGroup.m_accessList  = new ArrayList(this.m_accessList.Count);
                for (int index = 0; index < this.m_accessList.Count; ++index)
                {
                    netCodeGroup.m_accessList.Add(((ArrayList)this.m_accessList[index]).Clone());
                }
            }
            foreach (CodeGroup child in (IEnumerable)this.Children)
            {
                netCodeGroup.AddChild(child);
            }
            return((CodeGroup)netCodeGroup);
        }
        /// <summary>Makes a deep copy of the current code group.</summary>
        /// <returns>An equivalent copy of the current code group, including its membership conditions and child code groups.</returns>
        // Token: 0x0600298C RID: 10636 RVA: 0x00099480 File Offset: 0x00097680
        public override CodeGroup Copy()
        {
            NetCodeGroup netCodeGroup = new NetCodeGroup(base.MembershipCondition);

            netCodeGroup.Name        = base.Name;
            netCodeGroup.Description = base.Description;
            if (this.m_schemesList != null)
            {
                netCodeGroup.m_schemesList = (ArrayList)this.m_schemesList.Clone();
                netCodeGroup.m_accessList  = new ArrayList(this.m_accessList.Count);
                for (int i = 0; i < this.m_accessList.Count; i++)
                {
                    netCodeGroup.m_accessList.Add(((ArrayList)this.m_accessList[i]).Clone());
                }
            }
            foreach (object obj in base.Children)
            {
                netCodeGroup.AddChild((CodeGroup)obj);
            }
            return(netCodeGroup);
        }
        // Get a sandbox permission set that the CLR considers safe to grant an application with the given
        // evidence.  Note that this API is not a policy API, but rather a host helper API so that a host can
        // determine if an application's requested permission set is reasonable.  This is esentially just a
        // hard coded mapping of Zone -> Sandbox and is not configurable in any way.
        public static PermissionSet GetStandardSandbox(Evidence evidence)
        {
            if (evidence == null)
                throw new ArgumentNullException("evidence");
            Contract.EndContractBlock();

            //
            // The top-level switch for grant set is based upon Zone
            //   MyComputer -> FullTrust
            //   Intranet   -> LocalIntranet
            //   Trusted    -> Internet
            //   Internet   -> Internet
            //   All else   -> Nothing
            //   
            //   Both the Internet and LocalIntranet zones can have permission set extensions applied to them
            //   if there is Activation.
            //   

            Zone zone = evidence.GetHostEvidence<Zone>();
            if (zone == null)
            {
                return new PermissionSet(PermissionState.None);
            }
#if FEATURE_CAS_POLICY
            else if (zone.SecurityZone == SecurityZone.MyComputer)
            {
                return new PermissionSet(PermissionState.Unrestricted);
            }
            else if (zone.SecurityZone == SecurityZone.Intranet)
            {
                PermissionSet intranetGrantSet = BuiltInPermissionSets.LocalIntranet;

                // We also need to add in same site web and file IO permission
                PolicyStatement webPolicy =
                    new NetCodeGroup(new AllMembershipCondition()).Resolve(evidence);
                PolicyStatement filePolicy =
                    new FileCodeGroup(new AllMembershipCondition(), FileIOPermissionAccess.Read | FileIOPermissionAccess.PathDiscovery).Resolve(evidence);

                if (webPolicy != null)
                {
                    intranetGrantSet.InplaceUnion(webPolicy.PermissionSet);
                }
                if (filePolicy != null)
                {
                    intranetGrantSet.InplaceUnion(filePolicy.PermissionSet);
                }

                return intranetGrantSet;
            }
            else if (zone.SecurityZone == SecurityZone.Internet ||
                     zone.SecurityZone == SecurityZone.Trusted)
            {
                PermissionSet internetGrantSet = BuiltInPermissionSets.Internet;

                // We also need to add in same site web permission
                PolicyStatement webPolicy =
                    new NetCodeGroup(new AllMembershipCondition()).Resolve(evidence);

                if (webPolicy != null)
                {
                    internetGrantSet.InplaceUnion(webPolicy.PermissionSet);
                }

                return internetGrantSet;
            }
#endif // FEATURE_CAS_POLICY
            else
            {
                return new PermissionSet(PermissionState.None);
            }
        }
        [System.Security.SecurityCritical]  // auto-generated
        private CodeGroup CreateDefaultMachinePolicy() {
            UnionCodeGroup root = new UnionCodeGroup();
            root.FromXml(CreateCodeGroupElement("UnionCodeGroup", "Nothing", new AllMembershipCondition().ToXml()), this);
            root.Name = Environment.GetResourceString("Policy_AllCode_Name");
            root.Description = Environment.GetResourceString("Policy_AllCode_DescriptionNothing");

            UnionCodeGroup myComputerCodeGroup = new UnionCodeGroup();
            myComputerCodeGroup.FromXml(CreateCodeGroupElement("UnionCodeGroup", "FullTrust", new ZoneMembershipCondition(SecurityZone.MyComputer).ToXml()), this);
            myComputerCodeGroup.Name = Environment.GetResourceString("Policy_MyComputer_Name");
            myComputerCodeGroup.Description = Environment.GetResourceString("Policy_MyComputer_Description");

            // This code give trust to anything StrongName signed by Microsoft.
            StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(AssemblyRef.MicrosoftPublicKeyFull);
            UnionCodeGroup microsoft = new UnionCodeGroup();
            microsoft.FromXml(CreateCodeGroupElement("UnionCodeGroup", "FullTrust", new StrongNameMembershipCondition(blob, null, null).ToXml()), this);
            microsoft.Name = Environment.GetResourceString("Policy_Microsoft_Name");
            microsoft.Description = Environment.GetResourceString("Policy_Microsoft_Description");
            myComputerCodeGroup.AddChildInternal(microsoft);

            // This code give trust to anything StrongName signed using the ECMA
            // public key (core system assemblies).
            blob = new StrongNamePublicKeyBlob(AssemblyRef.EcmaPublicKeyFull);
            UnionCodeGroup ecma = new UnionCodeGroup();
            ecma.FromXml(CreateCodeGroupElement("UnionCodeGroup", "FullTrust", new StrongNameMembershipCondition(blob, null, null).ToXml()), this);
            ecma.Name = Environment.GetResourceString("Policy_Ecma_Name");
            ecma.Description = Environment.GetResourceString("Policy_Ecma_Description");
            myComputerCodeGroup.AddChildInternal(ecma);

            root.AddChildInternal(myComputerCodeGroup);

            // do the rest of the zones
            CodeGroup intranet = new UnionCodeGroup();
            intranet.FromXml(CreateCodeGroupElement("UnionCodeGroup", "LocalIntranet", new ZoneMembershipCondition(SecurityZone.Intranet).ToXml()), this);
            intranet.Name = Environment.GetResourceString("Policy_Intranet_Name");
            intranet.Description = Environment.GetResourceString("Policy_Intranet_Description");

            CodeGroup intranetNetCode = new NetCodeGroup(new AllMembershipCondition());
            intranetNetCode.Name = Environment.GetResourceString("Policy_IntranetNet_Name");
            intranetNetCode.Description = Environment.GetResourceString("Policy_IntranetNet_Description");
            intranet.AddChildInternal(intranetNetCode);

            CodeGroup intranetFileCode = new FileCodeGroup(new AllMembershipCondition(), FileIOPermissionAccess.Read | FileIOPermissionAccess.PathDiscovery);
            intranetFileCode.Name = Environment.GetResourceString("Policy_IntranetFile_Name");
            intranetFileCode.Description = Environment.GetResourceString("Policy_IntranetFile_Description");
            intranet.AddChildInternal(intranetFileCode);

            root.AddChildInternal(intranet);

            CodeGroup internet = new UnionCodeGroup();
            internet.FromXml(CreateCodeGroupElement("UnionCodeGroup", "Internet", new ZoneMembershipCondition(SecurityZone.Internet).ToXml()), this);
            internet.Name = Environment.GetResourceString("Policy_Internet_Name");
            internet.Description = Environment.GetResourceString("Policy_Internet_Description");

            CodeGroup internetNet = new NetCodeGroup(new AllMembershipCondition());
            internetNet.Name = Environment.GetResourceString("Policy_InternetNet_Name");
            internetNet.Description = Environment.GetResourceString("Policy_InternetNet_Description");
            internet.AddChildInternal(internetNet);

            root.AddChildInternal(internet);

            CodeGroup untrusted = new UnionCodeGroup();
            untrusted.FromXml(CreateCodeGroupElement("UnionCodeGroup", "Nothing", new ZoneMembershipCondition(SecurityZone.Untrusted).ToXml()), this);
            untrusted.Name = Environment.GetResourceString("Policy_Untrusted_Name");
            untrusted.Description = Environment.GetResourceString("Policy_Untrusted_Description");
            root.AddChildInternal(untrusted);

            CodeGroup trusted = new UnionCodeGroup();
            trusted.FromXml(CreateCodeGroupElement("UnionCodeGroup", "Internet", new ZoneMembershipCondition(SecurityZone.Trusted).ToXml()), this);
            trusted.Name = Environment.GetResourceString("Policy_Trusted_Name");
            trusted.Description = Environment.GetResourceString("Policy_Trusted_Description");
            CodeGroup trustedNet = new NetCodeGroup(new AllMembershipCondition());
            trustedNet.Name = Environment.GetResourceString("Policy_TrustedNet_Name");
            trustedNet.Description = Environment.GetResourceString("Policy_TrustedNet_Description");
            trusted.AddChildInternal(trustedNet);

            root.AddChildInternal(trusted);

            return root;
        }
	// Resolve code groups that match specific evidence.
	public override CodeGroup ResolveMatchingCodeGroups(Evidence evidence)
			{
				NetCodeGroup newGroup;
				CodeGroup child;

				// Validate the parameter.
				if(evidence == null)
				{
					throw new ArgumentNullException("evidence");
				}

				// Check the membership condition.
				if(!MembershipCondition.Check(evidence))
				{
					return null;
				}

				// Clone this group, except for the children.
				newGroup = new NetCodeGroup(MembershipCondition);
				newGroup.Name = Name;
				newGroup.Description = Description;

				// Resolve and add the children.
				foreach(CodeGroup group in Children)
				{
					child = group.ResolveMatchingCodeGroups(evidence);
					if(child != null)
					{
						newGroup.AddChild(child);
					}
				}

				// Return the result.
				return newGroup;
			}
Example #25
0
		public void Resolve_Null () 
		{
			NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
			cg.Resolve (null);
		}
Example #26
0
        internal void SetDefaultCodeGroups()
        {
            // NOTE: if you are going to add references to any permission set
            // that references permissions outside of mscorlib, DO NOT
            // CALL GetNamedPermissionSetInternal().  You need to use
            // CreateCodeGroupElement() and AddChildInternal().

            // NOTE: any changes to this will require that you recontemplate
            // the quick cache data found in PolicyLevelData.

            // Before we call GetNamedPermissionSetInternal, make sure that we are "loaded"
            m_loaded = true;
            UnionCodeGroup root = new UnionCodeGroup();
            root.FromXml( CreateCodeGroupElement( "UnionCodeGroup", "Nothing", new AllMembershipCondition().ToXml() ), this );
            root.Name = Environment.GetResourceString( "Policy_AllCode_Name" );
            root.Description = Environment.GetResourceString( "Policy_AllCode_DescriptionNothing" );

            UnionCodeGroup myComputerCodeGroup = new UnionCodeGroup();
            myComputerCodeGroup.FromXml( CreateCodeGroupElement( "UnionCodeGroup", "FullTrust", new ZoneMembershipCondition( SecurityZone.MyComputer ).ToXml() ), this );
            myComputerCodeGroup.Name = Environment.GetResourceString( "Policy_MyComputer_Name" );
            myComputerCodeGroup.Description = Environment.GetResourceString( "Policy_MyComputer_Description" );

            // This code give trust to anything StrongName signed by Microsoft.
            StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob( AssemblyRef.MicrosoftPublicKeyFull );
            UnionCodeGroup microsoft = new UnionCodeGroup();
            microsoft.FromXml( CreateCodeGroupElement( "UnionCodeGroup", "FullTrust", new StrongNameMembershipCondition( blob, null, null ).ToXml() ), this );
            microsoft.Name = Environment.GetResourceString( "Policy_Microsoft_Name" );
            microsoft.Description = Environment.GetResourceString( "Policy_Microsoft_Description" );
            myComputerCodeGroup.AddChildInternal( microsoft );

            // This code give trust to anything StrongName signed using the ECMA
            // public key (core system assemblies).
            blob = new StrongNamePublicKeyBlob( AssemblyRef.EcmaPublicKeyFull );
            UnionCodeGroup ecma = new UnionCodeGroup();
            ecma.FromXml( CreateCodeGroupElement( "UnionCodeGroup", "FullTrust", new StrongNameMembershipCondition( blob, null, null ).ToXml() ), this );
            ecma.Name = Environment.GetResourceString( "Policy_Ecma_Name" );
            ecma.Description = Environment.GetResourceString( "Policy_Ecma_Description" );
            myComputerCodeGroup.AddChildInternal( ecma );

            root.AddChildInternal(myComputerCodeGroup);
            
            // do the rest of the zones
            CodeGroup intranet = new UnionCodeGroup();
            intranet.FromXml( CreateCodeGroupElement( "UnionCodeGroup", "LocalIntranet", new ZoneMembershipCondition( SecurityZone.Intranet ).ToXml() ), this );
            intranet.Name = Environment.GetResourceString( "Policy_Intranet_Name" );
            intranet.Description = Environment.GetResourceString( "Policy_Intranet_Description" );

            CodeGroup intranetNetCode = new NetCodeGroup( new AllMembershipCondition() );
            intranetNetCode.Name = Environment.GetResourceString( "Policy_IntranetNet_Name" );
            intranetNetCode.Description = Environment.GetResourceString( "Policy_IntranetNet_Description" );
            intranet.AddChildInternal( intranetNetCode );

            CodeGroup intranetFileCode = new FileCodeGroup( new AllMembershipCondition(), FileIOPermissionAccess.Read | FileIOPermissionAccess.PathDiscovery );
            intranetFileCode.Name = Environment.GetResourceString( "Policy_IntranetFile_Name" );
            intranetFileCode.Description = Environment.GetResourceString( "Policy_IntranetFile_Description" );
            intranet.AddChildInternal( intranetFileCode );

            root.AddChildInternal( intranet );

            CodeGroup internet = new UnionCodeGroup();
            internet.FromXml( CreateCodeGroupElement( "UnionCodeGroup", "Nothing", new ZoneMembershipCondition( SecurityZone.Internet ).ToXml() ), this );
            internet.Name = Environment.GetResourceString( "Policy_Internet_Name" );
            internet.Description = Environment.GetResourceString( "Policy_Internet_Description" );


            root.AddChildInternal( internet );

            CodeGroup untrusted = new UnionCodeGroup();
            untrusted.FromXml( CreateCodeGroupElement( "UnionCodeGroup", "Nothing", new ZoneMembershipCondition( SecurityZone.Untrusted ).ToXml() ), this );
            untrusted.Name = Environment.GetResourceString( "Policy_Untrusted_Name" );
            untrusted.Description = Environment.GetResourceString( "Policy_Untrusted_Description" );
            root.AddChildInternal( untrusted );

            CodeGroup trusted = new UnionCodeGroup();
            trusted.FromXml( CreateCodeGroupElement( "UnionCodeGroup", "Internet", new ZoneMembershipCondition( SecurityZone.Trusted ).ToXml() ), this );
            trusted.Name = Environment.GetResourceString( "Policy_Trusted_Name" );
            trusted.Description = Environment.GetResourceString( "Policy_Trusted_Description" );
            CodeGroup trustedNet = new NetCodeGroup( new AllMembershipCondition() );
            trustedNet.Name = Environment.GetResourceString( "Policy_TrustedNet_Name" );
            trustedNet.Description = Environment.GetResourceString( "Policy_TrustedNet_Description" );
            trusted.AddChildInternal( trustedNet );

            root.AddChildInternal( trusted );
            m_rootCodeGroup = root;
        }
Example #27
0
		public void MergeLogic () 
		{
			NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
			Assert.AreEqual ("Union", cg.MergeLogic, "MergeLogic");
		}
Example #28
0
		public void Constructor_Null () 
		{
			NetCodeGroup cg = new NetCodeGroup ((IMembershipCondition)null);
		}
Example #29
0
		public void ToFromXmlRoundtrip () 
		{
			NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
			cg.Name = "SomeName";
			cg.Description = "Some Description";
			Assert.IsTrue (cg.Equals (cg), "Equals (itself)");
			SecurityElement se = cg.ToXml ();

			NetCodeGroup cg2 = new NetCodeGroup (new AllMembershipCondition());
			cg2.Name = "SomeOtherName";
			cg2.Description = "Some Other Description";
			Assert.IsTrue (!cg.Equals (cg2), "Equals (another)");

			cg2.FromXml (se);
			Assert.IsTrue (cg.Equals (cg2), "Equals (FromXml)");
		}
 public static PermissionSet GetStandardSandbox(Evidence evidence)
 {
     if (evidence == null)
     {
         throw new ArgumentNullException("evidence");
     }
     Zone hostEvidence = evidence.GetHostEvidence<Zone>();
     if (hostEvidence == null)
     {
         return new PermissionSet(PermissionState.None);
     }
     if (hostEvidence.SecurityZone == SecurityZone.MyComputer)
     {
         return new PermissionSet(PermissionState.Unrestricted);
     }
     if (hostEvidence.SecurityZone == SecurityZone.Intranet)
     {
         PermissionSet localIntranet = BuiltInPermissionSets.LocalIntranet;
         PolicyStatement statement = new NetCodeGroup(new AllMembershipCondition()).Resolve(evidence);
         PolicyStatement statement2 = new FileCodeGroup(new AllMembershipCondition(), FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read).Resolve(evidence);
         if (statement != null)
         {
             localIntranet.InplaceUnion(statement.PermissionSet);
         }
         if (statement2 != null)
         {
             localIntranet.InplaceUnion(statement2.PermissionSet);
         }
         return localIntranet;
     }
     if ((hostEvidence.SecurityZone != SecurityZone.Internet) && (hostEvidence.SecurityZone != SecurityZone.Trusted))
     {
         return new PermissionSet(PermissionState.None);
     }
     PermissionSet internet = BuiltInPermissionSets.Internet;
     PolicyStatement statement3 = new NetCodeGroup(new AllMembershipCondition()).Resolve(evidence);
     if (statement3 != null)
     {
         internet.InplaceUnion(statement3.PermissionSet);
     }
     return internet;
 }
 private CodeGroup CreateDefaultMachinePolicy()
 {
     UnionCodeGroup group = new UnionCodeGroup();
     group.FromXml(CreateCodeGroupElement("UnionCodeGroup", "Nothing", new AllMembershipCondition().ToXml()), this);
     group.Name = Environment.GetResourceString("Policy_AllCode_Name");
     group.Description = Environment.GetResourceString("Policy_AllCode_DescriptionNothing");
     UnionCodeGroup group2 = new UnionCodeGroup();
     group2.FromXml(CreateCodeGroupElement("UnionCodeGroup", "FullTrust", new ZoneMembershipCondition(SecurityZone.MyComputer).ToXml()), this);
     group2.Name = Environment.GetResourceString("Policy_MyComputer_Name");
     group2.Description = Environment.GetResourceString("Policy_MyComputer_Description");
     StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob("002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293");
     UnionCodeGroup group3 = new UnionCodeGroup();
     group3.FromXml(CreateCodeGroupElement("UnionCodeGroup", "FullTrust", new StrongNameMembershipCondition(blob, null, null).ToXml()), this);
     group3.Name = Environment.GetResourceString("Policy_Microsoft_Name");
     group3.Description = Environment.GetResourceString("Policy_Microsoft_Description");
     group2.AddChildInternal(group3);
     blob = new StrongNamePublicKeyBlob("00000000000000000400000000000000");
     UnionCodeGroup group4 = new UnionCodeGroup();
     group4.FromXml(CreateCodeGroupElement("UnionCodeGroup", "FullTrust", new StrongNameMembershipCondition(blob, null, null).ToXml()), this);
     group4.Name = Environment.GetResourceString("Policy_Ecma_Name");
     group4.Description = Environment.GetResourceString("Policy_Ecma_Description");
     group2.AddChildInternal(group4);
     group.AddChildInternal(group2);
     CodeGroup group5 = new UnionCodeGroup();
     group5.FromXml(CreateCodeGroupElement("UnionCodeGroup", "LocalIntranet", new ZoneMembershipCondition(SecurityZone.Intranet).ToXml()), this);
     group5.Name = Environment.GetResourceString("Policy_Intranet_Name");
     group5.Description = Environment.GetResourceString("Policy_Intranet_Description");
     CodeGroup group6 = new NetCodeGroup(new AllMembershipCondition()) {
         Name = Environment.GetResourceString("Policy_IntranetNet_Name"),
         Description = Environment.GetResourceString("Policy_IntranetNet_Description")
     };
     group5.AddChildInternal(group6);
     CodeGroup group7 = new FileCodeGroup(new AllMembershipCondition(), FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read) {
         Name = Environment.GetResourceString("Policy_IntranetFile_Name"),
         Description = Environment.GetResourceString("Policy_IntranetFile_Description")
     };
     group5.AddChildInternal(group7);
     group.AddChildInternal(group5);
     CodeGroup group8 = new UnionCodeGroup();
     group8.FromXml(CreateCodeGroupElement("UnionCodeGroup", "Internet", new ZoneMembershipCondition(SecurityZone.Internet).ToXml()), this);
     group8.Name = Environment.GetResourceString("Policy_Internet_Name");
     group8.Description = Environment.GetResourceString("Policy_Internet_Description");
     CodeGroup group9 = new NetCodeGroup(new AllMembershipCondition()) {
         Name = Environment.GetResourceString("Policy_InternetNet_Name"),
         Description = Environment.GetResourceString("Policy_InternetNet_Description")
     };
     group8.AddChildInternal(group9);
     group.AddChildInternal(group8);
     CodeGroup group10 = new UnionCodeGroup();
     group10.FromXml(CreateCodeGroupElement("UnionCodeGroup", "Nothing", new ZoneMembershipCondition(SecurityZone.Untrusted).ToXml()), this);
     group10.Name = Environment.GetResourceString("Policy_Untrusted_Name");
     group10.Description = Environment.GetResourceString("Policy_Untrusted_Description");
     group.AddChildInternal(group10);
     CodeGroup group11 = new UnionCodeGroup();
     group11.FromXml(CreateCodeGroupElement("UnionCodeGroup", "Internet", new ZoneMembershipCondition(SecurityZone.Trusted).ToXml()), this);
     group11.Name = Environment.GetResourceString("Policy_Trusted_Name");
     group11.Description = Environment.GetResourceString("Policy_Trusted_Description");
     CodeGroup group12 = new NetCodeGroup(new AllMembershipCondition()) {
         Name = Environment.GetResourceString("Policy_TrustedNet_Name"),
         Description = Environment.GetResourceString("Policy_TrustedNet_Description")
     };
     group11.AddChildInternal(group12);
     group.AddChildInternal(group11);
     return group;
 }
Example #32
0
        /// <include file='doc\NetCodeGroup.uex' path='docs/doc[@for="NetCodeGroup.Copy"]/*' />
        public override CodeGroup Copy()
        {
            NetCodeGroup group = new NetCodeGroup( this.MembershipCondition );
            
            group.Name = this.Name;
            group.Description = this.Description;

            IEnumerator enumerator = this.Children.GetEnumerator();

            while (enumerator.MoveNext())
            {
                group.AddChild( (CodeGroup)enumerator.Current );
            }

            
            return group;
        }
		public void MergeLogic () 
		{
			NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
			AssertEquals ("MergeLogic", "Union", cg.MergeLogic);
		}
        public override CodeGroup Copy()
        {
            NetCodeGroup group = new NetCodeGroup( this.MembershipCondition );

            group.Name = this.Name;
            group.Description = this.Description;
            if (m_schemesList != null)
            {
                group.m_schemesList = (ArrayList)this.m_schemesList.Clone();
                group.m_accessList = new ArrayList(this.m_accessList.Count);
                for (int i = 0; i < this.m_accessList.Count; ++i)
                    group.m_accessList.Add(((ArrayList)this.m_accessList[i]).Clone());
            }

            IEnumerator enumerator = this.Children.GetEnumerator();

            while (enumerator.MoveNext())
            {
                group.AddChild( (CodeGroup)enumerator.Current );
            }


            return group;
        }
Example #35
0
		public override CodeGroup Copy ()
		{
			NetCodeGroup copy = new NetCodeGroup (MembershipCondition);
			copy.Name = Name;
			copy.Description = Description;
			copy.PolicyStatement = PolicyStatement;		

			foreach (CodeGroup child in Children) {
				copy.AddChild (child.Copy ());	// deep copy
			}
			return copy;
		}