Esempio n. 1
0
tree_cell * replace_kb_item(lex_ctxt * lexic)
{
 struct arglist * script_infos = lexic->script_infos;
 char * name  = get_str_local_var_by_name(lexic, "name");
 int type = get_local_var_type_by_name(lexic, "value");
 
 if( name == NULL )
 {
  nasl_perror(lexic, "Syntax error with replace_kb_item() [null name]\n", name);
  return FAKE_CELL;
 }
 
 if(type == VAR2_INT)
 {
  int value = get_int_local_var_by_name(lexic, "value", -1);
  if ( value != -1 )plug_replace_key(script_infos, name, ARG_INT,(void*)value);
  else nasl_perror(lexic, "Syntax error with replace_kb_item(%s) [value=-1]\n", name); }
 else
 {
  char * value = get_str_local_var_by_name(lexic, "value");
  if( value == NULL )
  {
    nasl_perror(lexic, "Syntax error with replace_kb_item(%s) [null value]\n", name);
    return FAKE_CELL;
  }
  plug_replace_key(script_infos, name, ARG_STRING, value);
 }

 return FAKE_CELL;
}
Esempio n. 2
0
tree_cell *
nasl_open_sock_tcp_bufsz (lex_ctxt * lexic, int bufsz)
{
  int soc = -1;
  struct arglist *script_infos = lexic->script_infos;
  int to, port;
  int transport = -1;
  const char *priority;
  tree_cell *retc;
  int type;

  to = get_int_local_var_by_name (lexic, "timeout", lexic->recv_timeout * 2);
  if (to < 0)
    to = 10;

  transport = get_int_local_var_by_name (lexic, "transport", -1);

  if (transport == OPENVAS_ENCAPS_TLScustom)
    {
      priority = get_str_local_var_by_name (lexic, "priority");
      if (!priority)
        priority = NULL;
      type = get_local_var_type_by_name (lexic, "priority");
      if (type != VAR2_STRING && type != VAR2_DATA)
        priority = NULL;
    }
  else
    priority = NULL;

  if (bufsz < 0)
    bufsz = get_int_local_var_by_name (lexic, "bufsz", 0);

  port = get_int_var_by_num (lexic, 0, -1);
  if (port < 0)
    return NULL;

  /* If "transport" has not been given, use auto detection if enabled
     in the KB. if "transport" has been given with a value of 0 force
     autodetection reagardless of what the KB tells.  */
  if (transport < 0)
    soc = open_stream_auto_encaps_ext (script_infos, port, to, 0);
  else if (transport == 0)
    soc = open_stream_auto_encaps_ext (script_infos, port, to, 1);
  else
    soc = open_stream_connection_ext (script_infos, port, transport, to,
                                      priority);
  if (bufsz > 0 && soc >= 0)
    {
      if (stream_set_buffer (soc, bufsz) < 0)
        nasl_perror (lexic, "stream_set_buffer: soc=%d,bufsz=%d\n", soc, bufsz);
    }

  retc = alloc_tree_cell (0, NULL);
  retc->type = CONST_INT;
  retc->x.i_val = soc < 0 ? 0 : soc;

  return retc;
}
Esempio n. 3
0
tree_cell * set_kb_item(lex_ctxt * lexic)
{
 struct arglist * script_infos = lexic->script_infos;
 char * name  = get_str_local_var_by_name(lexic, "name");
 int type = get_local_var_type_by_name(lexic, "value");
 
 if( name == NULL )
 {
  nasl_perror(lexic, "Syntax error with set_kb_item() [null name]\n", name);
  return FAKE_CELL;
 }
 
 if (! lexic->authenticated && 
     strncmp(name, SECRET_KB_PREFIX, sizeof(SECRET_KB_PREFIX) - 1) == 0)
 {
  nasl_perror(lexic, "Only signed scripts can set a Secret/ KB entry\n");
  return FAKE_CELL;
 }


 if(type == VAR2_INT)
 {
  int value = get_int_local_var_by_name(lexic, "value", -1);
  if ( value != -1 )plug_set_key(script_infos, name, ARG_INT,(void*)value);
  else nasl_perror(lexic, "Syntax error with set_kb_item() [value=-1]\n", name); }
 else
 {
  char * value = get_str_local_var_by_name(lexic, "value");
  if( value == NULL )
  {
    nasl_perror(lexic, "Syntax error with set_kb_item() [null value]\n", name);
    return FAKE_CELL;
  }
  plug_set_key(script_infos, name, ARG_STRING, value);
 }

 return FAKE_CELL;
}