r9218: make the winreg library code handle arbitrary paths more efficiently
[kai/samba.git] / testprogs / ejs / winreg.js
1 #!/usr/bin/env smbscript
2 /*
3   test winreg calls from ejs
4 */      
5
6 libinclude("base.js");
7 libinclude("winreg.js");
8
9 var options = new Object();
10
11 ok = GetOptions(ARGV, options,
12                 "POPT_AUTOHELP",
13                 "POPT_COMMON_SAMBA",
14                 "POPT_COMMON_CREDENTIALS");
15 if (ok == false) {
16         println("Failed to parse options: " + options.ERROR);
17         return -1;
18 }
19
20 libinclude("base.js");
21
22 if (options.ARGV.length < 1) {
23         println("Usage: winreg.js <BINDING>");
24         return -1;
25 }
26 var binding = options.ARGV[0];
27 reg = winreg_init();
28 security_init(reg);
29
30 print("Connecting to " + binding + "\n");
31 status = reg.connect(binding);
32 if (status.is_ok != true) {
33         print("Failed to connect to " + binding + " - " + status.errstr + "\n");
34         return -1;
35 }
36
37 function list_path(path) {
38         var list = winreg_enum_path(reg, path);
39         var i;
40         if (list == undefined) {
41                 return;
42         }
43         for (i=0;i<list.length;i++) {
44                 var npath;
45                 if (path) {
46                         npath = path + "\\" + list[i];
47                 } else {
48                         npath = list[i];
49                 }
50                 println(npath);
51                 list_path(npath);
52         }
53 }
54
55 var root;
56
57 if (options.ARGV.length > 1) {
58         root = options.ARGV[1];
59 } else {
60         root = '';
61 }
62
63 printf("Listing registry tree '%s'\n", root);
64 list_path(root);
65 return 0;