http://qs321.pair.com?node_id=639668

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

Hello All:
 
This is probably more an apache issue than a perl issue. Still, I have been asking for help from apache folks and gotten none. So in the words of Mathezar of Galaxy Quest, "You are our last hope!"
 
There is a similar thread under "System and CGI - File Created but not the Content". I thought this was different enough to post separately becasue SELinux is off in my case and perl is the file writter.
 
#!/usr/bin/perl use strict; print "Content-Type: text/html\r\n\r\n"; print "<HTML>\n"; print "<HEAD>\n"; print "</HEAD>\n"; print "<BODY>\n"; my $filename ="/var/www/html/DATA/kk.txt"; open(KK,">$filename"); close(KK); # this line and the nex +t 2 were not part of system("chmod 666 $filename"); # of the original code. + They were added to open(KK,">>$filename"); # see if changing the p +ermissions would help print "we are trying to write\n"; print KK "we are trying to write\n"; close(KK); print "</BODY>\n"; print "</HTML>\n";
When executed the browser shows "we are trying to write", the /var/www/html/DATA/kk.txt file exists, it is 666, owned by apache and has zero content.
 
I am running FC4, Apache 2.0.54, perl 5.8.6, the server is not attached to the internet.
 
I have done what should never be done: 777 permissions on /var, /var/www, /var/www/html.
Below html I have a directory called DATA, also 777
user apache owns everything below var
setenforce 0 to remove SElinux
(basically, a desperate and ridiculous attempt to allow files to be written)
 
The odd thing is that the original program (from which this was extracted) up to 10am 9/17/2006. After that, the machine, untouched, exhibited the new behaviour.
 
All written files prior to 10 am 9/17 are apache 644 and have content. All written files after to 10am 9/17 are apache 644 and are empty.
 
1) I am probably not doing this the right way ... where should I be writting the files and how should I set upms and httpd.conf. I have been trolling google with "apache permissions" apachec cgi write files" and the like. If you have links to howtos, please send them!
 
2) In the above case, can I determine the reason and fix it? It would be nice to be able to dial back the permissions to something reasonable
 
Thanks in advance.

Replies are listed 'Best First'.
Re: System and CGI - File Created but not the Content (Similar Situation)
by Joost (Canon) on Sep 18, 2007 at 15:41 UTC
Re: System and CGI - File Created but not the Content (Similar Situation)
by snopal (Pilgrim) on Sep 18, 2007 at 18:53 UTC

    You might not have permission to write to the file.

    The system call to chmod swallows up any error messages, and will not report the output to any error log. You are better off using the perl chmod command because it will complain when it has trouble.

    It is feasible that your code could create a file to which it can not write. You need to check not only the resulting permissions on the file, but the immediate parent directory as well, assuming it exists.

    UPDATE: What I mean is that you might have all the permissions turned on, but the wrong user owns the file. It looks like due-diligence on your part, so I'm just throwing stuff out there.

      Checked all permissions. The apache configuration has apache as the user that executes and the file is 666 and owned by apache when it is finished. The parent and its parent are 777 (also owned by apache). Error logs are empty of any references to this. That's why I don't get it. I'll try the perl chmod suggestion to see if I get error reporting and let you know.
      I am presuming that the configured user for apache (called apache) is what is running the script.