198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn# blocks is an array of paths under which we want to block by
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn# blocks[0] = ['path' = '/sys', 'children' = [A,B] ]
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn# blocks[1] = ['path' = '/proc/sys', 'children' = [ E ] ]
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn# A = [ 'path' = 'fs', children = [C] ]
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn# C = [ 'path' = 'cgroup', children = [F] ]
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn# B = [ 'path' = 'class', children = [D] ]
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn# D = [ 'path' = 'net', children = [F] ]
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn# E = [ 'path' = 'shm*' ]
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn# F = [ 'path' = '**' ]
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn blocks.append({'path': path.strip(), 'children': []})
94a77f3fd8be2fb87f7d1465521fac3ec4b7e6b5Serge Hallyn# @prev is an array of dicts which containing 'path' and
94a77f3fd8be2fb87f7d1465521fac3ec4b7e6b5Serge Hallyn# 'children'. @path is a string. We are looking for an entry
94a77f3fd8be2fb87f7d1465521fac3ec4b7e6b5Serge Hallyn# in @prev which contains @path, and will return its
94a77f3fd8be2fb87f7d1465521fac3ec4b7e6b5Serge Hallyn# children array.
94a77f3fd8be2fb87f7d1465521fac3ec4b7e6b5Serge Hallyn return p['children']
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn # find which block we belong to
94a77f3fd8be2fb87f7d1465521fac3ec4b7e6b5Serge Hallyn # TODO - should we find the longest match?
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn print("allow with no previous block at %s" % path)
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn if tmp is not None:
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn except: # blank line
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn s = "%s wklx," % s
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn if char == len(c['path'])-1 and c['path'][char] == '*':
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn newdeny = "deny %s/%s[^%s]*{,/**}" % (pathsofar,
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn if c['path'] != '**' and c['path'][len(c['path'])-1] != '*':
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn newdeny = "deny %s/%s?*{,/**}" % (pathsofar, c['path'])
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn newdeny = "deny %s/%s/**" % (pathsofar, c['path'])
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyngenby = " # generated by: lxc-generate-aa-rules.py"
198b363fff1de9afcee2f26b9aa847316f589afeSerge Hallyn print(" %s" % d)