opening a file using CGI
kprasanna_79
created: 2006-01-03 22:01:03
Hi Monks,

Kindly ignore if its not a valid question. I am trying to open a file, which is present in my home directory(/home/prasanna).I am getting the file name from the user and concatinating it with the path.

My question is can we access the file outside the cgi-bin/htdocs directory.I think this is clear. But when i tried to open i couldnt able to open. Can any one help me

Update:-

I am using apache as my web server

-Prasanna.K
Re: opening a file using CGI
created: 2006-01-03 22:16:37
The most likely problem is that the web user (the user under whose authority Apache is running) doesn't have authority to open a file in your home directory. But we can't tell, because you didn't show us the error message that the open() command produced. Please post a little code, and we can probably help you more effectively. :)

No good deed goes unpunished. -- (attributed to) Oscar Wilde
Re: opening a file using CGI
created: 2006-01-03 22:19:14
Have you tried printing the path and checking to make sure it's valid? Keep in mind that opening a file requires the full path, not just the path from your hosting account.

Also, if the file doesn't have the proper permissions, that may be blocking the read. If you're using the full path, and the path matches correctly, check permissions.

Re: opening a file using CGI
created: 2006-01-03 22:21:54

Yes to all of what ptum said.

As a possible fix, you can change permissions on your home directory and the file(s) the web users will need to access. However, this may present a security risk on multiple levels.

Re: opening a file using CGI
sk
created: 2006-01-03 22:26:05
As mentioned by [ptum] the problem is likely due to file perm. I did this on my machine (Apache 2.0/Mod_perl) -

#!/usr/bin/perl -wT

use strict;
use CGI;
use CGI::Carp   qw/fatalsToBrowser/;

open (OUT, ">/no/perm/path/junkfile") or die $!;

print OUT ("hi there\n");

close(OUT);

I get this -

Software error:

Permission denied at /var/www/html/perl/create.cgi line 7.

For help, please send mail to the webmaster (root@localhost), giving this error message and the time and date of the error. 

However when i changed the path to /tmp/junkfile (world-writeable for me) it works just fine. I guess if you turn on the fatalsToBrowser (turn it off for production) you will get more info. Also take a look at your apache logs!

cheers

SK

Re: opening a file using CGI
created: 2006-01-03 23:42:21
Hi Prasanna,

      The most of the errors can happen with the permissions issues. I hope that you got enough information from the above replies. In addition to that , i want to add one more thing.

      In Redhat Linux Enterprise Edition - 4, we have some thing called as "Selinux". That is another extended linux security for linux files. That one also plays as important role in file permissions when using through apache. You can also find the enough information in "man selinux". You go through that page and give appropriate file permissions.



Regards,
S.Venni Rajan.
"A Flair For Excellence."
                -- BK Systems.

perlmonks.org content © perlmonks.org and kprasanna_79, ptum, sk, TedPride, vennirajan, wink

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03