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
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
24 changes: 0 additions & 24 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*);

Expand Down
1 change: 1 addition & 0 deletions src/manage_agent_installers.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "gmp_base.h"
#include "manage_agent_installers.h"
#include "manage_sql_agent_installers.h"
#include "manage_users.h"

#include <gvm/util/jsonpull.h>
#include <gvm/util/fileutils.h>
Expand Down
1 change: 1 addition & 0 deletions src/manage_alerts.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "manage_sql_report_formats.h"
#include "manage_sql_tickets.h"
#include "manage_tickets.h"
#include "manage_users.h"

#include <bsd/unistd.h>
#include <glib/gstdio.h>
Expand Down
1 change: 1 addition & 0 deletions src/manage_configs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <errno.h>
Expand Down
1 change: 1 addition & 0 deletions src/manage_openvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "manage_openvas.h"
#include "manage_sql.h"
#include "manage_users.h"

#undef G_LOG_DOMAIN
/**
Expand Down
1 change: 1 addition & 0 deletions src/manage_port_lists.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <gvm/util/fileutils.h>
Expand Down
1 change: 1 addition & 0 deletions src/manage_report_formats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <assert.h>
Expand Down
1 change: 1 addition & 0 deletions src/manage_scan_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "manage_sql.h"
#include "manage_sql_scan_queue.h"
#include "manage_scan_handler.h"
#include "manage_users.h"
#include <gvm/base/gvm_sentry.h>
#include <unistd.h>
#include <signal.h>
Expand Down
127 changes: 1 addition & 126 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
*/
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 @@ -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"

Expand Down
90 changes: 90 additions & 0 deletions src/manage_sql_users.c
Original file line number Diff line number Diff line change
@@ -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;
}
Loading
Loading