1
0
mirror of https://github.com/systemd/systemd.git synced 2025-08-23 05:49:52 +03:00
Files
systemd/tools/meson-render-jinja2.py
Yu Watanabe 7adac4caec meson: allow to customize the access mode for tty/pts devices
Then, switch the default value to "0600", due to general security
concerns about terminals being written to by other users.

Closing #35599.

Backport note: the default is changed back to 0620 to keep backward
compatbility intact for the purpose of backporting. This lets
security-conscious users fix  the issue if they want to, without
affecting users that do not want changes in the stable branches.

(cherry picked from commit a4d1891475)
2025-02-08 15:51:06 +09:00

46 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-2.1-or-later
# pylint: disable=consider-using-with
import ast
import os
import re
import sys
import jinja2
def parse_config_h(filename):
# Parse config.h file generated by meson.
ans = {}
for line in open(filename):
m = re.match(r'#define\s+(\w+)\s+(.*)', line)
if not m:
continue
a, b = m.groups()
# The function ast.literal_eval() cannot evaluate octal integers, e.g. 0600.
# So, it is intentional that the string below does not contain '0'.
if b and (b[0] in '123456789"' or b == '0'):
b = ast.literal_eval(b)
ans[a] = b
return ans
def render(filename, defines):
text = open(filename).read()
template = jinja2.Template(text,
trim_blocks=True,
lstrip_blocks=True,
keep_trailing_newline=True,
undefined=jinja2.StrictUndefined)
return template.render(defines)
def main():
defines = parse_config_h(sys.argv[1])
output = render(sys.argv[2], defines)
with open(sys.argv[3], 'w') as f:
f.write(output)
info = os.stat(sys.argv[2])
os.chmod(sys.argv[3], info.st_mode)
if __name__ == '__main__':
main()