"""Who can log in to the host, and how they do: napalm-device-types' ``LoginAccountsMixin`` (NetOrk/netork#2707); and the interactive logins it recorded, ``LoginSessionsMixin`` (NetOrk/netork#2881). The commands and their parses are napalm-device-types'; this is only how the commands reach the host. An exec channel, as for the hardening: the report can run to thousands of lines on a host whose btmp is full, more than netmiko's PTY reads reliably. Read-only either way; root for the lock, the expiry and the failed logins, and the mixin falls back to the login user, for the last logins only, where root is refused. The sessions are read as the login user only: the records are readable to everyone, and sudo would drop ``SSH_CONNECTION``, which names the driver's own address. """ from __future__ import annotations from typing import TYPE_CHECKING from napalm_device_types import CommandResult, LoginAccountsMixin, LoginSessionsMixin #: Seconds the reading may take: ``lastb`` reads all of btmp, which a host on the #: internet fills quickly. _READ_TIMEOUT = 120 class LinuxLoginAccountsMixin(LoginAccountsMixin, LoginSessionsMixin): """The transports for ``get_login_accounts`` and ``get_login_sessions``.""" if TYPE_CHECKING: # pragma: no cover - the driver's own, declared for type checkers def run_command( self, command: str, *, privileged: bool = False, timeout: float = 60, stdin: bytes | None = None, ) -> CommandResult: ... def _run_login_accounts_command(self, command: str, *, privileged: bool) -> str: return self.run_command(command, privileged=privileged, timeout=_READ_TIMEOUT).stdout def _run_login_sessions_command(self, command: str) -> str: return self.run_command(command, timeout=_READ_TIMEOUT).stdout