OpenVAS Libraries  9.0.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. More...
 
tree_cellnasl_wmi_connect (lex_ctxt *lexic)
 Connect to a WMI service and return a handle for it. More...
 
tree_cellnasl_wmi_close (lex_ctxt *lexic)
 Close WMI service handle. More...
 
tree_cellnasl_wmi_query (lex_ctxt *lexic)
 Perform WQL query. More...
 
tree_cellnasl_wmi_connect_rsop (lex_ctxt *lexic)
 Connect to a WMI RSOP service and return a handle for it. More...
 
tree_cellnasl_wmi_query_rsop (lex_ctxt *lexic)
 WMI RSOP query. More...
 
tree_cellnasl_wmi_connect_reg (lex_ctxt *lexic)
 Connect to a WMI Registry service and return a handle for it. More...
 
tree_cellnasl_wmi_reg_get_sz (lex_ctxt *lexic)
 Get string value from Registry. More...
 
tree_cellnasl_wmi_reg_enum_value (lex_ctxt *lexic)
 Enumerate registry values. More...
 
tree_cellnasl_wmi_reg_enum_key (lex_ctxt *lexic)
 Enumerate registry keys. More...
 
tree_cellnasl_wmi_reg_get_bin_val (lex_ctxt *lexic)
 Get registry binary value. More...
 
tree_cellnasl_wmi_reg_get_dword_val (lex_ctxt *lexic)
 Get registry DWORD value. More...
 
tree_cellnasl_wmi_reg_get_ex_string_val (lex_ctxt *lexic)
 Get registry expanded string value. More...
 
tree_cellnasl_wmi_reg_get_mul_string_val (lex_ctxt *lexic)
 Get registry multi valued strings. More...
 
tree_cellnasl_wmi_reg_get_qword_val (lex_ctxt *lexic)
 Get registry QWORD value. More...
 
tree_cellnasl_wmi_reg_set_dword_val (lex_ctxt *lexic)
 Set Registry DWORD value. More...
 
tree_cellnasl_wmi_reg_set_qword_val (lex_ctxt *lexic)
 Set Registry QWORD value. More...
 
tree_cellnasl_wmi_reg_set_ex_string_val (lex_ctxt *lexic)
 Set Registry Expanded string value. More...
 
tree_cellnasl_wmi_reg_set_string_val (lex_ctxt *lexic)
 Set Registry string value. More...
 
tree_cellnasl_wmi_reg_create_key (lex_ctxt *lexic)
 Create Registry key. More...
 
tree_cellnasl_wmi_reg_delete_key (lex_ctxt *lexic)
 Delete Registry key. More...
 

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 225 of file nasl_wmi.c.

226 {
227  WMI_HANDLE handle =
228  (WMI_HANDLE) get_int_local_var_by_name (lexic, "wmi_handle", 0);
229  if (!handle)
230  return NULL;
231 
232  tree_cell *retc = alloc_tree_cell (0, NULL);
233 
234  retc->type = CONST_INT;
235 
236  if (wmi_close (handle) == 0)
237  {
238  retc->x.i_val = 1;
239  return retc;
240  }
241  return NULL;
242 }
int wmi_close(WMI_HANDLE)
Close the connection handle for a WMI service.
short type
Definition: nasl_tree.h:107
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
union TC::@7 x
Definition: nasl_tree.h:105
void * WMI_HANDLE
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37

References alloc_tree_cell(), CONST_INT, get_int_local_var_by_name(), TC::i_val, TC::type, 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 148 of file nasl_wmi.c.

149 {
150  struct arglist *script_infos = lexic->script_infos;
151  struct in6_addr *host = plug_get_host_ip (script_infos);
152  char *ip;
153  IMPORT (username);
154  IMPORT (password);
155  IMPORT(ns);
156 
157  if (ns == NULL)
158  ns = "root\\cimv2";
159 
160  char *argv[max];
161 
162  WMI_HANDLE handle;
163  int argc = 5;
164  char *argv1 = "wmic";
165  char *argv2 = "-U";
166 
167  if ((host == NULL) || (username == NULL) || (password == NULL))
168  {
169  log_legacy_write ("nasl_wmi_connect: Invalid input arguments\n");
170  return NULL;
171  }
172 
173  ip = addr6_as_str (host);
174  if ((strlen (password) == 0) || (strlen (username) == 0)
175  || strlen (ip) == 0)
176  {
177  log_legacy_write ("nasl_wmi_connect: Invalid input arguments\n");
178  g_free (ip);
179  return NULL;
180  }
181 
182  argv[0] = (char *) g_malloc0 (strlen (argv1));
183  argv[1] = (char *) g_malloc0 (strlen (argv2));
184  argv[2] = (char *) g_malloc0 (strlen (username) + strlen (password) + 1);
185  argv[3] = (char *) g_malloc0 (strlen (ip) + 2);
186  argv[4] = (char *) g_malloc0 (strlen (ns));
187 
188  // Construct the WMI query
189  strcpy (argv[0], argv1);
190  strcpy (argv[1], "-U");
191  strcpy (argv[2], username);
192  strcat (argv[2], "%");
193  strcat (argv[2], password);
194  strcpy (argv[3], "//");
195  strcat (argv[3], ip);
196  strcpy (argv[4], ns);
197  g_free (ip);
198 
199  tree_cell *retc = alloc_tree_cell (0, NULL);
200 
201  retc->type = CONST_INT;
202  handle = wmi_connect (argc, argv);
203  if (!handle)
204  {
205  log_legacy_write ("nasl_wmi_connect: WMI Connect failed\n");
206  return NULL;
207  }
208 
209  retc->x.ref_val = handle;
210  return retc;
211 }
WMI_HANDLE wmi_connect(int argc, char **argv)
Establish connection to a WMI service.
short type
Definition: nasl_tree.h:107
#define max
Definition: nasl_wmi.c:61
void * ref_val
Definition: nasl_tree.h:115
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
union TC::@7 x
char * addr6_as_str(const struct in6_addr *addr6)
Definition: nasl_tree.h:105
struct in6_addr * plug_get_host_ip(struct arglist *desc)
Definition: plugutils.c:216
#define IMPORT(var)
Definition: nasl_wmi.c:60
void * WMI_HANDLE
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
struct arglist * script_infos
Definition: nasl_lex_ctxt.h:39

References addr6_as_str(), alloc_tree_cell(), CONST_INT, IMPORT, log_legacy_write(), max, plug_get_host_ip(), TC::ref_val, struct_lex_ctxt::script_infos, TC::type, 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 424 of file nasl_wmi.c.

425 {
426  struct arglist *script_infos = lexic->script_infos;
427  struct in6_addr *host = plug_get_host_ip (script_infos);
428  char *ip;
429  IMPORT (username);
430  IMPORT (password);
431  char *argv[4];
432 
433  WMI_HANDLE handle;
434  int argc = 4;
435  char *argv1 = "wmic";
436  char *argv2 = "-U";
437 
438  if ((host == NULL) || (username == NULL) || (password == NULL))
439  {
440  log_legacy_write ("nasl_wmi_connect_reg: Invalid input arguments\n");
441  return NULL;
442  }
443 
444  ip = addr6_as_str (host);
445  if ((strlen (password) == 0) || (strlen (username) == 0)
446  || strlen (ip) == 0)
447  {
448  log_legacy_write ("nasl_wmi_connect_reg: Invalid input arguments\n");
449  g_free (ip);
450  return NULL;
451  }
452 
453  argv[0] = (char *) g_malloc0 (strlen (argv1));
454  argv[1] = (char *) g_malloc0 (strlen (argv2));
455  argv[2] = (char *) g_malloc0 (strlen (username) + strlen (password) + 1);
456  argv[3] = (char *) g_malloc0 (strlen (ip) + 2);
457 
458  // Construct the WMI query
459  strcpy (argv[0], argv1);
460  strcpy (argv[1], "-U");
461  strcpy (argv[2], username);
462  strcat (argv[2], "%");
463  strcat (argv[2], password);
464  strcpy (argv[3], "//");
465  strcat (argv[3], ip);
466  g_free (ip);
467 
468  tree_cell *retc = alloc_tree_cell (0, NULL);
469 
470  retc->type = CONST_INT;
471  handle = wmi_connect_reg (argc, argv);
472  if (!handle)
473  {
474  log_legacy_write ("nasl_wmi_connect_reg: WMI Connect failed\n");
475  return NULL;
476  }
477 
478  retc->x.ref_val = handle;
479  return retc;
480 }
short type
Definition: nasl_tree.h:107
void * ref_val
Definition: nasl_tree.h:115
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
union TC::@7 x
WMI_HANDLE wmi_connect_reg(int argc, char **argv)
Establish connection to a WMI Registry service.
char * addr6_as_str(const struct in6_addr *addr6)
Definition: nasl_tree.h:105
struct in6_addr * plug_get_host_ip(struct arglist *desc)
Definition: plugutils.c:216
#define IMPORT(var)
Definition: nasl_wmi.c:60
void * WMI_HANDLE
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
struct arglist * script_infos
Definition: nasl_lex_ctxt.h:39

References addr6_as_str(), alloc_tree_cell(), CONST_INT, IMPORT, log_legacy_write(), plug_get_host_ip(), TC::ref_val, struct_lex_ctxt::script_infos, TC::type, 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 307 of file nasl_wmi.c.

308 {
309  struct arglist *script_infos = lexic->script_infos;
310  struct in6_addr *host = plug_get_host_ip (script_infos);
311  char *ip;
312  IMPORT (username);
313  IMPORT (password);
314  char *argv[4];
315 
316  WMI_HANDLE handle;
317  int argc = 4;
318  char *argv1 = "wmic";
319  char *argv2 = "-U";
320 
321  if ((host == NULL) || (username == NULL) || (password == NULL))
322  {
323  log_legacy_write ("nasl_wmi_connect_rsop: Invalid input arguments\n");
324  return NULL;
325  }
326 
327  ip = addr6_as_str (host);
328  if ((strlen (password) == 0) || (strlen (username) == 0)
329  || strlen (ip) == 0)
330  {
331  log_legacy_write ("nasl_wmi_connect_rsop: Invalid input arguments\n");
332  g_free (ip);
333  return NULL;
334  }
335 
336  argv[0] = (char *) g_malloc0 (strlen (argv1));
337  argv[1] = (char *) g_malloc0 (strlen (argv2));
338  argv[2] = (char *) g_malloc0 (strlen (username) + strlen (password) + 1);
339  argv[3] = (char *) g_malloc0 (strlen (ip) + 2);
340 
341  // Construct the WMI query
342  strcpy (argv[0], argv1);
343  strcpy (argv[1], "-U");
344  strcpy (argv[2], username);
345  strcat (argv[2], "%");
346  strcat (argv[2], password);
347  strcpy (argv[3], "//");
348  strcat (argv[3], ip);
349  g_free (ip);
350 
351  tree_cell *retc = alloc_tree_cell (0, NULL);
352 
353  retc->type = CONST_INT;
354  handle = wmi_connect_rsop (argc, argv);
355  if (!handle)
356  {
357  log_legacy_write ("nasl_wmi_connect_rsop: WMI Connect failed\n");
358  return NULL;
359  }
360 
361  retc->x.ref_val = handle;
362  return retc;
363 }
short type
Definition: nasl_tree.h:107
void * ref_val
Definition: nasl_tree.h:115
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
union TC::@7 x
char * addr6_as_str(const struct in6_addr *addr6)
Definition: nasl_tree.h:105
struct in6_addr * plug_get_host_ip(struct arglist *desc)
Definition: plugutils.c:216
#define IMPORT(var)
Definition: nasl_wmi.c:60
void * WMI_HANDLE
WMI_HANDLE wmi_connect_rsop(int argc, char **argv)
Establish connection to a WMI RSOP service.
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
struct arglist * script_infos
Definition: nasl_lex_ctxt.h:39

References addr6_as_str(), alloc_tree_cell(), CONST_INT, IMPORT, log_legacy_write(), plug_get_host_ip(), TC::ref_val, struct_lex_ctxt::script_infos, TC::type, 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 257 of file nasl_wmi.c.

258 {
259  WMI_HANDLE handle =
260  (WMI_HANDLE) get_int_local_var_by_name (lexic, "wmi_handle", 0);
261  char *query = get_str_local_var_by_name (lexic, "query");
262  char *res = NULL;
263  int value;
264 
265  if (!handle)
266  return NULL;
267 
268  tree_cell *retc = alloc_tree_cell (0, NULL);
269 
270  retc->type = CONST_DATA;
271  retc->x.str_val = NULL;
272  retc->size = 0;
273 
274  value = wmi_query (handle, query, &res);
275 
276  if ((value == -1) || (res == NULL))
277  {
278  log_legacy_write ("wmi_query: WMI query failed '%s'\n", query);
279  return NULL;
280  }
281 
282  retc->x.str_val = strdup (res);
283  retc->size = strlen (res);
284 
285  return retc;
286 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
int wmi_query(WMI_HANDLE, const char *, char **)
Query WMI service using a WQL query.
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
Definition: nasl_tree.h:105
void * WMI_HANDLE
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110

References alloc_tree_cell(), CONST_DATA, get_int_local_var_by_name(), get_str_local_var_by_name(), log_legacy_write(), TC::size, TC::str_val, TC::type, 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 377 of file nasl_wmi.c.

378 {
379  WMI_HANDLE handle =
380  (WMI_HANDLE) get_int_local_var_by_name (lexic, "wmi_handle", 0);
381  if (!handle)
382  return NULL;
383 
384  char *query = get_str_local_var_by_name (lexic, "query"); // WQL query
385  char *res = NULL;
386  int value;
387  tree_cell *retc = alloc_tree_cell (0, NULL);
388 
389  retc->type = CONST_DATA;
390  retc->x.str_val = NULL;
391  retc->size = 0;
392 
393  value = wmi_query_rsop (handle, query, &res);
394  if ((value == -1) || (res == NULL))
395  {
396  log_legacy_write ("wmi_query_rsop: WMI query failed\n");
397  return NULL;
398  }
399  retc->x.str_val = strdup (res);
400  retc->size = strlen (res);
401 
402  return retc;
403 }
int wmi_query_rsop(WMI_HANDLE, const char *, char **)
WMI RSOP query.
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
Definition: nasl_tree.h:105
void * WMI_HANDLE
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110

References alloc_tree_cell(), CONST_DATA, get_int_local_var_by_name(), get_str_local_var_by_name(), log_legacy_write(), TC::size, TC::str_val, TC::type, 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 1062 of file nasl_wmi.c.

1063 {
1064  WMI_HANDLE handle =
1065  (WMI_HANDLE) get_int_local_var_by_name (lexic, "wmi_handle", 0);
1066 
1067  if (!handle)
1068  return NULL;
1069 
1070  char *key = get_str_local_var_by_name (lexic, "key"); // REGISTRY KEY
1071 
1072  int value;
1073 
1074  tree_cell *retc = alloc_tree_cell (0, NULL);
1075 
1076  retc->type = CONST_INT;
1077  retc->x.i_val = 1;
1078 
1079  value = wmi_reg_create_key (handle, key);
1080 
1081  if (value == -1)
1082  {
1083  log_legacy_write ("nasl_wmi_reg_create_key: WMI registery key create"
1084  " operation failed\n");
1085  return NULL;
1086  }
1087  return retc;
1088 }
short type
Definition: nasl_tree.h:107
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
Definition: nasl_tree.h:105
void * WMI_HANDLE
int wmi_reg_create_key(WMI_HANDLE, const char *)
Create Registry Key.
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37

References alloc_tree_cell(), CONST_INT, get_int_local_var_by_name(), get_str_local_var_by_name(), TC::i_val, log_legacy_write(), TC::type, 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 1104 of file nasl_wmi.c.

1105 {
1106  WMI_HANDLE handle =
1107  (WMI_HANDLE) get_int_local_var_by_name (lexic, "wmi_handle", 0);
1108 
1109  if (!handle)
1110  return NULL;
1111 
1112  char *key = get_str_local_var_by_name (lexic, "key"); // REGISTRY KEY
1113 
1114  int value;
1115 
1116  tree_cell *retc = alloc_tree_cell (0, NULL);
1117 
1118  retc->type = CONST_INT;
1119  retc->x.i_val = 1;
1120 
1121  value = wmi_reg_delete_key (handle, key);
1122 
1123  if (value == -1)
1124  {
1125  log_legacy_write ("nasl_wmi_reg_delete_key: WMI registery key"
1126  " delete operation failed\n");
1127  return NULL;
1128  }
1129  return retc;
1130 }
int wmi_reg_delete_key(WMI_HANDLE, const char *)
Delete Registry Key.
short type
Definition: nasl_tree.h:107
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
Definition: nasl_tree.h:105
void * WMI_HANDLE
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37

References alloc_tree_cell(), CONST_INT, get_int_local_var_by_name(), get_str_local_var_by_name(), TC::i_val, log_legacy_write(), TC::type, 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 588 of file nasl_wmi.c.

589 {
590  WMI_HANDLE handle =
591  (WMI_HANDLE) get_int_local_var_by_name (lexic, "wmi_handle", 0);
592 
593  if (!handle)
594  return NULL;
595 
596  unsigned int hive = get_int_local_var_by_name (lexic, "hive", 0); // REGISTRY Hive
597  char *key = get_str_local_var_by_name (lexic, "key"); // REGISTRY KEY
598 
599  char *res = NULL;
600  int value;
601  tree_cell *retc = alloc_tree_cell (0, NULL);
602 
603  retc->type = CONST_DATA;
604  retc->x.str_val = NULL;
605  retc->size = 0;
606 
607  value = wmi_reg_enum_key (handle, hive, key, &res);
608 
609  if ((value == -1) || (res == NULL))
610  {
611  log_legacy_write ("nasl_wmi_reg_enum_key: WMI query failed\n");
612  return NULL;
613  }
614 
615  retc->x.str_val = strdup (res);
616  retc->size = strlen (res);
617 
618  return retc;
619 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
int wmi_reg_enum_key(WMI_HANDLE, unsigned int, const char *, char **)
Enumerate Registry keys.
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
Definition: nasl_tree.h:105
void * WMI_HANDLE
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110

References alloc_tree_cell(), CONST_DATA, get_int_local_var_by_name(), get_str_local_var_by_name(), log_legacy_write(), TC::size, TC::str_val, TC::type, 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 542 of file nasl_wmi.c.

543 {
544  WMI_HANDLE handle =
545  (WMI_HANDLE) get_int_local_var_by_name (lexic, "wmi_handle", 0);
546 
547  if (!handle)
548  return NULL;
549 
550  unsigned int hive = get_int_local_var_by_name (lexic, "hive", 0); // REGISTRY Hive
551  char *key = get_str_local_var_by_name (lexic, "key"); // REGISTRY KEY
552 
553  char *res = NULL;
554  int value;
555  tree_cell *retc = alloc_tree_cell (0, NULL);
556 
557  retc->type = CONST_DATA;
558  retc->x.str_val = NULL;
559  retc->size = 0;
560 
561  value = wmi_reg_enum_value (handle, hive, key, &res);
562 
563  if ((value == -1) || (res == NULL))
564  {
565  log_legacy_write ("nasl_wmi_reg_enum_value: WMI query failed\n");
566  return NULL;
567  }
568 
569  retc->x.str_val = strdup (res);
570  retc->size = strlen (res);
571 
572  return retc;
573 }
short type
Definition: nasl_tree.h:107
int wmi_reg_enum_value(WMI_HANDLE, unsigned int, const char *, char **)
Enumerate Registry values.
char * str_val
Definition: nasl_tree.h:113
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
Definition: nasl_tree.h:105
void * WMI_HANDLE
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110

References alloc_tree_cell(), CONST_DATA, get_int_local_var_by_name(), get_str_local_var_by_name(), log_legacy_write(), TC::size, TC::str_val, TC::type, 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 634 of file nasl_wmi.c.

635 {
636  WMI_HANDLE handle =
637  (WMI_HANDLE) get_int_local_var_by_name (lexic, "wmi_handle", 0);
638 
639  if (!handle)
640  return NULL;
641 
642  unsigned int hive = get_int_local_var_by_name (lexic, "hive", 0); // REGISTRY Hive
643  char *key = get_str_local_var_by_name (lexic, "key"); // REGISTRY KEY
644  char *val_name = get_str_local_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
645 
646  char *res = NULL;
647  int value;
648 
649  tree_cell *retc = alloc_tree_cell (0, NULL);
650 
651  retc->type = CONST_DATA;
652  retc->x.str_val = NULL;
653  retc->size = 0;
654 
655  value = wmi_reg_get_bin_val (handle, hive, key, val_name, &res);
656 
657  if ((value == -1) || (res == NULL))
658  {
659  log_legacy_write ("nasl_wmi_reg_get_bin_val: WMI query failed\n");
660  return NULL;
661  }
662 
663  retc->x.str_val = strdup (res);
664  retc->size = strlen (res);
665  return retc;
666 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
int wmi_reg_get_bin_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry binary value.
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
Definition: nasl_tree.h:105
void * WMI_HANDLE
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110

References alloc_tree_cell(), CONST_DATA, get_int_local_var_by_name(), get_str_local_var_by_name(), log_legacy_write(), TC::size, TC::str_val, TC::type, 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 681 of file nasl_wmi.c.

682 {
683  WMI_HANDLE handle =
684  (WMI_HANDLE) get_int_local_var_by_name (lexic, "wmi_handle", 0);
685 
686  if (!handle)
687  return NULL;
688 
689  unsigned int hive = get_int_local_var_by_name (lexic, "hive", 0); // REGISTRY Hive
690  char *key = get_str_local_var_by_name (lexic, "key"); // REGISTRY KEY
691  char *val_name = get_str_local_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
692 
693  char *res = NULL;
694  int value;
695 
696  tree_cell *retc = alloc_tree_cell (0, NULL);
697 
698  retc->type = CONST_DATA;
699  retc->x.str_val = NULL;
700  retc->size = 0;
701 
702  value = wmi_reg_get_dword_val (handle, hive, key, val_name, &res);
703 
704  if ((value == 0) && (res == 0))
705  res = "0";
706 
707  if ((value == -1) || (res == NULL))
708  {
709  log_legacy_write ("nasl_wmi_reg_get_dword_val: WMI query failed\n");
710  return NULL;
711  }
712 
713  retc->x.str_val = strdup (res);
714  retc->size = strlen (res);
715  return retc;
716 }
short type
Definition: nasl_tree.h:107
int wmi_reg_get_dword_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry DWORD value.
char * str_val
Definition: nasl_tree.h:113
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
Definition: nasl_tree.h:105
void * WMI_HANDLE
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110

References alloc_tree_cell(), CONST_DATA, get_int_local_var_by_name(), get_str_local_var_by_name(), log_legacy_write(), TC::size, TC::str_val, TC::type, 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 731 of file nasl_wmi.c.

732 {
733  WMI_HANDLE handle =
734  (WMI_HANDLE) get_int_local_var_by_name (lexic, "wmi_handle", 0);
735 
736  if (!handle)
737  return NULL;
738 
739  unsigned int hive = get_int_local_var_by_name (lexic, "hive", 0); // REGISTRY Hive
740  char *key = get_str_local_var_by_name (lexic, "key"); // REGISTRY KEY
741  char *val_name = get_str_local_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
742 
743  char *res = NULL;
744  int value;
745 
746  tree_cell *retc = alloc_tree_cell (0, NULL);
747 
748  retc->type = CONST_DATA;
749  retc->x.str_val = NULL;
750  retc->size = 0;
751 
752  value = wmi_reg_get_ex_string_val (handle, hive, key, val_name, &res);
753 
754  if ((value == -1) || (res == NULL))
755  {
756  log_legacy_write ("nasl_wmi_reg_get_ex_string_val: WMI query failed\n");
757  return NULL;
758  }
759 
760  retc->x.str_val = strdup (res);
761  retc->size = strlen (res);
762  return retc;
763 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
Definition: nasl_tree.h:105
int wmi_reg_get_ex_string_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry Expanded string value.
void * WMI_HANDLE
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110

References alloc_tree_cell(), CONST_DATA, get_int_local_var_by_name(), get_str_local_var_by_name(), log_legacy_write(), TC::size, TC::str_val, TC::type, 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 778 of file nasl_wmi.c.

779 {
780  WMI_HANDLE handle =
781  (WMI_HANDLE) get_int_local_var_by_name (lexic, "wmi_handle", 0);
782 
783  if (!handle)
784  return NULL;
785 
786  unsigned int hive = get_int_local_var_by_name (lexic, "hive", 0); // REGISTRY Hive
787  char *key = get_str_local_var_by_name (lexic, "key"); // REGISTRY KEY
788  char *val_name = get_str_local_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
789 
790  char *res = NULL;
791  int value;
792 
793  tree_cell *retc = alloc_tree_cell (0, NULL);
794 
795  retc->type = CONST_DATA;
796  retc->x.str_val = NULL;
797  retc->size = 0;
798 
799  value = wmi_reg_get_mul_string_val (handle, hive, key, val_name, &res);
800 
801  if ((value == -1) || (res == NULL))
802  {
803  log_legacy_write ("nasl_wmi_reg_get_mul_string_val: WMI query failed\n");
804  return NULL;
805  }
806 
807  retc->x.str_val = strdup (res);
808  retc->size = strlen (res);
809  return retc;
810 }
int wmi_reg_get_mul_string_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry multi-valued strings.
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
Definition: nasl_tree.h:105
void * WMI_HANDLE
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110

References alloc_tree_cell(), CONST_DATA, get_int_local_var_by_name(), get_str_local_var_by_name(), log_legacy_write(), TC::size, TC::str_val, TC::type, 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 825 of file nasl_wmi.c.

826 {
827  WMI_HANDLE handle =
828  (WMI_HANDLE) get_int_local_var_by_name (lexic, "wmi_handle", 0);
829 
830  if (!handle)
831  return NULL;
832 
833  unsigned int hive = get_int_local_var_by_name (lexic, "hive", 0); // REGISTRY Hive
834  char *key = get_str_local_var_by_name (lexic, "key"); // REGISTRY KEY
835  char *val_name = get_str_local_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
836 
837  char *res = NULL;
838  int value;
839 
840  tree_cell *retc = alloc_tree_cell (0, NULL);
841 
842  retc->type = CONST_DATA;
843  retc->x.str_val = NULL;
844  retc->size = 0;
845 
846  value = wmi_reg_get_qword_val (handle, hive, key, val_name, &res);
847 
848  if ((value == -1) || (res == NULL))
849  {
850  log_legacy_write ("nasl_wmi_reg_get_qword_val: WMI query failed\n");
851  return NULL;
852  }
853 
854  retc->x.str_val = strdup (res);
855  retc->size = strlen (res);
856  return retc;
857 }
int wmi_reg_get_qword_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry QWORD value.
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
Definition: nasl_tree.h:105
void * WMI_HANDLE
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110

References alloc_tree_cell(), CONST_DATA, get_int_local_var_by_name(), get_str_local_var_by_name(), log_legacy_write(), TC::size, TC::str_val, TC::type, 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 495 of file nasl_wmi.c.

496 {
497  WMI_HANDLE handle =
498  (WMI_HANDLE) get_int_local_var_by_name (lexic, "wmi_handle", 0);
499 
500  if (!handle)
501  return NULL;
502 
503  unsigned int hive = get_int_local_var_by_name (lexic, "hive", 0); // REGISTRY Hive
504  char *key = get_str_local_var_by_name (lexic, "key"); // REGISTRY KEY
505  char *key_name = get_str_local_var_by_name (lexic, "key_name"); // REGISTRY value name
506 
507  char *res = NULL;
508  int value;
509  tree_cell *retc = alloc_tree_cell (0, NULL);
510 
511  retc->type = CONST_DATA;
512  retc->x.str_val = NULL;
513  retc->size = 0;
514 
515  value = wmi_reg_get_sz (handle, hive, key, key_name, &res);
516 
517  if ((value == -1) || (res == NULL))
518  {
519  log_legacy_write ("nasl_wmi_reg_get_sz: WMI Registry get failed\n");
520  return NULL;
521  }
522 
523  retc->x.str_val = strdup (res);
524  retc->size = strlen (res);
525 
526  return retc;
527 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
int wmi_reg_get_sz(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry string value.
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
Definition: nasl_tree.h:105
void * WMI_HANDLE
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110

References alloc_tree_cell(), CONST_DATA, get_int_local_var_by_name(), get_str_local_var_by_name(), log_legacy_write(), TC::size, TC::str_val, TC::type, 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 873 of file nasl_wmi.c.

874 {
875  WMI_HANDLE handle =
876  (WMI_HANDLE) get_int_local_var_by_name (lexic, "wmi_handle", 0);
877 
878  if (!handle)
879  return NULL;
880 
881  char *key = get_str_local_var_by_name (lexic, "key"); // REGISTRY KEY
882  char *val_name = get_str_local_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
883  char *val = get_str_local_var_by_name (lexic, "val"); //REGISTERY VALUE TO SET
884 
885  uint32_t val1;
886  int value;
887 
888  // Return NULL if any alphabet is present
889  if (check_alpha(val) == 0)
890  return NULL;
891 
892  // Convert string to proper 64 bit integer
893  val1 = stoi_uint32_t(val);
894 
895  tree_cell *retc = alloc_tree_cell (0, NULL);
896 
897  retc->type = CONST_INT;
898  retc->x.i_val = 1;
899 
900  value = wmi_reg_set_dword_val (handle, key, val_name, val1);
901 
902  if (value == -1)
903  {
904  log_legacy_write ("nasl_wmi_reg_set_dword_val: WMI registry set"
905  " operation failed\n");
906  return NULL;
907  }
908  return retc;
909 }
const char * val
Definition: nasl_init.c:525
short type
Definition: nasl_tree.h:107
int wmi_reg_set_dword_val(WMI_HANDLE, const char *, const char *, uint32_t)
Set Registry DWORD value.
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
uint32_t stoi_uint32_t(char *s)
Definition: nasl_wmi.c:86
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
Definition: nasl_tree.h:105
int check_alpha(char *val)
Definition: nasl_wmi.c:66
void * WMI_HANDLE
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37

References alloc_tree_cell(), check_alpha(), CONST_INT, get_int_local_var_by_name(), get_str_local_var_by_name(), TC::i_val, log_legacy_write(), stoi_uint32_t(), TC::type, 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 977 of file nasl_wmi.c.

978 {
979  WMI_HANDLE handle =
980  (WMI_HANDLE) get_int_local_var_by_name (lexic, "wmi_handle", 0);
981 
982  if (!handle)
983  return NULL;
984 
985  char *key = get_str_local_var_by_name (lexic, "key"); // REGISTRY KEY
986  char *val_name = get_str_local_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
987  char *val = get_str_local_var_by_name (lexic, "val"); //REGISTERY VALUE TO SET
988 
989  int value;
990 
991  tree_cell *retc = alloc_tree_cell (0, NULL);
992 
993  retc->type = CONST_INT;
994  retc->x.i_val = 1;
995 
996  value = wmi_reg_set_ex_string_val (handle, key, val_name, val);
997 
998  if (value == -1)
999  {
1000  log_legacy_write ("nasl_wmi_reg_set_ex_string_val: WMI registery set operation failed\n");
1001  return NULL;
1002  }
1003  return retc;
1004 }
const char * val
Definition: nasl_init.c:525
int wmi_reg_set_ex_string_val(WMI_HANDLE, const char *, const char *, const char *)
Set Registry Expanded string value.
short type
Definition: nasl_tree.h:107
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
Definition: nasl_tree.h:105
void * WMI_HANDLE
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37

References alloc_tree_cell(), CONST_INT, get_int_local_var_by_name(), get_str_local_var_by_name(), TC::i_val, log_legacy_write(), TC::type, 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 925 of file nasl_wmi.c.

926 {
927  WMI_HANDLE handle =
928  (WMI_HANDLE) get_int_local_var_by_name (lexic, "wmi_handle", 0);
929 
930  if (!handle)
931  return NULL;
932 
933  char *key = get_str_local_var_by_name (lexic, "key"); // REGISTRY KEY
934  char *val_name = get_str_local_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
935  char *val = get_str_local_var_by_name (lexic, "val"); //REGISTERY VALUE TO SET
936 
937  uint64_t val1;
938  int value;
939 
940  // Return if alphabets present
941  if (check_alpha(val) == 0)
942  return NULL;
943 
944  // Convert string to proper integer
945  val1 = stoi_uint64_t(val);
946 
947  tree_cell *retc = alloc_tree_cell (0, NULL);
948 
949  retc->type = CONST_INT;
950  retc->x.i_val = 1;
951 
952  value = wmi_reg_set_qword_val (handle, key, val_name, val1);
953 
954  if (value == -1)
955  {
956  log_legacy_write ("nasl_wmi_reg_set_qword_val: WMI register"
957  " set operation failed\n");
958  return NULL;
959  }
960  return retc;
961 }
const char * val
Definition: nasl_init.c:525
short type
Definition: nasl_tree.h:107
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
uint64_t stoi_uint64_t(char *s)
Definition: nasl_wmi.c:96
Definition: nasl_tree.h:105
int wmi_reg_set_qword_val(WMI_HANDLE, const char *, const char *, uint64_t)
Set Registry QWORD value.
int check_alpha(char *val)
Definition: nasl_wmi.c:66
void * WMI_HANDLE
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37

References alloc_tree_cell(), check_alpha(), CONST_INT, get_int_local_var_by_name(), get_str_local_var_by_name(), TC::i_val, log_legacy_write(), stoi_uint64_t(), TC::type, 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 1020 of file nasl_wmi.c.

1021 {
1022  WMI_HANDLE handle =
1023  (WMI_HANDLE) get_int_local_var_by_name (lexic, "wmi_handle", 0);
1024 
1025  if (!handle)
1026  return NULL;
1027 
1028  char *key = get_str_local_var_by_name (lexic, "key"); // REGISTRY KEY
1029  char *val_name = get_str_local_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
1030  char *val = get_str_local_var_by_name (lexic, "val"); //REGISTERY VALUE TO SET
1031 
1032  int value;
1033 
1034  tree_cell *retc = alloc_tree_cell (0, NULL);
1035 
1036  retc->type = CONST_INT;
1037  retc->x.i_val = 1;
1038 
1039  value = wmi_reg_set_string_val (handle, key, val_name, val);
1040 
1041  if (value == -1)
1042  {
1043  log_legacy_write ("nasl_wmi_reg_set_string_val: WMI registery"
1044  " set operation failed\n");
1045  return NULL;
1046  }
1047  return retc;
1048 }
const char * val
Definition: nasl_init.c:525
short type
Definition: nasl_tree.h:107
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
char * get_str_local_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1262
union TC::@7 x
Definition: nasl_tree.h:105
void * WMI_HANDLE
long int i_val
Definition: nasl_tree.h:114
int wmi_reg_set_string_val(WMI_HANDLE, const char *, const char *, const char *)
Set Registry string value.
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37

References alloc_tree_cell(), CONST_INT, get_int_local_var_by_name(), get_str_local_var_by_name(), TC::i_val, log_legacy_write(), TC::type, 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 112 of file nasl_wmi.c.

113 {
114  char *version = wmi_versioninfo ();
115  tree_cell *retc = alloc_tree_cell (0, NULL);
116 
117  if (!version)
118  {
119  return NULL;
120  }
121 
122  retc->type = CONST_DATA;
123  retc->x.str_val = strdup (version);
124  retc->size = strlen (version);
125 
126  return retc;
127 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
union TC::@7 x
Definition: nasl_tree.h:105
char * wmi_versioninfo(void)
Return version info for WMI implementation.
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110

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

Here is the call graph for this function: