From 3c315e9391449ea830606cfc1d148e616331de7a Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Sun, 1 Jun 2014 14:39:56 -0700 Subject: [PATCH] strict conversion --- exports/lang/en | 2 + exports/save_export.cgi | 147 +++++++++++++++++++++++++--------------- 2 files changed, 93 insertions(+), 56 deletions(-) diff --git a/exports/lang/en b/exports/lang/en index 967792167..41773baaf 100644 --- a/exports/lang/en +++ b/exports/lang/en @@ -71,6 +71,8 @@ save_euids=UIDs not to trust must be a comma-separated list of numbers or ranges save_egids=GIDs not to trust must be a comma-separated list of numbers or ranges save_pfs='$1' is already exported as a directory save_create_dir=Can't create the directory '$1' +save_eanonuid=Invalid anonymous access username +save_eanongid=Invalid anonymous access group name exports_webnfs=WebNFS clients exports_ngroup=Netgroup $1 diff --git a/exports/save_export.cgi b/exports/save_export.cgi index 3bc2f9767..a84a6c075 100755 --- a/exports/save_export.cgi +++ b/exports/save_export.cgi @@ -2,17 +2,24 @@ # save_export.cgi # Save, create or delete an export +use strict; +use warnings; require './exports-lib.pl'; +our (%text, %in, %config); &ReadParse(); -&lock_file($config{'exports_file'}); -@exps = &list_exports(); +&lock_file($config{'exports_file'}); +my @exps = &list_exports(); + +my %exp; if ($in{'delete'}) { # Deleting some export - $exp = $exps[$in{'idx'}]; + my $exp = $exps[$in{'idx'}]; &delete_export($exp); + %exp = %$exp; } else { + my ($oldexp, %opts); if (!$in{'new'}) { # Get old export $oldexp = $exps[$in{'idx'}]; @@ -49,97 +56,125 @@ else { # Authentication is in the host name # Only sys and krb5 for the moment - local $auth = ""; + my $auth = ""; if ($in{'auth'}) { - if ($in{'sec'} == 0) { $auth = "krb5"; } - if ($in{'sec'} == 1) { $auth = "krb5i"; } - if ($in{'sec'} == 2) { $auth = "krb5p"; } - } - if ($auth ne "") { $exp{'host'} = "gss/$auth"; } + if ($in{'sec'} == 0) { $auth = "krb5"; } + if ($in{'sec'} == 1) { $auth = "krb5i"; } + if ($in{'sec'} == 2) { $auth = "krb5p"; } + } + if ($auth ne "") { + $exp{'host'} = "gss/$auth"; + } - # validate and parse options - delete($opts{'rw'}); delete($opts{'ro'}); + # Validate and parse options + delete($opts{'rw'}); + delete($opts{'ro'}); if ($in{'ro'}) { - $opts{'ro'} = ""; - } else { - $opts{'rw'} = ""; - } + $opts{'ro'} = ""; + } + else { + $opts{'rw'} = ""; + } - delete($opts{'secure'}); delete($opts{'insecure'}); + delete($opts{'secure'}); + delete($opts{'insecure'}); $opts{'insecure'} = "" if ($in{'insecure'}); - delete($opts{'no_subtree_check'}); delete($opts{'subtree_check'}); + delete($opts{'no_subtree_check'}); + delete($opts{'subtree_check'}); $opts{'no_subtree_check'} = "" if ($in{'no_subtree_check'}); - delete($opts{'nohide'}); delete($opts{'hide'}); + delete($opts{'nohide'}); + delete($opts{'hide'}); $opts{'nohide'} = "" if ($in{'nohide'}); delete($opts{'sync'}); delete($opts{'async'}); if ($in{'sync'} == 1) { - $opts{'sync'} = ""; - } elsif ($in{'sync'} == 2) { - $opts{'async'} = ""; - } + $opts{'sync'} = ""; + } + elsif ($in{'sync'} == 2) { + $opts{'async'} = ""; + } - delete($opts{'root_squash'}); delete($opts{'no_root_squash'}); - delete($opts{'all_squash'}); delete($opts{'no_all_squash'}); + delete($opts{'root_squash'}); + delete($opts{'no_root_squash'}); + delete($opts{'all_squash'}); + delete($opts{'no_all_squash'}); $opts{'no_root_squash'} = "" if ($in{'squash'} == 0); $opts{'all_squash'} = "" if ($in{'squash'} == 2); - if ($in{'anonuid_def'}) { delete($opts{'anonuid'}); } + if ($in{'anonuid_def'}) { + delete($opts{'anonuid'}); + } elsif ($in{'anonuid'} =~ /^-?[0-9]+$/) { - $opts{'anonuid'} = $in{'anonuid'}; } - else { $opts{'anonuid'} = getpwnam($in{'anonuid'}); } + $opts{'anonuid'} = $in{'anonuid'}; + } + else { + $opts{'anonuid'} = getpwnam($in{'anonuid'}); + $opts{'anonuid'} || &error($text{'save_eanonuid'}); + } - if ($in{'anongid_def'}) { delete($opts{'anongid'}); } + if ($in{'anongid_def'}) { + delete($opts{'anongid'}); + } elsif ($in{'anongid'} =~ /^-?[0-9]+$/) { - $opts{'anongid'} = $in{'anongid'}; } - else { $opts{'anongid'} = getgrnam($in{'anongid'}); } + $opts{'anongid'} = $in{'anongid'}; + } + else { + $opts{'anongid'} = getgrnam($in{'anongid'}); + $opts{'anongid'} || &error($text{'save_eanongid'}); + } # NFSv2 specific options - delete($opts{'link_relative'}); delete($opts{'link_absolute'}); + delete($opts{'link_relative'}); + delete($opts{'link_absolute'}); delete($opts{'noaccess'}); delete($opts{'squash_uids'}); delete($opts{'squash_gids'}); delete($opts{'map_daemon'}); - if (nfs_max_version("localhost") == 2) { - $opts{'link_relative'} = "" if ($in{'link_relative'}); - $opts{'noaccess'} = "" if ($in{'noaccess'}); + $opts{'link_relative'} = "" if ($in{'link_relative'}); + $opts{'noaccess'} = "" if ($in{'noaccess'}); - if (!$in{'squash_uids_def'}) { + if (!$in{'squash_uids_def'}) { if ($in{'squash_uids'} !~ /^[\d+\-\,]+$/) { - &error($text{'save_euids'}); - } else { - $opts{'squash_uids'} = $in{'squash_uids'}; - $opts{'map_daemon'} = ""; + &error($text{'save_euids'}); + } + else { + $opts{'squash_uids'} = $in{'squash_uids'}; + $opts{'map_daemon'} = ""; + } } - } - if (!$in{'squash_gids_def'}) { + if (!$in{'squash_gids_def'}) { if ($in{'squash_gids'} !~ /^[\d+\-\,]+$/) { - &error($text{'save_egids'}); - } else { - $opts{'squash_gids'} = $in{'squash_gids'}; - $opts{'map_daemon'} = ""; + &error($text{'save_egids'}); + } + else { + $opts{'squash_gids'} = $in{'squash_gids'}; + $opts{'map_daemon'} = ""; + } } - } - } $exp{'options'} = \%opts; + + # Create or update the export if ($in{'new'}) { - if ($in{'via_pfs'} == 1) { - &create_export_via_pfs(\%exp); - } else { - &create_export(\%exp); - } - } else { - &modify_export(\%exp, $oldexp); + if ($in{'via_pfs'} == 1) { + &create_export_via_pfs(\%exp); + } + else { + &create_export(\%exp); + } + } + else { + &modify_export(\%exp, $oldexp); + } } - } &unlock_file($config{'exports_file'}); + if ($in{'delete'}) { - &webmin_log("delete", "export", $exp->{'dir'}, $exp); + &webmin_log("delete", "export", $exp{'dir'}, \%exp); } elsif ($in{'new'}) { &webmin_log("create", "export", $exp{'dir'}, \%exp);