handle wrong password when using sudo which asks for another password
ClosedPublic

Authored by jriddell on Feb 21 2018, 2:45 PM.

Details

Summary

handle wrong password when using sudo which asks for another password
BUG: 389049

Test Plan

build and run with sudo and su options, test password and no, test diff languages

Diff Detail

Repository
R299 KDESu
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
There are a very large number of changes, so older changes are hidden. Show Older Changes
jriddell requested review of this revision.Feb 21 2018, 2:45 PM

As mentioned on IRC I think this would benefit greatly from some unit testing as that line check is dangerously close to requiring mental gymnastics to read. AT a glance, all that's needed is writing stub sudo/su helpers and a test asserting outcome of SuProcess('us0r', 'PATH/fakesudo').converseSU('passwd') in the given scenarios (password good su&sudo, password bad su&sudo).

jriddell updated this revision to Diff 27858.Feb 23 2018, 4:23 PM
  • add test
  • allow passwords to be separate
  • remove debugging
jriddell updated this revision to Diff 27859.Feb 23 2018, 4:25 PM
  • remove debugging

Add test. This uses the real sudo and su on your system, I fear that creating a stub replacement wouldn't be necessarily a reliable recreation. It does mean adding your own password.h with #defines for your user and root password

I fear that creating a stub replacement wouldn't be necessarily a reliable recreation.

I am not sure what you mean. If you create a stub from what you observe right now then that is a reliable recreation of how sudo 1.89 / su 4.2 behave, is it not?

ping ping ping

Restricted Application edited subscribers, added: kde-frameworks-devel; removed: Frameworks. · View Herald TranscriptJun 19 2018, 9:47 AM
sitter requested changes to this revision.Jun 19 2018, 9:59 AM
This revision now requires changes to proceed.Jun 19 2018, 9:59 AM
jriddell updated this revision to Diff 49091.Jan 9 2019, 6:09 PM
  • add a stub sudo for testing
fvogt requested changes to this revision.Jan 10 2019, 12:12 PM
fvogt added a subscriber: fvogt.
fvogt added inline comments.
autotests/su
28 ↗(On Diff #49091)

That won't work anywhere else and requires that the binary is installed when running tests.

autotests/sudo
28 ↗(On Diff #49091)

Same here.

This revision now requires changes to proceed.Jan 10 2019, 12:12 PM
jriddell updated this revision to Diff 49163.Jan 10 2019, 3:37 PM
  • use locally built kdesu_stub
jriddell updated this revision to Diff 49164.Jan 10 2019, 3:54 PM
  • in stub su and sudo use passed argument to find kdesu_stub and in suprocess pass local kdesu_stub for test mode
fvogt requested changes to this revision.Jan 10 2019, 3:57 PM
fvogt added inline comments.
src/suprocess.cpp
120 ↗(On Diff #27691)

This means the path to the build directory is hardcoded in the executable. That needs to be avoided to make builds fully reproducible (https://reproducible-builds.org/).

This revision now requires changes to proceed.Jan 10 2019, 3:57 PM
jriddell updated this revision to Diff 49173.Jan 10 2019, 4:42 PM
  • write out path to kdesu_stub and su command from the tests to a config rather than setting it within the suprocess class, allows for other testing possibilities and binary relateability
jriddell updated this revision to Diff 49175.Jan 10 2019, 4:50 PM
  • set XDG_CONFIG_HOME to put kdesutestrc not in running users config dir
fvogt requested changes to this revision.Jan 10 2019, 6:07 PM
  • set XDG_CONFIG_HOME to put kdesutestrc not in running users config dir

What you want is QStandardPaths::setTestModeEnabled(true);.

Some more general comments:

  • Autotests need to be conditional based on BUILD_TESTING
  • Is it necessary to write the mock su/sudo in python? That introduces a big and mostly unnecessary dependency on python.
  • By adding a new constructor to SuCommand which allows to specify the full path to su/sudo, testing would be much easier. It might be usable outside of the tests as well.
  • The testcases would be simpler if it used QTESTDATA and rows for the su/sudo and correct/incorrect password cases
autotests/kdesutest.cpp
3 ↗(On Diff #49175)

Try to make #include "suprocess.h" work instead.

13 ↗(On Diff #49175)

Should be above the defines.

45 ↗(On Diff #49175)

The config modification should be split into a separate method.

src/suprocess.cpp
34 ↗(On Diff #27691)

If autotests aren't built, this isn't available. AFAICT it's not necessary anyway.

42 ↗(On Diff #27691)

Not used anymore.

This revision now requires changes to proceed.Jan 10 2019, 6:07 PM
shubham edited the summary of this revision. (Show Details)Jan 10 2019, 6:45 PM
jriddell marked an inline comment as done.Jan 11 2019, 2:44 PM

Is it necessary to write the mock su/sudo in python? That introduces a big and mostly unnecessary dependency on python.

Nope but that's what was easiest for me and I'm out of energy for this

By adding a new constructor to SuCommand which allows to specify the full path to su/sudo, testing would be much easier. It might be usable outside of the tests as well.

I looked at that but I'd be scared of introducing binary incompatiblity. This approach covers the current needs.

The testcases would be simpler if it used QTESTDATA and rows for the su/sudo and correct/incorrect password cases

Something else I need to learn about.

jriddell updated this revision to Diff 49244.Jan 11 2019, 2:44 PM
  • remove unused variable
  • remove unused include
  • use QStandardPaths::setTestModeEnabled
  • tidy up includes and defines
  • refactor out config setting to remove duplication
jriddell marked 3 inline comments as done.Jan 11 2019, 2:44 PM
jriddell added inline comments.
autotests/su
28 ↗(On Diff #49091)

Not sure what you mean by won't work anywhere else, it'll work using the kdesu_stub which is built by the local compile. It doens't need kdesu_stub to be installed.

fvogt added a comment.Jan 11 2019, 7:15 PM

Is it necessary to write the mock su/sudo in python? That introduces a big and mostly unnecessary dependency on python.

Nope but that's what was easiest for me and I'm out of energy for this

The testcases would be simpler if it used QTESTDATA and rows for the su/sudo and correct/incorrect password cases

Something else I need to learn about.

Ok, those aren't major issues anyway.

By adding a new constructor to SuCommand which allows to specify the full path to su/sudo, testing would be much easier. It might be usable outside of the tests as well.

I looked at that but I'd be scared of introducing binary incompatiblity. This approach covers the current needs.

I don't really like that there's now a config entry only used for and during testing, maybe an environment variable would work?

Other than that, this is still missing:

  • Autotests need to be conditional based on BUILD_TESTING

It would be nice to have a check for python3 as well, but IMO the message on failure should be obvious enough.

autotests/su
28 ↗(On Diff #49091)

Now it doesn't - the comment was referring to the hardcoded path to kdesu_stub, which is now gone.

To avoid such misleading comments in the future, you can mark a comment as done to prevent it from reappearing out of context.

src/suprocess.cpp
122 ↗(On Diff #27691)

Use QStringLiteral instead.

src/suprocess.h
75 ↗(On Diff #49244)

Still necessary?

jriddell marked an inline comment as done.Jan 14 2019, 1:30 PM
jriddell added inline comments.
src/suprocess.h
75 ↗(On Diff #49244)

yes
autotests/kdesutest.cpp:40:45: error: ‘KDESu::SuProcess::SuErrors ok’ is private within this context

jriddell updated this revision to Diff 49440.Jan 14 2019, 1:30 PM
  • only build tests if BUILD_TESTING is set
  • use QStringLiteral
fvogt added inline comments.Jan 14 2019, 1:34 PM
src/suprocess.h
75 ↗(On Diff #49244)

Just use 0 instead - the enum isn't meant for that apparently.

jriddell updated this revision to Diff 49442.Jan 14 2019, 2:00 PM
jriddell marked 2 inline comments as done.
  • Just use 0 instead - the enum isnt meant for that apparently.
jriddell marked an inline comment as done.Jan 14 2019, 2:00 PM
jriddell updated this revision to Diff 49454.Jan 14 2019, 4:05 PM
  • revert enum, make strings const, add licence header
sitter accepted this revision.Jan 14 2019, 4:10 PM

lgtm

jriddell updated this revision to Diff 49456.Jan 14 2019, 4:15 PM
  • make string const, follow normal code style of pointer * being with variable name not the type
jriddell updated this revision to Diff 49457.Jan 14 2019, 4:23 PM
  • style fixes whitespace
jriddell updated this revision to Diff 49459.Jan 14 2019, 4:27 PM
  • make test lgpl, link configcore instead of service
fvogt requested changes to this revision.Jan 14 2019, 4:28 PM
This revision now requires changes to proceed.Jan 14 2019, 4:28 PM
jriddell marked 3 inline comments as done.Jan 14 2019, 4:34 PM
jriddell marked an inline comment as done.
fvogt added inline comments.Jan 14 2019, 5:52 PM
src/suprocess.h
75 ↗(On Diff #49244)

This is still there, so not done yet. The enum SuErrors is (apparently) not meant to be used by callers of exec as they have different accessibility.

jriddell updated this revision to Diff 49986.Jan 21 2019, 1:00 PM

Don't use friend class

fvogt accepted this revision.Jan 21 2019, 1:05 PM
This revision is now accepted and ready to land.Jan 21 2019, 1:05 PM
This revision was automatically updated to reflect the committed changes.