Class: Yast::SecurityClass

Inherits:
Module
  • Object
show all
Includes:
Logger
Defined in:
../../src/modules/Security.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) Abort

Abort function

Returns:

  • blah blah lahjk



255
256
257
258
# File '../../src/modules/Security.rb', line 255

def Abort
  return Builtins.eval(@AbortFunction) == true if @AbortFunction != nil
  false
end

- (Object) activate_changes

Executes the corresponding activation command for the settings that have an entry in @activation_mapping and have changed



632
633
634
635
636
637
638
639
640
641
642
643
# File '../../src/modules/Security.rb', line 632

def activate_changes
  # NOTE: the call to #sort is only needed to satisfy the old testsuite
  @activation_mapping.sort.each do |setting, action|
    next if @Settings[setting] == @Settings_bak[setting]
    log.info(
      "Option #{setting} has been modified, "\
      "activating the change: #{action}"
    )
    res = SCR.Execute(path(".target.bash"), action)
    log.error "Activation failed" if res != 0
  end
end

- (Object) apply_new_settings

Ensures that file permissions and PolicyKit privileges are applied



619
620
621
622
623
624
625
626
627
628
# File '../../src/modules/Security.rb', line 619

def apply_new_settings
  # 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
end

- (Hash) Export

Dump the security settings to a single map (For use by autoinstallation.)

Returns:

  • (Hash)

    Dumped settings (later acceptable by Import ())



768
769
770
# File '../../src/modules/Security.rb', line 768

def Export
  Builtins.eval(@Settings)
end

- (Object) ExtraServices

List of enabled services that are neither mandatory nor optional



243
244
245
# File '../../src/modules/Security.rb', line 243

def ExtraServices
  @extra_services
end

- (Boolean) GetModified

Function which returns if the settings were modified

Returns:

  • (Boolean)

    settings were modified



262
263
264
# File '../../src/modules/Security.rb', line 262

def GetModified
  @modified
end

- (Boolean) Import(settings)

Get all security settings from the first parameter (For use by autoinstallation.)

Parameters:

  • settings (Hash)

    The YCP structure to be imported.

Returns:

  • (Boolean)

    True on success



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
# File '../../src/modules/Security.rb', line 722

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



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
# File '../../src/modules/Security.rb', line 36

def main
  Yast.import "UI"
  textdomain "security"

  Yast.import "FileUtils"
  Yast.import "Package"
  Yast.import "Pam"
  Yast.import "Progress"
  Yast.import "Service"
  Yast.import "SystemdService"
  Yast.import "Directory"

  Yast.include self, "security/levels.rb"


  # Services to check
  srv_file = Directory.find_data_file("security/services.yml")
  if srv_file
    srv_lists = YAML.load_file(srv_file) rescue {}
  else
    srv_lists = {}
  end
  # These must be running
  @mandatory_services = srv_lists["mandatory_services"] || []
  # It must be an array of arrays (meaning [ [ || ] && && ])
  @mandatory_services.map! {|s| s.is_a?(::String) ? [s] : s }
  # These can be ignored (if they are running it's OK)
  @optional_services = srv_lists["optional_services"] || []
  # 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",
    "MANDATORY_SERVICES"                        => "yes",
    "EXTRA_SERVICES"                            => "no"
  }

  # List of missing mandatory services
  @missing_mandatory_services = []
  # List of enabled services not included in mandatory or optional lists
  @extra_services = []

  # the original settings
  @Settings_bak = deep_copy(@Settings)

  # keys that should not be tested against predefined levels:
  # - *_SERVICES have different syntax, are not saved in current form
  @do_not_test = [
    "MANDATORY_SERVICES",
    "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?)
  # - MANDATORY_SERVICES
  # - 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

List of missing mandatory services



238
239
240
# File '../../src/modules/Security.rb', line 238

def MissingMandatoryServices
  @missing_mandatory_services
end

- (Object) Modified

Data was modified?

Returns:

  • true if modified



276
277
278
279
# File '../../src/modules/Security.rb', line 276

def Modified
  Builtins.y2debug("modified=%1", @modified)
  @modified
end

- (Object) Overview

Create an overview table with all configured cards

Returns:

  • table items



803
804
805
# File '../../src/modules/Security.rb', line 803

def Overview
  []
end

- (Object) PollAbort

Check for pending Abort press

Returns:

  • true if pending abort



249
250
251
# File '../../src/modules/Security.rb', line 249

def PollAbort
  UI.PollInput == :abort
end

- (Object) Read

Read all security settings

Returns:

  • true on success



368
369
370
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
412
413
414
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
# File '../../src/modules/Security.rb', line 368

def Read
  @Settings = {}
  @modified = false

  # Read security settings
  read_from_locations
  Builtins.y2milestone("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_kernel_settings
  Builtins.y2debug("Settings=%1", @Settings)

  # remember the read values
  @Settings_bak = deep_copy(@Settings)
  true
end

- (Object) read_from_locations

Read the settings from the files included in @Locations



337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File '../../src/modules/Security.rb', line 337

def read_from_locations
  # NOTE: the call to #sort is only needed to satisfy the old testsuite
  @Locations.sort.each do |file, vars|
    vars.each do |var|
      val = ""
      filename = nil
      if file.include?("sysconfig")
        filename = "/etc" + file.tr(".", "/")
        log.info "filename=#{filename}"
      end
      if filename.nil? || SCR.Read(path(".target.size"), filename) > 0
        val = SCR.Read(path("#{file}.#{var}"))
        log.debug "Reading: #{file}.#{var} (#{val})"
      end
      @Settings[var] = val unless val.nil?
    end
  end
end

- (Object) read_kernel_settings

Read the settings from sysctl.conf



357
358
359
360
361
362
363
364
# File '../../src/modules/Security.rb', line 357

def read_kernel_settings
  # NOTE: the call to #sort is only needed to satisfy the old testsuite
  @sysctl.sort.each do |key, default_value|
    val = SCR.Read(path(".etc.sysctl_conf") + key)
    val = default_value if val.nil? || val == ""
    @Settings[key] = val
  end
end

- (Object) ReadConsoleShutdown

Read the information about ctrl+alt+del behavior See bug 742783 for description



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File '../../src/modules/Security.rb', line 294

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 == "/usr/lib/systemd/system/poweroff.target"
        ret = "halt"
      elsif link == "/usr/lib/systemd/system/reboot.target" ||
          link == "/usr/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



281
282
283
284
285
286
287
288
289
290
# File '../../src/modules/Security.rb', line 281

def ReadServiceSettings
  read_missing_mandatory_services
  setting = MissingMandatoryServices() == [] ? "secure" : "insecure"
  @Settings["MANDATORY_SERVICES"] = setting
  read_extra_services
  setting = ExtraServices() == [] ? "secure" : "insecure"
  @Settings["EXTRA_SERVICES"] = setting

  nil
end

- (Object) SetModified

Function sets internal variable, which indicates, that any settings were modified, to “true”



268
269
270
271
272
# File '../../src/modules/Security.rb', line 268

def SetModified
  @modified = true

  nil
end

- (Object) Summary

Create a textual summary and a list of unconfigured cards

Returns:

  • summary of the current configuration



774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
# File '../../src/modules/Security.rb', line 774

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

Returns:

  • true on success



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
# File '../../src/modules/Security.rb', line 647

def Write
  return true if !@modified
  log.info "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")
    ],
    ""
  )

  log.debug "Settings=#{@Settings}"

  # Write security settings
  return false if Abort()
  Progress.NextStage
  @Settings["PERMISSION_SECURITY"] << " local"
  write_to_locations

  # Write inittab settings
  return false if Abort()
  Progress.NextStage
  write_console_shutdown(@Settings.fetch("CONSOLE_SHUTDOWN", "ignore"))

  # Write authentication and privileges settings
  return false if Abort()
  Progress.NextStage
  write_pam_settings
  write_polkit_settings
  write_kernel_settings

  # Finish him
  return false if Abort()
  Progress.NextStage
  apply_new_settings

  return false if Abort()
  Progress.NextStage
  activate_changes

  return false if Abort()
  @modified = false
  true
end

- (Object) write_console_shutdown(ca)

Write the value of ctrl-alt-delete behavior



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
# File '../../src/modules/Security.rb', line 479

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"
    )
  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

- (Object) write_kernel_settings

Write settings related to sysctl.conf and sysrq



577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
# File '../../src/modules/Security.rb', line 577

def write_kernel_settings
  # write sysctl.conf
  written = false
  # NOTE: the call to #sort is only needed to satisfy the old testsuite
  @sysctl.sort.each do |key, default_value|
    val = @Settings.fetch(key, default_value)
    int_val = Integer(val) rescue nil
    if int_val.nil?
      log.error "value #{val} for #{key} is not integer, not writing"
    elsif val != SCR.Read(path(".etc.sysctl_conf") + key)
      SCR.Write(path(".etc.sysctl_conf") + key, val)
      written = true
    end
  end
  SCR.Write(path(".etc.sysctl_conf"), nil) if written

  # enable sysrq?
  sysrq = Integer(@Settings.fetch("kernel.sysrq", "0")) rescue nil
  if sysrq != nil
    SCR.Execute(
      path(".target.bash"),
      "echo #{sysrq} > /proc/sys/kernel/sysrq"
    )
  end
end

- (Object) write_pam_settings

Write settings related to PAM behavior



539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
# File '../../src/modules/Security.rb', line 539

def write_pam_settings
  # pam stuff
  encr = @Settings.fetch("PASSWD_ENCRYPTION", "sha512")
  if encr != @Settings_bak["PASSWD_ENCRYPTION"]
    SCR.Write(path(".etc.login_defs.ENCRYPT_METHOD"), encr)
  end

  # use cracklib?
  if @Settings["PASSWD_USE_CRACKLIB"] == "yes"
    Pam.Add("cracklib")
    pth = @Settings["CRACKLIB_DICT_PATH"]
    if pth && pth != "/usr/lib/cracklib_dict"
      Pam.Add("--cracklib-dictpath=#{pth}")
    end
  else
    Pam.Remove("cracklib")
  end

  # save min pass length
  min_len = @Settings["PASS_MIN_LEN"]
  if min_len && min_len != "5" && @Settings["PASSWD_USE_CRACKLIB"] == "yes"
    Pam.Add("cracklib") # minlen is part of cracklib
    Pam.Add("cracklib-minlen=#{min_len}")
  else
    Pam.Remove("cracklib-minlen")
  end

  # save "remember" value (number of old user passwords to not allow)
  remember_history = @Settings["PASSWD_REMEMBER_HISTORY"]
  if remember_history && remember_history != "0"
    Pam.Add("pwhistory")
    Pam.Add("pwhistory-remember=#{remember_history}")
  else
    Pam.Remove("pwhistory-remember")
  end
end

- (Object) write_polkit_settings

Write local PolicyKit configuration



604
605
606
607
608
609
610
611
612
613
614
615
616
# File '../../src/modules/Security.rb', line 604

def write_polkit_settings
  if @Settings.fetch("HIBERNATE_SYSTEM", "") !=
      @Settings_bak.fetch("HIBERNATE_SYSTEM", "")
    # allow writing any value (different from predefined ones)
    ycp_value = @Settings.fetch("HIBERNATE_SYSTEM", "active_console")
    hibernate = @ycp2polkit.fetch(ycp_value, ycp_value)
    action = "org.freedesktop.upower.hibernate"
    SCR.Write(
      path(".etc.polkit-default-privs_local") + action,
      hibernate
    )
  end
end

- (Object) write_to_locations

Write the settings from @Locations to the corresponding files



521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
# File '../../src/modules/Security.rb', line 521

def write_to_locations
  commitlist = []
  # NOTE: the call to #sort is only needed to satisfy the old testsuite
  @Locations.sort.each do |file, vars|
    vars.each do |var|
      val = @Settings[var]
      if val && val != SCR.Read(path("#{file}.#{var}"))
        SCR.Write(path("#{file}.#{var}"), val)
        commitlist << file unless commitlist.include?(file)
      end
    end
  end
  commitlist.each do |file|
    SCR.Write(path(file), nil)
  end
end