Make kdesu work when PWD is /usr/bin
ClosedPublic

Authored by mwolff on Jan 15 2018, 12:35 PM.

Details

Summary

This code seems to have accumulated quite some legacy cruft. The
two defines are never set from CMake, thus they get defined to
"false". Now when the PWD contains a file called "false", like is
usually the case for /usr/bin, then kdesu would suddenly stop working.
You just get the super unhelpful "Su returned with an error" dialog
shown...

This patch removes the obsolete macros and always uses QStandardPath
to find the executable path for the superUserCommand. This makes the
code work for me when the PWD contains a file called "false".

Diff Detail

Repository
R299 KDESu
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
mwolff created this revision.Jan 15 2018, 12:35 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptJan 15 2018, 12:35 PM
Restricted Application added a subscriber: Frameworks. · View Herald Transcript
mwolff requested review of this revision.Jan 15 2018, 12:35 PM
mwolff edited the summary of this revision. (Show Details)Jan 15 2018, 12:35 PM
mwolff added a comment.EditedJan 15 2018, 1:08 PM

FTR:

[13:35] <milian> how the hell can kdesu ever work? https://phabricator.kde.org/D9888 WTF
[13:35] <milian> does anyone know if I'm missing something?
[13:35] <milian> googling for these macros doesn't show me anything obvious either
[13:53] <sitter> milian: dead code I'd say. note the `if` following your change checks if the file 'false' is exectuable (which it isn't as that'd be ./false which likely never exists) and then falls back to QSP::findExec(cmd). where cmd is macro'd to sudo or su depending on the cmake switch KDESU_USE_SUDO_DEFAULT
[13:54] <milian> but it doesn't work for me without this patch
[13:54] <milian> so it cannot be dead code :D
[13:55] <milian> i.e. how can this work for anyone right now?
[13:58] <sitter> milian: http://paste.debian.net/1005279/ is how I read the original
[13:59] <milian> I'll see why this does not happen on my system
[14:02] <sitter> milian: try this for good measure http://paste.debian.net/1005280/
[14:02] <milian> yep
[14:03] <sitter> mind you, it could be that __PATH_SU/SUDO is actually defined somewhere in a system level include which would then make the QT_ACCESS pass and break things
[14:03] <milian> I can't find it in my  /usr/include at least
[14:06] <milian> sitter: QT_ACCESS("false", X_OK) == 0 on my system
[14:07] <milian> and no, there's no false in the current PWD
[14:07] <milian> it's in /usr/bin though
[14:07] <milian> I'd also be OK with removing that whole code and simplifying it
[14:08] <milian> like you proposed
[14:08] <sitter> something is wrong with your libc :P
[14:09] <sitter> https://linux.die.net/man/2/faccessat
[14:09] <sitter> "If the pathname given in pathname is relative, then it is interpreted relative to the directory referred to by the file descriptor dirfd (rather than relative to the current working directory of the calling process, as is done by access(2) for a relative pathname)."
[14:10] <milian> ah wait, the pwd _is_ /usr/bin inmy test
[14:10] <sitter> :)
[14:10] <milian> ah yes, now I see why, too
[14:10] <milian> (hotspot defaults to the test binaries origin, which for /usr/bin/ls is... /usr/bin - doh)
[14:10] <milian> still, breaking kdesu when PWD == /usr/bin makes no sense
mwolff updated this revision to Diff 25395.Jan 15 2018, 1:14 PM
mwolff retitled this revision from Let kdesu work when __PATH_SU or __PATH_SUDO are not defined to Make kdesu work when PWD is /usr/bin.
mwolff edited the summary of this revision. (Show Details)
mwolff added a subscriber: sitter.

cleanup now that I figured out what happens, thanks @sitter

sitter accepted this revision.Jan 15 2018, 1:23 PM
sitter added inline comments.
src/suprocess.cpp
122–124

Could probably make it const now

This revision is now accepted and ready to land.Jan 15 2018, 1:23 PM
This revision was automatically updated to reflect the committed changes.