ldap: Switch to using LdapOp instead of ServerOp
This is in preparation of supporting the password change message, since this is from the Extended Operations that is not available in the simple ServerOp.
This commit is contained in:
committed by
nitnelave
parent
438ac2818a
commit
d423c64d57
@@ -4,10 +4,9 @@ use crate::infra::ldap_handler::LdapHandler;
|
||||
use actix_rt::net::TcpStream;
|
||||
use actix_server::ServerBuilder;
|
||||
use actix_service::{fn_service, ServiceFactoryExt};
|
||||
use anyhow::{bail, Result};
|
||||
use anyhow::{anyhow, bail, Result};
|
||||
use futures_util::future::ok;
|
||||
use ldap3_server::simple::*;
|
||||
use ldap3_server::LdapCodec;
|
||||
use ldap3_server::{proto::LdapMsg, LdapCodec};
|
||||
use log::*;
|
||||
use tokio::net::tcp::WriteHalf;
|
||||
use tokio_util::codec::{FramedRead, FramedWrite};
|
||||
@@ -21,29 +20,19 @@ where
|
||||
Backend: BackendHandler + LoginHandler,
|
||||
{
|
||||
use futures_util::SinkExt;
|
||||
use std::convert::TryFrom;
|
||||
let server_op = match msg
|
||||
.map_err(|e| warn!("Error while receiving LDAP op: {:#}", e))
|
||||
.and_then(ServerOps::try_from)
|
||||
{
|
||||
Ok(a_value) => a_value,
|
||||
Err(an_error) => {
|
||||
let _err = resp
|
||||
.send(DisconnectionNotice::gen(
|
||||
LdapResultCode::Other,
|
||||
"Internal Server Error",
|
||||
))
|
||||
.await;
|
||||
let _err = resp.flush().await;
|
||||
bail!("Internal server error: {:?}", an_error);
|
||||
}
|
||||
};
|
||||
|
||||
match session.handle_ldap_message(server_op).await {
|
||||
let msg = msg.map_err(|e| anyhow!("Error while receiving LDAP op: {:#}", e))?;
|
||||
match session.handle_ldap_message(msg.op).await {
|
||||
None => return Ok(false),
|
||||
Some(result) => {
|
||||
for rmsg in result.into_iter() {
|
||||
if let Err(e) = resp.send(rmsg).await {
|
||||
for result_op in result.into_iter() {
|
||||
if let Err(e) = resp
|
||||
.send(LdapMsg {
|
||||
msgid: msg.msgid,
|
||||
op: result_op,
|
||||
ctrl: vec![],
|
||||
})
|
||||
.await
|
||||
{
|
||||
bail!("Error while sending a response: {:?}", e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user