PageRenderTime 27ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/exports-nfs4/save_export.cgi

http://github.com/webmin/webmin
Perl | 179 lines | 145 code | 22 blank | 12 comment | 51 complexity | e52b4a709d0d0f7c64e6a892fe454c57 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-3.0, CC-BY-SA-3.0
  1. #!/usr/bin/perl
  2. # save_export.cgi
  3. # Save, create or delete an export
  4. require './exports-lib.pl';
  5. &ReadParse();
  6. &lock_file($config{'exports_file'});
  7. @exps = &list_exports();
  8. local $nfsv = nfs_max_version("localhost");
  9. if ($in{'delete'}) {
  10. # Deleting some export
  11. $exp = $exps[$in{'idx'}];
  12. &delete_export($exp);
  13. }
  14. else {
  15. if (!$in{'new'}) {
  16. # Get old export
  17. $oldexp = $exps[$in{'idx'}];
  18. %opts = %{$oldexp->{'options'}};
  19. }
  20. # Validate and parse inputs
  21. &error_setup($text{'save_err'});
  22. $exp{'via_pfs'} = ($exp{'pfs'} ne "") ? $in{'via_pfs'} : 0;
  23. -d $in{'dir'} || &error(&text('save_edir', $in{'dir'}));
  24. $exp{'dir'} = $in{'dir'};
  25. $exp{'pfs'} = $in{'pfs'};
  26. $exp{'active'} = $in{'active'};
  27. if ($in{'mode'} == 0) { $exp{'host'} = "=public"; }
  28. elsif ($in{'mode'} == 1) {
  29. $in{'netgroup'} =~ /^\S+$/ ||
  30. &error($text{'save_enetgroup'});
  31. $exp{'host'} = '@'.$in{'netgroup'};
  32. }
  33. elsif ($in{'mode'} == 2) {
  34. &check_ipaddress($in{'network'}) ||
  35. &error(&text('save_enetwork', $in{'network'}));
  36. &check_ipaddress($in{'netmask'}) ||
  37. &error(&text('save_enetmask', $in{'netmask'}));
  38. $exp{'host'} = $in{'network'}."/".$in{'netmask'};
  39. }
  40. elsif ($in{'mode'} == 3) { $exp{'host'} = ""; }
  41. #Support for IPv6 address and prefix
  42. elsif ($in{'mode'} == 6){
  43. &check_ip6address($in{'address'}) ||
  44. &error(&text('save_eaddress', $in{'address'}));
  45. if(!($in{'prefix'}>0 && $in{'prefix'}<129)){
  46. &error(&text('save_eprefix', $in{'prefix'}));
  47. }
  48. $exp{'host'} = $in{'address'}."/".$in{'prefix'};
  49. }
  50. else{
  51. $in{'host'} =~ /\*/ || &to_ipaddress($in{'host'}) ||
  52. &error(&text('save_ehost', $in{'host'}));
  53. $exp{'host'} = $in{'host'};
  54. }
  55. # Authentication is in the host name
  56. # with support for spkm-3 and lipkey (experimental in NFSv4)
  57. @sec_to_name=('sys','krb5','krb5i','krb5p','spkm-3','spkm-3i','spkm-3p','lipkey','lipkeyi','lipkeyp');
  58. $string=$in{'the_flav'};
  59. @sec_flav= split(/,/, $in{'the_flav'});
  60. $str_flav="";
  61. foreach $nb (@sec_flav){
  62. if($nb==0){ $str_flav .= "*,";}
  63. else{ $str_flav .= "gss/$sec_to_name[$nb],";}
  64. }
  65. chop($str_flav);
  66. $str_flav="" if($in{'nfsv'}<4);
  67. if ($exp{'host'} ne "" && $str_flav ne ""){
  68. $exp{'host'}=$str_flav.":".$exp{'host'};
  69. }
  70. elsif ($exp{'host'} eq "" && $str_flav eq ""){
  71. $exp{'host'}="*";
  72. }
  73. elsif ($exp{'host'} eq ""){
  74. $exp{'host'}=$str_flav;
  75. }
  76. # validate and parse options
  77. delete ($opts{'fsid'});
  78. $opts{'fsid'} = "0" if($in{'is_pfs'});
  79. delete($opts{'rw'}); delete($opts{'ro'});
  80. if ($in{'ro'}) {
  81. $opts{'ro'} = "";
  82. } else {
  83. $opts{'rw'} = "";
  84. }
  85. delete($opts{'secure'}); delete($opts{'insecure'});
  86. $opts{'insecure'} = "" if ($in{'insecure'});
  87. delete($opts{'no_subtree_check'}); delete($opts{'subtree_check'});
  88. $opts{'no_subtree_check'} = "" if ($in{'no_subtree_check'});
  89. delete($opts{'nohide'}); delete($opts{'hide'});
  90. $opts{'nohide'} = "" if ($in{'nohide'});
  91. delete($opts{'sync'}); delete($opts{'async'});
  92. if ($in{'sync'}) {
  93. $opts{'sync'} = "";
  94. } else {
  95. $opts{'async'} = "";
  96. }
  97. delete($opts{'root_squash'}); delete($opts{'no_root_squash'});
  98. delete($opts{'all_squash'}); delete($opts{'no_all_squash'});
  99. $opts{'no_root_squash'} = "" if ($in{'squash'} == 0);
  100. $opts{'all_squash'} = "" if ($in{'squash'} == 2);
  101. if ($in{'anonuid_def'}) { delete($opts{'anonuid'}); }
  102. elsif ($in{'anonuid'} =~ /^-?[0-9]+$/) {
  103. $opts{'anonuid'} = $in{'anonuid'}; }
  104. else { $opts{'anonuid'} = getpwnam($in{'anonuid'}); }
  105. if ($in{'anongid_def'}) { delete($opts{'anongid'}); }
  106. elsif ($in{'anongid'} =~ /^-?[0-9]+$/) {
  107. $opts{'anongid'} = $in{'anongid'}; }
  108. else { $opts{'anongid'} = getgrnam($in{'anongid'}); }
  109. # NFSv2 specific options ---
  110. delete($opts{'link_relative'}); delete($opts{'link_absolute'});
  111. delete($opts{'noaccess'});
  112. delete($opts{'squash_uids'});
  113. delete($opts{'squash_gids'});
  114. delete($opts{'map_daemon'});
  115. if (nfs_max_version("localhost") == 2) {
  116. $opts{'link_relative'} = "" if ($in{'link_relative'});
  117. $opts{'noaccess'} = "" if ($in{'noaccess'});
  118. if (!$in{'squash_uids_def'}) {
  119. if ($in{'squash_uids'} !~ /^[\d+\-\,]+$/) {
  120. &error($text{'save_euids'});
  121. } else {
  122. $opts{'squash_uids'} = $in{'squash_uids'};
  123. $opts{'map_daemon'} = "";
  124. }
  125. }
  126. if (!$in{'squash_gids_def'}) {
  127. if ($in{'squash_gids'} !~ /^[\d+\-\,]+$/) {
  128. &error($text{'save_egids'});
  129. } else {
  130. $opts{'squash_gids'} = $in{'squash_gids'};
  131. $opts{'map_daemon'} = "";
  132. }
  133. }
  134. }
  135. # ---
  136. $exp{'options'} = \%opts;
  137. if ($in{'new'}) {
  138. if ($in{'is_pfs'} || $nfsv<4) {
  139. &create_export(\%exp);
  140. } else {
  141. &create_export_in_root(\%exp);
  142. }
  143. } else {
  144. &modify_export(\%exp, $oldexp);
  145. }
  146. }
  147. &unlock_file($config{'exports_file'});
  148. if ($in{'delete'}) {
  149. &webmin_log("delete", "export", $exp->{'dir'}, $exp);
  150. }
  151. elsif ($in{'new'}) {
  152. &webmin_log("create", "export", $exp{'dir'}, \%exp);
  153. }
  154. else {
  155. &webmin_log("modify", "export", $exp{'dir'}, \%exp);
  156. }
  157. &redirect("");