17 private bool m_noRestriction;
22 internal const int AnyPort = 0;
43 m_noRestriction = free;
56 m_noRestriction =
false;
83 m_connectList.Add(endPoint);
87 m_acceptList.
Add(endPoint);
97 return m_noRestriction;
105 socketPermission.m_connectList = (
ArrayList)m_connectList.
Clone();
107 return socketPermission;
117 if (item.SubsetMatch(item2))
143 if (socketPermission ==
null)
147 if (m_noRestriction || socketPermission.m_noRestriction)
152 for (
int i = 0; i < m_connectList.Count; i++)
156 for (
int j = 0; j < m_acceptList.
Count; j++)
160 return socketPermission2;
176 if (socketPermission ==
null)
185 else if (socketPermission.m_noRestriction)
192 intersectLists(m_connectList, socketPermission.m_connectList, socketPermission2.m_connectList);
193 intersectLists(m_acceptList, socketPermission.m_acceptList, socketPermission2.m_acceptList);
195 if (!socketPermission2.m_noRestriction && socketPermission2.m_connectList.
Count == 0 && socketPermission2.m_acceptList.
Count == 0)
199 return socketPermission2;
213 if (!m_noRestriction && m_connectList.Count == 0)
215 return m_acceptList.
Count == 0;
220 if (socketPermission ==
null)
232 if (m_acceptList.
Count + m_connectList.Count == 0)
236 if (socketPermission.m_acceptList.
Count + socketPermission.m_connectList.
Count == 0)
243 if (!FindSubset(m_connectList, socketPermission.m_connectList))
247 if (FindSubset(m_acceptList, socketPermission.m_acceptList))
259 private void CleanupDNS()
265 connect.address =
null;
268 foreach (EndpointPermission accept
in m_acceptList)
272 accept.address =
null;
283 if (securityElement ==
null)
287 if (!securityElement.
Tag.Equals(
"IPermission"))
289 throw new ArgumentException(SR.GetString(
"net_not_ipermission"),
"securityElement");
291 string text = securityElement.Attribute(
"class");
294 throw new ArgumentException(SR.GetString(
"net_no_classname"),
"securityElement");
296 if (text.IndexOf(GetType().FullName) < 0)
301 string text2 = securityElement.Attribute(
"Unrestricted");
304 m_noRestriction = (
string.Compare(text2,
"true",
StringComparison.OrdinalIgnoreCase) == 0);
310 m_noRestriction =
false;
314 if (securityElement2 !=
null)
316 ParseAddXmlElement(securityElement2, m_connectList,
"ConnectAccess, ");
319 if (securityElement2 !=
null)
321 ParseAddXmlElement(securityElement2, m_acceptList,
"AcceptAccess, ");
329 if (child.
Tag.Equals(
"ENDPOINT"))
335 text = (attributes[
"host"] as string);
343 throw new ArgumentNullException(accessStr +
"host");
345 string epname = text;
348 text = (attributes[
"transport"] as string);
356 throw new ArgumentNullException(accessStr +
"transport");
369 throw new ArgumentException(accessStr +
"transport", ex);
373 text = (attributes[
"port"] as string);
381 throw new ArgumentNullException(accessStr +
"port");
392 catch (Exception ex2)
394 if (ex2 is
ThreadAbortException || ex2 is StackOverflowException || ex2 is OutOfMemoryException)
398 throw new ArgumentException(SR.GetString(
"net_perm_invalid_val", accessStr +
"port", text), ex2);
400 if (!ValidationHelper.ValidateTcpPort(num) && num != -1)
402 throw new ArgumentOutOfRangeException(
"port", num, SR.GetString(
"net_perm_invalid_val", accessStr +
"port", text));
404 listToAdd.
Add(
new EndpointPermission(epname, num, trtype));
414 securityElement.
AddAttribute(
"class", GetType().FullName +
", " + GetType().
Module.Assembly.FullName.Replace(
'"',
'\''));
418 if (m_connectList.Count > 0)
427 securityElement2.AddChild(securityElement3);
429 securityElement.
AddChild(securityElement2);
431 if (m_acceptList.Count > 0)
440 securityElement4.AddChild(securityElement5);
442 securityElement.
AddChild(securityElement4);
449 return securityElement;
452 private void initialize()
454 m_noRestriction =
false;
461 bool[] array =
new bool[
A.Count];
462 bool[] array2 =
new bool[
B.Count];
465 foreach (EndpointPermission item
in A)
468 foreach (EndpointPermission item2
in B)
470 if (!array2[num2] && item.Equals(item2))
473 array[num] = (array2[num2] =
true);
481 foreach (EndpointPermission item3
in A)
486 foreach (EndpointPermission item4
in B)
490 EndpointPermission endpointPermission3 = item3.Intersect(item4);
491 if (endpointPermission3 !=
null)
494 foreach (EndpointPermission item5
in result)
496 if (item5.Equals(endpointPermission3))
504 result.Add(endpointPermission3);
bool IsUnrestricted()
Checks the overall permission state of the object.
Allows a permission to expose an unrestricted state.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
void AddPermission(NetworkAccess access, TransportType transport, string hostName, int portNumber)
Adds a permission to the set of permissions for a transport address.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
NetworkAccess
Specifies network access permissions.
TransportType Transport
Gets the transport type that is associated with this endpoint.
virtual int Count
Gets the number of elements actually contained in the T:System.Collections.ArrayList.
SecurityElement SearchForChildByTag(string tag)
Finds a child by its tag name.
Defines an endpoint that is authorized by a T:System.Net.SocketPermission instance.
virtual object Clone()
Creates a shallow copy of the T:System.Collections.ArrayList.
string Tag
Gets or sets the tag name of an XML element.
int Port
Gets the network port number that is associated with this endpoint.
override IPermission Intersect(IPermission target)
Returns the logical intersection between two T:System.Net.SocketPermission instances.
void AddChild(SecurityElement child)
Adds a child element to the XML element.
override SecurityElement ToXml()
Creates an XML encoding of a T:System.Net.SocketPermission instance and its current state.
const int AllPorts
Defines a constant that represents all ports.
Represents the XML object model for encoding security objects. This class cannot be inherited.
Hashtable Attributes
Gets or sets the attributes of an XML element as name/value pairs.
Represents a collection of key/value pairs that are organized based on the hash code of the key....
Defines the underlying structure of all code access permissions.
IEnumerator AcceptList
Gets a list of T:System.Net.EndpointPermission instances that identifies the endpoints that can be ac...
override IPermission Copy()
Creates a copy of a T:System.Net.SocketPermission instance.
Defines methods implemented by permission types.
virtual int Add(object value)
Adds an object to the end of the T:System.Collections.ArrayList.
Controls rights to make or accept connections on a transport address.
The exception that is thrown when one of the arguments provided to a method is not valid.
SocketPermission(PermissionState state)
Initializes a new instance of the T:System.Net.SocketPermission class that allows unrestricted access...
string Hostname
Gets the DNS host name or IP address of the server that is associated with this endpoint.
Attribute can be applied to a module.
TransportType
Defines transport types for the T:System.Net.SocketPermission and T:System.Net.Sockets....
Attribute can be applied to an enumeration.
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
void AddAttribute(string name, string value)
Adds a name/value attribute to an XML element.
override bool IsSubsetOf(IPermission target)
Determines if the current permission is a subset of the specified permission.
Specifies that the class can be serialized.
ArrayList Children
Gets or sets the array of child elements of the XML element.
SocketPermission(NetworkAccess access, TransportType transport, string hostName, int portNumber)
Initializes a new instance of the T:System.Net.SocketPermission class for the given transport address...
virtual IEnumerator GetEnumerator()
Returns an enumerator for the entire T:System.Collections.ArrayList.
IEnumerator ConnectList
Gets a list of T:System.Net.EndpointPermission instances that identifies the endpoints that can be co...
override IPermission Union(IPermission target)
Returns the logical union between two T:System.Net.SocketPermission instances.
The exception that is thrown when a call is made to the M:System.Threading.Thread....
override void FromXml(SecurityElement securityElement)
Reconstructs a T:System.Net.SocketPermission instance for an XML encoding.
Supports a simple iteration over a non-generic collection.
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...