OpenVAS Libraries  9.0.3
plugutils.h File Reference
#include "arglists.h"
#include "../base/nvti.h"
#include "../base/openvas_networking.h"
#include "../base/kb.h"
Include dependency graph for plugutils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LEGACY_OID   "1.3.6.1.4.1.25623.1.0."
 
#define post_alarm_tcp   post_alarm
 
#define post_error_tcp   post_error
 
#define post_log_tcp   post_log
 

Functions

void scanner_add_port (struct arglist *, int, char *)
 
void plug_set_dep (struct arglist *, const char *)
 
void plug_set_xref (struct arglist *, char *, char *)
 
void plug_set_tag (struct arglist *, char *, char *)
 
void plug_set_ssl_cert (struct arglist *, char *)
 
void plug_set_ssl_key (struct arglist *, char *)
 
void plug_set_ssl_pem_password (struct arglist *, char *)
 
void plug_set_ssl_CA_file (struct arglist *, char *)
 
const char * plug_get_hostname (struct arglist *)
 
char * plug_get_host_fqdn (struct arglist *)
 
unsigned int plug_get_host_open_port (struct arglist *desc)
 
void plug_set_port_transport (struct arglist *, int, int)
 
int plug_get_port_transport (struct arglist *, int)
 
struct arglistplug_create_from_nvti_and_prefs (const nvti_t *)
 
void proto_post_alarm (const char *, struct arglist *, int, const char *, const char *)
 
void post_alarm (const char *, struct arglist *, int, const char *)
 
void post_alarm_udp (struct arglist *, int, const char *)
 
void proto_post_error (const char *, struct arglist *, int, const char *, const char *)
 
void post_error (const char *, struct arglist *, int, const char *)
 
void proto_post_log (const char *, struct arglist *, int, const char *, const char *)
 Post a log message. More...
 
void post_log (const char *, struct arglist *, int, const char *)
 Post a log message about a tcp port. More...
 
int host_get_port_state (struct arglist *, int)
 
int host_get_port_state_udp (struct arglist *, int)
 
void plug_set_key (struct arglist *, char *, int, const void *)
 
void plug_replace_key (struct arglist *, char *, int, void *)
 
kb_t plug_get_kb (struct arglist *)
 
void * plug_get_key (struct arglist *, char *, int *, int)
 
struct in6_addr * plug_get_host_ip (struct arglist *)
 
char * plug_get_host_ip_str (struct arglist *)
 
void add_plugin_preference (struct arglist *, const char *, const char *, const char *)
 
char * get_plugin_preference (const char *, const char *)
 
const char * get_plugin_preference_fname (struct arglist *, const char *)
 Get the file name of a plugins preference that is of type "file". More...
 
char * get_plugin_preference_file_content (struct arglist *, const char *)
 Get the file contents of a plugins preference that is of type "file". More...
 
long get_plugin_preference_file_size (struct arglist *, const char *)
 Get the file size of a plugins preference that is of type "file". More...
 
char * find_in_path (char *, int)
 

Macro Definition Documentation

◆ LEGACY_OID

#define LEGACY_OID   "1.3.6.1.4.1.25623.1.0."

Definition at line 35 of file plugutils.h.

Referenced by script_id().

◆ post_alarm_tcp

#define post_alarm_tcp   post_alarm

Definition at line 73 of file plugutils.h.

◆ post_error_tcp

#define post_error_tcp   post_error

Definition at line 77 of file plugutils.h.

◆ post_log_tcp

#define post_log_tcp   post_log

Definition at line 81 of file plugutils.h.

Function Documentation

◆ add_plugin_preference()

void add_plugin_preference ( struct arglist ,
const char *  ,
const char *  ,
const char *   
)

Definition at line 465 of file plugutils.c.

References arg_get_value(), name, nvti_add_pref(), and nvtpref_new().

Referenced by script_add_preference().

467 {
468  nvti_t *n = arg_get_value (desc, "NVTI");
469  nvtpref_t *np = nvtpref_new ((gchar *)name, (gchar *)type, (gchar *)defaul);
470 
471  nvti_add_pref (n, np);
472 }
nvtpref_t * nvtpref_new(gchar *name, gchar *type, gchar *dflt)
Create a new nvtpref structure filled with the given values.
Definition: nvti.c:63
The structure of a information record that corresponds to a NVT.
Definition: nvti.h:64
int nvti_add_pref(nvti_t *n, nvtpref_t *np)
Add a preference to the NVT Info.
Definition: nvti.c:1109
const char * name
Definition: nasl_init.c:524
The structure for a preference of a NVT.
Definition: nvti.h:45
void * arg_get_value(struct arglist *args, const char *name)
Definition: arglists.c:252
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_in_path()

char* find_in_path ( char *  ,
int   
)

Definition at line 1041 of file plugutils.c.

References name.

Referenced by nasl_find_in_path(), and plugin_run_openvas_tcp_scanner().

1042 {
1043  char *buf = getenv ("PATH"), *pbuf, *p1, *p2;
1044  static char cmd[MAXPATHLEN];
1045  int len = strlen (name);
1046 
1047  if (len >= MAXPATHLEN)
1048  return NULL;
1049 
1050  if (buf == NULL) /* Should we use a standard PATH here? */
1051  return NULL;
1052 
1053  pbuf = buf;
1054  while (*pbuf != '\0')
1055  {
1056  for (p1 = pbuf, p2 = cmd; *p1 != ':' && *p1 != '\0';)
1057  *p2++ = *p1++;
1058  *p2 = '\0';
1059  if (*p1 == ':')
1060  p1++;
1061  pbuf = p1;
1062  if (p2 == cmd) /* :: found in $PATH */
1063  strcpy (cmd, ".");
1064 
1065  if (cmd[0] != '/' && safe)
1066  continue;
1067  if (p2 - cmd + 1 + len >= MAXPATHLEN)
1068  /* path too long: cannot be reached */
1069  continue;
1070 
1071  snprintf (p2, MAXPATHLEN, "/%s", name);
1072  if (access (cmd, X_OK) == 0)
1073  {
1074  struct stat st;
1075  if (stat (cmd, &st) < 0)
1076  perror (cmd);
1077  else if (S_ISREG (st.st_mode))
1078  {
1079  *p2 = '\0';
1080  return cmd;
1081  }
1082  }
1083  }
1084  return NULL;
1085 }
const char * name
Definition: nasl_init.c:524
Here is the caller graph for this function:

◆ get_plugin_preference()

char* get_plugin_preference ( const char *  ,
const char *   
)

Definition at line 476 of file plugutils.c.

References arglist::name, name, arglist::next, nvticache_get_name(), nvticache_get_prefs(), nvticache_initialized(), nvtpref_default(), nvtpref_free(), nvtpref_name(), oid, preferences_get(), and arglist::value.

Referenced by plugin_run_find_service(), script_get_preference(), script_get_preference_file_content(), and script_get_preference_file_location().

477 {
478  struct arglist *prefs;
479  char *plug_name, *cname, *retval = NULL;
480 
481  prefs = preferences_get ();
482  if (!prefs || !nvticache_initialized () || !oid || !name)
483  return NULL;
484 
485  plug_name = nvticache_get_name (oid);
486  if (!plug_name)
487  return NULL;
488  cname = g_strdup (name);
489 
490  g_strchomp (cname);
491  while (prefs->next)
492  {
493  char *a, *b;
494  char *t = prefs->name;
495 
496  a = strchr (t, '[');
497  b = strchr (t, ']');
498  if (a && b && b[1] == ':')
499  {
500  b += 2 * sizeof (char);
501  if (!strcmp (cname, b))
502  {
503  int old = a[0];
504  a[0] = 0;
505  if (!strcmp (t, plug_name))
506  {
507  a[0] = old;
508  retval = g_strdup (prefs->value);
509  break;
510  }
511  a[0] = old;
512  }
513  }
514  prefs = prefs->next;
515  }
516 
517  /* If no value set by the user, get the default one. */
518  if (!retval)
519  {
520  GSList *tmp, *nprefs;
521 
522  tmp = nprefs = nvticache_get_prefs (oid);
523  while (tmp)
524  {
525  const nvtpref_t *nvtpref = tmp->data;
526  if (!strcmp (cname, nvtpref_name (nvtpref)))
527  {
528  retval = g_strdup (nvtpref_default (nvtpref));
529  break;
530  }
531  tmp = tmp->next;
532  }
533  g_slist_free_full (nprefs, (void (*) (void *)) nvtpref_free);
534  }
535 
536  g_free (cname);
537  return retval;
538 }
gchar * nvtpref_default(const nvtpref_t *np)
Get the Default of a NVT Preference.
Definition: nvti.c:137
gchar * nvtpref_name(const nvtpref_t *np)
Get the Name of a NVT Preference.
Definition: nvti.c:109
const char * oid
void nvtpref_free(nvtpref_t *np)
Free memory of a nvtpref structure.
Definition: nvti.c:86
void * value
Definition: arglists.h:32
struct arglist * next
Definition: arglists.h:33
const char * name
Definition: nasl_init.c:524
int nvticache_initialized(void)
Return whether the nvt cache is initialized.
Definition: nvticache.c:60
GSList * nvticache_get_prefs(const char *oid)
Get the prefs from a plugin OID.
Definition: nvticache.c:518
struct arglist * preferences_get(void)
Get the pointer to the global preferences structure. Eventually this function should not be used anyw...
Definition: prefs.c:68
The structure for a preference of a NVT.
Definition: nvti.h:45
char * name
Definition: arglists.h:31
char * nvticache_get_name(const char *oid)
Get the name from a plugin OID.
Definition: nvticache.c:406
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_plugin_preference_file_content()

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.

Definition at line 605 of file plugutils.c.

References arg_get_value().

Referenced by get_plugin_preference_fname(), and script_get_preference_file_content().

607 {
608  struct arglist *globals = arg_get_value (desc, "globals");
609  GHashTable *trans;
610 
611  if (!globals)
612  return NULL;
613 
614  trans = arg_get_value (globals, "files_translation");
615  if (!trans)
616  return NULL;
617 
618  return g_hash_table_lookup (trans, identifier);
619 }
void * arg_get_value(struct arglist *args, const char *name)
Definition: arglists.c:252
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_plugin_preference_file_size()

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.

Definition at line 637 of file plugutils.c.

References arg_get_value().

Referenced by get_plugin_preference_fname(), and script_get_preference_file_content().

638 {
639  struct arglist *globals = arg_get_value (desc, "globals");
640  GHashTable *trans;
641  gchar *filesize_str;
642 
643  if (!globals)
644  return -1;
645 
646  trans = arg_get_value (globals, "files_size_translation");
647  if (!trans)
648  return -1;
649 
650  filesize_str = g_hash_table_lookup (trans, identifier);
651  if (filesize_str == NULL)
652  return -1;
653 
654  return atol (filesize_str);
655 }
void * arg_get_value(struct arglist *args, const char *name)
Definition: arglists.c:252
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_plugin_preference_fname()

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.

Definition at line 551 of file plugutils.c.

References get_plugin_preference_file_content(), get_plugin_preference_file_size(), and log_legacy_write().

Referenced by plugin_run_find_service(), and script_get_preference_file_location().

552 {
553  const char *content;
554  long contentsize = 0;
555  gint tmpfile;
556  gchar *tmpfilename;
557  GError *error = NULL;
558 
559  content = get_plugin_preference_file_content (desc, filename);
560  if (content == NULL)
561  {
562  return NULL;
563  }
564  contentsize = get_plugin_preference_file_size (desc, filename);
565  if (contentsize <= 0)
566  return NULL;
567 
568  tmpfile =
569  g_file_open_tmp ("openvassd-file-upload.XXXXXX", &tmpfilename, &error);
570  if (tmpfile == -1)
571  {
572  log_legacy_write ("get_plugin_preference_fname: Could not open temporary"
573  " file for %s: %s", filename, error->message);
574  g_error_free (error);
575  return NULL;
576  }
577  close (tmpfile);
578 
579  if (!g_file_set_contents (tmpfilename, content, contentsize, &error))
580  {
581  log_legacy_write ("get_plugin_preference_fname: could set contents of"
582  " temporary file for %s: %s", filename, error->message);
583  g_error_free (error);
584  return NULL;
585  }
586 
587  return tmpfilename;
588 }
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
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".
Definition: plugutils.c:605
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".
Definition: plugutils.c:637
Here is the call graph for this function:
Here is the caller graph for this function:

◆ host_get_port_state()

int host_get_port_state ( struct arglist ,
int   
)

Definition at line 177 of file plugutils.c.

References host_get_port_state_proto().

Referenced by get_port_state(), and open_sock_option().

178 {
179  return (host_get_port_state_proto (plugdata, portnum, "tcp"));
180 }
int host_get_port_state_proto(struct arglist *plugdata, int portnum, char *proto)
Definition: plugutils.c:169
Here is the call graph for this function:
Here is the caller graph for this function:

◆ host_get_port_state_udp()

int host_get_port_state_udp ( struct arglist ,
int   
)

Definition at line 183 of file plugutils.c.

References host_get_port_state_proto().

Referenced by get_udp_port_state().

184 {
185  return (host_get_port_state_proto (plugdata, portnum, "udp"));
186 }
int host_get_port_state_proto(struct arglist *plugdata, int portnum, char *proto)
Definition: plugutils.c:169
Here is the call graph for this function:
Here is the caller graph for this function:

◆ plug_create_from_nvti_and_prefs()

struct arglist* plug_create_from_nvti_and_prefs ( const nvti_t )

◆ plug_get_host_fqdn()

char* plug_get_host_fqdn ( struct arglist )

Definition at line 200 of file plugutils.c.

References arg_get_value(), host_info::fqdn, plug_get_key(), prefs_get(), and host_info::vhosts.

Referenced by get_hostname().

201 {
202  struct host_info *hinfos = arg_get_value (desc, "HOSTNAME");
203  int type;
204  char *vhosts;
205 
206  if (!prefs_get ("vhosts_ip") || !strlen (prefs_get ("vhosts_ip")))
207  return g_strdup (hinfos->fqdn);
208  vhosts = plug_get_key (desc, "hostinfos/vhosts", &type, 0);
209  if (!vhosts)
210  return g_strdup (hinfos->fqdn);
211  return vhosts;
212 }
void * plug_get_key(struct arglist *args, char *name, int *type, int single)
Definition: plugutils.c:767
const gchar * prefs_get(const gchar *key)
Get a string preference value via a key.
Definition: prefs.c:86
char * vhosts
Definition: network.h:60
void * arg_get_value(struct arglist *args, const char *name)
Definition: arglists.c:252
char * fqdn
Definition: network.h:59
Here is the call graph for this function:
Here is the caller graph for this function:

◆ plug_get_host_ip()

struct in6_addr* plug_get_host_ip ( struct arglist )

Definition at line 216 of file plugutils.c.

References arg_get_value(), and host_info::ip.

Referenced by forge_ip_packet(), forge_ipv6_packet(), get_host_ip(), ids_open_sock_tcp(), nasl_islocalhost(), nasl_islocalnet(), nasl_open_sock_udp(), nasl_pcap_next(), nasl_send_capture(), nasl_send_packet(), nasl_send_v6packet(), nasl_smb_connect(), nasl_target_is_ipv6(), nasl_tcp_ping(), nasl_tcp_v6_ping(), nasl_this_host(), nasl_win_cmd_exec(), nasl_wmi_connect(), nasl_wmi_connect_reg(), nasl_wmi_connect_rsop(), open_sock_option(), plug_get_host_ip_str(), and plugin_run_synscan().

217 {
218  struct host_info *hinfos = arg_get_value (desc, "HOSTNAME");
219  if (hinfos)
220  return hinfos->ip;
221  return NULL;
222 }
struct in6_addr * ip
Definition: network.h:61
void * arg_get_value(struct arglist *args, const char *name)
Definition: arglists.c:252
Here is the call graph for this function:
Here is the caller graph for this function:

◆ plug_get_host_ip_str()

char* plug_get_host_ip_str ( struct arglist )

Definition at line 225 of file plugutils.c.

References addr6_as_str(), and plug_get_host_ip().

Referenced by open_sock_tcp().

226 {
227  return addr6_as_str (plug_get_host_ip (desc));
228 }
char * addr6_as_str(const struct in6_addr *addr6)
struct in6_addr * plug_get_host_ip(struct arglist *desc)
Definition: plugutils.c:216
Here is the call graph for this function:
Here is the caller graph for this function:

◆ plug_get_host_open_port()

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...

Definition at line 917 of file plugutils.c.

References MAX_CANDIDATES, and plug_get_kb().

Referenced by get_host_open_port(), nasl_start_denial(), nasl_tcp_ping(), and nasl_tcp_v6_ping().

918 {
919  kb_t kb = plug_get_kb (desc);
920  struct kb_item *res, *k;
921  int open21 = 0, open80 = 0;
922 #define MAX_CANDIDATES 16
923  u_short candidates[MAX_CANDIDATES];
924  int num_candidates = 0;
925 
926  k = res = kb_item_get_pattern (kb, "Ports/tcp/*");
927  if (res == NULL)
928  return 0;
929  else
930  {
931  int ret;
932  char *s;
933 
934  for (;;)
935  {
936  s = res->name + sizeof ("Ports/tcp/") - 1;
937  ret = atoi (s);
938  if (ret == 21)
939  open21 = 1;
940  else if (ret == 80)
941  open80 = 1;
942  else
943  {
944  candidates[num_candidates++] = ret;
945  if (num_candidates >= MAX_CANDIDATES)
946  break;
947  }
948  res = res->next;
949  if (res == NULL)
950  break;
951  }
952 
953  kb_item_free (k);
954  if (num_candidates != 0)
955  return candidates[lrand48 () % num_candidates];
956  else if (open21)
957  return 21;
958  else if (open80)
959  return 80;
960  else
961  return 0;
962  }
963 
964  /* Not reachable */
965  return 0;
966 }
void kb_item_free(struct kb_item *)
Release a KB item (or a list).
Definition: kb_redis.c:501
Knowledge base item (defined by name, type (int/char*) and value). Implemented as a singly linked lis...
Definition: kb.h:81
struct kb_item * next
Definition: kb.h:91
kb_t plug_get_kb(struct arglist *args)
Definition: plugutils.c:710
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:102
#define MAX_CANDIDATES
char name[0]
Definition: kb.h:94
Here is the call graph for this function:
Here is the caller graph for this function:

◆ plug_get_hostname()

const char* plug_get_hostname ( struct arglist )

Definition at line 190 of file plugutils.c.

References arg_get_value(), and host_info::name.

Referenced by proto_post_wrapped().

191 {
192  struct host_info *hinfo = arg_get_value (desc, "HOSTNAME");
193  if (hinfo)
194  return hinfo->name;
195  else
196  return (NULL);
197 }
char * name
Definition: network.h:58
void * arg_get_value(struct arglist *args, const char *name)
Definition: arglists.c:252
Here is the call graph for this function:
Here is the caller graph for this function:

◆ plug_get_kb()

kb_t plug_get_kb ( struct arglist )

Definition at line 710 of file plugutils.c.

References arg_get_value().

Referenced by build_encode_URL(), exec_nasl_script(), get_kb_list(), host_get_port_state_proto(), open_sock_tcp(), plug_get_host_open_port(), plug_get_key(), plug_replace_key(), plug_set_key(), plugin_run_find_service(), and socket_negotiate_ssl().

711 {
712  return (kb_t) arg_get_value (args, "key");
713 }
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:102
void * arg_get_value(struct arglist *args, const char *name)
Definition: arglists.c:252
Here is the call graph for this function:
Here is the caller graph for this function:

◆ plug_get_key()

void* plug_get_key ( struct arglist ,
char *  ,
int *  ,
int   
)

Definition at line 767 of file plugutils.c.

References plug_get_kb(), and kb_item::type.

Referenced by get_kb_item(), nasl_open_sock_kdc(), and plug_get_host_fqdn().

768 {
769  kb_t kb = plug_get_kb (args);
770  struct kb_item *res = NULL, *res_list;
771  int sockpair[2];
772  int upstream = 0;
773 
774  if (type != NULL)
775  *type = -1;
776 
777  if (kb == NULL)
778  return NULL;
779 
780  res = kb_item_get_all (kb, name);
781 
782  if (res == NULL)
783  return NULL;
784 
785  if (res->next == NULL || single) /* No fork - good */
786  {
787  void *ret;
788  if (res->type == KB_TYPE_INT)
789  {
790  if (type != NULL)
791  *type = KB_TYPE_INT;
792  ret = g_memdup (&res->v_int, sizeof (res->v_int));
793  }
794  else
795  {
796  if (type != NULL)
797  *type = KB_TYPE_STR;
798  ret = g_strdup (res->v_str);
799  }
800  kb_item_free (res);
801  return ret;
802  }
803 
804 
805  /* More than one value - we will fork() then */
806  sig_chld (plug_get_key_sigchld);
807  res_list = res;
808  while (res != NULL)
809  {
810  pid_t pid;
811 
812  socketpair (AF_UNIX, SOCK_STREAM, 0, sockpair);
813  if ((pid = fork ()) == 0)
814  {
815  int old;
816  struct arglist *globals;
817  void *ret;
818 
819  sig_term (_exit);
820  kb_lnk_reset (kb);
821  nvticache_reset ();
822  close (sockpair[0]);
823  globals = arg_get_value (args, "globals");
824  old = arg_get_value_int (globals, "global_socket");
825  if (old > 0)
826  close (old);
827  arg_set_value (globals, "global_socket", GSIZE_TO_POINTER (sockpair[1]));
828 
829  srand48 (getpid () + getppid () + time (NULL));
830 
831  if (res->type == KB_TYPE_INT)
832  {
833  if (type != NULL)
834  *type = KB_TYPE_INT;
835  ret = g_memdup (&res->v_int, sizeof (res->v_int));
836  }
837  else
838  {
839  if (type != NULL)
840  *type = KB_TYPE_STR;
841  ret = g_strdup (res->v_str);
842  }
843  kb_item_free (res_list);
844  return ret;
845  }
846  else if (pid < 0)
847  {
848  log_legacy_write ("libopenvas:%s:%s(): fork() failed (%s)", __FILE__,
849  __func__, strerror (errno));
850  kb_item_free (res_list);
851  return NULL;
852  }
853  else
854  {
855  int e;
856  int status;
857  struct arglist *globals;
858 
859  globals = arg_get_value (args, "globals");
860  upstream = arg_get_value_int (globals, "global_socket");
861  close (sockpair[1]);
862  _plug_get_key_son = pid;
863  sig_term (plug_get_key_sighand_term);
864  for (;;)
865  {
866  fd_set rd;
867  struct timeval tv;
868  int type;
869 
870  do
871  {
872  tv.tv_sec = 0;
873  tv.tv_usec = 100000;
874  FD_ZERO (&rd);
875  FD_SET (sockpair[0], &rd);
876  e = select (sockpair[0] + 1, &rd, NULL, NULL, &tv);
877  }
878  while (e < 0 && errno == EINTR);
879 
880  if (e > 0)
881  {
882  char *buf = NULL;
883  int bufsz = 0;
884 
885  e = internal_recv (sockpair[0], &buf, &bufsz, &type);
886  if (e < 0 || (type & INTERNAL_COMM_MSG_TYPE_CTRL))
887  {
888  waitpid (pid, &status, WNOHANG);
889  _plug_get_key_son = 0;
890  close (sockpair[0]);
891  sig_term (_exit);
892  g_free (buf); /* Left NULL on error, harmless */
893  break;
894  }
895  else
896  internal_send (upstream, buf, type);
897 
898  g_free (buf);
899  }
900  }
901  }
902  res = res->next;
903  }
904  kb_item_free (res_list);
905  internal_send (upstream, NULL,
907  exit (0);
908 }
Definition: kb.h:49
void kb_item_free(struct kb_item *)
Release a KB item (or a list).
Definition: kb_redis.c:501
void nvticache_reset()
Reset connection to KB. To be called after a fork().
Definition: nvticache.c:138
int arg_set_value(struct arglist *arglst, const char *name, void *value)
Definition: arglists.c:225
Knowledge base item (defined by name, type (int/char*) and value). Implemented as a singly linked lis...
Definition: kb.h:81
struct kb_item * next
Definition: kb.h:91
enum kb_item_type type
Definition: kb.h:83
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
int type
Definition: arglists.h:34
kb_t plug_get_kb(struct arglist *args)
Definition: plugutils.c:710
Definition: kb.h:48
#define INTERNAL_COMM_CTRL_FINISHED
Definition: internal_com.h:33
int internal_recv(int soc, char **data, int *data_sz, int *msg_type)
Definition: network.c:2318
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:102
const char * name
Definition: nasl_init.c:524
#define INTERNAL_COMM_MSG_TYPE_CTRL
Definition: internal_com.h:30
int v_int
Definition: kb.h:88
struct timeval timeval(unsigned long val)
int arg_get_value_int(struct arglist *args, const char *name)
Definition: arglists.c:246
int internal_send(int soc, char *data, int msg_type)
Definition: network.c:2263
void * arg_get_value(struct arglist *args, const char *name)
Definition: arglists.c:252
char * v_str
Definition: kb.h:87
Here is the call graph for this function:
Here is the caller graph for this function:

◆ plug_get_port_transport()

int plug_get_port_transport ( struct arglist ,
int   
)

Definition at line 990 of file plugutils.c.

Referenced by get_port_transport(), and open_stream_auto_encaps_ext().

991 {
992  char s[256];
993  int trp;
994 
995  snprintf (s, sizeof (s), "Transports/TCP/%d", port);
996  trp = kb_item_get_int (plug_get_kb (args), s);
997  if (trp >= 0)
998  return trp;
999  else
1000  return OPENVAS_ENCAPS_IP; /* Change this to 0 for ultra smart SSL negotiation, at the expense
1001  of possibly breaking stuff */
1002 }
kb_t plug_get_kb(struct arglist *args)
Definition: plugutils.c:710
Here is the caller graph for this function:

◆ plug_replace_key()

void plug_replace_key ( struct arglist ,
char *  ,
int  ,
void *   
)

Definition at line 681 of file plugutils.c.

References ARG_STRING, name, plug_get_kb(), arglist::type, and arglist::value.

Referenced by replace_kb_item().

682 {
683  kb_t kb = plug_get_kb (args);
684 
685  if (name == NULL || value == NULL)
686  return;
687 
688  if (type == ARG_STRING)
689  kb_item_set_str (kb, name, value);
690  else if (type == ARG_INT)
691  kb_item_set_int (kb, name, GPOINTER_TO_SIZE (value));
692  if (global_nasl_debug == 1)
693  {
694  if (type == ARG_STRING)
695  log_legacy_write ("replace key %s -> %s\n", name, (char *) value);
696  else if (type == ARG_INT)
697  log_legacy_write ("replace key %s -> %d\n", name,
698  (int) GPOINTER_TO_SIZE (value));
699  }
700 }
#define ARG_INT
Definition: arglists.h:40
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
kb_t plug_get_kb(struct arglist *args)
Definition: plugutils.c:710
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:102
const char * name
Definition: nasl_init.c:524
#define ARG_STRING
Definition: arglists.h:38
int global_nasl_debug
Definition: plugutils.c:54
Here is the call graph for this function:
Here is the caller graph for this function:

◆ plug_set_dep()

void plug_set_dep ( struct arglist ,
const char *   
)

Definition at line 87 of file plugutils.c.

References arg_get_value(), nvti_dependencies(), and nvti_set_dependencies().

Referenced by script_dependencies().

88 {
89  nvti_t *n = arg_get_value (desc, "NVTI");
90  gchar * old = nvti_dependencies (n);
91  gchar * new;
92 
93  if (!depname) return;
94 
95  if (old)
96  {
97  new = g_strdup_printf ("%s, %s", old, depname);
98  nvti_set_dependencies (n, new);
99  g_free (new);
100  }
101  else
102  nvti_set_dependencies (n, depname);
103 }
The structure of a information record that corresponds to a NVT.
Definition: nvti.h:64
gchar * nvti_dependencies(const nvti_t *n)
Get the dependencies list.
Definition: nvti.c:344
int nvti_set_dependencies(nvti_t *n, const gchar *dependencies)
Set the dependencies of a NVT.
Definition: nvti.c:696
void * arg_get_value(struct arglist *args, const char *name)
Definition: arglists.c:252
Here is the call graph for this function:
Here is the caller graph for this function:

◆ plug_set_key()

void plug_set_key ( struct arglist ,
char *  ,
int  ,
const void *   
)

Definition at line 658 of file plugutils.c.

References ARG_STRING, name, plug_get_kb(), arglist::type, and arglist::value.

Referenced by host_add_port_proto(), plug_set_port_transport(), plugin_run_synscan(), scan(), and set_kb_item().

659 {
660  kb_t kb = plug_get_kb (args);
661 
662  if (name == NULL || value == NULL)
663  return;
664 
665  if (type == ARG_STRING)
666  kb_item_add_str (kb, name, value);
667  else if (type == ARG_INT)
668  kb_item_add_int (kb, name, GPOINTER_TO_SIZE (value));
669  if (global_nasl_debug == 1)
670  {
671  if (type == ARG_STRING)
672  log_legacy_write ("set key %s -> %s\n", name, (char *) value);
673  else if (type == ARG_INT)
674  log_legacy_write ("set key %s -> %d\n", name,
675  (int) GPOINTER_TO_SIZE (value));
676  }
677 }
#define ARG_INT
Definition: arglists.h:40
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
kb_t plug_get_kb(struct arglist *args)
Definition: plugutils.c:710
Top-level KB. This is to be inherited by KB implementations.
Definition: kb.h:102
const char * name
Definition: nasl_init.c:524
#define ARG_STRING
Definition: arglists.h:38
int global_nasl_debug
Definition: plugutils.c:54
Here is the call graph for this function:
Here is the caller graph for this function:

◆ plug_set_port_transport()

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

Definition at line 976 of file plugutils.c.

References ARG_INT, and plug_set_key().

Referenced by open_stream_auto_encaps_ext().

977 {
978  char s[256];
979 
980  snprintf (s, sizeof (s), "Transports/TCP/%d", port);
981  plug_set_key (args, s, ARG_INT, GSIZE_TO_POINTER (tr));
982 }
#define ARG_INT
Definition: arglists.h:40
void plug_set_key(struct arglist *args, char *name, int type, const void *value)
Definition: plugutils.c:658
Here is the call graph for this function:
Here is the caller graph for this function:

◆ plug_set_ssl_CA_file()

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.

Definition at line 1035 of file plugutils.c.

Referenced by plugin_run_find_service().

1036 {
1037  plug_set_ssl_item (args, "CA", key);
1038 }
Here is the caller graph for this function:

◆ plug_set_ssl_cert()

void plug_set_ssl_cert ( struct arglist ,
char *   
)

Definition at line 1013 of file plugutils.c.

Referenced by plugin_run_find_service().

1014 {
1015  plug_set_ssl_item (args, "cert", cert);
1016 }
Here is the caller graph for this function:

◆ plug_set_ssl_key()

void plug_set_ssl_key ( struct arglist ,
char *   
)

Definition at line 1019 of file plugutils.c.

Referenced by plugin_run_find_service().

1020 {
1021  plug_set_ssl_item (args, "key", key);
1022 }
Here is the caller graph for this function:

◆ plug_set_ssl_pem_password()

void plug_set_ssl_pem_password ( struct arglist ,
char *   
)

Definition at line 1025 of file plugutils.c.

Referenced by plugin_run_find_service().

1026 {
1027  plug_set_ssl_item (args, "password", key);
1028 }
Here is the caller graph for this function:

◆ plug_set_tag()

void plug_set_tag ( struct arglist ,
char *  ,
char *   
)

Definition at line 72 of file plugutils.c.

References arg_get_value(), name, nvti_set_tag(), and nvti_tag().

Referenced by script_tag().

73 {
74  nvti_t *n = arg_get_value (desc, "NVTI");
75  char *new;
76 
77  if (nvti_tag (n))
78  new = g_strconcat (nvti_tag (n), "|", name, "=", value, NULL);
79  else
80  new = g_strconcat (name, "=", value, NULL);
81 
82  nvti_set_tag (n, new);
83  g_free (new);
84 }
The structure of a information record that corresponds to a NVT.
Definition: nvti.h:64
int nvti_set_tag(nvti_t *n, const gchar *tag)
Set the tags of a NVT.
Definition: nvti.c:648
gchar * nvti_tag(const nvti_t *n)
Get the tag.
Definition: nvti.c:316
const char * name
Definition: nasl_init.c:524
void * arg_get_value(struct arglist *args, const char *name)
Definition: arglists.c:252
Here is the call graph for this function:
Here is the caller graph for this function:

◆ plug_set_xref()

void plug_set_xref ( struct arglist ,
char *  ,
char *   
)

Definition at line 57 of file plugutils.c.

References arg_get_value(), name, nvti_set_xref(), and nvti_xref().

Referenced by script_xref().

58 {
59  nvti_t *n = arg_get_value (desc, "NVTI");
60  char *new;
61 
62  if (nvti_xref (n))
63  new = g_strconcat (nvti_xref (n), ", ", name, ":", value, NULL);
64  else
65  new = g_strconcat (name, ":", value, NULL);
66 
67  nvti_set_xref (n, new);
68  g_free (new);
69 }
gchar * nvti_xref(const nvti_t *n)
Get the xref&#39;s.
Definition: nvti.c:302
The structure of a information record that corresponds to a NVT.
Definition: nvti.h:64
int nvti_set_xref(nvti_t *n, const gchar *xref)
Set the xrefs of a NVT.
Definition: nvti.c:624
const char * name
Definition: nasl_init.c:524
void * arg_get_value(struct arglist *args, const char *name)
Definition: arglists.c:252
Here is the call graph for this function:
Here is the caller graph for this function:

◆ post_alarm()

void post_alarm ( const char *  ,
struct arglist ,
int  ,
const char *   
)

Definition at line 425 of file plugutils.c.

References oid, and proto_post_alarm().

426 {
427  proto_post_alarm (oid, desc, port, "tcp", action);
428 }
void proto_post_alarm(const char *oid, struct arglist *desc, int port, const char *proto, const char *action)
Definition: plugutils.c:418
const char * oid
Here is the call graph for this function:

◆ post_alarm_udp()

void post_alarm_udp ( struct arglist ,
int  ,
const char *   
)

◆ post_error()

void post_error ( const char *  ,
struct arglist ,
int  ,
const char *   
)

Definition at line 459 of file plugutils.c.

References oid, and proto_post_error().

460 {
461  proto_post_error (oid, desc, port, "tcp", action);
462 }
void proto_post_error(const char *oid, struct arglist *desc, int port, const char *proto, const char *action)
Definition: plugutils.c:451
const char * oid
Here is the call graph for this function:

◆ post_log()

void post_log ( const char *  ,
struct arglist ,
int  ,
const char *   
)

Post a log message about a tcp port.

Definition at line 445 of file plugutils.c.

References oid, and proto_post_log().

446 {
447  proto_post_log (oid, desc, port, "tcp", action);
448 }
const char * oid
void proto_post_log(const char *oid, struct arglist *desc, int port, const char *proto, const char *action)
Post a log message.
Definition: plugutils.c:435
Here is the call graph for this function:

◆ proto_post_alarm()

void proto_post_alarm ( const char *  ,
struct arglist ,
int  ,
const char *  ,
const char *   
)

Definition at line 418 of file plugutils.c.

References oid, and proto_post_wrapped().

Referenced by post_alarm().

420 {
421  proto_post_wrapped (oid, desc, port, proto, action, "ALARM");
422 }
const char * oid
void proto_post_wrapped(const char *oid, struct arglist *desc, int port, const char *proto, const char *action, const char *what)
Post a security message (e.g. LOG, NOTE, WARNING ...).
Definition: plugutils.c:270
Here is the call graph for this function:
Here is the caller graph for this function:

◆ proto_post_error()

void proto_post_error ( const char *  ,
struct arglist ,
int  ,
const char *  ,
const char *   
)

Definition at line 451 of file plugutils.c.

References oid, and proto_post_wrapped().

Referenced by post_error().

453 {
454  proto_post_wrapped (oid, desc, port, proto, action, "ERRMSG");
455 }
const char * oid
void proto_post_wrapped(const char *oid, struct arglist *desc, int port, const char *proto, const char *action, const char *what)
Post a security message (e.g. LOG, NOTE, WARNING ...).
Definition: plugutils.c:270
Here is the call graph for this function:
Here is the caller graph for this function:

◆ proto_post_log()

void proto_post_log ( const char *  ,
struct arglist ,
int  ,
const char *  ,
const char *   
)

Post a log message.

Definition at line 435 of file plugutils.c.

References oid, and proto_post_wrapped().

Referenced by post_log().

437 {
438  proto_post_wrapped (oid, desc, port, proto, action, "LOG");
439 }
const char * oid
void proto_post_wrapped(const char *oid, struct arglist *desc, int port, const char *proto, const char *action, const char *what)
Post a security message (e.g. LOG, NOTE, WARNING ...).
Definition: plugutils.c:270
Here is the call graph for this function:
Here is the caller graph for this function:

◆ scanner_add_port()

void scanner_add_port ( struct arglist ,
int  ,
char *   
)

Definition at line 703 of file plugutils.c.

References host_add_port_proto().

Referenced by nasl_scanner_add_port(), sendpacket(), and v6_sendpacket().

704 {
705  host_add_port_proto (args, port, proto);
706 }
void host_add_port_proto(struct arglist *args, int portnum, char *proto)
Definition: plugutils.c:106
Here is the call graph for this function:
Here is the caller graph for this function: