2 # Functions for managing the FreeBSD exports file
4 BEGIN { push(@INC, ".."); };
9 # Returns the current exports list
12 local(@rv, $lnum, $_);
13 open(EXP, $config{'exports_file'});
14 $lnum = -1; $index = 0;
17 s/\r|\n//g; # remove newlines
18 s/#.*$//g; # remove comments
20 local @w = split(/[\s=]+/, $_);
22 for($i=0; $i<@w; $i++) {
23 if ($w[$i] =~ /^\//) { push(@{$exp{'dirs'}}, $w[$i]); }
24 elsif ($w[$i] eq "-maproot") { $exp{'maproot'} = $w[++$i]; }
25 elsif ($w[$i] eq "-r") { $exp{'maproot'} = $w[++$i]; }
26 elsif ($w[$i] eq "-mapall") { $exp{'mapall'} = $w[++$i]; }
27 elsif ($w[$i] eq "-kerb") { $exp{'kerb'}++; }
28 elsif ($w[$i] eq "-ro") { $exp{'ro'}++; }
29 elsif ($w[$i] eq "-alldirs") { $exp{'alldirs'}++; }
30 elsif ($w[$i] eq "-network") { $exp{'network'} = $w[++$i]; }
31 elsif ($w[$i] eq "-mask") { $exp{'mask'} = $w[++$i]; }
32 elsif ($w[$i] eq "-public") { $exp{'public'}++; }
33 elsif ($w[$i] eq "-webnfs") { $exp{'webnfs'}++; }
34 elsif ($w[$i] eq "-index") { $exp{'index'} = $w[++$i]; }
35 else { push(@{$exp{'hosts'}}, $w[$i]); }
38 $exp{'index'} = $index++;
45 # create_export(&export)
48 &open_tempfile(EXP, ">> $config{'exports_file'}");
49 &print_tempfile(EXP, &export_line($_[0]));
53 # modify_export(&old, &new)
56 &replace_file_line($config{'exports_file'}, $_[0]->{'line'},
60 # delete_export(&export)
63 &replace_file_line($config{'exports_file'}, $_[0]->{'line'});
66 # export_line(&export)
69 local %exp = %{$_[0]};
70 local $rv = join(' ', @{$exp{'dirs'}});
71 if ($exp{'alldirs'}) { $rv .= " -alldirs"; }
72 if ($exp{'ro'}) { $rv .= " -ro"; }
73 if ($exp{'kerb'}) { $rv .= " -kerb"; }
74 if ($exp{'maproot'}) { $rv .= " -maproot $exp{'maproot'}"; }
75 if ($exp{'mapall'}) { $rv .= " -mapall $exp{'mapall'}"; }
76 if ($exp{'mask'}) { $rv .= " -network $exp{'network'} -mask $exp{'mask'}"; }
77 if ($exp{'public'}) { $rv .= " -public"; }
78 if ($exp{'webnfs'}) { $rv .= " -webnfs"; }
79 if ($exp{'index'}) { $rv .= " -index $exp{'index'}"; }
80 else { $rv .= " ".join(" ", @{$exp{'hosts'}}); }
86 # Attempt to apply the NFS configuration, returning undef on success or an
87 # error message on failure
90 local $out = &backquote_logged("($config{'restart_command'}) </dev/null 2>&1");
92 return "<pre>$out</pre>";