fix(sudo): run the whole command as root without a sudo password

Without a root login and without a sudo password, _run_privileged typed
"sudo -n <command>" into the interactive shell. sudo covered only the
first simple command of the line, and dnf's and yum's advisory query,
which starts with a brace group, did not parse at all: no status marker
ever arrived, so netmiko waited out the 120 s read timeout and
get_available_updates() failed. This is the default path for netOrk's
own NOPASSWD account.

The command now goes to "sudo -n sh -c" as one argument, as _as_root
already does with a password. A status echo at its end stays outside
sh -c: it reports sh's status, which is the command's, and still
arrives when sudo refuses.

Closes #56
This commit is contained in:
Christian Manivong committed 2026-11-02 08:39:50 +01:00
1 parent c2d7c4d1b4
commit d3134c83b8
5 files changed
+232 -7

No files matched your search

+7
View File
@@ -45,6 +45,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
on 3.12, so 3.10 and 3.11 are no longer tested (NAPALM/driver-standard#6).
### Fixed
- `get_available_updates()` works on dnf and yum hosts whose login user has
passwordless sudo (NOPASSWD), as netOrk's own account does, and marks the security
fixes there (#56). The security-advisory query did not parse under `sudo -n`, so no
answer came back and the read ran into its 120 s timeout. Without a sudo password a
privileged command now runs as root as a whole, in one `sh -c`, as it already did
with a password; before, only its first command did. A refused sudo still reports
its exit status at once.
- `ping()` passes `destination` and `source` to the host's shell as one quoted word
each (#55). A destination such as `192.0.2.1; id` ran the command after the `;` as
the login user. `count`, `timeout`, `size` and `ttl` must be numbers; anything else