Class: Yast::NsswitchClass

Inherits:
Module
  • Object
show all
Defined in:
src/modules/Nsswitch.rb

Instance Method Summary collapse

Instance Method Details

#mainObject


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

def main

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

#ReadDb(db) ⇒ Object

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

#WriteObject

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

#WriteAutofs(start, source) ⇒ Object

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

#WriteDb(db, entries) ⇒ Object

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