Mercurial > trustbridge
comparison common/selftest.c @ 634:80d1a80b3e8d
Factor out selftest for better test and reviewability
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 23 Jun 2014 16:43:07 +0200 |
parents | |
children | f89b41fa7048 |
comparison
equal
deleted
inserted
replaced
633:6c090638b2b4 | 634:80d1a80b3e8d |
---|---|
1 #include "selftest.h" | |
2 #include "binverify.h" | |
3 #include "strhelp.h" | |
4 #include "logging.h" | |
5 | |
6 bool | |
7 selftest() | |
8 { | |
9 #ifdef WIN32 | |
10 wchar_t wPath[MAX_PATH]; | |
11 char *utf8path = NULL; | |
12 | |
13 if (!GetModuleFileNameW (NULL, wPath, MAX_PATH - 1)) | |
14 { | |
15 PRINTLASTERROR ("Failed to obtain module file name. Path too long?"); | |
16 return false; | |
17 } | |
18 | |
19 /* wPath might not be 0 terminated */ | |
20 wPath[MAX_PATH - 1] = '\0'; | |
21 | |
22 utf8path = wchar_to_utf8 (wPath, wcsnlen(wPath, MAX_PATH)); | |
23 | |
24 if (utf8path == NULL) | |
25 { | |
26 ERRORPRINTF ("Failed to convert module path to utf-8"); | |
27 return false; | |
28 } | |
29 | |
30 if (!verify_binary (utf8path, strlen(utf8path)) != VerifyValid) | |
31 { | |
32 ERRORPRINTF ("Verification of the binary failed"); | |
33 syslog_error_printf ("Integrity check failed."); | |
34 xfree(utf8path); | |
35 return false; | |
36 } | |
37 | |
38 xfree(utf8path); | |
39 #else | |
40 if (!verify_binary ("/proc/self/exe", 14) != VerifyValid) | |
41 { | |
42 syslog_error_printf ("Integrity check failed."); | |
43 return false; | |
44 } | |
45 #endif | |
46 } |