xdm halt & reboot buttons

classic Classic list List threaded Threaded
23 messages Options
12
Reply | Threaded
Open this post in threaded view
|

xdm halt & reboot buttons

Craig Skinner-3
Hello,

This diff presents 'Halt' and 'Reboot' buttons on the xdm screen.

Other buttons could be added, such as 'Hibernate' & 'Suspend'.

The message box remains after login.... but can be manually closed.

Adapted from http://cafim.sssup.it/~giulio/other/Customization_XDM.html#starting-the-necessary-programs


--- Xsetup_0~ Wed Aug  6 21:03:43 2014
+++ Xsetup_0 Tue Jun 28 13:51:23 2016
@@ -1,8 +1,25 @@
 #!/bin/sh
-# $OpenBSD: Xsetup_0,v 1.3 2010/03/28 09:33:02 matthieu Exp $
+# $OpenBSD: Xsetup_0,v 1.2 2016/06/28 13:24:23 craig Exp $
 if [ "$DISPLAY" = ":0" -o "$DISPLAY" = ":0.0" ]
 then
  xconsole -geometry 480x130-0-0 -daemon -notify -verbose -fn fixed -exitOnFail
+
+ # Show Halt and Reboot buttons:
+ (
+ xmessage -buttons 'Halt:20,Reboot:21' ' System: '
+ case $? in
+ 20)
+ exec halt -p
+ ;;
+ 21)
+ exec reboot
+ ;;
+ *)
+ print "xmessage closed on $(date)"
+ ;;
+ esac
+ ) &
+
 fi
 
 #sxpm OpenBSD.xpm &

Reply | Threaded
Open this post in threaded view
|

Re: xdm halt & reboot buttons

Craig Skinner-3
Hello,

On 2016-06-28 Tue 15:27 PM |, Craig Skinner wrote:
> This diff presents 'Halt' and 'Reboot' buttons on the xdm screen.
>

Now it closes the message box + adds 'Hibernate' & 'Suspend' buttons.

>
> Adapted from http://cafim.sssup.it/~giulio/other/Customization_XDM.html
>


--- /etc/X11/xdm/Xsetup_0 2016/06/28 14:20:18 1.1
+++ /etc/X11/xdm/Xsetup_0 2016/06/28 17:14:54
@@ -1,8 +1,31 @@
 #!/bin/sh
-# $OpenBSD: Xsetup_0,v 1.1 2016/06/28 13:20:18 craig Exp $
+# $OpenBSD: Xsetup_0,v 1.6 2016/06/28 16:16:11 craig Exp $
 if [ "$DISPLAY" = ":0" -o "$DISPLAY" = ":0.0" ]
 then
  xconsole -geometry 480x130-0-0 -daemon -notify -verbose -fn fixed -exitOnFail
+
+ # Show Halt and Reboot buttons:
+ (
+ xmessage -buttons 'Halt:20,Reboot:21,Suspend:22,Hibernate:23' ' System: '
+ case $? in
+ 20)
+ halt -p >/dev/console 2>&1
+ ;;
+ 21)
+ reboot >/dev/console 2>&1
+ ;;
+ 22)
+ zzz >/dev/console 2>&1
+ ;;
+ 23)
+ ZZZ >/dev/console 2>&1
+ ;;
+ *)
+ print 'xdm halter closed' >/dev/console
+ ;;
+ esac
+ ) &
+
 fi
 
 #sxpm OpenBSD.xpm &
--- /etc/X11/xdm/GiveConsole 2015/06/30 16:44:10 1.2
+++ /etc/X11/xdm/GiveConsole 2016/06/28 17:07:28
@@ -1,6 +1,11 @@
 #!/bin/sh
 # Assign ownership of the console to the invoking user
-# $OpenBSD: GiveConsole,v 1.2 2015/06/30 15:44:10 craig Exp $
+# $OpenBSD: GiveConsole,v 1.3 2016/06/28 16:09:24 craig Exp $
+#
+
+# Started in Xsetup_0
+pkill xmessage
+
 #
 # By convention, both xconsole and xterm -C check that the
 # console is owned by the invoking user and is readable before attaching

Reply | Threaded
Open this post in threaded view
|

Re: xdm halt & reboot buttons

Craig Skinner-3
Hiya,

On 2016-06-29 Wed 14:46 PM |, Craig Skinner wrote:

> On 2016-06-28 Tue 15:27 PM |, Craig Skinner wrote:
> > This diff presents 'Halt' and 'Reboot' buttons on the xdm screen.
> >
>
> Now it closes the message box + adds 'Hibernate' & 'Suspend' buttons.
>
> >
> > Adapted from http://cafim.sssup.it/~giulio/other/Customization_XDM.html
> >
>

Send all the sub shell's output to the console, + battery & load stats:


--- /etc/X11/xdm/Xsetup_0 2016/06/28 14:20:18 1.1
+++ /etc/X11/xdm/Xsetup_0 2016/06/30 16:16:09
@@ -1,8 +1,40 @@
 #!/bin/sh
-# $OpenBSD: Xsetup_0,v 1.1 2016/06/28 13:20:18 craig Exp $
+# $OpenBSD: Xsetup_0,v 1.12 2016/06/30 15:19:52 craig Exp $
 if [ "$DISPLAY" = ":0" -o "$DISPLAY" = ":0.0" ]
 then
  xconsole -geometry 480x130-0-0 -daemon -notify -verbose -fn fixed -exitOnFail
+
+ # Convenience GUI buttons via a backgrounded sub shell:
+ (
+ while true
+ do
+ xmessage -buttons 'Halt:20,Reboot:21,Suspend:22,Hibernate:23,Battery?:24,Load?:25' ' System: '
+ case $? in
+ 20)
+ halt -p && break
+ ;;
+ 21)
+ reboot && break
+ ;;
+ 22)
+ zzz
+ ;;
+ 23)
+ ZZZ
+ ;;
+ 24)
+ apm
+ ;;
+ 25)
+ uptime
+ ;;
+ *)
+ break
+ ;;
+ esac
+ done
+ ) >/dev/console 2>&1 &
+
 fi
 
 #sxpm OpenBSD.xpm &
--- /etc/X11/xdm/GiveConsole 2015/06/30 16:44:10 1.2
+++ /etc/X11/xdm/GiveConsole 2016/06/28 17:07:28
@@ -1,6 +1,11 @@
 #!/bin/sh
 # Assign ownership of the console to the invoking user
-# $OpenBSD: GiveConsole,v 1.2 2015/06/30 15:44:10 craig Exp $
+# $OpenBSD: GiveConsole,v 1.3 2016/06/28 16:09:24 craig Exp $
+#
+
+# Started in Xsetup_0
+pkill xmessage
+
 #
 # By convention, both xconsole and xterm -C check that the
 # console is owned by the invoking user and is readable before attaching

Reply | Threaded
Open this post in threaded view
|

Re: xdm halt & reboot buttons

Alexander Hall
On Thu, Jun 30, 2016 at 04:43:12PM +0100, Craig Skinner wrote:

> Hiya,
>
> On 2016-06-29 Wed 14:46 PM |, Craig Skinner wrote:
> > On 2016-06-28 Tue 15:27 PM |, Craig Skinner wrote:
> > > This diff presents 'Halt' and 'Reboot' buttons on the xdm screen.
> > >
> >
> > Now it closes the message box + adds 'Hibernate' & 'Suspend' buttons.
> >
> > >
> > > Adapted from http://cafim.sssup.it/~giulio/other/Customization_XDM.html
> > >
> >
>
> Send all the sub shell's output to the console, + battery & load stats:

1. xmessage has an sometimes useful, but in general awful, interface.
2. Too much code in 'XSetup*'. It should be a separate program.
3. I don't approve of the diagnostic parts (uptime, really?).

Maybe just add a button or two to the xdm login panel instead?

/Alexander

>
>
> --- /etc/X11/xdm/Xsetup_0 2016/06/28 14:20:18 1.1
> +++ /etc/X11/xdm/Xsetup_0 2016/06/30 16:16:09
> @@ -1,8 +1,40 @@
>  #!/bin/sh
> -# $OpenBSD: Xsetup_0,v 1.1 2016/06/28 13:20:18 craig Exp $
> +# $OpenBSD: Xsetup_0,v 1.12 2016/06/30 15:19:52 craig Exp $
>  if [ "$DISPLAY" = ":0" -o "$DISPLAY" = ":0.0" ]
>  then
>   xconsole -geometry 480x130-0-0 -daemon -notify -verbose -fn fixed -exitOnFail
> +
> + # Convenience GUI buttons via a backgrounded sub shell:
> + (
> + while true
> + do
> + xmessage -buttons 'Halt:20,Reboot:21,Suspend:22,Hibernate:23,Battery?:24,Load?:25' ' System: '
> + case $? in
> + 20)
> + halt -p && break
> + ;;
> + 21)
> + reboot && break
> + ;;
> + 22)
> + zzz
> + ;;
> + 23)
> + ZZZ
> + ;;
> + 24)
> + apm
> + ;;
> + 25)
> + uptime
> + ;;
> + *)
> + break
> + ;;
> + esac
> + done
> + ) >/dev/console 2>&1 &
> +
>  fi
>  
>  #sxpm OpenBSD.xpm &
> --- /etc/X11/xdm/GiveConsole 2015/06/30 16:44:10 1.2
> +++ /etc/X11/xdm/GiveConsole 2016/06/28 17:07:28
> @@ -1,6 +1,11 @@
>  #!/bin/sh
>  # Assign ownership of the console to the invoking user
> -# $OpenBSD: GiveConsole,v 1.2 2015/06/30 15:44:10 craig Exp $
> +# $OpenBSD: GiveConsole,v 1.3 2016/06/28 16:09:24 craig Exp $
> +#
> +
> +# Started in Xsetup_0
> +pkill xmessage
> +
>  #
>  # By convention, both xconsole and xterm -C check that the
>  # console is owned by the invoking user and is readable before attaching
>

Reply | Threaded
Open this post in threaded view
|

Re: xdm halt & reboot buttons

Craig Skinner-3
Hi Alexander,

On 2016-06-30 Thu 20:58 PM |, Alexander Hall wrote:
>
> 1. xmessage has an sometimes useful, but in general awful, interface.

Aye,... simple, in base & functional.

The prettiness factor can be cosmetically altered with Xmessage* lines
in /etc/X11/xdm/Xresources. See '! xmessage resources' mid way down:
http://cafim.sssup.it/~giulio/other/Customization_XDM.html

>
> Maybe just add a button or two to the xdm login panel instead?
>

Good idea. I'll try to alter that instead.... Suggestions welcome!

Cheers,
--
Craig Skinner | http://linkd.in/yGqkv7

Reply | Threaded
Open this post in threaded view
|

Re: xdm halt & reboot buttons

Matthieu Herrb-7
On Fri, Jul 01, 2016 at 02:22:57PM +0100, Craig Skinner wrote:

> Hi Alexander,
>
> On 2016-06-30 Thu 20:58 PM |, Alexander Hall wrote:
> >
> > 1. xmessage has an sometimes useful, but in general awful, interface.
>
> Aye,... simple, in base & functional.
>
> The prettiness factor can be cosmetically altered with Xmessage* lines
> in /etc/X11/xdm/Xresources. See '! xmessage resources' mid way down:
> http://cafim.sssup.it/~giulio/other/Customization_XDM.html
>
> >
> > Maybe just add a button or two to the xdm login panel instead?
> >
>
> Good idea. I'll try to alter that instead.... Suggestions welcome!
I'm not sure it's a good idea. The Login widget in xdm is ugly old
code. You will loose hair or your mind trying to hack there, unless
you decide to first clean it up completely.

If you spend some time providing a set of nice resouces for xmessages
and keep it minimalistic, I think we can include your suggestion. I've
been waiting for other comments.
--
Matthieu Herrb

attachment0 (476 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: xdm halt & reboot buttons

Sebastien Marie-2
On Fri, Jul 01, 2016 at 03:38:26PM +0200, Matthieu Herrb wrote:
>
> If you spend some time providing a set of nice resouces for xmessages
> and keep it minimalistic, I think we can include your suggestion. I've
> been waiting for other comments.

Personally I would be a bit reluctant to xmessage stuff (at least "as
it"), but it could be only due to my ignorance in the deep of X11
protocol.

It is the fact that xmessage would be run as root that worry me a bit.
My first react (with first version where xmessage wasn't killed in
GiveConsole) was "how is it possible to low-level interact with this X11
app" (I didn't take the time to check it for now).

For comparing, the other program, xconsole(1), which is started by
Xsetup_0, has privsep.

Now, as xmessage(1) would be only used to provide UI to user, it should
be possible to run it as _x11 (or other unpriviligied user). The useful
information is the exit code of the program, so the rest of the script
(the "case...esac" stuff) could be run as root and only read the exit
code of an unpriviligied one.

About the "pkill" in GiveConsole, I think it should be more "restricted"
(with -U, -x ...) : else any running xmessage(1) program on the host
will be killed (remote X11 xmessage on the host while another user log
using xdm).
--
Sebastien Marie

Reply | Threaded
Open this post in threaded view
|

Re: xdm halt & reboot buttons

patrick keshishian
In reply to this post by Matthieu Herrb-7
On 7/1/16, Matthieu Herrb <[hidden email]> wrote:

> On Fri, Jul 01, 2016 at 02:22:57PM +0100, Craig Skinner wrote:
>> Hi Alexander,
>>
>> On 2016-06-30 Thu 20:58 PM |, Alexander Hall wrote:
>> >
>> > 1. xmessage has an sometimes useful, but in general awful, interface.
>>
>> Aye,... simple, in base & functional.
>>
>> The prettiness factor can be cosmetically altered with Xmessage* lines
>> in /etc/X11/xdm/Xresources. See '! xmessage resources' mid way down:
>> http://cafim.sssup.it/~giulio/other/Customization_XDM.html
>>
>> >
>> > Maybe just add a button or two to the xdm login panel instead?
>> >
>>
>> Good idea. I'll try to alter that instead.... Suggestions welcome!
>
> I'm not sure it's a good idea. The Login widget in xdm is ugly old
> code. You will loose hair or your mind trying to hack there, unless
> you decide to first clean it up completely.
>
> If you spend some time providing a set of nice resouces for xmessages
> and keep it minimalistic, I think we can include your suggestion. I've
> been waiting for other comments.


Only comment I (as a user) have, has to do with liking the
default look as-is. I like the idea of this being put in a
separate script/program (suggested by Alexander Hall); that
way, it can easily be disabled (reverted to original look)
with a one-line comment.

cheers,
--patrick

Reply | Threaded
Open this post in threaded view
|

Re: xdm halt & reboot buttons

Craig Skinner-3
In reply to this post by Craig Skinner-3
On 2016-07-01 Fri 14:22 PM |, Craig Skinner wrote:
> On 2016-06-30 Thu 20:58 PM |, Alexander Hall wrote:
> >
> > Maybe just add a button or two to the xdm login panel instead?
> >
>
> Good idea. I'll try to alter that instead.... Suggestions welcome!
>

Ugh,... that's beyond me.

From xdm(1), the AUTHENTICATION WIDGET is special purpose, with
xlogin.Login.namePrompt and xlogin.Login.passwdPrompt, but not
xlogin.Login.MyNewButton1, xlogin.Login.MyNewButton2,....

Sorry Alexander.


Anyway, here's another attempt, with less buttons.

The 1st xmessage window has no loop to break as shutdown & reboot are
single instance actions. It also uses shutdown(8) to log to
/var/log/authlog, and can be run by operator instead of root.

The 2nd xmessage window on the top right of the screen diverts battery
state info to the console below it. This needs a breakable loop to be
run more than once.


--- /etc/X11/xdm/Xsetup_0 2016/06/28 14:20:18 1.1
+++ /etc/X11/xdm/Xsetup_0 2016/07/01 20:30:24
@@ -1,8 +1,38 @@
 #!/bin/sh
-# $OpenBSD: Xsetup_0,v 1.1 2016/06/28 13:20:18 craig Exp $
+# $OpenBSD: Xsetup_0,v 1.13 2016/07/01 19:51:18 craig Exp $
 if [ "$DISPLAY" = ":0" -o "$DISPLAY" = ":0.0" ]
 then
  xconsole -geometry 480x130-0-0 -daemon -notify -verbose -fn fixed -exitOnFail
+
+ # Convenience GUI buttons via a backgrounded sub shell:
+ (
+ xmessage -buttons 'Shutdown:20,Reboot:21' ' Machine:'
+ case $? in
+ 20)
+ shutdown -hp now 'xdm login screen'
+ ;;
+ 21)
+ shutdown -r now 'xdm login screen'
+ ;;
+ esac
+ ) >/dev/console 2>&1 &
+
+ # Convenience GUI buttons via a backgrounded sub shell:
+ (
+ while true
+ do
+ xmessage -geometry -0+0 -buttons 'Status:24' ' Battery:'
+ case $? in
+ 24)
+ apm
+ ;;
+ *)
+ break
+ ;;
+ esac
+ done
+ ) >/dev/console 2>&1 &
+
 fi
 
 #sxpm OpenBSD.xpm &
--- /etc/X11/xdm/GiveConsole 2015/06/30 16:44:10 1.2
+++ /etc/X11/xdm/GiveConsole 2016/06/28 17:07:28
@@ -1,6 +1,11 @@
 #!/bin/sh
 # Assign ownership of the console to the invoking user
-# $OpenBSD: GiveConsole,v 1.2 2015/06/30 15:44:10 craig Exp $
+# $OpenBSD: GiveConsole,v 1.3 2016/06/28 16:09:24 craig Exp $
+#
+
+# Started in Xsetup_0
+pkill xmessage
+
 #
 # By convention, both xconsole and xterm -C check that the
 # console is owned by the invoking user and is readable before attaching

Reply | Threaded
Open this post in threaded view
|

Re: xdm halt & reboot buttons

Craig Skinner-3
In reply to this post by Sebastien Marie-2
On 2016-07-01 Fri 18:01 PM |, Sebastien Marie wrote:
>
> It is the fact that xmessage would be run as root that worry me a bit.

Good point Sebastien.

> Now, as xmessage(1) would be only used to provide UI to user, it should
> be possible to run it as _x11 (or other unpriviligied user). The useful
> information is the exit code of the program, so the rest of the script
> (the "case...esac" stuff) could be run as root and only read the exit
> code of an unpriviligied one.
>

OK, I'll investigate that next.

My 4th version uses shutdown(8), which can run as operator.
I guess nobody could run apm(8) too.

> About the "pkill" in GiveConsole, I think it should be more "restricted"
> (with -U, -x ...) : else any running xmessage(1) program on the host
> will be killed (remote X11 xmessage on the host while another user log
> using xdm).

Yeah, I've a space at the front of the message, so pgrep -l was getting
a bit weird. But running xmessage as _x11 changes the situation!

Cheers,
--
Craig Skinner | http://linkd.in/yGqkv7

Reply | Threaded
Open this post in threaded view
|

Re: xdm halt & reboot buttons

Craig Skinner-3
In reply to this post by patrick keshishian
Hi Patrick,

On 2016-07-01 Fri 10:38 AM |, patrick keshishian wrote:
>
> Only comment I (as a user) have, has to do with liking the
> default look as-is.

Same for me. It's not pretty, but it's in keeping with the rest of the
landscape. Some CSS type guru could refashion the whole thing.

> I like the idea of this being put in a separate script/program
> (suggested by Alexander Hall); that way, it can easily be disabled
> (reverted to original look) with a one-line comment.
>

Most of the ideas on the web are TCL or Perl windows, which means
/usr/local/, which means ports,.... and they were so complicated,
writing PID files, watcher processes to kill the scripts, ughhhhh...

The page I adapted as a starting point was so simple & in base.

I hear you about easy on/off, + Alexander with an external widget.
--
Craig Skinner | http://linkd.in/yGqkv7

Reply | Threaded
Open this post in threaded view
|

Re: xdm halt & reboot buttons

Alexander Hall
In reply to this post by Matthieu Herrb-7
On Fri, Jul 01, 2016 at 03:38:26PM +0200, Matthieu Herrb wrote:

> On Fri, Jul 01, 2016 at 02:22:57PM +0100, Craig Skinner wrote:
> > Hi Alexander,
> >
> > On 2016-06-30 Thu 20:58 PM |, Alexander Hall wrote:
> > >
> > > 1. xmessage has an sometimes useful, but in general awful, interface.
> >
> > Aye,... simple, in base & functional.
> >
> > The prettiness factor can be cosmetically altered with Xmessage* lines
> > in /etc/X11/xdm/Xresources. See '! xmessage resources' mid way down:
> > http://cafim.sssup.it/~giulio/other/Customization_XDM.html
> >
> > >
> > > Maybe just add a button or two to the xdm login panel instead?
> > >
> >
> > Good idea. I'll try to alter that instead.... Suggestions welcome!
>
> I'm not sure it's a good idea. The Login widget in xdm is ugly old
> code. You will loose hair or your mind trying to hack there, unless
> you decide to first clean it up completely.
>
> If you spend some time providing a set of nice resouces for xmessages
> and keep it minimalistic, I think we can include your suggestion. I've
> been waiting for other comments.

Just throwing in another nickel here - *if* this was in the login widget
instead, you'd be able to use the keyboard to reach these. As is it now,
you, AFAIK, aren't. :-/

/Alexander

> --
> Matthieu Herrb


Reply | Threaded
Open this post in threaded view
|

Re: xdm halt & reboot buttons

Craig Skinner-3
In reply to this post by Sebastien Marie-2
Hello all,

On 2016-07-01 Fri 18:01 PM |, Sebastien Marie wrote:

>
> It is the fact that xmessage would be run as root that worry me a bit.
> [snip]
>
> Now, as xmessage(1) would be only used to provide UI to user, it should
> be possible to run it as _x11 (or other unpriviligied user). The useful
> information is the exit code of the program, so the rest of the script
> (the "case...esac" stuff) could be run as root and only read the exit
> code of an unpriviligied one.
>
> About the "pkill" in GiveConsole, I think it should be more "restricted"
> (with -U, -x ...) : else any running xmessage(1) program on the host
> will be killed (remote X11 xmessage on the host while another user log
> using xdm).


xmessage is now run as '_x11', shutdown as 'operator', and the status
items as 'nobody'. Only user _x11's xmessage windows are pkilled.

(Maybe the operator & nobody bits are overkill.)

As Patrick requested, the bits can simply be disabled by easy comments.

Feel free to further improve:


--- /etc/X11/xdm/Xsetup_0 2016/06/28 14:20:18 1.1
+++ /etc/X11/xdm/Xsetup_0 2016/07/02 14:58:30
@@ -1,8 +1,52 @@
 #!/bin/sh
-# $OpenBSD: Xsetup_0,v 1.1 2016/06/28 13:20:18 craig Exp $
+# $OpenBSD: Xsetup_0,v 1.16 2016/07/02 14:03:14 craig Exp $
+
+# Convenience GUI button items:
+alias su_x11='su -s /bin/sh _x11 -c'
+alias su_optr='su -s /bin/sh operator -c'
+alias su_nbdy='su -s /bin/sh nobody -c'
+
+function _xdm_machine_shutdown
+{
+ su_x11 "xmessage -geometry +0+0 -buttons 'Shutdown:20,Reboot:21' ' Machine:'"
+ case $? in
+ 20)
+ su_optr "shutdown -hp now 'xdm login screen'"
+ ;;
+ 21)
+ su_optr "shutdown -r now 'xdm login screen'"
+ ;;
+ esac
+}
+
+function _xdm_machine_status
+{
+ while true
+ do
+ su_x11 "xmessage -geometry -0+0 -buttons 'Battery:30,Load:31' ' Status:'"
+ case $? in
+ 30)
+ su_nbdy 'apm'
+ ;;
+ 31)
+ su_nbdy 'uptime'
+ ;;
+ # TODO:
+ #32)
+ # su_nbdy 'some-wifi-status-thing'
+ # ;;
+ *)
+ break
+ ;;
+ esac
+ done
+}
+
 if [ "$DISPLAY" = ":0" -o "$DISPLAY" = ":0.0" ]
 then
  xconsole -geometry 480x130-0-0 -daemon -notify -verbose -fn fixed -exitOnFail
+ _xdm_machine_shutdown >/dev/console 2>&1 &
+ _xdm_machine_status >/dev/console 2>&1 &
 fi
 
 #sxpm OpenBSD.xpm &
--- /etc/X11/xdm/GiveConsole 2015/06/30 16:44:10 1.2
+++ /etc/X11/xdm/GiveConsole 2016/07/02 13:18:32
@@ -1,6 +1,11 @@
 #!/bin/sh
 # Assign ownership of the console to the invoking user
-# $OpenBSD: GiveConsole,v 1.2 2015/06/30 15:44:10 craig Exp $
+# $OpenBSD: GiveConsole,v 1.4 2016/07/02 12:24:40 craig Exp $
+#
+
+# Started in Xsetup_0
+pkill -U _x11 -x xmessage
+
 #
 # By convention, both xconsole and xterm -C check that the
 # console is owned by the invoking user and is readable before attaching

Reply | Threaded
Open this post in threaded view
|

Re: xdm halt & reboot buttons

Craig Skinner-3
In reply to this post by Matthieu Herrb-7
On 2016-07-01 Fri 15:38 PM |, Matthieu Herrb wrote:
>
> If you spend some time providing a set of nice resouces for xmessages
> and keep it minimalistic, I think we can include your suggestion. I've
> been waiting for other comments.
>

Thanks Matthieu.

I wasted a while making an arse of /etc/X11/xdm/Xresources,
and some kangaroos are now blindly bouncing into buses.

My monitor is in rehab....

Who is good at that GUI stuff?
--
"Apathy is not the problem, it's the solution"

Reply | Threaded
Open this post in threaded view
|

Re: xdm halt & reboot buttons

Bob Beck-2
In reply to this post by Craig Skinner-3
Do not use nobody.

that is a very bad practice.  may as well call nobody NFS.

On Saturday, 2 July 2016, Craig Skinner <[hidden email]> wrote:

> Hello all,
>
> On 2016-07-01 Fri 18:01 PM |, Sebastien Marie wrote:
> >
> > It is the fact that xmessage would be run as root that worry me a bit.
> > [snip]
> >
> > Now, as xmessage(1) would be only used to provide UI to user, it should
> > be possible to run it as _x11 (or other unpriviligied user). The useful
> > information is the exit code of the program, so the rest of the script
> > (the "case...esac" stuff) could be run as root and only read the exit
> > code of an unpriviligied one.
> >
> > About the "pkill" in GiveConsole, I think it should be more "restricted"
> > (with -U, -x ...) : else any running xmessage(1) program on the host
> > will be killed (remote X11 xmessage on the host while another user log
> > using xdm).
>
>
> xmessage is now run as '_x11', shutdown as 'operator', and the status
> items as 'nobody'. Only user _x11's xmessage windows are pkilled.
>
> (Maybe the operator & nobody bits are overkill.)
>
> As Patrick requested, the bits can simply be disabled by easy comments.
>
> Feel free to further improve:
>
>
> --- /etc/X11/xdm/Xsetup_0       2016/06/28 14:20:18     1.1
> +++ /etc/X11/xdm/Xsetup_0       2016/07/02 14:58:30
> @@ -1,8 +1,52 @@
>  #!/bin/sh
> -# $OpenBSD: Xsetup_0,v 1.1 2016/06/28 13:20:18 craig Exp $
> +# $OpenBSD: Xsetup_0,v 1.16 2016/07/02 14:03:14 craig Exp $
> +
> +# Convenience GUI button items:
> +alias su_x11='su -s /bin/sh _x11 -c'
> +alias su_optr='su -s /bin/sh operator -c'
> +alias su_nbdy='su -s /bin/sh nobody -c'
> +
> +function _xdm_machine_shutdown
> +{
> +       su_x11 "xmessage -geometry +0+0 -buttons 'Shutdown:20,Reboot:21' '
> Machine:'"
> +       case $? in
> +               20)
> +                       su_optr "shutdown -hp now 'xdm login screen'"
> +                       ;;
> +               21)
> +                       su_optr "shutdown -r now 'xdm login screen'"
> +                       ;;
> +       esac
> +}
> +
> +function _xdm_machine_status
> +{
> +       while true
> +       do
> +               su_x11 "xmessage -geometry -0+0 -buttons
> 'Battery:30,Load:31' ' Status:'"
> +               case $? in
> +                       30)
> +                               su_nbdy 'apm'
> +                               ;;
> +                       31)
> +                               su_nbdy 'uptime'
> +                               ;;
> +                       # TODO:
> +                       #32)
> +                       #       su_nbdy 'some-wifi-status-thing'
> +                       #       ;;
> +                       *)
> +                               break
> +                               ;;
> +               esac
> +       done
> +}
> +
>  if [ "$DISPLAY" = ":0" -o "$DISPLAY" = ":0.0" ]
>  then
>         xconsole -geometry 480x130-0-0 -daemon -notify -verbose -fn fixed
> -exitOnFail
> +       _xdm_machine_shutdown >/dev/console 2>&1 &
> +       _xdm_machine_status >/dev/console 2>&1 &
>  fi
>
>  #sxpm OpenBSD.xpm &
> --- /etc/X11/xdm/GiveConsole    2015/06/30 16:44:10     1.2
> +++ /etc/X11/xdm/GiveConsole    2016/07/02 13:18:32
> @@ -1,6 +1,11 @@
>  #!/bin/sh
>  # Assign ownership of the console to the invoking user
> -# $OpenBSD: GiveConsole,v 1.2 2015/06/30 15:44:10 craig Exp $
> +# $OpenBSD: GiveConsole,v 1.4 2016/07/02 12:24:40 craig Exp $
> +#
> +
> +# Started in Xsetup_0
> +pkill -U _x11 -x xmessage
> +
>  #
>  # By convention, both xconsole and xterm -C check that the
>  # console is owned by the invoking user and is readable before attaching
>
>
Reply | Threaded
Open this post in threaded view
|

Re: xdm halt & reboot buttons

Alexander Hall
In reply to this post by Alexander Hall
On Sat, Jul 02, 2016 at 01:02:57AM +0200, Alexander Hall wrote:

> On Fri, Jul 01, 2016 at 03:38:26PM +0200, Matthieu Herrb wrote:
> > On Fri, Jul 01, 2016 at 02:22:57PM +0100, Craig Skinner wrote:
> > > Hi Alexander,
> > >
> > > On 2016-06-30 Thu 20:58 PM |, Alexander Hall wrote:
> > > >
> > > > 1. xmessage has an sometimes useful, but in general awful, interface.
> > >
> > > Aye,... simple, in base & functional.
> > >
> > > The prettiness factor can be cosmetically altered with Xmessage* lines
> > > in /etc/X11/xdm/Xresources. See '! xmessage resources' mid way down:
> > > http://cafim.sssup.it/~giulio/other/Customization_XDM.html
> > >
> > > >
> > > > Maybe just add a button or two to the xdm login panel instead?
> > > >
> > >
> > > Good idea. I'll try to alter that instead.... Suggestions welcome!
> >
> > I'm not sure it's a good idea. The Login widget in xdm is ugly old
> > code. You will loose hair or your mind trying to hack there, unless
> > you decide to first clean it up completely.
> >
> > If you spend some time providing a set of nice resouces for xmessages
> > and keep it minimalistic, I think we can include your suggestion. I've
> > been waiting for other comments.
>
> Just throwing in another nickel here - *if* this was in the login widget
> instead, you'd be able to use the keyboard to reach these. As is it now,
> you, AFAIK, aren't. :-/

This adds 'Ctrl+[SZQ]' bindings for suspend, hibernate and powerdown,
respecively.  This gives you added functionality without modifying the
interface, for better or worse. Mostly hacked up for fun and food-for-thought.

Hibernate is probably pretty silly here (unless you have important
stuff going on in the background).

Thinking of it again, you could possibly just use the action arguments for
a more generic "execute-program" action.

Anyways, here goes.

/Alexander


Index: greeter/Login.c
===================================================================
RCS file: /cvs/xenocara/app/xdm/greeter/Login.c,v
retrieving revision 1.6
diff -u -p -r1.6 Login.c
--- greeter/Login.c 15 Mar 2015 17:20:41 -0000 1.6
+++ greeter/Login.c 3 Jul 2016 01:17:12 -0000
@@ -1289,6 +1289,75 @@ RestartSession (
 
 /*ARGSUSED*/
 static void
+Exec (Widget ctxw, char *const argv[], const char *failMsg)
+{
+    LoginWidget ctx = (LoginWidget)ctxw;
+
+    pid_t pid = fork();
+    if (pid == -1)
+    {
+        /* fork() failed. */
+    }
+    else if (pid == 0)
+    {
+ execv(argv[0], argv);
+        /* execv() failed... */
+        _exit(99);
+    }
+    else
+    {
+        int status;
+        if (waitpid(pid, &status, 0) == pid &&
+    WIFEXITED(status) &&
+    WEXITSTATUS(status) == 0) {
+    XorCursor (ctx);
+    RemoveFail (ctx);
+    ResetLogin (ctx);
+    XorCursor (ctx);
+    return;
+ }
+    }
+    ErrorMessage(ctx, failMsg, True);
+}
+
+/*ARGSUSED*/
+static void
+SuspendMachine (
+    Widget ctxw,
+    XEvent *event,
+    String *params,
+    Cardinal *num_params)
+{
+    char *argv[] = { "/usr/sbin/zzz", NULL };
+    Exec (ctxw, argv, "Suspend failed");
+}
+
+/*ARGSUSED*/
+static void
+HibernateMachine (
+    Widget ctxw,
+    XEvent *event,
+    String *params,
+    Cardinal *num_params)
+{
+    char *argv[] = { "/usr/sbin/ZZZ", NULL };
+    Exec (ctxw, argv, "Hibernation failed");
+}
+
+/*ARGSUSED*/
+static void
+PowerdownMachine (
+    Widget ctxw,
+    XEvent *event,
+    String *params,
+    Cardinal *num_params)
+{
+    char *argv[] = { "/sbin/shutdown", "-p", "now", NULL };
+    Exec (ctxw, argv, "Shutdown failed");
+}
+
+/*ARGSUSED*/
+static void
 AbortSession (
     Widget ctxw,
     XEvent *event,
@@ -2027,6 +2096,9 @@ char defaultLoginTranslations [] =
 "Ctrl<Key>X: erase-line() \n"
 "Ctrl<Key>C: restart-session() \n"
 "Ctrl<Key>\\\\: abort-session() \n"
+"Ctrl<Key>S: suspend-machine() \n"
+"Ctrl<Key>Z: hibernate-machine() \n"
+"Ctrl<Key>Q: powerdown-machine() \n"
 ":Ctrl<Key>plus: allow-all-access() \n"
 "<Key>BackSpace: delete-previous-character() \n"
 #ifdef linux
@@ -2054,6 +2126,9 @@ XtActionsRec loginActionsTable [] = {
   {"abort-session", AbortSession},
   {"abort-display", AbortDisplay},
   {"restart-session", RestartSession},
+  {"suspend-machine", SuspendMachine},
+  {"hibernate-machine", HibernateMachine},
+  {"powerdown-machine", PowerdownMachine},
   {"insert-char", InsertChar},
   {"set-session-argument", SetSessionArgument},
   {"allow-all-access", AllowAccess},

Reply | Threaded
Open this post in threaded view
|

Re: xdm halt & reboot buttons

Craig Skinner-3
In reply to this post by Bob Beck-2
On 2016-07-02 Sat 11:21 AM |, Bob Beck wrote:

> On Saturday, 2 July 2016, Craig Skinner <[hidden email]> wrote:
> >
> > xmessage is now run as '_x11', shutdown as 'operator', and the status
> > items as 'nobody'. Only user _x11's xmessage windows are pkilled.
> >
>
> Do not use nobody.
>
> that is a very bad practice.  may as well call nobody NFS.
>

Thanks Bob;- user 'nobody' nuked & replaced by 'operator'.

Anything else to get sorted?

--- /etc/X11/xdm/Xsetup_0 2016/06/28 14:20:18 1.1
+++ /etc/X11/xdm/Xsetup_0 2016/07/04 13:20:56
@@ -1,8 +1,51 @@
 #!/bin/sh
-# $OpenBSD: Xsetup_0,v 1.1 2016/06/28 13:20:18 craig Exp $
+# $OpenBSD: Xsetup_0,v 1.17 2016/07/04 12:23:59 craig Exp $
+
+# Convenience GUI button items:
+alias su_x11='su -s /bin/sh _x11 -c'
+alias su_optr='su -s /bin/sh operator -c'
+
+function _xdm_machine_shutdown
+{
+ su_x11 "xmessage -geometry +0+0 -buttons 'Shutdown:20,Reboot:21' ' Machine:'"
+ case $? in
+ 20)
+ su_optr "shutdown -hp now 'xdm login screen'"
+ ;;
+ 21)
+ su_optr "shutdown -r now 'xdm login screen'"
+ ;;
+ esac
+}
+
+function _xdm_machine_status
+{
+ while true
+ do
+ su_x11 "xmessage -geometry -0+0 -buttons 'Battery:30,Load:31' ' Status:'"
+ case $? in
+ 30)
+ su_optr 'apm'
+ ;;
+ 31)
+ su_optr 'uptime'
+ ;;
+ # TODO:
+ #32)
+ # su_optr 'some-wifi-status-thing'
+ # ;;
+ *)
+ break
+ ;;
+ esac
+ done
+}
+
 if [ "$DISPLAY" = ":0" -o "$DISPLAY" = ":0.0" ]
 then
  xconsole -geometry 480x130-0-0 -daemon -notify -verbose -fn fixed -exitOnFail
+ _xdm_machine_shutdown >/dev/console 2>&1 &
+ _xdm_machine_status >/dev/console 2>&1 &
 fi
 
 #sxpm OpenBSD.xpm &
--- /etc/X11/xdm/GiveConsole 2015/06/30 16:44:10 1.2
+++ /etc/X11/xdm/GiveConsole 2016/07/02 13:18:32
@@ -1,6 +1,11 @@
 #!/bin/sh
 # Assign ownership of the console to the invoking user
-# $OpenBSD: GiveConsole,v 1.2 2015/06/30 15:44:10 craig Exp $
+# $OpenBSD: GiveConsole,v 1.4 2016/07/02 12:24:40 craig Exp $
+#
+
+# Started in Xsetup_0
+pkill -U _x11 -x xmessage
+
 #
 # By convention, both xconsole and xterm -C check that the
 # console is owned by the invoking user and is readable before attaching

Reply | Threaded
Open this post in threaded view
|

Re: xdm halt & reboot buttons

Bob Beck-3
On Mon, Jul 4, 2016 at 6:42 AM, Craig Skinner <[hidden email]> wrote:

> On 2016-07-02 Sat 11:21 AM |, Bob Beck wrote:
>> On Saturday, 2 July 2016, Craig Skinner <[hidden email]> wrote:
>> >
>> > xmessage is now run as '_x11', shutdown as 'operator', and the status
>> > items as 'nobody'. Only user _x11's xmessage windows are pkilled.
>> >
>>
>> Do not use nobody.
>>
>> that is a very bad practice.  may as well call nobody NFS.
>>
>
> Thanks Bob;- user 'nobody' nuked & replaced by 'operator'.


That's probably not better - now a bug in xdm can read your raw
disks..  You need to rethink this


>
> Anything else to get sorted?
>
> --- /etc/X11/xdm/Xsetup_0       2016/06/28 14:20:18     1.1
> +++ /etc/X11/xdm/Xsetup_0       2016/07/04 13:20:56
> @@ -1,8 +1,51 @@
>  #!/bin/sh
> -# $OpenBSD: Xsetup_0,v 1.1 2016/06/28 13:20:18 craig Exp $
> +# $OpenBSD: Xsetup_0,v 1.17 2016/07/04 12:23:59 craig Exp $
> +
> +# Convenience GUI button items:
> +alias su_x11='su -s /bin/sh _x11 -c'
> +alias su_optr='su -s /bin/sh operator -c'
> +
> +function _xdm_machine_shutdown
> +{
> +       su_x11 "xmessage -geometry +0+0 -buttons 'Shutdown:20,Reboot:21' ' Machine:'"
> +       case $? in
> +               20)
> +                       su_optr "shutdown -hp now 'xdm login screen'"
> +                       ;;
> +               21)
> +                       su_optr "shutdown -r now 'xdm login screen'"
> +                       ;;
> +       esac
> +}
> +
> +function _xdm_machine_status
> +{
> +       while true
> +       do
> +               su_x11 "xmessage -geometry -0+0 -buttons 'Battery:30,Load:31' ' Status:'"
> +               case $? in
> +                       30)
> +                               su_optr 'apm'
> +                               ;;
> +                       31)
> +                               su_optr 'uptime'
> +                               ;;
> +                       # TODO:
> +                       #32)
> +                       #       su_optr 'some-wifi-status-thing'
> +                       #       ;;
> +                       *)
> +                               break
> +                               ;;
> +               esac
> +       done
> +}
> +
>  if [ "$DISPLAY" = ":0" -o "$DISPLAY" = ":0.0" ]
>  then
>         xconsole -geometry 480x130-0-0 -daemon -notify -verbose -fn fixed -exitOnFail
> +       _xdm_machine_shutdown >/dev/console 2>&1 &
> +       _xdm_machine_status >/dev/console 2>&1 &
>  fi
>
>  #sxpm OpenBSD.xpm &
> --- /etc/X11/xdm/GiveConsole    2015/06/30 16:44:10     1.2
> +++ /etc/X11/xdm/GiveConsole    2016/07/02 13:18:32
> @@ -1,6 +1,11 @@
>  #!/bin/sh
>  # Assign ownership of the console to the invoking user
> -# $OpenBSD: GiveConsole,v 1.2 2015/06/30 15:44:10 craig Exp $
> +# $OpenBSD: GiveConsole,v 1.4 2016/07/02 12:24:40 craig Exp $
> +#
> +
> +# Started in Xsetup_0
> +pkill -U _x11 -x xmessage
> +
>  #
>  # By convention, both xconsole and xterm -C check that the
>  # console is owned by the invoking user and is readable before attaching
>

Reply | Threaded
Open this post in threaded view
|

Re: xdm halt & reboot buttons

Theo de Raadt
> On Mon, Jul 4, 2016 at 6:42 AM, Craig Skinner <[hidden email]> wrote:
> > On 2016-07-02 Sat 11:21 AM |, Bob Beck wrote:
> >> On Saturday, 2 July 2016, Craig Skinner <[hidden email]> wrote:
> >> >
> >> > xmessage is now run as '_x11', shutdown as 'operator', and the status
> >> > items as 'nobody'. Only user _x11's xmessage windows are pkilled.
> >> >
> >>
> >> Do not use nobody.
> >>
> >> that is a very bad practice.  may as well call nobody NFS.
> >>
> >
> > Thanks Bob;- user 'nobody' nuked & replaced by 'operator'.
>
>
> That's probably not better - now a bug in xdm can read your raw
> disks..  You need to rethink this

EXACTLY.

Craig, you are taking a program which should run with less privilege;
but because you want features, you are creating a worst-case scenario
that is very dangerous.

Reply | Threaded
Open this post in threaded view
|

Re: xdm halt & reboot buttons

Bob Beck-3
In reply to this post by Alexander Hall
>
> Thinking of it again, you could possibly just use the action arguments for
> a more generic "execute-program" action.
>

Ahhh.. are you insane? The way you get a generic "execute program"
action is to LOG IN TO THE DAMN MACHINE!

Why don't you guys just make an option so someone can set up their
machine to auto-log-in to the xdm without
a password - that gives you all the functionality people have
obviously been clamouring for in 30 years of unix
so that it can be exactly like Windows 95.

12