diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3a0af0091..e0b234fe0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -188,6 +188,7 @@ set( manage_scan_queue.c manage_oci_image_targets.c manage_container_image_scanner.c + manage_users.c ) if(ENABLE_AGENTS) @@ -220,6 +221,7 @@ set( manage_sql_roles.c manage_sql_tickets.c manage_sql_tls_certificates.c + manage_sql_users.c manage_sql_nvts_osp.c manage_sql_nvts_openvasd.c manage_sql_nvts_common.c @@ -695,7 +697,9 @@ set( "${CMAKE_CURRENT_SOURCE_DIR}/manage_sql_secinfo.c" "${CMAKE_CURRENT_SOURCE_DIR}/manage_sql_tickets.c" "${CMAKE_CURRENT_SOURCE_DIR}/manage_sql_tls_certificates.c" + "${CMAKE_CURRENT_SOURCE_DIR}/manage_sql_users.c" "${CMAKE_CURRENT_SOURCE_DIR}/manage_migrators.c" + "${CMAKE_CURRENT_SOURCE_DIR}/manage_users.c" "${CMAKE_CURRENT_SOURCE_DIR}/lsc_user.c" "${CMAKE_CURRENT_SOURCE_DIR}/lsc_crypt.c" "${CMAKE_CURRENT_SOURCE_DIR}/sql.c" diff --git a/src/gmp.c b/src/gmp.c index 5b069b4f5..df1e1e254 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -105,6 +105,7 @@ #include "manage_roles.h" #include "manage_runtime_flags.h" #include "manage_tls_certificates.h" +#include "manage_users.h" #include "sql.h" #include "utils.h" diff --git a/src/manage.h b/src/manage.h index 0b7d6d236..666f44db4 100644 --- a/src/manage.h +++ b/src/manage.h @@ -3276,33 +3276,9 @@ modify_user (const gchar *, gchar **, const gchar *, const gchar *, const array_t *, array_t *, gchar **, array_t *, gchar **, gchar **); -int -user_in_use (user_t); - -int -trash_user_in_use (user_t); - -int -user_writable (user_t); - -int -trash_user_writable (user_t); - int user_count (const get_data_t*); -gchar* -user_name (const char *); - -char* -user_uuid (user_t); - -gchar* -user_hosts (const char *); - -int -user_hosts_allow (const char *); - int init_vuln_iterator (iterator_t*, const get_data_t*); diff --git a/src/manage_agent_installers.c b/src/manage_agent_installers.c index edbd92eae..c7041bf25 100644 --- a/src/manage_agent_installers.c +++ b/src/manage_agent_installers.c @@ -13,6 +13,7 @@ #include "gmp_base.h" #include "manage_agent_installers.h" #include "manage_sql_agent_installers.h" +#include "manage_users.h" #include #include diff --git a/src/manage_alerts.c b/src/manage_alerts.c index 8c2598fcf..308b1f64b 100644 --- a/src/manage_alerts.c +++ b/src/manage_alerts.c @@ -20,6 +20,7 @@ #include "manage_sql_report_formats.h" #include "manage_sql_tickets.h" #include "manage_tickets.h" +#include "manage_users.h" #include #include diff --git a/src/manage_configs.c b/src/manage_configs.c index 87b82365a..b2317deb7 100644 --- a/src/manage_configs.c +++ b/src/manage_configs.c @@ -14,6 +14,7 @@ #include "manage_configs.h" #include "manage_sql.h" #include "manage_sql_configs.h" +#include "manage_users.h" #include "utils.h" #include diff --git a/src/manage_openvas.c b/src/manage_openvas.c index d18abea26..69e9769fa 100644 --- a/src/manage_openvas.c +++ b/src/manage_openvas.c @@ -10,6 +10,7 @@ #include "manage_openvas.h" #include "manage_sql.h" +#include "manage_users.h" #undef G_LOG_DOMAIN /** diff --git a/src/manage_port_lists.c b/src/manage_port_lists.c index 1e0ad9ba5..7d3f0d29c 100644 --- a/src/manage_port_lists.c +++ b/src/manage_port_lists.c @@ -14,6 +14,7 @@ #include "gmp_port_lists.h" #include "manage.h" #include "manage_sql_port_lists.h" +#include "manage_users.h" #include "utils.h" #include diff --git a/src/manage_report_formats.c b/src/manage_report_formats.c index e28ba6838..5384a09b6 100644 --- a/src/manage_report_formats.c +++ b/src/manage_report_formats.c @@ -15,6 +15,7 @@ #include "manage.h" #include "manage_sql.h" #include "manage_sql_report_formats.h" +#include "manage_users.h" #include "utils.h" #include diff --git a/src/manage_scan_handler.c b/src/manage_scan_handler.c index b20615ac6..36075b243 100644 --- a/src/manage_scan_handler.c +++ b/src/manage_scan_handler.c @@ -13,6 +13,7 @@ #include "manage_sql.h" #include "manage_sql_scan_queue.h" #include "manage_scan_handler.h" +#include "manage_users.h" #include #include #include diff --git a/src/manage_sql.c b/src/manage_sql.c index f4e5700db..2e698c81f 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -57,6 +57,7 @@ #include "manage_commands.h" #include "manage_authentication.h" #include "manage_oci_image_targets.h" +#include "manage_users.h" #include "lsc_user.h" #include "sql.h" #include "utils.h" @@ -39841,132 +39842,6 @@ modify_user (const gchar * user_id, gchar **name, const gchar *new_name, return 0; } -/** - * @brief Return the name of a user. - * - * @param[in] uuid UUID of user. - * - * @return Newly allocated name if available, else NULL. - */ -gchar* -user_name (const char *uuid) -{ - gchar *name, *quoted_uuid; - - quoted_uuid = sql_quote (uuid); - name = sql_string ("SELECT name FROM users WHERE uuid = '%s';", - quoted_uuid); - g_free (quoted_uuid); - return name; -} - -/** - * @brief Return the UUID of a user. - * - * Warning: this is only safe for users that are known to be in the db. - * - * @param[in] user User. - * - * @return Newly allocated UUID if available, else NULL. - */ -char* -user_uuid (user_t user) -{ - return sql_string ("SELECT uuid FROM users WHERE id = %llu;", - user); -} - -/** - * @brief Check whether a user is in use. - * - * @param[in] user User. - * - * @return 1 yes, 0 no. - */ -int -user_in_use (user_t user) -{ - return 0; -} - -/** - * @brief Check whether a trashcan user is in use. - * - * @param[in] user User. - * - * @return 1 yes, 0 no. - */ -int -trash_user_in_use (user_t user) -{ - return 0; -} - -/** - * @brief Check whether a user is writable. - * - * @param[in] user User. - * - * @return 1 yes, 0 no. - */ -int -user_writable (user_t user) -{ - return 1; -} - -/** - * @brief Check whether a trashcan user is writable. - * - * @param[in] user User. - * - * @return 1 yes, 0 no. - */ -int -trash_user_writable (user_t user) -{ - return 1; -} - -/** - * @brief Return the hosts of a user. - * - * @param[in] uuid UUID of user. - * - * @return Newly allocated hosts value if available, else NULL. - */ -gchar* -user_hosts (const char *uuid) -{ - gchar *name, *quoted_uuid; - - quoted_uuid = sql_quote (uuid); - name = sql_string ("SELECT hosts FROM users WHERE uuid = '%s';", - quoted_uuid); - g_free (quoted_uuid); - return name; -} - -/** - * @brief Return whether hosts value of a user denotes allowed. - * - * @param[in] uuid UUID of user. - * - * @return 1 if allow, else 0. - */ -int -user_hosts_allow (const char *uuid) -{ - gchar *quoted_uuid; - int allow; - - quoted_uuid = sql_quote (uuid); - allow = sql_int ("SELECT hosts_allow FROM users WHERE uuid = '%s';", - quoted_uuid); - g_free (quoted_uuid); - return allow; -} - /** * @brief User columns for user iterator. */ diff --git a/src/manage_sql_report_formats.c b/src/manage_sql_report_formats.c index 1b4bfd8ed..5881a7a8a 100644 --- a/src/manage_sql_report_formats.c +++ b/src/manage_sql_report_formats.c @@ -15,6 +15,7 @@ #include "manage_acl.h" #include "manage_report_configs.h" #include "manage_report_formats.h" +#include "manage_users.h" #include "sql.h" #include "utils.h" diff --git a/src/manage_sql_users.c b/src/manage_sql_users.c new file mode 100644 index 000000000..936bb5335 --- /dev/null +++ b/src/manage_sql_users.c @@ -0,0 +1,90 @@ +/* Copyright (C) 2026 Greenbone AG + * + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#include "manage_users.h" +#include "manage_acl.h" +#include "manage_sql.h" +#include "sql.h" + +/** + * @file + * @brief GVM management layer: Users SQL + * + * The Users SQL for the GVM management layer. + */ + +/** + * @brief Return the name of a user. + * + * @param[in] uuid UUID of user. + * + * @return Newly allocated name if available, else NULL. + */ +gchar * +user_name (const char *uuid) +{ + gchar *name, *quoted_uuid; + + quoted_uuid = sql_quote (uuid); + name = sql_string ("SELECT name FROM users WHERE uuid = '%s';", + quoted_uuid); + g_free (quoted_uuid); + return name; +} + +/** + * @brief Return the UUID of a user. + * + * Warning: this is only safe for users that are known to be in the db. + * + * @param[in] user User. + * + * @return Newly allocated UUID if available, else NULL. + */ +char* +user_uuid (user_t user) +{ + return sql_string ("SELECT uuid FROM users WHERE id = %llu;", + user); +} + +/** + * @brief Return the hosts of a user. + * + * @param[in] uuid UUID of user. + * + * @return Newly allocated hosts value if available, else NULL. + */ +gchar * +user_hosts (const char *uuid) +{ + gchar *name, *quoted_uuid; + + quoted_uuid = sql_quote (uuid); + name = sql_string ("SELECT hosts FROM users WHERE uuid = '%s';", + quoted_uuid); + g_free (quoted_uuid); + return name; +} + +/** + * @brief Return whether hosts value of a user denotes allowed. + * + * @param[in] uuid UUID of user. + * + * @return 1 if allow, else 0. + */ +int +user_hosts_allow (const char *uuid) +{ + gchar *quoted_uuid; + int allow; + + quoted_uuid = sql_quote (uuid); + allow = sql_int ("SELECT hosts_allow FROM users WHERE uuid = '%s';", + quoted_uuid); + g_free (quoted_uuid); + return allow; +} diff --git a/src/manage_users.c b/src/manage_users.c new file mode 100644 index 000000000..66d9aa0b6 --- /dev/null +++ b/src/manage_users.c @@ -0,0 +1,64 @@ +/* Copyright (C) 2026 Greenbone AG + * + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#include "manage_users.h" + +#undef G_LOG_DOMAIN +/** + * @brief GLib log domain. + */ +#define G_LOG_DOMAIN "md manage" + +/** + * @brief Check whether a user is in use. + * + * @param[in] user User. + * + * @return 1 yes, 0 no. + */ +int +user_in_use (user_t user) +{ + return 0; +} + +/** + * @brief Check whether a trashcan user is in use. + * + * @param[in] user User. + * + * @return 1 yes, 0 no. + */ +int +trash_user_in_use (user_t user) +{ + return 0; +} + +/** + * @brief Check whether a user is writable. + * + * @param[in] user User. + * + * @return 1 yes, 0 no. + */ +int +user_writable (user_t user) +{ + return 1; +} + +/** + * @brief Check whether a trashcan user is writable. + * + * @param[in] user User. + * + * @return 1 yes, 0 no. + */ +int +trash_user_writable (user_t user) +{ + return 1; +} diff --git a/src/manage_users.h b/src/manage_users.h new file mode 100644 index 000000000..4f18dfcc8 --- /dev/null +++ b/src/manage_users.h @@ -0,0 +1,35 @@ +/* Copyright (C) 2026 Greenbone AG + * + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#ifndef _GVMD_MANAGE_USERS_H +#define _GVMD_MANAGE_USERS_H + +#include "manage_resources.h" + +gchar * +user_name (const char *); + +char * +user_uuid (user_t); + +int +user_in_use (user_t); + +int +trash_user_in_use (user_t); + +int +user_writable (user_t); + +int +trash_user_writable (user_t); + +gchar * +user_hosts (const char *); + +int +user_hosts_allow (const char *); + +#endif /* not _GVMD_MANAGE_USERS_H */