OpenVAS Manager  7.0.3~git
manage_config_system_discovery.c
Go to the documentation of this file.
1 /* OpenVAS Manager
2  * $Id$
3  * Description: Manage library: NVTs for "System 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_system_discovery (char *const uuid, char *const selector_name)
48 {
49  config_t config;
50 
51  /* Create the System 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', 'System Discovery', NULL,"
57  " '%s', 'Network System 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 NVTs 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  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
71  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
72  " '1.3.6.1.4.1.25623.1.0.14259', 'Port scanners');",
73  selector_name);
74  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
75  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
76  " '1.3.6.1.4.1.25623.1.0.50282', 'General');",
77  selector_name);
78  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
79  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
80  " '1.3.6.1.4.1.25623.1.0.51662', 'General');",
81  selector_name);
82  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
83  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
84  " '1.3.6.1.4.1.25623.1.0.96207', 'Windows');",
85  selector_name);
86  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
87  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
88  " '1.3.6.1.4.1.25623.1.0.103621', 'Windows');",
89  selector_name);
90  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
91  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
92  " '1.3.6.1.4.1.25623.1.0.103220', 'Product detection');",
93  selector_name);
94  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
95  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
96  " '1.3.6.1.4.1.25623.1.0.102002', 'Product detection');",
97  selector_name);
98  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
99  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
100  " '1.3.6.1.4.1.25623.1.0.103633', 'Product detection');",
101  selector_name);
102  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
103  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
104  " '1.3.6.1.4.1.25623.1.0.103804', 'Product detection');",
105  selector_name);
106  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
107  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
108  " '1.3.6.1.4.1.25623.1.0.96200', 'Product detection');",
109  selector_name);
110  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
111  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
112  " '1.3.6.1.4.1.25623.1.0.103675', 'Product detection');",
113  selector_name);
114  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
115  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
116  " '1.3.6.1.4.1.25623.1.0.103817', 'Product detection');",
117  selector_name);
118  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
119  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
120  " '1.3.6.1.4.1.25623.1.0.103628', 'Product detection');",
121  selector_name);
122  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
123  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
124  " '1.3.6.1.4.1.25623.1.0.803719', 'Product detection');",
125  selector_name);
126  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
127  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
128  " '1.3.6.1.4.1.25623.1.0.103799', 'Product detection');",
129  selector_name);
130  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
131  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
132  " '1.3.6.1.4.1.25623.1.0.103685', 'Product detection');",
133  selector_name);
134  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
135  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
136  " '1.3.6.1.4.1.25623.1.0.103809', 'Product detection');",
137  selector_name);
138  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
139  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
140  " '1.3.6.1.4.1.25623.1.0.103707', 'Product detection');",
141  selector_name);
142  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
143  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
144  " '1.3.6.1.4.1.25623.1.0.103418', 'Product detection');",
145  selector_name);
146  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
147  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
148  " '1.3.6.1.4.1.25623.1.0.10267', 'Product detection');",
149  selector_name);
150  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
151  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
152  " '1.3.6.1.4.1.25623.1.0.103417', 'Product detection');",
153  selector_name);
154  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
155  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
156  " '1.3.6.1.4.1.25623.1.0.103648', 'Product detection');",
157  selector_name);
158  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
159  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
160  " '1.3.6.1.4.1.25623.1.0.103779', 'Product detection');",
161  selector_name);
162  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
163  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
164  " '1.3.6.1.4.1.25623.1.0.103997', 'Service detection');",
165  selector_name);
166  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
167  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
168  " '1.3.6.1.4.1.25623.1.0.10884', 'Service detection');",
169  selector_name);
170  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
171  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
172  " '1.3.6.1.4.1.25623.1.0.102011', 'Service detection');",
173  selector_name);
174  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
175  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
176  " '1.3.6.1.4.1.25623.1.0.101013', 'Service detection');",
177  selector_name);
178  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
179  " VALUES ('%s', 0, " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
180  " '1.3.6.1.4.1.25623.1.0.103416', 'SNMP');",
181  selector_name);
182 
183  /* Update number of families and nvts. */
184 
185  sql ("UPDATE configs"
186  " SET family_count = %i, nvt_count = %i,"
187  " modification_time = m_now ()"
188  " WHERE id = %llu;",
189  nvt_selector_family_count (selector_name, 0),
190  nvt_selector_nvt_count (selector_name, NULL, 0),
191  config);
192 }
193 
201 int
203 {
204  int update;
205 
206  update = 0;
207 
208  /* Check new NVT. */
209 
210  if (sql_int ("SELECT count (*) FROM nvt_selectors"
211  " WHERE name = (SELECT nvt_selector FROM configs"
212  " WHERE uuid = '%s')"
213  " AND family_or_nvt = '1.3.6.1.4.1.25623.1.0.51662';",
214  uuid)
215  == 0)
216  {
217  sql ("INSERT INTO nvt_selectors (name, exclude, type, family_or_nvt, family)"
218  " VALUES ((SELECT nvt_selector FROM configs WHERE uuid = '%s'), 0,"
219  " " G_STRINGIFY (NVT_SELECTOR_TYPE_NVT) ","
220  " '1.3.6.1.4.1.25623.1.0.51662', 'General');",
221  uuid);
222  update = 1;
223  }
224 
225  if (update)
227 
228  return 0;
229 }
void make_config_system_discovery(char *const uuid, char *const selector_name)
Make System 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_system_discovery(const char *uuid)
Ensure the Discovery config is up to date.
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