From 157641e37a36070207c3ab4920961eb758e83dbc Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 25 Aug 2025 08:59:53 -0400 Subject: [PATCH] Fixup imported windows media Samba by default needs executable bit on files for them to be executable by windows. Only give executable bits to .exe files that are PE32, mitigating the chance the executable bit could mean anything for Linux. It could still mean something with binfmt misc hooks, but that shouldn't be done much. --- confluent_server/confluent/osimage.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/confluent_server/confluent/osimage.py b/confluent_server/confluent/osimage.py index 1cd7dc11..2501b62b 100644 --- a/confluent_server/confluent/osimage.py +++ b/confluent_server/confluent/osimage.py @@ -648,6 +648,32 @@ def fixup_coreos(targpath): bootimg.write(b'\x01') +def is_windows_executable(filename): + with open(filename, 'rb') as f: + header = f.read(2) + if header == b'MZ': + # seems to be DOS, but let's also make sure it is PE32 + f.seek(0x3c) + pe_offset = f.read(4) + offset = int.from_bytes(pe_offset, byteorder='little') + f.seek(offset) + pe_header = f.read(4) + if pe_header == b'PE\x00\x00': + return True + return False + + +def fixup_windows(targpath): + # windows needs the executable file to be executable, which samba + # manifests as following the executable bit + for root, _, files in os.walk(targpath): + for fname in files: + if fname.endswith('.exe'): + fpath = os.path.join(root, fname) + if is_windows_executable(fpath): + st = os.stat(fpath) + os.chmod(fpath, st.st_mode | 0o111) + def check_coreos(isoinfo): arch = 'x86_64' # TODO: would check magic of vmlinuz to see which arch if 'zipl.prm' in isoinfo[1]: