Greenbone Vulnerability Manager
22.4.0~dev1
|
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 |
#define | REPORT_FORMAT_ITERATOR_COLUMNS |
#define | REPORT_FORMAT_ITERATOR_TRASH_COLUMNS |
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. More... | |
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. More... | |
static void | set_report_format_name (report_format_t report_format, const char *name) |
Set the name of the report format. More... | |
static void | set_report_format_summary (report_format_t report_format, const char *summary) |
Set the summary of the report format. More... | |
static void | set_report_format_active (report_format_t report_format, int active) |
Set the active flag of a report format. More... | |
static int | set_report_format_param (report_format_t, const char *, const char *) |
static const char * | get_sysconf_gpghome () |
Return the name of the sysconf GnuPG home directory. More... | |
static const char * | get_trustedkeys_name () |
Return the name of the trusted keys file name. More... | |
int | resource_predefined (const gchar *type, resource_t resource) |
Return whether a resource is predefined. More... | |
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. More... | |
static int | find_signature (const gchar *location, const gchar *installer_filename, gchar **signature, gsize *signature_size, gchar **uuid) |
Find a signature in a feed. More... | |
static gchar * | report_format_trash_dir (const gchar *report_format_id) |
Get trash directory of a report format. More... | |
gboolean | lookup_report_format (const char *name, report_format_t *report_format) |
Find a report format given a name. More... | |
gboolean | find_report_format_no_acl (const char *uuid, report_format_t *report_format) |
Find a report format given a UUID. More... | |
gboolean | find_trash_report_format_no_acl (const char *uuid, report_format_t *report_format) |
Find a trash report format given a UUID. More... | |
static gint | compare_files (gconstpointer one, gconstpointer two) |
Compare files for create_report_format. More... | |
static int | save_report_format_files (const gchar *report_id, array_t *files, gchar **report_format_dir) |
Save files of a report format. More... | |
static int | add_report_format_params (report_format_t report_format, array_t *params, array_t *params_options) |
Add params to a report format. More... | |
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. More... | |
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. More... | |
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. More... | |
static int | copy_report_format_dir (const gchar *source_dir, const gchar *copy_parent, const gchar *copy_uuid) |
Create a report format dir. More... | |
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. More... | |
static int | report_format_predefined_uuid (const gchar *report_format_id) |
Return whether a report format is predefined. More... | |
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. More... | |
static int | move_report_format_dir (const char *dir, const char *new_dir) |
Move a report format directory. More... | |
static void | delete_report_format_rows (report_format_t report_format) |
Delete a report format from the db. More... | |
int | delete_report_format (const char *report_format_id, int ultimate) |
Delete a report format. More... | |
int | restore_report_format (const char *report_format_id) |
Try restore a report format. More... | |
char * | report_format_uuid (report_format_t report_format) |
Return the UUID of a report format. More... | |
char * | report_format_owner_uuid (report_format_t report_format) |
Return the UUID of the owner of a report format. More... | |
char * | report_format_name (report_format_t report_format) |
Return the name of a report format. More... | |
char * | report_format_content_type (report_format_t report_format) |
Return the content type of a report format. More... | |
int | report_format_in_use (report_format_t report_format) |
Return whether a report format is referenced by an alert. More... | |
int | trash_report_format_in_use (report_format_t report_format) |
Return whether a report format in trash is referenced by an alert. More... | |
int | report_format_predefined (report_format_t report_format) |
Return whether a report format is predefined. More... | |
int | trash_report_format_predefined (report_format_t report_format) |
Return whether a trash report format is predefined. More... | |
char * | report_format_extension (report_format_t report_format) |
Return the extension of a report format. More... | |
int | report_format_active (report_format_t report_format) |
Return whether a report format is active. More... | |
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. More... | |
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. More... | |
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. More... | |
GVM management layer: Report format SQL.
The report format SQL for the GVM management layer.
#define REPORT_FORMAT_ITERATOR_COLUMNS |
#define REPORT_FORMAT_ITERATOR_FILTER_COLUMNS |
#define REPORT_FORMAT_ITERATOR_TRASH_COLUMNS |
|
static |
Add params to a report format.
[in] | report_format | Report format. |
[in] | params | Array of params. |
[in] | params_options | Array. 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. |
|
static |
Compare files for create_report_format.
[in] | one | First. |
[in] | two | Second. |
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.
[in] | name | Name of new Report Format. NULL to copy from existing. |
[in] | source_uuid | UUID of existing Report Format. |
[out] | new_report_format | New Report Format. |
|
static |
Create a report format dir.
[in] | source_dir | Full path of source directory, including UUID. |
[in] | copy_parent | Path of destination directory, excluding UUID. |
[in] | copy_uuid | UUID (dirname) of destination directory. |
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.
[in] | uuid | UUID of format. |
[in] | name | Name of format. |
[in] | content_type | Content type of format. |
[in] | extension | File extension of format. |
[in] | summary | Summary of format. |
[in] | description | Description of format. |
[in] | files | Array of memory. Each item is a file name string, a terminating NULL, the file contents in base64 and a terminating NULL. |
[in] | params | Array of params. |
[in] | params_options | Array. 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] | signature | Signature. |
[out] | report_format | Created report format. |
|
static |
Create a report format.
[in] | check_access | Whether to check for permission. |
[in] | may_exist | Whether it is OK if there is already a report format with this UUID. |
[in] | active | Whether report format is active. |
[in] | trusted | Whether to assumed report format is trusted. |
[in] | uuid | UUID of format. |
[in] | name | Name of format. |
[in] | content_type | Content type of format. |
[in] | extension | File extension of format. |
[in] | summary | Summary of format. |
[in] | description | Description of format. |
[in] | files | Array of memory. Each item is a file name string, a terminating NULL, the file contents in base64 and a terminating NULL. |
[in] | params | Array of params. |
[in] | params_options | Array. 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] | predefined | Whether report format is from the feed. |
[in] | signature | Signature. |
[out] | report_format | Created 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.
[in] | uuid | UUID of format. |
[in] | name | Name of format. |
[in] | content_type | Content type of format. |
[in] | extension | File extension of format. |
[in] | summary | Summary of format. |
[in] | description | Description of format. |
[in] | files | Array of memory. Each item is a file name string, a terminating NULL, the file contents in base64 and a terminating NULL. |
[in] | params | Array of params. |
[in] | params_options | Array. 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] | signature | Signature. |
[in] | predefined | Whether report format is from the feed. |
[out] | report_format | Created report format. |
int delete_report_format | ( | const char * | report_format_id, |
int | ultimate | ||
) |
Delete a report format.
[in] | report_format_id | UUID of Report format. |
[in] | ultimate | Whether to remove entirely, or to trashcan. |
|
static |
Delete a report format from the db.
[in] | report_format | Report format. |
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.
[in] | uuid | UUID of resource. |
[out] | report_format | Report Format return, 0 if no such report format. |
|
static |
Find a signature in a feed.
[in] | location | Feed directory to search for signature. |
[in] | installer_filename | Installer filename. |
[out] | signature | Freshly allocated installer signature. |
[out] | signature_size | Size of installer signature. |
[out] | uuid | Address 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. |
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.
[in] | uuid | UUID of resource. |
[out] | report_format | Report Format return, 0 if no such report format. |
|
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).
|
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.
gboolean lookup_report_format | ( | const char * | name, |
report_format_t * | report_format | ||
) |
Find a report format given a name.
[in] | name | Name of report_format. |
[out] | report_format | Report format return, 0 if successfully failed to find 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.
[in] | report_format_id | UUID of report format. |
[in] | name | Name of report format. |
[in] | summary | Summary of report format. |
[in] | active | Active flag. |
[in] | param_name | Parameter to modify. |
[in] | param_value | Value of parameter. |
|
static |
Move a report format directory.
[in] | dir | Old dir. |
[in] | new_dir | New dir. |
int report_format_active | ( | report_format_t | report_format | ) |
Return whether a report format is active.
[in] | report_format | Report format. |
char* report_format_content_type | ( | report_format_t | report_format | ) |
Return the content type of a report format.
[in] | report_format | Report format. |
char* report_format_extension | ( | report_format_t | report_format | ) |
Return the extension of a report format.
[in] | report_format | Report format. |
int report_format_in_use | ( | report_format_t | report_format | ) |
Return whether a report format is referenced by an alert.
[in] | report_format | Report Format. |
char* report_format_name | ( | report_format_t | report_format | ) |
Return the name of a report format.
[in] | report_format | Report format. |
char* report_format_owner_uuid | ( | report_format_t | report_format | ) |
Return the UUID of the owner of a report format.
[in] | report_format | Report format. |
|
static |
Return the type max of a report format param.
[in] | report_format | Report format. |
[in] | name | Name of param. |
|
static |
Return the type max of a report format param.
[in] | report_format | Report format. |
[in] | name | Name of param. |
|
static |
Return the type min of a report format param.
[in] | report_format | Report format. |
[in] | name | Name of param. |
int report_format_predefined | ( | report_format_t | report_format | ) |
Return whether a report format is predefined.
[in] | report_format | Report format. |
|
static |
Return whether a report format is predefined.
[in] | report_format_id | UUID of report format. |
|
static |
Get trash directory of a report format.
[in] | report_format_id | UUID of report format. NULL for the base dir that holds the report format trash. |
char* report_format_uuid | ( | report_format_t | report_format | ) |
Return the UUID of a report format.
[in] | report_format | Report format. |
int resource_predefined | ( | const gchar * | type, |
resource_t | resource | ||
) |
Return whether a resource is predefined.
[in] | type | Type of resource. |
[in] | resource | Resource. |
int restore_report_format | ( | const char * | report_format_id | ) |
Try restore a report format.
If success, ends transaction for caller before exiting.
[in] | report_format_id | UUID of resource. |
|
static |
Save files of a report format.
[in] | report_id | UUID of format. |
[in] | files | Array of memory. Each item is a file name string, a terminating NULL, the file contents in base64 and a terminating NULL. |
[out] | report_format_dir | Address for dir, or NULL. |
|
static |
Set the active flag of a report format.
[in] | report_format | The report format. |
[in] | active | Active flag. |
|
static |
Set the name of the report format.
[in] | report_format | The report format. |
[in] | name | Name. |
|
static |
Set the summary of the report format.
[in] | report_format | The report format. |
[in] | summary | Summary. |
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.
[in] | rebuild | Whether ignore timestamps to force a rebuild. |
int trash_report_format_in_use | ( | report_format_t | report_format | ) |
Return whether a report format in trash is referenced by an alert.
[in] | report_format | Report Format. |
int trash_report_format_predefined | ( | report_format_t | report_format | ) |
Return whether a trash report format is predefined.
[in] | report_format | Report format. |
|
static |
Validate a value for a report format param.
[in] | report_format | Report format. |
[in] | param | Param. |
[in] | name | Name of param. |
[in] | value | Potential value of param. |
|
static |
Execute gpg to verify an installer signature.
[in] | installer | Installer. |
[in] | installer_size | Size of installer. |
[in] | signature | Installer signature. |
[in] | signature_size | Size of installer signature. |
[out] | trust | Trust value. |