Greenbone Vulnerability Manager  22.4.0~dev1
Macros | Functions
manage_report_formats.c File Reference

GVM management layer: Report formats. More...

#include "manage_report_formats.h"
#include "gmp_report_formats.h"
#include "manage.h"
#include "manage_sql.h"
#include "manage_sql_report_formats.h"
#include "utils.h"
#include <assert.h>
#include <errno.h>
#include <glib.h>
#include <gvm/util/fileutils.h>
#include <locale.h>
#include <stdlib.h>
#include <string.h>

Macros

#define G_LOG_DOMAIN   "md manage"
 GLib log domain.
 

Functions

gboolean find_report_format_with_permission (const char *uuid, report_format_t *report_format, const char *permission)
 Find a report format for a specific permission, given a UUID. More...
 
int report_format_writable (report_format_t report_format)
 Return whether a report format is writable. More...
 
int trash_report_format_writable (report_format_t report_format)
 Return whether a trashcan report_format is writable. More...
 
const char * report_format_param_type_name (report_format_param_type_t type)
 Get the name of a report format param type. More...
 
report_format_param_type_t report_format_param_type_from_name (const char *name)
 Get a report format param type from a name. More...
 
static int backup_file_name (const char *name)
 Return whether a name is a backup file name. More...
 
static int get_report_format_files (const char *dir_name, GPtrArray **start)
 Get files associated with a report format. More...
 
int init_report_format_file_iterator (file_iterator_t *iterator, report_format_t report_format)
 Initialise a report format file iterator. More...
 
void cleanup_file_iterator (file_iterator_t *iterator)
 Cleanup a report type iterator. More...
 
gboolean next_file (file_iterator_t *iterator)
 Increment a report type iterator. More...
 
const char * file_iterator_name (file_iterator_t *iterator)
 Return the name from a file iterator. More...
 
gchar * file_iterator_content_64 (file_iterator_t *iterator)
 Return the file contents from a file iterator. More...
 
static const gchar * feed_dir_report_formats ()
 Get path to report formats in feed. More...
 
static int update_report_format_from_file (report_format_t report_format, const gchar *path)
 Create a report format from an XML file. More...
 
static void create_feed_report_format_permissions (const gchar *report_format_id)
 Grant 'Feed Import Roles' access to a report format. More...
 
static int create_report_format_from_file (const gchar *path)
 Create a report format from an XML file. More...
 
static int should_sync_report_format_from_path (const char *path, gboolean rebuild, report_format_t *report_format)
 Gets if a report format must be synced to a file path in the feed. More...
 
static void sync_report_format_with_feed (const gchar *path, gboolean rebuild)
 Sync a single report format with the feed. More...
 
static int try_open_report_formats_feed_dir (GDir **dir, gboolean set_current_user)
 Open the report formats feed directory if it is available and the feed owner is set. Optionally set the current user to the feed owner on success. More...
 
int sync_report_formats_with_feed (gboolean rebuild)
 Sync all report formats with the feed. More...
 
gboolean report_formats_feed_dir_exists ()
 Tests if the report formats feed directory exists. More...
 
void manage_sync_report_formats ()
 Sync report formats with the feed.
 
int manage_rebuild_report_formats ()
 Rebuild port lists from the feed. More...
 
gboolean should_sync_report_formats ()
 Checks if the report formats should be synced with the feed. More...
 

Detailed Description

GVM management layer: Report formats.

Non-SQL report format code for the GVM management layer.

Function Documentation

◆ backup_file_name()

static int backup_file_name ( const char *  name)
static

Return whether a name is a backup file name.

Parameters
[in]nameName.
Returns
0 if normal file name, 1 if backup file name.

◆ cleanup_file_iterator()

void cleanup_file_iterator ( file_iterator_t iterator)

Cleanup a report type iterator.

Parameters
[in]iteratorIterator.

◆ create_feed_report_format_permissions()

static void create_feed_report_format_permissions ( const gchar *  report_format_id)
static

Grant 'Feed Import Roles' access to a report format.

Parameters
[in]report_format_idUUID of report format.

◆ create_report_format_from_file()

static int create_report_format_from_file ( const gchar *  path)
static

Create a report format from an XML file.

Parameters
[in]pathPath to report format XML.
Returns
0 success, -1 error.

◆ feed_dir_report_formats()

static const gchar* feed_dir_report_formats ( )
static

Get path to report formats in feed.

Returns
Path to report formats in feed.

◆ file_iterator_content_64()

gchar* file_iterator_content_64 ( file_iterator_t iterator)

Return the file contents from a file iterator.

Parameters
[in]iteratorIterator.
Returns
Freshly allocated file contents, in base64.

◆ file_iterator_name()

const char* file_iterator_name ( file_iterator_t iterator)

Return the name from a file iterator.

Parameters
[in]iteratorIterator.
Returns
File name.

◆ find_report_format_with_permission()

gboolean find_report_format_with_permission ( const char *  uuid,
report_format_t *  report_format,
const char *  permission 
)

Find a report format for a specific permission, given a UUID.

Parameters
[in]uuidUUID of report format.
[out]report_formatReport format return, 0 if successfully failed to find report_format.
[in]permissionPermission.
Returns
FALSE on success (including if failed to find report_format), TRUE on error.

◆ get_report_format_files()

static int get_report_format_files ( const char *  dir_name,
GPtrArray **  start 
)
static

Get files associated with a report format.

Parameters
[in]dir_nameLocation of files.
[out]startFiles on success.
Returns
0 if successful, -1 otherwise.

◆ init_report_format_file_iterator()

int init_report_format_file_iterator ( file_iterator_t iterator,
report_format_t  report_format 
)

Initialise a report format file iterator.

Parameters
[in]iteratorIterator.
[in]report_formatSingle report format to iterate over, NULL for all.
Returns
0 on success, -1 on error.

◆ manage_rebuild_report_formats()

int manage_rebuild_report_formats ( )

Rebuild port lists from the feed.

Returns
0 success, 1 no feed directory, 2 no feed owner, -1 error.

◆ next_file()

gboolean next_file ( file_iterator_t iterator)

Increment a report type iterator.

The caller must stop using this after it returns FALSE.

Parameters
[in]iteratorTask iterator.
Returns
TRUE if there was a next item, else FALSE.

◆ report_format_param_type_from_name()

report_format_param_type_t report_format_param_type_from_name ( const char *  name)

Get a report format param type from a name.

Parameters
[in]nameParam type name.
Returns
The param type.

◆ report_format_param_type_name()

const char* report_format_param_type_name ( report_format_param_type_t  type)

Get the name of a report format param type.

Parameters
[in]typeParam type.
Returns
The name of the param type.

◆ report_format_writable()

int report_format_writable ( report_format_t  report_format)

Return whether a report format is writable.

Parameters
[in]report_formatReport Format.
Returns
1 if writable, else 0.

◆ report_formats_feed_dir_exists()

gboolean report_formats_feed_dir_exists ( )

Tests if the report formats feed directory exists.

Returns
TRUE if the directory exists.

◆ should_sync_report_format_from_path()

static int should_sync_report_format_from_path ( const char *  path,
gboolean  rebuild,
report_format_t *  report_format 
)
static

Gets if a report format must be synced to a file path in the feed.

Parameters
[in]pathPath to report format XML in feed.
[in]rebuildWhether ignore timestamps to force a rebuild.
[out]report_formatReport format id if it already exists, 0 if new.
Returns
1 if report format should be synced, 0 otherwise

◆ should_sync_report_formats()

gboolean should_sync_report_formats ( )

Checks if the report formats should be synced with the feed.

Returns
1 if report formats should be synced, 0 otherwise

◆ sync_report_format_with_feed()

static void sync_report_format_with_feed ( const gchar *  path,
gboolean  rebuild 
)
static

Sync a single report format with the feed.

Parameters
[in]pathPath to report format XML in feed.
[in]rebuildWhether ignore timestamps to force a rebuild.

◆ sync_report_formats_with_feed()

int sync_report_formats_with_feed ( gboolean  rebuild)

Sync all report formats with the feed.

Create report formats that exists in the feed but not in the db. Update report formats in the db that have changed on the feed. Do nothing to report formats in db that have been removed from the feed.

Parameters
[in]rebuildWhether ignore timestamps to force a rebuild.
Returns
0 success, 1 no feed directory, 2 no feed owner, -1 error.

◆ trash_report_format_writable()

int trash_report_format_writable ( report_format_t  report_format)

Return whether a trashcan report_format is writable.

Parameters
[in]report_formatReport Format.
Returns
1 if writable, else 0.

◆ try_open_report_formats_feed_dir()

static int try_open_report_formats_feed_dir ( GDir **  dir,
gboolean  set_current_user 
)
static

Open the report formats feed directory if it is available and the feed owner is set. Optionally set the current user to the feed owner on success.

The sync will be skipped if the feed directory does not exist or the feed owner is not set.

Parameters
[out]dirThe directory as GDir if available and feed owner is set, NULL otherwise.
[in]set_current_userWhether to set current user to feed owner.
Returns
0 success, 1 no feed directory, 2 no feed owner, -1 error.

◆ update_report_format_from_file()

static int update_report_format_from_file ( report_format_t  report_format,
const gchar *  path 
)
static

Create a report format from an XML file.

Parameters
[in]report_formatExisting report format.
[in]pathFull path to report format XML.
Returns
0 success, -1 error.