adopt_user_defaults() set the token's default DACL with FA (FILE_ALL_ACCESS). That default also applies to new process objects, and the file mask has no process query or set-information right, so a child could not be reopened by PID: the HighQoS helper timed out and procs.start_token could not record the child. GA lets Windows map the mask to the object being created; the principals are unchanged. Ported from PR #3428 by kossum (QoS reopen test). Test from PR #3399 by midhatn (a live child is identified and recorded) added; both fail without the change and pass with it. Co-authored-by: MIDHAT NASHAR <35053211+midhatn@users.noreply.github.com>
55 lines
2.0 KiB
Python
55 lines
2.0 KiB
Python
"""Windows token defaults must permit identifying children, not just opening files."""
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
PROBE = r"""
|
|
import json, subprocess, sys
|
|
from pathlib import Path
|
|
from strata_control import private_files, procs
|
|
|
|
assert private_files.adopt_user_defaults()
|
|
child = subprocess.Popen(
|
|
[sys.executable, "-c", "import time; print('ready', flush=True); time.sleep(30)"],
|
|
stdout=subprocess.PIPE, text=True,
|
|
)
|
|
try:
|
|
assert child.stdout.readline().strip() == "ready"
|
|
assert child.poll() is None
|
|
token = procs.start_token(child.pid)
|
|
assert token is not None, "live child became unreadable after adopting user defaults"
|
|
recorded = procs.write_record(child.pid, "engine")
|
|
assert recorded == token, "child identity could not be recorded"
|
|
print(json.dumps({"identified": True, "recorded": True}), flush=True)
|
|
finally:
|
|
child.kill()
|
|
child.wait(timeout=10)
|
|
child.stdout.close()
|
|
"""
|
|
|
|
|
|
@unittest.skipUnless(os.name == "nt", "Windows token default DACL")
|
|
class DefaultObjectAccess(unittest.TestCase):
|
|
def test_adopting_user_defaults_preserves_child_identity(self):
|
|
# Token defaults affect every subsequent object creation in this process.
|
|
# Exercise them in a disposable helper, not in the test runner itself.
|
|
with tempfile.TemporaryDirectory(prefix="strata-default-access-") as folder:
|
|
env = dict(os.environ, LOCALAPPDATA=folder, PYTHONPATH=str(ROOT))
|
|
result = subprocess.run(
|
|
[sys.executable, "-c", PROBE], cwd=ROOT, env=env,
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, timeout=25,
|
|
creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0),
|
|
)
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
self.assertEqual(json.loads(result.stdout), {"identified": True, "recorded": True})
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|