• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# This file is part of pyasn1-modules software.
3#
4# Copyright (c) 2005-2017, Ilya Etingof <etingof@gmail.com>
5# License: http://pyasn1.sf.net/license.html
6#
7# LDAP message syntax
8#
9# ASN.1 source from:
10# http://www.trl.ibm.com/projects/xml/xss4j/data/asn1/grammars/ldap.asn
11#
12# Sample captures from:
13# http://wiki.wireshark.org/SampleCaptures/
14#
15from pyasn1.type import constraint
16from pyasn1.type import namedtype
17from pyasn1.type import namedval
18from pyasn1.type import tag
19from pyasn1.type import univ
20
21maxInt = univ.Integer(2147483647)
22
23
24class LDAPString(univ.OctetString):
25    pass
26
27
28class LDAPOID(univ.OctetString):
29    pass
30
31
32class LDAPDN(LDAPString):
33    pass
34
35
36class RelativeLDAPDN(LDAPString):
37    pass
38
39
40class AttributeType(LDAPString):
41    pass
42
43
44class AttributeDescription(LDAPString):
45    pass
46
47
48class AttributeDescriptionList(univ.SequenceOf):
49    componentType = AttributeDescription()
50
51
52class AttributeValue(univ.OctetString):
53    pass
54
55
56class AssertionValue(univ.OctetString):
57    pass
58
59
60class AttributeValueAssertion(univ.Sequence):
61    componentType = namedtype.NamedTypes(
62        namedtype.NamedType('attributeDesc', AttributeDescription()),
63        namedtype.NamedType('assertionValue', AssertionValue())
64    )
65
66
67class Attribute(univ.Sequence):
68    componentType = namedtype.NamedTypes(
69        namedtype.NamedType('type', AttributeDescription()),
70        namedtype.NamedType('vals', univ.SetOf(componentType=AttributeValue()))
71    )
72
73
74class MatchingRuleId(LDAPString):
75    pass
76
77
78class Control(univ.Sequence):
79    componentType = namedtype.NamedTypes(
80        namedtype.NamedType('controlType', LDAPOID()),
81        namedtype.DefaultedNamedType('criticality', univ.Boolean('False')),
82        namedtype.OptionalNamedType('controlValue', univ.OctetString())
83    )
84
85
86class Controls(univ.SequenceOf):
87    componentType = Control()
88
89
90class LDAPURL(LDAPString):
91    pass
92
93
94class Referral(univ.SequenceOf):
95    componentType = LDAPURL()
96
97
98class SaslCredentials(univ.Sequence):
99    componentType = namedtype.NamedTypes(
100        namedtype.NamedType('mechanism', LDAPString()),
101        namedtype.OptionalNamedType('credentials', univ.OctetString())
102    )
103
104
105class AuthenticationChoice(univ.Choice):
106    componentType = namedtype.NamedTypes(
107        namedtype.NamedType('simple', univ.OctetString().subtype(
108            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
109        namedtype.NamedType('reserved-1', univ.OctetString().subtype(
110            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
111        namedtype.NamedType('reserved-2', univ.OctetString().subtype(
112            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),
113        namedtype.NamedType('sasl',
114                            SaslCredentials().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3)))
115    )
116
117
118class BindRequest(univ.Sequence):
119    tagSet = univ.Sequence.tagSet.tagImplicitly(
120        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 0)
121    )
122    componentType = namedtype.NamedTypes(
123        namedtype.NamedType('version', univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(1, 127))),
124        namedtype.NamedType('name', LDAPDN()),
125        namedtype.NamedType('authentication', AuthenticationChoice())
126    )
127
128
129class PartialAttributeList(univ.SequenceOf):
130    componentType = univ.Sequence(
131        componentType=namedtype.NamedTypes(
132            namedtype.NamedType('type', AttributeDescription()),
133            namedtype.NamedType('vals', univ.SetOf(componentType=AttributeValue()))
134        )
135    )
136
137
138class SearchResultEntry(univ.Sequence):
139    tagSet = univ.Sequence.tagSet.tagImplicitly(
140        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 4)
141    )
142    componentType = namedtype.NamedTypes(
143        namedtype.NamedType('objectName', LDAPDN()),
144        namedtype.NamedType('attributes', PartialAttributeList())
145    )
146
147
148class MatchingRuleAssertion(univ.Sequence):
149    componentType = namedtype.NamedTypes(
150        namedtype.OptionalNamedType('matchingRule', MatchingRuleId().subtype(
151            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
152        namedtype.OptionalNamedType('type', AttributeDescription().subtype(
153            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),
154        namedtype.NamedType('matchValue',
155                            AssertionValue().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3))),
156        namedtype.DefaultedNamedType('dnAttributes', univ.Boolean('False').subtype(
157            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4)))
158    )
159
160
161class SubstringFilter(univ.Sequence):
162    componentType = namedtype.NamedTypes(
163        namedtype.NamedType('type', AttributeDescription()),
164        namedtype.NamedType('substrings',
165            univ.SequenceOf(
166                componentType=univ.Choice(
167                    componentType=namedtype.NamedTypes(
168                        namedtype.NamedType(
169                            'initial', LDAPString().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))
170                        ),
171                        namedtype.NamedType(
172                            'any', LDAPString().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))
173                        ),
174                        namedtype.NamedType(
175                            'final', LDAPString().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))
176                        )
177                    )
178                )
179            )
180        )
181    )
182
183
184# Ugly hack to handle recursive Filter reference (up to 3-levels deep).
185
186class Filter3(univ.Choice):
187    componentType = namedtype.NamedTypes(
188        namedtype.NamedType('equalityMatch', AttributeValueAssertion().subtype(
189            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3))),
190        namedtype.NamedType('substrings', SubstringFilter().subtype(
191            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 4))),
192        namedtype.NamedType('greaterOrEqual', AttributeValueAssertion().subtype(
193            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 5))),
194        namedtype.NamedType('lessOrEqual', AttributeValueAssertion().subtype(
195            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 6))),
196        namedtype.NamedType('present', AttributeDescription().subtype(
197            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 7))),
198        namedtype.NamedType('approxMatch', AttributeValueAssertion().subtype(
199            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 8))),
200        namedtype.NamedType('extensibleMatch', MatchingRuleAssertion().subtype(
201            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 9)))
202    )
203
204
205class Filter2(univ.Choice):
206    componentType = namedtype.NamedTypes(
207        namedtype.NamedType('and', univ.SetOf(componentType=Filter3()).subtype(
208            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
209        namedtype.NamedType('or', univ.SetOf(componentType=Filter3()).subtype(
210            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))),
211        namedtype.NamedType('not',
212                            Filter3().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2))),
213        namedtype.NamedType('equalityMatch', AttributeValueAssertion().subtype(
214            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3))),
215        namedtype.NamedType('substrings', SubstringFilter().subtype(
216            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 4))),
217        namedtype.NamedType('greaterOrEqual', AttributeValueAssertion().subtype(
218            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 5))),
219        namedtype.NamedType('lessOrEqual', AttributeValueAssertion().subtype(
220            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 6))),
221        namedtype.NamedType('present', AttributeDescription().subtype(
222            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 7))),
223        namedtype.NamedType('approxMatch', AttributeValueAssertion().subtype(
224            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 8))),
225        namedtype.NamedType('extensibleMatch', MatchingRuleAssertion().subtype(
226            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 9)))
227    )
228
229
230class Filter(univ.Choice):
231    componentType = namedtype.NamedTypes(
232        namedtype.NamedType('and', univ.SetOf(componentType=Filter2()).subtype(
233            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
234        namedtype.NamedType('or', univ.SetOf(componentType=Filter2()).subtype(
235            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))),
236        namedtype.NamedType('not',
237                            Filter2().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2))),
238        namedtype.NamedType('equalityMatch', AttributeValueAssertion().subtype(
239            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3))),
240        namedtype.NamedType('substrings', SubstringFilter().subtype(
241            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 4))),
242        namedtype.NamedType('greaterOrEqual', AttributeValueAssertion().subtype(
243            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 5))),
244        namedtype.NamedType('lessOrEqual', AttributeValueAssertion().subtype(
245            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 6))),
246        namedtype.NamedType('present', AttributeDescription().subtype(
247            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 7))),
248        namedtype.NamedType('approxMatch', AttributeValueAssertion().subtype(
249            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 8))),
250        namedtype.NamedType('extensibleMatch', MatchingRuleAssertion().subtype(
251            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 9)))
252    )
253
254
255# End of Filter hack
256
257class SearchRequest(univ.Sequence):
258    tagSet = univ.Sequence.tagSet.tagImplicitly(
259        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 3)
260    )
261    componentType = namedtype.NamedTypes(
262        namedtype.NamedType('baseObject', LDAPDN()),
263        namedtype.NamedType('scope', univ.Enumerated(
264            namedValues=namedval.NamedValues(('baseObject', 0), ('singleLevel', 1), ('wholeSubtree', 2)))),
265        namedtype.NamedType('derefAliases', univ.Enumerated(
266            namedValues=namedval.NamedValues(('neverDerefAliases', 0), ('derefInSearching', 1),
267                                             ('derefFindingBaseObj', 2), ('derefAlways', 3)))),
268        namedtype.NamedType('sizeLimit',
269                            univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, maxInt))),
270        namedtype.NamedType('timeLimit',
271                            univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, maxInt))),
272        namedtype.NamedType('typesOnly', univ.Boolean()),
273        namedtype.NamedType('filter', Filter()),
274        namedtype.NamedType('attributes', AttributeDescriptionList())
275    )
276
277
278class UnbindRequest(univ.Null):
279    tagSet = univ.Sequence.tagSet.tagImplicitly(
280        tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 2)
281    )
282
283
284class BindResponse(univ.Sequence):
285    tagSet = univ.Sequence.tagSet.tagImplicitly(
286        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 1)
287    )
288    componentType = namedtype.NamedTypes(
289        namedtype.NamedType('resultCode', univ.Enumerated(
290            namedValues=namedval.NamedValues(('success', 0), ('operationsError', 1), ('protocolError', 2),
291                                             ('timeLimitExceeded', 3), ('sizeLimitExceeded', 4), ('compareFalse', 5),
292                                             ('compareTrue', 6), ('authMethodNotSupported', 7),
293                                             ('strongAuthRequired', 8), ('reserved-9', 9), ('referral', 10),
294                                             ('adminLimitExceeded', 11), ('unavailableCriticalExtension', 12),
295                                             ('confidentialityRequired', 13), ('saslBindInProgress', 14),
296                                             ('noSuchAttribute', 16), ('undefinedAttributeType', 17),
297                                             ('inappropriateMatching', 18), ('constraintViolation', 19),
298                                             ('attributeOrValueExists', 20), ('invalidAttributeSyntax', 21),
299                                             ('noSuchObject', 32), ('aliasProblem', 33), ('invalidDNSyntax', 34),
300                                             ('reserved-35', 35), ('aliasDereferencingProblem', 36),
301                                             ('inappropriateAuthentication', 48), ('invalidCredentials', 49),
302                                             ('insufficientAccessRights', 50), ('busy', 51), ('unavailable', 52),
303                                             ('unwillingToPerform', 53), ('loopDetect', 54), ('namingViolation', 64),
304                                             ('objectClassViolation', 65), ('notAllowedOnNonLeaf', 66),
305                                             ('notAllowedOnRDN', 67), ('entryAlreadyExists', 68),
306                                             ('objectClassModsProhibited', 69), ('reserved-70', 70),
307                                             ('affectsMultipleDSAs', 71), ('other', 80), ('reserved-81', 81),
308                                             ('reserved-82', 82), ('reserved-83', 83), ('reserved-84', 84),
309                                             ('reserved-85', 85), ('reserved-86', 86), ('reserved-87', 87),
310                                             ('reserved-88', 88), ('reserved-89', 89), ('reserved-90', 90)))),
311        namedtype.NamedType('matchedDN', LDAPDN()),
312        namedtype.NamedType('errorMessage', LDAPString()),
313        namedtype.OptionalNamedType('referral', Referral().subtype(
314            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3))),
315        namedtype.OptionalNamedType('serverSaslCreds', univ.OctetString().subtype(
316            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 7)))
317    )
318
319
320class LDAPResult(univ.Sequence):
321    componentType = namedtype.NamedTypes(
322        namedtype.NamedType('resultCode', univ.Enumerated(
323            namedValues=namedval.NamedValues(('success', 0), ('operationsError', 1), ('protocolError', 2),
324                                             ('timeLimitExceeded', 3), ('sizeLimitExceeded', 4), ('compareFalse', 5),
325                                             ('compareTrue', 6), ('authMethodNotSupported', 7),
326                                             ('strongAuthRequired', 8), ('reserved-9', 9), ('referral', 10),
327                                             ('adminLimitExceeded', 11), ('unavailableCriticalExtension', 12),
328                                             ('confidentialityRequired', 13), ('saslBindInProgress', 14),
329                                             ('noSuchAttribute', 16), ('undefinedAttributeType', 17),
330                                             ('inappropriateMatching', 18), ('constraintViolation', 19),
331                                             ('attributeOrValueExists', 20), ('invalidAttributeSyntax', 21),
332                                             ('noSuchObject', 32), ('aliasProblem', 33), ('invalidDNSyntax', 34),
333                                             ('reserved-35', 35), ('aliasDereferencingProblem', 36),
334                                             ('inappropriateAuthentication', 48), ('invalidCredentials', 49),
335                                             ('insufficientAccessRights', 50), ('busy', 51), ('unavailable', 52),
336                                             ('unwillingToPerform', 53), ('loopDetect', 54), ('namingViolation', 64),
337                                             ('objectClassViolation', 65), ('notAllowedOnNonLeaf', 66),
338                                             ('notAllowedOnRDN', 67), ('entryAlreadyExists', 68),
339                                             ('objectClassModsProhibited', 69), ('reserved-70', 70),
340                                             ('affectsMultipleDSAs', 71), ('other', 80), ('reserved-81', 81),
341                                             ('reserved-82', 82), ('reserved-83', 83), ('reserved-84', 84),
342                                             ('reserved-85', 85), ('reserved-86', 86), ('reserved-87', 87),
343                                             ('reserved-88', 88), ('reserved-89', 89), ('reserved-90', 90)))),
344        namedtype.NamedType('matchedDN', LDAPDN()),
345        namedtype.NamedType('errorMessage', LDAPString()),
346        namedtype.OptionalNamedType('referral', Referral().subtype(
347            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3)))
348    )
349
350
351class SearchResultReference(univ.SequenceOf):
352    tagSet = univ.Sequence.tagSet.tagImplicitly(
353        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 19)
354    )
355    componentType = LDAPURL()
356
357
358class SearchResultDone(LDAPResult):
359    tagSet = univ.Sequence.tagSet.tagImplicitly(
360        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 5)
361    )
362
363
364class AttributeTypeAndValues(univ.Sequence):
365    componentType = namedtype.NamedTypes(
366        namedtype.NamedType('type', AttributeDescription()),
367        namedtype.NamedType('vals', univ.SetOf(componentType=AttributeValue()))
368    )
369
370
371class ModifyRequest(univ.Sequence):
372    tagSet = univ.Sequence.tagSet.tagImplicitly(
373        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 6)
374    )
375    componentType = namedtype.NamedTypes(
376        namedtype.NamedType('object', LDAPDN()),
377        namedtype.NamedType('modification',
378            univ.SequenceOf(
379                componentType=univ.Sequence(
380                    componentType=namedtype.NamedTypes(
381                        namedtype.NamedType(
382                            'operation', univ.Enumerated(namedValues=namedval.NamedValues(('add', 0), ('delete', 1), ('replace', 2)))
383                        ),
384                        namedtype.NamedType('modification', AttributeTypeAndValues())))
385            )
386        )
387    )
388
389
390class ModifyResponse(LDAPResult):
391    tagSet = univ.Sequence.tagSet.tagImplicitly(
392        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 7)
393    )
394
395
396class AttributeList(univ.SequenceOf):
397    componentType = univ.Sequence(
398        componentType=namedtype.NamedTypes(
399           namedtype.NamedType('type', AttributeDescription()),
400           namedtype.NamedType('vals', univ.SetOf(componentType=AttributeValue()))
401        )
402    )
403
404
405class AddRequest(univ.Sequence):
406    tagSet = univ.Sequence.tagSet.tagImplicitly(
407        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 8)
408    )
409    componentType = namedtype.NamedTypes(
410        namedtype.NamedType('entry', LDAPDN()),
411        namedtype.NamedType('attributes', AttributeList())
412    )
413
414
415class AddResponse(LDAPResult):
416    tagSet = univ.Sequence.tagSet.tagImplicitly(
417        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 9)
418    )
419
420
421class DelRequest(LDAPResult):
422    tagSet = univ.Sequence.tagSet.tagImplicitly(
423        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 10)
424    )
425
426
427class DelResponse(LDAPResult):
428    tagSet = univ.Sequence.tagSet.tagImplicitly(
429        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 11)
430    )
431
432
433class ModifyDNRequest(univ.Sequence):
434    tagSet = univ.Sequence.tagSet.tagImplicitly(
435        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 12)
436    )
437    componentType = namedtype.NamedTypes(
438        namedtype.NamedType('entry', LDAPDN()),
439        namedtype.NamedType('newrdn', RelativeLDAPDN()),
440        namedtype.NamedType('deleteoldrdn', univ.Boolean()),
441        namedtype.OptionalNamedType('newSuperior',
442                                    LDAPDN().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0)))
443
444    )
445
446
447class ModifyDNResponse(LDAPResult):
448    tagSet = univ.Sequence.tagSet.tagImplicitly(
449        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 13)
450    )
451
452
453class CompareRequest(univ.Sequence):
454    tagSet = univ.Sequence.tagSet.tagImplicitly(
455        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 14)
456    )
457    componentType = namedtype.NamedTypes(
458        namedtype.NamedType('entry', LDAPDN()),
459        namedtype.NamedType('ava', AttributeValueAssertion())
460    )
461
462
463class CompareResponse(LDAPResult):
464    tagSet = univ.Sequence.tagSet.tagImplicitly(
465        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 15)
466    )
467
468
469class AbandonRequest(LDAPResult):
470    tagSet = univ.Sequence.tagSet.tagImplicitly(
471        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 16)
472    )
473
474
475class ExtendedRequest(univ.Sequence):
476    tagSet = univ.Sequence.tagSet.tagImplicitly(
477        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 23)
478    )
479    componentType = namedtype.NamedTypes(
480        namedtype.NamedType('requestName',
481                            LDAPOID().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
482        namedtype.OptionalNamedType('requestValue', univ.OctetString().subtype(
483            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))
484    )
485
486
487class ExtendedResponse(univ.Sequence):
488    tagSet = univ.Sequence.tagSet.tagImplicitly(
489        tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 24)
490    )
491    componentType = namedtype.NamedTypes(
492        namedtype.NamedType('resultCode', univ.Enumerated(
493            namedValues=namedval.NamedValues(('success', 0), ('operationsError', 1), ('protocolError', 2),
494                                             ('timeLimitExceeded', 3), ('sizeLimitExceeded', 4), ('compareFalse', 5),
495                                             ('compareTrue', 6), ('authMethodNotSupported', 7),
496                                             ('strongAuthRequired', 8), ('reserved-9', 9), ('referral', 10),
497                                             ('adminLimitExceeded', 11), ('unavailableCriticalExtension', 12),
498                                             ('confidentialityRequired', 13), ('saslBindInProgress', 14),
499                                             ('noSuchAttribute', 16), ('undefinedAttributeType', 17),
500                                             ('inappropriateMatching', 18), ('constraintViolation', 19),
501                                             ('attributeOrValueExists', 20), ('invalidAttributeSyntax', 21),
502                                             ('noSuchObject', 32), ('aliasProblem', 33), ('invalidDNSyntax', 34),
503                                             ('reserved-35', 35), ('aliasDereferencingProblem', 36),
504                                             ('inappropriateAuthentication', 48), ('invalidCredentials', 49),
505                                             ('insufficientAccessRights', 50), ('busy', 51), ('unavailable', 52),
506                                             ('unwillingToPerform', 53), ('loopDetect', 54), ('namingViolation', 64),
507                                             ('objectClassViolation', 65), ('notAllowedOnNonLeaf', 66),
508                                             ('notAllowedOnRDN', 67), ('entryAlreadyExists', 68),
509                                             ('objectClassModsProhibited', 69), ('reserved-70', 70),
510                                             ('affectsMultipleDSAs', 71), ('other', 80), ('reserved-81', 81),
511                                             ('reserved-82', 82), ('reserved-83', 83), ('reserved-84', 84),
512                                             ('reserved-85', 85), ('reserved-86', 86), ('reserved-87', 87),
513                                             ('reserved-88', 88), ('reserved-89', 89), ('reserved-90', 90)))),
514        namedtype.NamedType('matchedDN', LDAPDN()),
515        namedtype.NamedType('errorMessage', LDAPString()),
516        namedtype.OptionalNamedType('referral', Referral().subtype(
517            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3))),
518
519        namedtype.OptionalNamedType('responseName', LDAPOID().subtype(
520            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 10))),
521        namedtype.OptionalNamedType('response', univ.OctetString().subtype(
522            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 11)))
523    )
524
525
526class MessageID(univ.Integer):
527    subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(
528        0, maxInt
529    )
530
531
532class LDAPMessage(univ.Sequence):
533    componentType = namedtype.NamedTypes(
534        namedtype.NamedType('messageID', MessageID()),
535        namedtype.NamedType(
536            'protocolOp', univ.Choice(
537                componentType=namedtype.NamedTypes(
538                    namedtype.NamedType('bindRequest', BindRequest()),
539                    namedtype.NamedType('bindResponse', BindResponse()),
540                    namedtype.NamedType('unbindRequest', UnbindRequest()),
541                    namedtype.NamedType('searchRequest', SearchRequest()),
542                    namedtype.NamedType('searchResEntry', SearchResultEntry()),
543                    namedtype.NamedType('searchResDone', SearchResultDone()),
544                    namedtype.NamedType('searchResRef', SearchResultReference()),
545                    namedtype.NamedType('modifyRequest', ModifyRequest()),
546                    namedtype.NamedType('modifyResponse', ModifyResponse()),
547                    namedtype.NamedType('addRequest', AddRequest()),
548                    namedtype.NamedType('addResponse', AddResponse()),
549                    namedtype.NamedType('delRequest', DelRequest()),
550                    namedtype.NamedType('delResponse', DelResponse()),
551                    namedtype.NamedType('modDNRequest', ModifyDNRequest()),
552                    namedtype.NamedType('modDNResponse', ModifyDNResponse()),
553                    namedtype.NamedType('compareRequest', CompareRequest()),
554                    namedtype.NamedType('compareResponse', CompareResponse()),
555                    namedtype.NamedType('abandonRequest', AbandonRequest()),
556                    namedtype.NamedType('extendedReq', ExtendedRequest()),
557                    namedtype.NamedType('extendedResp', ExtendedResponse())
558                )
559            )
560        ),
561        namedtype.OptionalNamedType('controls', Controls().subtype(
562            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0)))
563    )
564