2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-30 13:58:22 +00:00

Implement code review comments.

This commit is contained in:
Mark Grassi
2022-07-19 20:32:03 -04:00
parent cf6606d380
commit e6cbdef4ab
2 changed files with 11 additions and 3 deletions

View File

@@ -2164,8 +2164,15 @@ def write_profile(profile, is_attachment=False):
serialize_options = {'METADATA': True, 'is_attachment': is_attachment}
profile_string = serialize_profile(split_to_merged(aa), profile, serialize_options)
with open(prof_filename, 'w') as file: # Keep this context simple: don't want to corrupt file.
file.write(profile_string)
with NamedTemporaryFile('w', suffix='~', delete=False, dir=profile_dir) as newprof:
if os.path.exists(prof_filename):
shutil.copymode(prof_filename, newprof.name)
else:
# permission_600 = stat.S_IRUSR | stat.S_IWUSR # Owner read and write
# os.chmod(newprof.name, permission_600)
pass
newprof.write(profile_string)
os.rename(newprof.name, prof_filename)
if profile in changed:
changed.pop(profile)

View File

@@ -677,8 +677,9 @@ class AppArmorEasyProfile:
if not isinstance(policy, bytes):
policy = policy.encode('utf-8')
with open(out_fn, "wb") as f:
with NamedTemporaryFile('wb', prefix='aa-easyprof', suffix='~', delete=False) as f:
f.write(policy)
os.rename(f.name, out_fn)
def gen_manifest(self, params):
'''Take params list and output a JSON file'''