Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ldap: implement abandon request - v1 #12390

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions rust/Cargo.lock.in

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/Cargo.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ lazy_static = "~1.4.0"
base64 = "~0.22.1"
bendy = { version = "~0.3.3", default-features = false }
asn1-rs = { version = "~0.6.1" }
ldap-parser = { version = "~0.4.0" }
ldap-parser = { version = "~0.4.1" }
hex = "~0.4.3"

time = "~0.3.36"
Expand Down
15 changes: 2 additions & 13 deletions rust/src/ldap/ldap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,7 @@ impl LdapState {

if self.request_gap {
match ldap_parse_msg(input) {
Ok((_, msg)) => {
let ldap_msg = LdapMessage::from(msg);
if ldap_msg.is_unknown() {
return AppLayerResult::err();
}
Ok((_, _msg)) => {
AppLayerResult::ok();
}
Err(_e) => {
Expand Down Expand Up @@ -264,11 +260,7 @@ impl LdapState {

if self.response_gap {
match ldap_parse_msg(input) {
Ok((_, msg)) => {
let ldap_msg = LdapMessage::from(msg);
if ldap_msg.is_unknown() {
return AppLayerResult::err();
}
Ok((_, _msg)) => {
AppLayerResult::ok();
}
Err(_e) => {
Expand Down Expand Up @@ -518,9 +510,6 @@ fn probe(input: &[u8], direction: Direction, rdir: *mut u8) -> AppProto {
match ldap_parse_msg(input) {
Ok((_, msg)) => {
let ldap_msg = LdapMessage::from(msg);
if ldap_msg.is_unknown() {
return ALPROTO_FAILED;
}
if direction == Direction::ToServer && !ldap_msg.is_request() {
unsafe {
*rdir = Direction::ToClient.into();
Expand Down
24 changes: 13 additions & 11 deletions rust/src/ldap/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ pub struct CompareRequest {
pub ava: AttributeValueAssertion,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AbandonRequest {
pub message_id: u32,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ExtendedRequest {
pub request_name: LdapOID,
Expand Down Expand Up @@ -297,7 +302,7 @@ pub enum ProtocolOp {
ExtendedRequest(ExtendedRequest),
ExtendedResponse(ExtendedResponse),
IntermediateResponse(IntermediateResponse),
Unknown,
AbandonRequest(AbandonRequest),
}

impl Display for ProtocolOp {
Expand All @@ -320,10 +325,10 @@ impl Display for ProtocolOp {
ProtocolOp::ModDnResponse(_) => write!(f, "mod_dn_response"),
ProtocolOp::CompareRequest(_) => write!(f, "compare_request"),
ProtocolOp::CompareResponse(_) => write!(f, "compare_response"),
ProtocolOp::AbandonRequest(_) => write!(f, "abandon_request"),
ProtocolOp::ExtendedRequest(_) => write!(f, "extended_request"),
ProtocolOp::ExtendedResponse(_) => write!(f, "extended_response"),
ProtocolOp::IntermediateResponse(_) => write!(f, "intermediate_response"),
ProtocolOp::Unknown => write!(f, "unknown"),
}
}
}
Expand Down Expand Up @@ -376,7 +381,7 @@ impl From<ldap_parser::ldap::LdapMessage<'_>> for LdapMessage {
ldap_parser::ldap::ProtocolOp::IntermediateResponse(msg) => {
Self::from_intermediate_response(msg)
}
ldap_parser::ldap::ProtocolOp::AbandonRequest(_) => ProtocolOp::Unknown,
ldap_parser::ldap::ProtocolOp::AbandonRequest(msg) => Self::from_abandon_request(msg),
};
let controls = ldap_msg.controls.map(|ctls| {
ctls.iter()
Expand All @@ -397,13 +402,6 @@ impl From<ldap_parser::ldap::LdapMessage<'_>> for LdapMessage {
}

impl LdapMessage {
pub fn is_unknown(&self) -> bool {
match self.protocol_op {
ProtocolOp::Unknown => return true,
_ => return false,
}
}

pub fn is_request(&self) -> bool {
match self.protocol_op {
ProtocolOp::BindRequest(_)
Expand All @@ -414,7 +412,7 @@ impl LdapMessage {
| ProtocolOp::DelRequest(_)
| ProtocolOp::ModDnRequest(_)
| ProtocolOp::CompareRequest(_)
| ProtocolOp::Unknown // AbandonRequest
| ProtocolOp::AbandonRequest(_)
| ProtocolOp::ExtendedRequest(_) => {
return true;
}
Expand Down Expand Up @@ -589,6 +587,10 @@ impl LdapMessage {
})
}

fn from_abandon_request(msg: ldap_parser::ldap::MessageID) -> ProtocolOp {
ProtocolOp::AbandonRequest(AbandonRequest {message_id: msg.0})
}

fn from_extended_request(msg: ldap_parser::ldap::ExtendedRequest) -> ProtocolOp {
ProtocolOp::ExtendedRequest(ExtendedRequest {
request_name: LdapOID(msg.request_name.0.to_string()),
Expand Down
Loading