Skip to content

Commit

Permalink
Fix plug_get_key().
Browse files Browse the repository at this point in the history
It add support to force getting an integer.
  • Loading branch information
jjnicola committed Jun 7, 2019
1 parent b955373 commit 5014a2f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
6 changes: 4 additions & 2 deletions misc/plugutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,14 +804,16 @@ plug_get_key (struct script_infos *args, char *name, int *type, size_t *len,
kb_t kb = args->key;
struct kb_item *res = NULL, *res_list;

if (type != NULL)
if (type != NULL && *type != KB_TYPE_INT)
*type = -1;

if (kb == NULL)
return NULL;

if (single)
if (single && *type != KB_TYPE_INT)
res = kb_item_get_single (kb, name, KB_TYPE_UNSPEC);
else if (*type == KB_TYPE_INT)
res = kb_item_get_single (kb, name, KB_TYPE_INT);
else
res = kb_item_get_all (kb, name);

Expand Down
19 changes: 12 additions & 7 deletions nasl/nasl_misc_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,9 +753,10 @@ tree_cell *
nasl_open_sock_kdc (lex_ctxt *lexic)
{
tree_cell *retc;
int ret, type;
int timeout = 30, port = 88, tcp = 0;
char *hostname = NULL, *port_str, *tcp_str; /* Domain name for windows */
int ret, type, forced_type = KB_TYPE_INT;
int timeout = 30, tcp = 0;
unsigned short port = 88, *port_aux = NULL;
char *hostname = NULL, *tcp_str; /* Domain name for windows */
struct script_infos *script_infos;

script_infos = lexic->script_infos;
Expand All @@ -764,10 +765,14 @@ nasl_open_sock_kdc (lex_ctxt *lexic)
if (!hostname || type != KB_TYPE_STR)
return NULL;

port_str = plug_get_key (script_infos, "Secret/kdc_port", &type, NULL, 0);
port = GPOINTER_TO_SIZE (port_str);
g_free (port_str);
if (port <= 0 || type != KB_TYPE_INT)
port_aux = (unsigned short *) plug_get_key (script_infos, "Secret/kdc_port",
&forced_type, NULL, 0);
if (port_aux)
{
port = *port_aux;
g_free (port_aux);
}
if (port <= 0 || forced_type != KB_TYPE_INT)
return NULL;

tcp_str = plug_get_key (script_infos, "Secret/kdc_use_tcp", &type, NULL, 0);
Expand Down
15 changes: 8 additions & 7 deletions nasl/nasl_ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,20 @@ static unsigned short
get_ssh_port (lex_ctxt *lexic)
{
const char *value;
char *port_str;
int type;
unsigned short port;
int type = KB_TYPE_INT;
unsigned short port, *port_aux = NULL;

value = prefs_get ("auth_port_ssh");
if (value && (port = (unsigned short) strtoul (value, NULL, 10)) > 0)
return port;

port_str = plug_get_key (lexic->script_infos, "Services/ssh", &type, NULL, 0);
if (port_str)
port_aux = (unsigned short *) plug_get_key (lexic->script_infos,
"Services/ssh", &type, NULL, 0);

if (port_aux)
{
port = GPOINTER_TO_SIZE (port_str);
g_free (port_str);
port = *port_aux;
g_free (port_aux);
if (type == KB_TYPE_INT && port > 0)
return port;
}
Expand Down

0 comments on commit 5014a2f

Please sign in to comment.