rfc2251.py 26 KB

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