Module: Yast::UsersLdapDialogsInclude

Defined in:
../../src/include/users/ldap_dialogs.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) initialize_users_ldap_dialogs(include_target)



30
31
32
33
34
35
36
37
38
39
40
41
# File '../../src/include/users/ldap_dialogs.rb', line 30

def initialize_users_ldap_dialogs(include_target)
  Yast.import "UI"

  Yast.import "Label"
  Yast.import "Ldap"
  Yast.import "LdapPopup"
  Yast.import "Popup"
  Yast.import "Users"
  Yast.import "Wizard"

  textdomain "users"
end

- (Object) LdapAdministrationDialog

Dialog for administering User & Group specific LDAP settigns



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
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
797
798
799
800
801
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
844
845
846
847
848
849
850
851
852
853
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
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
# File '../../src/include/users/ldap_dialogs.rb', line 591

def LdapAdministrationDialog
  Users.SetLdapSettingsRead(Ldap.Read) if !Users.LdapSettingsRead

  base_dn = Ldap.GetBaseDN
  file_server = Ldap.file_server
  modified = true

  ppolicy_list = []

  ppolicies_enabled = false
  ppolicies = {}
  ppolicies_orig = {}
  ppolicies_deleted = [] # list of DN

  # map with modifications of Password Policies objects
  write_ppolicies = {}

  # read the list of pwdpolicy objects under base_config_dn
  read_ppolicies = lambda do
    return if base_dn == ""

    if Ldap.ldap_initialized && Ldap.tls_when_initialized != Ldap.ldap_tls
      Ldap.LDAPClose
    end

    if Ldap.ldap_initialized || Ldap.LDAPInit == ""
      ppolicies_enabled = Convert.to_boolean(
        SCR.Execute(
          path(".ldap.ppolicy"),
          {
            "hostname" => Ldap.GetFirstServer(Ldap.server),
            "bind_dn"  => Ldap.GetBaseDN
          }
        )
      )

      schemas = Convert.to_list(
        SCR.Read(
          path(".ldap.search"),
          {
            "base_dn" => "",
            "attrs"   => ["subschemaSubentry"],
            "scope"   => 0
          }
        )
      )
      schema_dn = Ops.get_string(schemas, [0, "subschemaSubentry", 0], "")
      if schemas != nil && schema_dn != "" &&
          SCR.Execute(path(".ldap.schema"), { "schema_dn" => schema_dn }) == true
        pp = Convert.convert(
          SCR.Read(
            path(".ldap.search"),
            {
              "base_dn"      => base_dn,
              "filter"       => "objectClass=pwdPolicy",
              "scope"        => 2,
              "map"          => true,
              "not_found_ok" => true
            }
          ),
          :from => "any",
          :to   => "map <string, map>"
        )
        if pp != nil
          ppolicies = deep_copy(pp)
          ppolicies_orig = deep_copy(ppolicies)
        end
      end
    end

    nil
  end

  read_ppolicies.call

  help_text = _("<p><b>Home Directories</b></p>") +
    # help text
    _(
      "<p>If home directories of LDAP users should be stored on this machine,\n" +
        "check the appropriate option. Changing this value does not cause any direct\n" +
        "action.  It is only information for the YaST users module, which can manage\n" +
        "user home directories.</p>\n"
    ) + # help text caption
    # help text
    _(
      "<p>Press <b>Configure</b> to configure settings stored on the\n" +
        "LDAP server. You will be asked for the password if you are not connected yet or\n" +
        "have changed your configuration.</p>\n"
    ) +
    # password policy help text caption
    _("<p><b>Password Policy</b></p>") +
    # password policy help
    _(
      "<p>Configure the selected password policy with <b>Edit</b>. Use <b>Add</b> to add a new password policy. The configuration is only possible,\n  if the password policies are already enabled on the LDAP server.</p>"
    )

  contents = VBox(
    VSpacing(0.4),
    Left(
      CheckBox(
        Id(:file_server),
        # checkbox label
        _("&Home Directories on This Machine"),
        file_server
      )
    ),
    VSpacing(0.5),
    Right(
      PushButton(
        Id(:configure),
        # pushbutton label
        _("Configure User Management &Settings...")
      )
    ),
    VSpacing(),
    Table(
      Id(:ppolicy_table),
      Opt(:notify),
      Header(
        # table header
        _("Password Policy")
      ),
      Builtins.maplist(ppolicies) { |dn, pp| Item(Id(dn), dn) }
    ),
    HBox(
      PushButton(Id(:add), Label.AddButton),
      PushButton(Id(:edit), Label.EditButton),
      PushButton(Id(:delete), Label.DeleteButton),
      HStretch()
    ),
    VSpacing(0.4)
  )

  Wizard.CreateDialog
  # dialog title
  Wizard.SetContentsButtons(
    _("LDAP Administration Settings"),
    contents,
    help_text,
    Label.CancelButton,
    Label.OKButton
  )
  Wizard.HideAbortButton

  Builtins.foreach([:ppolicy_table, :add, :edit, :delete]) do |s|
    UI.ChangeWidget(Id(s), :Enabled, ppolicies_enabled)
  end

  ret = :cancel

  while true
    ret = Convert.to_symbol(UI.UserInput)
    if ret == :add
      suffix = base_dn
      UI.OpenDialog(
        Opt(:decorated),
        HBox(
          HSpacing(1),
          VBox(
            # InputField label
            InputField(
              Id(:cn),
              Opt(:hstretch),
              _("Name of Password Policy Object")
            ),
            ReplacePoint(
              Id(:rp_suf),
              HBox(
                # text label,suffix will follow in next label
                Label(Id(:suffix_label), _("Suffix:")),
                Label(Id(:suffix), base_dn),
                # pushbutton label
                PushButton(Id(:br_suf), _("Change Suffix"))
              )
            ),
            ButtonBox(
              PushButton(Id(:ok), Opt(:default, :key_F10), Label.OKButton),
              PushButton(Id(:cancel), Opt(:key_F9), Label.CancelButton)
            )
          ),
          HSpacing(1)
        )
      )
      UI.SetFocus(Id(:cn))
      ret2 = nil
      new_dn = ""
      while true
        ret2 = UI.UserInput
        break if ret2 == :cancel
        if ret2 == :br_suf
          suf = LdapPopup.InitAndBrowseTree(
            base_dn,
            {
              "hostname"   => Ldap.GetFirstServer(Ldap.server),
              "port"       => Ldap.GetFirstPort(Ldap.server),
              "use_tls"    => Ldap.ldap_tls ? "yes" : "no",
              "cacertdir"  => Ldap.tls_cacertdir,
              "cacertfile" => Ldap.tls_cacertfile
            }
          )
          if suf != ""
            UI.ReplaceWidget(
              Id(:rp_suf),
              HBox(
                # text label,suffix will follow in next label
                Label(Id(:suffix_label), _("Suffix:")),
                Label(Id(:suffix), suf),
                # pushbutton label
                PushButton(Id(:br_suf), _("Change Suffix"))
              )
            )
          end
        end
        if ret2 == :ok
          cn = Convert.to_string(UI.QueryWidget(Id(:cn), :Value))
          break if cn == ""
          suffix2 = Convert.to_string(UI.QueryWidget(Id(:suffix), :Value))
          new_dn = Builtins.sformat("cn=%1,%2", cn, suffix2)
          if Builtins.haskey(ppolicies, new_dn)
            Popup.Error(
              Builtins.sformat(
                _(
                  "The Policy '%1' already exists.\nPlease select another one."
                ),
                new_dn
              )
            )
            next
          end
          break
        end
      end
      UI.CloseDialog
      if ret2 == :ok && new_dn != ""
        new = PasswordPolicyDialog({ "dn" => new_dn })
        if new != nil
          Ops.set(ppolicies, new_dn, new)
          UI.ChangeWidget(
            Id(:ppolicy_table),
            :Items,
            Builtins.maplist(ppolicies) { |dn, pp| Item(Id(dn), dn) }
          )
          UI.ChangeWidget(
            Id(:edit),
            :Enabled,
            Ops.greater_than(Builtins.size(ppolicies), 0)
          )
          UI.ChangeWidget(
            Id(:delete),
            :Enabled,
            Ops.greater_than(Builtins.size(ppolicies), 0)
          )
        end
      end
    end
    if ret == :edit || ret == :ppolicy_table
      dn = Convert.to_string(
        UI.QueryWidget(Id(:ppolicy_table), :CurrentItem)
      )
      changes = PasswordPolicyDialog(Ops.get(ppolicies, dn, {}))
      if changes != nil
        Ops.set(
          ppolicies,
          dn,
          Builtins.union(Ops.get(ppolicies, dn, {}), changes)
        )
      end
    end
    if ret == :delete
      dn = Convert.to_string(
        UI.QueryWidget(Id(:ppolicy_table), :CurrentItem)
      )
      ppolicies = Builtins.remove(ppolicies, dn)
      ppolicies_deleted = Convert.convert(
        Builtins.union(ppolicies_deleted, [dn]),
        :from => "list",
        :to   => "list <string>"
      )
      UI.ChangeWidget(
        Id(:ppolicy_table),
        :Items,
        Builtins.maplist(ppolicies) { |dn2, pp| Item(Id(dn2), dn2) }
      )
      UI.ChangeWidget(
        Id(:edit),
        :Enabled,
        Ops.greater_than(Builtins.size(ppolicies), 0)
      )
      UI.ChangeWidget(
        Id(:delete),
        :Enabled,
        Ops.greater_than(Builtins.size(ppolicies), 0)
      )
    end
    # open "LDAP User objects configuration"
    if ret == :configure
      result = WFM.CallFunction("ldap_config")
      modified = true if result == :next
      next
    end
    break if ret == :back || ret == :cancel || ret == :abort
    if ret == :next
      file_server = Convert.to_boolean(
        UI.QueryWidget(Id(:file_server), :Value)
      )
      if file_server != Ldap.file_server
        Users.SetLdapSysconfigModified(true)
        Ldap.file_server = file_server
      end
      Builtins.foreach(ppolicies) do |dn, ppolicy|
        # new ppolicy
        if !Builtins.haskey(ppolicies_orig, dn)
          Ops.set(ppolicy, "modified", "added")
          Ops.set(ppolicy, "pwdAttribute", "userPassword")
          Ops.set(ppolicy, "objectClass", ["pwdPolicy", "namedObject"])
          Ops.set(ppolicy, "cn", Ldap.get_cn(dn))
          Ops.set(write_ppolicies, dn, ppolicy)
        else
          pp = {}
          Builtins.foreach(
            Convert.convert(
              ppolicy,
              :from => "map",
              :to   => "map <string, any>"
            )
          ) do |a, val|
            Ops.set(pp, a, val) if val != Ops.get(ppolicies_orig, [dn, a])
          end
          if pp != {}
            Ops.set(pp, "modified", "edited")
            Ops.set(write_ppolicies, dn, pp)
          end
        end
      end
      # deleted ppolicies
      Builtins.foreach(ppolicies_deleted) do |dn|
        pp = Ops.get(write_ppolicies, dn, {})
        if Ops.get_string(pp, "modified", "") == "added"
          write_ppolicies = Builtins.remove(write_ppolicies, dn)
        elsif Builtins.haskey(ppolicies_orig, dn)
          Ops.set(pp, "modified", "deleted")
          Ops.set(write_ppolicies, dn, pp)
        end
      end
      if write_ppolicies != {}
        Ldap.WriteLDAP(write_ppolicies)
        write_ppolicies = {}
      end
      break
    end
  end
  Wizard.CloseDialog
  modified || ret == :next
end

- (Hash) PasswordPolicyDialog(ppolicy)

dialog for Password Policy configuration object

Parameters:

  • ppolicy (Hash)

    data with Password Policy object to be edited (as obtained from LDAP search)

Returns:

  • (Hash)

    with modifications of ppolicy object, nil in case of `cancel



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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
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
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
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
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
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
# File '../../src/include/users/ldap_dialogs.rb', line 46

def PasswordPolicyDialog(ppolicy)
  ppolicy = deep_copy(ppolicy)
  # reduce the list values to single ones
  ppolicy = Builtins.mapmap(
    Convert.convert(ppolicy, :from => "map", :to => "map <string, any>")
  ) do |a, val|
    if Ops.is_list?(val) &&
        (Ldap.SingleValued(a) || Builtins.size(Convert.to_list(val)) == 1)
      val = Ops.get(Convert.to_list(val), 0)
    end
    val = val == "TRUE" if val == "TRUE" || val == "FALSE"
    { a => val }
  end
  ppolicy_orig = deep_copy(ppolicy)

  # help text for Password Policy Dialog
  help_text = _(
    "<p>Select the <b>Password Change Policies</b>, <b>Password Aging Policies</b>, and <b>Lockout Policies</b> tabs to choose LDAP password policy groups of attributes to configure.</p>"
  )


  # tab-specific help texts
  tabs_help_text = {
    # help text for pwdInHistory attribute
    :pwchange => _(
      "<p>Specify the <b>Maximum Number of Passwords Stored in History</b> to set how many previously used passwords should be saved. Saved passwords may not be used.</p>"
    ) +
      # help text for pwdMustChange attribute
      _(
        "<p>Check <b>User Must Change Password after Reset</b> to force users to change their passwords after the the password is reset or changed by an administrator.</p>"
      ) +
      # help text for pwdAllowUserChange attribute
      _(
        "<p>Check <b>User Can Change Password</b> to allow users to change their passwords.</p>"
      ) +
      # help text for pwdSafeModify attribute
      _(
        "<p>If the existing password must be provided along with the new password, check <b>Old Password Required for Password Change</b>.</p>"
      ) +
      # help text for pwdCheckQuality attribute
      _(
        "<p>Select whether the password quality should be verified while passwords are modified or added. Select <b>No Checking</b> if passwords should not be checked at all. With <b>Accept Uncheckable Passwords</b>, passwords are accepted even if the check cannot be performed, for example, if the user has provided an encrypted password. With <b>Only Accept Checked Passwords</b> passwords are refused if the quality test fails or the password cannot be checked.</p>"
      ) +
      # help text for pwdMinLength attribute
      _(
        "Set the minimum number of characters that must be used in a password in <b>Minimum Password Length</b>.</p>"
      ),
    # help text for pwdMinAge attribute
    :aging    => _(
      "<p><b>Minimum Password Age</b> sets how much time must pass between modifications to the password.</p>"
    ) +
      # help text for pwdMaxAge attribute
      _(
        "<p><b>Maximum Password Age</b> sets how long after modification a password expires.</p>"
      ) +
      # help text for pwdExpireWarning attribute
      _(
        "<p>In <b>Time before Password Expiration to Issue Warning</b> set how long before a password is due to expire that an expiration warning messages should be given to an authenticating user.</p>"
      ) +
      # help text for pwdGraceAuthNLimit attribute
      _(
        "<p>Set the number of times an expired password can be used to authenticate in <b>Allowed Uses of an Expired Password</b>.</p>"
      ),
    # help text for pwdLockout attribute
    :lockout  => _(
      "<p>Check <b>Enable Password Locking</b> to forbid use of a password after a specified number of consecutive failed bind attempts.</p>"
    ) +
      # help text for pwdMaxFailure attribute
      _(
        "<p>Set the number of consecutive failed bind  attempts after which the password may not be used to authenticate in <b>Bind Failures to Lock the Password</b>.</p>"
      ) +
      # help text for pwdLockoutDuration attribute
      _(
        "<p>Set how long the password cannot be used in <b>Password Lock Duration</b>.</p>"
      ) +
      # help text for pwdFailureCountInterval attribute
      _(
        "<p><b>Bind Failures Cache Duration</b> sets how long before password failures are purged from the failure counter even though no successful authentication has occurred.</p>"
      )
  }

  # map of attribute names for each tab
  attributes = {
    :pwchange => [
      "pwdInHistory",
      "pwdMustChange",
      "pwdAllowUserChange",
      "pwdSafeModify",
      "pwdCheckQuality",
      "pwdMinLength"
    ],
    :aging    => [
      "pwdMinAge",
      "pwdMaxAge",
      "pwdExpireWarning",
      "pwdGraceAuthNLimit"
    ],
    :lockout  => [
      "pwdLockout",
      "pwdLockoutDuration",
      "pwdMaxFailure",
      "pwdFailureCountInterval"
    ]
  }

  time_attributes = [
    "pwdMinAge",
    "pwdMaxAge",
    "pwdExpireWarning",
    "pwdLockoutDuration",
    "pwdFailureCountInterval"
  ]

  default_values = {
    "pwdMustChange"      => false,
    "pwdAllowUserChange" => true,
    "pwdSafeModify"      => false,
    "pwdLockout"         => false
  }

  # maximal value of IntFields
  max = 99999

  tabs = [
    # tab label
    Item(Id(:pwchange), _("&Password Change Policies"), true),
    # tab label
    Item(Id(:aging), _("Pa&ssword Aging Policies")),
    # tab label
    Item(Id(:lockout), _("&Lockout Policies"))
  ]
  tabs_term = VBox(
    DumbTab(Id(:tabs), tabs, ReplacePoint(Id(:tabContents), VBox(Empty())))
  )
  has_tabs = true
  if !UI.HasSpecialWidget(:DumbTab)
    has_tabs = false
    tabbar = HBox()
    Builtins.foreach(tabs) do |it|
      label = Ops.get_string(it, 1, "")
      tabbar = Builtins.add(tabbar, PushButton(Ops.get_term(it, 0) do
        Id(label)
      end, label))
    end
    tabs_term = VBox(
      Left(tabbar),
      Frame("", ReplacePoint(Id(:tabContents), Empty()))
    )
  end

  contents = deep_copy(tabs_term)

  # generate the term of password policy tab and update the help text
  set_password_policies_term = lambda do
    pwdcheckquality = Builtins.tointeger(
      Ops.get_string(ppolicy, "pwdCheckQuality", "0")
    )
    tab_cont = Top(
      HBox(
        HSpacing(0.5),
        VBox(
          VSpacing(0.8),
          IntField(
            Id("pwdInHistory"),
            # IntField label
            _("Ma&ximum Number of Passwords Stored in History"),
            0,
            max,
            Builtins.tointeger(Ops.get_string(ppolicy, "pwdInHistory", "0"))
          ),
          VSpacing(0.4),
          Left(
            CheckBox(
              Id("pwdMustChange"),
              # checkbox label
              _("U&ser Must Change Password after Reset"),
              Ops.get_boolean(ppolicy, "pwdMustChange", true)
            )
          ),
          VSpacing(0.2),
          Left(
            CheckBox(
              Id("pwdAllowUserChange"),
              # checkbox label
              _("&User Can Change Password"),
              Ops.get_boolean(ppolicy, "pwdAllowUserChange", true)
            )
          ),
          VSpacing(0.2),
          Left(
            CheckBox(
              Id("pwdSafeModify"),
              # checkbox label
              _("&Old Password Required for Password Change"),
              Ops.get_boolean(ppolicy, "pwdSafeModify", false)
            )
          ),
          VSpacing(0.4),
          # frame label
          HBox(
            HSpacing(2),
            Frame(
              _("Password Quality Checking"),
              VBox(
                VSpacing(0.5),
                RadioButtonGroup(
                  Id("pwdCheckQuality"),
                  VBox(
                    Left(
                      RadioButton(
                        Id(0),
                        Opt(:notify),
                        _("&No Checking"),
                        pwdcheckquality == 0
                      )
                    ),
                    Left(
                      RadioButton(
                        Id(1),
                        Opt(:notify),
                        _("Acc&ept Uncheckable Passwords"),
                        pwdcheckquality == 1
                      )
                    ),
                    Left(
                      RadioButton(
                        Id(2),
                        Opt(:notify),
                        _("&Only Accept Checked Passwords"),
                        pwdcheckquality == 2
                      )
                    )
                  )
                ),
                VSpacing(0.4),
                # IntField label
                IntField(
                  Id("pwdMinLength"),
                  _("&Minimum Password Length"),
                  0,
                  max,
                  Builtins.tointeger(
                    Ops.get_string(ppolicy, "pwdMinLength", "0")
                  )
                )
              )
            )
          )
        ),
        HSpacing(0.5)
      )
    )

    UI.ReplaceWidget(:tabContents, tab_cont)
    UI.ChangeWidget(
      Id("pwdMinLength"),
      :Enabled,
      Ops.greater_than(pwdcheckquality, 0)
    )
    nil
  end

  time_dialog = lambda do |id, label|
    value = Builtins.tointeger(Ops.get_string(ppolicy, id, "0"))
    days = Ops.divide(value, 24 * 60 * 60)
    if Ops.greater_than(days, 0)
      value = Ops.subtract(
        value,
        Ops.multiply(Ops.multiply(Ops.multiply(days, 24), 60), 60)
      )
    end
    hours = Ops.divide(value, 60 * 60)
    if Ops.greater_than(hours, 0)
      value = Ops.subtract(value, Ops.multiply(Ops.multiply(hours, 60), 60))
    end
    minutes = Ops.divide(value, 60)
    if Ops.greater_than(minutes, 0)
      value = Ops.subtract(value, Ops.multiply(minutes, 60))
    end
    HBox(
      HSpacing(0.3),
      Frame(
        label,
        HBox(
          IntField(Id(Ops.add(id, "d")), _("Days"), 0, max, days),
          IntField(Id(Ops.add(id, "h")), _("Hours"), 0, 23, hours),
          IntField(Id(Ops.add(id, "m")), _("Minutes"), 0, 59, minutes),
          IntField(Id(Ops.add(id, "s")), _("Seconds"), 0, 59, value)
        )
      ),
      HSpacing(0.3)
    )
  end

  get_seconds_value = lambda do |attr|
    days = Convert.to_integer(
      UI.QueryWidget(Id(Ops.add(attr, "d")), :Value)
    )
    hours = Convert.to_integer(
      UI.QueryWidget(Id(Ops.add(attr, "h")), :Value)
    )
    minutes = Convert.to_integer(
      UI.QueryWidget(Id(Ops.add(attr, "m")), :Value)
    )
    seconds = Convert.to_integer(
      UI.QueryWidget(Id(Ops.add(attr, "s")), :Value)
    )
    Ops.add(
      Ops.add(
        Ops.add(
          Ops.multiply(Ops.multiply(Ops.multiply(days, 24), 60), 60),
          Ops.multiply(Ops.multiply(hours, 60), 60)
        ),
        Ops.multiply(minutes, 60)
      ),
      seconds
    )
  end

  # generate the term of password aging tab
  set_aging_policies_term = lambda do
    tab_cont = Top(
      HBox(
        HSpacing(0.5),
        VBox(
          VSpacing(0.7),
          # frame label
          time_dialog.call("pwdMinAge", _("Minimum Password Age")),
          VSpacing(0.4),
          # frame label
          time_dialog.call("pwdMaxAge", _("Maximum Password Age")),
          VSpacing(0.4),
          time_dialog.call(
            "pwdExpireWarning",
            # frame label
            _("Time before Password Expiration to Issue Warning")
          ),
          VSpacing(0.2),
          IntField(
            Id("pwdGraceAuthNLimit"),
            # IntField label
            _("Allowed Uses of an Expired Password"),
            0,
            max,
            Builtins.tointeger(
              Ops.get_string(ppolicy, "pwdGraceAuthNLimit", "0")
            )
          )
        ),
        HSpacing(0.5)
      )
    )
    UI.ReplaceWidget(:tabContents, tab_cont)
    nil
  end

  # generate the term of lockout aging tab
  set_lockout_policies_term = lambda do
    pwdlockout = Ops.get_boolean(ppolicy, "pwdLockout", false)

    tab_cont = Top(
      HBox(
        HSpacing(0.5),
        VBox(
          VSpacing(0.8),
          Left(
            CheckBox(
              Id("pwdLockout"),
              Opt(:notify),
              # check box label
              _("Enable Password Locking"),
              pwdlockout
            )
          ),
          VSpacing(0.4),
          IntField(
            Id("pwdMaxFailure"),
            # intField label
            _("Bind Failures to Lock the Password"),
            0,
            max,
            Builtins.tointeger(
              Ops.get_string(ppolicy, "pwdMaxFailure", "0")
            )
          ),
          # frame label
          time_dialog.call(
            "pwdLockoutDuration",
            _("Password Lock Duration")
          ),
          VSpacing(0.4),
          time_dialog.call(
            "pwdFailureCountInterval",
            # frame label
            _("Bind Failures Cache Duration")
          )
        ),
        HSpacing(0.5)
      )
    )

    UI.ReplaceWidget(:tabContents, tab_cont)
    UI.ChangeWidget(Id("pwdMaxFailure"), :Enabled, pwdlockout)
    Builtins.foreach(["d", "h", "m", "s"]) do |suffix|
      UI.ChangeWidget(
        Id(Ops.add("pwdLockoutDuration", suffix)),
        :Enabled,
        pwdlockout
      )
      UI.ChangeWidget(
        Id(Ops.add("pwdFailureCountInterval", suffix)),
        :Enabled,
        pwdlockout
      )
    end
    nil
  end

  current_tab = :pwchange
  result = nil

  Wizard.OpenNextBackDialog

  # dialog label
  Wizard.SetContentsButtons(
    _("Password Policy Configuration"),
    contents,
    Ops.add(help_text, Ops.get_string(tabs_help_text, current_tab, "")),
    Label.CancelButton,
    Label.OKButton
  )
  Wizard.HideAbortButton

  set_password_policies_term.call

  while true
    result = UI.UserInput

    if Ops.is_symbol?(result) &&
        Builtins.contains(
          [:back, :cancel, :abort],
          Convert.to_symbol(result)
        )
      break
    end

    # save the values from UI
    Builtins.foreach(Ops.get_list(attributes, current_tab, [])) do |attr|
      if Builtins.contains(time_attributes, attr)
        Ops.set(
          ppolicy,
          attr,
          Builtins.sformat("%1", get_seconds_value.call(attr))
        )
        next
      end
      val = UI.QueryWidget(Id(attr), :Value)
      val = Builtins.sformat("%1", val) if Ops.is_integer?(val)
      Ops.set(ppolicy, attr, val)
    end

    if (result == :pwchange || result == :aging || result == :lockout) &&
        result != current_tab
      if result == :pwchange
        set_password_policies_term.call
      elsif result == :aging
        set_aging_policies_term.call
      elsif result == :lockout
        set_lockout_policies_term.call
      end
      current_tab = Convert.to_symbol(result)
      UI.ChangeWidget(Id(:tabs), :CurrentItem, current_tab) if has_tabs
      Wizard.SetHelpText(
        Ops.add(help_text, Ops.get_string(tabs_help_text, current_tab, ""))
      )
      next
    end
    if result == :next
      cont = false

      # check the template required attributes...
      Builtins.foreach(Ops.get_list(ppolicy, "objectClass", [])) do |oc|
        next if cont
        Builtins.foreach(Ldap.GetRequiredAttributes(oc)) do |attr|
          val = Ops.get(ppolicy, attr)
          if !cont && val == nil || val == [] || val == ""
            #error popup, %1 is attribute name
            Popup.Error(
              Builtins.sformat(
                _("The \"%1\" attribute is mandatory.\nEnter a value."),
                attr
              )
            )
            UI.SetFocus(Id(:table))
            cont = true
          end
        end
      end
      next if cont
      break
    end
    # now solve events inside the tabs
    if current_tab == :pwchange && Ops.is_integer?(result)
      UI.ChangeWidget(Id("pwdMinLength"), :Enabled, result != 0)
    end
    if current_tab == :lockout && result == "pwdLockout"
      pwdlockout = Convert.to_boolean(
        UI.QueryWidget(Id("pwdLockout"), :Value)
      )
      UI.ChangeWidget(Id("pwdMaxFailure"), :Enabled, pwdlockout)
      Builtins.foreach(["d", "h", "m", "s"]) do |suffix|
        UI.ChangeWidget(
          Id(Ops.add("pwdFailureCountInterval", suffix)),
          :Enabled,
          pwdlockout
        )
        UI.ChangeWidget(
          Id(Ops.add("pwdLockoutDuration", suffix)),
          :Enabled,
          pwdlockout
        )
      end
    end
  end
  Wizard.CloseDialog

  ret = {}
  if result == :next
    Builtins.foreach(
      Convert.convert(ppolicy, :from => "map", :to => "map <string, any>")
    ) do |key, val|
      if !Builtins.haskey(ppolicy_orig, key) &&
          (val == Ops.get(default_values, key) || val == "0")
        next
      end
      if val != Ops.get(ppolicy_orig, key)
        val = val == true ? "TRUE" : "FALSE" if Ops.is_boolean?(val)
        Ops.set(ret, key, val)
      end
    end
  end
  result == :next ? ret : nil
end