1 //===========================================
2 //  Lumina-DE source code
3 //  Copyright (c) 2016, Ken Moore
4 //  Available under the 3-clause BSD license
5 //  See the LICENSE file for full details
6 //===========================================
7 //  This is the backend classe for interacting with the "git" utility
8 //===========================================
9 #include "gitCompat.h"
10 #include <QApplication>
11 
12 #define TMPFILE QString("/tmp/.")
GitProcess()13 GitProcess::GitProcess() : QProcess(){
14   this->setProcessChannelMode(QProcess::MergedChannels);
15   tmpfile.setFileName(TMPFILE +QString::number( (rand()%8999) + 1000 ));
16   //qDebug() << "Temporary File Name:" << tmpfile.fileName();
17   tmpfile.setParent(this);
18   connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(cleanup()) );
19   connect(this, SIGNAL(readyReadStandardOutput()), this, SLOT(printoutput()) );
20 }
21 
~GitProcess()22 GitProcess::~GitProcess(){
23   if(tmpfile.exists()){ tmpfile.remove(); } //ensure that password file never gets left behind
24 }
25 
setSSHPassword(QString pass)26 void GitProcess::setSSHPassword(QString pass){
27   //Save the password into the temporary file
28   if( tmpfile.open(QIODevice::WriteOnly) ){
29     QTextStream in(&tmpfile);
30     in << "#!/bin/sh"<<"\n";
31     in << "echo \""+pass+"\"" << "\n";
32     in << "rm "+tmpfile.fileName()+"\n"; //have the script clean itself up after running once
33     tmpfile.close();
34   }
35   tmpfile.setPermissions( QFile::ReadOwner  | QFile::WriteOwner | QFile::ExeOwner );
36   QApplication::processEvents();
37   QProcessEnvironment env = this->processEnvironment();
38     env.insert("SSH_ASKPASS", tmpfile.fileName());
39     env.insert("DISPLAY",":0"); //will not actually be used - the tmp file sends the password back instantly
40   this->setProcessEnvironment(env);
41 }
42 
cleanup()43 void GitProcess::cleanup(){
44   if(tmpfile.exists()){ tmpfile.remove(); } //ensure that password file never gets left behind
45 }
46