\n";
local %inall;
local @all = split(/\s+/, $rule->{'all'}->{'value'});
map { $inall{$_}++ } @all;
print " | $text{'server_tables'} | \n";
print " | \n";
print "$text{'server_dns'} | \n";
printf " %s\n",
$var->{'B'}->{'value'} eq '-b' ? 'checked' : '', $text{'yes'};
printf " %s | \n",
$var->{'B'}->{'value'} eq '-b' ? '' : 'checked', $text{'no'};
print " | $text{'server_push'} | \n";
printf " %s\n",
$var->{'NOPUSH'}->{'value'} eq 'true' ? '' : 'checked', $text{'yes'};
printf " %s | \n",
$var->{'NOPUSH'}->{'value'} eq 'true' ? 'checked' : '', $text{'no'};
print " | $text{'server_dir'} | \n";
printf " %s | \n",
$var->{'DIR'}->{'value'}, &file_chooser_button("dir", 0);
print " | $text{'server_pwdir'} | \n";
printf " %s | \n",
$var->{'PWDIR'}->{'value'}, &file_chooser_button("pwdir", 0);
}
# parse_server_config()
# Parse and save the NIS server options
sub parse_server_config
{
local ($var, $rule) = &parse_yp_makefile();
$in{'domain_def'} || $in{'domain'} =~ /^[A-Za-z0-9\.\-\_]+$/ ||
&error(&text('server_edomain', $in{'domain'}));
if ($in{'boot'} && $in{'domain_def'}) {
&error($text{'server_ebootdom'});
}
$in{'type'} || &to_ipaddress($in{'slave'}) ||
&to_ip6address($in{'slave'}) || &error($text{'server_eslave'});
-d $in{'dir'} || &error($text{'server_edir'});
-d $in{'pwdir'} || &error($text{'server_epwdir'});
&update_makefile($var->{'NOPUSH'}, $in{'nopush'});
&update_makefile($var->{'B'}, $in{'b'});
&update_makefile($rule->{'all'}, join(" ", split(/\0/, $in{'tables'})), "");
&update_makefile($var->{'DIR'}, $in{'dir'});
&update_makefile($var->{'PWDIR'}, $in{'pwdir'});
&flush_file_lines();
if ($in{'domain_def'}) {
unlink("/etc/defaultdomain");
&system_logged("domainname \"\" >/dev/null 2>&1");
}
else {
local $old = `domainname`; chop($old);
&open_tempfile(DOM, ">/etc/defaultdomain");
&print_tempfile(DOM, "$in{'domain'}\n");
&close_tempfile(DOM);
&system_logged("domainname \"$in{'domain'}\" >/dev/null 2>&1");
if ($in{'boot'}) {
# Create the domain directory
mkdir("/var/yp/$in{'domain'}", 0755);
&system_logged("rm -f /var/yp/*.time"); # force a remake
}
}
if ($in{'type'}) {
# Master server
delete($config{'slave'});
&apply_table_changes()
if (!$in{'domain_def'} && -d "/var/yp/$in{'domain'}");
}
else {
local $temp = &transname();
open(TEMP, ">$temp");
print TEMP "n\ny\n";
close(TEMP);
$out = &backquote_logged("/usr/sbin/ypinit -s $in{'slave'} <$temp 2>&1");
unlink($temp);
if ($?) { &error("$out"); }
$config{'slave'} = $in{'slave'};
}
&write_file("$module_config_directory/config", \%config);
&system_logged("(/usr/lib/netsvc/yp/ypstop || /etc/init.d/yp stop) >/dev/null 2>&1");
&system_logged("(/usr/lib/netsvc/yp/ypstart || /etc/init.d/yp start) >/dev/null 2>&1");
}
# 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 $dom = `domainname`; chop($dom);
return !$dom ? 0 : $config{'slave'} ? 2 : 1;
}
# parse_yp_makefile()
# Returns hashes of makefile variables and rules
sub parse_yp_makefile
{
# First parse joined lines
local $lnum = 0;
local (@lines, $llast);
open(MAKE, "<".$yp_makefile);
while() {
s/\r|\n//g;
local $slash = (s/\\$//);
s/#.*$//;
if ($llast) {
$llast->{'value'} .= " $_";
$llast->{'eline'} = $lnum;
}
else {
push(@lines, { 'value' => $_,
'line' => $lnum,
'eline' => $lnum });
}
$llast = $slash ? $lines[$#lines] : undef;
$lnum++;
}
close(MAKE);
# Then look for variables and rules
local ($i, %var, %rule);
for($i=0; $i<@lines; $i++) {
if ($lines[$i]->{'value'} =~ /^\s*(\S+)\s*=\s*(.*)/) {
# Found a variable
$var{$1} = { 'name' => $1,
'value' => $2,
'type' => 0,
'line' => $lines[$i]->{'line'},
'eline' => $lines[$i]->{'eline'} };
}
elsif ($lines[$i]->{'value'} =~ /^\s*(\S+):\s*(.*)/) {
# Found a makefile rule
$rule{$1} = { 'name' => $1,
'value' => $2,
'type' => 1,
'code' => $lines[$i+1]->{'value'},
'line' => $lines[$i]->{'line'},
'eline' => $lines[$i+1]->{'eline'} };
$i++;
}
}
return ( \%var, \%rule );
}
# expand_vars(string, &vars)
sub expand_vars
{
local $rv = $_[0];
while($rv =~ /^(.*)\$\(([A-Za-z0-9_]+)\)(.*)$/) {
$rv = $1.$_[1]->{$2}->{'value'}.$3;
}
return $rv;
}
# update_makefile(&old, value, [value]);
sub update_makefile
{
local $lref = &read_file_lines($yp_makefile);
local @n;
if ($_[0]->{'type'} == 0) {
@n = ( "$_[0]->{'name'} = $_[1]" );
}
else {
@n = ( "$_[0]->{'name'}: $_[1]", $_[2] );
}
splice(@$lref, $_[0]->{'line'}, $_[0]->{'eline'} - $_[0]->{'line'} + 1, @n);
}
# apply_table_changes()
# Do whatever is necessary for the table text files to be loaded into
# the NIS server
sub apply_table_changes
{
if ($0 =~ /save_(\S+).cgi/) {
# Try to make just one table
local $table = $1;
local $ex = &system_logged("(cd /var/yp ; /usr/ccs/bin/make $table) >/dev/null 2>&1 /dev/null 2>&1 {'all'}->{'value'});
foreach $t (@all) {
local $table = { 'table' => $t,
'index' => scalar(@rv),
'domain' => $dom };
local $rt = $rule->{"$t.time"};
local @files = split(/\s+/, $rt->{'value'});
@files = map { &expand_vars($_, $var) } @files;
$table->{'files'} = \@files;
$table->{'type'} = $t eq 'passwd' && @files > 1 ? 'passwd_shadow' :
$t;
push(@rv, $table);
}
return @rv;
}
sub show_server_security
{
}
sub parse_server_security
{
&system_logged("(/usr/lib/netsvc/yp/ypstop || /etc/init.d/yp stop) >/dev/null 2>&1");
&system_logged("(/usr/lib/netsvc/yp/ypstart || /etc/init.d/yp start) >/dev/null 2>&1");
}
sub extra_config_files
{
local @rv = ( "/etc/defaultdomain" );
local $conf = &get_client_config();
if ($conf->{'domain'}) {
push(@rv, "$binding_dir/$conf->{'domain'}/ypservers");
}
return @rv;
}
1;
|