Skip to content

Commit

Permalink
valgrind & tests
Browse files Browse the repository at this point in the history
  • Loading branch information
open-license-manager committed Jul 31, 2014
1 parent 4150ba4 commit 6b97710
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 139 deletions.
39 changes: 24 additions & 15 deletions .cproject
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,41 @@
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.base.1941555127" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.base.1941555127" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
<configuration artifactName="${ProjName}" buildProperties="" description="" errorParsers="org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GLDErrorParser" id="cdt.managedbuild.toolchain.gnu.base.1941555127" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="cdt.managedbuild.toolchain.gnu.base.1941555127.38772218" name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.base.1610910832" name="cdt.managedbuild.toolchain.gnu.base" superClass="cdt.managedbuild.toolchain.gnu.base">
<toolChain errorParsers="" id="cdt.managedbuild.toolchain.gnu.base.1610910832" name="cdt.managedbuild.toolchain.gnu.base" nonInternalBuilderId="cdt.managedbuild.target.gnu.builder.base" superClass="cdt.managedbuild.toolchain.gnu.base">
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF;org.eclipse.cdt.core.GNU_ELF" id="cdt.managedbuild.target.gnu.platform.base.333980180" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>
<builder autoBuildTarget="" buildPath="${workspace_loc:/license-manager-cpp}/build/linux" enableAutoBuild="true" id="cdt.managedbuild.target.gnu.builder.base.516265988" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="cdt.managedbuild.target.gnu.builder.base">
<outputEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="outputPath" name=""/>
</outputEntries>
</builder>
<builder buildPath="${workspace_loc:/license-manager-cpp/build/linux}" enableAutoBuild="true" enabledIncrementalBuild="true" id="cdt.managedbuild.target.gnu.builder.base.834186429" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="cdt.managedbuild.target.gnu.builder.base"/>
<tool id="cdt.managedbuild.tool.gnu.archiver.base.1063978701" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.1465609732" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base">
<tool errorParsers="org.eclipse.cdt.core.GCCErrorParser" id="cdt.managedbuild.tool.gnu.cpp.compiler.base.1465609732" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base">
<option id="gnu.cpp.compiler.option.preprocessor.def.1664583179" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" useByScannerDiscovery="false" valueType="definedSymbols">
<listOptionValue builtIn="false" value="__GXX_EXPERIMENTAL_CXX0X__"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.18539696" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.base.589770174" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base">
<tool errorParsers="org.eclipse.cdt.core.GCCErrorParser" id="cdt.managedbuild.tool.gnu.c.compiler.base.589770174" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base">
<option id="gnu.c.compiler.option.include.paths.1362295159" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="/usr/include/dbus-1.0"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1441923396" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.base.1466986479" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.233385682" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base">
<tool errorParsers="org.eclipse.cdt.core.GLDErrorParser" id="cdt.managedbuild.tool.gnu.cpp.linker.base.233385682" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base">
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1900932213" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="cdt.managedbuild.tool.gnu.assembler.base.1674253564" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base">
<tool errorParsers="" id="cdt.managedbuild.tool.gnu.assembler.base.1674253564" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1912634158" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
</toolChain>
Expand Down Expand Up @@ -73,10 +71,21 @@
<resource resourceType="FOLDER" workspacePath="/license-manager-cpp/build/linux"/>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings">
<doc-comment-owner id="org.eclipse.cdt.ui.doxygen">
<path value=""/>
</doc-comment-owner>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
<buildTargets>
<target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments>-j4</buildArguments>
<buildTarget>all</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
</buildTargets>
</storageModule>
</cproject>
7 changes: 3 additions & 4 deletions .settings/language.settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
<project>
<configuration id="cdt.managedbuild.toolchain.gnu.base.1941555127" name="Default">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="true" env-hash="-1162336436791480065" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD --std=c++11 &quot;${INPUTS}&quot;">
<provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true" store-entries-with-project="true"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="true" env-hash="-1161885277975224065" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD --std=c++11 &quot;${INPUTS}&quot;" store-entries-with-project="false">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="(gcc)|([gc]\+\+)|(clang)" prefer-non-shared="true" resource-scope="per-folder"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
</extension>
</configuration>
Expand Down
15 changes: 9 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ project (license++ C CXX)
SET(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "CMake verbose" FORCE)

SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/build/modules/")

if(WIN32)
SET(PLATFORM_LIBS "")
if(CMAKE_CL_64)
Expand Down Expand Up @@ -43,14 +45,11 @@ else(CMAKE_SIZEOF_VOID_P EQUAL 8)
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set_property(DIRECTORY PROPERTY COMPILE_DEFINITIONS_DEBUG _DEBUG)


set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/build/modules/")
#find_package(CryptoPP REQUIRED)
#include_directories(${CRYPTOPP_INCLUDE_DIRS})
#link_directories ( ${Boost_LIBRARY_DIRS} )



SET(Boost_USE_STATIC_LIBS ON)
# static runtime requires /MT
#SET(Boost_USE_MULTITHREADED ON) #SET(Boost_USE_STATIC_RUNTIME OFF)
Expand All @@ -64,6 +63,13 @@ find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
list(APPEND EXTERNAL_LIBS ${OPENSSL_CRYPTO_LIBRARY})

if(NOT WIN32)
FIND_PACKAGE(Dbus REQUIRED)
include_directories(${DBUS_INCLUDE_DIR})
include_directories(${DBUS_ARCH_INCLUDE_DIR})
list(APPEND EXTERNAL_LIBS ${DBUS_LIBRARIES})
endif(NOT WIN32)

FIND_PACKAGE(Doxygen)

IF (DOXYGEN_FOUND)
Expand Down Expand Up @@ -100,7 +106,6 @@ configure_file (
#include build directory to find build_properties.h
include_directories(${CMAKE_BINARY_DIR})


add_subdirectory(src)

#test are done with boost_tests:disable them if boost not found.
Expand All @@ -116,8 +121,6 @@ ENDIF(Boost_FOUND)

#include(build/modules/CmakeDebugVariables.txt)



message("")
message( STATUS "C compiler: " ${CMAKE_C_COMPILER})
message( STATUS "C compiler flags: " ${CMAKE_C_FLAGS})
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ A lincense manager written in C++
Linux
===================

apt-get install libcrypto++dev (version 5.6.1)
apt-get install
libboost-dev libboost-filesystem-dev
libboost-program-options-dev libboost-test-dev libboost-date-time-dev
libssl-dev?

libdbus-1-dev
#libcrypto++dev (version 5.6.1)
openssl genrsa -out src/license-generator/privkey.pem 2048
72 changes: 72 additions & 0 deletions build/modules/FindDbus.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# - Try to find the low-level D-Bus library
# Once done this will define
#
# DBUS_FOUND - system has D-Bus
# DBUS_INCLUDE_DIR - the D-Bus include directory
# DBUS_ARCH_INCLUDE_DIR - the D-Bus architecture-specific include directory
# DBUS_LIBRARIES - the libraries needed to use D-Bus

# Copyright (c) 2008, Kevin Kofler, <[email protected]>
# modeled after FindLibArt.cmake:
# Copyright (c) 2006, Alexander Neundorf, <[email protected]>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

if (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES)

# in cache already
SET(DBUS_FOUND TRUE)

else (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES)

IF (NOT WIN32)
FIND_PACKAGE(PkgConfig)
IF (PKG_CONFIG_FOUND)
# use pkg-config to get the directories and then use these values
# in the FIND_PATH() and FIND_LIBRARY() calls
pkg_check_modules(_DBUS_PC QUIET dbus-1)
ENDIF (PKG_CONFIG_FOUND)
ENDIF (NOT WIN32)

FIND_PATH(DBUS_INCLUDE_DIR dbus/dbus.h
${_DBUS_PC_INCLUDE_DIRS}
/usr/include
/usr/include/dbus-1.0
/usr/local/include
)

FIND_PATH(DBUS_ARCH_INCLUDE_DIR dbus/dbus-arch-deps.h
${_DBUS_PC_INCLUDE_DIRS}
/usr/lib${LIB_SUFFIX}/include
/usr/lib${LIB_SUFFIX}/dbus-1.0/include
/usr/lib64/include
/usr/lib64/dbus-1.0/include
/usr/lib/include
/usr/lib/dbus-1.0/include
)

FIND_LIBRARY(DBUS_LIBRARIES NAMES dbus-1 dbus
PATHS
${_DBUS_PC_LIBDIR}
)


if (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES)
set(DBUS_FOUND TRUE)
endif (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES)


if (DBUS_FOUND)
if (NOT DBus_FIND_QUIETLY)
message(STATUS "Found D-Bus: ${DBUS_LIBRARIES}")
endif (NOT DBus_FIND_QUIETLY)
else (DBUS_FOUND)
if (DBus_FIND_REQUIRED)
message(FATAL_ERROR "Could NOT find D-Bus")
endif (DBus_FIND_REQUIRED)
endif (DBUS_FOUND)

MARK_AS_ADVANCED(DBUS_INCLUDE_DIR DBUS_ARCH_INCLUDE_DIR DBUS_LIBRARIES)

endif (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES)
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

add_subdirectory("bootstrap")
add_subdirectory("library")

Expand Down
36 changes: 21 additions & 15 deletions src/library/os/linux/os-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ FUNCTION_RETURN getAdapterInfos(AdapterInfo * adapterInfos,
perror("getifaddrs");
return ERROR;
}

if (adapterInfos != NULL) {
memset(adapterInfos, 0, (*adapter_info_size) * sizeof(AdapterInfo));
}

/* count the maximum number of interfaces */
for (ifa = ifaddr, if_max = 0; ifa != NULL; ifa = ifa->ifa_next, n++) {
if (ifa->ifa_addr == NULL) {
Expand Down Expand Up @@ -111,8 +116,8 @@ FUNCTION_RETURN getAdapterInfos(AdapterInfo * adapterInfos,
*/
#ifdef _DEBUG
s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host,
NI_MAXHOST,
NULL, 0, NI_NUMERICHOST);
NI_MAXHOST,
NULL, 0, NI_NUMERICHOST);
if (s != 0) {
printf("getnameinfo() failed: %s\n", gai_strerror(s));
}
Expand Down Expand Up @@ -190,7 +195,7 @@ static void parseUUID(const char *uuid, unsigned char* buffer_out,
hexuuid[j++] = '0';
}
hexuuid[j] = '\0';
for (i = 0; i < j/2; i++) {
for (i = 0; i < j / 2; i++) {
sscanf(&hexuuid[i * 2], "%2hhx", &cur_character);
buffer_out[i % out_size] = buffer_out[i % out_size] ^ cur_character;
}
Expand All @@ -204,7 +209,7 @@ FUNCTION_RETURN getDiskInfos(DiskInfo * diskInfos, size_t * disk_info_size) {
/*static char discard[1024];
char device[64], name[64], type[64];
*/
char path[MAX_PATH], cur_dir[MAX_PATH];
char cur_dir[MAX_PATH];
struct mntent *ent;

int maxDrives, currentDrive, i, drive_found;
Expand All @@ -224,23 +229,15 @@ FUNCTION_RETURN getDiskInfos(DiskInfo * diskInfos, size_t * disk_info_size) {
}
memset(tmpDrives, 0, sizeof(DiskInfo) * maxDrives);
statDrives = (__ino64_t *) malloc(maxDrives * sizeof(__ino64_t ));
memset(statDrives, 0, sizeof(__ino64_t ) * maxDrives);;
memset(statDrives, 0, sizeof(__ino64_t ) * maxDrives);
;

aFile = setmntent("/proc/mounts", "r");
if (aFile == NULL) {
/*proc not mounted*/
return ERROR;
}

disk_by_uuid_dir = opendir("/dev/disk/by-uuid");
if (disk_by_uuid_dir == NULL) {
#ifdef _DEBUG
printf("Open /dev/disk/by-uuid fail");
#endif
free(statDrives);
return ERROR;
}

currentDrive = 0;
while (NULL != (ent = getmntent(aFile))) {
if ((strncmp(ent->mnt_type, "ext", 3) == 0
Expand Down Expand Up @@ -276,16 +273,25 @@ FUNCTION_RETURN getDiskInfos(DiskInfo * diskInfos, size_t * disk_info_size) {
}
}
endmntent(aFile);

if (diskInfos == NULL) {
*disk_info_size = currentDrive;
free(tmpDrives);
result = OK;
} else if (*disk_info_size >= currentDrive) {
disk_by_uuid_dir = opendir("/dev/disk/by-uuid");
if (disk_by_uuid_dir == NULL) {
#ifdef _DEBUG
printf("Open /dev/disk/by-uuid fail");
#endif
free(statDrives);
return ERROR;
}
result = OK;
*disk_info_size = currentDrive;
while ((dir = readdir(disk_by_uuid_dir)) != NULL) {
strcpy(cur_dir, "/dev/disk/by-uuid/");
strcat(cur_dir, dir->d_name);
strncat(cur_dir, dir->d_name, 200);
if (stat(cur_dir, &sym_stat) == 0) {
for (i = 0; i < currentDrive; i++) {
if (sym_stat.st_ino == statDrives[i]) {
Expand Down
19 changes: 19 additions & 0 deletions src/library/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ FUNCTION_RETURN getAdapterInfos(AdapterInfo * adapterInfos,
size_t * adapter_info_size);
FUNCTION_RETURN getDiskInfos(DiskInfo * diskInfos, size_t * disk_info_size);
FUNCTION_RETURN getUserHomePath(char[MAX_PATH]);
/**
* Get an identifier of the machine in an os specific way.
* In Linux it uses:
* http://stackoverflow.com/questions/328936/getting-a-unique-id-from-a-unix-like-system
*
* <ul>
* <li>Dbus if available</li>
* </ul>
* Can be used as a fallback in case no other methods are available.
* Windows:
* HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\ CurrentVersion\ProductId
* http://sowkot.blogspot.it/2008/08/generating-unique-keyfinger-print-for.html
* http://stackoverflow.com/questions/2842116/reliable-way-of-generating-unique-hardware-id
*
*
* @param identifier
* @return
*/
FUNCTION_RETURN getOsSpecificIdentifier(unsigned char identifier[6]);
VIRTUALIZATION getVirtualization();
void os_initialize();

Expand Down
Loading

0 comments on commit 6b97710

Please sign in to comment.