TQt4 port kdesudo

This enables compilation under both Qt3 and Qt4


git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kdesudo@1238441 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
v3.5.13-sru
tpearson 13 years ago
parent b166c693b4
commit d0f4d15131

@ -20,10 +20,10 @@
#include "kdesudo.h" #include "kdesudo.h"
#include <qfile.h> #include <tqfile.h>
#include <qdir.h> #include <tqdir.h>
#include <qdatastream.h> #include <tqdatastream.h>
#include <qstring.h> #include <tqstring.h>
#include <kcmdlineargs.h> #include <kcmdlineargs.h>
#include <klocale.h> #include <klocale.h>
@ -43,12 +43,12 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
KdeSudo::KdeSudo(QWidget *parent, const char *name,const QString& icon, const QString& generic, bool withIgnoreButton) KdeSudo::KdeSudo(TQWidget *tqparent, const char *name,const TQString& icon, const TQString& generic, bool withIgnoreButton)
: KPasswordDialog(KPasswordDialog::Password, false, (withIgnoreButton ? User1: false), icon, parent, name) : KPasswordDialog(KPasswordDialog::Password, false, (withIgnoreButton ? User1: false), icon, tqparent, name)
{ {
KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
QString defaultComment = i18n("<b>%1</b> needs administrative privileges. Please enter your password for verification."); TQString defaultComment = i18n("<b>%1</b> needs administrative privileges. Please enter your password for verification.");
p=NULL; p=NULL;
bError=false; bError=false;
@ -63,8 +63,8 @@ KdeSudo::KdeSudo(QWidget *parent, const char *name,const QString& icon, const QS
bool noExec = false; bool noExec = false;
keepPwd = (!args->isSet("n")); keepPwd = (!args->isSet("n"));
emptyPwd = args->isSet("s"); emptyPwd = args->isSet("s");
QString runas = args->getOption("u"); TQString runas = args->getOption("u");
QString cmd; TQString cmd;
if (!args->isSet("c") && !args->count() && (!args->isSet("s"))) if (!args->isSet("c") && !args->count() && (!args->isSet("s")))
{ {
@ -78,15 +78,15 @@ KdeSudo::KdeSudo(QWidget *parent, const char *name,const QString& icon, const QS
// Parsins args // Parsins args
/* Get the comment out of cli args */ /* Get the comment out of cli args */
QByteArray commentBytes = args->getOption("comment"); TQByteArray commentBytes = args->getOption("comment");
QTextCodec* tCodecConv = QTextCodec::codecForLocale(); TQTextCodec* tCodecConv = TQTextCodec::codecForLocale();
QString comment = tCodecConv->toUnicode(commentBytes, commentBytes.size()); TQString comment = tCodecConv->toUnicode(commentBytes, commentBytes.size());
if (args->isSet("f")) if (args->isSet("f"))
{ {
// If file is writeable, do not change uid // If file is writeable, do not change uid
QString filename = QFile::decodeName(args->getOption("f")); TQString filename = TQFile::decodeName(args->getOption("f"));
QString file = filename; TQString file = filename;
if (!file.isEmpty()) if (!file.isEmpty())
{ {
if (file.at(0) != '/') if (file.at(0) != '/')
@ -100,7 +100,7 @@ KdeSudo::KdeSudo(QWidget *parent, const char *name,const QString& icon, const QS
exit(1); exit(1);
} }
} }
QFileInfo fi(file); TQFileInfo fi(file);
if (!fi.exists()) if (!fi.exists())
{ {
kdError(1206) << "File does not exist: " << file << "\n"; kdError(1206) << "File does not exist: " << file << "\n";
@ -124,8 +124,8 @@ KdeSudo::KdeSudo(QWidget *parent, const char *name,const QString& icon, const QS
// from the existing server and set ICEAUTHORITY to point to the file // from the existing server and set ICEAUTHORITY to point to the file
if (!newDcop) { if (!newDcop) {
dcopServer = m_pCookie->dcopServer(); dcopServer = m_pCookie->dcopServer();
QCString dcopAuth = m_pCookie->dcopAuth(); TQCString dcopAuth = m_pCookie->dcopAuth();
QCString iceAuth = m_pCookie->iceAuth(); TQCString iceAuth = m_pCookie->iceAuth();
FILE *fout; FILE *fout;
char iceauthority[200]; char iceauthority[200];
@ -161,14 +161,14 @@ KdeSudo::KdeSudo(QWidget *parent, const char *name,const QString& icon, const QS
pclose(fout); pclose(fout);
// Exporting the user's sycoca // Exporting the user's sycoca
kdeSycoca = QFile::encodeName(locateLocal("cache", "ksycoca")); kdeSycoca = TQFile::encodeName(locateLocal("cache", "ksycoca"));
} }
connect( p, SIGNAL(receivedStdout(KProcess*, char*, int)), this, SLOT(receivedOut(KProcess*, char*, int)) ); connect( p, TQT_SIGNAL(receivedStdout(KProcess*, char*, int)), this, TQT_SLOT(receivedOut(KProcess*, char*, int)) );
connect( p, SIGNAL(receivedStderr(KProcess*, char*, int)), this, SLOT(receivedOut(KProcess*, char*, int)) ); connect( p, TQT_SIGNAL(receivedStderr(KProcess*, char*, int)), this, TQT_SLOT(receivedOut(KProcess*, char*, int)) );
connect( p, SIGNAL(processExited (KProcess *)), this, SLOT(procExited(KProcess*))); connect( p, TQT_SIGNAL(processExited (KProcess *)), this, TQT_SLOT(procExited(KProcess*)));
QString xauthenv = QString(getenv("HOME")) + "/.Xauthority"; TQString xauthenv = TQString(getenv("HOME")) + "/.Xauthority";
p->setEnvironment("XAUTHORITY", xauthenv); p->setEnvironment("XAUTHORITY", xauthenv);
// Generate the xauth cookie and put it in a tempfile // Generate the xauth cookie and put it in a tempfile
@ -182,10 +182,10 @@ KdeSudo::KdeSudo(QWidget *parent, const char *name,const QString& icon, const QS
FILE *f; FILE *f;
char buf[1024]; char buf[1024];
QCString disp = m_pCookie->display(); TQCString disp = m_pCookie->display();
// command: xauth -q -f m_tmpname generate $DISPLAy . trusted timeout 60 // command: xauth -q -f m_tmpname generate $DISPLAy . trusted timeout 60
QString c = "/usr/bin/xauth -q -f " + m_tmpname + " generate " TQString c = "/usr/bin/xauth -q -f " + m_tmpname + " generate "
+ QString::fromLocal8Bit(disp) + " . trusted timeout 60"; + TQString::fromLocal8Bit(disp) + " . trusted timeout 60";
blockSigChild(); // pclose uses waitpid() blockSigChild(); // pclose uses waitpid()
if (!(f = popen(c, "r"))) { if (!(f = popen(c, "r"))) {
@ -196,7 +196,7 @@ KdeSudo::KdeSudo(QWidget *parent, const char *name,const QString& icon, const QS
// non root users need to be able to read the xauth file. // non root users need to be able to read the xauth file.
// the xauth file is deleted when kdesudo exits. security? // the xauth file is deleted when kdesudo exits. security?
QFile tf(m_tmpname); TQFile tf(m_tmpname);
if (!runas.isEmpty() && runas != "root" && tf.exists()) if (!runas.isEmpty() && runas != "root" && tf.exists())
chmod(m_tmpname.ascii(),0644); chmod(m_tmpname.ascii(),0644);
@ -237,36 +237,36 @@ KdeSudo::KdeSudo(QWidget *parent, const char *name,const QString& icon, const QS
if (realtime) if (realtime)
{ {
*p << "nice" << "-n" << "10"; *p << "nice" << "-n" << "10";
addLine(i18n("Priority:"), i18n("realtime:") + QChar(' ') + QString("50/100")); addLine(i18n("Priority:"), i18n("realtime:") + TQChar(' ') + TQString("50/100"));
} }
else if (priority) else if (priority)
{ {
QString n = args->getOption("p"); TQString n = args->getOption("p");
int intn = atoi(n); int intn = atoi(n);
intn = (intn * 40 / 100) - (20 + 0.5); intn = (intn * 40 / 100) - (20 + 0.5);
QString strn; TQString strn;
strn.sprintf("%d",intn); strn.sprintf("%d",intn);
*p << "nice" << "-n" << strn; *p << "nice" << "-n" << strn;
addLine(i18n("Priority:"), n + QString("/100")); addLine(i18n("Priority:"), n + TQString("/100"));
} }
*p << "--"; *p << "--";
if (args->isSet("c")) if (args->isSet("c"))
{ {
QString command = args->getOption("c"); TQString command = args->getOption("c");
QStringList commandSplit = KShell::splitArgs(command); TQStringList commandSplit = KShell::splitArgs(command);
for (int i = 0; i < commandSplit.count(); i++) for (int i = 0; i < commandSplit.count(); i++)
{ {
QString arg = validArg(commandSplit[i]); TQString arg = validArg(commandSplit[i]);
*p << arg; *p << arg;
if (i == 0) if (i == 0)
cmd += validArg(commandSplit[i]) + QChar(' '); cmd += validArg(commandSplit[i]) + TQChar(' ');
else else
cmd += KProcess::quote(validArg(commandSplit[i])) + QChar(' '); cmd += KProcess::quote(validArg(commandSplit[i])) + TQChar(' ');
} }
} }
@ -276,20 +276,20 @@ KdeSudo::KdeSudo(QWidget *parent, const char *name,const QString& icon, const QS
{ {
if ((!args->isSet("c")) && (i == 0)) if ((!args->isSet("c")) && (i == 0))
{ {
QStringList argsSplit = KShell::splitArgs(args->arg(i)); TQStringList argsSplit = KShell::splitArgs(args->arg(i));
for (int j = 0; j < argsSplit.count(); j++) for (int j = 0; j < argsSplit.count(); j++)
{ {
*p << validArg(argsSplit[j]); *p << validArg(argsSplit[j]);
if (j == 0) if (j == 0)
cmd += validArg(argsSplit[j]) + QChar(' '); cmd += validArg(argsSplit[j]) + TQChar(' ');
else else
cmd += KProcess::quote(validArg(argsSplit[j])) + QChar(' '); cmd += KProcess::quote(validArg(argsSplit[j])) + TQChar(' ');
} }
} }
else else
{ {
*p << validArg(args->arg(i)); *p << validArg(args->arg(i));
cmd += validArg(args->arg(i)) + QChar(' '); cmd += validArg(args->arg(i)) + TQChar(' ');
} }
} }
} }
@ -301,9 +301,9 @@ KdeSudo::KdeSudo(QWidget *parent, const char *name,const QString& icon, const QS
if (comment.isEmpty()) if (comment.isEmpty())
{ {
if (!generic.isEmpty()) if (!generic.isEmpty())
setPrompt(defaultComment.arg(generic)); setPrompt(defaultComment.tqarg(generic));
else else
setPrompt(defaultComment.arg(cmd)); setPrompt(defaultComment.tqarg(cmd));
} }
else else
setPrompt(comment); setPrompt(comment);
@ -323,13 +323,13 @@ void KdeSudo::receivedOut(KProcess*, char*buffer, int buflen)
char *pcTmp= new char[buflen+1]; char *pcTmp= new char[buflen+1];
strncpy(pcTmp,buffer,buflen); strncpy(pcTmp,buffer,buflen);
pcTmp[buflen]='\0'; pcTmp[buflen]='\0';
QString strOut(pcTmp); TQString strOut(pcTmp);
std::cout << strOut << std::endl; std::cout << strOut << std::endl;
static int badpass = 0; static int badpass = 0;
if (strOut.find("Sorry, try again")!=-1) if (strOut.tqfind("Sorry, try again")!=-1)
{ {
badpass++; badpass++;
if (badpass>2) if (badpass>2)
@ -339,37 +339,37 @@ void KdeSudo::receivedOut(KProcess*, char*buffer, int buflen)
kapp->quit(); kapp->quit();
} }
} }
if (strOut.find("command not found")!=-1) if (strOut.tqfind("command not found")!=-1)
{ {
bError=true; bError=true;
KMessageBox::error(this, i18n("Command not found!")); KMessageBox::error(this, i18n("Command not found!"));
kapp->quit(); kapp->quit();
} }
if (strOut.find("is not in the sudoers file")!=-1) if (strOut.tqfind("is not in the sudoers file")!=-1)
{ {
bError=true; bError=true;
KMessageBox::error(this, i18n("Your username is unknown to sudo!")); KMessageBox::error(this, i18n("Your username is unknown to sudo!"));
kapp->quit(); kapp->quit();
} }
if (strOut.find("is not allowed to execute")!=-1) if (strOut.tqfind("is not allowed to execute")!=-1)
{ {
bError=true; bError=true;
KMessageBox::error(this, i18n("Your user is not allowed to run the specified command!")); KMessageBox::error(this, i18n("Your user is not allowed to run the specified command!"));
kapp->quit(); kapp->quit();
} }
if (strOut.find("is not allowed to run sudo on")!=-1) if (strOut.tqfind("is not allowed to run sudo on")!=-1)
{ {
bError=true; bError=true;
KMessageBox::error(this, i18n("Your user is not allowed to run sudo on this host!")); KMessageBox::error(this, i18n("Your user is not allowed to run sudo on this host!"));
kapp->quit(); kapp->quit();
} }
if (strOut.find("may not run sudo on")!=-1) if (strOut.tqfind("may not run sudo on")!=-1)
{ {
bError=true; bError=true;
KMessageBox::error(this, i18n("Your user is not allowed to run sudo on this host!")); KMessageBox::error(this, i18n("Your user is not allowed to run sudo on this host!"));
kapp->quit(); kapp->quit();
} }
if ((strOut.find("passprompt")!=-1) || (strOut.find("PIN (CHV2)")!=-1)) if ((strOut.tqfind("passprompt")!=-1) || (strOut.tqfind("PIN (CHV2)")!=-1))
{ {
this->clearPassword(); this->clearPassword();
this->show(); this->show();
@ -388,18 +388,18 @@ void KdeSudo::procExited(KProcess*)
if (!newDcop && !iceauthorityFile.isEmpty()) if (!newDcop && !iceauthorityFile.isEmpty())
if (!iceauthorityFile.isEmpty()) if (!iceauthorityFile.isEmpty())
QFile::remove(iceauthorityFile); TQFile::remove(iceauthorityFile);
if (!bError) { if (!bError) {
if (!m_tmpname.isEmpty()) if (!m_tmpname.isEmpty())
QFile::remove(m_tmpname); TQFile::remove(m_tmpname);
kapp->quit(); kapp->quit();
} }
} }
void KdeSudo::slotOk() void KdeSudo::slotOk()
{ {
QString strTmp(password()); TQString strTmp(password());
strTmp+="\n"; strTmp+="\n";
p->writeStdin(strTmp.ascii(),(int)strTmp.length()); p->writeStdin(strTmp.ascii(),(int)strTmp.length());
this->hide(); this->hide();
@ -425,10 +425,10 @@ void KdeSudo::unblockSigChild()
sigprocmask(SIG_UNBLOCK, &sset, 0L); sigprocmask(SIG_UNBLOCK, &sset, 0L);
} }
QString KdeSudo::validArg(QString arg) TQString KdeSudo::validArg(TQString arg)
{ {
QChar firstChar = arg.at(0); TQChar firstChar = arg.at(0);
QChar lastChar = arg.at(arg.length() - 1); TQChar lastChar = arg.at(arg.length() - 1);
if ( (firstChar == '"' && lastChar == '"') || (firstChar == '\'' && lastChar == '\'') ) if ( (firstChar == '"' && lastChar == '"') || (firstChar == '\'' && lastChar == '\'') )
{ {

@ -26,10 +26,10 @@
#endif #endif
#include <kapp.h> #include <kapp.h>
#include <qwidget.h> #include <tqwidget.h>
#include <kpassdlg.h> #include <kpassdlg.h>
#include <qstring.h> #include <tqstring.h>
#include <qtextcodec.h> #include <tqtextcodec.h>
#include <kprocess.h> #include <kprocess.h>
class KCookie; class KCookie;
@ -45,12 +45,12 @@ class KCookie;
class KdeSudo : public KPasswordDialog class KdeSudo : public KPasswordDialog
{ {
Q_OBJECT TQ_OBJECT
public: public:
/* /*
* Default construtor * Default construtor
*/ */
KdeSudo(QWidget* parent=0, const char *name=0, const QString& icon=QString(), const QString& generic=QString(), bool withIgnoreButton=false); KdeSudo(TQWidget* tqparent=0, const char *name=0, const TQString& icon=TQString(), const TQString& generic=TQString(), bool withIgnoreButton=false);
/* /*
* Default destructor * Default destructor
@ -73,7 +73,7 @@ public slots: // Public slots
*/ */
void slotOk(); void slotOk();
void slotUser1(); void slotUser1();
QString validArg(QString arg); TQString validArg(TQString arg);
private: // Private attributes private: // Private attributes
KProcess * p; KProcess * p;
@ -84,10 +84,10 @@ private: // Private attributes
bool useTerm; bool useTerm;
bool noExec; bool noExec;
bool unCleaned; bool unCleaned;
QString m_tmpname; TQString m_tmpname;
QString iceauthorityFile; TQString iceauthorityFile;
QString dcopServer; TQString dcopServer;
QString kdeSycoca; TQString kdeSycoca;
KCookie* m_pCookie; KCookie* m_pCookie;
void blockSigChild(); void blockSigChild();
void unblockSigChild(); void unblockSigChild();

@ -31,8 +31,8 @@
#include <kstandarddirs.h> #include <kstandarddirs.h>
#include <kprocess.h> #include <kprocess.h>
#include <kdebug.h> #include <kdebug.h>
#include <qfile.h> #include <tqfile.h>
#include <qfileinfo.h> #include <tqfileinfo.h>
static const char *description = static const char *description =
I18N_NOOP("KdeSudo"); I18N_NOOP("KdeSudo");
@ -72,12 +72,12 @@ int main(int argc, char **argv)
KApplication a; KApplication a;
QString executable; TQString executable;
QStringList executableList; TQStringList executableList;
QString arg; TQString arg;
QString command; TQString command;
QStringList commandlist; TQStringList commandlist;
QString icon; TQString icon;
bool withIgnoreButton = args->isSet("ignorebutton"); bool withIgnoreButton = args->isSet("ignorebutton");
@ -89,16 +89,16 @@ int main(int argc, char **argv)
if (executable.isEmpty()) if (executable.isEmpty())
{ {
command = args->arg(0); command = args->arg(0);
commandlist = QStringList::split(QChar(' '), command); commandlist = TQStringList::split(TQChar(' '), command);
executable = commandlist[0]; executable = commandlist[0];
} }
} }
/* We have to make sure the executable is only the binary name */ /* We have to make sure the executable is only the binary name */
executableList = QStringList::split(" ", executable); executableList = TQStringList::split(" ", executable);
executable = executableList[0]; executable = executableList[0];
executableList = QStringList::split("/", executable); executableList = TQStringList::split("/", executable);
int i = executableList.count() - 1; int i = executableList.count() - 1;
executable = executableList[i]; executable = executableList[i];
@ -106,7 +106,7 @@ int main(int argc, char **argv)
KGlobal::dirs()->addResourceDir("apps","/usr/share/applications/kde"); KGlobal::dirs()->addResourceDir("apps","/usr/share/applications/kde");
KGlobal::dirs()->addResourceDir("apps","/usr/share/applications"); KGlobal::dirs()->addResourceDir("apps","/usr/share/applications");
QString deskFilePath = KGlobal::dirs()->findResource("apps",executable + ".desktop"); TQString deskFilePath = KGlobal::dirs()->findResource("apps",executable + ".desktop");
KDesktopFile desktopFile(deskFilePath,true); KDesktopFile desktopFile(deskFilePath,true);
/* icon parsing */ /* icon parsing */
@ -114,13 +114,13 @@ int main(int argc, char **argv)
icon = args->getOption("i"); icon = args->getOption("i");
else else
{ {
QString iconName = desktopFile.readIcon(); TQString iconName = desktopFile.readIcon();
icon = KGlobal::iconLoader()->iconPath(iconName, -1* KIcon::StdSizes(KIcon::SizeHuge), true); icon = KGlobal::iconLoader()->iconPath(iconName, -1* KIcon::StdSizes(KIcon::SizeHuge), true);
} }
/* generic name parsing */ /* generic name parsing */
QString name = desktopFile.readName(); TQString name = desktopFile.readName();
QString genericName = desktopFile.readGenericName(); TQString genericName = desktopFile.readGenericName();
if (!name.isEmpty()) if (!name.isEmpty())
{ {

Loading…
Cancel
Save