Gentoo Archives: gentoo-user

From: Matti Nykyri <matti.nykyri@×××.fi>
To: "gentoo-user@l.g.o" <gentoo-user@l.g.o>
Subject: Re: [gentoo-user] Re: How to poweroff the system from user?
Date: Sun, 22 Mar 2015 21:13:12
Message-Id: 3374B5D1-E964-4D1B-8433-678E506A053B@iki.fi
In Reply to: Re: [gentoo-user] Re: How to poweroff the system from user? by Philip Webb
1 > On Mar 22, 2015, at 17:58, Philip Webb <purslow@××××××××.net> wrote:
2 >
3 > 150322 Peter Humphrey wrote:
4 >> On Sunday 22 March 2015 13:04:44 Nikos Chantziaras wrote:
5 >>>> I can reboot the system when I am a user by Ctrl+Alt+Delete.
6 >>>> The user can reboot the system, but can't shut down ? Strange
7 >>> The thinking is that you can unplug the machine
8 >>> or press the hardware reset or power button or flip the PSU switch ...
9 >>> Preventing a ctrl+alt+del reboot does not add anything to security.
10 >>> Security doesn't apply to users with physical access to the machine.
11 >>> However, this is just a default. You can easily disable reboot
12 >>> on ctrl+alt+del by editing /etc/inittab and commenting-out this line:
13 >>> ca:12345:ctrlaltdel:/sbin/shutdown -r now
14 >
15 > Testing my single-user box with the above line in inittab ,
16 > I find that if I enter 'A-^Del' , I exit X to the raw terminal ;
17 > another 'A-^Del' then reboots the box. If I enter 'shutdown -r now' as user,
18 > I get "shutdown: you must be root to do that!". 'cd /sbin ; ls -l shutdown'
19 > shows '-rwxr-xr-x 1 root root 23192 May 17 2014 shutdown',
20 > so that behaviour arises from the shutdown script, not the permissions.
21 >
22 > The 1st effect is explained in ~/.fluxbox/keys by
23 > # exit fluxbox
24 > Control Mod1 Delete :Exit
25 >
26 > However, the 2nd effect is not explained so easily :
27 > 'A-^Del' reboots when entered at a raw terminal,
28 > but 'shutdown -r now' does not, yet the former is defined as the latter
29 > by the line above in my /etc/inittab .
30 >
31 > The cause seems to be that 'A-^Del' is intercepted by 'init' (Process 1),
32 > which is owned by root, but 'shutdown -r now' is heard by Process 910
33 > -- 'bash' running in the raw terminal, which was started by 'init' -- ,
34 > which is owned by my user.
35 >
36 > So the behaviour is explained, but following my earlier msg,
37 > which advised to follow proper Unix principles,
38 > I should comment the 'A-^Del' line in inittab :
39 > if the raw terminal can't react to 'su', it won't react to 'A-^Del' either,
40 > so there's no justification in terms of escaping from an emergency.
41
42 When you press ctrl-alt-delete kernel recieves it and sends it to the program that has grabbed the keyboard. If this program doesn't trap the sequence it goes to the parent program. Like if you are running a terminal in X it first goes to the shell then terminal and then to X-server.
43
44 Now usually X traps that and performs what ever action is configured. If you set X not to trap the key press it goes all the way down back to the kernel. When kernel receives it it generates hang-up signal and sends it to the PID 1 aka init. And then executes the command in inittab.
45
46 ca:12345:ctrlaltdel:/bin/echo "shutdown"
47
48 And then:
49 kill -HUP 1
50
51 Will print "shutdown" to your console. If you write a small program that traps ctrl-alt-del and run that in terminal, the server will not reboot :)
52
53 >>> pressing the reset button is far worse, since there's no clean shutdown,
54 >>> unmounting filesystems after flushing caches, etc.
55 >
56 > Yes : that's forced only when the keyboard ceases to respond.
57 >
58 >>> Because of that, the default of allowing ctrl+alt+del for local users
59 >>> makes more sense than disabling it.
60 >
61 > That doesn't follow : if you have multiple users,
62 > you don't want some rogue user rebooting randomly ;
63 > it makes sense only as a convenience on a single-user system.
64 > It seems to be the default behaviour of 'inittab'
65 > -- there no comment saying I set it myself, which I would have added -- ,
66 > which is not appropriate for Gentoo systems in general,
67 > some of which are undoubtedly multi-user.
68
69 On a multi-user system only the user sitting on the local terminal can press ctrl-alt-del and reboot the machine as he could also hit the server with a sledge hammer :)
70
71 --
72 -Matti