datannen has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a perl script in CGI in which I'm trying to execute:
system ("mv /home/test/10 /home/web/10");
/home/test/10 is not inside my DocumentRoot which is /home/web so it gives me a Permission denied error.

The script works fine when not run through a browser. Permissions on the directory are chown'ed for my webuser "www" and chmod 777...

Any ideas how I can get around this?

NOTE: I don't want /home/test accessible through a browser so a symlink is not going to work.

Replies are listed 'Best First'.
Re: Apache & Perl CGI Directory Permissions
by davis (Vicar) on Sep 10, 2003 at 09:20 UTC

    /home/test/10 is not inside my DocumentRoot which is /home/web so it gives me a Permission denied error.
    That's an incorrect analysis. CGI scripts can do whatever the user the scripts are run as can. E.g.:

    use warnings; use strict; use CGI qw(:standard); print header(); print start_html(-title=>"Nasty"); open(FOO, "<", "/etc/passwd") or die "Couldn't open\n"; print <FOO>; close(FOO); print end_html();

    The above prints out my passwd file, albeit with dodgy line endings, but that's irrelevant. The reason it can do this is because my webserver user has read access to the passwd file. The problem you're most likely facing is that www can't write to /home/test. Try copying the file first to test this. Hint: you could use the File::Copy module, which is in core.


    davis
    It's not easy to juggle a pregnant wife and a troubled child, but somehow I managed to fit in eight hours of TV a day.
    Update: Fixed typo.
Re: Apache & Perl CGI Directory Permissions
by Abigail-II (Bishop) on Sep 10, 2003 at 08:49 UTC
    I don't want /home/test accessible through a browser so a symlink is not going to work.

    Then that's the source of your problem. If /home/test isn't accessible, the mv command can't access it either, and hence you get a Permission denied error.

    Abigail

Re: Apache & Perl CGI Directory Permissions
by Anonymous Monk on Sep 10, 2003 at 08:54 UTC
    Any ideas how I can get around this?
    The only way to "get around this" is to get permission (not a perl specific issue).