mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 08:24:42 +01:00
Ease memory usage by collating rules in string form rather than as Rule
objects. Add randomly generating profile flags.
This commit is contained in:
parent
21875a520d
commit
2a0df39961
1 changed files with 57 additions and 6 deletions
|
@ -83,7 +83,10 @@ class CapRule < Rule
|
|||
"mknod",
|
||||
"lease",
|
||||
"audit_write",
|
||||
"audit_control"
|
||||
"audit_control",
|
||||
"setfcap",
|
||||
"mac_override",
|
||||
"mac_admin"
|
||||
]
|
||||
|
||||
def initialize()
|
||||
|
@ -104,6 +107,53 @@ def prefix_to_s(name)
|
|||
out << "#"
|
||||
end
|
||||
|
||||
class Flags
|
||||
FLAG_LIST = [
|
||||
"complain",
|
||||
"audit",
|
||||
"chroot_relative",
|
||||
"namespace_relative",
|
||||
"mediate_deleted",
|
||||
"delegate_deleted",
|
||||
"attach_disconnected",
|
||||
"no_attach_disconnected",
|
||||
"chroot_attach",
|
||||
"chroot_no_attach"
|
||||
]
|
||||
|
||||
FLAG_CONFLICTS = [
|
||||
["chroot_relative", "namespace_relative"],
|
||||
["mediate_deleted", "delegate_deleted"],
|
||||
["attach_disconnected", "no_attach_disconnected"],
|
||||
["chroot_attach", "chroot_no_attach"]
|
||||
]
|
||||
|
||||
def initialize()
|
||||
@flags = []
|
||||
if rand(2) == 1
|
||||
return
|
||||
end
|
||||
|
||||
0.upto(4 - Math.log(rand(32) + 1).to_int) do |x|
|
||||
@flags << FLAG_LIST[rand(FLAG_LIST.length)]
|
||||
end
|
||||
|
||||
FLAG_CONFLICTS.each do |c|
|
||||
if @flags.include?(c[0]) and @flags.include?(c[1])
|
||||
@flags.delete(c[rand(2)])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def to_s
|
||||
if @flags.empty?
|
||||
return ""
|
||||
end
|
||||
out = @flags.join(",")
|
||||
return "flags=(#{out})"
|
||||
end
|
||||
end
|
||||
|
||||
class Profile
|
||||
attr_reader :rvalue
|
||||
attr_reader :name
|
||||
|
@ -112,16 +162,17 @@ class Profile
|
|||
@rvalue = get_random_name()
|
||||
@name = "/does/not/exist/#{@rvalue}"
|
||||
@rules = []
|
||||
@flags = Flags.new()
|
||||
end
|
||||
|
||||
def generate_rules
|
||||
@rules << FileRule.new(@name, "rm")
|
||||
@rules << FileRule.new(@name, "rm").to_s
|
||||
0.upto(rand($max_rules - $min_rules) + $min_rules) do |x|
|
||||
case rand(100)
|
||||
when 0..19
|
||||
@rules << CapRule.new
|
||||
@rules << CapRule.new.to_s
|
||||
when 19..100
|
||||
@rules << FileRule.new
|
||||
@rules << FileRule.new.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -132,10 +183,10 @@ class Profile
|
|||
out << "# profile for #{@name}"
|
||||
out << "# generated by #{__FILE__} #{$my_version}"
|
||||
out << "#"
|
||||
out << "#{@name} {"
|
||||
out << "#{@name} #{@flags} {"
|
||||
out << " #include <abstractions/base>"
|
||||
out << ""
|
||||
@rules.each { |r| out << r.to_s }
|
||||
@rules.sort.each { |r| out << " #{r}" }
|
||||
out << "}"
|
||||
out << ""
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue