Permission denied trying to execute shell commands from Perl/CGI.

O

oleg106

Hi,

I just installed Apache and I am trying to call a script that should
output some stuff to my browser. I can't get this to work at all.

Simple script

#! /usr/bin/perl -w
print "Content-type:text/html\n\n";
print `ls`;

The screen is blank. httpd logs indicate permission denied ...

[Tue Aug 22 14:54:32 2006] [error] [client 172.25.31.80] ls: .,
referer: http://salrhellog01/maillog/
[Tue Aug 22 14:54:32 2006] [error] [client 172.25.31.80] : Permission
denied, referer: http://host/log/

Any idea? The script works just fine locally, but not via the web. I
tried exec and system, same deal. User nobody has access to everything
it needs.
 
B

Ben Morrow

Quoth (e-mail address removed):
Hi,

I just installed Apache and I am trying to call a script that should
output some stuff to my browser. I can't get this to work at all.

Simple script

#! /usr/bin/perl -w
^
You don't want this space.

You want
use warnings;
instead of -w.

You want
use strict;

Have you read the Posting Guidelines?
print "Content-type:text/html\n\n";

It's not nice to lie. The output of ls(1) is not HTML, so don't pretend
it is.

In any case, you should provide a charset parameter for text/
content-types. Not doing so can lead to invoking browser bugs.
print `ls`;

The screen is blank. httpd logs indicate permission denied ...

[Tue Aug 22 14:54:32 2006] [error] [client 172.25.31.80] ls: .,
referer: http://salrhellog01/maillog/
[Tue Aug 22 14:54:32 2006] [error] [client 172.25.31.80] : Permission
denied, referer: http://host/log/

Any idea? The script works just fine locally, but not via the web. I
tried exec and system, same deal. User nobody has access to everything
it needs.

Well, my initial guess would be that (for some reason) your web server
user doesn't have read permission on the current directory. What happens
if you run the script as the right user from the right directory?

Ben
 
T

Tad McClellan

I just installed Apache and I am trying to call a script that should
output some stuff to my browser. I can't get this to work at all.

#! /usr/bin/perl -w
print "Content-type:text/html\n\n"; ^^^^
^^^^
print `ls`;


The ls program does not output HTML...

The screen is blank. httpd logs indicate permission denied ...
Any idea?


Ask questions about web server configuration in a newsgroup
about web servers:

comp.infosystems.www.servers.mac
comp.infosystems.www.servers.misc
comp.infosystems.www.servers.ms-windows
comp.infosystems.www.servers.unix

or a newsgroup about programming in the CGI environment:

comp.infosystems.www.authoring.cgi

The script works just fine locally, but not via the web.

perldoc -q 500

My CGI script runs from the command line but not the browser. (500
Server Error)
I
tried exec and system, same deal.


Changing the Perl won't have much effect since you do not have
a Perl problem...

User nobody has access to everything
it needs.


Not if you are getting permission denied it doesn't.
 
A

alpha_beta_release

Use taint mode -T. The following i run with Apache on Windows. For
*NIX, linux,change 'c:/windows/system32'' to system path

---------------------------------------------
#!c:/perl/bin/perl -Tw
# ^

# u need to set this during Taint mode
$ENV{PATH} = 'c:/perl/bin/perl;c:/windows/system32';

use strict;
use CGI;
use CGI::Carp 'fatalsToBrowser'; # would help, but only to debug

my $page = new CGI;

my $content;
local $/;
if (!open(PIPE1, '-|', "dir -w *")) {
print $page->header('text/plain'),
"ERROR : Can't list - $!";
exit;
}
$content = <PIPE1>;
close PIPE1;

print $page->header('text/plain'),
$content;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top