2 winreg rpc utility functions
3 Copyright Andrew Tridgell 2005
4 released under the GNU GPL v2 or later
12 function __winreg_close(handle)
15 io.input.handle = handle;
16 this.winreg_CloseKey(io);
23 function __winreg_open_hive(hive)
26 io.input.system_name = NULL;
27 io.input.access_required = this.SEC_FLAG_MAXIMUM_ALLOWED;
30 status = this.winreg_OpenHKLM(io);
31 } else if (hive == "HKCR") {
32 status = this.winreg_OpenHKCR(io);
33 } else if (hive == "HKPD") {
34 status = this.winreg_OpenHKPD(io);
35 } else if (hive == "HKU") {
36 status = this.winreg_OpenHKU(io);
38 println("Unknown hive " + hive);
44 return io.output.handle;
48 open a handle to a path
50 function __winreg_open_path(path)
52 var s = string_init();
53 var i, components = s.split('\\', path);
54 var list = new Object();
58 /* cope with a leading slash */
59 if (components[0] == '') {
60 for (i=0;i<(components.length-1);i++) {
61 components[i] = components[i+1];
66 if (components.length == 0) {
70 var handle = this.open_hive(components[0]);
71 if (handle == undefined) {
75 if (components.length == 1) {
79 var hpath = components[1];
81 for (i=2;i<components.length;i++) {
82 hpath = hpath + "\\" + components[i];
86 io.input.handle = handle;
87 io.input.keyname = hpath;
89 io.input.access_mask = this.SEC_FLAG_MAXIMUM_ALLOWED;
90 var status = this.winreg_OpenKey(io);
97 if (io.output.result != "WERR_OK") {
101 return io.output.handle;
105 return a list of keys for a winreg server given a path
107 list = reg.enum_path(path);
109 function __winreg_enum_path(path)
111 var list = new Object();
114 if (path == null || path == "\\" || path == "") {
115 return new Array("HKLM", "HKU");
118 var handle = this.open_path(path);
119 if (handle == undefined) {
124 io.input.handle = handle;
125 io.input.name = new Object();
126 io.input.name.length = 0;
127 io.input.name.size = 32;
128 io.input.name.name = NULL;
129 io.input.class = new Object();
130 io.input.class.length = 0;
131 io.input.class.size = 1024;
132 io.input.class.name = NULL;
133 io.input.last_changed_time = 0;
136 for (idx=0;idx >= 0;idx++) {
137 io.input.enum_index = idx;
138 var status = this.winreg_EnumKey(io);
144 if (out.result == "WERR_MORE_DATA") {
145 io.input.name.size = io.input.name.size * 2;
147 if (io.input.name.size > 32000) {
153 if (out.result != "WERR_OK") {
157 list[list.length] = out.name.name;
167 return a list of values for a winreg server given a path
169 list = reg.enum_values(path);
171 each returned list element is an object containing a name, a
174 function __winreg_enum_values(path)
176 var data = datablob_init();
177 var list = new Object();
180 var handle = this.open_path(path);
181 if (handle == undefined) {
186 io.input.handle = handle;
187 io.input.name = new Object();
188 io.input.name.length = 0;
189 io.input.name.size = 128;
190 io.input.name.name = "";
192 io.input.value = new Array(0);
193 io.input.size = 1024;
197 for (idx=0;idx >= 0;idx++) {
198 io.input.enum_index = idx;
199 var status = this.winreg_EnumValue(io);
205 if (out.result == "WERR_MORE_DATA") {
206 io.input.size = io.input.size * 2;
207 io.input.name.size = io.input.name.size * 2;
209 /* limit blobs to 1M */
210 if (io.input.size > 1000000) {
216 if (out.result != "WERR_OK") {
220 var el = new Object();
221 el.name = out.name.name;
223 el.rawvalue = out.value;
224 el.value = data.regToVar(el.rawvalue, el.type);
226 list[list.length] = el;
235 return a string for a winreg type
237 function __winreg_typestring(type)
239 return this.typenames[type];
243 initialise the winreg lib, returning an object
247 var reg = winreg_init();
250 reg.typenames = new Array("REG_NONE", "REG_SZ", "REG_EXPAND_SZ", "REG_BINARY",
251 "REG_DWORD", "REG_DWORD_BIG_ENDIAN", "REG_LINK", "REG_MULTI_SZ",
252 "REG_RESOURCE_LIST", "REG_FULL_RESOURCE_DESCRIPTOR",
253 "REG_RESOURCE_REQUIREMENTS_LIST", "REG_QWORD");
255 reg.close = __winreg_close;
256 reg.open_hive = __winreg_open_hive;
257 reg.open_path = __winreg_open_path;
258 reg.enum_path = __winreg_enum_path;
259 reg.enum_values = __winreg_enum_values;
260 reg.typestring = __winreg_typestring;