Class: Yast::SambaClass

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) AdjustSharesServices(write_only)

adjust the services for sharing



564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
# File '../../src/modules/Samba.rb', line 564

def AdjustSharesServices(write_only)
  if Ops.greater_than(GetMaxShares(), 0)
    Builtins.foreach(["nmb", "smb"]) do |service|
      Service.Enable(service)
      if !write_only
        if Service.Status(service) == 0
          Service.Restart(service)
        else
          Service.Start(service)
        end
      end
    end
  elsif @stop_services
    Service.Disable("nmb")
    Service.Disable("smb")
    if !write_only
      Service.Stop("nmb")
      Service.Stop("smb")
    end
  end
  true
end

- (Hash) AutoPackages

Return required packages for auto-installation

Returns:

  • (Hash)

    of packages to be installed and to be removed



1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
# File '../../src/modules/Samba.rb', line 1153

def AutoPackages
  to_install = ["samba-client", "samba-winbind", "pam_mount"]
  if SambaAD.ADS != ""
    to_install = Convert.convert(
      Builtins.union(to_install, ["krb5", "krb5-client"]),
      :from => "list",
      :to   => "list <string>"
    )
  end
  { "install" => to_install, "remove" => [] }
end

- (Hash) Export

Dump the samba-client settings to a single map (For use by autoinstallation.)

Returns:

  • (Hash)

    Dumped settings (later acceptable by Import ())



1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
# File '../../src/modules/Samba.rb', line 1006

def Export
  return {} if !@globals_configured
  ret = { "winbind" => @winbind_enabled }
  Ops.set(ret, "mkhomedir", @mkhomedir) if @mkhomedir_modified

  if @shares_modified && @shares_group != ""
    Ops.set(ret, "shares_group", @shares_group)
  end

  if @disable_dhcp_hostname
    Ops.set(ret, "disable_dhcp_hostname", @disable_dhcp_hostname)
  end

  Builtins.foreach(
    Convert.convert(SambaConfig.Export, :from => "any", :to => "list <map>")
  ) do |sect|
    name = Ops.get_string(sect, "name", "")
    Ops.set(ret, name, Ops.get_map(sect, "parameters", {}))
  end

  if SambaAD.ADS != ""
    Ops.set(ret, "active_directory", { "kdc" => SambaAD.ADS })
  end
  # export user & password to "join" map
  joinmap = {}
  Builtins.foreach(@password_data) do |key, val|
    Ops.set(joinmap, key, val) if val != nil && val != ""
  end
  Ops.set(ret, "join", joinmap) if joinmap != {}
  @modified = false
  deep_copy(ret)
end

- (Object) GetDHCP

Check if dhcp.conf is included in smb.conf



315
316
317
318
# File '../../src/modules/Samba.rb', line 315

def GetDHCP
  include_list = SambaConfig.GlobalGetList("include", [])
  Builtins.contains(include_list, @dhcp_path)
end

- (Object) GetGuessAccess

check if shares guest access is allowed



340
341
342
# File '../../src/modules/Samba.rb', line 340

def GetGuessAccess
  SambaConfig.GlobalGetTruth("usershare allow guests", false)
end

- (Object) GetHostsResolution

Read /etc/nsswitch.conf and check if WINS is used for hosts resolution



282
283
284
285
286
287
288
289
# File '../../src/modules/Samba.rb', line 282

def GetHostsResolution
  if @hosts_resolution == nil
    @hosts_db = Nsswitch.ReadDb("hosts")
    @hosts_resolution = Builtins.contains(@hosts_db, "wins")
    @hosts_resolution_orig = @hosts_resolution
  end
  @hosts_resolution
end

- (Object) GetMaxShares

get number of max shares from smb.conf; 0 mean shares are not enabled



277
278
279
# File '../../src/modules/Samba.rb', line 277

def GetMaxShares
  SambaConfig.GlobalGetInteger("usershare max shares", 0)
end

- (Object) GetModified

Data was modified?

Returns:

  • true if modified



155
156
157
158
159
160
# File '../../src/modules/Samba.rb', line 155

def GetModified
  Builtins.y2debug("modified=%1", @modified)
  @modified || @mkhomedir_modified || @shares_modified ||
    SambaConfig.GetModified || @ssh_modified ||
    PAMMountModified()
end

- (Object) GetPAMMountVolumes

Return the list of 'volume' entries from pam_mount.conf.xml



187
188
189
# File '../../src/modules/Samba.rb', line 187

def GetPAMMountVolumes
  deep_copy(@pam_mount_volumes)
end

- (Object) GetSSHSupport

Get the current status of ssh single-sign-on support



466
467
468
# File '../../src/modules/Samba.rb', line 466

def GetSSHSupport
  @ssh_support
end

- (Boolean) GetWinbind

Get a winbind status

Returns:

  • (Boolean)

    d a winbind status



1147
1148
1149
# File '../../src/modules/Samba.rb', line 1147

def GetWinbind
  @winbind_enabled
end

- (Object) GetWinbindCaching

Get the current status of winbind caching



389
390
391
392
393
# File '../../src/modules/Samba.rb', line 389

def GetWinbindCaching
  cached = SambaConfig.WinbindGlobalGetStr("cached_login", "")
  offline = SambaConfig.GlobalGetStr("winbind offline logon", "")
  cached == "yes" && offline == "yes"
end

- (String) GetWorkgroup

Get a host workgroup

Returns:

  • (String)

    a new workgroup



1131
1132
1133
# File '../../src/modules/Samba.rb', line 1131

def GetWorkgroup
  SambaConfig.GlobalGetStr("workgroup", "")
end

- (Object) GetWorkgroupOrRealm



1135
1136
1137
1138
1139
1140
1141
# File '../../src/modules/Samba.rb', line 1135

def GetWorkgroupOrRealm
  workgroup = SambaConfig.GlobalGetStr("workgroup", "")
  if Builtins.toupper(SambaConfig.GlobalGetStr("security", "")) == "ADS"
    return SambaConfig.GlobalGetStr("realm", workgroup)
  end
  workgroup
end

- (Boolean) Import(settings)

Get all samba-client settings from the first parameter (For use by autoinstallation.)

Parameters:

  • settings (Hash)

    The YCP structure to be imported.

Returns:

  • (Boolean)

    True on success



936
937
938
939
940
941
942
943
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
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
# File '../../src/modules/Samba.rb', line 936

def Import(settings)
  settings = deep_copy(settings)
  @globals_configured = false
  globals = Ops.get_map(settings, "global", {})
  sections = []

  Builtins.foreach(
    Convert.convert(settings, :from => "map", :to => "map <string, any>")
  ) do |key, value|
    # handle special keys separately
    if key == "shares_group"
      @shares_group = Ops.get_string(
        settings,
        "shares_group",
        @shares_group
      )
    elsif key == "active_directory"
      SambaAD.SetADS(
        Ops.get_string(settings, ["active_directory", "kdc"], "")
      )
    elsif key == "join"
      @password_data = Ops.get_map(settings, "join", {})
    elsif key == "mkhomedir"
      SetMkHomeDir(Ops.get_boolean(settings, "mkhomedir", @mkhomedir))
    elsif key == "disable_dhcp_hostname"
      @disable_dhcp_hostname = Ops.get_boolean(
        settings,
        "disable_dhcp_hostname",
        @disable_dhcp_hostname
      )
    elsif key != "winbind" && Ops.is_map?(value)
      # form a section to import SambaConfig
      sections = Builtins.add(
        sections,
        { "name" => key, "parameters" => value }
      )
    end
  end

  # call this _after_ evaluation if AD is used
  winbind = Ops.get_boolean(
    settings,
    "winbind",
    Ops.get_boolean(settings, ["global", "winbind"], false)
  )
  SetWinbind(winbind) if winbind != nil

  SambaConfig.Import(sections) if sections != []

  # explicitely adapt some variables based on 'globals' section
  if globals != {}
    if Builtins.haskey(globals, "usershare_max_shares") ||
        Builtins.haskey(settings, "shares_group")
      SetShares(
        Builtins.tointeger(
          Ops.get_string(globals, "usershare_max_shares", "0")
        ),
        Ops.get_string(settings, "shares_group", @shares_group)
      )
    end
    @globals_configured = true
  end
  @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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File '../../src/modules/Samba.rb', line 35

def main
  textdomain "samba-client"

  Yast.import "Autologin"
  Yast.import "FileUtils"
  Yast.import "NetworkConfig"
  Yast.import "Mode"
  Yast.import "Nsswitch"
  Yast.import "Package"
  Yast.import "Pam"
  Yast.import "Progress"
  Yast.import "Report"
  Yast.import "Service"
  Yast.import "SambaAD"
  Yast.import "SambaConfig"
  Yast.import "SambaWinbind"
  Yast.import "SambaNetJoin"
  Yast.import "SambaNmbLookup"
  Yast.import "String"
  Yast.import "Summary"
  Yast.import "SuSEFirewall"


  # Data was modified?
  @modified = false

  # Are globals already configured (for AutoYaST)
  @globals_configured = false

  # Write only, used during autoinstallation.
  # Don't run services and SuSEconfig, it's all done at one place.
  @write_only = false

  # Should be winbind enabled?
  @winbind_enabled = false

  # If FAM should be started
  @start_fam = true

  # if pam_mkhomedir is set in /etc/pam.d/commond-session
  @mkhomedir = false

  # if it mkhomedir was modified
  @mkhomedir_modified = false

  # if shares config (actually group owner) was modified
  @shares_modified = false

  # map with user name and password (used for autoinstallation only)
  @password_data = {}

  # dir with user shares
  @shares_dir = "/var/lib/samba/usershares"

  # path to config file with DHCP settings
  @dhcp_path = "/etc/samba/dhcp.conf"

  # if existing shares should be removed
  @remove_shares = false

  # if smb + nmb services should be stopped
  @stop_services = false

  @shares_group = "users"

  @shares_separator = "\\"

  # remember if the last join was succesful
  @in_domain = nil

  # if changing hostname by DHCP should be disabled (#169260)
  @disable_dhcp_hostname = false

  # support for SSH single-sign-on (fate #303415)
  @ssh_support = false

  # initial status of single-sign-on suport in ssh_config
  @ssh_was_enabled = false

  # initial status of single-sign-on suport in sshd_config
  @sshd_was_enabled = false

  # if it ssh support was modified
  @ssh_modified = false

  # section in /etc/ssh/ssh_config file for storing single-sign-on settings
  @ssh_section = "*"

  # if hosts are resolved via WINS
  @hosts_resolution = nil

  # host line of nsswitch.conf
  @hosts_db = []

  # original value of hosts_resolution, for detecting changes
  @hosts_resolution_orig = false

  # path to pam_mount.conf.xml
  @pam_mount_path = "/etc/security/pam_mount.conf.xml"

  # the volume data from pam_mount.conf.xml
  @pam_mount_volumes = []

  # original value of pam_mount_volumes, for detecting changes
  @pam_mount_volumes_orig = nil

  # network configuration (to be read from NetworkConfig module)
  @network_setup = NetworkConfig.Export
end

- (Object) PAMMountModified



145
146
147
148
149
150
# File '../../src/modules/Samba.rb', line 145

def PAMMountModified
  @pam_mount_volumes_orig == nil && @pam_mount_volumes != [] ||
    @pam_mount_volumes_orig != nil &&
      Builtins.sort(@pam_mount_volumes) !=
        Builtins.sort(@pam_mount_volumes_orig)
end

- (Object) Read

Read all samba-client settings

Returns:

  • true on success



619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
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
# File '../../src/modules/Samba.rb', line 619

def Read
  # Samba-client read dialog caption
  caption = _("Initializing Samba Client Configuration")

  steps = 2

  # We do not set help text here, because it was set outside
  Progress.New(
    caption,
    " ",
    steps,
    [
      # translators: progress stage 1/2
      _("Read the global Samba settings"),
      # translators: progress stage 2/2
      _("Read the winbind status")
    ],
    [
      # translators: progress step 1/2
      _("Reading the global Samba settings..."),
      # translators: progress step 2/2
      _("Reading the winbind status..."),
      # translators: progress finished
      _("Finished")
    ],
    ""
  )

  # read global settings
  Progress.NextStage

  SambaConfig.Read(false)

  # read winbind status
  Progress.NextStage
  @winbind_enabled = SambaWinbind.IsEnabled

  # start nmbstatus in background
  SambaNmbLookup.Start if !Mode.test

  ReadMkHomeDir()

  ReadSharesSetting()

  GetHostsResolution()

  ReadSSHSupport()

  Autologin.Read

  # read network settings
  # (for bug 169260: do not allow DHCP to change the hostname)
  NetworkConfig.Read
  @network_setup = NetworkConfig.Export

  SuSEFirewall.Read

  ReadPAMMount()

  # ensure nmbd is restarted if stopped for lookup
  SambaNmbLookup.checkNmbstatus if !Mode.test

  # finished
  Progress.NextStage
  @globals_configured = true
  @modified = false
  true
end

- (Object) ReadMkHomeDir

Read the state of mkhomedir in /etc/pam.d/common-session (bug #143519)



255
256
257
258
# File '../../src/modules/Samba.rb', line 255

def ReadMkHomeDir
  @mkhomedir = Pam.Enabled("mkhomedir")
  @mkhomedir
end

- (Object) ReadPAMMount

Read the data from /etc/security/pam_mount.conf.xml regarding mounting user's home directories



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File '../../src/modules/Samba.rb', line 164

def ReadPAMMount
  if !FileUtils.Exists(@pam_mount_path)
    Builtins.y2warning("%1 does not exist", @pam_mount_path)
    return false
  end
  # initially, parse the whole file and let the agent build data map
  if SCR.Read(path(".pam_mount"), @pam_mount_path) != true
    Builtins.y2warning("reading %1 failed", @pam_mount_path)
    return false
  end

  @pam_mount_volumes = Convert.convert(
    SCR.Read(path(".pam_mount.get"), { "element" => "volume" }),
    :from => "any",
    :to   => "list <map>"
  )
  @pam_mount_volumes = [] if @pam_mount_volumes == nil

  @pam_mount_volumes_orig = deep_copy(@pam_mount_volumes)
  true
end

- (Object) ReadSharesSetting

Read user shares settings



351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File '../../src/modules/Samba.rb', line 351

def ReadSharesSetting
  @shares_dir = SambaConfig.GlobalGetStr("usershare path", @shares_dir)
  if @shares_dir != nil && FileUtils.Exists(@shares_dir)
    stat = Convert.to_map(SCR.Read(path(".target.stat"), @shares_dir))
    out = Convert.to_map(
      SCR.Execute(
        path(".target.bash_output"),
        Builtins.sformat(
          "getent group | grep \":%1:\" | /usr/bin/cut -f 1 -d :",
          Ops.get_integer(stat, "gid", 100)
        )
      )
    )
    @shares_group = String.FirstChunk(
      Ops.get_string(out, "stdout", ""),
      "\n"
    )
  end
  @shares_separator = SambaConfig.GlobalGetStr("winbind separator", "\\")

  nil
end

- (Object) ReadSSHSupport

Read the current status of ssh single-sign-on support (fate #303415)



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

def ReadSSHSupport
  ssh = nil
  sshd = false

  if FileUtils.Exists("/etc/ssh/ssh_config") &&
      FileUtils.Exists("/etc/ssh/sshd_config")
    hostname = "*"
    out = Convert.to_map(
      SCR.Execute(path(".target.bash_output"), "LANG=C /bin/hostname")
    )
    if Ops.get(out, "stderr") == ""
      hostname = Builtins.deletechars(
        Ops.get_string(out, "stdout", ""),
        "\n"
      )
    end
    Builtins.foreach(SCR.Dir(path(".etc.ssh.ssh_config.s"))) do |sec|
      next if ssh != 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 = 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
    sshd = true
    Builtins.foreach(
      [
        "GSSAPIAuthentication",
        "GSSAPICleanupCredentials",
        "ChallengeResponseAuthentication",
        "UsePAM"
      ]
    ) do |key|
      sshd = sshd &&
        Builtins.contains(
          Convert.to_list(
            SCR.Read(Builtins.add(path(".etc.ssh.sshd_config"), key))
          ),
          "yes"
        )
    end
  end
  @ssh_was_enabled = ssh == true
  @sshd_was_enabled = sshd
  @ssh_support = @ssh_was_enabled && @sshd_was_enabled
  @ssh_support
end

- (Object) SetDHCP(new)

Set the support of DHCP (include dhcp.conf in smb.conf)

Returns:

  • if status was changed



322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File '../../src/modules/Samba.rb', line 322

def SetDHCP(new)
  include_list = SambaConfig.GlobalGetList("include", [])
  if new && !Builtins.contains(include_list, @dhcp_path)
    include_list = Convert.convert(
      Builtins.union(include_list, [@dhcp_path]),
      :from => "list",
      :to   => "list <string>"
    )
  elsif !new && Builtins.contains(include_list, @dhcp_path)
    include_list = Builtins.filter(include_list) { |i| i != @dhcp_path }
  else
    return false
  end
  SambaConfig.GlobalSetList("include", include_list)
  true
end

- (Object) SetGuessAccess(guest)

Set the new value for guest access (#144787)



345
346
347
348
# File '../../src/modules/Samba.rb', line 345

def SetGuessAccess(guest)
  SambaConfig.GlobalSetTruth("usershare allow guests", guest)
  true
end

- (Object) SetHostsResolution(resolve)

Set the new value for hosts resolution



292
293
294
295
# File '../../src/modules/Samba.rb', line 292

def SetHostsResolution(resolve)
  @hosts_resolution = resolve
  true
end

- (Object) SetMkHomeDir(new_value)

Set the new value of mkhomedir



268
269
270
271
272
273
274
# File '../../src/modules/Samba.rb', line 268

def SetMkHomeDir(new_value)
  if @mkhomedir != new_value
    @mkhomedir_modified = true
    @mkhomedir = new_value
  end
  @mkhomedir
end

- (Object) SetPAMMountVolumes(new_volumes)

Set the new list of 'volume' entries



192
193
194
195
196
197
# File '../../src/modules/Samba.rb', line 192

def SetPAMMountVolumes(new_volumes)
  new_volumes = deep_copy(new_volumes)
  @pam_mount_volumes = deep_copy(new_volumes)

  nil
end

- (Object) SetShares(max, group)

set the new values for user shares

Parameters:

  • max (Fixnum)

    maximum number of shares (0 is for disabling)

  • group (String)

    permited group



377
378
379
380
381
382
383
384
385
386
# File '../../src/modules/Samba.rb', line 377

def SetShares(max, group)
  SambaConfig.GlobalSetStr(
    "usershare max shares",
    Ops.greater_than(max, 0) ? max : nil
  )

  @shares_modified = true if @shares_group != group
  @shares_group = group
  true
end

- (Object) SetSSHSupport(enable)

Set the new value for sh single-sign-on support



471
472
473
474
475
476
477
478
479
480
481
# File '../../src/modules/Samba.rb', line 471

def SetSSHSupport(enable)
  @ssh_support = enable
  @ssh_modified = enable != (@ssh_was_enabled && @sshd_was_enabled)
  kerberos_method = SambaConfig.GlobalGetStr("kerberos method", "")
  # bnc#673982, use "secrets and keytab" as default (=when not set otherwise)
  if @ssh_support && kerberos_method == ""
    kerberos_method = "secrets and keytab"
    SambaConfig.GlobalSetStr("kerberos method", kerberos_method)
  end
  enable
end

- (Object) SetStartFAM(fam)

update the information if FAM should be started

Returns:

  • current fam status



1167
1168
1169
1170
1171
1172
1173
# File '../../src/modules/Samba.rb', line 1167

def SetStartFAM(fam)
  if fam != @start_fam
    @start_fam = fam
    @modified = true
  end
  @start_fam
end

- (Object) SetWinbind(status)

Set a windind status

Parameters:

  • group

    a new winbind status



691
692
693
694
695
696
697
698
699
700
# File '../../src/modules/Samba.rb', line 691

def SetWinbind(status)
  if status != @winbind_enabled
    @modified = true
    @winbind_enabled = status
  end
  SambaAD.AdjustSambaConfig(status)
  SambaWinbind.AdjustSambaConfig(status)

  nil
end

- (Object) SetWinbindCaching(enable)

Set the new value for winbind caching (see bug #143927)



396
397
398
399
400
# File '../../src/modules/Samba.rb', line 396

def SetWinbindCaching(enable)
  SambaConfig.WinbindGlobalSetStr("cached_login", enable ? "yes" : nil)
  SambaConfig.GlobalSetStr("winbind offline logon", enable ? "yes" : nil)
  enable
end

- (Object) SetWorkgroup(group)

Set a host workgroup

Parameters:

  • group (String)

    a new workgroup



1122
1123
1124
1125
1126
# File '../../src/modules/Samba.rb', line 1122

def SetWorkgroup(group)
  SambaConfig.GlobalSetStr("workgroup", group)

  nil
end

- (Object) ShortSummary

Create shorter textual summary and a list of unconfigured options

Returns:

  • summary of the current configuration



1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
# File '../../src/modules/Samba.rb', line 1091

def ShortSummary
  summary = ""
  workgroup = SambaConfig.GlobalGetStr("workgroup", "")

  if @globals_configured
    # summary item: configured workgroup
    summary = Ops.add(
      Builtins.sformat(
        _("<p><b>Workgroup or Domain</b>: %1</p>"),
        workgroup
      ),
      # summary item: authentication using winbind
      Builtins.sformat(
        _("<p><b>Authentication with SMB</b>: %1</p>"),
        # translators: winbind status in summary
        @winbind_enabled ?
          _("Yes") :
          # translators: winbind status in summary
          _("No")
      )
    )
  else
    summary = Summary.NotConfigured
  end
  summary
end

- (Object) Summary

Create a textual summary and a list of unconfigured options

Returns:

  • summary of the current configuration



1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
# File '../../src/modules/Samba.rb', line 1041

def Summary
  summary = ""
  nc = Summary.NotConfigured
  workgroup = SambaConfig.GlobalGetStr("workgroup", "")

  # summary header
  summary = Summary.AddHeader(summary, _("Global Configuration"))

  if @globals_configured
    summary = Summary.AddLine(
      summary,
      Builtins.sformat(
        # autoyast summary item: configured workgroup
        _("Workgroup or Domain: %1"),
        workgroup
      )
    )

    if @mkhomedir
      summary = Summary.AddLine(
        summary,
        # autoyast summary item
        _("Create Home Directory on Login")
      )
    end
    if GetWinbindCaching()
      summary = Summary.AddLine(
        summary,
        # autoyast summary item
        _("Offline Authentication Enabled")
      )
    end
    if Ops.greater_than(GetMaxShares(), 0)
      summary = Summary.AddLine(
        summary,
        Builtins.sformat(
          # autoyast summary item
          _("Maximum Number of Shares: %1"),
          GetMaxShares()
        )
      )
    end
  else
    summary = Summary.AddLine(summary, nc)
  end
  summary
end

- (Object) SynchronizeCluster

In cluster environment, synchronize nodes after the configuration has been written



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

def SynchronizeCluster
  if FileUtils.Exists("/usr/sbin/csync2")
    # first, force syncing of smb.conf (bnc#802814)
    out = Convert.to_map(
      SCR.Execute(path(".target.bash_output"), "/usr/sbin/csync2 -cr /")
    )
    if Ops.get_integer(out, "exit", 0) != 0
      Builtins.y2error("csync2 -cr failed with %1", out)
      return false
    end
    out = Convert.to_map(
      SCR.Execute(
        path(".target.bash_output"),
        "/usr/sbin/csync2 -f /etc/samba/smb.conf"
      )
    )
    if Ops.get_integer(out, "exit", 0) != 0
      Builtins.y2error("csync2 -f failed with %1", out)
      return false
    end

    # sync the rest
    out = Convert.to_map(
      SCR.Execute(path(".target.bash_output"), "/usr/sbin/csync2 -xv")
    )
    if Ops.get_integer(out, "exit", 0) != 0
      Builtins.y2error("csync2 -x failed with %1", out)
      return false
    end
    return true
  end
  false
end

- (Object) Write(write_only)

Write all samba-client settings

Returns:

  • true on success



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

def Write(write_only)
  ret = true

  # Samba-client read dialog caption
  caption = _("Saving Samba Client Configuration")

  stages = [
    # translators: write progress stage
    _("Write the settings"),
    !# translators: write progress stage
    @winbind_enabled ?
      _("Disable Samba services") :
      # translators: write progress stage
      _("Enable Samba services")
  ]
  steps = [
    # translators: write progress step
    _("Writing the settings..."),
    !# translators: write progress step
    @winbind_enabled ?
      _("Disabling Samba services...") :
      # translators: write progress step
      _("Enabling Samba services..."),
    # translators: write progress finished
    _("Finished")
  ]

  # rely on ctdb to perform all changes to the samba services for the clustered case
  cluster_present = SambaNetJoin.ClusterPresent(false)

  if SambaAD.ADS != "" && @winbind_enabled
    # write progress stage
    stages = Builtins.add(stages, _("Write Kerberos configuration"))
    # write progress step
    steps = Builtins.add(steps, _("Writing Kerberos configuration..."))
  end

  # bug 169260: do not allow DHCP to change the hostname
  if @winbind_enabled && @disable_dhcp_hostname
    if @network_setup == {}
      NetworkConfig.Read
      @network_setup = NetworkConfig.Export
    end
    Ops.set(@network_setup, ["dhcp", "DHCLIENT_SET_HOSTNAME"], "no")
    NetworkConfig.Import(@network_setup)
    NetworkConfig.Write
  end

  # We do not set help text here, because it was set outside
  Progress.New(caption, " ", Builtins.size(stages), stages, steps, "")

  # write settings
  Progress.NextStage
  # if nothing to write, quit (but show at least the progress bar :-)
  return true if !GetModified()

  if Mode.autoinst
    if SambaAD.ADS != ""
      SambaConfig.GlobalSetStr(
        "workgroup",
        SambaAD.GetWorkgroup(SambaConfig.GlobalGetStr("workgroup", ""))
      )
      SambaAD.ReadRealm
    end
    # join the domain during autoinstallation
    if @password_data != {}
      SambaNetJoin.Join(
        SambaConfig.GlobalGetStr("workgroup", ""),
        "member",
        Ops.get(
          @password_data,
          "user",
          Ops.get(@password_data, "username", "")
        ),
        Ops.get(
          @password_data,
          "password",
          Ops.get(@password_data, "passwd", "")
        ),
        Ops.get(@password_data, "machine")
      )
    end
  end

  if !SambaConfig.Write(write_only)
    # translators: error message, %1 is filename
    Report.Error(
      Builtins.sformat(
        _("Cannot write settings to %1."),
        "/etc/samba/smb.conf"
      )
    )
    ret = false
  end

  # winbind
  Progress.NextStage
  if @winbind_enabled && !cluster_present
    ret = false if !Package.Installed("samba-winbind") && !Mode.test
    if !SambaWinbind.AdjustService(true)
      # translators: error message, do not change winbind
      Report.Error(_("Cannot start winbind service."))
      ret = false
    end
    if !write_only && !SambaWinbind.StartStopNow(true)
      # translators: error message, do not change winbind
      Report.Error(_("Cannot start winbind daemon."))
      ret = false
    end
  elsif !@winbind_enabled
    if !SambaWinbind.AdjustService(false)
      # translators: error message, do not change winbind
      Report.Error(_("Cannot stop winbind service."))
      ret = false
    end
    if !write_only && !SambaWinbind.StartStopNow(false)
      # translators: error message, do not change winbind
      Report.Error(_("Cannot stop winbind daemon."))
      ret = false
    end
  end
  if !SambaWinbind.AdjustNsswitch(@winbind_enabled, write_only)
    # translators: error message, %1 is filename
    Report.Error(
      Builtins.sformat(
        _("Cannot write settings to %1."),
        "/etc/nsswitch.conf"
      )
    )
    ret = false
  end
  if !SambaWinbind.AdjustPam(@winbind_enabled)
    # translators: error message
    Report.Error(_("Cannot write PAM settings."))
    ret = false
  end

  Progress.NextStage if SambaAD.ADS != "" && @winbind_enabled

  if !SambaAD.AdjustKerberos(@winbind_enabled)
    # translators: error message, %1 is filename
    Report.Error(
      Builtins.sformat(_("Cannot write settings to %1."), "/etc/krb5.conf")
    )
    ret = false
  end

  WriteMkHomeDir(@mkhomedir)

  WriteDisplayManager(@winbind_enabled)

  Autologin.Write(write_only) # see dialog.ycp

  WriteShares()

  AdjustSharesServices(write_only) if !cluster_present

  WriteSSHSupport(@ssh_support)

  WriteHostsResolution()

  SuSEFirewall.WriteOnly
  SuSEFirewall.ActivateConfiguration if !write_only

  if WritePAMMount() &&
      Ops.greater_than(Builtins.size(@pam_mount_volumes), 0)
    # enable pam_mount for services gdm, xdm, login, sshd (bnc#433845)
    Builtins.foreach(["gdm", "login", "xdm", "sshd"]) do |service|
      out = Convert.to_map(
        SCR.Execute(
          path(".target.bash_output"),
          Builtins.sformat("pam-config --service %1 -a --mount", service)
        )
      )
      if Ops.get_string(out, "stderr", "") != ""
        Builtins.y2warning("pam-config failed for service %1", service)
      end
    end
  end

  if cluster_present
    SynchronizeCluster()
    SambaNetJoin.CleanupCTDB
  end

  # finished
  Progress.NextStage
  @modified = false

  ret
end

- (Object) WriteDisplayManager(enable)

Tell displaymanager (KDM/GDM) to use special windbind greeter

Parameters:

  • enable (Boolean)

    if winbind is enabled

Returns:

  • success



590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
# File '../../src/modules/Samba.rb', line 590

def WriteDisplayManager(enable)
  return false if !FileUtils.Exists("/etc/sysconfig/displaymanager")

  if enable
    if !Package.InstalledAny(["kdebase3-kdm", "kde4-kdm", "gdm", "kdm"])
      return false
    end
    if SCR.Read(
        path(".sysconfig.displaymanager.DISPLAYMANAGER_AD_INTEGRATION")
      ) == "yes"
      return true
    end
  end

  SCR.Write(
    path(".sysconfig.displaymanager.DISPLAYMANAGER_AD_INTEGRATION"),
    enable ? "yes" : "no"
  )
  SCR.Write(path(".sysconfig.displaymanager"), nil)

  dm = Convert.to_string(
    SCR.Read(path(".sysconfig.displaymanager.DISPLAYMANAGER"))
  )

  true
end

- (Object) WriteFAM(write_only)

Start/Stop and FAM service according to current settings

Parameters:

  • write_only (Boolean)

    do not start/stop services

Returns:

  • success



526
527
528
529
530
531
532
533
534
535
536
537
# File '../../src/modules/Samba.rb', line 526

def WriteFAM(write_only)
  if @start_fam
    return false if !Package.InstalledAll(["fam", "fam-server"])

    Service.Enable("fam")
    Service.Start("fam") if !write_only
  else
    Service.Disable("fam")
    Service.Stop("fam") if !write_only
  end
  true
end

- (Object) WriteHostsResolution

Write /etc/nsswitch.conf if modified



298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File '../../src/modules/Samba.rb', line 298

def WriteHostsResolution
  if @hosts_resolution != @hosts_resolution_orig
    if @hosts_resolution
      @hosts_db = Builtins.add(@hosts_db, "wins")
    else
      @hosts_db = Builtins.filter(@hosts_db) { |e| e != "wins" }
    end
    Nsswitch.WriteDb("hosts", @hosts_db)
    ret = Nsswitch.Write
    Builtins.y2milestone("/etc/nsswitch.conf written: %1", ret)
    return ret
  end
  true
end

- (Object) WriteMkHomeDir(enabled)

Write the new value of pam_mkhomedir to /etc/pam.d/common-session

Parameters:

  • boolean

    new status



262
263
264
265
# File '../../src/modules/Samba.rb', line 262

def WriteMkHomeDir(enabled)
  return true if !@mkhomedir_modified
  Pam.Set("mkhomedir", enabled)
end

- (Object) WritePAMMount

Write the changes to /etc/security/pam_mount.conf.xml



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
246
247
248
249
250
251
252
# File '../../src/modules/Samba.rb', line 200

def WritePAMMount
  if !FileUtils.Exists(@pam_mount_path)
    Builtins.y2warning("%1 does not exist, no writing", @pam_mount_path)
    return false
  end
  if @pam_mount_volumes_orig == nil
    Builtins.y2milestone("%1 not read yet, reading now...", @pam_mount_path)
    if SCR.Read(path(".pam_mount"), @pam_mount_path) != true
      Builtins.y2error("reading %1 failed", @pam_mount_path)
      return false
    end
  end
  if !PAMMountModified()
    Builtins.y2milestone("no changes to pam_mount.conf.xml")
    return true
  end

  SCR.Execute(
    path(".target.bash"),
    Builtins.sformat("cp %1 %1.YaST2save", @pam_mount_path)
  )

  # 1. delete all volume entries with 'cifs' fstype
  SCR.Write(
    path(".pam_mount.delete"),
    { "element" => "volume", "attrmap" => { "fstype" => "cifs" } }
  )

  # 2. save the new set of volume entries
  Builtins.foreach(@pam_mount_volumes) do |volume|
    next if Ops.get_string(volume, "fstype", "") != "cifs"
    # if no volume entry is present, add new
    SCR.Write(
      path(".pam_mount.add"),
      {
        "element" => "volume",
        # ... the keys without values should not end in config file
        "attrmap" => Builtins.filter(
          Convert.convert(
            volume,
            :from => "map",
            :to   => "map <string, string>"
          )
        ) do |k, v|
          v != ""
        end,
        "newline" => true
      }
    )
  end
  SCR.Write(path(".pam_mount"), nil)
  true
end

- (Object) WriteShares

create the shares directory with correct rights



540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
# File '../../src/modules/Samba.rb', line 540

def WriteShares
  if !FileUtils.Exists(@shares_dir)
    SCR.Execute(path(".target.mkdir"), @shares_dir)
  elsif @remove_shares
    SCR.Execute(
      path(".target.bash"),
      Builtins.sformat("/bin/rm -f %1/*", @shares_dir)
    )
  end
  if FileUtils.Exists(@shares_dir)
    @shares_group = "users" if @shares_group == ""
    SCR.Execute(
      path(".target.bash"),
      Builtins.sformat(
        "/bin/chmod 1770 %1; /bin/chgrp '%2' %1",
        @shares_dir,
        @shares_group
      )
    )
  end
  true
end

- (Object) WriteSSHSupport(enable)

Write the new value for sh single-sign-on support (fate #303415)



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

def WriteSSHSupport(enable)
  write = enable ? "yes" : "no"

  # do not write "no" everywhere, there might be some user setting...
  if enable || @ssh_was_enabled
    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
  if enable || @sshd_was_enabled
    Builtins.foreach(
      [
        "GSSAPIAuthentication",
        "GSSAPICleanupCredentials",
        "ChallengeResponseAuthentication",
        "UsePAM"
      ]
    ) do |key|
      SCR.Write(Builtins.add(path(".etc.ssh.sshd_config"), key), [write])
    end
    SCR.Write(path(".etc.ssh.sshd_config"), nil)
    Builtins.y2milestone("/etc/ssh/sshd_config modified")
  end
  enable
end