Revert "Remove 'env' from start_session"

This reverts commit 1bc6ddbf67.
This commit is contained in:
Aleksei Bavshin
2022-08-13 12:16:08 -07:00
committed by Kenny Levinsen
parent 3b7229bacd
commit 2f1810d1a2
8 changed files with 15 additions and 13 deletions

View File

@@ -107,6 +107,7 @@ 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

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

View File

@@ -103,7 +103,7 @@ impl Context {
} }
} }
scheduled_session.send_args(cmd).await?; scheduled_session.send_args(cmd, vec![]).await?;
scheduled_session.start().await scheduled_session.start().await
} }
@@ -253,14 +253,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>) -> Result<(), Error> { pub async fn start(&self, cmd: Vec<String>, env: 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).await?; s.session.send_args(cmd, env).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

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

View File

@@ -193,8 +193,8 @@ impl Session {
/// ///
/// Send the arguments that will be used to start the session. /// Send the arguments that will be used to start the session.
/// ///
pub async fn send_args(&mut self, cmd: Vec<String>) -> Result<(), Error> { pub async fn send_args(&mut self, cmd: Vec<String>, env: Vec<String>) -> Result<(), Error> {
let msg = ParentToSessionChild::Args { cmd }; let msg = ParentToSessionChild::Args { env, 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

@@ -46,6 +46,7 @@ pub enum ParentToSessionChild {
resp: Option<String>, resp: Option<String>,
}, },
Args { Args {
env: Vec<String>,
cmd: Vec<String>, cmd: Vec<String>,
}, },
Start, Start,
@@ -110,8 +111,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 cmd = match ParentToSessionChild::recv(sock)? { let (env, cmd) = match ParentToSessionChild::recv(sock)? {
ParentToSessionChild::Args { cmd } => cmd, ParentToSessionChild::Args { env, cmd } => (env, cmd),
ParentToSessionChild::Cancel => return Err("cancelled".into()), ParentToSessionChild::Cancel => return Err("cancelled".into()),
msg => return Err(format!("expected Args or Cancel, got: {:?}", msg).into()), msg => return Err(format!("expected Args or Cancel, got: {:?}", msg).into()),
}; };
@@ -200,7 +201,7 @@ fn worker(sock: &UnixDatagram) -> Result<(), Error> {
), ),
]; ];
for e in prepared_env.iter() { for e in prepared_env.iter().chain(env.iter()) {
pam.putenv(e)?; pam.putenv(e)?;
} }

View File

@@ -75,7 +75,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> }, StartSession { cmd: Vec<String>, env: 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

@@ -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) : cmd (array of strings), env (array of strings)
: Requests for the session to be started using the provided command line. The session will start after the greeter process terminates. : 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.
| cancel_session | cancel_session
: :
: Cancels the session that is currently under configuration. : Cancels the session that is currently under configuration.