mirror of
https://github.com/samba-team/samba.git
synced 2025-01-11 05:18:09 +03:00
e604f75751
Windows Portable Executable files have a timestamp field and a checksum field. By default the timestamp field is updated to the current time, which consequently changes the checksum. This makes the build nondeterministic. It looks like this: --- a/tmp/winexe-1/winexesvc64_exe_binary.c +++ b/tmp/winexe-2/winexesvc64_exe_binary.c @@ -23,7 +23,7 @@ const DATA_BLOB *winexesvc64_exe_binary(void) 0x6D, 0x6F, 0x64, 0x65, 0x2E, 0x0D, 0x0D, 0x0A, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x45, 0x00, 0x00, 0x64, 0x86, 0x0A, 0x00, - 0xB2, 0x16, 0x55, 0x66, 0x00, 0x00, 0x00, 0x00, + 0xD3, 0x3B, 0x55, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x2E, 0x02, 0x0B, 0x02, 0x02, 0x26, 0x00, 0x86, 0x00, 0x00, 0x00, 0xBA, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, @@ -33,7 +33,7 @@ const DATA_BLOB *winexesvc64_exe_binary(void) 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, - 0x73, 0xD7, 0x00, 0x00, 0x03, 0x00, 0x60, 0x01, + 0x94, 0xFC, 0x00, 0x00, 0x03, 0x00, 0x60, 0x01, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, https://learn.microsoft.com/en-us/windows/win32/debug/pe-format says that a timestamp of zero can be used to represent a time that is not "real or meaningful", so we do that. As far as I can tell, the timestamp and checksum are only used in DLLs, not directly executed .exe files. Thanks to Freexian and the Debian LTS project for sponsoring this work. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13213 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
108 lines
3.0 KiB
Python
108 lines
3.0 KiB
Python
#!/usr/bin/env python
|
|
|
|
import samba_utils
|
|
|
|
def generate_winexesvc_c_from_exe(t):
|
|
'''generate a C source file with the contents of the given binary'''
|
|
src = t.inputs[0].bldpath(t.env)
|
|
tgt = t.outputs[0].bldpath(t.env)
|
|
fn = t.env.SAMBA_GENERATOR_VARS['WINEXE_FN']
|
|
|
|
try:
|
|
with open(src, 'rb') as f:
|
|
src_blob = f.read()
|
|
f.close()
|
|
except:
|
|
print('Failed to read %s to convert to C array' % (src))
|
|
return -1
|
|
|
|
def c_array(src):
|
|
result = []
|
|
for i in range(0, len(src), 8):
|
|
l = src[i:i+8]
|
|
h = ' '.join(["0x%02X," % x for x in l])
|
|
result.append(h)
|
|
return "\n\t\t".join(result)
|
|
|
|
src_array = c_array(src_blob)
|
|
if len(src_array) <= 0:
|
|
print('Failed to convert %s to C array' % (src))
|
|
return -1
|
|
|
|
contents = '''
|
|
#include "replace.h"
|
|
#include "lib/util/data_blob.h"
|
|
|
|
const DATA_BLOB *%s(void);
|
|
const DATA_BLOB *%s(void)
|
|
{
|
|
\tstatic const uint8_t array[] = {
|
|
\t\t%s
|
|
\t};
|
|
\tstatic const DATA_BLOB blob = {
|
|
\t\t.data = discard_const_p(uint8_t, array),
|
|
\t\t.length = ARRAY_SIZE(array),
|
|
\t};
|
|
\treturn &blob;
|
|
}
|
|
''' % (fn, fn, src_array)
|
|
|
|
if not samba_utils.save_file(tgt, contents):
|
|
print('Failed to write C source file %s' % (tgt))
|
|
return -1
|
|
return 0
|
|
|
|
winexesvc_binaries = ''
|
|
|
|
bld.SAMBA_GENERATOR(
|
|
'winexesvc32_exe',
|
|
source='winexesvc.c',
|
|
target='winexesvc32.exe',
|
|
rule='SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} ${WINEXE_CC_WIN32} ${SRC} -o ${TGT} ${WINEXE_LDFLAGS}',
|
|
enabled=bld.env.build_winexe and bld.env.WINEXE_CC_WIN32)
|
|
|
|
vars = {"WINEXE_FN": "winexesvc32_exe_binary"}
|
|
bld.SAMBA_GENERATOR(
|
|
'winexesvc32_exe_binary',
|
|
source='winexesvc32.exe',
|
|
target='winexesvc32_exe_binary.c',
|
|
group='build_source',
|
|
vars=vars,
|
|
rule=generate_winexesvc_c_from_exe,
|
|
enabled=bld.env.build_winexe and bld.env.WINEXE_CC_WIN32)
|
|
|
|
if bld.env.WINEXE_CC_WIN32:
|
|
winexesvc_binaries += ' winexesvc32_exe_binary.c'
|
|
|
|
bld.SAMBA_GENERATOR(
|
|
'winexesvc64_exe',
|
|
source='winexesvc.c',
|
|
target='winexesvc64.exe',
|
|
rule='SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} ${WINEXE_CC_WIN64} ${SRC} -o ${TGT} ${WINEXE_LDFLAGS}',
|
|
enabled=bld.env.build_winexe and bld.env.WINEXE_CC_WIN64)
|
|
|
|
vars = {"WINEXE_FN": "winexesvc64_exe_binary"}
|
|
bld.SAMBA_GENERATOR(
|
|
'winexesvc64_exe_binary',
|
|
source='winexesvc64.exe',
|
|
target='winexesvc64_exe_binary.c',
|
|
group='build_source',
|
|
vars=vars,
|
|
rule=generate_winexesvc_c_from_exe,
|
|
enabled=bld.env.build_winexe and bld.env.WINEXE_CC_WIN64)
|
|
|
|
if bld.env.WINEXE_CC_WIN64:
|
|
winexesvc_binaries += ' winexesvc64_exe_binary.c'
|
|
|
|
if winexesvc_binaries != '':
|
|
bld.SAMBA3_BINARY('winexe',
|
|
source='winexe.c ' + winexesvc_binaries,
|
|
deps='''
|
|
CMDLINE_S3
|
|
samba-credentials
|
|
LOADPARM_CTX
|
|
libsmb
|
|
msrpc3
|
|
''',
|
|
enabled=bld.env.build_winexe)
|