Bug 104062 - Using /sbin/reboot as the shell of a special account does not work as expected
Summary: Using /sbin/reboot as the shell of a special account does not work as expected
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: sysvinit
Version: rawhide
Hardware: i386
OS: Linux
medium
low
Target Milestone: ---
Assignee: Bill Nottingham
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-09-09 15:42 UTC by Dale R. Worley
Modified: 2014-03-17 02:38 UTC (History)
1 user (show)

Fixed In Version: 2.86-1
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2005-12-20 20:08:45 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
Patch to halt.c to improve its detection of "what name it was invoked using", and thus select the correct action to take. (746 bytes, patch)
2003-09-09 15:44 UTC, Dale R. Worley
no flags Details | Diff

Description Dale R. Worley 2003-09-09 15:42:38 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.2) Gecko/20030716

Description of problem:
Description:

I have created accounts so that one can halt or reboot the system without first
logging into 'root', by putting these entries in /etc/passwd:

    shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
    halt:x:7:0:halt:/sbin:/sbin/halt
    reboot:x:0:0:reboot:/sbin:/sbin/reboot

The first two are standard in the RH 8.0 distribution; I have added 'reboot'. 
All three logins have the same password as 'root', thus providing security.

However, the 'reboot' login halts the system, rather than rebooting it.  To the
best of my memory, the 'reboot' login worked as expected in RH 7.2.

Diagnosis:

/sbin/reboot is a symbolic link to /sbin/halt.  The binary determines whether it
is supposed to "shut down and halt" or "shut down and reboot" by examining the
name under with it was invoked, which is pointed to by argv[0].

However, when the binary is invoked by login(?) via the 'reboot' entry in
/etc/passwd shown above, argv[0] has the value "-reboot".  The binary does not
recognize this as meaning that it was invoked as "reboot", and so performs its
default action, "shut down and halt."

The logic for these tests is at lines 168 to 181 in sysvinit-2.84/src/halt.c in
sysvinit-2.84.tar.gz in SysVinit-2.84-5.src.rpm.  The value of argv[0] provided
by login was determined by inserting "sleep(60);" at the beginning of main() in
halt.c, logging into 'reboot' on another VC, attaching to the sleeping reboot
process using GDB, and using the usual GDB commands to determine the value of
argv[0] and the action of the logic in halt.c in processing it.

Suggested fix:

Augment the "Find out who we are" logic in halt.c by adding logic to detect and
remove any leading "-" on the program name.  A patch to do this is attached.

Version-Release number of selected component (if applicable):
SysVinit-2.84-5

How reproducible:
Always

Steps to Reproduce:
1.Add this entry to /etc/passwd:  reboot:x:0:0:reboot:/sbin:/sbin/reboot

2.Log in as 'reboot', thus initiating system shutdown.    

Actual Results:  System shuts down and halts.


Expected Results:  Systen should shut down and then reboot.


Additional info:

This bug can be worked around by having the "shell" of login 'reboot' be a short
shell script invoking /sbin/reboot, rather than having the shell be /sbin/reboot
itself.

Comment 1 Dale R. Worley 2003-09-09 15:44:35 UTC
Created attachment 94331 [details]
Patch to halt.c to improve its detection of "what name it was invoked using", and thus select the correct action to take.

Comment 2 Bill Nottingham 2005-12-20 20:08:45 UTC
Added in 2.86-1.

Comment 3 David Lawrence 2007-06-22 02:10:55 UTC
Package name is now sysvinit in Fedora.


Note You need to log in before you can comment on or make changes to this bug.