OpenVAS Scanner 23.32.3
nasl_wmi.h File Reference

Protos for NASL WMI API. More...

#include "nasl_lex_ctxt.h"
#include "nasl_tree.h"
Include dependency graph for nasl_wmi.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

tree_cellnasl_wmi_versioninfo (lex_ctxt *lexic)
 Get a version string of the WMI implementation.
tree_cellnasl_wmi_connect (lex_ctxt *lexic)
 Connect to a WMI service and return a handle for it.
tree_cellnasl_wmi_close (lex_ctxt *lexic)
 Close WMI service handle.
tree_cellnasl_wmi_query (lex_ctxt *lexic)
 Perform WQL query.
tree_cellnasl_wmi_connect_rsop (lex_ctxt *lexic)
 Connect to a WMI RSOP service and return a handle for it.
tree_cellnasl_wmi_query_rsop (lex_ctxt *lexic)
 WMI RSOP query.
tree_cellnasl_wmi_connect_reg (lex_ctxt *lexic)
 Connect to a WMI Registry service and return a handle for it.
tree_cellnasl_wmi_reg_get_sz (lex_ctxt *lexic)
 Get string value from Registry.
tree_cellnasl_wmi_reg_enum_value (lex_ctxt *lexic)
 Enumerate registry values.
tree_cellnasl_wmi_reg_enum_key (lex_ctxt *lexic)
 Enumerate registry keys.
tree_cellnasl_wmi_reg_get_bin_val (lex_ctxt *lexic)
 Get registry binary value.
tree_cellnasl_wmi_reg_get_dword_val (lex_ctxt *lexic)
 Get registry DWORD value.
tree_cellnasl_wmi_reg_get_ex_string_val (lex_ctxt *lexic)
 Get registry expanded string value.
tree_cellnasl_wmi_reg_get_mul_string_val (lex_ctxt *lexic)
 Get registry multi valued strings.
tree_cellnasl_wmi_reg_get_qword_val (lex_ctxt *lexic)
 Get registry QWORD value.
tree_cellnasl_wmi_reg_set_dword_val (lex_ctxt *lexic)
 Set Registry DWORD value.
tree_cellnasl_wmi_reg_set_qword_val (lex_ctxt *lexic)
 Set Registry QWORD value.
tree_cellnasl_wmi_reg_set_ex_string_val (lex_ctxt *lexic)
 Set Registry Expanded string value.
tree_cellnasl_wmi_reg_set_string_val (lex_ctxt *lexic)
 Set Registry string value.
tree_cellnasl_wmi_reg_create_key (lex_ctxt *lexic)
 Create Registry key.
tree_cellnasl_wmi_reg_delete_key (lex_ctxt *lexic)
 Delete Registry key.

Detailed Description

Protos for NASL WMI API.

This file contains the protos for nasl_wmi.c

Definition in file nasl_wmi.h.

Function Documentation

◆ nasl_wmi_close()

tree_cell * nasl_wmi_close ( lex_ctxt * lexic)

Close WMI service handle.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL in case of a serious problem. Else returns a treecell with integer == 1.

Retrieves local variable "wmi_handle" from the lexical context and closes the respective handle.

Definition at line 191 of file nasl_wmi.c.

192{
193 WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
194 if (!handle)
195 return NULL;
196
198
199 if (wmi_close (handle) == 0)
200 {
201 retc->x.i_val = 1;
202 return retc;
203 }
204 return NULL;
205}
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition nasl_var.c:1101
tree_cell * alloc_typed_cell(int typ)
Definition nasl_tree.c:25
@ CONST_INT
Definition nasl_tree.h:79
struct TC tree_cell
int wmi_close(WMI_HANDLE)
Close the connection handle for a WMI service.
void * WMI_HANDLE
long int i_val
Definition nasl_tree.h:104
union TC::@332262321161220155002104006201360276211317150140 x

References alloc_typed_cell(), CONST_INT, get_int_var_by_name(), TC::i_val, wmi_close(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_connect()

tree_cell * nasl_wmi_connect ( lex_ctxt * lexic)

Connect to a WMI service and return a handle for it.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL in case the connection could not be established. Else a tree_cell with the handle.

Retrieves local variables "host", "username", "password" and "ns" from the lexical context, performs and connects to this given WMI service returning a handle for the service as integer.

Definition at line 128 of file nasl_wmi.c.

129{
130 struct script_infos *script_infos = lexic->script_infos;
131 struct in6_addr *host = plug_get_host_ip (script_infos);
132 char *ip;
133 char *argv[max];
134 WMI_HANDLE handle;
135 int argc = 5;
136 IMPORT (username);
137 IMPORT (password);
138 IMPORT (ns);
139 IMPORT (options);
140
141 if (ns == NULL)
142 ns = "root\\cimv2";
143
144 if ((host == NULL) || (username == NULL) || (password == NULL))
145 {
146 g_message ("nasl_wmi_connect: Invalid input arguments");
147 return NULL;
148 }
149
150 ip = addr6_as_str (host);
151 if ((strlen (password) == 0) || (strlen (username) == 0) || strlen (ip) == 0)
152 {
153 g_message ("nasl_wmi_connect: Invalid input arguments");
154 g_free (ip);
155 return NULL;
156 }
157
158 // Construct the WMI query
159 argv[0] = g_strdup ("wmic");
160 argv[1] = g_strdup ("-U");
161 argv[2] = g_strdup_printf ("%s%%%s", username, password);
162 argv[3] = g_strdup_printf ("//%s%s", ip, options ? options : "[sign]");
163 argv[4] = g_strdup (ns);
164 g_free (ip);
165
167 handle = wmi_connect (argc, argv);
168 if (!handle)
169 {
170 g_message ("nasl_wmi_connect: WMI Connect failed or missing WMI support "
171 "for the scanner");
172 return NULL;
173 }
174
175 retc->x.ref_val = handle;
176 return retc;
177}
#define max
Definition nasl_wmi.c:34
#define IMPORT(var)
Definition nasl_wmi.c:33
WMI_HANDLE wmi_connect(int argc, char **argv)
Establish connection to a WMI service.
struct in6_addr * plug_get_host_ip(struct script_infos *args)
Definition plugutils.c:371
void * ref_val
Definition nasl_tree.h:105
Host information, implemented as doubly linked list.
Definition hosts.c:37
struct script_infos * script_infos

References alloc_typed_cell(), CONST_INT, IMPORT, max, plug_get_host_ip(), TC::ref_val, struct_lex_ctxt::script_infos, wmi_connect(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_connect_reg()

tree_cell * nasl_wmi_connect_reg ( lex_ctxt * lexic)

Connect to a WMI Registry service and return a handle for it.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL in case the connection could not be established. Else a tree_cell with the handle.

Retrieves local variables "host", "username", "password" from the lexical context, performs and connects to this given WMI service returning a handle for the service as integer.

Definition at line 388 of file nasl_wmi.c.

389{
390 struct script_infos *script_infos = lexic->script_infos;
391 struct in6_addr *host = plug_get_host_ip (script_infos);
392 char *ip;
393 IMPORT (username);
394 IMPORT (password);
395 IMPORT (options);
396
397 char *argv[4];
398 WMI_HANDLE handle;
399 int argc = 4;
400
401 if ((host == NULL) || (username == NULL) || (password == NULL))
402 {
403 g_message ("nasl_wmi_connect_reg: Invalid input arguments");
404 return NULL;
405 }
406
407 ip = addr6_as_str (host);
408 if ((strlen (password) == 0) || (strlen (username) == 0) || strlen (ip) == 0)
409 {
410 g_message ("nasl_wmi_connect_reg: Invalid input arguments");
411 g_free (ip);
412 return NULL;
413 }
414
415 // Construct the WMI query
416 argv[0] = g_strdup ("wmic");
417 argv[1] = g_strdup ("-U");
418 argv[2] = g_strdup_printf ("%s%%%s", username, password);
419 argv[3] = g_strdup_printf ("//%s%s", ip, options ? options : "[sign]");
420 g_free (ip);
421
423 handle = wmi_connect_reg (argc, argv);
424 if (!handle)
425 {
426 g_message ("nasl_wmi_connect_reg: WMI Connect failed or missing WMI "
427 "support for the scanner");
428 return NULL;
429 }
430
431 retc->x.ref_val = handle;
432 return retc;
433}
WMI_HANDLE wmi_connect_reg(int argc, char **argv)
Establish connection to a WMI Registry service.

References alloc_typed_cell(), CONST_INT, IMPORT, plug_get_host_ip(), TC::ref_val, struct_lex_ctxt::script_infos, wmi_connect_reg(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_connect_rsop()

tree_cell * nasl_wmi_connect_rsop ( lex_ctxt * lexic)

Connect to a WMI RSOP service and return a handle for it.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL in case the connection could not be established. Else a tree_cell with the handle.

Retrieves local variables "host", "username", "password" from the lexical context, performs and connects to this given WMI service returning a handle for the service as integer.

Definition at line 275 of file nasl_wmi.c.

276{
277 struct script_infos *script_infos = lexic->script_infos;
278 struct in6_addr *host = plug_get_host_ip (script_infos);
279 char *ip;
280 IMPORT (username);
281 IMPORT (password);
282 IMPORT (options);
283
284 char *argv[4];
285 WMI_HANDLE handle;
286 int argc = 4;
287
288 if ((host == NULL) || (username == NULL) || (password == NULL))
289 {
290 g_message ("nasl_wmi_connect_rsop: Invalid input arguments");
291 return NULL;
292 }
293
294 ip = addr6_as_str (host);
295 if ((strlen (password) == 0) || (strlen (username) == 0) || strlen (ip) == 0)
296 {
297 g_message ("nasl_wmi_connect_rsop: Invalid input arguments");
298 g_free (ip);
299 return NULL;
300 }
301
302 // Construct the WMI query
303 argv[0] = g_strdup ("wmic");
304 argv[1] = g_strdup ("-U");
305 argv[2] = g_strdup_printf ("%s%%%s", username, password);
306 argv[3] = g_strdup_printf ("//%s%s", ip, options ? options : "[sign]");
307 g_free (ip);
308
310 handle = wmi_connect_rsop (argc, argv);
311 if (!handle)
312 {
313 g_message ("nasl_wmi_connect_rsop: WMI Connect failed or missing WMI "
314 "support for the scanner");
315 return NULL;
316 }
317
318 retc->x.ref_val = handle;
319 return retc;
320}
WMI_HANDLE wmi_connect_rsop(int argc, char **argv)
Establish connection to a WMI RSOP service.

References alloc_typed_cell(), CONST_INT, IMPORT, plug_get_host_ip(), TC::ref_val, struct_lex_ctxt::script_infos, wmi_connect_rsop(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_query()

tree_cell * nasl_wmi_query ( lex_ctxt * lexic)

Perform WQL query.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL in case the query can not be executed properly. Else a tree_cell with the result of the query as string.

Retrieves local variables "wmi_handle" and "query" from the lexical context, performs a WMI query on the given handle and returns the result as a string.

Definition at line 220 of file nasl_wmi.c.

221{
222 WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
223 char *query = get_str_var_by_name (lexic, "query");
224 char *res = NULL;
225 int value;
226
227 if (!handle)
228 return NULL;
229
231 retc->x.str_val = NULL;
232 retc->size = 0;
233
234 value = wmi_query (handle, query, &res);
235 if ((value == -1) && (res != NULL))
236 {
237 g_message ("wmi_query: WMI query failed '%s' with error: '%s'", query,
238 res);
239 g_free (res);
240 return NULL;
241 }
242 else if ((value == -1) && (res == NULL))
243 {
244 g_debug ("wmi_query: WMI query failed '%s'", query);
245 return NULL;
246 }
247 else if (res == NULL)
248 return NULL;
249
250 retc->x.str_val = strdup (res);
251 retc->size = strlen (res);
252
253 return retc;
254}
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition nasl_var.c:1118
@ CONST_DATA
Definition nasl_tree.h:82
int wmi_query(WMI_HANDLE, const char *, char **)
Query WMI service using a WQL query.
int size
Definition nasl_tree.h:99
char * str_val
Definition nasl_tree.h:103

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_query(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_query_rsop()

tree_cell * nasl_wmi_query_rsop ( lex_ctxt * lexic)

WMI RSOP query.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure, 1 on success

Retrieves local variables "wmi_handle", "query" from the lexical context, performs the RSOP query returning results in string format.

Definition at line 334 of file nasl_wmi.c.

335{
336 WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
337 if (!handle)
338 return NULL;
339
340 char *query = get_str_var_by_name (lexic, "query"); // WQL query
341 char *res = NULL;
342 int value;
344 retc->x.str_val = NULL;
345 retc->size = 0;
346
347 value = wmi_query_rsop (handle, query, &res);
348 if ((value == -1) && (res != NULL))
349 {
350 g_message ("wmi_query_rsop: WMI query failed '%s' with error: '%s'",
351 query, res);
352 g_free (res);
353 return NULL;
354 }
355 else if ((value == -1) && (res == NULL))
356 {
357 g_debug ("wmi_query_rsop: WMI query failed");
358 return NULL;
359 }
360 else if (res == NULL)
361 return NULL;
362
363 retc->x.str_val = strdup (res);
364 retc->size = strlen (res);
365
366 return retc;
367}
int wmi_query_rsop(WMI_HANDLE, const char *, char **)
WMI RSOP query.

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_query_rsop(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_create_key()

tree_cell * nasl_wmi_reg_create_key ( lex_ctxt * lexic)

Create Registry key.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure

Retrieves local variables "wmi_handle", "key" from the lexical context, performs the registry create operation for the key.

Definition at line 990 of file nasl_wmi.c.

991{
992 WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
993
994 if (!handle)
995 return NULL;
996
997 char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
998
999 int value;
1000
1002 retc->x.i_val = 1;
1003
1004 value = wmi_reg_create_key (handle, key);
1005
1006 if (value == -1)
1007 {
1008 g_message ("nasl_wmi_reg_create_key: WMI registry key create"
1009 " operation failed");
1010 return NULL;
1011 }
1012 return retc;
1013}
int wmi_reg_create_key(WMI_HANDLE, const char *)
Create Registry Key.

References alloc_typed_cell(), CONST_INT, get_int_var_by_name(), get_str_var_by_name(), TC::i_val, wmi_reg_create_key(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_delete_key()

tree_cell * nasl_wmi_reg_delete_key ( lex_ctxt * lexic)

Delete Registry key.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure

Retrieves local variables "wmi_handle", "key" from the lexical context, performs the registry delete operation for the key.

It will work only if the key exist

Definition at line 1029 of file nasl_wmi.c.

1030{
1031 WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
1032
1033 if (!handle)
1034 return NULL;
1035
1036 char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
1037
1038 int value;
1039
1041 retc->x.i_val = 1;
1042
1043 value = wmi_reg_delete_key (handle, key);
1044
1045 if (value == -1)
1046 {
1047 g_message ("nasl_wmi_reg_delete_key: WMI registry key"
1048 " delete operation failed");
1049 return NULL;
1050 }
1051 return retc;
1052}
int wmi_reg_delete_key(WMI_HANDLE, const char *)
Delete Registry Key.

References alloc_typed_cell(), CONST_INT, get_int_var_by_name(), get_str_var_by_name(), TC::i_val, wmi_reg_delete_key(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_enum_key()

tree_cell * nasl_wmi_reg_enum_key ( lex_ctxt * lexic)

Enumerate registry keys.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL if the query fails. Else a tree_cell with the Registry keys.

Retrieves local variables "wmi_handle", "hive", "key" from the lexical context, performs the registry query returning a string value.

Definition at line 536 of file nasl_wmi.c.

537{
538 WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
539
540 if (!handle)
541 return NULL;
542
543 unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
544 char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
545
546 char *res = NULL;
547 int value;
549 retc->x.str_val = NULL;
550 retc->size = 0;
551
552 value = wmi_reg_enum_key (handle, hive, key, &res);
553
554 if ((value == -1) || (res == NULL))
555 {
556 g_message ("nasl_wmi_reg_enum_key: WMI query failed");
557 return NULL;
558 }
559
560 retc->x.str_val = strdup (res);
561 retc->size = strlen (res);
562
563 return retc;
564}
int wmi_reg_enum_key(WMI_HANDLE, unsigned int, const char *, char **)
Enumerate Registry keys.

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_reg_enum_key(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_enum_value()

tree_cell * nasl_wmi_reg_enum_value ( lex_ctxt * lexic)

Enumerate registry values.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL if the query fails. Else a tree_cell with the Registry values.

Retrieves local variables "wmi_handle", "hive", "key" from the lexical context, performs the registry query returning a string value.

Definition at line 493 of file nasl_wmi.c.

494{
495 WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
496
497 if (!handle)
498 return NULL;
499
500 unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
501 char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
502
503 char *res = NULL;
504 int value;
506 retc->x.str_val = NULL;
507 retc->size = 0;
508
509 value = wmi_reg_enum_value (handle, hive, key, &res);
510
511 if ((value == -1) || (res == NULL))
512 {
513 g_message ("nasl_wmi_reg_enum_value: WMI query failed");
514 return NULL;
515 }
516
517 retc->x.str_val = strdup (res);
518 retc->size = strlen (res);
519
520 return retc;
521}
int wmi_reg_enum_value(WMI_HANDLE, unsigned int, const char *, char **)
Enumerate Registry values.

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_reg_enum_value(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_get_bin_val()

tree_cell * nasl_wmi_reg_get_bin_val ( lex_ctxt * lexic)

Get registry binary value.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure, else tree_cell containing string representation of binary value

Retrieves local variables "wmi_handle", "hive", "key", "val_name" from the lexical context, performs the registry operation querying binary value.

Definition at line 579 of file nasl_wmi.c.

580{
581 WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
582
583 if (!handle)
584 return NULL;
585
586 unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
587 char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
588 char *val_name =
589 get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
590
591 char *res = NULL;
592 int value;
593
595 retc->x.str_val = NULL;
596 retc->size = 0;
597
598 value = wmi_reg_get_bin_val (handle, hive, key, val_name, &res);
599
600 if ((value == -1) || (res == NULL))
601 {
602 g_message ("nasl_wmi_reg_get_bin_val: WMI query failed");
603 return NULL;
604 }
605
606 retc->x.str_val = strdup (res);
607 retc->size = strlen (res);
608 return retc;
609}
int wmi_reg_get_bin_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry binary value.

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_reg_get_bin_val(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_get_dword_val()

tree_cell * nasl_wmi_reg_get_dword_val ( lex_ctxt * lexic)

Get registry DWORD value.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure, else tree_cell containing string representation of DWORD value

Retrieves local variables "wmi_handle", "hive", "key", "val_name" from the lexical context, performs the registry operation querying DWORD value.

Definition at line 624 of file nasl_wmi.c.

625{
626 WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
627
628 if (!handle)
629 return NULL;
630
631 unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
632 char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
633 char *val_name =
634 get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
635
636 char *res = NULL;
637 int value;
638
640 retc->x.str_val = NULL;
641 retc->size = 0;
642
643 value = wmi_reg_get_dword_val (handle, hive, key, val_name, &res);
644
645 if ((value == 0) && (res == 0))
646 res = "0";
647
648 if ((value == -1) || (res == NULL))
649 {
650 g_message ("nasl_wmi_reg_get_dword_val: WMI query failed");
651 return NULL;
652 }
653
654 retc->x.str_val = strdup (res);
655 retc->size = strlen (res);
656 return retc;
657}
int wmi_reg_get_dword_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry DWORD value.

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_reg_get_dword_val(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_get_ex_string_val()

tree_cell * nasl_wmi_reg_get_ex_string_val ( lex_ctxt * lexic)

Get registry expanded string value.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure, else tree_cell containing string representation of Expanded String value

Retrieves local variables "wmi_handle", "hive", "key", "val_name" from the lexical context, performs the registry operation querying Expanded string value.

Definition at line 672 of file nasl_wmi.c.

673{
674 WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
675
676 if (!handle)
677 return NULL;
678
679 unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
680 char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
681 char *val_name =
682 get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
683
684 char *res = NULL;
685 int value;
686
688 retc->x.str_val = NULL;
689 retc->size = 0;
690
691 value = wmi_reg_get_ex_string_val (handle, hive, key, val_name, &res);
692
693 if ((value == -1) || (res == NULL))
694 {
695 g_message ("nasl_wmi_reg_get_ex_string_val: WMI query failed");
696 return NULL;
697 }
698
699 retc->x.str_val = strdup (res);
700 retc->size = strlen (res);
701 return retc;
702}
int wmi_reg_get_ex_string_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry Expanded string value.

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_reg_get_ex_string_val(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_get_mul_string_val()

tree_cell * nasl_wmi_reg_get_mul_string_val ( lex_ctxt * lexic)

Get registry multi valued strings.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure, else tree_cell containing string representation of multi valued strings

Retrieves local variables "wmi_handle", "hive", "key", "val_name" from the lexical context, performs the registry operation querying Expanded string value.

Definition at line 717 of file nasl_wmi.c.

718{
719 WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
720
721 if (!handle)
722 return NULL;
723
724 unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
725 char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
726 char *val_name =
727 get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
728
729 char *res = NULL;
730 int value;
731
733 retc->x.str_val = NULL;
734 retc->size = 0;
735
736 value = wmi_reg_get_mul_string_val (handle, hive, key, val_name, &res);
737
738 if ((value == -1) || (res == NULL))
739 {
740 g_message ("nasl_wmi_reg_get_mul_string_val: WMI query failed");
741 return NULL;
742 }
743
744 retc->x.str_val = strdup (res);
745 retc->size = strlen (res);
746 return retc;
747}
int wmi_reg_get_mul_string_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry multi-valued strings.

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_reg_get_mul_string_val(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_get_qword_val()

tree_cell * nasl_wmi_reg_get_qword_val ( lex_ctxt * lexic)

Get registry QWORD value.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure, else tree_cell containing string representation of QWORD value

Retrieves local variables "wmi_handle", "hive", "key", "val_name" from the lexical context, performs the registry operation querying 64-bit unsigned integer.

Definition at line 762 of file nasl_wmi.c.

763{
764 WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
765
766 if (!handle)
767 return NULL;
768
769 unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
770 char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
771 char *val_name =
772 get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
773
774 char *res = NULL;
775 int value;
776
778 retc->x.str_val = NULL;
779 retc->size = 0;
780
781 value = wmi_reg_get_qword_val (handle, hive, key, val_name, &res);
782
783 if ((value == -1) || (res == NULL))
784 {
785 g_message ("nasl_wmi_reg_get_qword_val: WMI query failed");
786 return NULL;
787 }
788
789 retc->x.str_val = strdup (res);
790 retc->size = strlen (res);
791 return retc;
792}
int wmi_reg_get_qword_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry QWORD value.

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_reg_get_qword_val(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_get_sz()

tree_cell * nasl_wmi_reg_get_sz ( lex_ctxt * lexic)

Get string value from Registry.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL if the query fails. Else a tree_cell with the Registry value.

Retrieves local variables "wmi_handle", "hive", "key", "key_name" from the lexical context, performs the registry query returning a string value.

Definition at line 448 of file nasl_wmi.c.

449{
450 WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
451
452 if (!handle)
453 return NULL;
454
455 unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
456 char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
457 char *key_name =
458 get_str_var_by_name (lexic, "key_name"); // REGISTRY value name
459
460 char *res = NULL;
461 int value;
463 retc->x.str_val = NULL;
464 retc->size = 0;
465
466 value = wmi_reg_get_sz (handle, hive, key, key_name, &res);
467
468 if ((value == -1) || (res == NULL))
469 {
470 g_message ("nasl_wmi_reg_get_sz: WMI Registry get failed");
471 return NULL;
472 }
473
474 retc->x.str_val = strdup (res);
475 retc->size = strlen (res);
476
477 return retc;
478}
int wmi_reg_get_sz(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry string value.

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_reg_get_sz(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_set_dword_val()

tree_cell * nasl_wmi_reg_set_dword_val ( lex_ctxt * lexic)

Set Registry DWORD value.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure

Retrieves local variables "wmi_handle", "key", "val_name", "val" from the lexical context, performs the registry set/create operation for double word data type.

It will work only if the key exist

Definition at line 808 of file nasl_wmi.c.

809{
810 WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
811
812 if (!handle)
813 return NULL;
814
815 char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
816 char *val_name =
817 get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
818 char *val = get_str_var_by_name (lexic, "val"); // REGISTRY VALUE TO SET
819
820 uint32_t val1;
821 int value;
822
823 // Return NULL if any alphabet is present
824 if (check_alpha (val) == 0)
825 return NULL;
826
827 // Convert string to proper 64 bit integer
828 val1 = stoi_uint32_t (val);
829
831 retc->x.i_val = 1;
832
833 value = wmi_reg_set_dword_val (handle, key, val_name, val1);
834
835 if (value == -1)
836 {
837 g_message ("nasl_wmi_reg_set_dword_val: WMI registry set"
838 " operation failed");
839 return NULL;
840 }
841 return retc;
842}
const char * val
Definition nasl_init.c:440
static int check_alpha(char *val)
Definition nasl_wmi.c:46
static uint32_t stoi_uint32_t(char *s)
Definition nasl_wmi.c:67
int wmi_reg_set_dword_val(WMI_HANDLE, const char *, const char *, uint32_t)
Set Registry DWORD value.

References alloc_typed_cell(), check_alpha(), CONST_INT, get_int_var_by_name(), get_str_var_by_name(), TC::i_val, stoi_uint32_t(), val, wmi_reg_set_dword_val(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_set_ex_string_val()

tree_cell * nasl_wmi_reg_set_ex_string_val ( lex_ctxt * lexic)

Set Registry Expanded string value.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure

Retrieves local variables "wmi_handle", "key", "val_name", "val" from the lexical context, performs the registry set/create operation for string value.

It will work only if the key exist

Definition at line 908 of file nasl_wmi.c.

909{
910 WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
911
912 if (!handle)
913 return NULL;
914
915 char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
916 char *val_name =
917 get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
918 char *val = get_str_var_by_name (lexic, "val"); // REGISTRY VALUE TO SET
919
920 int value;
921
923 retc->x.i_val = 1;
924
925 value = wmi_reg_set_ex_string_val (handle, key, val_name, val);
926
927 if (value == -1)
928 {
929 g_message (
930 "nasl_wmi_reg_set_ex_string_val: WMI registry set operation failed");
931 return NULL;
932 }
933 return retc;
934}
int wmi_reg_set_ex_string_val(WMI_HANDLE, const char *, const char *, const char *)
Set Registry Expanded string value.

References alloc_typed_cell(), CONST_INT, get_int_var_by_name(), get_str_var_by_name(), TC::i_val, val, wmi_reg_set_ex_string_val(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_set_qword_val()

tree_cell * nasl_wmi_reg_set_qword_val ( lex_ctxt * lexic)

Set Registry QWORD value.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure

Retrieves local variables "wmi_handle", "key", "val_name", "val" from the lexical context, performs the registry set/create operation for 64-bit unsigned integer.

It will work only if the key exist

Definition at line 858 of file nasl_wmi.c.

859{
860 WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
861
862 if (!handle)
863 return NULL;
864
865 char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
866 char *val_name =
867 get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
868 char *val = get_str_var_by_name (lexic, "val"); // REGISTRY VALUE TO SET
869
870 uint64_t val1;
871 int value;
872
873 // Return if alphabets present
874 if (check_alpha (val) == 0)
875 return NULL;
876
877 // Convert string to proper integer
878 val1 = stoi_uint64_t (val);
879
881 retc->x.i_val = 1;
882
883 value = wmi_reg_set_qword_val (handle, key, val_name, val1);
884
885 if (value == -1)
886 {
887 g_message ("nasl_wmi_reg_set_qword_val: WMI register"
888 " set operation failed");
889 return NULL;
890 }
891 return retc;
892}
static uint64_t stoi_uint64_t(char *s)
Definition nasl_wmi.c:78
int wmi_reg_set_qword_val(WMI_HANDLE, const char *, const char *, uint64_t)
Set Registry QWORD value.

References alloc_typed_cell(), check_alpha(), CONST_INT, get_int_var_by_name(), get_str_var_by_name(), TC::i_val, stoi_uint64_t(), val, wmi_reg_set_qword_val(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_set_string_val()

tree_cell * nasl_wmi_reg_set_string_val ( lex_ctxt * lexic)

Set Registry string value.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure

Retrieves local variables "wmi_handle", "key", "val_name", "val" from the lexical context, performs the registry set/create operation for string value.

It will work only if the key exist

Definition at line 950 of file nasl_wmi.c.

951{
952 WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
953
954 if (!handle)
955 return NULL;
956
957 char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
958 char *val_name =
959 get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
960 char *val = get_str_var_by_name (lexic, "val"); // REGISTRY VALUE TO SET
961
962 int value;
963
965 retc->x.i_val = 1;
966
967 value = wmi_reg_set_string_val (handle, key, val_name, val);
968
969 if (value == -1)
970 {
971 g_message ("nasl_wmi_reg_set_string_val: WMI registry"
972 " set operation failed");
973 return NULL;
974 }
975 return retc;
976}
int wmi_reg_set_string_val(WMI_HANDLE, const char *, const char *, const char *)
Set Registry string value.

References alloc_typed_cell(), CONST_INT, get_int_var_by_name(), get_str_var_by_name(), TC::i_val, val, wmi_reg_set_string_val(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_versioninfo()

tree_cell * nasl_wmi_versioninfo ( lex_ctxt * lexic)

Get a version string of the WMI implementation.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL in case no implementation is present. Else a tree_cell with the version as string.

Definition at line 94 of file nasl_wmi.c.

95{
96 char *version = wmi_versioninfo ();
97 tree_cell *retc;
98 (void) lexic;
99
100 if (!version)
101 return NULL;
102
104 retc->x.str_val = strdup (version);
105 retc->size = strlen (version);
106 return retc;
107}
char * wmi_versioninfo(void)
Return version info for WMI implementation.

References alloc_typed_cell(), CONST_DATA, TC::size, TC::str_val, wmi_versioninfo(), and TC::x.

Here is the call graph for this function: