@ -20,10 +20,10 @@
# include "kdesudo.h"
# include "kdesudo.h"
# include < qfile.h>
# include < t qfile.h>
# include < qdir.h>
# include < t qdir.h>
# include < qdatastream.h>
# include < t qdatastream.h>
# include < qstring.h>
# include < t qstring.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 ( T QWidget * tq parent, const char * name , const T QString& icon , const T QString& generic , bool withIgnoreButton )
: KPasswordDialog ( KPasswordDialog : : Password , false , ( withIgnoreButton ? User1 : false ) , icon , parent, name )
: KPasswordDialog ( KPasswordDialog : : Password , false , ( withIgnoreButton ? User1 : false ) , icon , tq parent, name )
{
{
KCmdLineArgs * args = KCmdLineArgs : : parsedArgs ( ) ;
KCmdLineArgs * args = KCmdLineArgs : : parsedArgs ( ) ;
QString defaultComment = i18n ( " <b>%1</b> needs administrative privileges. Please enter your password for verification. " ) ;
T QString 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 " ) ;
T QString runas = args - > getOption ( " u " ) ;
QString cmd ;
T QString 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 " ) ;
T QByteArray commentBytes = args - > getOption ( " comment " ) ;
QTextCodec* tCodecConv = QTextCodec: : codecForLocale ( ) ;
T QTextCodec* tCodecConv = T QTextCodec: : codecForLocale ( ) ;
QString comment = tCodecConv - > toUnicode ( commentBytes , commentBytes . size ( ) ) ;
T QString 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 " ) ) ;
T QString filename = T QFile: : decodeName ( args - > getOption ( " f " ) ) ;
QString file = filename ;
T QString 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 ) ;
T QFileInfo 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 ( ) ;
T QCString dcopAuth = m_pCookie - > dcopAuth ( ) ;
QCString iceAuth = m_pCookie - > iceAuth ( ) ;
T QCString 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 = T QFile: : 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 " ;
T QString xauthenv = T QString( 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 ( ) ;
T QCString 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 "
T QString c = " /usr/bin/xauth -q -f " + m_tmpname + " generate "
+ QString: : fromLocal8Bit ( disp ) + " . trusted timeout 60 " ;
+ T QString: : 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 ) ;
T QFile 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: " ) + T QChar( ' ' ) + T QString( " 50/100 " ) ) ;
}
}
else if ( priority )
else if ( priority )
{
{
QString n = args - > getOption ( " p " ) ;
T QString 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 ;
T QString 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 + T QString( " /100 " ) ) ;
}
}
* p < < " -- " ;
* p < < " -- " ;
if ( args - > isSet ( " c " ) )
if ( args - > isSet ( " c " ) )
{
{
QString command = args - > getOption ( " c " ) ;
T QString command = args - > getOption ( " c " ) ;
QStringList commandSplit = KShell : : splitArgs ( command ) ;
T QStringList 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 ] ) ;
T QString arg = validArg ( commandSplit [ i ] ) ;
* p < < arg ;
* p < < arg ;
if ( i = = 0 )
if ( i = = 0 )
cmd + = validArg ( commandSplit [ i ] ) + QChar( ' ' ) ;
cmd + = validArg ( commandSplit [ i ] ) + T QChar( ' ' ) ;
else
else
cmd + = KProcess : : quote ( validArg ( commandSplit [ i ] ) ) + QChar( ' ' ) ;
cmd + = KProcess : : quote ( validArg ( commandSplit [ i ] ) ) + T QChar( ' ' ) ;
}
}
}
}
@ -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 ) ) ;
T QStringList 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 ] ) + T QChar( ' ' ) ;
else
else
cmd + = KProcess : : quote ( validArg ( argsSplit [ j ] ) ) + QChar( ' ' ) ;
cmd + = KProcess : : quote ( validArg ( argsSplit [ j ] ) ) + T QChar( ' ' ) ;
}
}
}
}
else
else
{
{
* p < < validArg ( args - > arg ( i ) ) ;
* p < < validArg ( args - > arg ( i ) ) ;
cmd + = validArg ( args - > arg ( i ) ) + QChar( ' ' ) ;
cmd + = validArg ( args - > arg ( i ) ) + T QChar( ' ' ) ;
}
}
}
}
}
}
@ -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 . tq arg( generic ) ) ;
else
else
setPrompt ( defaultComment . arg( cmd ) ) ;
setPrompt ( defaultComment . tq arg( 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 ) ;
T QString 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 . tq find( " 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 . tq find( " 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 . tq find( " 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 . tq find( " 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 . tq find( " 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 . tq find( " 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 . tq find( " passprompt " ) ! = - 1 ) | | ( strOut . tq find( " 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 ) ;
T QFile: : remove ( iceauthorityFile ) ;
if ( ! bError ) {
if ( ! bError ) {
if ( ! m_tmpname . isEmpty ( ) )
if ( ! m_tmpname . isEmpty ( ) )
QFile: : remove ( m_tmpname ) ;
T QFile: : remove ( m_tmpname ) ;
kapp - > quit ( ) ;
kapp - > quit ( ) ;
}
}
}
}
void KdeSudo : : slotOk ( )
void KdeSudo : : slotOk ( )
{
{
QString strTmp ( password ( ) ) ;
T QString 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 )
T QString KdeSudo : : validArg ( T QString arg )
{
{
QChar firstChar = arg . at ( 0 ) ;
T QChar firstChar = arg . at ( 0 ) ;
QChar lastChar = arg . at ( arg . length ( ) - 1 ) ;
T QChar lastChar = arg . at ( arg . length ( ) - 1 ) ;
if ( ( firstChar = = ' " ' & & lastChar = = ' " ' ) | | ( firstChar = = ' \' ' & & lastChar = = ' \' ' ) )
if ( ( firstChar = = ' " ' & & lastChar = = ' " ' ) | | ( firstChar = = ' \' ' & & lastChar = = ' \' ' ) )
{
{