async def stdin_bootstrap_path_from_store(store: nix.Store) -> Path: """Get the path to the rsyscall-stdin-bootstrap executable. We return a Path rather than a Command because the typical usage of this path will be to pass it as an argument to some other command, such as sudo. """ rsyscall_path = await store.realise(nix.import_nix_dep("rsyscall")) return rsyscall_path / "libexec" / "rsyscall" / "rsyscall-stdin-bootstrap"
async def make(cls, thread: Thread, store: nix.Store, dir: Path, name: str) -> StubServer: "In the passed-in dir, make a listening stub server and an executable to connect to it." rsyscall_path = await store.realise(nix.import_nix_dep("rsyscall")) stub_path = rsyscall_path / "libexec" / "rsyscall" / "rsyscall-unix-stub" sock_path = dir / f'{name}.sock' server = await StubServer.listen_on(thread, sock_path) # there's no POSIX sh way to set $0, so we'll pass $0 as $1, $1 as $2, etc. # $0 will be the stub executable, so we'll need to drop $0 in StubServer. wrapper = """#!/bin/sh RSYSCALL_UNIX_STUB_SOCK_PATH={sock} exec {bin} "$0" "$@" """.format(sock=os.fsdecode(sock_path), bin=os.fsdecode(stub_path)) await thread.spit(dir / name, wrapper, mode=0o755) return server
from rsyscall.unistd import Pipe __all__ = [ "SSHCommand", "SSHDCommand", "SSHExecutables", "SSHDExecutables", "make_local_ssh_from_executables", "make_ssh_host", "make_local_ssh", ] ssh_bootstrap_script_contents = importlib.resources.read_text('rsyscall.tasks', 'ssh_bootstrap.sh') logger = logging.getLogger(__name__) openssh = nix.import_nix_dep("openssh") T_ssh_command = t.TypeVar('T_ssh_command', bound="SSHCommand") class SSHCommand(Command): "The 'ssh' executable provided by OpenSSH, plus some arguments and special methods" def ssh_options(self, config: t.Mapping[str, t.Union[str, bytes, os.PathLike]]) -> SSHCommand: option_list: t.List[str] = [] for key, value in config.items(): option_list += ["-o", os.fsdecode(key) + "=" + os.fsdecode(value)] return self.args(*option_list) def proxy_command(self, command: Command) -> SSHCommand: return self.ssh_options({'ProxyCommand': command.in_shell_form()}) def local_forward(self, local_socket: Path, remote_socket: str) -> SSHCommand: return self.args("-L", os.fsdecode(local_socket) + ":" + os.fsdecode(remote_socket))
"Miscellaneous Nix dependencies" import rsyscall.nix as nix bash_nixdep = nix.import_nix_dep("bash") coreutils_nixdep = nix.import_nix_dep("coreutils") hello_nixdep = nix.import_nix_dep("hello")
import rsyscall.tasks.local as local from rsyscall.sys.capability import CAP, CapHeader, CapData from rsyscall.sys.socket import AF, SOCK, SOL, Socketpair from rsyscall.sys.prctl import PR, PR_CAP_AMBIENT from rsyscall.fcntl import O from rsyscall.sched import CLONE from rsyscall.netinet.in_ import SockaddrIn from rsyscall.netinet.ip import IP, IPPROTO from rsyscall.linux.netlink import SockaddrNl, NETLINK from rsyscall.linux.rtnetlink import RTMGRP from rsyscall.net.if_ import Ifreq, IFF_TUN, TUNSETIFF, SIOCGIFINDEX import rsyscall.nix as nix miredo_nixdep = nix.import_nix_dep("miredo") @dataclass class MiredoExecutables: run_client: Command privproc: Command @classmethod async def from_store(cls, store: nix.Store) -> MiredoExecutables: miredo_path = await store.realise(miredo_nixdep) return MiredoExecutables( run_client=Command( miredo_path / "libexec" / "miredo" / "miredo-run-client", ["miredo-run-client"], {}), privproc=Command(
async def from_store(cls, store: nix.Store) -> SSHDExecutables: ssh_path = await store.realise(nix.import_nix_dep("openssh")) ssh_keygen = Command(ssh_path / "bin" / "ssh-keygen", ["ssh-keygen"], {}) sshd = SSHDCommand.make(ssh_path / "bin" / "sshd") return SSHDExecutables(ssh_keygen, sshd)
async def from_store(cls, store: nix.Store) -> SSHExecutables: ssh_path = await store.realise(nix.import_nix_dep("openssh")) rsyscall_path = await store.realise(nix.import_nix_dep("rsyscall")) base_ssh = SSHCommand.make(ssh_path / "bin" / "ssh") bootstrap_path = rsyscall_path / "libexec" / "rsyscall" / "rsyscall-bootstrap" return SSHExecutables(base_ssh, bootstrap_path)