Delete a file from a CGI

Matias Surdi matiassurdi at gmail.com
Fri Jun 1 10:04:52 EDT 2007


Thanks for your reply.

This is the code that creates the file:
lock_file = open(".lock","w")
lock_file.write("test")
lock_file.close()
#Change permissions so that CGI can write lock file
os.chmod(".lock",stat.S_IMODE(stat.S_IRWXU | stat.S_IRWXO | stat.S_IRWXG))

This script was run as root.

Now, the code of the CGI that should delete the file:

#As you see, I can write to the file
lock_file = open(".lock","w")
lock_file.write("")
lock_file.close()
# But the following line raises a "permission denied" OSError
os.remove(".lock")

I've seen that the script is running as "nobody", but, the file is rwx by
everybody. I've also tryed changing the owner of the file to "nobody" also,
but no luck anyway.

Thanks a lot.


Steve Holden wrote:

> Matias Surdi wrote:
>> HI!
>> 
>> I want to delete a file from a CGI, but I always get a Permission denied
>> error.
>> 
>> I've tryed this after creating the file (from a normal script):
>> 
>> os.chmod(".lock",stat.S_IMODE(stat.S_IRWXU | stat.S_IRWXO |
>> stat.S_IRWXG))
>> os.chown(".lock",pwd.getpwnam("nobody")[2],pwd.getpwnam("nobody")[3])
>> 
>> but the CGI still can't delete the file.
>> 
>> I will appreciate very much your help.
>> 
>> Thanks a lot.
>> 
>> 
> How was the file created in the first place? If you don't have
> permissions to delete it you may well not have permissions to reown it
> or change its permissions either!
> 
> regards
>   Steve





More information about the Python-list mailing list