[LON-CAPA-cvs] cvs: loncom / lcinstallfile lond
foxr
foxr@source.lon-capa.org
Tue, 03 Mar 2009 12:08:07 -0000
This is a MIME encoded message
--foxr1236082087
Content-Type: text/plain
foxr Tue Mar 3 12:08:07 2009 EDT
Modified files:
/loncom lond lcinstallfile
Log:
Debugged lond/lcinstallfile support for cluster administration of
dns_hosts.tab and dns_domain.tab see also clusteradmin in this directory..
--foxr1236082087
Content-Type: text/plain
Content-Disposition: attachment; filename="foxr-20090303120807.txt"
Index: loncom/lond
diff -u loncom/lond:1.411 loncom/lond:1.412
--- loncom/lond:1.411 Tue Feb 10 11:31:26 2009
+++ loncom/lond Tue Mar 3 12:08:07 2009
@@ -2,7 +2,7 @@
# The LearningOnline Network
# lond "LON Daemon" Server (port "LOND" 5663)
#
-# $Id: lond,v 1.411 2009/02/10 11:31:26 foxr Exp $
+# $Id: lond,v 1.412 2009/03/03 12:08:07 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -54,12 +54,12 @@
use Fcntl qw(:flock);
use Apache::lonnet;
-my $DEBUG = 0; # Non zero to enable debug log entries.
+my $DEBUG = 1; # Non zero to enable debug log entries.
my $status='';
my $lastlog='';
-my $VERSION='$Revision: 1.411 $'; #' stupid emacs
+my $VERSION='$Revision: 1.412 $'; #' stupid emacs
my $remoteVERSION;
my $currenthostid="default";
my $currentdomainid;
@@ -142,6 +142,16 @@
"lcuseradd Password mismatch");
+# This array are the errors from lcinstallfile:
+
+my @installerrors = ("ok",
+ "Initial user id of client not that of www",
+ "Usage error, not enough command line arguments",
+ "Source file name does not exist",
+ "Destination file name does not exist",
+ "Some file operation failed",
+ "Invalid table filename."
+ );
#
# Statistics that are maintained and dislayed in the status line.
@@ -398,6 +408,7 @@
#
sub ReadManagerTable {
+ &Debug("Reading manager table");
# Clean out the old table first..
foreach my $key (keys %managers) {
@@ -520,11 +531,9 @@
}
#
# InstallFile: Called to install an administrative file:
-# - The file is created with <name>.tmp
-# - The <name>.tmp file is then mv'd to <name>
-# This lugubrious procedure is done to ensure that we are never without
-# a valid, even if dated, version of the file regardless of who crashes
-# and when the crash occurs.
+# - The file is created int a temp directory called <name>.tmp
+# - lcinstall file is called to install the file.
+# since the web app has no direct write access to the table directory
#
# Parameters:
# Name of the file
@@ -532,11 +541,16 @@
# Return:
# nonzero - success.
# 0 - failure and $! has an errno.
+# Assumptions:
+# File installtion is a relatively infrequent
#
sub InstallFile {
my ($Filename, $Contents) = @_;
- my $TempFile = $Filename.".tmp";
+# my $TempFile = $Filename.".tmp";
+ my $exedir = $perlvar{'lonDaemons'};
+ my $tmpdir = $exedir.'/tmp/';
+ my $TempFile = $tmpdir."TempTableFile.tmp";
# Open the file for write:
@@ -550,11 +564,27 @@
print $fh ($Contents);
$fh->close; # In case we ever have a filesystem w. locking
- chmod(0660, $TempFile);
+ chmod(0664, $TempFile); # Everyone can write it.
- # Now we can move install the file in position.
-
- move($TempFile, $Filename);
+ # Use lcinstall file to put the file in the table directory...
+
+ &Debug("Opening pipe to $exedir/lcinstallfile $TempFile $Filename");
+ my $pf = IO::File->new("| $exedir/lcinstallfile $TempFile $Filename > $exedir/logs/lcinstallfile.log");
+ close $pf;
+ my $err = $?;
+ &Debug("Status is $err");
+ if ($err != 0) {
+ my $msg = $err;
+ if ($err < @installerrors) {
+ $msg = $installerrors[$err];
+ }
+ &logthis("Install failed for table file $Filename : $msg");
+ return 0;
+ }
+
+ # Remove the temp file:
+
+ unlink($TempFile);
return 1;
}
@@ -608,6 +638,7 @@
sub PushFile {
my $request = shift;
my ($command, $filename, $contents) = split(":", $request, 3);
+ &Debug("PushFile");
# At this point in time, pushes for only the following tables are
# supported:
@@ -624,20 +655,7 @@
if(! (defined $tablefile)) {
return "refused";
}
- #
- # >copy< the old table to the backup table
- # don't rename in case system crashes/reboots etc. in the time
- # window between a rename and write.
- #
- my $backupfile = $tablefile;
- $backupfile =~ s/\.tab$/.old/;
- if(!CopyFile($tablefile, $backupfile)) {
- &logthis('<font color="green"> CopyFile from '.$tablefile." to ".$backupfile." failed </font>");
- return "error:$!";
- }
- &logthis('<font color="green"> Pushfile: backed up '
- .$tablefile." to $backupfile</font>");
-
+
# If the file being pushed is the host file, we adjust the entry for ourself so that the
# IP will be our current IP as looked up in dns. Note this is only 99% good as it's possible
# to conceive of conditions where we don't have a DNS entry locally. This is possible in a
@@ -650,6 +668,7 @@
# Install the new file:
+ &logthis("Installing new $tablefile contents:\n$contents");
if(!InstallFile($tablefile, $contents)) {
&logthis('<font color="red"> Pushfile: unable to install '
.$tablefile." $! </font>");
@@ -1203,7 +1222,7 @@
# a reply is written to the client.
sub push_file_handler {
my ($cmd, $tail, $client) = @_;
-
+ &Debug("In push file handler");
my $userinput = "$cmd:$tail";
# At this time we only know that the IP of our partner is a valid manager
@@ -1211,7 +1230,8 @@
# spoofing).
my $cert = &GetCertificate($userinput);
- if(&ValidManager($cert)) {
+ if(&ValidManager($cert)) {
+ &Debug("Valid manager: $client");
# Now presumably we have the bona fides of both the peer host and the
# process making the request.
@@ -1220,6 +1240,7 @@
&Reply($client, \$reply, $userinput);
} else {
+ &logthis("push_file_handler $client is not valid");
&Failure( $client, "refused\n", $userinput);
}
return 1;
@@ -5981,7 +6002,7 @@
if ($clientip eq '127.0.0.1') {
$outsideip=&Apache::lonnet::get_host_ip($perlvar{'lonHostID'});
}
-
+ &ReadManagerTable();
my $clientrec=defined(&Apache::lonnet::get_hosts_from_ip($outsideip));
my $ismanager=($managers{$outsideip} ne undef);
$clientname = "[unknonwn]";
Index: loncom/lcinstallfile
diff -u loncom/lcinstallfile:1.2 loncom/lcinstallfile:1.3
--- loncom/lcinstallfile:1.2 Tue Feb 24 11:52:03 2009
+++ loncom/lcinstallfile Tue Mar 3 12:08:07 2009
@@ -62,11 +62,12 @@
# 6 - Some file operation failed.
# 7 - Invalid table filename.
#
-my $noprint = 0;
+my $noprint = 1;
#
# Ensure we are www:
#
#
+print ("In lcinstallfile\n") unless $noprint;
my $wwwid=getpwnam('www');
&disable_root_capability;
@@ -80,12 +81,13 @@
#
my $argc = scalar(@ARGV);
if ($argc != 2) {
- print("Usage: lcinstallfile sourcepath destfile\n") unless $noprint;
+ print("Usage: lcinstallfile sourcepath destfile had $argc parameters\n") unless $noprint;
exit 2;
}
my $sourcepath = $ARGV[0];
my $destfile = $ARGV[1];
+print("From: $sourcepath to: $destfile\n") unless $noprint;
# Ensure the source file exists, and root can write it.:
@@ -96,10 +98,10 @@
# loncapa table files are all of the form.
# something.tab where something is all letters and _'s.
#
-if ($sourcepath =~ /^(\w+\.tab)$/) {
+if ($sourcepath =~ /^([\w\/]+\.\w+)$/) {
$sourcepath = $1;
} else {
- print ("Invalid characters in filename $sourcepath \n") unless $noprint;
+ print ("Invalid characters in filename '$sourcepath' \n") unless $noprint;
exit 7;
}
@@ -117,19 +119,16 @@
# We're not allowed to create new files, only replace existing files
# so ensure that the final destination file actually exists.
#
-my $config_vars = LONCAPA::Configuration::read_conf('loncapa.conf');
-my %config = %{$config_vars};
-my $tab_dir = $config{'lonTabDir'};
-my $final_file = $tab_dir.'/'.$destfile;
#
# Now sanitize the final file:
-if ($final_file =~ /^([\w\/]+\.tab)$/) {
+my $final_file;
+if ($destfile =~ /^([\w\/]+\.\w+)$/) {
$final_file = $1;
} else {
- print ("$final_file failed regexp match\n") unless $noprint;
+ print ("'$final_file' failed regexp match\n") unless $noprint;
exit 7;
}
@@ -186,6 +185,7 @@
else {
# root capability is already enabled
}
+ print ("Effective uid = $>\n");
return $>;
}
--foxr1236082087--