-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See: tools/testing/selftests/kexec/kexec_common_lib.sh Co-authored-by: Trevor Vaughan <tvaughan@onyxpoint.com>
- Loading branch information
1 parent
77628f6
commit 6710c51
Showing
4 changed files
with
202 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# _Description_ | ||
# | ||
# Return true if system booted via EFI | ||
# | ||
Facter.add("simplib__efi_enabled") do | ||
confine :kernel => 'Linux' | ||
|
||
setcode do | ||
File.exist?('/sys/firmware/efi') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# _Description_ | ||
# | ||
# Return true if system booted via UEFI Secure Boot | ||
# | ||
Facter.add("simplib__secure_boot_enabled") do | ||
confine :kernel => 'Linux' | ||
|
||
setcode do | ||
secure_boot_status = false | ||
Dir.glob('/sys/firmware/efi/efivars/SecureBoot-*').each do | file | | ||
begin | ||
File.open(file, 'r') do | hexcode | | ||
# skip leading status codes | ||
hexcode.read(4) | ||
code = hexcode.read() | ||
# If we didn't get any data, unpacking will fail | ||
secure_boot_status = (1 == code.unpack('H*').first.to_i) if code | ||
end | ||
rescue Errno::EPERM, Errno::EACCES | ||
next | ||
end | ||
|
||
break if secure_boot_status | ||
end | ||
|
||
setup_mode_status = false | ||
if secure_boot_status | ||
Dir.glob('/sys/firmware/efi/efivars/SetupMode-*').each do | file | | ||
begin | ||
File.open(file, 'r') do | hexcode | | ||
# skip leading status codes | ||
hexcode.read(4) | ||
code = hexcode.read() | ||
# If we didn't get any data, unpacking will fail | ||
setup_mode_status = (0 == code.unpack('H*').first.to_i) if code | ||
end | ||
rescue Errno::EPERM, Errno::EACCES | ||
next | ||
end | ||
|
||
break if setup_mode_status | ||
end | ||
end | ||
|
||
secure_boot_status & setup_mode_status | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'simplib__secure_boot_enabled' do | ||
before :each do | ||
Facter.clear | ||
Facter.stubs(:value).with(:kernel).returns('Linux') | ||
end | ||
|
||
context 'without SecureBoot files in /sys/firmware/efi/efivars' do | ||
it do | ||
Dir.stubs(:glob).with('/sys/firmware/efi/efivars/SecureBoot-*').returns([]) | ||
|
||
expect(Facter.fact('simplib__secure_boot_enabled').value).to match(false) | ||
end | ||
end | ||
|
||
context 'with a SecureBoot file in /sys/firmware/efi/efivars' do | ||
before :each do | ||
@sb_tempfile = Tempfile.new('simplib__secure_boot_enabled') | ||
@sm_tempfile = Tempfile.new('simplib__secure_boot_enabled') | ||
|
||
Dir.stubs(:glob).with('/sys/firmware/efi/efivars/SecureBoot-*').returns([@sb_tempfile.path]) | ||
Dir.stubs(:glob).with('/sys/firmware/efi/efivars/SetupMode-*').returns([@sm_tempfile.path]) | ||
end | ||
|
||
after :each do | ||
File.unlink(@sb_tempfile) if File.exist?(@sb_tempfile) | ||
File.unlink(@sm_tempfile) if File.exist?(@sm_tempfile) | ||
end | ||
|
||
context 'with SecureBoot enabled' do | ||
before :each do | ||
File.open(@sb_tempfile, 'wb') do |fh| | ||
fh.write('1234') | ||
fh.write([1].pack('C')) | ||
end | ||
end | ||
|
||
context 'with SetupMode disabled' do | ||
before :each do | ||
File.open(@sm_tempfile, 'w') do |fh| | ||
fh.write('1234') | ||
fh.write([0].pack('C')) | ||
end | ||
end | ||
|
||
it do | ||
expect(Facter.fact('simplib__secure_boot_enabled').value).to match(true) | ||
end | ||
end | ||
|
||
context 'with SetupMode enabled' do | ||
before :each do | ||
File.open(@sm_tempfile, 'w') do |fh| | ||
fh.write('1234') | ||
fh.write([1].pack('C')) | ||
end | ||
end | ||
|
||
it do | ||
expect(Facter.fact('simplib__secure_boot_enabled').value).to match(false) | ||
end | ||
end | ||
end | ||
|
||
context 'with SecureBoot disabled' do | ||
before :each do | ||
File.open(@sb_tempfile, 'w') do |fh| | ||
fh.write('1234') | ||
fh.write([0].pack('C')) | ||
end | ||
end | ||
|
||
context 'with SetupMode disabled' do | ||
before :each do | ||
File.open(@sm_tempfile, 'w') do |fh| | ||
fh.write('1234') | ||
fh.write([0].pack('C')) | ||
end | ||
end | ||
|
||
it do | ||
expect(Facter.fact('simplib__secure_boot_enabled').value).to match(false) | ||
end | ||
end | ||
|
||
context 'with SetupMode enabled' do | ||
before :each do | ||
File.open(@sm_tempfile, 'w') do |fh| | ||
fh.write('1234') | ||
fh.write([1].pack('C')) | ||
end | ||
end | ||
|
||
it do | ||
expect(Facter.fact('simplib__secure_boot_enabled').value).to match(false) | ||
end | ||
end | ||
end | ||
end | ||
end |