MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / session_user_and_home

Function session_user_and_home

crates/openshell-supervisor-process/src/ssh.rs:670–689  ·  view source on GitHub ↗

Derive the session USER and HOME from the policy's `run_as_user`. For name-based identities, looks up the home directory via `/etc/passwd` (or defaults to `/home/{user}`). For numeric UIDs, there is no passwd entry — falls back to `("{uid}", "/sandbox")` so the agent session still has a meaningful USER identifier.

(policy: &SandboxPolicy)

Source from the content-addressed store, hash-verified

668/// `("{uid}", "/sandbox")` so the agent session still has a meaningful
669/// USER identifier.
670fn session_user_and_home(policy: &SandboxPolicy) -> (String, String) {
671 match policy.process.run_as_user.as_deref() {
672 Some(user) if !user.is_empty() => {
673 // Numeric UID — no passwd entry expected; use default HOME.
674 if user.parse::<u32>().is_ok() {
675 return (user.to_string(), "/sandbox".to_string());
676 }
677 // Name-based identity — look up home from /etc/passwd.
678 let home = nix::unistd::User::from_name(user)
679 .ok()
680 .flatten()
681 .map_or_else(
682 || format!("/home/{user}"),
683 |u| u.dir.to_string_lossy().into_owned(),
684 );
685 (user.to_string(), home)
686 }
687 _ => ("sandbox".to_string(), "/sandbox".to_string()),
688 }
689}
690
691#[allow(clippy::too_many_arguments)]
692fn apply_child_env(

Calls 1

is_emptyMethod · 0.45