Mercurial > trustbridge
annotate ui/installwrapper.cpp @ 1185:69f7d302cdb9
Fix build with changed documentation paths
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 22 Sep 2014 13:11:30 +0200 |
parents | c8f698ca6355 |
children |
rev | line source |
---|---|
404 | 1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU GPL (v>=2) | |
5 * and comes with ABSOLUTELY NO WARRANTY! | |
6 * See LICENSE.txt for details. | |
7 */ | |
256
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
8 #include "installwrapper.h" |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
9 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
10 #include <QFileInfo> |
364 | 11 #include <QProcess> |
256
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
12 #include <QTemporaryFile> |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
13 #include <QApplication> |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
14 #include <QDir> |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
15 #include <QDebug> |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
16 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
17 #include "logging.h" |
511
cef732072774
Use open instead of runas if not admin
Andre Heinecke <aheinecke@intevation.de>
parents:
440
diff
changeset
|
18 #include "util.h" |
1084
b8fb6bf7f980
(issue118) Add signature check for cinst.exe and mozilla.exe
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1082
diff
changeset
|
19 #include "binverify.h" |
256
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
20 |
285
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
21 #define INSTALL_TIMEOUT 3600000 /* Wait up to an hour */ |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
22 |
256
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
23 InstallWrapper::InstallWrapper(QObject* parent, |
364 | 24 const QString& path, const QStringList& choices): |
256
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
25 QThread(parent), |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
26 mCertListFile(path), |
364 | 27 mChoices(choices) |
256
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
28 { |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
29 } |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
30 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
31 QFileInfo getCinstProcInfo() { |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
32 QFileInfo fi(QCoreApplication::applicationFilePath()); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
33 QDir myDir = fi.absoluteDir(); |
1176
c8f698ca6355
(issue128) Rename cinst to trustbridge-certificate-installer
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1162
diff
changeset
|
34 QString instProcName = "trustbridge-certificate-installer"; |
256
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
35 if (!fi.suffix().isEmpty()) { |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
36 instProcName += "." + fi.suffix(); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
37 } |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
38 return QFileInfo(myDir.absoluteFilePath(instProcName)); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
39 } |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
40 |
364 | 41 bool InstallWrapper::writeChoices(QTemporaryFile* choicesFile) const |
42 { | |
43 if (!choicesFile->open()) { | |
44 return false; | |
45 } | |
46 | |
47 foreach (const QString &b64data, mChoices) { | |
1082
a12e6172d82c
Extend logging to all choices and SW updates.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1060
diff
changeset
|
48 syslog_info_printf ("Selected certificate: %s\n", b64data.toLatin1().constData()); |
a12e6172d82c
Extend logging to all choices and SW updates.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1060
diff
changeset
|
49 if (choicesFile->write(b64data.toLatin1()) == -1) { |
a12e6172d82c
Extend logging to all choices and SW updates.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1060
diff
changeset
|
50 return false; |
a12e6172d82c
Extend logging to all choices and SW updates.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1060
diff
changeset
|
51 } |
a12e6172d82c
Extend logging to all choices and SW updates.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1060
diff
changeset
|
52 if (choicesFile->write("\n") == -1) { |
a12e6172d82c
Extend logging to all choices and SW updates.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1060
diff
changeset
|
53 return false; |
a12e6172d82c
Extend logging to all choices and SW updates.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1060
diff
changeset
|
54 } |
364 | 55 } |
56 | |
57 choicesFile->close(); | |
58 | |
59 return true; | |
60 } | |
61 | |
256
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
62 void InstallWrapper::run() |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
63 { |
364 | 64 QTemporaryFile choicesFile; |
256
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
65 QFileInfo cinstProcInfo = getCinstProcInfo(); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
66 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
67 QString cinstFileName = QDir::toNativeSeparators( |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
68 getCinstProcInfo().absoluteFilePath()); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
69 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
70 if (!cinstProcInfo.isExecutable()) { |
285
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
71 emit error(tr("Could not find certificate installation process.")); |
256
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
72 return; |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
73 } |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
74 |
364 | 75 if (!writeChoices(&choicesFile)) { |
76 emit error(tr("Failed to write temporary file.")); | |
77 return; | |
256
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
78 } |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
79 |
364 | 80 #ifdef WIN32 |
1084
b8fb6bf7f980
(issue118) Add signature check for cinst.exe and mozilla.exe
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1082
diff
changeset
|
81 bin_verify_result vres = verify_binary(cinstFileName.toUtf8().constData(), |
b8fb6bf7f980
(issue118) Add signature check for cinst.exe and mozilla.exe
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1082
diff
changeset
|
82 cinstFileName.toUtf8().size()); |
b8fb6bf7f980
(issue118) Add signature check for cinst.exe and mozilla.exe
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1082
diff
changeset
|
83 |
b8fb6bf7f980
(issue118) Add signature check for cinst.exe and mozilla.exe
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1082
diff
changeset
|
84 if (vres.result != VerifyValid) { |
b8fb6bf7f980
(issue118) Add signature check for cinst.exe and mozilla.exe
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1082
diff
changeset
|
85 emit error(tr("Integrity check of the certificate installation process failed. ") |
1104
a7a72353d6d2
(issue111) Wording and German translation.
Emanuel Schuetze <emanuel@intevation.de>
parents:
1084
diff
changeset
|
86 + "\n" + tr("Please reinstall the software.")); |
1084
b8fb6bf7f980
(issue118) Add signature check for cinst.exe and mozilla.exe
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1082
diff
changeset
|
87 return; |
b8fb6bf7f980
(issue118) Add signature check for cinst.exe and mozilla.exe
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1082
diff
changeset
|
88 } |
b8fb6bf7f980
(issue118) Add signature check for cinst.exe and mozilla.exe
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1082
diff
changeset
|
89 |
364 | 90 /* QProcess on Windows uses CreateProcess but we have to |
91 * use the runas shell command to get the UAC prompt if necessary. | |
92 * So we have to handle the process ourself. Starting with | |
93 * shell execute also means that we can not have stdout and stderr | |
94 * redirection. This is the reason we use command line parameters | |
95 * and not a pipe for communication. In debug mode the installer | |
96 * also makes use of output debug string. */ | |
97 DWORD retval = 0; | |
1159
0ddb173bcd8b
(issue36) Use 8 bit encoding for cinst process start
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1104
diff
changeset
|
98 SHELLEXECUTEINFOA shExecInfo; |
364 | 99 |
1159
0ddb173bcd8b
(issue36) Use 8 bit encoding for cinst process start
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1104
diff
changeset
|
100 memset (&shExecInfo, 0, sizeof(SHELLEXECUTEINFOA)); |
256
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
101 |
385
72487438a180
More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
364
diff
changeset
|
102 /* Windows needs each parameter packed in " */ |
72487438a180
More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
364
diff
changeset
|
103 QString parameters = "\"list=" + mCertListFile + |
72487438a180
More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
364
diff
changeset
|
104 "\" \"choices=" + choicesFile.fileName() + "\""; |
72487438a180
More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
364
diff
changeset
|
105 |
1060
317ee9dc4684
(issue46) Make debug output optional in cinst and mozilla and propagate its setting.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1003
diff
changeset
|
106 if (g_debug) { |
317ee9dc4684
(issue46) Make debug output optional in cinst and mozilla and propagate its setting.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1003
diff
changeset
|
107 parameters += " --debug"; |
317ee9dc4684
(issue46) Make debug output optional in cinst and mozilla and propagate its setting.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1003
diff
changeset
|
108 } |
317ee9dc4684
(issue46) Make debug output optional in cinst and mozilla and propagate its setting.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1003
diff
changeset
|
109 |
1159
0ddb173bcd8b
(issue36) Use 8 bit encoding for cinst process start
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1104
diff
changeset
|
110 shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOA); |
285
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
111 shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; |
1003
db7e7156c824
(issue66) Only depend on is_system_install on windows to decide privilege raise
Andre Heinecke <andre.heinecke@intevation.de>
parents:
987
diff
changeset
|
112 if (!is_system_install()) { |
1159
0ddb173bcd8b
(issue36) Use 8 bit encoding for cinst process start
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1104
diff
changeset
|
113 shExecInfo.lpVerb = "open"; |
511
cef732072774
Use open instead of runas if not admin
Andre Heinecke <aheinecke@intevation.de>
parents:
440
diff
changeset
|
114 } else { |
1159
0ddb173bcd8b
(issue36) Use 8 bit encoding for cinst process start
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1104
diff
changeset
|
115 shExecInfo.lpVerb = "runas"; |
511
cef732072774
Use open instead of runas if not admin
Andre Heinecke <aheinecke@intevation.de>
parents:
440
diff
changeset
|
116 } |
1159
0ddb173bcd8b
(issue36) Use 8 bit encoding for cinst process start
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1104
diff
changeset
|
117 shExecInfo.lpFile = strdup(cinstFileName.toLocal8Bit().constData()); |
0ddb173bcd8b
(issue36) Use 8 bit encoding for cinst process start
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1104
diff
changeset
|
118 shExecInfo.lpParameters = strdup(parameters.toUtf8().constData()); |
256
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
119 |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
120 qDebug() << "Starting process " << cinstFileName <<" params: " << parameters; |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
121 |
1159
0ddb173bcd8b
(issue36) Use 8 bit encoding for cinst process start
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1104
diff
changeset
|
122 if (!ShellExecuteExA(&shExecInfo)) { |
256
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
123 char* errmsg = getLastErrorMsg(); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
124 QString qerrmsg = QString::fromUtf8(errmsg); |
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
125 free(errmsg); |
285
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
126 emit error(tr("Error executing process: %1").arg(qerrmsg)); |
1084
b8fb6bf7f980
(issue118) Add signature check for cinst.exe and mozilla.exe
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1082
diff
changeset
|
127 fclose(vres.fptr); |
1159
0ddb173bcd8b
(issue36) Use 8 bit encoding for cinst process start
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1104
diff
changeset
|
128 free((void*)shExecInfo.lpFile); |
0ddb173bcd8b
(issue36) Use 8 bit encoding for cinst process start
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1104
diff
changeset
|
129 free((void*)shExecInfo.lpParameters); |
285
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
130 return; |
256
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
131 } |
285
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
132 |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
133 retval = WaitForSingleObject(shExecInfo.hProcess, INSTALL_TIMEOUT); |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
134 |
1159
0ddb173bcd8b
(issue36) Use 8 bit encoding for cinst process start
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1104
diff
changeset
|
135 free((void*)shExecInfo.lpFile); |
0ddb173bcd8b
(issue36) Use 8 bit encoding for cinst process start
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1104
diff
changeset
|
136 free((void*)shExecInfo.lpParameters); |
0ddb173bcd8b
(issue36) Use 8 bit encoding for cinst process start
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1104
diff
changeset
|
137 shExecInfo.lpFile = NULL; |
0ddb173bcd8b
(issue36) Use 8 bit encoding for cinst process start
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1104
diff
changeset
|
138 shExecInfo.lpParameters = NULL; |
0ddb173bcd8b
(issue36) Use 8 bit encoding for cinst process start
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1104
diff
changeset
|
139 |
285
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
140 if (retval != WAIT_OBJECT_0) { |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
141 if (retval == WAIT_FAILED) { |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
142 char* errmsg = getLastErrorMsg(); |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
143 QString qerrmsg = QString::fromUtf8(errmsg); |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
144 free(errmsg); |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
145 emit error (tr("Error monitoring process: %1").arg(qerrmsg)); |
1084
b8fb6bf7f980
(issue118) Add signature check for cinst.exe and mozilla.exe
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1082
diff
changeset
|
146 fclose(vres.fptr); |
285
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
147 return; |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
148 } else { |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
149 emit error (tr("Certificate installation timed out.")); |
1084
b8fb6bf7f980
(issue118) Add signature check for cinst.exe and mozilla.exe
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1082
diff
changeset
|
150 fclose(vres.fptr); |
285
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
151 return; |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
152 } |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
153 } |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
154 |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
155 if (GetExitCodeProcess(shExecInfo.hProcess, &retval)) { |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
156 if (retval == STILL_ACTIVE) { |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
157 qDebug() << "Process still running, huh.."; |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
158 } |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
159 } else { |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
160 char* errmsg = getLastErrorMsg(); |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
161 QString qerrmsg = QString::fromUtf8(errmsg); |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
162 free(errmsg); |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
163 emit error (tr("Failed to check process status: %1").arg(qerrmsg)); |
387
32309299bec9
Always return after error
Andre Heinecke <andre.heinecke@intevation.de>
parents:
385
diff
changeset
|
164 CloseHandle(shExecInfo.hProcess); |
1084
b8fb6bf7f980
(issue118) Add signature check for cinst.exe and mozilla.exe
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1082
diff
changeset
|
165 fclose(vres.fptr); |
387
32309299bec9
Always return after error
Andre Heinecke <andre.heinecke@intevation.de>
parents:
385
diff
changeset
|
166 return; |
285
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
167 } |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
168 CloseHandle(shExecInfo.hProcess); |
1084
b8fb6bf7f980
(issue118) Add signature check for cinst.exe and mozilla.exe
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1082
diff
changeset
|
169 fclose(vres.fptr); |
285
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
170 |
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
171 if (retval != 0) { |
1162
2a1206932f53
(issue107) Comment all TODO's and FIXME's with issues as documented in issue107
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1159
diff
changeset
|
172 /* TODO (issue135) make this nicer */ |
285
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
173 emit error (tr("The process failed with return code. %1").arg(retval)); |
388
a507e5f1b999
Emit a signal if no errors happened during installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
387
diff
changeset
|
174 return; |
285
f23e0ccd5d14
Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents:
256
diff
changeset
|
175 } |
364 | 176 #else /* WIN32 */ |
177 QProcess installerProcess; | |
385
72487438a180
More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
364
diff
changeset
|
178 QStringList parameters; |
72487438a180
More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
364
diff
changeset
|
179 |
72487438a180
More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
364
diff
changeset
|
180 choicesFile.setAutoRemove(false); |
72487438a180
More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
364
diff
changeset
|
181 parameters << "list=" + mCertListFile << "choices=" + choicesFile.fileName(); |
72487438a180
More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
364
diff
changeset
|
182 |
1060
317ee9dc4684
(issue46) Make debug output optional in cinst and mozilla and propagate its setting.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1003
diff
changeset
|
183 if (g_debug) { |
317ee9dc4684
(issue46) Make debug output optional in cinst and mozilla and propagate its setting.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1003
diff
changeset
|
184 parameters << "--debug"; |
317ee9dc4684
(issue46) Make debug output optional in cinst and mozilla and propagate its setting.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1003
diff
changeset
|
185 } |
317ee9dc4684
(issue46) Make debug output optional in cinst and mozilla and propagate its setting.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1003
diff
changeset
|
186 |
646
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
187 bool sudo_started = false; |
841
216a65d7fc4b
(issue66) Implement is_system_install and use it
Andre Heinecke <andre.heinecke@intevation.de>
parents:
647
diff
changeset
|
188 bool use_sudo = is_admin() && is_system_install(); |
646
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
189 if (use_sudo) { |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
190 QStringList sudoPrograms; |
987
b8ae69bcc540
Use pkexec instead of gksudo.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
841
diff
changeset
|
191 sudoPrograms << "pkexec" << "kdesudo" << "sudo"; |
646
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
192 QStringList sudoParams; |
647
51830f4912c2
Minor style fix
Andre Heinecke <andre.heinecke@intevation.de>
parents:
646
diff
changeset
|
193 sudoParams << cinstProcInfo.absoluteFilePath() << parameters; |
646
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
194 installerProcess.setArguments(sudoParams); |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
195 |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
196 foreach (const QString &sProg, sudoPrograms) { |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
197 installerProcess.setProgram(sProg); |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
198 qDebug() << "Starting process " << sProg <<" params: " << sudoParams; |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
199 installerProcess.start(); |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
200 if (!installerProcess.waitForStarted() || |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
201 installerProcess.state() == QProcess::NotRunning) { |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
202 continue; |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
203 } else { |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
204 sudo_started = true; |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
205 break; |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
206 } |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
207 } |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
208 } |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
209 |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
210 /* Fallback to start without sudo */ |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
211 if (!use_sudo || !sudo_started) { |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
212 installerProcess.setProgram(cinstProcInfo.absoluteFilePath()); |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
213 installerProcess.setArguments(parameters); |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
214 |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
215 qDebug() << "Starting process " << cinstFileName <<" params: " << parameters; |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
216 installerProcess.start(); |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
217 if (!installerProcess.waitForStarted() || |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
218 installerProcess.state() == QProcess::NotRunning) { |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
219 emit error (tr("Failed to start installer process.")); |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
220 return; |
a9a57dc1eb2f
Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
511
diff
changeset
|
221 } |
364 | 222 } |
223 | |
224 installerProcess.waitForFinished(); | |
225 | |
226 if (installerProcess.exitStatus() == QProcess::CrashExit) { | |
227 /* Woops */ | |
385
72487438a180
More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
364
diff
changeset
|
228 emit error (tr("Failed to complete installation.")); |
72487438a180
More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
364
diff
changeset
|
229 return; |
364 | 230 } else if (installerProcess.exitStatus() != QProcess::NormalExit) { |
231 /* Can not Happen. there are only those two values but maybe | |
232 * qt changed.. */ | |
385
72487438a180
More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
364
diff
changeset
|
233 emit error (tr("Failed to complete installation.")); |
364 | 234 return; |
235 } | |
236 | |
237 if (installerProcess.exitCode() == 0) { | |
238 qDebug() << "output: " << installerProcess.readAllStandardOutput(); | |
239 } else { | |
1162
2a1206932f53
(issue107) Comment all TODO's and FIXME's with issues as documented in issue107
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1159
diff
changeset
|
240 /* TODO (issue135) handle errors defined by errorcodes.h */ |
364 | 241 qDebug() << "Installer Process returned: " << installerProcess.exitCode(); |
242 qDebug() << "output: " << installerProcess.readAllStandardOutput(); | |
243 return; | |
244 } | |
245 #endif | |
388
a507e5f1b999
Emit a signal if no errors happened during installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
387
diff
changeset
|
246 emit installationSuccessful(); |
256
84ae353688e0
Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
247 } |