--- loncom/lcinstallfile 2009/02/24 11:52:03 1.2 +++ loncom/lcinstallfile 2010/10/12 10:14:25 1.5 @@ -1,6 +1,8 @@ #!/usr/bin/perl # -## Copyright Michigan State University Board of Trustees +# Copyright Michigan State University Board of Trustees +# +# $Id: lcinstallfile,v 1.5 2010/10/12 10:14:25 foxr Exp $ # # This file is part of the LearningOnline Network with CAPA (LON-CAPA). # @@ -22,8 +24,7 @@ # # # -# 2/17/2009 - Ron FOx -# +# 2/17/2009 - Ron Fox # # http://www.lon-capa.org/ # @@ -41,9 +42,7 @@ use strict; -my $LONCAPAHOME = '/home/httpd'; # Adjust if loncapa isn't installed here. - -use lib "/home/httpd/lib/perl"; +use lib "/home/httpd/lib/perl"; # Adjust if loncapa lib isn't installed here. use LONCAPA; use LONCAPA::Configuration; use IO::File; @@ -62,15 +61,16 @@ use File::Copy; # 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; -if ($wwwid!=$>) { +#&disable_root_capability; +if ($wwwid!=$<) { print("User ID mismatch. This program must be run as user 'www'\n") unless $noprint; exit 1; @@ -80,12 +80,13 @@ if ($wwwid!=$>) { # 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 +97,10 @@ my $destfile = $ARGV[1]; # 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 +118,16 @@ if (! -r $sourcepath) { # 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; } @@ -182,10 +180,10 @@ sub enable_root_capability { if ($wwwid==$>) { ($<,$>)=($>,0); ($(,$))=($),0); - } - else { + } else { # root capability is already enabled } + print ("Effective uid = $>\n"); return $>; } @@ -194,8 +192,7 @@ sub disable_root_capability { if ($wwwid==$<) { ($<,$>)=($>,$<); ($(,$))=($),$(); - } - else { + } else { # root capability is already disabled } }