aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt11
-rw-r--r--nDPId.c27
-rw-r--r--nDPIsrvd.c12
-rwxr-xr-xtest/run_tests.sh3
-rw-r--r--utils.c50
-rw-r--r--utils.h2
6 files changed, 77 insertions, 28 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 56733d62d..a1ad53f2b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,6 +31,12 @@ if(BUILD_NDPI)
"$<TARGET_FILE:nDPId-test>")
endif()
+execute_process(
+ COMMAND git describe --tags
+ WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
+ OUTPUT_VARIABLE GIT_VERSION ERROR_QUIET)
+string(STRIP "${GIT_VERSION}" GIT_VERSION)
+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
set(NDPID_C_FLAGS -DJSMN_STATIC=1 -DJSMN_STRICT=1)
if(ENABLE_MEMORY_PROFILING)
@@ -114,14 +120,14 @@ else()
endif()
find_package(PCAP "1.8.1" REQUIRED)
-target_compile_options(nDPId PRIVATE ${NDPID_C_FLAGS} ${MEMORY_PROFILING_CFLAGS} "-pthread")
+target_compile_options(nDPId PRIVATE ${NDPID_C_FLAGS} -DGIT_VERSION=\"${GIT_VERSION}\" ${MEMORY_PROFILING_CFLAGS} "-pthread")
target_include_directories(nDPId PRIVATE "${STATIC_LIBNDPI_INC}" "${NDPI_INCLUDEDIR}" "${NDPI_INCLUDEDIR}/ndpi")
target_link_libraries(nDPId "${STATIC_LIBNDPI_LIB}" "${pkgcfg_lib_NDPI_ndpi}"
"${pkgcfg_lib_PCRE_pcre}" "${pkgcfg_lib_MAXMINDDB_maxminddb}"
"${GCRYPT_LIBRARY}" "${PCAP_LIBRARY}"
"-pthread")
-target_compile_options(nDPId PRIVATE ${NDPID_C_FLAGS} ${MEMORY_PROFILING_CFLAGS})
+target_compile_options(nDPIsrvd PRIVATE ${NDPID_C_FLAGS} -DGIT_VERSION=\"${GIT_VERSION}\" ${MEMORY_PROFILING_CFLAGS})
target_include_directories(nDPIsrvd PRIVATE
"${CMAKE_SOURCE_DIR}"
"${CMAKE_SOURCE_DIR}/dependencies"
@@ -173,6 +179,7 @@ install(FILES dependencies/nDPIsrvd.py DESTINATION share/nDPId)
install(FILES examples/py-flow-info/flow-info.py DESTINATION bin RENAME nDPIsrvd-flow-info.py)
message(STATUS "--------------------------")
+message(STATUS "nDPId GIT_VERSION........: ${GIT_VERSION}")
message(STATUS "CMAKE_BUILD_TYPE.........: ${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_C_FLAGS............: ${CMAKE_C_FLAGS}")
message(STATUS "NDPID_C_FLAGS............: ${NDPID_C_FLAGS}")
diff --git a/nDPId.c b/nDPId.c
index 881fd3c68..427f3ab27 100644
--- a/nDPId.c
+++ b/nDPId.c
@@ -3085,8 +3085,6 @@ static int nDPId_parse_options(int argc, char ** argv)
int opt;
static char const usage[] =
- "(C) 2020-2021 Toni Uhlig\n"
- "Please report any BUG to toni@impl.cc\n\n"
"Usage: %s "
"[-i pcap-file/interface] [-I] [-E] [-B bpf-filter]\n"
"\t \t"
@@ -3094,9 +3092,11 @@ static int nDPId_parse_options(int argc, char ** argv)
"[-d] [-p pidfile]\n"
"\t \t"
"[-u user] [-g group] "
- "[-P path] [-C path] [-J path] "
- "[-a instance-alias] "
- "[-o subopt=value]\n\n"
+ "[-P path] [-C path] [-J path]\n"
+ "\t \t"
+ "[-a instance-alias] [-o subopt=value]\n"
+ "\t \t"
+ "[-v] [-h]\n\n"
"\t-i\tInterface or file from where to read packets from.\n"
"\t-I\tProcess only packets where the source address of the first packet\n"
"\t \tis part of the interface subnet. (Internal mode)\n"
@@ -3115,12 +3115,16 @@ static int nDPId_parse_options(int argc, char ** argv)
"\t \tSee: https://sslbl.abuse.ch/blacklist/ja3_fingerprints.csv\n"
"\t-S\tLoad a nDPI SSL SHA1 hash blacklist file.\n"
"\t \tSee: https://sslbl.abuse.ch/blacklist/sslblacklist.csv\n"
- "\t-a\tSet an alias name of this daemon instance which will be part of every JSON message.\n"
- "\t \tThis value is required for correct flow handling of multiple instances and should be unique.\n"
+ "\t-a\tSet an alias name of this daemon instance which will\n"
+ "\t \tbe part of every JSON message.\n"
+ "\t \tThis value is required for correct flow handling of\n"
+ "\t \tmultiple instances and should be unique.\n"
"\t \tDefaults to your hostname.\n"
- "\t-o\t(Carefully) Tune some daemon options. See subopts below.\n\n";
+ "\t-o\t(Carefully) Tune some daemon options. See subopts below.\n"
+ "\t-v\tversion\n"
+ "\t-h\tthis\n\n";
- while ((opt = getopt(argc, argv, "hi:IEB:lc:dp:u:g:P:C:J:S:a:o:")) != -1)
+ while ((opt = getopt(argc, argv, "hi:IEB:lc:dp:u:g:P:C:J:S:a:o:vh")) != -1)
{
switch (opt)
{
@@ -3252,7 +3256,12 @@ static int nDPId_parse_options(int argc, char ** argv)
}
break;
}
+ case 'v':
+ fprintf(stderr, "%s", get_nDPId_version());
+ return 1;
+ case 'h':
default:
+ fprintf(stderr, "%s\n", get_nDPId_version());
fprintf(stderr, usage, argv[0]);
print_subopt_usage();
return 1;
diff --git a/nDPIsrvd.c b/nDPIsrvd.c
index d16768ed9..0e86a84d5 100644
--- a/nDPIsrvd.c
+++ b/nDPIsrvd.c
@@ -227,7 +227,7 @@ static int nDPIsrvd_parse_options(int argc, char ** argv)
{
int opt;
- while ((opt = getopt(argc, argv, "hlc:dp:s:u:g:")) != -1)
+ while ((opt = getopt(argc, argv, "lc:dp:s:u:g:vh")) != -1)
{
switch (opt)
{
@@ -257,10 +257,16 @@ static int nDPIsrvd_parse_options(int argc, char ** argv)
free(nDPIsrvd_options.group);
nDPIsrvd_options.group = strdup(optarg);
break;
+ case 'v':
+ fprintf(stderr, "%s", get_nDPId_version());
+ return 1;
+ case 'h':
default:
+ fprintf(stderr, "%s\n", get_nDPId_version());
fprintf(stderr,
- "Usage: %s [-l] [-c path-to-unix-sock] [-d] [-p pidfile] "
- "[-s path-to-unix-socket|distributor-host:port] [-u user] [-g group]\n",
+ "Usage: %s [-l] [-c path-to-unix-sock] [-d] [-p pidfile]\n"
+ "\t[-s path-to-unix-socket|distributor-host:port] [-u user] [-g group]\n"
+ "\t[-v] [-h]\n",
argv[0]);
return 1;
}
diff --git a/test/run_tests.sh b/test/run_tests.sh
index 193fd96c4..61d8b8547 100755
--- a/test/run_tests.sh
+++ b/test/run_tests.sh
@@ -82,7 +82,8 @@ if [ $? -ne 1 ]; then
exit 7
fi
-find . -printf '%f\n' -iname '*.pcap' -o -iname '*.pcapng' -o -iname '*.cap' | while read pcap_file; do
+printf 'Using PCAP files from: %s (%s total)\n\n' "$(pwd)" "$(ls -l *.pcap *.pcapng *.cap | wc -l)"
+for pcap_file in $(ls *.pcap *.pcapng *.cap); do
if file "${pcap_file}" | grep -qoE ':\s(pcap|pcap-ng) capture file'; then
true # pass
else
diff --git a/utils.c b/utils.c
index 16b233ced..f6340105b 100644
--- a/utils.c
+++ b/utils.c
@@ -79,14 +79,14 @@ static int create_pidfile(char const * const pidfile)
return 0;
}
-int is_path_absolute(char const * const prefix,
- char const * const path)
+int is_path_absolute(char const * const prefix, char const * const path)
{
if (path[0] != '/')
{
syslog(LOG_DAEMON | LOG_ERR,
"%s path must be absolut i.e. starting with a `/', path given: `%s'",
- prefix, path);
+ prefix,
+ path);
return 1;
}
@@ -134,7 +134,8 @@ int daemonize_shutdown(char const * const pidfile)
return 0;
}
-int change_user_group(char const * const user, char const * const group,
+int change_user_group(char const * const user,
+ char const * const group,
char const * const pidfile,
char const * const uds_collector_path,
char const * const uds_distributor_path)
@@ -143,39 +144,62 @@ int change_user_group(char const * const user, char const * const group,
struct group * grp;
gid_t gid;
- if (getuid() != 0) {
+ if (getuid() != 0)
+ {
return 0;
}
- if (user == NULL) {
+ if (user == NULL)
+ {
return 1;
}
pwd = getpwnam(user);
- if (pwd == NULL) {
+ if (pwd == NULL)
+ {
return 1;
}
- if (group != NULL) {
+ if (group != NULL)
+ {
grp = getgrnam(group);
- if (grp == NULL) {
+ if (grp == NULL)
+ {
return 1;
}
gid = grp->gr_gid;
- } else {
+ }
+ else
+ {
gid = pwd->pw_gid;
}
- if (uds_collector_path != NULL) {
+ if (uds_collector_path != NULL)
+ {
chmod(uds_collector_path, S_IRUSR | S_IWUSR);
chown(uds_collector_path, pwd->pw_uid, gid);
}
- if (uds_distributor_path != NULL) {
+ if (uds_distributor_path != NULL)
+ {
chmod(uds_distributor_path, S_IRUSR | S_IWUSR | S_IRGRP);
chown(uds_distributor_path, pwd->pw_uid, gid);
}
- if (pidfile != NULL) {
+ if (pidfile != NULL)
+ {
chown(pidfile, pwd->pw_uid, gid);
}
return setregid(gid, gid) != 0 || setreuid(pwd->pw_uid, pwd->pw_uid);
}
+
+char const * get_nDPId_version()
+{
+ return "nDPId version "
+#ifdef GIT_VERSION
+ GIT_VERSION
+#else
+ "unknown"
+#endif
+ "\n"
+ "(C) 2020-2021 Toni Uhlig\n"
+ "Please report any BUGs to toni@impl.cc\n";
+}
diff --git a/utils.h b/utils.h
index 951cdea05..12bc9d373 100644
--- a/utils.h
+++ b/utils.h
@@ -15,4 +15,6 @@ int change_user_group(char const * const user, char const * const group,
char const * const uds_collector_path,
char const * const uds_distributor_path);
+char const * get_nDPId_version();
+
#endif