Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
358 additions
and
58 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
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
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,75 @@ | ||
require "yast" | ||
require "y2security/lsm/config" | ||
|
||
module Installation | ||
# This class stores the LSM configuration needed during the installation like selecting the LSM | ||
# to be used | ||
class LSMConfig | ||
include Yast::Logger | ||
extend Forwardable | ||
|
||
# Constructor | ||
def initialize | ||
@config = Y2Security::LSM::Config.new | ||
@config.supported.each do |lsm_module| | ||
self.class.send(:define_method, lsm_module.id.to_s.to_sym) do | ||
lsm_module | ||
end | ||
end | ||
end | ||
|
||
# Select the LSM to be used based in the one defined in the control file using apparmor as | ||
# fallback in case that no one is selected | ||
def propose_default | ||
log.info("The settings are #{product_feature_settings.inspect}") | ||
selected = product_feature_settings.fetch(:default, "apparmor") | ||
|
||
@config.select(selected) | ||
end | ||
|
||
def_delegators :@config, :supported, :selected, :select, :selectable | ||
|
||
# Returns whether the LSM is configurable during installation or not based in the control file | ||
# declaration. It returns false in case it is WSL | ||
# | ||
# @return [Boolean] true if LSM is configurable during the installation; false otherwise | ||
def configurable? | ||
return false if Yast::Arch.is_wsl | ||
|
||
product_feature_settings[:configurable] || false | ||
end | ||
|
||
# Returns the needed patterns for the selected LSM or an empty array if no one is selected | ||
# | ||
# @return [Array<Sting>] | ||
def needed_patterns | ||
return [] unless selected | ||
|
||
selected.needed_patterns | ||
end | ||
|
||
# Save the configuration of the selected LSM or false in case of no one selected | ||
# | ||
# @return [Boolean] whether the configuration was save or not | ||
def save | ||
return false unless selected | ||
|
||
selected.save | ||
end | ||
|
||
# Returns the values for the LSM setting from the product features | ||
# | ||
# @return [Hash{Symbol => Object}] e.g., { default: :selinux, selinux: { "selectable" => true }} | ||
# a hash holding the LSM options defined in the control file; | ||
# an empty object if no settings are defined | ||
def product_feature_settings | ||
return @product_feature_settings unless @product_feature_settings.nil? | ||
|
||
settings = Yast::ProductFeatures.GetFeature("globals", "lsm").dup | ||
settings = {} if settings.empty? | ||
settings.transform_keys!(&:to_sym) | ||
|
||
@product_feature_settings = settings | ||
end | ||
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
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,109 @@ | ||
require "yast" | ||
require "cwm/custom_widget" | ||
require "cwm/replace_point" | ||
require "cwm/common_widgets" | ||
require "installation/widgets/selinux_mode" | ||
|
||
Yast.import "HTML" | ||
|
||
module Installation | ||
module Widgets | ||
class LSM < CWM::CustomWidget | ||
attr_accessor :settings | ||
|
||
def initialize(settings) | ||
@settings = settings | ||
self.handle_all_events = true | ||
end | ||
|
||
def init | ||
lsm_selector_widget.init | ||
refresh | ||
end | ||
|
||
def contents | ||
VBox( | ||
lsm_selector_widget, | ||
Left(replace_widget) | ||
) | ||
end | ||
|
||
def replace_widget | ||
@replace_widget ||= CWM::ReplacePoint.new(id: "lsm_widget", widget: empty_lsm_widget) | ||
end | ||
|
||
def empty_lsm_widget | ||
@empty_lsm_widget ||= CWM::Empty.new("lsm_empty") | ||
end | ||
|
||
def lsm_selector_widget | ||
@lsm_selector_widget ||= LSMSelector.new(settings.lsm_config) | ||
end | ||
|
||
def selinux_widget | ||
@selinux_widget ||= SelinuxMode.new(settings.lsm_config.selinux) | ||
end | ||
|
||
def handle(event) | ||
return if event["ID"] != lsm_selector_widget.widget_id | ||
|
||
refresh | ||
nil | ||
end | ||
|
||
private | ||
|
||
def refresh | ||
case lsm_selector_widget.value | ||
when "selinux" then replace_widget.replace(selinux_widget) | ||
else | ||
replace_widget.replace(empty_lsm_widget) | ||
end | ||
end | ||
end | ||
|
||
class LSMSelector < CWM::ComboBox | ||
attr_reader :settings | ||
|
||
def initialize(settings) | ||
textdomain "installation" | ||
|
||
@settings = settings | ||
end | ||
|
||
def init | ||
self.value = settings.selected&.id.to_s | ||
end | ||
|
||
def opt | ||
[:notify, :hstretch] | ||
end | ||
|
||
def label | ||
# TRANSLATORS: SELinux Mode just SELinux is already content of frame. | ||
_("Selected Module") | ||
end | ||
|
||
def items | ||
available_modules.map { |m| [m.id.to_s, m.label] } | ||
end | ||
|
||
def store | ||
settings.select(value) | ||
end | ||
|
||
def help | ||
Yast::HTML.Para( | ||
_("Allows to choose between available Linux Security major modules like:") + | ||
Yast::HTML.List(available_modules.map(&:label)) | ||
) | ||
end | ||
|
||
private | ||
|
||
def available_modules | ||
settings.selectable | ||
end | ||
end | ||
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
Oops, something went wrong.