Skip to content

Commit

Permalink
Add: openvasd library
Browse files Browse the repository at this point in the history
Function and structure for talking with openvasd via Openvasd API
  • Loading branch information
jjnicola committed Jul 4, 2024
1 parent 59833c9 commit 415b163
Show file tree
Hide file tree
Showing 5 changed files with 1,982 additions and 4 deletions.
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
86 changes: 86 additions & 0 deletions openvasd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# 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 (GLIB_JSON REQUIRED json-glib-1.0>=1.4.4)
pkg_check_modules (CURL REQUIRED libcurl>=7.74.0)

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

set (FILES openvasd.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)


## Tests

if (BUILD_TESTS)
add_executable (openvasd-test
EXCLUDE_FROM_ALL
openvasd_tests.c)

add_test (openvasd-test openvasd-test)

target_include_directories (openvasd-test PRIVATE ${CGREEN_INCLUDE_DIRS})

target_link_libraries (openvasd-test gvm_base_shared gvm_util_shared
${CGREEN_LIBRARIES} ${GLIB_LDFLAGS} ${LINKER_HARDENING_FLAGS}
)

add_custom_target (tests-openvasd
DEPENDS openvasd-test)

endif (BUILD_TESTS)

## 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 415b163

Please sign in to comment.