-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperator-admin
More file actions
executable file
·38 lines (29 loc) · 1.05 KB
/
Copy pathoperator-admin
File metadata and controls
executable file
·38 lines (29 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python3 -I
# isort: skip_file
import os
import stat
import sys
from pathlib import Path
INSTALL_ROOT = Path(__file__).resolve().parent
def require_root_owned_code(path: Path) -> None:
for candidate in (path, path.resolve()):
current = Path("/")
for part in candidate.parts[1:]:
current /= part
metadata = current.lstat()
if metadata.st_uid != 0 or (
not stat.S_ISLNK(metadata.st_mode) and stat.S_IMODE(metadata.st_mode) & 0o022
):
raise SystemExit(f"unsafe privileged code path: {current}")
if os.geteuid() == 0:
require_root_owned_code(Path(sys.executable))
require_root_owned_code(INSTALL_ROOT / "operator-admin")
require_root_owned_code(INSTALL_ROOT / "authority_admin.py")
require_root_owned_code(INSTALL_ROOT / "authority_broker.py")
os.chdir("/")
os.environ.clear()
os.environ["LANG"] = "C"
sys.path.insert(0, str(INSTALL_ROOT))
from authority_admin import main # noqa: E402
if __name__ == "__main__":
raise SystemExit(main())