Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ set(
manage_license.c
manage_openvas.c
manage_osp.c
manage_permissions.c
manage_port_lists.c
manage_preferences.c
manage_resources.c
Expand All @@ -183,6 +184,7 @@ set(
manage_tls_certificates.c
manage_utils.c
manage_migrators.c
manage_permissions.c
manage_pg.c
manage_scan_handler.c
manage_scan_queue.c
Expand Down Expand Up @@ -214,6 +216,7 @@ set(
manage_sql_groups.c
manage_sql_nvts.c
manage_sql_secinfo.c
manage_sql_permissions.c
manage_sql_port_lists.c
manage_sql_configs.c
manage_sql_report_configs.c
Expand Down Expand Up @@ -675,6 +678,7 @@ set(
"${CMAKE_CURRENT_SOURCE_DIR}/manage_get.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage_groups.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage_oci_image_targets.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage_permissions.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage_port_lists.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage_preferences.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage_runtime_flags.c"
Expand All @@ -691,6 +695,7 @@ set(
"${CMAKE_CURRENT_SOURCE_DIR}/manage_sql_configs.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage_sql_nvts.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage_sql_oci_image_targets.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage_sql_permissions.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage_sql_port_lists.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage_sql_report_formats.c"
"${CMAKE_CURRENT_SOURCE_DIR}/manage_sql_roles.c"
Expand Down
1 change: 1 addition & 0 deletions src/gmp_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "gmp_base.h"
#include "manage_acl.h"
#include "manage_filters.h"
#include "manage_permissions.h"

#include <stdlib.h>
#include <string.h>
Expand Down
3 changes: 0 additions & 3 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -2897,9 +2897,6 @@ copy_permission (const char*, const char *, permission_t *);
char*
permission_uuid (permission_t);

int
permission_is_admin (const char *);

int
permission_in_use (permission_t);

Expand Down
29 changes: 29 additions & 0 deletions src/manage_permissions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* Copyright (C) 2026 Greenbone AG
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

#include "manage_sql_permissions.h"

#include <string.h>

#undef G_LOG_DOMAIN
/**
* @brief GLib log domain.
*/
#define G_LOG_DOMAIN "md manage"

/**
* @brief Test whether a permission is the special Admin permission.
*
* @param[in] permission_id UUID of permission.
*
* @return 1 permission is Admin, else 0.
*/
int
permission_is_admin (const char *permission_id)
{
if (permission_id)
return strcmp (permission_id, PERMISSION_UUID_ADMIN_EVERYTHING);
return 0;
}
12 changes: 12 additions & 0 deletions src/manage_permissions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* Copyright (C) 2026 Greenbone AG
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

#ifndef _GVMD_MANAGE_PERMISSIONS_H
#define _GVMD_MANAGE_PERMISSIONS_H

int
permission_is_admin (const char *);

#endif /* not _GVMD_MANAGE_PERMISSIONS_H */
46 changes: 1 addition & 45 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "manage_sql_filters.h"
#include "manage_sql_groups.h"
#include "manage_sql_oci_image_targets.h"
#include "manage_sql_permissions.h"
#include "manage_sql_port_lists.h"
#include "manage_sql_report_configs.h"
#include "manage_sql_report_formats.h"
Expand Down Expand Up @@ -33091,36 +33092,6 @@ modify_schedule (const char *schedule_id, const char *name, const char *comment,

/* Permissions. */

/**
* @brief Adjust location of resource in permissions.
*
* @param[in] type Type.
* @param[in] old Resource ID in old table.
* @param[in] new Resource ID in new table.
* @param[in] to Destination, trash or table.
*/
void
permissions_set_locations (const char *type, resource_t old, resource_t new,
int to)
{
sql ("UPDATE permissions SET resource_location = %i, resource = %llu"
" WHERE resource_type = '%s' AND resource = %llu"
" AND resource_location = %i;",
to,
new,
type,
old,
to == LOCATION_TABLE ? LOCATION_TRASH : LOCATION_TABLE);
sql ("UPDATE permissions_trash SET resource_location = %i, resource = %llu"
" WHERE resource_type = '%s' AND resource = %llu"
" AND resource_location = %i;",
to,
new,
type,
old,
to == LOCATION_TABLE ? LOCATION_TRASH : LOCATION_TABLE);
}

/**
* @brief Set permissions to orphan.
*
Expand Down Expand Up @@ -33936,21 +33907,6 @@ permission_is_predefined (permission_t permission)
permission);
}

/**
* @brief Test whether a permission is the special Admin permission.
*
* @param[in] permission_id UUID of permission.
*
* @return 1 permission is Admin, else 0.
*/
int
permission_is_admin (const char *permission_id)
{
if (permission_id)
return strcmp (permission_id, PERMISSION_UUID_ADMIN_EVERYTHING);
return 0;
}

/**
* @brief Return whether a permission is in use.
*
Expand Down
13 changes: 0 additions & 13 deletions src/manage_sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@
*/
#define MANAGE_NVT_SELECTOR_UUID_ALL "54b45713-d4f4-4435-b20d-304c175ed8c5"

/**
* @brief Predefined role UUID.
*/
#define PERMISSION_UUID_ADMIN_EVERYTHING "b3b56a8c-c2fd-11e2-a135-406186ea4fc5"

/**
* @brief Predefined role UUID.
*/
#define PERMISSION_UUID_SUPER_ADMIN_EVERYTHING "a9801074-6fe2-11e4-9d81-406186ea4fc5"

/**
* @brief Predefined role UUID.
*/
Expand Down Expand Up @@ -472,9 +462,6 @@ tags_remove_resource (const char *, resource_t, int);
void
tags_set_locations (const char *, resource_t, resource_t, int);

void
permissions_set_locations (const char *, resource_t, resource_t, int);

void
permissions_set_orphans (const char *, resource_t, int);

Expand Down
1 change: 1 addition & 0 deletions src/manage_sql_agent_groups.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "manage_sql_agent_groups.h"
#include "manage_sql_agents.h"
#include "manage_sql_copy.h"
#include "manage_sql_permissions.h"

#include <util/uuidutils.h>

Expand Down
1 change: 1 addition & 0 deletions src/manage_sql_alerts.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "manage_acl.h"
#include "manage_sql.h"
#include "manage_sql_filters.h"
#include "manage_sql_permissions.h"
#include "manage_sql_report_formats.h"

#include <ctype.h>
Expand Down
1 change: 1 addition & 0 deletions src/manage_sql_configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "manage_acl.h"
#include "manage_sql.h"
#include "manage_sql_nvts.h"
#include "manage_sql_permissions.h"
#include "sql.h"

#include <assert.h>
Expand Down
1 change: 1 addition & 0 deletions src/manage_sql_filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "manage_filter_utils.h"
#include "manage_settings.h"
#include "manage_sql.h"
#include "manage_sql_permissions.h"

#include <ctype.h>

Expand Down
1 change: 1 addition & 0 deletions src/manage_sql_groups.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "manage_sql_groups.h"
#include "manage_acl.h"
#include "manage_sql.h"
#include "manage_sql_permissions.h"
#include "manage_sql_users.h"
#include "sql.h"

Expand Down
1 change: 1 addition & 0 deletions src/manage_sql_oci_image_targets.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "debug_utils.h"
#include "manage_sql_oci_image_targets.h"
#include "manage_acl.h"
#include "manage_sql_permissions.h"
#include "sql.h"
#include "utils.h"

Expand Down
45 changes: 45 additions & 0 deletions src/manage_sql_permissions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* Copyright (C) 2026 Greenbone AG
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

#include "manage_sql_permissions.h"
#include "manage_acl.h"
#include "sql.h"

/**
* @file
* @brief GVM management layer: Permissions SQL
*
* The Permissions SQL for the GVM management layer.
*/

/**
* @brief Adjust location of resource in permissions.
*
* @param[in] type Type.
* @param[in] old Resource ID in old table.
* @param[in] new Resource ID in new table.
* @param[in] to Destination, trash or table.
*/
void
permissions_set_locations (const char *type, resource_t old, resource_t new,
int to)
{
sql ("UPDATE permissions SET resource_location = %i, resource = %llu"
" WHERE resource_type = '%s' AND resource = %llu"
" AND resource_location = %i;",
to,
new,
type,
old,
to == LOCATION_TABLE ? LOCATION_TRASH : LOCATION_TABLE);
sql ("UPDATE permissions_trash SET resource_location = %i, resource = %llu"
" WHERE resource_type = '%s' AND resource = %llu"
" AND resource_location = %i;",
to,
new,
type,
old,
to == LOCATION_TABLE ? LOCATION_TRASH : LOCATION_TABLE);
}
25 changes: 25 additions & 0 deletions src/manage_sql_permissions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Copyright (C) 2026 Greenbone AG
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

#ifndef _GVMD_MANAGE_SQL_PERMISSIONS_H
#define _GVMD_MANAGE_SQL_PERMISSIONS_H

#include "manage_permissions.h"
#include "manage_resources.h"

/**
* @brief Predefined role UUID.
*/
#define PERMISSION_UUID_ADMIN_EVERYTHING "b3b56a8c-c2fd-11e2-a135-406186ea4fc5"

/**
* @brief Predefined role UUID.
*/
#define PERMISSION_UUID_SUPER_ADMIN_EVERYTHING "a9801074-6fe2-11e4-9d81-406186ea4fc5"

void
permissions_set_locations (const char *, resource_t, resource_t, int);

#endif //_GVMD_MANAGE_SQL_PERMISSIONS_H
1 change: 1 addition & 0 deletions src/manage_sql_port_lists.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "manage_sql_port_lists.h"
#include "manage_acl.h"
#include "manage_sql_permissions.h"
#include "sql.h"

#include <errno.h>
Expand Down
1 change: 1 addition & 0 deletions src/manage_sql_report_configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "debug_utils.h"
#include "manage_sql_report_configs.h"
#include "manage_acl.h"
#include "manage_sql_permissions.h"
#include "manage_sql_report_formats.h"
#include "sql.h"
#include "utils.h"
Expand Down
1 change: 1 addition & 0 deletions src/manage_sql_report_formats.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "debug_utils.h"
#include "manage_sql_report_formats.h"
#include "manage_acl.h"
#include "manage_sql_permissions.h"
#include "manage_sql_report_configs.h"
#include "manage_sql_users.h"
#include "sql.h"
Expand Down
1 change: 1 addition & 0 deletions src/manage_sql_roles.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "manage_sql_roles.h"
#include "manage_acl.h"
#include "manage_sql.h"
#include "manage_sql_permissions.h"
#include "manage_sql_users.h"
#include "sql.h"

Expand Down
1 change: 1 addition & 0 deletions src/manage_sql_tickets.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "manage_sql_tickets.h"
#include "manage_acl.h"
#include "manage_sql.h"
#include "manage_sql_permissions.h"
#include "sql.h"

#include <stdlib.h>
Expand Down
Loading