Author: tridge
Date: 2005-08-08 22:29:44 +0000 (Mon, 08 Aug 2005)
New Revision: 9218

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=9218

Log:
make the winreg library code handle arbitrary paths more efficiently
and more conveniently (caller doesn't need to know the hive names now)


Modified:
   branches/SAMBA_4_0/source/scripting/libjs/winreg.js
   branches/SAMBA_4_0/testprogs/ejs/winreg.js


Changeset:
Modified: branches/SAMBA_4_0/source/scripting/libjs/winreg.js
===================================================================
--- branches/SAMBA_4_0/source/scripting/libjs/winreg.js 2005-08-08 22:14:40 UTC 
(rev 9217)
+++ branches/SAMBA_4_0/source/scripting/libjs/winreg.js 2005-08-08 22:29:44 UTC 
(rev 9218)
@@ -42,29 +42,48 @@
        var list = new Object();
 
        list.length = 0;
+
+       /* cope with a leading slash */
+       if (components[0] == '') {
+               for (i=0;i<(components.length-1);i++) {
+                       components[i] = components[i+1];
+               }
+               components.length--;
+       }
        
+       if (components.length == 0) {
+               return undefined;
+       }
+
        var handle = winreg_open_hive(reg, components[0]);
        if (handle == undefined) {
                return undefined;
        }
 
-       for (i=1;i<components.length;i++) {
-               io = irpcObj();
-               io.input.handle  = handle;
-               io.input.keyname = components[i];
-               io.input.unknown = 0;
-               io.input.access_mask = reg.SEC_FLAG_MAXIMUM_ALLOWED;
-               var status = reg.winreg_OpenKey(io);
-               if (!status.is_ok) {
-                       return undefined;
-               }
-               if (io.output.result != "WERR_OK") {
-                       return undefined;
-               }
+       if (components.length == 1) {
+               return handle;
+       }
 
-               handle = io.output.handle;
+       var hpath = components[1];
+
+       for (i=2;i<components.length;i++) {
+               hpath = hpath + "\\" + components[i];
        }
-       return handle;
+
+       io = irpcObj();
+       io.input.handle  = handle;
+       io.input.keyname = hpath;
+       io.input.unknown = 0;
+       io.input.access_mask = reg.SEC_FLAG_MAXIMUM_ALLOWED;
+       var status = reg.winreg_OpenKey(io);
+       if (!status.is_ok) {
+               return undefined;
+       }
+       if (io.output.result != "WERR_OK") {
+               return undefined;
+       }
+       
+       return io.output.handle;
 }
 
 /*
@@ -76,6 +95,10 @@
 {
        var list = new Object();
        list.length = 0;
+
+       if (path == null || path == "\\" || path == "") {
+               return new Array("HKLM", "HKU");
+       }
        
        handle = winreg_open_path(reg, path);
        if (handle == undefined) {
@@ -106,7 +129,6 @@
                if (out.result != "WERR_OK") {
                        return list;
                }
-
                list[list.length] = out.out_name.name;
                list.length++;
        }

Modified: branches/SAMBA_4_0/testprogs/ejs/winreg.js
===================================================================
--- branches/SAMBA_4_0/testprogs/ejs/winreg.js  2005-08-08 22:14:40 UTC (rev 
9217)
+++ branches/SAMBA_4_0/testprogs/ejs/winreg.js  2005-08-08 22:29:44 UTC (rev 
9218)
@@ -13,15 +13,15 @@
                "POPT_COMMON_SAMBA",
                "POPT_COMMON_CREDENTIALS");
 if (ok == false) {
-   println("Failed to parse options: " + options.ERROR);
-   return -1;
+       println("Failed to parse options: " + options.ERROR);
+       return -1;
 }
 
 libinclude("base.js");
 
-if (options.ARGV.length != 1) {
-   println("Usage: winreg.js <BINDING>");
-   return -1;
+if (options.ARGV.length < 1) {
+       println("Usage: winreg.js <BINDING>");
+       return -1;
 }
 var binding = options.ARGV[0];
 reg = winreg_init();
@@ -30,8 +30,8 @@
 print("Connecting to " + binding + "\n");
 status = reg.connect(binding);
 if (status.is_ok != true) {
-   print("Failed to connect to " + binding + " - " + status.errstr + "\n");
-   return -1;
+       print("Failed to connect to " + binding + " - " + status.errstr + "\n");
+       return -1;
 }
 
 function list_path(path) {
@@ -41,18 +41,25 @@
                return;
        }
        for (i=0;i<list.length;i++) {
-               var npath = path + "\\" + list[i];
+               var npath;
+               if (path) {
+                       npath = path + "\\" + list[i];
+               } else {
+                       npath = list[i];
+               }
                println(npath);
                list_path(npath);
        }
 }
 
-var trees = new Array("HKCR", "HKLM", "HKPD", "HKU");
+var root;
 
-for (i=0;i<trees.length;i++) {
-       printf("Listing tree '%s'\n", trees[i]);
-       list_path(trees[i]);
+if (options.ARGV.length > 1) {
+       root = options.ARGV[1];
+} else {
+       root = '';
 }
 
-print("All OK\n");
+printf("Listing registry tree '%s'\n", root);
+list_path(root);
 return 0;

Reply via email to