Skip to content

Commit

Permalink
Add: openvasd library (#826)
Browse files Browse the repository at this point in the history
* Add: openvasd library
Function and structure for talking with openvasd via Openvasd API
Add: function for parsing string containing the feed in json format
Replace libjson-glib with libcjson
Use json pull for parsing the feed metadata
Adjust CMakeLists.txt file

* Remove gvm_json_pull_event_reset() because duplicates gvm_json_pull_event_cleanup()
  • Loading branch information
jjnicola authored Nov 11, 2024
1 parent 08ef292 commit b9aa11d
Show file tree
Hide file tree
Showing 13 changed files with 3,108 additions and 22 deletions.
1 change: 1 addition & 0 deletions .docker/prod-oldstable.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ RUN apt-get update && \
libgpgme11 \
libgnutls30 \
libuuid1 \
libjson-glib-1.0-0 \
libssh-gcrypt-4 \
libhiredis0.14 \
libxml2 \
Expand Down
1 change: 1 addition & 0 deletions .docker/prod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ RUN apt-get update && \
libglib2.0-0 \
libgpgme11 \
libgnutls30 \
libjson-glib-1.0-0 \
libuuid1 \
libssh-gcrypt-4 \
libhiredis0.14 \
Expand Down
2 changes: 2 additions & 0 deletions .github/install-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ apt-get update && \
pkg-config \
gnupg \
libcjson-dev \
libcurl4-openssl-dev \
libjson-glib-dev \
libglib2.0-dev \
libgpgme-dev \
libgnutls28-dev \
Expand Down
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ find_program (CLANG_FORMAT clang-format)

if (CLANG_FORMAT)
message (STATUS "Looking for clang-format... ${CLANG_FORMAT}")
add_custom_target(format COMMAND ${CLANG_FORMAT} "-i" "./base/*.c"
"./boreas/*.c" "./gmp/*.c" "./osp/*.c" "./util/*.c"
"./base/*.h" "./boreas/*.h" "./gmp/*.h" "./osp/*.h"
"./util/*.h" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
add_custom_target(format COMMAND ${CLANG_FORMAT} "-i" "./base/*.c"
"./boreas/*.c" "./gmp/*.c" "./openvasd/*.c" "./osp/*.c"
"./util/*.c" "./base/*.h" "./boreas/*.h" "./gmp/*.h"
"./openvasd/*.h" "./osp/*.h" "./util/*.h"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
else (CLANG_FORMAT)
message (STATUS "clang-format not found...")
endif (CLANG_FORMAT)
Expand Down Expand Up @@ -257,6 +258,7 @@ if (NOT SKIP_SRC)
add_subdirectory (base)
add_subdirectory (boreas)
add_subdirectory (util)
add_subdirectory (openvasd)
add_subdirectory (osp)
add_subdirectory (gmp)
endif (NOT SKIP_SRC)
Expand Down
2 changes: 2 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ General build environment:

Specific development libraries:
* libcjson >= 1.7.14 (util)
* libcurl >= 7.74.0 (openvasd)
* libglib >= 2.42 (all)
* libgio >= 2.42 (util)
* zlib >= 1.2.8 (util)
Expand Down Expand Up @@ -45,6 +46,7 @@ Install prerequisites on Debian GNU/Linux 'Bullseye' 11:
cmake \
pkg-config \
libcjson-dev \
libcurl4-openssl-dev \
libglib2.0-dev \
libgpgme-dev \
libgnutls28-dev \
Expand Down
1 change: 1 addition & 0 deletions doc/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ WARN_LOGFILE =

INPUT = @CMAKE_SOURCE_DIR@/base \
@CMAKE_SOURCE_DIR@/gmp \
@CMAKE_SOURCE_DIR@/openvasd \
@CMAKE_SOURCE_DIR@/osp \
@CMAKE_SOURCE_DIR@/util

Expand Down
68 changes: 68 additions & 0 deletions openvasd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# SPDX-FileCopyrightText: 2015-2023 Greenbone AG
#
# SPDX-License-Identifier: GPL-2.0-or-later

## Library

include (FindPkgConfig)

if (NOT PKG_CONFIG_FOUND)
message(FATAL_ERROR "pkg-config executable not found. Aborting.")
endif (NOT PKG_CONFIG_FOUND)

## Dependency checks

pkg_check_modules (GLIB REQUIRED glib-2.0>=2.42)
pkg_check_modules (CURL REQUIRED libcurl>=7.74.0)

# for json parsing we need cJSON
pkg_check_modules (CJSON REQUIRED libcjson>=1.7.14)
pkg_check_modules (GLIB_JSON REQUIRED json-glib-1.0>=1.4.4)


include_directories (${GLIB_INCLUDE_DIRS} ${GLIB_JSON_INCLUDE_DIRS}
${CURL_INCLUDE_DIRS})

set (FILES openvasd.c vtparser.c)
set (HEADERS openvasd.h)

if (BUILD_STATIC)
add_library (gvm_openvasd_static STATIC ${FILES})
set_target_properties (gvm_openvasd_static PROPERTIES OUTPUT_NAME "gvm_openvasd")
set_target_properties (gvm_openvasd_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
set_target_properties (gvm_openvasd_static PROPERTIES PUBLIC_HEADER "${HEADERS}")
endif (BUILD_STATIC)

if (BUILD_SHARED)
add_library (gvm_openvasd_shared SHARED ${FILES})
set_target_properties (gvm_openvasd_shared PROPERTIES OUTPUT_NAME "gvm_openvasd")
set_target_properties (gvm_openvasd_shared PROPERTIES CLEAN_DIRECT_OUTPUT 1)
set_target_properties (gvm_openvasd_shared PROPERTIES SOVERSION "${PROJECT_VERSION_MAJOR}")
set_target_properties (gvm_openvasd_shared PROPERTIES VERSION "${CPACK_PACKAGE_VERSION}")
set_target_properties (gvm_openvasd_shared PROPERTIES PUBLIC_HEADER "${HEADERS}")

target_link_libraries (gvm_openvasd_shared LINK_PRIVATE ${GLIB_LDFLAGS} ${GLIB_JSON_LDFLAGS}
${CURL_LDFLAGS} ${LINKER_HARDENING_FLAGS})
endif (BUILD_SHARED)

## Install
configure_file (libgvm_openvasd.pc.in ${CMAKE_BINARY_DIR}/libgvm_openvasd.pc @ONLY)

install (FILES ${CMAKE_BINARY_DIR}/libgvm_openvasd.pc
DESTINATION ${LIBDIR}/pkgconfig)

if (BUILD_STATIC)
install (TARGETS gvm_openvasd_static
RUNTIME DESTINATION ${BINDIR}
ARCHIVE DESTINATION ${LIBDIR}
PUBLIC_HEADER DESTINATION "${INCLUDEDIR}/gvm/openvasd")
endif (BUILD_STATIC)
if (BUILD_SHARED)
install (TARGETS gvm_openvasd_shared
RUNTIME DESTINATION ${BINDIR}
LIBRARY DESTINATION ${LIBDIR}
ARCHIVE DESTINATION ${LIBDIR}
PUBLIC_HEADER DESTINATION "${INCLUDEDIR}/gvm/openvasd")
endif (BUILD_SHARED)

## End
11 changes: 11 additions & 0 deletions openvasd/libgvm_openvasd.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@EXEC_PREFIX@
libdir=@LIBDIR@
includedir=@INCLUDEDIR@

Name: gvmlibs-openvasd
Description: Greenbone Vulnerability Management Library openvasd
Version: @LIBGVMCONFIG_VERSION@
Requires.private: glib-2.0 >= 2.42.0
Cflags: -I${includedir} -I${includedir}/gvm
Libs: -L${libdir} -lgvm_openvasd
Loading

0 comments on commit b9aa11d

Please sign in to comment.