Forum Moderators: coopster

Message Too Old, No Replies

permission issues and inheritance...

Dealing php with folders owned by other users

         

ethan

12:38 pm on Aug 26, 2004 (gmt 0)

10+ Year Member



Hi there,

it happens that I'm coding a script that parses html documents and alters them.

Lets say I have all them under

/home/user/htdocs/site.com/content/

and I have chmod 777 this folder with my FTP client.

The problem comes when a new folder is created within this one, when a user uploads new documents thru FTP.
Such users own the folder and documents, and the permission of them becomes 755.

Askin the users to chmod their uploaded folders to 777 everytime they do upload something is not a practical sollution...

So, the question is:

how can I make that all folders that user creates within the content/ folder are automatically writable by everyone?

thx!

ethan

1:54 pm on Aug 26, 2004 (gmt 0)

10+ Year Member



I have been trying lots of thinks, and searching the net found one possible workarround:

make the content/ folder owned by php.

So I chmod'ed to 0777 the parent folder, and made
a php script that creates a new folder called content.

The problem is that the script can't set chmod this folder to 0777. Does not allow me to set the folder to be writable by everyone. (If not doing so, user can't upload files to that folder thru ftp... )

Any ideas on why php can't create a folder and set it to 0777? note: safe_mode is disabled in the server.

thx!

ethan

4:29 pm on Aug 26, 2004 (gmt 0)

10+ Year Member




I finally made php to chmod to 0777 the content folder, the error was a typo in the path ( hells! )

But not tht the php user is the owner of content/ folder, when an user uploads something in a new subfolder, such user is the owner of that folder with permission 0755 by default, so the script still can't write there...

Anyone has any ideas?

py9jmas

4:38 pm on Aug 26, 2004 (gmt 0)

10+ Year Member



Firstly, having permissions set to 777 is completely insecure.

Secondly, you want to set the setuid bit on the directory permission.

Directories with this bit set will force all files and sub-directories created in them to be owned by the directory owner and not by the uid of the creating process

All new files and directories will then automatically be owned by the owner of the content/ directory.

So you're looking for something like chmod 4755 content/

ethan

5:42 pm on Aug 26, 2004 (gmt 0)

10+ Year Member




I just tried it with:

chmod("/path/to/content", 4755);

but the resulting is that I do get the content folder with permissions: 223

Do you know why does this happens?

Thanks a lot!

ethan

10:14 am on Aug 27, 2004 (gmt 0)

10+ Year Member




I noticed in a comment at [php.net...] that the correct way to chmod with setuid, setgid and sticky bit is to place a 0 infront for the correct octal value...

So insead chmod ("folder", 4777);

it would be

chmod ("folder", 04777);

But even when I have done this, seems to have no effect in the FressBSD 4.7 server. As it is mounted in a nfs partition, perhaps it has disabled the setuid support...