public void FromXml (SecurityElement e, PolicyLevel level) { MembershipConditionHelper.CheckSecurityElement (e, "e", version, version); if (!Boolean.TryParse (e.Attribute ("LookAtDir"), out _lookAtDir)) _lookAtDir = false; // PolicyLevel isn't used as there's no need to resolve NamedPermissionSet references }
public AppDomain CreateAppDomain( PolicyLevel policyLevel ) { var domain = AppDomain.CreateDomain( "medium", AppDomain.CurrentDomain.Evidence ); domain.SetAppDomainPolicy( policyLevel ); return domain; }
public SecurityElement ToXml( PolicyLevel level ) { SecurityElement root = new SecurityElement( "IMembershipCondition" ); System.Security.Util.XMLUtil.AddClassAttribute( root, this.GetType(), this.GetType().FullName ); root.AddAttribute( "version", "1" ); return root; }
public SecurityElement ToXml(PolicyLevel level) { SecurityElement element = new SecurityElement("IMembershipCondition"); XMLUtil.AddClassAttribute(element, base.GetType(), "System.Security.Policy.AllMembershipCondition"); element.AddAttribute("version", "1"); return element; }
public void FromXml( SecurityElement e, PolicyLevel level ) { if (e == null) throw new ArgumentNullException("e"); if (!e.Tag.Equals( "IMembershipCondition" )) throw new ArgumentException( Environment.GetResourceString( "Argument_MembershipConditionElement" ) ); }
internal CodeGroup() { m_membershipCondition = null; m_children = null; m_policy = null; m_element = null; m_parentLevel = null; }
internal CodeGroup(IMembershipCondition membershipCondition, PermissionSet permSet) { this.m_membershipCondition = membershipCondition; this.m_policy = new System.Security.Policy.PolicyStatement(); this.m_policy.SetPermissionSetNoCopy(permSet); this.m_children = ArrayList.Synchronized(new ArrayList()); this.m_element = null; this.m_parentLevel = null; }
private static void ListPermissionSets(PolicyLevel pLevel) { IList namedPermissions = pLevel.NamedPermissionSets; IEnumerator namedPermission = namedPermissions.GetEnumerator(); while (namedPermission.MoveNext()) { Console.WriteLine("\t" + ((NamedPermissionSet)namedPermission.Current).Name); } }
protected override void ParseXml(SecurityElement e, PolicyLevel level) { string str = e.Attribute("Access"); if (str != null) { this.m_access = (FileIOPermissionAccess) Enum.Parse(typeof(FileIOPermissionAccess), str); } else { this.m_access = FileIOPermissionAccess.NoAccess; } }
public SecurityElement ToXml( PolicyLevel level ) { SecurityElement root = new SecurityElement( "IMembershipCondition" ); System.Security.Util.XMLUtil.AddClassAttribute( root, this.GetType(), "System.Security.Policy.AllMembershipCondition" ); // If you hit this assert then most likely you are trying to change the name of this class. // This is ok as long as you change the hard coded string above and change the assert below. Contract.Assert( this.GetType().FullName.Equals( "System.Security.Policy.AllMembershipCondition" ), "Class name changed!" ); root.AddAttribute( "version", "1" ); return root; }
internal CodeGroup( IMembershipCondition membershipCondition, PermissionSet permSet ) { BCLDebug.Assert( membershipCondition != null, "membershipCondition != null" ); BCLDebug.Assert( permSet != null, "permSet != null" ); m_membershipCondition = membershipCondition; m_policy = new PolicyStatement(); m_policy.SetPermissionSetNoCopy( permSet ); m_children = ArrayList.Synchronized( new ArrayList() ); m_element = null; m_parentLevel = null; }
protected CodeGroup( IMembershipCondition membershipCondition, PolicyStatement policy ) { if (membershipCondition == null) throw new ArgumentNullException( "membershipCondition" ); if (policy == null) m_policy = null; else m_policy = policy.Copy(); m_membershipCondition = membershipCondition.Copy(); m_children = ArrayList.Synchronized( new ArrayList() ); m_element = null; m_parentLevel = null; }
public void FromXml(SecurityElement e, PolicyLevel level) { if (e == null) { throw new ArgumentNullException("e"); } if (!e.Tag.Equals("IMembershipCondition")) { throw new ArgumentException(Environment.GetResourceString("Argument_MembershipConditionElement")); } lock (this) { this.m_zone = System.Security.SecurityZone.NoZone; this.m_element = e; } }
public void FromXml(SecurityElement e, PolicyLevel level) { if (e == null) { throw new ArgumentNullException("e"); } if (!e.Tag.Equals("IMembershipCondition")) { throw new ArgumentException(Environment.GetResourceString("Argument_MembershipConditionElement")); } Contract.EndContractBlock(); lock (this) { m_site = null; m_element = e; } }
// Implement the ISecurityPolicyEncodable interface. public void FromXml(SecurityElement et, PolicyLevel level) { if (et == null) { throw new ArgumentNullException("et"); } if (et.Tag != "IMembershipCondition") { throw new ArgumentException(_("Security_PolicyName")); } if (et.Attribute("version") != "1") { throw new ArgumentException(_("Security_PolicyVersion")); } String value = et.Attribute("X509Certificate"); certificate = new X509Certificate (StrongNamePublicKeyBlob.FromHex(value)); }
/// <include file='doc\ZoneMembershipCondition.uex' path='docs/doc[@for="ZoneMembershipCondition.ToXml1"]/*' /> public SecurityElement ToXml(PolicyLevel level) { if (m_zone == SecurityZone.NoZone && m_element != null) { ParseZone(); } SecurityElement root = new SecurityElement("IMembershipCondition"); System.Security.Util.XMLUtil.AddClassAttribute(root, this.GetType()); root.AddAttribute("version", "1"); if (m_zone != SecurityZone.NoZone) { root.AddAttribute("Zone", Enum.GetName(typeof(SecurityZone), m_zone)); } return(root); }
/// <include file='doc\URLMembershipCondition.uex' path='docs/doc[@for="UrlMembershipCondition.ToXml1"]/*' /> public SecurityElement ToXml(PolicyLevel level) { if (m_url == null && m_element != null) { ParseURL(); } SecurityElement root = new SecurityElement("IMembershipCondition"); System.Security.Util.XMLUtil.AddClassAttribute(root, this.GetType()); root.AddAttribute("version", "1"); if (m_url != null) { root.AddAttribute("Url", m_url.ToString()); } return(root); }
protected CodeGroup(IMembershipCondition membershipCondition, System.Security.Policy.PolicyStatement policy) { if (membershipCondition == null) { throw new ArgumentNullException("membershipCondition"); } if (policy == null) { this.m_policy = null; } else { this.m_policy = policy.Copy(); } this.m_membershipCondition = membershipCondition.Copy(); this.m_children = ArrayList.Synchronized(new ArrayList()); this.m_element = null; this.m_parentLevel = null; }
// Implement the ISecurityPolicyEncodable interface. public void FromXml(SecurityElement et, PolicyLevel level) { if (et == null) { throw new ArgumentNullException("et"); } if (et.Tag != "IMembershipCondition") { throw new ArgumentException(_("Security_PolicyName")); } if (et.Attribute("version") != "1") { throw new ArgumentException(_("Security_PolicyVersion")); } String val = et.Attribute("HashValue"); value = StrongNamePublicKeyBlob.FromHex(val); val = et.Attribute("HashAlgorithm"); hashAlg = HashAlgorithm.Create(val); }
public SecurityElement ToXml(PolicyLevel level) { SecurityElement element = new SecurityElement("IMembershipCondition"); XMLUtil.AddClassAttribute(element, base.GetType(), "System.Security.Policy.StrongNameMembershipCondition"); element.AddAttribute("version", "1"); if (this.PublicKey != null) { element.AddAttribute("PublicKeyBlob", Hex.EncodeHexString(this.PublicKey.PublicKey)); } if (this.Name != null) { element.AddAttribute("Name", this.Name); } if (this.Version != null) { element.AddAttribute("AssemblyVersion", this.Version.ToString()); } return(element); }
/// <summary>Reconstructs a security object with a given state from an XML encoding.</summary> /// <param name="et">The XML encoding to use to reconstruct the security object. </param> /// <param name="level">The <see cref="T:System.Security.Policy.PolicyLevel" /> context for lookup of <see cref="T:System.Security.NamedPermissionSet" /> values. </param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="et" /> parameter is null. </exception> /// <exception cref="T:System.ArgumentException">The <paramref name="et" /> parameter is not a valid <see cref="T:System.Security.Policy.PolicyStatement" /> encoding. </exception> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" /> /// </PermissionSet> public void FromXml(SecurityElement et, PolicyLevel level) { if (et == null) { throw new ArgumentNullException("et"); } if (et.Tag != "PolicyStatement") { throw new ArgumentException(Locale.GetText("Invalid tag.")); } string text = et.Attribute("Attributes"); if (text != null) { this.attrs = (PolicyStatementAttribute)((int)Enum.Parse(typeof(PolicyStatementAttribute), text)); } SecurityElement et2 = et.SearchForChildByTag("PermissionSet"); this.PermissionSet.FromXml(et2); }
// Token: 0x06002A0B RID: 10763 RVA: 0x0009C32C File Offset: 0x0009A52C internal SecurityElement ToXml(PolicyLevel level, bool useInternal) { SecurityElement securityElement = new SecurityElement("PolicyStatement"); securityElement.AddAttribute("version", "1"); if (this.m_attributes != PolicyStatementAttribute.Nothing) { securityElement.AddAttribute("Attributes", XMLUtil.BitFieldEnumToString(typeof(PolicyStatementAttribute), this.m_attributes)); } lock (this) { if (this.m_permSet != null) { if (this.m_permSet is NamedPermissionSet) { NamedPermissionSet namedPermissionSet = (NamedPermissionSet)this.m_permSet; if (level != null && level.GetNamedPermissionSet(namedPermissionSet.Name) != null) { securityElement.AddAttribute("PermissionSetName", namedPermissionSet.Name); } else if (useInternal) { securityElement.AddChild(namedPermissionSet.InternalToXml()); } else { securityElement.AddChild(namedPermissionSet.ToXml()); } } else if (useInternal) { securityElement.AddChild(this.m_permSet.InternalToXml()); } else { securityElement.AddChild(this.m_permSet.ToXml()); } } } return(securityElement); }
// internal stuff internal static CodeGroup CreateFromXml(SecurityElement se, PolicyLevel level) { string fullClassName = se.Attribute("class"); string className = fullClassName; // many possible formats // a. "FirstMatchCodeGroup" // b. "System.Security.Policy.FirstMatchCodeGroup" // c. "System.Security.Policy.FirstMatchCodeGroup, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\"\r\n version=\"1\">\r\n <IMembershipCondition class=\"System.Security.Policy.AllMembershipCondition, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" int n = className.IndexOf(","); if (n > 0) { className = className.Substring(0, n); } n = className.LastIndexOf("."); if (n > 0) { className = className.Substring(n + 1); } // much faster than calling Activator.CreateInstance switch (className) { case "FileCodeGroup": return(new FileCodeGroup(se, level)); case "FirstMatchCodeGroup": return(new FirstMatchCodeGroup(se, level)); case "NetCodeGroup": return(new NetCodeGroup(se, level)); case "UnionCodeGroup": return(new UnionCodeGroup(se, level)); default: // unknown Type classType = Type.GetType(fullClassName); CodeGroup cg = (CodeGroup)Activator.CreateInstance(classType, true); cg.FromXml(se, level); return(cg); } }
public void FromXml(SecurityElement element, PolicyLevel level) { MembershipConditionHelper.CheckSecurityElement(element, "element", version, version); string u = element.Attribute("Url"); #if NET_2_0 if (u != null) { CheckUrl(u); url = new Url(u); } else { url = null; } #else url = (u == null) ? null : new Url(u); #endif userUrl = u; }
/// <include file='doc\CodeGroup.uex' path='docs/doc[@for="CodeGroup.CodeGroup"]/*' /> public CodeGroup(IMembershipCondition membershipCondition, PolicyStatement policy) { if (membershipCondition == null) { throw new ArgumentNullException("membershipCondition"); } if (policy == null) { m_policy = null; } else { m_policy = policy.Copy(); } m_membershipCondition = membershipCondition.Copy(); m_children = ArrayList.Synchronized(new ArrayList()); m_element = null; m_parentLevel = null; }
/// <include file='doc\CodeGroup.uex' path='docs/doc[@for="CodeGroup.FromXml1"]/*' /> public void FromXml(SecurityElement e, PolicyLevel level) { if (e == null) { throw new ArgumentNullException("e"); } lock (this) { m_element = e; m_parentLevel = level; m_children = null; m_membershipCondition = null; m_policy = null; m_name = e.Attribute("Name"); m_description = e.Attribute("Description"); ParseXml(e, level); } }
/// <summary>Creates an XML encoding of the security object and its current state with the specified <see cref="T:System.Security.Policy.PolicyLevel" />.</summary> /// <returns>An XML encoding of the security object, including any state information.</returns> /// <param name="level">The <see cref="T:System.Security.Policy.PolicyLevel" /> context, which is used to resolve <see cref="T:System.Security.NamedPermissionSet" /> references. </param> public SecurityElement ToXml(PolicyLevel level) { SecurityElement securityElement = MembershipConditionHelper.Element(typeof(StrongNameMembershipCondition), this.version); if (this.blob != null) { securityElement.AddAttribute("PublicKeyBlob", this.blob.ToString()); } if (this.name != null) { securityElement.AddAttribute("Name", this.name); } if (this.assemblyVersion != null) { string text = this.assemblyVersion.ToString(); if (text != "0.0") { securityElement.AddAttribute("AssemblyVersion", text); } } return(securityElement); }
protected override void CreateXml(SecurityElement element, PolicyLevel level) { DictionaryEntry[] connectAccessRules = this.GetConnectAccessRules(); if (connectAccessRules != null) { SecurityElement child = new SecurityElement("connectAccessRules"); foreach (DictionaryEntry entry in connectAccessRules) { SecurityElement element3 = new SecurityElement("codeOrigin"); element3.AddAttribute("scheme", (string)entry.Key); foreach (CodeConnectAccess access in (CodeConnectAccess[])entry.Value) { SecurityElement element4 = new SecurityElement("connectAccess"); element4.AddAttribute("scheme", access.Scheme); element4.AddAttribute("port", access.StrPort); element3.AddChild(element4); } child.AddChild(element3); } element.AddChild(child); } }
public SecurityElement ToXml(PolicyLevel level) { if (m_url == null && m_element != null) { ParseURL(); } SecurityElement root = new SecurityElement("IMembershipCondition"); System.Security.Util.XMLUtil.AddClassAttribute(root, this.GetType(), "System.Security.Policy.UrlMembershipCondition"); // If you hit this assert then most likely you are trying to change the name of this class. // This is ok as long as you change the hard coded string above and change the assert below. Contract.Assert(this.GetType().FullName.Equals("System.Security.Policy.UrlMembershipCondition"), "Class name changed!"); root.AddAttribute("version", "1"); if (m_url != null) { root.AddAttribute("Url", m_url.ToString()); } return(root); }
public SecurityElement ToXml(PolicyLevel level) { SecurityElement element; element = new SecurityElement("IMembershipCondition"); element.AddAttribute ("class", SecurityElement.Escape (typeof(StrongNameMembershipCondition). AssemblyQualifiedName)); element.AddAttribute("version", "1"); element.AddAttribute("PublicKey", blob.ToString()); if (name != null) { element.AddAttribute("Name", SecurityElement.Escape(name)); } if (version != null) { element.AddAttribute("AssemblyVersion", version.ToString()); } return(element); }
protected override void ParseXml(SecurityElement e, PolicyLevel level) { this.ResetConnectAccess(); SecurityElement securityElement = e.SearchForChildByTag("connectAccessRules"); if (securityElement == null || securityElement.Children == null) { this.SetDefaults(); } else { foreach (SecurityElement child1 in securityElement.Children) { if (child1.Tag.Equals("codeOrigin")) { string originScheme = child1.Attribute("scheme"); bool flag = false; if (child1.Children != null) { foreach (SecurityElement child2 in child1.Children) { if (child2.Tag.Equals("connectAccess")) { string allowScheme = child2.Attribute("scheme"); string allowPort = child2.Attribute("port"); this.AddConnectAccess(originScheme, new CodeConnectAccess(allowScheme, allowPort)); flag = true; } } } if (!flag) { this.AddConnectAccess(originScheme, (CodeConnectAccess)null); } } } } }
// Token: 0x06002994 RID: 10644 RVA: 0x00099800 File Offset: 0x00097A00 protected override void ParseXml(SecurityElement e, PolicyLevel level) { this.ResetConnectAccess(); SecurityElement securityElement = e.SearchForChildByTag("connectAccessRules"); if (securityElement == null || securityElement.Children == null) { this.SetDefaults(); return; } foreach (object obj in securityElement.Children) { SecurityElement securityElement2 = (SecurityElement)obj; if (securityElement2.Tag.Equals("codeOrigin")) { string originScheme = securityElement2.Attribute("scheme"); bool flag = false; if (securityElement2.Children != null) { foreach (object obj2 in securityElement2.Children) { SecurityElement securityElement3 = (SecurityElement)obj2; if (securityElement3.Tag.Equals("connectAccess")) { string allowScheme = securityElement3.Attribute("scheme"); string allowPort = securityElement3.Attribute("port"); this.AddConnectAccess(originScheme, new CodeConnectAccess(allowScheme, allowPort)); flag = true; } } } if (!flag) { this.AddConnectAccess(originScheme, null); } } } }
public SecurityElement ToXml(PolicyLevel level) { // PolicyLevel isn't used as there's no need to resolve NamedPermissionSet references SecurityElement se = MembershipConditionHelper.Element(typeof(StrongNameMembershipCondition), version); if (blob != null) { se.AddAttribute("PublicKeyBlob", blob.ToString()); } if (name != null) { se.AddAttribute("Name", name); } if (assemblyVersion != null) { string v = assemblyVersion.ToString(); if (v != "0.0") { se.AddAttribute("AssemblyVersion", v); } } return(se); }
public SecurityElement ToXml(PolicyLevel level) { if (m_zone == SecurityZone.NoZone && m_element != null) { ParseZone(); } SecurityElement root = new SecurityElement("IMembershipCondition"); System.Security.Util.XMLUtil.AddClassAttribute(root, this.GetType(), "System.Security.Policy.ZoneMembershipCondition"); // If you hit this assert then most likely you are trying to change the name of this class. // This is ok as long as you change the hard coded string above and change the assert below. BCLDebug.Assert(this.GetType().FullName.Equals("System.Security.Policy.ZoneMembershipCondition"), "Class name changed!"); root.AddAttribute("version", "1"); if (m_zone != SecurityZone.NoZone) { root.AddAttribute("Zone", Enum.GetName(typeof(SecurityZone), m_zone)); } return(root); }
internal static CodeGroup CreateFromXml(SecurityElement se, PolicyLevel level) { string text = se.Attribute("class"); string text2 = text; int num = text2.IndexOf(","); if (num > 0) { text2 = text2.Substring(0, num); } num = text2.LastIndexOf("."); if (num > 0) { text2 = text2.Substring(num + 1); } string text3 = text2; switch (text3) { case "FileCodeGroup": return(new FileCodeGroup(se, level)); case "FirstMatchCodeGroup": return(new FirstMatchCodeGroup(se, level)); case "NetCodeGroup": return(new NetCodeGroup(se, level)); case "UnionCodeGroup": return(new UnionCodeGroup(se, level)); } Type type = Type.GetType(text); CodeGroup codeGroup = (CodeGroup)Activator.CreateInstance(type, true); codeGroup.FromXml(se, level); return(codeGroup); }
/// <summary>Creates an XML encoding of the security object and its current state with the specified <see cref="T:System.Security.Policy.PolicyLevel" />.</summary> /// <param name="level">The policy level context for resolving named permission set references. </param> /// <returns>An XML encoding of the security object, including any state information.</returns> // Token: 0x06002AD5 RID: 10965 RVA: 0x0009EFD8 File Offset: 0x0009D1D8 public SecurityElement ToXml(PolicyLevel level) { if (this.m_value == null && this.m_element != null) { this.ParseHashValue(); } if (this.m_hashAlg == null && this.m_element != null) { this.ParseHashAlgorithm(); } SecurityElement securityElement = new SecurityElement("IMembershipCondition"); XMLUtil.AddClassAttribute(securityElement, base.GetType(), "System.Security.Policy.HashMembershipCondition"); securityElement.AddAttribute("version", "1"); if (this.m_value != null) { securityElement.AddAttribute("HashValue", Hex.EncodeHexString(this.HashValue)); } if (this.m_hashAlg != null) { securityElement.AddAttribute("HashAlgorithm", this.HashAlgorithm.GetType().FullName); } return(securityElement); }
/// <include file='doc\StrongNameMembershipCondition.uex' path='docs/doc[@for="StrongNameMembershipCondition.ToXml1"]/*' /> public SecurityElement ToXml(PolicyLevel level) { SecurityElement root = new SecurityElement("IMembershipCondition"); System.Security.Util.XMLUtil.AddClassAttribute(root, this.GetType()); root.AddAttribute("version", "1"); if (PublicKey != null) { root.AddAttribute(s_tagPublicKeyBlob, System.Security.Util.Hex.EncodeHexString(PublicKey.PublicKey)); } if (Name != null) { root.AddAttribute(s_tagName, Name); } if ((Object)Version != null) { root.AddAttribute(s_tagVersion, Version.ToString()); } return(root); }
// Token: 0x06002993 RID: 10643 RVA: 0x00099728 File Offset: 0x00097928 protected override void CreateXml(SecurityElement element, PolicyLevel level) { DictionaryEntry[] connectAccessRules = this.GetConnectAccessRules(); if (connectAccessRules == null) { return; } SecurityElement securityElement = new SecurityElement("connectAccessRules"); foreach (DictionaryEntry dictionaryEntry in connectAccessRules) { SecurityElement securityElement2 = new SecurityElement("codeOrigin"); securityElement2.AddAttribute("scheme", (string)dictionaryEntry.Key); foreach (CodeConnectAccess codeConnectAccess in (CodeConnectAccess[])dictionaryEntry.Value) { SecurityElement securityElement3 = new SecurityElement("connectAccess"); securityElement3.AddAttribute("scheme", codeConnectAccess.Scheme); securityElement3.AddAttribute("port", codeConnectAccess.StrPort); securityElement2.AddChild(securityElement3); } securityElement.AddChild(securityElement2); } element.AddChild(securityElement); }
public void FromXml(SecurityElement e, PolicyLevel level) { if (e == null) { throw new ArgumentNullException("e"); } if (e.Tag != "PolicyStatement") { throw new ArgumentException(Locale.GetText("Invalid tag.")); } string attributes = e.Attribute("Attributes"); if (attributes != null) { attrs = (PolicyStatementAttribute)Enum.Parse( typeof(PolicyStatementAttribute), attributes); } SecurityElement permissions = e.SearchForChildByTag("PermissionSet"); PermissionSet.FromXml(permissions); }
public static void SavePolicyLevel (PolicyLevel level) { // Yes this will throw a NullReferenceException, just like MS (see FDBK13121) level.Save (); }
public static PolicyLevel LoadPolicyLevelFromString (string str, PolicyLevelType type) { if (null == str) throw new ArgumentNullException ("str"); PolicyLevel pl = null; try { pl = new PolicyLevel (type.ToString (), type); pl.LoadFromString (str); } catch (Exception e) { throw new ArgumentException (Locale.GetText ("Invalid policy XML"), e); } return pl; }
public void FromXml (SecurityElement e, PolicyLevel level) { MembershipConditionHelper.CheckSecurityElement (e, "e", version, version); string u = e.Attribute ("Url"); #if NET_2_0 if (u != null) { CheckUrl (u); url = new Url (u); } else { url = null; } #else url = (u == null) ? null : new Url (u); #endif userUrl = u; }
public SecurityElement ToXml (PolicyLevel level) { return _se; }
static CodeGroup FindCodeGroup (string name, ref CodeGroup parent, ref PolicyLevel pl) { if (name.Length < 1) return null; // Notes: // - labels starts with numbers (e.g. 1.2.1) // - names cannot start with numbers (A-Z, 0-9 and _) bool label = Char.IsDigit (name, 0); // More notes // - we can't remove the root code group // - we remove only one group (e.g. name) for (int i=0; i < Levels.Count; i++) { pl = (PolicyLevel) Levels [i]; parent = pl.RootCodeGroup; CodeGroup cg = null; if (label) cg = FindCodeGroupByLabel (name, "1", ref parent); else cg = FindCodeGroupByName (name, ref parent); if (cg != null) return cg; } Console.WriteLine ("CodeGroup with {0} '{1}' was not found!", label ? "label" : "name", name); return null; }
public void FromXml(SecurityElement e, PolicyLevel level) { }
public SecurityElement ToXml(PolicyLevel level) { return(this.ToXml(level, false)); }
internal void FromXml(SecurityDocument doc, int position, PolicyLevel level, bool allowInternalOnly) { if (doc == null) { throw new ArgumentNullException("doc"); } if (!doc.GetTagForElement(position).Equals("PolicyStatement")) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidXMLElement"), new object[] { "PolicyStatement", base.GetType().FullName })); } this.m_attributes = PolicyStatementAttribute.Nothing; string attributeForElement = doc.GetAttributeForElement(position, "Attributes"); if (attributeForElement != null) { this.m_attributes = (PolicyStatementAttribute)Enum.Parse(typeof(PolicyStatementAttribute), attributeForElement); } lock (this) { this.m_permSet = null; if (level != null) { string name = doc.GetAttributeForElement(position, "PermissionSetName"); if (name != null) { this.m_permSet = level.GetNamedPermissionSetInternal(name); if (this.m_permSet == null) { this.m_permSet = new System.Security.PermissionSet(PermissionState.None); } } } if (this.m_permSet == null) { ArrayList childrenPositionForElement = doc.GetChildrenPositionForElement(position); int num = -1; for (int i = 0; i < childrenPositionForElement.Count; i++) { if (doc.GetTagForElement((int)childrenPositionForElement[i]).Equals("PermissionSet")) { num = (int)childrenPositionForElement[i]; } } if (num == -1) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML")); } string str3 = doc.GetAttributeForElement(num, "class"); if ((str3 != null) && (str3.Equals("NamedPermissionSet") || str3.Equals("System.Security.NamedPermissionSet"))) { this.m_permSet = new NamedPermissionSet("DefaultName", PermissionState.None); } else { this.m_permSet = new System.Security.PermissionSet(PermissionState.None); } this.m_permSet.FromXml(doc, num, allowInternalOnly); } if (this.m_permSet == null) { this.m_permSet = new System.Security.PermissionSet(PermissionState.None); } } }
internal void FromXml(SecurityElement et, PolicyLevel level, bool allowInternalOnly) { if (et == null) { throw new ArgumentNullException("et"); } if (!et.Tag.Equals("PolicyStatement")) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidXMLElement"), new object[] { "PolicyStatement", base.GetType().FullName })); } this.m_attributes = PolicyStatementAttribute.Nothing; string str = et.Attribute("Attributes"); if (str != null) { this.m_attributes = (PolicyStatementAttribute)Enum.Parse(typeof(PolicyStatementAttribute), str); } lock (this) { this.m_permSet = null; if (level != null) { string name = et.Attribute("PermissionSetName"); if (name != null) { this.m_permSet = level.GetNamedPermissionSetInternal(name); if (this.m_permSet == null) { this.m_permSet = new System.Security.PermissionSet(PermissionState.None); } } } if (this.m_permSet == null) { SecurityElement element = et.SearchForChildByTag("PermissionSet"); if (element == null) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML")); } string str3 = element.Attribute("class"); if ((str3 != null) && (str3.Equals("NamedPermissionSet") || str3.Equals("System.Security.NamedPermissionSet"))) { this.m_permSet = new NamedPermissionSet("DefaultName", PermissionState.None); } else { this.m_permSet = new System.Security.PermissionSet(PermissionState.None); } try { this.m_permSet.FromXml(element, allowInternalOnly, true); } catch { } } if (this.m_permSet == null) { this.m_permSet = new System.Security.PermissionSet(PermissionState.None); } } }
static PolicyLevel GetLevel( LevelType type ) { m_danglingLevelIndicator = null; if (m_levelType == LevelType.None) { if (type == LevelType.None) { m_levelAssemblyList = m_userAssemblies; return GetLevel( "User" ); } else if (type == LevelType.All) { return null; } else { Error( null, "Unknown level type", -1 ); /* not reached */ return null; } } else if (m_levelType == LevelType.Machine) { m_levelAssemblyList = m_machineAssemblies; return GetLevel( "Machine" ); } else if (m_levelType == LevelType.UserDefault) { m_levelAssemblyList = m_userAssemblies; return GetLevel( "User" ); } else if (m_levelType == LevelType.UserCustom) { if (m_currentCustomLevel == null) { m_levelAssemblyList = m_customUserAssemblies; try { m_currentCustomLevel = SecurityManager.LoadPolicyLevelFromFile( m_levelPath, PolicyLevelType.User ); } catch (Exception e) { Error( null, e.Message, -1 ); } } return m_currentCustomLevel; } else if (m_levelType == LevelType.All) { return null; } else if (m_levelType == LevelType.Enterprise) { m_levelAssemblyList = m_enterpriseAssemblies; return GetLevel( "Enterprise" ); } else if (m_levelType == LevelType.AllCustom) { if (m_currentCustomLevel == null) { try { m_currentCustomLevel = SecurityManager.LoadPolicyLevelFromFile( m_levelPath, PolicyLevelType.User ); } catch (Exception e) { Error( null, e.Message, -1 ); } } return null; } else { // This should never occur. Error( null, "Unknown level type", -1 ); /* not reached */ return null; } }
private static void InitializePolicyHierarchy () { string machinePolicyPath = Path.GetDirectoryName (Environment.GetMachineConfigPath ()); // note: use InternalGetFolderPath to avoid recursive policy initialization string userPolicyPath = Path.Combine (Environment.UnixGetFolderPath (Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create), "mono"); PolicyLevel enterprise = new PolicyLevel ("Enterprise", PolicyLevelType.Enterprise); _level = enterprise; enterprise.LoadFromFile (Path.Combine (machinePolicyPath, "enterprisesec.config")); PolicyLevel machine = new PolicyLevel ("Machine", PolicyLevelType.Machine); _level = machine; machine.LoadFromFile (Path.Combine (machinePolicyPath, "security.config")); PolicyLevel user = new PolicyLevel ("User", PolicyLevelType.User); _level = user; user.LoadFromFile (Path.Combine (userPolicyPath, "security.config")); ArrayList al = new ArrayList (); al.Add (enterprise); al.Add (machine); al.Add (user); _hierarchy = ArrayList.Synchronized (al); _level = null; }
internal static bool ResolvePolicyLevel (ref PermissionSet ps, PolicyLevel pl, Evidence evidence) { PolicyStatement pst = pl.Resolve (evidence); if (pst != null) { if (ps == null) { // only for initial (first) policy level processed ps = pst.PermissionSet; } else { ps = ps.Intersect (pst.PermissionSet); if (ps == null) { // null is equals to None - exist that null can throw NullReferenceException ;-) ps = new PermissionSet (PermissionState.None); } } if ((pst.Attributes & PolicyStatementAttribute.LevelFinal) == PolicyStatementAttribute.LevelFinal) return true; } return false; }
public SecurityElement ToXml(PolicyLevel level) { return(default(SecurityElement)); }
static void ShowResolveGroup (PolicyLevel pl, Evidence e) { Console.WriteLine ("{0}Level: {1}{0}", Environment.NewLine, pl.Label); CodeGroup cg = pl.ResolveMatchingCodeGroups (e); Console.WriteLine ("Code Groups:{0}", Environment.NewLine); ShowCodeGroup (cg, "1"); Console.WriteLine (); }
public void SetAppDomainPolicy(PolicyLevel domainPolicy) { if (domainPolicy == null) throw new ArgumentNullException("domainPolicy"); Contract.EndContractBlock(); if (!IsLegacyCasPolicyEnabled) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyExplicit")); } // Check that policy has not been set previously. lock (this) { if (_HasSetPolicy) throw new PolicyException(Environment.GetResourceString("Policy_PolicyAlreadySet")); _HasSetPolicy = true; // Make sure that the loader allows us to change security policy // at this time (this will throw if not.) nChangeSecurityPolicy(); } // Add the new policy level. SecurityManager.PolicyManager.AddLevel(domainPolicy); }
public void FromXml (SecurityElement e, PolicyLevel level) { _se = e; }
// protected override void CreateXml( SecurityElement element, PolicyLevel level ) { DictionaryEntry[] rules = GetConnectAccessRules(); if (rules == null) return; SecurityElement rulesElement = new SecurityElement("connectAccessRules"); foreach (DictionaryEntry rule in rules) { SecurityElement codeOriginElement = new SecurityElement("codeOrigin"); codeOriginElement.AddAttribute("scheme", (string) rule.Key); foreach (CodeConnectAccess access in (CodeConnectAccess[])rule.Value) { SecurityElement accessElem = new SecurityElement("connectAccess"); accessElem.AddAttribute("scheme", access.Scheme); accessElem.AddAttribute("port", access.StrPort); codeOriginElement.AddChild(accessElem); } rulesElement.AddChild(codeOriginElement); } element.AddChild(rulesElement); }
static void BuildLevels () { IEnumerator e = SecurityManager.PolicyHierarchy (); if (e.MoveNext ()) levelEnterprise = (PolicyLevel) e.Current; if (e.MoveNext ()) levelMachine = (PolicyLevel) e.Current; if (e.MoveNext ()) levelUser = (PolicyLevel) e.Current; }
protected override void ParseXml( SecurityElement e, PolicyLevel level ) { //Reset the exiting content ResetConnectAccess(); SecurityElement et = e.SearchForChildByTag("connectAccessRules"); if (et == null || et.Children == null) { SetDefaults(); return; } foreach(SecurityElement codeOriginElem in et.Children) { if (codeOriginElem.Tag.Equals("codeOrigin")) { string originScheme = codeOriginElem.Attribute("scheme"); bool oneAdded = false; if (codeOriginElem.Children != null) { foreach(SecurityElement accessElem in codeOriginElem.Children) { if (accessElem.Tag.Equals("connectAccess")) { string connectScheme = accessElem.Attribute("scheme"); string connectPort = accessElem.Attribute("port"); AddConnectAccess(originScheme, new CodeConnectAccess(connectScheme, connectPort)); oneAdded = true; } else { // improper tag found, just ignore } } } if (!oneAdded) { //special case as to no talkback access for a given scheme AddConnectAccess(originScheme, null); } } else { // improper tag found, just ignore } } }
public SecurityElement ToXml (PolicyLevel level) { // PolicyLevel isn't used as there's no need to resolve NamedPermissionSet references SecurityElement se = MembershipConditionHelper.Element (typeof (UrlMembershipCondition), version); se.AddAttribute ("Url", userUrl); return se; }
public static PolicyLevel LoadPolicyLevelFromFile (string path, PolicyLevelType type) { if (path == null) throw new ArgumentNullException ("path"); PolicyLevel pl = null; try { pl = new PolicyLevel (type.ToString (), type); pl.LoadFromFile (path); } catch (Exception e) { throw new ArgumentException (Locale.GetText ("Invalid policy XML"), e); } return pl; }