Compare commits

...

2 Commits

Author SHA1 Message Date
ed
cade1990ce v1.3.5 2022-07-06 02:29:11 +02:00
ed
59b6e61816 build fstab from relabels when mtab is unreadable 2022-07-06 02:28:34 +02:00
2 changed files with 31 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
# coding: utf-8 # coding: utf-8
VERSION = (1, 3, 4) VERSION = (1, 3, 5)
CODENAME = "god dag" CODENAME = "god dag"
BUILD_DT = (2022, 7, 6) BUILD_DT = (2022, 7, 6)

View File

@@ -3,6 +3,7 @@ from __future__ import print_function, unicode_literals
import ctypes import ctypes
import re import re
import os
import time import time
from .__init__ import ANYWIN, MACOS from .__init__ import ANYWIN, MACOS
@@ -21,6 +22,7 @@ class Fstab(object):
def __init__(self, log: RootLogger): def __init__(self, log: RootLogger):
self.log_func = log self.log_func = log
self.trusted = False
self.tab: Optional[VFS] = None self.tab: Optional[VFS] = None
self.cache: dict[str, str] = {} self.cache: dict[str, str] = {}
self.age = 0.0 self.age = 0.0
@@ -49,6 +51,7 @@ class Fstab(object):
self.log(msg.format(path, fs, min_ex()), 3) self.log(msg.format(path, fs, min_ex()), 3)
return fs return fs
path = path.lstrip("/")
try: try:
return self.cache[path] return self.cache[path]
except: except:
@@ -92,21 +95,44 @@ class Fstab(object):
def relabel(self, path: str, nval: str) -> None: def relabel(self, path: str, nval: str) -> None:
assert self.tab assert self.tab
self.cache = {}
path = path.lstrip("/")
ptn = re.compile(r"^[^\\/]*") ptn = re.compile(r"^[^\\/]*")
vn, _ = self.tab._find(path) vn, rem = self.tab._find(path)
if not self.trusted:
# no mtab access; have to build as we go
if "/" in rem:
self.tab.add("idk", os.path.join(vn.vpath, rem.split("/")[0]))
if rem:
self.tab.add(nval, path)
else:
vn.realpath = nval
return
visit = [vn] visit = [vn]
while visit: while visit:
vn = visit.pop() vn = visit.pop()
vn.realpath = ptn.sub(nval, vn.realpath) vn.realpath = ptn.sub(nval, vn.realpath)
visit.extend(list(vn.nodes.values())) visit.extend(list(vn.nodes.values()))
self.cache = {}
def get_unix(self, path: str) -> str: def get_unix(self, path: str) -> str:
if not self.tab: if not self.tab:
self.build_tab() try:
self.build_tab()
self.trusted = True
except:
# prisonparty or other restrictive environment
self.log("failed to build tab:\n{}".format(min_ex()), 3)
self.tab = VFS(self.log_func, "idk", "/", AXS(), {})
self.trusted = False
assert self.tab assert self.tab
return self.tab._find(path)[0].realpath.split("/")[0] ret = self.tab._find(path)[0]
if self.trusted or path == ret.vpath:
return ret.realpath.split("/")[0]
else:
return "idk"
def get_w32(self, path: str) -> str: def get_w32(self, path: str) -> str:
# list mountpoints: fsutil fsinfo drives # list mountpoints: fsutil fsinfo drives