2 // System.Security.Policy.ApplicationDirectoryMembershipCondition
\r
5 // Nick Drochak (ndrochak@gol.com)
\r
6 // Jackson Harper (Jackson@LatitudeGeo.com)
\r
7 // Sebastien Pouliot <sebastien@ximian.com>
9 // (C) 2002 Nick Drochak, All rights reserved.
\r
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
33 using System.Globalization;
35 using System.Reflection;
39 namespace System.Security.Policy {
\r
42 public sealed class ApplicationDirectoryMembershipCondition : IConstantMembershipCondition, IMembershipCondition {
\r
44 private readonly int version = 1;
46 public ApplicationDirectoryMembershipCondition ()
51 public bool Check (Evidence evidence)
\r
53 if (evidence == null)
\r
56 string codebase = Assembly.GetCallingAssembly ().CodeBase;
57 Uri local = new Uri (codebase);
58 Url ucode = new Url (codebase);
60 // *both* ApplicationDirectory and Url must be in *Host* evidences
63 IEnumerator e = evidence.GetHostEnumerator ();
64 while (e.MoveNext ()) {
67 if (!adir && (o is ApplicationDirectory)) {
\r
68 ApplicationDirectory ad = (o as ApplicationDirectory);
69 string s = ad.Directory;
70 adir = (String.Compare (s, 0, local.ToString (), 0, s.Length, true, CultureInfo.InvariantCulture) == 0);
72 else if (!url && (o is Url)) {
73 url = ucode.Equals (o);
83 public IMembershipCondition Copy ()
\r
85 return new ApplicationDirectoryMembershipCondition ();
\r
88 public override bool Equals (object o)
\r
90 return (o is ApplicationDirectoryMembershipCondition);
\r
93 public void FromXml (SecurityElement e)
\r
98 public void FromXml (SecurityElement e, PolicyLevel level)
\r
100 MembershipConditionHelper.CheckSecurityElement (e, "e", version, version);
103 // All instances of ApplicationDirectoryMembershipCondition are equal so they should
\r
104 // have the same hashcode
\r
105 public override int GetHashCode ()
\r
107 return typeof (ApplicationDirectoryMembershipCondition).GetHashCode ();
\r
110 public override string ToString ()
\r
112 return "ApplicationDirectory";
\r
115 public SecurityElement ToXml ()
\r
117 return ToXml (null);
\r
120 public SecurityElement ToXml (PolicyLevel level)
\r
122 SecurityElement se = MembershipConditionHelper.Element (typeof (ApplicationDirectoryMembershipCondition), version);