Class List Method List File List

# Class: Yast::KerberosClass

Inherits:
  Module
  - Object
  - Module
  - Yast::KerberosClass
  show all
Defined in:
  ../../src/modules/Kerberos.rb

## Instance Method Summary (collapse)

- - (Hash) AutoPackages

  Return required packages for auto-installation.

- - (Hash) Export

  Dump the Kerberos settings to a map, for autoinstallation use.

- - (Object) Import(settings)

  Get all the Kerberos configuration from a map.

- - (Object) main
- - (Object) Modified

  Data was modified?.

- - (Object) Read

  Reads Kerberos settings from the SCR.

- - (Object) ReadFile(path_to_value, def_value) deprecated Deprecated.
- - (String) ReadKrb5ConfValue(path_to_value, def_value)

  Reads the item value from the /etc/krb5.conf via ini agent If the item doesn't exist, returns the default value.

- - (Array) ReadKrb5ConfValues(path_to_value, def_value)

  Reads the item values from the /etc/krb5.conf via ini agent If the item doesn't exist, returns the default value.

- - (Object) ReadSSSDValue(key, default_value)

  Read given value from /etc/sssd/sssd.conf.

- - (Object) RequiredPackages

  Return the list of packages for kerberos configuration.

- - (Object) ShortSummary

  Create a short textual summary.

- - (Object) Summary

  Create a textual summary.

- - (Object) ValidateTimeEntries(key, val)

  Validation function for time-related values.

- - (Object) Write

  Saves Kerberos configuration.

- - (Object) WriteFile(path_to_value, value) deprecated Deprecated.
- - (Object) WriteKrb5ConfValue(path_to_value, value)

  Write the item value to /etc/krb5.conf Do not write anything for empty and nil values.

- - (Object) WriteKrb5ConfValues(path_to_value, values)

  Write list of values for given key to /etc/krb5.conf Do not write anything for empty and nil values.

- - (Object) WriteKrb5ConfValuesAsString(path_to_value, values)

  Write (possible) multiple values of given key to /etc/krb5.conf.

- - (Object) WriteSSSD

  Write Kerberos related settings to sssd.conf.

## Instance Method Details

### - (`Hash`) AutoPackages

Return required packages for auto-installation

Returns:

- (`Hash`) —

  of packages to be installed and to be removed

    1041
    1042
    1043
    # File '../../src/modules/Kerberos.rb', line 1041

    def AutoPackages
      { "install" => RequiredPackages(), "remove" => [] }
    end

### - (`Hash`) Export

Dump the Kerberos settings to a map, for autoinstallation use.

Returns:

- (`Hash`) —

  with settings

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

    def Export
      export_map = {
        "pam_login"       => { "use_kerberos" => @use_pam_krb, "sssd" => @sssd },
        "kerberos_client" => {
          "default_domain"  => @default_domain,
          "default_realm"   => @default_realm,
          "kdc_server"      => @kdc,
          "clockskew"       => @clockskew,
          "ssh_support"     => @ssh_support,
          "ignore_unknown"  => @ignore_unknown,
          "ticket_lifetime" => @ticket_lifetime,
          "renew_lifetime"  => @renew_lifetime,
          "minimum_uid"     => @minimum_uid,
          "forwardable"     => @forwardable == "true",
          "proxiable"       => @proxiable == "true",
          "ExpertSettings"  => @ExpertSettings
        }
      }
      if @mappings != ""
        Ops.set(export_map, ["kerberos_client", "mappings"], @mappings)
      end
      if @trusted_servers != ""
        Ops.set(
          export_map,
          ["kerberos_client", "trusted_servers"],
          @trusted_servers
        )
      end
      deep_copy(export_map)
    end

### - (`Object`) Import(settings)

Get all the Kerberos configuration from a map.

Parameters:

- settings (`Hash`) —

  imported map

Returns:

- success

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

    def Import(settings)
      settings = deep_copy(settings)
      @use_pam_krb = Ops.get_boolean(
        settings,
        ["pam_login", "use_kerberos"],
        false
      )
      client = Ops.get_map(settings, "kerberos_client", {})

      @default_domain = Ops.get_string(client, "default_domain", "")
      @default_realm = Ops.get_string(client, "default_realm", "")
      @kdc = Ops.get_string(client, "kdc_server", "")
      @clockskew = Ops.get_string(client, "clockskew", @clockskew)
      @ssh_support = Ops.get_boolean(client, "ssh_support", false)
      @ignore_unknown = Ops.get_boolean(
        client,
        "ignore_unknown",
        @ignore_unknown
      )
      @ticket_lifetime = Ops.get_string(client, "ticket_lifetime", "1d")
      @renew_lifetime = Ops.get_string(client, "renew_lifetime", "1d")
      @minimum_uid = Ops.get_string(client, "minimum_uid", @minimum_uid)
      @forwardable = Ops.get_boolean(client, "forwardable", true) ? "true" : "false"
      @proxiable = Ops.get_boolean(client, "proxiable", false) ? "true" : "false"
      @use_shmem = Ops.get_string(client, "use_shmem", @use_shmem)
      @mappings = Ops.get_string(client, "mappings", "")
      @trusted_servers = Ops.get_string(client, "trusted_servers", "")
      @ExpertSettings = Ops.get_map(client, "ExpertSettings", {})
      if !Builtins.haskey(@ExpertSettings, "use_shmem") &&
          Builtins.haskey(client, "use_shmem")
        Ops.set(@ExpertSettings, "use_shmem", @use_shmem)
      end

      @sssd = Ops.get_boolean(settings, ["pam_login", "sssd"], @sssd)
      @pam_modified = true
      @modified = true
      @ssh_modified = true
      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
    # File '../../src/modules/Kerberos.rb', line 35

    def main

      textdomain "kerberos"

      Yast.import "FileUtils"
      Yast.import "Hostname"
      Yast.import "Label"
      Yast.import "Mode"
      Yast.import "Package"
      Yast.import "Pam"
      Yast.import "Progress"
      Yast.import "Report"
      Yast.import "Service"
      Yast.import "Stage"
      Yast.import "Summary"

      # Required packages for this module to operate
      @required_packages = ["pam_krb5", "krb5", "krb5-client"]

      @write_only = false

      # if pam_krb5 module is used for login
      @use_pam_krb = false

      # if pam_unix is in /etc/pam.d/login
      @pam_unix_present = false

      # default realm and domain name
      @default_realm = ""
      @default_domain = ""

      @dns_default_realm = ""
      @dns_kdc = ""

      # adress of KDC (key distribution centre) server for default realm
      @kdc = ""
      @admin_server = ""

      # used for pkinit-nss (feature 302132)
      @trusted_servers = ""

      @clockskew = "300"

      @pam_modified = false
      @ssh_modified = false
      @modified = false

      # advanced krb5.conf settings (pam section)
      @ticket_lifetime = "1d"
      @renew_lifetime = "1d"
      @forwardable = "true"
      @proxiable = "false"
      # obsolete, do not use
      @retain_after_close = "false"
      @ssh_support = false
      @minimum_uid = "1"

      # deprecated at this scope: now present in ExpertSettings map
      @use_shmem = "sshd"
      @mappings = ""

      # --krb5-ignore_unknown_principals for pam-config
      @ignore_unknown = true

      # section in /etc/ssh/ssh_config file for storing krb support
      @ssh_section = "*"

      # packages to install (openssh etc.)
      @packages = []

      # if DNS can be used for retrieving configuration data
      @dns_available = false

      # if DNS is used for retrieving configuration data
      @dns_used = false

      # if sssd is configured, do not use pam_krb5
      @sssd = false

      #   map with the settings configurable in the expert tabs
      @ExpertSettings = {}

      # backup of original ExpertSettings
      @OrigExpertSettings = {}
    end

### - (`Object`) Modified

Data was modified?

Returns:

- true if modified

    123
    124
    125
    126
    # File '../../src/modules/Kerberos.rb', line 123

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

### - (`Object`) Read

Reads Kerberos settings from the SCR

Returns:

- success

    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
    589
    590
    591
    592
    593
    594
    # File '../../src/modules/Kerberos.rb', line 296

    def Read
      pam_query = Pam.Query("krb5")
      @use_pam_krb = Ops.greater_than(Builtins.size(pam_query), 0)
      if @use_pam_krb # if krb is not enabled, ignore_unknown is true by default
        @ignore_unknown = Builtins.contains(
          Ops.get_list(pam_query, "account", []),
          "ignore_unknown_principals"
        )
      end

      # now read the settings from /etc/krb5.conf
      if FileUtils.Exists("/etc/krb5.conf")
        Builtins.y2debug(
          "krb5.conf sections: %1",
          SCR.Dir(path(".etc.krb5_conf.s"))
        )

        @default_realm = ReadKrb5ConfValue(
          path(".etc.krb5_conf.v.libdefaults.default_realm"),
          ""
        )

        @clockskew = ReadKrb5ConfValue(
          path(".etc.krb5_conf.v.libdefaults.clockskew"),
          "300"
        )

        if Ops.greater_than(Builtins.size(@default_realm), 0)
          realm = Builtins.add(path(".etc.krb5_conf.v"), @default_realm)
          @kdc = Builtins.mergestring(
            ReadKrb5ConfValues(Builtins.add(realm, "kdc"), ""),
            " "
          )
          @admin_server = Builtins.mergestring(
            ReadKrb5ConfValues(Builtins.add(realm, "admin_server"), ""),
            " "
          )
          @default_domain = ReadKrb5ConfValue(
            Builtins.add(realm, "default_domain"),
            ""
          )
        end
        @admin_server = "" if @admin_server == @kdc # we could replace it in Write in this case...

        pam_p = path(".etc.krb5_conf.v.pam")
        @ticket_lifetime = ReadKrb5ConfValue(
          Builtins.add(pam_p, "ticket_lifetime"),
          "1d"
        )
        @renew_lifetime = ReadKrb5ConfValue(
          Builtins.add(pam_p, "renew_lifetime"),
          "1d"
        )
        @forwardable = ReadKrb5ConfValue(
          Builtins.add(pam_p, "forwardable"),
          "true"
        )
        @proxiable = ReadKrb5ConfValue(
          Builtins.add(pam_p, "proxiable"),
          "false"
        )
        @minimum_uid = ReadKrb5ConfValue(
          Builtins.add(pam_p, "minimum_uid"),
          "1"
        )

        Builtins.foreach(
          [
            "keytab",
            "ccache_dir",
            "ccname_template",
            "mappings",
            "existing_ticket",
            "external",
            "validate",
            "use_shmem",
            "addressless",
            "debug",
            "debug_sensitive",
            "initial_prompt",
            "subsequent_prompt",
            "banner"
          ]
        ) do |key|
          val = ReadKrb5ConfValue(Builtins.add(pam_p, key), nil)
          Ops.set(@ExpertSettings, key, val) if val != nil
        end
        if !Builtins.haskey(@ExpertSettings, "use_shmem")
          Ops.set(@ExpertSettings, "use_shmem", "sshd")
        end
        @use_shmem = Ops.get_string(@ExpertSettings, "use_shmem", "sshd")
        if !Builtins.haskey(@ExpertSettings, "external")
          Ops.set(@ExpertSettings, "external", "sshd")
        end

        @OrigExpertSettings = deep_copy(@ExpertSettings)

        @trusted_servers = ReadKrb5ConfValue(
          path(".etc.krb5_conf.v.pkinit.trusted_servers"),
          ""
        )
      else
        SCR.Execute(
          path(".target.bash"),
          Builtins.sformat("/usr/bin/touch /etc/krb5.conf")
        )
      end

      # propose some good values, if there are install defaults
      if @default_domain == ""
        @default_domain = Hostname.CurrentDomain
        # workaround for bug#393951
        if @default_domain == "" && Stage.cont
          out = Convert.to_map(
            SCR.Execute(path(".target.bash_output"), "domainname")
          )
          if Ops.get_integer(out, "exit", 0) == 0
            @default_domain = Builtins.deletechars(
              Ops.get_string(out, "stdout", ""),
              "\n"
            )
          end
        end
      end

      # now, check DNS status (Fate 301812)
      if FileUtils.Exists("/usr/bin/dig") && @default_domain != "" && !Mode.test
        out = Convert.to_map(
          SCR.Execute(
            path(".target.bash_output"),
            Builtins.sformat("dig TXT _kerberos.%1 +short", @default_domain)
          )
        )
        @dns_default_realm = Builtins.deletechars(
          Ops.get_string(out, "stdout", ""),
          "\n\""
        )
        if @dns_default_realm != ""
          out = Convert.to_map(
            SCR.Execute(
              path(".target.bash_output"),
              Builtins.sformat(
                "dig SRV _kerberos._udp.%1 +short",
                @default_domain
              )
            )
          )
          split = Builtins.splitstring(
            Ops.get(
              Builtins.splitstring(Ops.get_string(out, "stdout", ""), "\n"),
              0,
              ""
            ),
            " "
          )
          @dns_kdc = Ops.get_string(split, 3, "")
          if @dns_kdc != "" &&
              Builtins.substring(
                @dns_kdc,
                Ops.subtract(Builtins.size(@dns_kdc), 1),
                1
              ) == "."
            @dns_kdc = Builtins.substring(
              @dns_kdc,
              0,
              Ops.subtract(Builtins.size(@dns_kdc), 1)
            )
          end
          @dns_available = true if @dns_kdc != ""
          # empty domain_realm section and no kdc entry defined and
          # values via DNS are available -> DNS is used
          if @kdc == "" &&
              (!Builtins.contains(
                SCR.Dir(path(".etc.krb5_conf.s")),
                "domain_realm"
              ) ||
                SCR.Dir(path(".etc.krb5_conf.v.domain_realm")) == [])
            @dns_used = true
            @kdc = @dns_kdc
            @default_realm = @dns_default_realm
            Builtins.y2milestone(
              "kdc by DNS %1, default_domain: %2",
              @dns_kdc,
              @dns_default_realm
            )
            Builtins.y2milestone("DNS is used for Kerberos data")
          end
        end
      end

      if (@default_realm == "" || @default_realm == "MY.REALM" ||
          @default_realm == "EXAMPLE.COM") &&
          @default_domain != ""
        @default_realm = Builtins.toupper(@default_domain)
      end
      if (@kdc == "" || @kdc == "MY.COMPUTER" || @kdc == "kerberos.example.com") &&
          FileUtils.Exists("/usr/bin/ypwhich")
        out = Convert.to_map(
          SCR.Execute(path(".target.bash_output"), "/usr/bin/ypwhich")
        )
        @kdc = Builtins.deletechars(Ops.get_string(out, "stdout", ""), "\n")
      end
      if (@kdc == "" || @kdc == "MY.COMPUTER" || @kdc == "kerberos.example.com") &&
          FileUtils.Exists("/usr/bin/host")
        proposed = Ops.add("kdc.", Hostname.CurrentDomain)
        m = Convert.to_map(
          SCR.Execute(
            path(".target.bash_output"),
            Builtins.sformat(
              "LANG=C /usr/bin/host %1 | /bin/grep address",
              proposed
            )
          )
        )
        @kdc = proposed if Ops.get_integer(m, "exit", 1) == 0
        Builtins.y2milestone("no kdc defined, proposing: %1", @kdc)
      end

      # read ssh support
      Builtins.y2debug(
        "ssh_config sections: %1",
        SCR.Dir(path(".etc.ssh.ssh_config.s"))
      )
      hostname = Hostname.CurrentHostname

      @ssh_support = nil
      Builtins.foreach(SCR.Dir(path(".etc.ssh.ssh_config.s"))) do |sec|
        # according to ssh man page, first value is taken:
        next if @ssh_support != nil
        cont = SCR.Dir(Builtins.add(path(".etc.ssh.ssh_config.v"), sec))
        Builtins.y2debug("section %1 contains: %2", sec, cont)
        if (sec == "*" || sec == hostname) &&
            Builtins.contains(cont, "GSSAPIAuthentication") &&
              Builtins.contains(cont, "GSSAPIDelegateCredentials")
          @ssh_support = SCR.Read(
            Builtins.add(
              Builtins.add(path(".etc.ssh.ssh_config.v"), sec),
              "GSSAPIAuthentication"
            )
          ) == "yes" &&
            SCR.Read(
              Builtins.add(
                Builtins.add(path(".etc.ssh.ssh_config.v"), sec),
                "GSSAPIDelegateCredentials"
              )
            ) == "yes"
          @ssh_section = sec
        end
      end
      @ssh_support = false if @ssh_support == nil

      @sssd = Pam.Enabled("sss")

      if @sssd && FileUtils.Exists("/etc/sssd/sssd.conf")
        # read kerberos settings from sssd.conf (if available)
        @default_realm = ReadSSSDValue("krb5_realm", @default_realm)
        @kdc = ReadSSSDValue("krb5_kdcip", @kdc)
        Ops.set(
          @ExpertSettings,
          "ccache_dir",
          ReadSSSDValue(
            "krb5_ccachedir",
            Ops.get_string(@ExpertSettings, "ccache_dir", "")
          )
        )
        Ops.set(
          @ExpertSettings,
          "ccname_template",
          ReadSSSDValue(
            "krb5_ccname_template",
            Ops.get_string(@ExpertSettings, "ccname_template", "")
          )
        )
        Ops.set(
          @ExpertSettings,
          "keytab",
          ReadSSSDValue(
            "krb5_keytab",
            Ops.get_string(@ExpertSettings, "keytab", "")
          )
        )
        @renew_lifetime = ReadSSSDValue(
          "krb5_renewable_lifetime",
          @renew_lifetime
        )
        @ticket_lifetime = ReadSSSDValue("krb5_lifetime", @ticket_lifetime)
        Ops.set(
          @ExpertSettings,
          "validate",
          Builtins.tolower(
            ReadSSSDValue(
              "krb5_validate",
              Ops.get_string(@ExpertSettings, "validate", "")
            )
          )
        )
      end
      true
    end

### - (`Object`) ReadFile(path_to_value, def_value)

Deprecated.

Deprecated variant to ReadKrb5ConfValue

    233
    234
    235
    236
    237
    238
    # File '../../src/modules/Kerberos.rb', line 233

    def ReadFile(path_to_value, def_value)
      Builtins.y2warning(
        "This function is deprecated, use ReadKrb5ConfValue instead."
      )
      ReadKrb5ConfValue(path_to_value, def_value)
    end

### - (`String`) ReadKrb5ConfValue(path_to_value, def_value)

Reads the item value from the /etc/krb5.conf via ini agent If the item doesn't exist, returns the default value

Parameters:

- path_to_value (`Yast::Path`) —

  path for agent (.etc.krb5_conf)

- def_value (`String`) —

  default value for the key (path)

Returns:

- (`String`) —

  the value

    226
    227
    228
    229
    # File '../../src/modules/Kerberos.rb', line 226

    def ReadKrb5ConfValue(path_to_value, def_value)
      vals = ReadKrb5ConfValues(path_to_value, def_value)
      Ops.get_string(vals, 0, def_value)
    end

### - (`Array`) ReadKrb5ConfValues(path_to_value, def_value)

Reads the item values from the /etc/krb5.conf via ini agent If the item doesn't exist, returns the default value

Parameters:

- path_to_value (`Yast::Path`) —

  path for agent (.etc.krb5_conf)

- def_value (`String`) —

  default value for the key (path)

Returns:

- (`Array`) —

  string the values for given key

    211
    212
    213
    214
    215
    216
    217
    218
    219
    # File '../../src/modules/Kerberos.rb', line 211

    def ReadKrb5ConfValues(path_to_value, def_value)
      value = Convert.convert(
        SCR.Read(path_to_value),
        :from => "any",
        :to   => "list <string>"
      )
      value = [def_value] if value == nil
      deep_copy(value)
    end

### - (`Object`) ReadSSSDValue(key, default_value)

Read given value from /etc/sssd/sssd.conf

Parameters:

- default_value (`String`) —

  default, if not found in the file

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

    def ReadSSSDValue(key, default_value)
      ret = default_value
      val = Convert.to_string(
        SCR.Read(
          Builtins.add(
            Builtins.add(path(".etc.sssd_conf.v"), "domain/default"),
            key
          )
        )
      )
      ret = val if val != nil
      ret
    end

### - (`Object`) RequiredPackages

Return the list of packages for kerberos configuration

    1031
    1032
    1033
    1034
    1035
    1036
    # File '../../src/modules/Kerberos.rb', line 1031

    def RequiredPackages
      pkgs = deep_copy(@required_packages)
      # do not install pam_krb5 if sssd is configured
      pkgs = Builtins.filter(pkgs) { |p| p != "pam_krb5" } if @sssd
      deep_copy(pkgs)
    end

### - (`Object`) ShortSummary

Create a short textual summary

Returns:

- summary of the current configuration

    986
    987
    988
    989
    990
    991
    992
    993
    994
    995
    996
    997
    998
    999
    1000
    1001
    1002
    1003
    1004
    1005
    1006
    1007
    1008
    1009
    1010
    1011
    1012
    1013
    1014
    1015
    1016
    1017
    1018
    1019
    1020
    1021
    1022
    1023
    1024
    1025
    1026
    1027
    1028
    # File '../../src/modules/Kerberos.rb', line 986

    def ShortSummary
      summary = ""
      nc = Summary.NotConfigured
      # summary text, %1 is value
      summary = Ops.add(
        Ops.add(
          Ops.add(
            Builtins.sformat(
              _("<b>KDC Server</b>: %1<br>"),
              @kdc != "" ? @kdc : nc
            ),
            # summary text, %1 is value
            Builtins.sformat(
              _("<b>Default Domain</b>: %1<br>"),
              @default_domain != "" ? @default_domain : nc
            )
          ),
          # summary text, %1 is value
          Builtins.sformat(
            _("<b>Default Realm</b>: %1<br>"),
            @default_realm != "" ? @default_realm : nc
          )
        ),
        # summary text (yes/no follows)
        Builtins.sformat(
          _("<b>Kerberos Authentication Enabled</b>: %1"),
          @use_pam_krb ?
            # summary value
            _("Yes") :
            # summary value
            _("No")
        )
      )
      if @dns_used
        # summary line
        summary = Ops.add(
          Ops.add(summary, "<br>"),
          _("Configuration Acquired via DNS")
        )
      end

      summary
    end

### - (`Object`) Summary

Create a textual summary

Returns:

- summary of the current configuration

    944
    945
    946
    947
    948
    949
    950
    951
    952
    953
    954
    955
    956
    957
    958
    959
    960
    961
    962
    963
    964
    965
    966
    967
    968
    969
    970
    971
    972
    973
    974
    975
    976
    977
    978
    979
    980
    981
    982
    # File '../../src/modules/Kerberos.rb', line 944

    def Summary
      summary = ""
      nc = Summary.NotConfigured
      # summary header
      summary = Summary.AddHeader(summary, _("PAM Login"))

      # summary item
      summary = Summary.AddLine(
        summary,
        @use_pam_krb ?
          _("Use Kerberos") :
          # summary item
          _("Do Not Use Kerberos")
      )

      # summary header
      summary = Summary.AddHeader(summary, _("Default Realm"))
      summary = Summary.AddLine(
        summary,
        @default_realm != "" ? @default_realm : nc
      )

      # summary header
      summary = Summary.AddHeader(summary, _("Default Domain"))
      summary = Summary.AddLine(
        summary,
        @default_domain != "" ? @default_domain : nc
      )

      # summary header
      summary = Summary.AddHeader(summary, _("KDC Server Address"))
      summary = Summary.AddLine(summary, @kdc != "" ? @kdc : nc)

      # summary header
      summary = Summary.AddHeader(summary, _("Clock Skew"))
      summary = Summary.AddLine(summary, @clockskew != "" ? @clockskew : nc)

      [summary, []]
    end

### - (`Object`) ValidateTimeEntries(key, val)

Validation function for time-related values

    1046
    1047
    1048
    1049
    1050
    1051
    1052
    1053
    1054
    1055
    1056
    1057
    1058
    1059
    # File '../../src/modules/Kerberos.rb', line 1046

    def ValidateTimeEntries(key, val)
      if !Builtins.regexpmatch(val, "^([0-9]+)[dmh]$") &&
          !Builtins.regexpmatch(val, "^([0-9]+)$")
        if key == "clockskew"
          # error popup (wrong format of entered value)
          Report.Error(_("Clock skew is invalid.\nTry again.\n"))
        else
          # error popup (wrong format of entered value)
          Report.Error(_("Lifetime is invalid.\nTry again."))
        end
        return false
      end
      true
    end

### - (`Object`) Write

Saves Kerberos configuration. (No parameters because it is too short to abort)

Returns:

- true on success

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

    def Write
      pam_installed = false
      ret = true

      # dialog caption
      caption = _("Saving Kerberos Client Configuration")

      no_stages = 3
      stages = [
        # progress stage label
        _("Write PAM settings"),
        # progress stage label
        _("Write Kerberos client settings"),
        # progress stage label
        _("Write OpenSSH settings")
      ]
      steps = [
        # progress step label
        _("Writing PAM settings..."),
        # progress step label
        _("Writing Kerberos client settings..."),
        # progress step label
        _("Writing OpenSSH settings..."),
        # final progress step label
        _("Finished")
      ]
      if @packages != []
        # progress stage label
        stages = Builtins.prepend(stages, _("Install required packages"))
        # progress step label
        steps = Builtins.prepend(steps, _("Installing required packages..."))
        no_stages = Ops.add(no_stages, 1)
      end

      Progress.New(caption, " ", no_stages, stages, steps, "")

      if @packages != []
        Builtins.y2debug("packages to install: %1", @packages)
        Progress.NextStage
        to_install = []
        # check if packages are avialable...
        Builtins.foreach(@packages) do |p|
          if Package.Available(p) == true
            to_install = Builtins.add(to_install, p)
          end
        end
        Package.DoInstallAndRemove(to_install, [])

        @packages = []
      end

      Progress.NextStage

      # -- pam settings
      if @pam_modified || @write_only
        # whem sssd is configured, do not use pam_krb5 and update sssd.conf
        # fate#308902
        if @sssd
          Builtins.y2milestone("not using pam_krb5 because sssd is configured")
          Pam.Remove("krb5")
        elsif @use_pam_krb
          Pam.Add("krb5")
          # If ldap is configured we need to change it to ldap-account_only
          Pam.Add("ldap-account_only") if Pam.Enabled("ldap")
          if @ignore_unknown
            Pam.Add("krb5-ignore_unknown_principals")
          else
            Pam.Remove("krb5-ignore_unknown_principals")
          end
        else
          # if ldap-account_only is used we need to change it to ldap
          Pam.Add("ldap") if Pam.Enabled("ldap-account_only")
          Pam.Remove("krb5")
        end
      end

      # -- write to /etc/krb5.conf
      Progress.NextStage

      if @modified && !@dns_used
        # change the default realm name
        WriteKrb5ConfValue(
          path(".etc.krb5_conf.v.libdefaults.default_realm"),
          @default_realm
        )

        # write the mapping domain-realm
        if @default_domain != ""
          domain = @default_domain
          if Builtins.findfirstof(domain, ".") != 0
            domain = Ops.add(".", domain)
          end
          WriteKrb5ConfValue(
            Builtins.add(path(".etc.krb5_conf.v.domain_realm"), domain),
            @default_realm
          )
        end

        WriteKrb5ConfValue(
          path(".etc.krb5_conf.v.libdefaults.clockskew"),
          @clockskew
        )

        if Builtins.contains(SCR.Dir(path(".etc.krb5_conf.s")), @default_realm)
          # update the default realm settings
          WriteKrb5ConfValuesAsString(
            Builtins.add(
              Builtins.add(path(".etc.krb5_conf.v"), @default_realm),
              "kdc"
            ),
            @kdc
          )
          if @default_domain != "" && @default_domain != nil
            WriteKrb5ConfValue(
              Builtins.add(
                Builtins.add(path(".etc.krb5_conf.v"), @default_realm),
                "default_domain"
              ),
              @default_domain
            )
          end
          if @admin_server == ""
            # save only when the entry was mising or same as KDC
            WriteKrb5ConfValuesAsString(
              Builtins.add(
                Builtins.add(path(".etc.krb5_conf.v"), @default_realm),
                "admin_server"
              ),
              @kdc
            )
          end
        elsif @default_realm != ""
          # specify the type of this subsection
          SCR.Write(
            Builtins.add(path(".etc.krb5_conf.st.realms"), @default_realm),
            [1]
          )
          # write the settings of the new default realm
          WriteKrb5ConfValuesAsString(
            Builtins.add(
              Builtins.add(path(".etc.krb5_conf.v.realms"), @default_realm),
              "kdc"
            ),
            @kdc
          )
          if @default_domain != "" && @default_domain != nil
            WriteKrb5ConfValue(
              Builtins.add(
                Builtins.add(path(".etc.krb5_conf.v.realms"), @default_realm),
                "default_domain"
              ),
              @default_domain
            )
          end
          if @admin_server == ""
            WriteKrb5ConfValuesAsString(
              Builtins.add(
                Builtins.add(path(".etc.krb5_conf.v.realms"), @default_realm),
                "admin_server"
              ),
              @kdc
            )
          end
        end
      end
      if @modified
        WriteSSSD() if @sssd

        #     3. Yes, if the user chooses DNS you need to remove the domain_realm
        #     section (so that the domain->realm mapping can be read through DNS)
        #     and at least the complete sub-section describing the realm
        #     (maybe even the whole [realms]-section).
        if @dns_used
          Builtins.y2milestone(
            "DNS set to use: removing domain info from krb5.conf"
          )
          WriteKrb5ConfValue(path(".etc.krb5_conf.s.domain_realm"), nil)
          WriteKrb5ConfValue(
            Builtins.add(path(".etc.krb5_conf.s"), @default_realm),
            nil
          )
          # write the default realm name
          WriteKrb5ConfValue(
            path(".etc.krb5_conf.v.libdefaults.default_realm"),
            @default_realm
          )
        end

        # write advanced settings
        pam_sect = path(".etc.krb5_conf.v.pam")
        if !Builtins.contains(SCR.Dir(path(".etc.krb5_conf.s")), "pam")
          # specify the type of new subsection
          SCR.Write(path(".etc.krb5_conf.st.appdefaults.pam"), [1])
          pam_sect = path(".etc.krb5_conf.v.appdefaults.pam")
        end

        WriteKrb5ConfValue(
          Builtins.add(pam_sect, "ticket_lifetime"),
          @ticket_lifetime
        )
        WriteKrb5ConfValue(
          Builtins.add(pam_sect, "renew_lifetime"),
          @renew_lifetime
        )
        WriteKrb5ConfValue(Builtins.add(pam_sect, "forwardable"), @forwardable)
        WriteKrb5ConfValue(Builtins.add(pam_sect, "proxiable"), @proxiable)
        WriteKrb5ConfValue(Builtins.add(pam_sect, "minimum_uid"), @minimum_uid)

        Builtins.foreach(@ExpertSettings) do |key, value|
          pth = Builtins.add(pam_sect, key)
          if Ops.is_boolean?(value)
            WriteKrb5ConfValue(pth, value == true ? "true" : "false")
            next
          end
          # rest is string
          if value != ""
            WriteKrb5ConfValue(pth, Convert.to_string(value))
          # removin
          elsif Ops.get_string(@OrigExpertSettings, key, "") != ""
            WriteKrb5ConfValue(pth, nil)
          end
        end

        if @trusted_servers != "" &&
            Package.Installed("krb5-plugin-preauth-pkinit-nss")
          pkinit_sect = path(".etc.krb5_conf.v.pkinit")
          if !Builtins.contains(SCR.Dir(path(".etc.krb5_conf.s")), "pkinit")
            SCR.Write(path(".etc.krb5_conf.st.appdefaults.pkinit"), [1])
            pkinit_sect = path(".etc.krb5_conf.v.appdefaults.pkinit")
          end
          WriteKrb5ConfValue(
            Builtins.add(pkinit_sect, "trusted_servers"),
            @trusted_servers
          )
          if FileUtils.Exists("/etc/pam_pkcs11/pam_pkcs11.conf")
            SCR.Write(
              Builtins.add(
                Builtins.add(
                  path(".etc.pam_pkcs11_conf.v.pam_pkcs11"),
                  "mapper ms"
                ),
                "domainname"
              ),
              @default_realm
            )
            SCR.Write(
              Builtins.add(
                Builtins.add(
                  path(".etc.pam_pkcs11_conf.v.pam_pkcs11"),
                  "mapper ms"
                ),
                "domainnickname"
              ),
              @default_domain
            )
            SCR.Write(path(".etc.pam_pkcs11_conf"), nil)
          end
        end

        # write the changes now
        SCR.Write(path(".etc.krb5_conf"), nil)

        # unmount agent; otherwise it won't be available to read new created
        # sections (it will treat DEFAULT_REALM as a subsection of [realms])
        SCR.UnmountAgent(path(".etc.krb5_conf"))
      end

      # -- write openssh settings
      Progress.NextStage

      if @ssh_modified
        write = @ssh_support ? "yes" : "no"
        SCR.Write(
          Builtins.add(
            Builtins.add(path(".etc.ssh.ssh_config.v"), @ssh_section),
            "GSSAPIAuthentication"
          ),
          write
        )
        SCR.Write(
          Builtins.add(
            Builtins.add(path(".etc.ssh.ssh_config.v"), @ssh_section),
            "GSSAPIDelegateCredentials"
          ),
          write
        )
        SCR.Write(path(".etc.ssh.ssh_config"), nil)
        Builtins.y2milestone("/etc/ssh/ssh_config modified")
      end

      # final stage
      Progress.NextStage

      ret
    end

### - (`Object`) WriteFile(path_to_value, value)

Deprecated.

Deprecated variant to WriteKrb5ConfValue

    271
    272
    273
    274
    275
    276
    # File '../../src/modules/Kerberos.rb', line 271

    def WriteFile(path_to_value, value)
      Builtins.y2warning(
        "This function is deprecated, use WriteKrb5ConfValue instead."
      )
      WriteKrb5ConfValue(path_to_value, value)
    end

### - (`Object`) WriteKrb5ConfValue(path_to_value, value)

Write the item value to /etc/krb5.conf Do not write anything for empty and nil values

Parameters:

- path_to_value (`Yast::Path`) —

  path for agent (.etc.krb5_conf)

- value (`String`)

Returns:

- false when nothing was written, success of write otherwise

    264
    265
    266
    267
    # File '../../src/modules/Kerberos.rb', line 264

    def WriteKrb5ConfValue(path_to_value, value)
      return SCR.Write(path_to_value, nil) if value == nil || value == ""
      WriteKrb5ConfValues(path_to_value, [value])
    end

### - (`Object`) WriteKrb5ConfValues(path_to_value, values)

Write list of values for given key to /etc/krb5.conf Do not write anything for empty and nil values

Parameters:

- path_to_value (`Yast::Path`) —

  path for agent (.etc.krb5_conf)

- value

Returns:

- false when nothing was written, success of write otherwise

    245
    246
    247
    248
    249
    # File '../../src/modules/Kerberos.rb', line 245

    def WriteKrb5ConfValues(path_to_value, values)
      values = deep_copy(values)
      return SCR.Write(path_to_value, nil) if values == nil || values == []
      SCR.Write(path_to_value, values)
    end

### - (`Object`) WriteKrb5ConfValuesAsString(path_to_value, values)

Write (possible) multiple values of given key to /etc/krb5.conf

Parameters:

- values (`String`) —

  values separated by spaces

    253
    254
    255
    256
    257
    258
    # File '../../src/modules/Kerberos.rb', line 253

    def WriteKrb5ConfValuesAsString(path_to_value, values)
      WriteKrb5ConfValues(
        path_to_value,
        Builtins.filter(Builtins.splitstring(values, " \t")) { |val| val != "" }
      )
    end

### - (`Object`) WriteSSSD

Write Kerberos related settings to sssd.conf

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

    def WriteSSSD
      Builtins.y2milestone("updating sssd.conf with new kerberos values")

      domain = Builtins.add(path(".etc.sssd_conf.v"), "domain/default")

      SCR.Write(Builtins.add(domain, "auth_provider"), "krb5")
      SCR.Write(Builtins.add(domain, "chpass_provider"), "krb5")
      SCR.Write(Builtins.add(domain, "krb5_realm"), @default_realm)
      # divide by commas: krb5_kdcip = kdcserver1, kdcserver2 (bnc#729174)
      krb5_kdcip = Builtins.mergestring(Builtins.splitstring(@kdc, " "), ",")
      SCR.Write(Builtins.add(domain, "krb5_kdcip"), krb5_kdcip)

      # write expert settings (bnc#778513)
      SCR.Write(
        Builtins.add(domain, "krb5_ccachedir"),
        Ops.get_string(@ExpertSettings, "ccache_dir", "") == "" ?
          nil :
          Ops.get_string(@ExpertSettings, "ccache_dir", "")
      )
      SCR.Write(
        Builtins.add(domain, "krb5_ccname_template"),
        Ops.get_string(@ExpertSettings, "ccname_template", "") == "" ?
          nil :
          Ops.get_string(@ExpertSettings, "ccname_template", "")
      )
      SCR.Write(
        Builtins.add(domain, "krb5_validate"),
        Ops.get_string(@ExpertSettings, "validate", "") == "true" ? "True" : "False"
      )
      SCR.Write(
        Builtins.add(domain, "krb5_keytab"),
        Ops.get_string(@ExpertSettings, "keytab", "") == "" ?
          nil :
          Ops.get_string(@ExpertSettings, "keytab", "")
      )
      SCR.Write(
        Builtins.add(domain, "krb5_renewable_lifetime"),
        @renew_lifetime
      )
      SCR.Write(Builtins.add(domain, "krb5_lifetime"), @ticket_lifetime)

      ret = SCR.Write(path(".etc.sssd_conf"), nil)
      Builtins.y2error("error writing sssd.conf file") if !ret
      ret
    end