@@ -321,29 +321,103 @@ class LdapError < StandardError; end
321321
322322 StartTlsOid = "1.3.6.1.4.1.1466.20037"
323323
324+ # https://tools.ietf.org/html/rfc4511#section-4.1.9
325+ # https://tools.ietf.org/html/rfc4511#appendix-A
326+ ResultCodeSuccess = 0
327+ ResultCodeOperationsError = 1
328+ ResultCodeProtocolError = 2
329+ ResultCodeTimeLimitExceeded = 3
330+ ResultCodeSizeLimitExceeded = 4
331+ ResultCodeCompareFalse = 5
332+ ResultCodeCompareTrue = 6
333+ ResultCodeAuthMethodNotSupported = 7
334+ ResultCodeStrongerAuthRequired = 8
335+ ResultCodeReferral = 10
336+ ResultCodeAdminLimitExceeded = 11
337+ ResultCodeUnavailableCriticalExtension = 12
338+ ResultCodeConfidentialityRequired = 13
339+ ResultCodeSaslBindInProgress = 14
340+ ResultCodeNoSuchAttribute = 16
341+ ResultCodeUndefinedAttributeType = 17
342+ ResultCodeInappropriateMatching = 18
343+ ResultCodeConstraintViolation = 19
344+ ResultCodeAttributeOrValueExists = 20
345+ ResultCodeInvalidAttributeSyntax = 21
346+ ResultCodeNoSuchObject = 32
347+ ResultCodeAliasProblem = 33
348+ ResultCodeInvalidDNSyntax = 34
349+ ResultCodeAliasDereferencingProblem = 36
350+ ResultCodeInappropriateAuthentication = 48
351+ ResultCodeInvalidCredentials = 49
352+ ResultCodeInsufficientAccessRights = 50
353+ ResultCodeBusy = 51
354+ ResultCodeUnavailable = 52
355+ ResultCodeUnwillingToPerform = 53
356+ ResultCodeNamingViolation = 64
357+ ResultCodeObjectClassViolation = 65
358+ ResultCodeNotAllowedOnNonLeaf = 66
359+ ResultCodeNotAllowedOnRDN = 67
360+ ResultCodeEntryAlreadyExists = 68
361+ ResultCodeObjectClassModsProhibited = 69
362+ ResultCodeAffectsMultipleDSAs = 71
363+ ResultCodeOther = 80
364+
365+ # https://tools.ietf.org/html/rfc4511#appendix-A.1
366+ ResultCodesNonError = [
367+ ResultCodeSuccess ,
368+ ResultCodeCompareFalse ,
369+ ResultCodeCompareTrue ,
370+ ResultCodeReferral ,
371+ ResultCodeSaslBindInProgress
372+ ]
373+
374+ # nonstandard list of "successful" result codes for searches
375+ ResultCodesSearchSuccess = [
376+ ResultCodeSuccess ,
377+ ResultCodeTimeLimitExceeded ,
378+ ResultCodeSizeLimitExceeded
379+ ]
380+
381+ # map of result code to human message
324382 ResultStrings = {
325- 0 => "Success" ,
326- 1 => "Operations Error" ,
327- 2 => "Protocol Error" ,
328- 3 => "Time Limit Exceeded" ,
329- 4 => "Size Limit Exceeded" ,
330- 10 => "Referral" ,
331- 12 => "Unavailable crtical extension" ,
332- 14 => "saslBindInProgress" ,
333- 16 => "No Such Attribute" ,
334- 17 => "Undefined Attribute Type" ,
335- 19 => "Constraint Violation" ,
336- 20 => "Attribute or Value Exists" ,
337- 32 => "No Such Object" ,
338- 34 => "Invalid DN Syntax" ,
339- 48 => "Inappropriate Authentication" ,
340- 49 => "Invalid Credentials" ,
341- 50 => "Insufficient Access Rights" ,
342- 51 => "Busy" ,
343- 52 => "Unavailable" ,
344- 53 => "Unwilling to perform" ,
345- 65 => "Object Class Violation" ,
346- 68 => "Entry Already Exists"
383+ ResultCodeSuccess => "Success" ,
384+ ResultCodeOperationsError => "Operations Error" ,
385+ ResultCodeProtocolError => "Protocol Error" ,
386+ ResultCodeTimeLimitExceeded => "Time Limit Exceeded" ,
387+ ResultCodeSizeLimitExceeded => "Size Limit Exceeded" ,
388+ ResultCodeCompareFalse => "False Comparison" ,
389+ ResultCodeCompareTrue => "True Comparison" ,
390+ ResultCodeAuthMethodNotSupported => "Auth Method Not Supported" ,
391+ ResultCodeStrongerAuthRequired => "Stronger Auth Needed" ,
392+ ResultCodeReferral => "Referral" ,
393+ ResultCodeAdminLimitExceeded => "Admin Limit Exceeded" ,
394+ ResultCodeUnavailableCriticalExtension => "Unavailable crtical extension" ,
395+ ResultCodeConfidentialityRequired => "Confidentiality Required" ,
396+ ResultCodeSaslBindInProgress => "saslBindInProgress" ,
397+ ResultCodeNoSuchAttribute => "No Such Attribute" ,
398+ ResultCodeUndefinedAttributeType => "Undefined Attribute Type" ,
399+ ResultCodeInappropriateMatching => "Inappropriate Matching" ,
400+ ResultCodeConstraintViolation => "Constraint Violation" ,
401+ ResultCodeAttributeOrValueExists => "Attribute or Value Exists" ,
402+ ResultCodeInvalidAttributeSyntax => "Invalide Attribute Syntax" ,
403+ ResultCodeNoSuchObject => "No Such Object" ,
404+ ResultCodeAliasProblem => "Alias Problem" ,
405+ ResultCodeInvalidDNSyntax => "Invalid DN Syntax" ,
406+ ResultCodeAliasDereferencingProblem => "Alias Dereferencing Problem" ,
407+ ResultCodeInappropriateAuthentication => "Inappropriate Authentication" ,
408+ ResultCodeInvalidCredentials => "Invalid Credentials" ,
409+ ResultCodeInsufficientAccessRights => "Insufficient Access Rights" ,
410+ ResultCodeBusy => "Busy" ,
411+ ResultCodeUnavailable => "Unavailable" ,
412+ ResultCodeUnwillingToPerform => "Unwilling to perform" ,
413+ ResultCodeNamingViolation => "Naming Violation" ,
414+ ResultCodeObjectClassViolation => "Object Class Violation" ,
415+ ResultCodeNotAllowedOnNonLeaf => "Not Allowed On Non-Leaf" ,
416+ ResultCodeNotAllowedOnRDN => "Not Allowed On RDN" ,
417+ ResultCodeEntryAlreadyExists => "Entry Already Exists" ,
418+ ResultCodeObjectClassModsProhibited => "ObjectClass Modifications Prohibited" ,
419+ ResultCodeAffectsMultipleDSAs => "Affects Multiple DSAs" ,
420+ ResultCodeOther => "Other"
347421 }
348422
349423 module LDAPControls
@@ -549,7 +623,7 @@ def get_operation_result
549623 elsif result
550624 os . code = result
551625 else
552- os . code = 0
626+ os . code = Net :: LDAP :: ResultCodeSuccess
553627 end
554628 os . message = Net ::LDAP . result2string ( os . code )
555629 os
@@ -667,7 +741,7 @@ def search(args = {})
667741 :port => @port ,
668742 :encryption => @encryption ,
669743 :instrumentation_service => @instrumentation_service
670- if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == 0
744+ if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == Net :: LDAP :: ResultCodeSuccess
671745 @result = conn . search ( args ) { |entry |
672746 result_set << entry if result_set
673747 yield entry if block_given?
@@ -680,14 +754,7 @@ def search(args = {})
680754
681755 if return_result_set
682756 unless @result . nil?
683- case @result . result_code
684- when ResultStrings . key ( "Success" )
685- # everything good
686- result_set
687- when ResultStrings . key ( "Size Limit Exceeded" ) , ResultStrings . key ( "Time Limit Exceeded" )
688- # LDAP: Size/Time limit exceeded
689- # This happens when we use size option and results are truncated
690- # Still we need to return user results
757+ if ResultCodesSearchSuccess . include? ( @result . result_code )
691758 result_set
692759 end
693760 end
@@ -873,7 +940,7 @@ def add(args)
873940 :port => @port ,
874941 :encryption => @encryption ,
875942 :instrumentation_service => @instrumentation_service
876- if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == 0
943+ if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == Net :: LDAP :: ResultCodeSuccess
877944 @result = conn . add ( args )
878945 end
879946 ensure
@@ -977,7 +1044,7 @@ def modify(args)
9771044 :port => @port ,
9781045 :encryption => @encryption ,
9791046 :instrumentation_service => @instrumentation_service
980- if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == 0
1047+ if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == Net :: LDAP :: ResultCodeSuccess
9811048 @result = conn . modify ( args )
9821049 end
9831050 ensure
@@ -1054,7 +1121,7 @@ def rename(args)
10541121 :port => @port ,
10551122 :encryption => @encryption ,
10561123 :instrumentation_service => @instrumentation_service
1057- if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == 0
1124+ if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == Net :: LDAP :: ResultCodeSuccess
10581125 @result = conn . rename ( args )
10591126 end
10601127 ensure
@@ -1087,7 +1154,7 @@ def delete(args)
10871154 :port => @port ,
10881155 :encryption => @encryption ,
10891156 :instrumentation_service => @instrumentation_service
1090- if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == 0
1157+ if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == Net :: LDAP :: ResultCodeSuccess
10911158 @result = conn . delete ( args )
10921159 end
10931160 ensure
0 commit comments