Changeset View
Changeset View
Standalone View
Standalone View
src/suprocess.cpp
Show All 18 Lines | |||||
19 | #include <QDebug> | 19 | #include <QDebug> | ||
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 | #include <QDebug> | ||||
28 | #include <QLoggingCategory> | ||||
27 | 29 | | |||
28 | #ifdef KDESU_USE_SUDO_DEFAULT | 30 | #ifdef KDESU_USE_SUDO_DEFAULT | ||
29 | # define DEFAULT_SUPER_USER_COMMAND QStringLiteral("sudo") | 31 | # define DEFAULT_SUPER_USER_COMMAND QStringLiteral("sudo") | ||
30 | #else | 32 | #else | ||
31 | # define DEFAULT_SUPER_USER_COMMAND QStringLiteral("su") | 33 | # define DEFAULT_SUPER_USER_COMMAND QStringLiteral("su") | ||
32 | #endif | 34 | #endif | ||
33 | 35 | | |||
34 | namespace KDESu | 36 | namespace KDESu | ||
fvogt: If autotests aren't built, this isn't available. AFAICT it's not necessary anyway. | |||||
35 | { | 37 | { | ||
36 | using namespace KDESuPrivate; | 38 | using namespace KDESuPrivate; | ||
37 | 39 | | |||
38 | class Q_DECL_HIDDEN SuProcess::SuProcessPrivate | 40 | class Q_DECL_HIDDEN SuProcess::SuProcessPrivate | ||
39 | { | 41 | { | ||
40 | public: | 42 | public: | ||
41 | QString superUserCommand; | 43 | QString superUserCommand; | ||
42 | }; | 44 | }; | ||
fvogt: Not used anymore. | |||||
43 | 45 | | |||
46 | static QLoggingCategory category("org.kde.kdesu"); | ||||
47 | | ||||
44 | SuProcess::SuProcess(const QByteArray &user, const QByteArray &command) | 48 | SuProcess::SuProcess(const QByteArray &user, const QByteArray &command) | ||
45 | : d(new SuProcessPrivate) | 49 | : d(new SuProcessPrivate) | ||
46 | { | 50 | { | ||
47 | m_user = user; | 51 | m_user = user; | ||
48 | m_command = command; | 52 | m_command = command; | ||
49 | 53 | | |||
50 | KSharedConfig::Ptr config = KSharedConfig::openConfig(); | 54 | KSharedConfig::Ptr config = KSharedConfig::openConfig(); | ||
51 | KConfigGroup group(config, "super-user-command"); | 55 | KConfigGroup group(config, "super-user-command"); | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 98 | { | |||
112 | } else { | 116 | } else { | ||
113 | args += m_user; | 117 | args += m_user; | ||
114 | } | 118 | } | ||
115 | 119 | | |||
116 | if (d->superUserCommand == QLatin1String("su")) { | 120 | if (d->superUserCommand == QLatin1String("su")) { | ||
117 | args += "-c"; | 121 | args += "-c"; | ||
118 | } | 122 | } | ||
119 | args += QByteArray(CMAKE_INSTALL_FULL_LIBEXECDIR_KF5) + "/kdesu_stub"; | 123 | args += QByteArray(CMAKE_INSTALL_FULL_LIBEXECDIR_KF5) + "/kdesu_stub"; | ||
120 | args += "-"; // krazy:exclude=doublequote_chars (QList, not QString) | 124 | args += "-"; // krazy:exclude=doublequote_chars (QList, not QString) | ||
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/). fvogt: This means the path to the build directory is hardcoded in the executable. That needs to be… | |||||
121 | 125 | | |||
122 | const QByteArray command = QFile::encodeName(QStandardPaths::findExecutable(d->superUserCommand)); | 126 | const QByteArray command = QFile::encodeName(QStandardPaths::findExecutable(d->superUserCommand)); | ||
fvogt: Use QStringLiteral instead. | |||||
123 | if (command.isEmpty()) { | 127 | if (command.isEmpty()) { | ||
124 | return check ? SuNotFound : -1; | 128 | return check ? SuNotFound : -1; | ||
125 | } | 129 | } | ||
126 | 130 | | |||
127 | if (StubProcess::exec(command, args) < 0) { | 131 | if (StubProcess::exec(command, args) < 0) { | ||
128 | return check ? SuNotFound : -1; | 132 | return check ? SuNotFound : -1; | ||
129 | } | 133 | } | ||
130 | 134 | | |||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | |||||
198 | { | 202 | { | ||
199 | enum { WaitForPrompt, CheckStar, HandleStub } state = WaitForPrompt; | 203 | enum { WaitForPrompt, CheckStar, HandleStub } state = WaitForPrompt; | ||
200 | int colon; | 204 | int colon; | ||
201 | unsigned i, j; | 205 | unsigned i, j; | ||
202 | 206 | | |||
203 | QByteArray line; | 207 | QByteArray line; | ||
204 | while (true) { | 208 | while (true) { | ||
205 | line = readLine(); | 209 | line = readLine(); | ||
206 | if (line.isNull()) { | 210 | // return if problem. sudo checks for a second prompt || su gets a blank line | ||
211 | if ((line.contains(':') && state != WaitForPrompt) || line.isNull()) { | ||||
207 | return (state == HandleStub ? notauthorized : error); | 212 | return (state == HandleStub ? notauthorized : error); | ||
208 | } | 213 | } | ||
209 | 214 | | |||
210 | if (line == "kdesu_stub") { | 215 | if (line == "kdesu_stub") { | ||
211 | unreadLine(line); | 216 | unreadLine(line); | ||
212 | return ok; | 217 | return ok; | ||
213 | } | 218 | } | ||
214 | 219 | | |||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |
If autotests aren't built, this isn't available. AFAICT it's not necessary anyway.