| | |
| | | endif(CMAKE_BUILD_TYPE) |
| | | |
| | | if(WIN32) |
| | | |
| | | SET(PLATFORM_LIBS "") |
| | | if(CMAKE_CL_64) |
| | | SET(CMAKE_EXE_LINKER_FLAGS "/machine:X64 /INCREMENTAL:NO" CACHE STRING "Linker flags") |
| | | endif(CMAKE_CL_64) |
| | | include(target_arch) |
| | | target_architecture( TARGET_ARCHITECTURE ) |
| | | message(STATUS "architecture detected: ${TARGET_ARCHITECTURE}") |
| | | #force to patch an error in cmake |
| | | if(TARGET_ARCHITECTURE STREQUAL "x86_64") |
| | | SET(CMAKE_EXE_LINKER_FLAGS "/machine:X64" CACHE STRING "Linker flags" FORCE) |
| | | SET(CMAKE_MODULE_LINKER_FLAGS "/machine:X64" CACHE STRING "Module Linker flags" FORCE) |
| | | SET(CMAKE_SHARED_LINKER_FLAGS "/machine:X64" CACHE STRING "Shared Linker flags" FORCE) |
| | | endif() |
| | | SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib ) #${CMAKE_FIND_LIBRARY_SUFFIXES} |
| | | add_definitions("/D_CRT_SECURE_NO_WARNINGS") |
| | | else(WIN32) |
| | |
| | | endif()
|
| | | execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${BOOST_ROOT}/Build)
|
| | |
|
| | | |
| | | #ADD_BOOST_STATIC_RUNTIME is a parsed function parameter
|
| | | if(ADD_BOOST_STATIC_RUNTIME)
|
| | | set(RUNTIME_LINK "static")
|
| | |
| | | else(MSVC)
|
| | | set(OUTPUT_FILE ${BOOST_ROOT}/stage/lib/libboost_${libName}-mt${BOOST_LIB_SUFFIX}.${LINUX_LIB_EXTENSION})
|
| | | endif(MSVC)
|
| | | if(NOT EXISTS "${OUTPUT_FILE}")
|
| | | message(STATUS "Building ${Component}")
|
| | | execute_process(COMMAND ${b2Args} --with-${Component} WORKING_DIRECTORY ${BOOST_ROOT})
|
| | | endif()
|
| | | #if(NOT EXISTS "${OUTPUT_FILE}")
|
| | | message(STATUS "Building ${Component}: ${b2Args}")
|
| | | execute_process(COMMAND ${b2Args} --with-${Component} WORKING_DIRECTORY ${BOOST_ROOT} RESULT_VARIABLE Result OUTPUT_VARIABLE Output ERROR_VARIABLE Error)
|
| | | if(NOT Result EQUAL 0)
|
| | | message(ERROR "Failed running ${b2Args} --with-${Component}:\n${Output}\n${Error}\n")
|
| | | endif()
|
| | | #endif()
|
| | | endforeach()
|
| | |
|
| | |
|
| | |
| | | extern "C" { |
| | | #endif |
| | | |
| | | #include <stdbool.h> |
| | | |
| | | //definition of size_t |
| | | #include <stdlib.h> |
| | | #ifdef __unix__ |
| | | #include <stdbool.h> |
| | | #define DllExport |
| | | #else |
| | | #include <windows.h> |
| | |
| | | |
| | | typedef struct { |
| | | const char *licenseFileLocation; |
| | | const char *environmentVariableName;bool openFileNearModule; |
| | | const char *environmentVariableName; |
| | | bool openFileNearModule; |
| | | } LicenseLocation; |
| | | |
| | | typedef struct { |
| | |
| | | #endif |
| | | |
| | | #ifdef __unix__ |
| | | |
| | | #include <limits.h> |
| | | #define DllExport |
| | | #ifndef MAX_PATH |
| | |
| | | #else //windows |
| | | #include <windows.h> |
| | | #define DllExport __declspec( dllexport ) |
| | | |
| | | #ifndef __cplusplus |
| | | typedef int bool; |
| | | #define false 0 |
| | | #define true -1 |
| | | #endif |
| | | |
| | | #endif |
| | | /* #define _DEBUG */ |
| | | /* |
| | | #define cmax(a,b) \ |
| | |
| | | #include <string.h> |
| | | #include <stdarg.h> |
| | | #include <time.h> |
| | | #include <unistd.h> |
| | | |
| | | #ifdef __unix__ |
| | | #include <unistd.h> |
| | | #define MAX_PATH 255 |
| | | #else |
| | | #include <windows.h> |
| | |
| | | #define logger_INCLUDED |
| | | |
| | | #ifndef LOG_ENABLED |
| | | #include <errno.h> |
| | | #define clean_errno() (errno == 0 ? "None" : strerror(errno)) |
| | | |
| | | #ifdef NDEBUG |
| | | #define LOG_DEBUG(M, ...) _log("[INFO] %s (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__) |
| | | #else |
| | |
| | | |
| | | #include "../base/base.h" |
| | | #include <stddef.h> |
| | | //definition of size_t |
| | | #include <stdlib.h> |
| | | #ifdef __unix__ |
| | | #include <stdbool.h> |
| | | #endif |
| | | |
| | | typedef enum { |
| | | NONE, VMWARE |
| | | } VIRTUALIZATION; |
| | | |
| | | typedef enum { |
| | | ETHERNET, WIRELESS |
| | | IFACE_TYPE_ETHERNET, IFACE_TYPE_WIRELESS |
| | | } IFACE_TYPE; |
| | | |
| | | typedef struct { |
| | |
| | | #include <Windows.h>
|
| | | #include <iphlpapi.h>
|
| | | //definition of size_t |
| | | #include <stdlib.h>
|
| | | #include "../../base/logger.h"
|
| | | #include"../os.h"
|
| | | #pragma comment(lib, "IPHLPAPI.lib")
|
| | |
|
| | | FUNCTION_RETURN getOsSpecificIdentifier(unsigned char identifier[6]){
|
| | |
|
| | | return FUNC_RET_NOT_AVAIL;
|
| | | }
|
| | |
|
| | | FUNCTION_RETURN getMachineName(unsigned char identifier[6]) {
|
| | | FUNCTION_RETURN result = FUNC_RET_ERROR;
|
| | | char buffer[MAX_COMPUTERNAME_LENGTH + 1];
|
| | | int bufsize = MAX_COMPUTERNAME_LENGTH + 1;
|
| | | BOOL cmpName = GetComputerName(
|
| | | buffer, &bufsize);
|
| | | strncpy(identifier, buffer, 6);
|
| | | if (cmpName){
|
| | | strncpy(identifier, buffer, 6);
|
| | | result = FUNC_RET_OK;
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
|
| | | FUNCTION_RETURN getCpuId(unsigned char identifier[6]) {
|
| | | return FUNC_RET_NOT_AVAIL;
|
| | | }
|
| | |
|
| | | void os_initialize() {
|
| | |
| | | int ndrives = 0;
|
| | | DWORD FileFlags;
|
| | | char volName[_MAX_FNAME], FileSysName[_MAX_FNAME];
|
| | | char* szSingleDrive;
|
| | | DWORD volSerial = 0;
|
| | | BOOL success;
|
| | | UINT driveType;
|
| | |
| | | if (dwResult > 0 && dwResult <= MAX_PATH)
|
| | | {
|
| | | return_value = FUNC_RET_OK;
|
| | | char* szSingleDrive = szLogicalDrives;
|
| | | szSingleDrive = szLogicalDrives;
|
| | | while (*szSingleDrive && ndrives < MAX_UNITS)
|
| | | {
|
| | |
|
| | |
| | | LOG_INFO("Volume Serial : 0x%x\n", volSerial);
|
| | | LOG_DEBUG("Max file length : %d\n", FileMaxLen);
|
| | | LOG_DEBUG("Filesystem : %s\n", FileSysName);
|
| | | if (diskInfos != NULL && * disk_info_size<ndrives){
|
| | | strncpy(diskInfos[ndrives].device,volName,MAX_PATH);
|
| | | strncpy(diskInfos[ndrives].label, FileSysName , MAX_PATH);
|
| | | diskInfos[ndrives].id=ndrives;
|
| | | diskInfos[ndrives].preferred = (strncmp(szSingleDrive,"C",1)!=0);
|
| | | if (diskInfos != NULL && * disk_info_size < ndrives){
|
| | | strncpy(diskInfos[ndrives].device, volName, MAX_PATH);
|
| | | strncpy(diskInfos[ndrives].label, FileSysName, MAX_PATH);
|
| | | diskInfos[ndrives].id = ndrives;
|
| | | diskInfos[ndrives].preferred = (strncmp(szSingleDrive, "C", 1) != 0);
|
| | |
|
| | | }
|
| | | ndrives++;
|
| | |
| | | return FUNC_RET_BUFFER_TOO_SMALL;
|
| | | }
|
| | |
|
| | | memset(adapterInfos, 0,*adapter_info_size);
|
| | | memset(adapterInfos, 0, *adapter_info_size);
|
| | | pAdapter = pAdapterInfo;
|
| | | i = 0;
|
| | | result = FUNC_RET_OK;
|
| | |
| | | strncpy(adapterInfos[i].description, pAdapter->Description, min(sizeof(adapterInfos->description), MAX_ADAPTER_DESCRIPTION_LENGTH));
|
| | | memcpy(adapterInfos[i].mac_address, pAdapter->Address, 8);
|
| | | translate(pAdapter->IpAddressList.IpAddress.String, adapterInfos[i].ipv4_address);
|
| | | adapterInfos[i].type = IFACE_TYPE_ETHERNET;
|
| | | i++;
|
| | | pAdapter = pAdapter->Next;
|
| | | if (i == *adapter_info_size){
|
| | |
| | | #include "pc-identifiers.h" |
| | | #include <stdlib.h> |
| | | #include <string.h> |
| | | #include <stdbool.h> |
| | | #include "base/base64.h" |
| | | #include "base/base.h" |
| | | #ifdef __linux__ |
| | | #include <stdbool.h> |
| | | #include <valgrind/memcheck.h> |
| | | #else |
| | | #include <Windows.h> |
| | | #endif |
| | | |
| | | static FUNCTION_RETURN generate_default_pc_id(PcIdentifier * identifiers, |
| | | unsigned int * num_identifiers) { |
| | | size_t adapter_num, disk_num; |
| | | FUNCTION_RETURN result_adapterInfos, result_diskinfos; |
| | | unsigned int required_id_size, i, j, k; |
| | | unsigned int required_id_size, defined_identifiers, i, j, k; |
| | | DiskInfo * diskInfos; |
| | | OsAdapterInfo *adapterInfos; |
| | | |
| | |
| | | } else { |
| | | required_id_size = disk_num; |
| | | } |
| | | int defined_identifiers = *num_identifiers; |
| | | defined_identifiers = *num_identifiers; |
| | | *num_identifiers = required_id_size; |
| | | if (identifiers == NULL) { |
| | | return FUNC_RET_OK; |
| | |
| | | } |
| | | |
| | | static FUNCTION_RETURN generate_ethernet_pc_id(PcIdentifier * identifiers, |
| | | unsigned int * num_identifiers, bool use_mac) { |
| | | unsigned int * num_identifiers, int use_mac) { |
| | | size_t adapters; |
| | | int defined_adapters; |
| | | FUNCTION_RETURN result_adapterInfos; |
| | | unsigned int i, j, k; |
| | | OsAdapterInfo *adapterInfos; |
| | |
| | | return result_adapterInfos; |
| | | } |
| | | |
| | | int defined_adapters = *num_identifiers; |
| | | defined_adapters = *num_identifiers; |
| | | *num_identifiers = adapters; |
| | | if (identifiers == NULL) { |
| | | return FUNC_RET_OK; |
| | |
| | | size_t disk_num, available_disk_info=0; |
| | | FUNCTION_RETURN result_diskinfos; |
| | | unsigned int i, k, j; |
| | | int defined_identifiers; |
| | | char firstChar; |
| | | DiskInfo * diskInfos; |
| | | |
| | |
| | | available_disk_info += firstChar == 0 ? 0 : 1; |
| | | } |
| | | |
| | | int defined_identifiers = *num_identifiers; |
| | | defined_identifiers = *num_identifiers; |
| | | *num_identifiers = available_disk_info; |
| | | if (identifiers == NULL) { |
| | | free(diskInfos); |
| | |
| | | * @param |
| | | * @return |
| | | */ |
| | | |
| | | FUNCTION_RETURN generate_pc_id(PcIdentifier * identifiers, |
| | | unsigned int * array_size, IDENTIFICATION_STRATEGY strategy) { |
| | | FUNCTION_RETURN result; |
| | |
| | | result = generate_default_pc_id(identifiers, array_size); |
| | | break; |
| | | case ETHERNET: |
| | | result = generate_ethernet_pc_id(identifiers, array_size, true); |
| | | result = generate_ethernet_pc_id(identifiers, array_size, true ); |
| | | break; |
| | | case IP_ADDRESS: |
| | | result = generate_ethernet_pc_id(identifiers, array_size, false); |
| | | result = generate_ethernet_pc_id(identifiers, array_size, false ); |
| | | break; |
| | | case DISK_NUM: |
| | | result = generate_disk_pc_id(identifiers, array_size, false); |
| | |
| | | PcSignature pc_identifier_out) { |
| | | //TODO base62 encoding, now uses base64 |
| | | PcIdentifier concat_identifiers[2]; |
| | | char* b64_data; |
| | | int b64_size = 0; |
| | | size_t concatIdentifiersSize = sizeof(PcIdentifier) * 2; |
| | | //concat_identifiers = (PcIdentifier *) malloc(concatIdentifiersSize); |
| | | memcpy(&concat_identifiers[0], identifier1, sizeof(PcIdentifier)); |
| | | memcpy(&concat_identifiers[1], identifier2, sizeof(PcIdentifier)); |
| | | char* b64_data = base64(concat_identifiers, concatIdentifiersSize, |
| | | b64_data = base64(concat_identifiers, concatIdentifiersSize, |
| | | &b64_size); |
| | | if (b64_size > sizeof(PcSignature)) { |
| | | return FUNC_RET_BUFFER_TOO_SMALL; |
| | |
| | | for (int i = 0; i < num_strategies; i++) { |
| | | FUNCTION_RETURN generate_ok = generate_user_pc_signature(identifier_out, |
| | | strategies[i]); |
| | | BOOST_ASSERT(generate_ok == FUNCTION_RETURN::FUNC_RET_OK); |
| | | BOOST_ASSERT(generate_ok == FUNC_RET_OK); |
| | | idfile << identifier_out << endl; |
| | | } |
| | | idfile.close(); |
| | |
| | | BOOST_AUTO_TEST_CASE(generated_identifiers_stability) { |
| | | const string idfileLocation(PROJECT_TEST_TEMP_DIR "/identifiers_file"); |
| | | IDENTIFICATION_STRATEGY strategies[] = |
| | | { IDENTIFICATION_STRATEGY::DEFAULT, |
| | | IDENTIFICATION_STRATEGY::DISK_LABEL, |
| | | IDENTIFICATION_STRATEGY::DISK_NUM, |
| | | IDENTIFICATION_STRATEGY::ETHERNET }; |
| | | { DEFAULT, |
| | | DISK_LABEL, |
| | | DISK_NUM, |
| | | ETHERNET }; |
| | | const int num_strategies = sizeof(strategies) / sizeof(strategies[0]); |
| | | std::ifstream test_idfile_exist(idfileLocation); |
| | | if (!test_idfile_exist.good()) { |
| | |
| | | BOOST_ASSERT(generate_ok == FUNCTION_RETURN::FUNC_RET_OK); |
| | | if (reference_signatures[i] != generated_identifier) { |
| | | string message = string("pc signature compare fail: strategy:") |
| | | + to_string(strategies[i]) + " generated: [" |
| | | + to_string((long double) strategies[i]) + " generated: [" |
| | | + generated_identifier + "] reference: [" |
| | | + reference_signatures[i] + "]"; |
| | | BOOST_FAIL(message); |