in reply to Script not setting ownership of new directory

As you must know, "chown" on any unix or linux box is strictly a root-user activity. There is simply no way to provide chown access without also providing root access. If you want your web server to run a cgi process that does chown, it must run as root, or else you must violate a basic principle of OS security by creating a set-uid script that does chown. In either case, you will be fully entitled to all the risks and disasters that this could conceivably support.

It would be better for the web transaction to create some sort of signal or other symptom that could be picked up by a separate, root-owned process (not directly accessible via http), so that this root-owned process could do the right thing in terms of changing ownership on specific files, so that a web process does not need to do this.

Or, you could run a process under your "sftp" user account that copies the uploaded files and thereby assumes ownership of the copies. If you want to keep the files where they are with original names intact, and the "sftp" user is able to have write access in the directory where the "www-data" user puts uploaded files (e.g. if they are both included in a given group, and there's group write access on the directory), "sftp" can rename the uploaded files, copy them to the original names (thereby taking ownership) and then delete the www-owned originals. "Look, ma! No root privileges!" (Generally better and certainly safer that way, IMHO.)

  • Comment on Re: Script not setting ownship of new directory

Replies are listed 'Best First'.
Re^2: Script not setting ownship of new directory
by pc88mxer (Vicar) on Jul 29, 2008 at 05:18 UTC
    chown will allow a user to change the group of a file to any group that the user is member of. But, in general, you need to have effective root privs to change the owner.
      Right. It seems I misunderstood the OP's question. I thought (mistakenly) he was talking about changing user ownership. If it's just a matter of changing group ownership, then yes, chown should work fine without root privilege and without problems, so long as the current user is included in the target group.
Re^2: Script not setting ownship of new directory
by JavaFan (Canon) on Jul 29, 2008 at 13:09 UTC
    As you must know, "chown" on any unix or linux box is strictly a root-user activity.

    That's not entirely true. Sure, (with the exception already pointed out), you have to be root on most unix boxes, but there have been OS versions (older versions of SunOS/Solaris for instance) that allowed users to "give away" their files. That is, they could "chown" their own files to some other user. While I've used that feature once or twice, it's not something I really miss.

      HP-UX also supports it.

      --MidLifeXis