File I/O Question 
Author Message
 File I/O Question

Hello,

I am writing a CGI program in C on a Unix box and trying to open and
write to a text file within the CGI.  The only way I can get it to work
is if the text file is already created and already has permissions set
for others.  I tried disabling the permissions(using chmod o-w fname)
and use the chmod(fname,S_IWOTH) function in the program to dynamically
set the permissions bu this did not work. Nor did system("chmod o+w
fname").

Any Ideas?

TIA
Andy C.



Thu, 06 Jan 2000 03:00:00 GMT  
 File I/O Question



Quote:
>Hello,

>I am writing a CGI program in C on a Unix box and trying to open and
>write to a text file within the CGI.  The only way I can get it to work
>is if the text file is already created and already has permissions set
>for others.  I tried disabling the permissions(using chmod o-w fname)
>and use the chmod(fname,S_IWOTH) function in the program to dynamically
>set the permissions bu this did not work. Nor did system("chmod o+w
>fname").

chmod() and file permissions are a Unix relates issue, the C language
knows nothing about them. Your best bet would be to ask over on
comp.unix.programmer.

Quote:
>Any Ideas?

Well, in order to create a file your user need to have write permissions
on the directory you want to create the file in. See comp.unix.programmer
for more ideas.

--
-----------------------------------------


-----------------------------------------



Fri, 07 Jan 2000 03:00:00 GMT  
 File I/O Question



[>I am writing a CGI program in C on a Unix box and trying to open and
[>write to a text file within the CGI.  The only way I can get it to work
[>is if the text file is already created and already has permissions set
[>for others.  I tried disabling the permissions(using chmod o-w fname)
[>and use the chmod(fname,S_IWOTH) function in the program to dynamically
[>set the permissions bu this did not work. Nor did system("chmod o+w
[>fname").

[>Any Ideas?

------- Depending on who your web server runs as, your cgi may my have
enough permissions to write you the file you want. Web servers usually
run as nobody, and so do cgis. If you just need a temporary file, use
the /tmp directory.
--
 Mariusz Zydyk                           http://www.ucalgary.ca/~mszydyk/

           How do you make holy water? Boil the hell out of it.



Fri, 07 Jan 2000 03:00:00 GMT  
 File I/O Question

Trust me when I say that you are very glad that your server doesn't
allow your cgi to dynamically change permissions to files.  It is a
security hole waiting to happen.  All a hacker has to do is trick the
cgi into using a filename different from what you had in mind and
bingo...your whole system is comprimised, not just your account.

The text file usually doesn't have to necessarily be already created,
it's just that the problem is that a text file doesn't come default with
a+rwx permission, which you need to use it via CGI.  That's why the file
has to exist...so you can set the permission on it and use it.  

I like playing with CGI, so if you have any more questions about it, ask
me.  

Thanks

Jay



Fri, 07 Jan 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Diff between PPC OS / HPC OS/ eXP OS

2. How to retrieve the date os a file ?

3. OS Question

4. OS/390 C program File I/O Problem with JCL

5. os question

6. Questions about compilers and executable formats for a new OS

7. More file handle for CRTLIB in OS/2

8. Make file (OS/2's nmake) and rcs

9. Playing *.wav files with OS/2

10. MFC / Database / OS questions and considerations

11. Linker question (Sun/OS)

12. CFile exception: accessDenied, File Unknown, OS error information = 5 -- Updated

 

 
Powered by phpBB® Forum Software