Greenbone Vulnerability Manager
22.4.0~dev1
|
GVM management layer: Port list SQL. More...
#include "manage_sql_port_lists.h"
#include "manage_acl.h"
#include "manage_port_lists.h"
#include "sql.h"
#include <errno.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
Macros | |
#define | G_LOG_DOMAIN "md manage" |
GLib log domain. | |
#define | RANGE(type, start, end) |
Insert a port range. More... | |
#define | PORT_LIST_ITERATOR_FILTER_COLUMNS { GET_ITERATOR_FILTER_COLUMNS, "total", "tcp", "udp", "predefined", NULL } |
Filter columns for Port List iterator. | |
#define | PORT_LIST_ITERATOR_COLUMNS |
Port List iterator columns. | |
#define | PORT_LIST_ITERATOR_TRASH_COLUMNS |
Port List iterator columns for trash case. | |
Functions | |
int | sync_port_lists_with_feed (gboolean) |
Sync all port lists with the feed. More... | |
static void | make_port_ranges_openvas_default (port_list_t list) |
Make port ranges. More... | |
gboolean | find_port_list (const char *uuid, port_list_t *port_list) |
Find a port list given a UUID. More... | |
gboolean | find_port_list_no_acl (const char *uuid, port_list_t *port_list) |
Find a port list given a UUID. More... | |
gboolean | find_port_list_with_permission (const char *uuid, port_list_t *port_list, const char *permission) |
Find a port list for a specific permission, given a UUID. More... | |
gboolean | find_trash_port_list_no_acl (const char *uuid, port_list_t *port_list) |
Find a trash port list given a UUID. More... | |
int | port_list_predefined (port_list_t port_list) |
Return whether a port list is predefined. More... | |
int | trash_port_list_predefined (port_list_t port_list) |
Return whether a trash port list is predefined. More... | |
static char * | port_range_port_list_uuid (const char *port_range) |
Return the UUID of the port list of a port_range. More... | |
static gboolean | find_port_range_with_permission (const char *uuid, port_range_t *port_range, const char *permission) |
Find a port range given a UUID. More... | |
static int | range_compare (gconstpointer one, gconstpointer two) |
Compare two ranges by type then start. More... | |
static void | ranges_sort_merge (array_t *ranges) |
Sort and merge ranges. More... | |
static int | create_port_list_lock (const char *quoted_id, const char *quoted_name, const char *comment, array_t *ranges, int predefined, port_list_t *port_list) |
Create a port list, with database locked. More... | |
int | create_port_list_unique (const char *name, const char *comment, const char *port_range, port_list_t *port_list) |
Create a port list having a unique name. More... | |
static int | create_port_list_internal (int check_access, const char *id, const char *name, const char *comment, const char *port_ranges, array_t *ranges, int predefined, port_list_t *port_list_return) |
Create a port list. More... | |
int | create_port_list (const char *id, const char *name, const char *comment, const char *port_ranges, array_t *ranges, port_list_t *port_list_return) |
Create a port list. More... | |
int | create_port_list_no_acl (const char *id, const char *name, const char *comment, const char *port_ranges, array_t *ranges, port_list_t *port_list_return) |
Create a port list. More... | |
int | copy_port_list (const char *name, const char *comment, const char *port_list_id, port_list_t *new_port_list) |
Create Port List from an existing Port List. More... | |
static int | port_list_predefined_uuid (const gchar *port_list_id) |
Return whether a port list is predefined. More... | |
int | modify_port_list (const char *port_list_id, const char *name, const char *comment) |
Modify a Port List. More... | |
int | create_port_range (const char *port_list_id, const char *type, const char *start, const char *end, const char *comment, port_range_t *port_range_return) |
Create a port range in a port list. More... | |
int | delete_port_list (const char *port_list_id, int ultimate) |
Delete a port list. More... | |
void | insert_port_range (port_list_t port_list, port_protocol_t type, int start, int end) |
Create a port range. More... | |
int | delete_port_range (const char *port_range_id, int dummy) |
Delete a port range. More... | |
const char ** | port_list_filter_columns () |
Get filter columns. More... | |
column_t * | port_list_select_columns () |
Get select columns. More... | |
int | port_list_count (const get_data_t *get) |
Count the number of Port Lists. More... | |
int | init_port_list_iterator (iterator_t *iterator, const get_data_t *get) |
Initialise a Port List iterator, including observed Port Lists. More... | |
int | port_list_iterator_count_all (iterator_t *iterator) |
Get the port count from a port_list iterator. More... | |
int | port_list_iterator_count_tcp (iterator_t *iterator) |
Get the TCP port count from a port_list iterator. More... | |
int | port_list_iterator_count_udp (iterator_t *iterator) |
Get the UDP port count from a port_list iterator. More... | |
int | port_list_iterator_predefined (iterator_t *iterator) |
Get predefined status from a port_list iterator. More... | |
char * | port_list_uuid (port_list_t port_list) |
Return the UUID of a port_list. More... | |
char * | port_range_uuid (port_range_t port_range) |
Return the UUID of a port_range. More... | |
int | port_list_in_use (port_list_t port_list) |
Return whether a port_list is in use by a task. More... | |
int | trash_port_list_in_use (port_list_t port_list) |
Check whether a trashcan Port List is in use. More... | |
int | port_list_writable (port_list_t port_list) |
Check whether a Port List is writable. More... | |
int | trash_port_list_writable (port_list_t port_list) |
Check whether a trashcan Port List is writable. More... | |
int | trash_port_list_readable_uuid (const gchar *port_list_id) |
Return whether a trashcan port list is readable. More... | |
void | init_port_range_iterator (iterator_t *iterator, port_list_t port_list, int trash, int ascending, const char *sort_field) |
Initialise a port_range iterator. More... | |
const char * | port_range_iterator_comment (iterator_t *iterator) |
Get the comment from a port range iterator. More... | |
const char * | port_range_iterator_type (iterator_t *iterator) |
Get the type from a port range iterator. More... | |
port_protocol_t | port_range_iterator_type_int (iterator_t *iterator) |
Get the type from a port range iterator. More... | |
void | init_port_list_target_iterator (iterator_t *iterator, port_list_t port_list, int ascending) |
Initialise a port list target iterator. More... | |
int | port_list_target_iterator_readable (iterator_t *iterator) |
Get the read permission status from a GET iterator. More... | |
int | restore_port_list (const char *port_list_id) |
Try restore a port list. More... | |
void | empty_trashcan_port_lists () |
Empty trashcan. | |
void | inherit_port_lists (user_t user, user_t inheritor) |
Change ownership of port lists, for user deletion. More... | |
void | delete_port_lists_user (user_t user) |
Delete all port lists owned by a user. More... | |
void | migrate_predefined_port_lists () |
Migrate old ownerless port lists to the Feed Owner. | |
int | port_list_updated_in_feed (port_list_t port_list, const gchar *path) |
Check if a port list has been updated in the feed. More... | |
void | update_port_list (port_list_t port_list, const gchar *name, const gchar *comment, array_t *ranges) |
Update a port list from an XML file. More... | |
void | check_db_port_lists () |
Check port lists, for startup. | |
int | cleanup_port_list_sequences () |
Cleans up port list related id sequences likely to run out. More... | |
GVM management layer: Port list SQL.
The Port List SQL for the GVM management layer.
#define RANGE | ( | type, | |
start, | |||
end | |||
) |
Insert a port range.
int cleanup_port_list_sequences | ( | ) |
Cleans up port list related id sequences likely to run out.
int copy_port_list | ( | const char * | name, |
const char * | comment, | ||
const char * | port_list_id, | ||
port_list_t * | new_port_list | ||
) |
Create Port List from an existing Port List.
[in] | name | Name of new Port List. NULL to copy from existing. |
[in] | comment | Comment on new Port List. NULL to copy from existing. |
[in] | port_list_id | UUID of existing Port List. |
[out] | new_port_list | New Port List. |
int create_port_list | ( | const char * | id, |
const char * | name, | ||
const char * | comment, | ||
const char * | port_ranges, | ||
array_t * | ranges, | ||
port_list_t * | port_list_return | ||
) |
Create a port list.
[in] | id | ID of port list. Only used with ranges . |
[in] | name | Name of port list. |
[in] | comment | Comment on port list. |
[in] | port_ranges | GMP port range string. |
[in] | ranges | Array of port ranges of type range_t. Overrides port_ranges. |
[out] | port_list_return | Created port list. |
|
static |
Create a port list.
[in] | check_access | Whether to check for create_config permission. |
[in] | id | ID of port list. Only used with ranges . |
[in] | name | Name of port list. |
[in] | comment | Comment on port list. |
[in] | port_ranges | GMP port range string. |
[in] | ranges | Array of port ranges of type range_t. Overrides port_ranges. |
[in] | predefined | Whether port list is predefined. |
[out] | port_list_return | Created port list. |
|
static |
Create a port list, with database locked.
Caller must lock the database.
[in] | quoted_id | SQL quoted UUID, or NULL. |
[in] | quoted_name | SQL quoted name of port list. |
[in] | comment | Comment on port list. |
[in] | ranges | Port ranges of port list. |
[in] | predefined | Whether port list is predefined. |
[out] | port_list | Created port list. |
int create_port_list_no_acl | ( | const char * | id, |
const char * | name, | ||
const char * | comment, | ||
const char * | port_ranges, | ||
array_t * | ranges, | ||
port_list_t * | port_list_return | ||
) |
Create a port list.
[in] | id | ID of port list. Only used with ranges . |
[in] | name | Name of port list. |
[in] | comment | Comment on port list. |
[in] | port_ranges | GMP port range string. |
[in] | ranges | Array of port ranges of type range_t. Overrides port_ranges. |
[out] | port_list_return | Created port list. |
int create_port_list_unique | ( | const char * | name, |
const char * | comment, | ||
const char * | port_range, | ||
port_list_t * | port_list | ||
) |
Create a port list having a unique name.
Caller must provide transaction.
[in] | name | Name of port list. |
[in] | comment | Comment on port list. |
[in] | port_range | GMP style port range list. |
[out] | port_list | Created port list. |
int create_port_range | ( | const char * | port_list_id, |
const char * | type, | ||
const char * | start, | ||
const char * | end, | ||
const char * | comment, | ||
port_range_t * | port_range_return | ||
) |
Create a port range in a port list.
[in] | port_list_id | Port list UUID. |
[in] | type | Type. |
[in] | start | Start port. |
[in] | end | End port. |
[in] | comment | Comment. |
[out] | port_range_return | Created port range. |
int delete_port_list | ( | const char * | port_list_id, |
int | ultimate | ||
) |
Delete a port list.
[in] | port_list_id | UUID of port_list. |
[in] | ultimate | Whether to remove entirely, or to trashcan. |
void delete_port_lists_user | ( | user_t | user | ) |
Delete all port lists owned by a user.
[in] | user | The user. |
int delete_port_range | ( | const char * | port_range_id, |
int | dummy | ||
) |
Delete a port range.
[in] | port_range_id | UUID of port_range. |
[in] | dummy | Dummy arg to match other delete functions. |
gboolean find_port_list | ( | const char * | uuid, |
port_list_t * | port_list | ||
) |
Find a port list given a UUID.
[in] | uuid | UUID of port_list. |
[out] | port_list | Port_List return, 0 if successfully failed to find port_list. |
gboolean find_port_list_no_acl | ( | const char * | uuid, |
port_list_t * | port_list | ||
) |
Find a port list given a UUID.
This does not do any permission checks.
[in] | uuid | UUID of resource. |
[out] | port_list | Port list return, 0 if no such port list. |
gboolean find_port_list_with_permission | ( | const char * | uuid, |
port_list_t * | port_list, | ||
const char * | permission | ||
) |
Find a port list for a specific permission, given a UUID.
[in] | uuid | UUID of port list. |
[out] | port_list | Port list return, 0 if successfully failed to find port list. |
[in] | permission | Permission. |
|
static |
Find a port range given a UUID.
[in] | uuid | UUID of port_range. |
[out] | port_range | Port range return, 0 if successfully failed to find port range. |
[in] | permission | UUID of port_range. |
gboolean find_trash_port_list_no_acl | ( | const char * | uuid, |
port_list_t * | port_list | ||
) |
Find a trash port list given a UUID.
This does not do any permission checks.
[in] | uuid | UUID of resource. |
[out] | port_list | Port list return, 0 if no such port list. |
void inherit_port_lists | ( | user_t | user, |
user_t | inheritor | ||
) |
Change ownership of port lists, for user deletion.
[in] | user | Current owner. |
[in] | inheritor | New owner. |
int init_port_list_iterator | ( | iterator_t * | iterator, |
const get_data_t * | get | ||
) |
Initialise a Port List iterator, including observed Port Lists.
[in] | iterator | Iterator. |
[in] | get | GET data. |
void init_port_list_target_iterator | ( | iterator_t * | iterator, |
port_list_t | port_list, | ||
int | ascending | ||
) |
Initialise a port list target iterator.
[in] | iterator | Iterator. |
[in] | port_list | Port list. |
[in] | ascending | Whether to sort ascending or descending. |
void init_port_range_iterator | ( | iterator_t * | iterator, |
port_list_t | port_list, | ||
int | trash, | ||
int | ascending, | ||
const char * | sort_field | ||
) |
Initialise a port_range iterator.
[in] | iterator | Iterator. |
[in] | port_list | Port list. |
[in] | trash | Whether port_list is in the trashcan. |
[in] | ascending | Whether to sort ascending or descending. |
[in] | sort_field | Field to sort on, or NULL for type then start. |
void insert_port_range | ( | port_list_t | port_list, |
port_protocol_t | type, | ||
int | start, | ||
int | end | ||
) |
Create a port range.
[in] | port_list | Port list to insert into. |
[in] | type | Protocol: PORT_PROTOCOL_UDP or PORT_PROTOCOL_TCP. |
[in] | start | Start of range. |
[in] | end | End of range. |
|
static |
Make port ranges.
Caller must lock the db.
[in] | list | Port list. |
int modify_port_list | ( | const char * | port_list_id, |
const char * | name, | ||
const char * | comment | ||
) |
Modify a Port List.
[in] | port_list_id | UUID of Port List. |
[in] | name | Name of Port List. |
[in] | comment | Comment on Port List. |
int port_list_count | ( | const get_data_t * | get | ) |
Count the number of Port Lists.
[in] | get | GET params. |
const char** port_list_filter_columns | ( | ) |
Get filter columns.
int port_list_in_use | ( | port_list_t | port_list | ) |
Return whether a port_list is in use by a task.
[in] | port_list | Port_List. |
int port_list_iterator_count_all | ( | iterator_t * | iterator | ) |
Get the port count from a port_list iterator.
[in] | iterator | Iterator. |
int port_list_iterator_count_tcp | ( | iterator_t * | iterator | ) |
Get the TCP port count from a port_list iterator.
[in] | iterator | Iterator. |
int port_list_iterator_count_udp | ( | iterator_t * | iterator | ) |
Get the UDP port count from a port_list iterator.
[in] | iterator | Iterator. |
int port_list_iterator_predefined | ( | iterator_t * | iterator | ) |
Get predefined status from a port_list iterator.
[in] | iterator | Iterator. |
int port_list_predefined | ( | port_list_t | port_list | ) |
Return whether a port list is predefined.
[in] | port_list | Port list. |
|
static |
Return whether a port list is predefined.
[in] | port_list_id | UUID of port list. |
column_t* port_list_select_columns | ( | ) |
Get select columns.
int port_list_target_iterator_readable | ( | iterator_t * | iterator | ) |
Get the read permission status from a GET iterator.
[in] | iterator | Iterator. |
int port_list_updated_in_feed | ( | port_list_t | port_list, |
const gchar * | path | ||
) |
Check if a port list has been updated in the feed.
[in] | path | Full path to port list XML in feed. |
[in] | port_list | Port List. |
char* port_list_uuid | ( | port_list_t | port_list | ) |
Return the UUID of a port_list.
[in] | port_list | Port_List. |
int port_list_writable | ( | port_list_t | port_list | ) |
Check whether a Port List is writable.
[in] | port_list | Port List. |
const char* port_range_iterator_comment | ( | iterator_t * | iterator | ) |
Get the comment from a port range iterator.
[in] | iterator | Iterator. |
const char* port_range_iterator_type | ( | iterator_t * | iterator | ) |
Get the type from a port range iterator.
[in] | iterator | Iterator. |
port_protocol_t port_range_iterator_type_int | ( | iterator_t * | iterator | ) |
Get the type from a port range iterator.
[in] | iterator | Iterator. |
|
static |
Return the UUID of the port list of a port_range.
[in] | port_range | Port Range UUID. |
char* port_range_uuid | ( | port_range_t | port_range | ) |
Return the UUID of a port_range.
[in] | port_range | Port Range. |
|
static |
Compare two ranges by type then start.
[in] | one | First range. |
[in] | two | Second range. |
|
static |
Sort and merge ranges.
[in] | ranges | Array of port ranges of type range_t. |
int restore_port_list | ( | const char * | port_list_id | ) |
Try restore a port list.
If success, ends transaction for caller before exiting.
[in] | port_list_id | UUID of resource. |
int sync_port_lists_with_feed | ( | gboolean | rebuild | ) |
Sync all port lists with the feed.
Create port lists that exists in the feed but not in the db. Update port lists in the db that have changed on the feed. Do nothing to db port lists that have been removed from the feed.
[in] | rebuild | Whether ignore timestamps to force a rebuild. |
int trash_port_list_in_use | ( | port_list_t | port_list | ) |
Check whether a trashcan Port List is in use.
[in] | port_list | Port List. |
int trash_port_list_predefined | ( | port_list_t | port_list | ) |
Return whether a trash port list is predefined.
[in] | port_list | Port list. |
int trash_port_list_readable_uuid | ( | const gchar * | port_list_id | ) |
Return whether a trashcan port list is readable.
[in] | port_list_id | Port list UUID. |
int trash_port_list_writable | ( | port_list_t | port_list | ) |
Check whether a trashcan Port List is writable.
[in] | port_list | Port List. |
void update_port_list | ( | port_list_t | port_list, |
const gchar * | name, | ||
const gchar * | comment, | ||
array_t * | ranges | ||
) |
Update a port list from an XML file.
[in] | port_list | Existing port list. |
[in] | name | New name. |
[in] | comment | New comment. |
[in] | ranges | New port ranges. |