/
Nis.rb
1359 lines (1199 loc) · 42.6 KB
/
Nis.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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
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
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
280
281
282
283
284
285
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
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
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
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
616
617
618
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
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
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
737
738
739
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
931
932
933
934
935
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
# encoding: utf-8
# ------------------------------------------------------------------------------
# Copyright (c) 2006-2012 Novell, Inc. All Rights Reserved.
#
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 of the GNU General Public License as published by the
# Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail, you may find
# current contact information at www.novell.com.
# ------------------------------------------------------------------------------
# File:
# modules/Nis.ycp
#
# Module:
# Configuration of NIS client
#
# Summary:
# NIS client configuration data, I/O functions.
#
# Authors:
# Jan Holesovsky <kendy@suse.cz>
# Dan Vesely <dan@suse.cz>
# Martin Vidner <mvidner@suse.cz>
#
# $Id$
#
require "yast"
module Yast
class NisClass < Module
def main
textdomain "nis"
Yast.import "Address"
Yast.import "Autologin"
Yast.import "IP"
Yast.import "Message"
Yast.import "Nsswitch"
Yast.import "Pam"
Yast.import "Package"
Yast.import "Progress"
Yast.import "Report"
Yast.import "Service"
Yast.import "Summary"
Yast.import "SuSEFirewall"
Yast.import "Wizard"
# default value of settings modified
@modified = false
# Required packages for this module to operate
#
@required_packages = ["ypbind"]
# Should ypbind be started at boot?
# If not, other settings are not touched.
@start = false
# IP addresses of NIS servers.
@servers = []
# Broadcast for the default domain?
# (New in ypbind-1.12)
@default_broadcast = false
# Servers for a multiple-domain configuration.
# Keys are domains, values are lists of servers (strings).
# The domains must be the same as for multidomain_broadcast
# @see #multidomain_broadcast
@multidomain_servers = {}
# Servers for a multiple-domain configuration.
# Whether a broadcast will be done if the servers don't respond.
# Keys are domains, values are booleans.
# The domains must be the same as for multidomain_servers
# @see #multidomain_servers
# @see #global_broadcast
@multidomain_broadcast = {}
# If this option is set, ypbind will ignore /etc/yp.conf and use
# a broadcast call to find a NIS server in the local subnet. You
# should avoid to use this, it is a big security risk.
# @see #multidomain_broadcast
# @see #default_broadcast
@global_broadcast = false
@slp_domain = {}
# netconfig policy
@policy = "auto"
# which service mapper is used (rpcbind/portmap)
@rpc_mapper = "rpcbind"
@domain = ""
@old_domain = nil
@domain_changed = false
@static_keylist = []
# DHCP cooperation
# #35654: if the server is running and sysconfig wants NIS data,
# it's ok to FitIntoSingle
@dhcpcd_running = false
# If dhcp_wanted changes, we need to restart the DHCP client
@dhcp_restart = false
# The following four are from sysconfig/ypbind; the comments are
# taken from there. The dialog help texts have "user friendlier"
# descriptions.
# If this option is set, ypbind will only bind to the loopback
# interface and remote hosts cannot query it.
@local_only = false
# You should set this to "yes" if you have a NIS server in your
# network, which binds only to high ports over 1024. Since this
# is a security risk, you should consider to replace the NIS
# server with another implementation.
@broken_server = false
# Extra options for ypbind. Here you can add options like
# "-ypset", "-ypsetme", "-p port" or "-no-ping".
@options = ""
# If no, automounter will not be affected.
@_autofs_allowed = true
# Start automounter and import the settings from NIS. (Bug 6092)
@_start_autofs = false
# Output of "rcypbind start", if there was an error.
# Read only.
# This is currently used only in nis-server for its more advanced
# error reporting. (Bug 14706)
@YpbindErrors = ""
# If the hostname resolution is done over NIS,
# names cannot be used to specify servers.
@hosts_by_nis = false
# Using NIS and LDAP simultaneously is not supported (#36981).
@users_by_ldap = false
# ----------------------------------------------------------------
# Has the configuration been changed?
# Can be used as an argument to Popup::ReallyAbort
@touched = false
# ----------------------------------------------------------------
# Read only, set by ProbePackages.
# Use as an argument to DoInstallAndRemove
@install_packages = []
end
# Function sets internal variable, which indicates, that any
# settings were modified, to "true"
def SetModified
@modified = true
nil
end
# Functions which returns if the settings were modified
# @return [Boolean] settings were modified
def GetModified
@modified
end
# @return Access the servers as a string
def GetServers
Builtins.mergestring(@servers, " ")
end
# Set the servers from a string
# @param [String] servers_s a whitespace separated list
def SetServers(servers_s)
@servers = Builtins.filter(Builtins.splitstring(servers_s, " \t")) do |s|
s != ""
end
nil
end
# Read Netconfig configuration
def getNetconfigValues
Builtins.y2milestone("getNetconfigValues called")
# reset the values
@multidomain_servers = {}
@multidomain_broadcast = {}
@slp_domain = {}
@servers = []
@policy = Convert.to_string(
SCR.Read(path(".sysconfig.network.config.NETCONFIG_NIS_POLICY"))
)
Builtins.y2milestone("policy : %1", @policy)
@policy = "" if @policy == nil
staticVals = {}
keylist = SCR.Dir(path(".sysconfig.network.config"))
Builtins.y2milestone("KEYLIST: %1", keylist)
keylist = [] if keylist == nil
Builtins.foreach(keylist) do |key|
if !Builtins.issubstring(key, "NETCONFIG_NIS_STATIC_DOMAIN") &&
!Builtins.issubstring(key, "NETCONFIG_NIS_STATIC_SERVERS")
next
end
value = Convert.to_string(
SCR.Read(Builtins.add(path(".sysconfig.network.config"), key))
)
Builtins.y2milestone("Found %1 = %2", key, value)
num = ""
if key == "NETCONFIG_NIS_STATIC_DOMAIN"
Ops.set(
staticVals,
"0",
Builtins.add(Ops.get(staticVals, "0", {}), "DOMAIN", value)
)
elsif key == "NETCONFIG_NIS_STATIC_SERVERS"
Ops.set(
staticVals,
"0",
Builtins.add(Ops.get(staticVals, "0", {}), "SERVERS", value)
)
else
@static_keylist = Builtins.add(@static_keylist, key)
num = Builtins.regexpsub(
key,
"^NETCONFIG_NIS_STATIC_(DOMAIN|SERVERS)_(.*)",
"\\2"
)
Builtins.y2milestone("try to get the number: %1", num)
if Builtins.issubstring(key, "NETCONFIG_NIS_STATIC_DOMAIN")
Ops.set(
staticVals,
num,
Builtins.add(Ops.get(staticVals, num, {}), "DOMAIN", value)
)
elsif Builtins.issubstring(key, "NETCONFIG_NIS_STATIC_SERVERS")
Ops.set(
staticVals,
num,
Builtins.add(Ops.get(staticVals, num, {}), "SERVERS", value)
)
end
end
end
Builtins.y2milestone("STATIC VALS: %1", staticVals)
Builtins.foreach(staticVals) do |key, value|
if Ops.get(value, "DOMAIN") == ""
if Ops.get(value, "SERVERS", "") != ""
sr = Ops.add(
Ops.add(GetServers(), " "),
Ops.get(value, "SERVERS", "")
)
SetServers(sr)
end
elsif Ops.get(value, "DOMAIN") == "broadcast"
@global_broadcast = true
elsif Ops.get(value, "DOMAIN", "") != ""
if Ops.get(value, "SERVERS") == "broadcast"
@default_broadcast = true if key == "0"
Ops.set(@multidomain_broadcast, Ops.get(value, "DOMAIN", ""), true)
elsif Ops.get(value, "SERVERS") == "slp"
Ops.set(@slp_domain, Ops.get(value, "DOMAIN", ""), true)
elsif Ops.get(value, "SERVERS", "") != ""
Ops.set(
@multidomain_servers,
Ops.get(value, "DOMAIN", ""),
Builtins.splitstring(Ops.get(value, "SERVERS", ""), " ")
)
end
end
end
Builtins.foreach(@multidomain_servers) do |domain, value|
if !Builtins.haskey(@multidomain_broadcast, domain)
Ops.set(@multidomain_broadcast, domain, false)
end
end
Builtins.foreach(@multidomain_broadcast) do |domain, value|
if !Builtins.haskey(@multidomain_servers, domain)
Ops.set(@multidomain_servers, domain, [])
end
end
Builtins.foreach(
Convert.convert(@slp_domain, :from => "map", :to => "map <string, any>")
) do |domain, value|
if !Builtins.haskey(@multidomain_servers, domain)
Ops.set(@multidomain_servers, domain, [])
end
end
Builtins.y2milestone("Servers: %1", @servers)
Builtins.y2milestone("multidomain_servers: %1", @multidomain_servers)
Builtins.y2milestone("multidomain_broadcast: %1", @multidomain_broadcast)
Builtins.y2milestone("slp_domain: %1", @slp_domain)
Builtins.y2milestone("default_broadcast: %1", @default_broadcast)
nil
end
# Write the netconfig configuration
def setNetconfigValues
SCR.Write(path(".sysconfig.network.config.NETCONFIG_NIS_POLICY"), @policy)
Builtins.foreach(@multidomain_servers) do |domain, value|
if !Builtins.haskey(@multidomain_broadcast, domain)
Ops.set(@multidomain_broadcast, domain, false)
end
end
Builtins.foreach(@multidomain_broadcast) do |domain, value|
if !Builtins.haskey(@multidomain_servers, domain)
Ops.set(@multidomain_servers, domain, [])
end
end
Builtins.foreach(
Convert.convert(@slp_domain, :from => "map", :to => "map <string, any>")
) do |domain, value|
if !Builtins.haskey(@multidomain_servers, domain)
Ops.set(@multidomain_servers, domain, [])
end
end
Builtins.foreach(@static_keylist) do |key|
Builtins.y2milestone("Remove : %1", key)
SCR.Write(Builtins.add(path(".sysconfig.network.config"), key), nil)
end
# remove the content of this
SCR.Write(
path(".sysconfig.network.config.NETCONFIG_NIS_STATIC_DOMAIN"),
""
)
SCR.Write(
path(".sysconfig.network.config.NETCONFIG_NIS_STATIC_SERVERS"),
""
)
Builtins.y2milestone("Servers: %1", @servers)
Builtins.y2milestone("multidomain_servers: %1", @multidomain_servers)
Builtins.y2milestone("multidomain_broadcast: %1", @multidomain_broadcast)
Builtins.y2milestone("slp_domain: %1", @slp_domain)
Builtins.y2milestone("default_broadcast: %1", @default_broadcast)
cnt = 0
if Ops.greater_than(Builtins.size(@servers), 0)
SCR.Write(
path(".sysconfig.network.config.NETCONFIG_NIS_STATIC_DOMAIN"),
""
)
SCR.Write(
path(".sysconfig.network.config.NETCONFIG_NIS_STATIC_SERVERS"),
Builtins.mergestring(@servers, " ")
)
cnt = Ops.add(cnt, 1)
end
Builtins.foreach(
Convert.convert(
@multidomain_servers,
:from => "map <string, list>",
:to => "map <string, list <string>>"
)
) do |dom, srvs|
next if dom == ""
if Ops.greater_than(Builtins.size(srvs), 0)
if cnt == 0
SCR.Write(
path(".sysconfig.network.config.NETCONFIG_NIS_STATIC_DOMAIN"),
dom
)
SCR.Write(
path(".sysconfig.network.config.NETCONFIG_NIS_STATIC_SERVERS"),
Builtins.mergestring(srvs, " ")
)
else
SCR.Write(
Builtins.add(
path(".sysconfig.network.config"),
Ops.add("NETCONFIG_NIS_STATIC_DOMAIN_", cnt)
),
dom
)
SCR.Write(
Builtins.add(
path(".sysconfig.network.config"),
Ops.add("NETCONFIG_NIS_STATIC_SERVERS_", cnt)
),
Builtins.mergestring(srvs, " ")
)
end
cnt = Ops.add(cnt, 1)
end
if Ops.get(@multidomain_broadcast, dom, false) == true
if cnt == 0
SCR.Write(
path(".sysconfig.network.config.NETCONFIG_NIS_STATIC_DOMAIN"),
dom
)
SCR.Write(
path(".sysconfig.network.config.NETCONFIG_NIS_STATIC_SERVERS"),
"broadcast"
)
else
SCR.Write(
Builtins.add(
path(".sysconfig.network.config"),
Ops.add("NETCONFIG_NIS_STATIC_DOMAIN_", cnt)
),
dom
)
SCR.Write(
Builtins.add(
path(".sysconfig.network.config"),
Ops.add("NETCONFIG_NIS_STATIC_SERVERS_", cnt)
),
"broadcast"
)
end
cnt = Ops.add(cnt, 1)
end
if Ops.get_boolean(@slp_domain, dom, false) == true
if cnt == 0
SCR.Write(
path(".sysconfig.network.config.NETCONFIG_NIS_STATIC_DOMAIN"),
dom
)
SCR.Write(
path(".sysconfig.network.config.NETCONFIG_NIS_STATIC_SERVERS"),
"slp"
)
else
SCR.Write(
Builtins.add(
path(".sysconfig.network.config"),
Ops.add("NETCONFIG_NIS_STATIC_DOMAIN_", cnt)
),
dom
)
SCR.Write(
Builtins.add(
path(".sysconfig.network.config"),
Ops.add("NETCONFIG_NIS_STATIC_SERVERS_", cnt)
),
"slp"
)
end
cnt = Ops.add(cnt, 1)
end
end
if @default_broadcast == true
if cnt == 0
SCR.Write(
path(".sysconfig.network.config.NETCONFIG_NIS_STATIC_DOMAIN"),
@domain
)
SCR.Write(
path(".sysconfig.network.config.NETCONFIG_NIS_STATIC_SERVERS"),
"broadcast"
)
else
SCR.Write(
Builtins.add(
path(".sysconfig.network.config"),
Ops.add("NETCONFIG_NIS_STATIC_DOMAIN_", cnt)
),
@domain
)
SCR.Write(
Builtins.add(
path(".sysconfig.network.config"),
Ops.add("NETCONFIG_NIS_STATIC_SERVERS_", cnt)
),
"broadcast"
)
end
cnt = Ops.add(cnt, 1)
elsif @global_broadcast == true
if cnt == 0
SCR.Write(
path(".sysconfig.network.config.NETCONFIG_NIS_STATIC_DOMAIN"),
"broadcast"
)
SCR.Write(
path(".sysconfig.network.config.NETCONFIG_NIS_STATIC_SERVERS"),
""
)
else
SCR.Write(
Builtins.add(
path(".sysconfig.network.config"),
Ops.add("NETCONFIG_NIS_STATIC_DOMAIN_", cnt)
),
"broadcast"
)
SCR.Write(
Builtins.add(
path(".sysconfig.network.config"),
Ops.add("NETCONFIG_NIS_STATIC_SERVERS_", cnt)
),
""
)
end
cnt = Ops.add(cnt, 1)
end
if !SCR.Write(path(".sysconfig.network.config"), nil)
Report.Error(Message.ErrorWritingFile("/etc/sysconfig/network/config"))
return false
end
true
end
# If the domain has changed from a nonempty one, it may only be
# changed at boot time. Use this to warn the user.
# @return whether changed by SetDomain
def DomainChanged
@domain_changed
end
# @return Get the NIS domain.
def GetDomain
@domain
end
# Set the NIS domain.
# @param [String] new_domain a new domain
def SetDomain(new_domain)
@domain = new_domain
@domain_changed = true if @domain != @old_domain && @old_domain != ""
nil
end
# ----------------------------------------------------------------
# used also for nis-server
# Check syntax of a NIS domain name
# @param [String] domain a domain name
# @return true if correct
def check_nisdomainname(domain)
# TODO
# disallow whitespace and special characters...
domain != "" && domain != "(none)" &&
Ops.less_or_equal(Builtins.size(domain), 64)
end
# @return describe a valid NIS domain name
def valid_nisdomainname
# Translators: do not translate (none)!
_(
"A NIS domain name must not be empty,\n" +
"it must not be \"(none)\",\n" +
"and it must be at most 64 characters long.\n"
)
end
# Used in the UI when NIS is turned on.
def UsersByLdap
@users_by_ldap
end
# Describe a valid address - ip4 or name, names only if
# nsswitch.conf does not have hosts: nis
# @return a description
def valid_address_nis
Builtins.y2debug("hosts_by_nis %1", @hosts_by_nis)
if @hosts_by_nis
# message popup
return Ops.add(
_(
"Only an IP address can be used\n" +
"because host names are resolved using NIS.\n" +
"\n"
),
IP.Valid4
)
else
return Address.Valid4
end
end
# Check syntax of a network address (ip4 or name), names only if
# nsswitch.conf does not have hosts: nis
# @param [String] a an address
# @return true if correct
def check_address_nis(a)
Builtins.y2debug("hosts_by_nis %1", @hosts_by_nis)
if @hosts_by_nis
return IP.Check4(a)
else
return Address.Check(a)
end
end
# A convenient shortcut for setting touched.
# @param [Boolean] really if true, set Nis::touched
# @example Nis::Touch (Nis::var != ui_var);
def Touch(really)
@touched = @touched || really
nil
end
# Detect which packages have to be installed
# and return a descriptive string for a plain text pop-up.
# @return "" or "Foo will be installed.\nBar will be installed.\n"
def ProbePackages
message = ""
@install_packages = []
if @_autofs_allowed && @_start_autofs
if !Package.Installed("autofs")
@install_packages = Builtins.add(@install_packages, "autofs")
# Translators: popup message part, ends with a newline
message = Ops.add(
message,
_("The automounter package will be installed.\n")
)
end
if !Package.Installed("nfs-client")
@install_packages = Builtins.add(@install_packages, "nfs-client")
end
end
message
end
# ----------------------------------------------------------------
# Set module data
# @return [void]
def Set(settings)
settings = deep_copy(settings)
@start = Ops.get_boolean(settings, "start_nis", false)
@servers = Ops.get_list(settings, "nis_servers", [])
@default_broadcast = Ops.get_boolean(settings, "nis_broadcast", false)
@domain = Ops.get_string(settings, "nis_domain", "")
@old_domain = @domain
# we don't know what the state will be before Write, so restart it
@dhcp_restart = true
other_domains = Ops.get_list(settings, "nis_other_domains", [])
Builtins.foreach(other_domains) do |other_domain|
domain = Ops.get_string(other_domain, "nis_domain", "")
servers = Ops.get_list(other_domain, "nis_servers", [])
b = Ops.get_boolean(other_domain, "nis_broadcast", false)
Ops.set(@multidomain_servers, domain, servers)
Ops.set(@multidomain_broadcast, domain, b)
end
@local_only = Ops.get_boolean(settings, "nis_local_only", false)
@broken_server = Ops.get_boolean(settings, "nis_broken_server", false)
@options = Ops.get_string(settings, "nis_options", "")
# autofs is not touched in Write if the map does not want it
@_autofs_allowed = Builtins.haskey(settings, "start_autofs")
@_start_autofs = Ops.get_boolean(settings, "start_autofs", false)
if @_start_autofs
@required_packages = Convert.convert(
Builtins.union(@required_packages, ["autofs", "nfs-client"]),
:from => "list",
:to => "list <string>"
)
end
@policy = Ops.get_string(settings, "netconfig_policy", @policy)
@slp_domain = Ops.get_map(settings, "slp_domain", @slp_domain)
@touched = true
nil
end
# TODO update the map keys
# better still: link to a current interface description
# Get all the NIS configuration from a map.
# When called by nis_auto (preparing autoinstallation data)
# the map may be empty.
# @param [Hash] settings $["start": "domain": "servers":[...] ]
# @return success
def Import(settings)
settings = deep_copy(settings)
if Builtins.size(settings) == 0
#Provide defaults for autoinstallation editing:
#Leave empty.
@old_domain = @domain
# enable _autofs_allowed
# Injecting it into the defaults for the GUI
# but leaving the check in Set makes it possible
# to delete the element manually from the xml profile
# and leave autofs untouched
Ops.set(settings, "start_autofs", false)
Set(settings)
return true
end
missing = false
# "nis_domain" can be omitted if nis_by_dhcp is true
Builtins.foreach(["start_nis"]) do |k|
if !Builtins.haskey(settings, k)
Builtins.y2error("Missing at Import: '%1'.", k)
missing = true
end
end
return false if missing
Set(settings)
true
end
# TODO update the map keys
# better still: link to a current interface description
# Dump the NIS settings to a map, for autoinstallation use.
# @return $["start":, "servers":[...], "domain":]
def Export
other_domains = Builtins.maplist(@multidomain_servers) do |d, s|
{
"nis_domain" => d,
"nis_servers" => s,
"nis_broadcast" => Ops.get(@multidomain_broadcast, d, false)
}
end
if @global_broadcast
Builtins.y2error("Attempt to export Nis::global_broadcast")
end
{
"start_nis" => @start,
"nis_servers" => @servers,
"nis_domain" => @domain,
"nis_broadcast" => @default_broadcast,
"nis_other_domains" => other_domains,
"nis_local_only" => @local_only,
"nis_broken_server" => @broken_server,
"nis_options" => @options,
"start_autofs" => @_start_autofs,
"slp_domain" => @slp_domain,
"netconfig_policy" => @policy
}
end
# copied from Mail.ycp
# replace with a custom list
# Summarizes a list of data
# @param [String] title passed to Summary::AddHeader
# @param [Object] value a list (of scalars, lists or maps)
# @return Summary-formatted description
def ListItem(title, value)
value = deep_copy(value)
summary = ""
summary = Summary.AddHeader(summary, title)
#enhancement BEGIN
value = Builtins.maplist(Convert.to_map(value)) { |k, v| k } if Ops.is_map?(
value
)
#enhancement END
if Ops.is_list?(value) &&
Ops.greater_than(Builtins.size(Convert.to_list(value)), 0)
summary = Summary.OpenList(summary)
Builtins.foreach(Convert.to_list(value)) do |d|
entry = ""
if Ops.is_map?(d) || Ops.is_list?(d)
entry = Builtins.sformat(
"%1 Entries configured",
Ops.is_map?(d) ?
Builtins.size(Convert.to_map(value)) :
Builtins.size(Convert.to_list(value))
)
else
entry = Convert.to_string(d)
end
summary = Summary.AddListItem(summary, entry)
end
summary = Summary.CloseList(summary)
else
summary = Summary.AddLine(summary, Summary.NotConfigured)
end
summary
end
# @return Html formatted configuration summary
def Summary
# TODO multidomain_servers, multidomain_broadcast
# OK, a dumb mapping is possible, but wouldn't it be
# too complicated to write by hand?
summary = ""
nc = Summary.NotConfigured
# summary: Domain or servers are retrieved by the
# Dynamic Host Configuration Protocol.
# Will be placed after NIS Domain/NIS Servers instead of the
# actual settings.
dhcp = _("by DHCP")
# summary header
summary = Summary.AddHeader(summary, _("NIS Client enabled"))
# summary item: an option is turned on
summary = Summary.AddLine(summary, @start ? _("Yes") : nc)
# summary header
summary = Summary.AddHeader(summary, _("NIS Domain"))
summary = Summary.AddLine(summary, @domain != "" ? @domain : nc)
# summary header
summary = Summary.AddHeader(summary, _("NIS Servers"))
summary = Summary.AddLine(
summary,
@servers != [] ? Builtins.mergestring(@servers, "<br>") : nc
)
# summary header
summary = Summary.AddHeader(summary, _("Broadcast"))
# summary item: an option is turned on
summary = Summary.AddLine(summary, @default_broadcast ? _("Yes") : nc)
# TODO: a full list
summary = Ops.add(
summary,
ListItem(_("Other domains"), @multidomain_servers)
)
# summary header
summary = Summary.AddHeader(summary, _("Answer to local host only"))
# summary item: an option is turned on
summary = Summary.AddLine(summary, @local_only ? _("Yes") : nc)
# summary header
summary = Summary.AddHeader(summary, _("Broken server"))
# summary item: an option is turned on
summary = Summary.AddLine(summary, @broken_server ? _("Yes") : nc)
# summary header
summary = Summary.AddHeader(summary, _("ypbind options"))
summary = Summary.AddLine(summary, @options != "" ? @options : nc)
# summary header
summary = Summary.AddHeader(summary, _("Automounter enabled"))
# summary item: an option is turned on
summary = Summary.AddLine(summary, @_start_autofs ? _("Yes") : nc)
summary
end
# Makes an item for the short summary. I guess the users module
# wants to avoid paragraph breaks.
# @param [String] title
# @param [String] value
# @return [b]title[/b]: value[br]
def BrItem(title, value)
Builtins.sformat("<b>%1</b>: %2<br>", title, value)
end
# Create a short textual summary with configuration abstract
# It is called by "authentication/user sources" dialog in yast2-users
# @return summary of the current configuration
def ShortSummary
summary = ""
nc = Summary.NotConfigured
summary = Ops.add(
Ops.add(
# summary item
BrItem(_("Servers"), @servers != [] ? GetServers() : nc),
# summary item
BrItem(_("Domain"), @domain != "" ? @domain : nc)
),
# summary item (yes/no follows)
BrItem(_("Client Enabled"), @start ? _("Yes") : _("No"))
)
summary
end
# Reads NIS settings from the SCR
# @return success
def Read
@start = Service.Enabled("ypbind")
getNetconfigValues
@servers = [] if @servers == nil
@default_broadcast = false if @default_broadcast == nil
@multidomain_servers = {} if @multidomain_servers == nil
@multidomain_broadcast = {} if @multidomain_broadcast == nil
@slp_domain = {} if @slp_domain == nil
out = SCR.Execute(path(".target.bash_output"), "/usr/bin/ypdomainname")
@domain = out["stdout"].strip
@old_domain = @domain
@dhcpcd_running = SCR.Execute(
path(".target.bash"),
"ls /var/run/dhcpcd-*.pid"
) == 0
@local_only = SCR.Read(path(".sysconfig.ypbind.YPBIND_LOCAL_ONLY")) == "yes"
@global_broadcast = SCR.Read(path(".sysconfig.ypbind.YPBIND_BROADCAST")) == "yes"
@broken_server = SCR.Read(path(".sysconfig.ypbind.YPBIND_BROKEN_SERVER")) == "yes"
@options = Convert.to_string(
SCR.Read(path(".sysconfig.ypbind.YPBIND_OPTIONS"))
)
# install on demand
@_start_autofs = @_autofs_allowed && Service.Enabled("autofs")
@hosts_by_nis = Builtins.contains(Nsswitch.ReadDb("hosts"), "nis")
nss_passwd = Nsswitch.ReadDb("passwd")
@users_by_ldap = Builtins.contains(nss_passwd, "ldap") ||
Builtins.contains(nss_passwd, "compat") &&
Builtins.contains(Nsswitch.ReadDb("passwd_compat"), "ldap")
Autologin.Read
progress_orig = Progress.set(false)
SuSEFirewall.Read
Progress.set(progress_orig)
true
end
# Make up data for screnshots.
# To be used instead of {#Read} .
def Fake
Builtins.y2milestone("Faking data for screenshots")
@start = true
@servers = ["10.42.0.1"]
@default_broadcast = false
@multidomain_servers = {
"printer.example.com" => [],
"test.example.com" => ["10.42.1.1", "10.42.1.2"]
}
@multidomain_broadcast = {
"printer.example.com" => true,
"test.example.com" => false
}
@domain = "example.com"
@old_domain = @domain
@local_only = false
@global_broadcast = false
@broken_server = false
@options = ""
@_autofs_allowed = true
@_start_autofs = true
@hosts_by_nis = false
nil
end
# @param [String] file a pathname
# @return is there a nis inclusion?
def HasPlus(file)
# does the file have a plus?
Builtins.y2milestone("file %1 has pluses", file)
0 ==
SCR.Execute(
path(".target.bash"),
Ops.add("/usr/bin/grep -q '^[+-]' ", file)
)
end
# If a file does not contain a NIS entry, add it.
# @param [String] file pathname
# @param [String] what a "+" line without a '\n'
# @return success?
def WritePlusesTo(file, what)
ok = true
if !HasPlus(file)
# backup the file:
SCR.Execute(
path(".target.bash"),
Builtins.sformat("/bin/cp %1 %1.YaST2save", file)
)
if SCR.Execute(
path(".target.bash"),
Builtins.sformat("/bin/echo '%1' >> %2", what, file)