Resolve() 개인적인 메소드

private Resolve ( ) : void
리턴 void
예제 #1
0
        private string IntersectHostname(EndpointPermission perm)
        {
            if (this.hostname == perm.hostname)
            {
                return(this.hostname);
            }

            this.Resolve();
            perm.Resolve();

            string _hostname = null;

            if (this.hasWildcard)
            {
                if (perm.hasWildcard)
                {
                    _hostname = Intersect(this.hostname, perm.hostname);
                }
                else if (perm.addresses != null)
                {
                    for (int j = 0; j < perm.addresses.Length; j++)
                    {
                        _hostname = Intersect(this.hostname, perm.addresses [j].ToString());
                        if (_hostname != null)
                        {
                            break;
                        }
                    }
                }
            }
            else if (this.addresses != null)
            {
                for (int i = 0; i < this.addresses.Length; i++)
                {
                    string thisaddr = this.addresses [i].ToString();
                    if (perm.hasWildcard)
                    {
                        _hostname = Intersect(thisaddr, perm.hostname);
                    }
                    else if (perm.addresses != null)
                    {
                        for (int j = 0; j < perm.addresses.Length; j++)
                        {
                            _hostname = Intersect(thisaddr, perm.addresses [j].ToString());
                            if (_hostname != null)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            return(_hostname);
        }
        internal bool MatchAddress(EndpointPermission e)
        {
            // For Asp.Net config we made it valid empty string in a hostname,
            // but it will match to nothing.
            if (this.Hostname.Length == 0 || e.Hostname.Length == 0)
            {
                return(false);
            }

            //
            // This is a fix for INADDR_ANY in Bind()
            // if this.Hostname == "0.0.0.0" then it matches only to e.Hostname="*.*.*.*"
            //
            // The reason is to not pass "0.0.0.0" into Resolve()
            if (this.Hostname.Equals("0.0.0.0"))
            {
                if (e.Hostname.Equals("*.*.*.*") || e.Hostname.Equals("0.0.0.0"))
                {
                    return(true);
                }
                return(false);
            }

            if (IsDns && e.IsDns)
            {
                return(String.Compare(hostname, e.hostname, StringComparison.OrdinalIgnoreCase) == 0);
            }
            Resolve();
            e.Resolve();


            if (((address == null) && !wildcard) || ((e.address == null) && !e.wildcard))
            {
                return(false);
            }

            //
            // try matching IP addresses against other wildcard address(es) or
            // wildcard
            //

            if (this.wildcard && !e.wildcard)
            {
                return(false);                           // as a wildcard I cannot be subset of a host.
            }
            else if (e.wildcard)
            {
                if (this.wildcard)
                {
                    // check against my _wildcard_
                    if (MatchWildcard(e.hostname))
                    {
                        return(true);
                    }
                }
                else
                {
                    // check against my _addresses_
                    for (int i = 0; i < address.Length; ++i)
                    {
                        if (e.MatchWildcard(address[i].ToString()))
                        {
                            return(true);
                        }
                    }
                }
            }
            else
            {
                //both are _not_ wildcards
                for (int i = 0; i < address.Length; ++i)
                {
                    for (int j = 0; j < e.address.Length; ++j)
                    {
                        if (address[i].Equals(e.address[j]))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        internal EndpointPermission Intersect(EndpointPermission E)
        {
            String        commonName = null;
            TransportType commonTransport;
            int           commonPort;

            //
            // Look at the transport
            //

            if (transport == E.transport)             // same transport
            {
                commonTransport = transport;
            }
            // NO: check if one of the permissions authorize all transports
            else if (transport == TransportType.All)
            {
                commonTransport = E.transport;
            }
            else if (E.transport == TransportType.All)
            {
                commonTransport = transport;
            }
            else     // transport dont match-- intersection is empty
            {
                return(null);
            }

            //
            // Determine common port
            //

            if (port == E.port)
            {
                commonPort = port;
            }
            else if (port == SocketPermission.AllPorts)
            {
                commonPort = E.port;
            }
            else if (E.port == SocketPermission.AllPorts)
            {
                commonPort = port;
            }
            else
            {
                return(null);
            }

            //Work out common hostname part
            //
            // This is a fix for INADDR_ANY in Bind()
            // if this.Hostname == "0.0.0.0" then it matches only to e.Hostname="*.*.*.*"
            //
            // The reason is to not pass "0.0.0.0" into Resolve()
            if (this.Hostname.Equals("0.0.0.0"))
            {
                if (E.Hostname.Equals("*.*.*.*") || E.Hostname.Equals("0.0.0.0"))
                {
                    commonName = this.Hostname;//i.e. 0.0.0.0
                }
                else
                {
                    return(null);
                }
            }
            else if (E.Hostname.Equals("0.0.0.0"))
            {
                if (this.Hostname.Equals("*.*.*.*") || this.Hostname.Equals("0.0.0.0"))
                {
                    commonName = E.Hostname; //i.e. 0.0.0.0
                }
                else
                {
                    return(null);
                }
            }
            else if (IsDns && E.IsDns)
            {
                //
                // If both are DNS names we compare names as strings
                //
                if (String.Compare(hostname, E.hostname, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    return(null);
                }
                else
                {
                    commonName = hostname;
                }
            }
            else
            {
                Resolve();
                E.Resolve();

                //

                if (((address == null) && !wildcard) || ((E.address == null) && !E.wildcard))
                {
                    return(null);
                }


                //
                // Find intersection of address lists
                if (wildcard && E.wildcard)
                {
                    string [] wcPieces  = hostname.Split(DotSeparator);
                    string [] strPieces = E.hostname.Split(DotSeparator);
                    string    result    = "";

                    if ((strPieces.Length != 4) || (wcPieces.Length != 4))
                    {
                        return(null);
                    }
                    for (int i = 0; i < 4; i++)
                    {
                        if (i != 0)
                        {
                            result += ".";
                        }
                        if (strPieces[i] == wcPieces[i])
                        {
                            result += strPieces[i];
                        }
                        else
                        if (strPieces[i] == "*")
                        {
                            result += wcPieces[i];
                        }
                        else
                        if (wcPieces[i] == "*")
                        {
                            result += strPieces[i];
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    commonName = result;
                }
                else
                if (wildcard)                                                   //if ME is a wildcard
                //
                //
                // Check for wildcard IP matching
                //
                {
                    for (int i = 0; i < E.address.Length; ++i)
                    {
                        if (MatchWildcard(E.address[i].ToString()))
                        {
                            commonName = E.hostname;    //SHE fits into my wildcard
                            break;
                        }
                    }
                }
                else if (E.wildcard)                                     //if SHE is a wildcard
                {
                    for (int i = 0; i < address.Length; ++i)
                    {
                        if (E.MatchWildcard(address[i].ToString()))
                        {
                            commonName = hostname;      //ME fit  into her wildcard
                            break;
                        }
                    }
                }
                else
                {
                    //
                    // Not wildcard: check aginst  IP addresses list
                    //

                    if (address == E.address)                   // they both are NOT null (already checked)
                    {
                        commonName = hostname;
                    }

                    //
                    // Search the IP addresses for match
                    //
                    for (int i = 0; commonName == null && i < address.Length; i++)
                    {
                        for (int k = 0; k < E.address.Length; k++)
                        {
                            if (address[i].Equals(E.address[k]))
                            {
                                commonName = hostname;
                                break;
                            }
                        }
                    }
                }
                if (commonName == null)
                {
                    return(null);
                }
            }

            return(new EndpointPermission(commonName, commonPort, commonTransport));
        }
        internal bool MatchAddress(EndpointPermission e) {

            // For Asp.Net config we made it valid empty string in a hostname,
            // but it will match to nothing.
            if(this.Hostname.Length == 0 || e.Hostname.Length == 0) {
                return false;
            }

            //
            // This is a fix for INADDR_ANY in Bind()
            // if this.Hostname == "0.0.0.0" then it matches only to e.Hostname="*.*.*.*"
            //
            // The reason is to not pass "0.0.0.0" into Resolve()
            if(this.Hostname.Equals("0.0.0.0"))
            {
                if(e.Hostname.Equals("*.*.*.*") || e.Hostname.Equals("0.0.0.0"))
                    return true;
                return false;
            }

            if (IsDns && e.IsDns) {

                //
                // <



                return (String.Compare(hostname, e.hostname, StringComparison.OrdinalIgnoreCase ) == 0);
            }
            Resolve();
            e.Resolve();

            //
            // if Resolve() didn't work for some reason then we're out of luck
            //

            if (((address == null) && !wildcard) || ((e.address == null) && !e.wildcard)) {
                return false;
            }

            //
            // try matching IP addresses against other wildcard address(es) or
            // wildcard
            //

            if (this.wildcard && !e.wildcard) {
                return false;                           // as a wildcard I cannot be subset of a host.

            }
            else if (e.wildcard) {
                if (this.wildcard) {
                    // check against my _wildcard_
                    if (MatchWildcard(e.hostname)) {
                        return true;
                    }
                }
                else {
                    // check against my _addresses_
                    for (int i = 0; i < address.Length; ++i) {
                        if (e.MatchWildcard(address[i].ToString())) {
                            return true;
                        }
                    }
                }
            } else {
                //both are _not_ wildcards
                for (int i = 0; i < address.Length; ++i) {
                    for (int j = 0; j < e.address.Length; ++j) {
                        if (address[i].Equals(e.address[j])) {
                            return true;
                        }
                    }
                }
            }
            return false;
        }
예제 #5
0
        // Internal & Private Methods

        internal bool IsSubsetOf(EndpointPermission perm)
        {
            if (perm == null)
            {
                return(false);
            }

            if (perm.port != SocketPermission.AllPorts &&
                this.port != perm.port)
            {
                return(false);
            }

            if (perm.transport != TransportType.All &&
                this.transport != perm.transport)
            {
                return(false);
            }

            this.Resolve();
            perm.Resolve();

            if (this.hasWildcard)
            {
                if (perm.hasWildcard)
                {
                    return(IsSubsetOf(this.hostname, perm.hostname));
                }
                else
                {
                    return(false);
                }
            }

            if (this.addresses == null)
            {
                return(false);
            }

            if (perm.hasWildcard)
            {
                // a bit dubious... should they all be a subset or is one
                // enough in this case?
                foreach (IPAddress addr in this.addresses)
                {
                    if (IsSubsetOf(addr.ToString(), perm.hostname))
                    {
                        return(true);
                    }
                }
            }

            if (perm.addresses == null)
            {
                return(false);
            }

            // a bit dubious... should they all be a subset or is one
            // enough in this case?
            foreach (IPAddress addr in perm.addresses)
            {
                if (IsSubsetOf(this.hostname, addr.ToString()))
                {
                    return(true);
                }
            }

            return(false);
        }
        internal EndpointPermission Intersect(EndpointPermission E) {

            String commonName=null;
            TransportType commonTransport;
            int commonPort;

            //
            // Look at the transport
            //

            if (transport == E.transport) {           // same transport
                commonTransport = transport;
            }
            // NO: check if one of the permissions authorize all transports
            else if (transport == TransportType.All) {
                commonTransport = E.transport;
            }
            else if (E.transport == TransportType.All) {
                commonTransport = transport;
            }
            else {   // transport dont match-- intersection is empty
                return null;
            }

            //
            // Determine common port
            //

            if (port == E.port) {
                commonPort = port;
            }
            else if (port == SocketPermission.AllPorts) {
                commonPort = E.port;
            }
            else if (E.port == SocketPermission.AllPorts) {
                commonPort = port;
            }
            else {
                return null;
            }

            //Work out common hostname part
            //
            // This is a fix for INADDR_ANY in Bind()
            // if this.Hostname == "0.0.0.0" then it matches only to e.Hostname="*.*.*.*"
            //
            // The reason is to not pass "0.0.0.0" into Resolve()
            if(this.Hostname.Equals("0.0.0.0"))
            {
                if(E.Hostname.Equals("*.*.*.*") || E.Hostname.Equals("0.0.0.0"))
                    commonName = this.Hostname;//i.e. 0.0.0.0
                else
                    return null;
            }
            else if(E.Hostname.Equals("0.0.0.0"))
            {
                if(this.Hostname.Equals("*.*.*.*") || this.Hostname.Equals("0.0.0.0"))
                    commonName = E.Hostname; //i.e. 0.0.0.0
                else
                    return null;
            }
            else if (IsDns && E.IsDns) {
                //
                // If both are DNS names we compare names as strings
                //
                if(String.Compare(hostname, E.hostname, StringComparison.OrdinalIgnoreCase ) != 0) {
                    return null;
                }
                else {
                    commonName = hostname;
                }
            }
            else
            {
                Resolve();
                E.Resolve();
                //after this step we got both clases updated with valid
                //wildcard and address members. It's safe now to access those members directly

                //
                // if Resolve() didn't work for some reason then we're out of luck
                //

                if (((address == null) && !wildcard) || ((E.address == null) && !E.wildcard)) {
                    return null;
                }


                //
                // Find intersection of address lists
                if(wildcard && E.wildcard) {
                    string [] wcPieces = hostname.Split(DotSeparator);
                    string [] strPieces = E.hostname.Split(DotSeparator);
                    string  result="";

                    if ((strPieces.Length != 4) || (wcPieces.Length != 4)) {
                        return null;
                    }
                    for (int i = 0; i < 4; i++) {
                        if(i != 0) {
                            result+=".";
                        }
                        if (strPieces[i] == wcPieces[i]) {
                            result+=strPieces[i];
                        }
                        else
                        if (strPieces[i] == "*") {
                            result+=wcPieces[i];
                        }
                        else
                        if (wcPieces[i] == "*") {
                            result+=strPieces[i];
                        }
                        else
                            return null;
                    }
                    commonName = result;
                }else
                if (wildcard) {                                                 //if ME is a wildcard
                    //
                    //
                    // Check for wildcard IP matching
                    //
                    for (int i = 0; i < E.address.Length; ++i) {
                        if (MatchWildcard(E.address[i].ToString())) {
                            commonName = E.hostname;    //SHE fits into my wildcard
                            break;
                        }
                    }
                }
                else if (E.wildcard) {                                   //if SHE is a wildcard
                    for (int i = 0; i < address.Length; ++i) {
                        if (E.MatchWildcard(address[i].ToString())) {
                            commonName = hostname;      //ME fit  into her wildcard
                            break;
                        }
                    }
                }
                else
                {
                    //
                    // Not wildcard: check aginst  IP addresses list
                    //

                    if (address == E.address) {                 // they both are NOT null (already checked)
                        commonName = hostname;
                    }

                    //
                    // Search the IP addresses for match
                    //
                    for (int i = 0; commonName == null && i < address.Length; i++) {
                        for (int k = 0; k < E.address.Length; k++) {
                            if (address[i].Equals(E.address[k])) {
                                commonName = hostname;
                                break;
                            }
                        }
                    }
                }
                if(commonName == null) {
                    return null;
                }
            }

            return new EndpointPermission(commonName, commonPort, commonTransport);
        }
		private string IntersectHostname (EndpointPermission perm)
		{
			if (this.hostname == perm.hostname)
				return this.hostname;
				
			this.Resolve ();
			perm.Resolve ();
			
			string _hostname = null;
			
			if (this.hasWildcard) {
				if (perm.hasWildcard) {
					_hostname = Intersect (this.hostname, perm.hostname);
				} else if (perm.addresses != null) {
					for (int j = 0; j < perm.addresses.Length; j++) {
						_hostname = Intersect (this.hostname, perm.addresses [j].ToString ());
						if (_hostname != null) 
							break;
					}
				}
			} else if (this.addresses != null) {
				for (int i = 0; i < this.addresses.Length; i++) {
					string thisaddr = this.addresses [i].ToString ();
					if (perm.hasWildcard) {
						_hostname = Intersect (thisaddr, perm.hostname);
					} else if (perm.addresses != null) {
						for (int j = 0; j < perm.addresses.Length; j++) {
							_hostname = Intersect (thisaddr, perm.addresses [j].ToString ());
							if (_hostname != null) 
								break;
						}
					}
				}
			}
			
			return _hostname;
		}
		// Internal & Private Methods
		
		internal bool IsSubsetOf (EndpointPermission perm) 
		{
			if (perm == null)
				return false;
			
			if (perm.port != SocketPermission.AllPorts &&
			    this.port != perm.port)
			    	return false;
			
			if (perm.transport != TransportType.All &&
			    this.transport != perm.transport)
				return false;
			
			this.Resolve ();
			perm.Resolve ();
			
			if (this.hasWildcard) {
				if (perm.hasWildcard)
					return IsSubsetOf (this.hostname, perm.hostname);
				else 
					return false;
			} 
			
			if (this.addresses == null) 
				return false;
			
			if (perm.hasWildcard) 
				// a bit dubious... should they all be a subset or is one 
				// enough in this case?
				foreach (IPAddress addr in this.addresses)
					if (IsSubsetOf (addr.ToString (), perm.hostname))
						return true;
				
			if (perm.addresses == null) 
				return false;
				
			// a bit dubious... should they all be a subset or is one 
			// enough in this case?
			foreach (IPAddress addr in perm.addresses)
				if (IsSubsetOf (this.hostname, addr.ToString ())) 
					return true;	
					
			return false;		
		}		
예제 #9
0
 internal bool MatchAddress(EndpointPermission e)
 {
     if ((this.Hostname.Length != 0) && (e.Hostname.Length != 0))
     {
         if (this.Hostname.Equals("0.0.0.0"))
         {
             if (!e.Hostname.Equals("*.*.*.*") && !e.Hostname.Equals("0.0.0.0"))
             {
                 return(false);
             }
             return(true);
         }
         if (this.IsDns && e.IsDns)
         {
             return(string.Compare(this.hostname, e.hostname, StringComparison.OrdinalIgnoreCase) == 0);
         }
         this.Resolve();
         e.Resolve();
         if (((this.address == null) && !this.wildcard) || ((e.address == null) && !e.wildcard))
         {
             return(false);
         }
         if (this.wildcard && !e.wildcard)
         {
             return(false);
         }
         if (e.wildcard)
         {
             if (this.wildcard)
             {
                 if (this.MatchWildcard(e.hostname))
                 {
                     return(true);
                 }
             }
             else
             {
                 for (int i = 0; i < this.address.Length; i++)
                 {
                     if (e.MatchWildcard(this.address[i].ToString()))
                     {
                         return(true);
                     }
                 }
             }
         }
         else
         {
             for (int j = 0; j < this.address.Length; j++)
             {
                 for (int k = 0; k < e.address.Length; k++)
                 {
                     if (this.address[j].Equals(e.address[k]))
                     {
                         return(true);
                     }
                 }
             }
         }
     }
     return(false);
 }
예제 #10
0
        internal EndpointPermission Intersect(EndpointPermission E)
        {
            string        epname = null;
            TransportType transport;
            int           port;

            if (this.transport == E.transport)
            {
                transport = this.transport;
            }
            else if (this.transport == TransportType.All)
            {
                transport = E.transport;
            }
            else if (E.transport == TransportType.All)
            {
                transport = this.transport;
            }
            else
            {
                return(null);
            }
            if (this.port == E.port)
            {
                port = this.port;
            }
            else if (this.port == -1)
            {
                port = E.port;
            }
            else if (E.port == -1)
            {
                port = this.port;
            }
            else
            {
                return(null);
            }
            if (this.Hostname.Equals("0.0.0.0"))
            {
                if (!E.Hostname.Equals("*.*.*.*") && !E.Hostname.Equals("0.0.0.0"))
                {
                    return(null);
                }
                epname = this.Hostname;
            }
            else if (E.Hostname.Equals("0.0.0.0"))
            {
                if (!this.Hostname.Equals("*.*.*.*") && !this.Hostname.Equals("0.0.0.0"))
                {
                    return(null);
                }
                epname = E.Hostname;
            }
            else if (this.IsDns && E.IsDns)
            {
                if (string.Compare(this.hostname, E.hostname, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    return(null);
                }
                epname = this.hostname;
            }
            else
            {
                this.Resolve();
                E.Resolve();
                if (((this.address == null) && !this.wildcard) || ((E.address == null) && !E.wildcard))
                {
                    return(null);
                }
                if (this.wildcard && E.wildcard)
                {
                    string[] strArray  = this.hostname.Split(DotSeparator);
                    string[] strArray2 = E.hostname.Split(DotSeparator);
                    string   str2      = "";
                    if ((strArray2.Length != 4) || (strArray.Length != 4))
                    {
                        return(null);
                    }
                    for (int i = 0; i < 4; i++)
                    {
                        if (i != 0)
                        {
                            str2 = str2 + ".";
                        }
                        if (strArray2[i] == strArray[i])
                        {
                            str2 = str2 + strArray2[i];
                        }
                        else if (strArray2[i] == "*")
                        {
                            str2 = str2 + strArray[i];
                        }
                        else if (strArray[i] == "*")
                        {
                            str2 = str2 + strArray2[i];
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    epname = str2;
                }
                else if (this.wildcard)
                {
                    for (int j = 0; j < E.address.Length; j++)
                    {
                        if (this.MatchWildcard(E.address[j].ToString()))
                        {
                            epname = E.hostname;
                            break;
                        }
                    }
                }
                else if (E.wildcard)
                {
                    for (int k = 0; k < this.address.Length; k++)
                    {
                        if (E.MatchWildcard(this.address[k].ToString()))
                        {
                            epname = this.hostname;
                            break;
                        }
                    }
                }
                else
                {
                    if (this.address == E.address)
                    {
                        epname = this.hostname;
                    }
                    for (int m = 0; (epname == null) && (m < this.address.Length); m++)
                    {
                        for (int n = 0; n < E.address.Length; n++)
                        {
                            if (this.address[m].Equals(E.address[n]))
                            {
                                epname = this.hostname;
                                break;
                            }
                        }
                    }
                }
                if (epname == null)
                {
                    return(null);
                }
            }
            return(new EndpointPermission(epname, port, transport));
        }