LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-11-2010, 04:35 PM   #1
tdnnash25
Member
 
Registered: Apr 2009
Posts: 63

Rep: Reputation: 15
Question how can www-data chown a file?


I have a php script that creats some files and moves them into certain directories. When the files are created, the ownership is www-data:www-data

When they are moved to the appropriate directories the maintain that. But, I need the files' ownership to be changed to asterisk:asterisk

However, www-data doesn't have permissions to do this. I don't want to run a cron as root that does this (I'm already doing that). I really wish there was a way for my files to be created via my php script and in that same file do something like:
system("chown asterisk:asterisk /home/test/test.call");

but that fails

any ideas?
 
Old 06-11-2010, 04:48 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,604

Rep: Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960
Quote:
Originally Posted by tdnnash25 View Post
I have a php script that creats some files and moves them into certain directories. When the files are created, the ownership is www-data:www-data

When they are moved to the appropriate directories the maintain that. But, I need the files' ownership to be changed to asterisk:asterisk

However, www-data doesn't have permissions to do this. I don't want to run a cron as root that does this (I'm already doing that). I really wish there was a way for my files to be created via my php script and in that same file do something like:
system("chown asterisk:asterisk /home/test/test.call");

but that fails

any ideas?
How does it fail? What does it show you in the logs?

When you create the file, you (obviously) have permissions to write/modify it...why don't you do the chown on it, BEFORE you move it to the destination directory, since you can't do it once the file is moved?
 
Old 06-11-2010, 05:03 PM   #3
tdnnash25
Member
 
Registered: Apr 2009
Posts: 63

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by TB0ne View Post
How does it fail? What does it show you in the logs?

When you create the file, you (obviously) have permissions to write/modify it...why don't you do the chown on it, BEFORE you move it to the destination directory, since you can't do it once the file is moved?
The thing is, apparently I can't even chown of the file in the directory it is created in...

I tested by doing the following:
su - www-data
chown asterisk:asterisk 7854102216201006111810.00-20100611165928.call
chown: changing ownership of `7854102216201006111810.00-20100611165928.call': Operation not permitted
 
Old 06-11-2010, 05:34 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,604

Rep: Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960
Quote:
Originally Posted by tdnnash25 View Post
The thing is, apparently I can't even chown of the file in the directory it is created in...

I tested by doing the following:
su - www-data
chown asterisk:asterisk 7854102216201006111810.00-20100611165928.call
chown: changing ownership of `7854102216201006111810.00-20100611165928.call': Operation not permitted
Hmm....tried this on my system here, and it did the same thing. Never noticed that before.

Apparently, only root can chown a file to another user ID. A plausible workaround would be to add the www-data user into the SUDO'ers file, and give them no-password access just to the chown command. Then you could use the system call as "sudo chown asterisk:asterisk <filename>". That said, I'd make VERY sure that the www-data user can't run "chown root", just "chown asterisk"...otherwise, that's a nice security hole...
 
Old 06-11-2010, 06:48 PM   #5
ComputerErik
Member
 
Registered: Apr 2005
Location: NYC
Distribution: Debian, RHEL
Posts: 269

Rep: Reputation: 54
Why does it need to be owned by asterisk, why not just change permissions so that the user has full access to the file? At least that is more secure than giving sudo permissions to a service account which is designed to be limited in scope and usage.
 
Old 06-12-2010, 09:53 AM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,604

Rep: Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960
Quote:
Originally Posted by ComputerErik View Post
Why does it need to be owned by asterisk, why not just change permissions so that the user has full access to the file? At least that is more secure than giving sudo permissions to a service account which is designed to be limited in scope and usage.
Very true, but my suggestion was to only grant SUDO access to one specific command. The OP had asked about how to chown it, so that's what I tried to address.
 
Old 06-12-2010, 11:33 AM   #7
ComputerErik
Member
 
Registered: Apr 2005
Location: NYC
Distribution: Debian, RHEL
Posts: 269

Rep: Reputation: 54
Quote:
Originally Posted by TB0ne View Post
Very true, but my suggestion was to only grant SUDO access to one specific command. The OP had asked about how to chown it, so that's what I tried to address.
Understood, but I still stand by my position of not wanting to give www-data any sudo permissions, even if limited. In theory if www-data could do sudo chown it would be possible for that to change ownership of files /directories other than those intended.

Ultimately though without fully understanding what is going on, and why this is being done it is hard to make a call as to the best solution. I was just trying to come at it from another angle the OP might not have considered.
 
Old 06-12-2010, 11:45 AM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,604

Rep: Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960Reputation: 7960
Totally agree, and it is a VERY bad thing to give SUDO away. But, in this case, if you limit that user to just a "chown asterisk" command only, the only thing that user can do is chown a file to another non-privileged user.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
www-data tommytomato Linux - Newbie 35 03-19-2010 02:03 AM
www-data execute iptables Legolas891 Linux - Security 2 12-22-2009 03:36 PM
Why does www-data have /bin/sh as a shell? reverse Debian 2 11-18-2007 07:35 AM
www-data group not appearing in file permissions tab nick1 Ubuntu 1 05-01-2006 11:48 AM
add www-data user restless Linux - Newbie 1 06-01-2004 07:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration