Messages in this thread | | | Date | Sat, 2 Jan 2010 09:19:28 -0600 | From | Jeff Epler <> | Subject | Re: how to get right euid? |
| |
On Sat, Jan 02, 2010 at 09:16:42PM +0800, Kevin Qu wrote: > sudo echo "some thing" > /proc/my_file > > It denied. (But it works when I su to superuser and do so.) > > So I checked the current_euid(), > but it returns 1000 (not 0),Why?
This may be due to a misunderstanding of how shell redirects work. Probably current_euid() is returning exactly the right thing.
When you execute some command line > somefile the shell opens somefile for writing and makes it be fd 1 (stdout) using dup2. Then it execs 'some' with the argument array being ['some', 'command', 'line'].
So consider your sudo: The shell, running as user 1000, opens 'somefile' for writing, then execs 'sudo' which happens to be setuid root.
Jeff
| |