mirror of
https://github.com/pi-hole/FTL.git
synced 2024-10-26 16:52:18 +02:00
Merge branch 'development-v6' into new/ntp
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "FTL x86_64 Build Env",
|
||||
"image": "ghcr.io/pi-hole/ftl-build:v2.5",
|
||||
"image": "ghcr.io/pi-hole/ftl-build:nightly",
|
||||
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
self.errors.append("Exception when GETing from FTL: " + str(e))
|
||||
// sitten -> sittin (substitution of "i" for "e"),
|
||||
// sittin -> sitting (insertion of "g" at the end).
|
||||
|
||||
+5
-7
@@ -1,4 +1,4 @@
|
||||
FROM ghcr.io/pi-hole/ftl-build:v2.5 AS builder
|
||||
FROM ghcr.io/pi-hole/ftl-build:v2.6 AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
@@ -10,16 +10,14 @@ ARG GIT_BRANCH="test"
|
||||
ENV GIT_BRANCH ${GIT_BRANCH}
|
||||
ARG GIT_TAG="test"
|
||||
ENV GIT_TAG ${GIT_TAG}
|
||||
ARG BUILD_OPTS=""
|
||||
ENV BUILD_OPTS ${BUILD_OPTS}
|
||||
|
||||
# Build FTL
|
||||
# Remove possible old build files
|
||||
RUN rm -rf cmake && \
|
||||
# Build FTL
|
||||
bash build.sh "-DSTATIC=${STATIC}" && \
|
||||
# Run binary architecture tests
|
||||
bash test/arch_test.sh && \
|
||||
# Run full test suite
|
||||
bash test/run.sh && \
|
||||
# Build and test FTL
|
||||
bash build.sh "-DSTATIC=${STATIC}" test ${BUILD_OPTS} && \
|
||||
# Move FTL binary to root directory
|
||||
cd / &&\
|
||||
mv /app/pihole-FTL . && \
|
||||
|
||||
@@ -5,6 +5,9 @@ inputs:
|
||||
platform:
|
||||
required: true
|
||||
description: The platform to build for
|
||||
build_opts:
|
||||
required: true
|
||||
description: Any extra build opts to use
|
||||
git_branch:
|
||||
required: true
|
||||
description: The branch to build from
|
||||
@@ -76,6 +79,7 @@ runs:
|
||||
"CI_ARCH=${{ inputs.platform }}"
|
||||
"GIT_BRANCH=${{ inputs.git_branch }}"
|
||||
"GIT_TAG=${{ inputs.git_tag }}"
|
||||
"BUILD_OPTS=${{ inputs.build_opts }}"
|
||||
-
|
||||
name: List files in current directory
|
||||
shell: bash
|
||||
@@ -108,13 +112,13 @@ runs:
|
||||
subject-path: ${{ inputs.bin_name }}
|
||||
-
|
||||
name: Extract documentation files from container
|
||||
if: inputs.event_name != 'pull_request' && inputs.platform == 'linux/amd64'
|
||||
if: inputs.event_name != 'pull_request' && inputs.platform == 'linux/amd64' && inputs.build_opts == ''
|
||||
shell: bash
|
||||
run: |
|
||||
tar -xf build.tar api-docs.tar.gz
|
||||
-
|
||||
name: Upload documentation artifacts for deployoment
|
||||
if: inputs.event_name != 'pull_request' && inputs.platform == 'linux/amd64'
|
||||
if: inputs.event_name != 'pull_request' && inputs.platform == 'linux/amd64' && inputs.build_opts == ''
|
||||
uses: actions/upload-artifact@v4.3.1
|
||||
with:
|
||||
name: pihole-api-docs
|
||||
|
||||
@@ -64,10 +64,16 @@ jobs:
|
||||
include:
|
||||
- platform: linux/amd64
|
||||
bin_name: pihole-FTL-amd64
|
||||
build_opts: ""
|
||||
- platform: linux/amd64
|
||||
bin_name: pihole-FTL-amd64-clang
|
||||
build_opts: clang
|
||||
- platform: linux/386
|
||||
bin_name: pihole-FTL-386
|
||||
build_opts: ""
|
||||
- platform: linux/riscv64
|
||||
bin_name: pihole-FTL-riscv64
|
||||
build_opts: ""
|
||||
env:
|
||||
CI_ARCH: ${{ matrix.platform }}
|
||||
GIT_BRANCH: ${{ needs.smoke-tests.outputs.GIT_BRANCH }}
|
||||
@@ -82,6 +88,7 @@ jobs:
|
||||
with:
|
||||
platform: ${{ matrix.platform }}
|
||||
bin_name: ${{ matrix.bin_name }}
|
||||
build_opts: ${{ matrix.build_opts }}
|
||||
artifact_name: ${{ matrix.bin_name }}-binary
|
||||
target_dir: ${{ needs.smoke-tests.outputs.OUTPUT_DIR }}
|
||||
git_branch: ${{ needs.smoke-tests.outputs.GIT_BRANCH }}
|
||||
|
||||
+2
-3
@@ -14,9 +14,8 @@ version~
|
||||
# IDE files
|
||||
.idea/
|
||||
*.sw*
|
||||
/.vscode
|
||||
.vscode/
|
||||
/.vscode/
|
||||
.vscode/*
|
||||
!.vscode/c_cpp_properties.json
|
||||
/build/
|
||||
|
||||
# __pycache__ files (API tests)
|
||||
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/src/**"
|
||||
],
|
||||
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
|
||||
"defines": [],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "gnu17",
|
||||
"cppStandard": "gnu++17",
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"configurationProvider": "ms-vscode.cmake-tools"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
+5
-1
@@ -8,7 +8,11 @@
|
||||
# This file is copyright under the latest version of the EUPL.
|
||||
# Please see LICENSE file for your rights under this license.
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.12)
|
||||
# C17 supports requires minimum CMake version 3.21
|
||||
# GCC 8.1.0
|
||||
# LLVM Clang 7.0.0
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
set(CMAKE_C_STANDARD 17)
|
||||
|
||||
project(PIHOLE_FTL C)
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ do
|
||||
"-C" | "CLEAN" ) clean=1 && nobuild=1;;
|
||||
"-i" | "install" ) install=1;;
|
||||
"-t" | "test" ) test=1;;
|
||||
"clang" ) clang=1;;
|
||||
"ci" ) builddir="cmake_ci/";;
|
||||
esac
|
||||
done
|
||||
@@ -60,6 +61,13 @@ for scriptname in src/lua/scripts/*.lua; do
|
||||
fi
|
||||
done
|
||||
|
||||
# Set compiler to clang if requested
|
||||
if [[ -n "${clang}" ]]; then
|
||||
export CC=clang
|
||||
export CXX=clang++
|
||||
export STATIC="false"
|
||||
fi
|
||||
|
||||
# Configure build, pass CMake CACHE entries if present
|
||||
# Wrap multiple options in "" as first argument to ./build.sh:
|
||||
# ./build.sh "-DA=1 -DB=2" install
|
||||
@@ -88,5 +96,6 @@ fi
|
||||
# If we are asked to run tests, we do this here
|
||||
if [[ -n "${test}" ]]; then
|
||||
cd ..
|
||||
./test/run.sh
|
||||
bash test/arch_test.sh
|
||||
bash test/run.sh
|
||||
fi
|
||||
|
||||
@@ -7,7 +7,7 @@ index 6280ebf6..a5e82f70 100644
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
+// print_FTL_version()
|
||||
+#include "../log.h"
|
||||
+#include "log.h"
|
||||
|
||||
#if !defined(_WIN32) && !defined(WIN32)
|
||||
# include <signal.h>
|
||||
|
||||
+45
-42
@@ -8,8 +8,6 @@
|
||||
# This file is copyright under the latest version of the EUPL.
|
||||
# Please see LICENSE file for your rights under this license.
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
||||
# Default to a release with debug info build
|
||||
if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
|
||||
if (NOT CMAKE_BUILD_TYPE)
|
||||
@@ -52,8 +50,10 @@ set(SQLITE_DEFINES "-DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DEFAULT_MEMSTATUS=0 -D
|
||||
# -Wl,-z,now: Disable lazy binding
|
||||
# -Wl,-z,relro: Read-only segments after relocation
|
||||
# -fno-common: Emit globals without explicit initializer from `.bss` to `.data`. This causes GCC to reject multiple definitions of global variables. This is the new default from GCC-10 on.
|
||||
set(HARDENING_FLAGS "-fstack-protector-strong -Wp,-D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now -fexceptions -funwind-tables -fasynchronous-unwind-tables -Wl,-z,defs -Wl,-z,now -Wl,-z,relro -fno-common")
|
||||
set(DEBUG_FLAGS "-rdynamic -fno-omit-frame-pointer")
|
||||
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||
set(HARDENING_FLAGS "-fstack-protector-strong -Wp,-D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now -fexceptions -funwind-tables -fasynchronous-unwind-tables -Wl,-z,defs -Wl,-z,now -Wl,-z,relro -fno-common")
|
||||
set(DEBUG_FLAGS "-rdynamic -fno-omit-frame-pointer")
|
||||
endif()
|
||||
|
||||
# -Wall: This enables all the warnings about constructions that some users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros. This also enables some language-specific warnings described in C++ Dialect Options and Objective-C and Objective-C++ Dialect Options.
|
||||
# -Wextra: This enables some extra warning flags that are not enabled by -Wall.
|
||||
@@ -154,11 +154,27 @@ else()
|
||||
set(EXTRAWARN_GCC13 "")
|
||||
endif()
|
||||
|
||||
set(EXTRAWARN "${EXTRAWARN_GCC6} \
|
||||
${EXTRAWARN_GCC7} \
|
||||
${EXTRAWARN_GCC8} \
|
||||
${EXTRAWARN_GCC12} \
|
||||
${EXTRAWARN_GCC13}")
|
||||
# Set extrawarn flags if CC is GCC
|
||||
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||
set(EXTRAWARN "${EXTRAWARN_GCC6} \
|
||||
${EXTRAWARN_GCC7} \
|
||||
${EXTRAWARN_GCC8} \
|
||||
${EXTRAWARN_GCC12} \
|
||||
${EXTRAWARN_GCC13}")
|
||||
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||
set(EXTRAWARN "
|
||||
-Werror \
|
||||
-Wnewline-eof \
|
||||
-Wno-dangling-else \
|
||||
-Wno-gnu-zero-variadic-macro-arguments \
|
||||
-Wno-gnu-variable-sized-type-not-at-end \
|
||||
-Wno-declaration-after-statement \
|
||||
-Wno-reserved-identifier \
|
||||
-Wno-reserved-macro-identifier")
|
||||
else()
|
||||
message(WARNING "Unknown compiler, not setting warnings flags")
|
||||
set(EXTRAWARN "")
|
||||
endif()
|
||||
|
||||
# Remove extra spaces from EXTRAWARN
|
||||
string(REGEX REPLACE " +" " " EXTRAWARN "${EXTRAWARN}")
|
||||
@@ -184,11 +200,14 @@ else()
|
||||
message(STATUS "Compiling dynamically linked executable")
|
||||
endif()
|
||||
# -pie -fPIE: (Dynamic) position independent executable
|
||||
set(HARDENING_FLAGS "${HARDENING_FLAGS} -pie -fPIE")
|
||||
|
||||
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||
set(HARDENING_FLAGS "${HARDENING_FLAGS} -pie -fPIE")
|
||||
endif()
|
||||
|
||||
# -FILE_OFFSET_BITS=64: used by stat(). Avoids problems with files > 2 GB on 32bit machines
|
||||
# We define HAVE_POLL_H as this is needed for the musl builds to succeed
|
||||
set(CMAKE_C_FLAGS "-pipe ${WARN_FLAGS} -D_FILE_OFFSET_BITS=64 ${HARDENING_FLAGS} ${DEBUG_FLAGS} ${CMAKE_C_FLAGS} -DHAVE_POLL_H ${SQLITE_DEFINES}")
|
||||
set(CMAKE_C_FLAGS "-std=c99 -pipe ${WARN_FLAGS} -D_FILE_OFFSET_BITS=64 ${HARDENING_FLAGS} ${DEBUG_FLAGS} ${CMAKE_C_FLAGS} -DHAVE_POLL_H ${SQLITE_DEFINES}")
|
||||
|
||||
set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
|
||||
set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
|
||||
@@ -255,7 +274,6 @@ target_compile_definitions(core PRIVATE DNSMASQ_VERSION=\"${DNSMASQ_VERSION}\")
|
||||
target_include_directories(core PRIVATE ${PROJECT_SOURCE_DIR}/src)
|
||||
add_dependencies(core gen_version)
|
||||
|
||||
|
||||
add_executable(pihole-FTL
|
||||
$<TARGET_OBJECTS:core>
|
||||
$<TARGET_OBJECTS:api>
|
||||
@@ -269,6 +287,7 @@ add_executable(pihole-FTL
|
||||
$<TARGET_OBJECTS:dnsmasq>
|
||||
$<TARGET_OBJECTS:sqlite3>
|
||||
$<TARGET_OBJECTS:lua>
|
||||
$<TARGET_OBJECTS:ftl_lua>
|
||||
$<TARGET_OBJECTS:tre-regex>
|
||||
$<TARGET_OBJECTS:syscalls>
|
||||
$<TARGET_OBJECTS:tomlc99>
|
||||
@@ -279,23 +298,25 @@ add_executable(pihole-FTL
|
||||
if(STATIC)
|
||||
set_target_properties(pihole-FTL PROPERTIES LINK_SEARCH_START_STATIC ON)
|
||||
set_target_properties(pihole-FTL PROPERTIES LINK_SEARCH_END_STATIC ON)
|
||||
target_link_libraries(pihole-FTL -static-libgcc -static -pie)
|
||||
target_link_libraries(pihole-FTL -static-libgcc -static)
|
||||
set(LIBRARY_SUFFIX "${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
||||
else()
|
||||
find_library(LIBMATH m)
|
||||
target_link_libraries(pihole-FTL ${LIBMATH})
|
||||
set(LIBRARY_SUFFIX "")
|
||||
endif()
|
||||
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
# for DNSSEC we need the nettle (+ hogweed) crypto and the gmp math libraries
|
||||
find_library(LIBHOGWEED NAMES libhogweed${CMAKE_STATIC_LIBRARY_SUFFIX} hogweed HINTS /usr/local/lib64)
|
||||
find_library(LIBGMP NAMES libgmp${CMAKE_STATIC_LIBRARY_SUFFIX} gmp)
|
||||
find_library(LIBNETTLE NAMES libnettle${CMAKE_STATIC_LIBRARY_SUFFIX} nettle HINTS /usr/local/lib64)
|
||||
find_library(LIBHOGWEED NAMES libhogweed${LIBRARY_SUFFIX} hogweed HINTS /usr/local/lib64)
|
||||
find_library(LIBGMP NAMES libgmp${LIBRARY_SUFFIX} gmp)
|
||||
find_library(LIBNETTLE NAMES libnettle${LIBRARY_SUFFIX} nettle HINTS /usr/local/lib64)
|
||||
|
||||
# for IDN2 we need the idn2 library which in turn depends on the unistring library
|
||||
find_library(LIBIDN2 NAMES libidn2${CMAKE_STATIC_LIBRARY_SUFFIX} idn2)
|
||||
find_library(LIBUNISTRING NAMES libunistring${CMAKE_STATIC_LIBRARY_SUFFIX} unistring)
|
||||
find_library(LIBIDN2 NAMES libidn2${LIBRARY_SUFFIX} idn2)
|
||||
find_library(LIBUNISTRING NAMES libunistring${LIBRARY_SUFFIX} unistring)
|
||||
|
||||
target_link_libraries(pihole-FTL rt Threads::Threads ${LIBHOGWEED} ${LIBGMP} ${LIBNETTLE} ${LIBIDN2} ${LIBUNISTRING})
|
||||
|
||||
@@ -317,9 +338,9 @@ add_subdirectory(config)
|
||||
add_subdirectory(tools)
|
||||
add_subdirectory(ntp)
|
||||
|
||||
find_library(LIBREADLINE NAMES libreadline${CMAKE_STATIC_LIBRARY_SUFFIX} readline)
|
||||
find_library(LIBHISTORY NAMES libhistory${CMAKE_STATIC_LIBRARY_SUFFIX} history)
|
||||
find_library(LIBTERMCAP NAMES libtermcap${CMAKE_STATIC_LIBRARY_SUFFIX} termcap)
|
||||
find_library(LIBREADLINE NAMES libreadline${LIBRARY_SUFFIX} readline)
|
||||
find_library(LIBHISTORY NAMES libhistory${LIBRARY_SUFFIX} history)
|
||||
find_library(LIBTERMCAP NAMES libtermcap${LIBRARY_SUFFIX} termcap)
|
||||
if(LIBREADLINE AND LIBHISTORY AND LIBTERMCAP)
|
||||
message(STATUS "Building FTL with readline support: YES")
|
||||
target_compile_definitions(lua PRIVATE LUA_USE_READLINE)
|
||||
@@ -329,31 +350,13 @@ else()
|
||||
message(STATUS "Building FTL with readline support: NO")
|
||||
endif()
|
||||
|
||||
# Do we want to compile an all-in FTL version?
|
||||
if(DEFINED ENV{CI_ARCH})
|
||||
if($ENV{CI_ARCH} STREQUAL "x86_64_full")
|
||||
add_definitions(-DDNSMASQ_ALL_OPTS)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
find_package(DBus REQUIRED)
|
||||
# Use results of find_package() call.
|
||||
include_directories(${DBUS_INCLUDE_DIRS})
|
||||
target_link_libraries(pihole-FTL ${DBUS_LIBRARIES})
|
||||
find_library(LIBMNL mnl)
|
||||
find_library(LIBNFTNL nftnl)
|
||||
find_library(LIBNFTABLES nftables)
|
||||
find_library(LIBNFNETLINK nfnetlink)
|
||||
find_library(LIBNETFILTER_CONNTRACK netfilter_conntrack)
|
||||
target_link_libraries(pihole-FTL ${LIBMNL} ${LIBNFTABLES} ${LIBNFTNL} ${LIBNFNETLINK} ${LIBNETFILTER_CONNTRACK})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||||
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "..." FORCE)
|
||||
endif()
|
||||
|
||||
find_library(LIBMBEDCRYPTO NAMES lmbedcrypto${CMAKE_STATIC_LIBRARY_SUFFIX} mbedcrypto)
|
||||
find_library(LIBMBEDX509 NAMES lmbedx509${CMAKE_STATIC_LIBRARY_SUFFIX} mbedx509)
|
||||
find_library(LIBMBEDTLS NAMES lmbedtls${CMAKE_STATIC_LIBRARY_SUFFIX} mbedtls)
|
||||
find_library(LIBMBEDCRYPTO NAMES lmbedcrypto${LIBRARY_SUFFIX} mbedcrypto)
|
||||
find_library(LIBMBEDX509 NAMES lmbedx509${LIBRARY_SUFFIX} mbedx509)
|
||||
find_library(LIBMBEDTLS NAMES lmbedtls${LIBRARY_SUFFIX} mbedtls)
|
||||
if(LIBMBEDCRYPTO AND LIBMBEDX509 AND LIBMBEDTLS)
|
||||
# Enable TLS support in civetweb if mbedTLS is available
|
||||
message(STATUS "Building FTL with TLS support: YES")
|
||||
|
||||
+1
-1
@@ -60,4 +60,4 @@ struct session {
|
||||
char csrf[SID_SIZE];
|
||||
};
|
||||
|
||||
#endif // AUTH_H
|
||||
#endif // AUTH_H
|
||||
|
||||
+2
-2
@@ -238,7 +238,7 @@ static const char *getJSONvalue(struct conf_item *conf_item, cJSON *elem, struct
|
||||
// 1. Check it is a number
|
||||
// 2. Check the number is within the allowed range for the given data type
|
||||
if(!cJSON_IsNumber(elem) ||
|
||||
elem->valuedouble < LONG_MIN || elem->valuedouble > LONG_MAX)
|
||||
elem->valuedouble < (double)LONG_MIN || elem->valuedouble > (double)LONG_MAX)
|
||||
return "not of type long";
|
||||
// Set item
|
||||
conf_item->v.l = elem->valuedouble;
|
||||
@@ -250,7 +250,7 @@ static const char *getJSONvalue(struct conf_item *conf_item, cJSON *elem, struct
|
||||
// 1. Check it is a number
|
||||
// 2. Check the number is within the allowed range for the given data type
|
||||
if(!cJSON_IsNumber(elem) ||
|
||||
elem->valuedouble < 0 || elem->valuedouble > ULONG_MAX)
|
||||
elem->valuedouble < 0 || elem->valuedouble > (double)ULONG_MAX)
|
||||
return "not of type unsigned long";
|
||||
// Set item
|
||||
conf_item->v.ul = elem->valuedouble;
|
||||
|
||||
+1
-1
@@ -110,4 +110,4 @@ int api_dhcp_leases_DELETE(struct ftl_conn *api)
|
||||
// - 404 Not Found (if no lease was found)
|
||||
cJSON *json = JSON_NEW_OBJECT();
|
||||
JSON_SEND_OBJECT_CODE(json, found ? 204 : 404);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -432,10 +432,14 @@ int api_queries(struct ftl_conn *api)
|
||||
|
||||
// Encoded URI string: %5B = [ and %5D = ]
|
||||
if(GET_VAR(sort_col_id, sort_col, api->request->query_string) > 0)
|
||||
{
|
||||
log_debug(DEBUG_API, "Sorting by column %s (%s)", sort_col, sort_dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
log_warn("Sorting by column %d (%s) requested, but column name not found",
|
||||
sort_column, sort_dir);
|
||||
}
|
||||
}
|
||||
|
||||
// Column searching?
|
||||
|
||||
@@ -458,7 +458,6 @@ int api_stats_top_clients(struct ftl_conn *api)
|
||||
|
||||
int api_stats_upstreams(struct ftl_conn *api)
|
||||
{
|
||||
unsigned int totalcount = 0;
|
||||
const int upstreams = counters->upstreams;
|
||||
int *temparray = calloc(2*upstreams, sizeof(int));
|
||||
if(temparray == NULL)
|
||||
@@ -480,7 +479,6 @@ int api_stats_upstreams(struct ftl_conn *api)
|
||||
|
||||
temparray[2*added_upstreams + 0] = upstreamID;
|
||||
temparray[2*added_upstreams + 1] = upstream->count;
|
||||
totalcount += upstream->count;
|
||||
|
||||
added_upstreams++;
|
||||
}
|
||||
|
||||
@@ -8,16 +8,16 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "../webserver/http-common.h"
|
||||
#include "../webserver/json_macros.h"
|
||||
#include "FTL.h"
|
||||
#include "webserver/http-common.h"
|
||||
#include "webserver/json_macros.h"
|
||||
#include "api.h"
|
||||
// querytypes[]
|
||||
#include "../datastructure.h"
|
||||
#include "datastructure.h"
|
||||
// logging routines
|
||||
#include "log.h"
|
||||
// db
|
||||
#include "../database/common.h"
|
||||
#include "database/common.h"
|
||||
|
||||
// SQL Query type filters for the database
|
||||
#define FILTER_STATUS_NOT_BLOCKED "status IN (0,2,3,12,13,14,17)"
|
||||
@@ -514,13 +514,11 @@ int api_history_database_clients(struct ftl_conn *api)
|
||||
|
||||
// Loop over clients and accumulate results
|
||||
cJSON *clients = JSON_NEW_OBJECT();
|
||||
unsigned int num_clients = 0;
|
||||
while((rc = sqlite3_step(stmt)) == SQLITE_ROW)
|
||||
{
|
||||
cJSON *item = JSON_NEW_OBJECT();
|
||||
JSON_COPY_STR_TO_OBJECT(item, "name", sqlite3_column_text(stmt, 2));
|
||||
JSON_ADD_ITEM_TO_OBJECT(clients, (const char*)sqlite3_column_text(stmt, 1), item);
|
||||
num_clients++;
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include "database/common.h"
|
||||
// MAX_ROTATIONS
|
||||
#include "files.h"
|
||||
//basename()
|
||||
#include <libgen.h>
|
||||
|
||||
#define MAXFILESIZE (50u*1024*1024)
|
||||
|
||||
@@ -795,8 +797,8 @@ static int process_received_tar_gz(struct ftl_conn *api, struct upload_data *dat
|
||||
// restore on restart
|
||||
for(unsigned int i = MAX_ROTATIONS; i > 0; i--)
|
||||
{
|
||||
const char *fname = GLOBALTOMLPATH;
|
||||
const char *filename = basename(fname);
|
||||
char *fname = strdup(GLOBALTOMLPATH);
|
||||
char *filename = basename(fname);
|
||||
// extra 6 bytes is enough space for up to 999 rotations ("/", ".", "\0", "999")
|
||||
const size_t buflen = strlen(filename) + strlen(BACKUP_DIR) + 6;
|
||||
char *path = calloc(buflen, sizeof(char));
|
||||
@@ -805,6 +807,8 @@ static int process_received_tar_gz(struct ftl_conn *api, struct upload_data *dat
|
||||
// Remove file (if it exists)
|
||||
if(remove(path) != 0 && errno != ENOENT)
|
||||
log_err("Unable to remove file \"%s\": %s", path, strerror(errno));
|
||||
|
||||
free(fname);
|
||||
}
|
||||
|
||||
// Free allocated memory
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
// NULL
|
||||
#include <stddef.h>
|
||||
// strcasecmp()
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
#include "theme.h"
|
||||
|
||||
|
||||
+6
-1
@@ -727,7 +727,12 @@ void parse_args(int argc, char* argv[])
|
||||
printf("Branch: " GIT_BRANCH "\n");
|
||||
printf("Commit: " GIT_HASH " (" GIT_DATE ")\n");
|
||||
printf("Architecture: " FTL_ARCH "\n");
|
||||
printf("Compiler: " FTL_CC "\n\n");
|
||||
printf("Compiler: " FTL_CC "\n");
|
||||
#if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
|
||||
printf("GLIBC version: %d.%d\n\n", __GLIBC__, __GLIBC_MINOR__);
|
||||
#else
|
||||
printf("GLIBC version: -\n\n");
|
||||
#endif
|
||||
|
||||
// Print dnsmasq version and compile time options
|
||||
print_dnsmasq_version(yellow, green, bold, normal);
|
||||
|
||||
+1
-1
@@ -13,4 +13,4 @@
|
||||
int set_config_from_CLI(const char *key, const char *value);
|
||||
int get_config_from_CLI(const char *key, const bool quiet);
|
||||
|
||||
#endif //CONFIG_CLI_H
|
||||
#endif //CONFIG_CLI_H
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
#define CONFIG_H
|
||||
|
||||
// enum privacy_level
|
||||
#include "../enums.h"
|
||||
#include "enums.h"
|
||||
#include <stdbool.h>
|
||||
// typedef int16_t
|
||||
#include <sys/types.h>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "log.h"
|
||||
#include <sys/inotify.h>
|
||||
// NAME_MAX
|
||||
#include <limits.h>
|
||||
#include <linux/limits.h>
|
||||
|
||||
#define WATCHDIR "/etc/pihole"
|
||||
|
||||
|
||||
+24
-17
@@ -28,7 +28,7 @@ static pthread_mutex_t lock;
|
||||
// Private prototypes
|
||||
static char *parseFTLconf(FILE *fp, const char *key);
|
||||
static void releaseConfigMemory(void);
|
||||
static char *getPath(FILE* fp, const char *option, char *ptr);
|
||||
static char *__attribute__((nonnull(1,2,3), malloc, warn_unused_result)) getPath(FILE* fp, const char *option, char *ptr);
|
||||
static bool parseBool(const char *option, bool *ptr);
|
||||
static void readDebugingSettingsLegacy(FILE *fp);
|
||||
static void getBlockingModeLegacy(FILE *fp);
|
||||
@@ -77,9 +77,12 @@ bool getLogFilePathLegacy(struct config *conf, FILE *fp)
|
||||
strerror(errno), errno);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
// Use sscanf() to obtain filename from config file parameter only if buffer != NULL
|
||||
else if(sscanf(buffer, "%127ms", &val_buffer) == 0)
|
||||
else if((val_buffer = calloc(128, sizeof(char))) == NULL || sscanf(buffer, "%127s", val_buffer) == 0)
|
||||
{
|
||||
// Free previously allocated memory (if any)
|
||||
if(conf->files.log.ftl.t == CONF_STRING_ALLOCATED)
|
||||
@@ -91,7 +94,8 @@ bool getLogFilePathLegacy(struct config *conf, FILE *fp)
|
||||
log_info("Using syslog facility");
|
||||
}
|
||||
|
||||
if(val_buffer)
|
||||
// Set string if memory allocation was successful and a value was read
|
||||
if(val_buffer != NULL && strlen(val_buffer) > 0)
|
||||
{
|
||||
// Free previously allocated memory (if any)
|
||||
if(conf->files.log.ftl.t == CONF_STRING_ALLOCATED)
|
||||
@@ -589,35 +593,38 @@ const char *readFTLlegacy(struct config *conf)
|
||||
return path;
|
||||
}
|
||||
|
||||
static char* getPath(FILE* fp, const char *option, char *ptr)
|
||||
static char *__attribute__((nonnull(1,2,3), malloc, warn_unused_result)) getPath(FILE* fp, const char *option, char *path_default)
|
||||
{
|
||||
// This subroutine is used to read paths from pihole-FTL.conf
|
||||
// fp: File ptr to opened and readable config file
|
||||
// option: Option string ("key") to try to read
|
||||
// ptr: Location where read (or default) parameter is stored
|
||||
// fp: File path to opened and readable config file
|
||||
// option: Option string ("key") to try to read
|
||||
// path_default: Location where read (or default) parameter is stored
|
||||
char *buffer = parseFTLconf(fp, option);
|
||||
|
||||
errno = 0;
|
||||
// Use sscanf() to obtain filename from config file parameter only if buffer != NULL
|
||||
if(buffer == NULL || sscanf(buffer, "%127ms", &ptr) != 1)
|
||||
{
|
||||
// Use standard path if no custom path was obtained from the config file
|
||||
return ptr;
|
||||
}
|
||||
char *val_ptr = calloc(128, sizeof(char));
|
||||
|
||||
// Test if memory allocation was successful
|
||||
if(ptr == NULL)
|
||||
if(val_ptr == NULL)
|
||||
{
|
||||
log_crit("Allocating memory for %s failed (%s, %i). Exiting.", option, strerror(errno), errno);
|
||||
log_crit("Allocating memory for %s failed (%s, %i). Exiting.",
|
||||
option, strerror(errno), errno);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else if(strlen(ptr) == 0)
|
||||
|
||||
if(buffer == NULL || sscanf(buffer, "%127s", val_ptr) != 1 || strlen(val_ptr) == 0)
|
||||
{
|
||||
// Use standard path if no custom path was obtained from the config file
|
||||
log_info(" %s: Empty path is not possible, using default",
|
||||
option);
|
||||
|
||||
strncpy(val_ptr, path_default, 127);
|
||||
val_ptr[127] = '\0';
|
||||
return val_ptr;
|
||||
}
|
||||
|
||||
return ptr;
|
||||
return val_ptr;
|
||||
}
|
||||
|
||||
static char *parseFTLconf(FILE *fp, const char * key)
|
||||
@@ -703,7 +710,7 @@ void releaseConfigMemory(void)
|
||||
void init_config_mutex(void)
|
||||
{
|
||||
// Initialize the lock attributes
|
||||
pthread_mutexattr_t lock_attr = {};
|
||||
pthread_mutexattr_t lock_attr;
|
||||
pthread_mutexattr_init(&lock_attr);
|
||||
|
||||
// Initialize the lock
|
||||
|
||||
@@ -315,10 +315,7 @@ char * __attribute__((malloc)) create_password(const char *password)
|
||||
enum password_result verify_login(const char *password)
|
||||
{
|
||||
enum password_result pw = verify_password(password, config.webserver.api.pwhash.v.s, true);
|
||||
if(pw == PASSWORD_CORRECT)
|
||||
log_debug(DEBUG_API, "Password correct");
|
||||
else
|
||||
log_debug(DEBUG_API, "Password incorrect");
|
||||
log_debug(DEBUG_API, "Password %s correct", pw == PASSWORD_CORRECT ? "" : "not");
|
||||
|
||||
// Check if an application password is set and if it matches
|
||||
if(pw == PASSWORD_INCORRECT &&
|
||||
|
||||
@@ -209,7 +209,7 @@ void print_comment(FILE *fp, const char *str, const char *intro, const unsigned
|
||||
// If this the first line? If not, add a newline
|
||||
if (i > 0)
|
||||
fputc('\n', fp);
|
||||
// Add intendation
|
||||
// Add indentation
|
||||
for (unsigned int j = 0; j != 2*indent; ++j)
|
||||
fputc(' ', fp);
|
||||
// Start a new line
|
||||
@@ -428,7 +428,7 @@ void writeTOMLvalue(FILE * fp, const int indent, const enum conf_type t, union c
|
||||
if(strlen(item->valuestring) == 0)
|
||||
continue;
|
||||
|
||||
// Add intendation (if we are indenting)
|
||||
// Add indentation (if we are indenting)
|
||||
if(indent > -1)
|
||||
indentTOML(fp, indent + 1);
|
||||
|
||||
|
||||
@@ -123,12 +123,6 @@ bool validate_dns_cnames(union conf_value *val, const char *key, char err[VALIDA
|
||||
return false;
|
||||
}
|
||||
|
||||
// Count the number of elements in the string
|
||||
unsigned int elements = 1;
|
||||
for(unsigned int j = 0; j < strlen(item->valuestring); j++)
|
||||
if(item->valuestring[j] == ',')
|
||||
elements++;
|
||||
|
||||
// Check if it's in the form "<cname>,[<cnameX>,]<target>[,<TTL>]"
|
||||
// <cnameX> is optional and may be repeated
|
||||
char *str = strdup(item->valuestring);
|
||||
@@ -398,12 +392,6 @@ bool validate_dns_revServers(union conf_value *val, const char *key, char err[VA
|
||||
return false;
|
||||
}
|
||||
|
||||
// Count the number of elements in the string
|
||||
unsigned int elements = 1;
|
||||
for(unsigned int j = 0; j < strlen(item->valuestring); j++)
|
||||
if(item->valuestring[j] == ',')
|
||||
elements++;
|
||||
|
||||
// Check if it's in the form "<enabled>,<ip-address>[/<prefix-len>],<server>[#<port>],<domain>"
|
||||
// Mandatory elements are: <enabled>, <ip-address>, <server>, and <domain>
|
||||
// Optional elements are: [/<prefix-len>] and [#<port>]
|
||||
|
||||
@@ -18,7 +18,11 @@ set(sqlite3_sources
|
||||
)
|
||||
|
||||
add_library(sqlite3 OBJECT ${sqlite3_sources})
|
||||
target_compile_options(sqlite3 PRIVATE -Wno-implicit-fallthrough -Wno-cast-function-type -Wno-sign-compare)
|
||||
target_compile_options(sqlite3 PRIVATE -Wno-implicit-fallthrough -Wno-cast-function-type -Wno-sign-compare -Wno-implicit-function-declaration -Wno-int-conversion)
|
||||
|
||||
if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||
target_compile_options(sqlite3 PRIVATE "-Wno-null-pointer-subtraction")
|
||||
endif()
|
||||
|
||||
set(database_sources
|
||||
common.c
|
||||
|
||||
@@ -8,15 +8,15 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
#include "aliasclients.h"
|
||||
#include "common.h"
|
||||
// global counters variable
|
||||
#include "../shmem.h"
|
||||
#include "shmem.h"
|
||||
// global config variable
|
||||
#include "../config/config.h"
|
||||
#include "config/config.h"
|
||||
// logging routines
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
// getAliasclientIDfromIP()
|
||||
#include "network-table.h"
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#define ALIASCLIENTS_TABLE_H
|
||||
|
||||
// type clientsData
|
||||
#include "../datastructure.h"
|
||||
#include "datastructure.h"
|
||||
|
||||
|
||||
bool create_aliasclients_table(sqlite3 *db);
|
||||
|
||||
@@ -253,11 +253,13 @@ void SQLite3LogCallback(void *pArg, int iErrCode, const char *zMsg)
|
||||
if(iErrCode == SQLITE_WARNING)
|
||||
log_warn("SQLite3: %s (%d)", zMsg, iErrCode);
|
||||
else if(iErrCode == SQLITE_NOTICE || iErrCode == SQLITE_SCHEMA)
|
||||
{
|
||||
// SQLITE_SCHEMA is returned when the database schema has changed
|
||||
// This is not necessarily an error, as sqlite3_step() will re-prepare
|
||||
// the statement and try again. If it cannot, it will return an error
|
||||
// and this will be handled over there.
|
||||
log_debug(DEBUG_ANY, "SQLite3: %s (%d)", zMsg, iErrCode);
|
||||
}
|
||||
else
|
||||
log_err("SQLite3: %s (%d)", zMsg, iErrCode);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ bool db_set_FTL_property(sqlite3* db, const enum ftl_table_props ID, const int v
|
||||
bool db_set_FTL_property_double(sqlite3* db, const enum ftl_table_props ID, const double value);
|
||||
|
||||
/// Execute a formatted SQL query and get the return code
|
||||
int dbquery(sqlite3* db, const char *format, ...) __attribute__ ((format (gnu_printf, 2, 3)));;
|
||||
int dbquery(sqlite3* db, const char *format, ...) __attribute__ ((format (printf, 2, 3)));;
|
||||
|
||||
#define dbopen(readonly, create) _dbopen(readonly, create, __FUNCTION__, __LINE__, __FILE__)
|
||||
sqlite3 *_dbopen(const bool readonly, const bool create, const char *func, const int line, const char *file) __attribute__((warn_unused_result));
|
||||
|
||||
@@ -8,29 +8,29 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
#include "sqlite3.h"
|
||||
#include "gravity-db.h"
|
||||
// struct config
|
||||
#include "../config/config.h"
|
||||
#include "config/config.h"
|
||||
// logging routines
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
// getstr()
|
||||
#include "../shmem.h"
|
||||
#include "shmem.h"
|
||||
// SQLite3 prepared statement vectors
|
||||
#include "../vector.h"
|
||||
#include "vector.h"
|
||||
// log_subnet_warning()
|
||||
// logg_inaccessible_adlist
|
||||
#include "message-table.h"
|
||||
// getMACfromIP()
|
||||
#include "network-table.h"
|
||||
// struct DNSCacheData
|
||||
#include "../datastructure.h"
|
||||
#include "datastructure.h"
|
||||
// reset_aliasclient()
|
||||
#include "aliasclients.h"
|
||||
|
||||
// Definition of struct regexData
|
||||
#include "../regex_r.h"
|
||||
#include "regex_r.h"
|
||||
|
||||
// Prefix of interface names in the client table
|
||||
#define INTERFACE_SEP ":"
|
||||
|
||||
@@ -8,21 +8,21 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
#include "network-table.h"
|
||||
#include "common.h"
|
||||
#include "../shmem.h"
|
||||
#include "../log.h"
|
||||
#include "shmem.h"
|
||||
#include "log.h"
|
||||
// timer_elapsed_msec()
|
||||
#include "../timers.h"
|
||||
#include "../config/config.h"
|
||||
#include "../datastructure.h"
|
||||
#include "timers.h"
|
||||
#include "config/config.h"
|
||||
#include "datastructure.h"
|
||||
// struct config
|
||||
#include "../config/config.h"
|
||||
#include "config/config.h"
|
||||
// resolve_this_name()
|
||||
#include "../resolve.h"
|
||||
#include "resolve.h"
|
||||
// killed
|
||||
#include "../signals.h"
|
||||
#include "signals.h"
|
||||
|
||||
// Private prototypes
|
||||
static char *getMACVendor(const char *hwaddr) __attribute__ ((malloc));
|
||||
|
||||
@@ -1120,13 +1120,13 @@ void DB_read_queries(void)
|
||||
(buffer = (const char *)sqlite3_column_text(stmt, 6)) != NULL)
|
||||
{
|
||||
// Get IP address and port of upstream destination
|
||||
char serv_addr[INET6_ADDRSTRLEN] = { 0 };
|
||||
char serv_addr[INET6_ADDRSTRLEN + 16] = { 0 };
|
||||
unsigned int serv_port = 53;
|
||||
// We limit the number of bytes written into the serv_addr buffer
|
||||
// to prevent buffer overflows. If there is no port available in
|
||||
// the database, we skip extracting them and use the default port
|
||||
sscanf(buffer, "%"xstr(INET6_ADDRSTRLEN)"[^#]#%u", serv_addr, &serv_port);
|
||||
serv_addr[INET6_ADDRSTRLEN-1] = '\0';
|
||||
serv_addr[INET6_ADDRSTRLEN + 15] = '\0';
|
||||
upstreamID = findUpstreamID(serv_addr, (in_port_t)serv_port);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
// free()
|
||||
#include <stdlib.h>
|
||||
// logging routines
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
// struct config
|
||||
#include "../config/config.h"
|
||||
#include "config/config.h"
|
||||
|
||||
// isMAC()
|
||||
#include "network-table.h"
|
||||
@@ -215,4 +215,4 @@ int sqlite3_pihole_extensions_init(sqlite3 *db, const char **pzErrMsg, const str
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,5 +65,9 @@ set(sources
|
||||
add_library(dnsmasq OBJECT ${sources})
|
||||
target_compile_definitions(dnsmasq PRIVATE VERSION=\"${DNSMASQ_VERSION}\")
|
||||
target_compile_definitions(dnsmasq PRIVATE CONFFILE=\"/etc/pihole/dnsmasq.conf\")
|
||||
target_compile_options(dnsmasq PRIVATE -Wno-maybe-uninitialized)
|
||||
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||
target_compile_options(dnsmasq PRIVATE -Wno-maybe-uninitialized -Wno-sign-compare)
|
||||
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||
target_compile_options(dnsmasq PRIVATE -Wno-gnu-variable-sized-type-not-at-end -Wno-sign-compare -Wno-deprecated-non-prototype)
|
||||
endif()
|
||||
target_include_directories(dnsmasq PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src/lua)
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
#include "dnsmasq.h"
|
||||
#include "../dnsmasq_interface.h"
|
||||
#include "dnsmasq_interface.h"
|
||||
|
||||
static struct frec *get_new_frec(time_t now, struct server *serv, int force);
|
||||
static struct frec *lookup_frec(unsigned short id, int fd, void *hash, int *firstp, int *lastp);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
#include "dnsmasq.h"
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
#ifdef HAVE_SCRIPT
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
|
||||
#include "dnsmasq.h"
|
||||
#include "../dnsmasq_interface.h"
|
||||
#include "../log.h"
|
||||
#include "dnsmasq_interface.h"
|
||||
#include "log.h"
|
||||
|
||||
#ifdef HAVE_LINUX_NETWORK
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <setjmp.h>
|
||||
|
||||
/* Pi-hole modification */
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
/************************/
|
||||
|
||||
static volatile int mem_recover = 0;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
#include "dnsmasq.h"
|
||||
#include "../dnsmasq_interface.h"
|
||||
#include "dnsmasq_interface.h"
|
||||
|
||||
int extract_name(struct dns_header *header, size_t plen, unsigned char **pp,
|
||||
char *name, int isExtract, int extrabytes)
|
||||
|
||||
@@ -200,10 +200,7 @@ size_t _FTL_make_answer(struct dns_header *header, char *limit, const size_t len
|
||||
return 0;
|
||||
|
||||
// Debug logging
|
||||
if(*ede != EDE_UNSET)
|
||||
log_debug(DEBUG_QUERIES, "Preparing reply for \"%s\", EDE: %s (%d)", name, edestr(*ede), *ede);
|
||||
else
|
||||
log_debug(DEBUG_QUERIES, "Preparing reply for \"%s\", EDE: N/A", name);
|
||||
log_debug(DEBUG_QUERIES, "Preparing reply for \"%s\", EDE: %s (%d)", name, *ede != EDE_UNSET ? edestr(*ede) : "N/A", *ede);
|
||||
|
||||
// Get question type
|
||||
int qtype, flags = 0;
|
||||
@@ -846,13 +843,17 @@ bool _FTL_new_query(const unsigned int flags, const char *name,
|
||||
if(config.debug.arp.v.b)
|
||||
{
|
||||
if(client->hwlen == 6)
|
||||
{
|
||||
log_debug(DEBUG_ARP, "find_mac(\"%s\") returned hardware address "
|
||||
"%02X:%02X:%02X:%02X:%02X:%02X", clientIP,
|
||||
client->hwaddr[0], client->hwaddr[1], client->hwaddr[2],
|
||||
client->hwaddr[3], client->hwaddr[4], client->hwaddr[5]);
|
||||
}
|
||||
else
|
||||
{
|
||||
log_debug(DEBUG_ARP, "find_mac(\"%s\") returned %i bytes of data",
|
||||
clientIP, client->hwlen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1999,10 +2000,12 @@ static void FTL_reply(const unsigned int flags, const char *name, const union al
|
||||
dispname = ".";
|
||||
|
||||
if(cached || last_server.sa.sa_family == 0)
|
||||
{
|
||||
// Log cache or upstream reply from unknown source
|
||||
log_debug(DEBUG_QUERIES, "**** got %s%s reply: %s is %s (ID %i, %s:%i)",
|
||||
stale ? "stale ": "", cached ? "cache" : "upstream",
|
||||
dispname, answer, id, file, line);
|
||||
}
|
||||
else
|
||||
{
|
||||
char ip[ADDRSTRLEN+1] = { 0 };
|
||||
|
||||
+1
-1
@@ -419,4 +419,4 @@ void FTL_parse_pseudoheaders(unsigned char *pheader, const size_t plen)
|
||||
p += optlen;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +134,7 @@ enum domain_client_status {
|
||||
} __attribute__ ((packed));
|
||||
|
||||
enum debug_flag {
|
||||
DEBUG_NONE = 0,
|
||||
DEBUG_DATABASE = 1,
|
||||
DEBUG_NETWORKING,
|
||||
DEBUG_LOCKS,
|
||||
|
||||
+1
-1
@@ -19,4 +19,4 @@ void _set_event(const enum events event, int line, const char *function, const c
|
||||
#define get_and_clear_event(event) _get_and_clear_event(event, __LINE__, __FUNCTION__, __FILE__)
|
||||
bool _get_and_clear_event(const enum events event, int line, const char *function, const char *file);
|
||||
|
||||
#endif // EVENTS_H
|
||||
#endif // EVENTS_H
|
||||
|
||||
@@ -33,6 +33,9 @@
|
||||
// PRIu64
|
||||
#include <inttypes.h>
|
||||
|
||||
//basename()
|
||||
#include <libgen.h>
|
||||
|
||||
// chmod_file() changes the file mode bits of a given file (relative
|
||||
// to the directory file descriptor) according to mode. mode is an
|
||||
// octal number representing the bit pattern for the new mode bits
|
||||
|
||||
@@ -219,12 +219,13 @@ const char *debugstr(const enum debug_flag flag)
|
||||
return "DEBUG_RESERVED";
|
||||
case DEBUG_MAX:
|
||||
return "DEBUG_MAX";
|
||||
case DEBUG_NONE: // fall through
|
||||
default:
|
||||
return "DEBUG_ANY";
|
||||
}
|
||||
}
|
||||
|
||||
void __attribute__ ((format (gnu_printf, 3, 4))) _FTL_log(const int priority, const enum debug_flag flag, const char *format, ...)
|
||||
void __attribute__ ((format (printf, 3, 4))) _FTL_log(const int priority, const enum debug_flag flag, const char *format, ...)
|
||||
{
|
||||
char timestring[TIMESTR_SIZE] = "";
|
||||
va_list args;
|
||||
@@ -321,7 +322,7 @@ void __attribute__ ((format (gnu_printf, 3, 4))) _FTL_log(const int priority, co
|
||||
}
|
||||
}
|
||||
|
||||
void __attribute__ ((format (gnu_printf, 1, 2))) log_web(const char *format, ...)
|
||||
void __attribute__ ((format (printf, 1, 2))) log_web(const char *format, ...)
|
||||
{
|
||||
char timestring[TIMESTR_SIZE] = "";
|
||||
const time_t now = time(NULL);
|
||||
@@ -362,7 +363,7 @@ void __attribute__ ((format (gnu_printf, 1, 2))) log_web(const char *format, ...
|
||||
}
|
||||
|
||||
// Log helper activity (may be script or lua)
|
||||
void FTL_log_helper(const unsigned char n, ...)
|
||||
void FTL_log_helper(const unsigned int n, ...)
|
||||
{
|
||||
// Only log helper debug messages if enabled
|
||||
if(!(config.debug.helper.v.b))
|
||||
|
||||
@@ -53,7 +53,7 @@ void log_FTL_version(bool crashreport);
|
||||
double double_time(void);
|
||||
void get_timestr(char timestring[TIMESTR_SIZE], const time_t timein, const bool millis, const bool uri_compatible);
|
||||
const char *debugstr(const enum debug_flag flag) __attribute__((const));
|
||||
void log_web(const char *format, ...) __attribute__ ((format (gnu_printf, 1, 2)));
|
||||
void log_web(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
const char *get_ordinal_suffix(unsigned int number) __attribute__ ((const));
|
||||
void print_FTL_version(void);
|
||||
unsigned int countchar(const char *str, const char c) __attribute__ ((pure));
|
||||
@@ -66,14 +66,13 @@ void dnsmasq_diagnosis_warning(char *message);
|
||||
#define log_warn(format, ...) _FTL_log(LOG_WARNING, 0, format, ## __VA_ARGS__)
|
||||
#define log_notice(format, ...) _FTL_log(LOG_NOTICE, 0, format, ## __VA_ARGS__)
|
||||
#define log_info(format, ...) _FTL_log(LOG_INFO, 0, format, ## __VA_ARGS__)
|
||||
#define log_debug(flag, format, ...)({ \
|
||||
#define log_debug(flag, format, ...) \
|
||||
if(flag > -1 && flag < DEBUG_MAX && debug_flags[flag]) \
|
||||
_FTL_log(LOG_DEBUG, flag, format, ## __VA_ARGS__); \
|
||||
})
|
||||
void _FTL_log(const int priority, const enum debug_flag flag, const char *format, ...) __attribute__ ((format (gnu_printf, 3, 4)));
|
||||
void FTL_log_dnsmasq_fatal(const char *format, ...) __attribute__ ((format (gnu_printf, 1, 2)));
|
||||
_FTL_log(LOG_DEBUG, flag, format, ## __VA_ARGS__)
|
||||
void _FTL_log(const int priority, const enum debug_flag flag, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
|
||||
void FTL_log_dnsmasq_fatal(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
void log_ctrl(bool vlog, bool vstdout);
|
||||
void FTL_log_helper(const unsigned char n, ...);
|
||||
void FTL_log_helper(const unsigned int n, ...);
|
||||
|
||||
int binbuf_to_escaped_C_literal(const char *src_buf, size_t src_sz, char *dst_str, size_t dst_sz);
|
||||
|
||||
@@ -84,7 +83,7 @@ int blocked_queries(void) __attribute__ ((pure));
|
||||
const char *short_path(const char *full_path) __attribute__ ((pure));
|
||||
|
||||
// How long is each line in the FIFO buffer allowed to be?
|
||||
#define MAX_MSG_FIFO 256u
|
||||
#define MAX_MSG_FIFO 260u
|
||||
|
||||
// How many messages do we keep in memory (FIFO message buffer)?
|
||||
// This number multiplied by MAX_MSG_FIFO (see above) gives the total buffer size
|
||||
@@ -97,9 +96,9 @@ bool flush_dnsmasq_log(void);
|
||||
|
||||
typedef struct {
|
||||
struct {
|
||||
char message[LOG_SIZE][MAX_MSG_FIFO];
|
||||
unsigned int next_id;
|
||||
double timestamp[LOG_SIZE];
|
||||
char message[LOG_SIZE][MAX_MSG_FIFO];
|
||||
const char *prio[LOG_SIZE];
|
||||
} logs[FIFO_MAX];
|
||||
} fifologData;
|
||||
|
||||
+11
-2
@@ -1,6 +1,11 @@
|
||||
set(sources
|
||||
set(ftl_sources
|
||||
ftl_lua.c
|
||||
ftl_lua.h
|
||||
)
|
||||
|
||||
add_library(ftl_lua OBJECT ${ftl_sources})
|
||||
|
||||
set(sources
|
||||
lapi.c
|
||||
lapi.h
|
||||
lauxlib.c
|
||||
@@ -65,7 +70,10 @@ set(sources
|
||||
)
|
||||
|
||||
add_library(lua OBJECT ${sources})
|
||||
target_compile_options(lua PRIVATE -Wno-maybe-uninitialized -Wno-unused-variable -Wno-unused-value)
|
||||
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||
target_compile_options(lua PRIVATE -Wno-maybe-uninitialized -Wno-unused-variable -Wno-unused-value)
|
||||
target_compile_options(ftl_lua PRIVATE -Wno-unused-value ${EXTRAWARN})
|
||||
endif()
|
||||
|
||||
# LUA_USE_POSIX: ensures recommended POSIX functions are used instead of
|
||||
# (partially obsoleted) standard C functions
|
||||
@@ -79,3 +87,4 @@ if(LUA_DL STREQUAL "true")
|
||||
endif()
|
||||
|
||||
target_include_directories(lua PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src/lua)
|
||||
target_include_directories(ftl_lua PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src/lua)
|
||||
|
||||
+20
-15
@@ -8,25 +8,33 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "ftl_lua.h"
|
||||
|
||||
#include "FTL.h"
|
||||
// struct luaL_Reg
|
||||
#include "lauxlib.h"
|
||||
// get_FTL_version()
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
// config struct
|
||||
#include "../config/config.h"
|
||||
#include "config/config.h"
|
||||
// file_exists
|
||||
#include "../files.h"
|
||||
#include "files.h"
|
||||
// get_web_theme_str
|
||||
#include "../datastructure.h"
|
||||
#if LUA_USE_READLINE
|
||||
#include <readline/history.h>
|
||||
#endif
|
||||
#include <wordexp.h>
|
||||
#include "datastructure.h"
|
||||
#include "api/api.h"
|
||||
#include "scripts/scripts.h"
|
||||
|
||||
#include "api/api.h"
|
||||
// prototype for luaopen_pihole()
|
||||
#include "lualib.h"
|
||||
|
||||
#if defined(LUA_USE_READLINE)
|
||||
# include <readline/history.h>
|
||||
#endif
|
||||
#include <wordexp.h>
|
||||
|
||||
// hostname()
|
||||
#include "daemon.h"
|
||||
|
||||
|
||||
int run_lua_interpreter(const int argc, char **argv, bool dnsmasq_debug)
|
||||
{
|
||||
@@ -100,11 +108,8 @@ static int pihole_ftl_version(lua_State *L) {
|
||||
|
||||
// pihole.hostname()
|
||||
static int pihole_hostname(lua_State *L) {
|
||||
// Get host name
|
||||
char name[256];
|
||||
if(gethostname(name, sizeof(name)) != 0)
|
||||
strcpy(name, "N/A");
|
||||
lua_pushstring(L, name);
|
||||
// Get and immediately push host name
|
||||
lua_pushstring(L, hostname());
|
||||
return 1; // number of results
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -26,4 +26,4 @@ extern int dolibrary (lua_State *L, char *name);
|
||||
void print_embedded_scripts(void);
|
||||
void ftl_lua_init(lua_State *L);
|
||||
|
||||
#endif //FTL_LUA_H
|
||||
#endif //FTL_LUA_H
|
||||
|
||||
@@ -27,8 +27,8 @@ foreach(INPUT_FILE ${COMPILED_RESOURCES})
|
||||
list(APPEND COMPILED_RESOURCES ${OUTPUT_FILE})
|
||||
endforeach()
|
||||
|
||||
# Ensure target lua_scripts is build before target lua
|
||||
add_dependencies(lua lua_scripts)
|
||||
# Ensure target lua_scripts is build before target ftl_lua depending on it
|
||||
add_dependencies(ftl_lua lua_scripts)
|
||||
|
||||
add_library(lua_scripts OBJECT ${sources})
|
||||
target_compile_options(lua_scripts PRIVATE ${EXTRAWARN})
|
||||
|
||||
@@ -28,12 +28,6 @@
|
||||
// export_queries_to_disk()
|
||||
#include "database/query-table.h"
|
||||
|
||||
#if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
|
||||
#pragma message "Minimum GLIBC version: " xstr(__GLIBC__) "." xstr(__GLIBC_MINOR__)
|
||||
#else
|
||||
#pragma message "Minimum GLIBC version: unknown, assuming this is a MUSL build"
|
||||
#endif
|
||||
|
||||
char *username;
|
||||
bool needGC = false;
|
||||
bool needDBGC = false;
|
||||
|
||||
+3
-2
@@ -8,6 +8,7 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "FTL.h"
|
||||
// close()
|
||||
#include <unistd.h>
|
||||
// clock_gettime()
|
||||
@@ -147,7 +148,7 @@ static bool get_reply(int fd, uint32_t org_[2])
|
||||
// Print current time at client
|
||||
char client_time_str[26];
|
||||
const time_t client_time = dst[0];
|
||||
ctime_r(&client_time, client_time_str);
|
||||
strncpy(client_time_str, ctime(&client_time), sizeof(client_time_str) -1);
|
||||
// Remove trailing newline
|
||||
client_time_str[24] = '\0';
|
||||
log_info("Current time at client: %s", client_time_str);
|
||||
@@ -155,9 +156,9 @@ static bool get_reply(int fd, uint32_t org_[2])
|
||||
// Print current time at server
|
||||
char server_time_str[26];
|
||||
const time_t server_time = xmt[0];
|
||||
strncpy(server_time_str, ctime(&server_time), sizeof(server_time_str) -1);
|
||||
// Remove trailing newline
|
||||
server_time_str[24] = '\0';
|
||||
ctime_r(&server_time, server_time_str);
|
||||
log_info("Current time at server: %s", server_time_str);
|
||||
|
||||
// Print offset and delay
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "FTL.h"
|
||||
// exit(0)
|
||||
#include <stdlib.h>
|
||||
// memcpy()
|
||||
|
||||
+1
-1
@@ -43,4 +43,4 @@ bool read_self_memory_status(struct statm_t *result);
|
||||
bool getProcessMemory(struct proc_mem *mem, const unsigned long total_memory);
|
||||
bool parse_proc_meminfo(struct proc_meminfo *mem);
|
||||
|
||||
#endif // PROCPS_H
|
||||
#endif // PROCPS_H
|
||||
|
||||
+19
-4
@@ -40,7 +40,7 @@ static unsigned char *name_fromDNS(unsigned char *reader, unsigned char *buffer,
|
||||
|
||||
// Avoid "error: packed attribute causes inefficient alignment for ..." on ARM32
|
||||
// builds due to the use of __attribute__((packed)) in the following structs
|
||||
// Their correct size is ensured for each by static_assert() below
|
||||
// Their correct size is ensured for each by check_struct_sizes() below
|
||||
_Pragma("GCC diagnostic push")
|
||||
_Pragma("GCC diagnostic ignored \"-Wattributes\"")
|
||||
|
||||
@@ -66,7 +66,6 @@ struct DNS_HEADER
|
||||
uint16_t auth_count; // number of authority entries
|
||||
uint16_t add_count; // number of resource entries
|
||||
} __attribute__((packed));
|
||||
static_assert(sizeof(struct DNS_HEADER) == 12);
|
||||
|
||||
// Constant sized fields of query structure
|
||||
struct QUESTION
|
||||
@@ -74,7 +73,6 @@ struct QUESTION
|
||||
uint16_t qtype;
|
||||
uint16_t qclass;
|
||||
};
|
||||
static_assert(sizeof(struct QUESTION) == 4);
|
||||
|
||||
// Constant sized fields of the resource record structure
|
||||
struct R_DATA
|
||||
@@ -84,9 +82,18 @@ struct R_DATA
|
||||
uint32_t ttl; // RFC 1035 defines the TTL field as "positive values of a signed 32bit number"
|
||||
uint16_t data_len;
|
||||
} __attribute__((packed));
|
||||
static_assert(sizeof(struct R_DATA) == 10);
|
||||
_Pragma("GCC diagnostic pop")
|
||||
|
||||
static bool check_struct_sizes(void)
|
||||
{
|
||||
// Check sizes of structs
|
||||
assert(sizeof(struct DNS_HEADER) == 12);
|
||||
assert(sizeof(struct QUESTION) == 4);
|
||||
assert(sizeof(struct R_DATA) == 10);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Pointers to resource record contents
|
||||
struct RES_RECORD
|
||||
{
|
||||
@@ -812,6 +819,14 @@ void *DNSclient_thread(void *val)
|
||||
thread_running[DNSclient] = true;
|
||||
prctl(PR_SET_NAME, thread_names[DNSclient], 0, 0, 0);
|
||||
|
||||
// Test struct sizes
|
||||
if(!check_struct_sizes())
|
||||
{
|
||||
log_err("Struct sizes do not match expected sizes, aborting resolver thread");
|
||||
thread_running[DNSclient] = false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Initial delay until we first try to resolve anything
|
||||
thread_sleepms(DNSclient, 2000);
|
||||
|
||||
|
||||
+9
-1
@@ -286,7 +286,7 @@ const char *_getstr(const size_t pos, const char *func, const int line, const ch
|
||||
// Create a mutex for shared memory
|
||||
static void create_mutex(pthread_mutex_t *lock) {
|
||||
log_debug(DEBUG_SHMEM, "Creating SHM mutex lock");
|
||||
pthread_mutexattr_t lock_attr = {};
|
||||
pthread_mutexattr_t lock_attr;
|
||||
|
||||
// Initialize the lock attributes
|
||||
pthread_mutexattr_init(&lock_attr);
|
||||
@@ -740,11 +740,15 @@ static bool realloc_shm(SharedMemory *sharedMemory, const size_t size1, const si
|
||||
|
||||
// Log output
|
||||
if(resize)
|
||||
{
|
||||
log_debug(DEBUG_SHMEM, "Resizing \"%s\" from %zu to (%zu * %zu) == %zu (%s)",
|
||||
sharedMemory->name, sharedMemory->size, size1, size2, size, df);
|
||||
}
|
||||
else
|
||||
{
|
||||
log_debug(DEBUG_SHMEM, "Remapping \"%s\" from %zu to (%zu * %zu) == %zu",
|
||||
sharedMemory->name, sharedMemory->size, size1, size2, size);
|
||||
}
|
||||
|
||||
if(config.misc.check.shmem.v.ui > 0 && percentage > config.misc.check.shmem.v.ui)
|
||||
log_resource_shortage(-1.0, 0, percentage, -1, SHMEM_PATH, df);
|
||||
@@ -801,11 +805,15 @@ static bool realloc_shm(SharedMemory *sharedMemory, const size_t size1, const si
|
||||
used_shmem += (size - sharedMemory->size);
|
||||
|
||||
if(sharedMemory->ptr == new_ptr)
|
||||
{
|
||||
log_debug(DEBUG_SHMEM, "SHMEM pointer not updated: %p (%zu %zu)",
|
||||
sharedMemory->ptr, sharedMemory->size, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
log_debug(DEBUG_SHMEM, "SHMEM pointer updated: %p -> %p (%zu %zu)",
|
||||
sharedMemory->ptr, new_ptr, sharedMemory->size, size);
|
||||
}
|
||||
|
||||
sharedMemory->ptr = new_ptr;
|
||||
sharedMemory->size = size;
|
||||
|
||||
+1
-1
@@ -15,4 +15,4 @@
|
||||
|
||||
int check_one_struct(const char *struct_name, const size_t found_size, const size_t size64, const size_t size32);
|
||||
|
||||
#endif // STRUCT_SIZE_HEADER
|
||||
#endif // STRUCT_SIZE_HEADER
|
||||
|
||||
@@ -36,3 +36,4 @@ set(sources
|
||||
|
||||
add_library(syscalls OBJECT ${sources})
|
||||
target_compile_options(syscalls PRIVATE ${EXTRAWARN})
|
||||
target_include_directories(syscalls PRIVATE ${PROJECT_SOURCE_DIR}/src)
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
#undef accept
|
||||
int FTLaccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen, const char *file, const char *func, const int line)
|
||||
@@ -39,4 +39,4 @@ int FTLaccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen, const char
|
||||
errno = _errno;
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
int FTLasprintf(const char *file, const char *func, const int line, char **buffer, const char *format, ...)
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
#undef calloc
|
||||
void* __attribute__((malloc)) __attribute__((alloc_size(1,2))) FTLcalloc(const size_t nmemb, const size_t size, const char *file, const char *func, const int line)
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
static uint8_t already_writing = 0;
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
int FTLfprintf(FILE *stream, const char *file, const char *func, const int line, const char *format, ...)
|
||||
{
|
||||
|
||||
+2
-2
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
#undef free
|
||||
void FTLfree(void **ptr, const char *file, const char *func, const int line)
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
#include <fcntl.h>
|
||||
|
||||
// off_t is automatically set as off64_t when this is a 64bit system
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
#undef realloc
|
||||
void __attribute__((alloc_size(2))) *FTLrealloc(void *ptr_in, const size_t size, const char * file, const char * func, const int line)
|
||||
|
||||
+3
-3
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
@@ -41,4 +41,4 @@ ssize_t FTLrecv(int sockfd, void *buf, size_t len, int flags, const char *file,
|
||||
errno = _errno;
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
@@ -45,4 +45,4 @@ ssize_t FTLrecvfrom(int sockfd, void *buf, size_t len, int flags, struct sockadd
|
||||
errno = _errno;
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <sys/select.h>
|
||||
|
||||
@@ -41,4 +41,4 @@ int FTLselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, st
|
||||
errno = _errno;
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
@@ -43,4 +43,4 @@ ssize_t FTLsendto(int sockfd, void *buf, size_t len, int flags, const struct soc
|
||||
errno = _errno;
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
int FTLsnprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const size_t maxlen, const char *format, ...)
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
int FTLsprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const char *format, ...)
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
char* __attribute__((malloc)) FTLstrdup(const char *src, const char *file, const char *func, const int line)
|
||||
{
|
||||
@@ -35,4 +35,4 @@ char* __attribute__((malloc)) FTLstrdup(const char *src, const char *file, const
|
||||
dest[len] = '\0';
|
||||
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
#undef strlen
|
||||
size_t FTLstrlen(const char *s, const char *file, const char *func, const int line)
|
||||
|
||||
@@ -21,17 +21,17 @@ int FTLfallocate(const int fd, const off_t offset, const off_t len, const char *
|
||||
// Interrupt-safe printing routines
|
||||
// printf() is derived from fprintf(stdout, ...)
|
||||
// vprintf() is derived from vfprintf(stdout, ...)
|
||||
int FTLfprintf(FILE *stream, const char*file, const char *func, const int line, const char *format, ...) __attribute__ ((format (gnu_printf, 5, 6)));
|
||||
int FTLvfprintf(FILE *stream, const char*file, const char *func, const int line, const char *format, va_list args) __attribute__ ((format (gnu_printf, 5, 0)));
|
||||
int FTLfprintf(FILE *stream, const char*file, const char *func, const int line, const char *format, ...) __attribute__ ((format (printf, 5, 6)));
|
||||
int FTLvfprintf(FILE *stream, const char*file, const char *func, const int line, const char *format, va_list args) __attribute__ ((format (printf, 5, 0)));
|
||||
|
||||
int FTLsprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const char *format, ...) __attribute__ ((format (gnu_printf, 5, 6)));
|
||||
int FTLvsprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const char *format, va_list args) __attribute__ ((format (gnu_printf, 5, 0)));
|
||||
int FTLsprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const char *format, ...) __attribute__ ((format (printf, 5, 6)));
|
||||
int FTLvsprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const char *format, va_list args) __attribute__ ((format (printf, 5, 0)));
|
||||
|
||||
int FTLasprintf(const char *file, const char *func, const int line, char **buffer, const char *format, ...) __attribute__ ((format (gnu_printf, 5, 6)));
|
||||
int FTLvasprintf(const char *file, const char *func, const int line, char **buffer, const char *format, va_list args) __attribute__ ((format (gnu_printf, 5, 0)));
|
||||
int FTLasprintf(const char *file, const char *func, const int line, char **buffer, const char *format, ...) __attribute__ ((format (printf, 5, 6)));
|
||||
int FTLvasprintf(const char *file, const char *func, const int line, char **buffer, const char *format, va_list args) __attribute__ ((format (printf, 5, 0)));
|
||||
|
||||
int FTLsnprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const size_t maxlen, const char *format, ...) __attribute__ ((format (gnu_printf, 6, 7)));
|
||||
int FTLvsnprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const size_t maxlen, const char *format, va_list args) __attribute__ ((format (gnu_printf, 6, 0)));
|
||||
int FTLsnprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const size_t maxlen, const char *format, ...) __attribute__ ((format (printf, 6, 7)));
|
||||
int FTLvsnprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const size_t maxlen, const char *format, va_list args) __attribute__ ((format (printf, 6, 0)));
|
||||
|
||||
// Interrupt-safe socket routines
|
||||
ssize_t FTLwrite(int fd, const void *buf, size_t total, const char *file, const char *func, const int line);
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
#undef vasprintf
|
||||
int FTLvasprintf(const char *file, const char *func, const int line, char **buffer, const char *format, va_list args)
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
// itoa implementation using only static memory
|
||||
// taken from Kernighan and Ritchie's "The C Programming Language"
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
#undef vsnprintf
|
||||
int FTLvsnprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const size_t maxlen, const char *format, va_list args)
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
#undef vsprintf
|
||||
int FTLvsprintf(const char *file, const char *func, const int line, char *__restrict__ buffer, const char *format, va_list args)
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "../FTL.h"
|
||||
#include "FTL.h"
|
||||
//#include "syscalls.h" is implicitly done in FTL.h
|
||||
#include "../log.h"
|
||||
#include "log.h"
|
||||
|
||||
#undef write
|
||||
ssize_t FTLwrite(int fd, const void *buf, size_t total, const char *file, const char *func, const int line)
|
||||
@@ -50,4 +50,4 @@ ssize_t FTLwrite(int fd, const void *buf, size_t total, const char *file, const
|
||||
|
||||
// Return number of written bytes
|
||||
return written;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,7 +381,7 @@ static void *arp_scan_iface(void *args)
|
||||
thread_data->dst_cidr = netmask_to_cidr(&thread_data->mask.sin_addr);
|
||||
|
||||
// Get interface index
|
||||
const int ifindex = if_nametoindex(iface);
|
||||
const int ifindex = (int)if_nametoindex(iface);
|
||||
|
||||
// Scan only interfaces with CIDR >= 24
|
||||
if(thread_data->dst_cidr < 24 && !thread_data->scan_all)
|
||||
@@ -701,7 +701,7 @@ int run_arp_scan(const bool scan_all, const bool extreme_mode)
|
||||
{
|
||||
// Calculate progress (total number of scans / total number of addresses)
|
||||
// We add 1 to total_scans to avoid division by zero
|
||||
const unsigned int new_progress = 100 * num_scans / (total_scans + 1);
|
||||
const unsigned int new_progress = 100 * (unsigned int)(num_scans / (total_scans + 1));
|
||||
if(new_progress > progress)
|
||||
{
|
||||
// Print progress
|
||||
|
||||
@@ -54,15 +54,12 @@
|
||||
// we scan for DHCP activity.
|
||||
#define MAXTHREADS 32
|
||||
|
||||
// Probe DHCP servers responding to the broadcast address
|
||||
#define PROBE_BCAST
|
||||
|
||||
// Should we generate test data for DHCP option 249?
|
||||
//#define TEST_OPT_249
|
||||
|
||||
// Global lock used by all threads
|
||||
static pthread_mutex_t lock;
|
||||
static void __attribute__((format(gnu_printf, 1, 2))) printf_locked(const char *format, ...)
|
||||
static void __attribute__((format(printf, 1, 2))) printf_locked(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
@@ -179,7 +176,7 @@ struct dhcp_packet_data
|
||||
unsigned char chaddr [MAX_DHCP_CHADDR_LENGTH]; // hardware address of this machine
|
||||
char sname [MAX_DHCP_SNAME_LENGTH]; // name of DHCP server
|
||||
char file [MAX_DHCP_FILE_LENGTH]; // boot file name (used for diskless booting?)
|
||||
char options[MAX_DHCP_OPTIONS_LENGTH]; // options
|
||||
unsigned char options[MAX_DHCP_OPTIONS_LENGTH]; // options
|
||||
};
|
||||
|
||||
// sends a DHCPDISCOVER message to the specified in an attempt to find DHCP servers
|
||||
@@ -219,7 +216,7 @@ static bool send_dhcp_discover(const int sock, const uint32_t xid, const char *i
|
||||
discover_packet.options[6] = 1; // DHCP message type code for DHCPDISCOVER
|
||||
|
||||
// Place end option at the end of the options
|
||||
discover_packet.options[7] = 255;
|
||||
discover_packet.options[7] = (char)255;
|
||||
|
||||
// Send the DHCPDISCOVER packet to the specified address
|
||||
struct sockaddr_in target = { 0 };
|
||||
@@ -236,7 +233,7 @@ static bool send_dhcp_discover(const int sock, const uint32_t xid, const char *i
|
||||
printf_locked("DHCDISCOVER giaddr: %s\n", inet_ntoa(discover_packet.giaddr));
|
||||
#endif
|
||||
// send the DHCPDISCOVER packet
|
||||
const int bytes = sendto(sock, (char *)&discover_packet, sizeof(discover_packet), 0, (struct sockaddr *)&target, sizeof(target));
|
||||
const ssize_t bytes = sendto(sock, (char *)&discover_packet, sizeof(discover_packet), 0, (struct sockaddr *)&target, sizeof(target));
|
||||
if(bytes < 0)
|
||||
{
|
||||
// strerror() returns "Required key not available" for ENOKEY
|
||||
@@ -250,7 +247,7 @@ static bool send_dhcp_discover(const int sock, const uint32_t xid, const char *i
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
printf_locked("Sent %d bytes\n", bytes);
|
||||
printf_locked("Sent %zu bytes\n", (size_t)bytes);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
@@ -340,7 +337,7 @@ static void print_dhcp_offer(struct in_addr source, struct dhcp_packet_data *off
|
||||
// possible "(empty)"
|
||||
const size_t bufsiz = 4*optlen + 9;
|
||||
char *buffer = calloc(bufsiz, sizeof(char));
|
||||
binbuf_to_escaped_C_literal(&offer_packet->options[x], optlen, buffer, bufsiz);
|
||||
binbuf_to_escaped_C_literal((char*)&offer_packet->options[x], optlen, buffer, bufsiz);
|
||||
printf("%s: \"%s\"\n", opttab[i].name, buffer);
|
||||
free(buffer);
|
||||
}
|
||||
@@ -428,7 +425,7 @@ static void print_dhcp_offer(struct in_addr source, struct dhcp_packet_data *off
|
||||
// chars per control character plus room for
|
||||
// possible "(empty)"
|
||||
char *buffer = calloc(4*optlen + 9, sizeof(char));
|
||||
binbuf_to_escaped_C_literal(&offer_packet->options[x], optlen, buffer, sizeof(buffer));
|
||||
binbuf_to_escaped_C_literal((char*)&offer_packet->options[x], optlen, buffer, sizeof(buffer));
|
||||
printf("wpad-server: \"%s\"\n", buffer);
|
||||
free(buffer);
|
||||
}
|
||||
@@ -730,7 +727,7 @@ int run_dhcp_discover(void)
|
||||
pthread_attr_init(&attr);
|
||||
|
||||
// Create processing/printfing lock
|
||||
pthread_mutexattr_t lock_attr = {};
|
||||
pthread_mutexattr_t lock_attr;
|
||||
// Initialize the lock attributes
|
||||
pthread_mutexattr_init(&lock_attr);
|
||||
// Initialize the lock
|
||||
|
||||
@@ -27,4 +27,6 @@ set(sources
|
||||
)
|
||||
|
||||
add_library(tre-regex OBJECT ${sources})
|
||||
target_compile_options(tre-regex PRIVATE -Wno-maybe-uninitialized -Wno-unused-value -Wno-empty-body)
|
||||
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||
target_compile_options(tre-regex PRIVATE -Wno-maybe-uninitialized -Wno-unused-value -Wno-empty-body)
|
||||
endif()
|
||||
|
||||
@@ -10,17 +10,17 @@
|
||||
/* #undef C_ALLOCA */
|
||||
|
||||
/* Define to 1 if you have `alloca', as a function or macro. */
|
||||
#define HAVE_ALLOCA 1
|
||||
#define HAVE_ALLOCA 0
|
||||
|
||||
/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
|
||||
*/
|
||||
#define HAVE_ALLOCA_H 1
|
||||
#define HAVE_ALLOCA_H 0
|
||||
|
||||
/* Define if the GNU gettext() function is already present or preinstalled. */
|
||||
/* #define HAVE_GETTEXT 1 */
|
||||
|
||||
/* Define to 1 if you have the `isascii' function. */
|
||||
#define HAVE_ISASCII 1
|
||||
//#define HAVE_ISASCII 1
|
||||
|
||||
/* Define to 1 if you have the `isblank' function. */
|
||||
#define HAVE_ISBLANK 1
|
||||
@@ -72,7 +72,7 @@
|
||||
|
||||
/* Define if you want TRE to use alloca() instead of malloc() when allocating
|
||||
memory needed for regexec operations. */
|
||||
#define TRE_USE_ALLOCA 1
|
||||
// #define TRE_USE_ALLOCA 1
|
||||
|
||||
/* Define to include the system regex.h from TRE regex.h */
|
||||
/* #undef TRE_USE_SYSTEM_REGEX_H */
|
||||
|
||||
@@ -340,6 +340,7 @@ xrealloc_impl(void *ptr, size_t new_size, const char *file, int line,
|
||||
new_ptr = realloc(ptr, new_size);
|
||||
if (new_ptr != NULL)
|
||||
{
|
||||
ptr = NULL;
|
||||
hash_table_del(xmalloc_table, ptr);
|
||||
hash_table_add(xmalloc_table, new_ptr, (int)new_size, file, line, func);
|
||||
}
|
||||
|
||||
@@ -18,4 +18,4 @@ void free_lua(void);
|
||||
void init_lua(const struct mg_connection *conn, void *L, unsigned context_flags);
|
||||
int request_handler(struct mg_connection *conn, void *cbdata);
|
||||
|
||||
#endif // LUA_WEB_H
|
||||
#endif // LUA_WEB_H
|
||||
|
||||
@@ -469,7 +469,8 @@ void http_init(void)
|
||||
}
|
||||
|
||||
// Configure logging handlers
|
||||
struct mg_callbacks callbacks = { NULL };
|
||||
struct mg_callbacks callbacks;
|
||||
memset(&callbacks, 0, sizeof(callbacks));
|
||||
callbacks.log_message = log_http_message;
|
||||
callbacks.log_access = log_http_access;
|
||||
callbacks.init_lua = init_lua;
|
||||
|
||||
@@ -18,4 +18,4 @@ void http_terminate(void);
|
||||
in_port_t get_https_port(void) __attribute__((pure));
|
||||
unsigned short get_api_string(char **buf, const bool domain);
|
||||
|
||||
#endif // WEBSERVER_H
|
||||
#endif // WEBSERVER_H
|
||||
|
||||
+16
-6
@@ -8,14 +8,16 @@
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
#include "gzip.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
// le32toh and friends
|
||||
#define __USE_MISC
|
||||
#include <endian.h>
|
||||
#include "gzip.h"
|
||||
#include "log.h"
|
||||
|
||||
static int mz_uncompress2_raw(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong *pSource_len);
|
||||
|
||||
@@ -92,7 +94,7 @@ static bool deflate_buffer(const unsigned char *buffer_uncompressed, const mz_ul
|
||||
// ITU-T V.42.)
|
||||
// isize: This contains the size of the original (uncompressed) input
|
||||
// data modulo 2^32 (little endian).
|
||||
const uint32_t crc = mz_crc32(MZ_CRC32_INIT, buffer_uncompressed, size_uncompressed);
|
||||
const uint32_t crc = (uint32_t)mz_crc32(MZ_CRC32_INIT, buffer_uncompressed, size_uncompressed);
|
||||
memcpy(*buffer_compressed + *size_compressed, &crc, sizeof(crc));
|
||||
*size_compressed += sizeof(crc);
|
||||
const uint32_t isize = htole32(size_uncompressed);
|
||||
@@ -313,7 +315,15 @@ bool inflate_file(const char *infilename, const char *outfilename, bool verbose)
|
||||
|
||||
// Get file size
|
||||
fseek(infile, 0, SEEK_END);
|
||||
const mz_ulong size_compressed = ftell(infile);
|
||||
const long sc = ftell(infile);
|
||||
if(sc < 0)
|
||||
{
|
||||
log_warn("Failed to get file size of %s", infilename);
|
||||
fclose(infile);
|
||||
fclose(outfile);
|
||||
return false;
|
||||
}
|
||||
const mz_ulong size_compressed = (mz_ulong)sc;
|
||||
fseek(infile, 0, SEEK_SET);
|
||||
|
||||
// Read file into memory
|
||||
@@ -398,7 +408,7 @@ bool deflate_file(const char *infilename, const char *outfilename, bool verbose)
|
||||
|
||||
// Get file size
|
||||
fseek(infile, 0, SEEK_END);
|
||||
const mz_ulong size_uncompressed = ftell(infile);
|
||||
const long size_uncompressed = ftell(infile);
|
||||
fseek(infile, 0, SEEK_SET);
|
||||
|
||||
// Read file into memory
|
||||
@@ -410,7 +420,7 @@ bool deflate_file(const char *infilename, const char *outfilename, bool verbose)
|
||||
fclose(outfile);
|
||||
return false;
|
||||
}
|
||||
if(fread(buffer_uncompressed, 1, size_uncompressed, infile) != size_uncompressed)
|
||||
if(fread(buffer_uncompressed, 1, size_uncompressed, infile) != (size_t)size_uncompressed)
|
||||
{
|
||||
log_warn("Failed to read %lu bytes from %s", (unsigned long)size_uncompressed, infilename);
|
||||
fclose(infile);
|
||||
|
||||
@@ -14,5 +14,5 @@ set(sources
|
||||
)
|
||||
|
||||
add_library(miniz OBJECT ${sources})
|
||||
target_compile_options(miniz PRIVATE)
|
||||
target_compile_options(miniz PRIVATE -Wno-padded -Wno-type-limits)
|
||||
target_include_directories(miniz PRIVATE ${PROJECT_SOURCE_DIR}/src)
|
||||
|
||||
@@ -1419,4 +1419,4 @@ MINIZ_EXPORT void *mz_zip_extract_archive_file_to_heap_v2(const char *pZip_filen
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MINIZ_NO_ARCHIVE_APIS */
|
||||
#endif /* MINIZ_NO_ARCHIVE_APIS */
|
||||
|
||||
+1
-1
@@ -125,4 +125,4 @@ cJSON * __attribute__((nonnull (1))) list_files_in_tar(const uint8_t *tarData, c
|
||||
} while (p + newOffset + TAR_BLOCK_SIZE <= tarSize);
|
||||
|
||||
return files;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -16,4 +16,4 @@
|
||||
const char *find_file_in_tar(const uint8_t *tar, const size_t tarSize, const char *fileName, size_t *fileSize) __attribute__((nonnull (1,3,4)));
|
||||
cJSON *list_files_in_tar(const uint8_t *tarData, const size_t tarSize) __attribute__((nonnull (1)));
|
||||
|
||||
#endif // TAR_H
|
||||
#endif // TAR_H
|
||||
|
||||
+10
-4
@@ -95,10 +95,16 @@ check_minimum_glibc_version() {
|
||||
|
||||
if [[ "${CI_ARCH}" == "linux/amd64" ]]; then
|
||||
|
||||
check_machine "ELF64" "Advanced Micro Devices X86-64"
|
||||
check_static # Binary should not rely on any dynamic interpreter
|
||||
check_libs "" # No dependency on any shared library is intended
|
||||
check_file "ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped"
|
||||
if [[ "${STATIC}" == "true" ]]; then
|
||||
check_machine "ELF64" "Advanced Micro Devices X86-64"
|
||||
check_static # Binary should not rely on any dynamic interpreter
|
||||
check_libs "" # No dependency on any shared library is intended
|
||||
check_file "ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped"
|
||||
else
|
||||
check_machine "ELF64" "Advanced Micro Devices X86-64"
|
||||
check_libs "[libgmp.so.10] [libidn2.so.0] [libc.musl-x86_64.so.1]"
|
||||
check_file "ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, with debug_info, not stripped"
|
||||
fi
|
||||
|
||||
elif [[ "${CI_ARCH}" == "linux/386" ]]; then
|
||||
|
||||
|
||||
@@ -73,6 +73,9 @@ export FTLCONF_misc_nice="-11"
|
||||
export FTLCONF_dns_upstrrr="-11"
|
||||
export FTLCONF_debug_api="not_a_bool"
|
||||
|
||||
# Prepare gdb session
|
||||
echo "handle SIGHUP nostop SIGPIPE nostop SIGTERM nostop SIG32 nostop SIG33 nostop SIG34 nostop SIG35 nostop SIG41 nostop" > /root/.gdbinit
|
||||
|
||||
# Start FTL
|
||||
if ! su pihole -s /bin/sh -c /home/pihole/pihole-FTL; then
|
||||
echo "pihole-FTL failed to start"
|
||||
@@ -89,6 +92,10 @@ fi
|
||||
# Give FTL some time for startup preparations
|
||||
sleep 2
|
||||
|
||||
# Attach debugger and immediately continue running the binary
|
||||
# In case a non-ignored signal occurs (a crash), create a full backtrace
|
||||
gdb -p $(cat /run/pihole-FTL.pid) --ex continue --ex "bt full" &
|
||||
|
||||
# Print versions of pihole-FTL
|
||||
echo -n "FTL version (DNS): "
|
||||
dig TXT CHAOS version.FTL @127.0.0.1 +short
|
||||
@@ -130,6 +137,7 @@ if [[ $RET != 0 ]]; then
|
||||
fi
|
||||
|
||||
# Kill pihole-FTL after having completed tests
|
||||
# This will also shut down the debugger
|
||||
kill "$(pidof pihole-FTL)"
|
||||
|
||||
# Restore umask
|
||||
|
||||
@@ -972,19 +972,6 @@
|
||||
[[ "${STATIC}" == "true" && "${lines[@]}" != *"interpreter"* ]]
|
||||
}
|
||||
|
||||
@test "Architecture is correctly reported on startup" {
|
||||
run bash -c 'grep "Compiled for" /var/log/pihole/FTL.log'
|
||||
printf "Output: %s\n\$CI_ARCH: %s\nuname -m: %s\n" "${lines[@]:-not set}" "${CI_ARCH:-not set}" "$(uname -m)"
|
||||
[[ ${lines[0]} == *"Compiled for ${CI_ARCH:-$(uname -m)}"* ]]
|
||||
}
|
||||
|
||||
@test "Building machine (CI) is reported on startup" {
|
||||
[[ ${CI_ARCH} != "" ]] && compiled_str="on CI" || compiled_str="locally" && export compiled_str
|
||||
run bash -c 'grep "Compiled for" /var/log/pihole/FTL.log'
|
||||
printf "Output: %s\n\$CI_ARCH: %s\n" "${lines[@]:-not set}" "${CI_ARCH:-not set}"
|
||||
[[ ${lines[0]} == *"(compiled ${compiled_str})"* ]]
|
||||
}
|
||||
|
||||
@test "Compiler version is correctly reported on startup" {
|
||||
compiler_version="$(${CC} --version | head -n1)" && export compiler_version
|
||||
run bash -c 'grep "Compiled for" /var/log/pihole/FTL.log'
|
||||
|
||||
Reference in New Issue
Block a user