wintrust: Implement WintrustLoadFunctionPointers.
[wine] / dlls / setupapi / misc.c
1 /*
2  * Setupapi miscellaneous functions
3  *
4  * Copyright 2005 Eric Kohl
5  * Copyright 2007 Hans Leidekker
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 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "setupapi.h"
30 #include "lzexpand.h"
31
32 #include "wine/unicode.h"
33 #include "wine/debug.h"
34
35 #include "setupapi_private.h"
36
37
38 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
39
40 /* arbitrary limit not related to what native actually uses */
41 #define OEM_INDEX_LIMIT 999
42
43 /**************************************************************************
44  * MyFree [SETUPAPI.@]
45  *
46  * Frees an allocated memory block from the process heap.
47  *
48  * PARAMS
49  *     lpMem [I] pointer to memory block which will be freed
50  *
51  * RETURNS
52  *     None
53  */
54 VOID WINAPI MyFree(LPVOID lpMem)
55 {
56     HeapFree(GetProcessHeap(), 0, lpMem);
57 }
58
59
60 /**************************************************************************
61  * MyMalloc [SETUPAPI.@]
62  *
63  * Allocates memory block from the process heap.
64  *
65  * PARAMS
66  *     dwSize [I] size of the allocated memory block
67  *
68  * RETURNS
69  *     Success: pointer to allocated memory block
70  *     Failure: NULL
71  */
72 LPVOID WINAPI MyMalloc(DWORD dwSize)
73 {
74     return HeapAlloc(GetProcessHeap(), 0, dwSize);
75 }
76
77
78 /**************************************************************************
79  * MyRealloc [SETUPAPI.@]
80  *
81  * Changes the size of an allocated memory block or allocates a memory
82  * block from the process heap.
83  *
84  * PARAMS
85  *     lpSrc  [I] pointer to memory block which will be resized
86  *     dwSize [I] new size of the memory block
87  *
88  * RETURNS
89  *     Success: pointer to the resized memory block
90  *     Failure: NULL
91  *
92  * NOTES
93  *     If lpSrc is a NULL-pointer, then MyRealloc allocates a memory
94  *     block like MyMalloc.
95  */
96 LPVOID WINAPI MyRealloc(LPVOID lpSrc, DWORD dwSize)
97 {
98     if (lpSrc == NULL)
99         return HeapAlloc(GetProcessHeap(), 0, dwSize);
100
101     return HeapReAlloc(GetProcessHeap(), 0, lpSrc, dwSize);
102 }
103
104
105 /**************************************************************************
106  * DuplicateString [SETUPAPI.@]
107  *
108  * Duplicates a unicode string.
109  *
110  * PARAMS
111  *     lpSrc  [I] pointer to the unicode string that will be duplicated
112  *
113  * RETURNS
114  *     Success: pointer to the duplicated unicode string
115  *     Failure: NULL
116  *
117  * NOTES
118  *     Call MyFree() to release the duplicated string.
119  */
120 LPWSTR WINAPI DuplicateString(LPCWSTR lpSrc)
121 {
122     LPWSTR lpDst;
123
124     lpDst = MyMalloc((lstrlenW(lpSrc) + 1) * sizeof(WCHAR));
125     if (lpDst == NULL)
126         return NULL;
127
128     strcpyW(lpDst, lpSrc);
129
130     return lpDst;
131 }
132
133
134 /**************************************************************************
135  * QueryRegistryValue [SETUPAPI.@]
136  *
137  * Retrieves value data from the registry and allocates memory for the
138  * value data.
139  *
140  * PARAMS
141  *     hKey        [I] Handle of the key to query
142  *     lpValueName [I] Name of value under hkey to query
143  *     lpData      [O] Destination for the values contents,
144  *     lpType      [O] Destination for the value type
145  *     lpcbData    [O] Destination for the size of data
146  *
147  * RETURNS
148  *     Success: ERROR_SUCCESS
149  *     Failure: Otherwise
150  *
151  * NOTES
152  *     Use MyFree to release the lpData buffer.
153  */
154 LONG WINAPI QueryRegistryValue(HKEY hKey,
155                                LPCWSTR lpValueName,
156                                LPBYTE  *lpData,
157                                LPDWORD lpType,
158                                LPDWORD lpcbData)
159 {
160     LONG lError;
161
162     TRACE("%p %s %p %p %p\n",
163           hKey, debugstr_w(lpValueName), lpData, lpType, lpcbData);
164
165     /* Get required buffer size */
166     *lpcbData = 0;
167     lError = RegQueryValueExW(hKey, lpValueName, 0, lpType, NULL, lpcbData);
168     if (lError != ERROR_SUCCESS)
169         return lError;
170
171     /* Allocate buffer */
172     *lpData = MyMalloc(*lpcbData);
173     if (*lpData == NULL)
174         return ERROR_NOT_ENOUGH_MEMORY;
175
176     /* Query registry value */
177     lError = RegQueryValueExW(hKey, lpValueName, 0, lpType, *lpData, lpcbData);
178     if (lError != ERROR_SUCCESS)
179         MyFree(*lpData);
180
181     return lError;
182 }
183
184
185 /**************************************************************************
186  * IsUserAdmin [SETUPAPI.@]
187  *
188  * Checks whether the current user is a member of the Administrators group.
189  *
190  * PARAMS
191  *     None
192  *
193  * RETURNS
194  *     Success: TRUE
195  *     Failure: FALSE
196  */
197 BOOL WINAPI IsUserAdmin(VOID)
198 {
199     SID_IDENTIFIER_AUTHORITY Authority = {SECURITY_NT_AUTHORITY};
200     HANDLE hToken;
201     DWORD dwSize;
202     PTOKEN_GROUPS lpGroups;
203     PSID lpSid;
204     DWORD i;
205     BOOL bResult = FALSE;
206
207     TRACE("\n");
208
209     if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
210     {
211         return FALSE;
212     }
213
214     if (!GetTokenInformation(hToken, TokenGroups, NULL, 0, &dwSize))
215     {
216         if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
217         {
218             CloseHandle(hToken);
219             return FALSE;
220         }
221     }
222
223     lpGroups = MyMalloc(dwSize);
224     if (lpGroups == NULL)
225     {
226         CloseHandle(hToken);
227         return FALSE;
228     }
229
230     if (!GetTokenInformation(hToken, TokenGroups, lpGroups, dwSize, &dwSize))
231     {
232         MyFree(lpGroups);
233         CloseHandle(hToken);
234         return FALSE;
235     }
236
237     CloseHandle(hToken);
238
239     if (!AllocateAndInitializeSid(&Authority, 2, SECURITY_BUILTIN_DOMAIN_RID,
240                                   DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
241                                   &lpSid))
242     {
243         MyFree(lpGroups);
244         return FALSE;
245     }
246
247     for (i = 0; i < lpGroups->GroupCount; i++)
248     {
249         if (EqualSid(lpSid, lpGroups->Groups[i].Sid))
250         {
251             bResult = TRUE;
252             break;
253         }
254     }
255
256     FreeSid(lpSid);
257     MyFree(lpGroups);
258
259     return bResult;
260 }
261
262
263 /**************************************************************************
264  * MultiByteToUnicode [SETUPAPI.@]
265  *
266  * Converts a multi-byte string to a Unicode string.
267  *
268  * PARAMS
269  *     lpMultiByteStr  [I] Multi-byte string to be converted
270  *     uCodePage       [I] Code page
271  *
272  * RETURNS
273  *     Success: pointer to the converted Unicode string
274  *     Failure: NULL
275  *
276  * NOTE
277  *     Use MyFree to release the returned Unicode string.
278  */
279 LPWSTR WINAPI MultiByteToUnicode(LPCSTR lpMultiByteStr, UINT uCodePage)
280 {
281     LPWSTR lpUnicodeStr;
282     int nLength;
283
284     nLength = MultiByteToWideChar(uCodePage, 0, lpMultiByteStr,
285                                   -1, NULL, 0);
286     if (nLength == 0)
287         return NULL;
288
289     lpUnicodeStr = MyMalloc(nLength * sizeof(WCHAR));
290     if (lpUnicodeStr == NULL)
291         return NULL;
292
293     if (!MultiByteToWideChar(uCodePage, 0, lpMultiByteStr,
294                              nLength, lpUnicodeStr, nLength))
295     {
296         MyFree(lpUnicodeStr);
297         return NULL;
298     }
299
300     return lpUnicodeStr;
301 }
302
303
304 /**************************************************************************
305  * UnicodeToMultiByte [SETUPAPI.@]
306  *
307  * Converts a Unicode string to a multi-byte string.
308  *
309  * PARAMS
310  *     lpUnicodeStr  [I] Unicode string to be converted
311  *     uCodePage     [I] Code page
312  *
313  * RETURNS
314  *     Success: pointer to the converted multi-byte string
315  *     Failure: NULL
316  *
317  * NOTE
318  *     Use MyFree to release the returned multi-byte string.
319  */
320 LPSTR WINAPI UnicodeToMultiByte(LPCWSTR lpUnicodeStr, UINT uCodePage)
321 {
322     LPSTR lpMultiByteStr;
323     int nLength;
324
325     nLength = WideCharToMultiByte(uCodePage, 0, lpUnicodeStr, -1,
326                                   NULL, 0, NULL, NULL);
327     if (nLength == 0)
328         return NULL;
329
330     lpMultiByteStr = MyMalloc(nLength);
331     if (lpMultiByteStr == NULL)
332         return NULL;
333
334     if (!WideCharToMultiByte(uCodePage, 0, lpUnicodeStr, -1,
335                              lpMultiByteStr, nLength, NULL, NULL))
336     {
337         MyFree(lpMultiByteStr);
338         return NULL;
339     }
340
341     return lpMultiByteStr;
342 }
343
344
345 /**************************************************************************
346  * DoesUserHavePrivilege [SETUPAPI.@]
347  *
348  * Check whether the current user has got a given privilege.
349  *
350  * PARAMS
351  *     lpPrivilegeName  [I] Name of the privilege to be checked
352  *
353  * RETURNS
354  *     Success: TRUE
355  *     Failure: FALSE
356  */
357 BOOL WINAPI DoesUserHavePrivilege(LPCWSTR lpPrivilegeName)
358 {
359     HANDLE hToken;
360     DWORD dwSize;
361     PTOKEN_PRIVILEGES lpPrivileges;
362     LUID PrivilegeLuid;
363     DWORD i;
364     BOOL bResult = FALSE;
365
366     TRACE("%s\n", debugstr_w(lpPrivilegeName));
367
368     if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
369         return FALSE;
370
371     if (!GetTokenInformation(hToken, TokenPrivileges, NULL, 0, &dwSize))
372     {
373         if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
374         {
375             CloseHandle(hToken);
376             return FALSE;
377         }
378     }
379
380     lpPrivileges = MyMalloc(dwSize);
381     if (lpPrivileges == NULL)
382     {
383         CloseHandle(hToken);
384         return FALSE;
385     }
386
387     if (!GetTokenInformation(hToken, TokenPrivileges, lpPrivileges, dwSize, &dwSize))
388     {
389         MyFree(lpPrivileges);
390         CloseHandle(hToken);
391         return FALSE;
392     }
393
394     CloseHandle(hToken);
395
396     if (!LookupPrivilegeValueW(NULL, lpPrivilegeName, &PrivilegeLuid))
397     {
398         MyFree(lpPrivileges);
399         return FALSE;
400     }
401
402     for (i = 0; i < lpPrivileges->PrivilegeCount; i++)
403     {
404         if (lpPrivileges->Privileges[i].Luid.HighPart == PrivilegeLuid.HighPart &&
405             lpPrivileges->Privileges[i].Luid.LowPart == PrivilegeLuid.LowPart)
406         {
407             bResult = TRUE;
408         }
409     }
410
411     MyFree(lpPrivileges);
412
413     return bResult;
414 }
415
416
417 /**************************************************************************
418  * EnablePrivilege [SETUPAPI.@]
419  *
420  * Enables or disables one of the current users privileges.
421  *
422  * PARAMS
423  *     lpPrivilegeName  [I] Name of the privilege to be changed
424  *     bEnable          [I] TRUE: Enables the privilege
425  *                          FALSE: Disables the privilege
426  *
427  * RETURNS
428  *     Success: TRUE
429  *     Failure: FALSE
430  */
431 BOOL WINAPI EnablePrivilege(LPCWSTR lpPrivilegeName, BOOL bEnable)
432 {
433     TOKEN_PRIVILEGES Privileges;
434     HANDLE hToken;
435     BOOL bResult;
436
437     TRACE("%s %s\n", debugstr_w(lpPrivilegeName), bEnable ? "TRUE" : "FALSE");
438
439     if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
440         return FALSE;
441
442     Privileges.PrivilegeCount = 1;
443     Privileges.Privileges[0].Attributes = (bEnable) ? SE_PRIVILEGE_ENABLED : 0;
444
445     if (!LookupPrivilegeValueW(NULL, lpPrivilegeName,
446                                &Privileges.Privileges[0].Luid))
447     {
448         CloseHandle(hToken);
449         return FALSE;
450     }
451
452     bResult = AdjustTokenPrivileges(hToken, FALSE, &Privileges, 0, NULL, NULL);
453
454     CloseHandle(hToken);
455
456     return bResult;
457 }
458
459
460 /**************************************************************************
461  * DelayedMove [SETUPAPI.@]
462  *
463  * Moves a file upon the next reboot.
464  *
465  * PARAMS
466  *     lpExistingFileName  [I] Current file name
467  *     lpNewFileName       [I] New file name
468  *
469  * RETURNS
470  *     Success: TRUE
471  *     Failure: FALSE
472  */
473 BOOL WINAPI DelayedMove(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName)
474 {
475     return MoveFileExW(lpExistingFileName, lpNewFileName,
476                        MOVEFILE_REPLACE_EXISTING | MOVEFILE_DELAY_UNTIL_REBOOT);
477 }
478
479
480 /**************************************************************************
481  * FileExists [SETUPAPI.@]
482  *
483  * Checks whether a file exists.
484  *
485  * PARAMS
486  *     lpFileName     [I] Name of the file to check
487  *     lpNewFileName  [O] Optional information about the existing file
488  *
489  * RETURNS
490  *     Success: TRUE
491  *     Failure: FALSE
492  */
493 BOOL WINAPI FileExists(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFileFindData)
494 {
495     WIN32_FIND_DATAW FindData;
496     HANDLE hFind;
497     UINT uErrorMode;
498     DWORD dwError;
499
500     uErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
501
502     hFind = FindFirstFileW(lpFileName, &FindData);
503     if (hFind == INVALID_HANDLE_VALUE)
504     {
505         dwError = GetLastError();
506         SetErrorMode(uErrorMode);
507         SetLastError(dwError);
508         return FALSE;
509     }
510
511     FindClose(hFind);
512
513     if (lpFileFindData)
514         memcpy(lpFileFindData, &FindData, sizeof(WIN32_FIND_DATAW));
515
516     SetErrorMode(uErrorMode);
517
518     return TRUE;
519 }
520
521
522 /**************************************************************************
523  * CaptureStringArg [SETUPAPI.@]
524  *
525  * Captures a UNICODE string.
526  *
527  * PARAMS
528  *     lpSrc  [I] UNICODE string to be captured
529  *     lpDst  [O] Pointer to the captured UNICODE string
530  *
531  * RETURNS
532  *     Success: ERROR_SUCCESS
533  *     Failure: ERROR_INVALID_PARAMETER
534  *
535  * NOTE
536  *     Call MyFree to release the captured UNICODE string.
537  */
538 DWORD WINAPI CaptureStringArg(LPCWSTR pSrc, LPWSTR *pDst)
539 {
540     if (pDst == NULL)
541         return ERROR_INVALID_PARAMETER;
542
543     *pDst = DuplicateString(pSrc);
544
545     return ERROR_SUCCESS;
546 }
547
548
549 /**************************************************************************
550  * CaptureAndConvertAnsiArg [SETUPAPI.@]
551  *
552  * Captures an ANSI string and converts it to a UNICODE string.
553  *
554  * PARAMS
555  *     lpSrc  [I] ANSI string to be captured
556  *     lpDst  [O] Pointer to the captured UNICODE string
557  *
558  * RETURNS
559  *     Success: ERROR_SUCCESS
560  *     Failure: ERROR_INVALID_PARAMETER
561  *
562  * NOTE
563  *     Call MyFree to release the captured UNICODE string.
564  */
565 DWORD WINAPI CaptureAndConvertAnsiArg(LPCSTR pSrc, LPWSTR *pDst)
566 {
567     if (pDst == NULL)
568         return ERROR_INVALID_PARAMETER;
569
570     *pDst = MultiByteToUnicode(pSrc, CP_ACP);
571
572     return ERROR_SUCCESS;
573 }
574
575
576 /**************************************************************************
577  * OpenAndMapFileForRead [SETUPAPI.@]
578  *
579  * Open and map a file to a buffer.
580  *
581  * PARAMS
582  *     lpFileName [I] Name of the file to be opened
583  *     lpSize     [O] Pointer to the file size
584  *     lpFile     [0] Pointer to the file handle
585  *     lpMapping  [0] Pointer to the mapping handle
586  *     lpBuffer   [0] Pointer to the file buffer
587  *
588  * RETURNS
589  *     Success: ERROR_SUCCESS
590  *     Failure: Other
591  *
592  * NOTE
593  *     Call UnmapAndCloseFile to release the file.
594  */
595 DWORD WINAPI OpenAndMapFileForRead(LPCWSTR lpFileName,
596                                    LPDWORD lpSize,
597                                    LPHANDLE lpFile,
598                                    LPHANDLE lpMapping,
599                                    LPVOID *lpBuffer)
600 {
601     DWORD dwError;
602
603     TRACE("%s %p %p %p %p\n",
604           debugstr_w(lpFileName), lpSize, lpFile, lpMapping, lpBuffer);
605
606     *lpFile = CreateFileW(lpFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
607                           OPEN_EXISTING, 0, NULL);
608     if (*lpFile == INVALID_HANDLE_VALUE)
609         return GetLastError();
610
611     *lpSize = GetFileSize(*lpFile, NULL);
612     if (*lpSize == INVALID_FILE_SIZE)
613     {
614         dwError = GetLastError();
615         CloseHandle(*lpFile);
616         return dwError;
617     }
618
619     *lpMapping = CreateFileMappingW(*lpFile, NULL, PAGE_READONLY, 0,
620                                     *lpSize, NULL);
621     if (*lpMapping == NULL)
622     {
623         dwError = GetLastError();
624         CloseHandle(*lpFile);
625         return dwError;
626     }
627
628     *lpBuffer = MapViewOfFile(*lpMapping, FILE_MAP_READ, 0, 0, *lpSize);
629     if (*lpBuffer == NULL)
630     {
631         dwError = GetLastError();
632         CloseHandle(*lpMapping);
633         CloseHandle(*lpFile);
634         return dwError;
635     }
636
637     return ERROR_SUCCESS;
638 }
639
640
641 /**************************************************************************
642  * UnmapAndCloseFile [SETUPAPI.@]
643  *
644  * Unmap and close a mapped file.
645  *
646  * PARAMS
647  *     hFile    [I] Handle to the file
648  *     hMapping [I] Handle to the file mapping
649  *     lpBuffer [I] Pointer to the file buffer
650  *
651  * RETURNS
652  *     Success: TRUE
653  *     Failure: FALSE
654  */
655 BOOL WINAPI UnmapAndCloseFile(HANDLE hFile, HANDLE hMapping, LPVOID lpBuffer)
656 {
657     TRACE("%p %p %p\n",
658           hFile, hMapping, lpBuffer);
659
660     if (!UnmapViewOfFile(lpBuffer))
661         return FALSE;
662
663     if (!CloseHandle(hMapping))
664         return FALSE;
665
666     if (!CloseHandle(hFile))
667         return FALSE;
668
669     return TRUE;
670 }
671
672
673 /**************************************************************************
674  * StampFileSecurity [SETUPAPI.@]
675  *
676  * Assign a new security descriptor to the given file.
677  *
678  * PARAMS
679  *     lpFileName          [I] Name of the file
680  *     pSecurityDescriptor [I] New security descriptor
681  *
682  * RETURNS
683  *     Success: ERROR_SUCCESS
684  *     Failure: other
685  */
686 DWORD WINAPI StampFileSecurity(LPCWSTR lpFileName, PSECURITY_DESCRIPTOR pSecurityDescriptor)
687 {
688     TRACE("%s %p\n", debugstr_w(lpFileName), pSecurityDescriptor);
689
690     if (!SetFileSecurityW(lpFileName, OWNER_SECURITY_INFORMATION |
691                           GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
692                           pSecurityDescriptor))
693         return GetLastError();
694
695     return ERROR_SUCCESS;
696 }
697
698
699 /**************************************************************************
700  * TakeOwnershipOfFile [SETUPAPI.@]
701  *
702  * Takes the ownership of the given file.
703  *
704  * PARAMS
705  *     lpFileName [I] Name of the file
706  *
707  * RETURNS
708  *     Success: ERROR_SUCCESS
709  *     Failure: other
710  */
711 DWORD WINAPI TakeOwnershipOfFile(LPCWSTR lpFileName)
712 {
713     SECURITY_DESCRIPTOR SecDesc;
714     HANDLE hToken = NULL;
715     PTOKEN_OWNER pOwner = NULL;
716     DWORD dwError;
717     DWORD dwSize;
718
719     TRACE("%s\n", debugstr_w(lpFileName));
720
721     if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
722         return GetLastError();
723
724     if (!GetTokenInformation(hToken, TokenOwner, NULL, 0, &dwSize))
725     {
726         goto fail;
727     }
728
729     pOwner = (PTOKEN_OWNER)MyMalloc(dwSize);
730     if (pOwner == NULL)
731     {
732         CloseHandle(hToken);
733         return ERROR_NOT_ENOUGH_MEMORY;
734     }
735
736     if (!GetTokenInformation(hToken, TokenOwner, pOwner, dwSize, &dwSize))
737     {
738         goto fail;
739     }
740
741     if (!InitializeSecurityDescriptor(&SecDesc, SECURITY_DESCRIPTOR_REVISION))
742     {
743         goto fail;
744     }
745
746     if (!SetSecurityDescriptorOwner(&SecDesc, pOwner->Owner, FALSE))
747     {
748         goto fail;
749     }
750
751     if (!SetFileSecurityW(lpFileName, OWNER_SECURITY_INFORMATION, &SecDesc))
752     {
753         goto fail;
754     }
755
756     MyFree(pOwner);
757     CloseHandle(hToken);
758
759     return ERROR_SUCCESS;
760
761 fail:;
762     dwError = GetLastError();
763
764     MyFree(pOwner);
765
766     if (hToken != NULL)
767         CloseHandle(hToken);
768
769     return dwError;
770 }
771
772
773 /**************************************************************************
774  * RetreiveFileSecurity [SETUPAPI.@]
775  *
776  * Retrieve the security descriptor that is associated with the given file.
777  *
778  * PARAMS
779  *     lpFileName [I] Name of the file
780  *
781  * RETURNS
782  *     Success: ERROR_SUCCESS
783  *     Failure: other
784  */
785 DWORD WINAPI RetreiveFileSecurity(LPCWSTR lpFileName,
786                                   PSECURITY_DESCRIPTOR *pSecurityDescriptor)
787 {
788     PSECURITY_DESCRIPTOR SecDesc;
789     DWORD dwSize = 0x100;
790     DWORD dwError;
791
792     SecDesc = (PSECURITY_DESCRIPTOR)MyMalloc(dwSize);
793     if (SecDesc == NULL)
794         return ERROR_NOT_ENOUGH_MEMORY;
795
796     if (GetFileSecurityW(lpFileName, OWNER_SECURITY_INFORMATION |
797                          GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
798                          SecDesc, dwSize, &dwSize))
799     {
800       *pSecurityDescriptor = SecDesc;
801       return ERROR_SUCCESS;
802     }
803
804     dwError = GetLastError();
805     if (dwError != ERROR_INSUFFICIENT_BUFFER)
806     {
807         MyFree(SecDesc);
808         return dwError;
809     }
810
811     SecDesc = (PSECURITY_DESCRIPTOR)MyRealloc(SecDesc, dwSize);
812     if (SecDesc == NULL)
813         return ERROR_NOT_ENOUGH_MEMORY;
814
815     if (GetFileSecurityW(lpFileName, OWNER_SECURITY_INFORMATION |
816                          GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
817                          SecDesc, dwSize, &dwSize))
818     {
819       *pSecurityDescriptor = SecDesc;
820       return ERROR_SUCCESS;
821     }
822
823     dwError = GetLastError();
824     MyFree(SecDesc);
825
826     return dwError;
827 }
828
829
830 static DWORD global_flags = 0;  /* FIXME: what should be in here? */
831
832 /***********************************************************************
833  *              pSetupGetGlobalFlags  (SETUPAPI.@)
834  */
835 DWORD WINAPI pSetupGetGlobalFlags(void)
836 {
837     FIXME( "stub\n" );
838     return global_flags;
839 }
840
841
842 /***********************************************************************
843  *              pSetupSetGlobalFlags  (SETUPAPI.@)
844  */
845 void WINAPI pSetupSetGlobalFlags( DWORD flags )
846 {
847     global_flags = flags;
848 }
849
850 /***********************************************************************
851  *              CMP_WaitNoPendingInstallEvents  (SETUPAPI.@)
852  */
853 DWORD WINAPI CMP_WaitNoPendingInstallEvents( DWORD dwTimeout )
854 {
855     FIXME("%d\n", dwTimeout);
856     return WAIT_OBJECT_0;
857 }
858
859 /***********************************************************************
860  *              AssertFail  (SETUPAPI.@)
861  *
862  * Shows an assert fail error messagebox
863  *
864  * PARAMS
865  *   lpFile [I]         file where assert failed
866  *   uLine [I]          line number in file
867  *   lpMessage [I]      assert message
868  *
869  */
870 void WINAPI AssertFail(LPCSTR lpFile, UINT uLine, LPCSTR lpMessage)
871 {
872     FIXME("%s %u %s\n", lpFile, uLine, lpMessage);
873 }
874
875 /***********************************************************************
876  *      SetupCopyOEMInfA  (SETUPAPI.@)
877  */
878 BOOL WINAPI SetupCopyOEMInfA( PCSTR source, PCSTR location,
879                               DWORD media_type, DWORD style, PSTR dest,
880                               DWORD buffer_size, PDWORD required_size, PSTR *component )
881 {
882     BOOL ret = FALSE;
883     LPWSTR destW = NULL, sourceW = NULL, locationW = NULL;
884     DWORD size;
885
886     TRACE("%s, %s, %d, %d, %p, %d, %p, %p\n", debugstr_a(source), debugstr_a(location),
887           media_type, style, dest, buffer_size, required_size, component);
888
889     if (dest && !(destW = MyMalloc( buffer_size * sizeof(WCHAR) ))) return FALSE;
890     if (source && !(sourceW = strdupAtoW( source ))) goto done;
891     if (location && !(locationW = strdupAtoW( location ))) goto done;
892
893     if (!(ret = SetupCopyOEMInfW( sourceW, locationW, media_type, style, destW,
894                                   buffer_size, &size, NULL )))
895     {
896         if (required_size) *required_size = size;
897         goto done;
898     }
899
900     if (dest)
901     {
902         if (buffer_size >= size)
903         {
904             WideCharToMultiByte( CP_ACP, 0, destW, -1, dest, buffer_size, NULL, NULL );
905             if (component) *component = strrchr( dest, '\\' ) + 1;
906         }
907         else
908         {
909             SetLastError( ERROR_INSUFFICIENT_BUFFER );
910             goto done;
911         }
912     }
913
914 done:
915     MyFree( destW );
916     HeapFree( GetProcessHeap(), 0, sourceW );
917     HeapFree( GetProcessHeap(), 0, locationW );
918     if (ret) SetLastError(ERROR_SUCCESS);
919     return ret;
920 }
921
922 /***********************************************************************
923  *      SetupCopyOEMInfW  (SETUPAPI.@)
924  */
925 BOOL WINAPI SetupCopyOEMInfW( PCWSTR source, PCWSTR location,
926                               DWORD media_type, DWORD style, PWSTR dest,
927                               DWORD buffer_size, PDWORD required_size, PWSTR *component )
928 {
929     BOOL ret = FALSE;
930     WCHAR target[MAX_PATH], *p;
931     static const WCHAR inf[] = { '\\','i','n','f','\\',0 };
932     DWORD size;
933
934     TRACE("%s, %s, %d, %d, %p, %d, %p, %p\n", debugstr_w(source), debugstr_w(location),
935           media_type, style, dest, buffer_size, required_size, component);
936
937     if (!source)
938     {
939         SetLastError(ERROR_INVALID_PARAMETER);
940         return FALSE;
941     }
942
943     /* check for a relative path */
944     if (!(*source == '\\' || (*source && source[1] == ':')))
945     {
946         SetLastError(ERROR_FILE_NOT_FOUND);
947         return FALSE;
948     }
949
950     if (!GetWindowsDirectoryW( target, sizeof(target)/sizeof(WCHAR) )) return FALSE;
951
952     strcatW( target, inf );
953     if ((p = strrchrW( source, '\\' )))
954         strcatW( target, p + 1 );
955
956     /* does the file exist already? */
957     if ((GetFileAttributesW( target ) != INVALID_FILE_ATTRIBUTES) &&
958         !(style & SP_COPY_NOOVERWRITE))
959     {
960         static const WCHAR oem[] = { 'o','e','m',0 };
961         unsigned int i;
962
963         p = strrchrW( target, '\\' ) + 1;
964         memcpy( p, oem, sizeof(oem) );
965         p += sizeof(oem)/sizeof(oem[0]) - 1;
966
967         /* generate OEMnnn.inf ending */
968         for (i = 0; i < OEM_INDEX_LIMIT; i++)
969         {
970             static const WCHAR format[] = { '%','u','.','i','n','f',0 };
971             wsprintfW( p, format, i );
972             /* if we found a file name that doesn't exist then we're done */
973             if (GetFileAttributesW( target ) == INVALID_FILE_ATTRIBUTES)
974                 break;
975         }
976
977         if (i == OEM_INDEX_LIMIT)
978         {
979             SetLastError( ERROR_FILENAME_EXCED_RANGE );
980             return FALSE;
981         }
982     }
983
984     if (!(ret = CopyFileW( source, target, (style & SP_COPY_NOOVERWRITE) != 0 )))
985         return ret;
986
987     if (style & SP_COPY_DELETESOURCE)
988         DeleteFileW( source );
989
990     size = strlenW( target ) + 1;
991     if (dest)
992     {
993         if (buffer_size >= size)
994         {
995             strcpyW( dest, target );
996         }
997         else
998         {
999             SetLastError( ERROR_INSUFFICIENT_BUFFER );
1000             ret = FALSE;
1001         }
1002     }
1003
1004     if (component) *component = p + 1;
1005     if (required_size) *required_size = size;
1006     if (ret) SetLastError(ERROR_SUCCESS);
1007
1008     return ret;
1009 }
1010
1011 /***********************************************************************
1012  *      InstallCatalog  (SETUPAPI.@)
1013  */
1014 DWORD WINAPI InstallCatalog( LPCSTR catalog, LPCSTR basename, LPSTR fullname )
1015 {
1016     FIXME("%s, %s, %p\n", debugstr_a(catalog), debugstr_a(basename), fullname);
1017     return 0;
1018 }
1019
1020 static UINT detect_compression_type( LPCWSTR file )
1021 {
1022     DWORD size;
1023     HANDLE handle;
1024     UINT type = FILE_COMPRESSION_NONE;
1025     static const BYTE LZ_MAGIC[] = { 0x53, 0x5a, 0x44, 0x44, 0x88, 0xf0, 0x27, 0x33 };
1026     static const BYTE MSZIP_MAGIC[] = { 0x4b, 0x57, 0x41, 0x4a };
1027     static const BYTE NTCAB_MAGIC[] = { 0x4d, 0x53, 0x43, 0x46 };
1028     BYTE buffer[8];
1029
1030     handle = CreateFileW( file, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL );
1031     if (handle == INVALID_HANDLE_VALUE)
1032     {
1033         ERR("cannot open file %s\n", debugstr_w(file));
1034         return FILE_COMPRESSION_NONE;
1035     }
1036     if (!ReadFile( handle, buffer, sizeof(buffer), &size, NULL ) || size != sizeof(buffer))
1037     {
1038         CloseHandle( handle );
1039         return FILE_COMPRESSION_NONE;
1040     }
1041     if (!memcmp( buffer, LZ_MAGIC, sizeof(LZ_MAGIC) )) type = FILE_COMPRESSION_WINLZA;
1042     else if (!memcmp( buffer, MSZIP_MAGIC, sizeof(MSZIP_MAGIC) )) type = FILE_COMPRESSION_MSZIP;
1043     else if (!memcmp( buffer, NTCAB_MAGIC, sizeof(NTCAB_MAGIC) )) type = FILE_COMPRESSION_MSZIP; /* not a typo */
1044
1045     CloseHandle( handle );
1046     return type;
1047 }
1048
1049 static BOOL get_file_size( LPCWSTR file, DWORD *size )
1050 {
1051     HANDLE handle;
1052
1053     handle = CreateFileW( file, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL );
1054     if (handle == INVALID_HANDLE_VALUE)
1055     {
1056         ERR("cannot open file %s\n", debugstr_w(file));
1057         return FALSE;
1058     }
1059     *size = GetFileSize( handle, NULL );
1060     CloseHandle( handle );
1061     return TRUE;
1062 }
1063
1064 static BOOL get_file_sizes_none( LPCWSTR source, DWORD *source_size, DWORD *target_size )
1065 {
1066     DWORD size;
1067
1068     if (!get_file_size( source, &size )) return FALSE;
1069     if (source_size) *source_size = size;
1070     if (target_size) *target_size = size;
1071     return TRUE;
1072 }
1073
1074 static BOOL get_file_sizes_lz( LPCWSTR source, DWORD *source_size, DWORD *target_size )
1075 {
1076     DWORD size;
1077     BOOL ret = TRUE;
1078
1079     if (source_size)
1080     {
1081         if (!get_file_size( source, &size )) ret = FALSE;
1082         else *source_size = size;
1083     }
1084     if (target_size)
1085     {
1086         INT file;
1087         OFSTRUCT of;
1088
1089         if ((file = LZOpenFileW( (LPWSTR)source, &of, OF_READ )) < 0)
1090         {
1091             ERR("cannot open source file for reading\n");
1092             return FALSE;
1093         }
1094         *target_size = LZSeek( file, 0, 2 );
1095         LZClose( file );
1096     }
1097     return ret;
1098 }
1099
1100 static UINT CALLBACK file_compression_info_callback( PVOID context, UINT notification, UINT_PTR param1, UINT_PTR param2 )
1101 {
1102     DWORD *size = context;
1103     FILE_IN_CABINET_INFO_W *info = (FILE_IN_CABINET_INFO_W *)param1;
1104
1105     switch (notification)
1106     {
1107     case SPFILENOTIFY_FILEINCABINET:
1108     {
1109         *size = info->FileSize;
1110         return FILEOP_SKIP;
1111     }
1112     default: return NO_ERROR;
1113     }
1114 }
1115
1116 static BOOL get_file_sizes_cab( LPCWSTR source, DWORD *source_size, DWORD *target_size )
1117 {
1118     DWORD size;
1119     BOOL ret = TRUE;
1120
1121     if (source_size)
1122     {
1123         if (!get_file_size( source, &size )) ret = FALSE;
1124         else *source_size = size;
1125     }
1126     if (target_size)
1127     {
1128         ret = SetupIterateCabinetW( source, 0, file_compression_info_callback, target_size );
1129     }
1130     return ret;
1131 }
1132
1133 /***********************************************************************
1134  *      SetupGetFileCompressionInfoExA  (SETUPAPI.@)
1135  *
1136  * See SetupGetFileCompressionInfoExW.
1137  */
1138 BOOL WINAPI SetupGetFileCompressionInfoExA( PCSTR source, PSTR name, DWORD len, PDWORD required,
1139                                             PDWORD source_size, PDWORD target_size, PUINT type )
1140 {
1141     BOOL ret;
1142     WCHAR *nameW = NULL, *sourceW = NULL;
1143     DWORD nb_chars = 0;
1144     LPSTR nameA;
1145
1146     TRACE("%s, %p, %d, %p, %p, %p, %p\n", debugstr_a(source), name, len, required,
1147           source_size, target_size, type);
1148
1149     if (!source || !(sourceW = MultiByteToUnicode( source, CP_ACP ))) return FALSE;
1150
1151     if (name)
1152     {
1153         ret = SetupGetFileCompressionInfoExW( sourceW, NULL, 0, &nb_chars, NULL, NULL, NULL );
1154         if (!(nameW = HeapAlloc( GetProcessHeap(), 0, nb_chars * sizeof(WCHAR) )))
1155         {
1156             MyFree( sourceW );
1157             return FALSE;
1158         }
1159     }
1160     ret = SetupGetFileCompressionInfoExW( sourceW, nameW, nb_chars, &nb_chars, source_size, target_size, type );
1161     if (ret)
1162     {
1163         if ((nameA = UnicodeToMultiByte( nameW, CP_ACP )))
1164         {
1165             if (name && len >= nb_chars) lstrcpyA( name, nameA );
1166             else
1167             {
1168                 SetLastError( ERROR_INSUFFICIENT_BUFFER );
1169                 ret = FALSE;
1170             }
1171             MyFree( nameA );
1172         }
1173     }
1174     if (required) *required = nb_chars;
1175     HeapFree( GetProcessHeap(), 0, nameW );
1176     MyFree( sourceW );
1177
1178     return ret;
1179 }
1180
1181 /***********************************************************************
1182  *      SetupGetFileCompressionInfoExW  (SETUPAPI.@)
1183  *
1184  * Get compression type and compressed/uncompressed sizes of a given file.
1185  *
1186  * PARAMS
1187  *  source      [I] File to examine.
1188  *  name        [O] Actual filename used.
1189  *  len         [I] Length in characters of 'name' buffer.
1190  *  required    [O] Number of characters written to 'name'.
1191  *  source_size [O] Size of compressed file.
1192  *  target_size [O] Size of uncompressed file.
1193  *  type        [O] Compression type.
1194  *
1195  * RETURNS
1196  *  Success: TRUE
1197  *  Failure: FALSE
1198  */
1199 BOOL WINAPI SetupGetFileCompressionInfoExW( PCWSTR source, PWSTR name, DWORD len, PDWORD required,
1200                                             PDWORD source_size, PDWORD target_size, PUINT type )
1201 {
1202     UINT comp;
1203     BOOL ret = FALSE;
1204     DWORD source_len;
1205
1206     TRACE("%s, %p, %d, %p, %p, %p, %p\n", debugstr_w(source), name, len, required,
1207           source_size, target_size, type);
1208
1209     if (!source) return FALSE;
1210
1211     source_len = lstrlenW( source ) + 1;
1212     if (required) *required = source_len;
1213     if (name && len >= source_len)
1214     {
1215         lstrcpyW( name, source );
1216         ret = TRUE;
1217     }
1218     else return FALSE;
1219
1220     comp = detect_compression_type( source );
1221     if (type) *type = comp;
1222
1223     switch (comp)
1224     {
1225     case FILE_COMPRESSION_MSZIP:
1226     case FILE_COMPRESSION_NTCAB:  ret = get_file_sizes_cab( source, source_size, target_size ); break;
1227     case FILE_COMPRESSION_NONE:   ret = get_file_sizes_none( source, source_size, target_size ); break;
1228     case FILE_COMPRESSION_WINLZA: ret = get_file_sizes_lz( source, source_size, target_size ); break;
1229     default: break;
1230     }
1231     return ret;
1232 }
1233
1234 /***********************************************************************
1235  *      SetupGetFileCompressionInfoA  (SETUPAPI.@)
1236  *
1237  * See SetupGetFileCompressionInfoW.
1238  */
1239 DWORD WINAPI SetupGetFileCompressionInfoA( PCSTR source, PSTR *name, PDWORD source_size,
1240                                            PDWORD target_size, PUINT type )
1241 {
1242     BOOL ret;
1243     DWORD error, required;
1244     LPSTR actual_name;
1245
1246     TRACE("%s, %p, %p, %p, %p\n", debugstr_a(source), name, source_size, target_size, type);
1247
1248     if (!source || !name || !source_size || !target_size || !type)
1249         return ERROR_INVALID_PARAMETER;
1250
1251     ret = SetupGetFileCompressionInfoExA( source, NULL, 0, &required, NULL, NULL, NULL );
1252     if (!(actual_name = MyMalloc( required ))) return ERROR_NOT_ENOUGH_MEMORY;
1253
1254     ret = SetupGetFileCompressionInfoExA( source, actual_name, required, &required,
1255                                           source_size, target_size, type );
1256     if (!ret)
1257     {
1258         error = GetLastError();
1259         MyFree( actual_name );
1260         return error;
1261     }
1262     *name = actual_name;
1263     return ERROR_SUCCESS;
1264 }
1265
1266 /***********************************************************************
1267  *      SetupGetFileCompressionInfoW  (SETUPAPI.@)
1268  *
1269  * Get compression type and compressed/uncompressed sizes of a given file.
1270  *
1271  * PARAMS
1272  *  source      [I] File to examine.
1273  *  name        [O] Actual filename used.
1274  *  source_size [O] Size of compressed file.
1275  *  target_size [O] Size of uncompressed file.
1276  *  type        [O] Compression type.
1277  *
1278  * RETURNS
1279  *  Success: ERROR_SUCCESS
1280  *  Failure: Win32 error code.
1281  */
1282 DWORD WINAPI SetupGetFileCompressionInfoW( PCWSTR source, PWSTR *name, PDWORD source_size,
1283                                            PDWORD target_size, PUINT type )
1284 {
1285     BOOL ret;
1286     DWORD error, required;
1287     LPWSTR actual_name;
1288
1289     TRACE("%s, %p, %p, %p, %p\n", debugstr_w(source), name, source_size, target_size, type);
1290
1291     if (!source || !name || !source_size || !target_size || !type)
1292         return ERROR_INVALID_PARAMETER;
1293
1294     ret = SetupGetFileCompressionInfoExW( source, NULL, 0, &required, NULL, NULL, NULL );
1295     if (!(actual_name = MyMalloc( required ))) return ERROR_NOT_ENOUGH_MEMORY;
1296
1297     ret = SetupGetFileCompressionInfoExW( source, actual_name, required, &required,
1298                                           source_size, target_size, type );
1299     if (!ret)
1300     {
1301         error = GetLastError();
1302         MyFree( actual_name );
1303         return error;
1304     }
1305     *name = actual_name;
1306     return ERROR_SUCCESS;
1307 }
1308
1309 static DWORD decompress_file_lz( LPCWSTR source, LPCWSTR target )
1310 {
1311     DWORD ret;
1312     LONG error;
1313     INT src, dst;
1314     OFSTRUCT sof, dof;
1315
1316     if ((src = LZOpenFileW( (LPWSTR)source, &sof, OF_READ )) < 0)
1317     {
1318         ERR("cannot open source file for reading\n");
1319         return ERROR_FILE_NOT_FOUND;
1320     }
1321     if ((dst = LZOpenFileW( (LPWSTR)target, &dof, OF_CREATE )) < 0)
1322     {
1323         ERR("cannot open target file for writing\n");
1324         LZClose( src );
1325         return ERROR_FILE_NOT_FOUND;
1326     }
1327     if ((error = LZCopy( src, dst )) >= 0) ret = ERROR_SUCCESS;
1328     else
1329     {
1330         WARN("failed to decompress file %d\n", error);
1331         ret = ERROR_INVALID_DATA;
1332     }
1333
1334     LZClose( src );
1335     LZClose( dst );
1336     return ret;
1337 }
1338
1339 static UINT CALLBACK decompress_or_copy_callback( PVOID context, UINT notification, UINT_PTR param1, UINT_PTR param2 )
1340 {
1341     FILE_IN_CABINET_INFO_W *info = (FILE_IN_CABINET_INFO_W *)param1;
1342
1343     switch (notification)
1344     {
1345     case SPFILENOTIFY_FILEINCABINET:
1346     {
1347         LPCWSTR filename, targetname = context;
1348         WCHAR *p;
1349
1350         if ((p = strrchrW( targetname, '\\' ))) filename = p + 1;
1351         else filename = targetname;
1352
1353         if (!lstrcmpiW( filename, info->NameInCabinet ))
1354         {
1355             strcpyW( info->FullTargetName, targetname );
1356             return FILEOP_DOIT;
1357         }
1358         return FILEOP_SKIP;
1359     }
1360     default: return NO_ERROR;
1361     }
1362 }
1363
1364 static DWORD decompress_file_cab( LPCWSTR source, LPCWSTR target )
1365 {
1366     BOOL ret;
1367
1368     ret = SetupIterateCabinetW( source, 0, decompress_or_copy_callback, (PVOID)target );
1369
1370     if (ret) return ERROR_SUCCESS;
1371     else return GetLastError();
1372 }
1373
1374 /***********************************************************************
1375  *      SetupDecompressOrCopyFileA  (SETUPAPI.@)
1376  *
1377  * See SetupDecompressOrCopyFileW.
1378  */
1379 DWORD WINAPI SetupDecompressOrCopyFileA( PCSTR source, PCSTR target, PUINT type )
1380 {
1381     DWORD ret = FALSE;
1382     WCHAR *sourceW = NULL, *targetW = NULL;
1383
1384     if (source && !(sourceW = MultiByteToUnicode( source, CP_ACP ))) return FALSE;
1385     if (target && !(targetW = MultiByteToUnicode( target, CP_ACP )))
1386     {
1387         MyFree( sourceW );
1388         return ERROR_NOT_ENOUGH_MEMORY;
1389     }
1390
1391     ret = SetupDecompressOrCopyFileW( sourceW, targetW, type );
1392
1393     MyFree( sourceW );
1394     MyFree( targetW );
1395
1396     return ret;
1397 }
1398
1399 /***********************************************************************
1400  *      SetupDecompressOrCopyFileW  (SETUPAPI.@)
1401  *
1402  * Copy a file and decompress it if needed.
1403  *
1404  * PARAMS
1405  *  source [I] File to copy.
1406  *  target [I] Filename of the copy.
1407  *  type   [I] Compression type.
1408  *
1409  * RETURNS
1410  *  Success: ERROR_SUCCESS
1411  *  Failure: Win32 error code.
1412  */
1413 DWORD WINAPI SetupDecompressOrCopyFileW( PCWSTR source, PCWSTR target, PUINT type )
1414 {
1415     UINT comp;
1416     DWORD ret = ERROR_INVALID_PARAMETER;
1417
1418     if (!source || !target) return ERROR_INVALID_PARAMETER;
1419
1420     if (!type) comp = detect_compression_type( source );
1421     else comp = *type;
1422
1423     switch (comp)
1424     {
1425     case FILE_COMPRESSION_NONE:
1426         if (CopyFileW( source, target, FALSE )) ret = ERROR_SUCCESS;
1427         else ret = GetLastError();
1428         break;
1429     case FILE_COMPRESSION_WINLZA:
1430         ret = decompress_file_lz( source, target );
1431         break;
1432     case FILE_COMPRESSION_NTCAB:
1433     case FILE_COMPRESSION_MSZIP:
1434         ret = decompress_file_cab( source, target );
1435         break;
1436     default:
1437         WARN("unknown compression type %d\n", comp);
1438         break;
1439     }
1440
1441     TRACE("%s -> %s %d\n", debugstr_w(source), debugstr_w(target), comp);
1442     return ret;
1443 }