Skip to content

Commit

Permalink
wip: crypt memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
mereacre committed Aug 25, 2021
1 parent a6f6d0e commit e5820f4
Show file tree
Hide file tree
Showing 104 changed files with 651 additions and 372 deletions.
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
"hash_map": "c",
"hash_set": "c",
"bitset": "c",
"any": "c"
"any": "c",
"array": "cpp",
"string_view": "cpp",
"initializer_list": "cpp",
"regex": "cpp",
"utility": "cpp",
"valarray": "cpp"
}
}
107 changes: 56 additions & 51 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ include(glibc)
set(CMAKE_INSTALL_RPATH "$ORIGIN" "$ORIGIN/lib")
set(CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/install" CACHE BOOL "Installation path" FORCE)

option(BUILD_TEST "Build the unit tests" OFF)
option(USE_ARM_MUSL_LIBC "Use arm musl standard C library" OFF)
option(BUILD_ONLY_DOCS "Build only docs" OFF)
option(BUILD_CAPTURE_SERVICE "Build Capture server" ON)
Expand Down Expand Up @@ -207,75 +208,79 @@ include(doxygen)

if (NOT BUILD_ONLY_DOCS)
add_subdirectory(src)
add_subdirectory(tests)
if (BUILD_TEST)
add_subdirectory(tests)
endif ()
endif ()

install(
TARGETS edgesec capsrv
RUNTIME DESTINATION "bin"
)

if (BUILD_REST_SERVER AND LIBMICROHTTPD_LIB)
if (NOT BUILD_TEST)
install(
TARGETS restsrv
TARGETS edgesec capsrv
RUNTIME DESTINATION "bin"
)
endif ()

if (BUILD_SQLSYNC_SERVICE AND LIBSQLITE_LIB)
install(
TARGETS sqlsyncsrv
RUNTIME DESTINATION "bin"
)
endif ()
if (BUILD_REST_SERVER AND LIBMICROHTTPD_LIB)
install(
TARGETS restsrv
RUNTIME DESTINATION "bin"
)
endif ()

if (BUILD_REVERSE_SERVICE)
install(
TARGETS revclient revsrv
RUNTIME DESTINATION "bin"
)
endif ()
if (BUILD_SQLSYNC_SERVICE AND LIBSQLITE_LIB)
install(
TARGETS sqlsyncsrv
RUNTIME DESTINATION "bin"
)
endif ()

install(FILES "${PROJECT_BINARY_DIR}/config.ini" DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
if (BUILD_REVERSE_SERVICE)
install(
TARGETS revclient revsrv
RUNTIME DESTINATION "bin"
)
endif ()

if (BUILD_UUID_LIB AND LIBUUID_LIB)
install(DIRECTORY ${LIBUUID_LIB_DIR} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif ()
install(FILES "${PROJECT_BINARY_DIR}/config.ini" DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")

if (BUILD_SQLITE_LIB AND LIBSQLITE_LIB)
install(DIRECTORY ${LIBSQLITE_LIB_DIR} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif ()
if (BUILD_UUID_LIB AND LIBUUID_LIB)
install(DIRECTORY ${LIBUUID_LIB_DIR} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif ()

if(BUILD_PCAP_LIB AND LIBPCAP_LIB)
install(DIRECTORY ${LIBPCAP_LIB_DIR} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif ()
if (BUILD_SQLITE_LIB AND LIBSQLITE_LIB)
install(DIRECTORY ${LIBSQLITE_LIB_DIR} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif ()

if(BUILD_OPENSSL_LIB AND LIBCRYPTO_LIB)
install(DIRECTORY ${LIBOPENSSL_LIB_PATH} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif ()
if(BUILD_PCAP_LIB AND LIBPCAP_LIB)
install(DIRECTORY ${LIBPCAP_LIB_DIR} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif ()

if (BUILD_NETLINK_LIB AND LIBNETLINK_LIB)
install(DIRECTORY ${LIBNETLINK_LIB_PATH} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif ()
if(BUILD_OPENSSL_LIB AND LIBCRYPTO_LIB)
install(DIRECTORY ${LIBOPENSSL_LIB_PATH} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif ()

if (BUILD_NDPI_LIB AND LIBNDPI_LIB)
install(DIRECTORY ${LIBNDPI_LIB_DIR} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif ()
if (BUILD_NETLINK_LIB AND LIBNETLINK_LIB)
install(DIRECTORY ${LIBNETLINK_LIB_PATH} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif ()

if (BUILD_MNL_LIB AND LIBMNL_LIB)
install(DIRECTORY ${LIBMNL_LIB_DIR} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif ()
if (BUILD_NDPI_LIB AND LIBNDPI_LIB)
install(DIRECTORY ${LIBNDPI_LIB_DIR} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif ()

if (BUILD_MICROHTTPD_LIB AND LIBMICROHTTPD_LIB)
install(DIRECTORY ${LIBMICROHTTPD_LIB_DIR} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif ()
if (BUILD_MNL_LIB AND LIBMNL_LIB)
install(DIRECTORY ${LIBMNL_LIB_DIR} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif ()

if (BUILD_GRPC_LIB AND LIBGRPC_LIB)
install(DIRECTORY ${LIBGRPC_LIB_DIR} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif ()
if (BUILD_MICROHTTPD_LIB AND LIBMICROHTTPD_LIB)
install(DIRECTORY ${LIBMICROHTTPD_LIB_DIR} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif ()

if (BUILD_GRPC_LIB AND LIBGRPC_LIB)
install(DIRECTORY ${LIBGRPC_LIB_DIR} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif ()

if (BUILD_HOSTAPD AND HOSTAPD)
install(FILES ${HOSTAPD} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
if (BUILD_HOSTAPD AND HOSTAPD)
install(FILES ${HOSTAPD} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif ()
endif ()
# setup_target_for_coverage_lcov(
# NAME coverage
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ To enable verbose debug mode use:
```

## Testing
To run the tests use:
To compile the tests use:
```console
make tests
cd build/
rm CMakeCache.txt
cmake -DBUILD_TEST=ON ../
make
make test
```

To run each test individually the test binaries can be located in ```./build/tests``` folder.
Expand All @@ -61,7 +65,7 @@ To run each test individually the test binaries can be located in ```./build/tes

To compile the docs from ```./build``` folder:
```console
make docs
make doxydocs
```

See [`./docs`](./docs) for how to build the developer doxygen documentation website.
Expand Down
16 changes: 9 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ endif ()
add_library(config config.c)
target_link_libraries(config minIni mac_mapper)

if (BUILD_CAPTURE_SERVICE)
if (BUILD_CAPTURE_SERVICE AND NOT BUILD_TEST)
add_executable(capsrv capsrv.c)
target_include_directories(capsrv PRIVATE ${LIBPCAP_INCLUDE_PATH} ${PROJECT_BINARY_DIR})
target_link_libraries(capsrv capture_service capture_config config minIni os hashmap ${LIBPCAP_LIB})
endif ()

if (BUILD_REST_SERVER AND BUILD_MICROHTTPD_LIB)
if (BUILD_REST_SERVER AND BUILD_MICROHTTPD_LIB AND NOT BUILD_TEST)
add_executable(restsrv restsrv.c)
target_include_directories(restsrv PRIVATE ${LIBMICROHTTPD_INCLUDE_DIR} ${PROJECT_BINARY_DIR})
target_link_libraries(restsrv config minIni cryptou os hashmap cmd_processor ${LIBMICROHTTPD_LIB})
endif ()

if (BUILD_SQLSYNC_SERVICE)
if (BUILD_SQLSYNC_SERVICE AND NOT BUILD_TEST)
add_executable(sqlsyncsrv sqlsyncsrv.cc)
target_include_directories(sqlsyncsrv PRIVATE ${PROJECT_BINARY_DIR} ${LIBGRPC_INCLUDE_PATH})
target_link_libraries(sqlsyncsrv PUBLIC os sqlite_grpc_proto ${LIBGRPCPP_REFLECTION_LIB} ${LIBGRPCPP_LIB} ${LIBPROTOBUF_LIB} ${LIBSQLITE_LIB})
endif ()

if (BUILD_REVERSE_SERVICE)
if (BUILD_REVERSE_SERVICE AND NOT BUILD_TEST)
add_executable(revclient revclient.cc)
target_include_directories(revclient PRIVATE ${PROJECT_BINARY_DIR} ${LIBGRPC_INCLUDE_PATH})
target_link_libraries(revclient os log reverse_grpc_proto ${LIBGRPCPP_REFLECTION_LIB} ${LIBGRPCPP_LIB} ${LIBPROTOBUF_LIB} ${LIBPTHREAD_LIB})
Expand All @@ -50,6 +50,8 @@ if (BUILD_REVERSE_SERVICE)
target_link_libraries(revsrv os log eloop domain reverse_grpc_proto ${LIBGRPCPP_REFLECTION_LIB} ${LIBGRPCPP_LIB} ${LIBPROTOBUF_LIB} ${LIBPTHREAD_LIB})
endif ()

add_executable(edgesec edgesec.c)
target_include_directories(edgesec PRIVATE ${PROJECT_BINARY_DIR} ${LIBOPENSSL_INCLUDE_PATH})
target_link_libraries(edgesec config engine minIni os hashmap ${LIBCRYPTO_LIB})
if (NOT BUILD_TEST)
add_executable(edgesec edgesec.c)
target_include_directories(edgesec PRIVATE ${PROJECT_BINARY_DIR} ${LIBOPENSSL_INCLUDE_PATH})
target_link_libraries(edgesec config engine minIni os hashmap ${LIBCRYPTO_LIB})
endif ()
1 change: 1 addition & 0 deletions src/ap/ap_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <net/if.h>
#include <stdbool.h>

#include "../utils/allocs.h"
#include "../utils/os.h"
#include "../radius/radius_server.h"

Expand Down
1 change: 1 addition & 0 deletions src/ap/ap_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "ap_config.h"
#include "hostapd.h"
#include "radius/radius_server.h"
#include "utils/allocs.h"
#include "utils/os.h"
#include "utils/if.h"
#include "utils/log.h"
Expand Down
1 change: 1 addition & 0 deletions src/ap/ap_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "ap_config.h"
#include "../radius/radius_server.h"
#include "../utils/allocs.h"
#include "../utils/os.h"
#include "../utils/if.h"

Expand Down
1 change: 1 addition & 0 deletions src/ap/hostapd.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include "ap_config.h"
#include "utils/log.h"
#include "utils/allocs.h"
#include "utils/os.h"
#include "utils/if.h"

Expand Down
1 change: 1 addition & 0 deletions src/ap/hostapd.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <stdbool.h>

#include "ap_config.h"
#include "../utils/allocs.h"
#include "../utils/os.h"
#include "../radius/radius_server.h"

Expand Down
1 change: 1 addition & 0 deletions src/capsrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "config.h"
#include "version.h"
#include "utils/log.h"
#include "utils/allocs.h"
#include "utils/os.h"
#include "utils/minIni.h"

Expand Down
2 changes: 1 addition & 1 deletion src/capture/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include_directories (
)

add_library(capture_config capture_config.c)
target_link_libraries(capture_config log os)
target_link_libraries(capture_config PRIVATE log os)

if (BUILD_PCAP_LIB)
add_library(mdns_decoder mdns_decoder.c)
Expand Down
2 changes: 2 additions & 0 deletions src/capture/capture_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "capture_config.h"

#include "../utils/log.h"
#include "../utils/allocs.h"
#include "../utils/os.h"
#include "../utils/utarray.h"

Expand All @@ -45,6 +46,7 @@ int process_sync_params(char *param_str, struct capture_conf *config)
utarray_new(param_arr, &ut_str_icd);

if (split_string_array(param_str, ',', param_arr) < 0) {
utarray_free(param_arr);
return -1;
}

Expand Down
1 change: 1 addition & 0 deletions src/capture/capture_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <net/if.h>
#include <stdbool.h>

#include "../utils/allocs.h"
#include "../utils/os.h"

#define MAX_ANALYSER_NAME_SIZE 64
Expand Down
1 change: 1 addition & 0 deletions src/capture/capture_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "capture_service.h"

#include "../utils/log.h"
#include "../utils/allocs.h"
#include "../utils/os.h"

int run_capture(struct capture_conf *config)
Expand Down
11 changes: 4 additions & 7 deletions src/capture/default_analyser.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "../utils/log.h"
#include "../utils/eloop.h"
#include "../utils/list.h"
#include "../utils/allocs.h"
#include "../utils/os.h"

#define MAX_PCAP_FILE_NAME_LENGTH MAX_RANDOM_UUID_LEN + STRLEN(PCAP_EXTENSION)
Expand Down Expand Up @@ -289,16 +290,12 @@ int start_default_analyser(struct capture_conf *config)
if (!run_register_db(context.grpc_srv_addr, context.db_name)) {
log_trace("run_register_db fail");
}

ret = open_sqlite_header_db(header_db_path, trace_callback, (void*)context.squeue,
(sqlite3 **)&context.header_db);
ret = open_sqlite_header_db(header_db_path, trace_callback, (void*)context.squeue, &context.header_db);
#else
ret = open_sqlite_header_db(header_db_path, NULL, NULL,
(sqlite3 **)&context.header_db);
ret = open_sqlite_header_db(header_db_path, NULL, NULL, &context.header_db);
#endif
} else {
ret = open_sqlite_header_db(header_db_path, NULL, NULL,
(sqlite3 **)&context.header_db);
ret = open_sqlite_header_db(header_db_path, NULL, NULL, &context.header_db);
}

if (ret < 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/capture/default_analyser.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct capture_context {
struct packet_queue *pqueue;
struct pcap_queue *cqueue;
struct string_queue *squeue;
sqlite3 *header_db;
struct sqlite_header_context *header_db;
sqlite3 *pcap_db;
bool file_write;
bool db_write;
Expand Down
1 change: 1 addition & 0 deletions src/capture/dns_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <arpa/inet.h>

#include "../utils/utarray.h"
#include "../utils/allocs.h"
#include "../utils/os.h"
#include "../utils/hash.h"

Expand Down
1 change: 1 addition & 0 deletions src/capture/mdns_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <arpa/inet.h>

#include "../utils/utarray.h"
#include "../utils/allocs.h"
#include "../utils/os.h"
#include "../utils/hash.h"

Expand Down
1 change: 1 addition & 0 deletions src/capture/ndpi_analyser.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "ndpi_serialiser.h"

#include "../utils/log.h"
#include "../utils/allocs.h"
#include "../utils/os.h"
#include "../utils/domain.h"
#include "../utils/base64.h"
Expand Down
1 change: 1 addition & 0 deletions src/capture/ndpi_serialiser.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "ndpi_serialiser.h"

#include "../utils/log.h"
#include "../utils/allocs.h"
#include "../utils/os.h"

int ndpi_serialise_dhcp(struct ndpi_flow_struct *flow, struct nDPI_flow_meta *meta)
Expand Down
1 change: 1 addition & 0 deletions src/capture/ndpi_serialiser.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include "capture_config.h"

#include "../utils/allocs.h"
#include "../utils/os.h"
#include "../utils/hash.h"

Expand Down
1 change: 1 addition & 0 deletions src/capture/packet_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <pcap.h>

#include "../utils/log.h"
#include "../utils/allocs.h"
#include "../utils/os.h"
#include "../utils/if.h"
#include "../utils/hash.h"
Expand Down
Loading

0 comments on commit e5820f4

Please sign in to comment.