diff --git a/agreety/src/main.rs b/agreety/src/main.rs index d0c2806..0168a71 100644 --- a/agreety/src/main.rs +++ b/agreety/src/main.rs @@ -107,6 +107,7 @@ fn login(node: &str, cmd: &mut Option) -> Result prompt_stderr("Command: ")?, }; next_request = Request::StartSession { + env: vec![], cmd: vec![command.to_string()], } } diff --git a/fakegreet/src/main.rs b/fakegreet/src/main.rs index 0a23c77..187551e 100644 --- a/fakegreet/src/main.rs +++ b/fakegreet/src/main.rs @@ -137,7 +137,7 @@ async fn client_handler(ctx: &Context, mut s: UnixStream) -> Result<(), Error> { 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), }; diff --git a/greetd/src/context.rs b/greetd/src/context.rs index cff0a44..5025015 100644 --- a/greetd/src/context.rs +++ b/greetd/src/context.rs @@ -103,7 +103,7 @@ impl Context { } } - scheduled_session.send_args(cmd).await?; + scheduled_session.send_args(cmd, vec![]).await?; scheduled_session.start().await } @@ -253,14 +253,14 @@ impl Context { } /// Schedule the session under configuration with the provided arguments. - pub async fn start(&self, cmd: Vec) -> Result<(), Error> { + pub async fn start(&self, cmd: Vec, env: Vec) -> Result<(), Error> { let mut session = self.inner.write().await.configuring.take(); match &mut session { Some(s) => match s.session.get_state().await? { SessionState::Ready => { // 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; std::mem::swap(&mut session, &mut inner.scheduled); diff --git a/greetd/src/server.rs b/greetd/src/server.rs index 9dab635..041b64c 100644 --- a/greetd/src/server.rs +++ b/greetd/src/server.rs @@ -85,7 +85,7 @@ async fn client_handler(ctx: &Context, mut s: UnixStream) -> Result<(), Error> { 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), }; diff --git a/greetd/src/session/interface.rs b/greetd/src/session/interface.rs index 805f07a..a52d3f9 100644 --- a/greetd/src/session/interface.rs +++ b/greetd/src/session/interface.rs @@ -193,8 +193,8 @@ impl Session { /// /// Send the arguments that will be used to start the session. /// - pub async fn send_args(&mut self, cmd: Vec) -> Result<(), Error> { - let msg = ParentToSessionChild::Args { cmd }; + pub async fn send_args(&mut self, cmd: Vec, env: Vec) -> Result<(), Error> { + let msg = ParentToSessionChild::Args { env, cmd }; msg.send(&mut self.sock).await?; let msg = SessionChildToParent::recv(&mut self.sock).await?; diff --git a/greetd/src/session/worker.rs b/greetd/src/session/worker.rs index f968968..9e691fa 100644 --- a/greetd/src/session/worker.rs +++ b/greetd/src/session/worker.rs @@ -46,6 +46,7 @@ pub enum ParentToSessionChild { resp: Option, }, Args { + env: Vec, cmd: Vec, }, Start, @@ -110,8 +111,8 @@ fn worker(sock: &UnixDatagram) -> Result<(), Error> { SessionChildToParent::Success.send(sock)?; // Fetch our arguments from the parent. - let cmd = match ParentToSessionChild::recv(sock)? { - ParentToSessionChild::Args { cmd } => cmd, + let (env, cmd) = match ParentToSessionChild::recv(sock)? { + ParentToSessionChild::Args { env, cmd } => (env, cmd), ParentToSessionChild::Cancel => return Err("cancelled".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)?; } diff --git a/greetd_ipc/src/lib.rs b/greetd_ipc/src/lib.rs index a3fdf9d..970e6e8 100644 --- a/greetd_ipc/src/lib.rs +++ b/greetd_ipc/src/lib.rs @@ -75,7 +75,7 @@ pub enum Request { /// Start a successfully logged in session. This will fail if the session /// has pending messages or has encountered an error. - StartSession { cmd: Vec }, + StartSession { cmd: Vec, env: Vec }, /// 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 diff --git a/man/greetd-ipc-7.scd b/man/greetd-ipc-7.scd index 8721918..d1dff3c 100644 --- a/man/greetd-ipc-7.scd +++ b/man/greetd-ipc-7.scd @@ -46,8 +46,8 @@ following hexdump: : 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. | start_session -: cmd (array of strings) -: Requests for the session to be started using the provided command line. The session will start after the greeter process terminates. +: cmd (array of strings), env (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. | cancel_session : : Cancels the session that is currently under configuration.