3 # Save, create or delete an export
5 require './exports-lib.pl';
7 &lock_file($config{'exports_file'});
8 @exps = &list_exports();
9 local $nfsv = nfs_max_version("localhost");
12 # Deleting some export
13 $exp = $exps[$in{'idx'}];
19 $oldexp = $exps[$in{'idx'}];
20 %opts = %{$oldexp->{'options'}};
23 # Validate and parse inputs
24 &error_setup($text{'save_err'});
25 $exp{'via_pfs'} = ($exp{'pfs'} ne "") ? $in{'via_pfs'} : 0;
26 -d $in{'dir'} || &error(&text('save_edir', $in{'dir'}));
27 $exp{'dir'} = $in{'dir'};
28 $exp{'pfs'} = $in{'pfs'};
29 $exp{'active'} = $in{'active'};
31 if ($in{'mode'} == 0) { $exp{'host'} = "=public"; }
32 elsif ($in{'mode'} == 1) {
33 $in{'netgroup'} =~ /^\S+$/ ||
34 &error($text{'save_enetgroup'});
35 $exp{'host'} = '@'.$in{'netgroup'};
37 elsif ($in{'mode'} == 2) {
38 &check_ipaddress($in{'network'}) ||
39 &error(&text('save_enetwork', $in{'network'}));
40 &check_ipaddress($in{'netmask'}) ||
41 &error(&text('save_enetmask', $in{'netmask'}));
42 $exp{'host'} = $in{'network'}."/".$in{'netmask'};
44 elsif ($in{'mode'} == 3) { $exp{'host'} = ""; }
45 #Support for IPv6 address and prefix
46 elsif ($in{'mode'} == 6){
47 &check_ip6address($in{'address'}) ||
48 &error(&text('save_eaddress', $in{'address'}));
49 if(!($in{'prefix'}>0 && $in{'prefix'}<129)){
50 &error(&text('save_eprefix', $in{'prefix'}));
52 $exp{'host'} = $in{'address'}."/".$in{'prefix'};
55 $in{'host'} =~ /\*/ || &to_ipaddress($in{'host'}) ||
56 &error(&text('save_ehost', $in{'host'}));
57 $exp{'host'} = $in{'host'};
60 # Authentication is in the host name
61 # with support for spkm-3 and lipkey (experimental in NFSv4)
63 @sec_to_name=('sys','krb5','krb5i','krb5p','spkm-3','spkm-3i','spkm-3p','lipkey','lipkeyi','lipkeyp');
65 $string=$in{'the_flav'};
66 @sec_flav= split(/,/, $in{'the_flav'});
68 foreach $nb (@sec_flav){
69 if($nb==0){ $str_flav .= "*,";}
70 else{ $str_flav .= "gss/$sec_to_name[$nb],";}
73 $str_flav="" if($in{'nfsv'}<4);
75 if ($exp{'host'} ne "" && $str_flav ne ""){
76 $exp{'host'}=$str_flav.":".$exp{'host'};
78 elsif ($exp{'host'} eq "" && $str_flav eq ""){
81 elsif ($exp{'host'} eq ""){
82 $exp{'host'}=$str_flav;
85 # validate and parse options
86 delete ($opts{'fsid'});
87 $opts{'fsid'} = "0" if($in{'is_pfs'});
89 delete($opts{'rw'}); delete($opts{'ro'});
95 delete($opts{'secure'}); delete($opts{'insecure'});
96 $opts{'insecure'} = "" if ($in{'insecure'});
98 delete($opts{'no_subtree_check'}); delete($opts{'subtree_check'});
99 $opts{'no_subtree_check'} = "" if ($in{'no_subtree_check'});
101 delete($opts{'nohide'}); delete($opts{'hide'});
102 $opts{'nohide'} = "" if ($in{'nohide'});
104 delete($opts{'sync'}); delete($opts{'async'});
111 delete($opts{'root_squash'}); delete($opts{'no_root_squash'});
112 delete($opts{'all_squash'}); delete($opts{'no_all_squash'});
113 $opts{'no_root_squash'} = "" if ($in{'squash'} == 0);
114 $opts{'all_squash'} = "" if ($in{'squash'} == 2);
116 if ($in{'anonuid_def'}) { delete($opts{'anonuid'}); }
117 elsif ($in{'anonuid'} =~ /^-?[0-9]+$/) {
118 $opts{'anonuid'} = $in{'anonuid'}; }
119 else { $opts{'anonuid'} = getpwnam($in{'anonuid'}); }
121 if ($in{'anongid_def'}) { delete($opts{'anongid'}); }
122 elsif ($in{'anongid'} =~ /^-?[0-9]+$/) {
123 $opts{'anongid'} = $in{'anongid'}; }
124 else { $opts{'anongid'} = getgrnam($in{'anongid'}); }
126 # NFSv2 specific options ---
127 delete($opts{'link_relative'}); delete($opts{'link_absolute'});
128 delete($opts{'noaccess'});
129 delete($opts{'squash_uids'});
130 delete($opts{'squash_gids'});
131 delete($opts{'map_daemon'});
133 if (nfs_max_version("localhost") == 2) {
134 $opts{'link_relative'} = "" if ($in{'link_relative'});
135 $opts{'noaccess'} = "" if ($in{'noaccess'});
137 if (!$in{'squash_uids_def'}) {
138 if ($in{'squash_uids'} !~ /^[\d+\-\,]+$/) {
139 &error($text{'save_euids'});
141 $opts{'squash_uids'} = $in{'squash_uids'};
142 $opts{'map_daemon'} = "";
146 if (!$in{'squash_gids_def'}) {
147 if ($in{'squash_gids'} !~ /^[\d+\-\,]+$/) {
148 &error($text{'save_egids'});
150 $opts{'squash_gids'} = $in{'squash_gids'};
151 $opts{'map_daemon'} = "";
157 $exp{'options'} = \%opts;
159 if ($in{'is_pfs'} || $nfsv<4) {
160 &create_export(\%exp);
162 &create_export_in_root(\%exp);
165 &modify_export(\%exp, $oldexp);
168 &unlock_file($config{'exports_file'});
170 &webmin_log("delete", "export", $exp->{'dir'}, $exp);
173 &webmin_log("create", "export", $exp{'dir'}, \%exp);
176 &webmin_log("modify", "export", $exp{'dir'}, \%exp);