@@ -8,45 +8,79 @@ import (
88
99// LDAP Result Codes
1010const (
11- LDAPResultSuccess = 0
12- LDAPResultOperationsError = 1
13- LDAPResultProtocolError = 2
14- LDAPResultTimeLimitExceeded = 3
15- LDAPResultSizeLimitExceeded = 4
16- LDAPResultCompareFalse = 5
17- LDAPResultCompareTrue = 6
18- LDAPResultAuthMethodNotSupported = 7
19- LDAPResultStrongAuthRequired = 8
20- LDAPResultReferral = 10
21- LDAPResultAdminLimitExceeded = 11
22- LDAPResultUnavailableCriticalExtension = 12
23- LDAPResultConfidentialityRequired = 13
24- LDAPResultSaslBindInProgress = 14
25- LDAPResultNoSuchAttribute = 16
26- LDAPResultUndefinedAttributeType = 17
27- LDAPResultInappropriateMatching = 18
28- LDAPResultConstraintViolation = 19
29- LDAPResultAttributeOrValueExists = 20
30- LDAPResultInvalidAttributeSyntax = 21
31- LDAPResultNoSuchObject = 32
32- LDAPResultAliasProblem = 33
33- LDAPResultInvalidDNSyntax = 34
34- LDAPResultAliasDereferencingProblem = 36
35- LDAPResultInappropriateAuthentication = 48
36- LDAPResultInvalidCredentials = 49
37- LDAPResultInsufficientAccessRights = 50
38- LDAPResultBusy = 51
39- LDAPResultUnavailable = 52
40- LDAPResultUnwillingToPerform = 53
41- LDAPResultLoopDetect = 54
42- LDAPResultNamingViolation = 64
43- LDAPResultObjectClassViolation = 65
44- LDAPResultNotAllowedOnNonLeaf = 66
45- LDAPResultNotAllowedOnRDN = 67
46- LDAPResultEntryAlreadyExists = 68
47- LDAPResultObjectClassModsProhibited = 69
48- LDAPResultAffectsMultipleDSAs = 71
49- LDAPResultOther = 80
11+ LDAPResultSuccess = 0
12+ LDAPResultOperationsError = 1
13+ LDAPResultProtocolError = 2
14+ LDAPResultTimeLimitExceeded = 3
15+ LDAPResultSizeLimitExceeded = 4
16+ LDAPResultCompareFalse = 5
17+ LDAPResultCompareTrue = 6
18+ LDAPResultAuthMethodNotSupported = 7
19+ LDAPResultStrongAuthRequired = 8
20+ LDAPResultReferral = 10
21+ LDAPResultAdminLimitExceeded = 11
22+ LDAPResultUnavailableCriticalExtension = 12
23+ LDAPResultConfidentialityRequired = 13
24+ LDAPResultSaslBindInProgress = 14
25+ LDAPResultNoSuchAttribute = 16
26+ LDAPResultUndefinedAttributeType = 17
27+ LDAPResultInappropriateMatching = 18
28+ LDAPResultConstraintViolation = 19
29+ LDAPResultAttributeOrValueExists = 20
30+ LDAPResultInvalidAttributeSyntax = 21
31+ LDAPResultNoSuchObject = 32
32+ LDAPResultAliasProblem = 33
33+ LDAPResultInvalidDNSyntax = 34
34+ LDAPResultIsLeaf = 35
35+ LDAPResultAliasDereferencingProblem = 36
36+ LDAPResultInappropriateAuthentication = 48
37+ LDAPResultInvalidCredentials = 49
38+ LDAPResultInsufficientAccessRights = 50
39+ LDAPResultBusy = 51
40+ LDAPResultUnavailable = 52
41+ LDAPResultUnwillingToPerform = 53
42+ LDAPResultLoopDetect = 54
43+ LDAPResultSortControlMissing = 60
44+ LDAPResultOffsetRangeError = 61
45+ LDAPResultNamingViolation = 64
46+ LDAPResultObjectClassViolation = 65
47+ LDAPResultNotAllowedOnNonLeaf = 66
48+ LDAPResultNotAllowedOnRDN = 67
49+ LDAPResultEntryAlreadyExists = 68
50+ LDAPResultObjectClassModsProhibited = 69
51+ LDAPResultResultsTooLarge = 70
52+ LDAPResultAffectsMultipleDSAs = 71
53+ LDAPResultVirtualListViewErrorOrControlError = 76
54+ LDAPResultOther = 80
55+ LDAPResultServerDown = 81
56+ LDAPResultLocalError = 82
57+ LDAPResultEncodingError = 83
58+ LDAPResultDecodingError = 84
59+ LDAPResultTimeout = 85
60+ LDAPResultAuthUnknown = 86
61+ LDAPResultFilterError = 87
62+ LDAPResultUserCanceled = 88
63+ LDAPResultParamError = 89
64+ LDAPResultNoMemory = 90
65+ LDAPResultConnectError = 91
66+ LDAPResultNotSupported = 92
67+ LDAPResultControlNotFound = 93
68+ LDAPResultNoResultsReturned = 94
69+ LDAPResultMoreResultsToReturn = 95
70+ LDAPResultClientLoop = 96
71+ LDAPResultReferralLimitExceeded = 97
72+ LDAPResultInvalidResponse = 100
73+ LDAPResultAmbiguousResponse = 101
74+ LDAPResultTLSNotSupported = 112
75+ LDAPResultIntermediateResponse = 113
76+ LDAPResultUnknownType = 114
77+ LDAPResultCanceled = 118
78+ LDAPResultNoSuchOperation = 119
79+ LDAPResultTooLate = 120
80+ LDAPResultCannotCancel = 121
81+ LDAPResultAssertionFailed = 122
82+ LDAPResultAuthorizationDenied = 123
83+ LDAPResultSyncRefreshRequired = 4096
5084
5185 ErrorNetwork = 200
5286 ErrorFilterCompile = 201
@@ -58,46 +92,80 @@ const (
5892)
5993
6094// LDAPResultCodeMap contains string descriptions for LDAP error codes
61- var LDAPResultCodeMap = map [uint8 ]string {
62- LDAPResultSuccess : "Success" ,
63- LDAPResultOperationsError : "Operations Error" ,
64- LDAPResultProtocolError : "Protocol Error" ,
65- LDAPResultTimeLimitExceeded : "Time Limit Exceeded" ,
66- LDAPResultSizeLimitExceeded : "Size Limit Exceeded" ,
67- LDAPResultCompareFalse : "Compare False" ,
68- LDAPResultCompareTrue : "Compare True" ,
69- LDAPResultAuthMethodNotSupported : "Auth Method Not Supported" ,
70- LDAPResultStrongAuthRequired : "Strong Auth Required" ,
71- LDAPResultReferral : "Referral" ,
72- LDAPResultAdminLimitExceeded : "Admin Limit Exceeded" ,
73- LDAPResultUnavailableCriticalExtension : "Unavailable Critical Extension" ,
74- LDAPResultConfidentialityRequired : "Confidentiality Required" ,
75- LDAPResultSaslBindInProgress : "Sasl Bind In Progress" ,
76- LDAPResultNoSuchAttribute : "No Such Attribute" ,
77- LDAPResultUndefinedAttributeType : "Undefined Attribute Type" ,
78- LDAPResultInappropriateMatching : "Inappropriate Matching" ,
79- LDAPResultConstraintViolation : "Constraint Violation" ,
80- LDAPResultAttributeOrValueExists : "Attribute Or Value Exists" ,
81- LDAPResultInvalidAttributeSyntax : "Invalid Attribute Syntax" ,
82- LDAPResultNoSuchObject : "No Such Object" ,
83- LDAPResultAliasProblem : "Alias Problem" ,
84- LDAPResultInvalidDNSyntax : "Invalid DN Syntax" ,
85- LDAPResultAliasDereferencingProblem : "Alias Dereferencing Problem" ,
86- LDAPResultInappropriateAuthentication : "Inappropriate Authentication" ,
87- LDAPResultInvalidCredentials : "Invalid Credentials" ,
88- LDAPResultInsufficientAccessRights : "Insufficient Access Rights" ,
89- LDAPResultBusy : "Busy" ,
90- LDAPResultUnavailable : "Unavailable" ,
91- LDAPResultUnwillingToPerform : "Unwilling To Perform" ,
92- LDAPResultLoopDetect : "Loop Detect" ,
93- LDAPResultNamingViolation : "Naming Violation" ,
94- LDAPResultObjectClassViolation : "Object Class Violation" ,
95- LDAPResultNotAllowedOnNonLeaf : "Not Allowed On Non Leaf" ,
96- LDAPResultNotAllowedOnRDN : "Not Allowed On RDN" ,
97- LDAPResultEntryAlreadyExists : "Entry Already Exists" ,
98- LDAPResultObjectClassModsProhibited : "Object Class Mods Prohibited" ,
99- LDAPResultAffectsMultipleDSAs : "Affects Multiple DSAs" ,
100- LDAPResultOther : "Other" ,
95+ var LDAPResultCodeMap = map [uint16 ]string {
96+ LDAPResultSuccess : "Success" ,
97+ LDAPResultOperationsError : "Operations Error" ,
98+ LDAPResultProtocolError : "Protocol Error" ,
99+ LDAPResultTimeLimitExceeded : "Time Limit Exceeded" ,
100+ LDAPResultSizeLimitExceeded : "Size Limit Exceeded" ,
101+ LDAPResultCompareFalse : "Compare False" ,
102+ LDAPResultCompareTrue : "Compare True" ,
103+ LDAPResultAuthMethodNotSupported : "Auth Method Not Supported" ,
104+ LDAPResultStrongAuthRequired : "Strong Auth Required" ,
105+ LDAPResultReferral : "Referral" ,
106+ LDAPResultAdminLimitExceeded : "Admin Limit Exceeded" ,
107+ LDAPResultUnavailableCriticalExtension : "Unavailable Critical Extension" ,
108+ LDAPResultConfidentialityRequired : "Confidentiality Required" ,
109+ LDAPResultSaslBindInProgress : "Sasl Bind In Progress" ,
110+ LDAPResultNoSuchAttribute : "No Such Attribute" ,
111+ LDAPResultUndefinedAttributeType : "Undefined Attribute Type" ,
112+ LDAPResultInappropriateMatching : "Inappropriate Matching" ,
113+ LDAPResultConstraintViolation : "Constraint Violation" ,
114+ LDAPResultAttributeOrValueExists : "Attribute Or Value Exists" ,
115+ LDAPResultInvalidAttributeSyntax : "Invalid Attribute Syntax" ,
116+ LDAPResultNoSuchObject : "No Such Object" ,
117+ LDAPResultAliasProblem : "Alias Problem" ,
118+ LDAPResultInvalidDNSyntax : "Invalid DN Syntax" ,
119+ LDAPResultIsLeaf : "Is Leaf" ,
120+ LDAPResultAliasDereferencingProblem : "Alias Dereferencing Problem" ,
121+ LDAPResultInappropriateAuthentication : "Inappropriate Authentication" ,
122+ LDAPResultInvalidCredentials : "Invalid Credentials" ,
123+ LDAPResultInsufficientAccessRights : "Insufficient Access Rights" ,
124+ LDAPResultBusy : "Busy" ,
125+ LDAPResultUnavailable : "Unavailable" ,
126+ LDAPResultUnwillingToPerform : "Unwilling To Perform" ,
127+ LDAPResultLoopDetect : "Loop Detect" ,
128+ LDAPResultSortControlMissing : "Sort Control Missing" ,
129+ LDAPResultOffsetRangeError : "Result Offset Range Error" ,
130+ LDAPResultNamingViolation : "Naming Violation" ,
131+ LDAPResultObjectClassViolation : "Object Class Violation" ,
132+ LDAPResultResultsTooLarge : "Results Too Large" ,
133+ LDAPResultNotAllowedOnNonLeaf : "Not Allowed On Non Leaf" ,
134+ LDAPResultNotAllowedOnRDN : "Not Allowed On RDN" ,
135+ LDAPResultEntryAlreadyExists : "Entry Already Exists" ,
136+ LDAPResultObjectClassModsProhibited : "Object Class Mods Prohibited" ,
137+ LDAPResultAffectsMultipleDSAs : "Affects Multiple DSAs" ,
138+ LDAPResultVirtualListViewErrorOrControlError : "Failed because of a problem related to the virtual list view" ,
139+ LDAPResultOther : "Other" ,
140+ LDAPResultServerDown : "Cannot establish a connection" ,
141+ LDAPResultLocalError : "An error occurred" ,
142+ LDAPResultEncodingError : "LDAP encountered an error while encoding" ,
143+ LDAPResultDecodingError : "LDAP encountered an error while decoding" ,
144+ LDAPResultTimeout : "LDAP timeout while waiting for a response from the server" ,
145+ LDAPResultAuthUnknown : "The auth method requested in a bind request is unknown" ,
146+ LDAPResultFilterError : "An error occurred while encoding the given search filter" ,
147+ LDAPResultUserCanceled : "The user canceled the operation" ,
148+ LDAPResultParamError : "An invalid parameter was specified" ,
149+ LDAPResultNoMemory : "Out of memory error" ,
150+ LDAPResultConnectError : "A connection to the server could not be established" ,
151+ LDAPResultNotSupported : "An attempt has been made to use a feature not supported LDAP" ,
152+ LDAPResultControlNotFound : "The controls required to perform the requested operation were not found" ,
153+ LDAPResultNoResultsReturned : "No results were returned from the server" ,
154+ LDAPResultMoreResultsToReturn : "There are more results in the chain of results" ,
155+ LDAPResultClientLoop : "A loop has been detected. For example when following referrals" ,
156+ LDAPResultReferralLimitExceeded : "The referral hop limit has been exceeded" ,
157+ LDAPResultCanceled : "Operation was canceled" ,
158+ LDAPResultNoSuchOperation : "Server has no knowledge of the operation requested for cancellation" ,
159+ LDAPResultTooLate : "Too late to cancel the outstanding operation" ,
160+ LDAPResultCannotCancel : "The identified operation does not support cancellation or the cancel operation cannot be performed" ,
161+ LDAPResultAssertionFailed : "An assertion control given in the LDAP operation evaluated to false causing the operation to not be performed" ,
162+ LDAPResultSyncRefreshRequired : "Refresh Required" ,
163+ LDAPResultInvalidResponse : "Invalid Response" ,
164+ LDAPResultAmbiguousResponse : "Ambiguous Response" ,
165+ LDAPResultTLSNotSupported : "Tls Not Supported" ,
166+ LDAPResultIntermediateResponse : "Intermediate Response" ,
167+ LDAPResultUnknownType : "Unknown Type" ,
168+ LDAPResultAuthorizationDenied : "Authorization Denied" ,
101169
102170 ErrorNetwork : "Network Error" ,
103171 ErrorFilterCompile : "Filter Compile Error" ,
@@ -108,7 +176,7 @@ var LDAPResultCodeMap = map[uint8]string{
108176 ErrorEmptyPassword : "Empty password not allowed by the client" ,
109177}
110178
111- func getLDAPResultCode (packet * ber.Packet ) (code uint8 , description string ) {
179+ func getLDAPResultCode (packet * ber.Packet ) (code uint16 , description string ) {
112180 if packet == nil {
113181 return ErrorUnexpectedResponse , "Empty packet"
114182 } else if len (packet .Children ) >= 2 {
@@ -118,7 +186,7 @@ func getLDAPResultCode(packet *ber.Packet) (code uint8, description string) {
118186 }
119187 if response .ClassType == ber .ClassApplication && response .TagType == ber .TypeConstructed && len (response .Children ) >= 3 {
120188 // Children[1].Children[2] is the diagnosticMessage which is guaranteed to exist as seen here: https://tools.ietf.org/html/rfc4511#section-4.1.9
121- return uint8 (response .Children [0 ].Value .(int64 )), response .Children [2 ].Value .(string )
189+ return uint16 (response .Children [0 ].Value .(int64 )), response .Children [2 ].Value .(string )
122190 }
123191 }
124192
@@ -130,20 +198,20 @@ type Error struct {
130198 // Err is the underlying error
131199 Err error
132200 // ResultCode is the LDAP error code
133- ResultCode uint8
201+ ResultCode uint16
134202}
135203
136204func (e * Error ) Error () string {
137205 return fmt .Sprintf ("LDAP Result Code %d %q: %s" , e .ResultCode , LDAPResultCodeMap [e .ResultCode ], e .Err .Error ())
138206}
139207
140208// NewError creates an LDAP error with the given code and underlying error
141- func NewError (resultCode uint8 , err error ) error {
209+ func NewError (resultCode uint16 , err error ) error {
142210 return & Error {ResultCode : resultCode , Err : err }
143211}
144212
145213// IsErrorWithCode returns true if the given error is an LDAP error with the given result code
146- func IsErrorWithCode (err error , desiredResultCode uint8 ) bool {
214+ func IsErrorWithCode (err error , desiredResultCode uint16 ) bool {
147215 if err == nil {
148216 return false
149217 }
0 commit comments