(
policy: &SandboxPolicy,
workdir: Option<String>,
command: Option<String>,
pty: &PtyRequest,
handle: Handle,
channel: ChannelId,
netns_fd: Option<RawFd>,
proxy_url: Op
| 737 | |
| 738 | #[allow(clippy::too_many_arguments)] |
| 739 | fn spawn_pty_shell( |
| 740 | policy: &SandboxPolicy, |
| 741 | workdir: Option<String>, |
| 742 | command: Option<String>, |
| 743 | pty: &PtyRequest, |
| 744 | handle: Handle, |
| 745 | channel: ChannelId, |
| 746 | netns_fd: Option<RawFd>, |
| 747 | proxy_url: Option<String>, |
| 748 | ca_file_paths: Option<Arc<(PathBuf, PathBuf)>>, |
| 749 | provider_env: &HashMap<String, String>, |
| 750 | user_environment: &HashMap<String, String>, |
| 751 | ) -> anyhow::Result<(std::fs::File, mpsc::Sender<Vec<u8>>)> { |
| 752 | let winsize = Winsize { |
| 753 | ws_row: to_u16(pty.row_height.max(1)), |
| 754 | ws_col: to_u16(pty.col_width.max(1)), |
| 755 | ws_xpixel: to_u16(pty.pixel_width), |
| 756 | ws_ypixel: to_u16(pty.pixel_height), |
| 757 | }; |
| 758 | let openpty = openpty(Some(&winsize), None)?; |
| 759 | let master = std::fs::File::from(openpty.master); |
| 760 | let slave = std::fs::File::from(openpty.slave); |
| 761 | let slave_fd = slave.as_raw_fd(); |
| 762 | |
| 763 | let stdin = slave.try_clone()?; |
| 764 | let stdout = slave.try_clone()?; |
| 765 | let stderr = slave; |
| 766 | let mut reader = master.try_clone()?; |
| 767 | let mut writer = master.try_clone()?; |
| 768 | |
| 769 | let mut cmd = command.map_or_else( |
| 770 | || { |
| 771 | let mut c = Command::new("/bin/bash"); |
| 772 | c.arg("-i"); |
| 773 | c |
| 774 | }, |
| 775 | |command| { |
| 776 | let mut c = Command::new("/bin/bash"); |
| 777 | c.arg("-lc").arg(command); |
| 778 | c |
| 779 | }, |
| 780 | ); |
| 781 | |
| 782 | let term = if pty.term.is_empty() { |
| 783 | "xterm-256color" |
| 784 | } else { |
| 785 | pty.term.as_str() |
| 786 | }; |
| 787 | |
| 788 | // Derive USER and HOME from the policy's run_as_user when available, |
| 789 | // falling back to "sandbox" / "/sandbox" for backward compatibility. |
| 790 | let (session_user, session_home) = session_user_and_home(policy); |
| 791 | apply_child_env( |
| 792 | &mut cmd, |
| 793 | &session_home, |
| 794 | &session_user, |
| 795 | term, |
| 796 | proxy_url.as_deref(), |
no test coverage detected