You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2006/09/30 20:53:26 UTC

svn commit: r451636 - /james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java

Author: norman
Date: Sat Sep 30 11:53:26 2006
New Revision: 451636

URL: http://svn.apache.org/viewvc?view=rev&rev=451636
Log:
Catch UnknownHostException when try to resolve ip on init Handler. See JAMES-646

Modified:
    james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java

Modified: james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java?view=diff&rev=451636&r1=451635&r2=451636
==============================================================================
--- james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java (original)
+++ james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java Sat Sep 30 11:53:26 2006
@@ -43,6 +43,7 @@
 import java.io.PrintWriter;
 import java.net.Socket;
 import java.net.SocketException;
+import java.net.UnknownHostException;
 
 /**
  * Common Handler code
@@ -133,7 +134,11 @@
     protected void initHandler( Socket connection ) throws IOException {
         this.socket = connection;
         remoteIP = socket.getInetAddress().getHostAddress();
-        remoteHost = dnsServer.getHostName(socket.getInetAddress());
+        try {
+            remoteHost = dnsServer.getHostName(socket.getInetAddress());
+        } catch (UnknownHostException e) {
+            remoteHost = "unknown";
+        }
         try {
             synchronized (this) {
                 handlerThread = Thread.currentThread();



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


RE: svn commit: r451636 - /james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java

Posted by "Noel J. Bergman" <no...@devtech.com>.
Stefano Bagnara wrote:

> Noel J. Bergman wrote:
>>> mmm... "unknown", [IP] or null (compatibility)? I do not see it very clear 
>>> in http://java.sun.com/j2se/1.5.0/docs/api/java/net/InetAddress.html#getHostName()
>> As I said, InetAddress and dnsjava do not always exhibit the same behavior.
> That's one reason why we only changed JAMES to use dnsjava where proper TTL
> handling was important.  Otherwise, we left it using the standard Java API.
> If we are going to use dnsjava more broadly (and *not* directly in Matchers
> and Mailets), we'll likely encounter additional nuances.

> The problem is that if we use 2 services we'll have 2 caches to monitor 
> and manage and this does not make so much sense.

Agreed.  I'm just pointing out that this isn't as trivial an exercise at would appear.

> We should probably expose more used parameters (hostname/address of the 
> sender) via mailetContext so we can serve them via our DNSService.

That's two separate issues.  One: modifying MailetContext for the common needs, and then how a MailetContext is implemented.  PLEASE remember that we intend for MailetContext to not be JAMES only.

I'm hoping that an enhanced MailetContext for most things, and dnsjava via JNDI for any odd cases, will suffice for portable code, and dnsjava directly for the rest.

> > To answer the question asked by you, Norman and Stefano, see
> >getHostFromNameService in InetAddress.

> Yes, they never return exceptions but catch them and return the hostaddress

:-)

> PS: the java.net class also checks for spoofing running a getAllByName0 
> on the resulting host to check that the IP address is in the list of the 
> forward conversion.

Yes, it does.  The only thing really wrong with the java.net code is the fatally flawed cache handling that renders it useless for our needs.  One of the things I want to check is whether or not the JNDI codepath (calling dnsjava via JNDI) has the same flaw.  I suspect not, which would be good.

	--- Noel



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: svn commit: r451636 - /james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java

Posted by Stefano Bagnara <ap...@bago.org>.
Noel J. Bergman wrote:
>> mmm... "unknown", [IP] or null (compatibility)? I do not see it very clear 
>> in http://java.sun.com/j2se/1.5.0/docs/api/java/net/InetAddress.html#getHostName()
> 
> As I said, InetAddress and dnsjava do not always exhibit the same behavior.  That's one reason why we only changed JAMES to use dnsjava where proper TTL handling was important.  Otherwise, we left it using the standard Java API.  If we are going to use dnsjava more broadly (and *not* directly in Matchers and Mailets), we'll likely encounter additional nuances.

The problem is that if we use 2 services we'll have 2 caches to monitor 
and manage and this does not make so much sense.

We should probably expose more used parameters (hostname/address of the 
sender) via mailetContext so we can serve them via our DNSService.

> To answer the question asked by you, Norman and Stefano, see getHostFromNameService in InetAddress.
> 
> 	--- Noel

Yes, they never return exceptions but catch them and return the hostaddress:
---
} catch (SecurityException e) {
   host = addr.getHostAddress();
} catch (UnknownHostException e) {
   host = addr.getHostAddress();
}
----

If we want to replace it with dnsjava we should make sure we do the same 
to avoid compatibility problems.

PS: the java.net class also checks for spoofing running a getAllByName0 
on the resulting host to check that the IP address is in the list of the 
forward conversion.

Stefano


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: svn commit: r451636 - /james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java

Posted by Norman Maurer <nm...@byteaction.de>.
Stefano Bagnara schrieb:
> Noel J. Bergman wrote:
>>> mmm... "unknown", [IP] or null (compatibility)? I do not see it very 
>>> clear in 
>>> http://java.sun.com/j2se/1.5.0/docs/api/java/net/InetAddress.html#getHostName() 
>>>
>>
>> As I said, InetAddress and dnsjava do not always exhibit the same 
>> behavior.  That's one reason why we only changed JAMES to use dnsjava 
>> where proper TTL handling was important.  Otherwise, we left it using 
>> the standard Java API.  If we are going to use dnsjava more broadly 
>> (and *not* directly in Matchers and Mailets), we'll likely encounter 
>> additional nuances.
>
> The problem is that if we use 2 services we'll have 2 caches to 
> monitor and manage and this does not make so much sense.
I agree.

>
> We should probably expose more used parameters (hostname/address of 
> the sender) via mailetContext so we can serve them via our DNSService.
That make sense. We should also add setter methodes for the DNSService 
to it. So we not bind the mailets/matchers to our code.
>
>> To answer the question asked by you, Norman and Stefano, see 
>> getHostFromNameService in InetAddress.
>>
>>     --- Noel
>
> Yes, they never return exceptions but catch them and return the 
> hostaddress:
> ---
> } catch (SecurityException e) {
>   host = addr.getHostAddress();
> } catch (UnknownHostException e) {
>   host = addr.getHostAddress();
> }
> ----
>
> If we want to replace it with dnsjava we should make sure we do the 
> same to avoid compatibility problems.
Ok that should be no problem.. But for me it whould make more sense to 
return "unknown" as hostname if the host can not resolved. Anyway im ok 
with it.
>
> PS: the java.net class also checks for spoofing running a 
> getAllByName0 on the resulting host to check that the IP address is in 
> the list of the forward conversion.
>
> Stefano
>
bye
Norman



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


RE: svn commit: r451636 - /james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java

Posted by "Noel J. Bergman" <no...@devtech.com>.
> mmm... "unknown", [IP] or null (compatibility)? I do not see it very clear 
> in http://java.sun.com/j2se/1.5.0/docs/api/java/net/InetAddress.html#getHostName()

As I said, InetAddress and dnsjava do not always exhibit the same behavior.  That's one reason why we only changed JAMES to use dnsjava where proper TTL handling was important.  Otherwise, we left it using the standard Java API.  If we are going to use dnsjava more broadly (and *not* directly in Matchers and Mailets), we'll likely encounter additional nuances.

To answer the question asked by you, Norman and Stefano, see getHostFromNameService in InetAddress.

	--- Noel



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: svn commit: r451636 - /james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java

Posted by Guillermo Grandes <gu...@gmail.com>.
mmm... "unknown", [IP] or null (compatibility)? I do not see it very clear 
in
http://java.sun.com/j2se/1.5.0/docs/api/java/net/InetAddress.html#getHostName()

----- Original Message ----- 
From: <no...@apache.org>
To: <se...@james.apache.org>
Sent: Saturday, September 30, 2006 8:53 PM
Subject: svn commit: r451636 -
/james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java


> Author: norman
> Date: Sat Sep 30 11:53:26 2006
> New Revision: 451636
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=451636
> Log:
> Catch UnknownHostException when try to resolve ip on init Handler. See
> JAMES-646
>
> Modified:
>
> james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java
>
> Modified:
> james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java
> URL:
> http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java?view=diff&rev=451636&r1=451635&r2=451636
> ==============================================================================
> ---
> james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java
> (original)
> +++
> james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java
> Sat Sep 30 11:53:26 2006
> @@ -43,6 +43,7 @@
> import java.io.PrintWriter;
> import java.net.Socket;
> import java.net.SocketException;
> +import java.net.UnknownHostException;
>
> /**
>  * Common Handler code
> @@ -133,7 +134,11 @@
>     protected void initHandler( Socket connection ) throws IOException {
>         this.socket = connection;
>         remoteIP = socket.getInetAddress().getHostAddress();
> -        remoteHost = dnsServer.getHostName(socket.getInetAddress());
> +        try {
> +            remoteHost = dnsServer.getHostName(socket.getInetAddress());
> +        } catch (UnknownHostException e) {
> +            remoteHost = "unknown";
> +        }
>         try {
>             synchronized (this) {
>                 handlerThread = Thread.currentThread();
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: svn commit: r451636 - /james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java

Posted by Stefano Bagnara <ap...@bago.org>.
Norman Maurer wrote:
> Same here.. But i think unknown whould be the best we can return.


To avoin backward incompatibilities we should check what 
InetAddress.getHostName was returning when there was no IN PTR record.

Maybe it returns the IP itself.

Stefano


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: svn commit: r451636 - /james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java

Posted by Guillermo Grandes <gu...@gmail.com>.
it could affect of collateral way, some routine that used the name directly, 
that have fallback to IP if hostname missing, mmm... IP better better better 
;-), more secure :-)

----- Original Message ----- 
From: "Norman Maurer" <nm...@byteaction.de>
To: "James Developers List" <se...@james.apache.org>
Sent: Saturday, September 30, 2006 9:34 PM
Subject: Re: svn commit: r451636 - 
/james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java


> Yes it returns the ip. But i think unknown whould be better!
>
> bye
> Norman
>
> Stefano Bagnara schrieb:
>> Norman Maurer wrote:
>>> Same here.. But i think unknown whould be the best we can return.
>>
>>
>> To avoin backward incompatibilities we should check what 
>> InetAddress.getHostName was returning when there was no IN PTR record.
>>
>> Maybe it returns the IP itself.
>>
>> Stefano
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-dev-help@james.apache.org
>>
>> !EXCUBATOR:1,451ec59553072511287336!
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: svn commit: r451636 - /james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java

Posted by Norman Maurer <nm...@byteaction.de>.
Well , i for me unkown is the right. Cause the hostname is "unknown"! 
Anyway i can life with both.

bye
Norman

Guillermo Grandes schrieb:
> it could affect of collateral way, some routine that used the name 
> directly, that have fallback to IP if hostname missing, mmm... IP 
> better better better ;-), more secure :-)
>
> ----- Original Message ----- From: "Norman Maurer" <nm...@byteaction.de>
> To: "James Developers List" <se...@james.apache.org>
> Sent: Saturday, September 30, 2006 9:34 PM
> Subject: Re: svn commit: r451636 - 
> /james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java 
>
>
>
>> Yes it returns the ip. But i think unknown whould be better!
>>
>> bye
>> Norman
>>
>> Stefano Bagnara schrieb:
>>> Norman Maurer wrote:
>>>> Same here.. But i think unknown whould be the best we can return.
>>>
>>>
>>> To avoin backward incompatibilities we should check what 
>>> InetAddress.getHostName was returning when there was no IN PTR record.
>>>
>>> Maybe it returns the IP itself.
>>>
>>> Stefano
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>
>>> !EXCUBATOR:1,451ec59553072511287336!
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-dev-help@james.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>
> !EXCUBATOR:1,451ec91d53071969473845!



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: svn commit: r451636 - /james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java

Posted by Norman Maurer <nm...@byteaction.de>.
Yes it returns the ip. But i think unknown whould be better!

bye
Norman

Stefano Bagnara schrieb:
> Norman Maurer wrote:
>> Same here.. But i think unknown whould be the best we can return.
>
>
> To avoin backward incompatibilities we should check what 
> InetAddress.getHostName was returning when there was no IN PTR record.
>
> Maybe it returns the IP itself.
>
> Stefano
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>
> !EXCUBATOR:1,451ec59553072511287336!



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: svn commit: r451636 - /james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java

Posted by Norman Maurer <nm...@byteaction.de>.
Same here.. But i think unknown whould be the best we can return.

bye
Norman

Guillermo Grandes schrieb:
> mmm... "unknown", [IP] or null (compatibility)? I do not see it very 
> clear in
> http://java.sun.com/j2se/1.5.0/docs/api/java/net/InetAddress.html#getHostName() 
>
>
> ----- Original Message ----- From: <no...@apache.org>
> To: <se...@james.apache.org>
> Sent: Saturday, September 30, 2006 8:53 PM
> Subject: svn commit: r451636 -
> /james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java 
>
>
>
>> Author: norman
>> Date: Sat Sep 30 11:53:26 2006
>> New Revision: 451636
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=451636
>> Log:
>> Catch UnknownHostException when try to resolve ip on init Handler. See
>> JAMES-646
>>
>> Modified:
>>
>> james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java 
>>
>>
>> Modified:
>> james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java 
>>
>> URL:
>> http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java?view=diff&rev=451636&r1=451635&r2=451636 
>>
>> ============================================================================== 
>>
>> ---
>> james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java 
>>
>> (original)
>> +++
>> james/server/trunk/src/java/org/apache/james/core/AbstractJamesHandler.java 
>>
>> Sat Sep 30 11:53:26 2006
>> @@ -43,6 +43,7 @@
>> import java.io.PrintWriter;
>> import java.net.Socket;
>> import java.net.SocketException;
>> +import java.net.UnknownHostException;
>>
>> /**
>>  * Common Handler code
>> @@ -133,7 +134,11 @@
>>     protected void initHandler( Socket connection ) throws IOException {
>>         this.socket = connection;
>>         remoteIP = socket.getInetAddress().getHostAddress();
>> -        remoteHost = dnsServer.getHostName(socket.getInetAddress());
>> +        try {
>> +            remoteHost = 
>> dnsServer.getHostName(socket.getInetAddress());
>> +        } catch (UnknownHostException e) {
>> +            remoteHost = "unknown";
>> +        }
>>         try {
>>             synchronized (this) {
>>                 handlerThread = Thread.currentThread();
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-dev-help@james.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>
> !EXCUBATOR:1,451ec1e853072519838221!



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org