Commit 514d103e authored by SZ Lin (林上智)'s avatar SZ Lin (林上智)

Import openvas-libraries_9.0.0.orig.tar.gz

parent 53d810d9
This diff is collapsed.
......@@ -7,7 +7,7 @@
# Jan-Oliver Wagner <jan-oliver.wagner@greenbone.net>
#
# Copyright:
# Copyright (C) 2011-2015 Greenbone Networks GmbH
# Copyright (C) 2011-2016 Greenbone Networks GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
......@@ -23,7 +23,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 2.8)
include (openvas_cmake_macros)
......@@ -70,9 +70,9 @@ if (NOT CMAKE_BUILD_TYPE MATCHES "Release")
if (EXISTS "${CMAKE_SOURCE_DIR}/.svn/")
if (SVN_EXECUTABLE)
Subversion_GET_REVISION(. ProjectRevision)
set (SVN_REVISION ".SVN.r${ProjectRevision}")
set (SVN_REVISION "~svn${ProjectRevision}")
else (SVN_EXECUTABLE)
set (SVN_REVISION ".SVN")
set (SVN_REVISION "~svn")
endif (SVN_EXECUTABLE)
endif (EXISTS "${CMAKE_SOURCE_DIR}/.svn/")
endif (NOT CMAKE_BUILD_TYPE MATCHES "Release")
......@@ -92,11 +92,11 @@ set (CPACK_SOURCE_GENERATOR "TGZ")
set (CPACK_SOURCE_TOPLEVEL_TAG "")
set (CPACK_SYSTEM_NAME "")
set (CPACK_TOPLEVEL_TAG "")
set (CPACK_PACKAGE_VERSION_MAJOR "8")
set (CPACK_PACKAGE_VERSION_MAJOR "9")
set (CPACK_PACKAGE_VERSION_MINOR "0")
# Use this scheme for stable releases:
set (CPACK_PACKAGE_VERSION_PATCH "8${SVN_REVISION}")
set (CPACK_PACKAGE_VERSION_PATCH "0${SVN_REVISION}")
set (CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
# Use this scheme for +betaN and +rcN releases:
#set (CPACK_PACKAGE_VERSION_PATCH "+beta1${SVN_REVISION}")
......@@ -106,24 +106,9 @@ set (CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}")
set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}")
set (CPACK_PACKAGE_VENDOR "The OpenVAS Project")
set (CPACK_SOURCE_IGNORE_FILES
"${CMAKE_BINARY_DIR}"
"/.svn/"
"/_CPack_Packages/"
"/CMakeFiles/"
"cmake$"
"swp$"
"Cache.txt$"
".tar.gz"
"install_manifest.txt"
"Makefile"
"/doc/generated/"
"log.conf$"
"Doxyfile$"
"Doxyfile_full$"
"VERSION$"
"libopenvas_omp.pc$"
"libopenvas_nasl.pc$"
"libopenvas_base.pc$"
"libopenvas_misc.pc$"
"nasl/nasl_grammar.tab.c"
"nasl/nasl_grammar.tab.h"
"nasl/nasl_grammar.output"
......@@ -177,6 +162,10 @@ if (NOT DATADIR)
set (DATADIR "${CMAKE_INSTALL_PREFIX}/share")
endif (NOT DATADIR)
if (NOT OPENVAS_PID_DIR)
set (OPENVAS_PID_DIR "${LOCALSTATEDIR}/run")
endif (NOT OPENVAS_PID_DIR)
#if (NOT SYSCONFDIR)
# set (SYSCONFDIR "${CMAKE_INSTALL_PREFIX}/etc")
#endif (NOT SYSCONFDIR)
......@@ -185,17 +174,11 @@ set (OPENVAS_DATA_DIR "${DATADIR}/openvas")
set (OPENVAS_STATE_DIR "${LOCALSTATEDIR}/lib/openvas")
set (OPENVAS_LOG_DIR "${LOCALSTATEDIR}/log/openvas")
set (OPENVAS_CACHE_DIR "${LOCALSTATEDIR}/cache/openvas")
set (OPENVAS_PID_DIR "${LOCALSTATEDIR}/run")
set (OPENVAS_SYSCONF_DIR "${SYSCONFDIR}/openvas")
set (OPENVAS_NVT_DIR "${OPENVAS_STATE_DIR}/plugins")
set (OPENVAS_LIB_INSTALL_DIR "${LIBDIR}")
set (OPENVAS_HEADER_INSTALL_DIR "${INCLUDEDIR}")
set (OPENVAS_SERVER_CERTIFICATE "${OPENVAS_STATE_DIR}/CA/servercert.pem")
set (OPENVAS_SERVER_KEY "${OPENVAS_STATE_DIR}/private/CA/serverkey.pem")
set (OPENVAS_CA_CERTIFICATE "${OPENVAS_STATE_DIR}/CA/cacert.pem")
add_definitions (-DOPENVASSD_CONF=\\\"${OPENVAS_SYSCONF_DIR}/openvassd.conf\\\")
message ("-- Install prefix: ${CMAKE_INSTALL_PREFIX}")
......@@ -204,12 +187,11 @@ message ("-- Install prefix: ${CMAKE_INSTALL_PREFIX}")
##
## TODO Also check for headers where needed.
pkg_check_modules (GNUTLS REQUIRED gnutls>=2.12)
pkg_check_modules (GLIB REQUIRED glib-2.0>=2.16)
pkg_check_modules (REDIS hiredis>=0.10.1)
pkg_check_modules (GNUTLS REQUIRED gnutls>=3.2.15)
pkg_check_modules (GLIB REQUIRED glib-2.0>=2.32)
if (NOT OPENVAS_OMP_ONLY)
pkg_check_modules (OPENVAS_WMICLIENT libopenvas_wmiclient>=0.0.1)
pkg_check_modules (OPENVAS_WINCMD libopenvas_wincmd>=0.0.1)
pkg_check_modules (OPENVAS_WMICLIENT libopenvas_wmiclient>=1.0.1)
pkg_check_modules (OPENVAS_WINCMD libopenvas_wincmd>=1.0.1)
pkg_check_modules (LIBSSH REQUIRED libssh>=0.5.0)
message (STATUS "Looking for pcap...")
......@@ -237,18 +219,6 @@ if (NOT OPENVAS_OMP_ONLY)
endif (PCAP_CONFIG)
endif (NOT OPENVAS_OMP_ONLY)
if (NOT REDIS_FOUND)
# Make a second attempt to find hiredis without pkg-config
message (STATUS "Looking for hiredis...")
find_library (HIREDIS hiredis)
message (STATUS "Looking for hiredis... ${HIREDIS}")
if (NOT HIREDIS)
message (SEND_ERROR "The hiredis library is required.")
endif (NOT HIREDIS)
set (REDIS_LDFLAGS "-lhiredis")
endif (NOT REDIS_FOUND)
if (NOT MINGW)
# TODO: We do not have a library lookup for those modules
# which also works when cross compiling. Library names
......@@ -267,10 +237,6 @@ if (NOT MINGW)
OUTPUT_VARIABLE GPGME_CFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
message (STATUS "Looking for ksba...")
find_library (KSBA ksba)
message (STATUS "Looking for ksba... ${KSBA}")
message (STATUS "Looking for netsnmp...")
find_library (SNMP snmp)
message (STATUS "Looking for netsnmp... ${SNMP}")
......@@ -280,13 +246,6 @@ if (NOT MINGW)
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif (SNMP)
execute_process (COMMAND ksba-config --libs
OUTPUT_VARIABLE KSBA_LDFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process (COMMAND ksba-config --cflags
OUTPUT_VARIABLE KSBA_CFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
message (STATUS "Looking for libgcrypt...")
find_library (GCRYPT gcrypt)
message (STATUS "Looking for libgcrypt... ${GCRYPT}")
......@@ -303,7 +262,8 @@ if (NOT MINGW)
endif (NOT MINGW)
set (HARDENING_FLAGS "-Wformat -Wformat-security -O2 -D_FORTIFY_SOURCE=2 -fstack-protector -Wl,-z,relro -Wl,-z,now")
set (HARDENING_FLAGS "-Wformat -Wformat-security -O2 -D_FORTIFY_SOURCE=2 -fstack-protector")
set (LINKER_HARDENING_FLAGS "-Wl,-z,relro -Wl,-z,now")
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Werror")
......@@ -327,6 +287,7 @@ configure_file (libopenvas_base.pc.in ${CMAKE_BINARY_DIR}/libopenvas_base.pc @ON
configure_file (libopenvas_omp.pc.in ${CMAKE_BINARY_DIR}/libopenvas_omp.pc @ONLY)
configure_file (libopenvas_misc.pc.in ${CMAKE_BINARY_DIR}/libopenvas_misc.pc @ONLY)
configure_file (libopenvas_nasl.pc.in ${CMAKE_BINARY_DIR}/libopenvas_nasl.pc @ONLY)
configure_file (libopenvas_osp.pc.in ${CMAKE_BINARY_DIR}/libopenvas_osp.pc @ONLY)
## Program
......@@ -336,6 +297,7 @@ if (NOT OPENVAS_OMP_ONLY)
add_subdirectory (nasl)
endif (NOT OPENVAS_OMP_ONLY)
add_subdirectory (omp)
add_subdirectory (osp)
## Documentation
......@@ -345,6 +307,8 @@ add_subdirectory (doc)
install (FILES doc/openvas-nasl.1
DESTINATION ${DATADIR}/man/man1 )
install (FILES doc/openvas-nasl-lint.1
DESTINATION ${DATADIR}/man/man1 )
install (FILES ${CMAKE_BINARY_DIR}/libopenvas_base.pc
DESTINATION ${LIBDIR}/pkgconfig)
......@@ -354,12 +318,13 @@ install (FILES ${CMAKE_BINARY_DIR}/libopenvas_misc.pc
DESTINATION ${LIBDIR}/pkgconfig)
install (FILES ${CMAKE_BINARY_DIR}/libopenvas_nasl.pc
DESTINATION ${LIBDIR}/pkgconfig)
install (FILES ${CMAKE_BINARY_DIR}/libopenvas_osp.pc
DESTINATION ${LIBDIR}/pkgconfig)
install (DIRECTORY DESTINATION ${OPENVAS_LOG_DIR})
install (DIRECTORY DESTINATION ${OPENVAS_DATA_DIR})
install (DIRECTORY DESTINATION ${OPENVAS_CACHE_DIR})
install (DIRECTORY DESTINATION ${OPENVAS_PID_DIR})
install (DIRECTORY DESTINATION ${OPENVAS_NVT_DIR})
install (DIRECTORY DESTINATION ${OPENVAS_SYSCONF_DIR})
install (DIRECTORY
DESTINATION ${OPENVAS_SYSCONF_DIR}/gnupg
......
......@@ -32,10 +32,11 @@ base/openvas_file.[c|h]: GPLv2+
base/openvas_hosts.[c|h]: GPLv2+
base/openvas_networking.[c|h]: GPLv2+
base/openvas_string.[c|h]: GPLv2+
base/osp.[c|h]: GPLv2+
base/pwpolicy.[c|h]: GPLv2+
base/pidfile.[c|h]: GPLv2+
base/settings.[c|h]: GPLv2+
base/kb.h: GPLv2+
base/kb_redis.c: GPLv2+
misc/arglists.[c|h]: LGPLv2+
misc/bpf_share.c: GPLv2
......@@ -44,7 +45,6 @@ misc/CMakeLists.txt: GPLv2
misc/ftp_funcs.[c|h]: LGPLv2+
misc/ids_send.[c|h]: LGPLv2+
misc/internal_com.h: GPLv2+
misc/kb.h: GPLv2+
misc/ldap_connect_auth.[c|h]: GPLv2+
misc/network.[c|h]: LGPLv2+
misc/nvt_categories.h: LGPLv2+
......@@ -58,7 +58,6 @@ misc/pcap_openvas.h: LGPLv2+
misc/plugutils.[c|h]: LGPLv2+
misc/popen.[c|h]: LGPLv2+
misc/prefs.[c|h]: GPLv2+
misc/kb_redis.c: GPLv2+
misc/support.h: GPLv2+
misc/www_funcs.c: GPLv2
misc/www_funcs.h: LGPLv2+
......@@ -138,3 +137,6 @@ nasl/tests/testsuitesummary.nasl: GPLv2+
omp/CMakeLists.txt: GPLv2+
omp/omp.[c|h]: GPLv2+
omp/xml.[c|h]: GPLv2+
osp/CMakeLists.txt: GPLv2+
osp/osp.[c|h]: GPLv2+
This diff is collapsed.
......@@ -2,7 +2,7 @@ INSTALLATION INSTRUCTIONS FOR OPENVAS-LIBRARIES
===============================================
Please note: The reference system used by most of the developers is Debian
GNU/Linux 'Wheezy' 7. The build might fail on any other system. Also it is
GNU/Linux 'Jessie' 8. The build might fail on any other system. Also it is
necessary to install dependent development packages.
......@@ -16,12 +16,12 @@ General build environment:
* a C compiler (e.g. gcc)
* bison
* flex
* cmake
* cmake >= 2.8
* pkg-config
Specific development libraries:
* libglib >= 2.16
* libgnutls >= 2.12
* libglib >= 2.32
* libgnutls >= 3.2.15
* libgcrypt
* zlib
* libpcap
......@@ -29,6 +29,7 @@ Specific development libraries:
* uuid-dev (from e2fsprogs)
* libssh >= 0.5.0
* libhiredis >= 0.10.1
* libksba >= 1.0.7
Prerequisites for building documentation:
* doxygen
......@@ -36,14 +37,11 @@ Prerequisites for building documentation:
* sqlfairy (optional, for producing database diagram)
Recommended to have WMI support:
* openvas-smb
* openvas-smb >= 1.0.1
Recommended to have improved SNMP support:
* netsnmp
Recommended to have improved SSL support:
* libksba >= 1.0.7
Recommended to have LDAP support:
* libldap >= 2.4.11
(LDAP can be disabled with -DBUILD_WITHOUT_LDAP=1)
......@@ -52,12 +50,7 @@ Recommended to have RADIUS support:
* libfreeradius-client >= 1.1.6
(RADIUS can be enabled with -DBUILD_WITH_RADIUS=1)
Install prerequisites on Debian GNU/Linux 'Wheezy' 7:
# apt-get install pkg-config libssh-dev libgnutls-dev libglib2.0-dev libpcap-dev \
libgpgme11-dev uuid-dev bison libksba-dev libhiredis-dev libsnmp-dev
libldap2-dev
Install prerequisites on Debian GNU/Linux 'Jessie' 8:
Install prerequisites on Debian GNU/Linux 'Jessie' 8:
# apt-get install dpkg-dev pkg-config libssh-dev libgnutls28-dev libglib2.0-dev \
libpcap-dev libgpgme11-dev uuid-dev bison libksba-dev libhiredis-dev \
libsnmp-dev libgcrypt20-dev libldap2-dev
......
......@@ -28,27 +28,42 @@
if (NOT MINGW)
# FIXME: certain flags should be defined on the global level,
# because they change the API (e.g. _FILE_OFFSET_BITS).
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${HARDENING_FLAGS} -D_FILE_OFFSET_BITS=64 -Wall -fPIC")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${HARDENING_FLAGS} -D_FILE_OFFSET_BITS=64 -Wall -Wextra -fPIC")
pkg_check_modules (ZLIB REQUIRED zlib)
pkg_check_modules (GIO REQUIRED gio-2.0)
pkg_check_modules (REDIS hiredis>=0.10.1)
if (NOT REDIS_FOUND)
# Make a second attempt to find hiredis without pkg-config
message (STATUS "Looking for hiredis...")
find_library (HIREDIS hiredis)
message (STATUS "Looking for hiredis... ${HIREDIS}")
if (NOT HIREDIS)
message (SEND_ERROR "The hiredis library is required.")
endif (NOT HIREDIS)
set (REDIS_LDFLAGS "-lhiredis")
endif (NOT REDIS_FOUND)
endif (NOT MINGW)
include_directories (${GLIB_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ${GNUTLS_INCLUDE_DIRS})
include_directories (${GLIB_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ${REDIS_INCLUDE_DIRS})
if (MINGW)
set (FILES array.c credentials.c openvas_hosts.c cvss.c nvti.c nvticache.c
openvas_file.c openvas_string.c pidfile.c settings.c gpgme_util.c
pwpolicy.c osp.c)
pwpolicy.c)
set (HEADERS array.h credentials.h openvas_hosts.h cvss.h nvti.h settings.h
openvas_file.h openvas_string.h pidfile.h gpgme_util.h pwpolicy.h osp.h)
openvas_file.h openvas_string.h pidfile.h gpgme_util.h pwpolicy.h)
else (MINGW)
set (FILES array.c credentials.c openvas_hosts.c cvss.c drop_privileges.c
nvti.c nvticache.c openvas_compress.c openvas_file.c openvas_networking.c
openvas_string.c pidfile.c settings.c gpgme_util.c pwpolicy.c osp.c)
kb_redis.c openvas_string.c pidfile.c settings.c gpgme_util.c pwpolicy.c)
set (HEADERS array.h credentials.h openvas_hosts.h cvss.h drop_privileges.h
nvticache.h nvti.h settings.h openvas_compress.h openvas_file.h osp.h
kb.h nvticache.h nvti.h settings.h openvas_compress.h openvas_file.h
openvas_networking.h openvas_string.h pidfile.h gpgme_util.h pwpolicy.h)
endif (MINGW)
......@@ -71,9 +86,9 @@ if (BUILD_SHARED)
set (GLIB_LDFLAGS -Wl,--start-group ${GLIB_LDFLAGS} gmodule-2.0 -Wl,--end-group)
set (W32LIBS ${GLIB_LDFLAGS} intl iconv gpgme
assuan libgpg-error ole32 ws2_32 ffi z shlwapi dnsapi winmm)
target_link_libraries (openvas_base_shared openvas_omp_shared ${W32LIBS})
target_link_libraries (openvas_base_shared ${W32LIBS})
else (MINGW)
target_link_libraries (openvas_base_shared openvas_omp_shared ${GLIB_LDFLAGS} ${GIO_LDFLAGS} ${GNUTLS_LDFLAGS} ${ZLIB_LDFLAGS} ${GPGME_LDFLAGS})
target_link_libraries (openvas_base_shared LINK_PRIVATE ${GLIB_LDFLAGS} ${GIO_LDFLAGS} ${ZLIB_LDFLAGS} ${GPGME_LDFLAGS} ${REDIS_LDFLAGS} ${LINKER_HARDENING_FLAGS})
endif (MINGW)
endif (BUILD_SHARED)
......@@ -89,7 +104,7 @@ add_custom_indent_targets (${FILES})
# TODO: This is currently only built for BUILD_SHARED
if (BUILD_SHARED)
add_executable (test-hosts test-hosts.c)
target_link_libraries (test-hosts openvas_base_shared ${GNUTLS_LDFLAGS} openvas_misc_shared ${GLIB_LDFLAGS})
target_link_libraries (test-hosts openvas_base_shared ${GLIB_LDFLAGS} ${REDIS_LDFLAGS})
endif (BUILD_SHARED)
## Install
......
......@@ -28,8 +28,6 @@
#ifndef _OPENVAS_LIBRARIES_BASE_CREDENTIALS_H
#define _OPENVAS_LIBRARIES_BASE_CREDENTIALS_H
#include "credentials.h"
#include <glib.h>
/**
......
......@@ -65,7 +65,6 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
......@@ -310,7 +309,7 @@ __get_cvss_score (struct cvss *cvss)
/**
* @brief Calculate CVSS Score.
*
* @param base_metrics Base vector string from which to compute score.
* @param cvss_str Base vector string from which to compute score.
*
* @return The resulting score. -1 upon error during parsing.
*/
......
......@@ -42,7 +42,7 @@
#include <grp.h>
/**
* @brief Sets an error and return \param errorcode.
* @brief Sets an error and return \param errorcode
*
* @param error Error to set.
* @param errorcode Errorcode (possible values defined in drop_privileges.h),
......
......@@ -35,6 +35,8 @@
#include <stdlib.h>
#include <locale.h> /* for LC_CTYPE */
#include <unistd.h> /* for F_OK */
#include <sys/stat.h> /* for mkdir */
#include <errno.h> /* for ENOENT */
#include "gpgme_util.h"
......@@ -44,6 +46,8 @@
*/
#define G_LOG_DOMAIN "base gpgme"
static char *gpghome = NULL;
/**
* @brief Log function with extra gpg-error style output
*
......@@ -82,42 +86,20 @@ log_gpgme (GLogLevelFlags level, gpg_error_t err, const char *fmt, ...)
g_free (msg);
}
/**
* @brief Return the name of the writable GnuPG home directory
*
* Returns the name of the GnuPG home directory to use when checking
* GnuPG signatures. The return value is the value of the environment
* variable OPENVAS_GPGHOME if it is set. Otherwise it is the
* directory openvas/gnupg under the statedir that was set by
* configure (usually $prefix/var/lib/openvas/gnupg). The return
* value must be released with g_free.
*
* @return Custom name of the GnuPG home directory for general use.
*/
static char *
determine_gpghome (void)
{
char *envdir = getenv ("OPENVAS_GPGHOME");
if (envdir)
return g_strdup (envdir);
else
return g_build_filename (OPENVAS_STATE_DIR, "gnupg", NULL);
}
/**
* @brief Returns a new gpgme context.
*
* Inits a gpgme context with the custom gpghome directory, protocol
* Inits a gpgme context with the custom gpg directory, protocol
* version etc. Returns the context or NULL if an error occurred.
* This function also does an gpgme initialization the first time it
* is called. It is advisable to call this function as early as
* possible to notice a bad installation (e.g. an too old gpg version).
* is called.
*
* @param dir Directory to use for gpg
*
* @return The gpgme_ctx_t to the context or NULL if an error occurred.
*/
gpgme_ctx_t
openvas_init_gpgme_ctx (void)
openvas_init_gpgme_ctx_from_dir (const gchar *dir)
{
static int initialized;
gpgme_error_t err;
......@@ -131,7 +113,6 @@ openvas_init_gpgme_ctx (void)
been found. */
if (!initialized)
{
char *gpghome;
gpgme_engine_info_t info;
if (!gpgme_check_version (NULL))
......@@ -144,18 +125,31 @@ openvas_init_gpgme_ctx (void)
gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
# endif
gpghome = determine_gpghome ();
#ifndef NDEBUG
g_message ("Setting GnuPG homedir to '%s'", gpghome);
g_message ("Setting GnuPG dir to '%s'", dir);
#endif
if (access (gpghome, F_OK))
err = gpg_error_from_syserror ();
else
err = gpgme_set_engine_info (GPGME_PROTOCOL_OpenPGP, NULL, gpghome);
g_free (gpghome);
err = 0;
if (access (dir, F_OK))
{
err = gpg_error_from_syserror ();
if (errno == ENOENT)
/* directory does not exists. try to create it */
if (mkdir (dir, 0700) == 0)
{
#ifndef NDEBUG
g_message ("Created GnuPG dir '%s'", dir);
#endif
err = 0;
}
}
if (!err)
err = gpgme_set_engine_info (GPGME_PROTOCOL_OpenPGP, NULL, dir);
if (err)
{
log_gpgme (G_LOG_LEVEL_WARNING, err, "Setting GnuPG homedir failed");
log_gpgme (G_LOG_LEVEL_WARNING, err, "Setting GnuPG dir failed");
return NULL;
}
......@@ -185,6 +179,65 @@ openvas_init_gpgme_ctx (void)
return ctx;
}
/**
* @brief Return the name of the writable GnuPG home directory
*
* Returns the name of the GnuPG home directory to use when checking
* GnuPG signatures. The return value is the value of the environment
* variable OPENVAS_GPGHOME if it is set. Otherwise it is the
* directory openvas/gnupg under the statedir that was set by
* configure (usually $prefix/var/lib/openvas/gnupg). The return
* value must be released with g_free.
*
* @param subdir Directory to use in OPENVAS_STATE_DIR for gpghome, if
* environment OPENVAS_GPGHOME is not set.
*
* @return Custom name of the GnuPG home directory for general use.
*/
static char *
determine_gpghome (const gchar *subdir)
{
char *envdir = getenv ("OPENVAS_GPGHOME");
if (envdir)
return g_strdup (envdir);
if (subdir)
return g_build_filename (OPENVAS_STATE_DIR, subdir, "gnupg", NULL);
return g_build_filename (OPENVAS_STATE_DIR, "gnupg", NULL);
}
/**
* @brief Returns a new gpgme context.
*
* Inits a gpgme context with the custom gpghome directory, protocol
* version etc. Returns the context or NULL if an error occurred.
* This function also does an gpgme initialization the first time it
* is called. It is advisable to call this function as early as
* possible to notice a bad installation (e.g. an too old gpg version).
*
* @param subdir Directory to use in OPENVAS_STATE_DIR for gpghome, if
* environment OPENVAS_GPGHOME is not set.
*
* @return The gpgme_ctx_t to the context or NULL if an error occurred.
*/
gpgme_ctx_t
openvas_init_gpgme_ctx (const gchar *subdir)
{
char *path;
gpgme_ctx_t ctx;
path = determine_gpghome (subdir);
ctx = openvas_init_gpgme_ctx_from_dir (path);
g_free (path);
return ctx;
}
void
set_gpghome (const char *path)
{
gpghome = g_strdup (path);
}
/**
* @brief Return the name of the sysconf GnuPG home directory
*
......@@ -194,15 +247,18 @@ openvas_init_gpgme_ctx (void)
*
* @return Static name of the Sysconf GnuPG home directory.
*/
static const char *
static char *
get_sysconf_gpghome (void)
{
static char *name;
char *envdir = NULL;
if (!name)
name = g_build_filename (OPENVAS_SYSCONF_DIR, "gnupg", NULL);
return name;
envdir = getenv ("OPENVAS_GPGHOME");
if (gpghome)
return g_strdup (gpghome);
else if (envdir)
return g_strdup (envdir);
else
return g_build_filename (OPENVAS_SYSCONF_DIR, "gnupg", NULL);
}
/**
......@@ -220,35 +276,11 @@ get_sysconf_gpghome (void)
gpgme_ctx_t
openvas_init_gpgme_sysconf_ctx (void)
{
static int info_shown;
gpg_error_t err;
gpgme_ctx_t ctx;
char *path;
ctx = openvas_init_gpgme_ctx ();
if (!ctx)
return NULL;
if (!info_shown)
{
info_shown = 1;
#ifndef NDEBUG
g_message ("Setting GnuPG sysconf homedir to '%s'",
get_sysconf_gpghome());
#endif
}
if (access (get_sysconf_gpghome (), F_OK))
err = gpg_error_from_syserror ();
else
err = gpgme_ctx_set_engine_info (ctx, GPGME_PROTOCOL_OpenPGP,
NULL, get_sysconf_gpghome ());
if (err)
{
log_gpgme (G_LOG_LEVEL_WARNING, err,
"Setting GnuPG sysconf homedir to '%s' failed",
get_sysconf_gpghome());
gpgme_release (ctx);
ctx = NULL;
}
path = get_sysconf_gpghome ();
ctx = openvas_init_gpgme_ctx_from_dir (path);
g_free (path);
return ctx;
}
......@@ -35,8 +35,9 @@
#include <gpgme.h>
gpgme_ctx_t openvas_init_gpgme_ctx (void);
gpgme_ctx_t openvas_init_gpgme_ctx (const gchar *);
gpgme_ctx_t openvas_init_gpgme_sysconf_ctx (void);
void set_gpghome (const char *);
#endif /*_OPENVAS_LIBRARIES_GPGME_UTIL_H*/
......@@ -246,7 +246,7 @@ kb_item_get_pattern (kb_t kb, const char *pattern)
* @brief Insert (append) a new entry under a given name.
* @param[in] kb KB handle where to store the item.
* @param[in] name Item name.
* @maram[in] str Item value.
* @param[in] str Item value.
* @return 0 on success, non-null on error.
*/
static inline int
......@@ -263,7 +263,7 @@ kb_item_add_str (kb_t kb, const char *name, const char *str)
* @brief Set (replace) a new entry under a given name.
* @param[in] kb KB handle where to store the item.
* @param[in] name Item name.
* @maram[in] str Item value.
* @param[in] str Item value.
* @return 0 on success, non-null on error.
*/
static inline int
......@@ -280,7 +280,7 @@ kb_item_set_str (kb_t kb, const char *name, const char *str)
* @brief Insert (append) a new entry under a given name.
* @param[in] kb KB handle where to store the item.
* @param[in] name Item name.
* @maram[in] val Item value.
* @param[in] val Item value.
* @return 0 on success, non-null on error.
*/
static inline int
......@@ -297,7 +297,7 @@ kb_item_add_int (kb_t kb, const char *name, int val)
* @brief Set (replace) a new entry under a given name.
* @param[in] kb KB handle where to store the item.
* @param[in] name Item name.
* @maram[in] val Item value.
* @param[in] val Item value.
* @return 0 on success, non-null on error.
*/
static inline int
......
......@@ -40,7 +40,6 @@
#include <hiredis/hiredis.h>
#include <glib.h>
#include "arglists.h"
#include "kb.h"
#undef G_LOG_DOMAIN
......@@ -253,18 +252,20 @@ err_cleanup:
static int
select_database (struct kb_redis *kbr)
{
int rc, i;
int rc;
redisContext *ctx = kbr->rctx;
redisReply *rep = NULL;
if (kbr->db == 0)
{
unsigned i;
if (kbr->max_db == 0)
fetch_max_db_index (kbr);
for (i = 1; i < kbr->max_db; i++)
{
rc = try_database_index(kbr, i);
rc = try_database_index (kbr, i);
if (rc == 0)
break;
}
......@@ -593,13 +594,14 @@ redis2kbitem_single (const char *name, const redisReply *elt, int force_int)
static struct kb_item *
redis2kbitem (const char *name, const redisReply *rep)
{
int i;
struct kb_item *kbi;