1
votes

I have to save a file in the server with a CGI C program and then access it with the client. If I save the file in the cgi-bin directory, it works but I cannot access it with the client because that directory is protected. If I try to save the file in another directory, the fopen function can't create the file.

FILE *fh = fopen (filename, "wb");    

Working but file not accessible.

FILE *fh = fopen (//var//www//filename, "wb");   

Not working. The directory is writeable, it works if I run the statement on a local C program.

So, how I can give permissions to CGI programs to write in the www directory?

I'm using Ubuntu and apache.

Thank you

1
if you tried it like this be sure it would not work FILE *fh = fopen (//var//www//filename, "wb");.You forgot to add FILE *fh = fopen ("//var//www//filename", "wb"); maybe that's why, and try to specify the whole path. - bitcell
Have you tried chmod a+rw /var/www? Default permissions for CGI scripts are: 0755 (rwx-rx-rx), whereas you probably want 0766 (rwx-rw-rw) or something - Elias Van Ootegem

1 Answers

0
votes

The permissions were OK. It was a problem in the C code. I solved it using

snprintf(pathFile,120,"//var//www//files//%s",filename);
FILE *fh = fopen (pathFile, "wb");