OpenVAS Libraries  6.0+beta5
Macros | Functions
plugutils.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <sys/wait.h>
#include <time.h>
#include <glib.h>
#include "arglists.h"
#include "comm.h"
#include "kb.h"
#include "network.h"
#include "rand.h"
#include "plugutils.h"
#include "internal_com.h"
#include "services.h"
#include "share_fd.h"
#include "system.h"
#include "scanners_utils.h"
#include "../base/nvticache.h"

Macros

#define MAX_CANDIDATES   16
 

Functions

char * openvaslib_version ()
 Returns a static version string. More...
 
void openvas_lib_version (int *major, int *minor, int *rev)
 Sets major minor and to the respective values of the openvas-libraries version. More...
 
char * addslashes (char *in)
 Escapes \n and \r and \ in <in> properly. The. More...
 
char * rmslashes (char *in)
 Replaces escape codes (\n, \r) by the real value. More...
 
void plug_set_xref (struct arglist *desc, char *name, char *value)
 
void plug_set_tag (struct arglist *desc, char *name, char *value)
 
void plug_set_dep (struct arglist *desc, const char *depname)
 
void plug_set_launch (struct arglist *desc, int launch)
 
int plug_get_launch (struct arglist *desc)
 
void plug_add_host (struct arglist *desc, struct arglist *hostname)
 
void _add_plugin_preference (struct arglist *prefs, const char *p_name, const char *name, const char *type, const char *defaul)
 
struct arglistplug_create_from_nvti_and_prefs (nvti_t *nvti, struct arglist *prefs)
 Returns a (plugin) arglist assembled from the nvti. More...
 
void host_add_port_proto (struct arglist *args, int portnum, int state, char *proto)
 
void host_add_port (struct arglist *hostdata, int portnum, int state)
 
void host_add_port_udp (struct arglist *hostdata, int portnum, int state)
 
int port_in_ports (u_short port, u_short *ports, int s, int e)
 
int kb_get_port_state_proto (struct kb_item **kb, struct arglist *prefs, int portnum, char *proto)
 
int host_get_port_state_proto (struct arglist *plugdata, int portnum, char *proto)
 
int host_get_port_state (struct arglist *plugdata, int portnum)
 
int host_get_port_state_udp (struct arglist *plugdata, int portnum)
 
const char * plug_get_hostname (struct arglist *desc)
 
const char * plug_get_host_fqdn (struct arglist *desc)
 
struct in6_addr * plug_get_host_ip (struct arglist *desc)
 
void proto_post_wrapped (struct arglist *desc, int port, const char *proto, const char *action, const char *what)
 Post a security message (e.g. LOG, NOTE, WARNING ...). More...
 
void proto_post_hole (struct arglist *desc, int port, const char *proto, const char *action)
 
void post_hole (struct arglist *desc, int port, const char *action)
 
void post_hole_udp (struct arglist *desc, int port, const char *action)
 
void post_info (struct arglist *desc, int port, const char *action)
 
void post_info_udp (struct arglist *desc, int port, const char *action)
 
void proto_post_info (struct arglist *desc, int port, const char *proto, const char *action)
 
void post_note (struct arglist *desc, int port, const char *action)
 
void post_note_udp (struct arglist *desc, int port, const char *action)
 
void proto_post_note (struct arglist *desc, int port, const char *proto, const char *action)
 
void proto_post_log (struct arglist *desc, int port, const char *proto, const char *action)
 Post a log message. More...
 
void post_log (struct arglist *desc, int port, const char *action)
 Post a log message about a tcp port. More...
 
void post_log_udp (struct arglist *desc, int port, const char *action)
 Post a log message about a udp port. More...
 
void proto_post_error (struct arglist *desc, int port, const char *proto, const char *action)
 
void post_error (struct arglist *desc, int port, const char *action)
 
void post_error_udp (struct arglist *desc, int port, const char *action)
 Post a debug message about a udp port. More...
 
char * get_preference (struct arglist *desc, const char *name)
 
void add_plugin_preference (struct arglist *desc, const char *name, const char *type, const char *defaul)
 
char * get_plugin_preference (struct arglist *desc, const char *name)
 
const char * get_plugin_preference_fname (struct arglist *desc, const char *filename)
 Get the file name of a plugins preference that is of type "file". More...
 
char * get_plugin_preference_file_content (struct arglist *desc, const char *identifier)
 Get the file contents of a plugins preference that is of type "file". More...
 
const long get_plugin_preference_file_size (struct arglist *desc, const char *identifier)
 Get the file size of a plugins preference that is of type "file". More...
 
void * plug_get_fresh_key (struct arglist *args, char *name, int *type)
 
void plug_set_key (struct arglist *args, char *name, int type, void *value)
 
void plug_replace_key (struct arglist *args, char *name, int type, void *value)
 
void scanner_add_port (struct arglist *args, int port, char *proto)
 
struct kb_item ** plug_get_kb (struct arglist *args)
 
void * plug_get_key (struct arglist *args, char *name, int *type)
 
unsigned int plug_get_host_open_port (struct arglist *desc)
 
void plug_set_port_transport (struct arglist *args, int port, int tr)
 
int plug_get_port_transport (struct arglist *args, int port)
 
const char * plug_get_port_transport_name (struct arglist *args, int port)
 
void plug_set_ssl_cert (struct arglist *args, char *cert)
 
void plug_set_ssl_key (struct arglist *args, char *key)
 
void plug_set_ssl_pem_password (struct arglist *args, char *key)
 
void plug_set_ssl_CA_file (struct arglist *args, char *key)
 
char * find_in_path (char *name, int safe)
 

Macro Definition Documentation

#define MAX_CANDIDATES   16

Function Documentation

void _add_plugin_preference ( struct arglist prefs,
const char *  p_name,
const char *  name,
const char *  type,
const char *  defaul 
)
void add_plugin_preference ( struct arglist desc,
const char *  name,
const char *  type,
const char *  defaul 
)
char* addslashes ( char *  in)

Escapes \n and \r and \ in <in> properly. The.

resulting string is copied and returned.

Parameters
inString in which to escape \n, \r and
Returns
Copy of in with \n, \r and \ escaped, NULL if in is NULL.
See Also
To undo, call rmslashes.
char* find_in_path ( char *  name,
int  safe 
)
char* get_plugin_preference ( struct arglist desc,
const char *  name 
)
char* get_plugin_preference_file_content ( struct arglist desc,
const char *  identifier 
)

Get the file contents of a plugins preference that is of type "file".

As files sent to the scanner (e.g. as plugin preference) are stored in a hash table with an identifier supplied by the client as the key, the contents have to be looked up here.

Parameters
identifierIdentifier that was supplied by the client when the file was uploaded.
Returns
Contents of the file identified by identifier, NULL if not found or setup broken.
const long get_plugin_preference_file_size ( struct arglist desc,
const char *  identifier 
)

Get the file size of a plugins preference that is of type "file".

Files sent to the scanner (e.g. as plugin preference) are stored in a hash table with an identifier supplied by the client as the key. The size of the file is stored in a separate hash table with the same identifier as key, which can be looked up here.

Parameters
identifierIdentifier that was supplied by the client when the file was uploaded.
Returns
Size of the file identified by identifier, -1 if not found or setup broken.
const char* get_plugin_preference_fname ( struct arglist desc,
const char *  filename 
)

Get the file name of a plugins preference that is of type "file".

As files sent to the server (e.g. as plugin preference) are stored at pseudo-random locations with different names, the "real" file name has to be looked up in a hashtable.

Returns
Filename on disc for filename, NULL if not found or setup broken.
char* get_preference ( struct arglist desc,
const char *  name 
)
void host_add_port ( struct arglist hostdata,
int  portnum,
int  state 
)
void host_add_port_proto ( struct arglist args,
int  portnum,
int  state,
char *  proto 
)
void host_add_port_udp ( struct arglist hostdata,
int  portnum,
int  state 
)
int host_get_port_state ( struct arglist plugdata,
int  portnum 
)
int host_get_port_state_proto ( struct arglist plugdata,
int  portnum,
char *  proto 
)
int host_get_port_state_udp ( struct arglist plugdata,
int  portnum 
)
int kb_get_port_state_proto ( struct kb_item **  kb,
struct arglist prefs,
int  portnum,
char *  proto 
)
Parameters
protoProtocol (udp/tcp). If NULL, "tcp" will be used.
void openvas_lib_version ( int *  major,
int *  minor,
int *  rev 
)

Sets major minor and to the respective values of the openvas-libraries version.

char* openvaslib_version ( )

Returns a static version string.

Returns
Version of openvas-libraries, do not modify nor free.
void plug_add_host ( struct arglist desc,
struct arglist hostname 
)
struct arglist* plug_create_from_nvti_and_prefs ( nvti_t nvti,
struct arglist prefs 
)
read

Returns a (plugin) arglist assembled from the nvti.

Parameters
nvtiNVT Information to be used for the creation.
prefsPlugin preference arglist that is added to new arglist and where all preferences of the NVTI are copied to as single entries.
Returns
Pointer to plugin as arglist or NULL.
void* plug_get_fresh_key ( struct arglist args,
char *  name,
int *  type 
)
const char* plug_get_host_fqdn ( struct arglist desc)
struct in6_addr* plug_get_host_ip ( struct arglist desc)
read
unsigned int plug_get_host_open_port ( struct arglist desc)

Don't always return the first open port, otherwise we might get bitten by OSes doing active SYN flood countermeasures. Also, avoid returning 80 and 21 as open ports, as many transparent proxies are acting for these...

const char* plug_get_hostname ( struct arglist desc)
struct kb_item** plug_get_kb ( struct arglist args)
read
void* plug_get_key ( struct arglist args,
char *  name,
int *  type 
)
int plug_get_launch ( struct arglist desc)
int plug_get_port_transport ( struct arglist args,
int  port 
)
const char* plug_get_port_transport_name ( struct arglist args,
int  port 
)
void plug_replace_key ( struct arglist args,
char *  name,
int  type,
void *  value 
)
void plug_set_dep ( struct arglist desc,
const char *  depname 
)
void plug_set_key ( struct arglist args,
char *  name,
int  type,
void *  value 
)
void plug_set_launch ( struct arglist desc,
int  launch 
)
void plug_set_port_transport ( struct arglist args,
int  port,
int  tr 
)
Todo:
Those brain damaged functions should probably be in another file They are use to remember who speaks SSL or not
void plug_set_ssl_CA_file ( struct arglist args,
char *  key 
)
Todo:
Also, all plug_set_ssl*-functions set values that are only accessed in network.c:open_stream_connection under specific conditions. Check whether these conditions can actually occur. Document the functions on the way.
void plug_set_ssl_cert ( struct arglist args,
char *  cert 
)
void plug_set_ssl_key ( struct arglist args,
char *  key 
)
void plug_set_ssl_pem_password ( struct arglist args,
char *  key 
)
void plug_set_tag ( struct arglist desc,
char *  name,
char *  value 
)
void plug_set_xref ( struct arglist desc,
char *  name,
char *  value 
)
int port_in_ports ( u_short  port,
u_short *  ports,
int  s,
int  e 
)
void post_error ( struct arglist desc,
int  port,
const char *  action 
)
void post_error_udp ( struct arglist desc,
int  port,
const char *  action 
)

Post a debug message about a udp port.

void post_hole ( struct arglist desc,
int  port,
const char *  action 
)
void post_hole_udp ( struct arglist desc,
int  port,
const char *  action 
)
void post_info ( struct arglist desc,
int  port,
const char *  action 
)
void post_info_udp ( struct arglist desc,
int  port,
const char *  action 
)
void post_log ( struct arglist desc,
int  port,
const char *  action 
)

Post a log message about a tcp port.

void post_log_udp ( struct arglist desc,
int  port,
const char *  action 
)

Post a log message about a udp port.

void post_note ( struct arglist desc,
int  port,
const char *  action 
)
void post_note_udp ( struct arglist desc,
int  port,
const char *  action 
)
void proto_post_error ( struct arglist desc,
int  port,
const char *  proto,
const char *  action 
)
void proto_post_hole ( struct arglist desc,
int  port,
const char *  proto,
const char *  action 
)
void proto_post_info ( struct arglist desc,
int  port,
const char *  proto,
const char *  action 
)
void proto_post_log ( struct arglist desc,
int  port,
const char *  proto,
const char *  action 
)

Post a log message.

void proto_post_note ( struct arglist desc,
int  port,
const char *  proto,
const char *  action 
)
void proto_post_wrapped ( struct arglist desc,
int  port,
const char *  proto,
const char *  action,
const char *  what 
)

Post a security message (e.g. LOG, NOTE, WARNING ...).

Parameters
portPort number related to the issue.
protoProtocol related to the issue.
char* rmslashes ( char *  in)

Replaces escape codes (\n, \r) by the real value.

The resulting string is stored in another buffer.

See Also
(slashes could have been added with addslashes)
void scanner_add_port ( struct arglist args,
int  port,
char *  proto 
)