inspec 4.10.4 → 4.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -7
- data/inspec.gemspec +2 -1
- data/lib/inspec/resources/command.rb +2 -0
- data/lib/inspec/resources/dh_params.rb +63 -61
- data/lib/inspec/resources/etc_hosts.rb +46 -44
- data/lib/inspec/resources/groups.rb +26 -8
- data/lib/inspec/resources/grub_conf.rb +180 -178
- data/lib/inspec/resources/iis_app_pool.rb +106 -104
- data/lib/inspec/resources/service.rb +12 -3
- data/lib/inspec/resources/ssl.rb +74 -72
- data/lib/inspec/runner.rb +1 -0
- data/lib/inspec/version.rb +1 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72aac2ba7eb1565ecbbd18436e96c770151f5be68b3bcc8897db7a0baee22621
|
4
|
+
data.tar.gz: 2466be933623846f985f9b66e3a572d617f516274ad2dc7b81d048b2ebe2d104
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 269ccd7e103663bec2dd23058dc0481775b840f22a93a3cd81e8f8e0e5c774def3cd6ecaae12604f2c13fe6bcfd33864040acfa9a2ff3bf49e50c1111f5d7be9
|
7
|
+
data.tar.gz: 9f6b41d84be75a69cb1c405302f7c076f6192f16f506d8d4b958bf76e707057961a6ba692dadb528b39997140c1682ee9d2d328efd8d06f2249f104497c79b62
|
data/README.md
CHANGED
@@ -327,13 +327,13 @@ Remote Targets
|
|
327
327
|
|
328
328
|
In addition, runtime support is provided for:
|
329
329
|
|
330
|
-
| Platform | Versions |
|
331
|
-
| -------- | -------- |
|
332
|
-
| Debian | 8, 9 |
|
333
|
-
| RHEL | 6, 7 |
|
334
|
-
| Ubuntu | 12.04+ |
|
335
|
-
| Windows | 7+ |
|
336
|
-
| Windows | 2012+ |
|
330
|
+
| Platform | Versions | Arch |
|
331
|
+
| -------- | -------- | ------ |
|
332
|
+
| Debian | 8, 9 | x86_64 |
|
333
|
+
| RHEL | 6, 7 | x86_64 |
|
334
|
+
| Ubuntu | 12.04+ | x86_64 |
|
335
|
+
| Windows | 7+ | x86_64 |
|
336
|
+
| Windows | 2012+ | x86_64 |
|
337
337
|
|
338
338
|
## Documentation
|
339
339
|
|
data/inspec.gemspec
CHANGED
@@ -23,10 +23,11 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.required_ruby_version = ">= 2.4"
|
25
25
|
|
26
|
-
spec.add_dependency "train", "~>
|
26
|
+
spec.add_dependency "train", "~> 3.0" # Inspec 4 must have train 2+; 3+ if we include train-winrm
|
27
27
|
# Train plugins we ship with InSpec
|
28
28
|
spec.add_dependency "train-habitat", "~> 0.1"
|
29
29
|
spec.add_dependency "train-aws", "~> 0.1"
|
30
|
+
spec.add_dependency "train-winrm", "~> 0.2" # Requires train 3+
|
30
31
|
|
31
32
|
# Implementation dependencies
|
32
33
|
spec.add_dependency "license-acceptance", ">= 0.2.13", "< 2.0"
|
@@ -1,81 +1,83 @@
|
|
1
1
|
require "openssl"
|
2
2
|
require "inspec/utils/file_reader"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
4
|
+
module Inspec::Resources
|
5
|
+
class DhParams < Inspec.resource(1)
|
6
|
+
name "dh_params"
|
7
|
+
supports platform: "unix"
|
8
|
+
desc '
|
9
|
+
Use the `dh_params` InSpec audit resource to test Diffie-Hellman (DH)
|
10
|
+
parameters.
|
11
|
+
'
|
12
|
+
|
13
|
+
example <<~EXAMPLE
|
14
|
+
describe dh_params('/path/to/file.dh_pem') do
|
15
|
+
it { should be_dh_params }
|
16
|
+
it { should be_valid }
|
17
|
+
its('generator') { should eq 2 }
|
18
|
+
its('modulus') { should eq '00:91:a0:15:89:e5:bc:38:93:12:02:fc:...' }
|
19
|
+
its('prime_length') { should eq 2048 }
|
20
|
+
its('pem') { should eq '-----BEGIN DH PARAMETERS...' }
|
21
|
+
its('text') { should eq 'PKCS#3 DH Parameters: (2048 bit)...' }
|
22
|
+
end
|
23
|
+
EXAMPLE
|
24
|
+
|
25
|
+
include FileReader
|
26
|
+
|
27
|
+
def initialize(filename)
|
28
|
+
@dh_params_path = filename
|
29
|
+
@dh_params = OpenSSL::PKey::DH.new read_file_content(@dh_params_path)
|
21
30
|
end
|
22
|
-
EXAMPLE
|
23
31
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@dh_params = OpenSSL::PKey::DH.new read_file_content(@dh_params_path)
|
29
|
-
end
|
30
|
-
|
31
|
-
# it { should be_dh_params }
|
32
|
-
def dh_params?
|
33
|
-
!@dh_params.nil?
|
34
|
-
end
|
32
|
+
# it { should be_dh_params }
|
33
|
+
def dh_params?
|
34
|
+
!@dh_params.nil?
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
# its('generator') { should eq 2 }
|
38
|
+
def generator
|
39
|
+
return if @dh_params.nil?
|
39
40
|
|
40
|
-
|
41
|
-
|
41
|
+
@dh_params.g.to_i
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
# its('modulus') { should eq '00:91:a0:15:89:e5:bc:38:93:12:02:fc:...' }
|
45
|
+
def modulus
|
46
|
+
return if @dh_params.nil?
|
46
47
|
|
47
|
-
|
48
|
-
|
48
|
+
"00:" + @dh_params.p.to_s(16).downcase.scan(/.{2}/).join(":")
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
# its('pem') { should eq '-----BEGIN DH PARAMETERS...' }
|
52
|
+
def pem
|
53
|
+
return if @dh_params.nil?
|
53
54
|
|
54
|
-
|
55
|
-
|
55
|
+
@dh_params.to_pem
|
56
|
+
end
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
# its('prime_length') { should be 2048 }
|
59
|
+
def prime_length
|
60
|
+
return if @dh_params.nil?
|
60
61
|
|
61
|
-
|
62
|
-
|
62
|
+
@dh_params.p.num_bits
|
63
|
+
end
|
63
64
|
|
64
|
-
|
65
|
-
|
66
|
-
|
65
|
+
# its('text') { should eq 'human-readable-text' }
|
66
|
+
def text
|
67
|
+
return if @dh_params.nil?
|
67
68
|
|
68
|
-
|
69
|
-
|
69
|
+
@dh_params.to_text
|
70
|
+
end
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
# it { should be_valid }
|
73
|
+
def valid?
|
74
|
+
return if @dh_params.nil?
|
74
75
|
|
75
|
-
|
76
|
-
|
76
|
+
@dh_params.params_ok?
|
77
|
+
end
|
77
78
|
|
78
|
-
|
79
|
-
|
79
|
+
def to_s
|
80
|
+
"dh_params #{@dh_params_path}"
|
81
|
+
end
|
80
82
|
end
|
81
83
|
end
|
@@ -1,62 +1,64 @@
|
|
1
1
|
require "inspec/utils/parser"
|
2
2
|
require "inspec/utils/file_reader"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
4
|
+
module Inspec::Resources
|
5
|
+
class EtcHosts < Inspec.resource(1)
|
6
|
+
name "etc_hosts"
|
7
|
+
supports platform: "linux"
|
8
|
+
supports platform: "bsd"
|
9
|
+
supports platform: "windows"
|
10
|
+
desc 'Use the etc_hosts InSpec audit resource to find an
|
11
|
+
ip_address and its associated hosts'
|
12
|
+
example <<~EXAMPLE
|
13
|
+
describe etc_hosts.where { ip_address == '127.0.0.1' } do
|
14
|
+
its('ip_address') { should cmp '127.0.0.1' }
|
15
|
+
its('primary_name') { should cmp 'localhost' }
|
16
|
+
its('all_host_names') { should eq [['localhost', 'localhost.localdomain', 'localhost4', 'localhost4.localdomain4']] }
|
17
|
+
end
|
18
|
+
EXAMPLE
|
18
19
|
|
19
|
-
|
20
|
+
attr_reader :params
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
include CommentParser
|
23
|
+
include FileReader
|
23
24
|
|
24
|
-
|
25
|
-
|
25
|
+
DEFAULT_UNIX_PATH = "/etc/hosts".freeze
|
26
|
+
DEFAULT_WINDOWS_PATH = 'C:\windows\system32\drivers\etc\hosts'.freeze
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
def initialize(hosts_path = nil)
|
29
|
+
content = read_file_content(hosts_path || default_hosts_file_path)
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
@params = parse_conf(content.lines)
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
FilterTable.create
|
35
|
+
.register_column(:ip_address, field: "ip_address")
|
36
|
+
.register_column(:primary_name, field: "primary_name")
|
37
|
+
.register_column(:all_host_names, field: "all_host_names")
|
38
|
+
.install_filter_methods_on_resource(self, :params)
|
38
39
|
|
39
|
-
|
40
|
+
private
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
def default_hosts_file_path
|
43
|
+
inspec.os.windows? ? DEFAULT_WINDOWS_PATH : DEFAULT_UNIX_PATH
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
def parse_conf(lines)
|
47
|
+
lines.reject(&:empty?).reject(&comment?).map(&parse_data).map(&format_data)
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
50
|
+
def comment?
|
51
|
+
parse_options = { comment_char: "#", standalone_comments: false }
|
51
52
|
|
52
|
-
|
53
|
-
|
53
|
+
->(data) { parse_comment_line(data, parse_options).first.empty? }
|
54
|
+
end
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
def parse_data
|
57
|
+
->(data) { [data.split[0], data.split[1], data.split[1..-1]] }
|
58
|
+
end
|
58
59
|
|
59
|
-
|
60
|
-
|
60
|
+
def format_data
|
61
|
+
->(data) { %w{ip_address primary_name all_host_names}.zip(data).to_h }
|
62
|
+
end
|
61
63
|
end
|
62
64
|
end
|
@@ -164,22 +164,40 @@ module Inspec::Resources
|
|
164
164
|
# OSX uses opendirectory for groups, so `/etc/group` may not be fully accurate
|
165
165
|
# This uses `dscacheutil` to get the group info instead of `etc_group`
|
166
166
|
class DarwinGroup < GroupInfo
|
167
|
+
def runmap(cmd, &blk)
|
168
|
+
hashmap(inspec.command(cmd).stdout.lines, &blk)
|
169
|
+
end
|
170
|
+
|
171
|
+
def hashmap(enum, &blk)
|
172
|
+
enum.map(&blk).to_h
|
173
|
+
end
|
174
|
+
|
167
175
|
def groups
|
168
|
-
|
176
|
+
group_by_id = runmap("dscl . -list /Groups PrimaryGroupID") { |l| name, id = l.split; [id.to_i, name] }
|
177
|
+
userss = runmap("dscl . -list /Users PrimaryGroupID") { |l| name, id = l.split; [name, id.to_i] }
|
178
|
+
membership = runmap("dscl . -list /Groups GroupMembership") { |l| key, *vs = l.split; [key, vs] }
|
179
|
+
membership.default_proc = ->(h, k) { h[k] = [] }
|
180
|
+
|
181
|
+
users_by_group = hashmap(userss.keys.group_by { |k| userss[k] }) { |k, vs| [group_by_id[k], vs] }
|
182
|
+
users_by_group.each do |name, users|
|
183
|
+
membership[name].concat users
|
184
|
+
end
|
185
|
+
|
186
|
+
group_info = inspec.command("dscacheutil -q group").stdout.split("\n\n").uniq
|
169
187
|
|
170
|
-
groups = []
|
171
188
|
regex = /^([^:]*?)\s*:\s(.*?)\s*$/
|
172
|
-
group_info.
|
173
|
-
|
189
|
+
groups = group_info.map do |data|
|
190
|
+
inspec.parse_config(data, assignment_regex: regex).params
|
174
191
|
end
|
175
192
|
|
176
193
|
# Convert the `dscacheutil` groups to match `inspec.etc_group.entries`
|
177
194
|
groups.each { |g| g["gid"] = g["gid"].to_i }
|
178
195
|
groups.each do |g|
|
179
|
-
|
180
|
-
|
181
|
-
g["
|
182
|
-
g["members"]
|
196
|
+
users = g.delete("users") || ""
|
197
|
+
users = users.split
|
198
|
+
users += Array(users_by_group[g["name"]])
|
199
|
+
g["members"] = users
|
200
|
+
g["members"].sort.join ","
|
183
201
|
end
|
184
202
|
end
|
185
203
|
end
|
@@ -1,228 +1,230 @@
|
|
1
1
|
require "inspec/utils/simpleconfig"
|
2
2
|
require "inspec/utils/file_reader"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
4
|
+
module Inspec::Resources
|
5
|
+
class GrubConfig < Inspec.resource(1)
|
6
|
+
name "grub_conf"
|
7
|
+
supports platform: "unix"
|
8
|
+
desc "Use the grub_conf InSpec audit resource to test the boot config of Linux systems that use Grub."
|
9
|
+
example <<~EXAMPLE
|
10
|
+
describe grub_conf('/etc/grub.conf', 'default') do
|
11
|
+
its('kernel') { should include '/vmlinuz-2.6.32-573.7.1.el6.x86_64' }
|
12
|
+
its('initrd') { should include '/initramfs-2.6.32-573.el6.x86_64.img=1' }
|
13
|
+
its('default') { should_not eq '1' }
|
14
|
+
its('timeout') { should eq '5' }
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
also check specific kernels
|
18
|
+
describe grub_conf('/etc/grub.conf', 'CentOS (2.6.32-573.12.1.el6.x86_64)') do
|
19
|
+
its('kernel') { should include 'audit=1' }
|
20
|
+
end
|
21
|
+
EXAMPLE
|
21
22
|
|
22
|
-
|
23
|
+
include FileReader
|
23
24
|
|
24
|
-
|
25
|
+
class UnknownGrubConfig < StandardError; end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
def initialize(path = nil, kernel = nil)
|
28
|
+
config_for_platform(path)
|
29
|
+
@content = read_file(@conf_path)
|
30
|
+
@kernel = kernel || "default"
|
31
|
+
rescue UnknownGrubConfig
|
32
|
+
skip_resource "The `grub_config` resource is not supported on your OS yet."
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
35
|
+
def config_for_platform(path)
|
36
|
+
os = inspec.os
|
37
|
+
if os.redhat? || os[:name] == "fedora"
|
38
|
+
config_for_redhatish(path)
|
39
|
+
elsif os.debian?
|
40
|
+
@conf_path = path || "/boot/grub/grub.cfg"
|
41
|
+
@defaults_path = "/etc/default/grub"
|
42
|
+
@grubenv_path = "/boot/grub2/grubenv"
|
43
|
+
@version = "grub2"
|
44
|
+
elsif os[:name] == "amazon"
|
45
|
+
@conf_path = path || "/etc/grub.conf"
|
46
|
+
@version = "legacy"
|
47
|
+
else
|
48
|
+
raise UnknownGrubConfig
|
49
|
+
end
|
48
50
|
end
|
49
|
-
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
def config_for_redhatish(path)
|
53
|
+
if inspec.os[:release].to_f < 7
|
54
|
+
@conf_path = path || "/etc/grub.conf"
|
55
|
+
@version = "legacy"
|
56
|
+
else
|
57
|
+
@conf_path = path || "/boot/grub2/grub.cfg"
|
58
|
+
@defaults_path = "/etc/default/grub"
|
59
|
+
@grubenv_path = "/boot/grub2/grubenv"
|
60
|
+
@version = "grub2"
|
61
|
+
end
|
60
62
|
end
|
61
|
-
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
def method_missing(name)
|
65
|
+
read_params[name.to_s]
|
66
|
+
end
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
def to_s
|
69
|
+
"Grub Config"
|
70
|
+
end
|
70
71
|
|
71
|
-
|
72
|
+
private
|
72
73
|
|
73
|
-
|
74
|
-
|
75
|
-
|
74
|
+
######################################################################
|
75
|
+
# Grub2 This is used by all supported versions of Ubuntu and Rhel 7+ #
|
76
|
+
######################################################################
|
76
77
|
|
77
|
-
|
78
|
-
|
78
|
+
def grub2_parse_kernel_lines(content, conf)
|
79
|
+
menu_entries = extract_menu_entries(content)
|
79
80
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
81
|
+
if @kernel == "default"
|
82
|
+
default_menu_entry(menu_entries, conf["GRUB_DEFAULT"])
|
83
|
+
else
|
84
|
+
menu_entries.find { |entry| entry["name"] == @kernel }
|
85
|
+
end
|
84
86
|
end
|
85
|
-
end
|
86
87
|
|
87
|
-
|
88
|
-
|
88
|
+
def extract_menu_entries(content)
|
89
|
+
menu_entries = []
|
89
90
|
|
90
|
-
|
91
|
-
|
92
|
-
|
91
|
+
lines = content.split("\n")
|
92
|
+
lines.each_with_index do |line, index|
|
93
|
+
next unless line =~ /^menuentry\s+.*/
|
93
94
|
|
94
|
-
|
95
|
-
|
95
|
+
entry = {}
|
96
|
+
entry["insmod"] = []
|
96
97
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
98
|
+
# Extract name from menuentry line
|
99
|
+
capture_data = line.match(/(?:^|\s+).*menuentry\s*['|"](.*)['|"]\s*--/)
|
100
|
+
if capture_data.nil? || capture_data.captures[0].nil?
|
101
|
+
raise Inspec::Exceptions::ResourceFailed "Failed to extract menuentry name from #{line}"
|
102
|
+
end
|
102
103
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
104
|
+
entry["name"] = capture_data.captures[0]
|
105
|
+
|
106
|
+
# Begin processing from index forward until a `}` line is met
|
107
|
+
lines.drop(index + 1).each do |mline|
|
108
|
+
break if mline =~ /^\s*}\s*$/
|
109
|
+
|
110
|
+
case mline
|
111
|
+
when /(?:^|\s*)initrd.*/
|
112
|
+
entry["initrd"] = mline.split(" ")[1]
|
113
|
+
when /(?:^|\s*)linux.*/
|
114
|
+
entry["kernel"] = mline.split
|
115
|
+
when /(?:^|\s*)set root=.*/
|
116
|
+
entry["root"] = mline.split("=")[1].tr("'", "")
|
117
|
+
when /(?:^|\s*)insmod.*/
|
118
|
+
entry["insmod"] << mline.split(" ")[1]
|
119
|
+
end
|
118
120
|
end
|
121
|
+
|
122
|
+
menu_entries << entry
|
119
123
|
end
|
120
124
|
|
121
|
-
menu_entries
|
125
|
+
menu_entries
|
122
126
|
end
|
123
127
|
|
124
|
-
menu_entries
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
# If the default entry isn't `saved` then a number is used as an index.
|
129
|
-
# By default this is `0`, which would be the first item in the list.
|
130
|
-
return menu_entries[default.to_i] unless default == "saved"
|
128
|
+
def default_menu_entry(menu_entries, default)
|
129
|
+
# If the default entry isn't `saved` then a number is used as an index.
|
130
|
+
# By default this is `0`, which would be the first item in the list.
|
131
|
+
return menu_entries[default.to_i] unless default == "saved"
|
131
132
|
|
132
|
-
|
133
|
+
grubenv_contents = inspec.file(@grubenv_path).content
|
133
134
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
135
|
+
# The location of the grubenv file is not guaranteed. In the case that
|
136
|
+
# the file does not exist this will return the 0th entry. This will also
|
137
|
+
# return the 0th entry if InSpec lacks permission to read the file. Both
|
138
|
+
# of these reflect the default Grub2 behavior.
|
139
|
+
return menu_entries[0] if grubenv_contents.nil?
|
139
140
|
|
140
|
-
|
141
|
-
|
142
|
-
|
141
|
+
default_name = SimpleConfig.new(grubenv_contents).params["saved_entry"]
|
142
|
+
default_entry = menu_entries.select { |k| k["name"] == default_name }[0]
|
143
|
+
return default_entry unless default_entry.nil?
|
143
144
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
145
|
+
# It is possible for the saved entry to not be valid . For example, grubenv
|
146
|
+
# not being up to date. If so, the 0th entry is the default.
|
147
|
+
menu_entries[0]
|
148
|
+
end
|
148
149
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
150
|
+
###################################################################
|
151
|
+
# Grub1 aka legacy-grub config. Primarily used by Centos/Rhel 6.x #
|
152
|
+
###################################################################
|
153
|
+
|
154
|
+
def parse_kernel_lines(content, conf)
|
155
|
+
# Find all "title" lines and then parse them into arrays
|
156
|
+
menu_entry = 0
|
157
|
+
lines = content.split("\n")
|
158
|
+
kernel_opts = {}
|
159
|
+
lines.each_with_index do |file_line, index|
|
160
|
+
next unless file_line =~ /^title.*/
|
161
|
+
|
162
|
+
current_kernel = file_line.split(" ", 2)[1]
|
163
|
+
lines.drop(index + 1).each do |kernel_line|
|
164
|
+
if kernel_line =~ /^\s.*/
|
165
|
+
option_type = kernel_line.split(" ")[0]
|
166
|
+
line_options = kernel_line.split(" ").drop(1)
|
167
|
+
if (menu_entry == conf["default"].to_i && @kernel == "default") || current_kernel == @kernel
|
168
|
+
if option_type == "kernel"
|
169
|
+
kernel_opts["kernel"] = line_options
|
170
|
+
else
|
171
|
+
kernel_opts[option_type] = line_options[0]
|
172
|
+
end
|
171
173
|
end
|
174
|
+
else
|
175
|
+
menu_entry += 1
|
176
|
+
break
|
172
177
|
end
|
173
|
-
else
|
174
|
-
menu_entry += 1
|
175
|
-
break
|
176
178
|
end
|
177
179
|
end
|
180
|
+
kernel_opts
|
178
181
|
end
|
179
|
-
kernel_opts
|
180
|
-
end
|
181
182
|
|
182
|
-
|
183
|
-
|
184
|
-
|
183
|
+
def read_file(config_file)
|
184
|
+
read_file_content(config_file)
|
185
|
+
end
|
185
186
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
187
|
+
def read_params
|
188
|
+
return @params if defined?(@params)
|
189
|
+
|
190
|
+
content = read_file(@conf_path)
|
191
|
+
|
192
|
+
if @version == "legacy"
|
193
|
+
# parse the file
|
194
|
+
conf = SimpleConfig.new(
|
195
|
+
content,
|
196
|
+
multiple_values: true
|
197
|
+
).params
|
198
|
+
# convert single entry arrays into strings
|
199
|
+
conf.each do |key, value|
|
200
|
+
if value.size == 1
|
201
|
+
conf[key] = conf[key][0].to_s
|
202
|
+
end
|
201
203
|
end
|
204
|
+
kernel_opts = parse_kernel_lines(content, conf)
|
205
|
+
@params = conf.merge(kernel_opts)
|
202
206
|
end
|
203
|
-
kernel_opts = parse_kernel_lines(content, conf)
|
204
|
-
@params = conf.merge(kernel_opts)
|
205
|
-
end
|
206
207
|
|
207
|
-
|
208
|
-
|
209
|
-
|
208
|
+
if @version == "grub2"
|
209
|
+
# read defaults
|
210
|
+
defaults = read_file(@defaults_path)
|
210
211
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
212
|
+
conf = SimpleConfig.new(
|
213
|
+
defaults,
|
214
|
+
multiple_values: true
|
215
|
+
).params
|
215
216
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
217
|
+
# convert single entry arrays into strings
|
218
|
+
conf.each do |key, value|
|
219
|
+
if value.size == 1
|
220
|
+
conf[key] = conf[key][0].to_s
|
221
|
+
end
|
220
222
|
end
|
221
|
-
end
|
222
223
|
|
223
|
-
|
224
|
-
|
224
|
+
kernel_opts = grub2_parse_kernel_lines(content, conf)
|
225
|
+
@params = conf.merge(kernel_opts)
|
226
|
+
end
|
227
|
+
@params
|
225
228
|
end
|
226
|
-
@params
|
227
229
|
end
|
228
230
|
end
|