fix: separate skipped writes and file proof from native release

This commit is contained in:
阿白叔 committed 2026-11-16 09:53:29 +08:00
1 parent fee4a67ff1
commit fa5590468d
10 files changed
+296 -63

No files matched your search

+41 -33
View File
@@ -10,60 +10,68 @@ from .session_record import process_identity
class WriteOwnerChoice(OpenChoice):
def __init__(self, block, library, owners):
super().__init__(block, library)
self.owners=tuple(dict(row) for row in owners)
self.owners = tuple(dict(row) for row in owners)
class WriteAdmissionDeclined(ValueError):
def __init__(self, decision):
self.decision=decision
super().__init__('已取消本批次,未提交后续写入。' if decision=='cancel' else '用户跳过本项,未确认未知程序与目标库无关。')
def __init__(self, decision, detail=None):
self.decision = decision
super().__init__(detail or ('已取消本批次,未提交后续写入。' if decision == 'cancel' else
'用户跳过本项,未确认未知程序与目标库无关。'))
class WriteAdmission:
def __init__(self, *, prompt=None, stop=None):
self.prompt,self.stop=prompt,stop
self._grants={}
self.prompt, self.stop = prompt, stop
self._grants = {}
def _identities(self, owners):
rows=[]
rows = []
for row in owners:
try:identity=process_identity(row['pid'])
try:
identity = process_identity(row['pid'])
except Exception as error:
if getattr(error,'winerror',None)==87:continue
if getattr(error, 'winerror', None) == 87:
continue
raise
if Path(identity['image']).name.casefold()!=row['name'].casefold():
if Path(identity['image']).name.casefold() != row['name'].casefold():
raise ValueError('TARGET_NATIVE_OWNER_UNCONFIRMED: PID 已被其他程序复用,请重新检查。')
if row.get('executable') and Path(row['executable']).resolve()!=Path(identity['image']).resolve():
if row.get('executable') and Path(row['executable']).resolve() != Path(identity['image']).resolve():
raise ValueError('TARGET_NATIVE_OWNER_UNCONFIRMED: 原生程序身份已变化,请重新检查。')
rows.append({**identity,'name':row['name']})
return tuple(sorted((row['pid'],row['created_handle'],row['image'],row['owner_sid'],row['session_id'])
for row in rows)),rows
rows.append({**identity, 'name': row['name']})
return tuple(sorted((row['pid'], row['created_handle'], row['image'], row['owner_sid'], row['session_id'])
for row in rows)), rows
def confirmed(self, library, owners):
key=str(Path(library).resolve()).casefold()
identities,_=self._identities(owners)
return set(identities).issubset(self._grants.get(key,set()))
key = str(Path(library).resolve()).casefold()
identities, _ = self._identities(owners)
return set(identities).issubset(self._grants.get(key, set()))
def confirm(self, library, owners, *, evidence, block):
key=str(Path(library).resolve()).casefold()
identities,rows=self._identities(owners)
if set(identities).issubset(self._grants.get(key,set())):return
key = str(Path(library).resolve()).casefold()
identities, rows = self._identities(owners)
if set(identities).issubset(self._grants.get(key, set())):
return
if self.prompt is None:
raise ValueError('TARGET_NATIVE_OWNER_UNCONFIRMED: 无法确认原生程序是否使用目标库,请通过界面核对后选择。')
choice=WriteOwnerChoice(block,str(Path(library)),rows)
raise WriteAdmissionDeclined('skip',
'TARGET_NATIVE_OWNER_UNCONFIRMED: 无法确认原生程序是否使用目标库,未执行;请通过界面核对后选择。')
choice = WriteOwnerChoice(block, str(Path(library)), rows)
self.prompt(choice)
while choice.decision is None and not (self.stop is not None and self.stop.is_set()):time.sleep(.05)
decision=choice.decision or 'cancel'
if decision!='continue':
if decision=='cancel' and self.stop is not None:self.stop.set()
while choice.decision is None and not (self.stop is not None and self.stop.is_set()):
time.sleep(.05)
decision = choice.decision or 'cancel'
if decision != 'continue':
if decision == 'cancel' and self.stop is not None:
self.stop.set()
raise WriteAdmissionDeclined(decision)
current,_=self._identities(owners)
current, _ = self._identities(owners)
if not set(current).issubset(identities):
raise ValueError('TARGET_NATIVE_OWNER_UNCONFIRMED: 确认期间进程身份已变化,请重新检查。')
from .management import _write_json
root=Path(evidence);root.mkdir(parents=True,exist_ok=True)
_write_json(root/('write-owner-consent-'+uuid4().hex+'.json'),dict(
intent='user_confirmed_unknown_clients_do_not_use_target_library',library=str(Path(library).resolve()),
block=block,scope='current_batch_library',owners=rows,choice='continue',
proves_native_ownership=False,requires_fresh_resource_checks=True))
self._grants.setdefault(key,set()).update(current)
root = Path(evidence)
root.mkdir(parents=True, exist_ok=True)
_write_json(root/('write-owner-consent-'+uuid4().hex+'.json'), dict(
intent='user_confirmed_unknown_clients_do_not_use_target_library', library=str(Path(library).resolve()),
block=block, scope='current_batch_library', owners=rows, choice='continue',
proves_native_ownership=False, requires_fresh_resource_checks=True))
self._grants.setdefault(key, set()).update(current)