OpenVAS Scanner  5.1.3
utils.c File Reference
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <openvas/misc/network.h>
#include <openvas/misc/prefs.h>
#include "log.h"
#include "comm.h"
#include "ntp.h"
#include "utils.h"
#include "pluginscheduler.h"
Include dependency graph for utils.c:

Go to the source code of this file.

Functions

int common (struct arglist *l1, struct arglist *l2)
 Returns 1 if the two arglists have a name in common. More...
 
struct arglist * list2arglist (char *list)
 
int get_max_hosts_number (void)
 
int get_max_checks_number (void)
 
int process_alive (pid_t pid)
 
int data_left (int soc)
 
void wait_for_children1 (void)
 
int is_scanner_only_pref (const char *pref)
 
void send_printf (int soc, char *data,...)
 Writes data to a socket. More...
 

Variables

int global_max_hosts
 
int global_max_checks
 

Function Documentation

◆ common()

int common ( struct arglist *  l1,
struct arglist *  l2 
)

Returns 1 if the two arglists have a name in common.

Returns
0 if l1 and l2 have a name in common, 0 otherwise.

Definition at line 54 of file utils.c.

56 {
57  struct arglist *l2_start = l2;
58  if (!l1 || !l2)
59  {
60  return 0;
61  }
62  while (l1->next != NULL)
63  {
64  l2 = l2_start;
65  while (l2->next != NULL)
66  {
67  if (strcmp (l1->name, l2->name) == 0)
68  return 1;
69  l2 = l2->next;
70  }
71  l1 = l1->next;
72  }
73  return 0;
74 }

◆ data_left()

int data_left ( int  soc)

Definition at line 193 of file utils.c.

195 {
196  int data = 0;
197  ioctl (soc, FIONREAD, &data);
198  return data;
199 }

◆ get_max_checks_number()

int get_max_checks_number ( void  )

Get the max number of plugins to launch against the remote host at the same time

Definition at line 150 of file utils.c.

151 {
152  int max_checks;
153  if (prefs_get ("max_checks"))
154  {
155  max_checks = atoi (prefs_get ("max_checks"));
156  if (max_checks <= 0)
157  {
158  log_write ("Error ! max_hosts = %d -- check %s", max_checks,
159  (char *) prefs_get ("config_file"));
160  max_checks = global_max_checks;
161  }
162  else if (max_checks > global_max_checks)
163  {
164  log_write ("Client tried to raise the maximum checks number - %d."
165  " Using %d. Change 'max_checks' in openvassd.conf if you"
166  " believe this is incorrect", max_checks, global_max_checks);
167  max_checks = global_max_checks;
168  }
169  }
170  else
171  max_checks = global_max_checks;
172  return (max_checks);
173 }
void log_write(const char *str,...)
Write into the logfile / syslog.
Definition: log.c:140
int global_max_checks
Definition: openvassd.c:87

References global_max_checks, and log_write().

Here is the call graph for this function:

◆ get_max_hosts_number()

int get_max_hosts_number ( void  )

Get the max number of hosts to test at the same time.

Definition at line 120 of file utils.c.

121 {
122  int max_hosts;
123  if (prefs_get ("max_hosts"))
124  {
125  max_hosts = atoi (prefs_get ("max_hosts"));
126  if (max_hosts <= 0)
127  {
128  log_write ("Error ! max_hosts = %d -- check %s", max_hosts,
129  (char *) prefs_get ("config_file"));
130  max_hosts = global_max_hosts;
131  }
132  else if (max_hosts > global_max_hosts)
133  {
134  log_write ("Client tried to raise the maximum hosts number - %d."
135  " Using %d. Change 'max_hosts' in openvassd.conf if you"
136  " believe this is incorrect", max_hosts, global_max_hosts);
137  max_hosts = global_max_hosts;
138  }
139  }
140  else
141  max_hosts = global_max_hosts;
142  return (max_hosts);
143 }
void log_write(const char *str,...)
Write into the logfile / syslog.
Definition: log.c:140
int global_max_hosts
Definition: openvassd.c:86

References global_max_hosts, and log_write().

Here is the call graph for this function:

◆ is_scanner_only_pref()

int is_scanner_only_pref ( const char *  pref)

Definition at line 221 of file utils.c.

222 {
223  if (pref == NULL)
224  return 0;
225  if (!strcmp (pref, "logfile") || !strcmp (pref, "config_file")
226  || !strcmp (pref, "plugins_folder")
227  || !strcmp (pref, "kb_location")
228  || !strcmp (pref, "dumpfile")
229  || !strcmp (pref, "negot_timeout")
230  || !strcmp (pref, "force_pubkey_auth")
231  || !strcmp (pref, "log_whole_attack")
232  || !strcmp (pref, "be_nice")
233  || !strcmp (pref, "log_plugins_name_at_load")
234  || !strcmp (pref, "nasl_no_signature_check")
235  /* Preferences starting with sys_ are scanner-side only. */
236  || !strncmp (pref, "sys_", 4))
237  return 1;
238  return 0;
239 }

Referenced by comm_send_preferences().

Here is the caller graph for this function:

◆ list2arglist()

struct arglist* list2arglist ( char *  list)

Converts a user comma delimited input (1,2,3) into an arglist.

Definition at line 81 of file utils.c.

83 {
84  struct arglist *ret;
85  char *t;
86 
87  if (!list)
88  return NULL;
89 
90  ret = g_malloc0 (sizeof (struct arglist));
91 
92  while ((t = strchr (list, ',')) != NULL)
93  {
94  t[0] = 0;
95  while (list[0] == ' ')
96  list++;
97  if (list[0] != '\0')
98  {
99  arg_add_value (ret, list, ARG_INT, (void *) 1);
100  }
101  list = t + 1;
102  }
103 
104  while (list[0] == ' ')
105  list++;
106  if (list[0] != '\0')
107  {
108  arg_add_value (ret, list, ARG_INT, (void *) 1);
109  }
110  return ret;
111 }

◆ process_alive()

int process_alive ( pid_t  pid)

Determines if a process is alive - as reliably as we can

Definition at line 180 of file utils.c.

181 {
182  int i, ret;
183  if (pid == 0)
184  return 0;
185 
186  for (i = 0, ret = 1; (i < 10) && (ret > 0); i++)
187  ret = waitpid (pid, NULL, WNOHANG);
188 
189  return kill (pid, 0) == 0;
190 }

◆ send_printf()

void send_printf ( int  soc,
char *  data,
  ... 
)

Writes data to a socket.

Definition at line 276 of file utils.c.

277 {
278  va_list param;
279  char *buffer;
280 
281  va_start (param, data);
282  buffer = g_strdup_vprintf (data, param);
283  va_end (param);
284 
285  auth_send (soc, buffer);
286  g_free (buffer);
287 }

Referenced by comm_send_pluginlist(), comm_send_preferences(), comm_terminate(), send_plug_info(), and send_plugins_preferences().

Here is the caller graph for this function:

◆ wait_for_children1()

void wait_for_children1 ( void  )

Definition at line 202 of file utils.c.

203 {
204  int e, n = 0;
205  do
206  {
207  errno = 0;
208  e = waitpid (-1, NULL, WNOHANG);
209  n++;
210  }
211  while ((e > 0 || errno == EINTR) && n < 20);
212 }

Variable Documentation

◆ global_max_checks

int global_max_checks

Definition at line 87 of file openvassd.c.

Referenced by get_max_checks_number().

◆ global_max_hosts

int global_max_hosts

Globals that should not be touched (used in utils module).

Definition at line 86 of file openvassd.c.

Referenced by get_max_hosts_number().