Skip to content

Commit aef6ec8

Browse files
authored
20260408 Fixes search handling to allow clients that search without binding. (#140)
1 parent cb04207 commit aef6ec8

4 files changed

Lines changed: 61 additions & 11 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ldap-proxy"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
FROM opensuse/tumbleweed:latest AS ref_repo
22

3-
RUN sed -i -E 's/https?:\/\/download.opensuse.org/https:\/\/mirrorcache.firstyear.id.au/g' /etc/zypp/repos.d/*.repo && \
3+
RUN sed -i -E 's/https?:\/\/download.opensuse.org/http:\/\/suse-updates.int.firstyear.id.au\/opensuse/g' /etc/zypp/repos.d/*.repo && \
44
zypper --gpg-auto-import-keys ref --force
55

66
# // setup the builder pkgs
77
FROM ref_repo AS build_base
8-
RUN zypper install -y cargo rust gcc libopenssl-3-devel sccache perl make gawk
8+
RUN zypper install -y cargo rust gcc sccache
99

1010
# // setup the runner pkgs
1111
FROM ref_repo AS run_base
12-
RUN zypper install -y sqlite3 openssl-3 timezone iputils iproute2 openldap2-client
12+
RUN zypper install -y timezone iputils iproute2 openldap2-client
1313
COPY SUSE_CA_Root.pem /etc/pki/trust/anchors/
1414
RUN /usr/sbin/update-ca-certificates
1515

src/proxy.rs

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ async fn search<W: AsyncWrite + Unpin>(
215215
w: &mut FramedWrite<W, LdapCodec>,
216216
app_state: &AppState,
217217
search_request: SearchRequest<'_>,
218-
) -> Result<Option<ClientState>, LdapError> {
218+
) -> Result<(), LdapError> {
219219
let SearchRequest {
220220
sr,
221221
msgid,
@@ -265,7 +265,7 @@ async fn search<W: AsyncWrite + Unpin>(
265265
LdapError::Transport
266266
})?;
267267

268-
return Ok(None);
268+
return Ok(());
269269
}
270270
};
271271

@@ -328,7 +328,7 @@ async fn search<W: AsyncWrite + Unpin>(
328328
})?;
329329

330330
// Error sent, return with no state change.
331-
return Ok(None);
331+
return Ok(());
332332
}
333333
}
334334
}
@@ -378,7 +378,7 @@ async fn search<W: AsyncWrite + Unpin>(
378378
app_state.cache.try_quiesce();
379379

380380
// No state change
381-
Ok(None)
381+
Ok(())
382382
}
383383

384384
#[instrument(level = "info", skip_all)]
@@ -471,6 +471,56 @@ pub async fn client_process<W: AsyncWrite + Unpin, R: AsyncRead + Unpin>(
471471
break;
472472
}
473473

474+
// Unbound handler
475+
(
476+
ClientState::Unbound,
477+
LdapMsg {
478+
msgid,
479+
op: LdapOp::SearchRequest(sr),
480+
ctrl,
481+
},
482+
) => {
483+
// We have to trigger a bind first in case we have a mapping.
484+
let lbr = LdapBindRequest {
485+
dn: "".to_string(),
486+
cred: LdapBindCred::Simple("".to_string()),
487+
};
488+
489+
let mut next_state = match bind(&mut w, &app_state, lbr, 0, Vec::default()).await {
490+
Ok(ns) => ns,
491+
Err(_) => break,
492+
};
493+
494+
match &mut next_state {
495+
Some(ClientState::Unbound) | None => {
496+
error!("Invalid state, bind did not return an authenticated state!");
497+
break;
498+
}
499+
Some(ClientState::Authenticated {
500+
dn,
501+
display_dn,
502+
config,
503+
ref mut client,
504+
}) => {
505+
let search_req = SearchRequest {
506+
sr,
507+
msgid,
508+
ctrl,
509+
dn,
510+
display_dn,
511+
config,
512+
client,
513+
};
514+
match search(&mut w, &app_state, search_req).await {
515+
Ok(()) => {}
516+
Err(_) => break,
517+
}
518+
}
519+
}
520+
521+
next_state
522+
}
523+
474524
// Authenticated message handler.
475525
// - Search
476526
(
@@ -497,7 +547,7 @@ pub async fn client_process<W: AsyncWrite + Unpin, R: AsyncRead + Unpin>(
497547
};
498548

499549
match search(&mut w, &app_state, search_req).await {
500-
Ok(ns) => ns,
550+
Ok(()) => None,
501551
Err(_) => break,
502552
}
503553
}
@@ -520,7 +570,7 @@ pub async fn client_process<W: AsyncWrite + Unpin, R: AsyncRead + Unpin>(
520570
},
521571
// Unknown message handler.
522572
(_, msg) => {
523-
debug!(?msg);
573+
debug!(?msg, "Invalid message state, triggering disconnection");
524574
// Return a disconnect.
525575
break;
526576
}

0 commit comments

Comments
 (0)