23 private string m_label;
25 [OptionalField(VersionAdded = 2)]
28 private ConfigId m_configId;
30 private bool m_useDefaultCodeGroupsOnReset;
32 private bool m_generateQuickCacheOnLoad;
34 private bool m_caching;
36 private bool m_throwOnLoadError;
40 private bool m_loaded;
44 private string m_path;
46 private static object s_InternalSyncObject;
48 private static readonly
string[] s_reservedNamedPermissionSets;
50 private static string[] EcmaFullTrustAssemblies;
52 private static string[] MicrosoftFullTrustAssemblies;
54 private static object InternalSyncObject
58 if (s_InternalSyncObject ==
null)
60 object value =
new object();
63 return s_InternalSyncObject;
75 m_label = DeriveLabelFromType();
92 internal ConfigId ConfigId => m_configId;
94 internal string Path => m_path;
100 [SecuritySafeCritical]
104 return GetLocationFromType(m_type);
113 [SecuritySafeCritical]
117 return m_rootCodeGroup;
119 [SecuritySafeCritical]
127 m_rootCodeGroup = value.Copy();
135 [SecuritySafeCritical]
139 LoadAllPermissionSets();
152 [Obsolete(
"Because all GAC assemblies always get full trust, the full trust list is no longer meaningful. You should install any assemblies that are used in security policy in the GAC to ensure they are trusted.")]
155 [SecuritySafeCritical]
159 return new ArrayList(m_fullTrustAssemblies);
165 s_reservedNamedPermissionSets =
new string[7]
175 EcmaFullTrustAssemblies =
new string[9]
177 "mscorlib.resources",
181 "System.Xml.resources",
182 "System.Windows.Forms",
183 "System.Windows.Forms.resources",
185 "System.Data.resources" 187 MicrosoftFullTrustAssemblies =
new string[12]
190 "System.Security.resources",
192 "System.Drawing.resources",
194 "System.Messaging.resources",
195 "System.ServiceProcess",
196 "System.ServiceProcess.resources",
197 "System.DirectoryServices",
198 "System.DirectoryServices.resources",
200 "System.Deployment.resources" 209 DeriveTypeFromLabel();
213 private void DeriveTypeFromLabel()
215 if (m_label.Equals(Environment.GetResourceString(
"Policy_PL_User")))
220 if (m_label.Equals(Environment.GetResourceString(
"Policy_PL_Machine")))
225 if (m_label.Equals(Environment.GetResourceString(
"Policy_PL_Enterprise")))
230 if (m_label.Equals(Environment.GetResourceString(
"Policy_PL_AppDomain")))
235 throw new ArgumentException(Environment.GetResourceString(
"Policy_Default"));
238 private string DeriveLabelFromType()
243 return Environment.GetResourceString(
"Policy_PL_User");
245 return Environment.GetResourceString(
"Policy_PL_Machine");
247 return Environment.GetResourceString(
"Policy_PL_Enterprise");
249 return Environment.GetResourceString(
"Policy_PL_AppDomain");
251 throw new ArgumentException(Environment.GetResourceString(
"Arg_EnumIllegalVal", (
int)m_type));
255 private PolicyLevel()
261 : this(type, GetLocationFromType(type))
266 : this(type, path, ConfigId.
None)
270 internal PolicyLevel(
PolicyLevelType type,
string path, ConfigId configId)
274 m_loaded = (path ==
null);
277 m_rootCodeGroup = CreateDefaultAllGroup();
278 SetFactoryPermissionSets();
279 SetDefaultFullTrustAssemblies();
281 m_configId = configId;
290 return Config.UserDirectory +
"security.config";
292 return Config.MachineDirectory +
"security.config";
294 return Config.MachineDirectory +
"enterprisesec.config";
302 [SecuritySafeCritical]
303 [Obsolete(
"AppDomain policy levels are obsolete and will be removed in a future release of the .NET Framework. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
316 if (evidence ==
null)
327 [Obsolete(
"Because all GAC assemblies always get full trust, the full trust list is no longer meaningful. You should install any assemblies that are used in security policy in the GAC to ensure they are trusted.")]
341 [SecuritySafeCritical]
342 [Obsolete(
"Because all GAC assemblies always get full trust, the full trust list is no longer meaningful. You should install any assemblies that are used in security policy in the GAC to ensure they are trusted.")]
350 IEnumerator enumerator = m_fullTrustAssemblies.GetEnumerator();
358 lock (m_fullTrustAssemblies)
360 m_fullTrustAssemblies.Add(snMC);
368 [Obsolete(
"Because all GAC assemblies always get full trust, the full trust list is no longer meaningful. You should install any assemblies that are used in security policy in the GAC to ensure they are trusted.")]
382 [SecuritySafeCritical]
383 [Obsolete(
"Because all GAC assemblies always get full trust, the full trust list is no longer meaningful. You should install any assemblies that are used in security policy in the GAC to ensure they are trusted.")]
392 IEnumerator enumerator = m_fullTrustAssemblies.GetEnumerator();
405 lock (m_fullTrustAssemblies)
407 m_fullTrustAssemblies.Remove(obj);
415 [SecuritySafeCritical]
423 LoadAllPermissionSets();
435 namedPermissionSet.IgnoreTypeLoadFailures =
true;
436 m_namedPermissionSets.
Add(namedPermissionSet);
459 [SecuritySafeCritical]
467 LoadAllPermissionSets();
469 for (
int i = 0; i < s_reservedNamedPermissionSets.Length; i++)
471 if (s_reservedNamedPermissionSets[i].Equals(name))
476 ArrayList namedPermissionSets = m_namedPermissionSets;
477 for (
int j = 0; j < namedPermissionSets.
Count; j++)
490 arrayList.
Add(m_rootCodeGroup);
491 for (
int k = 0; k < arrayList.
Count; k++)
499 if (enumerator !=
null)
518 [SecuritySafeCritical]
529 for (
int i = 0; i < s_reservedNamedPermissionSets.Length; i++)
531 if (s_reservedNamedPermissionSets[i].Equals(name))
537 if (namedPermissionSetInternal ==
null)
542 namedPermissionSetInternal.Reset();
543 namedPermissionSetInternal.SetUnrestricted(pSet.
IsUnrestricted());
560 [SecuritySafeCritical]
568 if (namedPermissionSetInternal !=
null)
577 [SecuritySafeCritical]
580 if (m_configId == ConfigId.None)
586 if (!Config.RecoverData(m_configId))
591 m_rootCodeGroup =
null;
592 m_namedPermissionSets =
null;
598 [SecuritySafeCritical]
609 [SecuritySafeCritical]
612 return Resolve(evidence, 0,
null);
617 [SecuritySafeCritical]
621 LoadAllPermissionSets();
635 enumerator = m_fullTrustAssemblies.GetEnumerator();
647 securityElement4.
AddChild(securityElement5);
649 securityElement.
AddChild(securityElement4);
650 securityElement.
AddChild(securityElement2);
652 securityElement.
AddChild(securityElement3);
653 return securityElement;
672 if (securityElement !=
null)
679 if (securityElement2.
Tag.Equals(
"SecurityClass"))
681 string text = securityElement2.Attribute(
"Name");
682 string text2 = securityElement2.Attribute(
"Description");
683 if (text !=
null && text2 !=
null)
685 hashtable.
Add(text, text2);
695 if (securityElement3 !=
null && securityElement3.InternalChildren !=
null)
703 arrayList.
Add(strongNameMembershipCondition);
706 m_fullTrustAssemblies = arrayList;
710 if (securityElement4 !=
null && securityElement4.InternalChildren !=
null)
712 securityElement5 = UnnormalizeClassDeep(securityElement4, hashtable);
713 string[] array = s_reservedNamedPermissionSets;
714 foreach (
string name
in array)
716 FindElement(securityElement5, name);
719 if (securityElement5 ==
null)
723 arrayList2.
Add(BuiltInPermissionSets.FullTrust);
724 arrayList2.
Add(BuiltInPermissionSets.Everything);
725 arrayList2.
Add(BuiltInPermissionSets.SkipVerification);
726 arrayList2.
Add(BuiltInPermissionSets.Execution);
727 arrayList2.
Add(BuiltInPermissionSets.Nothing);
728 arrayList2.
Add(BuiltInPermissionSets.Internet);
729 arrayList2.
Add(BuiltInPermissionSets.LocalIntranet);
732 item.IgnoreTypeLoadFailures =
true;
734 m_namedPermissionSets = arrayList2;
735 m_permSetElement = securityElement5;
737 if (securityElement6 ==
null)
741 CodeGroup codeGroup = XMLUtil.CreateCodeGroup(UnnormalizeClassDeep(securityElement6, hashtable));
742 if (codeGroup ==
null)
746 codeGroup.
FromXml(securityElement6,
this);
747 m_rootCodeGroup = codeGroup;
754 if (
string.IsNullOrEmpty(name))
758 if (name.Equals(
"FullTrust"))
760 return BuiltInPermissionSets.FullTrust;
762 if (name.Equals(
"Nothing"))
764 return BuiltInPermissionSets.Nothing;
766 if (name.Equals(
"Execution"))
768 return BuiltInPermissionSets.Execution;
770 if (name.Equals(
"SkipVerification"))
772 return BuiltInPermissionSets.SkipVerification;
774 if (name.Equals(
"Internet"))
776 return BuiltInPermissionSets.Internet;
778 if (name.Equals(
"LocalIntranet"))
780 return BuiltInPermissionSets.LocalIntranet;
786 internal NamedPermissionSet GetNamedPermissionSetInternal(
string name)
789 lock (InternalSyncObject)
791 foreach (NamedPermissionSet namedPermissionSet3
in m_namedPermissionSets)
793 if (namedPermissionSet3.Name.Equals(name))
795 return namedPermissionSet3;
798 if (m_permSetElement !=
null)
800 SecurityElement securityElement = FindElement(m_permSetElement, name);
801 if (securityElement !=
null)
803 NamedPermissionSet namedPermissionSet2 =
new NamedPermissionSet();
804 namedPermissionSet2.Name = name;
805 m_namedPermissionSets.Add(namedPermissionSet2);
808 namedPermissionSet2.FromXml(securityElement, allowInternalOnly:
false, ignoreTypeLoadFailures:
true);
812 m_namedPermissionSets.Remove(namedPermissionSet2);
815 if (namedPermissionSet2.Name !=
null)
817 return namedPermissionSet2;
819 m_namedPermissionSets.Remove(namedPermissionSet2);
827 internal PolicyStatement
Resolve(Evidence evidence,
int count,
byte[] serializedEvidence)
829 if (evidence ==
null)
831 throw new ArgumentNullException(
"evidence");
833 PolicyStatement policyStatement =
null;
834 if (serializedEvidence !=
null)
836 policyStatement = CheckCache(count, serializedEvidence);
838 if (policyStatement ==
null)
842 if (m_fullTrustAssemblies !=
null && IsFullTrustAssembly(m_fullTrustAssemblies, evidence))
849 ArrayList arrayList = GenericResolve(evidence, out allConst);
850 policyStatement =
new PolicyStatement();
851 policyStatement.PermissionSet =
null;
855 PolicyStatement policy = ((CodeGroupStackFrame)enumerator.
Current).policy;
858 policyStatement.GetPermissionSetNoCopy().InplaceUnion(policy.GetPermissionSetNoCopy());
859 policyStatement.Attributes |= policy.Attributes;
860 if (policy.HasDependentEvidence)
862 foreach (IDelayEvaluatedEvidence item
in policy.DependentEvidence)
872 Cache(count, evidence.RawSerialize(), policyStatement);
875 return policyStatement;
879 private void CheckLoaded()
883 lock (InternalSyncObject)
893 private static byte[] ReadFile(
string fileName)
897 int num = (int)fileStream.
Length;
898 byte[] array =
new byte[num];
899 num = fileStream.
Read(array, 0, num);
906 private void LoadPolicyLevel()
909 CodeAccessPermission.Assert(allPossible:
true);
910 if (
File.InternalExists(m_path))
913 SecurityElement securityElement;
916 string @
string = uTF.
GetString(ReadFile(m_path));
917 securityElement = SecurityElement.FromString(@
string);
919 catch (Exception ex2)
921 string text =
string.IsNullOrEmpty(ex2.Message) ? ex2.GetType().AssemblyQualifiedName : ex2.Message;
922 ex = LoadError(Environment.GetResourceString(
"Error_SecurityPolicyFileParseEx",
Label, text));
925 if (securityElement ==
null)
927 ex = LoadError(Environment.GetResourceString(
"Error_SecurityPolicyFileParse",
Label));
931 SecurityElement securityElement2 = securityElement.SearchForChildByTag(
"mscorlib");
932 if (securityElement2 ==
null)
934 ex = LoadError(Environment.GetResourceString(
"Error_SecurityPolicyFileParse",
Label));
938 SecurityElement securityElement3 = securityElement2.SearchForChildByTag(
"security");
939 if (securityElement3 ==
null)
941 ex = LoadError(Environment.GetResourceString(
"Error_SecurityPolicyFileParse",
Label));
945 SecurityElement securityElement4 = securityElement3.SearchForChildByTag(
"policy");
946 if (securityElement4 ==
null)
948 ex = LoadError(Environment.GetResourceString(
"Error_SecurityPolicyFileParse",
Label));
952 SecurityElement securityElement5 = securityElement4.SearchForChildByTag(
"PolicyLevel");
953 if (securityElement5 !=
null)
961 ex = LoadError(Environment.GetResourceString(
"Error_SecurityPolicyFileParse",
Label));
967 ex = LoadError(Environment.GetResourceString(
"Error_SecurityPolicyFileParse",
Label));
984 private Exception LoadError(
string message)
988 return new ArgumentException(message);
990 Config.WriteToEventLog(message);
995 private void Cache(
int count,
byte[] serializedEvidence, PolicyStatement policy)
997 if (m_configId != 0 && serializedEvidence !=
null)
999 byte[] data =
new SecurityDocument(policy.ToXml(
null, useInternal:
true)).m_data;
1000 Config.AddCacheEntry(m_configId, count, serializedEvidence, data);
1005 private PolicyStatement CheckCache(
int count,
byte[] serializedEvidence)
1007 if (m_configId == ConfigId.None)
1011 if (serializedEvidence ==
null)
1015 if (!Config.GetCacheEntry(m_configId, count, serializedEvidence, out
byte[] data))
1019 PolicyStatement policyStatement =
new PolicyStatement();
1020 SecurityDocument doc =
new SecurityDocument(data);
1021 policyStatement.FromXml(doc, 0,
null, allowInternalOnly:
true);
1022 return policyStatement;
1026 private static bool IsFullTrustAssembly(
ArrayList fullTrustAssemblies, Evidence evidence)
1028 if (fullTrustAssemblies.
Count == 0)
1032 if (evidence !=
null)
1034 lock (fullTrustAssemblies)
1039 StrongNameMembershipCondition strongNameMembershipCondition = (StrongNameMembershipCondition)enumerator.
Current;
1040 if (strongNameMembershipCondition.Check(evidence))
1042 if (Environment.GetCompatibilityFlag(CompatibilityFlag.FullTrustListAssembliesInGac))
1044 if (
new ZoneMembershipCondition().Check(evidence))
1049 else if (
new GacMembershipCondition().Check(evidence))
1060 private CodeGroup CreateDefaultAllGroup()
1062 UnionCodeGroup unionCodeGroup =
new UnionCodeGroup();
1063 unionCodeGroup.FromXml(CreateCodeGroupElement(
"UnionCodeGroup",
"FullTrust",
new AllMembershipCondition().
ToXml()),
this);
1064 unionCodeGroup.Name = Environment.GetResourceString(
"Policy_AllCode_Name");
1065 unionCodeGroup.Description = Environment.GetResourceString(
"Policy_AllCode_DescriptionFullTrust");
1066 return unionCodeGroup;
1070 private CodeGroup CreateDefaultMachinePolicy()
1072 UnionCodeGroup unionCodeGroup =
new UnionCodeGroup();
1073 unionCodeGroup.FromXml(CreateCodeGroupElement(
"UnionCodeGroup",
"Nothing",
new AllMembershipCondition().
ToXml()),
this);
1074 unionCodeGroup.Name = Environment.GetResourceString(
"Policy_AllCode_Name");
1075 unionCodeGroup.Description = Environment.GetResourceString(
"Policy_AllCode_DescriptionNothing");
1076 UnionCodeGroup unionCodeGroup2 =
new UnionCodeGroup();
1077 unionCodeGroup2.FromXml(CreateCodeGroupElement(
"UnionCodeGroup",
"FullTrust",
new ZoneMembershipCondition(
SecurityZone.MyComputer).ToXml()),
this);
1078 unionCodeGroup2.Name = Environment.GetResourceString(
"Policy_MyComputer_Name");
1079 unionCodeGroup2.Description = Environment.GetResourceString(
"Policy_MyComputer_Description");
1080 StrongNamePublicKeyBlob blob =
new StrongNamePublicKeyBlob(
"002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293");
1081 UnionCodeGroup unionCodeGroup3 =
new UnionCodeGroup();
1082 unionCodeGroup3.FromXml(CreateCodeGroupElement(
"UnionCodeGroup",
"FullTrust",
new StrongNameMembershipCondition(blob,
null,
null).
ToXml()),
this);
1083 unionCodeGroup3.Name = Environment.GetResourceString(
"Policy_Microsoft_Name");
1084 unionCodeGroup3.Description = Environment.GetResourceString(
"Policy_Microsoft_Description");
1085 unionCodeGroup2.AddChildInternal(unionCodeGroup3);
1087 UnionCodeGroup unionCodeGroup4 =
new UnionCodeGroup();
1088 unionCodeGroup4.FromXml(CreateCodeGroupElement(
"UnionCodeGroup",
"FullTrust",
new StrongNameMembershipCondition(blob,
null,
null).
ToXml()),
this);
1089 unionCodeGroup4.Name = Environment.GetResourceString(
"Policy_Ecma_Name");
1090 unionCodeGroup4.Description = Environment.GetResourceString(
"Policy_Ecma_Description");
1091 unionCodeGroup2.AddChildInternal(unionCodeGroup4);
1092 unionCodeGroup.AddChildInternal(unionCodeGroup2);
1093 CodeGroup codeGroup =
new UnionCodeGroup();
1094 codeGroup.FromXml(CreateCodeGroupElement(
"UnionCodeGroup",
"LocalIntranet",
new ZoneMembershipCondition(
SecurityZone.Intranet).ToXml()),
this);
1095 codeGroup.Name = Environment.GetResourceString(
"Policy_Intranet_Name");
1096 codeGroup.Description = Environment.GetResourceString(
"Policy_Intranet_Description");
1097 CodeGroup codeGroup2 =
new NetCodeGroup(
new AllMembershipCondition());
1098 codeGroup2.Name = Environment.GetResourceString(
"Policy_IntranetNet_Name");
1099 codeGroup2.Description = Environment.GetResourceString(
"Policy_IntranetNet_Description");
1100 codeGroup.AddChildInternal(codeGroup2);
1102 codeGroup3.Name = Environment.GetResourceString(
"Policy_IntranetFile_Name");
1103 codeGroup3.Description = Environment.GetResourceString(
"Policy_IntranetFile_Description");
1104 codeGroup.AddChildInternal(codeGroup3);
1105 unionCodeGroup.AddChildInternal(codeGroup);
1106 CodeGroup codeGroup4 =
new UnionCodeGroup();
1107 codeGroup4.FromXml(CreateCodeGroupElement(
"UnionCodeGroup",
"Internet",
new ZoneMembershipCondition(
SecurityZone.Internet).ToXml()),
this);
1108 codeGroup4.Name = Environment.GetResourceString(
"Policy_Internet_Name");
1109 codeGroup4.Description = Environment.GetResourceString(
"Policy_Internet_Description");
1110 CodeGroup codeGroup5 =
new NetCodeGroup(
new AllMembershipCondition());
1111 codeGroup5.Name = Environment.GetResourceString(
"Policy_InternetNet_Name");
1112 codeGroup5.Description = Environment.GetResourceString(
"Policy_InternetNet_Description");
1113 codeGroup4.AddChildInternal(codeGroup5);
1114 unionCodeGroup.AddChildInternal(codeGroup4);
1115 CodeGroup codeGroup6 =
new UnionCodeGroup();
1116 codeGroup6.FromXml(CreateCodeGroupElement(
"UnionCodeGroup",
"Nothing",
new ZoneMembershipCondition(
SecurityZone.Untrusted).ToXml()),
this);
1117 codeGroup6.Name = Environment.GetResourceString(
"Policy_Untrusted_Name");
1118 codeGroup6.Description = Environment.GetResourceString(
"Policy_Untrusted_Description");
1119 unionCodeGroup.AddChildInternal(codeGroup6);
1120 CodeGroup codeGroup7 =
new UnionCodeGroup();
1121 codeGroup7.FromXml(CreateCodeGroupElement(
"UnionCodeGroup",
"Internet",
new ZoneMembershipCondition(
SecurityZone.Trusted).ToXml()),
this);
1122 codeGroup7.Name = Environment.GetResourceString(
"Policy_Trusted_Name");
1123 codeGroup7.Description = Environment.GetResourceString(
"Policy_Trusted_Description");
1124 CodeGroup codeGroup8 =
new NetCodeGroup(
new AllMembershipCondition());
1125 codeGroup8.Name = Environment.GetResourceString(
"Policy_TrustedNet_Name");
1126 codeGroup8.Description = Environment.GetResourceString(
"Policy_TrustedNet_Description");
1127 codeGroup7.AddChildInternal(codeGroup8);
1128 unionCodeGroup.AddChildInternal(codeGroup7);
1129 return unionCodeGroup;
1132 private static SecurityElement CreateCodeGroupElement(
string codeGroupType,
string permissionSetName, SecurityElement mshipElement)
1134 SecurityElement securityElement =
new SecurityElement(
"CodeGroup");
1135 securityElement.AddAttribute(
"class", (
"System.Security." + codeGroupType +
", mscorlib, Version={VERSION}, Culture=neutral, PublicKeyToken=b77a5c561934e089") ??
"");
1136 securityElement.AddAttribute(
"version",
"1");
1137 securityElement.AddAttribute(
"PermissionSetName", permissionSetName);
1138 securityElement.AddChild(mshipElement);
1139 return securityElement;
1142 private void SetDefaultFullTrustAssemblies()
1144 m_fullTrustAssemblies =
new ArrayList();
1146 for (
int i = 0; i < EcmaFullTrustAssemblies.Length; i++)
1148 StrongNameMembershipCondition value =
new StrongNameMembershipCondition(blob, EcmaFullTrustAssemblies[i],
new Version(
"4.0.0.0"));
1149 m_fullTrustAssemblies.Add(value);
1151 StrongNamePublicKeyBlob blob2 =
new StrongNamePublicKeyBlob(
"002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293");
1152 for (
int j = 0; j < MicrosoftFullTrustAssemblies.Length; j++)
1154 StrongNameMembershipCondition value2 =
new StrongNameMembershipCondition(blob2, MicrosoftFullTrustAssemblies[j],
new Version(
"4.0.0.0"));
1155 m_fullTrustAssemblies.Add(value2);
1160 private void SetDefault()
1164 string path = GetLocationFromType(m_type) +
".default";
1165 if (
File.InternalExists(path))
1167 PolicyLevel policyLevel =
new PolicyLevel(m_type, path);
1168 m_rootCodeGroup = policyLevel.RootCodeGroup;
1169 m_namedPermissionSets = (
ArrayList)policyLevel.NamedPermissionSets;
1170 m_fullTrustAssemblies = (
ArrayList)policyLevel.FullTrustAssemblies;
1175 m_namedPermissionSets =
null;
1176 m_rootCodeGroup =
null;
1177 m_permSetElement =
null;
1178 m_rootCodeGroup = ((m_type ==
PolicyLevelType.Machine) ? CreateDefaultMachinePolicy() : CreateDefaultAllGroup());
1179 SetFactoryPermissionSets();
1180 SetDefaultFullTrustAssemblies();
1186 private void SetFactoryPermissionSets()
1188 lock (InternalSyncObject)
1190 m_namedPermissionSets =
new ArrayList();
1191 m_namedPermissionSets.Add(BuiltInPermissionSets.FullTrust);
1192 m_namedPermissionSets.Add(BuiltInPermissionSets.Everything);
1193 m_namedPermissionSets.Add(BuiltInPermissionSets.Nothing);
1194 m_namedPermissionSets.Add(BuiltInPermissionSets.SkipVerification);
1195 m_namedPermissionSets.Add(BuiltInPermissionSets.Execution);
1196 m_namedPermissionSets.Add(BuiltInPermissionSets.Internet);
1197 m_namedPermissionSets.Add(BuiltInPermissionSets.LocalIntranet);
1201 private SecurityElement FindElement(SecurityElement element,
string name)
1203 IEnumerator enumerator = element.Children.GetEnumerator();
1206 SecurityElement securityElement = (SecurityElement)enumerator.
Current;
1207 if (securityElement.Tag.Equals(
"PermissionSet"))
1209 string text = securityElement.Attribute(
"Name");
1210 if (text !=
null && text.Equals(name))
1212 element.InternalChildren.Remove(securityElement);
1213 return securityElement;
1221 private void LoadAllPermissionSets()
1223 if (m_permSetElement !=
null && m_permSetElement.InternalChildren !=
null)
1225 lock (InternalSyncObject)
1227 while (m_permSetElement !=
null && m_permSetElement.InternalChildren.
Count != 0)
1229 SecurityElement securityElement = (SecurityElement)m_permSetElement.
Children[m_permSetElement.InternalChildren.
Count - 1];
1230 m_permSetElement.InternalChildren.
RemoveAt(m_permSetElement.InternalChildren.
Count - 1);
1231 if (securityElement.Tag.Equals(
"PermissionSet") && securityElement.Attribute(
"class").Equals(
"System.Security.NamedPermissionSet"))
1233 NamedPermissionSet namedPermissionSet =
new NamedPermissionSet();
1234 namedPermissionSet.FromXmlNameOnly(securityElement);
1235 if (namedPermissionSet.Name !=
null)
1237 m_namedPermissionSets.Add(namedPermissionSet);
1240 namedPermissionSet.FromXml(securityElement, allowInternalOnly:
false, ignoreTypeLoadFailures:
true);
1244 m_namedPermissionSets.Remove(namedPermissionSet);
1249 m_permSetElement =
null;
1255 private ArrayList GenericResolve(Evidence evidence, out
bool allConst)
1257 CodeGroupStack codeGroupStack =
new CodeGroupStack();
1258 CodeGroup rootCodeGroup = m_rootCodeGroup;
1259 if (rootCodeGroup ==
null)
1261 throw new PolicyException(Environment.GetResourceString(
"Policy_NonFullTrustAssembly"));
1263 CodeGroupStackFrame codeGroupStackFrame =
new CodeGroupStackFrame();
1264 codeGroupStackFrame.current = rootCodeGroup;
1265 codeGroupStackFrame.parent =
null;
1266 codeGroupStack.Push(codeGroupStackFrame);
1270 Exception ex =
null;
1271 while (!codeGroupStack.IsEmpty())
1273 codeGroupStackFrame = codeGroupStack.Pop();
1274 FirstMatchCodeGroup firstMatchCodeGroup = codeGroupStackFrame.current as FirstMatchCodeGroup;
1275 UnionCodeGroup unionCodeGroup = codeGroupStackFrame.current as UnionCodeGroup;
1276 if (!(codeGroupStackFrame.current.MembershipCondition is IConstantMembershipCondition) || (unionCodeGroup ==
null && firstMatchCodeGroup ==
null))
1282 codeGroupStackFrame.policy = PolicyManager.ResolveCodeGroup(codeGroupStackFrame.current, evidence);
1284 catch (Exception ex2)
1291 if (codeGroupStackFrame.policy ==
null)
1299 throw new PolicyException(Environment.GetResourceString(
"Policy_MultipleExclusive"));
1302 arrayList.
Add(codeGroupStackFrame);
1307 arrayList.
Add(codeGroupStackFrame);
1317 private static string GenerateFriendlyName(
string className,
Hashtable classes)
1321 return (
string)classes[className];
1324 if (type !=
null && !type.IsVisible)
1334 classes.
Add(className, type.Name);
1339 classes.
Add(className, type.FullName);
1340 return type.FullName;
1342 classes.
Add(className, type.AssemblyQualifiedName);
1343 return type.AssemblyQualifiedName;
1346 private SecurityElement NormalizeClassDeep(SecurityElement elem,
Hashtable classes)
1348 NormalizeClass(elem, classes);
1349 if (elem.InternalChildren !=
null && elem.InternalChildren.Count > 0)
1351 IEnumerator enumerator = elem.Children.GetEnumerator();
1354 NormalizeClassDeep((SecurityElement)enumerator.
Current, classes);
1360 private SecurityElement NormalizeClass(SecurityElement elem,
Hashtable classes)
1362 if (elem.m_lAttributes ==
null || elem.m_lAttributes.Count == 0)
1366 int count = elem.m_lAttributes.Count;
1367 for (
int i = 0; i < count; i += 2)
1369 string text = (string)elem.m_lAttributes[i];
1370 if (text.Equals(
"class"))
1372 string className = (string)elem.m_lAttributes[i + 1];
1373 elem.m_lAttributes[i + 1] = GenerateFriendlyName(className, classes);
1380 private SecurityElement UnnormalizeClassDeep(SecurityElement elem,
Hashtable classes)
1382 UnnormalizeClass(elem, classes);
1383 if (elem.InternalChildren !=
null && elem.InternalChildren.Count > 0)
1385 IEnumerator enumerator = elem.Children.GetEnumerator();
1388 UnnormalizeClassDeep((SecurityElement)enumerator.
Current, classes);
1394 private SecurityElement UnnormalizeClass(SecurityElement elem,
Hashtable classes)
1396 if (classes ==
null || elem.m_lAttributes ==
null || elem.m_lAttributes.Count == 0)
1400 int count = elem.m_lAttributes.Count;
1401 for (
int i = 0; i < count; i += 2)
1403 string text = (string)elem.m_lAttributes[i];
1404 if (text.Equals(
"class"))
1406 string key = (string)elem.m_lAttributes[i + 1];
1407 string text2 = (
string)classes[key];
1410 elem.m_lAttributes[i + 1] = text2;
Represents a character encoding.To browse the .NET Framework source code for this type,...
abstract CodeGroup ResolveMatchingCodeGroups(Evidence evidence)
When overridden in a derived class, resolves matching code groups.
bool IsUnrestricted()
Determines whether the T:System.Security.PermissionSet is Unrestricted.
void AddFullTrustAssembly(StrongName sn)
Adds a T:System.Security.Policy.StrongNameMembershipCondition corresponding to the specified T:System...
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
FileIOPermissionAccess
Specifies the type of file access requested.
unsafe string GetString(byte *bytes, int byteCount)
When overridden in a derived class, decodes a specified number of bytes starting at a specified addre...
virtual void Add(object key, object value)
Adds an element with the specified key and value into the T:System.Collections.Hashtable.
bool MoveNext()
Advances the enumerator to the next element of the collection.
IEnumerator GetEnumerator()
Returns an enumerator for the permissions of the set.
Provides the strong name of a code assembly as evidence for policy evaluation. This class cannot be i...
SecurityZone
Defines the integer values corresponding to security zones used by security policy.
void FromXml(SecurityElement e)
Reconstructs a security object with a given state from an XML encoding.
string StoreLocation
Gets the path where the policy file is stored.
PolicyLevelType
Specifies the type of a managed code policy level.
virtual void RemoveAt(int index)
Removes the element at the specified index of the T:System.Collections.ArrayList.
object Key
Gets the key of the current dictionary entry.
FileMode
Specifies how the operating system should open a file.
No initialization action.
Represents a non-generic collection of objects that can be individually accessed by index.
Represents the security policy levels for the common language runtime. This class cannot be inherited...
void FromXml(SecurityElement e)
Reconstructs a security object with a given state from an XML encoding.
virtual int Count
Gets the number of elements actually contained in the T:System.Collections.ArrayList.
PolicyStatementAttribute
Defines special attribute flags for security policy on code groups.
StrongNamePublicKeyBlob PublicKey
Gets the T:System.Security.Permissions.StrongNamePublicKeyBlob of the current T:System....
SecurityElement SearchForChildByTag(string tag)
Finds a child by its tag name.
Version Version
Gets the T:System.Version of the current T:System.Security.Policy.StrongName.
IPermission SetPermission(IPermission perm)
Sets a permission to the T:System.Security.PermissionSet, replacing any existing permission of the sa...
string Name
Gets or sets the name of the current named permission set.
Determines whether an assembly belongs to a code group by testing its strong name....
PolicyLevelType Type
Gets the type of the policy level.
NamedPermissionSet RemoveNamedPermissionSet(NamedPermissionSet permSet)
Removes the specified T:System.Security.NamedPermissionSet from the current policy level.
override int Read([In] [Out] byte[] array, int offset, int count)
Reads a block of bytes from the stream and writes the data in a given buffer.
virtual bool ContainsKey(object key)
Determines whether the T:System.Collections.Hashtable contains a specific key.
Describes the source and destination of a given serialized stream, and provides an additional caller-...
string Tag
Gets or sets the tag name of an XML element.
NamedPermissionSet ChangeNamedPermissionSet(string name, PermissionSet pSet)
Replaces a T:System.Security.NamedPermissionSet in the current policy level with the specified T:Syst...
Represents the statement of a T:System.Security.Policy.CodeGroup describing the permissions and other...
Defines a permission set that has a name and description associated with it. This class cannot be inh...
void AddChild(SecurityElement child)
Adds a child element to the XML element.
string Label
Gets a descriptive label for the policy level.
SecurityElement ToXml()
Creates an XML encoding of the security object and its current state.
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
virtual void Close()
Closes the current stream and releases any resources (such as sockets and file handles) associated wi...
IList Children
Gets or sets an ordered list of the child code groups of a code group.
Represents a collection that can contain many different types of permissions.
void FromXml(SecurityElement e)
Reconstructs a security object with a specified state from an XML encoding.
Represents the XML object model for encoding security objects. This class cannot be inherited.
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
Represents a collection of key/value pairs that are organized based on the hash code of the key....
Provides a T:System.IO.Stream for a file, supporting both synchronous and asynchronous read and write...
object Current
Gets the element in the collection at the current position of the enumerator.
Represents the abstract base class from which all implementations of code groups must derive.
void Reset()
Returns the current policy level to the default state.
Represents type declarations: class types, interface types, array types, value types,...
override PermissionSet Copy()
Creates a permission set copy from a named permission set.
CodeGroup RootCodeGroup
Gets or sets the root code group for the policy level.
virtual void RemoveRange(int index, int count)
Removes a range of elements from the T:System.Collections.ArrayList.
IEnumerator GetEnumerator()
Returns an enumerator that iterates through a collection.
virtual bool ContainsValue(object value)
Determines whether the T:System.Collections.Hashtable contains a specific value.
Defines methods implemented by permission types.
virtual int Add(object value)
Adds an object to the end of the T:System.Collections.ArrayList.
virtual string? PermissionSetName
Gets the name of the named permission set for the code group.
static PolicyLevel CreateAppDomainLevel()
Creates a new policy level for use at the application domain policy level.
The exception that is thrown when one of the arguments provided to a method is not valid.
override long Length
Gets the length in bytes of the stream.
NamedPermissionSet RemoveNamedPermissionSet(string name)
Removes the T:System.Security.NamedPermissionSet with the specified name from the current policy leve...
SecurityElement ToXml()
Creates an XML encoding of the security object and its current state.
void RemoveFullTrustAssembly(StrongName sn)
Removes an assembly with the specified T:System.Security.Policy.StrongName from the list of assemblie...
FileAccess
Defines constants for read, write, or read/write access to a file.
string Description
Gets or sets the text description of the current named permission set.
Defines the set of information that constitutes input to security policy decisions....
object Value
Gets the value of the current dictionary entry.
void AddAttribute(string name, string value)
Adds a name/value attribute to an XML element.
IList NamedPermissionSets
Gets a list of named permission sets defined for the policy level.
Specifies that the class can be serialized.
void AddNamedPermissionSet(NamedPermissionSet permSet)
Adds a T:System.Security.NamedPermissionSet to the current policy level.
Enumerates the elements of a nongeneric dictionary.
ArrayList Children
Gets or sets the array of child elements of the XML element.
static Encoding UTF8
Gets an encoding for the UTF-8 format.
virtual IEnumerator GetEnumerator()
Returns an enumerator for the entire T:System.Collections.ArrayList.
Provides static methods for the creation, copying, deletion, moving, and opening of a single file,...
static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Gets the T:System.Type with the specified name, specifying whether to throw an exception if the type ...
IList FullTrustAssemblies
Gets a list of T:System.Security.Policy.StrongNameMembershipCondition objects used to determine wheth...
NamedPermissionSet GetNamedPermissionSet(string name)
Returns the T:System.Security.NamedPermissionSet in the current policy level with the specified name.
SecurityPermissionFlag
Specifies access flags for the security permission object.
void RemoveFullTrustAssembly(StrongNameMembershipCondition snMC)
Removes an assembly with the specified T:System.Security.Policy.StrongNameMembershipCondition from th...
void Recover()
Replaces the configuration file for this T:System.Security.Policy.PolicyLevel with the last backup (r...
Provides atomic operations for variables that are shared by multiple threads.
The exception that is thrown when policy forbids code to run.
CodeGroup ResolveMatchingCodeGroups(Evidence evidence)
Resolves policy at the policy level and returns the root of a code group tree that matches the eviden...
Supports a simple iteration over a non-generic collection.
Performs operations on T:System.String instances that contain file or directory path information....
PolicyStatement Resolve(Evidence evidence)
Resolves policy based on evidence for the policy level, and returns the resulting T:System....
string Name
Gets the simple name of the current T:System.Security.Policy.StrongName.
Represents the public key information (called a blob) for a strong name. This class cannot be inherit...
void AddFullTrustAssembly(StrongNameMembershipCondition snMC)
Adds the specified T:System.Security.Policy.StrongNameMembershipCondition to the list of T:System....
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...