fix(system): set_hostname hands the name to uci as one shell word (#43)
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Successful in 1m5s
driver / test (3.12) (pull_request) Successful in 1m7s
driver / lowest (pull_request) Successful in 30s
driver / test (3.13) (pull_request) Successful in 56s
driver / build (pull_request) Successful in 33s
driver / security (pull_request) Successful in 1m2s
CI / driver (pull_request) Successful in 2m38s
driver / publish (pull_request) Skipped
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Successful in 1m5s
driver / test (3.12) (pull_request) Successful in 1m7s
driver / lowest (pull_request) Successful in 30s
driver / test (3.13) (pull_request) Successful in 56s
driver / build (pull_request) Successful in 33s
driver / security (pull_request) Successful in 1m2s
CI / driver (pull_request) Successful in 2m38s
driver / publish (pull_request) Skipped
The name stood between single quotes of its own in `uci set system.@system[0].hostname='<name>'`, so a name with a single quote ended them and the rest ran as root (NetOrk/netork#2456). The command is now built with uci_steps.uci(), which quotes each word with shlex.
This commit is contained in:
1 parent
3dc24612f0
commit
d3abda34b4
3 files changed
+61
-2
No files matched your search
@@ -15,6 +15,8 @@ from __future__ import annotations
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
from napalm_openwrt.uci_steps import uci
|
||||
|
||||
|
||||
def _split_uci_list(value: str) -> list[str]:
|
||||
"""Split a ``uci show`` option value into its items.
|
||||
@@ -280,9 +282,14 @@ class OpenWrtVLANMixin:
|
||||
return instances
|
||||
|
||||
def set_hostname(self, new_hostname: str) -> None:
|
||||
"""Set the system hostname via UCI and reload the system service."""
|
||||
"""Set the system hostname via UCI and reload the system service.
|
||||
|
||||
The name reaches ``uci`` as one shell word, whatever it holds
|
||||
(NetOrk/netork#2456): between single quotes of its own, a name with a
|
||||
single quote ended them and the rest ran as root.
|
||||
"""
|
||||
self._send_command(
|
||||
f"uci set system.@system[0].hostname='{new_hostname}' && "
|
||||
f"{uci('set', f'system.@system[0].hostname={new_hostname}')} && "
|
||||
f"uci commit system && "
|
||||
f"/etc/init.d/system reload"
|
||||
)
|
||||
Reference in new issue
Block a user