2 winreg rpc utility functions
3 Copyright Andrew Tridgell 2005
4 released under the GNU GPL version 3 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_mask = 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 this._last_error = "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);
55 /* cope with a leading slash */
56 if (components[0] == '') {
57 for (i=0;i<(components.length-1);i++) {
58 components[i] = components[i+1];
60 delete(components[i]);
63 if (components.length == 0) {
67 var handle = this.open_hive(components[0]);
68 if (handle == undefined) {
72 if (components.length == 1) {
76 var hpath = components[1];
78 for (i=2;i<components.length;i++) {
79 hpath = hpath + "\\" + components[i];
83 io.input.parent_handle = handle;
84 io.input.keyname = hpath;
86 io.input.access_mask = this.SEC_FLAG_MAXIMUM_ALLOWED;
87 var status = this.winreg_OpenKey(io);
94 if (io.output.result != "WERR_OK") {
98 return io.output.handle;
102 return a list of keys for a winreg server given a path
104 list = reg.enum_path(path);
106 function __winreg_enum_path(path)
108 var list = new Array(0);
110 if (path == null || path == "\\" || path == "") {
111 return new Array("HKLM", "HKU");
114 var handle = this.open_path(path);
115 if (handle == undefined) {
120 io.input.handle = handle;
121 io.input.name = new Object();
122 io.input.name.length = 0;
123 io.input.name.size = 32;
124 io.input.name.name = NULL;
125 io.input.keyclass = new Object();
126 io.input.keyclass.length = 0;
127 io.input.keyclass.size = 1024;
128 io.input.keyclass.name = NULL;
129 io.input.last_changed_time = 0;
132 for (idx=0;idx >= 0;idx++) {
133 io.input.enum_index = idx;
134 var status = this.winreg_EnumKey(io);
140 if (out.result == "WERR_MORE_DATA") {
141 io.input.name.size = io.input.name.size * 2;
143 if (io.input.name.size > 32000) {
149 if (out.result != "WERR_OK") {
153 list[list.length] = out.name.name;
162 return a list of values for a winreg server given a path
164 list = reg.enum_values(path);
166 each returned list element is an object containing a name, a
169 function __winreg_enum_values(path)
171 var data = datablob_init();
172 var list = new Array(0);
174 var handle = this.open_path(path);
175 if (handle == undefined) {
180 io.input.handle = handle;
181 io.input.name = new Object();
182 io.input.name.length = 0;
183 io.input.name.size = 128;
184 io.input.name.name = "";
186 io.input.value = new Array(0);
187 io.input.size = 1024;
191 for (idx=0;idx >= 0;idx++) {
192 io.input.enum_index = idx;
193 var status = this.winreg_EnumValue(io);
199 if (out.result == "WERR_MORE_DATA") {
200 io.input.size = io.input.size * 2;
201 io.input.name.size = io.input.name.size * 2;
203 /* limit blobs to 1M */
204 if (io.input.size > 1000000) {
210 if (out.result != "WERR_OK") {
214 var el = new Object();
215 el.name = out.name.name;
217 el.rawvalue = out.value;
218 el.value = data.regToVar(el.rawvalue, el.type);
220 list[list.length] = el;
230 ok = reg.create_key(path, key);
232 function __winreg_create_key(path, key)
234 var handle = this.open_path(path);
235 if (handle == undefined) {
240 io.input.handle = handle;
242 io.input.keyclass = NULL;
243 io.input.options = 0;
244 io.input.access_mask = this.SEC_FLAG_MAXIMUM_ALLOWED;
245 io.input.secdesc = NULL;
246 io.input.action_taken = 0;
248 var status = this.winreg_CreateKey(io);
253 if (io.output.result != "WERR_OK") {
256 this.close(io.output.new_handle);
262 return a string for a winreg type
264 function __winreg_typestring(type)
266 return this.typenames[type];
270 initialise the winreg lib, returning an object
274 var reg = winreg_init();
277 reg.typenames = new Array("REG_NONE", "REG_SZ", "REG_EXPAND_SZ", "REG_BINARY",
278 "REG_DWORD", "REG_DWORD_BIG_ENDIAN", "REG_LINK", "REG_MULTI_SZ",
279 "REG_RESOURCE_LIST", "REG_FULL_RESOURCE_DESCRIPTOR",
280 "REG_RESOURCE_REQUIREMENTS_LIST", "REG_QWORD");
282 reg.close = __winreg_close;
283 reg.open_hive = __winreg_open_hive;
284 reg.open_path = __winreg_open_path;
285 reg.enum_path = __winreg_enum_path;
286 reg.enum_values = __winreg_enum_values;
287 reg.create_key = __winreg_create_key;
288 reg.typestring = __winreg_typestring;