Bug 772344

Summary: can't shutdown as root from kdm with DISPLAYMANAGER_SHUTDOWN="root"
Product: [openSUSE] openSUSE 13.1 Reporter: Robert Klein <kleinrob>
Component: KDE4 WorkspaceAssignee: E-mail List <kde-maintainers>
Status: RESOLVED FIXED QA Contact: E-mail List <qa-bugs>
Severity: Normal    
Priority: P5 - None CC: bugz57, ctrippe, DOlsson, forgotten_sEuUlliMqY, maintenance, mgriessmeier, o.knobloch, wbauer
Version: Final   
Target Milestone: ---   
Hardware: x86-64   
OS: openSUSE 12.2   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Robert Klein 2012-07-20 07:25:38 UTC
User-Agent:       Opera/9.80 (X11; Linux x86_64; U; en) Presto/2.10.289 Version/12.00

When I set DISPLAYMANAGER_SHUTDOWN="root" I can't shutdown from kdm anymore.  The popup-window asks for a root password, but doesn't seem to react to any keyboard input.  When I click the "Ok" button I get "Authentication failed"

Reproducible: Always

Steps to Reproduce:
1. Install openSUSE 12.2 RC1 w/o changing options (i disabled the firewall, though)
2. Set DISPLAYMANAGER_SHUTDOWN="root" in /etc/sysconfig/displaymanager
3. run SuSEconfig  (I'm not sure this is required)
4. reboot
5. try to shutdown the system from the displaymanagers login screen
Actual Results:  
Error message "Authentication failed"

Expected Results:  
System shuts down

I first noticed this with a NIS based install. For this report I tried installations with plain /etc/password authentication.

Also, I noticed this before, maybe even 12.1, but at least on 12.2 milestones
Comment 1 Christian Trippe 2014-04-06 18:03:26 UTC
*** Bug 860506 has been marked as a duplicate of this bug. ***
Comment 2 Christian Trippe 2014-04-06 18:04:29 UTC
Still valid with 13.1 accoding to bug 850813
Comment 3 Wolfgang Bauer 2014-05-06 21:43:46 UTC
*** Bug 860506 has been marked as a duplicate of this bug. ***
Comment 4 Wolfgang Bauer 2014-05-06 21:45:12 UTC
I can confirm this here on 13.1 (KDE:Current).

And those upstream bug reports seem related:
https://bugs.kde.org/show_bug.cgi?id=280422
https://bugs.kde.org/show_bug.cgi?id=293617
https://bugs.kde.org/show_bug.cgi?id=313021

So not an openSUSE specific problem I would say.
Comment 5 Wolfgang Bauer 2014-12-16 09:53:14 UTC
I found out something:
Setting the option "GrabInput=Always" in /usr/share/kde4/config/kdm/kdmrc (in the "[X-*-Greeter]" section) fixes the input focus issue in KDM completely, not only for the root password dialog, but also for the remote login dialog.

We could make this the default, but the comment says:
# Whether to grab keyboard and mouse while the greeter is visible. Grabs
# may improve security, but make on-screen keyboards, etc. unusable.


Anyway, I think I managed to fix the focus problem for the non-GrabInput case as well.
Please stay tuned for packages to test... ;)
Comment 6 Wolfgang Bauer 2014-12-16 16:19:05 UTC
Packages with my fix are available here:
http://download.opensuse.org/repositories/home:/wolfi323:/branches:/OBS_Maintained:/kdebase4-workspace/

Or, if you use KDE:Current:
http://download.opensuse.org/repositories/home:/wolfi323:/branches:/KDE:/Current/

Please test them (without setting "GrabInput=Always") and tell me whether they work or whether there are any problems.
Thank you!

You only need to install the updated kdm package...
Comment 7 Volker Kuhlmann 2014-12-17 09:17:11 UTC
Thanks Wolfgang!

Referring to https://bugs.kde.org/show_bug.cgi?id=338018

A) - Fixed.

B) - Fixed.

C) - Fixed.

D) - Depends. If the mouse pointer is within the remote login popup window, alt-xx are accepted and work fine. If the mouse pointer is elsewhere on the screen all keyboard input is ignored. Even if it was intended I think it is undesirable. There are no other windows, there is no window manager, and the pointer having to be within the "popup" area unexpected and confusing.

Switching back and forth between local and remote logins works fine.

I used http://download.opensuse.org/repositories/home:/wolfi323:/branches:/OBS_Maintained:/kdebase4-workspace/openSUSE_12.3_Update/x86_64/kdm-4.10.5-1.125.1.x86_64.rpm

I won't be able to test on 13.1, but I can test on 13.2 once I have upgraded sometime during the holidays.
Comment 8 Wolfgang Bauer 2014-12-17 10:07:08 UTC
Thanks for testing!

(In reply to Volker Kuhlmann from comment #7)
> D) - Depends. If the mouse pointer is within the remote login popup window,
> alt-xx are accepted and work fine. If the mouse pointer is elsewhere on the
> screen all keyboard input is ignored. Even if it was intended I think it is
> undesirable. There are no other windows, there is no window manager, and the
> pointer having to be within the "popup" area unexpected and confusing.

Yes, focus follows the mouse.
But that's normal behavior when no window manager is running. Just kill kwin in a KDE session and you'll see the same.

I don't think there's a way around that other than grabbing the input completely (for that you have the GrabInput=Always option, see comment 5).

But before, the "windows" could not get focus at all (although they seemed to have focus), now they should correctly get focus when you move the mouse over them, and the focus state is shown correctly as well. So at least you should see that the widget has no focus and it should accept the input if it looks like it has the focus.

> I won't be able to test on 13.1, but I can test on 13.2 once I have upgraded
> sometime during the holidays.

I don't think that's necessary. kdm hasn't changed at all in years (this problem is caused by a change in 4.4 from 2009 btw, where they decided to make input grabbing optional: https://projects.kde.org/projects/kde/kde-workspace/repository/revisions/d03df6169ecb291318e87099a346488c961fe1d6). 
Unless I made a mistake in packaging the patch should work the same there as well.

For the record, I did some testing myself with onscreen keyboards, xvkbd and kvkbd in particular. My patch didn't change anything regarding their behavior, here are my exact findings:
- Without GrabInput, none of them work, the currently focussed widget looses focus as soon as you move the mouse to the OSK. But xvkbd has a "Focus" button, with which you can force to focus to a particular widget, this works perfectly then (with and without my patch). kvkbd doesn't offer anything like this though, AFAICS.
- With GrabInput, xvkbd doesn't work at all, just as the option's comment indicates. You cannot click on any of its buttons. Strange enough, kvkbd works perfectly in this case.

As I wrote in comment 5, we could also (maybe in addition to this patch) make GrabInput=Always the default, but I'm not completely sure about this.
Any opinions?
Comment 9 Wolfgang Bauer 2014-12-17 14:52:05 UTC
(In reply to Wolfgang Bauer from comment #8)
> Yes, focus follows the mouse.
> But that's normal behavior when no window manager is running. Just kill kwin
> in a KDE session and you'll see the same.
> 
> I don't think there's a way around that other than grabbing the input
> completely (for that you have the GrabInput=Always option, see comment 5).

By looking at xvkbd's source code (in particular what it does when you press the "Focus" button), I actually did find a way to prevent the dialogs from loosing focus when you move the mouse... ;)

New packages are up at the same locations, please re-test!

There shouldn't be any noticeable difference between GrabInput on or off now any more.

I also tried xvkbd and kvkbd again, _both_ work fine now without GrabInput. And you don't even need to use xvkbd's "Focus" button any more...
Comment 10 Volker Kuhlmann 2014-12-17 20:13:27 UTC
Thanks Wolfgang, you're brilliant. Thanks also for making the testing easy (providing packages and saying which minimum needs to be installed, that really helped).

Re D): In kdm it would be "focus strictly under mouse", not "focus follows mouse", either can be set for the desktop. The difference is that the window does not lose focus with the latter when the mouse is moved onto the desktop and no window is under the pointer. That really ought to be the behaviour for kdm too?

For me the change with GrabInput caused years of aggrevation with non-functional KDE software. As you say, "yes" was the behaviour until 2009. Setting that to "no" annoyed all normal keyboard users while allowing a minority to use on-screen keyboards. I say it's a minority because I had never heard of such things being available for kdm. I am certain my use cases will always be "yes", so would personally favour that default.

It all comes down to communication. How do you tell users to change option never-heard-of in file never-needed-to-touch-that? (Not this bugzilla...)
Comment 11 Dennis Olsson 2014-12-18 09:05:34 UTC
Have verified on openSUSE 12.3 and openSUSE 13.1 using http://download.opensuse.org/repositories/home:/wolfi323:/branches:/KDE:/Current/
that your fix works very nicely.

Using the first solution (kdm-4.11.14-7.1.x86_64.rpm) the password (or remote host) window loses focus, when the mouse pointer is moved outside the window frame.
Using the second solution (kdm-4.11.14-10.1.x86_64.rpm) the window keeps focus, no matter where the mouse pointer happens to be, just like you have explained.

Any idea as to when this very nicely working fix will be official available for KDE Current on openSUSE 12.3, 13.1 and 13.2?  And for KDE itself?
Comment 12 Wolfgang Bauer 2014-12-18 22:37:23 UTC
Thanks for the feedback!

(In reply to Volker Kuhlmann from comment #10)
> Re D): In kdm it would be "focus strictly under mouse", not "focus follows
> mouse", either can be set for the desktop. The difference is that the window
> does not lose focus with the latter when the mouse is moved onto the desktop
> and no window is under the pointer. That really ought to be the behaviour
> for kdm too?
No. That is a kwin feature to offer different focus options.
But on the login screen no window manager is running at all.

And there are no "windows" really anyway, just modal dialogs.

> For me the change with GrabInput caused years of aggrevation with
> non-functional KDE software. As you say, "yes" was the behaviour until 2009.
> Setting that to "no" annoyed all normal keyboard users while allowing a
> minority to use on-screen keyboards. I say it's a minority because I had
> never heard of such things being available for kdm. I am certain my use
> cases will always be "yes", so would personally favour that default.

It was not the default that has been changed. In the past KDM unconditionally grabbed the input completely. In 2009 this has been made optional, with the default set to "IfNoAuth", which means: "grab if the display requires no X authorization"

Regarding on-screen keyboards, I did know that they exist, but I didn't know how to use them with kdm. I had to google that.
It's not exactly straight-forward, i.e. you cannot just enable them in the settings, you have to run them in /etc/X11/xdm/Xsetup. This is explained in kvkbd's manual though.

> It all comes down to communication. How do you tell users to change option
> never-heard-of in file never-needed-to-touch-that? (Not this bugzilla...)

Well, this should not be needed any more with my patch.
I just mentioned that option here as an immediate workaround for users that are affected, and it might have been a possible "fix" to change the default.

I only discovered this option myself because I looked at the source code, although it is of course present in the shipped kdmrc (including the documentation I cited earlier).
But regarding to the discoveribility of that option, better complain to KDE... ;)

(In reply to Dennis Olsson from comment #11)
> Any idea as to when this very nicely working fix will be official available
> for KDE Current on openSUSE 12.3, 13.1 and 13.2?  And for KDE itself?

I created submit requests for KDE:Current and KDE:Distro:Factory, the fix will be in those repos as soon as those are accepted by the maintainers, and in Tumbleweed a few days later.
An openSUSE maintenance update normally takes about a week until it is released, if nothing goes wrong.

I'll try to push the patch upstream to KDE, but I cannot give a time frame for that. As the latest release has been yesterday, this will take at least a month though of course.
Comment 13 Wolfgang Bauer 2014-12-18 22:43:29 UTC
@Maintenance team: Is it ok to do an online update?
Comment 14 Matthias Griessmeier 2014-12-19 06:25:41 UTC
feel free to submit an update
Comment 15 Volker Kuhlmann 2014-12-19 10:52:15 UTC
(In reply to Wolfgang Bauer from comment #12)

> No. That is a kwin feature to offer different focus options.
> But on the login screen no window manager is running at all.

Yes I realise both of those facts, I used the kwin behaviour to describe what was happening. With your second test package the dialog doesn't lose mouse focus any more even if the mouse is moved, so thumbs up for that. I only tested with GrabInput= commented out.

Remote logins are working fine again so big thanks Wolfgang.
Comment 16 Wolfgang Bauer 2014-12-19 13:10:11 UTC
(In reply to Matthias Grießmeier from comment #14)
> feel free to submit an update

Done: https://build.opensuse.org/request/show/265919


(In reply to Volker Kuhlmann from comment #15)
> Yes I realise both of those facts, I used the kwin behaviour to describe
> what was happening. With your second test package the dialog doesn't lose
> mouse focus any more even if the mouse is moved, so thumbs up for that.

Yes, but as I said that's Xorg's standard behavior when there's no window manager running, nothing to do with kdm. Try to kill kwin in a KDE session and you'll see exactly the same.

But I do think that this "focus follows mouse" policy doesn't make sense on the login screen. There are not different windows between you might want to switch, only the modal dialogs. That's why I tried to "fix" this as well. ;)

Btw, kdm did activate the dialogs (by calling QWidget::activateWindow()), but for some reason this didn't give input focus. This might be seen as a bug in Qt I suppose. Not even calling QWidget::setFocus() helped though.
I'm now calling Xlib's XSetInputFocus() instead which works nicely, and keeps the focus even when the mouse is moved out of the dialog.

> I only tested with GrabInput= commented out.

Good, because with "GrabInput=Always", my patch is not even used (and it's not needed anyway)...
 
> Remote logins are working fine again so big thanks Wolfgang.

Hm? My patch doesn't change anything regarding remote logins.

It was of course not possible to use keyboard shortcuts and enter a hostname on the remote login screen, and you couldn't even login locally any more afterwards because you couldn't enter the password.
Is that what you mean? This should be fixed now of course, yes.
Comment 17 Matthias Griessmeier 2015-01-14 08:31:31 UTC
Update released for openSUSE 12.3, 13.1 and 13.2 - resolved fixed
Comment 18 Swamp Workflow Management 2015-01-14 09:04:56 UTC
openSUSE-RU-2015:0035-1: An update that has one recommended fix can now be installed.

Category: recommended (low)
Bug References: 772344
CVE References: 
Sources used:
openSUSE 13.2 (src):    kdebase4-workspace-4.11.14-9.1
openSUSE 13.1 (src):    kdebase4-workspace-4.11.12-123.1
openSUSE 12.3 (src):    kdebase4-workspace-4.10.5-1.123.1
Comment 19 Wolfgang Bauer 2015-08-26 18:46:18 UTC
*** Bug 848606 has been marked as a duplicate of this bug. ***
Comment 20 Wolfgang Bauer 2015-11-06 18:30:32 UTC
*** Bug 744661 has been marked as a duplicate of this bug. ***