If we're not running as root try to gain super user privileges by calling
kdesu/kdesudo/gksu/gksudo with ourselves as arg. This should stop the complaints from poor gnome users not being able to do anything in the app because their DE doesn't know anything about X-KDE-SubstituteUID. svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1053264
This commit is contained in:
parent
b514d16fad
commit
d994440466
|
@ -27,6 +27,9 @@
|
|||
int main(int argc, char* argv[])
|
||||
{
|
||||
KCmdLineArgs::init(argc, argv, createPartitionManagerAboutData());
|
||||
KCmdLineOptions options;
|
||||
options.add("dontsu", ki18nc("@info:shell", "Do not try to gain super user privileges"));
|
||||
KCmdLineArgs::addCmdLineOptions(options);
|
||||
|
||||
// workaround for https://bugs.launchpad.net/kdesudo/+bug/272427
|
||||
unblockSigChild();
|
||||
|
|
|
@ -27,6 +27,13 @@
|
|||
#include <kmessagebox.h>
|
||||
#include <kglobal.h>
|
||||
#include <kcomponentdata.h>
|
||||
#include <kstandarddirs.h>
|
||||
#include <kcmdlineargs.h>
|
||||
#include <kdebug.h>
|
||||
|
||||
#include <QProcess>
|
||||
#include <QFileInfo>
|
||||
#include <QApplication>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
@ -45,9 +52,45 @@ void unblockSigChild()
|
|||
sigprocmask(SIG_UNBLOCK, &sset, NULL);
|
||||
}
|
||||
|
||||
static QString suCommand()
|
||||
{
|
||||
QString rval = KStandardDirs().locate("exe", "kdesu");
|
||||
|
||||
if (rval.isEmpty() || !QFileInfo(rval).isExecutable())
|
||||
rval = KStandardDirs().locate("exe", "kdesudo");
|
||||
|
||||
// is it even possible to install kdelibs without kdesu? well, won't hurt and you never
|
||||
// know what distros and packagers do...
|
||||
if (rval.isEmpty() || !QFileInfo(rval).isExecutable())
|
||||
rval = KStandardDirs().locate("exe", "gksudo");
|
||||
|
||||
if (rval.isEmpty() || !QFileInfo(rval).isExecutable())
|
||||
rval = KStandardDirs().locate("exe", "gksu");
|
||||
|
||||
return QFileInfo(rval).isExecutable() ? rval : QString();
|
||||
}
|
||||
|
||||
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
|
||||
// endless loops of calling the same non-working (kde|gk)su(do) binary again and again.
|
||||
if (!suCommand().isEmpty() && !KCmdLineArgs::parsedArgs()->isSet("dontsu"))
|
||||
{
|
||||
QStringList args = qApp->arguments();
|
||||
|
||||
// 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 kdesu(do)
|
||||
const QString suArgs = qApp->applicationFilePath() + args.join(" ") + " --dontsu";
|
||||
if (QProcess::execute(suCommand(), QStringList() << suArgs) == 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
return KMessageBox::warningContinueCancel(NULL, i18nc("@info",
|
||||
"<para><warning>You do not have administrative privileges.</warning></para>"
|
||||
"<para>It is possible to run <application>%1</application> without these privileges. "
|
||||
|
@ -58,6 +101,7 @@ bool checkPermissions()
|
|||
KGuiItem(i18nc("@action:button", "Run without administrative privileges")),
|
||||
KStandardGuiItem::cancel(),
|
||||
"runWithoutRootPrivileges") == KMessageBox::Continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue