Ejemplo n.º 1
0
    def get_clean(self, depth=0):
        '''return rule (in clean/default formatting)'''

        space = '  ' * depth

        if self.execmode:
            execmode = ' %s' % self.execmode
        else:
            execmode = ''

        if self.all_execconds:
            execcond = ''
        elif self.execcond:
            execcond = ' %s' % quote_if_needed(self.execcond)
        else:
            raise AppArmorBug('Empty execcond in change_profile rule')

        if self.all_targetprofiles:
            targetprofile = ''
        elif self.targetprofile:
            targetprofile = ' -> %s' % quote_if_needed(self.targetprofile)
        else:
            raise AppArmorBug('Empty target profile in change_profile rule')

        return ('%s%schange_profile%s%s%s,%s' %
                (space, self.modifiers_str(), execmode, execcond,
                 targetprofile, self.comment))
Ejemplo n.º 2
0
    def get_clean(self, depth=0):
        '''return rule (in clean/default formatting)'''

        space = '  ' * depth

        return '%salias %s -> %s,' % (space, quote_if_needed(
            self.orig_path), quote_if_needed(self.target))
Ejemplo n.º 3
0
    def get_clean(self, depth=0):
        '''return rule (in clean/default formatting)'''

        space = '  ' * depth

        if self.all_paths:
            path = ''
        elif self.path:
            path = quote_if_needed(self.path.regex)
        else:
            raise AppArmorBug('Empty path in file rule')

        if self.all_perms:
            perms = ''
        else:
            perms = self._joint_perms()
            if not perms:
                raise AppArmorBug('Empty permissions in file rule')

        if self.leading_perms:
            path_and_perms = '%s %s' % (perms, path)
        else:
            path_and_perms = '%s %s' % (path, perms)

        if self.all_targets:
            target = ''
        elif self.target:
            target = ' -> %s' % quote_if_needed(self.target.regex)
        else:
            raise AppArmorBug('Empty exec target in file rule')

        if self.owner:
            owner = 'owner '
        else:
            owner = ''

        if self.file_keyword:
            file_keyword = 'file '
        else:
            file_keyword = ''

        if self.all_paths and self.all_perms and not path and not perms and not target:
            return ('%s%s%sfile,%s' %
                    (space, self.modifiers_str(), owner, self.comment)
                    )  # plain 'file,' rule
        elif not self.all_paths and not self.all_perms and path and perms:
            return ('%s%s%s%s%s%s,%s' %
                    (space, self.modifiers_str(), file_keyword, owner,
                     path_and_perms, target, self.comment))
        else:
            raise AppArmorBug(
                'Invalid combination of path and perms in file rule - either specify path and perms, or none of them'
            )
Ejemplo n.º 4
0
    def get_clean(self, depth=0):
        '''return rule (in clean/default formatting)'''

        space = '  ' * depth

        if self.all_access:
            access = ''
        elif len(self.access) == 1:
            access = ' %s' % ' '.join(self.access)
        elif self.access:
            access = ' (%s)' % ' '.join(sorted(self.access))
        else:
            raise AppArmorBug('Empty access in signal rule')

        if self.all_signals:
            signal = ''
        elif len(self.signal) == 1:
            signal = ' set=%s' % ' '.join(self.signal)
        elif self.signal:
            signal = ' set=(%s)' % ' '.join(sorted(self.signal))
        else:
            raise AppArmorBug('Empty signal in signal rule')

        if self.all_peers:
            peer = ''
        elif self.peer:
            peer = ' peer=%s' % quote_if_needed(self.peer.regex)
        else:
            raise AppArmorBug('Empty peer in signal rule')

        return (
            '%s%ssignal%s%s%s,%s' %
            (space, self.modifiers_str(), access, signal, peer, self.comment))
Ejemplo n.º 5
0
def var_transform(ref):
    data = []
    for value in sorted(ref):
        if not value:
            value = '""'
        data.append(quote_if_needed(value))
    return ' '.join(data)
Ejemplo n.º 6
0
    def get_clean(self, depth=0):
        '''return rule (in clean/default formatting)'''

        space = '  ' * depth

        if self.rlimit:
            rlimit = ' %s' % quote_if_needed(self.rlimit)
        else:
            raise AppArmorBug('Empty rlimit in rlimit rule')

        if self.all_values:
            value = ' <= infinity'
        elif self.value:
            value = ' <= %s' % quote_if_needed(self.value)
        else:
            raise AppArmorBug('Empty value in rlimit rule')

        return('%s%sset rlimit%s%s,%s' % (space, self.modifiers_str(), rlimit, value, self.comment))
Ejemplo n.º 7
0
    def get_clean(self, depth=0):
        '''return rule (in clean/default formatting)'''

        space = '  ' * depth

        if self.rlimit:
            rlimit = ' %s' % quote_if_needed(self.rlimit)
        else:
            raise AppArmorBug('Empty rlimit in rlimit rule')

        if self.all_values:
            value = ' <= infinity'
        elif self.value:
            value = ' <= %s' % quote_if_needed(self.value)
        else:
            raise AppArmorBug('Empty value in rlimit rule')

        return('%s%sset rlimit%s%s,%s' % (space, self.modifiers_str(), rlimit, value, self.comment))
Ejemplo n.º 8
0
    def get_clean(self, depth=0):
        '''return rule (in clean/default formatting)'''

        space = '  ' * depth

        if self.all_execconds:
            execcond = ''
        elif self.execcond:
            execcond = ' %s' % quote_if_needed(self.execcond)
        else:
            raise AppArmorBug('Empty execcond in change_profile rule')

        if self.all_targetprofiles:
            targetprofile = ''
        elif self.targetprofile:
            targetprofile = ' -> %s' % quote_if_needed(self.targetprofile)
        else:
            raise AppArmorBug('Empty target profile in change_profile rule')

        return('%s%schange_profile%s%s,%s' % (space, self.modifiers_str(), execcond, targetprofile, self.comment))
Ejemplo n.º 9
0
    def get_clean(self, depth=0):
        '''return rule (in clean/default formatting)'''

        space = '  ' * depth

        data = []
        for value in sorted(self.values):
            if not value:
                value = '""'
            data.append(quote_if_needed(value))

        return '%s%s %s %s' % (space, self.varname, self.mode, ' '.join(data))
Ejemplo n.º 10
0
 def _get_aare_rule_part(self, prefix, value, all_values):
     '''helper function to write a rule part
        value is expected to be a AARE'''
     if all_values:
         return ''
     elif value:
         return ' %(prefix)s=%(value)s' % {
             'prefix': prefix,
             'value': quote_if_needed(value.regex)
         }
     else:
         raise AppArmorBug('Empty %(prefix_name)s in %(rule_name)s rule' % {
             'prefix_name': prefix,
             'rule_name': self.rule_name
         })