backport r1278089 and r1278090:

Workaround broken kdesu backward compatibility.

svn path=/branches/partitionmanager/1.0/partitionmanager/; revision=1278091
This commit is contained in:
Volker Lanz 2012-02-04 10:42:38 +00:00
parent ffea238a78
commit 731f5bfec5
1 changed files with 19 additions and 12 deletions

View File

@ -72,23 +72,30 @@ bool checkPermissions()
{ {
if (geteuid() != 0) if (geteuid() != 0)
{ {
// only try to gain root privileges if we have a valid (kde|gk)su(do) command and KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
// we did not try so before: the dontsu-option is there to make sure there are no // 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. // 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]) const QString suCmd = suCommand();
if (!args.isEmpty())
args.removeFirst(); // 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
// arguments to partition manager must be _one_ argument to (kde|gk)su(do) // without. kdesu maintainers won't fix their app, so we need to work around that here.
const QString suArgs = qApp->applicationFilePath() + args.join(" ") + " --dontsu"; if (suCmd.indexOf("kde") != -1)
if (QProcess::execute(suCommand(), QStringList() << suArgs) == 0) argList << "-c";
argList << args->allArguments().join(" ") + " --dontsu";
kDebug() << "command: " << suCmd << ", arguments: " << argList;
if (QProcess::execute(suCmd, argList) == 0)
return false; return false;
} }
return KMessageBox::warningContinueCancel(NULL, i18nc("@info", return KMessageBox::warningContinueCancel(NULL, i18nc("@info",
"<para><warning>You do not have administrative privileges.</warning></para>" "<para><warning>You do not have administrative privileges.</warning></para>"
"<para>It is possible to run <application>%1</application> without these privileges. " "<para>It is possible to run <application>%1</application> without these privileges. "