# hpux-lib.pl # Functions for HPUX exports files # list_exports() # Return a list of all the directories currently being exported sub list_exports { local (@rv, $pos, $lnum, $h, $o, $line); return @list_exports_cache if (@list_exports_cache); open(EXP, "<".$config{'exports_file'}); $lnum = 0; while($line = ) { local $slnum = $lnum; $line =~ s/\s+$//g; while($line =~ /\\$/) { # continuation character! $line =~ s/\\$//; $line .= ; $line =~ s/\s+$//g; $lnum++; } if ($line =~ /^(#*)\s*(\/\S*)\s+-(.*)$/) { local %exp; $exp{'active'} = !$1; $exp{'dir'} = $2; # 'host' includes the hole option string! # for describe_host needed, only $exp{'host'} = $3; parse_options($3, $exp{'options'}); $exp{'line'} = $slnum; $exp{'eline'} = $lnum; $exp{'pos'} = $pos++; $exp{'index'} = scalar(@rv); push(@rv, \%exp); } $lnum++; } close(EXP); @list_exports_cache = @rv; return @list_exports_cache; } # make_exports_line([&export]+) sub make_exports_line { local ($options, $line); $options = join_options($_[0]->{'options'}); $line = ($_[0]->{'active'} ? "" : "#").$_[0]->{'dir'}; $line .= ($options ? " -".$options : ""); return $line; } # describe_host(host) # Given a host option string return a human-readable version sub describe_host { local ($desc, %options); &parse_options($_[0], \%options); if (defined($options{"ro"}) && $options{"access"} ne "") { $desc = $text{'index_sel_ro'}; } elsif (defined($options{"ro"}) && !defined($options{"access"})) { $desc = $text{'index_all_ro'}; } elsif ($options{"rw"} ne "") { $desc = $text{'index_ro_rw'}; } elsif (!defined($options{"ro"}) && $options{"access"} ne "") { $desc = $text{'index_sel_rw'}; } elsif (!defined($options{"ro"}) && !defined($options{"rw"}) && !defined($options{"access"})) { $desc = $text{'index_all_rw'}; } if ($options{"root"} ne "") { $desc .= ", "; $desc .= $text{'index_sel_root'}; } return $desc; } # more_detail_fields() sub more_detail_fields { print " ", &hlink($text{'edit_async'}, "async"), "\n"; printf " %s\n", defined($opts{"async"}) ? "checked" : "", $text{'yes'}; printf " %s \n", defined($opts{"async"}) ? "" : "checked", $text{'no'}; } # security_fields() sub security_fields { print "\n"; print " ", &hlink($text{'edit_user_access'}, "user_access"), "\n"; print " ", &hlink($text{'edit_root_access'}, "root_access"), "\n"; print " ", &hlink($text{'edit_anon_access'}, "anon"), "\n"; print "\n"; $fn = ""; $efn = ""; print "\n"; printf " $text{'edit_sel_ro'}
\n", defined($opts{"ro"}) && $opts{"access"} ne "" ? "checked" : ""; printf " $text{'edit_all_ro'}
\n", defined($opts{"ro"}) && !defined($opts{"access"}) ? "checked" : ""; printf " $text{'edit_ro_rw'}
\n", $opts{"rw"} ne "" ? "checked" : ""; printf " $text{'edit_sel_rw'}
\n", !defined($opts{"ro"}) && $opts{"access"} ne "" ? "checked" : ""; printf " $text{'edit_all_rw'}
\n", !defined($opts{"ro"}) && !defined($opts{"rw"}) && !defined($opts{"access"}) ? "checked" : ""; print " \n"; printf " $text{'edit_none'}
\n", defined($opts{"root"}) ? "" : "checked"; print "
"; print "
"; print "
"; printf " $text{'edit_sel_hosts'}
\n", $opts{"root"} ne "" ? "checked" : ""; print " \n"; print " \n"; if ($in{'new'}) { $opts{"anon"} = getpwnam("nobody"); } printf " $text{'edit_anon_noaccess'}
\n", $opts{"anon"} == -1 ? "checked" : ""; if (defined($opts{"anon"}) && $opts{"anon"} != -1) { $anonuser = getpwuid($opts{'anon'}) ? getpwuid($opts{'anon'}) : $opts{'anon'}; } printf "\n", $opts{"anon"} != -1 ? "checked" : ""; print " ", &user_chooser_button("anonnam", 0),"\n"; print "
"; print "
"; print "
"; print "
"; print " \n"; print "\n"; print "\n"; print " $fn$efn\n"; printf " $fn$efn\n", join("\n", split(/:/, $opts{"root"})); print "\n"; } # check_inputs() sub check_inputs { if ($in{user} == 1 || $in{user} == 3 || $in{user} == 4) { &check_hosts($text{'edit_user_access'}, $in{ualist}); @ualist = split(/\s+/, $in{ualist}); } if ($in{root} == 2) { &check_hosts($text{'edit_root_access'}, $in{rtlist}); @rtlist = split(/\s+/, $in{rtlist}); } # Remove from the root list any hosts which not in the user list as well if (($in{user} == 1 || $in{user} == 3 || $in{user} == 4) && $in{root} == 2) { @tmplist = @rtlist; foreach $rth (@tmplist) { if (($idx = &indexof($rth, @ualist)) == -1) { splice(@rtlist, &indexof($rth, @rtlist), 1); } } if (@rtlist == 0) { $in{root} = 1; } } } # set_options() # Fill in the options associative array sub set_options { delete($opts{"ro"}); delete($opts{"rw"}); delete($opts{"access"}); if ($in{user} == 1) { $opts{"ro"} = ""; $opts{"access"} = join(':', @ualist); } elsif ($in{user} == 2) { $opts{"ro"} = ""; } elsif ($in{user} == 3) { $opts{"rw"} = join(':', @ualist); } elsif ($in{user} == 4) { $opts{"access"} = join(':', @ualist); } elsif ($in{user} == 5) { ; } if ($in{root} == 1) { delete($opts{"root"}); } elsif ($in{root} == 2) { $opts{"root"} = join(':', @rtlist); } if ($in{async} == 1) { $opts{"async"} = ""; } else { delete($opts{"async"}); } if ($in{'anon'} == 1) { $opts{"anon"} = -1; } elsif ($in{'anonnam'} =~ /^[0-9\-]+$/) { $opts{"anon"} = $in{"anonnam"}; } elsif (getpwnam($in{"anonnam"})) { $opts{"anon"} = getpwnam($in{"anonnam"}); } else { $opts{"anon"} = -1; } } 1;