Greenbone Vulnerability Management Libraries 22.8.0
Data Structures | Macros | Functions | Variables
logging.c File Reference

Implementation of logging methods. More...

#include "logging.h"
#include "gvm_sentry.h"
#include <errno.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <time.h>
#include <unistd.h>

Data Structures

struct  gvm_logging_t
 Logging stores the parameters loaded from a log configuration. More...
 

Macros

#define SYSLOG_NAMES
 
#define G_LOG_DOMAIN   "libgvm base"
 GLib log domain.
 

Functions

gchar * get_time (gchar *time_fmt)
 Returns time as specified in time_fmt strftime format.
 
static gint level_int_from_string (const gchar *level)
 Return the integer corresponding to a log level string.
 
static gint facility_int_from_string (const gchar *facility)
 Return the integer corresponding to a syslog facility string.
 
GSList * load_log_configuration (gchar *config_file)
 Loads parameters from a config file into a linked list.
 
void free_log_configuration (GSList *log_domain_list)
 Frees all resources loaded by the config loader.
 
void gvm_log_silent (const char *log_domain, GLogLevelFlags log_level, const char *message, gpointer gvm_log_config_list)
 Returns immediately.
 
static void gvm_log_lock_init (void)
 Initialize logger_mutex mutex if it was not done before.
 
void gvm_log_lock (void)
 Try to lock logger_mutex.
 
void gvm_log_unlock (void)
 Unlock logger_mutex.
 
void set_log_reference (char *ref)
 Set the log reference object.
 
char * get_log_reference (void)
 Get the log reference object.
 
void free_log_reference (void)
 Free the log reference object.
 
void gvm_log_func (const char *log_domain, GLogLevelFlags log_level, const char *message, gpointer gvm_log_config_list)
 Creates the formatted string and outputs it to the log destination.
 
void log_func_for_gnutls (int level, const char *message)
 This function logs debug messages from gnutls.
 
static int check_log_file (gvm_logging_t *log_domain_entry)
 Check permissions of log file and log file directory.
 
int setup_log_handlers (GSList *gvm_log_config_list)
 Sets up routing of logdomains to log handlers.
 

Variables

static GMutex * logger_mutex = NULL
 
static char * reference = NULL
 

Detailed Description

Implementation of logging methods.

This file contains all methods needed for logging. To enable logging, methods in this file are called.

The module reuses glib datatypes and api for memory management and logging.

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "libgvm base"

GLib log domain.

◆ SYSLOG_NAMES

#define SYSLOG_NAMES

Function Documentation

◆ check_log_file()

static int check_log_file ( gvm_logging_t * log_domain_entry)
static

Check permissions of log file and log file directory.

Do not check permissions if log file is syslog or empty string.

Parameters
log_domain_entryLog domain entry.
Returns
0 on success, -1 on error.

◆ facility_int_from_string()

static gint facility_int_from_string ( const gchar * facility)
static

Return the integer corresponding to a syslog facility string.

Parameters
facilityFacility name.
Returns
Facility integer if facility matches a facility name, else LOG_LOCAL0.

◆ free_log_configuration()

void free_log_configuration ( GSList * log_domain_list)

Frees all resources loaded by the config loader.

Parameters
log_domain_listHead of the link list.

◆ free_log_reference()

void free_log_reference ( void )

Free the log reference object.

The reference object is used to detect corresponding logs.

◆ get_log_reference()

char * get_log_reference ( void )

Get the log reference object.

This function returns the current log reference. This enables the possibility to save or modify the current reference value.

Returns
char*

◆ get_time()

gchar * get_time ( gchar * time_fmt)

Returns time as specified in time_fmt strftime format.

Parameters
time_fmtptr to the string format to use. The strftime man page documents the conversion specification. An example time_fmt string is "%Y-%m-%d %H:%M:%S".
Returns
NULL in case the format string is NULL. A ptr to a string that contains the formatted date time value. This value must be freed using glib's g_free.

◆ gvm_log_func()

void gvm_log_func ( const char * log_domain,
GLogLevelFlags log_level,
const char * message,
gpointer gvm_log_config_list )

Creates the formatted string and outputs it to the log destination.

Parameters
log_domainA string containing the message's log domain.
log_levelFlags defining the message's log level.
messageA string containing the log message.
gvm_log_config_listA pointer to the configuration linked list.

◆ gvm_log_lock()

void gvm_log_lock ( void )

Try to lock logger_mutex.

◆ gvm_log_lock_init()

static void gvm_log_lock_init ( void )
static

Initialize logger_mutex mutex if it was not done before.

◆ gvm_log_silent()

void gvm_log_silent ( const char * log_domain,
GLogLevelFlags log_level,
const char * message,
gpointer gvm_log_config_list )

Returns immediately.

Parameters
log_domainA string containing the message's log domain.
log_levelFlags defining the message's log level.
messageA string containing the log message.
gvm_log_config_listA pointer to the configuration linked list.

◆ gvm_log_unlock()

void gvm_log_unlock ( void )

Unlock logger_mutex.

◆ level_int_from_string()

static gint level_int_from_string ( const gchar * level)
static

Return the integer corresponding to a log level string.

Parameters
levelLevel name or integer.
Returns
Log level integer if level matches a level name, else 0.

◆ load_log_configuration()

GSList * load_log_configuration ( gchar * config_file)

Loads parameters from a config file into a linked list.

Parameters
config_fileA string containing the path to the configuration file to load.
Returns
NULL in case the config file could not be loaded or an error occurred otherwise, a singly linked list of parameter groups is returned.

◆ log_func_for_gnutls()

void log_func_for_gnutls ( int level,
const char * message )

This function logs debug messages from gnutls.

Parameters
levelGnuTLS log level (integer from 0 to 99 according to GnuTLS documentation.
messageGnuTLS log message.

To enable GNUTLS debug messages, the environment variable OPENVAS_GNUTLS_DEBUG is to be set to the desired log level as described in the GNUTLS manual.

◆ set_log_reference()

void set_log_reference ( char * ref)

Set the log reference object.

In order to be able to see which logs are related to each other, we define a common reference for them. E.g. when multiple scans in OpenVAS are running simultaniousely it is possible to detect all log corresponding to the same scan. The log reference is optional and must be set before calling setup_log_handlers. The data given must be freed by calling free_log_reference(). If called multiple times the old reference gets freed and the new one is set instead.

Parameters
ref

◆ setup_log_handlers()

int setup_log_handlers ( GSList * gvm_log_config_list)

Sets up routing of logdomains to log handlers.

Iterates over the link list and adds the groups to the handler.

Parameters
gvm_log_config_listA pointer to the configuration linked list.
Returns
0 on success, -1 if not able to create log file directory or open log file for some domain.

Variable Documentation

◆ logger_mutex

GMutex* logger_mutex = NULL
static

◆ reference

char* reference = NULL
static