Greenbone Vulnerability Manager 22.5.2
Macros | Enumerations | Functions
manage_sql_report_formats.c File Reference

GVM management layer: Report format SQL. More...

#include "debug_utils.h"
#include "manage_sql_report_formats.h"
#include "manage_acl.h"
#include "manage_report_formats.h"
#include "sql.h"
#include "utils.h"
#include <errno.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <grp.h>
#include <libgen.h>
#include <limits.h>
#include <locale.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <gvm/base/gvm_sentry.h>
#include <bsd/unistd.h>
#include <gvm/util/uuidutils.h>
#include <gvm/util/fileutils.h>

Macros

#define G_LOG_DOMAIN   "md manage"
 GLib log domain.
 
#define REPORT_FORMAT_ITERATOR_FILTER_COLUMNS
 Filter columns for Report Format iterator.
 
#define REPORT_FORMAT_ITERATOR_COLUMNS
 Report Format iterator columns.
 
#define REPORT_FORMAT_ITERATOR_TRASH_COLUMNS
 Report Format iterator columns for trash case.
 

Enumerations

enum  report_format_flag_t { REPORT_FORMAT_FLAG_ACTIVE = 1 }
 Possible port types.
 

Functions

int sync_report_formats_with_feed (gboolean)
 Sync all report formats with the feed.
 
static int validate_param_value (report_format_t report_format, report_format_param_t param, const char *name, const char *value)
 Validate a value for a report format param.
 
static void set_report_format_name (report_format_t report_format, const char *name)
 Set the name of the report format.
 
static void set_report_format_summary (report_format_t report_format, const char *summary)
 Set the summary of the report format.
 
static void set_report_format_active (report_format_t report_format, int active)
 Set the active flag of a report format.
 
static int set_report_format_param (report_format_t report_format, const char *name, const char *value_64)
 Set the value of the report format param.
 
static const char * get_sysconf_gpghome ()
 Return the name of the sysconf GnuPG home directory.
 
static const char * get_trustedkeys_name ()
 Return the name of the trusted keys file name.
 
int resource_predefined (const gchar *type, resource_t resource)
 Return whether a resource is predefined.
 
static int verify_signature (const gchar *installer, gsize installer_size, const gchar *signature, gsize signature_size, int *trust)
 Execute gpg to verify an installer signature.
 
static int find_signature (const gchar *location, const gchar *installer_filename, gchar **signature, gsize *signature_size, gchar **uuid)
 Find a signature in a feed.
 
static gchar * report_format_trash_dir (const gchar *report_format_id)
 Get trash directory of a report format.
 
gboolean lookup_report_format (const char *name, report_format_t *report_format)
 Find a report format given a name.
 
gboolean find_report_format_no_acl (const char *uuid, report_format_t *report_format)
 Find a report format given a UUID.
 
gboolean find_trash_report_format_no_acl (const char *uuid, report_format_t *report_format)
 Find a trash report format given a UUID.
 
static gint compare_files (gconstpointer one, gconstpointer two)
 Compare files for create_report_format.
 
static int save_report_format_files (const gchar *report_id, array_t *files, gchar **report_format_dir)
 Save files of a report format.
 
static int add_report_format_params (report_format_t report_format, array_t *params, array_t *params_options)
 Add params to a report format.
 
static int create_report_format_internal (int check_access, int may_exist, int active, int trusted, const char *uuid, const char *name, const char *content_type, const char *extension, const char *summary, const char *description, array_t *files, array_t *params, array_t *params_options, const char *signature, int predefined, report_format_t *report_format)
 Create a report format.
 
int create_report_format (const char *uuid, const char *name, const char *content_type, const char *extension, const char *summary, const char *description, array_t *files, array_t *params, array_t *params_options, const char *signature, report_format_t *report_format)
 Create a report format.
 
int create_report_format_no_acl (const char *uuid, const char *name, const char *content_type, const char *extension, const char *summary, const char *description, array_t *files, array_t *params, array_t *params_options, const char *signature, int predefined, report_format_t *report_format)
 Create a report format.
 
static int copy_report_format_dir (const gchar *source_dir, const gchar *copy_parent, const gchar *copy_uuid)
 Create a report format dir.
 
int copy_report_format (const char *name, const char *source_uuid, report_format_t *new_report_format)
 Create Report Format from an existing Report Format.
 
static int report_format_predefined_uuid (const gchar *report_format_id)
 Return whether a report format is predefined.
 
int modify_report_format (const char *report_format_id, const char *name, const char *summary, const char *active, const char *param_name, const char *param_value)
 Modify a report format.
 
static int move_report_format_dir (const char *dir, const char *new_dir)
 Move a report format directory.
 
static void delete_report_format_rows (report_format_t report_format)
 Delete a report format from the db.
 
int delete_report_format (const char *report_format_id, int ultimate)
 Delete a report format.
 
int restore_report_format (const char *report_format_id)
 Try restore a report format.
 
char * report_format_uuid (report_format_t report_format)
 Return the UUID of a report format.
 
char * report_format_owner_uuid (report_format_t report_format)
 Return the UUID of the owner of a report format.
 
char * report_format_name (report_format_t report_format)
 Return the name of a report format.
 
char * report_format_content_type (report_format_t report_format)
 Return the content type of a report format.
 
int report_format_in_use (report_format_t report_format)
 Return whether a report format is referenced by an alert.
 
int trash_report_format_in_use (report_format_t report_format)
 Return whether a report format in trash is referenced by an alert.
 
int report_format_predefined (report_format_t report_format)
 Return whether a report format is predefined.
 
int trash_report_format_predefined (report_format_t report_format)
 Return whether a trash report format is predefined.
 
char * report_format_extension (report_format_t report_format)
 Return the extension of a report format.
 
int report_format_active (report_format_t report_format)
 Return whether a report format is active.
 
static report_format_param_type_t report_format_param_type (report_format_t report_format, const char *name)
 Return the type max of a report format param.
 
static long long int report_format_param_type_max (report_format_t report_format, const char *name)
 Return the type max of a report format param.
 
static long long int report_format_param_type_min (report_format_t report_format, const char *name)
 Return the type min of a report format param.
 
int report_format_trust (report_format_t report_format)
 Return the trust of a report format.
 
const char ** report_format_filter_columns ()
 Get filter columns.
 
column_treport_format_select_columns ()
 Get select columns.
 
int report_format_count (const get_data_t *get)
 Count the number of Report Formats.
 
int init_report_format_iterator (iterator_t *iterator, const get_data_t *get)
 Initialise a Report Format iterator, including observed Report Formats.
 
const char * report_format_iterator_trust (iterator_t *iterator)
 Get the trust value from a report format iterator.
 
time_t report_format_iterator_trust_time (iterator_t *iterator)
 Get the trust time from a report format iterator.
 
int report_format_iterator_active (iterator_t *iterator)
 Get the active flag from a report format iterator.
 
void init_report_format_alert_iterator (iterator_t *iterator, report_format_t report_format)
 Initialise a Report Format alert iterator.
 
int report_format_alert_iterator_readable (iterator_t *iterator)
 Get the read permission status from a GET iterator.
 
void init_report_format_param_iterator (iterator_t *iterator, report_format_t report_format, int trash, int ascending, const char *sort_field)
 Initialise a report format iterator.
 
report_format_param_t report_format_param_iterator_param (iterator_t *iterator)
 Get the report format param from a report format param iterator.
 
const char * report_format_param_iterator_type_name (iterator_t *iterator)
 Get the name of the type of a report format param iterator.
 
report_format_param_type_t report_format_param_iterator_type (iterator_t *iterator)
 Get the type from a report format param iterator.
 
long long int report_format_param_iterator_type_min (iterator_t *iterator)
 Get the type min from a report format param iterator.
 
long long int report_format_param_iterator_type_max (iterator_t *iterator)
 Get the type max from a report format param iterator.
 
void init_param_option_iterator (iterator_t *iterator, report_format_param_t report_format_param, int ascending, const char *sort_field)
 Initialise a report format param option iterator.
 
static int verify_report_format_internal (report_format_t report_format)
 Verify a report format.
 
int verify_report_format (const char *report_format_id)
 Verify a report format.
 
static int run_report_format_script (gchar *report_format_id, gchar *xml_file, gchar *xml_dir, gchar *report_format_extra, gchar *output_file)
 Runs the script of a report format.
 
int print_report_xml_end (gchar *xml_start, gchar *xml_full, report_format_t report_format)
 Completes a report by adding report format info.
 
gchar * apply_report_format (gchar *report_format_id, gchar *xml_start, gchar *xml_file, gchar *xml_dir, GList **used_rfps)
 Applies a report format to an XML report.
 
int empty_trashcan_report_formats ()
 Empty trashcan.
 
void inherit_report_format_dir (const gchar *report_format_id, const gchar *user_id, user_t inheritor)
 Change ownership of report formats, for user deletion.
 
gboolean inherit_report_formats (user_t user, user_t inheritor, iterator_t *rows)
 Change ownership of report formats, for user deletion.
 
gboolean delete_report_formats_user (user_t user, iterator_t *rows)
 Delete all report formats owned by a user.
 
void delete_report_format_dirs_user (const gchar *user_id, iterator_t *rows)
 Delete all report formats owned by a user.
 
void update_report_format (report_format_t report_format, const gchar *report_id, const gchar *name, const gchar *content_type, const gchar *extension, const gchar *summary, const gchar *description, const gchar *signature, array_t *files, array_t *params, array_t *params_options)
 Update a report format from an XML file.
 
int report_format_updated_in_feed (report_format_t report_format, const gchar *path)
 Check if a report format has been updated in the feed.
 
int migrate_predefined_report_formats ()
 Migrate old ownerless report formats to the Feed Owner.
 
static int make_report_format_uuids_unique ()
 Ensure every report format has a unique UUID.
 
static int check_db_trash_report_formats ()
 Check that trash report formats are correct.
 
int check_db_report_formats ()
 Ensure the predefined report formats exist.
 
int check_db_report_formats_trash ()
 Ensure that the report formats trash directory matches the database.
 

Detailed Description

GVM management layer: Report format SQL.

The report format SQL for the GVM management layer.

Macro Definition Documentation

◆ REPORT_FORMAT_ITERATOR_COLUMNS

#define REPORT_FORMAT_ITERATOR_COLUMNS
Value:
{ \
{ "id", NULL, KEYWORD_TYPE_INTEGER }, \
{ "uuid", NULL, KEYWORD_TYPE_STRING }, \
{ "name", NULL, KEYWORD_TYPE_STRING }, \
{ "''", NULL, KEYWORD_TYPE_STRING }, \
{ "iso_time (creation_time)", NULL, KEYWORD_TYPE_STRING }, \
{ "iso_time (modification_time)", NULL, KEYWORD_TYPE_STRING }, \
{ "creation_time", "created", KEYWORD_TYPE_INTEGER }, \
{ "modification_time", "modified", KEYWORD_TYPE_INTEGER }, \
{ \
"(SELECT name FROM users WHERE users.id = report_formats.owner)", \
"_owner", \
KEYWORD_TYPE_STRING \
}, \
{ "owner", NULL, KEYWORD_TYPE_INTEGER }, \
{ "extension", NULL, KEYWORD_TYPE_STRING }, \
{ "content_type", NULL, KEYWORD_TYPE_STRING }, \
{ "summary", NULL, KEYWORD_TYPE_STRING }, \
{ "description", NULL, KEYWORD_TYPE_STRING }, \
{ "signature", NULL, KEYWORD_TYPE_STRING }, \
{ "trust", NULL, KEYWORD_TYPE_INTEGER }, \
{ "trust_time", NULL, KEYWORD_TYPE_INTEGER }, \
{ "flags & 1", "active", KEYWORD_TYPE_INTEGER }, \
{ "predefined", NULL, KEYWORD_TYPE_INTEGER }, \
{ NULL, NULL, KEYWORD_TYPE_UNKNOWN } \
}

Report Format iterator columns.

◆ REPORT_FORMAT_ITERATOR_FILTER_COLUMNS

#define REPORT_FORMAT_ITERATOR_FILTER_COLUMNS
Value:
{ ANON_GET_ITERATOR_FILTER_COLUMNS, "name", "extension", "content_type", \
"summary", "description", "trust", "trust_time", "active", "predefined", \
NULL }

Filter columns for Report Format iterator.

◆ REPORT_FORMAT_ITERATOR_TRASH_COLUMNS

#define REPORT_FORMAT_ITERATOR_TRASH_COLUMNS
Value:
{ \
{ "id", NULL, KEYWORD_TYPE_INTEGER }, \
{ "uuid", NULL, KEYWORD_TYPE_STRING }, \
{ "name", NULL, KEYWORD_TYPE_STRING }, \
{ "''", NULL, KEYWORD_TYPE_STRING }, \
{ "iso_time (creation_time)", NULL, KEYWORD_TYPE_STRING }, \
{ "iso_time (modification_time)", NULL, KEYWORD_TYPE_STRING }, \
{ "creation_time", "created", KEYWORD_TYPE_INTEGER }, \
{ "modification_time", "modified", KEYWORD_TYPE_INTEGER }, \
{ \
"(SELECT name FROM users" \
" WHERE users.id = report_formats_trash.owner)", \
"_owner", \
KEYWORD_TYPE_STRING \
}, \
{ "owner", NULL, KEYWORD_TYPE_INTEGER }, \
{ "extension", NULL, KEYWORD_TYPE_STRING }, \
{ "content_type", NULL, KEYWORD_TYPE_STRING }, \
{ "summary", NULL, KEYWORD_TYPE_STRING }, \
{ "description", NULL, KEYWORD_TYPE_STRING }, \
{ "signature", NULL, KEYWORD_TYPE_STRING }, \
{ "trust", NULL, KEYWORD_TYPE_INTEGER }, \
{ "trust_time", NULL, KEYWORD_TYPE_INTEGER }, \
{ "flags & 1", "active", KEYWORD_TYPE_INTEGER }, \
{ "predefined", NULL, KEYWORD_TYPE_INTEGER }, \
{ NULL, NULL, KEYWORD_TYPE_UNKNOWN } \
}

Report Format iterator columns for trash case.

Function Documentation

◆ add_report_format_params()

static int add_report_format_params ( report_format_t  report_format,
array_t *  params,
array_t *  params_options 
)
static

Add params to a report format.

Parameters
[in]report_formatReport format.
[in]paramsArray of params.
[in]params_optionsArray. Each item is an array corresponding to params. Each item of an inner array is a string, the text of an option in a selection.
Returns
0 success, 3 param value validation failed, 4 param value validation failed, 5 param default missing, 6 param min or max out of range, 7 param type missing, 8 duplicate param name, 9 bogus param type name, 99 permission denied, -1 error.

◆ apply_report_format()

gchar * apply_report_format ( gchar *  report_format_id,
gchar *  xml_start,
gchar *  xml_file,
gchar *  xml_dir,
GList **  used_rfps 
)

Applies a report format to an XML report.

Parameters
[in]report_format_idReport format to apply.
[in]xml_startPath to the main part of the report XML.
[in]xml_filePath to the report XML file.
[in]xml_dirPath to the temporary dir.
[in]used_rfpsList of already applied report formats.
Returns
Path to the generated file or NULL.

◆ check_db_report_formats()

int check_db_report_formats ( )

Ensure the predefined report formats exist.

Returns
0 success, -1 error.

◆ check_db_report_formats_trash()

int check_db_report_formats_trash ( )

Ensure that the report formats trash directory matches the database.

Returns
-1 if error, 0 if success.

◆ check_db_trash_report_formats()

static int check_db_trash_report_formats ( )
static

Check that trash report formats are correct.

Returns
0 success, -1 error.

◆ compare_files()

static gint compare_files ( gconstpointer  one,
gconstpointer  two 
)
static

Compare files for create_report_format.

Parameters
[in]oneFirst.
[in]twoSecond.
Returns
Less than, equal to, or greater than zero if one is found to be less than, to match, or be greater than two.

◆ copy_report_format()

int copy_report_format ( const char *  name,
const char *  source_uuid,
report_format_t *  new_report_format 
)

Create Report Format from an existing Report Format.

Parameters
[in]nameName of new Report Format. NULL to copy from existing.
[in]source_uuidUUID of existing Report Format.
[out]new_report_formatNew Report Format.
Returns
0 success, 1 Report Format exists already, 2 failed to find existing Report Format, 99 permission denied, -1 error.

◆ copy_report_format_dir()

static int copy_report_format_dir ( const gchar *  source_dir,
const gchar *  copy_parent,
const gchar *  copy_uuid 
)
static

Create a report format dir.

Parameters
[in]source_dirFull path of source directory, including UUID.
[in]copy_parentPath of destination directory, excluding UUID.
[in]copy_uuidUUID (dirname) of destination directory.
Returns
0 success, -1 error.

◆ create_report_format()

int create_report_format ( const char *  uuid,
const char *  name,
const char *  content_type,
const char *  extension,
const char *  summary,
const char *  description,
array_t *  files,
array_t *  params,
array_t *  params_options,
const char *  signature,
report_format_t *  report_format 
)

Create a report format.

Parameters
[in]uuidUUID of format.
[in]nameName of format.
[in]content_typeContent type of format.
[in]extensionFile extension of format.
[in]summarySummary of format.
[in]descriptionDescription of format.
[in]filesArray of memory. Each item is a file name string, a terminating NULL, the file contents in base64 and a terminating NULL.
[in]paramsArray of params.
[in]params_optionsArray. Each item is an array corresponding to params. Each item of an inner array is a string, the text of an option in a selection.
[in]signatureSignature.
[out]report_formatCreated report format.
Returns
0 success, 2 empty file name, 3 param value validation failed, 4 param value validation failed, 5 param default missing, 6 param min or max out of range, 7 param type missing, 8 duplicate param name, 9 bogus param type name, 99 permission denied, -1 error.

◆ create_report_format_internal()

static int create_report_format_internal ( int  check_access,
int  may_exist,
int  active,
int  trusted,
const char *  uuid,
const char *  name,
const char *  content_type,
const char *  extension,
const char *  summary,
const char *  description,
array_t *  files,
array_t *  params,
array_t *  params_options,
const char *  signature,
int  predefined,
report_format_t *  report_format 
)
static

Create a report format.

Parameters
[in]check_accessWhether to check for permission.
[in]may_existWhether it is OK if there is already a report format with this UUID.
[in]activeWhether report format is active.
[in]trustedWhether to assumed report format is trusted.
[in]uuidUUID of format.
[in]nameName of format.
[in]content_typeContent type of format.
[in]extensionFile extension of format.
[in]summarySummary of format.
[in]descriptionDescription of format.
[in]filesArray of memory. Each item is a file name string, a terminating NULL, the file contents in base64 and a terminating NULL.
[in]paramsArray of params.
[in]params_optionsArray. Each item is an array corresponding to params. Each item of an inner array is a string, the text of an option in a selection.
[in]predefinedWhether report format is from the feed.
[in]signatureSignature.
[out]report_formatCreated report format.
Returns
0 success, 1 report format exists, 2 empty file name, 3 param value validation failed, 4 param value validation failed, 5 param default missing, 6 param min or max out of range, 7 param type missing, 8 duplicate param name, 9 bogus param type name, 99 permission denied, -1 error.

◆ create_report_format_no_acl()

int create_report_format_no_acl ( const char *  uuid,
const char *  name,
const char *  content_type,
const char *  extension,
const char *  summary,
const char *  description,
array_t *  files,
array_t *  params,
array_t *  params_options,
const char *  signature,
int  predefined,
report_format_t *  report_format 
)

Create a report format.

Parameters
[in]uuidUUID of format.
[in]nameName of format.
[in]content_typeContent type of format.
[in]extensionFile extension of format.
[in]summarySummary of format.
[in]descriptionDescription of format.
[in]filesArray of memory. Each item is a file name string, a terminating NULL, the file contents in base64 and a terminating NULL.
[in]paramsArray of params.
[in]params_optionsArray. Each item is an array corresponding to params. Each item of an inner array is a string, the text of an option in a selection.
[in]signatureSignature.
[in]predefinedWhether report format is from the feed.
[out]report_formatCreated report format.
Returns
0 success, 1 report format exists, 2 empty file name, 3 param value validation failed, 4 param value validation failed, 5 param default missing, 6 param min or max out of range, 7 param type missing, 8 duplicate param name, 9 bogus param type name, 99 permission denied, -1 error.

◆ delete_report_format()

int delete_report_format ( const char *  report_format_id,
int  ultimate 
)

Delete a report format.

Parameters
[in]report_format_idUUID of Report format.
[in]ultimateWhether to remove entirely, or to trashcan.
Returns
0 success, 1 report format in use, 2 failed to find report format, 99 permission denied, -1 error.

◆ delete_report_format_dirs_user()

void delete_report_format_dirs_user ( const gchar *  user_id,
iterator_t rows 
)

Delete all report formats owned by a user.

Parameters
[in]user_idUUID of user.
[in]rowsTrash report format ids if any, else NULL. Cleaned up before returning.

◆ delete_report_format_rows()

static void delete_report_format_rows ( report_format_t  report_format)
static

Delete a report format from the db.

Parameters
[in]report_formatReport format.

◆ delete_report_formats_user()

gboolean delete_report_formats_user ( user_t  user,
iterator_t rows 
)

Delete all report formats owned by a user.

Parameters
[in]userThe user.
[in]rowsTrash report format ids.
Returns
TRUE if there are rows in rows, else FALSE.

◆ empty_trashcan_report_formats()

int empty_trashcan_report_formats ( )

Empty trashcan.

Returns
0 success, -1 error.

◆ find_report_format_no_acl()

gboolean find_report_format_no_acl ( const char *  uuid,
report_format_t *  report_format 
)

Find a report format given a UUID.

This does not do any permission checks.

Parameters
[in]uuidUUID of resource.
[out]report_formatReport Format return, 0 if no such report format.
Returns
FALSE on success (including if no such report format), TRUE on error.

◆ find_signature()

static int find_signature ( const gchar *  location,
const gchar *  installer_filename,
gchar **  signature,
gsize *  signature_size,
gchar **  uuid 
)
static

Find a signature in a feed.

Parameters
[in]locationFeed directory to search for signature.
[in]installer_filenameInstaller filename.
[out]signatureFreshly allocated installer signature.
[out]signature_sizeSize of installer signature.
[out]uuidAddress for basename of linked signature when the signature was found in the private directory, if desired, else NULL. Private directory is only checked if this is given.
Returns
0 success, -1 error.

◆ find_trash_report_format_no_acl()

gboolean find_trash_report_format_no_acl ( const char *  uuid,
report_format_t *  report_format 
)

Find a trash report format given a UUID.

This does not do any permission checks.

This considers the actual UUID of the report format, not the original_uuid.

Parameters
[in]uuidUUID of resource.
[out]report_formatReport Format return, 0 if no such report format.
Returns
FALSE on success (including if no such report format), TRUE on error.

◆ get_sysconf_gpghome()

static const char * get_sysconf_gpghome ( )
static

Return the name of the sysconf GnuPG home directory.

Returns the name of the GnuPG home directory to use when checking signatures. It is the directory openvas/gnupg under the sysconfdir that was set by configure (usually $prefix/etc).

Returns
Static name of the Sysconf GnuPG home directory.

◆ get_trustedkeys_name()

static const char * get_trustedkeys_name ( )
static

Return the name of the trusted keys file name.

We currently use the name pubring.gpg to be compatible with previous installations. That file should best be installed read-only so that it is not accidentally accessed while we are running a verification. All files in that keyring are assumed to be fully trustworthy.

Returns
Static file name.

◆ inherit_report_format_dir()

void inherit_report_format_dir ( const gchar *  report_format_id,
const gchar *  user_id,
user_t  inheritor 
)

Change ownership of report formats, for user deletion.

Parameters
[in]report_format_idUUID of report format.
[in]user_idUUID of current owner.
[in]inheritorNew owner.

◆ inherit_report_formats()

gboolean inherit_report_formats ( user_t  user,
user_t  inheritor,
iterator_t rows 
)

Change ownership of report formats, for user deletion.

Parameters
[in]userCurrent owner.
[in]inheritorNew owner.
[in]rowsIterator for inherited report formats, with next already called.
Returns
TRUE if there is a row available, else FALSE.

◆ init_param_option_iterator()

void init_param_option_iterator ( iterator_t iterator,
report_format_param_t  report_format_param,
int  ascending,
const char *  sort_field 
)

Initialise a report format param option iterator.

Parameters
[in]iteratorIterator.
[in]report_format_paramParam whose options to iterate over.
[in]ascendingWhether to sort ascending or descending.
[in]sort_fieldField to sort on, or NULL for "id".

◆ init_report_format_alert_iterator()

void init_report_format_alert_iterator ( iterator_t iterator,
report_format_t  report_format 
)

Initialise a Report Format alert iterator.

Iterates over all alerts that use the Report Format.

Parameters
[in]iteratorIterator.
[in]report_formatReport Format.

◆ init_report_format_iterator()

int init_report_format_iterator ( iterator_t iterator,
const get_data_t get 
)

Initialise a Report Format iterator, including observed Report Formats.

Parameters
[in]iteratorIterator.
[in]getGET data.
Returns
0 success, 1 failed to find Report Format, 2 failed to find filter, -1 error.

◆ init_report_format_param_iterator()

void init_report_format_param_iterator ( iterator_t iterator,
report_format_t  report_format,
int  trash,
int  ascending,
const char *  sort_field 
)

Initialise a report format iterator.

Parameters
[in]iteratorIterator.
[in]report_formatSingle report_format to iterate over, or 0 for all.
[in]trashWhether to iterate over trashcan report formats.
[in]ascendingWhether to sort ascending or descending.
[in]sort_fieldField to sort on, or NULL for "id".

◆ lookup_report_format()

gboolean lookup_report_format ( const char *  name,
report_format_t *  report_format 
)

Find a report format given a name.

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

◆ make_report_format_uuids_unique()

static int make_report_format_uuids_unique ( )
static

Ensure every report format has a unique UUID.

Returns
0 success, -1 error.

◆ migrate_predefined_report_formats()

int migrate_predefined_report_formats ( )

Migrate old ownerless report formats to the Feed Owner.

Returns
0 success, -1 error.

◆ modify_report_format()

int modify_report_format ( const char *  report_format_id,
const char *  name,
const char *  summary,
const char *  active,
const char *  param_name,
const char *  param_value 
)

Modify a report format.

Parameters
[in]report_format_idUUID of report format.
[in]nameName of report format.
[in]summarySummary of report format.
[in]activeActive flag.
[in]param_nameParameter to modify.
[in]param_valueValue of parameter.
Returns
0 success, 1 failed to find report format, 2 report_format_id required, 3 failed to find report format parameter, 4 parameter value validation failed, 99 permission denied, -1 internal error.

◆ move_report_format_dir()

static int move_report_format_dir ( const char *  dir,
const char *  new_dir 
)
static

Move a report format directory.

Parameters
[in]dirOld dir.
[in]new_dirNew dir.
Returns
0 success, -1 error.

◆ print_report_xml_end()

int print_report_xml_end ( gchar *  xml_start,
gchar *  xml_full,
report_format_t  report_format 
)

Completes a report by adding report format info.

Parameters
[in]xml_startPath of file containing start of report.
[in]xml_fullPath to file to print full report to.
[in]report_formatFormat of report that will be created from XML.
Returns
0 success, -1 error.

◆ report_format_active()

int report_format_active ( report_format_t  report_format)

Return whether a report format is active.

Parameters
[in]report_formatReport format.
Returns
-1 on error, 1 if active, else 0.

◆ report_format_alert_iterator_readable()

int report_format_alert_iterator_readable ( iterator_t iterator)

Get the read permission status from a GET iterator.

Parameters
[in]iteratorIterator.
Returns
1 if may read, else 0.

◆ report_format_content_type()

char * report_format_content_type ( report_format_t  report_format)

Return the content type of a report format.

Parameters
[in]report_formatReport format.
Returns
Newly allocated content type.

◆ report_format_count()

int report_format_count ( const get_data_t get)

Count the number of Report Formats.

Parameters
[in]getGET params.
Returns
Total number of Report Formats filtered set.

◆ report_format_extension()

char * report_format_extension ( report_format_t  report_format)

Return the extension of a report format.

Parameters
[in]report_formatReport format.
Returns
Newly allocated extension.

◆ report_format_filter_columns()

const char ** report_format_filter_columns ( )

Get filter columns.

Returns
Constant array of filter columns.

◆ report_format_in_use()

int report_format_in_use ( report_format_t  report_format)

Return whether a report format is referenced by an alert.

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

◆ report_format_iterator_active()

int report_format_iterator_active ( iterator_t iterator)

Get the active flag from a report format iterator.

Parameters
[in]iteratorIterator.
Returns
Active flag, or -1 if iteration is complete.

◆ report_format_iterator_trust()

const char * report_format_iterator_trust ( iterator_t iterator)

Get the trust value from a report format iterator.

Parameters
[in]iteratorIterator.
Returns
Trust value.

◆ report_format_iterator_trust_time()

time_t report_format_iterator_trust_time ( iterator_t iterator)

Get the trust time from a report format iterator.

Parameters
[in]iteratorIterator.
Returns
Time report format was verified.

◆ report_format_name()

char * report_format_name ( report_format_t  report_format)

Return the name of a report format.

Parameters
[in]report_formatReport format.
Returns
Newly allocated name.

◆ report_format_owner_uuid()

char * report_format_owner_uuid ( report_format_t  report_format)

Return the UUID of the owner of a report format.

Parameters
[in]report_formatReport format.
Returns
Newly allocated owner UUID if there is an owner, else NULL.

◆ report_format_param_iterator_param()

report_format_param_t report_format_param_iterator_param ( iterator_t iterator)

Get the report format param from a report format param iterator.

Parameters
[in]iteratorIterator.
Returns
Report format param.

◆ report_format_param_iterator_type()

report_format_param_type_t report_format_param_iterator_type ( iterator_t iterator)

Get the type from a report format param iterator.

Parameters
[in]iteratorIterator.
Returns
Type.

◆ report_format_param_iterator_type_max()

long long int report_format_param_iterator_type_max ( iterator_t iterator)

Get the type max from a report format param iterator.

Parameters
[in]iteratorIterator.
Returns
Type max.

◆ report_format_param_iterator_type_min()

long long int report_format_param_iterator_type_min ( iterator_t iterator)

Get the type min from a report format param iterator.

Parameters
[in]iteratorIterator.
Returns
Type min.

◆ report_format_param_iterator_type_name()

const char * report_format_param_iterator_type_name ( iterator_t iterator)

Get the name of the type of a report format param iterator.

Parameters
[in]iteratorIterator.
Returns
Static string naming type, or NULL if iteration is complete.

◆ report_format_param_type()

static report_format_param_type_t report_format_param_type ( report_format_t  report_format,
const char *  name 
)
static

Return the type max of a report format param.

Parameters
[in]report_formatReport format.
[in]nameName of param.
Returns
Param type.

◆ report_format_param_type_max()

static long long int report_format_param_type_max ( report_format_t  report_format,
const char *  name 
)
static

Return the type max of a report format param.

Parameters
[in]report_formatReport format.
[in]nameName of param.
Returns
Max.

◆ report_format_param_type_min()

static long long int report_format_param_type_min ( report_format_t  report_format,
const char *  name 
)
static

Return the type min of a report format param.

Parameters
[in]report_formatReport format.
[in]nameName of param.
Returns
Min.

◆ report_format_predefined()

int report_format_predefined ( report_format_t  report_format)

Return whether a report format is predefined.

Parameters
[in]report_formatReport format.
Returns
1 if predefined, else 0.

◆ report_format_predefined_uuid()

static int report_format_predefined_uuid ( const gchar *  report_format_id)
static

Return whether a report format is predefined.

Parameters
[in]report_format_idUUID of report format.
Returns
1 if predefined, else 0.

◆ report_format_select_columns()

column_t * report_format_select_columns ( )

Get select columns.

Returns
Constant array of select columns.

◆ report_format_trash_dir()

static gchar * report_format_trash_dir ( const gchar *  report_format_id)
static

Get trash directory of a report format.

Parameters
[in]report_format_idUUID of report format. NULL for the base dir that holds the report format trash.
Returns
Freshly allocated trash dir.

◆ report_format_trust()

int report_format_trust ( report_format_t  report_format)

Return the trust of a report format.

Parameters
[in]report_formatReport format.
Returns
Trust: 1 yes, 2 no, 3 unknown.

◆ report_format_updated_in_feed()

int report_format_updated_in_feed ( report_format_t  report_format,
const gchar *  path 
)

Check if a report format has been updated in the feed.

Parameters
[in]pathFull path to report format XML in feed.
[in]report_formatReport Format.
Returns
1 if updated in feed, else 0.

◆ report_format_uuid()

char * report_format_uuid ( report_format_t  report_format)

Return the UUID of a report format.

Parameters
[in]report_formatReport format.
Returns
Newly allocated UUID.

◆ resource_predefined()

int resource_predefined ( const gchar *  type,
resource_t  resource 
)

Return whether a resource is predefined.

Parameters
[in]typeType of resource.
[in]resourceResource.
Returns
1 if predefined, else 0.

◆ restore_report_format()

int restore_report_format ( const char *  report_format_id)

Try restore a report format.

If success, ends transaction for caller before exiting.

Parameters
[in]report_format_idUUID of resource.
Returns
0 success, 1 fail because resource is in use, 2 failed to find resource, 4 fail because resource with UUID exists, -1 error.

◆ run_report_format_script()

static int run_report_format_script ( gchar *  report_format_id,
gchar *  xml_file,
gchar *  xml_dir,
gchar *  report_format_extra,
gchar *  output_file 
)
static

Runs the script of a report format.

Parameters
[in]report_format_idUUID of the report format.
[in]xml_filePath to main part of the report XML.
[in]xml_dirPath of the dir with XML and subreports.
[in]report_format_extraExtra data for report format.
[in]output_filePath to write report to.
Returns
0 success, -1 error.

◆ save_report_format_files()

static int save_report_format_files ( const gchar *  report_id,
array_t *  files,
gchar **  report_format_dir 
)
static

Save files of a report format.

Parameters
[in]report_idUUID of format.
[in]filesArray of memory. Each item is a file name string, a terminating NULL, the file contents in base64 and a terminating NULL.
[out]report_format_dirAddress for dir, or NULL.
Returns
0 success, 2 empty file name, -1 error.

◆ set_report_format_active()

static void set_report_format_active ( report_format_t  report_format,
int  active 
)
static

Set the active flag of a report format.

Parameters
[in]report_formatThe report format.
[in]activeActive flag.

◆ set_report_format_name()

static void set_report_format_name ( report_format_t  report_format,
const char *  name 
)
static

Set the name of the report format.

Parameters
[in]report_formatThe report format.
[in]nameName.

◆ set_report_format_param()

static int set_report_format_param ( report_format_t  report_format,
const char *  name,
const char *  value_64 
)
static

Set the value of the report format param.

Parameters
[in]report_formatThe report format.
[in]nameParam name.
[in]value_64Param value in base64.
Returns
0 success, 1 failed to find param, 2 validation of value failed, -1 error.

◆ set_report_format_summary()

static void set_report_format_summary ( report_format_t  report_format,
const char *  summary 
)
static

Set the summary of the report format.

Parameters
[in]report_formatThe report format.
[in]summarySummary.

◆ 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_in_use()

int trash_report_format_in_use ( report_format_t  report_format)

Return whether a report format in trash is referenced by an alert.

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

◆ trash_report_format_predefined()

int trash_report_format_predefined ( report_format_t  report_format)

Return whether a trash report format is predefined.

Parameters
[in]report_formatReport format.
Returns
1 if predefined, else 0.

◆ update_report_format()

void update_report_format ( report_format_t  report_format,
const gchar *  report_id,
const gchar *  name,
const gchar *  content_type,
const gchar *  extension,
const gchar *  summary,
const gchar *  description,
const gchar *  signature,
array_t *  files,
array_t *  params,
array_t *  params_options 
)

Update a report format from an XML file.

Parameters
[in]report_formatExisting report format.
[in]report_idUUID of report format.
[in]nameNew name.
[in]content_typeNew content type.
[in]extensionNew extension.
[in]summaryNew summary.
[in]descriptionNew description.
[in]signatureNew signature.
[in]filesNew files.
[in]paramsNew params.
[in]params_optionsOptions for new params.

◆ validate_param_value()

static int validate_param_value ( report_format_t  report_format,
report_format_param_t  param,
const char *  name,
const char *  value 
)
static

Validate a value for a report format param.

Parameters
[in]report_formatReport format.
[in]paramParam.
[in]nameName of param.
[in]valuePotential value of param.
Returns
0 success, 1 fail.

◆ verify_report_format()

int verify_report_format ( const char *  report_format_id)

Verify a report format.

Parameters
[in]report_format_idReport format UUID.
Returns
0 success, 1 failed to find report format, 99 permission denied, -1 error.

◆ verify_report_format_internal()

static int verify_report_format_internal ( report_format_t  report_format)
static

Verify a report format.

Parameters
[in]report_formatReport format.
Returns
0 success, -1 error.

◆ verify_signature()

static int verify_signature ( const gchar *  installer,
gsize  installer_size,
const gchar *  signature,
gsize  signature_size,
int *  trust 
)
static

Execute gpg to verify an installer signature.

Parameters
[in]installerInstaller.
[in]installer_sizeSize of installer.
[in]signatureInstaller signature.
[in]signature_sizeSize of installer signature.
[out]trustTrust value.
Returns
0 success, -1 error.