'shutdown' and 'cat'


 
Thread Tools Search this Thread
# 1  
Old 11-24-2008
Power 'shutdown' and 'cat'

Hi All,

This is actually a good interview question.

On linux, the permissions and group for 'shutdown' and 'cat' is the same.

-rwxr-xr-x 1 root root 18K 2008-05-21 10:43 shutdown
-rwxr-xr-x 1 root root 17K 2007-01-30 19:51 cat

Then why is it that a normal user cannot run the 'shutdown' command ?

I've done some searching and I think it has something to do with SUID.
The 'shutdown' command calls the seteuid(0) where as the 'cat' command does not.

Is this correct ? Could someone please verify? Also is there a list of commands which can only be run by su even though the permissions are the same? I mean how can we know?
Thanks.

Last edited by scottsiddharth; 11-25-2008 at 12:00 AM..
# 2  
Old 11-25-2008
Since there is no SETUID bit set, as you can see yourself looking at the permissions, I think it is the binary itself checking who is executing it. If you try different binaries in /sbin as a non root user you get different output, so it seems not to be a system wide mechanism.

Here is a good explanation for SETUID bit etc., 6.2:

Linux permissions
# 3  
Old 11-25-2008
The following:

/sbin/halt

in suse uses geteuid. If it's not superuser it reportsL
halt: must be superuser.
# 4  
Old 11-25-2008
This happen because your normal user can't setuid to 0. Try this and see why you cannot run successfully shutdown with normal user:

$ strace shutdown

and

# strace shutdown
# 5  
Old 11-25-2008
Yes, shutdown uses this, I was reporting halt. Thanks.
# 6  
Old 11-25-2008
$ strace ./shutdown

execve("./shutdown", ["./shutdown"], [/* 16 vars */]) = 0
.
. *****text omitted*****
.
getuid32() = 8218
geteuid32() = 8218
setuid32(8218) = 0
getuid32() = 8218
write(2, "shutdown: you must be root to do"..., 39shutdown: you must be root to do that!
) = 39
exit_group(1) = ?
Process 6144 detached
*************************************************

$ ./shutdown
shutdown: you must be root to do that!


Wow. Thanks dude. Never knew such a command existed even.
 

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Server Shutdown manoj.solaris AIX 3 01-07-2011 10:49 AM
Script to force Oracle database shutdown when shutdown immediate does not work aixhp UNIX for Dummies Questions & Answers 7 03-11-2010 01:04 PM
Script sh for shutdown Dymblos Shell Programming and Scripting 1 11-12-2009 02:24 PM
shutdown command manoj.solaris AIX 3 06-25-2009 04:38 AM
Understanding shutdown chebarbudo UNIX for Dummies Questions & Answers 6 02-17-2009 09:34 AM
cat in the command line doesn't match cat in the script shira Shell Programming and Scripting 21 01-28-2009 10:15 AM
for i in `cat myname.txt` && for y in `cat yourname.txt` danimad Shell Programming and Scripting 1 11-06-2008 12:14 AM
Difference between cat , cat > , cat >> and touch !!! skyineyes UNIX for Dummies Questions & Answers 6 05-28-2008 07:21 AM
A script for shutdown kelu UNIX for Dummies Questions & Answers 12 08-23-2006 09:09 PM
Shutdown aewpcoles UNIX for Advanced & Expert Users 6 08-03-2006 09:46 AM
How do you shutdown from login? kapolani UNIX for Dummies Questions & Answers 1 07-08-2005 09:55 AM
Shutdown scripts luft SuSE 1 05-15-2005 06:17 AM
non root shutdown???? byblyk Linux 4 07-26-2004 02:01 AM
to shutdown rajashekaran UNIX for Advanced & Expert Users 2 02-18-2002 12:42 PM