35 #include <openvas/nasl/nasl.h> 36 #include <openvas/misc/nvt_categories.h> 37 #include <openvas/misc/plugutils.h> 38 #include <openvas/misc/network.h> 39 #include <openvas/misc/prefs.h> 41 #include <openvas/base/nvticache.h> 64 n = recv_line (soc, buf,
sizeof (buf) - 1);
67 log_write (
"Failed reading client-requested OTP version.");
71 buf[
sizeof (buf) - 1] =
'\0';
72 if (strncmp (buf,
"< OTP/2.0 >", 11))
74 log_write (
"Unknown client-requested OTP version: %s.", buf);
77 nsend (soc,
"< OTP/2.0 >\n", 12, 0);
93 n = recv_line (soc, buf,
sizeof (buf) - 1);
96 log_write (
"Failed reading client input.");
100 g_snprintf (buf,
sizeof (buf),
"SCANNER_LOADING <|> %d <|> %d\n",
103 n = nsend (soc, buf, len, 0);
107 n = recv_line (soc, buf,
sizeof (buf) - 1);
117 is_client_present (
int soc)
129 e = select (soc + 1, &rd, NULL, NULL, &tv);
148 send_printf (soc,
"SERVER <|> BYE <|> BYE <|> SERVER\n");
149 while (is_client_present (soc))
154 n = recv_line (soc, buffer,
sizeof (buffer) - 1);
155 if (n < 0 || *buffer ==
'\0')
167 char *name = NULL, *copyright = NULL, *version = NULL, *family = NULL;
168 char *cve_id = NULL, *bid = NULL, *xref = NULL, *tag = NULL;
170 category = nvticache_get_category (oid);
171 if (category >= ACT_UNKNOWN || category < ACT_FIRST)
172 category = ACT_UNKNOWN;
173 version = nvticache_get_version (oid);
174 name = nvticache_get_name (oid);
175 if (!name || strchr (name,
'\n'))
177 log_write (
"Erroneous name for plugin %s", oid);
180 copyright = nvticache_get_copyright (oid);
181 if (!copyright || strchr (copyright,
'\n'))
183 log_write (
"Erroneous copyright for plugin %s", oid);
186 family = nvticache_get_family (oid);
189 log_write (
"Missing family for plugin %s", oid);
193 cve_id = nvticache_get_cves (oid);
194 bid = nvticache_get_bids (oid);
195 xref = nvticache_get_xrefs (oid);
196 tag = nvticache_get_tags (oid);
209 (soc,
"%s <|> %s <|> %d <|> %s <|> %s <|> %s <|> %s <|> %s <|> " 210 "%s <|> %s\n", oid, name, category, copyright, family, version,
211 (cve_id && *cve_id) ? cve_id :
"NOCVE", (bid && *bid) ? bid :
"NOBID",
212 (xref && *xref) ? xref:
"NOXREF", (tag && *tag) ? tag :
"NOTAG");
234 GSList *
list, *element;
236 list = element = nvticache_get_oids ();
241 element = element->next;
244 g_slist_free_full (
list, g_free);
250 GSList *
list, *element;
252 list = element = nvticache_get_oids ();
255 GSList *tmp, *nprefs;
256 char *name = nvticache_get_name (element->data);
258 tmp = nprefs = nvticache_get_prefs (element->data);
261 const nvtpref_t *nvtpref = tmp->data;
262 send_printf (soc,
"%s[%s]:%s <|> %s\n", name, nvtpref_type (nvtpref),
263 g_strchomp (nvtpref_name (nvtpref)),
264 nvtpref_default (nvtpref));
268 g_slist_free_full (nprefs, (
void (*) (
void *)) nvtpref_free);
269 element = element->next;
271 g_slist_free_full (
list, g_free);
281 struct arglist *prefs = preferences_get ();
286 while (prefs && prefs->next)
290 (
const char *) prefs->value);
305 int soc = arg_get_value_int (globals,
"global_socket");
309 static char str[2048];
312 memset (str,
'\0',
sizeof (str));
313 n = recv_line (soc, str,
sizeof (str) - 1);
316 log_write (
"Client closed the communication");
320 if (!is_client_present (soc))
331 log_write (
"Client input parsing error: %s", str);
348 nvt_feed_version (
char *feed_version,
int feed_size)
351 gchar *command, *info_file;
352 info_file = g_build_filename (OPENVAS_NVT_DIR,
"plugin_feed_info.inc", NULL);
353 command = g_strdup_printf (
"grep PLUGIN_SET %s | sed -e 's/[^0-9]//g'",
356 foutput = popen (command,
"r");
357 if (fgets (feed_version, feed_size, foutput) == NULL)
365 feed_version[strlen (feed_version) - 1] =
'\0';
380 is_valid_feed_version (
const char *feed_version)
382 if (feed_version == NULL)
385 while (*feed_version)
386 if (!g_ascii_isdigit (*feed_version++))
401 feed_version = g_malloc0 (feed_size);
402 nvt_feed_version (feed_version, feed_size);
404 send_printf (soc,
"SERVER <|> NVT_INFO <|> %s <|> SERVER\n",
405 is_valid_feed_version (feed_version)
406 ? feed_version :
"NOVERSION");
408 g_free (feed_version);
412 bzero (buf,
sizeof (buf));
413 recv_line (soc, buf,
sizeof (buf) - 1);
414 if (strstr (buf,
"COMPLETE_LIST"))
void log_write(const char *str,...)
Write into the logfile / syslog.
void send_printf(int soc, char *data,...)
Writes data to a socket.
int comm_loading(int soc)
Informs the client that the scanner is still loading.
int total_loading_plugins(void)
void comm_send_nvt_info(int soc)
Send the OTP NVT_INFO message and then handle any COMPLETE_LIST.
void comm_send_preferences(int soc)
Sends the preferences of the scanner.
void comm_send_pluginlist(int soc)
Sends the list of plugins that the scanner could load to the client,.
void send_plugins_preferences(int soc)
void send_plug_info(int soc, const char *oid)
Sends a plugin info.
int current_loading_plugins(void)
int is_scanner_only_pref(const char *pref)
int comm_init(int soc)
Initializes the communication between the scanner (us) and the client.
int ntp_parse_input(struct arglist *globals, char *input)
Parses the input sent by the client before the NEW_ATTACK message.
int comm_wait_order(struct arglist *globals)
This function waits for the attack order of the client. Meanwhile, it processes all the messages the ...
void comm_terminate(int soc)
This function must be called at the end of a session.