JFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3Rbr# suse-linux-lib.pl # NIS functions for SuSE linux NIS client and server $yp_makefile = "/var/yp/Makefile"; $ypserv_conf = "/etc/ypserv.conf"; $pid_file = "/var/run/ypserv.pid"; $rc_config = "/etc/rc.config"; # get_nis_support() # Returns 0 for no support, 1 for client only, 2 for server and 3 for both sub get_nis_support { local $rv; $rv += 1 if (&has_command("ypbind")); $rv += 2 if (&has_command("ypserv")); return $rv; } # get_client_config() # Returns a hash ref containing details of the client's NIS settings sub get_client_config { local $nis; local $rc = &parse_rc_config(); if ($rc->{'START_YPBIND'}->{'value'} eq 'yes') { $nis->{'domain'} = $rc->{'YP_DOMAINNAME'}->{'value'}; local @s = split(/\s+/, $rc->{'YP_SERVER'}->{'value'}); if (@s) { $nis->{'servers'} = \@s; } else { $nis->{'broadcast'} = 1; } } return $nis; } # save_client_config(&config) # Saves and applies the NIS client configuration in the give hash. # Returns an error message if any, or undef on success. sub save_client_config { # Save the config file &open_tempfile(CONF, ">$config{'client_conf'}"); if ($_[0]->{'domain'}) { if ($_[0]->{'broadcast'}) { &print_tempfile(CONF, "domain $_[0]->{'domain'} broadcast\n"); } else { local @s = @{$_[0]->{'servers'}}; &print_tempfile(CONF, "domain $_[0]->{'domain'} server ",shift(@s),"\n"); foreach $s (@s) { &print_tempfile(CONF, "ypserver $s\n"); } } } &close_tempfile(CONF); # Stop the init script local $init = &init_script("ypbind"); if (!-r $init) { $init = &init_script("ypclient"); } &system_logged("$init stop >/dev/null 2>&1"); # Save rc.config local $rc = &parse_rc_config(); if ($_[0]->{'domain'}) { &save_rc_config($rc, "START_YPBIND", "yes"); &save_rc_config($rc, "YP_DOMAINNAME", $_[0]->{'domain'}); if ($_[0]->{'broadcast'}) { &save_rc_config($rc, "YP_SERVER", ""); } else { &save_rc_config($rc, "YP_SERVER", join(" ", @{$_[0]->{'servers'}})); } &init::enable_at_boot("ypbind"); } else { &save_rc_config($rc, "START_YPBIND", "no"); } # Start the init script if ($_[0]->{'domain'}) { local $out = &backquote_logged("$init start 2>&1"); if ($?) { return "
$out
"; } } return undef; } @nis_files = ( "passwd", "shadow", "group", "gshadow", "adjunct", "aliases", "ethers", "bootparams", "hosts", "networks", "printcap", "protocols", "publickeys", "rpc", "services", "netgroup", "netid", "auto_master", "auto_home", "auto_local", "timezone", "locale", "netmasks" ); @nis_tables = ( "passwd", "group", "hosts", "rpc", "services", "netid", "protocols", "netgrp", "mail", "shadow", "publickey", "networks", "ethers", "bootparams", "printcap", "amd.home", "auto.master", "auto.home", "auto.local", "passwd.adjunct", "timezone", "locale", "netmasks" ); # show_server_config() # Display a form for editing NIS server options sub show_server_config { local ($var, $rule) = &parse_yp_makefile(); local $rc = &parse_rc_config(); if ($var->{'YPPWDDIR'}->{'value'} =~ /^\$\(shell.*\s(\S+)\)$/) { # Value comes from some rc.config file! local $yrc = &parse_rc_config($1); $var->{'YPPWDDIR'}->{'value'} = $yrc->{'YPPWD_SRCDIR'}->{'value'}; } local $boot = &init::action_status("ypserv") == 2 && $rc->{'START_YPSERV'}->{'value'} eq 'yes'; print " $text{'server_boot'}\n"; printf " %s\n", $boot ? 'checked' : '', $text{'yes'}; printf " %s\n", $boot ? '' : 'checked', $text{'no'}; local $dom = $var->{'LOCALDOMAIN'}->{'value'}; print "$text{'server_domain'}\n"; printf " %s\n", $dom =~ /`.*domainname`/ ? 'checked' : '', $text{'server_domain_auto'}; printf "\n", $dom =~ /`.*domainname`/ ? '' : 'checked'; printf " \n", $dom =~ /`.*domainname`/ ? '' : $dom; print " $text{'server_type'}\n"; printf " %s\n", $config{'slave'} ? '' : 'checked', $text{'server_master'}; printf " %s\n", $config{'slave'} ? 'checked' : '', $text{'server_slave'}; printf " \n", $config{'slave'}; print "

\n"; print "\n"; print "\n"; print "
$text{'server_mheader'}
\n"; print "\n"; printf "\n", $var->{'B'}->{'value'} eq '-b' ? '' : 'checked', $text{'no'}; print "\n"; printf "\n", $var->{'NOPUSH'}->{'value'} eq 'true' ? 'checked' : '', $text{'no'}; local %inall; map { $inall{$_}++ } split(/\s+/, $rule->{'all'}->{'value'}); print "\n"; print "\n"; print "\n"; printf "\n", $var->{'MINUID'}->{'value'}; print "\n"; printf "\n", $var->{'MINGID'}->{'value'}; print "\n"; open(SLAVES, ") { s/\s//g; push(@slaves, $_) if ($_); } close(SLAVES); printf "\n", join(" ", @slaves); print "
$text{'server_dns'} %s\n", $var->{'B'}->{'value'} eq '-b' ? 'checked' : '', $text{'yes'}; printf " %s$text{'server_push'} %s\n", $var->{'NOPUSH'}->{'value'} eq 'true' ? '' : 'checked', $text{'yes'}; printf " %s
$text{'server_tables'}$text{'server_minuid'}
$text{'server_mingid'}
$text{'server_slaves'}

\n"; print "\n"; print "\n"; print "
$text{'server_fheader'}
\n"; local $i = 0; foreach $t (@nis_files) { local $f = &expand_vars($var->{uc($t)}->{'value'}, $var); next if (!$f); print "\n" if ($i%2 == 0); print "\n"; print "\n"; print "\n" if ($i++%2 == 1); } } # parse_server_config() # Parse and save the NIS server options sub parse_server_config { local ($var, $rule) = &parse_yp_makefile(); local $rc = &parse_rc_config(); if ($var->{'YPPWDDIR'}->{'value'} =~ /^\$\(shell.*\s(\S+)\)$/) { # Value comes from some rc.config file! local $yrc = &parse_rc_config($1); $var->{'YPPWDDIR'}->{'value'} = $yrc->{'YPPWD_SRCDIR'}->{'value'}; } $in{'minuid'} =~ /^\d+$/ || &error($text{'server_eminuid'}); $in{'mingid'} =~ /^\d+$/ || &error($text{'server_emingid'}); $in{'domain_auto'} || $in{'domain'} =~ /^[A-Za-z0-9\.\-]+$/ || &error($text{'server_edomain'}); $in{'type'} || &to_ipaddress($in{'slave'}) || &to_ip6address($in{'slave'}) || &error($text{'server_eslave'}); &update_makefile($var->{'MINUID'}, $in{'minuid'}); &update_makefile($var->{'MINGID'}, $in{'mingid'}); &update_makefile($var->{'NOPUSH'}, $in{'nopush'}); &update_makefile($var->{'B'}, $in{'b'}); &update_makefile($var->{'LOCALDOMAIN'}, $in{'domain_auto'} ? "`domainname`" : $in{'domain'}); &update_makefile($rule->{'all'}, join(" ", split(/\0/, $in{'tables'})), ""); foreach $t (@nis_files) { local $old = &expand_vars($var->{uc($t)}->{'value'}, $var); next if (!$old); if ($old ne $in{$t}) { $in{$t} =~ /\S/ || &error(&text('server_efile', $text{"desc_$t"})); &update_makefile($var->{uc($t)}, $in{$t}); } } &flush_file_lines(); &open_tempfile(SLAVES, ">/var/yp/ypservers"); foreach $s (split(/\s+/, $in{'slaves'})) { &print_tempfile(SLAVES, "$s\n"); } &close_tempfile(SLAVES); local $init1 = &init_script("ypserv"); local $init2 = &init_script("yppasswdd"); &system_logged("$init1 stop >/dev/null 2>&1"); &system_logged("$init2 stop >/dev/null 2>&1"); if ($in{'boot'}) { &init::enable_at_boot("ypserv"); &init::enable_at_boot("yppasswdd"); &save_rc_config($rc, "START_YPSERV", "yes"); &save_rc_config($rc, "START_YPPASSWDD", "yes"); } else { &save_rc_config($rc, "START_YPSERV", "no"); &save_rc_config($rc, "START_YPPASSWDD", "no"); } if ($in{'boot'}) { &system_logged("$init1 start >/dev/null 2>&1"); &system_logged("$init2 start >/dev/null 2>&1"); } if ($in{'type'}) { # Master server delete($config{'slave'}); &apply_table_changes() if ($in{'boot'}); } else { $out = &backquote_logged("/usr/lib/yp/ypinit -s $in{'slave'} 2>&1"); if ($?) { &error("$out"); } $config{'slave'} = $in{'slave'}; } &write_file("$module_config_directory/config", \%config); } # get_server_mode() # Returns 0 if the NIS server is inactive, 1 if active as a master, or 2 if # active as a slave. sub get_server_mode { if (&init::action_status("ypserv") != 2) { return 0; } elsif ($config{'slave'}) { return 2; } else { return 1; } } # list_nis_tables() # Returns a list of structures of all NIS tables sub list_nis_tables { local ($var, $rule) = &parse_yp_makefile(); if ($var->{'YPPWDDIR'}->{'value'} =~ /^\$\(shell.*\s(\S+)\)$/) { # Value comes from some rc.config file! local $yrc = &parse_rc_config($1); $var->{'YPPWDDIR'}->{'value'} = $yrc->{'YPPWD_SRCDIR'}->{'value'}; } local @rv; local $dom = $var->{'LOCALDOMAIN'}->{'value'}; chop($dom = `domainname`) if ($dom =~ /`.*domainname`/); local %file; map { $file{uc($_)} = &expand_vars($var->{uc($_)}->{'value'}, $var) } @nis_files; local @all = split(/\s+/, $rule->{'all'}->{'value'}); foreach $t (@all) { local $table = { 'table' => $t, 'index' => scalar(@rv), 'domain' => $dom }; if ($t eq "passwd") { if ($var->{'MERGE_PASSWD'}->{'value'} eq 'true') { $table->{'type'} = 'passwd_shadow'; $table->{'files'} = [ $file{'PASSWD'}, $file{'SHADOW'} ]; } elsif (&indexof('shadow', @all) >= 0) { # Show separate shadow and passwd tables as one table $table->{'type'} = 'passwd_shadow_full'; $table->{'files'} = [ $file{'PASSWD'}, $file{'SHADOW'} ]; @all = grep { $_ ne 'shadow' } @all; } else { $table->{'type'} = 'passwd'; $table->{'files'} = [ $file{'PASSWD'} ]; } } elsif ($t eq "group") { if ($var->{'MERGE_GROUP'}->{'value'} eq 'true') { $table->{'type'} = 'group_shadow'; $table->{'files'} = [ $file{'GROUP'}, $file{'GSHADOW'} ]; } else { $table->{'type'} = 'group'; $table->{'files'} = [ $file{'GROUP'} ]; } } elsif ($t eq "netgrp") { $table->{'type'} = "netgroup"; $table->{'files'} = [ $file{'NETGROUP'} ]; } elsif ($t eq "mail") { $table->{'type'} = "aliases"; $table->{'files'} = [ $file{'ALIASES'} ]; } else { $table->{'type'} = $t; $table->{'files'} = [ $file{uc($t)} ]; } push(@rv, $table); } return @rv; } # apply_table_changes() # Do whatever is necessary for the table text files to be loaded into # the NIS server sub apply_table_changes { &system_logged("(cd /var/yp ; make) >/dev/null 2>&1 ) { s/\r|\n//g; s/#.*$//g; if (/([^=\s]+)="(.*)"/) { $rc->{$1} = { 'value' => $2, 'line' => $lnum }; } elsif (/([^=\s]+)=(\S+)/) { $rc->{$1} = { 'value' => $2, 'line' => $lnum }; } $lnum++; } close(CONF); return $rc; } # save_rc_config(&config, directive, value) sub save_rc_config { local $old = $_[0]->{$_[1]}; local $line = "$_[1]=\"$_[2]\"\n"; if ($old) { &replace_file_line($rc_config, $old->{'line'}, $line); } else { &open_tempfile(RC, ">>$rc_config"); &print_tempfile(RC, $line); &close_tempfile(RC); } } sub extra_config_files { return ( $rc_config, "/var/yp/ypservers" ); } 1;
",&text('server_file', $text{"desc_$t"} ? $text{"desc_$t"} : $t),"