katetextbuffer: refactor TextBuffer::save() to better separate code paths
ClosedPublic

Authored by mgerstner on Feb 14 2019, 12:12 PM.

Details

Summary

This change breaks up the rather large TextBuffer::save() into separate
functions. Most notably the privileged code path that requires a D-Bus
helper invocation is now better separated from the unprivileged local
code path.

This change also introduces a small change in behaviour: If file open
failed for other reasons than lacking permissions the invocation of the
D-Bus helper is skipped, since there is no hope of the helper helping us
in this case.

This is preparatory work for further security related improvements
of the katetextbuffer privilege escalation handling.

Diff Detail

Repository
R39 KTextEditor
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
mgerstner created this revision.Feb 14 2019, 12:12 PM
Restricted Application added projects: Kate, Frameworks. · View Herald TranscriptFeb 14 2019, 12:12 PM
Restricted Application added subscribers: kde-frameworks-devel, kwrite-devel. · View Herald Transcript
mgerstner requested review of this revision.Feb 14 2019, 12:12 PM
cullmann requested changes to this revision.Feb 16 2019, 3:38 PM

This looks reasonable, but could we get some Qt/KDE style CamelCase enum values?

enum SaveResult {

    SAVE_FAILED = 0,
    SAVE_NO_PERMS,
    SAVE_SUCCESS
};
This revision now requires changes to proceed.Feb 16 2019, 3:38 PM

This looks reasonable, but could we get some Qt/KDE style CamelCase enum values?

enum SaveResult {

    SAVE_FAILED = 0,
    SAVE_NO_PERMS,
    SAVE_SUCCESS
};

You could even use an enum class:

enum class SaveResult {
    Failed = 0,
    MissingPermissions,
    Success
};
mgerstner updated this revision to Diff 51951.Feb 18 2019, 11:32 AM

Use a C++11 enum class with KDE style CamelCase identifiers.

cullmann accepted this revision.Feb 20 2019, 6:01 AM

Thanks, other things looks reasonable to me.

This revision is now accepted and ready to land.Feb 20 2019, 6:01 AM

If you pass me your author email, I will push that.

@cullmann wrote:

If you pass me your author email, I will push that.

Sure, it's matthias.gerstner@suse.de

Thanks, will apply this.

Nice that you help to improve this code.

This revision was automatically updated to reflect the committed changes.