lxpolkit: cancelling the auth dialog is reported as "not authorized" instead of dismissed (pkexec exits 127 instead of 126)
What happens
Run any command that asks for a password through polkit on LXDE (for example pkexec true), then press Cancel or Escape in the lxpolkit dialog.
- pkexec exits with code 127 and prints "Not authorized".
- It should exit with code 126, meaning the user dismissed the dialog.
- Same test with the polkit-gnome or MATE agent exits 126, as expected.
So apps that treat "user cancelled" differently from "authentication failed" get it wrong under LXDE. The user presses Cancel and the app reports a failure instead.
Why
In lxpolkit/lxpolkit-listener.c:
on_dlg_responseonly handlesGTK_RESPONSE_OK. Cancel and Escape just callg_cancellable_cancel().- When the session completes,
on_completedruns withauthorized == FALSEand the cancellable already cancelled. It skips the "wrong password" dialog and callsg_simple_async_result_complete(result)without ever callingg_simple_async_result_set_error. - polkit then sees a "successful" completion with no error, so the backend classifies the result as not authorized. The backend only sets the dismissed detail when the agent returns
POLKIT_ERROR_CANCELLED(seepolkitbackendinteractiveauthority.c). - And pkexec only exits 126 when the result has the dismissed detail, 127 otherwise (see
src/programs/pkexec.c).
So the "user cancelled" information is dropped at the agent level and nothing downstream can recover it.
polkit-gnome shows what the fix looks like: in polkitgnomelistener.c (around line 159), when the dialog is dismissed it creates a POLKIT_ERROR_CANCELLED error and sets it on the result before completing. lxpolkit is missing exactly that part.
Suggested fix
In on_completed, when authorized == FALSE and the cancellable is cancelled, set a POLKIT_ERROR_CANCELLED error on the result before completing it. Roughly three lines, same as polkit-gnome.
Extra context
- Affects lxpolkit 0.5.5, 0.5.6, 0.5.7 and current master. The cancel path hasn't changed since 2014.
- Debian bug #894746 (filed 2018-04) describes the same symptom and is still open: https://bugs.debian.org/894746
- lxqt-policykit and polkit-kde-agent-1 have the same bug in their current master, so lxpolkit is not alone here, but this is the repo we tested.
- We found this while testing our app's service installer (it treats pkexec exit 126 as "user cancelled" and 127 as a real failure, which is the correct reading of pkexec's exit codes).
Happy to test a patch or send one if that helps.