Skip to content

Commit bed20f8

Browse files
mattmundellgreenbonebot
authored andcommitted
Change: move first target functions to dedicated files
1 parent d12c711 commit bed20f8

File tree

10 files changed

+90
-37
lines changed

10 files changed

+90
-37
lines changed

src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ set(
197197
manage_scan_queue.c
198198
manage_oci_image_targets.c
199199
manage_container_image_scanner.c
200+
manage_targets.c
200201
manage_users.c
201202
)
202203

@@ -231,6 +232,7 @@ set(
231232
manage_sql_report_formats.c
232233
manage_sql_resources.c
233234
manage_sql_roles.c
235+
manage_sql_targets.c
234236
manage_sql_tickets.c
235237
manage_sql_tls_certificates.c
236238
manage_sql_users.c
@@ -722,6 +724,7 @@ set(
722724
"${CMAKE_CURRENT_SOURCE_DIR}/manage_sql_resources.c"
723725
"${CMAKE_CURRENT_SOURCE_DIR}/manage_sql_roles.c"
724726
"${CMAKE_CURRENT_SOURCE_DIR}/manage_sql_secinfo.c"
727+
"${CMAKE_CURRENT_SOURCE_DIR}/manage_sql_targets.c"
725728
"${CMAKE_CURRENT_SOURCE_DIR}/manage_sql_tickets.c"
726729
"${CMAKE_CURRENT_SOURCE_DIR}/manage_sql_tls_certificates.c"
727730
"${CMAKE_CURRENT_SOURCE_DIR}/manage_sql_users.c"

src/gmp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
#include "manage_resources.h"
107107
#include "manage_roles.h"
108108
#include "manage_runtime_flags.h"
109+
#include "manage_targets.h"
109110
#include "manage_tls_certificates.h"
110111
#include "manage_users.h"
111112
#include "sql.h"

src/manage.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,9 +1621,6 @@ prognosis_iterator_description (iterator_t*);
16211621
*/
16221622
#define MANAGE_USER_MAX_HOSTS 16777216
16231623

1624-
int
1625-
manage_max_hosts ();
1626-
16271624
int
16281625
manage_count_hosts (const char *, const char *);
16291626

src/manage_sql.c

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "manage_sql_report_formats.h"
5454
#include "manage_sql_resources.h"
5555
#include "manage_sql_roles.h"
56+
#include "manage_sql_targets.h"
5657
#include "manage_sql_tickets.h"
5758
#include "manage_sql_tls_certificates.h"
5859
#include "manage_sql_users.h"
@@ -286,11 +287,6 @@ type_build_select (const char *, const char *, const get_data_t *,
286287
*/
287288
manage_connection_forker_t manage_fork_connection;
288289

289-
/**
290-
* @brief Max number of hosts per target.
291-
*/
292-
static int max_hosts = MANAGE_MAX_HOSTS;
293-
294290
/**
295291
* @brief Memory cache of NVT information from the database.
296292
*/
@@ -4632,7 +4628,7 @@ init_manage_internal (GSList *log_config,
46324628
|| (max_ips_per_target > MANAGE_ABSOLUTE_MAX_IPS_PER_TARGET))
46334629
return -4;
46344630

4635-
max_hosts = max_ips_per_target;
4631+
manage_set_max_hosts (max_ips_per_target);
46364632
if (max_email_attachment_size)
46374633
set_max_email_attachment_size (max_email_attachment_size);
46384634
if (max_email_include_size)
@@ -4684,7 +4680,7 @@ init_manage_internal (GSList *log_config,
46844680
sql ("INSERT INTO meta (name, value)"
46854681
" VALUES ('max_hosts', %i)"
46864682
" ON CONFLICT (name) DO UPDATE SET value = EXCLUDED.value;",
4687-
max_hosts);
4683+
manage_max_hosts ());
46884684
}
46894685

46904686
if (stop_tasks)
@@ -20382,28 +20378,6 @@ modify_task (const gchar *task_id, const gchar *name,
2038220378

2038320379
/* Targets. */
2038420380

20385-
/**
20386-
* @brief Get the maximum allowed number of hosts per target.
20387-
*
20388-
* @return Maximum.
20389-
*/
20390-
int
20391-
manage_max_hosts ()
20392-
{
20393-
return max_hosts;
20394-
}
20395-
20396-
/**
20397-
* @brief Set the maximum allowed number of hosts per target.
20398-
*
20399-
* @param[in] new_max New max_hosts value.
20400-
*/
20401-
void
20402-
manage_set_max_hosts (int new_max)
20403-
{
20404-
max_hosts = new_max;
20405-
}
20406-
2040720381
/**
2040820382
* @brief Find a target for a specific permission, given a UUID.
2040920383
*
@@ -21050,7 +21024,7 @@ create_target (const char* name, const char* asset_hosts_filter,
2105021024
sql_rollback ();
2105121025
return 2;
2105221026
}
21053-
if (max > max_hosts)
21027+
if (max > manage_max_hosts ())
2105421028
{
2105521029
g_free (clean);
2105621030
g_free (clean_exclude);
@@ -21977,7 +21951,7 @@ modify_target (const char *target_id, const char *name, const char *hosts,
2197721951
return 2;
2197821952
}
2197921953

21980-
if (max > max_hosts)
21954+
if (max > manage_max_hosts ())
2198121955
{
2198221956
g_free (clean);
2198321957
g_free (clean_exclude);

src/manage_sql.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,9 +596,6 @@ ldap_auth_enabled ();
596596
int
597597
radius_auth_enabled ();
598598

599-
void
600-
manage_set_max_hosts (int);
601-
602599
gchar*
603600
clean_hosts (const char *, int *);
604601

src/manage_sql_targets.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* Copyright (C) 2026 Greenbone AG
2+
*
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
#include "manage_sql_targets.h"
7+
8+
/**
9+
* @file
10+
* @brief GVM management layer: Targets SQL
11+
*
12+
* The Targets SQL for the GVM management layer.
13+
*/
14+

src/manage_sql_targets.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* Copyright (C) 2026 Greenbone AG
2+
*
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
#ifndef _GVMD_MANAGE_SQL_TARGETS_H
7+
#define _GVMD_MANAGE_SQL_TARGETS_H
8+
9+
#include "manage_targets.h"
10+
11+
#endif // not _GVMD_MANAGE_SQL_TARGETS_H

src/manage_sql_users.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "manage_sql_report_formats.h"
1717
#include "manage_sql_resources.h"
1818
#include "manage_sql_roles.h"
19+
#include "manage_sql_targets.h"
1920
#include "manage_sql_tickets.h"
2021
#include "manage_sql_tls_certificates.h"
2122
#include "sql.h"

src/manage_targets.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* Copyright (C) 2026 Greenbone AG
2+
*
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
#include "manage_sql_targets.h"
7+
#include "manage.h"
8+
9+
#undef G_LOG_DOMAIN
10+
/**
11+
* @brief GLib log domain.
12+
*/
13+
#define G_LOG_DOMAIN "md manage"
14+
15+
/**
16+
* @brief Max number of hosts per target.
17+
*/
18+
static int max_hosts = MANAGE_MAX_HOSTS;
19+
20+
/**
21+
* @brief Get the maximum allowed number of hosts per target.
22+
*
23+
* @return Maximum.
24+
*/
25+
int
26+
manage_max_hosts ()
27+
{
28+
return max_hosts;
29+
}
30+
31+
/**
32+
* @brief Set the maximum allowed number of hosts per target.
33+
*
34+
* @param[in] new_max New max_hosts value.
35+
*/
36+
void
37+
manage_set_max_hosts (int new_max)
38+
{
39+
max_hosts = new_max;
40+
}

src/manage_targets.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* Copyright (C) 2026 Greenbone AG
2+
*
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
#ifndef _GVMD_MANAGE_TARGETS_H
7+
#define _GVMD_MANAGE_TARGETS_H
8+
9+
int
10+
manage_max_hosts ();
11+
12+
void
13+
manage_set_max_hosts (int);
14+
15+
#endif /* not _GVMD_MANAGE_TARGETS_H */

0 commit comments

Comments
 (0)