HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //lib/python3.9/site-packages/cockpit/_vendor/ferny/interaction_client.py
#!/usr/bin/python3

import array
import io
import os
import socket
import sys
from typing import Sequence


def command(stderr_fd: int, command: str, *args: object, fds: Sequence[int] = ()) -> None:
    cmd_read, cmd_write = [io.open(*end) for end in zip(os.pipe(), 'rw')]

    with cmd_write:
        with cmd_read:
            with socket.fromfd(stderr_fd, socket.AF_UNIX, socket.SOCK_STREAM) as sock:
                fd_array = array.array('i', (cmd_read.fileno(), *fds))
                sock.sendmsg([b'\0'], [(socket.SOL_SOCKET, socket.SCM_RIGHTS, fd_array)])

        cmd_write.write(repr((command, args)))


def askpass(stderr_fd: int, stdout_fd: int, args: 'list[str]', env: 'dict[str, str]') -> int:
    ours, theirs = socket.socketpair()

    with theirs:
        command(stderr_fd, 'ferny.askpass', args, env, fds=(theirs.fileno(), stdout_fd))

    with ours:
        return int(ours.recv(16) or b'1')


def main() -> None:
    if len(sys.argv) == 1:
        command(2, 'ferny.end', [])
    else:
        sys.exit(askpass(2, 1, sys.argv, dict(os.environ)))


if __name__ == '__main__':
    main()