Advertisement
Guest User

Untitled

a guest
Dec 30th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.60 KB | None | 0 0
  1. sub take_ownership{
  2.     # Looks like this is required to make sure that permissions are correct...
  3.     my ($home_path, $action) = @_;
  4.    
  5.     my $icaclsStr = "";
  6.     my $takeownCommand = "";
  7.     my $chmodCommand = "";
  8.     my $fullCommands = "";
  9.    
  10.     if (defined $home_path && $home_path ne "" && -e "$home_path"){
  11.         my $windows_home_path = clean(`cygpath -wa $home_path`);
  12.        
  13.         logger "Running takeown commands on path of $home_path and $windows_home_path";
  14.        
  15.         #cygwin path handling
  16.         $takeownCommand = 'takeown /U cyg_server /f "' . $home_path . '" /r >/dev/null 2>&1';
  17.         $chmodCommand = 'chmod 775 -R "' . $home_path . '" >/dev/null 2>&1';
  18.         if(defined $action && $action eq "str"){
  19.             $fullCommands .= $takeownCommand . "\n";
  20.             $fullCommands .= $chmodCommand . "\n";
  21.         }else{
  22.             system($takeownCommand);
  23.             system($chmodCommand);
  24.         }
  25.        
  26.         # Windows path handling
  27.         if(defined $windows_home_path && $windows_home_path ne ""){
  28.             $takeownCommand = 'takeown /U cyg_server /f "' . $windows_home_path . '" /r >/dev/null 2>&1';
  29.             $chmodCommand = 'chmod 775 -R "' . $windows_home_path . '" >/dev/null 2>&1';
  30.             $icaclsStr = 'icacls "' . $windows_home_path . '" /grant cyg_server:\\(OI\\)\\(CI\\)F /T >/dev/null 2>&1';
  31.            
  32.             if(defined $action && $action eq "str"){
  33.                 $fullCommands .= $takeownCommand . "\n";
  34.                 $fullCommands .= $chmodCommand . "\n";
  35.                 $fullCommands .= $icaclsStr . "\n";
  36.             }else{
  37.                 logger "Running icacls command: $icaclsStr";
  38.                 system($takeownCommand);
  39.                 system($chmodCommand);
  40.                 system($icaclsStr);
  41.             }
  42.         }      
  43.     }
  44.    
  45.     if($fullCommands ne ""){
  46.         return $fullCommands;
  47.     }
  48.    
  49.     return 1;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement