Author: arkurth
Date: Thu Aug 26 15:43:57 2010
New Revision: 989776
URL: http://svn.apache.org/viewvc?rev=989776&view=rev
Log:
VCL-331
Updated Windows.pm::set_password to better handle the updating of scheduled
task passwords. It now specifies the username when issuing the schtasks.exe
command in case the username stored in the task contains an old computer name.
The code was changed to not return false if it fails to set a scheduled task
password because of Windows 7 bug which causes "ERROR: The parameter is
incorrect" to be returned if schtasks.exe is used to change the password of a
task created using the GUI. There was also a problem caused by
utils.pm::run_ssh_command(). The output it returned included carriage returns
at the end of the lines of Windows command output. It was updated to remove
these.
VCL-164
There were 2 get_user_info subroutines in utils.pm. These were consolidated
and the calls to get_user_info() in image.pm. and blockrequest.pm were updated
accordingly.
Modified:
incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm
incubator/vcl/trunk/managementnode/lib/VCL/blockrequest.pm
incubator/vcl/trunk/managementnode/lib/VCL/image.pm
incubator/vcl/trunk/managementnode/lib/VCL/utils.pm
Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm?rev=989776&r1=989775&r2=989776&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm Thu Aug 26
15:43:57 2010
@@ -1827,7 +1827,7 @@ sub set_password {
# Attempt to change scheduled task passwords
notify($ERRORS{'DEBUG'}, 0, "changing passwords for scheduled tasks");
- my ($schtasks_query_exit_status, $schtasks_query_output) =
run_ssh_command($computer_node_name, $management_node_keys, "schtasks.exe
/Query /V /FO LIST", '', '', 1);
+ my ($schtasks_query_exit_status, $schtasks_query_output) =
run_ssh_command($computer_node_name, $management_node_keys, "schtasks.exe
/Query /V /FO LIST", '', '', 0);
if (defined($schtasks_query_exit_status) && $schtasks_query_exit_status
== 0) {
notify($ERRORS{'DEBUG'}, 0, "queried scheduled tasks on
$computer_node_name");
}
@@ -1844,31 +1844,42 @@ sub set_password {
my $task_name;
my @task_names_to_update;
for my $schtasks_output_line (@{$schtasks_query_output}) {
- if ($schtasks_output_line =~ /TaskName:\s+([ \S]+)/i) {
+ if ($schtasks_output_line =~ /TaskName:\s+(.+)/i) {
$task_name = $1;
}
- if ($schtasks_output_line =~ /Run As User.*\\$username/i) {
- notify($ERRORS{'DEBUG'}, 0, "password needs to be
updated for scheduled task: $task_name\n$schtasks_output_line");
+ if ($schtasks_output_line =~ /Run As User.*[\W]$username\s*$/) {
+ notify($ERRORS{'DEBUG'}, 0, "password needs to be
updated for scheduled task: '$task_name'");
push @task_names_to_update, $task_name;
}
- } ## end for my $schtasks_output_line (@{$schtasks_query_output...
+ }
# Loop through the scheduled tasks configured to run as the user,
update the password
for my $task_name_to_update (@task_names_to_update) {
- my ($schtasks_change_exit_status, $schtasks_change_output) =
run_ssh_command($computer_node_name, $management_node_keys, "schtasks.exe
/Change /RP \"$password\" /TN \"$task_name_to_update\"");
- if (defined($schtasks_change_exit_status) &&
$schtasks_change_exit_status == 0) {
+ my $schtasks_command = "schtasks.exe /Change /RU \"$username\"
/RP \"$password\" /TN \"$task_name_to_update\"";
+ my ($schtasks_change_exit_status, $schtasks_change_output) =
run_ssh_command($computer_node_name, $management_node_keys, $schtasks_command,
'', '', 0);
+ if (!defined($schtasks_change_output)) {
+ notify($ERRORS{'WARNING'}, 0, "failed to run ssh
command to change password for scheduled task: $task_name_to_update");
+ return;
+ }
+ elsif (grep (/^SUCCESS:/, @$schtasks_change_output)) {
notify($ERRORS{'OK'}, 0, "changed password for
scheduled task: $task_name_to_update");
}
- elsif (defined $schtasks_change_exit_status) {
- notify($ERRORS{'WARNING'}, 0, "failed to change
password for scheduled task: $task_name_to_update, exit status:
$schtasks_change_exit_status, output:\...@{$schtasks_change_output}");
- return 0;
+ elsif (grep (/The parameter is incorrect/,
@$schtasks_change_output)) {
+ notify($ERRORS{'WARNING'}, 0, "encountered Windows bug
while attempting to change password for scheduled task: $task_name_to_update,
output:\...@{$schtasks_change_output}");
+ # Don't return - There is a bug in Windows 7
+ # If a scheduled task is created using the GUI using a
schedule the password cannot be set via schtasks.exe
+ # schtasks.exe displays: ERROR: The parameter is
incorrect.
+ # If the same task is changed to run on an event such
as logon it works
+ }
+ elsif (grep (/^ERROR:/, @$schtasks_change_output)) {
+ notify($ERRORS{'WARNING'}, 0, "failed to change
password for scheduled task: $task_name_to_update,
command:\n$schtasks_command\noutput:\...@{$schtasks_change_output}");
}
else {
- notify($ERRORS{'WARNING'}, 0, "failed to run ssh
command to change password for scheduled task: $task_name_to_update");
- return 0;
+ notify($ERRORS{'WARNING'}, 0, "unexpected output
returned while attempting to change password for scheduled task:
$task_name_to_update,
command:\n$schtasks_command\noutput:\...@{$schtasks_change_output}");
}
- } ## end for my $task_name_to_update (@task_names_to_update)
-
+ }
+
+ notify($ERRORS{'OK'}, 0, "changed password for user: $username");
return 1;
} ## end sub set_password
Modified: incubator/vcl/trunk/managementnode/lib/VCL/blockrequest.pm
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/blockrequest.pm?rev=989776&r1=989775&r2=989776&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/blockrequest.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/blockrequest.pm Thu Aug 26
15:43:57 2010
@@ -137,15 +137,15 @@ sub process {
my $block_group_name =
$self->data->get_blockrequest_group_name();
# Get user info
- my %info;
+ my $user_info;
my $owner_affiliation_helpaddress;
my $owner_email;
- if( %info = get_user_info($blockrequest_owner_id)){
- $owner_email = $info{email};
- $owner_affiliation_helpaddress = $info{helpaddress};
+ if ($user_info = get_user_info($blockrequest_owner_id)) {
+ $owner_email = $user_info->{email};
+ $owner_affiliation_helpaddress =
$user_info->{affiliation}{helpaddress};
}
-
+
#Set local timer
my $localtimer = convert_to_epoch_seconds();
Modified: incubator/vcl/trunk/managementnode/lib/VCL/image.pm
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/image.pm?rev=989776&r1=989775&r2=989776&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/image.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/image.pm Thu Aug 26 15:43:57 2010
@@ -545,8 +545,8 @@ sub setup_capture_base_image {
print "User was not found: $user_identifier\n";
}
else {
- $user_id = (keys %$user_info)[0];
- $username = $user_info->{$user_id}{unityid};
+ $user_id = $user_info->{id};
+ $username = $user_info->{unityid};
}
}
print "\nUser who will own the image: $username (ID: $user_id)\n\n";
Modified: incubator/vcl/trunk/managementnode/lib/VCL/utils.pm
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=989776&r1=989775&r2=989776&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/utils.pm Thu Aug 26 15:43:57 2010
@@ -138,7 +138,6 @@ our @EXPORT = qw(
get_managable_resource_groups
get_user_info
get_vmhost_info
- get_user_info
getdynamicaddress
getimagesize
getnewdbh
@@ -479,7 +478,7 @@ our ($JABBER, $PROCESSNAME);
our %ERRORS = ('DEPENDENT' => 4, 'UNKNOWN' => 3, 'OK' => 0, 'WARNING' => 1,
'CRITICAL' => 2, 'MAILMASTERS' => 5, 'DEBUG' => 6);
our ($LockerWrtUser, $wrtPass, $database, $server);
our ($jabServer, $jabUser, $jabPass, $jabResource, $jabPort);
-our ($vcldquerykey, $DEFAULTHELPEMAIL,$RETURNPATH);
+our ($vcldquerykey, $RETURNPATH);
our ($LOGFILE, $PIDFILE, $VCLDRPCQUERYKEY);
our ($SERVER, $DATABASE, $WRTUSER, $WRTPASS);
our ($MYSQL_SSL, $MYSQL_SSL_CERT);
@@ -5518,7 +5517,7 @@ sub run_ssh_command {
# SSH command was executed successfully, actual command
on node may have succeeded or failed
# Split the output up into an array of lines
- my @output_lines = split(/\n/, $ssh_output);
+ my @output_lines = split(/[\r\n]+/, $ssh_output);
# Print the output unless no_output is set
notify($ERRORS{'DEBUG'}, 0, "run_ssh_command output:\n"
. join("\n", @output_lines)) if $output_level > 1;
@@ -7917,52 +7916,116 @@ sub get_computer_grp_members {
=head2 get_user_info
- Parameters : $user_id
- Returns : scalar - group name
- Description :
+ Parameters : $user_identifier
+ Returns : hash reference
+ Description : Retrieves user information from the database. The user
identifier
+ argument can either be a user ID or unityid. A hash reference is
+ returned. Example:
+ my $user_info = user_info('vclreload');
+
+ %{$user_info->{adminlevel}}
+ |---$user_info->{adminlevel}{name} = 'none'
+ $user_info->{adminlevelid} = '1'
+ %{$user_info->{affiliation}}
+ |---$user_info->{affiliation}{dataUpdateText} = ''
+ |---$user_info->{affiliation}{helpaddress} = NULL
+ |---$user_info->{affiliation}{name} = 'Local'
+ |---$user_info->{affiliation}{shibname} = NULL
+ |---$user_info->{affiliation}{shibonly} = '0'
+ |---$user_info->{affiliation}{sitewwwaddress} =
'http://vcl.ncsu.edu'
+ $user_info->{affiliationid} = '4'
+ $user_info->{audiomode} = 'local'
+ $user_info->{bpp} = '16'
+ $user_info->{email} = ''
+ $user_info->{emailnotices} = '0'
+ $user_info->{firstname} = 'vcl'
+ $user_info->{height} = '768'
+ $user_info->{id} = '2'
+ $user_info->{IMid} = NULL
+ %{$user_info->{IMtype}}
+ |---$user_info->{IMtype}{name} = 'none'
+ $user_info->{IMtypeid} = '1'
+ $user_info->{lastname} = 'reload'
+ $user_info->{lastupdated} = '0000-00-00 00:00:00'
+ $user_info->{mapdrives} = '1'
+ $user_info->{mapprinters} = '1'
+ $user_info->{mapserial} = '0'
+ $user_info->{preferredname} = NULL
+ $user_info->{showallgroups} = '0'
+ $user_info->{uid} = NULL
+ $user_info->{unityid} = 'vclreload'
+ $user_info->{width} = '1024'
=cut
sub get_user_info {
- my ($user_id) = @_;
-
-
- if(!defined($user_id)){
- notify($ERRORS{'WARNING'}, $LOGFILE, "user_id was not
supplied");
- return 0;
- }
+ my ($user_identifier) = @_;
+ if (!defined($user_identifier)) {
+ notify($ERRORS{'WARNING'}, 0, "user identifier argument was not
specified");
+ return;
+ }
- my $select_statement = <<EOF;
+ my $select_statement = <<EOF;
SELECT DISTINCT
user.*,
-affiliation.sitewwwaddress AS sitewwwaddress,
-affiliation.helpaddress AS helpaddress
+adminlevel.name AS adminlevel_name,
+affiliation.name AS affiliation_name,
+affiliation.shibname AS affiliation_shibname,
+affiliation.dataUpdateText AS affiliation_dataUpdateText,
+affiliation.sitewwwaddress AS affiliation_sitewwwaddress,
+affiliation.helpaddress AS affiliation_helpaddress,
+affiliation.helpaddress AS affiliation_helpaddress,
+affiliation.shibonly AS affiliation_shibonly,
+IMtype.name AS IMtype_name
FROM
-user,
-affiliation
+user
+LEFT JOIN (adminlevel) ON (adminlevel.id = user.adminlevelid)
+LEFT JOIN (affiliation) ON (affiliation.id = user.affiliationid)
+LEFT JOIN (IMtype) ON (IMtype.id = user.IMtypeid)
WHERE
-user.id = $user_id AND
-affiliation.id = user.affiliationid
EOF
+ if ($user_identifier =~ /^\d+$/) {
+ $select_statement .= "user.id = $user_identifier";
+ }
+ else {
+ $select_statement .= "user.unityid = '$user_identifier'";
+ }
+
# Call the database select subroutine
- # This will return an array of one or more rows based on the select
statement
- my @selected_rows = database_select($select_statement);
+ # This will return an array of one or more rows based on the select
statement
+ my @selected_rows = database_select($select_statement);
# Check to make sure 1 row was returned
- if (scalar @selected_rows == 0) {
- notify($ERRORS{'OK'}, 0, "user id $user_id was not found in
the database, 0 rows were returned");
- return ();
- }
- elsif (scalar @selected_rows > 1) {
- notify($ERRORS{'WARNING'}, 0, "" . scalar @selected_rows . "
rows were returned from database select");
- return ();
- }
-
- # A single row was returned (good)
- # Return the hash
- return %{$selected_rows[0]};
-
+ if (scalar @selected_rows == 0) {
+ notify($ERRORS{'OK'}, 0, "user was not found in the database:
$user_identifier, 0 rows were returned");
+ return;
+ }
+ elsif (scalar @selected_rows > 1) {
+ notify($ERRORS{'WARNING'}, 0, "" . scalar @selected_rows . "
rows were returned from database select for user: $user_identifier");
+ return;
+ }
+
+ my %row = %{$selected_rows[0]};
+
+ my %user_info;
+
+ # Loop through all the columns returned
+ foreach my $key (keys %row) {
+ my $value = $row{$key};
+
+ # Create another variable by stripping off the column_ part of
each key
+ # This variable stores the original (correct) column name
+ (my $original_key = $key) =~ s/^.+_//;
+
+ if ($key =~ /^(.+)_/) {
+ $user_info{$1}{$original_key} = $value;
+ }
+ else {
+ $user_info{$original_key} = $value;
+ }
+ }
+ return \%user_info;
}
#/////////////////////////////////////////////////////////////////////////////
@@ -9594,64 +9657,6 @@ sub get_module_info {
#/////////////////////////////////////////////////////////////////////////////
-=head2 get_user_info
-
- Parameters : $user_identifier
- Returns : hash reference
- Description : Retrieves information from the database for the user specified
by
- the $user_identifier argument. The $user_identifier argument can
- either be a user ID or login name.
-
-=cut
-
-sub get_user_info {
- my ($user_identifier) = @_;
- if (!defined($user_identifier)) {
- notify($ERRORS{'WARNING'}, 0, "user identifier argument was not
specified");
- return;
- }
-
- my $select_statement = <<EOF;
-SELECT
-*
-FROM
-user
-WHERE
-EOF
-
- if ($user_identifier =~ /^\d+$/) {
- $select_statement .= "id = $user_identifier";
- }
- else {
- $select_statement .= "unityid = '$user_identifier'";
- }
-
- # Call the database select subroutine
- my @selected_rows = database_select($select_statement);
-
- # Check to make sure rows were returned
- if (!...@selected_rows) {
- notify($ERRORS{'WARNING'}, 0, "unable to retrieve rows from
user table");
- return;
- }
-
- # Transform the array of database rows into a hash
- my %info_hash;
- for my $row (@selected_rows) {
- my $user_id = $row->{id};
-
- for my $key (keys %$row) {
- my $value = $row->{$key};
- $info_hash{$user_id}{$key} = $value;
- }
- }
-
- notify($ERRORS{'DEBUG'}, 0, "retrieved user info:\n" .
format_data(\%info_hash));
- return \%info_hash;
-}
-
-#/////////////////////////////////////////////////////////////////////////////
-
=head2 get_current_package_name
Parameters : None