2

Having a weird problem on a Solaris 10 box. I have a cgi script (perl) which needs to overwrite a file. We do not have suexec running on Apache so the destination directory has full (777) access so that Apache can write to it.

The problem is that the CGI script is able to write a new file to the directory but not overwrite an existing file.

**Directory permissions for file destination:** 

drwxrwxrwx 146 myuser white      32768 Jun  2 20:46 dest-dir

**File Permissions of file that needs to be over written:** 

-rw-r--r--   1 myuser white      0 Jun  2 20:50 cgitestfile

Anyone know a simple solution for resolving this ??

Seems like apache can only overwrite a file if it owns it.

3 Answers 3

1

-rw-r--r-- 1 myuser white 0 Jun 2 20:50 cgitestfile

You only have write permissions on the file for owner (myuser) Is apache running as user myuser? or as apache or www.data or something like that? Perhaps you need to add write access for other?

1
  • Thanks all. I chose to just re-chmod the file each time when I re-write it either in the perl or cgi script. Simple enough. Thanks !
    – user770395
    Jun 2, 2011 at 22:25
1

On Solaris 10 the default is for apache to run as User nobody, Group nobody (check /etc/apache/httpd.conf User and Group directives). Given your example apache won't be able to write to the cgitestfile as it has no write access to it.

Change the owner:group of dest-dir and the files you want apache to overwrite to nobody

0

I ran into this due to the "SELinux" configuration. If SELinux is running, you need to explictly enable the ability for Apache to write to files. To use this, you also need to set additional permissions on those directories and files for which you are granting write access.

To determine if SELinux is enabled, execute:

sestatus

To turn on the SE booleans which enabled cgi to write to files:

sudo setsebool -P allow_httpd_anon_write 1
sudo setsebool -P allow_httpd_sys_script_anon_write 1

Then, finally to set the file/directory "SELinux security context type" to a "system" read/write file/directory (you could also make it a "public" type - Google "chcon" for info), execute this:

sudo chcon -R -t httpd_sys_rw_content_t /some/write/path

(Change /some/write/path to your path.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .