Class List Method List File List

# Class: Yast::NsswitchClass

Inherits:
  Module
  - Object
  - Module
  - Yast::NsswitchClass
  show all
Defined in:
  ../../src/modules/Nsswitch.rb

## Instance Method Summary (collapse)

- - (Object) main
- - (Object) ReadDb(db)

  Reads a database entry from nsswitch_conf and returns it as a list.

- - (Object) Write

  Writes the edited files to the disk.

- - (Object) WriteAutofs(start, source)

  Configures the name service switch for autofs according to chosen settings.

- - (Object) WriteDb(db, entries)

  Writes a database entry as a list to nsswitch_conf.

## Instance Method Details

### - (`Object`) main

    33
    34
    35
    36
    37
    # File '../../src/modules/Nsswitch.rb', line 33

    def main

      Yast.import "Message"
      Yast.import "Report"
    end

### - (`Object`) ReadDb(db)

Reads a database entry from nsswitch_conf and returns it as a list

Parameters:

- db (`String`) —

  eg. “passwd”

    42
    43
    44
    45
    46
    47
    48
    # File '../../src/modules/Nsswitch.rb', line 42

    def ReadDb(db)
      db_s = Convert.to_string(
        SCR.Read(Builtins.add(path(".etc.nsswitch_conf"), db))
      )
      db_s = "" if db_s == nil
      Builtins.filter(Builtins.splitstring(db_s, " \t")) { |s| s != "" }
    end

### - (`Object`) Write

Writes the edited files to the disk

Returns:

- true on success

    94
    95
    96
    # File '../../src/modules/Nsswitch.rb', line 94

    def Write
      SCR.Write(path(".etc.nsswitch_conf"), nil)
    end

### - (`Object`) WriteAutofs(start, source)

Configures the name service switch for autofs according to chosen settings

Parameters:

- start (`Boolean`) —

  autofs and service (ldap/nis) should be started

- source (`String`) —

  for automounter data (ldap/nis)

Returns:

- success?

    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    # File '../../src/modules/Nsswitch.rb', line 69

    def WriteAutofs(start, source)
      ok = true

      # nsswitch automount:
      # bracket options not allowed, order does not matter
      automount_l = ReadDb("automount")
      enabled = Builtins.contains(automount_l, source)
      # enable it if it is not enabled yet and both services run
      if start && !enabled
        automount_l = Builtins.add(automount_l, source)
        ok = WriteDb("automount", automount_l)
        ok = ok && SCR.Write(path(".etc.nsswitch_conf"), nil)
      # disable it if it is enabled and either service does not run
      elsif !start && enabled
        automount_l = Builtins.filter(automount_l) { |s| s != source }
        ok = WriteDb("automount", automount_l)
        ok = ok && SCR.Write(path(".etc.nsswitch_conf"), nil)
      end

      Report.Error(Message.ErrorWritingFile("/etc/nsswitch.conf")) if !ok
      ok
    end

### - (`Object`) WriteDb(db, entries)

Writes a database entry as a list to nsswitch_conf

Parameters:

- db (`String`) —

  eg. “passwd”

- entries (`Array<String>`) —

  eg. [“files”, “nis”]

Returns:

- success?

    55
    56
    57
    58
    59
    60
    61
    62
    63
    # File '../../src/modules/Nsswitch.rb', line 55

    def WriteDb(db, entries)
      entries = deep_copy(entries)
      # if there are no entries, delete the key using nil
      entry = Builtins.mergestring(entries, " ")
      SCR.Write(
        Builtins.add(path(".etc.nsswitch_conf"), db),
        entry == "" ? nil : entry
      )
    end