OpenVAS Manager  7.0.3~git
otp.h File Reference
#include "manage.h"
#include <glib.h>
Include dependency graph for otp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  scanner_init_state_t {
  SCANNER_INIT_CONNECTED, SCANNER_INIT_DONE, SCANNER_INIT_DONE_CACHE_MODE, SCANNER_INIT_DONE_CACHE_MODE_UPDATE,
  SCANNER_INIT_GOT_FEED_VERSION, SCANNER_INIT_GOT_PLUGINS, SCANNER_INIT_SENT_COMPLETE_LIST, SCANNER_INIT_SENT_COMPLETE_LIST_UPDATE,
  SCANNER_INIT_SENT_VERSION, SCANNER_INIT_TOP
}
 Possible initialisation states of the scanner. More...
 

Functions

void init_otp_data ()
 Initialise OTP library data. More...
 
int process_otp_scanner_input (void(*)())
 Process any lines available in from_scanner. More...
 
void set_scanner_init_state (scanner_init_state_t state)
 Set the scanner initialisation state, scanner_init_state. More...
 
void reset_scanner_states ()
 Set the scanner initialisation state, scanner_init_state. More...
 

Variables

scanner_init_state_t scanner_init_state
 The initialisation state of the scanner. More...
 
int scanner_current_loading
 Scanner current number of loaded plugins, when still loading. More...
 
int scanner_total_loading
 Scanner total number of plugins to be loaded, when still loading. More...
 
int scanner_init_offset
 Offset into initialisation string being sent to scanner. More...
 

Enumeration Type Documentation

◆ scanner_init_state_t

Possible initialisation states of the scanner.

Todo:
Exported for following functions.
Enumerator
SCANNER_INIT_CONNECTED 
SCANNER_INIT_DONE 
SCANNER_INIT_DONE_CACHE_MODE 
SCANNER_INIT_DONE_CACHE_MODE_UPDATE 
SCANNER_INIT_GOT_FEED_VERSION 
SCANNER_INIT_GOT_PLUGINS 
SCANNER_INIT_SENT_COMPLETE_LIST 
SCANNER_INIT_SENT_COMPLETE_LIST_UPDATE 
SCANNER_INIT_SENT_VERSION 
SCANNER_INIT_TOP 

Definition at line 42 of file otp.h.

Function Documentation

◆ init_otp_data()

void init_otp_data ( )

Initialise OTP library data.

This must run once, before the first call to process_otp_scanner_input.

Definition at line 342 of file otp.c.

Referenced by openvas_scanner_connect_unix().

343 {
344  plugins_feed_version = NULL;
345 }
Here is the caller graph for this function:

◆ process_otp_scanner_input()

int process_otp_scanner_input ( void(*)()  progress)

Process any lines available in from_scanner.

Update scanner information according to the input from the scanner.

This function simply records input from the scanner. Output to the scanner or client is almost always done via process_omp_client_input in reaction to client requests, the only exception being stop requests initiated in other processes.

Parameters
[in]progressFunction to mark progress, or NULL.
Returns
0 success, 1 received scanner BYE, 2 bad login, 3 scanner loading, -1 error.
Todo:
Replace "\n" with newline in description.
Todo:
Field could be "general".
Todo:
Replace "\n" with newline in description.
Todo:
Field could be "general".
Todo:
Replace "\n" with newline in description.
Todo:
Field could be "general".
Todo:
Exit more formally with Scanner?
Todo:
Consider reading all fields up to <|> SERVER?

Definition at line 781 of file otp.c.

References from_scanner, from_scanner_end, from_scanner_start, manage_check_current_task(), SCANNER_INIT_SENT_VERSION, and scanner_init_state.

Referenced by openvas_scanner_is_loading().

782 {
783  char* match = NULL;
784  char* messages = from_scanner + from_scanner_start;
785  char* input;
786  const char *ver_str = "< OTP/2.0 >\n";
787  size_t ver_len = strlen (ver_str);
788  buffer_size_t from_start, from_end;
789  //g_debug (" consider %.*s\n", from_scanner_end - from_scanner_start, messages);
790 
791  /* Before processing the input, check if another manager process has stopped
792  * the current task. If so, send the stop request to the scanner. This is
793  * the only place in this file that writes to the to_scanner buffer, and hence
794  * the only place that requires that the writes to to_scanner in the OMP XML
795  * handlers must be whole OTP commands. */
796 
797  if (manage_check_current_task () == -1)
798  {
799  /* Out of space in to_scanner. Just treat it as an error for now. */
800  return -1;
801  }
802 
803  /* First, handle special scanner states where the input from the scanner
804  * ends in something other than <|> (usually a newline). */
805 
806  switch (scanner_init_state)
807  {
809  /* Read over any whitespace left by the previous session. */
811  && (messages[0] == ' ' || messages[0] == '\n'))
812  from_scanner_start++, messages++;
813 
814  if (scanner_is_loading (messages))
815  {
816  parse_scanner_loading (messages);
818  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE,
819  "Waiting for scanner to load NVTs: %d / %d.\n",
821  else
822  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE,
823  "Waiting for scanner to load: No information provided. (Message: %s)\n", messages);
824  return 3;
825  }
826  /* If message is empty we assume the scanner is still loading. */
827  if (!*messages)
828  {
829  return 5;
830  }
831  if (from_scanner_end - from_scanner_start < ver_len)
832  {
833  /* Need more input. */
834  if (sync_buffer ()) return -1;
835  return 0;
836  }
837  if (strncasecmp (ver_str, messages, ver_len))
838  {
839  g_debug (" scanner fail: expected \"%s\""
840  " got \"%.12s\"\n\n", ver_str, messages);
841  return -1;
842  }
843  from_scanner_start += ver_len;
844  messages += ver_len;
846  return 0;
848  /* Nothing to parse. */
849  return 0;
851  /* Nothing to parse. */
852  return 0;
854  /* Input from scanner before version string sent. */
855  return -1;
858  case SCANNER_INIT_DONE:
861  case SCANNER_INIT_TOP:
862  if (scanner_state == SCANNER_TOP)
863  switch (parse_scanner_bad_login (&messages))
864  {
865  case 0: return 2; /* Found bad login response. */
866  case 1: break;
867  }
868  else if (scanner_state == SCANNER_DONE)
869  switch (parse_scanner_done (&messages))
870  {
871  case -1: return -1;
872  case -2:
873  /* Need more input. */
874  if (sync_buffer ()) return -1;
875  return 0;
876  }
877  else if (scanner_state == SCANNER_PLUGIN_LIST_TAGS)
878  switch (parse_scanner_plugin_list_tags (&messages))
879  {
880  case -2:
881  /* Need more input. */
882  if (sync_buffer ()) return -1;
883  return 0;
884  }
885  else if (scanner_state == SCANNER_PREFERENCE_VALUE)
886  {
887  switch (parse_scanner_preference_value (&messages, progress))
888  {
889  case -2:
890  /* Need more input. */
891  if (sync_buffer ()) return -1;
892  return 0;
893  }
894  g_free (current_scanner_preference);
895  current_scanner_preference = NULL;
896  }
897  else if (scanner_state == SCANNER_SERVER)
898  /* Look for any newline delimited scanner commands. */
899  switch (parse_scanner_server (&messages))
900  {
901  case 0: break; /* Found newline delimited command. */
902  case -1: return -1; /* Error. */
903  case -2:
904  /* Need more input. */
905  if (sync_buffer ()) return -1;
906  return 0;
907  case -3: break; /* Next <|> is before next \n. */
908  case -4: break; /* Failed to find \n, try for <|>. */
909  }
910  break;
911  } /* switch (scanner_init_state) */
912 
913  /* Parse and handle any fields ending in <|>. */
914 
915  input = messages;
916  from_start = from_scanner_start;
917  from_end = from_scanner_end;
918  while (from_start < from_end
919  && ((match = memchr (input,
920  (int) '<',
921  from_end - from_start))
922  != NULL))
923  {
924  assert (match >= input);
925 
926  /* Check whether we've had a transaction open too long, because
927  * it may take some time until we get out of this loop and do a
928  * process_omp_change, and we don't want to hold up other writer
929  * processes. Note that in GSA even tabular pages like Tasks now
930  * write (settings) to the db. */
931  manage_transaction_stop (FALSE);
932 
933  if ((((match - input) + from_start + 1) < from_end)
934  && (match[1] == '|')
935  && (match[2] == '>'))
936  {
937  char* message;
938  char* field;
939  /* Found a full field, process the field. */
940  message = messages;
941  *match = '\0';
942  from_scanner_start += match + 3 - messages;
943  from_start = from_scanner_start;
944  messages = match + 3;
945  input = messages;
946 
947  /* Strip leading and trailing whitespace. */
948  field = openvas_strip_space (message, match);
949  blank_control_chars (field);
950 
951  g_debug (" scanner old state %i\n", scanner_state);
952  g_debug (" scanner field: %s\n", field);
953  switch (scanner_state)
954  {
955  case SCANNER_BYE:
956  if (strcasecmp ("BYE", field))
957  goto return_error;
958  /* It's up to the caller to set the init state, as the
959  * caller must flush the ACK. */
960  set_scanner_state (SCANNER_DONE);
961  switch (parse_scanner_done (&messages))
962  {
963  case 0:
964  if (sync_buffer ()) goto return_error;
965  if (acknowledge_bye ()) goto return_error;
966  goto return_bye;
967  case -1: goto return_error;
968  case -2:
969  /* Need more input. */
970  if (sync_buffer ()) goto return_error;
971  goto return_need_more;
972  }
973  break;
975  {
976  if (current_message)
977  {
979  char* description = g_strdup (field);
980  set_message_description (current_message, description);
981  }
982  set_scanner_state (SCANNER_ERRMSG_OID);
983  break;
984  }
985  case SCANNER_ERRMSG_HOST:
986  {
987  assert (current_message == NULL);
988  current_message = make_message (field);
989  set_scanner_state (SCANNER_ERRMSG_NUMBER);
990  break;
991  }
993  {
995  int number;
996  char *protocol, *formatted;
997 
998  assert (current_message);
999 
1000  protocol = g_newa (char, strlen (field));
1001 
1002  if (sscanf (field, "%i/%s",
1003  &number, protocol)
1004  != 2)
1005  {
1006  number = atoi (field);
1007  protocol[0] = '\0';
1008  }
1009  g_debug (" scanner got debug port, number: %i, protocol: %s\n",
1010  number, protocol);
1011 
1012  set_message_port_number (current_message, number);
1013  set_message_port_protocol (current_message, protocol);
1014 
1015  formatted = port_name_formatted (field);
1016  if (formatted == NULL)
1017  formatted = g_strdup (field);
1018  set_message_port_string (current_message, formatted);
1019 
1020  set_scanner_state (SCANNER_ERRMSG_DESCRIPTION);
1021  break;
1022  }
1023  case SCANNER_ERRMSG_OID:
1024  {
1025  if (current_message != NULL
1026  && current_scanner_task != (task_t) 0)
1027  {
1028  char* oid = g_strdup (field);
1029  set_message_oid (current_message, oid);
1030 
1031  append_error_message (current_scanner_task, current_message);
1032  free_message (current_message);
1033  current_message = NULL;
1034  }
1035  set_scanner_state (SCANNER_DONE);
1036  switch (parse_scanner_done (&messages))
1037  {
1038  case -1: goto return_error;
1039  case -2:
1040  /* Need more input. */
1041  if (sync_buffer ()) goto return_error;
1042  goto return_need_more;
1043  }
1044  break;
1045  }
1047  {
1048  if (current_message)
1049  {
1051  char* description = g_strdup (field);
1052  set_message_description (current_message, description);
1053  }
1054  set_scanner_state (SCANNER_ALARM_OID);
1055  break;
1056  }
1057  case SCANNER_ALARM_HOST:
1058  {
1059  assert (current_message == NULL);
1060  current_message = make_message (field);
1061  set_scanner_state (SCANNER_ALARM_NUMBER);
1062  break;
1063  }
1064  case SCANNER_ALARM_NUMBER:
1065  {
1067  int number;
1068  char *protocol, *formatted;
1069 
1070  assert (current_message);
1071 
1072  protocol = g_newa (char, strlen (field));
1073 
1074  if (sscanf (field, "%i/%s",
1075  &number, protocol)
1076  != 2)
1077  {
1078  number = atoi (field);
1079  protocol[0] = '\0';
1080  }
1081  g_debug (" scanner got alarm port, number: %i, protocol: %s\n",
1082  number, protocol);
1083 
1084  set_message_port_number (current_message, number);
1085  set_message_port_protocol (current_message, protocol);
1086 
1087  formatted = port_name_formatted (field);
1088  if (formatted == NULL)
1089  formatted = g_strdup (field);
1090  set_message_port_string (current_message, formatted);
1091 
1092  set_scanner_state (SCANNER_ALARM_DESCRIPTION);
1093  break;
1094  }
1095  case SCANNER_ALARM_OID:
1096  {
1097  if (current_message != NULL
1098  && current_scanner_task != (task_t) 0)
1099  {
1100  char* oid = g_strdup (field);
1101  set_message_oid (current_message, oid);
1102 
1103  append_alarm_message (current_scanner_task, current_message);
1104  free_message (current_message);
1105  current_message = NULL;
1106  }
1107  set_scanner_state (SCANNER_DONE);
1108  switch (parse_scanner_done (&messages))
1109  {
1110  case -1: goto return_error;
1111  case -2:
1112  /* Need more input. */
1113  if (sync_buffer ()) goto return_error;
1114  goto return_need_more;
1115  }
1116  break;
1117  }
1119  {
1120  if (current_message)
1121  {
1123  char* description = g_strdup (field);
1124  set_message_description (current_message, description);
1125  }
1126  set_scanner_state (SCANNER_LOG_OID);
1127  break;
1128  }
1129  case SCANNER_LOG_HOST:
1130  {
1131  assert (current_message == NULL);
1132  current_message = make_message (field);
1133  set_scanner_state (SCANNER_LOG_NUMBER);
1134  break;
1135  }
1136  case SCANNER_LOG_NUMBER:
1137  {
1139  int number;
1140  char *protocol, *formatted;
1141 
1142  assert (current_message);
1143 
1144  protocol = g_newa (char, strlen (field));
1145 
1146  if (sscanf (field, "%i/%s",
1147  &number, protocol)
1148  != 2)
1149  {
1150  number = atoi (field);
1151  protocol[0] = '\0';
1152  }
1153  g_debug (" scanner got log port, number: %i, protocol: %s\n",
1154  number, protocol);
1155 
1156  set_message_port_number (current_message, number);
1157  set_message_port_protocol (current_message, protocol);
1158 
1159  formatted = port_name_formatted (field);
1160  if (formatted == NULL)
1161  formatted = g_strdup (field);
1162  set_message_port_string (current_message, formatted);
1163 
1164  set_scanner_state (SCANNER_LOG_DESCRIPTION);
1165  break;
1166  }
1167  case SCANNER_LOG_OID:
1168  {
1169  if (current_message != NULL
1170  && current_scanner_task != (task_t) 0)
1171  {
1172  char* oid = g_strdup (field);
1173  set_message_oid (current_message, oid);
1174 
1175  append_log_message (current_scanner_task, current_message);
1176  free_message (current_message);
1177  current_message = NULL;
1178  }
1179  set_scanner_state (SCANNER_DONE);
1180  switch (parse_scanner_done (&messages))
1181  {
1182  case -1: goto return_error;
1183  case -2:
1184  /* Need more input. */
1185  if (sync_buffer ()) goto return_error;
1186  goto return_need_more;
1187  }
1188  break;
1189  }
1191  {
1192  /* Use match[1] instead of field[1] for UTF-8 hack. */
1193  if (strlen (field) == 0 && match[1] == '|')
1194  {
1195  set_scanner_state (SCANNER_DONE);
1196  switch (parse_scanner_done (&messages))
1197  {
1198  case 0:
1199  if (scanner_init_state
1203  {
1205  set_nvts_feed_version (plugins_feed_version);
1206  }
1207  break;
1208  case -1: goto return_error;
1209  case -2:
1210  /* Need more input. */
1211  if (sync_buffer ()) goto return_error;
1212  goto return_need_more;
1213  }
1214  break;
1215  }
1216  assert (current_plugin == NULL);
1217  current_plugin = nvti_new ();
1218  if (progress)
1219  progress ();
1220  if (current_plugin == NULL) abort ();
1221  nvti_set_oid (current_plugin, field);
1222  set_scanner_state (SCANNER_PLUGIN_LIST_NAME);
1223  break;
1224  }
1226  {
1227  nvti_set_name (current_plugin, field);
1228  set_scanner_state (SCANNER_PLUGIN_LIST_CATEGORY);
1229  break;
1230  }
1232  {
1233  nvti_set_category (current_plugin, category_number (field));
1234  set_scanner_state (SCANNER_PLUGIN_LIST_COPYRIGHT);
1235  break;
1236  }
1238  {
1239  nvti_set_copyright (current_plugin, field);
1240  set_scanner_state (SCANNER_PLUGIN_LIST_FAMILY);
1241  break;
1242  }
1244  {
1245  nvti_set_family (current_plugin, field);
1246  set_scanner_state (SCANNER_PLUGIN_LIST_PLUGIN_VERSION);
1247  break;
1248  }
1250  {
1251  nvti_set_version (current_plugin, field);
1252  set_scanner_state (SCANNER_PLUGIN_LIST_CVE_ID);
1253  break;
1254  }
1256  {
1257  nvti_set_cve (current_plugin, field);
1258  set_scanner_state (SCANNER_PLUGIN_LIST_BUGTRAQ_ID);
1259  break;
1260  }
1262  {
1263  nvti_set_bid (current_plugin, field);
1264  set_scanner_state (SCANNER_PLUGIN_LIST_XREFS);
1265  break;
1266  }
1268  {
1269  nvti_set_xref (current_plugin, field);
1270  set_scanner_state (SCANNER_PLUGIN_LIST_TAGS);
1271  switch (parse_scanner_plugin_list_tags (&messages))
1272  {
1273  case -2:
1274  /* Need more input. */
1275  if (sync_buffer ()) goto return_error;
1276  goto return_need_more;
1277  }
1278  break;
1279  }
1280  case SCANNER_NVT_INFO:
1281  {
1282  char* feed_version = g_strdup (field);
1283  g_debug (" scanner got nvti_info: %s\n", feed_version);
1284  if (plugins_feed_version)
1285  g_free (plugins_feed_version);
1286  plugins_feed_version = feed_version;
1287  set_scanner_state (SCANNER_DONE);
1288  switch (parse_scanner_done (&messages))
1289  {
1290  case 0:
1293  else if (acknowledge_feed_version_info ())
1294  goto return_error;
1295  break;
1296  case -1: goto return_error;
1297  case -2:
1298  /* Need more input. */
1299  if (sync_buffer ()) goto return_error;
1300  goto return_need_more;
1301  }
1302  break;
1303  }
1305  {
1306  /* Use match[1] instead of field[1] for UTF-8 hack. */
1307  if (strlen (field) == 0 && match[1] == '|')
1308  {
1309  set_scanner_state (SCANNER_DONE);
1310  switch (parse_scanner_done (&messages))
1311  {
1312  case -1: goto return_error;
1313  case -2:
1314  /* Need more input. */
1315  if (sync_buffer ()) goto return_error;
1316  goto return_need_more;
1317  }
1321  {
1326  ? -2 : -1);
1329  /* Return 1, as though the scanner sent BYE. */
1331  goto return_bye;
1332  }
1333  break;
1334  }
1335 
1336  {
1337  int value_start = -1, value_end = -1, count;
1338  char name[21];
1339  /* LDAPsearch[entry]:Timeout value */
1340  count = sscanf (field, "%20[^[][%*[^]]]:%n%*[ -~]%n",
1341  name, &value_start, &value_end);
1342  if (count == 1 && value_start > 0 && value_end > 0
1343  && ((strcmp (name, "SSH Authorization") == 0)
1344  || (strcmp (name, "SMB Authorization") == 0)))
1345  current_scanner_preference = NULL;
1346  else
1347  current_scanner_preference = g_strdup (field);
1348  set_scanner_state (SCANNER_PREFERENCE_VALUE);
1349  switch (parse_scanner_preference_value (&messages,
1350  progress))
1351  {
1352  case -2:
1353  /* Need more input. */
1354  if (sync_buffer ()) goto return_error;
1355  goto return_need_more;
1356  }
1357  g_free (current_scanner_preference);
1358  current_scanner_preference = NULL;
1359  }
1360  break;
1361  }
1362  case SCANNER_SERVER:
1363  if (strcasecmp ("BYE", field) == 0)
1364  set_scanner_state (SCANNER_BYE);
1365  else if (strcasecmp ("ERRMSG", field) == 0)
1366  set_scanner_state (SCANNER_ERRMSG_HOST);
1367  else if (strcasecmp ("FILE_ACCEPTED", field) == 0)
1368  {
1369  set_scanner_state (SCANNER_DONE);
1370  switch (parse_scanner_done (&messages))
1371  {
1372  case -1: goto return_error;
1373  case -2:
1374  /* Need more input. */
1375  if (sync_buffer ()) goto return_error;
1376  goto return_need_more;
1377  }
1378  }
1379  else if (strcasecmp ("ALARM", field) == 0)
1380  set_scanner_state (SCANNER_ALARM_HOST);
1381  else if (strcasecmp ("LOG", field) == 0)
1382  set_scanner_state (SCANNER_LOG_HOST);
1383  else if (strcasecmp ("NVT_INFO", field) == 0)
1384  set_scanner_state (SCANNER_NVT_INFO);
1385  else if (strcasecmp ("PLUGIN_LIST", field) == 0)
1386  {
1387  set_scanner_state (SCANNER_PLUGIN_LIST_OID);
1388  }
1389  else if (strcasecmp ("PREFERENCES", field) == 0)
1390  {
1391  assert (current_scanner_preference == NULL);
1392  set_scanner_state (SCANNER_PREFERENCE_NAME);
1393  }
1394  else if (strcasecmp ("TIME", field) == 0)
1395  {
1396  set_scanner_state (SCANNER_TIME);
1397  }
1398  else if (strcasecmp ("STATUS", field) == 0)
1399  {
1400  set_scanner_state (SCANNER_STATUS_HOST);
1401  }
1402  else
1403  {
1404  g_debug ("New scanner command to implement: %s\n",
1405  field);
1406  goto return_error;
1407  }
1408  break;
1409  case SCANNER_STATUS_HOST:
1410  {
1411  assert (current_host == NULL);
1412  current_host = g_strdup (field);
1413  set_scanner_state (SCANNER_STATUS_PROGRESS);
1414  break;
1415  }
1417  {
1418  /* Store the progress in the ports slots in the db. */
1419  assert (current_report);
1420  if (current_report && current_host)
1421  {
1422  unsigned int current, max;
1423  g_debug (" scanner got ports: %s\n", field);
1424  if (sscanf (field, "%u/%u", &current, &max) == 2)
1426  current_host,
1427  current,
1428  max);
1429  }
1430  if (current_host)
1431  {
1432  g_free (current_host);
1433  current_host = NULL;
1434  }
1435  set_scanner_state (SCANNER_DONE);
1436  switch (parse_scanner_done (&messages))
1437  {
1438  case -1: goto return_error;
1439  case -2:
1440  /* Need more input. */
1441  if (sync_buffer ()) goto return_error;
1442  goto return_need_more;
1443  }
1444  break;
1445  }
1446  case SCANNER_TIME:
1447  {
1448  if (strcasecmp ("HOST_START", field) == 0)
1449  set_scanner_state (SCANNER_TIME_HOST_START_HOST);
1450  else if (strcasecmp ("HOST_END", field) == 0)
1451  set_scanner_state (SCANNER_TIME_HOST_END_HOST);
1452  else if (strcasecmp ("SCAN_START", field) == 0)
1453  set_scanner_state (SCANNER_TIME_SCAN_START);
1454  else if (strcasecmp ("SCAN_END", field) == 0)
1455  set_scanner_state (SCANNER_TIME_SCAN_END);
1456  else
1458  abort ();
1459  break;
1460  }
1462  {
1463  assert (current_host == NULL);
1464  current_host = g_strdup (field);
1465  set_scanner_state (SCANNER_TIME_HOST_START_TIME);
1466  break;
1467  }
1469  {
1471  {
1472  assert (current_host);
1473  assert (current_report);
1474 
1476  current_host,
1477  field);
1478  g_free (current_host);
1479  current_host = NULL;
1480  }
1481  set_scanner_state (SCANNER_DONE);
1482  switch (parse_scanner_done (&messages))
1483  {
1484  case -1: goto return_error;
1485  case -2:
1486  /* Need more input. */
1487  if (sync_buffer ()) goto return_error;
1488  goto return_need_more;
1489  }
1490  break;
1491  }
1493  {
1494  assert (current_host == NULL);
1495  current_host = g_strdup (field);
1496  set_scanner_state (SCANNER_TIME_HOST_END_TIME);
1497  break;
1498  }
1500  {
1501  assert (current_host);
1502  assert (current_report);
1503 
1504  if (report_host_noticeable (current_report, current_host))
1505  {
1506  char *uuid;
1507  uuid = report_uuid (current_report);
1508  host_notice (current_host, "ip", current_host,
1509  "Report Host", uuid, 1, 0);
1510  free (uuid);
1511  }
1512 
1514  {
1515  assert (current_host);
1517  current_host,
1518  field);
1519  g_free (current_host);
1520  current_host = NULL;
1521  }
1522  set_scanner_state (SCANNER_DONE);
1523  switch (parse_scanner_done (&messages))
1524  {
1525  case -1: goto return_error;
1526  case -2:
1527  /* Need more input. */
1528  if (sync_buffer ()) goto return_error;
1529  goto return_need_more;
1530  }
1531  break;
1532  }
1534  {
1536  {
1539  {
1542  /* If the scan has been started before, then leave
1543  * the start time alone. */
1545  {
1547  g_strdup (field));
1549  }
1550  }
1551  }
1552  set_scanner_state (SCANNER_DONE);
1553  switch (parse_scanner_done (&messages))
1554  {
1555  case -1: goto return_error;
1556  case -2:
1557  /* Need more input. */
1558  if (sync_buffer ()) goto return_error;
1559  goto return_need_more;
1560  }
1561  break;
1562  }
1563  case SCANNER_TIME_SCAN_END:
1564  {
1566  {
1567  /* Stop transaction now, because delete_task_lock and
1568  * set_scan_end_time_otp run transactions themselves. */
1569  manage_transaction_stop (TRUE);
1571  if (current_report)
1572  {
1573  hosts_set_max_severity (current_report, NULL, NULL);
1576  }
1578  {
1580  break;
1585  break;
1591  current_report = (report_t) 0;
1592  break;
1598  current_report = (report_t) 0;
1599  break;
1600  default:
1602  g_strdup (field));
1605  }
1608  current_report = (report_t) 0;
1610  }
1611  set_scanner_state (SCANNER_DONE);
1612  switch (parse_scanner_done (&messages))
1613  {
1614  case -1: goto return_error;
1615  case -2:
1616  /* Need more input. */
1617  if (sync_buffer ()) goto return_error;
1618  goto return_need_more;
1619  }
1620  break;
1621  }
1622  case SCANNER_TOP:
1623  default:
1624  g_debug (" switch t\n");
1625  g_debug (" cmp %i\n", strcasecmp ("SERVER", field));
1626  if (strcasecmp ("SERVER", field))
1627  goto return_error;
1628  set_scanner_state (SCANNER_SERVER);
1629  /* Look for any newline delimited scanner commands. */
1630  switch (parse_scanner_server (&messages))
1631  {
1632  case 0: break; /* Found newline delimited command. */
1633  case -1: goto return_error; /* Error. */
1634  case -2:
1635  /* Need more input. */
1636  if (sync_buffer ()) goto return_error;
1637  goto return_need_more;
1638  case -3: break; /* Next <|> is before next \n. */
1639  case -4: break; /* Failed to find \n, try for <|>. */
1640  }
1641  break;
1642  }
1643 
1644  g_debug (" scanner new state: %i\n", scanner_state);
1645 
1646  continue;
1647 
1648  return_error:
1649  return -1;
1650 
1651  return_need_more:
1652  return 0;
1653 
1654  return_bye:
1655  return 1;
1656  }
1657  else
1658  {
1659  from_start += match + 1 - input;
1660  input = match + 1;
1661  }
1662  }
1663 
1664  if (sync_buffer ()) return -1;
1665  return 0;
1666 }
int report_host_noticeable(report_t, const gchar *)
void set_scan_host_start_time_otp(report_t, const char *, const char *)
int scanner_total_loading
Scanner total number of plugins to be loaded, when still loading.
Definition: otp.c:426
void manage_complete_nvt_cache_update(GList *, GList *, int)
scanner_init_state_t scanner_init_state
The initialisation state of the scanner.
Definition: otp.c:411
GList * scanner_plugins_list
The full plugins list, during reading of scanner plugin list.
Definition: otp.c:326
void set_task_run_status(task_t, task_status_t)
Set the run state of a task.
Definition: manage_sql.c:18307
int scan_start_time_epoch(report_t)
host_t host_notice(const char *, const char *, const char *, const char *, const char *, int, int)
task_t current_scanner_task
The task currently running on the scanner.
Definition: manage.c:998
void hosts_set_max_severity(report_t, int *, int *)
task_status_t task_run_status(task_t)
Return the run state of a task.
Definition: manage_sql.c:18238
void set_scan_start_time_otp(report_t, const char *)
buffer_size_t from_scanner_start
The start of the data in the from_scanner buffer.
Definition: scanner.c:67
void set_scan_host_end_time_otp(report_t, const char *, const char *)
void(* progress)()
Function to mark progress.
Definition: manage_sql.c:352
void clear_duration_schedules(task_t)
void hosts_set_identifiers()
long long int report_t
Definition: manage.h:288
void set_scan_ports(report_t, const char *, unsigned int, unsigned int)
void hosts_set_details(report_t report)
#define G_LOG_DOMAIN
GLib log domain.
Definition: otp.c:65
void set_task_start_time_otp(task_t, char *)
Set the start time of a task.
Definition: manage_sql.c:18524
buffer_size_t from_scanner_end
The end of the data in the from_scanner buffer.
Definition: scanner.c:72
void set_scanner_init_state(scanner_init_state_t state)
Set the scanner initialisation state, scanner_init_state.
Definition: otp.c:432
void update_duration_schedule_periods(task_t)
report_t current_report
The report of the current task.
Definition: manage.c:1003
int manage_check_current_task()
Handle state changes to current task made by other processes.
Definition: manage.c:5733
void set_scan_end_time_otp(report_t, const char *)
void set_task_end_time(task_t task, char *time)
char * report_uuid(report_t)
void manage_transaction_stop(gboolean)
int acknowledge_bye()
Acknowledge a scanner BYE.
Definition: manage.c:5705
void set_nvts_feed_version(const char *)
char * port_name_formatted(const char *)
Returns formatted port number, protocol and iana name from.
Definition: manage_sql.c:6378
void manage_nvt_preferences_enable()
GList * scanner_preferences_list
The full preferences list, during reading of scanner plugin list.
Definition: otp.c:331
int acknowledge_feed_version_info()
Acknowledge scanner PLUGINS_FEED_VERSION message,.
Definition: manage.c:5719
unsigned int buffer_size_t
Definition: types.h:31
char * from_scanner
Buffer of input from the scanner.
Definition: scanner.c:62
long long int task_t
Definition: manage.h:286
int scanner_current_loading
Scanner current number of loaded plugins, when still loading.
Definition: otp.c:421
int delete_task_lock(task_t, int)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset_scanner_states()

void reset_scanner_states ( )

Set the scanner initialisation state, scanner_init_state.

Todo:
Exported for scanner.c.

Definition at line 442 of file otp.c.

Referenced by openvas_scanner_fork().

443 {
444  set_scanner_state (SCANNER_TOP);
449 }
int scanner_total_loading
Scanner total number of plugins to be loaded, when still loading.
Definition: otp.c:426
void set_scanner_init_state(scanner_init_state_t state)
Set the scanner initialisation state, scanner_init_state.
Definition: otp.c:432
int scanner_init_offset
Offset into initialisation string being sent to scanner.
Definition: otp.c:416
int scanner_current_loading
Scanner current number of loaded plugins, when still loading.
Definition: otp.c:421
Here is the caller graph for this function:

◆ set_scanner_init_state()

void set_scanner_init_state ( scanner_init_state_t  state)

Set the scanner initialisation state, scanner_init_state.

Todo:
Exported for ompd.c and scanner.c.

Definition at line 432 of file otp.c.

References scanner_init_state.

Referenced by openvas_scanner_write().

433 {
434  scanner_init_state = state;
435  g_debug (" scanner init state set: %i\n", scanner_init_state);
436 }
scanner_init_state_t scanner_init_state
The initialisation state of the scanner.
Definition: otp.c:411
Here is the caller graph for this function:

Variable Documentation

◆ scanner_current_loading

int scanner_current_loading

Scanner current number of loaded plugins, when still loading.

Definition at line 421 of file otp.c.

◆ scanner_init_offset

int scanner_init_offset

Offset into initialisation string being sent to scanner.

Todo:
Exported for ompd.c.

Definition at line 416 of file otp.c.

Referenced by openvas_scanner_write().

◆ scanner_init_state

scanner_init_state_t scanner_init_state

The initialisation state of the scanner.

Todo:
Exported for ompd.c.

Definition at line 411 of file otp.c.

Referenced by openvas_scanner_write(), process_otp_scanner_input(), and set_scanner_init_state().

◆ scanner_total_loading

int scanner_total_loading

Scanner total number of plugins to be loaded, when still loading.

Definition at line 426 of file otp.c.