comparison ui/main.cpp @ 631:edf269b6e499

Add self test as first opertation on start
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 23 Jun 2014 13:05:08 +0200
parents 2ea11a95aa4a
children 6c090638b2b4
comparison
equal deleted inserted replaced
630:aa48ea7ead1f 631:edf269b6e499
5 * and comes with ABSOLUTELY NO WARRANTY! 5 * and comes with ABSOLUTELY NO WARRANTY!
6 * See LICENSE.txt for details. 6 * See LICENSE.txt for details.
7 */ 7 */
8 #include "mainwindow.h" 8 #include "mainwindow.h"
9 #include "processhelp.h" 9 #include "processhelp.h"
10 #include "binverify.h"
11 #include "logging.h"
12 #include "strhelp.h"
10 13
11 #include <QApplication> 14 #include <QApplication>
12 #include <QSystemTrayIcon> 15 #include <QSystemTrayIcon>
13 #include <QtPlugin> 16 #include <QtPlugin>
14 #include <QMessageBox> 17 #include <QMessageBox>
34 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin) 37 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
35 #endif 38 #endif
36 39
37 int main(int argc, char **argv) 40 int main(int argc, char **argv)
38 { 41 {
42 /* First verify integrity even before calling QApplication*/
43 #ifdef Q_OS_WIN
44 DWORD sizeNeeded = GetModuleFileNameW (NULL, NULL, 0);
45 wchar_t wPath[sizeNeeded + 1];
46 char *utf8path = NULL;
47
48 if (sizeNeeded == 0) {
49 PRINTLASTERROR ("Failed to obtain module file name");
50 syslog_error_printf ("Integrity check failed.");
51 return -1;
52 }
53
54 DWORD realSize = GetModuleFileNameW (NULL, wPath, sizeNeeded + 1);
55
56 if (realSize != sizeNeeded) {
57 ERRORPRINTF ("Module name changed");
58 syslog_error_printf ("Integrity check failed.");
59 return -1;
60 }
61
62 utf8path = wchar_to_utf8 (wPath, sizeNeeded + 1);
63
64 if (utf8path == NULL) {
65 ERRORPRINTF ("Failed to convert module path to utf-8");
66 syslog_error_printf ("Integrity check failed.");
67 return -1;
68 }
69
70 if (!verify_binary (utf8path, strlen(utf8path)) != VerifyValid)
71 {
72 syslog_error_printf ("Integrity check failed.");
73 xfree(utf8path);
74 #ifdef RELEASE_BUILD
75 return -1;
76 #endif
77 }
78
79 xfree(utf8path);
80 #else
81 if (!verify_binary ("/proc/self/exe", 14) != VerifyValid)
82 {
83 syslog_error_printf ("Integrity check failed.");
84 #ifdef RELEASE_BUILD
85 return -1;
86 #endif
87 }
88 #endif
89
39 QApplication app (argc, argv); 90 QApplication app (argc, argv);
40 91
41 QApplication::setQuitOnLastWindowClosed(false); 92 QApplication::setQuitOnLastWindowClosed(false);
42 QApplication::setOrganizationName(QString::fromLatin1(ORGANIZATION)); 93 QApplication::setOrganizationName(QString::fromLatin1(ORGANIZATION));
43 QApplication::setApplicationName(QString::fromLatin1(APPNAME)); 94 QApplication::setApplicationName(QString::fromLatin1(APPNAME));

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