summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/util/selinux.rb13
-rw-r--r--spec/unit/util/selinux.rb2
2 files changed, 12 insertions, 3 deletions
diff --git a/lib/puppet/util/selinux.rb b/lib/puppet/util/selinux.rb
index 0a4af3ca1..148748950 100644
--- a/lib/puppet/util/selinux.rb
+++ b/lib/puppet/util/selinux.rb
@@ -6,8 +6,12 @@
# are available. At this time (2008-09-26) these bindings aren't bundled on
# any SELinux-using distribution I know of.
+require 'puppet/util'
+
module Puppet::Util::SELinux
+ include Puppet::Util
+
def selinux_support?
FileTest.exists?("/selinux/enforce")
end
@@ -103,10 +107,15 @@ module Puppet::Util::SELinux
when :selrange
flag = "-l"
else
- flag = ""
+ flag = nil
end
- execute(["/usr/bin/chcon","-h",flag,value,file])
+ if flag.nil?
+ cmd = ["/usr/bin/chcon","-h",value,file]
+ else
+ cmd = ["/usr/bin/chcon","-h",flag,value,file]
+ end
+ execute(cmd)
return true
end
diff --git a/spec/unit/util/selinux.rb b/spec/unit/util/selinux.rb
index 515c3a273..7a56f914a 100644
--- a/spec/unit/util/selinux.rb
+++ b/spec/unit/util/selinux.rb
@@ -117,7 +117,7 @@ describe Puppet::Util::SELinux do
it "should use chcon to set a context" do
self.expects(:selinux_support?).returns true
- self.expects(:execute).with(["/usr/bin/chcon","-h","","user_u:role_r:type_t:s0","/foo"]).returns 0
+ self.expects(:execute).with(["/usr/bin/chcon","-h","user_u:role_r:type_t:s0","/foo"]).returns 0
set_selinux_context("/foo", "user_u:role_r:type_t:s0").should be_true
end