@ -69,6 +69,7 @@ static mut G_LDAP_REQUEST_DN_BUFFER_ID: c_int = 0;
static mut G_LDAP_RESPONSES_DN_BUFFER_ID : c_int = 0 ;
static mut G_LDAP_RESPONSES_RESULT_CODE_KW_ID : c_int = 0 ;
static mut G_LDAP_RESPONSES_RESULT_CODE_BUFFER_ID : c_int = 0 ;
static mut G_LDAP_RESPONSES_MSG_BUFFER_ID : c_int = 0 ;
unsafe extern "C" fn ldap_parse_protocol_req_op (
ustr : * const std ::os ::raw ::c_char ,
@ -499,6 +500,66 @@ unsafe extern "C" fn ldap_detect_responses_result_code_free(_de: *mut c_void, ct
std ::mem ::drop ( Box ::from_raw ( ctx ) ) ;
}
unsafe extern "C" fn ldap_detect_responses_msg_setup (
de : * mut c_void , s : * mut c_void , _raw : * const std ::os ::raw ::c_char ,
) -> c_int {
if DetectSignatureSetAppProto ( s , ALPROTO_LDAP ) ! = 0 {
return - 1 ;
}
if DetectBufferSetActiveList ( de , s , G_LDAP_RESPONSES_MSG_BUFFER_ID ) < 0 {
return - 1 ;
}
return 0 ;
}
unsafe extern "C" fn ldap_detect_responses_msg_get_data (
de : * mut c_void , transforms : * const c_void , flow : * const c_void , flow_flags : u8 ,
tx : * const c_void , list_id : c_int , local_id : u32 ,
) -> * mut c_void {
return DetectHelperGetMultiData (
de ,
transforms ,
flow ,
flow_flags ,
tx ,
list_id ,
local_id ,
ldap_tx_get_responses_msg ,
) ;
}
unsafe extern "C" fn ldap_tx_get_responses_msg (
tx : * const c_void , _flags : u8 , local_id : u32 , buffer : * mut * const u8 , buffer_len : * mut u32 ,
) -> bool {
let tx = cast_pointer ! ( tx , LdapTransaction ) ;
if local_id as usize > = tx . responses . len ( ) {
return false ;
}
* buffer = std ::ptr ::null ( ) ;
* buffer_len = 0 ;
let response = & tx . responses [ local_id as usize ] ;
// We expect every response in one tx to be the same protocol_op
let str_buffer : & str = match & response . protocol_op {
ProtocolOp ::BindResponse ( resp ) = > resp . result . diagnostic_message . 0. as_str ( ) ,
ProtocolOp ::SearchResultDone ( resp ) = > resp . diagnostic_message . 0. as_str ( ) ,
ProtocolOp ::ModifyResponse ( resp ) = > resp . result . diagnostic_message . 0. as_str ( ) ,
ProtocolOp ::AddResponse ( resp ) = > resp . diagnostic_message . 0. as_str ( ) ,
ProtocolOp ::DelResponse ( resp ) = > resp . diagnostic_message . 0. as_str ( ) ,
ProtocolOp ::ModDnResponse ( resp ) = > resp . diagnostic_message . 0. as_str ( ) ,
ProtocolOp ::CompareResponse ( resp ) = > resp . diagnostic_message . 0. as_str ( ) ,
ProtocolOp ::ExtendedResponse ( resp ) = > resp . result . diagnostic_message . 0. as_str ( ) ,
_ = > "" ,
// This ensures that the iteration continues,
// allowing other responses in the transaction to be processed correctly
} ;
* buffer = str_buffer . as_ptr ( ) ;
* buffer_len = str_buffer . len ( ) as u32 ;
return true ;
}
#[ no_mangle ]
pub unsafe extern "C" fn SCDetectLdapRegister ( ) {
let kw = SCSigTableElmt {
@ -603,4 +664,22 @@ pub unsafe extern "C" fn SCDetectLdapRegister() {
true , //to client
false , //to server
) ;
let kw = SCSigTableElmt {
name : b "ldap.responses.message\0" . as_ptr ( ) as * const libc ::c_char ,
desc : b "match LDAPResult message for responses\0" . as_ptr ( ) as * const libc ::c_char ,
url : b "/rules/ldap-keywords.html#ldap.responses.message\0" . as_ptr ( ) as * const libc ::c_char ,
Setup : ldap_detect_responses_msg_setup ,
flags : SIGMATCH_NOOPT | SIGMATCH_INFO_STICKY_BUFFER ,
AppLayerTxMatch : None ,
Free : None ,
} ;
let _g_ldap_responses_dn_kw_id = DetectHelperKeywordRegister ( & kw ) ;
G_LDAP_RESPONSES_MSG_BUFFER_ID = DetectHelperMultiBufferMpmRegister (
b" ldap.responses.message \0 " . as_ptr ( ) as * const libc ::c_char ,
b" LDAP RESPONSES DISTINGUISHED_NAME \0 " . as_ptr ( ) as * const libc ::c_char ,
ALPROTO_LDAP ,
true , //to client
false , //to server
ldap_detect_responses_msg_get_data ,
) ;
}