annotate ui/installwrapper.cpp @ 1082:a12e6172d82c

Extend logging to all choices and SW updates.
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 11 Sep 2014 12:05:59 +0200
parents 317ee9dc4684
children b8fb6bf7f980
rev   line source
404
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 388
diff changeset
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 388
diff changeset
2 * Software engineering by Intevation GmbH
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 388
diff changeset
3 *
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 388
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 388
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 388
diff changeset
6 * See LICENSE.txt for details.
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 388
diff changeset
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
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
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"
256
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
19
285
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
20 #define INSTALL_TIMEOUT 3600000 /* Wait up to an hour */
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
21
256
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
22 InstallWrapper::InstallWrapper(QObject* parent,
364
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
23 const QString& path, const QStringList& choices):
256
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
24 QThread(parent),
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
25 mCertListFile(path),
364
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
26 mChoices(choices)
256
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
27 {
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 QFileInfo getCinstProcInfo() {
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
31 QFileInfo fi(QCoreApplication::applicationFilePath());
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
32 QDir myDir = fi.absoluteDir();
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
33 QString instProcName = "cinst";
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
34 if (!fi.suffix().isEmpty()) {
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
35 instProcName += "." + fi.suffix();
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
36 }
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37 return QFileInfo(myDir.absoluteFilePath(instProcName));
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38 }
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39
364
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
40 bool InstallWrapper::writeChoices(QTemporaryFile* choicesFile) const
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
41 {
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
42 if (!choicesFile->open()) {
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
43 return false;
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
44 }
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
45
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
46 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
47 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
48 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
49 return false;
a12e6172d82c Extend logging to all choices and SW updates.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1060
diff changeset
50 }
a12e6172d82c Extend logging to all choices and SW updates.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1060
diff changeset
51 if (choicesFile->write("\n") == -1) {
a12e6172d82c Extend logging to all choices and SW updates.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1060
diff changeset
52 return false;
a12e6172d82c Extend logging to all choices and SW updates.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1060
diff changeset
53 }
364
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
54 }
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
55
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
56 choicesFile->close();
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
57
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
58 return true;
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
59 }
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
60
256
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
61 void InstallWrapper::run()
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
62 {
285
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
63 /* TODO: We need errorcodes here so that we can see if a user
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
64 * cancled the UAC elevation */
364
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
65 QTemporaryFile choicesFile;
256
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
66 QFileInfo cinstProcInfo = getCinstProcInfo();
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
67
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
68 QString cinstFileName = QDir::toNativeSeparators(
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
69 getCinstProcInfo().absoluteFilePath());
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
70
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
71 if (!cinstProcInfo.isExecutable()) {
285
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
72 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
73 return;
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
74 }
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
75
364
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
76 if (!writeChoices(&choicesFile)) {
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
77 emit error(tr("Failed to write temporary file."));
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
78 return;
256
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
79 }
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
80
364
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
81 #ifdef WIN32
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
82 /* QProcess on Windows uses CreateProcess but we have to
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
83 * use the runas shell command to get the UAC prompt if necessary.
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
84 * So we have to handle the process ourself. Starting with
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
85 * shell execute also means that we can not have stdout and stderr
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
86 * redirection. This is the reason we use command line parameters
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
87 * and not a pipe for communication. In debug mode the installer
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
88 * also makes use of output debug string. */
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
89 DWORD retval = 0;
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
90 SHELLEXECUTEINFOW shExecInfo;
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
91
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
92 memset (&shExecInfo, 0, sizeof(SHELLEXECUTEINFOW));
256
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
93
385
72487438a180 More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 364
diff changeset
94 /* 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
95 QString parameters = "\"list=" + mCertListFile +
72487438a180 More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 364
diff changeset
96 "\" \"choices=" + choicesFile.fileName() + "\"";
72487438a180 More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 364
diff changeset
97
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
98 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
99 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
100 }
317ee9dc4684 (issue46) Make debug output optional in cinst and mozilla and propagate its setting.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1003
diff changeset
101
285
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
102 shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW);
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
103 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
104 if (!is_system_install()) {
511
cef732072774 Use open instead of runas if not admin
Andre Heinecke <aheinecke@intevation.de>
parents: 440
diff changeset
105 shExecInfo.lpVerb = L"open";
cef732072774 Use open instead of runas if not admin
Andre Heinecke <aheinecke@intevation.de>
parents: 440
diff changeset
106 } else {
cef732072774 Use open instead of runas if not admin
Andre Heinecke <aheinecke@intevation.de>
parents: 440
diff changeset
107 shExecInfo.lpVerb = L"runas";
cef732072774 Use open instead of runas if not admin
Andre Heinecke <aheinecke@intevation.de>
parents: 440
diff changeset
108 }
285
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
109 shExecInfo.lpFile = reinterpret_cast<LPCWSTR> (cinstFileName.utf16());
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
110 shExecInfo.lpParameters = reinterpret_cast<LPCWSTR> (parameters.utf16());
256
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
111
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
112 qDebug() << "Starting process " << cinstFileName <<" params: " << parameters;
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
113
285
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
114 if (!ShellExecuteExW(&shExecInfo)) {
256
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
115 char* errmsg = getLastErrorMsg();
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
116 QString qerrmsg = QString::fromUtf8(errmsg);
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
117 free(errmsg);
285
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
118 emit error(tr("Error executing process: %1").arg(qerrmsg));
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
119 return;
256
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
120 }
285
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
121
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
122 retval = WaitForSingleObject(shExecInfo.hProcess, INSTALL_TIMEOUT);
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
123
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
124 if (retval != WAIT_OBJECT_0) {
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
125 if (retval == WAIT_FAILED) {
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
126 char* errmsg = getLastErrorMsg();
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
127 QString qerrmsg = QString::fromUtf8(errmsg);
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
128 free(errmsg);
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
129 emit error (tr("Error monitoring process: %1").arg(qerrmsg));
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
130 return;
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
131 } else {
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
132 emit error (tr("Certificate installation timed out."));
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
133 return;
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
134 }
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
135 }
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
136
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
137 if (GetExitCodeProcess(shExecInfo.hProcess, &retval)) {
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
138 if (retval == STILL_ACTIVE) {
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
139 qDebug() << "Process still running, huh..";
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
140 }
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
141 } else {
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("Failed to check process status: %1").arg(qerrmsg));
387
32309299bec9 Always return after error
Andre Heinecke <andre.heinecke@intevation.de>
parents: 385
diff changeset
146 CloseHandle(shExecInfo.hProcess);
32309299bec9 Always return after error
Andre Heinecke <andre.heinecke@intevation.de>
parents: 385
diff changeset
147 return;
285
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
148 }
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
149 CloseHandle(shExecInfo.hProcess);
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
150
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
151 if (retval != 0) {
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
152 /* TODO make this nicer */
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
153 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
154 return;
285
f23e0ccd5d14 Fix call to windows process.
Andre Heinecke <aheinecke@intevation.de>
parents: 256
diff changeset
155 }
364
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
156 #else /* WIN32 */
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
157 QProcess installerProcess;
385
72487438a180 More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 364
diff changeset
158 QStringList parameters;
72487438a180 More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 364
diff changeset
159
72487438a180 More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 364
diff changeset
160 choicesFile.setAutoRemove(false);
72487438a180 More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 364
diff changeset
161 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
162
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
163 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
164 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
165 }
317ee9dc4684 (issue46) Make debug output optional in cinst and mozilla and propagate its setting.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1003
diff changeset
166
646
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
167 bool sudo_started = false;
841
216a65d7fc4b (issue66) Implement is_system_install and use it
Andre Heinecke <andre.heinecke@intevation.de>
parents: 647
diff changeset
168 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
169 if (use_sudo) {
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
170 QStringList sudoPrograms;
987
b8ae69bcc540 Use pkexec instead of gksudo.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 841
diff changeset
171 sudoPrograms << "pkexec" << "kdesudo" << "sudo";
646
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
172 QStringList sudoParams;
647
51830f4912c2 Minor style fix
Andre Heinecke <andre.heinecke@intevation.de>
parents: 646
diff changeset
173 sudoParams << cinstProcInfo.absoluteFilePath() << parameters;
646
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
174 installerProcess.setArguments(sudoParams);
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
175
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
176 foreach (const QString &sProg, sudoPrograms) {
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
177 installerProcess.setProgram(sProg);
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
178 qDebug() << "Starting process " << sProg <<" params: " << sudoParams;
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
179 installerProcess.start();
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
180 if (!installerProcess.waitForStarted() ||
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
181 installerProcess.state() == QProcess::NotRunning) {
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
182 continue;
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
183 } else {
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
184 sudo_started = true;
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
185 break;
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
186 }
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
187 }
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
188 }
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
189
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
190 /* Fallback to start without sudo */
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
191 if (!use_sudo || !sudo_started) {
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
192 installerProcess.setProgram(cinstProcInfo.absoluteFilePath());
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
193 installerProcess.setArguments(parameters);
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
194
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
195 qDebug() << "Starting process " << cinstFileName <<" params: " << parameters;
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
196 installerProcess.start();
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
197 if (!installerProcess.waitForStarted() ||
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
198 installerProcess.state() == QProcess::NotRunning) {
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
199 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
200 return;
a9a57dc1eb2f Start installer process as sudo if possible.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 511
diff changeset
201 }
364
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
202 }
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
203
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
204 installerProcess.waitForFinished();
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
205
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
206 if (installerProcess.exitStatus() == QProcess::CrashExit) {
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
207 /* Woops */
385
72487438a180 More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 364
diff changeset
208 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
209 return;
364
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
210 } else if (installerProcess.exitStatus() != QProcess::NormalExit) {
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
211 /* Can not Happen. there are only those two values but maybe
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
212 * qt changed.. */
385
72487438a180 More user visible errors. Correct parameters for installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 364
diff changeset
213 emit error (tr("Failed to complete installation."));
364
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
214 return;
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
215 }
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
216
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
217 if (installerProcess.exitCode() == 0) {
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
218 qDebug() << "output: " << installerProcess.readAllStandardOutput();
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
219 } else {
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
220 /* TODO handle errors defined by errorcodes.h */
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
221 qDebug() << "Installer Process returned: " << installerProcess.exitCode();
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
222 qDebug() << "output: " << installerProcess.readAllStandardOutput();
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
223 return;
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
224 }
dc4efb0a70cb Add Linux support
Andre Heinecke <aheinecke@intevation.de>
parents: 285
diff changeset
225 #endif
388
a507e5f1b999 Emit a signal if no errors happened during installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 387
diff changeset
226 emit installationSuccessful();
256
84ae353688e0 Add installwrapper class to handle process communication
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
227 }

http://wald.intevation.org/projects/trustbridge/