CVE-2018-16841 heimdal: Fix segfault on PKINIT with mis-matching principal
[Samba.git] / buildtools / wafsamba / configure_file.py
blob6ad43546249fba7b4c0a037035e8574e7a9d2753
1 # handle substitution of variables in .in files
3 import sys
4 import re
5 import os
6 from waflib import Build, Logs
7 from samba_utils import SUBST_VARS_RECURSIVE
9 def subst_at_vars(task):
10 '''substiture @VAR@ style variables in a file'''
12 env = task.env
13 s = task.inputs[0].read()
15 # split on the vars
16 a = re.split('(@\w+@)', s)
17 out = []
18 for v in a:
19 if re.match('@\w+@', v):
20 vname = v[1:-1]
21 if not vname in task.env and vname.upper() in task.env:
22 vname = vname.upper()
23 if not vname in task.env:
24 Logs.error("Unknown substitution %s in %s" % (v, task.name))
25 sys.exit(1)
26 v = SUBST_VARS_RECURSIVE(task.env[vname], task.env)
27 out.append(v)
28 contents = ''.join(out)
29 task.outputs[0].write(contents)
30 return 0
32 def CONFIGURE_FILE(bld, in_file, **kwargs):
33 '''configure file'''
35 base=os.path.basename(in_file)
36 t = bld.SAMBA_GENERATOR('INFILE_%s' % base,
37 rule = subst_at_vars,
38 source = in_file + '.in',
39 target = in_file,
40 vars = kwargs)
41 Build.BuildContext.CONFIGURE_FILE = CONFIGURE_FILE