| $text{'server_domain'} | \n";
printf "".
" %s\n",
$d ? '' : 'checked', $text{'server_none'};
printf "\n",
$d ? 'checked' : '';
print " | \n";
local @conf = &parse_nisupdate_conf(
$d ? "$nis_config_dir/$d/.nisupdate.conf"
: "nisupdate.conf");
print "$text{'server_tables'} | \n";
print " |
\n";
$n++;
}
}
# parse_server_config()
# Parse and save the NIS server options
sub parse_server_config
{
local ($n, $anydomains);
for($n=0; defined($in{"old_$n"}); $n++) {
# Update the domain name directory
$in{"domain_def_$n"} || $in{"domain_$n"} =~ /^[A-Za-z0-9\.\-]+$/ ||
&error(&text('server_edomain', $in{"domain_$n"}));
local $domain = $in{"domain_def_$n"} ? undef : $in{"domain_$n"};
local $old = $in{"old_$n"};
if (!$old && !$domain) {
# No domain before, and none chosen
next;
}
elsif (!$old && $domain) {
# New domain added
mkdir("$nis_config_dir/$domain", 0755);
&system_logged("cp nisupdate.conf ".
"$nis_config_dir/$domain/.nisupdate.conf");
}
elsif ($old && !$domain) {
# Domain taken away
&system_logged("rm -rf $nis_config_dir/$old");
next;
}
elsif ($old ne $domain) {
# Domain renamed
&rename_logged("$nis_config_dir/$old",
"$nis_config_dir/$domain");
}
$anydomains++;
# Update the config file
local $file = "$nis_config_dir/$domain/.nisupdate.conf";
local @conf = &parse_nisupdate_conf($file);
local $lref = &read_file_lines($file);
local %table;
map { $table{$_}++ } split(/\0/, $in{"tables_$n"});
foreach $c (@conf) {
if ($c->{'active'} && !$table{$c->{'table'}}) {
# Need to deactivate a table
splice(@$lref, $c->{'line'},
$c->{'eline'} - $c->{'line'} + 1,
map { "#$_" } @{$c->{'data'}});
}
elsif (!$c->{'active'} && $table{$c->{'table'}}) {
# Need to activate a table
splice(@$lref, $c->{'line'},
$c->{'eline'} - $c->{'line'} + 1,
@{$c->{'data'}});
}
}
&flush_file_lines();
}
# Start the NIS server and rebuild maps if needed
if ($in{'boot'}) {
&init::enable_at_boot("nis-server");
}
else {
&init::disable_at_boot("nis-server");
}
local $init = &init_script("nis-server");
&system_logged("$init stop >/dev/null 2>&1");
if ($anydomains && $in{'boot'}) {
&system_logged("$init start >/dev/null 2>&1");
}
&apply_table_changes();
}
# 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
{
local $boot = &init::action_status("nis-server");
local $dc;
opendir(DIR, $nis_config_dir);
foreach $f (readdir(DIR)) {
$dc++ if ($f !~ /^\./ && -r "$nis_config_dir/$f/.nisupdate.conf");
}
closedir(DIR);
if ($boot != 2 || !$dc) {
return 0;
}
else {
return 1;
}
}
# parse_nisupdate_conf(file)
sub parse_nisupdate_conf
{
local @rv;
local $lnum = 0;
open(CONF, "<".$_[0]);
while(