session: Do not cancel on None answer

This commit is contained in:
Kenny Levinsen
2020-03-30 03:33:06 +02:00
parent 3d24916319
commit c9cbf1b9c3
4 changed files with 21 additions and 13 deletions

View File

@@ -65,7 +65,7 @@ impl Context {
loop { loop {
match scheduled_session.get_state().await { match scheduled_session.get_state().await {
Ok(SessionState::Ready) => break, Ok(SessionState::Ready) => break,
Ok(SessionState::Question(_, _)) => scheduled_session.post_response(Some("".to_string())).await?, Ok(SessionState::Question(_, _)) => scheduled_session.post_response(None).await?,
Err(err) => return Err(format!("session start failed: {}", err).into()), Err(err) => return Err(format!("session start failed: {}", err).into()),
} }
} }

View File

@@ -8,7 +8,7 @@ pub struct SessionConv<'a> {
} }
impl<'a> SessionConv<'a> { impl<'a> SessionConv<'a> {
fn question(&self, msg: &str, style: AuthMessageType) -> Result<String, ()> { fn question(&self, msg: &str, style: AuthMessageType) -> Result<Option<String>, ()> {
let msg = SessionChildToParent::PamMessage { let msg = SessionChildToParent::PamMessage {
style, style,
msg: msg.to_string(), msg: msg.to_string(),
@@ -34,15 +34,27 @@ impl<'a> SessionConv<'a> {
impl<'a> Converse for SessionConv<'a> { impl<'a> Converse for SessionConv<'a> {
fn prompt_echo(&self, msg: &str) -> Result<String, ()> { fn prompt_echo(&self, msg: &str) -> Result<String, ()> {
self.question(msg, AuthMessageType::Visible) match self.question(msg, AuthMessageType::Visible) {
Ok(Some(response)) => Ok(response),
_ => Err(()),
}
} }
fn prompt_blind(&self, msg: &str) -> Result<String, ()> { fn prompt_blind(&self, msg: &str) -> Result<String, ()> {
self.question(msg, AuthMessageType::Secret) match self.question(msg, AuthMessageType::Secret) {
Ok(Some(response)) => Ok(response),
_ => Err(()),
}
} }
fn info(&self, msg: &str) -> Result<(), ()> { fn info(&self, msg: &str) -> Result<(), ()> {
self.question(msg, AuthMessageType::Info).map(|_| ()) match self.question(msg, AuthMessageType::Info) {
Ok(None) => Ok(()),
_ => Err(()),
}
} }
fn error(&self, msg: &str) -> Result<(), ()> { fn error(&self, msg: &str) -> Result<(), ()> {
self.question(msg, AuthMessageType::Error).map(|_| ()) match self.question(msg, AuthMessageType::Error) {
Ok(None) => Ok(()),
_ => Err(()),
}
} }
} }

View File

@@ -179,11 +179,7 @@ impl Session {
/// authentication attempt. /// authentication attempt.
pub async fn post_response(&mut self, answer: Option<String>) -> Result<(), Error> { pub async fn post_response(&mut self, answer: Option<String>) -> Result<(), Error> {
self.last_msg = None; self.last_msg = None;
let msg = match answer { ParentToSessionChild::PamResponse { resp: answer }.send(&mut self.sock).await?;
Some(resp) => ParentToSessionChild::PamResponse { resp },
None => ParentToSessionChild::Cancel,
};
msg.send(&mut self.sock).await?;
Ok(()) Ok(())
} }
@@ -221,7 +217,7 @@ impl Session {
SessionChildToParent::FinalChildPid(raw_pid) => break Pid::from_raw(raw_pid as i32), SessionChildToParent::FinalChildPid(raw_pid) => break Pid::from_raw(raw_pid as i32),
SessionChildToParent::PamMessage { style, msg } => { SessionChildToParent::PamMessage { style, msg } => {
eprintln!("pam_conv after start: {:?}, {}", style, msg); eprintln!("pam_conv after start: {:?}, {}", style, msg);
ParentToSessionChild::PamResponse{resp: "".to_string()}.send(&mut self.sock).await?; ParentToSessionChild::PamResponse{resp: None}.send(&mut self.sock).await?;
continue; continue;
} }
msg => panic!("expected Error or FinalChildPid from session worker, got: {:?}", msg), msg => panic!("expected Error or FinalChildPid from session worker, got: {:?}", msg),

View File

@@ -32,7 +32,7 @@ pub enum ParentToSessionChild {
vt: usize, vt: usize,
}, },
PamResponse { PamResponse {
resp: String, resp: Option<String>,
}, },
Args { Args {
cmd: Vec<String>, cmd: Vec<String>,