Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selinux_build_module_simple.sh: improve quoting #375

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions files/selinux_build_module_simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ module_dir="$2"

set -e

cd $module_dir
test -d tmp || mkdir tmp
cd "$module_dir"
mkdir -p tmp

checkmodule -M -m -o "tmp/${module_name}.mod" "${module_name}.te"

checkmodule -M -m -o tmp/${module_name}.mod ${module_name}.te
package_args="-o ${module_name}.pp -m tmp/${module_name}.mod"
if [ -s "${module_name}.fc" ]; then
package_args="${package_args} --fc ${module_name}.fc"
semodule_package -o "${module_name}.pp" -m "tmp/${module_name}.mod" --fc "${module_name}.fc"
else
semodule_package -o "${module_name}.pp" -m "tmp/${module_name}.mod"
fi

semodule_package ${package_args}
4 changes: 2 additions & 2 deletions manifests/module.pp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
exec { "build-module-${title}":
path => '/bin:/usr/bin',
cwd => $module_dir,
command => "${build_command} || (rm -f ${module_file}.pp ${module_file}.loaded && exit 1)",
command => "${build_command} || (rm -f '${module_file}.pp' '${module_file}.loaded' && exit 1)",
creates => "${module_file}.pp",
notify => Exec["install-module-${title}"],
}
Expand Down Expand Up @@ -168,7 +168,7 @@
exec { "install-module-${title}":
path => '/sbin:/usr/sbin:/bin:/usr/bin',
cwd => $module_dir,
command => "semodule -i ${module_file}.pp && touch ${module_file}.loaded",
command => "semodule -i '${module_file}.pp' && touch '${module_file}.loaded'",
creates => "${module_file}.loaded",
before => Selmodule[$title],
}
Expand Down
26 changes: 13 additions & 13 deletions spec/defines/selinux_module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
it { is_expected.to contain_file("#{workdir}/mymodule.fc").with(source: nil, content: '') }
it { is_expected.to contain_file("#{workdir}/mymodule.if").with(source: nil, content: '') }
it { is_expected.to contain_exec('clean-module-mymodule').with(command: "rm -f '#{module_basepath}.pp' '#{module_basepath}.loaded'", cwd: workdir) }
it { is_expected.to contain_exec('build-module-mymodule').with(command: "make -f /usr/share/selinux/devel/Makefile mymodule.pp || (rm -f #{module_basepath}.pp #{module_basepath}.loaded && exit 1)", creates: "#{module_basepath}.pp") }
it { is_expected.to contain_exec('install-module-mymodule').with(command: "semodule -i #{module_basepath}.pp && touch #{module_basepath}.loaded", cwd: workdir, creates: "#{module_basepath}.loaded") }
it { is_expected.to contain_exec('build-module-mymodule').with(command: "make -f /usr/share/selinux/devel/Makefile mymodule.pp || (rm -f '#{module_basepath}.pp' '#{module_basepath}.loaded' && exit 1)", creates: "#{module_basepath}.pp") }
it { is_expected.to contain_exec('install-module-mymodule').with(command: "semodule -i '#{module_basepath}.pp' && touch '#{module_basepath}.loaded'", cwd: workdir, creates: "#{module_basepath}.loaded") }
it { is_expected.to contain_selmodule('mymodule').with_ensure('present', selmodulepath: workdir) }
end

Expand All @@ -65,8 +65,8 @@
it { is_expected.to contain_file("#{workdir}/mymodule.fc").that_notifies('Exec[clean-module-mymodule]') }
it { is_expected.to contain_file("#{workdir}/mymodule.if").with(source: nil, content: '') }
it { is_expected.to contain_exec('clean-module-mymodule').with(command: "rm -f '#{module_basepath}.pp' '#{module_basepath}.loaded'", cwd: workdir) }
it { is_expected.to contain_exec('build-module-mymodule').with(command: "make -f /usr/share/selinux/devel/Makefile mymodule.pp || (rm -f #{module_basepath}.pp #{module_basepath}.loaded && exit 1)", creates: "#{module_basepath}.pp") }
it { is_expected.to contain_exec('install-module-mymodule').with(command: "semodule -i #{module_basepath}.pp && touch #{module_basepath}.loaded", cwd: workdir, creates: "#{module_basepath}.loaded") }
it { is_expected.to contain_exec('build-module-mymodule').with(command: "make -f /usr/share/selinux/devel/Makefile mymodule.pp || (rm -f '#{module_basepath}.pp' '#{module_basepath}.loaded' && exit 1)", creates: "#{module_basepath}.pp") }
it { is_expected.to contain_exec('install-module-mymodule').with(command: "semodule -i '#{module_basepath}.pp' && touch '#{module_basepath}.loaded'", cwd: workdir, creates: "#{module_basepath}.loaded") }
it { is_expected.to contain_selmodule('mymodule').with_ensure('present', selmodulepath: workdir) }
end

Expand All @@ -85,8 +85,8 @@
it { is_expected.to contain_file("#{workdir}/mymodule.if").that_notifies('Exec[clean-module-mymodule]') }
it { is_expected.to contain_file("#{workdir}/mymodule.fc").that_notifies('Exec[clean-module-mymodule]') }
it { is_expected.to contain_exec('clean-module-mymodule').with(command: "rm -f '#{module_basepath}.pp' '#{module_basepath}.loaded'", cwd: workdir) }
it { is_expected.to contain_exec('build-module-mymodule').with(command: "make -f /usr/share/selinux/devel/Makefile mymodule.pp || (rm -f #{module_basepath}.pp #{module_basepath}.loaded && exit 1)", creates: "#{module_basepath}.pp") }
it { is_expected.to contain_exec('install-module-mymodule').with(command: "semodule -i #{module_basepath}.pp && touch #{module_basepath}.loaded", cwd: workdir, creates: "#{module_basepath}.loaded") }
it { is_expected.to contain_exec('build-module-mymodule').with(command: "make -f /usr/share/selinux/devel/Makefile mymodule.pp || (rm -f '#{module_basepath}.pp' '#{module_basepath}.loaded' && exit 1)", creates: "#{module_basepath}.pp") }
it { is_expected.to contain_exec('install-module-mymodule').with(command: "semodule -i '#{module_basepath}.pp' && touch '#{module_basepath}.loaded'", cwd: workdir, creates: "#{module_basepath}.loaded") }
it { is_expected.to contain_selmodule('mymodule').with_ensure('present', selmodulepath: workdir) }
end

Expand All @@ -105,8 +105,8 @@
it { is_expected.to contain_file("#{workdir}/mymodule.if").with(source: nil, content: 'interface(puppet_test)').that_notifies('Exec[clean-module-mymodule]') }
it { is_expected.to contain_file("#{workdir}/mymodule.fc").with(source: nil, content: '/bin/sh system_u:object_r:bin_t').that_notifies('Exec[clean-module-mymodule]') }
it { is_expected.to contain_exec('clean-module-mymodule').with(command: "rm -f '#{module_basepath}.pp' '#{module_basepath}.loaded'", cwd: workdir) }
it { is_expected.to contain_exec('build-module-mymodule').with(command: "make -f /usr/share/selinux/devel/Makefile mymodule.pp || (rm -f #{module_basepath}.pp #{module_basepath}.loaded && exit 1)", creates: "#{module_basepath}.pp") }
it { is_expected.to contain_exec('install-module-mymodule').with(command: "semodule -i #{module_basepath}.pp && touch #{module_basepath}.loaded", cwd: workdir, creates: "#{module_basepath}.loaded") }
it { is_expected.to contain_exec('build-module-mymodule').with(command: "make -f /usr/share/selinux/devel/Makefile mymodule.pp || (rm -f '#{module_basepath}.pp' '#{module_basepath}.loaded' && exit 1)", creates: "#{module_basepath}.pp") }
it { is_expected.to contain_exec('install-module-mymodule').with(command: "semodule -i '#{module_basepath}.pp' && touch '#{module_basepath}.loaded'", cwd: workdir, creates: "#{module_basepath}.loaded") }
it { is_expected.to contain_selmodule('mymodule').with_ensure('present', selmodulepath: workdir) }
end

Expand All @@ -124,8 +124,8 @@
it { is_expected.to contain_file("#{workdir}/mymodule.fc").with(source: nil, content: '') }
it { is_expected.to contain_file("#{workdir}/mymodule.if").with(source: nil, content: '') }
it { is_expected.to contain_exec('clean-module-mymodule').with(command: "rm -f '#{module_basepath}.pp' '#{module_basepath}.loaded'", cwd: workdir) }
it { is_expected.to contain_exec('build-module-mymodule').with(command: "/var/lib/puppet/puppet-selinux/bin/selinux_build_module_simple.sh mymodule #{workdir} || (rm -f #{module_basepath}.pp #{module_basepath}.loaded && exit 1)", creates: "#{module_basepath}.pp") }
it { is_expected.to contain_exec('install-module-mymodule').with(command: "semodule -i #{module_basepath}.pp && touch #{module_basepath}.loaded", cwd: workdir, creates: "#{module_basepath}.loaded") }
it { is_expected.to contain_exec('build-module-mymodule').with(command: "/var/lib/puppet/puppet-selinux/bin/selinux_build_module_simple.sh mymodule #{workdir} || (rm -f '#{module_basepath}.pp' '#{module_basepath}.loaded' && exit 1)", creates: "#{module_basepath}.pp") }
it { is_expected.to contain_exec('install-module-mymodule').with(command: "semodule -i '#{module_basepath}.pp' && touch '#{module_basepath}.loaded'", cwd: workdir, creates: "#{module_basepath}.loaded") }
it { is_expected.to contain_selmodule('mymodule').with_ensure('present', selmodulepath: workdir) }
end

Expand All @@ -142,8 +142,8 @@
it { is_expected.to contain_file("#{workdir}/mymodule.fc").with(source: nil, content: '') }
it { is_expected.to contain_file("#{workdir}/mymodule.if").with(source: nil, content: '') }
it { is_expected.to contain_exec('clean-module-mymodule').with(command: "rm -f '#{module_basepath}.pp' '#{module_basepath}.loaded'", cwd: workdir) }
it { is_expected.to contain_exec('build-module-mymodule').with(command: "/var/lib/puppet/puppet-selinux/bin/selinux_build_module_simple.sh mymodule #{workdir} || (rm -f #{module_basepath}.pp #{module_basepath}.loaded && exit 1)", creates: "#{module_basepath}.pp") }
it { is_expected.to contain_exec('install-module-mymodule').with(command: "semodule -i #{module_basepath}.pp && touch #{module_basepath}.loaded", cwd: workdir, creates: "#{module_basepath}.loaded") }
it { is_expected.to contain_exec('build-module-mymodule').with(command: "/var/lib/puppet/puppet-selinux/bin/selinux_build_module_simple.sh mymodule #{workdir} || (rm -f '#{module_basepath}.pp' '#{module_basepath}.loaded' && exit 1)", creates: "#{module_basepath}.pp") }
it { is_expected.to contain_exec('install-module-mymodule').with(command: "semodule -i '#{module_basepath}.pp' && touch '#{module_basepath}.loaded'", cwd: workdir, creates: "#{module_basepath}.loaded") }
it { is_expected.to contain_selmodule('mymodule').with_ensure('present', selmodulepath: workdir) }
end

Expand All @@ -170,7 +170,7 @@
it { is_expected.to contain_file(workdir) }
it { is_expected.to contain_file("#{workdir}/mymodule.pp").that_notifies('Exec[clean-module-mymodule]') }
it { is_expected.to contain_exec('clean-module-mymodule').with(command: "rm -f '#{module_basepath}.loaded'", cwd: workdir) }
it { is_expected.to contain_exec('install-module-mymodule').with(command: "semodule -i #{module_basepath}.pp && touch #{module_basepath}.loaded", cwd: workdir, creates: "#{module_basepath}.loaded") }
it { is_expected.to contain_exec('install-module-mymodule').with(command: "semodule -i '#{module_basepath}.pp' && touch '#{module_basepath}.loaded'", cwd: workdir, creates: "#{module_basepath}.loaded") }
it { is_expected.to contain_selmodule('mymodule').with_ensure('present', selmodulepath: workdir) }
end

Expand Down