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

GVM management layer: Ticket SQL. More...

#include "manage_tickets.h"
#include "manage_acl.h"
#include "manage_sql_tickets.h"
#include "manage_sql.h"
#include "sql.h"
#include <stdlib.h>
#include <string.h>

Macros

#define G_LOG_DOMAIN   "md manage"
 GLib log domain.
 
#define TICKET_ITERATOR_FILTER_COLUMNS
 Filter columns for ticket iterator. More...
 
#define TICKET_ITERATOR_COLUMNS
 Ticket iterator columns.
 
#define TICKET_ITERATOR_TRASH_COLUMNS
 Ticket iterator columns for trash case.
 

Enumerations

enum  ticket_status_t {
  TICKET_STATUS_OPEN = 0 , TICKET_STATUS_FIXED = 1 , TICKET_STATUS_FIX_VERIFIED = 2 , TICKET_STATUS_CLOSED = 3 ,
  TICKET_STATUS_MAX , TICKET_STATUS_ERROR = 100
}
 Ticket statuses.
 

Functions

static ticket_status_t ticket_status_integer (const char *status)
 Get ticket status DB identifier from string. More...
 
int ticket_count (const get_data_t *get)
 Count number of tickets. More...
 
int init_ticket_iterator (iterator_t *iterator, const get_data_t *get)
 Initialise a ticket iterator. More...
 
double ticket_iterator_severity (iterator_t *iterator)
 Get a column value from a ticket iterator. More...
 
int ticket_iterator_orphan (iterator_t *iterator)
 Get column value from a ticket iterator. More...
 
int init_ticket_result_iterator (iterator_t *iterator, const gchar *ticket_id, int trash)
 Initialise a ticket result iterator. More...
 
int init_result_ticket_iterator (iterator_t *iterator, result_t result)
 Initialise a result ticket iterator. More...
 
user_t ticket_owner (ticket_t ticket)
 Return owner of ticket. More...
 
user_t ticket_assigned_to (ticket_t ticket)
 Return user that ticket is assigned to. More...
 
gchar * ticket_nvt_name (ticket_t ticket)
 Return NVT name of ticket. More...
 
static task_t ticket_task (ticket_t ticket)
 Return task of ticket. More...
 
int ticket_in_use (ticket_t ticket)
 Return whether a ticket is in use. More...
 
int trash_ticket_in_use (ticket_t ticket)
 Return whether a trashcan ticket is in use. More...
 
int ticket_writable (ticket_t ticket)
 Return whether a ticket is writable. More...
 
int trash_ticket_writable (ticket_t ticket)
 Return whether a trashcan ticket is writable. More...
 
int delete_ticket (const char *ticket_id, int ultimate)
 Delete a ticket. More...
 
int restore_ticket (const char *ticket_id)
 Try restore a ticket. More...
 
int create_ticket (const char *comment, const char *result_id, const char *user_id, const char *open_note, ticket_t *ticket)
 Create a ticket. More...
 
int copy_ticket (const char *comment, const char *ticket_id, ticket_t *new_ticket)
 Create a ticket from an existing ticket. More...
 
char * ticket_uuid (ticket_t ticket)
 Return the UUID of a ticket. More...
 
static int set_note (ticket_t ticket, const gchar *name, const gchar *note)
 Set a note on a ticket. More...
 
int modify_ticket (const gchar *ticket_id, const gchar *comment, const gchar *status_name, const gchar *open_note, const gchar *fixed_note, const gchar *closed_note, const gchar *user_id)
 Modify a ticket. More...
 
void empty_trashcan_tickets ()
 Empty ticket trashcans.
 
void check_tickets (task_t task)
 Check if tickets have been resolved. More...
 
void delete_tickets_user (user_t user)
 Delete all tickets owner by a user. More...
 
void inherit_tickets (user_t user, user_t inheritor)
 Change ownership of tickets, for user deletion. More...
 
void tickets_remove_task (task_t task)
 Remove a task from all tickets. More...
 
void tickets_remove_report (report_t report)
 Remove a report from all tickets. More...
 
void tickets_remove_tasks_user (user_t user)
 Remove all of a user's tasks from all tickets. More...
 
void tickets_trash_task (task_t task)
 Adjust tickets for task being moved to trash. More...
 
void tickets_restore_task (task_t task)
 Adjust tickets for task being restored. More...
 

Detailed Description

GVM management layer: Ticket SQL.

The Ticket SQL for the GVM management layer.

Macro Definition Documentation

◆ TICKET_ITERATOR_FILTER_COLUMNS

#define TICKET_ITERATOR_FILTER_COLUMNS
Value:
{ GET_ITERATOR_FILTER_COLUMNS, "severity", "host", "location", \
"solution_type", "status", "opened", "fixed", "closed", "orphan", \
"result_id", "username", NULL }

Filter columns for ticket iterator.

Function Documentation

◆ check_tickets()

void check_tickets ( task_t  task)

Check if tickets have been resolved.

Parameters
[in]taskTask.

◆ copy_ticket()

int copy_ticket ( const char *  comment,
const char *  ticket_id,
ticket_t *  new_ticket 
)

Create a ticket from an existing ticket.

Parameters
[in]commentComment on new ticket. NULL to copy from existing.
[in]ticket_idUUID of existing ticket.
[out]new_ticketNew ticket.
Returns
0 success, 1 ticket exists already, 2 failed to find existing ticket, 99 permission denied, -1 error.

◆ create_ticket()

int create_ticket ( const char *  comment,
const char *  result_id,
const char *  user_id,
const char *  open_note,
ticket_t *  ticket 
)

Create a ticket.

Parameters
[in]commentComment on ticket.
[in]result_idResult that the ticket is on.
[in]user_idUser the ticket is assigned to.
[in]open_noteNote on open status.
[out]ticketCreated ticket.
Returns
0 success, 1 failed to find user, 2 failed to find result, 99 permission to create ticket denied, 98 permission to create permission denied, -1 error.

◆ delete_ticket()

int delete_ticket ( const char *  ticket_id,
int  ultimate 
)

Delete a ticket.

Parameters
[in]ticket_idUUID of ticket.
[in]ultimateWhether to remove entirely, or to trashcan.
Returns
0 success, 1 fail because ticket is in use, 2 failed to find ticket, 99 permission denied, -1 error.

◆ delete_tickets_user()

void delete_tickets_user ( user_t  user)

Delete all tickets owner by a user.

Also delete trash tickets and assign any tickets that were assigned to the user back to the owner.

Parameters
[in]userThe user.

◆ inherit_tickets()

void inherit_tickets ( user_t  user,
user_t  inheritor 
)

Change ownership of tickets, for user deletion.

Also assign tickets that are assigned to the user to the inheritor.

Parameters
[in]userCurrent owner.
[in]inheritorNew owner.

◆ init_result_ticket_iterator()

int init_result_ticket_iterator ( iterator_t iterator,
result_t  result 
)

Initialise a result ticket iterator.

Will iterate over all the tickets that apply to the result's NVT.

Parameters
[in]iteratorIterator.
[in]resultResult.
Returns
0 success, -1 error.

◆ init_ticket_iterator()

int init_ticket_iterator ( iterator_t iterator,
const get_data_t get 
)

Initialise a ticket iterator.

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

◆ init_ticket_result_iterator()

int init_ticket_result_iterator ( iterator_t iterator,
const gchar *  ticket_id,
int  trash 
)

Initialise a ticket result iterator.

Will iterate over all the results assigned to the ticket.

Parameters
[in]iteratorIterator.
[in]ticket_idUUID of ticket.
[in]trashWhether ticket is in trash.
Returns
0 success, 1 failed to find ticket, -1 error.

◆ modify_ticket()

int modify_ticket ( const gchar *  ticket_id,
const gchar *  comment,
const gchar *  status_name,
const gchar *  open_note,
const gchar *  fixed_note,
const gchar *  closed_note,
const gchar *  user_id 
)

Modify a ticket.

Parameters
[in]ticket_idUUID of ticket.
[in]commentComment on ticket.
[in]status_nameStatus of ticket.
[in]open_noteNote if status is 'Open'.
[in]fixed_noteNote if status is 'Fixed'.
[in]closed_noteNote if status is 'Closed'.
[in]user_idUUID of user that ticket is assigned to.
Returns
0 success, 1 ticket exists already, 2 failed to find ticket, 3 failed to find user, 4 error in status, 5 Fixed status requires a fixed_note, 6 Closed status requires a closed_note, 7 Open status requires an open_note, 99 permission denied, -1 error.

◆ restore_ticket()

int restore_ticket ( const char *  ticket_id)

Try restore a ticket.

If success, ends transaction for caller before exiting.

Parameters
[in]ticket_idUUID of resource.
Returns
0 success, 1 fail because ticket is in use, 2 failed to find ticket, -1 error.

◆ set_note()

static int set_note ( ticket_t  ticket,
const gchar *  name,
const gchar *  note 
)
static

Set a note on a ticket.

Parameters
[in]ticketTicket.
[in]nameName of note column.
[in]noteNote text.
Returns
1 if ticket modified, else 0.

◆ ticket_assigned_to()

user_t ticket_assigned_to ( ticket_t  ticket)

Return user that ticket is assigned to.

Parameters
[in]ticketTicket.
Returns
User.

◆ ticket_count()

int ticket_count ( const get_data_t get)

Count number of tickets.

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

◆ ticket_in_use()

int ticket_in_use ( ticket_t  ticket)

Return whether a ticket is in use.

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

◆ ticket_iterator_orphan()

int ticket_iterator_orphan ( iterator_t iterator)

Get column value from a ticket iterator.

Parameters
[in]iteratorIterator.
Returns
Value of the column, or -1 if iteration is complete.

◆ ticket_iterator_severity()

double ticket_iterator_severity ( iterator_t iterator)

Get a column value from a ticket iterator.

Parameters
[in]iteratorIterator.
Returns
Value of the column, or SEVERITY_MISSING if iteration is complete.

◆ ticket_nvt_name()

gchar* ticket_nvt_name ( ticket_t  ticket)

Return NVT name of ticket.

Parameters
[in]ticketTicket.
Returns
NVT name.

◆ ticket_owner()

user_t ticket_owner ( ticket_t  ticket)

Return owner of ticket.

Parameters
[in]ticketTicket.
Returns
Owner.

◆ ticket_status_integer()

static ticket_status_t ticket_status_integer ( const char *  status)
static

Get ticket status DB identifier from string.

Parameters
[in]statusStatus name.
Returns
Status integer.

◆ ticket_task()

static task_t ticket_task ( ticket_t  ticket)
static

Return task of ticket.

Parameters
[in]ticketTicket.
Returns
Task if there is one, else 0.

◆ ticket_uuid()

char* ticket_uuid ( ticket_t  ticket)

Return the UUID of a ticket.

Parameters
[in]ticketTicket.
Returns
Newly allocated UUID if available, else NULL.

◆ ticket_writable()

int ticket_writable ( ticket_t  ticket)

Return whether a ticket is writable.

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

◆ tickets_remove_report()

void tickets_remove_report ( report_t  report)

Remove a report from all tickets.

Parameters
[in]reportReport.

◆ tickets_remove_task()

void tickets_remove_task ( task_t  task)

Remove a task from all tickets.

Parameters
[in]taskTask.

◆ tickets_remove_tasks_user()

void tickets_remove_tasks_user ( user_t  user)

Remove all of a user's tasks from all tickets.

Parameters
[in]userUser.

◆ tickets_restore_task()

void tickets_restore_task ( task_t  task)

Adjust tickets for task being restored.

This must be called while the old and new results still exist.

Parameters
[in]taskTask.

◆ tickets_trash_task()

void tickets_trash_task ( task_t  task)

Adjust tickets for task being moved to trash.

This must be called while the old and new results still exist.

Parameters
[in]taskTask.

◆ trash_ticket_in_use()

int trash_ticket_in_use ( ticket_t  ticket)

Return whether a trashcan ticket is in use.

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

◆ trash_ticket_writable()

int trash_ticket_writable ( ticket_t  ticket)

Return whether a trashcan ticket is writable.

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