Changeset View
Changeset View
Standalone View
Standalone View
src/suprocess.cpp
Show All 19 Lines | |||||
20 | #include <QStandardPaths> | 20 | #include <QStandardPaths> | ||
21 | #include <qplatformdefs.h> | 21 | #include <qplatformdefs.h> | ||
22 | 22 | | |||
23 | #include <kconfig.h> | 23 | #include <kconfig.h> | ||
24 | #include <kconfiggroup.h> | 24 | #include <kconfiggroup.h> | ||
25 | #include <ksharedconfig.h> | 25 | #include <ksharedconfig.h> | ||
26 | #include <kuser.h> | 26 | #include <kuser.h> | ||
27 | 27 | | |||
28 | #ifndef __PATH_SU | | |||
29 | #define __PATH_SU "false" | | |||
30 | #endif | | |||
31 | | ||||
32 | #ifndef __PATH_SUDO | | |||
33 | #define __PATH_SUDO "false" | | |||
34 | #endif | | |||
35 | | ||||
36 | #ifdef KDESU_USE_SUDO_DEFAULT | 28 | #ifdef KDESU_USE_SUDO_DEFAULT | ||
37 | # define DEFAULT_SUPER_USER_COMMAND QStringLiteral("sudo") | 29 | # define DEFAULT_SUPER_USER_COMMAND QStringLiteral("sudo") | ||
38 | #else | 30 | #else | ||
39 | # define DEFAULT_SUPER_USER_COMMAND QStringLiteral("su") | 31 | # define DEFAULT_SUPER_USER_COMMAND QStringLiteral("su") | ||
40 | #endif | 32 | #endif | ||
41 | 33 | | |||
42 | namespace KDESu | 34 | namespace KDESu | ||
43 | { | 35 | { | ||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Line(s) | 94 | { | |||
122 | } | 114 | } | ||
123 | 115 | | |||
124 | if (d->superUserCommand == QLatin1String("su")) { | 116 | if (d->superUserCommand == QLatin1String("su")) { | ||
125 | args += "-c"; | 117 | args += "-c"; | ||
126 | } | 118 | } | ||
127 | args += QByteArray(CMAKE_INSTALL_FULL_LIBEXECDIR_KF5) + "/kdesu_stub"; | 119 | args += QByteArray(CMAKE_INSTALL_FULL_LIBEXECDIR_KF5) + "/kdesu_stub"; | ||
128 | args += "-"; // krazy:exclude=doublequote_chars (QList, not QString) | 120 | args += "-"; // krazy:exclude=doublequote_chars (QList, not QString) | ||
129 | 121 | | |||
130 | QByteArray command; | 122 | const QByteArray command = QFile::encodeName(QStandardPaths::findExecutable(d->superUserCommand)); | ||
131 | if (d->superUserCommand == QLatin1String("sudo")) { | | |||
132 | command = __PATH_SUDO; | | |||
133 | } else { | | |||
134 | command = __PATH_SU; | | |||
135 | } | | |||
136 | | ||||
137 | if (QT_ACCESS(command.constData(), X_OK) != 0) { | | |||
138 | command = QFile::encodeName(QStandardPaths::findExecutable(d->superUserCommand)); | | |||
139 | if (command.isEmpty()) { | 123 | if (command.isEmpty()) { | ||
140 | return check ? SuNotFound : -1; | 124 | return check ? SuNotFound : -1; | ||
sitter: Could probably make it `const` now | |||||
141 | } | 125 | } | ||
142 | } | | |||
143 | 126 | | |||
144 | if (StubProcess::exec(command, args) < 0) { | 127 | if (StubProcess::exec(command, args) < 0) { | ||
145 | return check ? SuNotFound : -1; | 128 | return check ? SuNotFound : -1; | ||
146 | } | 129 | } | ||
147 | 130 | | |||
148 | SuErrors ret = (SuErrors)converseSU(password); | 131 | SuErrors ret = (SuErrors)converseSU(password); | ||
149 | 132 | | |||
150 | if (ret == error) { | 133 | if (ret == error) { | ||
▲ Show 20 Lines • Show All 146 Lines • Show Last 20 Lines |
Could probably make it const now