Skip to content

Instantly share code, notes, and snippets.

@andrwgldmn andrwgldmn/gromozdko Secret
Created Mar 10, 2019

Embed
What would you like to do?
with open('log.txt') as input_file, open('allows.txt', 'w') as output_file:
output_file.writelines(i for i in input_file if 'avc: denied' in i)
with open('allows.txt') as input_file, open('allows.te', 'w') as output_file:
text = input_file.read()
for scontext in re.findall('scontext=u:r:(.+?):s0', text):
scontext_wr = 'allow {}'.format(scontext)
for tcontext in re.findall('tcontext=u:r:(.+?):s0', text):
tcontext_wr = ' {}:'.format(tcontext)
for tcls in re.findall('tclass=(.+?):s0', text):
tcls_w = '{} '.format(tcls)
#output_file.write(tcls_w)
for braces in re.findall('denied (.+?) for', text):
braces_wr = '{}; \n'.format(braces)
output = (scontext_wr + tcontext_wr + tcls_w + braces_wr)
output_file.write(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.