session: Do not cancel on None answer
This commit is contained in:
@@ -65,7 +65,7 @@ impl Context {
|
||||
loop {
|
||||
match scheduled_session.get_state().await {
|
||||
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()),
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ pub struct 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 {
|
||||
style,
|
||||
msg: msg.to_string(),
|
||||
@@ -34,15 +34,27 @@ impl<'a> SessionConv<'a> {
|
||||
|
||||
impl<'a> Converse for SessionConv<'a> {
|
||||
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, ()> {
|
||||
self.question(msg, AuthMessageType::Secret)
|
||||
match self.question(msg, AuthMessageType::Secret) {
|
||||
Ok(Some(response)) => Ok(response),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
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<(), ()> {
|
||||
self.question(msg, AuthMessageType::Error).map(|_| ())
|
||||
match self.question(msg, AuthMessageType::Error) {
|
||||
Ok(None) => Ok(()),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -179,11 +179,7 @@ impl Session {
|
||||
/// authentication attempt.
|
||||
pub async fn post_response(&mut self, answer: Option<String>) -> Result<(), Error> {
|
||||
self.last_msg = None;
|
||||
let msg = match answer {
|
||||
Some(resp) => ParentToSessionChild::PamResponse { resp },
|
||||
None => ParentToSessionChild::Cancel,
|
||||
};
|
||||
msg.send(&mut self.sock).await?;
|
||||
ParentToSessionChild::PamResponse { resp: answer }.send(&mut self.sock).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -221,7 +217,7 @@ impl Session {
|
||||
SessionChildToParent::FinalChildPid(raw_pid) => break Pid::from_raw(raw_pid as i32),
|
||||
SessionChildToParent::PamMessage { 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;
|
||||
}
|
||||
msg => panic!("expected Error or FinalChildPid from session worker, got: {:?}", msg),
|
||||
|
@@ -32,7 +32,7 @@ pub enum ParentToSessionChild {
|
||||
vt: usize,
|
||||
},
|
||||
PamResponse {
|
||||
resp: String,
|
||||
resp: Option<String>,
|
||||
},
|
||||
Args {
|
||||
cmd: Vec<String>,
|
||||
|
Reference in New Issue
Block a user