Skip to content

Commit

Permalink
Removed old code for sysvinit configuration (bsc#1175494). (#79)
Browse files Browse the repository at this point in the history
* Removed old code for sysvinit configuration (bsc#1175494).
  • Loading branch information
schubi2 committed Dec 15, 2020
1 parent 73ff970 commit 4e1946a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 167 deletions.
6 changes: 6 additions & 0 deletions package/yast2-security.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Tue Dec 15 12:33:52 UTC 2020 - schubi <schubi@localhost>

- Removed old code for sysvinit configuration (bsc#1175494).
- 4.3.7

-------------------------------------------------------------------
Mon Dec 14 14:49:26 UTC 2020 - schubi <schubi@intern>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-security.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-security
Version: 4.3.6
Version: 4.3.7
Release: 0
Group: System/YaST
License: GPL-2.0-only
Expand Down
25 changes: 0 additions & 25 deletions src/lib/security/ctrl_alt_del_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ def systemd?
Yast::PackageSystem.Installed("systemd")
end

def inittab?
Yast::FileUtils.Exists("/etc/inittab")
end

def default
Yast::Arch.s390 ? "halt" : "reboot"
end
Expand All @@ -55,7 +51,6 @@ def options

def current
return current_systemd if systemd?
return current_inittab if inittab?

nil
end
Expand All @@ -80,26 +75,6 @@ def current_systemd
end
ret
end

def current_inittab
ca = Yast::SCR.Read(Yast::Path.new(".etc.inittab.ca"))
ret =
case ca
when /\/bin\/true/, /\/bin\/false/
"ignore"
when /reboot/, / -r/
"reboot"
when /halt/, / -h/
"halt"
when nil
log.error("No ca entry")
nil
else
log.error "Unknown ca status: #{ca}"
"ignore"
end
ret
end
end
end
end
55 changes: 14 additions & 41 deletions src/modules/Security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ def init_settings
}

# Remaining settings:
# - CONSOLE_SHUTDOWN (/etc/inittab)
# - PASSWD_ENCRYPTION (/etc/pam?)
# - MANDATORY_SERVICES
# - EXTRA_SERVICES
Expand Down Expand Up @@ -316,11 +315,6 @@ def ReadServiceSettings
nil
end

def inittab_shutdown_configured?
inittab = SCR.Dir(path(".etc.inittab"))
inittab.include?("ca")
end

# Read the information about ctrl+alt+del behavior
# See bug 742783 for description
def ReadConsoleShutdown
Expand Down Expand Up @@ -487,43 +481,22 @@ def Read

# Write the value of ctrl-alt-delete behavior
def write_console_shutdown(ca)
if Package.Installed("systemd")
if ca == "reboot"
SCR.Execute(path(".target.remove"), @ctrl_alt_del_file)
elsif ca == "halt"
SCR.Execute(
path(".target.bash"),
Builtins.sformat(
"ln -s -f /usr/lib/systemd/system/poweroff.target %1",
@ctrl_alt_del_file
)
)
else
SCR.Execute(
path(".target.bash"),
Builtins.sformat("ln -s -f /dev/null %1", @ctrl_alt_del_file)
)
end
return true
end

if ca == "reboot"
SCR.Write(
path(".etc.inittab.ca"),
":ctrlaltdel:/sbin/shutdown -r -t 4 now"
)
SCR.Execute(path(".target.remove"), @ctrl_alt_del_file)
elsif ca == "halt"
SCR.Write(
path(".etc.inittab.ca"),
":ctrlaltdel:/sbin/shutdown -h -t 4 now"
SCR.Execute(
path(".target.bash"),
Builtins.sformat(
"ln -s -f /usr/lib/systemd/system/poweroff.target %1",
@ctrl_alt_del_file
)
)
else
SCR.Write(path(".etc.inittab.ca"), ":ctrlaltdel:/bin/true")
SCR.Execute(
path(".target.bash"),
Builtins.sformat("ln -s -f /dev/null %1", @ctrl_alt_del_file)
)
end
SCR.Write(path(".etc.inittab"), nil)

# re-read the modified inittab (#83480)
SCR.Execute(path(".target.bash"), "/sbin/telinit q")
true
end

Expand Down Expand Up @@ -683,7 +656,7 @@ def Write
# Progress stage 1/4
_("Write security settings"),
# Progress stage 2/4
_("Write inittab settings"),
_("Write shutdown settings"),
# Progress stage 3/4
_("Write PAM settings"),
# Progress stage 4/4
Expand All @@ -693,7 +666,7 @@ def Write
# Progress step 1/5
_("Writing security settings..."),
# Progress step 2/5
_("Writing inittab settings..."),
_("Writing shutdown settings..."),
# Progress step 3/5
_("Writing PAM settings..."),
# Progress step 4/5
Expand All @@ -716,7 +689,7 @@ def Write
write_to_locations
write_shadow_config

# Write inittab settings
# Write shutdown settings
return false if Abort()

Progress.NextStage
Expand Down
100 changes: 0 additions & 100 deletions test/security_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -415,106 +415,6 @@ def enabled?
end
end
end

context "when systemd is not installed but inittab exist" do
before do
allow(PackageSystem).to receive(:Installed).with("systemd") { false }
end

context "on a non s390 architecture" do
before do
allow(Arch).to receive(:s390) { false }
allow(::Security::CtrlAltDelConfig).to receive(:inittab?) { true }
end

context "when no inittab ca entry" do
it "sets settings for shutdown as 'reboot'" do
allow(FileUtils).to receive(:Exists).with("/etc/inittab") { false }

Security.ReadConsoleShutdown
expect(Security.Settings["CONSOLE_SHUTDOWN"]).to eq("reboot")
end
end

context "when inittab ca entry exist" do
before do
allow(FileUtils).to receive(:Exists).with("/etc/inittab") { true }
end

it "sets settings for shutdown as 'ignore' by default" do
allow(SCR).to receive(:Read).with(path(".etc.inittab.ca"))
.and_return("12345:ctrlaltdel:/bin/false")

Security.ReadConsoleShutdown
expect(Security.Settings["CONSOLE_SHUTDOWN"]).to eq("ignore")
end

it "sets settings for shutdown as 'halt' if contains 'halt' or ' -h'" do
allow(SCR).to receive(:Read).with(path(".etc.inittab.ca"))
.and_return("12345:ctrlaltdel:/sbin/shutdown -h now")

Security.ReadConsoleShutdown
expect(Security.Settings["CONSOLE_SHUTDOWN"]).to eq("halt")
end

it "sets settings for shutdown as 'reboot' if contains 'reboot' or -r" do
allow(SCR).to receive(:Read).with(path(".etc.inittab.ca"))
.and_return("12345:ctrlaltdel:/sbin/shutdown -r now")

Security.ReadConsoleShutdown
expect(Security.Settings["CONSOLE_SHUTDOWN"]).to eq("reboot")
end

end
end

context "on a s390 architecture" do
before do
allow(Arch).to receive(:s390) { true }
allow(::Security::CtrlAltDelConfig).to receive(:inittab?) { true }
end

context "when no inittab ca entry" do
it "returns 'halt'" do
allow(FileUtils).to receive(:Exists).with("/etc/inittab") { false }

Security.ReadConsoleShutdown
expect(Security.Settings["CONSOLE_SHUTDOWN"]).to eq("halt")
end
end

context "when inittab ca entry exist" do
before do
allow(FileUtils).to receive(:Exists).with("/etc/inittab") { true }
end

it "sets settings for shutdown as 'ignore' by default" do
allow(SCR).to receive(:Read).with(path(".etc.inittab.ca"))
.and_return("12345:ctrlaltdel:/bin/echo 'Not implemented'")

Security.ReadConsoleShutdown
expect(Security.Settings["CONSOLE_SHUTDOWN"]).to eq("ignore")
end

it "sets settings for shutdown as 'halt' if contains 'halt' or ' -h'" do
allow(SCR).to receive(:Read).with(path(".etc.inittab.ca"))
.and_return("12345:/sbin/shutdown -h now")

Security.ReadConsoleShutdown
expect(Security.Settings["CONSOLE_SHUTDOWN"]).to eq("halt")
end

it "sets settings for shutdown as 'reboot' if contains 'reboot' or -r" do
allow(SCR).to receive(:Read).with(path(".etc.inittab.ca"))
.and_return("12345:ctrlaltdel:/sbin/shutdown -r now")

Security.ReadConsoleShutdown
expect(Security.Settings["CONSOLE_SHUTDOWN"]).to eq("reboot")
end

end
end
end
end

describe "#read_pam_settings" do
Expand Down

0 comments on commit 4e1946a

Please sign in to comment.