The transport runs the shared, read-only command on an exec channel, as root first for the lock, the expiry and the failed logins, and as the login user where root is refused.
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
"""Who can log in to the host, and how they do: napalm-device-types' ``LoginAccountsMixin``
|
|
(NetOrk/netork#2707).
|
|
|
|
The command and its parse are napalm-device-types'; this is only how the command
|
|
reaches 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.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from napalm_device_types import CommandResult, LoginAccountsMixin
|
|
|
|
#: Seconds the reading may take: ``lastb`` reads all of btmp, which a host on the
|
|
#: internet fills quickly.
|
|
_READ_TIMEOUT = 120
|
|
|
|
|
|
class LinuxLoginAccountsMixin(LoginAccountsMixin):
|
|
"""The transport for ``get_login_accounts``."""
|
|
|
|
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
|