Skip to content

Commit

Permalink
Merge pull request voxpupuli#138 from traylenator/sl6
Browse files Browse the repository at this point in the history
Fixes voxpupuli#133 Use semange -f 'all files' on RHEL6
  • Loading branch information
roidelapluie committed Dec 14, 2016
2 parents 02b1fff + 4616cc2 commit f341fca
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
19 changes: 17 additions & 2 deletions manifests/fcontext.pp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,23 @@
fail('"filemode" must be one of: a,f,d,c,b,s,l,p - see "man semanage-fcontext"')
}
$resource_name = "add_${context}_${pathname}_type_${filemode}"
$command = shellquote('semanage', 'fcontext','-a', '-f', $filemode, '-t', $context, $pathname)
$unless = sprintf('semanage fcontext -E | grep -Fx %s', shellquote("fcontext -a -f ${filemode} -t ${context} '${pathname}'"))
if $::osfamily == 'RedHat' and $::operatingsystemmajrelease == '6' {
case $filemode {
'a': {
$_filemode = 'all files'
$_quotedfilemode = '\'all files\''
}
default: {
$_filemode = $filemode
$_quotedfilemode = $_filemode
}
}
} else {
$_filemode = $filemode
$_quotedfilemode = $_filemode
}
$command = shellquote('semanage', 'fcontext','-a', '-f', $_filemode, '-t', $context, $pathname)
$unless = sprintf('semanage fcontext -E | grep -Fx %s', shellquote("fcontext -a -f ${_quotedfilemode} -t ${context} '${pathname}'"))
}

Exec {
Expand Down
32 changes: 27 additions & 5 deletions spec/defines/selinux_fcontext_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@
context: 'user_home_dir_t'
}
end
it { is_expected.to contain_exec('add_user_home_dir_t_/tmp/file1_type_a').with(command: 'semanage fcontext -a -f a -t user_home_dir_t /tmp/file1') }
if (facts[:osfamily] == 'RedHat') && (facts[:operatingsystemmajrelease] == '6')
it { is_expected.to contain_exec('add_user_home_dir_t_/tmp/file1_type_a').with(command: 'semanage fcontext -a -f "all files" -t user_home_dir_t /tmp/file1') }
else
it { is_expected.to contain_exec('add_user_home_dir_t_/tmp/file1_type_a').with(command: 'semanage fcontext -a -f a -t user_home_dir_t /tmp/file1') }
end
it { is_expected.to contain_exec('restorecond add_user_home_dir_t_/tmp/file1_type_a').with(command: 'restorecon /tmp/file1') }
end

Expand All @@ -99,7 +103,11 @@
context: 'user_home_dir_t'
}
end
it { is_expected.to contain_exec('add_user_home_dir_t_/tmp/file1_type_a').with(command: 'semanage fcontext -a -f a -t user_home_dir_t /tmp/file1') }
if (facts[:osfamily] == 'RedHat') && (facts[:operatingsystemmajrelease] == '6')
it { is_expected.to contain_exec('add_user_home_dir_t_/tmp/file1_type_a').with(command: 'semanage fcontext -a -f "all files" -t user_home_dir_t /tmp/file1') }
else
it { is_expected.to contain_exec('add_user_home_dir_t_/tmp/file1_type_a').with(command: 'semanage fcontext -a -f a -t user_home_dir_t /tmp/file1') }
end
it { is_expected.to contain_exec('restorecond add_user_home_dir_t_/tmp/file1_type_a').with(command: 'restorecon /tmp/file1') }
end

Expand All @@ -121,7 +129,11 @@
restorecond_path: '/tmp/file1/different'
}
end
it { is_expected.to contain_exec('add_user_home_dir_t_/tmp/file1_type_a').with(command: 'semanage fcontext -a -f a -t user_home_dir_t /tmp/file1') }
if (facts[:osfamily] == 'RedHat') && (facts[:operatingsystemmajrelease] == '6')
it { is_expected.to contain_exec('add_user_home_dir_t_/tmp/file1_type_a').with(command: 'semanage fcontext -a -f "all files" -t user_home_dir_t /tmp/file1') }
else
it { is_expected.to contain_exec('add_user_home_dir_t_/tmp/file1_type_a').with(command: 'semanage fcontext -a -f a -t user_home_dir_t /tmp/file1') }
end
it { is_expected.to contain_exec('restorecond add_user_home_dir_t_/tmp/file1_type_a').with(command: 'restorecon /tmp/file1/different') }
end
context 'with restorecon recurse specific path' do
Expand All @@ -133,7 +145,13 @@
restorecond_recurse: true
}
end
it { is_expected.to contain_exec('add_user_home_dir_t_/tmp/file1_type_a').with(command: 'semanage fcontext -a -f a -t user_home_dir_t /tmp/file1') }
if (facts[:osfamily] == 'RedHat') && (facts[:operatingsystemmajrelease] == '6')
it { is_expected.to contain_exec('add_user_home_dir_t_/tmp/file1_type_a').with(command: 'semanage fcontext -a -f "all files" -t user_home_dir_t /tmp/file1') }
it { is_expected.to contain_exec('add_user_home_dir_t_/tmp/file1_type_a').with(unless: "semanage fcontext -E | grep -Fx \"fcontext -a -f 'all files' -t user_home_dir_t '/tmp/file1'\"") }
else
it { is_expected.to contain_exec('add_user_home_dir_t_/tmp/file1_type_a').with(command: 'semanage fcontext -a -f a -t user_home_dir_t /tmp/file1') }
it { is_expected.to contain_exec('add_user_home_dir_t_/tmp/file1_type_a').with(unless: "semanage fcontext -E | grep -Fx \"fcontext -a -f a -t user_home_dir_t '/tmp/file1'\"") }
end
it { is_expected.to contain_exec('restorecond add_user_home_dir_t_/tmp/file1_type_a').with(command: 'restorecon -R /tmp/file1/different') }
end
context 'with restorecon path with quotation' do
Expand All @@ -143,7 +161,11 @@
context: 'user_home_dir_t'
}
end
it { is_expected.to contain_exec('add_user_home_dir_t_/tmp/"$HOME"/"$PATH"/[^ \'\\\#\`]+(?:.*)_type_a').with(command: 'semanage fcontext -a -f a -t user_home_dir_t "/tmp/\\"\\$HOME\\"/\\"\\$PATH\\"/[^ \'\\\\\\\\#\\\\\`]+(?:.*)"') }
if (facts[:osfamily] == 'RedHat') && (facts[:operatingsystemmajrelease] == '6')
it { is_expected.to contain_exec('add_user_home_dir_t_/tmp/"$HOME"/"$PATH"/[^ \'\\\#\`]+(?:.*)_type_a').with(command: 'semanage fcontext -a -f "all files" -t user_home_dir_t "/tmp/\\"\\$HOME\\"/\\"\\$PATH\\"/[^ \'\\\\\\\\#\\\\\`]+(?:.*)"') }
else
it { is_expected.to contain_exec('add_user_home_dir_t_/tmp/"$HOME"/"$PATH"/[^ \'\\\#\`]+(?:.*)_type_a').with(command: 'semanage fcontext -a -f a -t user_home_dir_t "/tmp/\\"\\$HOME\\"/\\"\\$PATH\\"/[^ \'\\\\\\\\#\\\\\`]+(?:.*)"') }
end
it { is_expected.to contain_exec('restorecond add_user_home_dir_t_/tmp/"$HOME"/"$PATH"/[^ \'\\\#\`]+(?:.*)_type_a').with(command: 'restorecon "/tmp/\\"\\$HOME\\"/\\"\\$PATH\\"/[^ \'\\\\\\\\#\\\\\`]+(?:.*)"') }
end
end
Expand Down

0 comments on commit f341fca

Please sign in to comment.