[apparmor] [patch] aa.py: split off parse_profile_start() from parse_profile_data() and add tests

Steve Beattie steve at nxnw.org
Mon Mar 2 19:34:00 UTC 2015


On Sun, Mar 01, 2015 at 07:12:05PM +0100, Christian Boltz wrote:
> [ split-off-parse_profile_start-and-add-tests.diff ]

[SNIP]

> === modified file 'utils/apparmor/aa.py'
> --- utils/apparmor/aa.py        2015-02-20 20:36:55 +0000
> +++ utils/apparmor/aa.py        2015-03-01 17:42:11 +0000
> @@ -2632,6 +2642,49 @@
>      for p in profile_data.keys():
>          profiles[p] = deepcopy(profile_data[p])
>  
> +
> +def parse_profile_start(line, file, lineno, profile, hat):
> +    print (line)
> +    print("    profile %s   hat %s   file %s" % (profile, hat, file))
> +    matches = RE_PROFILE_START.search(line).groups()
> +
> +    pps_set_profile = False
> +    pps_set_hat_external = False
> +
> +    if profile:
> +        #print(profile, hat)
> +        if profile != hat or not matches[3]:
> +            raise AppArmorException(_('%(profile)s profile in %(file)s contains syntax errors in line: %(line)s.') % { 'profile': profile, 'file': file, 'line': lineno + 1 })
> +    # Keep track of the start of a profile
> +    if profile and profile == hat and matches[3]:
> +        # local profile
> +        hat = matches[3]
> +        in_contained_hat = True
> +        pps_set_profile = True
> +    else:
> +        if matches[1]:
> +            profile = matches[1]
> +        else:
> +            profile = matches[3]
> +        #print(profile)
> +        if len(profile.split('//')) >= 2:
> +            profile, hat = profile.split('//')[:2]
> +        else:
> +            hat = None
> +        in_contained_hat = False
> +        if hat:
> +            pps_set_hat_external = True
> +        else:
> +            hat = profile
> +
> +    flags = matches[6]
> +
> +    profile = strip_quotes(profile)
> +    if hat:
> +        hat = strip_quotes(hat)
> +
> +    return (profile, hat, flags, in_contained_hat, pps_set_profile, pps_set_hat_external)
> +
>  def parse_profile_data(data, file, do_include):
>      profile_data = hasher()
>      profile = None
> @@ -2655,41 +2708,15 @@
>              lastline = None
>          # Starting line of a profile
>          if RE_PROFILE_START.search(line):
> -            matches = RE_PROFILE_START.search(line).groups()
> -
> -            if profile:
> -                #print(profile, hat)
> -                if profile != hat or not matches[3]:
> -                    raise AppArmorException(_('%(profile)s profile in %(file)s contains syntax errors in line: %(line)s.') % { 'profile': profile, 'file': file, 'line': lineno + 1 })
> -            # Keep track of the start of a profile
> -            if profile and profile == hat and matches[3]:
> -                # local profile
> -                hat = matches[3]
> -                in_contained_hat = True
> +            (profile, hat, flags, in_contained_hat, pps_set_profile, pps_set_hat_external) = parse_profile_start(line, file, lineno, profile, hat, profile_data)

You pass 6 arguments to parse_profile_start() here, but the declaration
for it only takes 5 arguments. I'm guessing that's not intended?

> +            if pps_set_profile:
>                  profile_data[profile][hat]['profile'] = True
> -            else:
> -                if matches[1]:
> -                    profile = matches[1]
> -                else:
> -                    profile = matches[3]
> -                #print(profile)
> -                if len(profile.split('//')) >= 2:
> -                    profile, hat = profile.split('//')[:2]
> -                else:
> -                    hat = None
> -                in_contained_hat = False
> -                if hat:
> -                    profile_data[profile][hat]['external'] = True
> -                else:
> -                    hat = profile
> +            if pps_set_hat_external:
> +                profile_data[profile][hat]['external'] = True
> +
>              # Profile stored
>              existing_profiles[profile] = file
>  
> -            flags = matches[6]
> -
> -            profile = strip_quotes(profile)
> -            if hat:
> -                hat = strip_quotes(hat)
>              # save profile name and filename
>              profile_data[profile][hat]['name'] = profile
>              profile_data[profile][hat]['filename'] = file
> 
> 
> 
> Regards,
> 
> Christian Boltz
> -- 
> Ähhh, so ein Quark. Egal was du rauchst, es ist zuviel.
> [David Haller in opensuse-de]
> 
> 
> -- 
> AppArmor mailing list
> AppArmor at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor

-- 
Steve Beattie
<sbeattie at ubuntu.com>
http://NxNW.org/~steve/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20150302/e3bc8613/attachment.pgp>


More information about the AppArmor mailing list