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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

chmod 1

Status
Not open for further replies.

ThomasJSmart

Programmer
Sep 16, 2002
634
not sure if i should post this here or in linux forum...

anyway i need to set the chmod of a folder,

i need a folder to be 777 while i do some commands, and when im finished i need it back on 755.

using the php chmod function doesnt work tho because php is running as nobody i guess. is there a way i can run this command through system() or exec() ?



I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!
 
if you have sudo rights why don't you run the scripts via sudo and exec()?

be aware that this is a big security risk though. unless it is unavoidable, i'd advise you redesign your app so that the directories etc you need to operate on are owned by the same group as the webserver.
 
Hi, thank you for your help,
there is no way to redesign this system, this is realy how it has to work :/

how do i call sudo from php?

is that like exec("su user:password") or something ?

so this would mean anybody who can get the code can get the login to a server user ? unless i encrypt the code.


I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!
 
i don't see how you could encrypt the code to be honest. at least, not so that anyone with access to the script could get access.

i would add the apache user to the sudoers file and restrict its credentials to have access only to chmod. not perfect.

you can't supply the password to sudo in the command line in that manner (I think). you need to supply it via STDIN and tell sudo to look for the pwd in STDIN. lots of examples for this on the web

alternative is to give the apache user sudo right without pwd. again, you can restrict its commands.

last alternative i can think of is to use exec to call php-cli on a scipt that sits outside the webroot. that script could have the sudo password in it. just another layer of protection but nothing that a determined hacker could not bypass - but frankly once they have access to your php code, your screwed anyway.
 
cheers, i should be able to fix it with this :)

I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!
 
Status
Not open for further replies.

Similar threads

Replies
2
Views
22
Replies
4
Views
35
Replies
1
Views
27
Replies
5
Views
24

Part and Inventory Search

Sponsor

Back
Top