OpenVAS Scanner  7.0.0~git
utils.h File Reference

utils.c headerfile. More...

#include <sys/types.h>
Include dependency graph for utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int get_max_hosts_number (void)
 
int get_max_checks_number (void)
 
int process_alive (pid_t)
 
int data_left (int)
 
void wait_for_children1 (void)
 
int is_scanner_only_pref (const char *)
 
int store_file (struct scan_globals *, const char *, const char *)
 Stores a file type preference in a hash table. More...
 

Detailed Description

utils.c headerfile.

Definition in file utils.h.

Function Documentation

◆ data_left()

int data_left ( int  )

Definition at line 216 of file utils.c.

217 {
218  int data = 0;
219  ioctl (soc, FIONREAD, &data);
220  return data;
221 }

◆ 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 174 of file utils.c.

175 {
176  int max_checks;
177  if (prefs_get ("max_checks"))
178  {
179  max_checks = atoi (prefs_get ("max_checks"));
180  if (max_checks <= 0)
181  {
182  g_debug ("Error ! max_hosts = %d -- check %s", max_checks,
183  (char *) prefs_get ("config_file"));
184  max_checks = global_max_checks;
185  }
186  else if (max_checks > global_max_checks)
187  {
188  g_debug ("Client tried to raise the maximum checks number - %d."
189  " Using %d. Change 'max_checks' in openvas.conf if you"
190  " believe this is incorrect",
191  max_checks, global_max_checks);
192  max_checks = global_max_checks;
193  }
194  }
195  else
196  max_checks = global_max_checks;
197  return (max_checks);
198 }

References global_max_checks.

Referenced by attack_network(), and pluginlaunch_init().

Here is the caller 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 143 of file utils.c.

144 {
145  int max_hosts;
146  if (prefs_get ("max_hosts"))
147  {
148  max_hosts = atoi (prefs_get ("max_hosts"));
149  if (max_hosts <= 0)
150  {
151  g_debug ("Error ! max_hosts = %d -- check %s", max_hosts,
152  (char *) prefs_get ("config_file"));
153  max_hosts = global_max_hosts;
154  }
155  else if (max_hosts > global_max_hosts)
156  {
157  g_debug ("Client tried to raise the maximum hosts number - %d."
158  " Using %d. Change 'max_hosts' in openvas.conf if you"
159  " believe this is incorrect",
160  max_hosts, global_max_hosts);
161  max_hosts = global_max_hosts;
162  }
163  }
164  else
165  max_hosts = global_max_hosts;
166  return (max_hosts);
167 }

References global_max_hosts.

Referenced by attack_network().

Here is the caller graph for this function:

◆ is_scanner_only_pref()

int is_scanner_only_pref ( const char *  )

Definition at line 243 of file utils.c.

244 {
245  if (pref == NULL)
246  return 0;
247  if (!strcmp (pref, "logfile") || !strcmp (pref, "config_file")
248  || !strcmp (pref, "plugins_folder")
249  || !strcmp (
250  pref,
251  "kb_location") // old name of db_address, ignore from old conf's
252  || !strcmp (pref, "db_address") || !strcmp (pref, "negot_timeout")
253  || !strcmp (pref, "force_pubkey_auth")
254  || !strcmp (pref, "log_whole_attack")
255  || !strcmp (pref, "log_plugins_name_at_load")
256  || !strcmp (pref, "nasl_no_signature_check")
257  || !strcmp (pref, "vendor_version")
258  /* Preferences starting with sys_ are scanner-side only. */
259  || !strncmp (pref, "sys_", 4))
260  return 1;
261  return 0;
262 }

◆ process_alive()

int process_alive ( pid_t  pid)

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

Definition at line 204 of file utils.c.

205 {
206  int i, ret;
207  if (pid == 0)
208  return 0;
209 
210  for (i = 0, ret = 1; (i < 10) && (ret > 0); i++)
211  ret = waitpid (pid, NULL, WNOHANG);
212 
213  return kill (pid, 0) == 0;
214 }

References pid.

Referenced by attack_host(), next_free_process(), and update_running_processes().

Here is the caller graph for this function:

◆ store_file()

int store_file ( struct scan_globals globals,
const char *  file,
const char *  file_hash 
)

Stores a file type preference in a hash table.

Parameters
globalsGlobal struct.
fileFile content.
file_hashhash to reference the file.
Returns
0 if successful, -1 in case of errors.

Definition at line 110 of file utils.c.

112 {
113  char *origname;
114  gchar *contents = NULL;
115 
116  size_t bytes = 0;
117 
118  if (!file_hash && *file_hash == '\0')
119  return -1;
120 
121  origname = g_strdup (file_hash);
122 
123  contents = (gchar *) g_base64_decode (file, &bytes);
124 
125  if (contents == NULL)
126  {
127  g_debug ("store_file: Failed to allocate memory for uploaded file.");
128  g_free (origname);
129  return -1;
130  }
131 
132  files_add_translation (globals, origname, contents);
133  files_add_size_translation (globals, origname, bytes);
134 
135  g_free (origname);
136  return 0;
137 }

References files_add_size_translation(), and files_add_translation().

Referenced by load_scan_preferences().

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

◆ wait_for_children1()

void wait_for_children1 ( void  )

Definition at line 224 of file utils.c.

225 {
226  int e, n = 0;
227  do
228  {
229  errno = 0;
230  e = waitpid (-1, NULL, WNOHANG);
231  n++;
232  }
233  while ((e > 0 || errno == EINTR) && n < 20);
234 }
pid
static pid_t pid
Definition: nasl_builtin_nmap.c:499
files_add_translation
static void files_add_translation(struct scan_globals *globals, const char *file_hash, char *contents)
Adds a 'translation' entry for a file sent by the client.
Definition: utils.c:57
global_max_hosts
int global_max_hosts
Definition: openvas.c:88
files_add_size_translation
static void files_add_size_translation(struct scan_globals *globals, const char *file_hash, const long filesize)
Adds a 'content size' entry for a file sent by the client.
Definition: utils.c:84
global_max_checks
int global_max_checks
Definition: openvas.c:89