OpenVAS Manager  7.0.3~git
manage_config_host_discovery.c
Go to the documentation of this file.
1 /* OpenVAS Manager
2  * $Id$
3  * Description: Manage library: NVTs for "Host Discovery" scan configuration.
4  *
5  * Authors:
6  * Hani Benhabiles <hani.benhabiles@greenbone.net>
7  *
8  * Copyright:
9  * Copyright (C) 2013 Greenbone Networks GmbH
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25 
26 #include "manage.h"
27 #include "manage_sql.h"
28 #include "sql.h"
29 
30 #include <assert.h>
31 
32 #undef G_LOG_DOMAIN
33 
36 #define G_LOG_DOMAIN "md main"
37 
46 void
47 make_config_host_discovery (char *const uuid, char *const selector_name)
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 }
104 
108 #define NAME "Global variable settings[checkbox]:Strictly unauthenticated"
109 
117 int
118 check_config_host_discovery (const char *uuid)
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 }
void make_config_host_discovery(char *const uuid, char *const selector_name)
Make Host Discovery Scan Config.
int sql_int(char *sql,...)
Get a particular cell from a SQL query, as an int.
Definition: sql.c:438
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 check_config_host_discovery(const char *uuid)
Ensure the Host Discovery config is up to date.
#define NAME
Preference name.
int nvt_selector_nvt_count(const char *, const char *, int)
Get the number of NVTs selected by an NVT selector.
Definition: manage_sql.c:39704
int nvt_selector_family_count(const char *, int)
Get the number of families selected by an NVT selector.
Definition: manage_sql.c:39347
void update_config_cache_init(const char *uuid)
Update count and growing info in config, without checking user.
Definition: manage_sql.c:38210