diff --git a/greetd/src/context.rs b/greetd/src/context.rs index 05cc863..f267d93 100644 --- a/greetd/src/context.rs +++ b/greetd/src/context.rs @@ -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()), } } diff --git a/greetd/src/session/conv.rs b/greetd/src/session/conv.rs index e3867c9..2800409 100644 --- a/greetd/src/session/conv.rs +++ b/greetd/src/session/conv.rs @@ -8,7 +8,7 @@ pub struct SessionConv<'a> { } impl<'a> SessionConv<'a> { - fn question(&self, msg: &str, style: AuthMessageType) -> Result { + fn question(&self, msg: &str, style: AuthMessageType) -> Result, ()> { 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 { - self.question(msg, AuthMessageType::Visible) + match self.question(msg, AuthMessageType::Visible) { + Ok(Some(response)) => Ok(response), + _ => Err(()), + } } fn prompt_blind(&self, msg: &str) -> Result { - 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(()), + } } } diff --git a/greetd/src/session/interface.rs b/greetd/src/session/interface.rs index a682fc8..d5e7516 100644 --- a/greetd/src/session/interface.rs +++ b/greetd/src/session/interface.rs @@ -179,11 +179,7 @@ impl Session { /// authentication attempt. pub async fn post_response(&mut self, answer: Option) -> 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), diff --git a/greetd/src/session/worker.rs b/greetd/src/session/worker.rs index c583503..37484dd 100644 --- a/greetd/src/session/worker.rs +++ b/greetd/src/session/worker.rs @@ -32,7 +32,7 @@ pub enum ParentToSessionChild { vt: usize, }, PamResponse { - resp: String, + resp: Option, }, Args { cmd: Vec,