From 731f5bfec530972ef2cb6aa5c163ad56449e4b5e Mon Sep 17 00:00:00 2001 From: Volker Lanz Date: Sat, 4 Feb 2012 10:42:38 +0000 Subject: [PATCH] backport r1278089 and r1278090: Workaround broken kdesu backward compatibility. svn path=/branches/partitionmanager/1.0/partitionmanager/; revision=1278091 --- src/util/helpers.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/util/helpers.cpp b/src/util/helpers.cpp index 3a85da2..61c8ebf 100644 --- a/src/util/helpers.cpp +++ b/src/util/helpers.cpp @@ -72,23 +72,30 @@ bool checkPermissions() { if (geteuid() != 0) { - // only try to gain root privileges if we have a valid (kde|gk)su(do) command and - // we did not try so before: the dontsu-option is there to make sure there are no + KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); + // only try to gain root privileges if we have a valid (kde|gk)su(do) command and + // we did not try so before: the dontsu-option is there to make sure there are no // endless loops of calling the same non-working (kde|gk)su(do) binary again and again. - if (!suCommand().isEmpty() && !KCmdLineArgs::parsedArgs()->isSet("dontsu")) + if (!suCommand().isEmpty() && !args->isSet("dontsu")) { - QStringList args = qApp->arguments(); + QStringList argList; - // first argument is our own command again (i.e., argv[0]) - if (!args.isEmpty()) - args.removeFirst(); - - // arguments to partition manager must be _one_ argument to (kde|gk)su(do) - const QString suArgs = qApp->applicationFilePath() + args.join(" ") + " --dontsu"; - if (QProcess::execute(suCommand(), QStringList() << suArgs) == 0) + const QString suCmd = suCommand(); + + // kdesu broke backward compatibility at some point and now only works with "-c"; + // kdesudo accepts either (with or without "-c"), but the gk* helpers only work + // without. kdesu maintainers won't fix their app, so we need to work around that here. + if (suCmd.indexOf("kde") != -1) + argList << "-c"; + + argList << args->allArguments().join(" ") + " --dontsu"; + + kDebug() << "command: " << suCmd << ", arguments: " << argList; + + if (QProcess::execute(suCmd, argList) == 0) return false; } - + return KMessageBox::warningContinueCancel(NULL, i18nc("@info", "You do not have administrative privileges." "It is possible to run %1 without these privileges. "