Module: Yast::InetdRoutinesInclude

Defined in:
../../src/include/inetd/routines.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) AddNotInstalled(netd_conf, table_data)

  • This function merges real xinetd configuration (read by agent) and

  • available services packages generated for SuSE distribution

  • This function is automaticaly calld by CreateTableData() if Inetd::configured_service

  • is `xinetd.

  • Adds those from default_conf that do not have a matching

  • service in the working config.

  • @param netd_conf not used in this function, but used for

  • isServiceMatchPresent call.

  • @param table_data Table data structure used as source data

  • @return list New table data



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File '../../src/include/inetd/routines.rb', line 163

def AddNotInstalled(netd_conf, table_data)
  netd_conf = deep_copy(netd_conf)
  table_data = deep_copy(table_data)
  #y2milestone("in function mergeXinetdConfs()");

  defaults = deep_copy(Inetd.default_conf)

  index = 0
  Builtins.foreach(defaults) do |line|
    if !isServiceMatchPresent(netd_conf, line)
      index = Ops.add(index, 1)
      entry = ServiceToTableItem(line, index)
      table_data = Builtins.add(table_data, entry)
    end
  end
  deep_copy(table_data)
end

- (Array) CreateLocalGroupsList

Read group names from group It does not get the NIS entries. "+" is filtered out.

Returns:

  • (Array)

    groups



340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File '../../src/include/inetd/routines.rb', line 340

def CreateLocalGroupsList
  groups = Convert.convert(
    Builtins.merge(
      UsersCache.GetGroupnames("local"),
      UsersCache.GetGroupnames("system")
    ),
    :from => "list",
    :to   => "list <string>"
  )
  groups = Builtins.sort(groups)
  Builtins.y2debug("groups: %1", groups)

  groups = Builtins.add(groups, _("--default--"))

  deep_copy(groups)
end

- (Array) CreateLocalUsersList

Read user names from passwd. It does not get the NIS entries. "+" is filtered out.

Returns:

  • (Array)

    users



320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File '../../src/include/inetd/routines.rb', line 320

def CreateLocalUsersList
  users = Convert.convert(
    Builtins.merge(
      UsersCache.GetUsernames("local"),
      UsersCache.GetUsernames("system")
    ),
    :from => "list",
    :to   => "list <string>"
  )
  users = Builtins.sort(users)
  Builtins.y2debug("users: %1", users)

  users = Builtins.add(users, _("--default--"))
  deep_copy(users)
end

- (Object) CreateTableData(netd_conf)

Converts configuration format from agent to table data structures

Parameters:

  • netd_conf (Array<Hash{String => Object>})

    netd_conf handles whole configuration of configured service

Returns:

  • returnes table data



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
# File '../../src/include/inetd/routines.rb', line 286

def CreateTableData(netd_conf)
  netd_conf = deep_copy(netd_conf)
  table_input = []

  Builtins.foreach(netd_conf) do |service|
    # service must be marked as nondeleted ("deleted" == false or "deleted" not exists)
    if !Ops.get_boolean(service, "deleted", false)
      entry = ServiceToTableItem(service, nil)
      # add line to table structure
      table_input = Builtins.add(table_input, entry)
    end
  end

  # now can do it for both superservers
  # ... not yet
  # because in the system data, we do not have the "package" field

  table_input = AddNotInstalled(netd_conf, table_input)

  # table_input = find out which are installed
  # but that would require a better data model.
  # let's try doing with the current one.

  # OK, let's start with sorting the data by the service name
  # term field '2' is the service name
  table_input = SortTableData(table_input, 3)

  deep_copy(table_input)
end

- (Object) GetServerBasename(server, server_args)

Used for cpmparisons whether the servers match: If server is /usr/sbin/tcpd, consider server_args instead. Then take the firse word (strips arguments or the parenthesized pkg name). Then take the last slash-delimited component. For sparse matching: nil is returned if server is nil (or if server args is nil AND is needed)

Parameters:

  • server (String)

    “server” field of a service

  • server_args (String)

    “server_args” field of a service

Returns:

  • basename of the real server



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File '../../src/include/inetd/routines.rb', line 80

def GetServerBasename(server, server_args)
  result = server
  # discard tcpd
  result = server_args if result == "/usr/sbin/tcpd"
  # check nil
  if result != nil
    # program only
    result = String.FirstChunk(result, " \t")
    # basename
    comp = Builtins.splitstring(result, "/")
    result = Ops.get(comp, Ops.subtract(Builtins.size(comp), 1), "")
  end
  result
end

- (Object) initialize_inetd_routines(include_target)



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File '../../src/include/inetd/routines.rb', line 33

def initialize_inetd_routines(include_target)
  Yast.import "UI"

  textdomain "inetd"

  Yast.import "Inetd"
  Yast.import "Progress"
  Yast.import "Service"
  Yast.import "Popup"
  Yast.import "Package"
  Yast.import "UsersCache"
  Yast.import "String"

  # Cache for {#IsInstalled.}
  @is_installed_cache = {}
end

- (Object) IsAnyServiceEnabled(ready_conf)

Find any service to be enabled If no found, return `no

Parameters:

  • ready_conf (Array<Hash{String => Object>})

    ready_conf handles whole service configuration (Inetd::netd_conf)

Returns:

  • returnes if found yes, otherwiseno



361
362
363
364
365
366
367
368
369
370
371
# File '../../src/include/inetd/routines.rb', line 361

def IsAnyServiceEnabled(ready_conf)
  ready_conf = deep_copy(ready_conf)
  ret = :no

  Builtins.foreach(ready_conf) do |line|
    if Ops.get_boolean(line, "deleted", false) == false
      ret = :yes if Ops.get_boolean(line, "enabled", false) != false
    end
  end
  ret
end

- (Object) IsInstalled(rpm)



401
402
403
404
405
406
407
408
409
# File '../../src/include/inetd/routines.rb', line 401

def IsInstalled(rpm)
  result = rpm == "" ? true : Ops.get(@is_installed_cache, rpm)
  if result == nil
    result = Package.Installed(rpm)
    @is_installed_cache = Builtins.add(@is_installed_cache, rpm, result)
  end
  Builtins.y2debug("%1: %2", rpm, result)
  result
end

- (Object) IsInstalledClearCache

Clears cache for #IsInstalled . This is too wasteful. Later, when it works, optimize for single packages.



396
397
398
399
400
# File '../../src/include/inetd/routines.rb', line 396

def IsInstalledClearCache
  @is_installed_cache = {}

  nil
end

- (Object) isServiceMatchPresent(netd_conf, s)

Determine, if service package is installed. This function requires full configuration (like Inetd::netd_conf) and standalone map with service. Linear complexity (in the working config)

Parameters:

  • netd_conf (Array<Hash{String => Object>})

    Full configuration

  • s (Hash{String => Object})

    a #service

Returns:

  • match found



144
145
146
147
148
149
# File '../../src/include/inetd/routines.rb', line 144

def isServiceMatchPresent(netd_conf, s)
  netd_conf = deep_copy(netd_conf)
  s = deep_copy(s)
  match = Builtins.find(netd_conf) { |i| ServicesMatch(i, s) }
  match != nil
end

- (Object) PollAbort

Check for pending Abort press

Returns:

  • true if pending abort



52
53
54
# File '../../src/include/inetd/routines.rb', line 52

def PollAbort
  UI.PollInput == :abort
end

- (Object) ProgressNextStage(title)

Progress::NextStage and Progress::Title combined into one function

Parameters:

  • title (String)

    progressbar title



64
65
66
67
68
69
# File '../../src/include/inetd/routines.rb', line 64

def ProgressNextStage(title)
  Progress.NextStage
  Progress.Title(title)

  nil
end

- (Object) ReallyAbort

If modified, ask for confirmation

Returns:

  • true if abort is confirmed



58
59
60
# File '../../src/include/inetd/routines.rb', line 58

def ReallyAbort
  !Inetd.Modified || Popup.ReallyAbort(true)
end

- (Object) ServicesMatch(a, b)



372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File '../../src/include/inetd/routines.rb', line 372

def ServicesMatch(a, b)
  a = deep_copy(a)
  b = deep_copy(b)
  if struct_match_sparse(a, b, ["script", "service", "protocol"])
    # Compare whether the server matches
    # Watch out for tcpd, use basenames
    # because the 8.2 UI produced server="in.ftpd (ftpd)"
    a_serverbn = GetServerBasename(
      Ops.get_string(a, "server"),
      Ops.get_string(a, "server_args")
    )
    b_serverbn = GetServerBasename(
      Ops.get_string(b, "server"),
      Ops.get_string(b, "server_args")
    )
    if a_serverbn == nil || b_serverbn == nil || a_serverbn == b_serverbn
      return true
    end
  end
  false
end

- (Object) ServiceToTableItem(service, ni_index)



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
# File '../../src/include/inetd/routines.rb', line 180

def ServiceToTableItem(service, ni_index)
  service = deep_copy(service)
  Builtins.y2debug("* %1", Ops.get_string(service, "service", ""))
  status_text = ""
  wait_text = ""

  # determine service is enabled (enabled text)
  changed_text = Ops.get_boolean(service, "changed", false) ? "X" : ""
  if Ops.get_boolean(service, "enabled", true)
    # Translators: Service status: On = running, --- = stopped
    status_text = _("On")
  else
    # Translators: This string you can leave unchanged
    status_text = _("---")
  end

  # HACK:
  # our data structures kinda suck, so we have no quick way of determining
  # what package a service belongs to.
  # But IsInstalled returns true for "" so we don't get to install an
  # unknown package.
  if !IsInstalled(Ops.get_string(service, "package", ""))
    # Translators: This is used for status "Not Installed".
    #    Please, make the
    #    translation as short as possible.
    status_text = _("NI")
  end

  # determine wait mode (convert to string)
  if Ops.get_boolean(service, "wait", true)
    wait_text = _("Yes")
  else
    wait_text = _("No")
  end
  sname = Ops.get_string(service, "service", "")
  rpc_ver = Ops.get_string(service, "rpc_version", "")
  sname = Ops.add(Ops.add(sname, "/"), rpc_ver) if rpc_ver != ""
  user_group = Ops.get_string(service, "group", "")
  if user_group == ""
    user_group = Ops.get_string(service, "user", "")
  else
    # TODO switch to ":" as separator
    user_group = Ops.add(
      Ops.add(Ops.get_string(service, "user", ""), "."),
      user_group
    )
  end
  # create line for table structure
  entry = Item(
    Id(
      ni_index == nil ?
        Ops.get_string(service, "iid", "0") :
        Ops.add("NI", ni_index)
    ),
    changed_text,
    status_text,
    sname,
    Ops.get_string(service, "socket_type", ""),
    Ops.get_string(service, "protocol", ""),
    wait_text,
    user_group,
    Ops.get_string(service, "server", ""),
    Ops.get_string(service, "server_args", "")
  )
  deep_copy(entry)
end

- (Array<Yast::Term>) SortTableData(unsorted_terms, sort_by)

Sorts items for table of xinetd services

Parameters:

  • unsorted_terms (Array<Yast::Term>)

Returns:

  • (Array<Yast::Term>)

    sorted_terms



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
# File '../../src/include/inetd/routines.rb', line 251

def SortTableData(unsorted_terms, sort_by)
  unsorted_terms = deep_copy(unsorted_terms)
  sorted_terms = []

  # string as the service name
  # list of integers of position in unsorted list (the same service name can exist twice or more)
  helper_sorting_map = {}
  position = 0
  service_name = ""
  Builtins.foreach(unsorted_terms) do |item|
    service_name = Ops.get_string(item, sort_by, "")
    Ops.set(
      helper_sorting_map,
      service_name,
      Builtins.add(Ops.get(helper_sorting_map, service_name, []), position)
    )
    position = Ops.add(position, 1)
  end

  # map is sorted by the string service name by defualt
  Builtins.foreach(helper_sorting_map) do |service_name2, term_ids|
    Builtins.foreach(term_ids) do |term_id|
      sorted_terms = Builtins.add(
        sorted_terms,
        Ops.get(unsorted_terms, term_id) { Item("") }
      )
    end
  end

  deep_copy(sorted_terms)
end

- (Object) struct_match(a, b, fields)

Considers the maps as structs and tests some of their fields for equality (conjunctively, short circuit).

Parameters:

  • a (Hash)

    one struct

  • b (Hash)

    other struct

  • fields (Array)

    list of keys

Returns:

  • Do the maps have all the named fields equal?



101
102
103
104
105
106
107
108
109
110
111
# File '../../src/include/inetd/routines.rb', line 101

def struct_match(a, b, fields)
  a = deep_copy(a)
  b = deep_copy(b)
  fields = deep_copy(fields)
  # short circuit: use the _find_ builtin to get the mismatching key
  mismatch = Builtins.find(fields) do |key|
    Ops.get(a, key) != Ops.get(b, key)
  end
  # mismatch is nil => they match
  mismatch == nil
end

- (Object) struct_match_sparse(a, b, fields)

Considers the maps as structs and tests some of their fields for equality (conjunctively, short circuit). If a key is missing in either of the maps, it is considered as matching. <p> Used when merging autoyast items, to match only those fields that are specified in the profile. There, only one map is sparse. (the profile map)

Examples:

match: $[“a”: 1, “b”: 2, “c”: 3], $[“b”: 2, “d”: 4]

Parameters:

  • a (Hash)

    one struct

  • b (Hash)

    other struct

  • fields (Array)

    list of keys

Returns:

  • Do the maps have all named fields that are in both of them equal?



124
125
126
127
128
129
130
131
132
133
134
135
# File '../../src/include/inetd/routines.rb', line 124

def struct_match_sparse(a, b, fields)
  a = deep_copy(a)
  b = deep_copy(b)
  fields = deep_copy(fields)
  # short circuit: use the _find_ builtin to get the mismatching key
  mismatch = Builtins.find(fields) do |key|
    !(Ops.get(a, key) == Ops.get(b, key) || !Builtins.haskey(a, key) ||
      !Builtins.haskey(b, key))
  end
  # mismatch is nil => they match
  mismatch == nil
end