3 # Save, create or delete an export
5 require './exports-lib.pl';
7 &lock_file($config{'exports_file'});
8 @exps = &list_exports();
11 # Deleting some export
12 $exp = $exps[$in{'idx'}];
18 $oldexp = $exps[$in{'idx'}];
19 %opts = %{$oldexp->{'options'}};
22 # Validate and parse inputs
23 &error_setup($text{'save_err'});
24 $exp{'via_pfs'} = ($exp{'pfs'} ne "") ? $in{'via_pfs'} : 0;
25 -d $in{'dir'} || &error(&text('save_edir', $in{'dir'}));
26 $exp{'dir'} = $in{'dir'};
27 $exp{'pfs'} = $in{'pfs'};
28 $exp{'active'} = $in{'active'};
30 if ($in{'mode'} == 0) { $exp{'host'} = "=public"; }
31 elsif ($in{'mode'} == 1) {
32 $in{'netgroup'} =~ /^\S+$/ ||
33 &error($text{'save_enetgroup'});
34 $exp{'host'} = '@'.$in{'netgroup'};
36 elsif ($in{'mode'} == 2) {
37 &check_ipaddress($in{'network'}) ||
38 &error(&text('save_enetwork', $in{'network'}));
39 &check_ipaddress($in{'netmask'}) ||
40 &error(&text('save_enetmask', $in{'netmask'}));
41 $exp{'host'} = $in{'network'}."/".$in{'netmask'};
43 elsif ($in{'mode'} == 3) { $exp{'host'} = ""; }
45 $in{'host'} =~ /\*/ || &to_ipaddress($in{'host'}) ||
46 &error(&text('save_ehost', $in{'host'}));
47 $exp{'host'} = $in{'host'};
50 # Authentication is in the host name
51 # Only sys and krb5 for the moment
54 if ($in{'sec'} == 0) { $auth = "krb5"; }
55 if ($in{'sec'} == 1) { $auth = "krb5i"; }
56 if ($in{'sec'} == 2) { $auth = "krb5p"; }
58 if ($auth ne "") { $exp{'host'} = "gss/$auth"; }
60 # validate and parse options
61 delete($opts{'rw'}); delete($opts{'ro'});
68 delete($opts{'secure'}); delete($opts{'insecure'});
69 $opts{'insecure'} = "" if ($in{'insecure'});
71 delete($opts{'no_subtree_check'}); delete($opts{'subtree_check'});
72 $opts{'no_subtree_check'} = "" if ($in{'no_subtree_check'});
74 delete($opts{'nohide'}); delete($opts{'hide'});
75 $opts{'nohide'} = "" if ($in{'nohide'});
77 delete($opts{'sync'}); delete($opts{'async'});
78 if ($in{'sync'} == 1) {
80 } elsif ($in{'sync'} == 2) {
84 delete($opts{'root_squash'}); delete($opts{'no_root_squash'});
85 delete($opts{'all_squash'}); delete($opts{'no_all_squash'});
86 $opts{'no_root_squash'} = "" if ($in{'squash'} == 0);
87 $opts{'all_squash'} = "" if ($in{'squash'} == 2);
89 if ($in{'anonuid_def'}) { delete($opts{'anonuid'}); }
90 elsif ($in{'anonuid'} =~ /^-?[0-9]+$/) {
91 $opts{'anonuid'} = $in{'anonuid'}; }
92 else { $opts{'anonuid'} = getpwnam($in{'anonuid'}); }
94 if ($in{'anongid_def'}) { delete($opts{'anongid'}); }
95 elsif ($in{'anongid'} =~ /^-?[0-9]+$/) {
96 $opts{'anongid'} = $in{'anongid'}; }
97 else { $opts{'anongid'} = getgrnam($in{'anongid'}); }
99 # NFSv2 specific options
100 delete($opts{'link_relative'}); delete($opts{'link_absolute'});
101 delete($opts{'noaccess'});
102 delete($opts{'squash_uids'});
103 delete($opts{'squash_gids'});
104 delete($opts{'map_daemon'});
106 if (nfs_max_version("localhost") == 2) {
107 $opts{'link_relative'} = "" if ($in{'link_relative'});
108 $opts{'noaccess'} = "" if ($in{'noaccess'});
110 if (!$in{'squash_uids_def'}) {
111 if ($in{'squash_uids'} !~ /^[\d+\-\,]+$/) {
112 &error($text{'save_euids'});
114 $opts{'squash_uids'} = $in{'squash_uids'};
115 $opts{'map_daemon'} = "";
119 if (!$in{'squash_gids_def'}) {
120 if ($in{'squash_gids'} !~ /^[\d+\-\,]+$/) {
121 &error($text{'save_egids'});
123 $opts{'squash_gids'} = $in{'squash_gids'};
124 $opts{'map_daemon'} = "";
129 $exp{'options'} = \%opts;
131 if ($in{'via_pfs'} == 1) {
132 &create_export_via_pfs(\%exp);
134 &create_export(\%exp);
137 &modify_export(\%exp, $oldexp);
140 &unlock_file($config{'exports_file'});
142 &webmin_log("delete", "export", $exp->{'dir'}, $exp);
145 &webmin_log("create", "export", $exp{'dir'}, \%exp);
148 &webmin_log("modify", "export", $exp{'dir'}, \%exp);