OpenVAS Scanner  22.7.9
hosts.h File Reference

hosts.c header. More...

#include "../misc/scanneraux.h"
#include <gvm/base/hosts.h>
Include dependency graph for hosts.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int hosts_init (int)
 
int hosts_new (char *, kb_t, kb_t)
 
int hosts_set_pid (char *, pid_t)
 
int hosts_read (void)
 Returns -1 if client asked to stop all tests or connection was lost or error. 0 otherwise. More...
 
void hosts_stop_all (void)
 
void host_set_time (kb_t, char *, char *)
 Add star_scan and end_scan results to the main kb. More...
 
int host_is_currently_scanned (gvm_host_t *)
 Returns 1 if the host is being scanned. 0 otherwise. More...
 

Detailed Description

hosts.c header.

Definition in file hosts.h.

Function Documentation

◆ host_is_currently_scanned()

int host_is_currently_scanned ( gvm_host_t *  host_to_check)

Returns 1 if the host is being scanned. 0 otherwise.

It checks not only the main IP of the host, but also the ips that a dns-lookup returns.

Definition at line 271 of file hosts.c.

272 {
273  struct host *h = hosts;
274 
275  GSList *list, *tmp;
276  char *vhost = NULL;
277 
278  hosts_read ();
279 
280  if (h == NULL)
281  return 0;
282 
283  vhost = gvm_host_reverse_lookup (host_to_check);
284  if (!vhost)
285  return 0;
286 
287  list = tmp = gvm_resolve_list (vhost);
288  g_free (vhost);
289  while (tmp)
290  {
291  h = hosts;
292  char buffer[INET6_ADDRSTRLEN];
293  addr6_to_str (tmp->data, buffer);
294 
295  while (h != NULL)
296  {
297  if (!strcasecmp (h->name, buffer))
298  {
299  g_slist_free_full (list, g_free);
300  return 1;
301  }
302  h = h->next;
303  }
304  tmp = tmp->next;
305  }
306 
307  g_slist_free_full (list, g_free);
308  return 0;
309 }

References hosts, hosts_read(), host::name, and host::next.

Referenced by attack_network().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ host_set_time()

void host_set_time ( kb_t  kb,
char *  ip,
char *  type 
)

Add star_scan and end_scan results to the main kb.

Parameters
[in]kbMain KB where results are stored.
[in]ipList of vhosts to add new vhosts to.
[in]typeIf it is start or end message.

Definition at line 64 of file hosts.c.

65 {
66  char *timestr;
67  char log_msg[1024];
68  time_t t;
69  int len;
70 
71  t = time (NULL);
72  char ts[26];
73  char *ts_ptr = ts;
74  ctime_r (&t, ts_ptr);
75  timestr = g_strdup (ts_ptr);
76  len = strlen (timestr);
77  if (timestr[len - 1] == '\n')
78  timestr[len - 1] = '\0';
79 
80  snprintf (log_msg, sizeof (log_msg), "%s|||%s||||||||| |||%s", type, ip,
81  timestr);
82  g_free (timestr);
83 
84  kb_item_push_str_with_main_kb_check (kb, "internal/results", log_msg);
85 }

References host::ip, kb_item_push_str_with_main_kb_check(), and len.

Referenced by attack_host().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hosts_init()

int hosts_init ( int  )

Definition at line 144 of file hosts.c.

145 {
146  g_max_hosts = max_hosts;
147  return 0;
148 }

References g_max_hosts.

Referenced by attack_network().

Here is the caller graph for this function:

◆ hosts_new()

int hosts_new ( char *  ,
kb_t  ,
kb_t   
)

Definition at line 151 of file hosts.c.

152 {
153  struct host *h;
154 
155  while (hosts_num () >= g_max_hosts)
156  {
157  if (hosts_read () < 0)
158  return -1;
159  }
160  if (global_scan_stop)
161  return 0;
162 
163  h = g_malloc0 (sizeof (struct host));
164  h->name = g_strdup (name);
165  h->pid = 0;
166  h->host_kb = kb;
167  h->results_kb = main_kb;
168  if (hosts != NULL)
169  hosts->prev = h;
170  h->next = hosts;
171  h->prev = NULL;
172  hosts = h;
173  return 0;
174 }

References g_max_hosts, global_scan_stop, host::host_kb, hosts, hosts_num(), hosts_read(), main_kb, name, host::name, host::next, host::pid, host::prev, and host::results_kb.

Referenced by attack_network().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hosts_read()

int hosts_read ( void  )

Returns -1 if client asked to stop all tests or connection was lost or error. 0 otherwise.

Definition at line 253 of file hosts.c.

254 {
255  if (hosts == NULL)
256  return -1;
257 
258  hosts_read_data ();
259  usleep (500000);
260 
261  return 0;
262 }

References hosts, and hosts_read_data().

Referenced by attack_network(), host_is_currently_scanned(), and hosts_new().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hosts_set_pid()

int hosts_set_pid ( char *  ,
pid_t   
)

Definition at line 177 of file hosts.c.

178 {
179  struct host *h = hosts_get (name);
180  if (h == NULL)
181  {
182  g_debug ("host_set_pid() failed!\n");
183  return -1;
184  }
185 
186  h->pid = pid;
187  return 0;
188 }

References hosts_get(), name, pid, and host::pid.

Referenced by attack_network().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hosts_stop_all()

void hosts_stop_all ( void  )

Definition at line 203 of file hosts.c.

204 {
205  struct host *host = hosts;
206 
207  global_scan_stop = 1;
208  while (host)
209  {
211  host = host->next;
212  }
213 }

References global_scan_stop, hosts, hosts_stop_host(), and host::next.

Referenced by scan_stop_cleanup().

Here is the call graph for this function:
Here is the caller graph for this function:
hosts_read
int hosts_read(void)
Returns -1 if client asked to stop all tests or connection was lost or error. 0 otherwise.
Definition: hosts.c:253
host::pid
pid_t pid
Definition: hosts.c:40
host::ip
char * ip
Definition: hosts.c:39
main_kb
kb_t main_kb
Definition: kb_cache.c:15
hosts_get
static struct host * hosts_get(char *name)
Retrieves a host specified by its name from the global host list.
Definition: hosts.c:131
hosts_read_data
static void hosts_read_data(void)
Definition: hosts.c:218
name
const char * name
Definition: nasl_init.c:411
g_max_hosts
static int g_max_hosts
Definition: hosts.c:50
global_scan_stop
int global_scan_stop
Definition: attack.c:260
host::prev
struct host * prev
Definition: hosts.c:44
pid
static pid_t pid
Definition: nasl_cmd_exec.c:39
len
uint8_t len
Definition: nasl_packet_forgery.c:1
hosts_stop_host
static int hosts_stop_host(struct host *h)
Definition: hosts.c:192
host::name
char * name
Definition: hosts.c:38
host
Host information, implemented as doubly linked list.
Definition: hosts.c:37
hosts_num
static int hosts_num(void)
Returns the number of entries in the global hosts list.
Definition: hosts.c:116
host::results_kb
kb_t results_kb
Definition: hosts.c:42
host::host_kb
kb_t host_kb
Definition: hosts.c:41
hosts
static struct host * hosts
Definition: hosts.c:49
kb_item_push_str_with_main_kb_check
int kb_item_push_str_with_main_kb_check(kb_t kb, const char *name, const char *value)
Check if the current kb corresponds to the original scanid, if it matches it kb_item_push_str....
Definition: plugutils.c:478
list
Definition: nasl_builtin_synscan.c:249
host::next
struct host * next
Definition: hosts.c:43