2 // System.Security.Policy.ApplicationDirectoryMembershipCondition
5 // Nick Drochak (ndrochak@gol.com)
6 // Jackson Harper (Jackson@LatitudeGeo.com)
7 // Sebastien Pouliot <sebastien@ximian.com>
9 // (C) 2002 Nick Drochak, All rights reserved.
10 // Copyright (C) 2004-2005 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
;
36 using System
.Runtime
.InteropServices
;
40 namespace System
.Security
.Policy
{
44 public sealed class ApplicationDirectoryMembershipCondition
: IConstantMembershipCondition
, IMembershipCondition
{
46 private readonly int version
= 1;
48 public ApplicationDirectoryMembershipCondition ()
53 public bool Check (Evidence evidence
)
58 string codebase
= Assembly
.GetCallingAssembly ().CodeBase
;
59 Uri local
= new Uri (codebase
);
60 Url ucode
= new Url (codebase
);
62 // *both* ApplicationDirectory and Url must be in *Host* evidences
65 IEnumerator e
= evidence
.GetHostEnumerator ();
66 while (e
.MoveNext ()) {
69 if (!adir
&& (o
is ApplicationDirectory
)) {
70 ApplicationDirectory ad
= (o
as ApplicationDirectory
);
71 string s
= ad
.Directory
;
72 adir
= (String
.Compare (s
, 0, local
.ToString (), 0, s
.Length
, true, CultureInfo
.InvariantCulture
) == 0);
74 else if (!url
&& (o
is Url
)) {
75 url
= ucode
.Equals (o
);
85 public IMembershipCondition
Copy ()
87 return new ApplicationDirectoryMembershipCondition ();
90 public override bool Equals (object o
)
92 return (o
is ApplicationDirectoryMembershipCondition
);
95 public void FromXml (SecurityElement e
)
100 public void FromXml (SecurityElement e
, PolicyLevel level
)
102 MembershipConditionHelper
.CheckSecurityElement (e
, "e", version
, version
);
105 // All instances of ApplicationDirectoryMembershipCondition are equal so they should
106 // have the same hashcode
107 public override int GetHashCode ()
109 return typeof (ApplicationDirectoryMembershipCondition
).GetHashCode ();
112 public override string ToString ()
114 return "ApplicationDirectory";
117 public SecurityElement
ToXml ()
122 public SecurityElement
ToXml (PolicyLevel level
)
124 SecurityElement se
= MembershipConditionHelper
.Element (typeof (ApplicationDirectoryMembershipCondition
), version
);