@@ -321,29 +321,103 @@ class LdapError < StandardError; end
321
321
322
322
StartTlsOid = "1.3.6.1.4.1.1466.20037"
323
323
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
324
382
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"
347
421
}
348
422
349
423
module LDAPControls
@@ -549,7 +623,7 @@ def get_operation_result
549
623
elsif result
550
624
os . code = result
551
625
else
552
- os . code = 0
626
+ os . code = Net :: LDAP :: ResultCodeSuccess
553
627
end
554
628
os . message = Net ::LDAP . result2string ( os . code )
555
629
os
@@ -667,7 +741,7 @@ def search(args = {})
667
741
:port => @port ,
668
742
:encryption => @encryption ,
669
743
: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
671
745
@result = conn . search ( args ) { |entry |
672
746
result_set << entry if result_set
673
747
yield entry if block_given?
@@ -680,14 +754,7 @@ def search(args = {})
680
754
681
755
if return_result_set
682
756
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 )
691
758
result_set
692
759
end
693
760
end
@@ -873,7 +940,7 @@ def add(args)
873
940
:port => @port ,
874
941
:encryption => @encryption ,
875
942
: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
877
944
@result = conn . add ( args )
878
945
end
879
946
ensure
@@ -977,7 +1044,7 @@ def modify(args)
977
1044
:port => @port ,
978
1045
:encryption => @encryption ,
979
1046
: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
981
1048
@result = conn . modify ( args )
982
1049
end
983
1050
ensure
@@ -1054,7 +1121,7 @@ def rename(args)
1054
1121
:port => @port ,
1055
1122
:encryption => @encryption ,
1056
1123
: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
1058
1125
@result = conn . rename ( args )
1059
1126
end
1060
1127
ensure
@@ -1087,7 +1154,7 @@ def delete(args)
1087
1154
:port => @port ,
1088
1155
:encryption => @encryption ,
1089
1156
: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
1091
1158
@result = conn . delete ( args )
1092
1159
end
1093
1160
ensure
0 commit comments