Class: Yast::NisClass
- Inherits:
-
Module
- Object
- Module
- Yast::NisClass
- Defined in:
- ../../src/modules/Nis.rb
Instance Method Summary (collapse)
-
- (Hash) AutoPackages
Return needed packages and packages to be removed during autoinstallation.
-
- (b) BrItem(title, value)
Makes an item for the short summary.
-
- (Object) check_address_nis(a)
Check syntax of a network address (ip4 or name), names only if nsswitch.conf does not have hosts: nis.
-
- (Object) check_nisdomainname(domain)
Check syntax of a NIS domain name.
-
- (Object) DomainChanged
If the domain has changed from a nonempty one, it may only be changed at boot time.
-
- (Object) Export
TODO update the map keys better still: link to a current interface description Dump the NIS settings to a map, for autoinstallation use.
-
- (Object) Fake
Make up data for screnshots.
-
- (Object) GetDomain
Get the NIS domain.
-
- (Boolean) GetModified
Functions which returns if the settings were modified.
-
- (Object) getNetconfigValues
Read Netconfig configuration.
-
- (Object) GetServers
Access the servers as a string.
-
- (Object) HasPlus(file)
Is there a nis inclusion?.
-
- (Object) HavePlus
Do we need compat? Is there a plus in any of the user databases?.
-
- (Object) Import(settings)
TODO update the map keys better still: link to a current interface description Get all the NIS configuration from a map.
-
- (Object) ListItem(title, value)
copied from Mail.ycp replace with a custom list Summarizes a list of data.
- - (Object) main
-
- (Object) ProbePackages
Detect which packages have to be installed and return a descriptive string for a plain text pop-up.
-
- (Object) Read
Reads NIS settings from the SCR.
-
- (void) Set(settings)
Set module data.
-
- (Object) SetDomain(new_domain)
Set the NIS domain.
-
- (Object) SetModified
Function sets internal variable, which indicates, that any settings were modified, to “true”.
-
- (Object) setNetconfigValues
Write the netconfig configuration.
-
- (Object) SetServers(servers_s)
Set the servers from a string.
-
- (Object) ShortSummary
Create a short textual summary with configuration abstract It is called by “authentication/user sources” dialog in yast2-users.
-
- (Object) Summary
Html formatted configuration summary.
-
- (Object) Touch(really)
A convenient shortcut for setting touched.
-
- (Object) UsersByLdap
Used in the UI when NIS is turned on.
-
- (Object) valid_address_nis
Describe a valid address - ip4 or name, names only if nsswitch.conf does not have hosts: nis.
-
- (Object) valid_nisdomainname
Describe a valid NIS domain name.
-
- (Object) Write
Saves NIS configuration.
-
- (Object) WriteNssConf
Configures the name service switch for the user databases according to chosen settings.
-
- (Object) WriteOnly
Only write new configuration w/o starting any scripts.
-
- (Object) WritePluses
Add “+” lines to system files so that NIS entries get merged in.
-
- (Object) WritePlusesTo(file, what)
If a file does not contain a NIS entry, add it.
Instance Method Details
- (Hash) AutoPackages
Return needed packages and packages to be removed during autoinstallation.
1314 1315 1316 1317 1318 |
# File '../../src/modules/Nis.rb', line 1314 def AutoPackages install_pkgs = deep_copy(@required_packages) remove_pkgs = [] { "install" => install_pkgs, "remove" => remove_pkgs } end |
- (b) BrItem(title, value)
Makes an item for the short summary. I guess the users module wants to avoid paragraph breaks.
874 875 876 |
# File '../../src/modules/Nis.rb', line 874 def BrItem(title, value) Builtins.sformat("<b>%1</b>: %2<br>", title, value) end |
- (Object) check_address_nis(a)
Check syntax of a network address (ip4 or name), names only if nsswitch.conf does not have hosts: nis
616 617 618 619 620 621 622 623 |
# File '../../src/modules/Nis.rb', line 616 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 |
- (Object) check_nisdomainname(domain)
Check syntax of a NIS domain name
570 571 572 573 574 575 |
# File '../../src/modules/Nis.rb', line 570 def check_nisdomainname(domain) # TODO # disallow whitespace and special characters... domain != "" && domain != "(none)" && Ops.less_or_equal(Builtins.size(domain), 64) end |
- (Object) DomainChanged
If the domain has changed from a nonempty one, it may only be changed at boot time. Use this to warn the user.
546 547 548 |
# File '../../src/modules/Nis.rb', line 546 def DomainChanged @domain_changed end |
- (Object) Export
TODO update the map keys better still: link to a current interface description Dump the NIS settings to a map, for autoinstallation use.
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 |
# File '../../src/modules/Nis.rb', line 747 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 |
- (Object) Fake
Make up data for screnshots. To be used instead of #Read .
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 |
# File '../../src/modules/Nis.rb', line 950 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 |
- (Object) GetDomain
Returns Get the NIS domain.
551 552 553 |
# File '../../src/modules/Nis.rb', line 551 def GetDomain @domain end |
- (Boolean) GetModified
Functions which returns if the settings were modified
181 182 183 |
# File '../../src/modules/Nis.rb', line 181 def GetModified @modified end |
- (Object) getNetconfigValues
Read Netconfig configuration
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 |
# File '../../src/modules/Nis.rb', line 201 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 |
- (Object) GetServers
Returns Access the servers as a string
186 187 188 |
# File '../../src/modules/Nis.rb', line 186 def GetServers Builtins.mergestring(@servers, " ") end |
- (Object) HasPlus(file)
Returns is there a nis inclusion?
978 979 980 981 982 983 984 985 986 |
# File '../../src/modules/Nis.rb', line 978 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 |
- (Object) HavePlus
Do we need compat? Is there a plus in any of the user databases?
1027 1028 1029 1030 1031 |
# File '../../src/modules/Nis.rb', line 1027 def HavePlus files = ["/etc/passwd", "/etc/shadow", "/etc/group"] # find a file having a plus nil != Builtins.find(files) { |file| HasPlus(file) } end |
- (Object) Import(settings)
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.
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 |
# File '../../src/modules/Nis.rb', line 713 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 |
- (Object) ListItem(title, value)
copied from Mail.ycp replace with a custom list Summarizes a list of data
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 |
# File '../../src/modules/Nis.rb', line 781 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 |
- (Object) main
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 |
# File '../../src/modules/Nis.rb', line 42 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 |
- (Object) ProbePackages
Detect which packages have to be installed and return a descriptive string for a plain text pop-up.
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 |
# File '../../src/modules/Nis.rb', line 637 def ProbePackages = "" @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 = Ops.add( , _("The automounter package will be installed.\n") ) end if !Package.Installed("nfs-client") @install_packages = Builtins.add(@install_packages, "nfs-client") end end end |
- (Object) Read
Reads NIS settings from the SCR
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 |
# File '../../src/modules/Nis.rb', line 900 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 = Convert.to_map( SCR.Execute(path(".target.bash_output"), "/bin/ypdomainname") ) @domain = Builtins.deletechars(Ops.get_string(out, "stdout", ""), "\n") @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 |
- (void) Set(settings)
This method returns an undefined value.
Set module data
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 |
# File '../../src/modules/Nis.rb', line 662 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 |
- (Object) SetDomain(new_domain)
Set the NIS domain.
557 558 559 560 561 562 |
# File '../../src/modules/Nis.rb', line 557 def SetDomain(new_domain) @domain = new_domain @domain_changed = true if @domain != @old_domain && @old_domain != "" nil end |
- (Object) SetModified
Function sets internal variable, which indicates, that any settings were modified, to "true"
173 174 175 176 177 |
# File '../../src/modules/Nis.rb', line 173 def SetModified @modified = true nil end |
- (Object) setNetconfigValues
Write the netconfig configuration
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 |
# File '../../src/modules/Nis.rb', line 328 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 |
- (Object) SetServers(servers_s)
Set the servers from a string
192 193 194 195 196 197 198 |
# File '../../src/modules/Nis.rb', line 192 def SetServers(servers_s) @servers = Builtins.filter(Builtins.splitstring(servers_s, " \t")) do |s| s != "" end nil end |
- (Object) ShortSummary
Create a short textual summary with configuration abstract It is called by "authentication/user sources" dialog in yast2-users
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 |
# File '../../src/modules/Nis.rb', line 881 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 |
- (Object) Summary
Returns Html formatted configuration summary
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 |
# File '../../src/modules/Nis.rb', line 815 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 |
- (Object) Touch(really)
A convenient shortcut for setting touched.
628 629 630 631 632 |
# File '../../src/modules/Nis.rb', line 628 def Touch(really) @touched = @touched || really nil end |
- (Object) UsersByLdap
Used in the UI when NIS is turned on.
588 589 590 |
# File '../../src/modules/Nis.rb', line 588 def UsersByLdap @users_by_ldap end |
- (Object) valid_address_nis
Describe a valid address - ip4 or name, names only if nsswitch.conf does not have hosts: nis
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 |
# File '../../src/modules/Nis.rb', line 595 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 |
- (Object) valid_nisdomainname
Returns describe a valid NIS domain name
578 579 580 581 582 583 584 585 |
# File '../../src/modules/Nis.rb', line 578 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 |
- (Object) Write
Saves NIS configuration.
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 |
# File '../../src/modules/Nis.rb', line 1203 def Write return false if !WriteOnly() # dialog label Progress.New( _("Writing NIS Configuration..."), " ", 2, [ # progress stage label _("Stop services"), # progress stage label _("Start services") ], [ # progress step label _("Stopping services..."), # progress step label _("Starting services..."), # final progress step label _("Finished") ], "" ) # help text Wizard.RestoreHelp(_("Writing NIS client settings")) Progress.NextStage if @dhcp_restart # Restart the dhcp client, if it is running, to parse the changed # options Service.RunInitScript("network", "restart-all-dhcp-clients") end Service.Stop("ypbind") Progress.NextStage if @start if Service.Status(@rpc_mapper) != 0 if Service.Start(@rpc_mapper) == false Message.CannotStartService(@rpc_mapper) return false end end Builtins.sleep(1000) # workaround for bug #10428, ypbind restart # FIXME might be wrong with systemd! out = Convert.to_map( SCR.Execute( path(".target.bash_output"), "/etc/init.d/ypbind start", { "TERM" => "raw" } ) ) if Ops.get_integer(out, "exit", 1) == 0 @YpbindErrors = "" else @YpbindErrors = Ops.get_string(out, "stdout", "internal error") # error popup message Report.Error(_("Error while running ypclient.")) return false end # only test for a server if domain not changed if !@domain_changed if SCR.Execute(path(".target.bash"), "/usr/bin/ypwhich >/dev/null") != 0 # error popup message Report.Error(_("NIS server not found.")) return false end end end # remove nscd cache if Package.Installed("nscd") && @modified SCR.Execute(path(".target.bash"), "/usr/sbin/nscd -i passwd") SCR.Execute(path(".target.bash"), "/usr/sbin/nscd -i group") end if @_autofs_allowed && @touched Service.Stop("autofs") Service.Start("autofs") if @_start_autofs end # adapt PAM if needed (bnc#848963) if @touched && Pam.Enabled("unix") if @start Pam.Add("unix-nis") else Pam.Remove("unix-nis") end end SuSEFirewall.ActivateConfiguration # final stage Progress.NextStage true end |
- (Object) WriteNssConf
Configures the name service switch for the user databases according to chosen settings
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 1088 1089 1090 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 1117 1118 1119 1120 1121 |
# File '../../src/modules/Nis.rb', line 1058 def WriteNssConf dbs = ["passwd", "group", "shadow"] nis_dbs = ["services", "netgroup", "aliases"] # Why bother with both compat and nis? # If there's no plus, we don't have to write passwd etc. # And it's supposed to be faster. # But then programs have to reread nsswitch :( #23203 # so we stick with compat. if @start # we want to switch to "compat" Builtins.foreach(dbs) do |db| # what if a db is not mentioned? # We get [] meaning compat, so it's ok to make it explicit db_l = Nsswitch.ReadDb(db) if !Builtins.contains(db_l, "compat") # remove "files" and "nis", if there; db_l = Builtins.filter(db_l) { |s| s != "files" && s != "nis" } # put "compat" and the rest; db_l = Builtins.prepend(db_l, "compat") Nsswitch.WriteDb(db, db_l) end # *_compat may be set to nisplus, nuke it (#16168) db_c = Ops.add(db, "_compat") Nsswitch.WriteDb(db_c, []) end Builtins.y2milestone("Writing pluses") WritePluses() Builtins.foreach(nis_dbs) do |db| db_l = Nsswitch.ReadDb(db) if !Builtins.contains(db_l, "nis") if db == "netgroup" db_l = ["nis"] else db_l = ["files", "nis"] end Nsswitch.WriteDb(db, db_l) end end # not start else Builtins.y2milestone("not writing pluses") have_plus = HavePlus() Builtins.foreach(dbs) do |db| db_l = Nsswitch.ReadDb(db) # remove "nis" if there; db_l = Builtins.filter(db_l) { |s| s != "nis" } # if nothing left, put "files"; # NOT. just remove it, meaning compat. #35299 Nsswitch.WriteDb(db, db_l) end if !have_plus Builtins.foreach(nis_dbs) do |db| db_l = Nsswitch.ReadDb(db) db_l = Builtins.filter(db_l) { |s| s != "nis" } db_l = ["files"] if db_l == [] Nsswitch.WriteDb(db, db_l) end end if !SCR.Write(path(".etc.nsswitch_conf"), nil) Report.Error(Message.ErrorWritingFile("/etc/nsswitch.conf")) return false end true end |
- (Object) WriteOnly
Only write new configuration w/o starting any scripts
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 |
# File '../../src/modules/Nis.rb', line 1125 def WriteOnly if @start if Package.Installed("rpcbind") @rpc_mapper = "rpcbind" else @rpc_mapper = "portmap" end Service.Enable(@rpc_mapper) Service.Enable("ypbind") if !SCR.Write(path(".etc.defaultdomain"), @domain) Report.Error(Message.ErrorWritingFile("/etc/defaultdomain")) return false end # so that dhcpcd cannot restore it SCR.Execute(path(".target.remove"), "/etc/yp.conf.sv") setNetconfigValues SCR.Execute(path(".target.bash"), "/sbin/netconfig update") SCR.Write( path(".sysconfig.ypbind.YPBIND_LOCAL_ONLY"), @local_only ? "yes" : "no" ) SCR.Write( path(".sysconfig.ypbind.YPBIND_BROADCAST"), @global_broadcast ? "yes" : "no" ) SCR.Write( path(".sysconfig.ypbind.YPBIND_BROKEN_SERVER"), @broken_server ? "yes" : "no" ) SCR.Write(path(".sysconfig.ypbind.YPBIND_OPTIONS"), @options) if !SCR.Write(path(".sysconfig.ypbind"), nil) Report.Error(Message.ErrorWritingFile("/etc/sysconfig/ypbind")) return false end SCR.Write( path(".sysconfig.network.config.NETCONFIG_NIS_SETDOMAINNAME"), @policy == "" ? "no" : "yes" ) if !SCR.Write(path(".sysconfig.network.dhcp"), nil) Report.Error(Message.ErrorWritingFile("/etc/sysconfig/network/dhcp")) return false end Autologin.Write(false) else Service.Disable("ypbind") end # TODO do as much as possible if one thing fails # especially WRT nis/autofs independence WriteNssConf() if @_autofs_allowed return false if !Nsswitch.WriteAutofs(@start && @_start_autofs, "nis") if @_start_autofs Service.Enable("autofs") else Service.Disable("autofs") end end progress_orig = Progress.set(false) SuSEFirewall.WriteOnly Progress.set(progress_orig) true end |
- (Object) WritePluses
Add “+” lines to system files so that NIS entries get merged in.
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 |
# File '../../src/modules/Nis.rb', line 1035 def WritePluses files = ["passwd", "shadow", "group"] #don't forget a newline what_to_write = { "passwd" => "+::::::", "group" => "+:::", "shadow" => "+" } Builtins.foreach(files) do |f| Builtins.y2milestone("Writing pluses to %1", f) if !WritePlusesTo( Builtins.sformat("/etc/%1", f), Ops.get_string(what_to_write, f, "") ) next false end end true end |
- (Object) WritePlusesTo(file, what)
If a file does not contain a NIS entry, add it.
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 |
# File '../../src/modules/Nis.rb', line 992 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) ) != 0 ok = false end # TODO only for passwd? # replace the 'nologin' occurence (#40571) elsif SCR.Execute( path(".target.bash"), Builtins.sformat("/bin/grep -q '^%1/sbin/nologin' %2", what, file) ) == 0 ok = SCR.Execute( path(".target.bash"), Builtins.sformat( "/usr/bin/sed -i.YaST2save -e 's@%1/sbin/nologin@%1@' %2", what, file ) ) == 0 end Report.Error(Message.ErrorWritingFile(file)) if !ok ok end |