Module: Yast::AuditLafComplexInclude

Defined in:
../../src/include/audit-laf/complex.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) CheckExec(file, key)



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# File '../../src/include/audit-laf/complex.rb', line 334

def CheckExec(file, key)
  # Check the executable like done in audit package (see audit-1.7.7/src/auditd-config.c)
  ret = true
  # Second part of an error message: the value won't be changed because of previous error
  message = Builtins.sformat(_("Value of '%1' remains unchanged."), key)

  if !FileUtils.Exists(file)
    Report.Error(
      Ops.add(Builtins.sformat(_("%1 doesn't exist.\n"), file), message)
    )
    ret = false
  elsif !FileUtils.IsFile(file)
    Report.Error(
      Ops.add(
        Builtins.sformat(_("%1 is not a regular file.\n"), file),
        message
      )
    )
    ret = false
  elsif FileUtils.GetOwnerUserID(file) != 0
    Report.Error(
      Ops.add(Builtins.sformat(_("%1 not owned by root.\n"), file), message)
    )
    ret = false
  else
    # check permissions
    output = Convert.to_map(
      SCR.Execute(
        path(".target.bash_output"),
        Builtins.sformat("ls -al %1", file)
      )
    )

    if Builtins.substring(Ops.get_string(output, "stdout", ""), 0, 10) != "-rwxr-x---"
      Report.Error(
        Ops.add(
          Builtins.sformat(
            _("File permissions of %1 NOT set to -rwxr-x---.\n"),
            file
          ),
          message
        )
      )
      ret = false
    end
  end

  ret
end

- (Object) CheckSettings



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
# File '../../src/include/audit-laf/complex.rb', line 654

def CheckSettings
  ret = :next
  AuditLaf.SetRulesLocked(false)

  rules = AuditLaf.GetRules
  rules_list = Builtins.splitstring(rules, "\n")

  Builtins.y2milestone("Checking rules...")

  Builtins.foreach(rules_list) do |rule|
    if Builtins.regexpmatch(rule, "^[ /t]*-e[ /t]*2")
      yes = Popup.AnyQuestion(
        _("Lock set"),
        _(
          "The audit configuration is locked (option -e 2).\n" +
            "This means the rules are locked until next boot!\n" +
            "If you really want this, make sure '-e 2' is the last entry\n" +
            "in the rules file. If not, either enable or disable auditing.\n" +
            "To check or change the rules, go back to the rules editor.\n"
        ),
        Label.ContinueButton,
        Label.BackButton,
        :focus_no
      )
      if yes
        ret = :next
      else
        ret = :back
        AuditLaf.SetRulesLocked(true)
      end
    end
  end

  ret
end

- (Object) HandleDiskspaceSettingsDialog(id, event)

Handle actions of disk space



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
# File '../../src/include/audit-laf/complex.rb', line 294

def HandleDiskspaceSettingsDialog(id, event)
  event = deep_copy(event)
  action = Ops.get(event, "ID")
  Builtins.y2milestone(
    "HandleDiskspaceSettingsDialog got action: %1",
    action
  )

  actions_list = [
    "space_left_action",
    "admin_space_left_action",
    "disk_full_action",
    "disk_error_action"
  ]

  if Ops.is_string?(action) &&
      Builtins.contains(actions_list, Convert.to_string(action))
    option = Convert.to_string(
      UI.QueryWidget(Id(Convert.to_string(action)), :Value)
    )
    Builtins.y2milestone("Option: %1", option)

    if option == "EXEC"
      UI.ChangeWidget(
        Id(Ops.add(Convert.to_string(action), "_exec")),
        :Enabled,
        true
      )
    else
      UI.ChangeWidget(
        Id(Ops.add(Convert.to_string(action), "_exec")),
        :Enabled,
        false
      )
    end
  end

  nil
end

- (Object) HandleDispatcherDialog(id, event)

Handle actions of dispatcher dialog (button 'Select file')



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File '../../src/include/audit-laf/complex.rb', line 213

def HandleDispatcherDialog(id, event)
  event = deep_copy(event)
  action = Ops.get(event, "ID")

  Builtins.y2milestone("HandleDispatcherDialog got action: %1", action)

  if action == "select_disp"
    file_name = UI.AskForExistingFile(
      "/sbin",
      "*",
      _("Select the dispatcher program")
    )

    UI.ChangeWidget(Id("dispatcher"), :Value, file_name)
    Builtins.y2milestone("Dispatcher program set to: %1", file_name)
  end
  nil
end

- (Object) HandleLogfileSettingsDialog(id, event)

Handle actions of log file dialog (button 'Select file')



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
# File '../../src/include/audit-laf/complex.rb', line 116

def HandleLogfileSettingsDialog(id, event)
  event = deep_copy(event)
  action = Ops.get(event, "ID")

  Builtins.y2milestone("HandleLogfileSettingsDialog got action: %1", action)

  if action == "select_file"
    file_name = UI.AskForSaveFileName(
      "/var/log/audit",
      "*.log",
      _("Select the log file")
    )
    UI.ChangeWidget(Id("log_file"), :Value, file_name)

    Builtins.y2milestone("Logfile set to: %1", file_name)
  elsif action == "name_format"
    option = Convert.to_string(UI.QueryWidget(Id("name_format"), :Value))
    if option == "USER"
      UI.ChangeWidget(Id("name"), :Enabled, true)
    else
      UI.ChangeWidget(Id("name"), :Enabled, false)
    end
  end
  nil
end

- (Object) HandleRulesDialog(id, event)

Handle actions of rules dialog



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
557
558
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
599
600
601
602
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
# File '../../src/include/audit-laf/complex.rb', line 500

def HandleRulesDialog(id, event)
  event = deep_copy(event)
  action = Ops.get(event, "ID")
  Builtins.y2milestone("HandleRulesDialog got action: %1", action)

  if action == "audit_enabled"
    rule = ""
    rules_list = []

    value = Convert.to_string(UI.QueryWidget(Id("audit_enabled"), :Value))
    rules = Convert.to_string(UI.QueryWidget(Id("rules"), :Value))

    Builtins.y2milestone("Setting status to: %1", value)

    case value
      when "locked"
        rule = "-e 2"
      when "enabled"
        rule = "-e 1"
      when "disabled"
        rule = "-e 0"
    end

    if rules != nil && rules != ""
      rules_list = Builtins.splitstring(rules, "\n")
    end

    rule_found = false

    if rules_list != []
      new_rules = Builtins.maplist(rules_list) do |line|
        if Builtins.regexpmatch(line, "^[ /t]*-e")
          rule_found = true
          next rule
        else
          next line
        end
      end
      new_rules = Builtins.add(new_rules, rule) if !rule_found

      UI.ChangeWidget(
        Id("rules"),
        :Value,
        Builtins.mergestring(new_rules, "\n")
      )
    end
  elsif action == "restore"
    InitRulesDialog("restore")
  elsif action == "reset"
    InitRulesDialog("reset")

    ResetRules()
  elsif action == "test"
    go_on = true

    rules = Convert.to_string(UI.QueryWidget(Id("rules"), :Value))
    rules_list = Builtins.splitstring(rules, "\n")

    if AuditLaf.RulesAlreadyLocked
      Report.Warning(
        _(
          "The rules are already locked.\n" +
            "\n" +
            "A test is impossible because sending new rules\n" +
            "will cause an error.\n"
        )
      )
      go_on = false
    end

    Builtins.foreach(rules_list) do |rule|
      if Builtins.regexpmatch(rule, "^[ /t]*-e[ /t]*2")
        Report.Warning(
          _(
            "Lock is set in audit.rules (-e 2).\n" +
              "\n" +
              "It makes no sense to continue, because the rules will\n" +
              "be locked until next boot.\n"
          )
        )
        go_on = false
      end
    end if go_on

    if go_on
      tmpfile = Ops.add(
        Convert.to_string(SCR.Read(path(".target.tmpdir"))),
        "/rules_test_file"
      )

      success = SCR.Write(path(".target.string"), tmpfile, rules)
      if success
        Builtins.y2milestone("Calling auditctl -R %1", tmpfile)

        output = Convert.to_map(
          SCR.Execute(
            path(".target.bash_output"),
            Builtins.sformat("auditctl -R %1", tmpfile)
          )
        )

        AuditLaf.SetRulesChanged(true)

        if Ops.get_integer(output, "exit", 0) != 0
          Report.Error(Ops.get_string(output, "stderr", ""))
        else
          Popup.Message(_("Success"))
        end
      else
        Report.Error(_("Cannot create tmp file for rules."))
      end
    end
  elsif action == "load"
    file_name = UI.AskForExistingFile(
      "/usr/share/doc/packages/audit",
      "*.rules",
      _("Select an example")
    )
    if file_name != nil
      example_rules = Convert.to_string(
        SCR.Read(path(".target.string"), file_name))
      UI.ChangeWidget(Id("rules"), :Value, example_rules)
      Builtins.y2milestone("Example rules loaded: %1", file_name)
    end
  end

  nil
end

- (Object) InitDiskspaceSettingsDialog(id)

Init disk space dialog (set values to values read with AuditLad::Read())



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File '../../src/include/audit-laf/complex.rb', line 251

def InitDiskspaceSettingsDialog(id)
  UI.ChangeWidget(Id("space_left"), :ValidChars, "0123456789")
  UI.ChangeWidget(Id("admin_space_left"), :ValidChars, "0123456789")

  # Set all values to values read from /etc/audit/auditd.conf
  Builtins.foreach(["space_left", "action_mail_acct", "admin_space_left"]) do |key|
    UI.ChangeWidget(Id(key), :Value, AuditLaf.GetAuditdOption(key))
  end

  Builtins.foreach(
    [
      "space_left_action",
      "admin_space_left_action",
      "disk_full_action",
      "disk_error_action"
    ]
  ) do |key|
    if Builtins.toupper(
        Builtins.substring(AuditLaf.GetAuditdOption(key), 0, 4)
      ) == "EXEC"
      UI.ChangeWidget(Id(key), :Value, "EXEC")
      UI.ChangeWidget(Id(Ops.add(key, "_exec")), :Enabled, true)
      UI.ChangeWidget(
        Id(Ops.add(key, "_exec")),
        :Value,
        Builtins.substring(AuditLaf.GetAuditdOption(key), 5)
      )
    else
      UI.ChangeWidget(
        Id(key),
        :Value,
        Builtins.toupper(AuditLaf.GetAuditdOption(key))
      )
      UI.ChangeWidget(Id(Ops.add(key, "_exec")), :Enabled, false)
    end
  end

  Builtins.y2milestone("Init disk space settings")

  nil
end

- (Object) InitDispatcherDialog(id)

Init dispatcher dialog (set values to values read with AuditLad::Read())



201
202
203
204
205
206
207
208
209
210
# File '../../src/include/audit-laf/complex.rb', line 201

def InitDispatcherDialog(id)
  # Set all values to values read from /etc/audit/auditd.conf
  Builtins.foreach(["dispatcher", "disp_qos"]) do |key|
    UI.ChangeWidget(Id(key), :Value, AuditLaf.GetAuditdOption(key))
  end

  Builtins.y2milestone("Init dispatcher dialog")

  nil
end

- (Object) initialize_audit_laf_complex(include_target)



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File '../../src/include/audit-laf/complex.rb', line 29

def initialize_audit_laf_complex(include_target)
  Yast.import "UI"

  textdomain "audit-laf"

  Yast.import "Label"
  Yast.import "Popup"
  Yast.import "Wizard"
  Yast.import "Confirm"
  Yast.import "AuditLaf"
  Yast.import "Report"
  Yast.import "FileUtils"

  Yast.include include_target, "audit-laf/helps.rb"
end

- (Object) InitLogfileSettingsDialog(id)

Init log file dialog (set values to values read with AuditLad::Read())



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
# File '../../src/include/audit-laf/complex.rb', line 75

def InitLogfileSettingsDialog(id)
  UI.ChangeWidget(Id("max_log_file"), :ValidChars, "0123456789")

  # Set all values to values read from /etc/audit/auditd.conf
  UI.ChangeWidget(
    Id("freq"),
    :Value,
    Builtins.tointeger(AuditLaf.GetAuditdOption("freq"))
  )
  UI.ChangeWidget(
    Id("num_logs"),
    :Value,
    Builtins.tointeger(AuditLaf.GetAuditdOption("num_logs"))
  )
  Builtins.foreach(["log_file", "max_log_file", "name"]) do |key|
    UI.ChangeWidget(Id(key), :Value, AuditLaf.GetAuditdOption(key))
  end

  Builtins.foreach(
    ["log_format", "flush", "max_log_file_action", "name_format"]
  ) do |key|
    UI.ChangeWidget(
      Id(key),
      :Value,
      Builtins.toupper(AuditLaf.GetAuditdOption(key))
    )
    if key == "name_format"
      if Builtins.toupper(AuditLaf.GetAuditdOption(key)) == "USER"
        UI.ChangeWidget(Id("name"), :Enabled, true)
      else
        UI.ChangeWidget(Id("name"), :Enabled, false)
      end
    end
  end

  Builtins.y2milestone("Init log file settings")

  nil
end

- (Object) InitRulesDialog(id)

Init rules dialog



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
# File '../../src/include/audit-laf/complex.rb', line 426

def InitRulesDialog(id)
  rules = ""
  combo_box_id = "disabled"

  if id == "restore" || id == "reset"
    rules = AuditLaf.GetInitialRules
  else
    rules = AuditLaf.GetRules
  end

  UI.ChangeWidget(Id("rules"), :Value, rules)
  rules_list = Builtins.splitstring(rules, "\n")

  Builtins.foreach(rules_list) do |rule|
    if Builtins.regexpmatch(rule, "^[ /t]*-e[ /t]*2")
      combo_box_id = "locked"
    elsif Builtins.regexpmatch(rule, "^[ /t]*-e[ /t]*1")
      combo_box_id = "enabled"
    elsif Builtins.regexpmatch(rule, "^[ /t]*-e[ /t]*0")
      combo_box_id = "disabled"
    end
  end
  UI.ChangeWidget(Id("audit_enabled"), :Value, combo_box_id)

  Builtins.y2milestone("Init rules dialog")

  nil
end

- (Object) Modified

Return a modification status

Returns:

  • true if data was modified



47
48
49
# File '../../src/include/audit-laf/complex.rb', line 47

def Modified
  AuditLaf.Modified
end

- (Object) ReadDialog

Read settings dialog

Returns:

  • abort if aborted andnext otherwise



57
58
59
60
61
62
63
# File '../../src/include/audit-laf/complex.rb', line 57

def ReadDialog
  Wizard.RestoreHelp(Ops.get_string(@HELPS, "read", ""))
  return :abort if !Confirm.MustBeRoot

  ret = AuditLaf.Read
  ret ? :next : :abort
end

- (Object) ReallyAbort



51
52
53
# File '../../src/include/audit-laf/complex.rb', line 51

def ReallyAbort
  Popup.ReallyAbort(AuditLaf.Modified)
end

- (Object) Reset

Called if 'Abort' button is pressed in main dialog. If the rules are changed by a syntax check the changes will be reseted.



648
649
650
651
652
# File '../../src/include/audit-laf/complex.rb', line 648

def Reset
  ResetRules() if AuditLaf.RulesChanged

  nil
end

- (Object) ResetRules

Reset rules - called if button 'Restore and Reset' is pressed or if the user aborts configuration after doing 'Check Syntax' (which changes the rules).



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
# File '../../src/include/audit-laf/complex.rb', line 457

def ResetRules
  if AuditLaf.RulesAlreadyLocked
    # Warning - the audit configuration is locked, reset impossible
    Report.Warning(
      _(
        "The rules are already locked, a reset is impossible.\n" +
          "\n" +
          "If you want to unlock, set the enabled flag accordingly and\n" +
          "finish the configuration. Afterwards a reboot is required."
      )
    )
  else
    Builtins.y2milestone("Calling auditctl -D")

    exit_code = Convert.to_integer(
      SCR.Execute(path(".target.bash"), "auditctl -D")
    )

    Builtins.y2milestone("Calling auditctl -R /etc/audit/audit.rules")

    if exit_code == 0
      exit_code = Convert.to_integer(
        SCR.Execute(
          path(".target.bash"),
          "auditctl -R /etc/audit/audit.rules"
        )
      )
    end

    if exit_code == 0
      # Report success
      Popup.Message(_("Rules successfully restored"))
      AuditLaf.SetRulesChanged(false)
    else
      # Report error - error during reset
      Report.Error(_("Cannot reset rules. Check /etc/audit/audit.rules."))
    end
  end

  nil
end

- (Object) StoreDiskspaceSettingsDialog(id, event)

Store all settings made in disk space dialog



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
# File '../../src/include/audit-laf/complex.rb', line 385

def StoreDiskspaceSettingsDialog(id, event)
  event = deep_copy(event)
  option = ""
  exec = ""

  Builtins.foreach(["space_left", "action_mail_acct", "admin_space_left"]) do |key|
    AuditLaf.SetAuditdOption(
      key,
      Convert.to_string(UI.QueryWidget(Id(key), :Value))
    )
  end

  Builtins.foreach(
    [
      "space_left_action",
      "admin_space_left_action",
      "disk_full_action",
      "disk_error_action"
    ]
  ) do |key|
    option = Convert.to_string(UI.QueryWidget(Id(key), :Value))
    if option == "EXEC"
      exec = Convert.to_string(
        UI.QueryWidget(Id(Ops.add(key, "_exec")), :Value)
      )
      if CheckExec(exec, key)
        AuditLaf.SetAuditdOption(key, Ops.add(Ops.add(option, " "), exec))
      end
    else
      AuditLaf.SetAuditdOption(key, option)
    end
  end

  AuditLaf.SetDataModified

  Builtins.y2milestone("Store disk space settings")

  nil
end

- (Object) StoreDispatcherDialog(id, event)

Store all settings made in dispatcher dialog



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File '../../src/include/audit-laf/complex.rb', line 233

def StoreDispatcherDialog(id, event)
  event = deep_copy(event)
  # Store all values in SETTINGS
  Builtins.foreach(["dispatcher", "disp_qos"]) do |key|
    AuditLaf.SetAuditdOption(
      key,
      Convert.to_string(UI.QueryWidget(Id(key), :Value))
    )
  end

  AuditLaf.SetDataModified

  Builtins.y2milestone("Store dispatcher dialog")

  nil
end

- (Object) StoreLogfileSettingsDialog(id, event)

Store all settings made in log file dialog



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
# File '../../src/include/audit-laf/complex.rb', line 143

def StoreLogfileSettingsDialog(id, event)
  event = deep_copy(event)
  # Store all values in SETTINGS
  AuditLaf.SetAuditdOption(
    "freq",
    Builtins.tostring(
      Convert.to_integer(UI.QueryWidget(Id("freq"), :Value))
    )
  )
  AuditLaf.SetAuditdOption(
    "num_logs",
    Builtins.tostring(
      Convert.to_integer(UI.QueryWidget(Id("num_logs"), :Value))
    )
  )

  Builtins.foreach(
    [
      "log_file",
      "log_format",
      "max_log_file",
      "flush",
      "max_log_file_action",
      "name_format"
    ]
  ) do |key|
    AuditLaf.SetAuditdOption(
      key,
      Convert.to_string(UI.QueryWidget(Id(key), :Value))
    )
  end

  if AuditLaf.GetAuditdOption("name_format") == "USER"
    if Convert.to_string(UI.QueryWidget(Id("name"), :Value)) == ""
      Report.Error(
        _(
          "The 'User Defined Name' is NOT set although\n" +
            "the 'Computer Name Format' is set to 'USER'.\n" +
            "Setting the format to 'NONE' (default)."
        )
      )
      AuditLaf.SetAuditdOption("name_format", "NONE")
    else
      AuditLaf.SetAuditdOption(
        "name",
        Convert.to_string(UI.QueryWidget(Id("name"), :Value))
      )
    end
  end

  AuditLaf.SetDataModified

  Builtins.y2milestone("Store log file settings")

  nil
end

- (Object) StoreRulesDialog(id, event)

Store the rules edited in rules dialog



630
631
632
633
634
635
636
637
638
639
640
641
642
# File '../../src/include/audit-laf/complex.rb', line 630

def StoreRulesDialog(id, event)
  event = deep_copy(event)
  rules = Convert.to_string(UI.QueryWidget(Id("rules"), :Value))

  AuditLaf.SetRules(rules)

  AuditLaf.SetDataModified

  Builtins.y2debug("RULES: %1", rules)
  Builtins.y2milestone("Store rules dialog")

  nil
end

- (Object) WriteDialog

Write settings dialog

Returns:

  • abort if aborted andnext otherwise



67
68
69
70
71
72
# File '../../src/include/audit-laf/complex.rb', line 67

def WriteDialog
  Wizard.RestoreHelp(Ops.get_string(@HELPS, "write", ""))

  ret = AuditLaf.Write
  ret ? :next : :abort
end