Module: Yast::SambaClientRoutinesInclude

Defined in:
../../src/include/samba-client/routines.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) AskForSharesRemoval

ask user if existing shares should be removed

Returns:

  • true for removing



351
352
353
354
355
356
357
358
359
360
361
362
363
# File '../../src/include/samba-client/routines.rb', line 351

def AskForSharesRemoval
  !Popup.AnyQuestion(
    Popup.NoHeadline,
    # popup question
    _("User shares already exist.  Keep or delete these shares?"),
    # button label
    _("&Keep"),
    # button label
    _("&Delete"),
    :focus_yes
  ) 
  # FIXME details
end

- (Symbol) AskJoinDomain(workgroup, status)

Allow to join a domain. Uses result of #CheckWorkgroup to inform the user about the status.

Parameters:

  • workgroup (String)

    the workgroup to be joined

  • status (Symbol)

    domain status returned by CheckWorkgroup

Returns:

  • (Symbol)

    ok on successful join (workgroup is always successful), fail on error or user cancel `nojoin if user don't want to join



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
# File '../../src/include/samba-client/routines.rb', line 289

def AskJoinDomain(workgroup, status)
  # for autoyast, skip testing
  return :ok if Mode.config

  return :ok if status == :workgroup || status == :joined_domain

  res = false

  # popup question, the domain status cannot be found out, ask user what to do
  dont_know = _(
    "Cannot automatically determine if this host\nis a member of the domain %1."
  )
  # popup question, first part
  not_member = _("This host is not a member\nof the domain %1.")
  # last part of popup question
  join_q = Ops.add(
    "\n\n",
    Builtins.sformat(_("Join the domain %1?"), workgroup)
  )

  if SambaNetJoin.ClusterPresent(false)
    dont_know = _(
      "Cannot automatically determine if this cluster\nis a member of the domain %1."
    )
    not_member = _("This cluster is not a member\nof the domain %1.")
  end

  # allow to join the domain
  if status == :domain
    # we don't know the domain status
    res = Popup.YesNo(
      Ops.add(Builtins.sformat(dont_know, workgroup), join_q)
    )
  elsif status == :not_joined_domain
    res = Popup.YesNo(
      Ops.add(Builtins.sformat(not_member, workgroup), join_q)
    )
  end

  return :nojoin if !res
  JoinDomain(workgroup)
end

- (Object) AskToStopServices

check if services should be stopped: only if there are more sections in smb.conf and if user confirms (bug #143908)

Returns:

  • true if smb+nmb should be stopped



368
369
370
371
372
373
374
375
376
377
# File '../../src/include/samba-client/routines.rb', line 368

def AskToStopServices
  return false if Service.Status("nmb") != 0 && Service.Status("smb") != 0

  return true if Ops.less_than(Builtins.size(SambaConfig.GetShares), 1)

  # yes/no popup
  Popup.YesNo(
    _("Other Windows sharing services are available. Stop them as well?")
  )
end

- (Symbol) CheckWorkgroup(workgroup)

Check, if the workgroup is a domain or a workgroup. Uses caching to avoid long checks of a workgroup members.

Parameters:

  • workgroup (String)

    the workgroup to be checked

Returns:

  • (Symbol)

    type of the workgroup: joined_domain,not_joined_domain, workgroup ordomain if it is a domain, but the status is not known



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
# File '../../src/include/samba-client/routines.rb', line 168

def CheckWorkgroup(workgroup)
  # for autoyast, skip testing
  return :workgroup if Mode.config

  ret = nil

  # translators: text for busy pop-up
  Popup.ShowFeedback("", _("Verifying workgroup membership..."))

  if SambaNmbLookup.IsDomain(workgroup) || SambaAD.ADS != ""
    # handle domain joining
    res = SambaNetJoin.Test(workgroup)
    # we the host is already in domain, continue
    if res == true
      ret = :joined_domain
    elsif res != nil
      ret = :not_joined_domain
    else
      ret = :domain
    end
  else
    ret = :workgroup
  end
  Popup.ClearFeedback
  Builtins.y2debug("Check workgroup result: %1", ret)
  ret
end

- (Object) DHCPSupportHelp

return the help text for DHCP support



410
411
412
413
414
415
# File '../../src/include/samba-client/routines.rb', line 410

def DHCPSupportHelp
  # help text ("Retrieve WINS server via DHCP" is a checkbox label)
  _(
    "<p>Check <b>Retrieve WINS server via DHCP</b> to use a WINS server provided by DHCP.</p>"
  )
end

- (Object) DHCPSupportTerm(dhcp_support)

return the term with DHCP support check box

Parameters:

  • dhcp_support (Boolean)

    current value of DHCP support in smb.conf



402
403
404
405
406
407
# File '../../src/include/samba-client/routines.rb', line 402

def DHCPSupportTerm(dhcp_support)
  # check box label
  Left(
    CheckBox(Id(:dhcp), _("Retrieve WINS server via &DHCP"), dhcp_support)
  )
end

- (Object) GetSharesTerm(allow, group, max)

return the term with shares settings

Parameters:

  • allow (Boolean)

    if shares are allowed

  • group (String)

    name of group owning the shares dir

  • max (Fixnum)

    maximum number of allowed shares



492
493
494
495
496
497
# File '../../src/include/samba-client/routines.rb', line 492

def GetSharesTerm(allow, group, max)
  Builtins.y2warning("GetSharesTerm is obsolete, use SharesTerm instead")
  SharesTerm(
    { "allow_share" => allow, "shares_group" => group, "max_shares" => max }
  )
end

- (Object) HostsResolutionHelp

Return help text for hosts resolution term



393
394
395
396
397
398
# File '../../src/include/samba-client/routines.rb', line 393

def HostsResolutionHelp
  # help text for "Use WINS for Hostname Resolution" check box label
  _(
    "<p>If you want to use Microsoft Windows Internet Name Service (WINS) for name resolution, check <b>Use WINS for Hostname Resolution</b>.</p>"
  )
end

- (Object) HostsResolutionTerm(hosts_resolution)

return the term with hosts resolution support check box (fate#300971)

Parameters:

  • hosts_resolution (Boolean)

    current value of hosts resolution in nsswitch.conf



381
382
383
384
385
386
387
388
389
390
# File '../../src/include/samba-client/routines.rb', line 381

def HostsResolutionTerm(hosts_resolution)
  # check box label
  Left(
    CheckBox(
      Id(:hosts_resolution),
      _("&Use WINS for Hostname Resolution"),
      hosts_resolution
    )
  )
end

- (Object) initialize_samba_client_routines(include_target)



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File '../../src/include/samba-client/routines.rb', line 30

def initialize_samba_client_routines(include_target)
  Yast.import "UI"

  textdomain "samba-client"

  Yast.import "FileUtils"
  Yast.import "Mode"
  Yast.import "Label"
  Yast.import "Stage"
  Yast.import "Popup"
  Yast.import "Service"
  Yast.import "String"

  Yast.import "Samba"
  Yast.import "SambaConfig"
  Yast.import "SambaNetJoin"
  Yast.import "SambaNmbLookup"
  Yast.import "SambaAD"
end

- (Object) JoinDomain(workgroup)



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
# File '../../src/include/samba-client/routines.rb', line 225

def JoinDomain(workgroup)
  cluster_info = ""
  if SambaNetJoin.ClusterPresent(false)
    # additional information for cluster environment
    cluster_info = _(
      "The configuration will be propagated across cluster nodes."
    )
  end

  # popup to fill in the domain joining info; %1 is the domain name
  passwd = passwordUserPopup(
    Ops.add(
      Ops.add(
        Ops.add(
          Builtins.sformat(
            _(
              "Enter the username and the password for joining the domain %1."
            ),
            workgroup
          ),
          "\n\n"
        ),
        _("To join the domain anonymously, leave the text entries empty.\n")
      ),
      cluster_info
    ),
    "Administrator",
    workgroup,
    :join
  )

  # cancelled the domain joining
  return :fail if passwd == nil
  # try to join the domain
  error = SambaNetJoin.Join(
    workgroup,
    "member",
    Ops.get(passwd, "user"),
    Ops.get(passwd, "password", ""),
    Ops.get(passwd, "machine")
  )

  if error != nil
    Popup.Error(error)
    return :fail
  end
  # Translators: Information popup, %1 is the name of the domain
  Popup.Message(
    Builtins.sformat(
      _("Domain %1 joined successfully."),
      Samba.GetWorkgroup
    )
  )
  :ok
end

- (Object) KerberosMethodHelp

return help for Kerberos Method



538
539
540
541
542
543
# File '../../src/include/samba-client/routines.rb', line 538

def KerberosMethodHelp
  # help text for kerberos method option
  _(
    "<p>The value of <b>Kerberos Method</b> defines how kerberos tickets are verified. When <b>Single Sing-on for SSH</b> is used, the default Kerberos Method set by YaST is <tt>secrets and keytab</tt>. See smb.conf manual page for details.</p>"
  )
end

- (Object) LeaveDomain(workgroup)

Leave an AD domain



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
# File '../../src/include/samba-client/routines.rb', line 197

def LeaveDomain(workgroup)
  # popup to fill in the domain leaving info; %1 is the domain name
  passwd = passwordUserPopup(
    Builtins.sformat(
      _("Enter the username and the password for leaving the domain %1."),
      workgroup
    ),
    "Administrator",
    workgroup,
    :leave
  )

  # cancelled the domain leaving
  return :fail if passwd == nil
  # try to join the domain
  error = SambaNetJoin.Leave(
    workgroup,
    Ops.get(passwd, "user"),
    Ops.get(passwd, "password", "")
  )

  if error != nil
    Popup.Error(error)
    return :fail
  end
  :ok
end

- (Object) PAMMountHelp

return the help text for PAM Mount table



523
524
525
526
527
528
529
530
531
532
533
534
535
# File '../../src/include/samba-client/routines.rb', line 523

def PAMMountHelp
  # help text for PAM Mount table
  _(
    "<p>In the table <b>Mount Server Directories</b>, you can specify server\n" +
      "directories (such as home directory) which should be locally mounted when the\n" +
      "user is logged in. If mounting should be user-specific, specify <b>User\n" +
      "Name</b> for the selected rule. Otherwise, the directory is mounted for each user. For more information, see pam_mount.conf manual page.</p>"
  ) +
    # help text for PAM Mount table: example
    _(
      "<p>For example, you may use <tt>/home/%(DOMAIN_USER)</tt> value for <b>Remote Path</b>, <tt>~/</tt> value for <b>Local Mount Point</b> to mount the home directory, together with a value <tt>user=%(DOMAIN_USER)</tt> as a part of <b>Options</b>.</p>"
    )
end

- (Hash{String => String}) passwordUserPopup(message, defaultuser, domain, what)

Allow user to type in a user/password pair in a popup.

Parameters:

  • message (String)

    a text to be displayed above the password text entry

  • defaultuser (String)

    a pre-filled user name

Returns:

  • (Hash{String => String})

    $[“user”: string, “password”: string] with information provided by the user or nil on cancel



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
# File '../../src/include/samba-client/routines.rb', line 56

def passwordUserPopup(message, defaultuser, domain, what)
  machine_term = Empty()
  default_id = "default_entry"
  # default value of Machine Account
  default_entry = Item(Id(default_id), _("(default)"))
  if SambaAD.ADS != "" && what != :leave
    machines = [default_entry]
    machine_term = HBox(
      ReplacePoint(
        Id(:rpcombo),
        Left(
          ComboBox(
            Id(:machines),
            Opt(:hstretch),
            # combo box label
            _("&Machine Account OU"),
            machines
          )
        )
      ),
      VBox(Label(""), PushButton(Id(:acquire), _("O&btain list")))
    )
  end
  UI.OpenDialog(
    Opt(:decorated),
    HBox(
      HSpacing(0.7),
      VBox(
        HSpacing(25),
        VSpacing(0.2),
        Left(Label(message)),
        # text entry label
        InputField(Id(:user), Opt(:hstretch), _("&Username"), defaultuser),
        Password(Id(:passwd), Opt(:hstretch), Label.Password),
        machine_term,
        VSpacing(0.2),
        ButtonBox(
          PushButton(Id(:ok), Opt(:default), Label.OKButton),
          PushButton(Id(:cancel), Label.CancelButton)
        ),
        VSpacing(0.2)
      ),
      HSpacing(0.7)
    )
  )

  if SambaAD.ADS != "" && what != :leave
    UI.ChangeWidget(Id(:machines), :Enabled, false)
  end
  UI.SetFocus(Id(:passwd))
  ret = nil
  user = ""
  pass = ""
  while true
    ret = UI.UserInput
    user = Convert.to_string(UI.QueryWidget(Id(:user), :Value))
    pass = Convert.to_string(UI.QueryWidget(Id(:passwd), :Value))

    break if ret == :ok || ret == :cancel
    if ret == :acquire
      if user == "" || pass == ""
        # error popup
        Popup.Error(
          _(
            "User name and password are required\nfor listing the machine accounts."
          )
        )
        next
      end
      machines = SambaAD.GetMachines(domain, user, pass)
      if machines != nil
        items = Builtins.maplist(Builtins.sort(machines)) do |m|
          Item(Id(m), m)
        end
        items = Builtins.prepend(items, default_entry)
        UI.ReplaceWidget(
          Id(:rpcombo),
          Left(
            ComboBox(
              Id(:machines),
              Opt(:hstretch),
              _("&Machine Account"),
              items
            )
          )
        )
        UI.ChangeWidget(Id(:machines), :Enabled, true)
      end
    end
  end

  result = ret == :ok ? { "user" => user, "password" => pass } : nil
  if SambaAD.ADS != "" && ret == :ok && what != :leave
    machine = Convert.to_string(UI.QueryWidget(Id(:machines), :Value))
    Ops.set(result, "machine", machine) if machine != default_id
  end
  UI.CloseDialog

  deep_copy(result)
end

- (Object) ReallyAbort

If modified, ask for confirmation

Returns:

  • true if abort is confirmed



159
160
161
# File '../../src/include/samba-client/routines.rb', line 159

def ReallyAbort
  Samba.GetModified || Stage.cont ? Popup.ReallyAbort(true) : true
end

- (Object) SharesExist(share_dir)

Check if user shares already exist

Parameters:

  • path

    to directory with shares



335
336
337
338
339
340
341
342
343
344
345
346
347
# File '../../src/include/samba-client/routines.rb', line 335

def SharesExist(share_dir)
  return false if !FileUtils.Exists(share_dir)
  out = Convert.to_map(
    SCR.Execute(
      path(".target.bash_output"),
      Builtins.sformat("/usr/bin/find %1 -type f | wc -l", share_dir)
    )
  )
  count = Builtins.tointeger(
    String.FirstChunk(Ops.get_string(out, "stdout", "0"), "\n")
  )
  count != nil && Ops.greater_than(count, 0)
end

- (Object) SharesHelp

return the help text for shares



500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# File '../../src/include/samba-client/routines.rb', line 500

def SharesHelp
  Ops.add(
    Ops.add(
      # membership dialog help (common part 3/4), %1 is separator (e.g. '\')
      Builtins.sformat(
        _(
          "<p><b>Allow Users to Share Their Directories</b> enables members of the group in <b>Permitted Group</b> to share directories they own with other users. For example, <tt>users</tt> for a local scope or <tt>DOMAIN%1Users</tt> for a domain scope.  The user also must make sure that the file system permissions allow access.</p>"
        ),
        Samba.shares_separator
      ),
      # membership dialog help (common part 3/4)
      _(
        "<p>With <b>Maximum Number of Shares</b>, limit the total amount of shares that may be created.</p>"
      )
    ),
    # membership dialog help common part
    _(
      "<p>To permit access to user shares without authentication, enable <b>Allow Guest Access</b>.</p>"
    )
  )
end

- (Object) SharesTerm(settings)

return the term with shares settings

Parameters:

  • settings (Hash)

    map with parameters to show in term



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
# File '../../src/include/samba-client/routines.rb', line 419

def SharesTerm(settings)
  settings = deep_copy(settings)
  allow = Ops.get_boolean(settings, "allow_share", false)
  group = Ops.get_string(
    settings,
    "group",
    Ops.get_string(settings, "shares_group", "")
  )
  max = Ops.get_integer(settings, "max_shares", 100)
  guest = Ops.get_boolean(settings, "guest_access", false)

  # frame label
  label = true ?
    _("Sharing by Users") :
    # frame label
    _("Sharing")
  VBox(
    VSpacing(0.4),
    # frame label
    Frame(
      label,
      VBox(
        VSpacing(0.4),
        Left(
          CheckBox(
            Id(:share_ch),
            Opt(:notify),
            # checkbox label
            _("&Allow Users to Share Their Directories"),
            allow
          )
        ),
        Builtins.haskey(settings, "guest_access") ?
          Left(
            CheckBox(
              Id(:guest_ch),
              Opt(:notify),
              # checkbox label
              _("Allow &Guest Access"),
              guest
            )
          ) :
          VSpacing(0),
        HBox(
          HSpacing(2),
          VBox(
            # texty entry label
            InputField(
              Id(:group),
              Opt(:hstretch),
              _("&Permitted Group"),
              group
            ),
            # infield label
            IntField(
              Id(:max_shares),
              _("&Maximum Number of Shares"),
              1,
              99999,
              max
            )
          )
        ),
        VSpacing(0.2)
      )
    )
  )
end