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

Discussion in 'Perl Misc' started by oleg106@yahoo.com, Aug 22, 2006.

  1. Guest

    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.
     
    , Aug 22, 2006
    #1
    1. Advertising

  2. Ben Morrow Guest

    Quoth :
    > 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

    --
    Razors pain you / Rivers are damp
    Acids stain you / And drugs cause cramp. [Dorothy Parker]
    Guns aren't lawful / Nooses give
    Gas smells awful / You might as well live.
     
    Ben Morrow, Aug 22, 2006
    #2
    1. Advertising

  3. <> wrote:

    > 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.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Aug 23, 2006
    #3
  4. 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;


    Glenn Jackman wrote:
    > At 2006-08-22 03:56PM, "Ben Morrow" wrote:
    > > > #! /usr/bin/perl -w

    > > ^
    > > You don't want this space.

    >
    > Nothing wrong with spaces there. See exec(2)
    >
    > --
    > Glenn Jackman
    > Ulterior Designer
     
    alpha_beta_release, Aug 24, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. raocheng
    Replies:
    2
    Views:
    620
    Reedick, Andrew
    Jan 18, 2008
  2. news.microsoft.com

    WScript.Shell to execute Ms-DOS commands?

    news.microsoft.com, Dec 8, 2003, in forum: ASP General
    Replies:
    2
    Views:
    243
    news.microsoft.com
    Dec 9, 2003
  3. Aayush Dubey
    Replies:
    0
    Views:
    536
    Aayush Dubey
    Aug 13, 2004
  4. Replies:
    8
    Views:
    293
    Woody Peterson
    Sep 12, 2008
  5. Luckystr Luckystr

    Can't execute shell commands in CGI

    Luckystr Luckystr, Aug 15, 2009, in forum: Ruby
    Replies:
    6
    Views:
    266
    Luckystr Luckystr
    Aug 18, 2009
Loading...

Share This Page