libksysguard_kauth.diff 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. diff --git a/processcore/CMakeLists.txt b/processcore/CMakeLists.txt
  2. index 9fef4ec..939d055 100644
  3. --- a/processcore/CMakeLists.txt
  4. +++ b/processcore/CMakeLists.txt
  5. @@ -41,18 +41,18 @@ install( FILES processes.h process.h DESTINATION ${INCLUDE_INSTALL_DIR}/ksysguar
  6. #------ KAuth stuff
  7. # Auth example helper
  8. -# set(ksysguardprocesslist_helper_srcs
  9. -# helper.cpp
  10. -# process.cpp
  11. -# processes_local_p.cpp
  12. -# processes_base_p.cpp)
  13. -#
  14. -# add_executable(ksysguardprocesslist_helper ${ksysguardprocesslist_helper_srcs})
  15. -# target_link_libraries(ksysguardprocesslist_helper )
  16. -# install(TARGETS ksysguardprocesslist_helper DESTINATION ${LIBEXEC_INSTALL_DIR})
  17. -#
  18. -# kauth_install_helper_files(ksysguardprocesslist_helper org.kde.ksysguard.processlisthelper root)
  19. -# kauth_install_actions(org.kde.ksysguard.processlisthelper actions.actions)
  20. -#
  21. -# set_target_properties(ksysguardprocesslist_helper PROPERTIES COMPILE_FLAGS "-Wall -ggdb")
  22. +set(ksysguardprocesslist_helper_srcs
  23. + helper.cpp
  24. + process.cpp
  25. + processes_local_p.cpp
  26. + processes_base_p.cpp)
  27. +
  28. +add_executable(ksysguardprocesslist_helper ${ksysguardprocesslist_helper_srcs})
  29. +target_link_libraries(ksysguardprocesslist_helper Qt5::Core KF5::Auth KF5::I18n)
  30. +install(TARGETS ksysguardprocesslist_helper DESTINATION ${KAUTH_HELPER_INSTALL_DIR})
  31. +
  32. +kauth_install_helper_files(ksysguardprocesslist_helper org.kde.ksysguard.processlisthelper root)
  33. +kauth_install_actions(org.kde.ksysguard.processlisthelper actions.actions)
  34. +
  35. +set_target_properties(ksysguardprocesslist_helper PROPERTIES COMPILE_FLAGS "-Wall -ggdb")
  36. diff --git a/processcore/helper.cpp b/processcore/helper.cpp
  37. index 6c1f570..c34ab1e 100644
  38. --- a/processcore/helper.cpp
  39. +++ b/processcore/helper.cpp
  40. @@ -23,24 +23,26 @@
  41. #include "helper.h"
  42. #include "processes_local_p.h"
  43. +using namespace KAuth;
  44. +
  45. KSysGuardProcessListHelper::KSysGuardProcessListHelper()
  46. {
  47. qRegisterMetaType<QList<long long> >();
  48. }
  49. /* The functions here run as ROOT. So be careful. DO NOT TRUST THE INPUTS TO BE SANE. */
  50. -#define GET_PID(i) parameters.value(QString("pid%1").arg(i), -1).toULongLong(); if(pid < 0) return KAuth::ActionReply::HelperErrorReply;
  51. -KAuth::ActionReply KSysGuardProcessListHelper::sendsignal(QVariantMap parameters) {
  52. - KAuth::ActionReply errorReply(KAuth::ActionReply::HelperError);
  53. +#define GET_PID(i) parameters.value(QString("pid%1").arg(i), -1).toULongLong(); if(pid < 0) return ActionReply(ActionReply::HelperErrorType);
  54. +ActionReply KSysGuardProcessListHelper::sendsignal(QVariantMap parameters) {
  55. + ActionReply reply(ActionReply::HelperErrorType);
  56. if(!parameters.contains("signal")) {
  57. - errorReply.setErrorDescription("Internal error - no signal parameter was passed to the helper");
  58. - errorReply.setErrorCode(1);
  59. - return errorReply;
  60. + reply.setErrorDescription("Internal error - no signal parameter was passed to the helper");
  61. + reply.setErrorCode(static_cast<ActionReply::Error>(1));
  62. + return reply;
  63. }
  64. if(!parameters.contains("pidcount")) {
  65. - errorReply.setErrorDescription("Internal error - no pidcount parameter was passed to the helper");
  66. - errorReply.setErrorCode(2);
  67. - return errorReply;
  68. + reply.setErrorDescription("Internal error - no pidcount parameter was passed to the helper");
  69. + reply.setErrorCode(static_cast<ActionReply::Error>(2));
  70. + return reply;
  71. }
  72. KSysGuard::ProcessesLocal processes;
  73. @@ -56,17 +58,17 @@ KAuth::ActionReply KSysGuardProcessListHelper::sendsignal(QVariantMap parameters
  74. success = successForThisPid && success;
  75. }
  76. if(success) {
  77. - return KAuth::ActionReply::SuccessReply;
  78. + return ActionReply::SuccessReply();
  79. } else {
  80. - errorReply.setErrorDescription(QString("Could not send signal to: ") + errorList.join(", "));
  81. - errorReply.setErrorCode(0);
  82. - return errorReply;
  83. + reply.setErrorDescription(QString("Could not send signal to: ") + errorList.join(", "));
  84. + reply.setErrorCode(static_cast<ActionReply::Error>(0));
  85. + return reply;
  86. }
  87. }
  88. -KAuth::ActionReply KSysGuardProcessListHelper::renice(QVariantMap parameters) {
  89. +ActionReply KSysGuardProcessListHelper::renice(QVariantMap parameters) {
  90. if(!parameters.contains("nicevalue") || !parameters.contains("pidcount"))
  91. - return KAuth::ActionReply::HelperErrorReply;
  92. + return ActionReply(ActionReply::HelperErrorType);
  93. KSysGuard::ProcessesLocal processes;
  94. int niceValue = qvariant_cast<int>(parameters.value("nicevalue"));
  95. @@ -77,14 +79,14 @@ KAuth::ActionReply KSysGuardProcessListHelper::renice(QVariantMap parameters) {
  96. success = processes.setNiceness(pid, niceValue) && success;
  97. }
  98. if(success)
  99. - return KAuth::ActionReply::SuccessReply;
  100. + return ActionReply::SuccessReply();
  101. else
  102. - return KAuth::ActionReply::HelperErrorReply;
  103. + return ActionReply(ActionReply::HelperErrorType);
  104. }
  105. -KAuth::ActionReply KSysGuardProcessListHelper::changeioscheduler(QVariantMap parameters) {
  106. +ActionReply KSysGuardProcessListHelper::changeioscheduler(QVariantMap parameters) {
  107. if(!parameters.contains("ioScheduler") || !parameters.contains("ioSchedulerPriority") || !parameters.contains("pidcount"))
  108. - return KAuth::ActionReply::HelperErrorReply;
  109. + return ActionReply(ActionReply::HelperErrorType);
  110. KSysGuard::ProcessesLocal processes;
  111. int ioScheduler = qvariant_cast<int>(parameters.value("ioScheduler"));
  112. @@ -96,14 +98,14 @@ KAuth::ActionReply KSysGuardProcessListHelper::changeioscheduler(QVariantMap par
  113. success = processes.setIoNiceness(pid, ioScheduler, ioSchedulerPriority) && success;
  114. }
  115. if(success)
  116. - return KAuth::ActionReply::SuccessReply;
  117. + return ActionReply::SuccessReply();
  118. else
  119. - return KAuth::ActionReply::HelperErrorReply;
  120. + return ActionReply(ActionReply::HelperErrorType);
  121. }
  122. -KAuth::ActionReply KSysGuardProcessListHelper::changecpuscheduler(QVariantMap parameters) {
  123. +ActionReply KSysGuardProcessListHelper::changecpuscheduler(QVariantMap parameters) {
  124. if(!parameters.contains("cpuScheduler") || !parameters.contains("cpuSchedulerPriority") || !parameters.contains("pidcount"))
  125. - return KAuth::ActionReply::HelperErrorReply;
  126. + return ActionReply(ActionReply::HelperErrorType);
  127. KSysGuard::ProcessesLocal processes;
  128. int cpuScheduler = qvariant_cast<int>(parameters.value("cpuScheduler"));
  129. @@ -116,9 +118,9 @@ KAuth::ActionReply KSysGuardProcessListHelper::changecpuscheduler(QVariantMap pa
  130. success = processes.setScheduler(pid, cpuScheduler, cpuSchedulerPriority) && success;
  131. }
  132. if(success)
  133. - return KAuth::ActionReply::SuccessReply;
  134. + return ActionReply::SuccessReply();
  135. else
  136. - return KAuth::ActionReply::HelperErrorReply;
  137. + return ActionReply(ActionReply::HelperErrorType);
  138. }
  139. KAUTH_HELPER_MAIN("org.kde.ksysguard.processlisthelper", KSysGuardProcessListHelper)
  140. diff --git a/processcore/processes_linux_p.cpp b/processcore/processes_linux_p.cpp
  141. index 65b8dfd..0cff0e8 100644
  142. --- a/processcore/processes_linux_p.cpp
  143. +++ b/processcore/processes_linux_p.cpp
  144. @@ -22,7 +22,7 @@
  145. #include "processes_local_p.h"
  146. #include "process.h"
  147. -#include <klocale.h>
  148. +#include <klocalizedstring.h>
  149. #include <QFile>
  150. #include <QHash>
  151. diff --git a/processui/ksysguardprocesslist.cpp b/processui/ksysguardprocesslist.cpp
  152. index 1651a0a..ba9d8c9 100644
  153. --- a/processui/ksysguardprocesslist.cpp
  154. +++ b/processui/ksysguardprocesslist.cpp
  155. @@ -48,6 +48,9 @@
  156. #include <signal.h> //For SIGTERM
  157. #include <kauth.h>
  158. +#include <kauthaction.h>
  159. +#include <kauthactionreply.h>
  160. +#include <kauthobjectdecorator.h>
  161. #include <klocale.h>
  162. #include <kmessagebox.h>
  163. #include <kdialog.h>
  164. @@ -188,7 +191,7 @@ struct KSysGuardProcessListPrivate {
  165. int totalRowCount(const QModelIndex &parent) const;
  166. /** Helper function to setup 'action' with the given pids */
  167. - void setupKAuthAction(KAuth::Action *action, const QList<long long> & pids) const;
  168. + void setupKAuthAction(KAuth::Action &action, const QList<long long> & pids) const;
  169. /** fire a timer event if we are set to use our internal timer*/
  170. void fireTimerEvent();
  171. @@ -392,15 +395,15 @@ int KSysGuardProcessListPrivate::totalRowCount(const QModelIndex &parent ) const
  172. return total;
  173. }
  174. -void KSysGuardProcessListPrivate::setupKAuthAction(KAuth::Action *action, const QList<long long> & pids) const
  175. +void KSysGuardProcessListPrivate::setupKAuthAction(KAuth::Action &action, const QList<long long> & pids) const
  176. {
  177. - action->setHelperId("org.kde.ksysguard.processlisthelper");
  178. + action.setHelperId("org.kde.ksysguard.processlisthelper");
  179. int processCount = pids.count();
  180. for(int i = 0; i < processCount; i++) {
  181. - action->addArgument(QString("pid%1").arg(i), pids[i]);
  182. + action.addArgument(QString("pid%1").arg(i), pids[i]);
  183. }
  184. - action->addArgument("pidcount", processCount);
  185. + action.addArgument("pidcount", processCount);
  186. }
  187. void KSysGuardProcessList::selectionChanged()
  188. {
  189. @@ -1023,23 +1026,19 @@ bool KSysGuardProcessList::reniceProcesses(const QList<long long> &pids, int nic
  190. #warning KAuth needs porting, but docu is not adjusted, no idea how to do it
  191. -#if 0
  192. - KAuth::Action *action = new KAuth::Action("org.kde.ksysguard.processlisthelper.renice");
  193. - action->setParentWidget(window());
  194. + KAuth::Action action("org.kde.ksysguard.processlisthelper.renice");
  195. + action.setParentWidget(window());
  196. d->setupKAuthAction( action, unreniced_pids);
  197. - action->addArgument("nicevalue", niceValue);
  198. - KAuth::ActionReply reply = action->execute();
  199. + action.addArgument("nicevalue", niceValue);
  200. + KAuth::ExecuteJob *job = action.execute();
  201. - if (reply == KAuth::ActionReply::SuccessReply) {
  202. + if (job->exec()) {
  203. updateList();
  204. - delete action;
  205. - } else if (reply != KAuth::ActionReply::UserCancelled && reply != KAuth::ActionReply::AuthorizationDenied) {
  206. + } else if (!job->exec()) {
  207. KMessageBox::sorry(this, i18n("You do not have the permission to renice the process and there "
  208. - "was a problem trying to run as root. Error %1 %2", reply.errorCode(), reply.errorDescription()));
  209. - delete action;
  210. + "was a problem trying to run as root. Error %1 %2", job->error(), job->errorString()));
  211. return false;
  212. }
  213. -#endif
  214. return true;
  215. }
  216. @@ -1189,26 +1188,22 @@ bool KSysGuardProcessList::changeIoScheduler(const QList< long long> &pids, KSys
  217. if(!d->mModel.isLocalhost()) return false; //We can't use kauth to affect non-localhost processes
  218. #warning KAuth needs porting, but docu is not adjusted, no idea how to do it
  219. -#if 0
  220. - KAuth::Action *action = new KAuth::Action("org.kde.ksysguard.processlisthelper.changeioscheduler");
  221. - action->setParentWidget(window());
  222. + KAuth::Action action("org.kde.ksysguard.processlisthelper.changeioscheduler");
  223. + action.setParentWidget(window());
  224. d->setupKAuthAction( action, unchanged_pids);
  225. - action->addArgument("ioScheduler", (int)newIoSched);
  226. - action->addArgument("ioSchedulerPriority", newIoSchedPriority);
  227. + action.addArgument("ioScheduler", (int)newIoSched);
  228. + action.addArgument("ioSchedulerPriority", newIoSchedPriority);
  229. - KAuth::ActionReply reply = action->execute();
  230. + KAuth::ExecuteJob *job = action.execute();
  231. - if (reply == KAuth::ActionReply::SuccessReply) {
  232. + if (job->exec()) {
  233. updateList();
  234. - delete action;
  235. - } else if (reply != KAuth::ActionReply::UserCancelled && reply != KAuth::ActionReply::AuthorizationDenied) {
  236. + } else if (!job->exec()) {
  237. KMessageBox::sorry(this, i18n("You do not have the permission to change the I/O priority of the process and there "
  238. - "was a problem trying to run as root. Error %1 %2", reply.errorCode(), reply.errorDescription()));
  239. - delete action;
  240. + "was a problem trying to run as root. Error %1 %2", job->error(), job->errorString()));
  241. return false;
  242. }
  243. -#endif
  244. return true;
  245. }
  246. @@ -1226,24 +1221,20 @@ bool KSysGuardProcessList::changeCpuScheduler(const QList< long long> &pids, KSy
  247. if(!d->mModel.isLocalhost()) return false; //We can't use KAuth to affect non-localhost processes
  248. #warning KAuth needs porting, but docu is not adjusted, no idea how to do it
  249. -#if 0
  250. - KAuth::Action *action = new KAuth::Action("org.kde.ksysguard.processlisthelper.changecpuscheduler");
  251. - action->setParentWidget(window());
  252. + KAuth::Action action("org.kde.ksysguard.processlisthelper.changecpuscheduler");
  253. + action.setParentWidget(window());
  254. d->setupKAuthAction( action, unchanged_pids);
  255. - action->addArgument("cpuScheduler", (int)newCpuSched);
  256. - action->addArgument("cpuSchedulerPriority", newCpuSchedPriority);
  257. - KAuth::ActionReply reply = action->execute();
  258. + action.addArgument("cpuScheduler", (int)newCpuSched);
  259. + action.addArgument("cpuSchedulerPriority", newCpuSchedPriority);
  260. + KAuth::ExecuteJob *job = action.execute();
  261. - if (reply == KAuth::ActionReply::SuccessReply) {
  262. + if (job->exec()) {
  263. updateList();
  264. - delete action;
  265. - } else if (reply != KAuth::ActionReply::UserCancelled && reply != KAuth::ActionReply::AuthorizationDenied) {
  266. + } else if (!job->exec()) {
  267. KMessageBox::sorry(this, i18n("You do not have the permission to change the CPU Scheduler for the process and there "
  268. - "was a problem trying to run as root. Error %1 %2", reply.errorCode(), reply.errorDescription()));
  269. - delete action;
  270. + "was a problem trying to run as root. Error %1 %2", job->error(), job->errorString()));
  271. return false;
  272. }
  273. -#endif
  274. return true;
  275. }
  276. @@ -1262,26 +1253,20 @@ bool KSysGuardProcessList::killProcesses(const QList< long long> &pids, int sig)
  277. if(!d->mModel.isLocalhost()) return false; //We can't elevate privileges to kill non-localhost processes
  278. #warning KAuth needs porting, but docu is not adjusted, no idea how to do it
  279. -#if 0
  280. KAuth::Action action("org.kde.ksysguard.processlisthelper.sendsignal");
  281. action.setParentWidget(window());
  282. - d->setupKAuthAction( &action, unkilled_pids);
  283. + //action.setHelperId("org.kde.ksysguard.processlisthelper");
  284. + d->setupKAuthAction( action, unkilled_pids);
  285. action.addArgument("signal", sig);
  286. - KAuth::ActionReply reply = action.execute();
  287. + KAuth::ExecuteJob *job = action.execute();
  288. - if (reply == KAuth::ActionReply::SuccessReply) {
  289. + if (job->exec()) {
  290. updateList();
  291. - } else if (reply.type() == KAuth::ActionReply::HelperError) {
  292. - if (reply.errorCode() > 0)
  293. - KMessageBox::sorry(this, i18n("You do not have the permission to kill the process and there "
  294. - "was a problem trying to run as root. %1", reply.errorDescription()));
  295. - return false;
  296. - } else if (reply != KAuth::ActionReply::UserCancelled && reply != KAuth::ActionReply::AuthorizationDenied) {
  297. + } else if (!job->exec()) {
  298. KMessageBox::sorry(this, i18n("You do not have the permission to kill the process and there "
  299. - "was a problem trying to run as root. Error %1 %2", reply.errorCode(), reply.errorDescription()));
  300. + "was a problem trying to run as root. Error %1 %2", job->error(), job->errorString()));
  301. return false;
  302. }
  303. -#endif
  304. return true;
  305. }