andre@634: #include "selftest.h" andre@634: #include "binverify.h" andre@634: #include "strhelp.h" andre@634: #include "logging.h" andre@634: andre@634: bool andre@634: selftest() andre@634: { andre@1081: bin_verify_result res; andre@634: #ifdef WIN32 andre@634: wchar_t wPath[MAX_PATH]; andre@634: char *utf8path = NULL; andre@634: andre@904: if (!GetModuleFileNameW (NULL, wPath, MAX_PATH - 1)) andre@634: { andre@634: PRINTLASTERROR ("Failed to obtain module file name. Path too long?"); andre@634: return false; andre@634: } andre@634: andre@634: /* wPath might not be 0 terminated */ andre@634: wPath[MAX_PATH - 1] = '\0'; andre@634: andre@634: utf8path = wchar_to_utf8 (wPath, wcsnlen(wPath, MAX_PATH)); andre@634: andre@634: if (utf8path == NULL) andre@634: { andre@634: ERRORPRINTF ("Failed to convert module path to utf-8"); andre@634: return false; andre@634: } andre@634: andre@1081: res = verify_binary (utf8path, strlen(utf8path)); andre@1081: if (res.result != VerifyValid) andre@634: { andre@634: ERRORPRINTF ("Verification of the binary failed"); andre@634: syslog_error_printf ("Integrity check failed."); andre@634: xfree(utf8path); andre@634: return false; andre@634: } andre@634: andre@1081: fclose(res.fptr); andre@634: xfree(utf8path); andre@1073: return true; andre@634: #else andre@1081: res = verify_binary ("/proc/self/exe", 14); andre@1081: if (res.result != VerifyValid) andre@634: { andre@634: syslog_error_printf ("Integrity check failed."); andre@634: return false; andre@634: } andre@1081: fclose(res.fptr); andre@1081: return true; andre@634: #endif andre@634: }