Ignore:
Timestamp:
07/15/13 13:53:57 (16 months ago)
Author:
Kris Moore <kris@…>
Branches:
master, 9.2-release, releng/10.0, releng/10.0.1, releng/10.0.2, releng/10.0.3, releng/10.1
Children:
438117c
Parents:
b633c064
Message:

Update qsudo, now it is smarter, will test passwords and let you retry up to 3x

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src-qt4/qsudo/mainwindow.cpp

    rb633c064 r33b8b3a  
    1313#include <QDir> 
    1414#include <QString> 
     15#include <QProcess> 
    1516#include <QTextStream> 
     17#include <QApplication> 
    1618#include "mainwindow.h" 
    1719#include "../config.h" 
     
    1921void MainWindow::ProgramInit() 
    2022{ 
     23  tries=3; 
    2124  connect(buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(slotButtonClicked(QAbstractButton *))); 
    2225  connect(passwordLineEdit, SIGNAL(returnPressed()), this, SLOT(slotReturnPressed())); 
     
    2528void MainWindow::slotReturnPressed() 
    2629{ 
    27   QTextStream cout(stdout); 
    28   cout << passwordLineEdit->text(); 
    29   close(); 
     30  testPass(); 
     31} 
     32 
     33void MainWindow::testPass() 
     34{ 
     35 
     36  QString program = "sudo"; 
     37  QStringList arguments; 
     38  arguments << "-S"; 
     39  arguments << "-k"; 
     40  arguments << "true"; 
     41 
     42  QProcess *tP = new QProcess(this); 
     43  tP->start(program, arguments); 
     44  tP->write(passwordLineEdit->text().toLatin1() + "\n"); 
     45  tP->write(passwordLineEdit->text().toLatin1() + "\n"); 
     46  tP->write(passwordLineEdit->text().toLatin1() + "\n"); 
     47  while(tP->state() == QProcess::Starting || tP->state() == QProcess::Running ) { 
     48     tP->waitForFinished(500); 
     49     QCoreApplication::processEvents(); 
     50     qDebug() << "Waiting..."; 
     51  } 
     52  if ( tP->exitCode() != 0 ) 
     53  { 
     54     QString tmp; 
     55     tmp.setNum(tries-1); 
     56     labelBadPW->setText(tr("Invalid Password! Tries Left: %1").arg(tmp) ); 
     57     tries--; 
     58     if ( tries == 0 ) 
     59       exit(1); 
     60  } else { 
     61     startSudo(); 
     62  } 
     63} 
     64 
     65void MainWindow::startSudo() 
     66{ 
     67  setVisible(false); 
     68  QString program = "sudo"; 
     69  QStringList arguments; 
     70  arguments << "-S"; 
     71  for ( int i = 1; i< qApp->argc() ; i++) 
     72    arguments << qApp->argv()[i]; 
     73 
     74  sudoProc = new QProcess(this); 
     75  sudoProc->start(program, arguments); 
     76  sudoProc->write(passwordLineEdit->text().toLatin1() + "\n"); 
     77  connect( sudoProc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotProcDone() ) ); 
     78  while(sudoProc->state() == QProcess::Starting ) { 
     79     sudoProc->waitForFinished(500); 
     80     QCoreApplication::processEvents(); 
     81  } 
     82} 
     83 
     84void MainWindow::slotProcDone() 
     85{ 
     86   exit(sudoProc->exitCode()); 
    3087} 
    3188 
    3289void MainWindow::slotButtonClicked(QAbstractButton *myBut) 
    3390{ 
    34   if ( buttonBox->buttonRole(myBut) == QDialogButtonBox::AcceptRole ){ 
    35     QTextStream cout(stdout); 
    36     cout << passwordLineEdit->text(); 
    37   } 
     91  if ( buttonBox->buttonRole(myBut) == QDialogButtonBox::AcceptRole )  
     92     testPass(); 
    3893  close(); 
    3994} 
Note: See TracChangeset for help on using the changeset viewer.