| 1037 | |
| 1038 | |
| 1039 | class LDAP(ASN1_Packet): |
| 1040 | ASN1_codec = ASN1_Codecs.BER |
| 1041 | ASN1_root = ASN1F_SEQUENCE( |
| 1042 | ASN1F_INTEGER("messageID", 0), |
| 1043 | ASN1F_CHOICE( |
| 1044 | "protocolOp", |
| 1045 | LDAP_SearchRequest(), |
| 1046 | LDAP_BindRequest, |
| 1047 | LDAP_BindResponse, |
| 1048 | LDAP_SearchRequest, |
| 1049 | LDAP_SearchResponseEntry, |
| 1050 | LDAP_SearchResponseResultDone, |
| 1051 | LDAP_AbandonRequest, |
| 1052 | LDAP_SearchResponseReference, |
| 1053 | LDAP_ModifyRequest, |
| 1054 | LDAP_ModifyResponse, |
| 1055 | LDAP_AddRequest, |
| 1056 | LDAP_AddResponse, |
| 1057 | LDAP_DelRequest, |
| 1058 | LDAP_DelResponse, |
| 1059 | LDAP_ModifyDNRequest, |
| 1060 | LDAP_ModifyDNResponse, |
| 1061 | LDAP_UnbindRequest, |
| 1062 | LDAP_ExtendedResponse, |
| 1063 | ), |
| 1064 | # LDAP v3 only |
| 1065 | ASN1F_optional( |
| 1066 | ASN1F_SEQUENCE_OF("Controls", None, LDAP_Control, implicit_tag=0xA0) |
| 1067 | ), |
| 1068 | ) |
| 1069 | |
| 1070 | show_indent = 0 |
| 1071 | |
| 1072 | @classmethod |
| 1073 | def dispatch_hook(cls, _pkt=None, *args, **kargs): |
| 1074 | if _pkt and len(_pkt) >= 4: |
| 1075 | # Heuristic to detect SASL_Buffer |
| 1076 | if _pkt[0] != 0x30: |
| 1077 | if struct.unpack("!I", _pkt[:4])[0] + 4 == len(_pkt): |
| 1078 | return LDAP_SASL_Buffer |
| 1079 | return conf.raw_layer |
| 1080 | return cls |
| 1081 | |
| 1082 | @classmethod |
| 1083 | def tcp_reassemble(cls, data, *args, **kwargs): |
| 1084 | if len(data) < 4: |
| 1085 | return None |
| 1086 | # For LDAP, we would prefer to have the entire LDAP response |
| 1087 | # (multiple LDAP concatenated) in one go, to stay consistent with |
| 1088 | # what you get when using SASL. |
| 1089 | remaining = data |
| 1090 | while remaining: |
| 1091 | try: |
| 1092 | length, x = BER_len_dec(BER_id_dec(remaining)[1]) |
| 1093 | except (BER_Decoding_Error, IndexError): |
| 1094 | return None |
| 1095 | if length and len(x) >= length: |
| 1096 | remaining = x[length:] |
no test coverage detected
searching dependent graphs…