mscorlib(4.0.0.0) API with additions
PolicyLevel.cs
1 using System.Collections;
2 using System.IO;
6 using System.Security.Util;
7 using System.Text;
8 using System.Threading;
9 
10 namespace System.Security.Policy
11 {
13  [Serializable]
14  [ComVisible(true)]
15  public sealed class PolicyLevel
16  {
17  private ArrayList m_fullTrustAssemblies;
18 
19  private ArrayList m_namedPermissionSets;
20 
21  private CodeGroup m_rootCodeGroup;
22 
23  private string m_label;
24 
25  [OptionalField(VersionAdded = 2)]
26  private PolicyLevelType m_type;
27 
28  private ConfigId m_configId;
29 
30  private bool m_useDefaultCodeGroupsOnReset;
31 
32  private bool m_generateQuickCacheOnLoad;
33 
34  private bool m_caching;
35 
36  private bool m_throwOnLoadError;
37 
38  private Encoding m_encoding;
39 
40  private bool m_loaded;
41 
42  private SecurityElement m_permSetElement;
43 
44  private string m_path;
45 
46  private static object s_InternalSyncObject;
47 
48  private static readonly string[] s_reservedNamedPermissionSets;
49 
50  private static string[] EcmaFullTrustAssemblies;
51 
52  private static string[] MicrosoftFullTrustAssemblies;
53 
54  private static object InternalSyncObject
55  {
56  get
57  {
58  if (s_InternalSyncObject == null)
59  {
60  object value = new object();
61  Interlocked.CompareExchange(ref s_InternalSyncObject, value, null);
62  }
63  return s_InternalSyncObject;
64  }
65  }
66 
69  public string Label
70  {
71  get
72  {
73  if (m_label == null)
74  {
75  m_label = DeriveLabelFromType();
76  }
77  return m_label;
78  }
79  }
80 
83  [ComVisible(false)]
84  public PolicyLevelType Type
85  {
86  get
87  {
88  return m_type;
89  }
90  }
91 
92  internal ConfigId ConfigId => m_configId;
93 
94  internal string Path => m_path;
95 
98  public string StoreLocation
99  {
100  [SecuritySafeCritical]
101  [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlPolicy)]
102  get
103  {
104  return GetLocationFromType(m_type);
105  }
106  }
107 
111  public CodeGroup RootCodeGroup
112  {
113  [SecuritySafeCritical]
114  get
115  {
116  CheckLoaded();
117  return m_rootCodeGroup;
118  }
119  [SecuritySafeCritical]
120  set
121  {
122  if (value == null)
123  {
124  throw new ArgumentNullException("RootCodeGroup");
125  }
126  CheckLoaded();
127  m_rootCodeGroup = value.Copy();
128  }
129  }
130 
134  {
135  [SecuritySafeCritical]
136  get
137  {
138  CheckLoaded();
139  LoadAllPermissionSets();
140  ArrayList arrayList = new ArrayList(m_namedPermissionSets.Count);
141  IEnumerator enumerator = m_namedPermissionSets.GetEnumerator();
142  while (enumerator.MoveNext())
143  {
144  arrayList.Add(((NamedPermissionSet)enumerator.Current).Copy());
145  }
146  return arrayList;
147  }
148  }
149 
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.")]
154  {
155  [SecuritySafeCritical]
156  get
157  {
158  CheckLoaded();
159  return new ArrayList(m_fullTrustAssemblies);
160  }
161  }
162 
163  static PolicyLevel()
164  {
165  s_reservedNamedPermissionSets = new string[7]
166  {
167  "FullTrust",
168  "Nothing",
169  "Execution",
170  "SkipVerification",
171  "Internet",
172  "LocalIntranet",
173  "Everything"
174  };
175  EcmaFullTrustAssemblies = new string[9]
176  {
177  "mscorlib.resources",
178  "System",
179  "System.resources",
180  "System.Xml",
181  "System.Xml.resources",
182  "System.Windows.Forms",
183  "System.Windows.Forms.resources",
184  "System.Data",
185  "System.Data.resources"
186  };
187  MicrosoftFullTrustAssemblies = new string[12]
188  {
189  "System.Security",
190  "System.Security.resources",
191  "System.Drawing",
192  "System.Drawing.resources",
193  "System.Messaging",
194  "System.Messaging.resources",
195  "System.ServiceProcess",
196  "System.ServiceProcess.resources",
197  "System.DirectoryServices",
198  "System.DirectoryServices.resources",
199  "System.Deployment",
200  "System.Deployment.resources"
201  };
202  }
203 
204  [OnDeserialized]
205  private void OnDeserialized(StreamingContext ctx)
206  {
207  if (m_label != null)
208  {
209  DeriveTypeFromLabel();
210  }
211  }
212 
213  private void DeriveTypeFromLabel()
214  {
215  if (m_label.Equals(Environment.GetResourceString("Policy_PL_User")))
216  {
217  m_type = PolicyLevelType.User;
218  return;
219  }
220  if (m_label.Equals(Environment.GetResourceString("Policy_PL_Machine")))
221  {
222  m_type = PolicyLevelType.Machine;
223  return;
224  }
225  if (m_label.Equals(Environment.GetResourceString("Policy_PL_Enterprise")))
226  {
227  m_type = PolicyLevelType.Enterprise;
228  return;
229  }
230  if (m_label.Equals(Environment.GetResourceString("Policy_PL_AppDomain")))
231  {
232  m_type = PolicyLevelType.AppDomain;
233  return;
234  }
235  throw new ArgumentException(Environment.GetResourceString("Policy_Default"));
236  }
237 
238  private string DeriveLabelFromType()
239  {
240  switch (m_type)
241  {
242  case PolicyLevelType.User:
243  return Environment.GetResourceString("Policy_PL_User");
244  case PolicyLevelType.Machine:
245  return Environment.GetResourceString("Policy_PL_Machine");
246  case PolicyLevelType.Enterprise:
247  return Environment.GetResourceString("Policy_PL_Enterprise");
248  case PolicyLevelType.AppDomain:
249  return Environment.GetResourceString("Policy_PL_AppDomain");
250  default:
251  throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)m_type));
252  }
253  }
254 
255  private PolicyLevel()
256  {
257  }
258 
259  [SecurityCritical]
260  internal PolicyLevel(PolicyLevelType type)
261  : this(type, GetLocationFromType(type))
262  {
263  }
264 
265  internal PolicyLevel(PolicyLevelType type, string path)
266  : this(type, path, ConfigId.None)
267  {
268  }
269 
270  internal PolicyLevel(PolicyLevelType type, string path, ConfigId configId)
271  {
272  m_type = type;
273  m_path = path;
274  m_loaded = (path == null);
275  if (m_path == null)
276  {
277  m_rootCodeGroup = CreateDefaultAllGroup();
278  SetFactoryPermissionSets();
279  SetDefaultFullTrustAssemblies();
280  }
281  m_configId = configId;
282  }
283 
284  [SecurityCritical]
285  internal static string GetLocationFromType(PolicyLevelType type)
286  {
287  switch (type)
288  {
289  case PolicyLevelType.User:
290  return Config.UserDirectory + "security.config";
291  case PolicyLevelType.Machine:
292  return Config.MachineDirectory + "security.config";
293  case PolicyLevelType.Enterprise:
294  return Config.MachineDirectory + "enterprisesec.config";
295  default:
296  return null;
297  }
298  }
299 
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.")]
305  {
306  return new PolicyLevel(PolicyLevelType.AppDomain);
307  }
308 
315  {
316  if (evidence == null)
317  {
318  throw new ArgumentNullException("evidence");
319  }
320  return RootCodeGroup.ResolveMatchingCodeGroups(evidence);
321  }
322 
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.")]
329  {
330  if (sn == null)
331  {
332  throw new ArgumentNullException("sn");
333  }
335  }
336 
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.")]
344  {
345  if (snMC == null)
346  {
347  throw new ArgumentNullException("snMC");
348  }
349  CheckLoaded();
350  IEnumerator enumerator = m_fullTrustAssemblies.GetEnumerator();
351  while (enumerator.MoveNext())
352  {
353  if (((StrongNameMembershipCondition)enumerator.Current).Equals(snMC))
354  {
355  throw new ArgumentException(Environment.GetResourceString("Argument_AssemblyAlreadyFullTrust"));
356  }
357  }
358  lock (m_fullTrustAssemblies)
359  {
360  m_fullTrustAssemblies.Add(snMC);
361  }
362  }
363 
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.")]
370  {
371  if (sn == null)
372  {
373  throw new ArgumentNullException("assembly");
374  }
376  }
377 
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.")]
385  {
386  if (snMC == null)
387  {
388  throw new ArgumentNullException("snMC");
389  }
390  CheckLoaded();
391  object obj = null;
392  IEnumerator enumerator = m_fullTrustAssemblies.GetEnumerator();
393  while (enumerator.MoveNext())
394  {
395  if (((StrongNameMembershipCondition)enumerator.Current).Equals(snMC))
396  {
397  obj = enumerator.Current;
398  break;
399  }
400  }
401  if (obj == null)
402  {
403  throw new ArgumentException(Environment.GetResourceString("Argument_AssemblyNotFullTrust"));
404  }
405  lock (m_fullTrustAssemblies)
406  {
407  m_fullTrustAssemblies.Remove(obj);
408  }
409  }
410 
415  [SecuritySafeCritical]
417  {
418  if (permSet == null)
419  {
420  throw new ArgumentNullException("permSet");
421  }
422  CheckLoaded();
423  LoadAllPermissionSets();
424  lock (this)
425  {
426  IEnumerator enumerator = m_namedPermissionSets.GetEnumerator();
427  while (enumerator.MoveNext())
428  {
429  if (((NamedPermissionSet)enumerator.Current).Name.Equals(permSet.Name))
430  {
431  throw new ArgumentException(Environment.GetResourceString("Argument_DuplicateName"));
432  }
433  }
434  NamedPermissionSet namedPermissionSet = (NamedPermissionSet)permSet.Copy();
435  namedPermissionSet.IgnoreTypeLoadFailures = true;
436  m_namedPermissionSets.Add(namedPermissionSet);
437  }
438  }
439 
446  {
447  if (permSet == null)
448  {
449  throw new ArgumentNullException("permSet");
450  }
451  return RemoveNamedPermissionSet(permSet.Name);
452  }
453 
459  [SecuritySafeCritical]
461  {
462  if (name == null)
463  {
464  throw new ArgumentNullException("name");
465  }
466  CheckLoaded();
467  LoadAllPermissionSets();
468  int num = -1;
469  for (int i = 0; i < s_reservedNamedPermissionSets.Length; i++)
470  {
471  if (s_reservedNamedPermissionSets[i].Equals(name))
472  {
473  throw new ArgumentException(Environment.GetResourceString("Argument_ReservedNPMS", name));
474  }
475  }
476  ArrayList namedPermissionSets = m_namedPermissionSets;
477  for (int j = 0; j < namedPermissionSets.Count; j++)
478  {
479  if (((NamedPermissionSet)namedPermissionSets[j]).Name.Equals(name))
480  {
481  num = j;
482  break;
483  }
484  }
485  if (num == -1)
486  {
487  throw new ArgumentException(Environment.GetResourceString("Argument_NoNPMS"));
488  }
489  ArrayList arrayList = new ArrayList();
490  arrayList.Add(m_rootCodeGroup);
491  for (int k = 0; k < arrayList.Count; k++)
492  {
493  CodeGroup codeGroup = (CodeGroup)arrayList[k];
494  if (codeGroup.PermissionSetName != null && codeGroup.PermissionSetName.Equals(name))
495  {
496  throw new ArgumentException(Environment.GetResourceString("Argument_NPMSInUse", name));
497  }
498  IEnumerator enumerator = codeGroup.Children.GetEnumerator();
499  if (enumerator != null)
500  {
501  while (enumerator.MoveNext())
502  {
503  arrayList.Add(enumerator.Current);
504  }
505  }
506  }
507  NamedPermissionSet result = (NamedPermissionSet)namedPermissionSets[num];
508  namedPermissionSets.RemoveAt(num);
509  return result;
510  }
511 
518  [SecuritySafeCritical]
520  {
521  if (name == null)
522  {
523  throw new ArgumentNullException("name");
524  }
525  if (pSet == null)
526  {
527  throw new ArgumentNullException("pSet");
528  }
529  for (int i = 0; i < s_reservedNamedPermissionSets.Length; i++)
530  {
531  if (s_reservedNamedPermissionSets[i].Equals(name))
532  {
533  throw new ArgumentException(Environment.GetResourceString("Argument_ReservedNPMS", name));
534  }
535  }
536  NamedPermissionSet namedPermissionSetInternal = GetNamedPermissionSetInternal(name);
537  if (namedPermissionSetInternal == null)
538  {
539  throw new ArgumentException(Environment.GetResourceString("Argument_NoNPMS"));
540  }
541  NamedPermissionSet result = (NamedPermissionSet)namedPermissionSetInternal.Copy();
542  namedPermissionSetInternal.Reset();
543  namedPermissionSetInternal.SetUnrestricted(pSet.IsUnrestricted());
544  IEnumerator enumerator = pSet.GetEnumerator();
545  while (enumerator.MoveNext())
546  {
547  namedPermissionSetInternal.SetPermission(((IPermission)enumerator.Current).Copy());
548  }
549  if (pSet is NamedPermissionSet)
550  {
551  namedPermissionSetInternal.Description = ((NamedPermissionSet)pSet).Description;
552  }
553  return result;
554  }
555 
560  [SecuritySafeCritical]
562  {
563  if (name == null)
564  {
565  throw new ArgumentNullException("name");
566  }
567  NamedPermissionSet namedPermissionSetInternal = GetNamedPermissionSetInternal(name);
568  if (namedPermissionSetInternal != null)
569  {
570  return new NamedPermissionSet(namedPermissionSetInternal);
571  }
572  return null;
573  }
574 
577  [SecuritySafeCritical]
578  public void Recover()
579  {
580  if (m_configId == ConfigId.None)
581  {
582  throw new PolicyException(Environment.GetResourceString("Policy_RecoverNotFileBased"));
583  }
584  lock (this)
585  {
586  if (!Config.RecoverData(m_configId))
587  {
588  throw new PolicyException(Environment.GetResourceString("Policy_RecoverNoConfigFile"));
589  }
590  m_loaded = false;
591  m_rootCodeGroup = null;
592  m_namedPermissionSets = null;
593  m_fullTrustAssemblies = new ArrayList();
594  }
595  }
596 
598  [SecuritySafeCritical]
599  public void Reset()
600  {
601  SetDefault();
602  }
603 
609  [SecuritySafeCritical]
611  {
612  return Resolve(evidence, 0, null);
613  }
614 
617  [SecuritySafeCritical]
619  {
620  CheckLoaded();
621  LoadAllPermissionSets();
622  SecurityElement securityElement = new SecurityElement("PolicyLevel");
623  securityElement.AddAttribute("version", "1");
624  Hashtable hashtable = new Hashtable();
625  lock (this)
626  {
627  SecurityElement securityElement2 = new SecurityElement("NamedPermissionSets");
628  IEnumerator enumerator = m_namedPermissionSets.GetEnumerator();
629  while (enumerator.MoveNext())
630  {
631  securityElement2.AddChild(NormalizeClassDeep(((NamedPermissionSet)enumerator.Current).ToXml(), hashtable));
632  }
633  SecurityElement child = NormalizeClassDeep(m_rootCodeGroup.ToXml(this), hashtable);
634  SecurityElement securityElement3 = new SecurityElement("FullTrustAssemblies");
635  enumerator = m_fullTrustAssemblies.GetEnumerator();
636  while (enumerator.MoveNext())
637  {
638  securityElement3.AddChild(NormalizeClassDeep(((StrongNameMembershipCondition)enumerator.Current).ToXml(), hashtable));
639  }
640  SecurityElement securityElement4 = new SecurityElement("SecurityClasses");
641  IDictionaryEnumerator enumerator2 = hashtable.GetEnumerator();
642  while (enumerator2.MoveNext())
643  {
644  SecurityElement securityElement5 = new SecurityElement("SecurityClass");
645  securityElement5.AddAttribute("Name", (string)enumerator2.Value);
646  securityElement5.AddAttribute("Description", (string)enumerator2.Key);
647  securityElement4.AddChild(securityElement5);
648  }
649  securityElement.AddChild(securityElement4);
650  securityElement.AddChild(securityElement2);
651  securityElement.AddChild(child);
652  securityElement.AddChild(securityElement3);
653  return securityElement;
654  }
655  }
656 
661  public void FromXml(SecurityElement e)
662  {
663  if (e == null)
664  {
665  throw new ArgumentNullException("e");
666  }
667  lock (this)
668  {
669  ArrayList arrayList = new ArrayList();
670  SecurityElement securityElement = e.SearchForChildByTag("SecurityClasses");
671  Hashtable hashtable;
672  if (securityElement != null)
673  {
674  hashtable = new Hashtable();
675  IEnumerator enumerator = securityElement.Children.GetEnumerator();
676  while (enumerator.MoveNext())
677  {
678  SecurityElement securityElement2 = (SecurityElement)enumerator.Current;
679  if (securityElement2.Tag.Equals("SecurityClass"))
680  {
681  string text = securityElement2.Attribute("Name");
682  string text2 = securityElement2.Attribute("Description");
683  if (text != null && text2 != null)
684  {
685  hashtable.Add(text, text2);
686  }
687  }
688  }
689  }
690  else
691  {
692  hashtable = null;
693  }
694  SecurityElement securityElement3 = e.SearchForChildByTag("FullTrustAssemblies");
695  if (securityElement3 != null && securityElement3.InternalChildren != null)
696  {
697  string assemblyQualifiedName = typeof(StrongNameMembershipCondition).AssemblyQualifiedName;
698  IEnumerator enumerator2 = securityElement3.Children.GetEnumerator();
699  while (enumerator2.MoveNext())
700  {
701  StrongNameMembershipCondition strongNameMembershipCondition = new StrongNameMembershipCondition();
702  strongNameMembershipCondition.FromXml((SecurityElement)enumerator2.Current);
703  arrayList.Add(strongNameMembershipCondition);
704  }
705  }
706  m_fullTrustAssemblies = arrayList;
707  ArrayList arrayList2 = new ArrayList();
708  SecurityElement securityElement4 = e.SearchForChildByTag("NamedPermissionSets");
709  SecurityElement securityElement5 = null;
710  if (securityElement4 != null && securityElement4.InternalChildren != null)
711  {
712  securityElement5 = UnnormalizeClassDeep(securityElement4, hashtable);
713  string[] array = s_reservedNamedPermissionSets;
714  foreach (string name in array)
715  {
716  FindElement(securityElement5, name);
717  }
718  }
719  if (securityElement5 == null)
720  {
721  securityElement5 = new SecurityElement("NamedPermissionSets");
722  }
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);
730  foreach (PermissionSet item in arrayList2)
731  {
732  item.IgnoreTypeLoadFailures = true;
733  }
734  m_namedPermissionSets = arrayList2;
735  m_permSetElement = securityElement5;
736  SecurityElement securityElement6 = e.SearchForChildByTag("CodeGroup");
737  if (securityElement6 == null)
738  {
739  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXMLElement", "CodeGroup", GetType().FullName));
740  }
741  CodeGroup codeGroup = XMLUtil.CreateCodeGroup(UnnormalizeClassDeep(securityElement6, hashtable));
742  if (codeGroup == null)
743  {
744  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXMLElement", "CodeGroup", GetType().FullName));
745  }
746  codeGroup.FromXml(securityElement6, this);
747  m_rootCodeGroup = codeGroup;
748  }
749  }
750 
751  [SecurityCritical]
752  internal static PermissionSet GetBuiltInSet(string name)
753  {
754  if (string.IsNullOrEmpty(name))
755  {
756  return null;
757  }
758  if (name.Equals("FullTrust"))
759  {
760  return BuiltInPermissionSets.FullTrust;
761  }
762  if (name.Equals("Nothing"))
763  {
764  return BuiltInPermissionSets.Nothing;
765  }
766  if (name.Equals("Execution"))
767  {
768  return BuiltInPermissionSets.Execution;
769  }
770  if (name.Equals("SkipVerification"))
771  {
772  return BuiltInPermissionSets.SkipVerification;
773  }
774  if (name.Equals("Internet"))
775  {
776  return BuiltInPermissionSets.Internet;
777  }
778  if (name.Equals("LocalIntranet"))
779  {
780  return BuiltInPermissionSets.LocalIntranet;
781  }
782  return null;
783  }
784 
785  [SecurityCritical]
786  internal NamedPermissionSet GetNamedPermissionSetInternal(string name)
787  {
788  CheckLoaded();
789  lock (InternalSyncObject)
790  {
791  foreach (NamedPermissionSet namedPermissionSet3 in m_namedPermissionSets)
792  {
793  if (namedPermissionSet3.Name.Equals(name))
794  {
795  return namedPermissionSet3;
796  }
797  }
798  if (m_permSetElement != null)
799  {
800  SecurityElement securityElement = FindElement(m_permSetElement, name);
801  if (securityElement != null)
802  {
803  NamedPermissionSet namedPermissionSet2 = new NamedPermissionSet();
804  namedPermissionSet2.Name = name;
805  m_namedPermissionSets.Add(namedPermissionSet2);
806  try
807  {
808  namedPermissionSet2.FromXml(securityElement, allowInternalOnly: false, ignoreTypeLoadFailures: true);
809  }
810  catch
811  {
812  m_namedPermissionSets.Remove(namedPermissionSet2);
813  return null;
814  }
815  if (namedPermissionSet2.Name != null)
816  {
817  return namedPermissionSet2;
818  }
819  m_namedPermissionSets.Remove(namedPermissionSet2);
820  }
821  }
822  }
823  return null;
824  }
825 
826  [SecurityCritical]
827  internal PolicyStatement Resolve(Evidence evidence, int count, byte[] serializedEvidence)
828  {
829  if (evidence == null)
830  {
831  throw new ArgumentNullException("evidence");
832  }
833  PolicyStatement policyStatement = null;
834  if (serializedEvidence != null)
835  {
836  policyStatement = CheckCache(count, serializedEvidence);
837  }
838  if (policyStatement == null)
839  {
840  CheckLoaded();
841  bool allConst;
842  if (m_fullTrustAssemblies != null && IsFullTrustAssembly(m_fullTrustAssemblies, evidence))
843  {
844  policyStatement = new PolicyStatement(new PermissionSet(fUnrestricted: true), PolicyStatementAttribute.Nothing);
845  allConst = true;
846  }
847  else
848  {
849  ArrayList arrayList = GenericResolve(evidence, out allConst);
850  policyStatement = new PolicyStatement();
851  policyStatement.PermissionSet = null;
852  IEnumerator enumerator = arrayList.GetEnumerator();
853  while (enumerator.MoveNext())
854  {
855  PolicyStatement policy = ((CodeGroupStackFrame)enumerator.Current).policy;
856  if (policy != null)
857  {
858  policyStatement.GetPermissionSetNoCopy().InplaceUnion(policy.GetPermissionSetNoCopy());
859  policyStatement.Attributes |= policy.Attributes;
860  if (policy.HasDependentEvidence)
861  {
862  foreach (IDelayEvaluatedEvidence item in policy.DependentEvidence)
863  {
864  item.MarkUsed();
865  }
866  }
867  }
868  }
869  }
870  if (allConst)
871  {
872  Cache(count, evidence.RawSerialize(), policyStatement);
873  }
874  }
875  return policyStatement;
876  }
877 
878  [SecurityCritical]
879  private void CheckLoaded()
880  {
881  if (!m_loaded)
882  {
883  lock (InternalSyncObject)
884  {
885  if (!m_loaded)
886  {
887  LoadPolicyLevel();
888  }
889  }
890  }
891  }
892 
893  private static byte[] ReadFile(string fileName)
894  {
895  using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
896  {
897  int num = (int)fileStream.Length;
898  byte[] array = new byte[num];
899  num = fileStream.Read(array, 0, num);
900  fileStream.Close();
901  return array;
902  }
903  }
904 
905  [SecurityCritical]
906  private void LoadPolicyLevel()
907  {
908  Exception ex = null;
909  CodeAccessPermission.Assert(allPossible: true);
910  if (File.InternalExists(m_path))
911  {
912  Encoding uTF = Encoding.UTF8;
913  SecurityElement securityElement;
914  try
915  {
916  string @string = uTF.GetString(ReadFile(m_path));
917  securityElement = SecurityElement.FromString(@string);
918  }
919  catch (Exception ex2)
920  {
921  string text = string.IsNullOrEmpty(ex2.Message) ? ex2.GetType().AssemblyQualifiedName : ex2.Message;
922  ex = LoadError(Environment.GetResourceString("Error_SecurityPolicyFileParseEx", Label, text));
923  goto IL_01bd;
924  }
925  if (securityElement == null)
926  {
927  ex = LoadError(Environment.GetResourceString("Error_SecurityPolicyFileParse", Label));
928  }
929  else
930  {
931  SecurityElement securityElement2 = securityElement.SearchForChildByTag("mscorlib");
932  if (securityElement2 == null)
933  {
934  ex = LoadError(Environment.GetResourceString("Error_SecurityPolicyFileParse", Label));
935  }
936  else
937  {
938  SecurityElement securityElement3 = securityElement2.SearchForChildByTag("security");
939  if (securityElement3 == null)
940  {
941  ex = LoadError(Environment.GetResourceString("Error_SecurityPolicyFileParse", Label));
942  }
943  else
944  {
945  SecurityElement securityElement4 = securityElement3.SearchForChildByTag("policy");
946  if (securityElement4 == null)
947  {
948  ex = LoadError(Environment.GetResourceString("Error_SecurityPolicyFileParse", Label));
949  }
950  else
951  {
952  SecurityElement securityElement5 = securityElement4.SearchForChildByTag("PolicyLevel");
953  if (securityElement5 != null)
954  {
955  try
956  {
957  FromXml(securityElement5);
958  }
959  catch (Exception)
960  {
961  ex = LoadError(Environment.GetResourceString("Error_SecurityPolicyFileParse", Label));
962  goto IL_01bd;
963  }
964  m_loaded = true;
965  return;
966  }
967  ex = LoadError(Environment.GetResourceString("Error_SecurityPolicyFileParse", Label));
968  }
969  }
970  }
971  }
972  }
973  goto IL_01bd;
974  IL_01bd:
975  SetDefault();
976  m_loaded = true;
977  if (ex != null)
978  {
979  throw ex;
980  }
981  }
982 
983  [SecurityCritical]
984  private Exception LoadError(string message)
985  {
986  if (m_type != 0 && m_type != PolicyLevelType.Machine && m_type != PolicyLevelType.Enterprise)
987  {
988  return new ArgumentException(message);
989  }
990  Config.WriteToEventLog(message);
991  return null;
992  }
993 
994  [SecurityCritical]
995  private void Cache(int count, byte[] serializedEvidence, PolicyStatement policy)
996  {
997  if (m_configId != 0 && serializedEvidence != null)
998  {
999  byte[] data = new SecurityDocument(policy.ToXml(null, useInternal: true)).m_data;
1000  Config.AddCacheEntry(m_configId, count, serializedEvidence, data);
1001  }
1002  }
1003 
1004  [SecurityCritical]
1005  private PolicyStatement CheckCache(int count, byte[] serializedEvidence)
1006  {
1007  if (m_configId == ConfigId.None)
1008  {
1009  return null;
1010  }
1011  if (serializedEvidence == null)
1012  {
1013  return null;
1014  }
1015  if (!Config.GetCacheEntry(m_configId, count, serializedEvidence, out byte[] data))
1016  {
1017  return null;
1018  }
1019  PolicyStatement policyStatement = new PolicyStatement();
1020  SecurityDocument doc = new SecurityDocument(data);
1021  policyStatement.FromXml(doc, 0, null, allowInternalOnly: true);
1022  return policyStatement;
1023  }
1024 
1025  [SecurityCritical]
1026  private static bool IsFullTrustAssembly(ArrayList fullTrustAssemblies, Evidence evidence)
1027  {
1028  if (fullTrustAssemblies.Count == 0)
1029  {
1030  return false;
1031  }
1032  if (evidence != null)
1033  {
1034  lock (fullTrustAssemblies)
1035  {
1036  IEnumerator enumerator = fullTrustAssemblies.GetEnumerator();
1037  while (enumerator.MoveNext())
1038  {
1039  StrongNameMembershipCondition strongNameMembershipCondition = (StrongNameMembershipCondition)enumerator.Current;
1040  if (strongNameMembershipCondition.Check(evidence))
1041  {
1042  if (Environment.GetCompatibilityFlag(CompatibilityFlag.FullTrustListAssembliesInGac))
1043  {
1044  if (new ZoneMembershipCondition().Check(evidence))
1045  {
1046  return true;
1047  }
1048  }
1049  else if (new GacMembershipCondition().Check(evidence))
1050  {
1051  return true;
1052  }
1053  }
1054  }
1055  }
1056  }
1057  return false;
1058  }
1059 
1060  private CodeGroup CreateDefaultAllGroup()
1061  {
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;
1067  }
1068 
1069  [SecurityCritical]
1070  private CodeGroup CreateDefaultMachinePolicy()
1071  {
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);
1086  blob = new StrongNamePublicKeyBlob("00000000000000000400000000000000");
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);
1101  CodeGroup codeGroup3 = new FileCodeGroup(new AllMembershipCondition(), FileIOPermissionAccess.Read | FileIOPermissionAccess.PathDiscovery);
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;
1130  }
1131 
1132  private static SecurityElement CreateCodeGroupElement(string codeGroupType, string permissionSetName, SecurityElement mshipElement)
1133  {
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;
1140  }
1141 
1142  private void SetDefaultFullTrustAssemblies()
1143  {
1144  m_fullTrustAssemblies = new ArrayList();
1145  StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob("00000000000000000400000000000000");
1146  for (int i = 0; i < EcmaFullTrustAssemblies.Length; i++)
1147  {
1148  StrongNameMembershipCondition value = new StrongNameMembershipCondition(blob, EcmaFullTrustAssemblies[i], new Version("4.0.0.0"));
1149  m_fullTrustAssemblies.Add(value);
1150  }
1151  StrongNamePublicKeyBlob blob2 = new StrongNamePublicKeyBlob("002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293");
1152  for (int j = 0; j < MicrosoftFullTrustAssemblies.Length; j++)
1153  {
1154  StrongNameMembershipCondition value2 = new StrongNameMembershipCondition(blob2, MicrosoftFullTrustAssemblies[j], new Version("4.0.0.0"));
1155  m_fullTrustAssemblies.Add(value2);
1156  }
1157  }
1158 
1159  [SecurityCritical]
1160  private void SetDefault()
1161  {
1162  lock (this)
1163  {
1164  string path = GetLocationFromType(m_type) + ".default";
1165  if (File.InternalExists(path))
1166  {
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;
1171  m_loaded = true;
1172  }
1173  else
1174  {
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();
1181  m_loaded = true;
1182  }
1183  }
1184  }
1185 
1186  private void SetFactoryPermissionSets()
1187  {
1188  lock (InternalSyncObject)
1189  {
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);
1198  }
1199  }
1200 
1201  private SecurityElement FindElement(SecurityElement element, string name)
1202  {
1203  IEnumerator enumerator = element.Children.GetEnumerator();
1204  while (enumerator.MoveNext())
1205  {
1206  SecurityElement securityElement = (SecurityElement)enumerator.Current;
1207  if (securityElement.Tag.Equals("PermissionSet"))
1208  {
1209  string text = securityElement.Attribute("Name");
1210  if (text != null && text.Equals(name))
1211  {
1212  element.InternalChildren.Remove(securityElement);
1213  return securityElement;
1214  }
1215  }
1216  }
1217  return null;
1218  }
1219 
1220  [SecurityCritical]
1221  private void LoadAllPermissionSets()
1222  {
1223  if (m_permSetElement != null && m_permSetElement.InternalChildren != null)
1224  {
1225  lock (InternalSyncObject)
1226  {
1227  while (m_permSetElement != null && m_permSetElement.InternalChildren.Count != 0)
1228  {
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"))
1232  {
1233  NamedPermissionSet namedPermissionSet = new NamedPermissionSet();
1234  namedPermissionSet.FromXmlNameOnly(securityElement);
1235  if (namedPermissionSet.Name != null)
1236  {
1237  m_namedPermissionSets.Add(namedPermissionSet);
1238  try
1239  {
1240  namedPermissionSet.FromXml(securityElement, allowInternalOnly: false, ignoreTypeLoadFailures: true);
1241  }
1242  catch
1243  {
1244  m_namedPermissionSets.Remove(namedPermissionSet);
1245  }
1246  }
1247  }
1248  }
1249  m_permSetElement = null;
1250  }
1251  }
1252  }
1253 
1254  [SecurityCritical]
1255  private ArrayList GenericResolve(Evidence evidence, out bool allConst)
1256  {
1257  CodeGroupStack codeGroupStack = new CodeGroupStack();
1258  CodeGroup rootCodeGroup = m_rootCodeGroup;
1259  if (rootCodeGroup == null)
1260  {
1261  throw new PolicyException(Environment.GetResourceString("Policy_NonFullTrustAssembly"));
1262  }
1263  CodeGroupStackFrame codeGroupStackFrame = new CodeGroupStackFrame();
1264  codeGroupStackFrame.current = rootCodeGroup;
1265  codeGroupStackFrame.parent = null;
1266  codeGroupStack.Push(codeGroupStackFrame);
1267  ArrayList arrayList = new ArrayList();
1268  bool flag = false;
1269  allConst = true;
1270  Exception ex = null;
1271  while (!codeGroupStack.IsEmpty())
1272  {
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))
1277  {
1278  allConst = false;
1279  }
1280  try
1281  {
1282  codeGroupStackFrame.policy = PolicyManager.ResolveCodeGroup(codeGroupStackFrame.current, evidence);
1283  }
1284  catch (Exception ex2)
1285  {
1286  if (ex == null)
1287  {
1288  ex = ex2;
1289  }
1290  }
1291  if (codeGroupStackFrame.policy == null)
1292  {
1293  continue;
1294  }
1295  if ((codeGroupStackFrame.policy.Attributes & PolicyStatementAttribute.Exclusive) != 0)
1296  {
1297  if (flag)
1298  {
1299  throw new PolicyException(Environment.GetResourceString("Policy_MultipleExclusive"));
1300  }
1301  arrayList.RemoveRange(0, arrayList.Count);
1302  arrayList.Add(codeGroupStackFrame);
1303  flag = true;
1304  }
1305  if (!flag)
1306  {
1307  arrayList.Add(codeGroupStackFrame);
1308  }
1309  }
1310  if (ex != null)
1311  {
1312  throw ex;
1313  }
1314  return arrayList;
1315  }
1316 
1317  private static string GenerateFriendlyName(string className, Hashtable classes)
1318  {
1319  if (classes.ContainsKey(className))
1320  {
1321  return (string)classes[className];
1322  }
1323  Type type = System.Type.GetType(className, throwOnError: false, ignoreCase: false);
1324  if (type != null && !type.IsVisible)
1325  {
1326  type = null;
1327  }
1328  if (type == null)
1329  {
1330  return className;
1331  }
1332  if (!classes.ContainsValue(type.Name))
1333  {
1334  classes.Add(className, type.Name);
1335  return type.Name;
1336  }
1337  if (!classes.ContainsValue(type.FullName))
1338  {
1339  classes.Add(className, type.FullName);
1340  return type.FullName;
1341  }
1342  classes.Add(className, type.AssemblyQualifiedName);
1343  return type.AssemblyQualifiedName;
1344  }
1345 
1346  private SecurityElement NormalizeClassDeep(SecurityElement elem, Hashtable classes)
1347  {
1348  NormalizeClass(elem, classes);
1349  if (elem.InternalChildren != null && elem.InternalChildren.Count > 0)
1350  {
1351  IEnumerator enumerator = elem.Children.GetEnumerator();
1352  while (enumerator.MoveNext())
1353  {
1354  NormalizeClassDeep((SecurityElement)enumerator.Current, classes);
1355  }
1356  }
1357  return elem;
1358  }
1359 
1360  private SecurityElement NormalizeClass(SecurityElement elem, Hashtable classes)
1361  {
1362  if (elem.m_lAttributes == null || elem.m_lAttributes.Count == 0)
1363  {
1364  return elem;
1365  }
1366  int count = elem.m_lAttributes.Count;
1367  for (int i = 0; i < count; i += 2)
1368  {
1369  string text = (string)elem.m_lAttributes[i];
1370  if (text.Equals("class"))
1371  {
1372  string className = (string)elem.m_lAttributes[i + 1];
1373  elem.m_lAttributes[i + 1] = GenerateFriendlyName(className, classes);
1374  break;
1375  }
1376  }
1377  return elem;
1378  }
1379 
1380  private SecurityElement UnnormalizeClassDeep(SecurityElement elem, Hashtable classes)
1381  {
1382  UnnormalizeClass(elem, classes);
1383  if (elem.InternalChildren != null && elem.InternalChildren.Count > 0)
1384  {
1385  IEnumerator enumerator = elem.Children.GetEnumerator();
1386  while (enumerator.MoveNext())
1387  {
1388  UnnormalizeClassDeep((SecurityElement)enumerator.Current, classes);
1389  }
1390  }
1391  return elem;
1392  }
1393 
1394  private SecurityElement UnnormalizeClass(SecurityElement elem, Hashtable classes)
1395  {
1396  if (classes == null || elem.m_lAttributes == null || elem.m_lAttributes.Count == 0)
1397  {
1398  return elem;
1399  }
1400  int count = elem.m_lAttributes.Count;
1401  for (int i = 0; i < count; i += 2)
1402  {
1403  string text = (string)elem.m_lAttributes[i];
1404  if (text.Equals("class"))
1405  {
1406  string key = (string)elem.m_lAttributes[i + 1];
1407  string text2 = (string)classes[key];
1408  if (text2 != null)
1409  {
1410  elem.m_lAttributes[i + 1] = text2;
1411  }
1412  break;
1413  }
1414  }
1415  return elem;
1416  }
1417  }
1418 }
Represents a character encoding.To browse the .NET Framework source code for this type,...
Definition: Encoding.cs:15
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...
Definition: PolicyLevel.cs:328
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...
Definition: Encoding.cs:1918
virtual void Add(object key, object value)
Adds an element with the specified key and value into the T:System.Collections.Hashtable.
Definition: Hashtable.cs:916
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...
Definition: StrongName.cs:12
SecurityZone
Defines the integer values corresponding to security zones used by security policy.
Definition: SecurityZone.cs:8
void FromXml(SecurityElement e)
Reconstructs a security object with a given state from an XML encoding.
Definition: PolicyLevel.cs:661
string StoreLocation
Gets the path where the policy file is stored.
Definition: PolicyLevel.cs:99
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.
Definition: ArrayList.cs:2847
object Key
Gets the key of the current dictionary entry.
FileMode
Specifies how the operating system should open a file.
Definition: FileMode.cs:8
Represents a non-generic collection of objects that can be individually accessed by index.
Definition: IList.cs:8
Represents the security policy levels for the common language runtime. This class cannot be inherited...
Definition: PolicyLevel.cs:15
void FromXml(SecurityElement e)
Reconstructs a security object with a given state from an XML encoding.
Definition: CodeGroup.cs:330
virtual int Count
Gets the number of elements actually contained in the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2255
Definition: __Canon.cs:3
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....
Definition: StrongName.cs:28
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.
Definition: StrongName.cs:36
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.
Definition: PolicyLevel.cs:85
NamedPermissionSet RemoveNamedPermissionSet(NamedPermissionSet permSet)
Removes the specified T:System.Security.NamedPermissionSet from the current policy level.
Definition: PolicyLevel.cs:445
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.
Definition: FileStream.cs:1222
virtual bool ContainsKey(object key)
Determines whether the T:System.Collections.Hashtable contains a specific key.
Definition: Hashtable.cs:983
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...
Definition: PolicyLevel.cs:519
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.
Definition: PolicyLevel.cs:70
SecurityElement ToXml()
Creates an XML encoding of the security object and its current state.
Definition: CodeGroup.cs:322
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
virtual void Close()
Closes the current stream and releases any resources (such as sockets and file handles) associated wi...
Definition: Stream.cs:855
IList Children
Gets or sets an ordered list of the child code groups of a code group.
Definition: CodeGroup.cs:32
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....
Definition: Hashtable.cs:17
Provides a T:System.IO.Stream for a file, supporting both synchronous and asynchronous read and write...
Definition: FileStream.cs:15
object Current
Gets the element in the collection at the current position of the enumerator.
Definition: IEnumerator.cs:15
Represents the abstract base class from which all implementations of code groups must derive.
Definition: CodeGroup.cs:11
void Reset()
Returns the current policy level to the default state.
Definition: PolicyLevel.cs:599
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
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.
Definition: PolicyLevel.cs:112
virtual void RemoveRange(int index, int count)
Removes a range of elements from the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2871
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.
Definition: Hashtable.cs:1017
Defines methods implemented by permission types.
Definition: IPermission.cs:7
virtual int Add(object value)
Adds an object to the end of the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2381
virtual string? PermissionSetName
Gets the name of the named permission set for the code group.
Definition: CodeGroup.cs:156
static PolicyLevel CreateAppDomainLevel()
Creates a new policy level for use at the application domain policy level.
Definition: PolicyLevel.cs:304
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.
Definition: FileStream.cs:126
NamedPermissionSet RemoveNamedPermissionSet(string name)
Removes the T:System.Security.NamedPermissionSet with the specified name from the current policy leve...
Definition: PolicyLevel.cs:460
SecurityElement ToXml()
Creates an XML encoding of the security object and its current state.
Definition: PolicyLevel.cs:618
void RemoveFullTrustAssembly(StrongName sn)
Removes an assembly with the specified T:System.Security.Policy.StrongName from the list of assemblie...
Definition: PolicyLevel.cs:369
FileAccess
Defines constants for read, write, or read/write access to a file.
Definition: FileAccess.cs:9
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....
Definition: Evidence.cs:17
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.
Definition: PolicyLevel.cs:134
Specifies that the class can be serialized.
void AddNamedPermissionSet(NamedPermissionSet permSet)
Adds a T:System.Security.NamedPermissionSet to the current policy level.
Definition: PolicyLevel.cs:416
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.
Definition: Encoding.cs:1023
virtual IEnumerator GetEnumerator()
Returns an enumerator for the entire T:System.Collections.ArrayList.
Definition: ArrayList.cs:2615
Provides static methods for the creation, copying, deletion, moving, and opening of a single file,...
Definition: File.cs:14
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 ...
Definition: Type.cs:853
IList FullTrustAssemblies
Gets a list of T:System.Security.Policy.StrongNameMembershipCondition objects used to determine wheth...
Definition: PolicyLevel.cs:154
NamedPermissionSet GetNamedPermissionSet(string name)
Returns the T:System.Security.NamedPermissionSet in the current policy level with the specified name.
Definition: PolicyLevel.cs:561
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...
Definition: PolicyLevel.cs:384
void Recover()
Replaces the configuration file for this T:System.Security.Policy.PolicyLevel with the last backup (r...
Definition: PolicyLevel.cs:578
Provides atomic operations for variables that are shared by multiple threads.
Definition: Interlocked.cs:10
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...
Definition: PolicyLevel.cs:314
Supports a simple iteration over a non-generic collection.
Definition: IEnumerator.cs:9
Performs operations on T:System.String instances that contain file or directory path information....
Definition: Path.cs:13
PolicyStatement Resolve(Evidence evidence)
Resolves policy based on evidence for the policy level, and returns the resulting T:System....
Definition: PolicyLevel.cs:610
string Name
Gets the simple name of the current T:System.Security.Policy.StrongName.
Definition: StrongName.cs:32
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....
Definition: PolicyLevel.cs:343
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...
Definition: ArrayList.cs:14