comparison common/selftest.c @ 1081:edbf5e5e88f4

(issue118) Extend verify_binary to carry an open file * binverify.c: Change result to a structure containing an open fptr Use in Memory data for windows verification. * mainwindow.cpp, selftest.c: Handle the returend structure * binverifytest.cpp: Test for the exclusive read and update signature. * listutil.c: Add optional fptr parameter to read_file
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 11 Sep 2014 12:05:24 +0200
parents fa3f4e2370d3
children a974b61a5cce
comparison
equal deleted inserted replaced
1080:898b1ddcca11 1081:edbf5e5e88f4
4 #include "logging.h" 4 #include "logging.h"
5 5
6 bool 6 bool
7 selftest() 7 selftest()
8 { 8 {
9 bin_verify_result res;
9 #ifdef WIN32 10 #ifdef WIN32
10 wchar_t wPath[MAX_PATH]; 11 wchar_t wPath[MAX_PATH];
11 char *utf8path = NULL; 12 char *utf8path = NULL;
12 13
13 if (!GetModuleFileNameW (NULL, wPath, MAX_PATH - 1)) 14 if (!GetModuleFileNameW (NULL, wPath, MAX_PATH - 1))
25 { 26 {
26 ERRORPRINTF ("Failed to convert module path to utf-8"); 27 ERRORPRINTF ("Failed to convert module path to utf-8");
27 return false; 28 return false;
28 } 29 }
29 30
30 if (verify_binary (utf8path, strlen(utf8path)) != VerifyValid) 31 res = verify_binary (utf8path, strlen(utf8path));
32 if (res.result != VerifyValid)
31 { 33 {
32 ERRORPRINTF ("Verification of the binary failed"); 34 ERRORPRINTF ("Verification of the binary failed");
33 syslog_error_printf ("Integrity check failed."); 35 syslog_error_printf ("Integrity check failed.");
34 xfree(utf8path); 36 xfree(utf8path);
35 return false; 37 return false;
36 } 38 }
37 39
40 fclose(res.fptr);
38 xfree(utf8path); 41 xfree(utf8path);
39 return true; 42 return true;
40 #else 43 #else
41 if (!verify_binary ("/proc/self/exe", 14) != VerifyValid) 44 res = verify_binary ("/proc/self/exe", 14);
45 if (res.result != VerifyValid)
42 { 46 {
43 syslog_error_printf ("Integrity check failed."); 47 syslog_error_printf ("Integrity check failed.");
44 return false; 48 return false;
45 } 49 }
50 fclose(res.fptr);
51 return true;
46 #endif 52 #endif
47 } 53 }

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