OpenVAS Manager  7.0.3~git
manage_config_host_discovery.c File Reference
#include "manage.h"
#include "manage_sql.h"
#include "sql.h"
#include <assert.h>
Include dependency graph for manage_config_host_discovery.c:

Go to the source code of this file.

Macros

#define G_LOG_DOMAIN   "md main"
 GLib log domain. More...
 
#define NAME   "Global variable settings[checkbox]:Strictly unauthenticated"
 Preference name. More...
 

Functions

void make_config_host_discovery (char *const uuid, char *const selector_name)
 Make Host Discovery Scan Config. More...
 
int check_config_host_discovery (const char *uuid)
 Ensure the Host Discovery config is up to date. More...
 

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "md main"

GLib log domain.

Definition at line 36 of file manage_config_host_discovery.c.

◆ NAME

#define NAME   "Global variable settings[checkbox]:Strictly unauthenticated"

Preference name.

Definition at line 108 of file manage_config_host_discovery.c.

Function Documentation

◆ check_config_host_discovery()

int check_config_host_discovery ( const char *  uuid)

Ensure the Host Discovery config is up to date.

Parameters
[in]uuidUUID of config.
Returns
0 success, -1 error.

Definition at line 118 of file manage_config_host_discovery.c.

119 {
120  int update;
121 
122  update = 0;
123 
124  /* Check new preference. */
125 
126  if (sql_int ("SELECT count (*) FROM config_preferences"
127  " WHERE config = (SELECT id FROM configs WHERE uuid = '%s')"
128  " AND type = 'PLUGINS_PREFS'"
129  " AND name = '" NAME "';",
130  uuid)
131  == 0)
132  {
133  sql ("INSERT INTO config_preferences (config, type, name, value)"
134  " VALUES ((SELECT id FROM configs WHERE uuid = '%s'),"
135  " 'PLUGINS_PREFS',"
136  " '" NAME "',"
137  " 'yes');",
138  uuid);
139  update = 1;
140  }
141 
142  /* Check new NVT. */
143 
144  if (sql_int ("SELECT count (*) FROM nvt_selectors"
145  " WHERE name = (SELECT nvt_selector FROM configs"
146  " WHERE uuid = '%s')"
147  " AND family_or_nvt = '1.3.6.1.4.1.25623.1.0.12288';",
148  uuid)
149  == 0)
150  {
151  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
152  " VALUES ((SELECT nvt_selector FROM configs WHERE uuid = '%s'), 0,"
153  " " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
154  " '1.3.6.1.4.1.25623.1.0.12288', 'Settings');",
155  uuid);
156  update = 1;
157  }
158 
159  if (update)
161 
162  return 0;
163 }
int sql_int(char *sql,...)
Get a particular cell from a SQL query, as an int.
Definition: sql.c:438
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:199
#define NVT_SELECTOR_TYPE_NVT
NVT selector type for "NVT" rule.
Definition: manage.h:2001
#define NAME
Preference name.
void update_config_cache_init(const char *)

References NAME, NVT_SELECTOR_TYPE_NVT, sql(), sql_int(), and update_config_cache_init().

Here is the call graph for this function:

◆ make_config_host_discovery()

void make_config_host_discovery ( char *const  uuid,
char *const  selector_name 
)

Make Host Discovery Scan Config.

Caller must lock the db.

Parameters
[in]uuidUUID for new scan config.
[in]selector_nameName of NVT selector to use.

Definition at line 47 of file manage_config_host_discovery.c.

48 {
49  config_t config;
50 
51  /* Create the Host Discovery config. */
52 
53  sql ("INSERT into configs (uuid, name, owner, nvt_selector, comment,"
54  " family_count, nvt_count, nvts_growing, families_growing,"
55  " type, creation_time, modification_time)"
56  " VALUES ('%s', 'Host Discovery', NULL,"
57  " '%s', 'Network Host Discovery scan configuration.',"
58  " 0, 0, 0, 0, 0, m_now (), m_now ());",
59  uuid,
60  selector_name);
61 
62  config = sql_last_insert_id ();
63 
64  /* Add the Ping Host NVT to the config. */
65 
66  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
67  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
68  " '1.3.6.1.4.1.25623.1.0.100315', 'Port scanners');",
69  selector_name);
70 
71  /* Update number of families and nvts. */
72 
73  sql ("UPDATE configs"
74  " SET family_count = %i, nvt_count = %i,"
75  " modification_time = m_now ()"
76  " WHERE id = %llu;",
77  nvt_selector_family_count (selector_name, 0),
78  nvt_selector_nvt_count (selector_name, NULL, 0),
79  config);
80 
81  /* Add preferences for "ping host" nvt. */
82 
83  sql ("INSERT INTO config_preferences (config, type, name, value)"
84  " VALUES (%llu,"
85  " 'PLUGINS_PREFS',"
86  " 'Ping Host[checkbox]:Mark unrechable Hosts as dead (not scanning)',"
87  " 'yes');",
88  config);
89 
90  sql ("INSERT INTO config_preferences (config, type, name, value)"
91  " VALUES (%llu,"
92  " 'PLUGINS_PREFS',"
93  " 'Ping Host[checkbox]:Report about reachable Hosts',"
94  " 'yes');",
95  config);
96 
97  sql ("INSERT INTO config_preferences (config, type, name, value)"
98  " VALUES (%llu,"
99  " 'PLUGINS_PREFS',"
100  " 'Ping Host[checkbox]:Report about unrechable Hosts',"
101  " 'no');",
102  config);
103 }
long long int config_t
Definition: manage.h:278
resource_t sql_last_insert_id()
Get the ID of the last inserted row.
Definition: sql_pg.c:395
void sql(char *sql,...)
Perform an SQL statement, retrying if database is busy or locked.
Definition: sql.c:199
#define NVT_SELECTOR_TYPE_NVT
NVT selector type for "NVT" rule.
Definition: manage.h:2001
int nvt_selector_nvt_count(const char *, const char *, int)
int nvt_selector_family_count(const char *, int)

References nvt_selector_family_count(), nvt_selector_nvt_count(), NVT_SELECTOR_TYPE_NVT, sql(), and sql_last_insert_id().

Here is the call graph for this function: