Class: Yast::SecurityClass
- Inherits:
-
Module
- Object
- Module
- Yast::SecurityClass
- Includes:
- Logger
- Defined in:
- ../../src/modules/Security.rb
Instance Method Summary (collapse)
-
- (Object) Abort
Abort function.
-
- (Hash) Export
Dump the security settings to a single map (For use by autoinstallation.).
-
- (Object) ExtraServices(enabled_services = nil)
List of enabled services that are neither mandatory nor optional.
-
- (Boolean) GetModified
Function which returns if the settings were modified.
-
- (Boolean) Import(settings)
Get all security settings from the first parameter (For use by autoinstallation.).
- - (Object) main
-
- (Object) MissingMandatoryServices(enabled_services = nil)
List of missing mandatory services.
-
- (Object) Modified
Data was modified?.
-
- (Object) Overview
Create an overview table with all configured cards.
-
- (Object) PollAbort
Check for pending Abort press.
-
- (Object) Read
Read all security settings.
-
- (Object) ReadConsoleShutdown
Read the information about ctrl+alt+del behavior See bug 742783 for description.
- - (Object) ReadServiceSettings
- - (Object) SetModified
-
- (Object) Summary
Create a textual summary and a list of unconfigured cards.
-
- (Object) Write
Write all security settings.
-
- (Object) WriteConsoleShutdown(ca)
Write the value of ctrl-alt-delete behavior.
Instance Method Details
- (Object) Abort
Abort function
328 329 330 331 |
# File '../../src/modules/Security.rb', line 328 def Abort return Builtins.eval(@AbortFunction) == true if @AbortFunction != nil false end |
- (Hash) Export
Dump the security settings to a single map (For use by autoinstallation.)
848 849 850 |
# File '../../src/modules/Security.rb', line 848 def Export Builtins.eval(@Settings) end |
- (Object) ExtraServices(enabled_services = nil)
List of enabled services that are neither mandatory nor optional
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File '../../src/modules/Security.rb', line 302 def ExtraServices(enabled_services = nil) log.info("Searching for extra services") enabled_services ||= SystemdService.all.select(&:enabled?).map(&:name) return nil if enabled_services == nil mandatory = @mandatory_services.flatten ret = enabled_services.select do |service| # the extra service is not mandatory and it's not optional extra = !mandatory.include?(service) && !@optional_services.include?(service) log.info("Found extra service: #{service}") if extra extra end log.info("All extra services: #{ret}") deep_copy(ret) end |
- (Boolean) GetModified
Function which returns if the settings were modified
336 337 338 |
# File '../../src/modules/Security.rb', line 336 def GetModified @modified end |
- (Boolean) Import(settings)
Get all security settings from the first parameter (For use by autoinstallation.)
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 |
# File '../../src/modules/Security.rb', line 802 def Import(settings) settings = deep_copy(settings) return true if settings == {} @modified = true tmpSettings = {} Builtins.foreach(@Settings) do |k, v| if !Builtins.haskey(settings, k) if Builtins.haskey(@sysctl, k) && Builtins.haskey(settings, Ops.get(@sysctl2sysconfig, k, "")) val = Ops.get_string( settings, Ops.get(@sysctl2sysconfig, k, ""), "" ) if val == "yes" Ops.set(tmpSettings, k, "1") elsif val == "no" Ops.set(tmpSettings, k, "0") else Ops.set(tmpSettings, k, val) end elsif Builtins.haskey(settings, Ops.get(@obsolete_login_defs, k, "")) Ops.set( tmpSettings, k, Ops.get_string(settings, Ops.get(@obsolete_login_defs, k, ""), "") ) else Ops.set(tmpSettings, k, v) end else Ops.set(tmpSettings, k, Ops.get_string(settings, k, "")) end end @Settings = Convert.convert( Builtins.eval(tmpSettings), :from => "map", :to => "map <string, string>" ) true end |
- (Object) main
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File '../../src/modules/Security.rb', line 35 def main Yast.import "UI" textdomain "security" Yast.import "FileUtils" Yast.import "Package" Yast.import "Pam" Yast.import "Progress" Yast.import "SystemdService" Yast.include self, "security/levels.rb" # services to check - these must be running # meaning [ [ || ] && && ] @mandatory_services = [ ["ntp"], ["syslog"], ["auditd"], ["random"], ["kbd"], ["cron"], ["postfix", "sendmail"] ] # sevices to check - these can be ignored (if they are running it's OK) @optional_services = [ "acpid", "boot.clock", "dbus", "ealysyslog", "fbset", "framebufferset", "isdn", "microcode.ctl", "random", "consolekit", "haldaemon", "network", "syslog", "auditd", "splash_early", "alsasound", "irq_balancer", "kbd", "powersaved", "splash", "sshd", "earlyxdm", "hotkey-setup", "atd", "nscd", "smpppd", "xend", "autofs", "libvirtd", "sendmail", "postfix", "xendomains", "cron", "ddclient", "smartd", "stopblktrace", "ntp", "SuSEfirewall", "earlysyslog" ] # All other services should be turned off # systemd target, defining ctrl-alt-del behavior @ctrl_alt_del_file = "/etc/systemd/system/ctrl-alt-del.target" # encryption methods supported by pam_unix (bnc#802006) @encryption_methods = ["des", "md5", "sha256", "sha512"] # All security settings @Settings = { "CONSOLE_SHUTDOWN" => "reboot", "CRACKLIB_DICT_PATH" => "/usr/lib/cracklib_dict", "DISPLAYMANAGER_REMOTE_ACCESS" => "no", "kernel.sysrq" => "0", "net.ipv4.tcp_syncookies" => "1", "net.ipv4.ip_forward" => "0", "net.ipv6.conf.all.forwarding" => "0", "FAIL_DELAY" => "3", "GID_MAX" => "60000", "GID_MIN" => "1000", "DISPLAYMANAGER_SHUTDOWN" => "all", "HIBERNATE_SYSTEM" => "active_console", "PASSWD_ENCRYPTION" => "sha512", "PASSWD_USE_CRACKLIB" => "yes", "PASS_MAX_DAYS" => "99999", "PASS_MIN_DAYS" => "0", "PASS_MIN_LEN" => "5", "PASS_WARN_AGE" => "7", "PERMISSION_SECURITY" => "secure", "DISABLE_RESTART_ON_UPDATE" => "no", "DISABLE_STOP_ON_REMOVAL" => "no", "RUN_UPDATEDB_AS" => "nobody", "UID_MAX" => "60000", "UID_MIN" => "500", "SYS_UID_MAX" => "499", "SYS_UID_MIN" => "100", "SYS_GID_MAX" => "499", "SYS_GID_MIN" => "100", "USERADD_CMD" => "/usr/sbin/useradd.local", "USERDEL_PRECMD" => "/usr/sbin/userdel-pre.local", "USERDEL_POSTCMD" => "/usr/sbin/userdel-post.local", "PASSWD_REMEMBER_HISTORY" => "0", "SYSTOHC" => "yes", "SYSLOG_ON_NO_ERROR" => "yes", "DISPLAYMANAGER_ROOT_LOGIN_REMOTE" => "no", "DISPLAYMANAGER_XSERVER_TCP_PORT_6000_OPEN" => "no", "SMTPD_LISTEN_REMOTE" => "no", "RUNLEVEL3_MANDATORY_SERVICES" => "yes", "RUNLEVEL5_MANDATORY_SERVICES" => "yes", "RUNLEVEL3_EXTRA_SERVICES" => "no", "RUNLEVEL5_EXTRA_SERVICES" => "no" } # the original settings @Settings_bak = deep_copy(@Settings) # keys that should not be tested against predefined levels: # - RUNLEVEL*_SERVICES have different syntax, are not saved in current form @do_not_test = [ "RUNLEVEL3_MANDATORY_SERVICES", "RUNLEVEL5_MANDATORY_SERVICES", "RUNLEVEL3_EXTRA_SERVICES", "RUNLEVEL5_EXTRA_SERVICES" ] # Security settings locations @Locations = { ".etc.login_defs" => [ "FAIL_DELAY", "GID_MAX", "GID_MIN", "PASS_MAX_DAYS", "PASS_MIN_DAYS", "PASS_WARN_AGE", "UID_MAX", "UID_MIN", "SYS_UID_MAX", "SYS_UID_MIN", "SYS_GID_MAX", "SYS_GID_MIN", "USERADD_CMD", "USERDEL_PRECMD", "USERDEL_POSTCMD" ], ".sysconfig.displaymanager" => [ "DISPLAYMANAGER_REMOTE_ACCESS", "DISPLAYMANAGER_ROOT_LOGIN_REMOTE", "DISPLAYMANAGER_XSERVER_TCP_PORT_6000_OPEN", "DISPLAYMANAGER_SHUTDOWN" ], ".sysconfig.security" => ["PERMISSION_SECURITY"], ".sysconfig.services" => [ "DISABLE_RESTART_ON_UPDATE", "DISABLE_STOP_ON_REMOVAL" ], ".sysconfig.locate" => ["RUN_UPDATEDB_AS"], ".sysconfig.clock" => ["SYSTOHC"], ".sysconfig.cron" => ["SYSLOG_ON_NO_ERROR"], ".sysconfig.mail" => ["SMTPD_LISTEN_REMOTE"] } # Default values for /etc/sysctl.conf keys @sysctl = { "kernel.sysrq" => "0", "net.ipv4.tcp_syncookies" => "1", "net.ipv4.ip_forward" => "0", "net.ipv6.conf.all.forwarding" => "0" } # Mapping of /etc/sysctl.conf keys to old (obsoleted) sysconfig ones # (used during autoYaST import @sysctl2sysconfig = { "kernel.sysrq" => "ENABLE_SYSRQ", "net.ipv4.tcp_syncookies" => "IP_TCP_SYNCOOKIES", "net.ipv4.ip_forward" => "IP_FORWARD", "net.ipv6.conf.all.forwarding" => "IPV6_FORWARD" } # Mapping of /etc/login.defs keys to old (obsoleted) ones # (used during autoYaST import) @obsolete_login_defs = { "SYS_UID_MAX" => "SYSTEM_UID_MAX", "SYS_UID_MIN" => "SYSTEM_UID_MIN", "SYS_GID_MAX" => "SYSTEM_GID_MAX", "SYS_GID_MIN" => "SYSTEM_GID_MIN" } # mapping of internal YaST values to values needed for # org.freedesktop.upower.hibernate privilege @ycp2polkit = { "active_console" => "auth_admin:auth_admin:yes", "auth_admin" => "auth_admin:auth_admin:auth_admin", "anyone" => "yes:yes:yes" } # Remaining settings: # - CONSOLE_SHUTDOWN (/etc/inittab) # - PASSWD_ENCRYPTION (/etc/pam?) # - RUNLEVEL3_MANDATORY_SERVICES # - RUNLEVEL5_MANDATORY_SERVICES # - RUNLEVEL3_EXTRA_SERVICES # - RUNLEVEL5_EXTRA_SERVICES # Number of sigificant characters in the password @PasswordMaxLengths = { "des" => 8, "md5" => 127, "sha256" => 127, "sha512" => 127 } # Abort function # return boolean return true if abort @AbortFunction = nil # Data was modified? @modified = false @proposal_valid = false @write_only = false @activation_mapping = { "SYSLOG_ON_NO_ERROR" => "/etc/init.d/boot.clock start", "DHCPD_RUN_CHROOTED" => "/etc/init.d/dhcpd restart", "DHCPD_RUN_AS" => "/etc/init.d/dhcpd restart", # restart sendmail or postfix - whatever is installed "SMTPD_LISTEN_REMOTE" => "(test -e /etc/init.d/sendmail && VERBOSE=false /usr/lib/sendmail.d/update && /etc/init.d/sendmail restart) || (test -e /etc/init.d/postfix && /usr/sbin/SuSEconfig.postfix && /etc/init.d/postfix restart)", "net.ipv4.tcp_syncookies" => "/etc/init.d/boot.ipconfig start", "net.ipv4.ip_forward" => "/etc/init.d/boot.ipconfig start", "net.ipv6.conf.all.forwarding" => "/etc/init.d/boot.ipconfig start" } end |
- (Object) MissingMandatoryServices(enabled_services = nil)
List of missing mandatory services
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File '../../src/modules/Security.rb', line 280 def MissingMandatoryServices(enabled_services = nil) log.info("Checking mandatory services") enabled_services ||= SystemdService.all.select(&:enabled?).map(&:name) log.info("enabled_services: #{enabled_services}") return nil if enabled_services.nil? ret = @mandatory_services.select do |services| enabled = services.any? { |service| enabled_services.include?(service) } log.info("Mandatory services #{services} are enabled: #{enabled}") !enabled end log.info("Missing mandatory services: #{ret}") deep_copy(ret) end |
- (Object) Modified
Data was modified?
352 353 354 355 |
# File '../../src/modules/Security.rb', line 352 def Modified Builtins.y2debug("modified=%1", @modified) @modified end |
- (Object) Overview
Create an overview table with all configured cards
883 884 885 |
# File '../../src/modules/Security.rb', line 883 def Overview [] end |
- (Object) PollAbort
Check for pending Abort press
322 323 324 |
# File '../../src/modules/Security.rb', line 322 def PollAbort UI.PollInput == :abort end |
- (Object) Read
Read all security settings
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
# File '../../src/modules/Security.rb', line 415 def Read @Settings = {} @modified = false # Read security settings Builtins.mapmap(@Locations) do |file, vars| Builtins.maplist(vars) do |var| val = "" filename = nil if Builtins.issubstring(file, "sysconfig") filename = Ops.add( "/etc", Builtins.mergestring(Builtins.splitstring(file, "."), "/") ) Builtins.y2debug("filename=%1", filename) end if filename == nil || Ops.greater_than(SCR.Read(path(".target.size"), filename), 0) val = Convert.to_string( SCR.Read(Builtins.topath(Ops.add(Ops.add(file, "."), var))) ) Builtins.y2debug( "Reading: %1 (%2)", Builtins.topath(Ops.add(Ops.add(file, "."), var)), val ) end Ops.set(@Settings, var, val) if val != nil end { 0 => 0 } end Builtins.y2debug("Settings=%1", @Settings) Ops.set(@Settings, "CONSOLE_SHUTDOWN", ReadConsoleShutdown()) Builtins.y2debug("Settings=%1", @Settings) # Read runlevel setting ReadServiceSettings() # Read pam settings method = Convert.to_string( SCR.Read(path(".etc.login_defs.ENCRYPT_METHOD")) ) if method == nil || !Builtins.contains(@encryption_methods, Builtins.tolower(method)) method = "des" end Ops.set(@Settings, "PASSWD_ENCRYPTION", Builtins.tolower(method)) # cracklib and pwhistory settings Ops.set(@Settings, "PASS_MIN_LEN", "5") Ops.set(@Settings, "PASSWD_USE_CRACKLIB", "no") Ops.set(@Settings, "PASSWD_REMEMBER_HISTORY", "0") pam_cracklib = Pam.Query("cracklib") if Ops.greater_than(Builtins.size(pam_cracklib), 0) Ops.set(@Settings, "PASSWD_USE_CRACKLIB", "yes") end # save the default value Ops.set(@Settings, "CRACKLIB_DICT_PATH", "/usr/lib/cracklib_dict") Builtins.foreach(Ops.get_list(pam_cracklib, "password", [])) do |val| lval = Builtins.splitstring(val, "=") if Builtins.issubstring(val, "dictpath=") Ops.set( @Settings, "CRACKLIB_DICT_PATH", Ops.get_string(lval, 1, "/usr/lib/cracklib_dict") ) end if Builtins.issubstring(val, "minlen=") && Ops.get_string(lval, 1, "") != "" Ops.set(@Settings, "PASS_MIN_LEN", Ops.get_string(lval, 1, "5")) end end pam_history = Pam.Query("pwhistory") Builtins.foreach(Ops.get_list(pam_history, "password", [])) do |val| lval = Builtins.splitstring(val, "=") if Builtins.issubstring(val, "remember=") && Ops.get_string(lval, 1, "") != "" Ops.set( @Settings, "PASSWD_REMEMBER_HISTORY", Ops.get_string(lval, 1, "0") ) end end Builtins.y2debug("Settings=%1", @Settings) # Local permissions hack perm = Ops.get(@Settings, "PERMISSION_SECURITY", "") if Builtins.issubstring(perm, "easy") perm = "easy" elsif Builtins.issubstring(perm, "paranoid") perm = "paranoid" elsif Builtins.issubstring(perm, "secure") perm = "secure" else perm = "secure" end Ops.set(@Settings, "PERMISSION_SECURITY", perm) Builtins.y2debug("Settings=%1", @Settings) # read local polkit settings action = "org.freedesktop.upower.hibernate" hibernate = Convert.to_string( SCR.Read(Builtins.add(path(".etc.polkit-default-privs_local"), action)) ) if hibernate != nil Ops.set(@Settings, "HIBERNATE_SYSTEM", "active_console") if hibernate == "auth_admin:auth_admin:auth_admin" Ops.set(@Settings, "HIBERNATE_SYSTEM", "auth_admin") end if hibernate == "yes:yes:yes" Ops.set(@Settings, "HIBERNATE_SYSTEM", "anyone") end end Builtins.y2debug( "HIBERNATE_SYSTEM: %1", Ops.get(@Settings, "HIBERNATE_SYSTEM", "") ) # read sysctl.conf Builtins.foreach(@sysctl) do |key, default_value| val = Convert.to_string( SCR.Read(Builtins.add(path(".etc.sysctl_conf"), key)) ) val = default_value if val == nil || val == "" Ops.set(@Settings, key, val) end Builtins.y2debug("Settings=%1", @Settings) # remeber the read values @Settings_bak = deep_copy(@Settings) true end |
- (Object) ReadConsoleShutdown
Read the information about ctrl+alt+del behavior See bug 742783 for description
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File '../../src/modules/Security.rb', line 371 def ReadConsoleShutdown ret = "ignore" if Package.Installed("systemd") if !FileUtils.Exists(@ctrl_alt_del_file) ret = "reboot" else link = Convert.to_string( SCR.Read(path(".target.symlink"), @ctrl_alt_del_file) ) if link == "/lib/systemd/system/poweroff.target" ret = "halt" elsif link == "/lib/systemd/system/reboot.target" || link == "/lib/systemd/system/ctrl-alt-del.target" ret = "reboot" end end return ret end inittab = SCR.Dir(path(".etc.inittab")) if Builtins.contains(inittab, "ca") ca = Convert.to_string(SCR.Read(path(".etc.inittab.ca"))) if Builtins.issubstring(ca, "/bin/true") || Builtins.issubstring(ca, "/bin/false") Ops.set(@Settings, "CONSOLE_SHUTDOWN", "ignore") elsif Builtins.issubstring(ca, "reboot") || Builtins.issubstring(ca, " -r") Ops.set(@Settings, "CONSOLE_SHUTDOWN", "reboot") elsif Builtins.issubstring(ca, "halt") || Builtins.issubstring(ca, " -h") Ops.set(@Settings, "CONSOLE_SHUTDOWN", "halt") else Builtins.y2error("Unknown ca status: %1", ca) Ops.set(@Settings, "CONSOLE_SHUTDOWN", "ignore") end else Ops.set(@Settings, "CONSOLE_SHUTDOWN", "ignore") end nil end |
- (Object) ReadServiceSettings
357 358 359 360 361 362 363 364 365 366 367 |
# File '../../src/modules/Security.rb', line 357 def ReadServiceSettings services = SystemdService.all.select(&:enabled?).map(&:name) setting = MissingMandatoryServices(services) == [] ? "secure" : "insecure" # Runlevels are not longer used, but @Settings is populated this way for # compatibility with the current interface @Settings["RUNLEVEL3_MANDATORY_SERVICES"] = @Settings["RUNLEVEL5_MANDATORY_SERVICES"] = setting setting = ExtraServices(services) == [] ? "secure" : "insecure" @Settings["RUNLEVEL3_EXTRA_SERVICES"] = @Settings["RUNLEVEL5_EXTRA_SERVICES"] = setting nil end |
- (Object) SetModified
343 344 345 346 347 |
# File '../../src/modules/Security.rb', line 343 def SetModified @modified = true nil end |
- (Object) Summary
Create a textual summary and a list of unconfigured cards
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 |
# File '../../src/modules/Security.rb', line 854 def Summary settings = deep_copy(@Settings) Builtins.foreach(@do_not_test) do |key| settings = Builtins.remove(settings, key) end # Determine current settings current = :custom Builtins.maplist(@Levels) do |key, level| Builtins.y2debug("%1=%2", key, level) current = key if level == settings end Builtins.y2debug("%1=%2", current, @Settings) # Summary text summary = _("Current Security Level: Custom settings") if current != :custom # Summary text summary = Builtins.sformat( _("Current Security Level: %1"), Ops.get(@LevelsNames, Convert.to_string(current), "") ) end [summary, []] end |
- (Object) Write
Write all security settings
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 |
# File '../../src/modules/Security.rb', line 603 def Write return true if !@modified Builtins.y2milestone("Writing configuration") # Security read dialog caption caption = _("Saving Security Configuration") steps = 4 Progress.New( caption, " ", steps, [ # Progress stage 1/4 _("Write security settings"), # Progress stage 2/4 _("Write inittab settings"), # Progress stage 3/4 _("Write PAM settings"), # Progress stage 4/4 _("Update system settings") ], [ # Progress step 1/5 _("Writing security settings..."), # Progress step 2/5 _("Writing inittab settings..."), # Progress step 3/5 _("Writing PAM settings..."), # Progress step 4/5 _("Updating system settings..."), # Progress step 5/5 _("Finished") ], "" ) # Write security settings return false if Abort() Progress.NextStage Builtins.y2debug("Settings=%1", @Settings) Ops.set( @Settings, "PERMISSION_SECURITY", Ops.add(Ops.get(@Settings, "PERMISSION_SECURITY", ""), " local") ) commitlist = [] Builtins.mapmap(@Locations) do |file, vars| Builtins.maplist(vars) do |var| val = Ops.get(@Settings, var) if val != nil && val != SCR.Read(Builtins.topath(Ops.add(Ops.add(file, "."), var))) SCR.Write(Builtins.topath(Ops.add(Ops.add(file, "."), var)), val) commitlist = Convert.convert( Builtins.union(commitlist, [file]), :from => "list", :to => "list <string>" ) end end { 0 => 0 } end Builtins.maplist(commitlist) do |file| SCR.Write(Builtins.topath(file), nil) end # Write inittab settings return false if Abort() Progress.NextStage WriteConsoleShutdown(Ops.get(@Settings, "CONSOLE_SHUTDOWN", "ignore")) # Write pam settings return false if Abort() Progress.NextStage # pam stuff encr = Ops.get(@Settings, "PASSWD_ENCRYPTION", "sha512") if encr != Ops.get(@Settings_bak, "PASSWD_ENCRYPTION", "") SCR.Write(path(".etc.login_defs.ENCRYPT_METHOD"), encr) end # use cracklib? if Ops.get(@Settings, "PASSWD_USE_CRACKLIB", "no") == "yes" Pam.Add("cracklib") pth = Ops.get(@Settings, "CRACKLIB_DICT_PATH", "/usr/lib/cracklib_dict") if pth != "/usr/lib/cracklib_dict" Pam.Add(Ops.add("--cracklib-dictpath=", pth)) end else Pam.Remove("cracklib") end # save min pass length if Ops.get(@Settings, "PASS_MIN_LEN", "5") != "5" && Ops.get(@Settings, "PASSWD_USE_CRACKLIB", "no") == "yes" Pam.Add("cracklib") # minlen is part of cracklib Pam.Add( Builtins.sformat( "cracklib-minlen=%1", Ops.get(@Settings, "PASS_MIN_LEN", "5") ) ) else Pam.Remove("cracklib-minlen") end # save "remember" value (number of old user passwords to not allow) if Ops.get(@Settings, "PASSWD_REMEMBER_HISTORY", "0") != "0" Pam.Add("pwhistory") Pam.Add( Builtins.sformat( "pwhistory-remember=%1", Ops.get(@Settings, "PASSWD_REMEMBER_HISTORY", "0") ) ) else Pam.Remove("pwhistory-remember") end # write local polkit settings if Ops.get(@Settings, "HIBERNATE_SYSTEM", "") != Ops.get(@Settings_bak, "HIBERNATE_SYSTEM", "") # allow writing any value (different from predefined ones) ycp_value = Ops.get(@Settings, "HIBERNATE_SYSTEM", "active_console") hibernate = Ops.get(@ycp2polkit, ycp_value, ycp_value) action = "org.freedesktop.upower.hibernate" SCR.Write( Builtins.add(path(".etc.polkit-default-privs_local"), action), hibernate ) end # write sysctl.conf Builtins.foreach(@sysctl) do |key, default_value| val = Ops.get(@Settings, key, default_value) if Builtins.tointeger(val) == nil Builtins.y2error( "value %1 for %2 is not integer, not writing", val, key ) elsif val != SCR.Read(Builtins.add(path(".etc.sysctl_conf"), key)) SCR.Write(Builtins.add(path(".etc.sysctl_conf"), key), val) end end # enable sysrq? sysrq = Builtins.tointeger(Ops.get(@Settings, "kernel.sysrq", "0")) if sysrq != nil SCR.Execute( path(".target.bash"), Builtins.sformat("echo %1 > /proc/sys/kernel/sysrq", sysrq) ) end # Finish him return false if Abort() Progress.NextStage # apply all current permissions as they are now (what SuSEconfig --module permissions would have done) SCR.Execute(path(".target.bash"), "/usr/bin/chkstat --system") # ensure polkit privileges are applied (bnc #541393) if FileUtils.Exists("/sbin/set_polkit_default_privs") SCR.Execute(path(".target.bash"), "/sbin/set_polkit_default_privs") end return false if Abort() Progress.NextStage # activate the changes Builtins.foreach(@activation_mapping) do |setting, action| if Ops.get(@Settings, setting, "") != Ops.get(@Settings_bak, setting, "") Builtins.y2milestone( "Option %1 has been modified, activating the change: %2", setting, action ) res = Convert.to_integer(SCR.Execute(path(".target.bash"), action)) Builtins.y2error("Activation failed") if res != 0 end end return false if Abort() @modified = false true end |
- (Object) WriteConsoleShutdown(ca)
Write the value of ctrl-alt-delete behavior
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 |
# File '../../src/modules/Security.rb', line 559 def WriteConsoleShutdown(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 /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" ) elsif ca == "halt" SCR.Write( path(".etc.inittab.ca"), ":ctrlaltdel:/sbin/shutdown -h -t 4 now" ) else SCR.Write(path(".etc.inittab.ca"), ":ctrlaltdel:/bin/true") end SCR.Write(path(".etc.inittab"), nil) # re-read the modified inittab (#83480) SCR.Execute(path(".target.bash"), "/sbin/telinit q") true end |