OpenVAS Libraries  9.0.3
nasl_wmi.c
Go to the documentation of this file.
1 /* OpenVAS
2  *
3  * $Id$
4  * Description: NASL API implementation for WMI support
5  *
6  * Authors:
7  * Chandrashekhar B <bchandra@secpod.com>
8  *
9  * Copyright:
10  * Copyright (c) 2009 Greenbone Networks GmbH, http://www.greenbone.net
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25  */
26 
47 #include <string.h>
48 #include <stdio.h>
49 #include <netinet/in.h>
50 #include <sys/socket.h>
51 #include <arpa/inet.h>
52 #include <ctype.h>
53 #include <inttypes.h>
54 
55 #include "../misc/plugutils.h"
56 #include "nasl_wmi.h"
57 #include "openvas_wmi_interface.h"
58 #include "../misc/openvas_logging.h"
59 
60 #define IMPORT(var) char *var = get_str_local_var_by_name(lexic, #var)
61 #define max 5
62 
66 int check_alpha(char *val)
67 {
68  int i, val_len;
69  val_len = strlen(val);
70 
71  if((strcmp(val,"-1")) != 0 )
72  {
73  for(i = 0; i < val_len; i++)
74  if(!isdigit(val[i]))
75  return 0;
76  }
77  else
78  return 0;
79 
80  return 1;
81 }
82 
86 uint32_t stoi_uint32_t(char * s)
87 {
88  uint32_t v;
89  sscanf(s, "%" PRIu32, &v);
90  return v;
91 }
92 
96 uint64_t stoi_uint64_t(char * s)
97 {
98  uint64_t v;
99  sscanf(s, "%" PRIu64, &v);
100  return v;
101 }
102 
111 tree_cell *
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 }
128 
129 /*
130 ################################################################################
131  WMI_FUNCTIONS
132 ################################################################################
133 */
134 
147 tree_cell *
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 }
212 
224 tree_cell *
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 }
243 
256 tree_cell *
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 }
287 
288 /*
289 ################################################################################
290  WMI_RSOP_FUNCTIONS
291 ################################################################################
292 */
293 
306 tree_cell *
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 }
364 
376 tree_cell *
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 }
404 
405 /*
406 ################################################################################
407  WMI_REGISTRY_FUNCTIONS
408 ################################################################################
409 */
410 
423 tree_cell *
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 }
481 
494 tree_cell *
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 }
528 
541 tree_cell *
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 }
574 
587 tree_cell *
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 }
620 
633 tree_cell *
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 }
667 
680 tree_cell *
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 }
717 
730 tree_cell *
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 }
764 
777 tree_cell *
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 }
811 
824 tree_cell *
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 }
858 
872 tree_cell *
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 }
910 
924 tree_cell *
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 }
962 
976 tree_cell *
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 }
1005 
1019 tree_cell *
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 }
1049 
1061 tree_cell *
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 }
1089 
1103 tree_cell *
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_get_qword_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry QWORD value.
int wmi_close(WMI_HANDLE)
Close the connection handle for a WMI service.
int wmi_query_rsop(WMI_HANDLE, const char *, char **)
WMI RSOP query.
tree_cell * nasl_wmi_reg_set_string_val(lex_ctxt *lexic)
Set Registry string value.
Definition: nasl_wmi.c:1020
const char * val
Definition: nasl_init.c:525
tree_cell * nasl_wmi_reg_set_qword_val(lex_ctxt *lexic)
Set Registry QWORD value.
Definition: nasl_wmi.c:925
int wmi_reg_get_mul_string_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry multi-valued strings.
int wmi_reg_delete_key(WMI_HANDLE, const char *)
Delete Registry Key.
int wmi_reg_set_ex_string_val(WMI_HANDLE, const char *, const char *, const char *)
Set Registry Expanded string value.
WMI_HANDLE wmi_connect(int argc, char **argv)
Establish connection to a WMI service.
tree_cell * nasl_wmi_connect(lex_ctxt *lexic)
Connect to a WMI service and return a handle for it.
Definition: nasl_wmi.c:148
short type
Definition: nasl_tree.h:107
#define max
Definition: nasl_wmi.c:61
int wmi_reg_get_dword_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry DWORD value.
tree_cell * nasl_wmi_query_rsop(lex_ctxt *lexic)
WMI RSOP query.
Definition: nasl_wmi.c:377
int wmi_reg_enum_value(WMI_HANDLE, unsigned int, const char *, char **)
Enumerate Registry values.
char * str_val
Definition: nasl_tree.h:113
tree_cell * nasl_wmi_reg_get_dword_val(lex_ctxt *lexic)
Get registry DWORD value.
Definition: nasl_wmi.c:681
int wmi_reg_enum_key(WMI_HANDLE, unsigned int, const char *, char **)
Enumerate Registry keys.
tree_cell * nasl_wmi_reg_get_ex_string_val(lex_ctxt *lexic)
Get registry expanded string value.
Definition: nasl_wmi.c:731
int wmi_reg_set_dword_val(WMI_HANDLE, const char *, const char *, uint32_t)
Set Registry DWORD value.
int wmi_reg_get_bin_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry binary value.
void * ref_val
Definition: nasl_tree.h:115
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
tree_cell * nasl_wmi_reg_get_bin_val(lex_ctxt *lexic)
Get registry binary value.
Definition: nasl_wmi.c:634
int wmi_query(WMI_HANDLE, const char *, char **)
Query WMI service using a WQL query.
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
tree_cell * nasl_wmi_reg_set_ex_string_val(lex_ctxt *lexic)
Set Registry Expanded string value.
Definition: nasl_wmi.c:977
tree_cell * nasl_wmi_reg_get_qword_val(lex_ctxt *lexic)
Get registry QWORD value.
Definition: nasl_wmi.c:825
uint64_t stoi_uint64_t(char *s)
Definition: nasl_wmi.c:96
tree_cell * nasl_wmi_connect_rsop(lex_ctxt *lexic)
Connect to a WMI RSOP service and return a handle for it.
Definition: nasl_wmi.c:307
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)
tree_cell * nasl_wmi_close(lex_ctxt *lexic)
Close WMI service handle.
Definition: nasl_wmi.c:225
Definition: nasl_tree.h:105
Protos for NASL WMI API.
int wmi_reg_set_qword_val(WMI_HANDLE, const char *, const char *, uint64_t)
Set Registry QWORD value.
tree_cell * nasl_wmi_reg_set_dword_val(lex_ctxt *lexic)
Set Registry DWORD value.
Definition: nasl_wmi.c:873
int wmi_reg_get_ex_string_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry Expanded string value.
struct in6_addr * plug_get_host_ip(struct arglist *desc)
Definition: plugutils.c:216
#define IMPORT(var)
Definition: nasl_wmi.c:60
int check_alpha(char *val)
Definition: nasl_wmi.c:66
void * WMI_HANDLE
tree_cell * nasl_wmi_reg_delete_key(lex_ctxt *lexic)
Delete Registry key.
Definition: nasl_wmi.c:1104
tree_cell * nasl_wmi_reg_enum_key(lex_ctxt *lexic)
Enumerate registry keys.
Definition: nasl_wmi.c:588
int wmi_reg_create_key(WMI_HANDLE, const char *)
Create Registry Key.
long int i_val
Definition: nasl_tree.h:114
WMI_HANDLE wmi_connect_rsop(int argc, char **argv)
Establish connection to a WMI RSOP service.
char * wmi_versioninfo(void)
Return version info for WMI implementation.
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
tree_cell * nasl_wmi_reg_get_sz(lex_ctxt *lexic)
Get string value from Registry.
Definition: nasl_wmi.c:495
tree_cell * nasl_wmi_connect_reg(lex_ctxt *lexic)
Connect to a WMI Registry service and return a handle for it.
Definition: nasl_wmi.c:424
struct arglist * script_infos
Definition: nasl_lex_ctxt.h:39
tree_cell * nasl_wmi_reg_create_key(lex_ctxt *lexic)
Create Registry key.
Definition: nasl_wmi.c:1062
tree_cell * nasl_wmi_versioninfo(lex_ctxt *lexic)
Get a version string of the WMI implementation.
Definition: nasl_wmi.c:112
tree_cell * nasl_wmi_query(lex_ctxt *lexic)
Perform WQL query.
Definition: nasl_wmi.c:257
tree_cell * nasl_wmi_reg_get_mul_string_val(lex_ctxt *lexic)
Get registry multi valued strings.
Definition: nasl_wmi.c:778
API protos describing the interface of a wmi interface implementation.
tree_cell * nasl_wmi_reg_enum_value(lex_ctxt *lexic)
Enumerate registry values.
Definition: nasl_wmi.c:542
int size
Definition: nasl_tree.h:110