aheinecke@256: #include "installwrapper.h" aheinecke@256: aheinecke@256: #include aheinecke@256: #include aheinecke@256: #include aheinecke@256: #include aheinecke@256: #include aheinecke@256: aheinecke@256: #include "logging.h" aheinecke@256: aheinecke@256: InstallWrapper::InstallWrapper(QObject* parent, aheinecke@256: const QString& path, const QStringList& instructions): aheinecke@256: QThread(parent), aheinecke@256: mCertListFile(path), aheinecke@256: mInstructions(instructions) aheinecke@256: { aheinecke@256: } aheinecke@256: aheinecke@256: QFileInfo getCinstProcInfo() { aheinecke@256: QFileInfo fi(QCoreApplication::applicationFilePath()); aheinecke@256: QDir myDir = fi.absoluteDir(); aheinecke@256: QString instProcName = "cinst"; aheinecke@256: if (!fi.suffix().isEmpty()) { aheinecke@256: instProcName += "." + fi.suffix(); aheinecke@256: } aheinecke@256: return QFileInfo(myDir.absoluteFilePath(instProcName)); aheinecke@256: } aheinecke@256: aheinecke@256: #ifdef WIN32 aheinecke@256: extern Q_CORE_EXPORT int qt_ntfs_permission_lookup; aheinecke@256: aheinecke@256: void InstallWrapper::run() aheinecke@256: { aheinecke@256: QTemporaryFile instructionsFile; aheinecke@256: QFileInfo cinstProcInfo = getCinstProcInfo(); aheinecke@256: aheinecke@256: QString cinstFileName = QDir::toNativeSeparators( aheinecke@256: getCinstProcInfo().absoluteFilePath()); aheinecke@256: aheinecke@256: if (!cinstProcInfo.isExecutable()) { aheinecke@256: emit error (tr("Could not find certificate installation process.")); aheinecke@256: return; aheinecke@256: } aheinecke@256: aheinecke@256: instructionsFile.open(); aheinecke@256: aheinecke@256: qt_ntfs_permission_lookup++; aheinecke@256: if (instructionsFile.permissions() ^ ( aheinecke@256: QFileDevice::ReadUser | aheinecke@256: QFileDevice::WriteUser | aheinecke@256: QFileDevice::ReadOwner | aheinecke@256: QFileDevice::WriteOwner)) { aheinecke@256: emit error (tr("Invalid permissions on temporary file.")); aheinecke@256: } aheinecke@256: aheinecke@256: foreach (const QString &b64data, mInstructions) { aheinecke@256: instructionsFile.write(b64data.toLatin1()); aheinecke@256: instructionsFile.write("\n"); aheinecke@256: } aheinecke@256: aheinecke@256: instructionsFile.close(); aheinecke@256: aheinecke@256: QString parameters = "\"" + mCertListFile + "\" \"" +instructionsFile.fileName() + "\""; aheinecke@256: aheinecke@256: memset (&mExecInfo, 0, sizeof(SHELLEXECUTEINFOW)); aheinecke@256: mExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW); aheinecke@256: mExecInfo.fMask = SEE_MASK_FLAG_NO_UI | aheinecke@256: SEE_MASK_NOASYNC; aheinecke@256: mExecInfo.lpVerb = L"runas"; aheinecke@256: mExecInfo.lpFile = reinterpret_cast (cinstFileName.utf16()); aheinecke@256: mExecInfo.lpParameters = reinterpret_cast (parameters.utf16()); aheinecke@256: aheinecke@256: qDebug() << "Starting process " << cinstFileName <<" params: " << parameters; aheinecke@256: aheinecke@256: if (!ShellExecuteExW(&mExecInfo)) { aheinecke@256: char* errmsg = getLastErrorMsg(); aheinecke@256: QString qerrmsg = QString::fromUtf8(errmsg); aheinecke@256: free(errmsg); aheinecke@256: emit(tr("Error executing process: %1").arg(qerrmsg)); aheinecke@256: } aheinecke@256: qt_ntfs_permission_lookup--; aheinecke@256: } aheinecke@256: #else aheinecke@256: void InstallWrapper::run() aheinecke@256: { aheinecke@256: } aheinecke@256: #endif