directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r436848 - in /directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec: ./ add/ bind/ compare/ del/ modify/ modifyDn/ search/
Date Fri, 25 Aug 2006 16:39:50 GMT
Author: elecharny
Date: Fri Aug 25 09:39:48 2006
New Revision: 436848

URL: http://svn.apache.org/viewvc?rev=436848&view=rev
Log:
Fixed the potentiol hang if a clien send an invalid DN. Now a 
correct Response is send, with an error in LdapResult. This will fix 
DIRSERVER-711, at least partially

Modified:
    directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapResultGrammar.java
    directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/add/AddRequestGrammar.java
    directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/bind/BindRequestGrammar.java
    directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestGrammar.java
    directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/del/DelRequestGrammar.java
    directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestGrammar.java
    directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modifyDn/ModifyDNRequestGrammar.java
    directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchRequestGrammar.java
    directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryGrammar.java

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapResultGrammar.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapResultGrammar.java?rev=436848&r1=436847&r2=436848&view=diff
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapResultGrammar.java
(original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapResultGrammar.java
Fri Aug 25 09:39:48 2006
@@ -276,13 +276,20 @@
                             || ( ldapResult.getResultCode() == LdapResultEnum.INVALID_DN_SYNTAX
)
                             || ( ldapResult.getResultCode() == LdapResultEnum.ALIAS_DEREFERENCING_PROBLEM
) )
                         {
+                            byte[] dnBytes = tlv.getValue().getData();
+                            
                             try
                             {
-                                ldapResult.setMatchedDN( new LdapDN( tlv.getValue().getData()
) );
+                                ldapResult.setMatchedDN( new LdapDN( dnBytes ) );
                             }
                             catch ( InvalidNameException ine )
                             {
-                                log.error( "Incorrect DN given : " + StringTools.dumpBytes(
tlv.getValue().getData() ) );
+                                // This is for the client side. We will never decode LdapResult
on the server
+                                String msg = "Incorrect DN given : " + StringTools.utf8ToString(
dnBytes ) + 
+                                    " (" + StringTools.dumpBytes( dnBytes )
+                                    + ") is invalid";
+                                log.error( "{} : {}", msg, ine.getMessage() );
+                            
                                 throw new DecoderException( "Incorrect DN given : " + ine.getMessage()
);
                             }
                         }

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/add/AddRequestGrammar.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/add/AddRequestGrammar.java?rev=436848&r1=436847&r2=436848&view=diff
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/add/AddRequestGrammar.java
(original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/add/AddRequestGrammar.java
Fri Aug 25 09:39:48 2006
@@ -35,9 +35,12 @@
 import org.apache.directory.shared.ldap.codec.LdapMessage;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.LdapStatesEnum;
+import org.apache.directory.shared.ldap.codec.ResponseCarryingException;
 import org.apache.directory.shared.ldap.codec.util.LdapString;
 import org.apache.directory.shared.ldap.codec.util.LdapStringEncodingException;
 import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeIdentifierException;
+import org.apache.directory.shared.ldap.message.AddResponseImpl;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
@@ -150,17 +153,29 @@
                     else
                     {
                         LdapDN entry = null;
+                        byte[] dnBytes = tlv.getValue().getData();
 
                         try
                         {
-                            entry = new LdapDN( tlv.getValue().getData() );
+                            entry = new LdapDN( dnBytes );
                         }
                         catch ( InvalidNameException ine )
                         {
-                            String msg = "The DN is invalid : " + StringTools.dumpBytes(
tlv.getValue().getData() )
-                                + " : " + ine.getMessage();
+                            String msg = "Invalid DN given : " + StringTools.utf8ToString(
dnBytes ) + 
+                                " (" + StringTools.dumpBytes( dnBytes ) + 
+                                ") is invalid";
                             log.error( "{} : {}", msg, ine.getMessage() );
-                            throw new DecoderException( msg, ine );
+                
+                            AddResponseImpl message = new AddResponseImpl( ldapMessage.getMessageId()
);
+                            message.getLdapResult().setErrorMessage( msg );
+                            message.getLdapResult().setResultCode( ResultCodeEnum.INVALIDDNSYNTAX
);
+                            message.getLdapResult().setMatchedDn( LdapDN.EMPTY_LDAPDN );
+                
+                            ResponseCarryingException exception = new ResponseCarryingException(
msg, ine );
+                
+                            exception.setResponse( message );
+                
+                            throw exception;
                         }
 
                         addRequest.setEntry( entry );

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/bind/BindRequestGrammar.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/bind/BindRequestGrammar.java?rev=436848&r1=436847&r2=436848&view=diff
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/bind/BindRequestGrammar.java
(original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/bind/BindRequestGrammar.java
Fri Aug 25 09:39:48 2006
@@ -37,8 +37,11 @@
 import org.apache.directory.shared.ldap.codec.LdapMessage;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.LdapStatesEnum;
+import org.apache.directory.shared.ldap.codec.ResponseCarryingException;
 import org.apache.directory.shared.ldap.codec.util.LdapString;
 import org.apache.directory.shared.ldap.codec.util.LdapStringEncodingException;
+import org.apache.directory.shared.ldap.message.BindResponseImpl;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
@@ -205,7 +208,8 @@
                 {
 
                     LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
container;
-                    BindRequest bindRequestMessage = ldapMessageContainer.getLdapMessage().getBindRequest();
+                    LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage();
+                    BindRequest bindRequestMessage = ldapMessage.getBindRequest();
 
                     // Get the Value and store it in the BindRequest
                     TLV tlv = ldapMessageContainer.getCurrentTLV();
@@ -218,17 +222,29 @@
                     else
                     {
                         LdapDN name = LdapDN.EMPTY_LDAPDN;
+                        byte[] dnBytes = tlv.getValue().getData();
 
                         try
                         {
-                            name = new LdapDN( tlv.getValue().getData() );
+                            name = new LdapDN( dnBytes );
                         }
                         catch ( InvalidNameException ine )
                         {
-                            String msg = "Incorrect DN given : " + StringTools.dumpBytes(
tlv.getValue().getData() )
-                                + " : " + ine.getMessage();
+                            String msg = "Incorrect DN given : " + StringTools.utf8ToString(
dnBytes ) + 
+                                " (" + StringTools.dumpBytes( dnBytes )
+                                + ") is invalid";
                             log.error( "{} : {}", msg, ine.getMessage() );
-                            throw new DecoderException( msg, ine );
+                        
+                            BindResponseImpl message = new BindResponseImpl( ldapMessage.getMessageId()
);
+                            message.getLdapResult().setErrorMessage( msg );
+                            message.getLdapResult().setResultCode( ResultCodeEnum.INVALIDDNSYNTAX
);
+                            message.getLdapResult().setMatchedDn( LdapDN.EMPTY_LDAPDN );
+                        
+                            ResponseCarryingException exception = new ResponseCarryingException(
msg, ine );
+                        
+                            exception.setResponse( message );
+                        
+                            throw exception;
                         }
 
                         bindRequestMessage.setName( name );

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestGrammar.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestGrammar.java?rev=436848&r1=436847&r2=436848&view=diff
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestGrammar.java
(original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestGrammar.java
Fri Aug 25 09:39:48 2006
@@ -34,8 +34,11 @@
 import org.apache.directory.shared.ldap.codec.LdapMessage;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.LdapStatesEnum;
+import org.apache.directory.shared.ldap.codec.ResponseCarryingException;
 import org.apache.directory.shared.ldap.codec.util.LdapString;
 import org.apache.directory.shared.ldap.codec.util.LdapStringEncodingException;
+import org.apache.directory.shared.ldap.message.CompareResponseImpl;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
@@ -140,16 +143,29 @@
                     }
                     else
                     {
+                        byte[] dnBytes = tlv.getValue().getData();
+                        
                         try
                         {
-                            entry = new LdapDN( tlv.getValue().getData() );
+                            entry = new LdapDN( dnBytes );
                         }
                         catch ( InvalidNameException ine )
                         {
-                            String msg = "The DN to compare  (" + StringTools.dumpBytes(
tlv.getValue().getData() )
-                                + ") is invalid";
+                            String msg = "Invalid DN given : " + StringTools.utf8ToString(
dnBytes ) + 
+                                " (" + StringTools.dumpBytes( dnBytes ) + 
+                                ") is invalid";
                             log.error( "{} : {}", msg, ine.getMessage() );
-                            throw new DecoderException( msg, ine );
+            
+                            CompareResponseImpl message = new CompareResponseImpl( ldapMessage.getMessageId()
);
+                            message.getLdapResult().setErrorMessage( msg );
+                            message.getLdapResult().setResultCode( ResultCodeEnum.INVALIDDNSYNTAX
);
+                            message.getLdapResult().setMatchedDn( LdapDN.EMPTY_LDAPDN );
+            
+                            ResponseCarryingException exception = new ResponseCarryingException(
msg, ine );
+            
+                            exception.setResponse( message );
+            
+                            throw exception;
                         }
 
                         compareRequest.setEntry( entry );

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/del/DelRequestGrammar.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/del/DelRequestGrammar.java?rev=436848&r1=436847&r2=436848&view=diff
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/del/DelRequestGrammar.java
(original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/del/DelRequestGrammar.java
Fri Aug 25 09:39:48 2006
@@ -114,13 +114,16 @@
                     }
                     else
                     {
+                        byte[] dnBytes = tlv.getValue().getData();
+                        
                         try
                         {
-                            entry = new LdapDN( tlv.getValue().getData() );
+                            entry = new LdapDN( dnBytes );
                         }
                         catch ( InvalidNameException ine )
                         {
-                            String msg = "The DN to delete :" + StringTools.utf8ToString(
tlv.getValue().getData() )+ " (" + StringTools.dumpBytes( tlv.getValue().getData() )
+                            String msg = "The DN to delete : " + StringTools.utf8ToString(
dnBytes ) + 
+                                " (" + StringTools.dumpBytes( dnBytes )
                                 + ") is invalid";
                             log.error( "{} : {}", msg, ine.getMessage() );
                             
@@ -135,6 +138,7 @@
                             
                             throw exception;
                         }
+
                         delRequest.setEntry( entry );
                     }
 

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestGrammar.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestGrammar.java?rev=436848&r1=436847&r2=436848&view=diff
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestGrammar.java
(original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestGrammar.java
Fri Aug 25 09:39:48 2006
@@ -36,8 +36,11 @@
 import org.apache.directory.shared.ldap.codec.LdapMessage;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.LdapStatesEnum;
+import org.apache.directory.shared.ldap.codec.ResponseCarryingException;
 import org.apache.directory.shared.ldap.codec.util.LdapString;
 import org.apache.directory.shared.ldap.codec.util.LdapStringEncodingException;
+import org.apache.directory.shared.ldap.message.ModifyResponseImpl;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
@@ -143,17 +146,29 @@
                     }
                     else
                     {
+                        byte[] dnBytes = tlv.getValue().getData();
 
                         try
                         {
-                            object = new LdapDN( tlv.getValue().getData() );
+                            object = new LdapDN( dnBytes );
                         }
                         catch ( InvalidNameException ine )
                         {
-                            String msg = "Invalid DN " + StringTools.dumpBytes( tlv.getValue().getData()
) + ", : "
-                                + ine.getMessage();
+                            String msg = "Invalid DN given : " + StringTools.utf8ToString(
dnBytes ) + 
+                                " (" + StringTools.dumpBytes( dnBytes ) + 
+                                ") is invalid";
                             log.error( "{} : {}", msg, ine.getMessage() );
-                            throw new DecoderException( msg, ine );
+                    
+                            ModifyResponseImpl message = new ModifyResponseImpl( ldapMessage.getMessageId()
);
+                            message.getLdapResult().setErrorMessage( msg );
+                            message.getLdapResult().setResultCode( ResultCodeEnum.INVALIDDNSYNTAX
);
+                            message.getLdapResult().setMatchedDn( LdapDN.EMPTY_LDAPDN );
+                    
+                            ResponseCarryingException exception = new ResponseCarryingException(
msg, ine );
+                    
+                            exception.setResponse( message );
+                    
+                            throw exception;
                         }
 
                         modifyRequest.setObject( object );

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modifyDn/ModifyDNRequestGrammar.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modifyDn/ModifyDNRequestGrammar.java?rev=436848&r1=436847&r2=436848&view=diff
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modifyDn/ModifyDNRequestGrammar.java
(original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/modifyDn/ModifyDNRequestGrammar.java
Fri Aug 25 09:39:48 2006
@@ -37,6 +37,9 @@
 import org.apache.directory.shared.ldap.codec.LdapMessage;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.LdapStatesEnum;
+import org.apache.directory.shared.ldap.codec.ResponseCarryingException;
+import org.apache.directory.shared.ldap.message.ModifyDnResponseImpl;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.util.StringTools;
@@ -144,16 +147,29 @@
                     }
                     else
                     {
+                        byte[] dnBytes = tlv.getValue().getData();
+                        
                         try
                         {
-                            entry = new LdapDN( tlv.getValue().getData() );
+                            entry = new LdapDN( dnBytes );
                         }
                         catch ( InvalidNameException ine )
                         {
-                            String msg = "The DN to modify  (" + StringTools.dumpBytes( tlv.getValue().getData()
)
-                                + ") is invalid";
+                            String msg = "Invalid DN given : " + StringTools.utf8ToString(
dnBytes ) + 
+                                " (" + StringTools.dumpBytes( dnBytes ) + 
+                                ") is invalid";
                             log.error( "{} : {}", msg, ine.getMessage() );
-                            throw new DecoderException( msg, ine );
+        
+                            ModifyDnResponseImpl message = new ModifyDnResponseImpl( ldapMessage.getMessageId()
);
+                            message.getLdapResult().setErrorMessage( msg );
+                            message.getLdapResult().setResultCode( ResultCodeEnum.INVALIDDNSYNTAX
);
+                            message.getLdapResult().setMatchedDn( LdapDN.EMPTY_LDAPDN );
+        
+                            ResponseCarryingException exception = new ResponseCarryingException(
msg, ine );
+        
+                            exception.setResponse( message );
+        
+                            throw exception;
                         }
 
                         modifyDNRequest.setEntry( entry );
@@ -209,17 +225,30 @@
                     }
                     else
                     {
+                        byte[] dnBytes = tlv.getValue().getData();
+                        
                         try
                         {
-                            LdapDN dn = new LdapDN( tlv.getValue().getData() );
+                            LdapDN dn = new LdapDN( dnBytes );
                             newRdn = ( ( LdapDN ) dn ).getRdn( 0 );
                         }
                         catch ( InvalidNameException ine )
                         {
-                            String msg = "The new RDN (" + StringTools.dumpBytes( tlv.getValue().getData()
)
-                                + ") is invalid";
+                            String msg = "Invalid new RDN given : " + StringTools.utf8ToString(
dnBytes ) + 
+                                " (" + StringTools.dumpBytes( dnBytes ) + 
+                                ") is invalid";
                             log.error( "{} : {}", msg, ine.getMessage() );
-                            throw new DecoderException( msg, ine );
+    
+                            ModifyDnResponseImpl message = new ModifyDnResponseImpl( ldapMessage.getMessageId()
);
+                            message.getLdapResult().setErrorMessage( msg );
+                            message.getLdapResult().setResultCode( ResultCodeEnum.INVALIDDNSYNTAX
);
+                            message.getLdapResult().setMatchedDn( LdapDN.EMPTY_LDAPDN );
+    
+                            ResponseCarryingException exception = new ResponseCarryingException(
msg, ine );
+    
+                            exception.setResponse( message );
+    
+                            throw exception;
                         }
 
                         modifyDNRequest.setNewRDN( newRdn );
@@ -352,16 +381,29 @@
                     }
                     else
                     {
+                        byte[] dnBytes = tlv.getValue().getData();
+                        
                         try
                         {
-                            newSuperior = new LdapDN( tlv.getValue().getData() );
+                            newSuperior = new LdapDN( dnBytes );
                         }
                         catch ( InvalidNameException ine )
                         {
-                            String msg = "The new superior DN (" + StringTools.dumpBytes(
tlv.getValue().getData() )
-                                + ") is invalid";
+                            String msg = "Invalid new superior DN given : " + StringTools.utf8ToString(
dnBytes ) + 
+                                " (" + StringTools.dumpBytes( dnBytes ) + 
+                                ") is invalid";
                             log.error( "{} : {}", msg, ine.getMessage() );
-                            throw new DecoderException( msg, ine );
+    
+                            ModifyDnResponseImpl message = new ModifyDnResponseImpl( ldapMessage.getMessageId()
);
+                            message.getLdapResult().setErrorMessage( msg );
+                            message.getLdapResult().setResultCode( ResultCodeEnum.INVALIDDNSYNTAX
);
+                            message.getLdapResult().setMatchedDn( LdapDN.EMPTY_LDAPDN );
+    
+                            ResponseCarryingException exception = new ResponseCarryingException(
msg, ine );
+    
+                            exception.setResponse( message );
+    
+                            throw exception;
                         }
 
                         modifyDNRequest.setNewSuperior( newSuperior );

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchRequestGrammar.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchRequestGrammar.java?rev=436848&r1=436847&r2=436848&view=diff
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchRequestGrammar.java
(original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchRequestGrammar.java
Fri Aug 25 09:39:48 2006
@@ -39,8 +39,11 @@
 import org.apache.directory.shared.ldap.codec.LdapMessage;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.LdapStatesEnum;
+import org.apache.directory.shared.ldap.codec.ResponseCarryingException;
 import org.apache.directory.shared.ldap.codec.util.LdapString;
 import org.apache.directory.shared.ldap.codec.util.LdapStringEncodingException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.message.SearchResponseDoneImpl;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
@@ -132,8 +135,8 @@
                 {
 
                     LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
container;
-
-                    SearchRequest searchRequest = ldapMessageContainer.getLdapMessage().getSearchRequest();
+                    LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage();
+                    SearchRequest searchRequest = ldapMessage.getSearchRequest();
 
                     TLV tlv = ldapMessageContainer.getCurrentTLV();
 
@@ -146,15 +149,29 @@
                     // root.
                     if ( tlv.getLength().getLength() != 0 )
                     {
+                        byte[] dnBytes = tlv.getValue().getData();
+
                         try
                         {
-                            baseObject = new LdapDN( tlv.getValue().getData() );
+                            baseObject = new LdapDN( dnBytes );
                         }
                         catch ( InvalidNameException ine )
                         {
-                            String msg = "The root DN " + baseObject.toString() + " is invalid";
+                            String msg = "Invalid root DN given : " + StringTools.utf8ToString(
dnBytes ) + 
+                                " (" + StringTools.dumpBytes( dnBytes ) +
+                                ") is invalid";
                             log.error( "{} : {}", msg, ine.getMessage() );
-                            throw new DecoderException( msg, ine );
+                    
+                            SearchResponseDoneImpl message = new SearchResponseDoneImpl(
ldapMessage.getMessageId() );
+                            message.getLdapResult().setErrorMessage( msg );
+                            message.getLdapResult().setResultCode( ResultCodeEnum.INVALIDDNSYNTAX
);
+                            message.getLdapResult().setMatchedDn( LdapDN.EMPTY_LDAPDN );
+                    
+                            ResponseCarryingException exception = new ResponseCarryingException(
msg, ine );
+                    
+                            exception.setResponse( message );
+                    
+                            throw exception;
                         }
                     }
 

Modified: directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryGrammar.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryGrammar.java?rev=436848&r1=436847&r2=436848&view=diff
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryGrammar.java
(original)
+++ directory/branches/shared/0.9.5/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/SearchResultEntryGrammar.java
Fri Aug 25 09:39:48 2006
@@ -146,13 +146,16 @@
                     }
                     else
                     {
+                        byte[] dnBytes = tlv.getValue().getData();
+
                         try
                         {
-                            objectName = new LdapDN( tlv.getValue().getData() );
+                            objectName = new LdapDN( dnBytes );
                         }
                         catch ( InvalidNameException ine )
                         {
-                            String msg = "The DN " + StringTools.dumpBytes( tlv.getValue().getData()
)
+                            // This is for the client side. We will never decode LdapResult
on the server
+                            String msg = "The DN " + StringTools.dumpBytes( dnBytes )
                                 + "is invalid : " + ine.getMessage();
                             log.error( "{} : {}", msg, ine.getMessage() );
                             throw new DecoderException( msg, ine );



Mime
View raw message