Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Chmod within a program

Status
Not open for further replies.

LookingBeyond99

Programmer
Jul 2, 2001
18
0
0
US
I have a cgi program that writes to different webpages. One webpage is in a directory with permissions of 000. I was wondering how I could changes its permissions within the perl program. So I would ended up changing that directory from 000 to 777 then write to it and then change it back to 000 before I closed the program.

Thanks a lot for your help!
 
how? in a word, dangerously. make sure the script you do this with is running with taint checking enabled (although it may even be turned on automatically with the use of a setuid script, i would do it explicitly just in case). and take extra care not to let the user do anything they shouldn't.

read 'perldoc perlsec' and 'info chmod'. what you'll do is set the setuid bits of the script so that the kernel sees the script as being a different user than it actually is (in this case, either as the owner of the file in question or as root). from there, you can do all the things you need it to.

depending on the kernel version and OS you're running with, you may have to do some trickery to get this to work - this is explained in 'perldoc perlsec'. "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
echo stillflames' warning. Don't do it. The file system should be set up to facilitate it's use by it's expected users ( like the web server process , httpd daemon). Get the file system correct and then keep the web server process in it's box.

'just my humble opinion.


keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top