Remove 'env' from start_session

It was entirely unused, and was complicating a change. It is only
necessary if we need to pass arguments to PAM, as other environment
variables can be loaded by the started command.

This feature can be revisited in the future if it becomes necessary.
This commit is contained in:
Kenny Levinsen
2020-03-30 02:16:31 +02:00
parent b709d2b228
commit 1bc6ddbf67
7 changed files with 11 additions and 14 deletions

View File

@@ -105,7 +105,6 @@ fn login(node: &str, cmd: &mut Option<String>) -> Result<LoginResult, Box<dyn st
None => prompt_stderr("Command: ")?, None => prompt_stderr("Command: ")?,
}; };
next_request = Request::StartSession { next_request = Request::StartSession {
env: vec![],
cmd: vec![command.to_string()], cmd: vec![command.to_string()],
} }
} }

View File

@@ -68,7 +68,7 @@ pub enum Request {
/// Start a successfully logged in session. This will fail if the session /// Start a successfully logged in session. This will fail if the session
/// has pending messages or has encountered an error. /// has pending messages or has encountered an error.
StartSession { cmd: Vec<String>, env: Vec<String> }, StartSession { cmd: Vec<String> },
/// Cancel a session. This can only be done if the session has not been /// Cancel a session. This can only be done if the session has not been
/// started. Cancel does not have to be called if an error has been /// started. Cancel does not have to be called if an error has been

View File

@@ -69,7 +69,7 @@ impl Context {
} }
scheduled_session scheduled_session
.send_args(vec![self.greeter_bin.to_string()], vec![], self.vt) .send_args(vec![self.greeter_bin.to_string()], self.vt)
.await?; .await?;
scheduled_session.start().await scheduled_session.start().await
} }
@@ -168,14 +168,14 @@ impl Context {
} }
/// Schedule the session under configuration with the provided arguments. /// Schedule the session under configuration with the provided arguments.
pub async fn start(&self, cmd: Vec<String>, env: Vec<String>) -> Result<(), Error> { pub async fn start(&self, cmd: Vec<String>) -> Result<(), Error> {
let mut session = self.inner.write().await.configuring.take(); let mut session = self.inner.write().await.configuring.take();
match &mut session { match &mut session {
Some(s) => match s.session.get_state().await? { Some(s) => match s.session.get_state().await? {
SessionState::Ready => { SessionState::Ready => {
// Send our arguments to the session. // Send our arguments to the session.
s.session.send_args(cmd, env, self.vt).await?; s.session.send_args(cmd, self.vt).await?;
let mut inner = self.inner.write().await; let mut inner = self.inner.write().await;
std::mem::swap(&mut session, &mut inner.scheduled); std::mem::swap(&mut session, &mut inner.scheduled);

View File

@@ -68,7 +68,7 @@ async fn client_handler(ctx: &Context, mut s: UnixStream) -> Result<(), Error> {
res => wrap_result(res), res => wrap_result(res),
} }
} }
Request::StartSession { cmd, env } => wrap_result(ctx.start(cmd, env).await), Request::StartSession { cmd } => wrap_result(ctx.start(cmd).await),
Request::CancelSession => wrap_result(ctx.cancel().await), Request::CancelSession => wrap_result(ctx.cancel().await),
}; };

View File

@@ -191,10 +191,9 @@ impl Session {
pub async fn send_args( pub async fn send_args(
&mut self, &mut self,
cmd: Vec<String>, cmd: Vec<String>,
env: Vec<String>,
vt: usize, vt: usize,
) -> Result<(), Error> { ) -> Result<(), Error> {
let msg = ParentToSessionChild::Args { vt, env, cmd }; let msg = ParentToSessionChild::Args { vt, cmd };
msg.send(&mut self.sock).await?; msg.send(&mut self.sock).await?;
let msg = SessionChildToParent::recv(&mut self.sock).await?; let msg = SessionChildToParent::recv(&mut self.sock).await?;

View File

@@ -35,7 +35,6 @@ pub enum ParentToSessionChild {
}, },
Args { Args {
vt: usize, vt: usize,
env: Vec<String>,
cmd: Vec<String>, cmd: Vec<String>,
}, },
Start, Start,
@@ -93,8 +92,8 @@ fn worker(sock: &UnixDatagram) -> Result<(), Error> {
SessionChildToParent::Success.send(sock)?; SessionChildToParent::Success.send(sock)?;
// Fetch our arguments from the parent. // Fetch our arguments from the parent.
let (vt, env, cmd) = match ParentToSessionChild::recv(sock)? { let (vt, cmd) = match ParentToSessionChild::recv(sock)? {
ParentToSessionChild::Args { vt, env, cmd } => (vt, env, cmd), ParentToSessionChild::Args { vt, cmd } => (vt, cmd),
ParentToSessionChild::Cancel => return Err("cancelled".into()), ParentToSessionChild::Cancel => return Err("cancelled".into()),
_ => return Err("unexpected message".into()), _ => return Err("unexpected message".into()),
}; };
@@ -185,7 +184,7 @@ fn worker(sock: &UnixDatagram) -> Result<(), Error> {
), ),
]; ];
for e in prepared_env.iter().chain(env.iter()) { for e in prepared_env.iter() {
pam.putenv(e)?; pam.putenv(e)?;
} }

View File

@@ -46,8 +46,8 @@ following hexdump:
: response (string, optional) : response (string, optional)
: Answers an authentication message. If the message was informative (info, error), then a response does not need to be set in this message. The session is ready to be started if a success is returned. : Answers an authentication message. If the message was informative (info, error), then a response does not need to be set in this message. The session is ready to be started if a success is returned.
| start_session | start_session
: cmd (array of strings), env (array of strings) : cmd (array of strings)
: Requests for the session to be started using the provided command line, adding the supplied environment to that created by PAM. The session will start after the greeter process terminates. : Requests for the session to be started using the provided command line. The session will start after the greeter process terminates.
| cancel_session | cancel_session
: :
: Cancels the session that is currently under configuration. : Cancels the session that is currently under configuration.