|
|||||||||||
|
CGI Scripts running as user that started apache
From: Travis Gillitzer <tgmlists(at)kc.rr.com>
Date: Sat Mar 15 2003 - 13:15:28 EST
I am installing Twiki (twiki.org). One of the steps is to run a CGI script that tests the environment. It gives the following info regarding the user that is running the script. Below is part of the output of the script. PATH_INFO: / Note: For a URL such as http://www.therawvegan.org/wiki/bin/testenv/foo/bar, the correct PATH_INFO is /foo/bar, without any prefixed path components. Test this now - particularly if you are using Apache or IIS, or are using a web hosting provider. The page resulting from the test link should have a PATH_INFO of /foo/bar. mod_perl: Not used for this script (mod_perl loaded) User: root Note: Your CGI scripts are executing as this user. Warning: Since your CGI script is not running as user nobody, you need to change the locks in the *,v RCS files of the TWiki distribution from nobody to root. Otherwise, changes to topics will not be logged by RCS. Group(s): Any assistance would be helpful. Thanks Below is the entire CGI script. #!/usr/bin/perl -w # # TWiki Collaboration Platform, http://TWiki.org/ # # Copyright (C) 2000-2003 Peter Thoeny, peter@thoeny.com # # For licensing info read license.txt file in the TWiki root. # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 package TWiki;
# Set library paths in @INC, at compile time
require './setlib.cfg';
unshift @INC, '../lib';
use vars qw( $useLocale );
# ===========================
# Do a dynamic 'use locale' for this script if( $useLocale ) {
require locale;
import locale ();
} }
# use strict; # Recommended for mod_perl, enable for Perl
# Doesn't work well here, due to 'do
my $setlibAvail = -r './setlib.cfg'; &main(); sub checkBasicModules { # Check whether basic CGI modules exist (some broken installations of # Perl don't have this, even though they are standard modules), and warn user my @basicMods = @_;
my $modMissing = 0;
eval "use $mod";
if ($@) {
unless ($modMissing) {
print "Content-type: text/html\n\n";
print "} # If any critical modules missing, display @INC and give up if ($modMissing) { print " } }
sub main
my $perlverRequired = 5.00503; # Oldest supported version of Perl my $perlverRequiredString = '5.005_03'; my $perlverRecommended = '5.6.1'; my $ActivePerlRecommendedBuild = 631; # Fixes PERL5SHELL bugs my $rcsverRequired = 5.7; my @basicMods = qw( CGI CGI::Carp ); # Required for testenv to work
my @requiredMods = ( # Required for TWiki
@basicMods,
'File::Copy',
);
# Required on non-Unix platforms (mainly Windows)
'Digest::SHA1', # For register script 'MIME::Base64', # For register script 'Net::SMTP', # For registration emails and mailnotify); # Optional modules on all platforms
open(STDERR,'>&STDOUT'); # redirect errors to browser $| = 1; # no buffering - FIXME: mod_perl issue?
# Check for modules required by this script
# Load CGI modules (run-time, after checking they are accessible)
my $query = new CGI;
print "Content-type: text/html\n\n";
Please read the <a href="http://TWiki.org/cgi-bin/view/TWiki/TWikiInstallationNotes">TWikiI nstallationNotes</a> for more information on TWiki installation. <h3>Environment variables:</h3> <table> EOM my $key; for $key ( sort keys %ENV ) {
print "<tr><th align=\"right\">$key</th><td>$ENV{$key}</td></tr>\n";
}
| ||||||||||
| Perl version: | $perlver"; print " ($perltype)" if $perltype ne 'generic'; print " | ||||
|---|---|---|---|---|---|
| Note:\n";
print "This is the Perl library path, used to load TWiki modules, ";
print "third-party modules used by some plugins, and Perl built-in
modules.";
print "</td></tr>\n"; # Add to list of required modules if non-Unix, or MacOS X (detected by
push @requiredMods, @requiredModsNonUnix; }
# Turn off fatalsToBrowser while checking module loads, to avoid load
# Check that the TWiki.pm module can be found
print "Warning: ";
print "'$mod.pm' not found - check path to
$setlibAvail;
print ".\n";
$twikiFound = 1;
# Do locale settings if TWiki.pm was found
TWiki::setupLocale();
# Check that each of the required Perl modules can be loaded, and
eval "use $mod";
print "Warning: "; print "'$mod' not installed - check TWiki documentation to see if this is required.\n"; print " | |||||
| PATH_INFO: | $thePathInfo | ||||
| Note:\n";
print "For a URL such as $theUrl/foo/bar, \n";
print "the correct PATH_INFO is /foo/bar, without any prefixed
path \n";
print "components. <a href=\"$theUrl/foo/bar#PATH_INFO\"><b>Test this now</b></a> \n"; print "- particularly if you are using Apache or IIS, or are using a web hosting provider.\n"; print "The page resulting from the test link should have a PATH_INFO of <b>/foo/bar</b>.\n"; print "</td></tr>\n"; print "<tr><th align=\"right\">mod_perl:</th><td>$USE_MOD_PERL for this script (mod_perl $LOAD_MOD_PERL)</td></tr>\n"; # Get userid (ActiveState or other Perl), should work on all Perl
foreach( split( " ", $( ) ) { # Unix/Cygwin Perl my $onegrp = getgrgid( $_ ); $grp .= " " . lc($onegrp); } } else { # ActiveState or other Win32 Perl # Try to use Cygwin's 'id' command - may be on the path, since Cygwin # is probably installed to supply ls, egrep, etc - if it isn't, give up. # Run command without stderr output, to avoid CGI giving error. # Get names of primary and other groups. $grp = lc(qx(sh -c '( id -un ; id -gn) 2>/dev/null' 2>nul )); if ($?) { $grp = "[Can't identify groups - no Cygwin 'id' or 'sh' command on path]";
}
print " if( $usr ne "nobody" ) { print "<tr><th></th><td><b><font color=\"red\">Warning:</font></b> "; print "Since your CGI script is not running as user <tt>nobody</tt>, "; print "you need to change the locks in the *,v RCS files of the TWiki ";
print "distribution from nobody to $usr.\n";
print "Otherwise, changes to topics will not be logged by RCS.\n";
print " | |||||
| Group(s): | "; print "$grp"; print " |
print "<h3>Test of <tt>TWiki.cfg</tt> Configuration:</h3>\n";
# TWiki.cfg read earlier
print "<table>\n";
print "<tr><th
align=\"right\">\$wikiHomeUrl:</th><td>$wikiHomeUrl</td></tr>\n";
my $junk1 = $wikiHomeUrl; # Avoid warning
print "\n"; Note: "; print "This is the link of the TWiki icon in the upper left corner."; print "
print "<tr><th
align=\"right\">\$defaultUrlHost:</th><td>$defaultUrlHost</td></tr>\n";
print "<tr><th></th><td><b><font color=\"green\">Note:</font></b> ";
print "This must be the protocol and host part (with optional port
number) of ";
print "the TWiki URL.";
print "</td></tr>\n";
my $val = $ENV{"HTTP_HOST"} || '';
if( $defaultUrlHost !~ /$val/ ) {
print "<tr><th></th><td><b><font color=\"red\">Warning:</font></b> ";
print "This does not match </b>HTTP_HOST</b>";
print "</td></tr>\n";
}
print "<tr><th
align=\"right\">\$scriptUrlPath:</th><td>$scriptUrlPath</td></tr>\n";
print "\n"; Note: "; print "This must be the URI of the TWiki cgi-bin directory."; print "
print "<tr><th></th><td><b><font color=\"red\">Warning:</font></b> ";
print "This does not match </b>REQUEST_URI</b>";
print "</td></tr>\n";
}
print "<tr><th
align=\"right\">\$pubUrlPath:</th><td>$pubUrlPath</td></tr>\n";
print "\n"; print " Note: "; print "This must be the URI of the public directory."; print "This is not set correctly if the "; print "$pubUrlPath/wikiHome.gif image below is broken:
"; print ""; print "
\n"; print " \$pubDir: $pubDir \n"; Note: "; print "This is the public directory, as seen from the file system. "; print "It must correspond to <b>\$pubUrlPath</b>."; print "</td></tr>\n";
if( ! ( -e "$pubDir/wikiHome.gif" ) ) {print "<tr><th></th><td><b><font color=\"red\">Error:</font></b> "; print "Directory does not exist or file <tt>wikiHome.gif</tt> does not exist in this directory.";
print "</td></tr>\n";
} elsif( ! testFileIsWritable( "$pubDir/testenv.test" ) ) {# directory is not writable
print "\n"; Error: "; print "This directory is not writable by $usr user."; print "
}print "<tr><th
align=\"right\">\$templateDir:</th><td>$templateDir</td></tr>\n"; print "<tr><th></th><td><b><font color=\"green\">Note:</font></b> "; print "This is the TWiki template directory, as seen from the file system. ";
print "</td></tr>\n";
if( ! ( -e "$templateDir/view.tmpl" ) ) {print "<tr><th></th><td><b><font color=\"red\">Error:</font></b> "; print "Directory does not exist or file <tt>view.tmpl</tt> does not exist in this directory.";
print "</td></tr>\n";
} elsif( testFileIsWritable( "$templateDir/testenv.test" ) ) {# directory is writable
print "<tr><th></th><td><b><font color=\"red\">Warning:</font></b> ";print "Security issue: This directory should not be writable by the <b>$usr</b> user.";
print "</td></tr>\n";
}print "\n"; print " \$dataDir: $dataDir \n"; Note: "; print "This is the data directory where TWiki stores all topics."; print "
if( ! ( -e "$dataDir" ) ) {print "\n"; Error: "; print "Directory does not exist."; print "
} elsif( ! testFileIsWritable( "$dataDir/testenv.test" ) ) {# directory is not writable
print "\n"; Error: "; print "This directory must be writable by the $usr user."; print "
}# Check 'sendmail'
$val = $mailProgram;
$val =~ s/([^\s]*).*/$1/g;
# Don't warn on Windows, as Net::SMTP is normally used
if( $OS ne 'WINDOWS' && ! ( -e $val ) ) {print "<tr><th></th><td><b><font color=\"red\">Warning:</font></b> ";
print "Mail program <tt>$val</tt> not found. Check the path."; print "</td></tr>\n";
}print "<tr><th
align=\"right\">\$mailProgram:</th><td>$mailProgram</td></tr>\n"; print "<tr><th></th><td><b><font color=\"green\">Note:</font></b> "; if( $OS ne 'WINDOWS' ) {print "This is the mail program TWiki uses to send mail."; } else {
print "This is not typically used on Windows - the Perl Net::SMTP module is used instead.";
}
print "</td></tr>\n";# Check RCS directory
print "\n"; print " \$rcsDir: $rcsDir \n"; Note: "; print "This is the directory where RCS is located."; print " # Check RCS
if( ! ( -e "$rcsDir/ci$exeSuffix" ) ) {# RCS not installed
print "<tr><th></th><td><b><font color=\"red\">Warning:</font></b> ";print "RCS program <tt>$rcsDir/ci$exeSuffix</tt> not found. Check \$rcsDir setting in TWiki.cfg. ";
print "TWiki will not work (unless you are "; print "using TWiki's built-in RCS implementation, RcsLite)."; print "
} else {
# Check RCS version
my $rcsVerNum = `$rcsDir/ci$exeSuffix -V`; # May fail due
to diff or DLL not on PATH
$rcsVerNum = (split(/\s+/, $rcsVerNum))[2] || ""; # Recover from unset variable
print "<tr><th align=\"right\">RCS Version:</th><td>$rcsVerNum"; print " (Cygwin package <tt>rcs-$cygwinRcsVerNum</tt>)" if defined($cygwinRcsVerNum);
print "\n";
print "Note: ";
print "This is the version of RCS which will be used.";
print " \n";
if( $rcsVerNum && $rcsVerNum < $rcsverRequired ) {
# RCS too old
print "Warning: ";
print "RCS program is too old, upgrade to version
$rcsverRequired or higher.";
print " \n";
# Check 'ls'
print "\n"; print " \$lsCmd: $lsCmd \n"; Note: "; print "This is the file list program TWiki uses to list topics."; print "
print "<tr><th></th><td><b><font color=\"red\">Warning:</font></b> ";
print "List program <tt>$val</tt> not found. Check the path.";
print "</td></tr>\n";
}
# Check 'grep'
print "<tr><th
align=\"right\">\$egrepCmd:</th><td>$egrepCmd</td></tr>\n";
print "\n"; Note: "; print "This is a program TWiki uses for search."; print "
print "<tr><th></th><td><b><font color=\"red\">Warning:</font></b> ";
print "Search program <tt>$val</tt> not found. Check the path.";
print "</td></tr>\n";
}
# Check 'fgrep'
print "<tr><th
align=\"right\">\$fgrepCmd:</th><td>$fgrepCmd</td></tr>\n";
print "\n"; Note: "; print "This is a program TWiki uses for search."; print "
print "<tr><th></th><td><b><font color=\"red\">Warning:</font></b> ";
print "Search program <tt>$val</tt> not found. Check the path.";
print "</td></tr>\n";
}
print "<tr><th
align=\"right\">\$safeEnvPath:</th><td>$safeEnvPath</td></tr>\n";
print "<tr><th></th><td><b><font color=\"green\">Note:</font></b> ";
print "This is used to initialise the PATH variable, and is used to run
the\n";
print "'diff' program used by RCS, as well as to run shell programs such
as\n";
if( $OS eq 'WINDOWS' ) {
print "cmd.exe or Cygwin's 'bash'.\n";
print "<p>\n";
if( $perltype eq 'Cygwin' ) {
print "Since you are using Cygwin Perl, 'bash' will be used without any special setup.\n";
} elsif( $perltype eq 'ActiveState' ) {
print "To use 'bash' with ActiveState Perl, see the PERL5SHELL section below\n";
print "- this is recommended\n"; print "if Cygwin is installed.\n";
print "Bourne shell or 'bash'.";
}
if( $safeEnvPath eq '' ) {
print "<tr><th></th><td><b><font color=\"red\">Warning:</font></b> \n";
print "Security issue: <b>\$safeEnvPath</b> set to empty string. Check TWiki.cfg.\n";
print "</td></tr>\n";
}
print "</td></tr>\n";
# Generate a separate table about specific environment variables
print "\n"; print "Path and Shell Environment
\n"; print "
| Warning: "; print "'diff' program was not found on the current PATH.\n"; print " | "; } else { # diff found, check that it's GNU - using '-v' should cause error if not GNU, # since there are no arguments (tested with Solaris diff). $diffOut = `diff -v 2>&1` || ""; if( $diffOut !~ /\bGNU\b/ ) { print "Warning: "; print "'diff' program was found on the PATH but is not GNU diff - this may cause problems.\n"; print " | "; } else { print "GNU diff was found on the PATH - this is the recommended diff tool."; print " | "; }
| Warning: "; print "Using Perl on Windows, which may have missing or incorrect locales (in Cygwin or ActiveState Perl, respectively)\n"; print "- use of \$useLocale = 0 is recommended unless you know your version of Perl has working locale support.\n"; print " | |||
| Note: ";
print "This TWiki.cfg parameter sets the site-wide locale - for\n";
print "example, de_AT.ISO-8859-1 where 'de' is the language
code, 'AT' the country code and 'ISO-8859-1' is the character set. Use
the <code>locale -a</code> command on your system to determine available
locales.\n";
print "</td></tr>\n"; # Try to see if required locale was correctly set earlier my $currentLocale = setlocale(&LC_CTYPE); if ( $currentLocale ne $siteLocale ) { print " } # Locales are off, or using pre-5.6 Perl, so have to explicitly list the accented characters my $perlVerPreferred = 5.006; # 5.6 or higher has [:lower:] etc if ( not $useLocale or $perlvernum < $perlVerPreferred ) { # If using Perl 5.005_03 or lower, generate upper and lower case
character
if ( $forUpperNat ) {
print "
been found in this locale and should be considered for use in this
parameter: <b>$forUpperNat</b></p>\n";
} print " | |||
| \$lowerNational: | $lowerNational | ||
| Note: ";
print "This TWiki.cfg parameter is used whenever
<b>\$upperNational</b> is used.\n";
print "This parameter should be set to the lower case accented
characters you require in your locale.\n";
if ( $forLowerNat ) {
print " The following lower case accented characters have been found in this locale and should be considered for use in this parameter: <b>$forLowerNat</b></p>\n"; } print " | |||
|
|||