<div dir="ltr">Hello,<br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 18, 2015 at 12:24 AM, Christian Boltz <span dir="ltr"><<a href="mailto:apparmor@cboltz.de" target="_blank">apparmor@cboltz.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br>
<br>
this patch rewrites parse_profile_start() in aa.py to a more readable<br>
version. The behaviour remains unchanged (and is covered by tests).<br>
<br>
The patch also updates the comment about the internal struct of<br>
aa[profile][hat] - initial_comment was missing.<br>
<br>
<br>
[ 25-rewrite-parse_profile_start.diff ]<br>
<br>
=== modified file utils/apparmor/aa.py<br>
--- utils/apparmor/aa.py 2015-03-17 19:49:58.129177681 +0100<br>
+++ utils/apparmor/aa.py 2015-03-17 19:49:07.899127019 +0100<br>
@@ -105,7 +105,7 @@<br>
# a) rules (as dict): alias, change_profile, include, lvar, rlimit<br>
# b) rules (as hasher): allow, deny<br>
# c) one for each rule class<br>
-# d) other: declared, external, flags, name, profile, attachment,<br>
+# d) other: declared, external, flags, name, profile, attachment, initial_comment,<br>
# profile_keyword, header_comment (these two are currently only set by set_profile_flags())<br>
aa = hasher() # Profiles originally in sd, replace by aa<br>
original_aa = hasher()<br>
@@ -2641,31 +2641,31 @@<br>
def parse_profile_start(line, file, lineno, profile, hat):<br>
matches = parse_profile_start_line(line, file)<br>
<br>
- pps_set_profile = False<br>
- pps_set_hat_external = False<br></blockquote><div><br></div><div>Python's scoping for variables with if is not something I like, but okay to clean-up.<br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ if profile: # we are inside a profile, so we expect a child profile<br>
+ if not matches['profile_keyword']:<br>
+ raise AppArmorException(_('%(profile)s profile in %(file)s contains syntax errors in line %(line)s: missing "profile" keyword.') % {<br>
+ 'profile': profile, 'file': file, 'line': lineno + 1 })<br>
+ if profile != hat:<br>
+ # nesting limit reached - a child profile can't contain another child profile<br>
+ raise AppArmorException(_('%(profile)s profile in %(file)s contains syntax errors in line %(line)s: a child profile inside another child profile is not allowed.') % {<br>
+ 'profile': profile, 'file': file, 'line': lineno + 1 })<br>
<br>
- if profile:<br>
- #print(profile, hat)<br>
- if profile != hat or not matches['profile_keyword']:<br>
- raise AppArmorException(_('%(profile)s profile in %(file)s contains syntax errors in line: %(line)s.') % { 'profile': profile, 'file': file, 'line': lineno + 1 })<br>
- # Keep track of the start of a profile<br>
- if profile and profile == hat and matches['profile_keyword']:<br>
- # local profile<br>
hat = matches['profile']<br>
in_contained_hat = True<br>
pps_set_profile = True<br>
- else:<br>
+ pps_set_hat_external = False<br>
+<br>
+ else: # stand-alone profile<br>
profile = matches['profile']<br>
- #print(profile)<br>
if len(profile.split('//')) >= 2:<br>
profile, hat = profile.split('//')[:2]<br>
- else:<br>
- hat = None<br>
- in_contained_hat = False<br>
- if hat:<br>
pps_set_hat_external = True<br>
else:<br>
hat = profile<br>
+ pps_set_hat_external = False<br>
+<br>
+ in_contained_hat = False<br>
+ pps_set_profile = False<br>
<br>
attachment = matches['attachment']<br>
flags = matches['flags']<br>
<br>
<br></blockquote><div>Looks good to me.<br></div><div>Plus its covered by tests so good on that front.<br><br>Thanks for the re-write and cleanup.<br><br>Acked-by: Kshitij Gupta <<a href="mailto:kgupta8592@gmail.com" target="_blank">kgupta8592@gmail.com</a>><br> <br><div>Regards,<br><br></div>Kshitij Gupta<br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Regards,<br>
<br>
Christian Boltz<br>
<span class=""><font color="#888888">--<br>
Als Autofahrer würden die sich vergleichbar in einen PKW setzen der<br>
nicht abschliessbar ist und kein Zündschloss besitzt, dazu noch ein<br>
Zettel an der Tür, "Fahr mich, ich stehe zur Verfügung und bin<br>
Vollgetankt." [Thomas Templin in suse-linux über unsichere Passwörter]<br>
<br>
<br>
--<br>
AppArmor mailing list<br>
<a href="mailto:AppArmor@lists.ubuntu.com">AppArmor@lists.ubuntu.com</a><br>
Modify settings or unsubscribe at: <a href="https://lists.ubuntu.com/mailman/listinfo/apparmor" target="_blank">https://lists.ubuntu.com/mailman/listinfo/apparmor</a><br>
</font></span></blockquote></div><br></div></div>