mirror of
				https://github.com/xcat2/xcat-core.git
				synced 2025-10-31 11:22:27 +00:00 
			
		
		
		
	Fix 3052 and add sudo for dcp and fix 3380
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/branches/2.8@15301 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
		| @@ -592,6 +592,7 @@ sub _execute_dsh | ||||
|                         xCAT::MsgUtils->message("D", $rsp, $::CALLBACK); | ||||
|                         $rsp = {}; | ||||
|                         push @{$rsp->{error}}, @{$error_buffers{$user_target}}; | ||||
|                         $rsp->{NoErrorPrefix} = 1; | ||||
|                         xCAT::MsgUtils->message("E", $rsp, $::CALLBACK,0); | ||||
|                     } | ||||
|                 } | ||||
| @@ -607,6 +608,7 @@ sub _execute_dsh | ||||
|                     xCAT::MsgUtils->message("D", $rsp, $::CALLBACK); | ||||
|                     $rsp = {}; | ||||
|                     push @{$rsp->{error}}, @{$error_buffers{$user_target}}; | ||||
|                     $rsp->{NoErrorPrefix} = 1; | ||||
|                     xCAT::MsgUtils->message("E", $rsp, $::CALLBACK,0); | ||||
|  | ||||
|                 } | ||||
| @@ -815,7 +817,7 @@ sub fork_fanout_dcp | ||||
|         my @dcp_command; | ||||
|         my $rsyncfile; | ||||
|  | ||||
|         if (!$$target_properties{'localhost'}) | ||||
|         if (!$$target_properties{'localhost'})  # this is to a remote host | ||||
|         { | ||||
|             my $target_type = $$target_properties{'type'}; | ||||
|  | ||||
| @@ -869,21 +871,25 @@ sub fork_fanout_dcp | ||||
|             my $localhost=0;   # this is from the MN to another node  | ||||
|             @dcp_command = | ||||
|               $remoteshell->remote_copy_command(\%rcp_config, $remote_copy); | ||||
|             # add sudo  for non-root users | ||||
|             if ($$options{'sudo'}) { | ||||
|                   unshift (@dcp_command,'sudo');  | ||||
|             } | ||||
|  | ||||
|         } | ||||
|         else  # this is the local host ( running on the Management Node) | ||||
|         { | ||||
|             if ($$options{'destDir_srcFile'}{$user_target}) | ||||
|             { | ||||
|             my $target_type = $$target_properties{'type'}; | ||||
|              my $target_type = $$target_properties{'type'}; | ||||
|  | ||||
|             my %rcp_config = (); | ||||
|              my %rcp_config = (); | ||||
|  | ||||
|             my $remote_copy; | ||||
|             my $rsh_extension = 'RSH'; | ||||
|              my $remote_copy; | ||||
|              my $rsh_extension = 'RSH'; | ||||
|  | ||||
|             if ($target_type eq 'node') | ||||
|             { | ||||
|              if ($target_type eq 'node') | ||||
|              { | ||||
|                 $remote_copy = | ||||
|                      $$options{'node-rcp'}{$$target_properties{'context'}} | ||||
|                   || $$target_properties{'remote-copy'}; | ||||
| @@ -891,10 +897,10 @@ sub fork_fanout_dcp | ||||
|                 ($remote_copy =~ /\/rsync$/) && ($rsh_extension = 'RSYNC'); | ||||
|                 $rcp_config{'options'} = | ||||
|                   $$options{'node-options'}{$$target_properties{'context'}}; | ||||
|             } | ||||
|              } | ||||
|  | ||||
|             $rcp_config{'preserve'}  = $$options{'preserve'}; | ||||
|             $rcp_config{'recursive'} = $$options{'recursive'}; | ||||
|              $rcp_config{'preserve'}  = $$options{'preserve'}; | ||||
|              $rcp_config{'recursive'} = $$options{'recursive'}; | ||||
|  | ||||
|  | ||||
|              $rcp_config{'src-file'}  = $$options{'source'}; | ||||
| @@ -905,20 +911,19 @@ sub fork_fanout_dcp | ||||
|              $rcp_config{'destDir_srcFile'} = | ||||
|                   $$options{'destDir_srcFile'}{$user_target}; | ||||
|  | ||||
|             #eval "require RemoteShell::$rsh_extension"; | ||||
|             eval "require xCAT::$rsh_extension"; | ||||
|             my $remoteshell = "xCAT::$rsh_extension"; | ||||
|             # HERE: Build the dcp command based on the arguments | ||||
|             my $localhost=1;   # this is on the MN to the MN | ||||
|             @dcp_command = | ||||
|              eval "require xCAT::$rsh_extension"; | ||||
|              my $remoteshell = "xCAT::$rsh_extension"; | ||||
|              # HERE: Build the dcp command based on the arguments | ||||
|              my $localhost=1;   # this is on the MN to the MN | ||||
|              @dcp_command = | ||||
|               $remoteshell->remote_copy_command(\%rcp_config, $remote_copy,$localhost); | ||||
|                  | ||||
|             } | ||||
|             else    # just a copy not a sync | ||||
|             { | ||||
|              } | ||||
|              else    # just a copy not a sync | ||||
|              { | ||||
|                 @dcp_command = | ||||
|                   ('/bin/cp', '-r', $$options{'source'}, $$options{'target'}); | ||||
|             } | ||||
|              } | ||||
|         } | ||||
|  | ||||
|         my $rsp = {}; | ||||
| @@ -1034,6 +1039,28 @@ sub fork_fanout_dsh | ||||
|  | ||||
|         if ($$options{'environment'}) | ||||
|         { | ||||
|             # if we are on a servicenode need to get the environment file | ||||
|             # from the SNsyncfiledir, not local | ||||
|             if (xCAT::Utils->isServiceNode()) { | ||||
|               my $newenvfile; | ||||
|               my $synfiledir = "/var/xcat/syncfiles"; #default | ||||
|  | ||||
|               # get the directory on the servicenode to and add to filepath  | ||||
|               my @syndir= xCAT::TableUtils->get_site_attribute("SNsyncfiledir"); | ||||
|               if ($syndir[0]) | ||||
|               { | ||||
|                 $synfiledir = $syndir[0]; | ||||
|               } | ||||
|               $newenvfile = $synfiledir; | ||||
|               $newenvfile .= $$options{'environment'}; | ||||
|               $$options{'environment'} =  $newenvfile; | ||||
|             } | ||||
|             if (!(-e $$options{'environment'})) | ||||
|             { | ||||
|               my $rsp={}; | ||||
|                $rsp->{error}->[0] = "File $$options{'environment'} does not exist"; | ||||
|                xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); | ||||
|             } | ||||
|             push @dsh_command, | ||||
|               "$$options{'pre-command'} . $$options{'environment'} ; $$options{'command'}$$options{'post-command'}"; | ||||
|         } | ||||
| @@ -1163,13 +1190,13 @@ sub fork_fanout_dsh | ||||
|             if ($$options{'execute'}) | ||||
|             { | ||||
|                 # first build the scp command to copy the file to execute | ||||
|                 # down to the node into /tmp/*.dsh | ||||
|                 # down to the node into /tmp/*.dsh  | ||||
|                 my $rsp = {}; | ||||
|                 $rsp->{data}->[0] = "TRACE: Execute option specified."; | ||||
|                 $dsh_trace && (xCAT::MsgUtils->message("I", $rsp, $::CALLBACK)); | ||||
|  | ||||
|                 my %exe_rcp_config = (); | ||||
|                 $tmp_cmd_file = POSIX::tmpnam . ".dsh"; | ||||
|                 $tmp_cmd_file = POSIX::tmpnam . ".dsh";  | ||||
|  | ||||
|                 my ($exe_cmd, @args) = @{$$options{'execute'}}; | ||||
|                 my $chmod_cmd = ""; | ||||
| @@ -4216,7 +4243,7 @@ sub usage_dcp | ||||
| { | ||||
|     ### usage message | ||||
|     my $usagemsg1 = " xdcp -h \n xdcp -q\n xdcp -V \n xdcp <noderange>\n"; | ||||
|     my $usagemsg2 = "      [-B bypass] [-c] [-f fanout] [-l user_ID]\n"; | ||||
|     my $usagemsg2 = "      [-B bypass] [-c] [-f fanout] [-l user_ID] [--sudo]\n"; | ||||
|     my $usagemsg3 = | ||||
|       "      [-m] [-o options] [-p] [-P] [-q] [-Q] [-r node_remote_copy]\n"; | ||||
|     my $usagemsg4 = | ||||
| @@ -4325,7 +4352,8 @@ sub parse_and_run_dcp | ||||
|                     'T|trace'          => \$options{'trace'}, | ||||
|                     'V|version'        => \$options{'version'}, | ||||
|                     'devicetype=s'     => \$options{'devicetype'}, | ||||
|                     'nodestatus|nodestatus' => \$options{'nodestatus'},             | ||||
|                     'nodestatus|nodestatus' => \$options{'nodestatus'},         | ||||
|                     'sudo|sudo' => \$options{'sudo'},             | ||||
|                     'X:s'              => \$options{'ignore_env'} | ||||
|         ) | ||||
|       ) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user