Compare commits

...
Author SHA1 Message Date
maxjivi05 b08eb91d8f Merge remote-tracking branch 'droiddeck/main' into fix/battlenet-wowf-agent-2113 2026-11-23 12:42:34 -05:00
The412Banner ffd94f964a fix(runtime): Windows folder permissions stay valid after the machine ID changes
Proton builds the Windows user SID from /etc/machine-id. Runtime updates
reset that file, so descriptors written earlier named a user that no
longer exists and Battle.net's updater was denied access to its own game
folder (error 2113). The session now keeps the machine ID with the home
folder, and wineserver reads stored descriptors for an earlier ID of this
account as the current user.
2026-11-23 00:13:58 +00:00
The412Banner cc46851c64 fix(logs): shared logs keep a Battle.net Agent log over 8 MB instead of dropping it 2026-11-16 17:56:37 +00:00
7 changed files with 339 additions and 19 deletions

No files matched your search

@@ -870,7 +870,7 @@ internal object EnhancedSessionLogShare {
truncated = truncated || scan.truncated
partial = partial || scan.partial
found += scan.files.asSequence()
.filter { recent(it) && it.name.endsWith(".log") && it.length() <= LEGACY_LOG_MAX_BYTES }
.filter { recent(it) && it.name.endsWith(".log") }
.filter { names == null || it.name in names }
.map { it to root }
.toList()
@@ -968,7 +968,6 @@ internal object EnhancedSessionLogShare {
private const val STORE_LOG_SCAN = 512
private const val COPY_BUFFER_BYTES = 64 * 1024
private const val TRACE_SCAN_BYTES = 16L * 1024 * 1024
private const val LEGACY_LOG_MAX_BYTES = 8L * 1024 * 1024
private const val MAX_BATTLENET_SCAN = 64
private const val MAX_BATTLENET_DIRECTORIES = 64
private const val MAX_MANIFEST_RECORDS = 512
@@ -173,6 +173,43 @@ class SessionLogShareZipTest {
SessionLogShare.clear(app)
}
@Test fun aBattleNetAgentLogOverThePerFileLimitIsSharedWithItsTail() {
val session = File(LinuxRuntime.logDir(app), "2026-11-16-01-battle-net").apply { mkdirs() }
File(session, "session.log").writeText("droiddeck-battlenet: open (from the menu)\n")
val agent = File(com.droiddeck.launcher.runtime.BattleNet.prefix(app), "pfx/drive_c/ProgramData/Battle.net/Agent")
val switcher = File(agent, "Logs").apply { mkdirs() }
val now = System.currentTimeMillis()
for (i in 1..10) switcher.resolve("Agent-$i.log").apply {
writeText("switcher argument[0]: '--session=$i'\n")
setLastModified(now - i * 60_000L)
}
val log = File(agent, "Agent.9900/Logs").apply { mkdirs() }.resolve("Agent-11.log")
try {
log.bufferedWriter().use { out ->
out.write("Agent started as Administrator\n")
val chunk = "x".repeat(8191) + "\n"
repeat(1100) { out.write(chunk) }
out.write("Update failed with error 2113\n")
}
assertTrue(log.length() > 8L * 1024 * 1024)
val zip = SessionLogShare.zipFolder(app, session)!!
ZipFile(zip).use { archive ->
val shared = archive.getInputStream(archive.getEntry("battlenet/agent/Agent.9900/Agent-11.log")!!).bufferedReader().readText()
assertTrue(shared.startsWith("Agent started as Administrator"))
assertTrue(shared.contains("diagnostic file truncated"))
assertTrue(shared.trimEnd().endsWith("Update failed with error 2113"))
val agentEntries = archive.entries().toList().map { it.name }.filter { it.startsWith("battlenet/agent/") }
assertEquals(10, agentEntries.size)
assertEquals((1..9).map { "Agent-$it.log" }.toSet(), agentEntries.filterNot { it.contains("Agent.9900") }.map { it.substringAfterLast('/') }.toSet())
}
} finally {
SessionLogShare.clear(app)
session.deleteRecursively()
agent.deleteRecursively()
}
}
@Test fun theSharePassChangesNothingInACleanLine() {
val line = "dxvk: Device 0x5 (Adreno 750) https://github.com/doitsujin/dxvk/releases code 403"
assertEquals(line, com.droiddeck.launcher.core.LogRedactor.redactForShare(line))
@@ -57,12 +57,18 @@ sync_timezone() {
sync_timezone
ensure_machine_id() {
local id=
id=$(< /etc/machine-id)
[[ $id =~ ^[0-9a-f]{32}$ && $id != 00000000000000000000000000000000 ]] && return 0
id=$(dbus-uuidgen) || return 0
[[ $id =~ ^[0-9a-f]{32}$ ]] || return 0
printf '%s\n' "$id" > /etc/machine-id.droiddeck && mv -f /etc/machine-id.droiddeck /etc/machine-id
local id= source kept=$HOME/.local/share/droiddeck/machine-id
for source in /etc/machine-id "$kept" dbus-uuidgen; do
if [ "$source" = dbus-uuidgen ]; then id=$(dbus-uuidgen) || return 0; else id=$(< "$source"); fi
[[ $id =~ ^[0-9a-f]{32}$ && $id != 00000000000000000000000000000000 ]] && break
id=
done
[ -n "$id" ] || return 0
if [ "$(< /etc/machine-id)" != "$id" ]; then
printf '%s\n' "$id" > /etc/machine-id.droiddeck && mv -f /etc/machine-id.droiddeck /etc/machine-id || return 0
fi
[ "$(< "$kept")" = "$id" ] && return 0
mkdir -p "${kept%/*}" && printf '%s\n' "$id" > "$kept.droiddeck" && mv -f "$kept.droiddeck" "$kept"
} 2>/dev/null
ensure_machine_id
+99 -5
View File
@@ -13,15 +13,107 @@
#define DESCRIPTOR "user.wine.sd"
#define STORE "/.droiddeck-descriptors"
#define ENTRY_MAX (PATH_MAX * 2)
#define MACHINE_ID "/etc/machine-id"
#define SD_HEADER 22
#define SID_SIZE 28
int dd_is_wineserver(void) __attribute__((visibility("hidden")));
static int store_seen;
static unsigned int user_sub[3];
static int kept(const char *name) {
return name != NULL && strcmp(name, DESCRIPTOR) == 0 && dd_is_wineserver();
}
__attribute__((visibility("hidden")))
void dd_descriptor_opened(const char *path) {
char id[17];
ssize_t got, n = 0;
unsigned long long value;
int saved = errno, fd;
if (path == NULL || strcmp(path, MACHINE_ID) != 0 || !dd_is_wineserver()) {
errno = saved;
return;
}
memset(user_sub, 0, sizeof(user_sub));
fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd >= 0) {
while (n < 16 && (got = read(fd, id + n, (size_t)(16 - n))) > 0) n += got;
close(fd);
}
if (n == 16) {
id[16] = '\0';
value = strtoull(id, NULL, 16);
user_sub[0] = (unsigned int)(value >> 32);
user_sub[1] = (unsigned int)value;
user_sub[2] = (unsigned int)getuid();
}
errno = saved;
}
static unsigned int word_at(const unsigned char *p) {
unsigned int v;
memcpy(&v, p, sizeof(v));
return v;
}
static unsigned short half_at(const unsigned char *p) {
unsigned short v;
memcpy(&v, p, sizeof(v));
return v;
}
static void current_user(unsigned char *sid, size_t size) {
static const unsigned char local[8] = {1, 5, 0, 0, 0, 0, 0, 5};
unsigned int owner;
if (size < SID_SIZE || memcmp(sid, local, sizeof(local)) != 0) return;
if (word_at(sid + 8) != 21 || word_at(sid + 24) != 1000) return;
owner = word_at(sid + 20);
if (owner != 0 && owner != (unsigned int)getuid()) return;
memcpy(sid + 12, user_sub, sizeof(user_sub));
}
static int current_user_acl(unsigned char *acl, size_t size, int apply) {
size_t used = 8;
unsigned int count, i;
if (size == 0) return 1;
if (size < 8) return 0;
count = half_at(acl + 4);
for (i = 0; i < count && used + 8 <= size; i++) {
unsigned char *ace = acl + used;
size_t length = half_at(ace + 2);
if (length < 8 || length > size - used) return 0;
if (apply && ace[0] <= 3) current_user(ace + 8, length - 8);
used += length;
}
return i == count;
}
static void current_user_sd(unsigned char *value, size_t size) {
size_t part[4], at = SD_HEADER;
int i;
if (size < SD_HEADER || value[0] != 1 || value[1] != 0) return;
for (i = 0; i < 4; i++) {
part[i] = word_at(value + 6 + 4 * i);
if (part[i] > size - at) return;
at += part[i];
}
at = SD_HEADER + part[0] + part[1];
if (!current_user_acl(value + at, part[2], 0) || !current_user_acl(value + at + part[2], part[3], 0)) return;
current_user(value + SD_HEADER, part[0]);
current_user(value + SD_HEADER + part[0], part[1]);
current_user_acl(value + at, part[2], 1);
current_user_acl(value + at + part[2], part[3], 1);
}
static int store_root(char *out, size_t size) {
const char *prefix = getenv("WINEPREFIX");
int n;
@@ -171,12 +263,14 @@ ssize_t fgetxattr(int fd, const char *name, void *value, size_t size) {
return -1;
}
result = next(fd, name, value, size);
if (result >= 0 || errno != ENOTSUP || !kept(name)) return result;
result = stored_read(fd, value, size);
if (result == -2) {
errno = ENOTSUP;
return -1;
if (result < 0 && errno == ENOTSUP && kept(name)) {
result = stored_read(fd, value, size);
if (result == -2) {
errno = ENOTSUP;
return -1;
}
}
if (result > 0 && size > 0 && kept(name)) current_user_sd(value, (size_t)result);
return result;
}
+3
View File
@@ -610,6 +610,8 @@ int dd_status_without_tracer(const char *path, int flags, const void *caller) __
const char *dd_oom_adj_redirect(const char *path, int writing) __attribute__((visibility("hidden")));
void dd_descriptor_opened(const char *path) __attribute__((visibility("hidden")));
static FILE *open_stream(fopen_fn real, const char *path, const char *mode, const void *caller) {
int status = mode && mode[0] == 'r' && !strchr(mode, '+')
? dd_status_without_tracer(path, O_RDONLY | O_CLOEXEC, caller) : -1;
@@ -623,6 +625,7 @@ static FILE *open_stream(fopen_fn real, const char *path, const char *mode, cons
FILE *f;
if (table >= 0 && denied_recently(table, path) && (f = synthesize(table)) != NULL) return f;
f = real(path, mode);
if (f) dd_descriptor_opened(path);
if (f || table < 0) return f;
int saved = errno;
if ((f = synthesize(table)) != NULL) {
+147 -5
View File
@@ -1,6 +1,8 @@
import os
from pathlib import Path
import re
import shutil
import struct
import subprocess
import tempfile
import unittest
@@ -17,18 +19,36 @@ FAKE = r"""
#include <sys/types.h>
#include <unistd.h>
static int answer(int fd) {
char link[32], path[4096];
static void path_of(int fd, char *path, size_t size) {
char link[32];
snprintf(link, sizeof(link), "/proc/self/fd/%d", fd);
long n = syscall(SYS_readlinkat, AT_FDCWD, link, path, sizeof(path) - 1);
long n = syscall(SYS_readlinkat, AT_FDCWD, link, path, size - 1);
path[n > 0 ? n : 0] = '\0';
}
static int answer(int fd) {
char path[4096];
path_of(fd, path, sizeof(path));
if (strstr(path, "/card/")) return ENOTSUP;
if (strstr(path, "/denied/")) return EACCES;
return ENODATA;
}
ssize_t fgetxattr(int fd, const char *name, void *value, size_t size) {
(void)name; (void)value; (void)size;
char path[4096], side[4200];
(void)name;
path_of(fd, path, sizeof(path));
if (strstr(path, "/native/")) {
snprintf(side, sizeof(side), "%s.xattr", path);
int file = (int)syscall(SYS_openat, AT_FDCWD, side, O_RDONLY | O_CLOEXEC, 0);
if (file < 0) {
errno = ENODATA;
return -1;
}
long n = syscall(SYS_read, file, value, size);
syscall(SYS_close, file);
return n;
}
errno = answer(fd);
return -1;
}
@@ -57,6 +77,10 @@ PROGRAM = r"""
#include <sys/xattr.h>
#include <unistd.h>
static int hex_value(char c) {
return c >= '0' && c <= '9' ? c - '0' : c >= 'a' && c <= 'f' ? c - 'a' + 10 : -1;
}
static const char *error(void) {
return errno == ENOTSUP ? "unsupported" : errno == ENODATA ? "none" : errno == ERANGE ? "range" :
errno == EACCES ? "denied" : "other";
@@ -74,6 +98,12 @@ int main(int argc, char **argv) {
printf("%s\n", remove(argv[++i]) == 0 ? "ok" : "failed");
continue;
}
if (!strcmp(op, "machine-id")) {
FILE *f = fopen("/etc/machine-id", "r");
printf("%s\n", f ? "opened" : "missing");
if (f) fclose(f);
continue;
}
if (!strcmp(op, "rename")) {
const char *from = argv[++i], *to = argv[++i];
printf("%s\n", rename(from, to) == 0 ? "ok" : "failed");
@@ -86,6 +116,23 @@ int main(int argc, char **argv) {
errno = 1234;
int result = fsetxattr(fd, "user.wine.sd", text, strlen(text), 0);
printf("%s\n", result == 0 ? errno == 1234 ? "ok" : "errno" : error());
} else if (!strcmp(op, "sethex")) {
const char *text = argv[++i];
unsigned char bytes[4096];
size_t n = 0;
for (; text[2 * n] && text[2 * n + 1] && n < sizeof(bytes); n++)
bytes[n] = (unsigned char)(hex_value(text[2 * n]) * 16 + hex_value(text[2 * n + 1]));
int result = fsetxattr(fd, "user.wine.sd", bytes, n, 0);
printf("%s\n", result == 0 ? "ok" : error());
} else if (!strcmp(op, "gethex")) {
unsigned char bytes[4096];
ssize_t n = fgetxattr(fd, "user.wine.sd", bytes, sizeof(bytes));
if (n < 0) printf("%s\n", error());
else {
printf("=");
for (ssize_t k = 0; k < n; k++) printf("%02x", bytes[k]);
printf("\n");
}
} else if (!strcmp(op, "get")) {
ssize_t n = fgetxattr(fd, "user.wine.sd", value, sizeof(value));
if (n < 0) printf("%s\n", error());
@@ -112,6 +159,39 @@ int main(int argc, char **argv) {
"""
def machine_id_head():
try:
with open("/etc/machine-id", "rb") as f:
return f.read(16)
except OSError:
return b""
def sid(*subs, authority=5):
return bytes([1, len(subs), 0, 0, 0, 0, 0, authority]) + b"".join(struct.pack("=I", s) for s in subs)
def ace(kind, who, mask=0x1F01FF):
return struct.pack("=BBHI", kind, 3, 8 + len(who), mask) + who
def acl(*aces):
body = b"".join(aces)
return struct.pack("=BBHHH", 2, 0, 8 + len(body), len(aces), 0) + body
def descriptor(owner, group, dacl, sacl=b""):
control = 0x4 | (0x10 if sacl else 0)
return (b"\x01\x00" + struct.pack("=IIIII", control, len(owner), len(group), len(sacl), len(dacl)) +
owner + group + sacl + dacl)
DEFAULT_USER = sid(21, 0, 0, 0, 1000)
OLD_USER = sid(21, 0x12345678, 0x9ABCDEF0, os.getuid(), 1000)
USERS = sid(21, 0, 0, 0, 513)
ADMINS = sid(32, 544)
@unittest.skipUnless(shutil.which("cc"), "needs a C compiler")
class DescriptorPreloadTest(unittest.TestCase):
@classmethod
@@ -140,7 +220,7 @@ class DescriptorPreloadTest(unittest.TestCase):
self.prefix = self.dir / "prefix"
self.prefix.mkdir()
self.store = self.prefix / ".droiddeck-descriptors"
for kind in ("card", "disk", "denied"):
for kind in ("card", "disk", "denied", "native"):
(self.dir / kind / "game").mkdir(parents=True)
(self.dir / kind / "game" / "file").write_text("x")
@@ -240,6 +320,68 @@ class DescriptorPreloadTest(unittest.TestCase):
Path(long_file).write_text("x")
self.assertEqual(["unsupported", "unsupported"], self.server("set", long_file, "one", "get", long_file))
def keep_natively(self, file, value):
Path(file + ".xattr").write_bytes(value)
def assert_read_as(self, expected, *args, program=None):
out = self.run_as(program or self.wineserver, *args)
self.assertEqual("=" + expected.hex(), out[-1])
def test_a_descriptor_written_for_an_earlier_user_id_is_read_for_the_current_user(self):
written = descriptor(OLD_USER, USERS, acl(ace(0, OLD_USER), ace(0, ADMINS), ace(1, OLD_USER, 0x40000)),
acl(ace(2, OLD_USER)))
current = written.replace(OLD_USER, DEFAULT_USER)
stored = self.path("card", "game", "file")
self.assertEqual(["ok"], self.server("sethex", stored, written.hex()))
self.assert_read_as(current, "gethex", stored)
native = self.path("native", "game", "file")
self.keep_natively(native, written)
self.assert_read_as(current, "gethex", native)
self.assertEqual(written, Path(native + ".xattr").read_bytes())
@unittest.skipUnless(re.fullmatch(rb"[0-9a-f]{16}", machine_id_head()), "needs a machine ID")
def test_the_current_user_follows_the_machine_id_the_server_reads(self):
value = int(machine_id_head(), 16)
current = sid(21, value >> 32, value & 0xFFFFFFFF, os.getuid(), 1000)
written = descriptor(DEFAULT_USER, USERS, acl(ace(0, DEFAULT_USER)))
native = self.path("native", "game", "file")
self.keep_natively(native, written)
out = self.server("machine-id", "gethex", native)
self.assertEqual(["opened", "=" + written.replace(DEFAULT_USER, current).hex()], out)
def test_other_accounts_groups_and_unknown_entries_are_kept(self):
others = [sid(21, 1, 2, os.getuid() + 1, 1000), sid(21, 1, 2, os.getuid(), 500),
sid(21, 1, 2, os.getuid(), 1000, 7), sid(0, authority=1), sid(18), USERS, ADMINS]
written = descriptor(others[0], USERS, acl(*(ace(0, other) for other in others), ace(5, OLD_USER),
ace(0x11, OLD_USER)))
native = self.path("native", "game", "file")
self.keep_natively(native, written)
self.assert_read_as(written, "gethex", native)
def test_a_descriptor_in_the_current_user_and_other_programs_are_unchanged(self):
native = self.path("native", "game", "file")
current = descriptor(DEFAULT_USER, USERS, acl(ace(0, DEFAULT_USER)))
self.keep_natively(native, current)
self.assert_read_as(current, "gethex", native)
written = descriptor(OLD_USER, USERS, acl(ace(0, OLD_USER)))
self.keep_natively(native, written)
self.assert_read_as(written, "gethex", native, program=self.other)
def test_a_malformed_descriptor_is_returned_as_stored(self):
good = descriptor(OLD_USER, USERS, acl(ace(0, OLD_USER)))
broken = [
b"\x02" + good[1:],
good[:2] + struct.pack("=I", 4) + struct.pack("=I", 4096) + good[10:],
good[:-4],
good[:-len(acl(ace(0, OLD_USER)))] + acl(ace(0, OLD_USER))[:10] + struct.pack("=H", 200) +
acl(ace(0, OLD_USER))[12:],
good[:30],
]
native = self.path("native", "game", "file")
for value in broken:
self.keep_natively(native, value)
self.assert_read_as(value, "gethex", native)
if __name__ == "__main__":
unittest.main()
+40 -1
View File
@@ -16,6 +16,8 @@ class SessionMachineIdTest(unittest.TestCase):
self.bin = self.root / "bin"
self.bin.mkdir()
self.file = self.root / "machine-id"
self.home = self.root / "home"
self.kept = self.home / ".local/share/droiddeck/machine-id"
def generator(self, output, status=0):
tool = self.bin / "dbus-uuidgen"
@@ -25,7 +27,7 @@ class SessionMachineIdTest(unittest.TestCase):
def ensure(self):
match = re.search(r"^ensure_machine_id\(\) \{\n.*?^\} 2>/dev/null\n", SESSION.read_text(), re.M | re.S)
script = match.group(0).replace("/etc/machine-id", str(self.file)) + "ensure_machine_id\n"
subprocess.run(["bash", "-c", script], env={"PATH": "%s:/usr/bin:/bin" % self.bin}, timeout=30, check=True)
subprocess.run(["bash", "-c", script], env={"PATH": "%s:/usr/bin:/bin" % self.bin, "HOME": str(self.home)}, timeout=30, check=True)
return self.file.read_text() if self.file.exists() else None
def test_the_empty_id_shipped_in_the_runtime_gets_a_fresh_one(self):
@@ -56,6 +58,43 @@ class SessionMachineIdTest(unittest.TestCase):
self.generator("not-an-id")
self.assertEqual("", self.ensure())
def test_the_id_is_kept_where_a_runtime_update_keeps_user_data(self):
self.file.write_text("fedcba9876543210fedcba9876543210\n")
self.generator(FRESH)
self.ensure()
self.assertEqual("fedcba9876543210fedcba9876543210\n", self.kept.read_text())
self.assertEqual([self.kept.name], [p.name for p in self.kept.parent.iterdir()])
def test_a_runtime_update_gets_the_kept_id_back_instead_of_a_fresh_one(self):
self.kept.parent.mkdir(parents=True)
self.kept.write_text("fedcba9876543210fedcba9876543210\n")
self.file.write_text("")
self.generator(FRESH)
self.assertEqual("fedcba9876543210fedcba9876543210\n", self.ensure())
self.assertEqual("fedcba9876543210fedcba9876543210\n", self.kept.read_text())
def test_a_malformed_kept_id_is_replaced_with_a_fresh_one(self):
self.kept.parent.mkdir(parents=True)
for bad in ("", "0" * 32 + "\n", "uninitialized\n"):
self.kept.write_text(bad)
self.file.write_text("")
self.generator(FRESH)
self.assertEqual(FRESH + "\n", self.ensure())
self.assertEqual(FRESH + "\n", self.kept.read_text())
def test_the_running_id_wins_over_a_different_kept_one(self):
self.kept.parent.mkdir(parents=True)
self.kept.write_text(FRESH + "\n")
self.file.write_text("fedcba9876543210fedcba9876543210\n")
self.assertEqual("fedcba9876543210fedcba9876543210\n", self.ensure())
self.assertEqual("fedcba9876543210fedcba9876543210\n", self.kept.read_text())
def test_without_a_usable_generator_nothing_is_kept(self):
self.file.write_text("")
self.generator(FRESH, status=1)
self.ensure()
self.assertFalse(self.kept.exists())
if __name__ == "__main__":
unittest.main()