crypt32: Introduce function to encode an array of items as a set.
[wine] / dlls / msi / registry.c
1 /*
2  * Implementation of the Microsoft Installer (msi.dll)
3  *
4  * Copyright 2005 Mike McCormack for CodeWeavers
5  * Copyright 2005 Aric Stewart for CodeWeavers
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include <stdarg.h>
23
24 #define COBJMACROS
25 #define NONAMELESSUNION
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winreg.h"
30 #include "winnls.h"
31 #include "shlwapi.h"
32 #include "wine/debug.h"
33 #include "msi.h"
34 #include "msipriv.h"
35 #include "wincrypt.h"
36 #include "wine/unicode.h"
37 #include "winver.h"
38 #include "winuser.h"
39 #include "sddl.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(msi);
42
43
44 /* 
45  * This module will be all the helper functions for registry access by the
46  * installer bits. 
47  */
48 static const WCHAR szUserFeatures_fmt[] = {
49 'S','o','f','t','w','a','r','e','\\',
50 'M','i','c','r','o','s','o','f','t','\\',
51 'I','n','s','t','a','l','l','e','r','\\',
52 'F','e','a','t','u','r','e','s','\\',
53 '%','s',0};
54
55 static const WCHAR szInstaller_Features[] = {
56 'S','o','f','t','w','a','r','e','\\',
57 'M','i','c','r','o','s','o','f','t','\\',
58 'W','i','n','d','o','w','s','\\',
59 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
60 'I','n','s','t','a','l','l','e','r','\\',
61 'F','e','a','t','u','r','e','s',0 };
62
63 static const WCHAR szUserDataFeatures_fmt[] = {
64 'S','o','f','t','w','a','r','e','\\',
65 'M','i','c','r','o','s','o','f','t','\\',
66 'W','i','n','d','o','w','s','\\',
67 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
68 'I','n','s','t','a','l','l','e','r','\\',
69 'U','s','e','r','D','a','t','a','\\',
70 '%','s','\\','P','r','o','d','u','c','t','s','\\',
71 '%','s','\\','F','e','a','t','u','r','e','s',0};
72
73 static const WCHAR szInstaller_Features_fmt[] = {
74 'S','o','f','t','w','a','r','e','\\',
75 'M','i','c','r','o','s','o','f','t','\\',
76 'W','i','n','d','o','w','s','\\',
77 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
78 'I','n','s','t','a','l','l','e','r','\\',
79 'F','e','a','t','u','r','e','s','\\',
80 '%','s',0};
81
82 static const WCHAR szInstaller_Components[] = {
83 'S','o','f','t','w','a','r','e','\\',
84 'M','i','c','r','o','s','o','f','t','\\',
85 'W','i','n','d','o','w','s','\\',
86 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
87 'I','n','s','t','a','l','l','e','r','\\',
88 'C','o','m','p','o','n','e','n','t','s',0 };
89
90 static const WCHAR szInstaller_Components_fmt[] = {
91 'S','o','f','t','w','a','r','e','\\',
92 'M','i','c','r','o','s','o','f','t','\\',
93 'W','i','n','d','o','w','s','\\',
94 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
95 'I','n','s','t','a','l','l','e','r','\\',
96 'C','o','m','p','o','n','e','n','t','s','\\',
97 '%','s',0};
98
99 static const WCHAR szUser_Components_fmt[] = {
100 'S','o','f','t','w','a','r','e','\\',
101 'M','i','c','r','o','s','o','f','t','\\',
102 'I','n','s','t','a','l','l','e','r','\\',
103 'C','o','m','p','o','n','e','n','t','s','\\',
104 '%','s',0};
105
106 static const WCHAR szUserDataComp_fmt[] = {
107 'S','o','f','t','w','a','r','e','\\',
108 'M','i','c','r','o','s','o','f','t','\\',
109 'W','i','n','d','o','w','s','\\',
110 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
111 'I','n','s','t','a','l','l','e','r','\\',
112 'U','s','e','r','D','a','t','a','\\',
113 '%','s','\\','C','o','m','p','o','n','e','n','t','s','\\','%','s',0};
114
115 static const WCHAR szUninstall_fmt[] = {
116 'S','o','f','t','w','a','r','e','\\',
117 'M','i','c','r','o','s','o','f','t','\\',
118 'W','i','n','d','o','w','s','\\',
119 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
120 'U','n','i','n','s','t','a','l','l','\\',
121 '%','s',0 };
122
123 static const WCHAR szUserProduct_fmt[] = {
124 'S','o','f','t','w','a','r','e','\\',
125 'M','i','c','r','o','s','o','f','t','\\',
126 'I','n','s','t','a','l','l','e','r','\\',
127 'P','r','o','d','u','c','t','s','\\',
128 '%','s',0};
129
130 static const WCHAR szUserPatch_fmt[] = {
131 'S','o','f','t','w','a','r','e','\\',
132 'M','i','c','r','o','s','o','f','t','\\',
133 'I','n','s','t','a','l','l','e','r','\\',
134 'P','a','t','c','h','e','s','\\',
135 '%','s',0};
136
137 static const WCHAR szInstaller_Products[] = {
138 'S','o','f','t','w','a','r','e','\\',
139 'M','i','c','r','o','s','o','f','t','\\',
140 'W','i','n','d','o','w','s','\\',
141 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
142 'I','n','s','t','a','l','l','e','r','\\',
143 'P','r','o','d','u','c','t','s',0};
144
145 static const WCHAR szInstaller_Products_fmt[] = {
146 'S','o','f','t','w','a','r','e','\\',
147 'M','i','c','r','o','s','o','f','t','\\',
148 'W','i','n','d','o','w','s','\\',
149 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
150 'I','n','s','t','a','l','l','e','r','\\',
151 'P','r','o','d','u','c','t','s','\\',
152 '%','s',0};
153
154 static const WCHAR szInstaller_Patches_fmt[] = {
155 'S','o','f','t','w','a','r','e','\\',
156 'M','i','c','r','o','s','o','f','t','\\',
157 'W','i','n','d','o','w','s','\\',
158 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
159 'I','n','s','t','a','l','l','e','r','\\',
160 'P','a','t','c','h','e','s','\\',
161 '%','s',0};
162
163 static const WCHAR szInstaller_UpgradeCodes_fmt[] = {
164 'S','o','f','t','w','a','r','e','\\',
165 'M','i','c','r','o','s','o','f','t','\\',
166 'W','i','n','d','o','w','s','\\',
167 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
168 'I','n','s','t','a','l','l','e','r','\\',
169 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
170 '%','s',0};
171
172 static const WCHAR szInstaller_UserUpgradeCodes_fmt[] = {
173 'S','o','f','t','w','a','r','e','\\',
174 'M','i','c','r','o','s','o','f','t','\\',
175 'I','n','s','t','a','l','l','e','r','\\',
176 'U','p','g','r','a','d','e','C','o','d','e','s','\\',
177 '%','s',0};
178
179 static const WCHAR szUserDataProd_fmt[] = {
180 'S','o','f','t','w','a','r','e','\\',
181 'M','i','c','r','o','s','o','f','t','\\',
182 'W','i','n','d','o','w','s','\\',
183 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
184 'I','n','s','t','a','l','l','e','r','\\',
185 'U','s','e','r','D','a','t','a','\\',
186 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s',0};
187
188 static const WCHAR szInstallProperties_fmt[] = {
189 'S','o','f','t','w','a','r','e','\\',
190 'M','i','c','r','o','s','o','f','t','\\',
191 'W','i','n','d','o','w','s','\\',
192 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
193 'I','n','s','t','a','l','l','e','r','\\',
194 'U','s','e','r','D','a','t','a','\\',
195 '%','s','\\','P','r','o','d','u','c','t','s','\\','%','s','\\',
196 'I','n','s','t','a','l','l','P','r','o','p','e','r','t','i','e','s',0};
197
198
199 #define SQUISH_GUID_SIZE 33
200
201 BOOL unsquash_guid(LPCWSTR in, LPWSTR out)
202 {
203     DWORD i,n=0;
204
205     out[n++]='{';
206     for(i=0; i<8; i++)
207         out[n++] = in[7-i];
208     out[n++]='-';
209     for(i=0; i<4; i++)
210         out[n++] = in[11-i];
211     out[n++]='-';
212     for(i=0; i<4; i++)
213         out[n++] = in[15-i];
214     out[n++]='-';
215     for(i=0; i<2; i++)
216     {
217         out[n++] = in[17+i*2];
218         out[n++] = in[16+i*2];
219     }
220     out[n++]='-';
221     for( ; i<8; i++)
222     {
223         out[n++] = in[17+i*2];
224         out[n++] = in[16+i*2];
225     }
226     out[n++]='}';
227     out[n]=0;
228     return TRUE;
229 }
230
231 BOOL squash_guid(LPCWSTR in, LPWSTR out)
232 {
233     DWORD i,n=1;
234     GUID guid;
235
236     if (FAILED(CLSIDFromString((LPOLESTR)in, &guid)))
237         return FALSE;
238
239     for(i=0; i<8; i++)
240         out[7-i] = in[n++];
241     n++;
242     for(i=0; i<4; i++)
243         out[11-i] = in[n++];
244     n++;
245     for(i=0; i<4; i++)
246         out[15-i] = in[n++];
247     n++;
248     for(i=0; i<2; i++)
249     {
250         out[17+i*2] = in[n++];
251         out[16+i*2] = in[n++];
252     }
253     n++;
254     for( ; i<8; i++)
255     {
256         out[17+i*2] = in[n++];
257         out[16+i*2] = in[n++];
258     }
259     out[32]=0;
260     return TRUE;
261 }
262
263
264 /* tables for encoding and decoding base85 */
265 static const unsigned char table_dec85[0x80] = {
266 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
267 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
268 0xff,0x00,0xff,0xff,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0xff,
269 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0xff,0xff,0xff,0x16,0xff,0x17,
270 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
271 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0xff,0x34,0x35,0x36,
272 0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,0x45,0x46,
273 0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xff,0x53,0x54,0xff,
274 };
275
276 static const char table_enc85[] =
277 "!$%&'()*+,-.0123456789=?@ABCDEFGHIJKLMNO"
278 "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwx"
279 "yz{}~";
280
281 /*
282  *  Converts a base85 encoded guid into a GUID pointer
283  *  Base85 encoded GUIDs should be 20 characters long.
284  *
285  *  returns TRUE if successful, FALSE if not
286  */
287 BOOL decode_base85_guid( LPCWSTR str, GUID *guid )
288 {
289     DWORD i, val = 0, base = 1, *p;
290
291     if (!str)
292         return FALSE;
293
294     p = (DWORD*) guid;
295     for( i=0; i<20; i++ )
296     {
297         if( (i%5) == 0 )
298         {
299             val = 0;
300             base = 1;
301         }
302         val += table_dec85[str[i]] * base;
303         if( str[i] >= 0x80 )
304             return FALSE;
305         if( table_dec85[str[i]] == 0xff )
306             return FALSE;
307         if( (i%5) == 4 )
308             p[i/5] = val;
309         base *= 85;
310     }
311     return TRUE;
312 }
313
314 /*
315  *  Encodes a base85 guid given a GUID pointer
316  *  Caller should provide a 21 character buffer for the encoded string.
317  *
318  *  returns TRUE if successful, FALSE if not
319  */
320 BOOL encode_base85_guid( GUID *guid, LPWSTR str )
321 {
322     unsigned int x, *p, i;
323
324     p = (unsigned int*) guid;
325     for( i=0; i<4; i++ )
326     {
327         x = p[i];
328         *str++ = table_enc85[x%85];
329         x = x/85;
330         *str++ = table_enc85[x%85];
331         x = x/85;
332         *str++ = table_enc85[x%85];
333         x = x/85;
334         *str++ = table_enc85[x%85];
335         x = x/85;
336         *str++ = table_enc85[x%85];
337     }
338     *str = 0;
339
340     return TRUE;
341 }
342
343 DWORD msi_version_str_to_dword(LPCWSTR p)
344 {
345     DWORD major, minor = 0, build = 0, version = 0;
346
347     if (!p)
348         return version;
349
350     major = atoiW(p);
351
352     p = strchrW(p, '.');
353     if (p)
354     {
355         minor = atoiW(p+1);
356         p = strchrW(p+1, '.');
357         if (p)
358             build = atoiW(p+1);
359     }
360
361     return MAKELONG(build, MAKEWORD(minor, major));
362 }
363
364 LPWSTR msi_version_dword_to_str(DWORD version)
365 {
366     const WCHAR fmt[] = { '%','u','.','%','u','.','%','u',0 };
367     LPWSTR str = msi_alloc(20);
368     sprintfW(str, fmt,
369              (version&0xff000000)>>24,
370              (version&0x00ff0000)>>16,
371               version&0x0000ffff);
372     return str;
373 }
374
375 LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
376 {
377     DWORD len = value ? (lstrlenW(value) + 1) * sizeof (WCHAR) : 0;
378     return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, len );
379 }
380
381 LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
382 {
383     LPCWSTR p = value;
384     while (*p) p += lstrlenW(p) + 1;
385     return RegSetValueExW( hkey, name, 0, REG_MULTI_SZ,
386                            (const BYTE *)value, (p + 1 - value) * sizeof(WCHAR) );
387 }
388
389 LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val )
390 {
391     return RegSetValueExW( hkey, name, 0, REG_DWORD, (LPBYTE)&val, sizeof (DWORD) );
392 }
393
394 LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val )
395 {
396     HKEY hsubkey = 0;
397     LONG r;
398
399     r = RegCreateKeyW( hkey, path, &hsubkey );
400     if (r != ERROR_SUCCESS)
401         return r;
402     r = msi_reg_set_val_str( hsubkey, name, val );
403     RegCloseKey( hsubkey );
404     return r;
405 }
406
407 LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name )
408 {
409     DWORD len = 0;
410     LPWSTR val;
411     LONG r;
412
413     r = RegQueryValueExW(hkey, name, NULL, NULL, NULL, &len);
414     if (r != ERROR_SUCCESS)
415         return NULL;
416
417     len += sizeof (WCHAR);
418     val = msi_alloc( len );
419     if (!val)
420         return NULL;
421     val[0] = 0;
422     RegQueryValueExW(hkey, name, NULL, NULL, (LPBYTE) val, &len);
423     return val;
424 }
425
426 BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val)
427 {
428     DWORD type, len = sizeof (DWORD);
429     LONG r = RegQueryValueExW(hkey, name, NULL, &type, (LPBYTE) val, &len);
430     return r == ERROR_SUCCESS && type == REG_DWORD;
431 }
432
433 static UINT get_user_sid(LPWSTR *usersid)
434 {
435     HANDLE token;
436     BYTE buf[1024];
437     DWORD size;
438     PTOKEN_USER user;
439
440     if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
441         return ERROR_FUNCTION_FAILED;
442
443     size = sizeof(buf);
444     if (!GetTokenInformation(token, TokenUser, (void *)buf, size, &size))
445         return ERROR_FUNCTION_FAILED;
446
447     user = (PTOKEN_USER)buf;
448     if (!ConvertSidToStringSidW(user->User.Sid, usersid))
449         return ERROR_FUNCTION_FAILED;
450
451     return ERROR_SUCCESS;
452 }
453
454 UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create)
455 {
456     UINT rc;
457     WCHAR keypath[0x200];
458     TRACE("%s\n",debugstr_w(szProduct));
459
460     sprintfW(keypath,szUninstall_fmt,szProduct);
461
462     if (create)
463         rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
464     else
465         rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
466
467     return rc;
468 }
469
470 UINT MSIREG_OpenUserProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
471 {
472     UINT rc;
473     WCHAR squished_pc[GUID_SIZE];
474     WCHAR keypath[0x200];
475
476     TRACE("%s\n",debugstr_w(szProduct));
477     squash_guid(szProduct,squished_pc);
478     TRACE("squished (%s)\n", debugstr_w(squished_pc));
479
480     sprintfW(keypath,szUserProduct_fmt,squished_pc);
481
482     if (create)
483         rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
484     else
485         rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
486
487     return rc;
488 }
489
490 UINT MSIREG_DeleteUserProductKey(LPCWSTR szProduct)
491 {
492     WCHAR squished_pc[GUID_SIZE];
493     WCHAR keypath[0x200];
494
495     TRACE("%s\n",debugstr_w(szProduct));
496     squash_guid(szProduct,squished_pc);
497     TRACE("squished (%s)\n", debugstr_w(squished_pc));
498
499     sprintfW(keypath,szUserProduct_fmt,squished_pc);
500
501     return RegDeleteTreeW(HKEY_CURRENT_USER, keypath);
502 }
503
504 UINT MSIREG_OpenUserPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
505 {
506     UINT rc;
507     WCHAR squished_pc[GUID_SIZE];
508     WCHAR keypath[0x200];
509
510     TRACE("%s\n",debugstr_w(szPatch));
511     squash_guid(szPatch,squished_pc);
512     TRACE("squished (%s)\n", debugstr_w(squished_pc));
513
514     sprintfW(keypath,szUserPatch_fmt,squished_pc);
515
516     if (create)
517         rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
518     else
519         rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
520
521     return rc;
522 }
523
524 UINT MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
525 {
526     UINT rc;
527     WCHAR squished_pc[GUID_SIZE];
528     WCHAR keypath[0x200];
529
530     TRACE("%s\n",debugstr_w(szProduct));
531     squash_guid(szProduct,squished_pc);
532     TRACE("squished (%s)\n", debugstr_w(squished_pc));
533
534     sprintfW(keypath,szUserFeatures_fmt,squished_pc);
535
536     if (create)
537         rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
538     else
539         rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
540
541     return rc;
542 }
543
544 UINT MSIREG_OpenFeatures(HKEY* key)
545 {
546     return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Features,key);
547 }
548
549 UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
550 {
551     UINT rc;
552     WCHAR squished_pc[GUID_SIZE];
553     WCHAR keypath[0x200];
554
555     TRACE("%s\n",debugstr_w(szProduct));
556     squash_guid(szProduct,squished_pc);
557     TRACE("squished (%s)\n", debugstr_w(squished_pc));
558
559     sprintfW(keypath,szInstaller_Features_fmt,squished_pc);
560
561     if (create)
562         rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
563     else
564         rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
565
566     return rc;
567 }
568
569 UINT MSIREG_OpenUserDataFeaturesKey(LPCWSTR szProduct, HKEY *key, BOOL create)
570 {
571     UINT rc;
572     WCHAR squished_pc[GUID_SIZE];
573     WCHAR keypath[0x200];
574     LPWSTR usersid;
575
576     TRACE("%s\n", debugstr_w(szProduct));
577     squash_guid(szProduct, squished_pc);
578     TRACE("squished (%s)\n", debugstr_w(squished_pc));
579
580     rc = get_user_sid(&usersid);
581     if (rc != ERROR_SUCCESS || !usersid)
582     {
583         ERR("Failed to retrieve user SID: %d\n", rc);
584         return rc;
585     }
586
587     sprintfW(keypath, szUserDataFeatures_fmt, usersid, squished_pc);
588
589     if (create)
590         rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
591     else
592         rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
593
594     msi_free(usersid);
595     return rc;
596 }
597
598 UINT MSIREG_OpenComponents(HKEY* key)
599 {
600     return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Components,key);
601 }
602
603 UINT MSIREG_OpenComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
604 {
605     UINT rc;
606     WCHAR squished_cc[GUID_SIZE];
607     WCHAR keypath[0x200];
608
609     TRACE("%s\n",debugstr_w(szComponent));
610     squash_guid(szComponent,squished_cc);
611     TRACE("squished (%s)\n", debugstr_w(squished_cc));
612
613     sprintfW(keypath,szInstaller_Components_fmt,squished_cc);
614
615     if (create)
616         rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
617     else
618         rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
619
620     return rc;
621 }
622
623 UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
624 {
625     UINT rc;
626     WCHAR squished_cc[GUID_SIZE];
627     WCHAR keypath[0x200];
628
629     TRACE("%s\n",debugstr_w(szComponent));
630     squash_guid(szComponent,squished_cc);
631     TRACE("squished (%s)\n", debugstr_w(squished_cc));
632
633     sprintfW(keypath,szUser_Components_fmt,squished_cc);
634
635     if (create)
636         rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
637     else
638         rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
639
640     return rc;
641 }
642
643 UINT MSIREG_OpenUserDataComponentKey(LPCWSTR szComponent, HKEY *key, BOOL create)
644 {
645     UINT rc;
646     WCHAR comp[GUID_SIZE];
647     WCHAR keypath[0x200];
648     LPWSTR usersid;
649
650     TRACE("%s\n", debugstr_w(szComponent));
651     squash_guid(szComponent, comp);
652     TRACE("squished (%s)\n", debugstr_w(comp));
653
654     rc = get_user_sid(&usersid);
655     if (rc != ERROR_SUCCESS || !usersid)
656     {
657         ERR("Failed to retrieve user SID: %d\n", rc);
658         return rc;
659     }
660
661     sprintfW(keypath, szUserDataComp_fmt, usersid, comp);
662
663     if (create)
664         rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
665     else
666         rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
667
668     msi_free(usersid);
669     return rc;
670 }
671
672 UINT MSIREG_OpenUserDataProductKey(LPCWSTR szProduct, HKEY *key, BOOL create)
673 {
674     UINT rc;
675     WCHAR squished_pc[GUID_SIZE];
676     WCHAR keypath[0x200];
677     LPWSTR usersid;
678
679     TRACE("%s\n", debugstr_w(szProduct));
680     squash_guid(szProduct, squished_pc);
681     TRACE("squished (%s)\n", debugstr_w(squished_pc));
682
683     rc = get_user_sid(&usersid);
684     if (rc != ERROR_SUCCESS || !usersid)
685     {
686         ERR("Failed to retrieve user SID: %d\n", rc);
687         return rc;
688     }
689
690     sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
691
692     if (create)
693         rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
694     else
695         rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
696
697     msi_free(usersid);
698     return rc;
699 }
700
701 UINT MSIREG_OpenInstallPropertiesKey(LPCWSTR szProduct, HKEY *key, BOOL create)
702 {
703     UINT rc;
704     WCHAR squished_pc[GUID_SIZE];
705     WCHAR keypath[0x200];
706     LPWSTR usersid;
707
708     TRACE("%s\n", debugstr_w(szProduct));
709     squash_guid(szProduct, squished_pc);
710     TRACE("squished (%s)\n", debugstr_w(squished_pc));
711
712     rc = get_user_sid(&usersid);
713     if (rc != ERROR_SUCCESS || !usersid)
714     {
715         ERR("Failed to retrieve user SID: %d\n", rc);
716         return rc;
717     }
718
719     sprintfW(keypath, szInstallProperties_fmt, usersid, squished_pc);
720
721     if (create)
722         rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
723     else
724         rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
725
726     msi_free(usersid);
727     return rc;
728 }
729
730 UINT MSIREG_DeleteUserDataProductKey(LPCWSTR szProduct)
731 {
732     UINT rc;
733     WCHAR squished_pc[GUID_SIZE];
734     WCHAR keypath[0x200];
735     LPWSTR usersid;
736
737     TRACE("%s\n", debugstr_w(szProduct));
738     squash_guid(szProduct, squished_pc);
739     TRACE("squished (%s)\n", debugstr_w(squished_pc));
740
741     rc = get_user_sid(&usersid);
742     if (rc != ERROR_SUCCESS || !usersid)
743     {
744         ERR("Failed to retrieve user SID: %d\n", rc);
745         return rc;
746     }
747
748     sprintfW(keypath, szUserDataProd_fmt, usersid, squished_pc);
749
750     msi_free(usersid);
751     return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
752 }
753
754 UINT MSIREG_OpenProducts(HKEY* key)
755 {
756     return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Products,key);
757 }
758
759 UINT MSIREG_OpenProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
760 {
761     UINT rc;
762     WCHAR squished_pc[GUID_SIZE];
763     WCHAR keypath[0x200];
764
765     TRACE("%s\n",debugstr_w(szProduct));
766     squash_guid(szProduct,squished_pc);
767     TRACE("squished (%s)\n", debugstr_w(squished_pc));
768
769     sprintfW(keypath,szInstaller_Products_fmt,squished_pc);
770
771     if (create)
772         rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
773     else
774         rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
775
776     return rc;
777 }
778
779 UINT MSIREG_DeleteProductKey(LPCWSTR szProduct)
780 {
781     WCHAR squished_pc[GUID_SIZE];
782     WCHAR keypath[0x200];
783
784     TRACE("%s\n", debugstr_w(szProduct));
785     squash_guid(szProduct, squished_pc);
786     TRACE("squished (%s)\n", debugstr_w(squished_pc));
787
788     sprintfW(keypath, szInstaller_Products_fmt, squished_pc);
789
790     return RegDeleteTreeW(HKEY_LOCAL_MACHINE, keypath);
791 }
792
793 UINT MSIREG_OpenPatchesKey(LPCWSTR szPatch, HKEY* key, BOOL create)
794 {
795     UINT rc;
796     WCHAR squished_pc[GUID_SIZE];
797     WCHAR keypath[0x200];
798
799     TRACE("%s\n",debugstr_w(szPatch));
800     squash_guid(szPatch,squished_pc);
801     TRACE("squished (%s)\n", debugstr_w(squished_pc));
802
803     sprintfW(keypath,szInstaller_Patches_fmt,squished_pc);
804
805     if (create)
806         rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
807     else
808         rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
809
810     return rc;
811 }
812
813 UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
814 {
815     UINT rc;
816     WCHAR squished_pc[GUID_SIZE];
817     WCHAR keypath[0x200];
818
819     TRACE("%s\n",debugstr_w(szUpgradeCode));
820     squash_guid(szUpgradeCode,squished_pc);
821     TRACE("squished (%s)\n", debugstr_w(squished_pc));
822
823     sprintfW(keypath,szInstaller_UpgradeCodes_fmt,squished_pc);
824
825     if (create)
826         rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
827     else
828         rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
829
830     return rc;
831 }
832
833 UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
834 {
835     UINT rc;
836     WCHAR squished_pc[GUID_SIZE];
837     WCHAR keypath[0x200];
838
839     TRACE("%s\n",debugstr_w(szUpgradeCode));
840     squash_guid(szUpgradeCode,squished_pc);
841     TRACE("squished (%s)\n", debugstr_w(squished_pc));
842
843     sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
844
845     if (create)
846         rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
847     else
848         rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
849
850     return rc;
851 }
852
853
854 /*************************************************************************
855  *  MsiDecomposeDescriptorW   [MSI.@]
856  *
857  * Decomposes an MSI descriptor into product, feature and component parts.
858  * An MSI descriptor is a string of the form:
859  *   [base 85 guid] [feature code] '>' [base 85 guid]
860  *
861  * PARAMS
862  *   szDescriptor  [I]  the descriptor to decompose
863  *   szProduct     [O]  buffer of MAX_FEATURE_CHARS+1 for the product guid
864  *   szFeature     [O]  buffer of MAX_FEATURE_CHARS+1 for the feature code
865  *   szComponent   [O]  buffer of MAX_FEATURE_CHARS+1 for the component guid
866  *   pUsed         [O]  the length of the descriptor
867  *
868  * RETURNS
869  *   ERROR_SUCCESS             if everything worked correctly
870  *   ERROR_INVALID_PARAMETER   if the descriptor was invalid
871  *
872  */
873 UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct,
874                 LPWSTR szFeature, LPWSTR szComponent, DWORD *pUsed )
875 {
876     UINT r, len;
877     LPWSTR p;
878     GUID product, component;
879
880     TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor), szProduct,
881           szFeature, szComponent, pUsed);
882
883     r = decode_base85_guid( szDescriptor, &product );
884     if( !r )
885         return ERROR_INVALID_PARAMETER;
886
887     TRACE("product %s\n", debugstr_guid( &product ));
888
889     p = strchrW(&szDescriptor[20],'>');
890     if( !p )
891         return ERROR_INVALID_PARAMETER;
892
893     len = (p - &szDescriptor[20]);
894     if( len > MAX_FEATURE_CHARS )
895         return ERROR_INVALID_PARAMETER;
896
897     TRACE("feature %s\n", debugstr_wn( &szDescriptor[20], len ));
898
899     r = decode_base85_guid( p+1, &component );
900     if( !r )
901         return ERROR_INVALID_PARAMETER;
902
903     TRACE("component %s\n", debugstr_guid( &component ));
904
905     if (szProduct)
906         StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 );
907     if (szComponent)
908         StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 );
909     if (szFeature)
910     {
911         memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) );
912         szFeature[len] = 0;
913     }
914     len = ( &p[21] - szDescriptor );
915
916     TRACE("length = %d\n", len);
917     *pUsed = len;
918
919     return ERROR_SUCCESS;
920 }
921
922 UINT WINAPI MsiDecomposeDescriptorA( LPCSTR szDescriptor, LPSTR szProduct,
923                 LPSTR szFeature, LPSTR szComponent, DWORD *pUsed )
924 {
925     WCHAR product[MAX_FEATURE_CHARS+1];
926     WCHAR feature[MAX_FEATURE_CHARS+1];
927     WCHAR component[MAX_FEATURE_CHARS+1];
928     LPWSTR str = NULL, p = NULL, f = NULL, c = NULL;
929     UINT r;
930
931     TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct,
932           szFeature, szComponent, pUsed);
933
934     str = strdupAtoW( szDescriptor );
935     if( szDescriptor && !str )
936         return ERROR_OUTOFMEMORY;
937
938     if (szProduct)
939         p = product;
940     if (szFeature)
941         f = feature;
942     if (szComponent)
943         c = component;
944
945     r = MsiDecomposeDescriptorW( str, p, f, c, pUsed );
946
947     if (r == ERROR_SUCCESS)
948     {
949         WideCharToMultiByte( CP_ACP, 0, p, -1,
950                              szProduct, MAX_FEATURE_CHARS+1, NULL, NULL );
951         WideCharToMultiByte( CP_ACP, 0, f, -1,
952                              szFeature, MAX_FEATURE_CHARS+1, NULL, NULL );
953         WideCharToMultiByte( CP_ACP, 0, c, -1,
954                              szComponent, MAX_FEATURE_CHARS+1, NULL, NULL );
955     }
956
957     msi_free( str );
958
959     return r;
960 }
961
962 UINT WINAPI MsiEnumProductsA(DWORD index, LPSTR lpguid)
963 {
964     DWORD r;
965     WCHAR szwGuid[GUID_SIZE];
966
967     TRACE("%d %p\n", index, lpguid);
968
969     if (NULL == lpguid)
970         return ERROR_INVALID_PARAMETER;
971     r = MsiEnumProductsW(index, szwGuid);
972     if( r == ERROR_SUCCESS )
973         WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
974
975     return r;
976 }
977
978 UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid)
979 {
980     HKEY hkeyProducts = 0;
981     DWORD r;
982     WCHAR szKeyName[SQUISH_GUID_SIZE];
983
984     TRACE("%d %p\n", index, lpguid);
985
986     if (NULL == lpguid)
987         return ERROR_INVALID_PARAMETER;
988
989     r = MSIREG_OpenProducts(&hkeyProducts);
990     if( r != ERROR_SUCCESS )
991         return ERROR_NO_MORE_ITEMS;
992
993     r = RegEnumKeyW(hkeyProducts, index, szKeyName, SQUISH_GUID_SIZE);
994     if( r == ERROR_SUCCESS )
995         unsquash_guid(szKeyName, lpguid);
996     RegCloseKey(hkeyProducts);
997
998     return r;
999 }
1000
1001 UINT WINAPI MsiEnumFeaturesA(LPCSTR szProduct, DWORD index, 
1002       LPSTR szFeature, LPSTR szParent)
1003 {
1004     DWORD r;
1005     WCHAR szwFeature[GUID_SIZE], szwParent[GUID_SIZE];
1006     LPWSTR szwProduct = NULL;
1007
1008     TRACE("%s %d %p %p\n", debugstr_a(szProduct), index, szFeature, szParent);
1009
1010     if( szProduct )
1011     {
1012         szwProduct = strdupAtoW( szProduct );
1013         if( !szwProduct )
1014             return ERROR_OUTOFMEMORY;
1015     }
1016
1017     r = MsiEnumFeaturesW(szwProduct, index, szwFeature, szwParent);
1018     if( r == ERROR_SUCCESS )
1019     {
1020         WideCharToMultiByte(CP_ACP, 0, szwFeature, -1,
1021                             szFeature, GUID_SIZE, NULL, NULL);
1022         WideCharToMultiByte(CP_ACP, 0, szwParent, -1,
1023                             szParent, GUID_SIZE, NULL, NULL);
1024     }
1025
1026     msi_free( szwProduct);
1027
1028     return r;
1029 }
1030
1031 UINT WINAPI MsiEnumFeaturesW(LPCWSTR szProduct, DWORD index, 
1032       LPWSTR szFeature, LPWSTR szParent)
1033 {
1034     HKEY hkeyProduct = 0;
1035     DWORD r, sz;
1036
1037     TRACE("%s %d %p %p\n", debugstr_w(szProduct), index, szFeature, szParent);
1038
1039     if( !szProduct )
1040         return ERROR_INVALID_PARAMETER;
1041
1042     r = MSIREG_OpenFeaturesKey(szProduct,&hkeyProduct,FALSE);
1043     if( r != ERROR_SUCCESS )
1044         return ERROR_NO_MORE_ITEMS;
1045
1046     sz = GUID_SIZE;
1047     r = RegEnumValueW(hkeyProduct, index, szFeature, &sz, NULL, NULL, NULL, NULL);
1048     RegCloseKey(hkeyProduct);
1049
1050     return r;
1051 }
1052
1053 UINT WINAPI MsiEnumComponentsA(DWORD index, LPSTR lpguid)
1054 {
1055     DWORD r;
1056     WCHAR szwGuid[GUID_SIZE];
1057
1058     TRACE("%d %p\n", index, lpguid);
1059
1060     r = MsiEnumComponentsW(index, szwGuid);
1061     if( r == ERROR_SUCCESS )
1062         WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
1063
1064     return r;
1065 }
1066
1067 UINT WINAPI MsiEnumComponentsW(DWORD index, LPWSTR lpguid)
1068 {
1069     HKEY hkeyComponents = 0;
1070     DWORD r;
1071     WCHAR szKeyName[SQUISH_GUID_SIZE];
1072
1073     TRACE("%d %p\n", index, lpguid);
1074
1075     r = MSIREG_OpenComponents(&hkeyComponents);
1076     if( r != ERROR_SUCCESS )
1077         return ERROR_NO_MORE_ITEMS;
1078
1079     r = RegEnumKeyW(hkeyComponents, index, szKeyName, SQUISH_GUID_SIZE);
1080     if( r == ERROR_SUCCESS )
1081         unsquash_guid(szKeyName, lpguid);
1082     RegCloseKey(hkeyComponents);
1083
1084     return r;
1085 }
1086
1087 UINT WINAPI MsiEnumClientsA(LPCSTR szComponent, DWORD index, LPSTR szProduct)
1088 {
1089     DWORD r;
1090     WCHAR szwProduct[GUID_SIZE];
1091     LPWSTR szwComponent = NULL;
1092
1093     TRACE("%s %d %p\n", debugstr_a(szComponent), index, szProduct);
1094
1095     if( szComponent )
1096     {
1097         szwComponent = strdupAtoW( szComponent );
1098         if( !szwComponent )
1099             return ERROR_OUTOFMEMORY;
1100     }
1101
1102     r = MsiEnumClientsW(szComponent?szwComponent:NULL, index, szwProduct);
1103     if( r == ERROR_SUCCESS )
1104     {
1105         WideCharToMultiByte(CP_ACP, 0, szwProduct, -1,
1106                             szProduct, GUID_SIZE, NULL, NULL);
1107     }
1108
1109     msi_free( szwComponent);
1110
1111     return r;
1112 }
1113
1114 UINT WINAPI MsiEnumClientsW(LPCWSTR szComponent, DWORD index, LPWSTR szProduct)
1115 {
1116     HKEY hkeyComp = 0;
1117     DWORD r, sz;
1118     WCHAR szValName[SQUISH_GUID_SIZE];
1119
1120     TRACE("%s %d %p\n", debugstr_w(szComponent), index, szProduct);
1121
1122     r = MSIREG_OpenComponentsKey(szComponent,&hkeyComp,FALSE);
1123     if( r != ERROR_SUCCESS )
1124         return ERROR_NO_MORE_ITEMS;
1125
1126     sz = SQUISH_GUID_SIZE;
1127     r = RegEnumValueW(hkeyComp, index, szValName, &sz, NULL, NULL, NULL, NULL);
1128     if( r == ERROR_SUCCESS )
1129         unsquash_guid(szValName, szProduct);
1130
1131     RegCloseKey(hkeyComp);
1132
1133     return r;
1134 }
1135
1136 static UINT WINAPI MSI_EnumComponentQualifiers( LPCWSTR szComponent, DWORD iIndex,
1137                 awstring *lpQualBuf, DWORD* pcchQual,
1138                 awstring *lpAppBuf, DWORD* pcchAppBuf )
1139 {
1140     DWORD name_sz, val_sz, name_max, val_max, type, ofs;
1141     LPWSTR name = NULL, val = NULL;
1142     UINT r, r2;
1143     HKEY key;
1144
1145     TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1146           lpQualBuf, pcchQual, lpAppBuf, pcchAppBuf);
1147
1148     if (!szComponent)
1149         return ERROR_INVALID_PARAMETER;
1150
1151     r = MSIREG_OpenUserComponentsKey( szComponent, &key, FALSE );
1152     if (r != ERROR_SUCCESS)
1153         return ERROR_UNKNOWN_COMPONENT;
1154
1155     /* figure out how big the name is we want to return */
1156     name_max = 0x10;
1157     r = ERROR_OUTOFMEMORY;
1158     name = msi_alloc( name_max * sizeof(WCHAR) );
1159     if (!name)
1160         goto end;
1161
1162     val_max = 0x10;
1163     r = ERROR_OUTOFMEMORY;
1164     val = msi_alloc( val_max );
1165     if (!val)
1166         goto end;
1167
1168     /* loop until we allocate enough memory */
1169     while (1)
1170     {
1171         name_sz = name_max;
1172         val_sz = val_max;
1173         r = RegEnumValueW( key, iIndex, name, &name_sz,
1174                            NULL, &type, (LPBYTE)val, &val_sz );
1175         if (r == ERROR_SUCCESS)
1176             break;
1177         if (r != ERROR_MORE_DATA)
1178             goto end;
1179  
1180         if (type != REG_MULTI_SZ)
1181         {
1182             ERR("component data has wrong type (%d)\n", type);
1183             goto end;
1184         }
1185
1186         r = ERROR_OUTOFMEMORY;
1187         if ((name_sz+1) >= name_max)
1188         {
1189             name_max *= 2;
1190             msi_free( name );
1191             name = msi_alloc( name_max * sizeof (WCHAR) );
1192             if (!name)
1193                 goto end;
1194             continue;
1195         }
1196         if (val_sz > val_max)
1197         {
1198             val_max = val_sz + sizeof (WCHAR);
1199             msi_free( val );
1200             val = msi_alloc( val_max * sizeof (WCHAR) );
1201             if (!val)
1202                 goto end;
1203             continue;
1204         }
1205         ERR("should be enough data, but isn't %d %d\n", name_sz, val_sz );
1206         goto end;
1207     }
1208
1209     ofs = 0;
1210     r = MsiDecomposeDescriptorW( val, NULL, NULL, NULL, &ofs );
1211     if (r != ERROR_SUCCESS)
1212         goto end;
1213
1214     TRACE("Providing %s and %s\n", debugstr_w(name), debugstr_w(val+ofs));
1215
1216     r = msi_strcpy_to_awstring( name, lpQualBuf, pcchQual );
1217     r2 = msi_strcpy_to_awstring( val+ofs, lpAppBuf, pcchAppBuf );
1218
1219     if (r2 != ERROR_SUCCESS)
1220         r = r2;
1221
1222 end:
1223     msi_free(val);
1224     msi_free(name);
1225     RegCloseKey(key);
1226
1227     return r;
1228 }
1229
1230 /*************************************************************************
1231  *  MsiEnumComponentQualifiersA [MSI.@]
1232  */
1233 UINT WINAPI MsiEnumComponentQualifiersA( LPCSTR szComponent, DWORD iIndex,
1234                 LPSTR lpQualifierBuf, DWORD* pcchQualifierBuf,
1235                 LPSTR lpApplicationDataBuf, DWORD* pcchApplicationDataBuf )
1236 {
1237     awstring qual, appdata;
1238     LPWSTR comp;
1239     UINT r;
1240
1241     TRACE("%s %08x %p %p %p %p\n", debugstr_a(szComponent), iIndex,
1242           lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1243           pcchApplicationDataBuf);
1244
1245     comp = strdupAtoW( szComponent );
1246     if (szComponent && !comp)
1247         return ERROR_OUTOFMEMORY;
1248
1249     qual.unicode = FALSE;
1250     qual.str.a = lpQualifierBuf;
1251
1252     appdata.unicode = FALSE;
1253     appdata.str.a = lpApplicationDataBuf;
1254
1255     r = MSI_EnumComponentQualifiers( comp, iIndex,
1256               &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1257     msi_free( comp );
1258     return r;
1259 }
1260
1261 /*************************************************************************
1262  *  MsiEnumComponentQualifiersW [MSI.@]
1263  */
1264 UINT WINAPI MsiEnumComponentQualifiersW( LPCWSTR szComponent, DWORD iIndex,
1265                 LPWSTR lpQualifierBuf, DWORD* pcchQualifierBuf,
1266                 LPWSTR lpApplicationDataBuf, DWORD* pcchApplicationDataBuf )
1267 {
1268     awstring qual, appdata;
1269
1270     TRACE("%s %08x %p %p %p %p\n", debugstr_w(szComponent), iIndex,
1271           lpQualifierBuf, pcchQualifierBuf, lpApplicationDataBuf,
1272           pcchApplicationDataBuf);
1273
1274     qual.unicode = TRUE;
1275     qual.str.w = lpQualifierBuf;
1276
1277     appdata.unicode = TRUE;
1278     appdata.str.w = lpApplicationDataBuf;
1279
1280     return MSI_EnumComponentQualifiers( szComponent, iIndex,
1281                  &qual, pcchQualifierBuf, &appdata, pcchApplicationDataBuf );
1282 }
1283
1284 /*************************************************************************
1285  *  MsiEnumRelatedProductsW   [MSI.@]
1286  *
1287  */
1288 UINT WINAPI MsiEnumRelatedProductsW(LPCWSTR szUpgradeCode, DWORD dwReserved,
1289                                     DWORD iProductIndex, LPWSTR lpProductBuf)
1290 {
1291     UINT r;
1292     HKEY hkey;
1293     DWORD dwSize = SQUISH_GUID_SIZE;
1294     WCHAR szKeyName[SQUISH_GUID_SIZE];
1295
1296     TRACE("%s %u %u %p\n", debugstr_w(szUpgradeCode), dwReserved,
1297           iProductIndex, lpProductBuf);
1298
1299     if (NULL == szUpgradeCode)
1300         return ERROR_INVALID_PARAMETER;
1301     if (NULL == lpProductBuf)
1302         return ERROR_INVALID_PARAMETER;
1303
1304     r = MSIREG_OpenUpgradeCodesKey(szUpgradeCode, &hkey, FALSE);
1305     if (r != ERROR_SUCCESS)
1306         return ERROR_NO_MORE_ITEMS;
1307
1308     r = RegEnumValueW(hkey, iProductIndex, szKeyName, &dwSize, NULL, NULL, NULL, NULL);
1309     if( r == ERROR_SUCCESS )
1310         unsquash_guid(szKeyName, lpProductBuf);
1311     RegCloseKey(hkey);
1312
1313     return r;
1314 }
1315
1316 /*************************************************************************
1317  *  MsiEnumRelatedProductsA   [MSI.@]
1318  *
1319  */
1320 UINT WINAPI MsiEnumRelatedProductsA(LPCSTR szUpgradeCode, DWORD dwReserved,
1321                                     DWORD iProductIndex, LPSTR lpProductBuf)
1322 {
1323     LPWSTR szwUpgradeCode = NULL;
1324     WCHAR productW[GUID_SIZE];
1325     UINT r;
1326
1327     TRACE("%s %u %u %p\n", debugstr_a(szUpgradeCode), dwReserved,
1328           iProductIndex, lpProductBuf);
1329
1330     if (szUpgradeCode)
1331     {
1332         szwUpgradeCode = strdupAtoW( szUpgradeCode );
1333         if( !szwUpgradeCode )
1334             return ERROR_OUTOFMEMORY;
1335     }
1336
1337     r = MsiEnumRelatedProductsW( szwUpgradeCode, dwReserved,
1338                                  iProductIndex, productW );
1339     if (r == ERROR_SUCCESS)
1340     {
1341         WideCharToMultiByte( CP_ACP, 0, productW, GUID_SIZE,
1342                              lpProductBuf, GUID_SIZE, NULL, NULL );
1343     }
1344     msi_free( szwUpgradeCode);
1345     return r;
1346 }
1347
1348 /***********************************************************************
1349  * MsiEnumPatchesA            [MSI.@]
1350  */
1351 UINT WINAPI MsiEnumPatchesA( LPCSTR szProduct, DWORD iPatchIndex,
1352         LPSTR lpPatchBuf, LPSTR lpTransformsBuf, DWORD* pcchTransformsBuf)
1353 {
1354     FIXME("%s %d %p %p %p\n", debugstr_a(szProduct),
1355           iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1356     return ERROR_NO_MORE_ITEMS;
1357 }
1358
1359 /***********************************************************************
1360  * MsiEnumPatchesW            [MSI.@]
1361  */
1362 UINT WINAPI MsiEnumPatchesW( LPCWSTR szProduct, DWORD iPatchIndex,
1363         LPWSTR lpPatchBuf, LPWSTR lpTransformsBuf, DWORD* pcchTransformsBuf)
1364 {
1365     FIXME("%s %d %p %p %p\n", debugstr_w(szProduct),
1366           iPatchIndex, lpPatchBuf, lpTransformsBuf, pcchTransformsBuf);
1367     return ERROR_NO_MORE_ITEMS;
1368 }
1369
1370 UINT WINAPI MsiEnumProductsExA( LPCSTR szProductCode, LPCSTR szUserSid,
1371         DWORD dwContext, DWORD dwIndex, LPSTR szInstalledProductCode,
1372         MSIINSTALLCONTEXT* pdwInstalledContext, LPSTR szSid, LPDWORD pcchSid)
1373 {
1374     FIXME("%s %s %d %d %p %p %p %p\n", debugstr_a(szProductCode), debugstr_a(szUserSid),
1375           dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
1376           szSid, pcchSid);
1377     return ERROR_NO_MORE_ITEMS;
1378 }
1379
1380 UINT WINAPI MsiEnumProductsExW( LPCWSTR szProductCode, LPCWSTR szUserSid,
1381         DWORD dwContext, DWORD dwIndex, LPWSTR szInstalledProductCode,
1382         MSIINSTALLCONTEXT* pdwInstalledContext, LPWSTR szSid, LPDWORD pcchSid)
1383 {
1384     FIXME("%s %s %d %d %p %p %p %p\n", debugstr_w(szProductCode), debugstr_w(szUserSid),
1385           dwContext, dwIndex, szInstalledProductCode, pdwInstalledContext,
1386           szSid, pcchSid);
1387     return ERROR_NO_MORE_ITEMS;
1388 }