ntdll/tests: Added more registry symlink tests.
[wine.git] / dlls / msi / custom.c
blob35a1b5c8482da4934c5b27450711ecaeec046284
1 /*
2 * Custom Action processing for the Microsoft Installer (msi.dll)
4 * Copyright 2005 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #define COBJMACROS
26 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "msidefs.h"
31 #include "winuser.h"
32 #include "objbase.h"
33 #include "oleauto.h"
35 #include "msipriv.h"
36 #include "msiserver.h"
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
39 #include "wine/exception.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msi);
43 #define CUSTOM_ACTION_TYPE_MASK 0x3F
45 typedef struct tagMSIRUNNINGACTION
47 struct list entry;
48 HANDLE handle;
49 BOOL process;
50 LPWSTR name;
51 } MSIRUNNINGACTION;
53 typedef UINT (WINAPI *MsiCustomActionEntryPoint)( MSIHANDLE );
55 static CRITICAL_SECTION msi_custom_action_cs;
56 static CRITICAL_SECTION_DEBUG msi_custom_action_cs_debug =
58 0, 0, &msi_custom_action_cs,
59 { &msi_custom_action_cs_debug.ProcessLocksList,
60 &msi_custom_action_cs_debug.ProcessLocksList },
61 0, 0, { (DWORD_PTR)(__FILE__ ": msi_custom_action_cs") }
63 static CRITICAL_SECTION msi_custom_action_cs = { &msi_custom_action_cs_debug, -1, 0, 0, 0, 0 };
65 static struct list msi_pending_custom_actions = LIST_INIT( msi_pending_custom_actions );
67 UINT msi_schedule_action( MSIPACKAGE *package, UINT script, const WCHAR *action )
69 UINT count;
70 WCHAR **newbuf = NULL;
72 if (script >= SCRIPT_MAX)
74 FIXME("Unknown script requested %u\n", script);
75 return ERROR_FUNCTION_FAILED;
77 TRACE("Scheduling action %s in script %u\n", debugstr_w(action), script);
79 count = package->script->ActionCount[script];
80 package->script->ActionCount[script]++;
81 if (count != 0) newbuf = msi_realloc( package->script->Actions[script],
82 package->script->ActionCount[script] * sizeof(WCHAR *) );
83 else newbuf = msi_alloc( sizeof(WCHAR *) );
85 newbuf[count] = strdupW( action );
86 package->script->Actions[script] = newbuf;
87 return ERROR_SUCCESS;
90 UINT msi_register_unique_action( MSIPACKAGE *package, const WCHAR *action )
92 UINT count;
93 WCHAR **newbuf = NULL;
95 if (!package->script) return FALSE;
97 TRACE("Registering %s as unique action\n", debugstr_w(action));
99 count = package->script->UniqueActionsCount;
100 package->script->UniqueActionsCount++;
101 if (count != 0) newbuf = msi_realloc( package->script->UniqueActions,
102 package->script->UniqueActionsCount * sizeof(WCHAR *) );
103 else newbuf = msi_alloc( sizeof(WCHAR *) );
105 newbuf[count] = strdupW( action );
106 package->script->UniqueActions = newbuf;
107 return ERROR_SUCCESS;
110 BOOL msi_action_is_unique( const MSIPACKAGE *package, const WCHAR *action )
112 UINT i;
114 if (!package->script) return FALSE;
116 for (i = 0; i < package->script->UniqueActionsCount; i++)
118 if (!strcmpW( package->script->UniqueActions[i], action )) return TRUE;
120 return FALSE;
123 static BOOL check_execution_scheduling_options(MSIPACKAGE *package, LPCWSTR action, UINT options)
125 if (!package->script)
126 return TRUE;
128 if ((options & msidbCustomActionTypeClientRepeat) ==
129 msidbCustomActionTypeClientRepeat)
131 if (!(package->script->InWhatSequence & SEQUENCE_UI &&
132 package->script->InWhatSequence & SEQUENCE_EXEC))
134 TRACE("Skipping action due to dbCustomActionTypeClientRepeat option.\n");
135 return FALSE;
138 else if (options & msidbCustomActionTypeFirstSequence)
140 if (package->script->InWhatSequence & SEQUENCE_UI &&
141 package->script->InWhatSequence & SEQUENCE_EXEC )
143 TRACE("Skipping action due to msidbCustomActionTypeFirstSequence option.\n");
144 return FALSE;
147 else if (options & msidbCustomActionTypeOncePerProcess)
149 if (msi_action_is_unique(package, action))
151 TRACE("Skipping action due to msidbCustomActionTypeOncePerProcess option.\n");
152 return FALSE;
154 else
155 msi_register_unique_action(package, action);
158 return TRUE;
161 /* stores the following properties before the action:
163 * [CustomActionData<=>UserSID<=>ProductCode]Action
165 static LPWSTR msi_get_deferred_action(LPCWSTR action, LPCWSTR actiondata,
166 LPCWSTR usersid, LPCWSTR prodcode)
168 LPWSTR deferred;
169 DWORD len;
171 static const WCHAR format[] = {
172 '[','%','s','<','=','>','%','s','<','=','>','%','s',']','%','s',0
175 if (!actiondata)
176 return strdupW(action);
178 len = lstrlenW(action) + lstrlenW(actiondata) +
179 lstrlenW(usersid) + lstrlenW(prodcode) +
180 lstrlenW(format) - 7;
181 deferred = msi_alloc(len * sizeof(WCHAR));
183 sprintfW(deferred, format, actiondata, usersid, prodcode, action);
184 return deferred;
187 static void set_deferred_action_props( MSIPACKAGE *package, const WCHAR *deferred_data )
189 static const WCHAR sep[] = {'<','=','>',0};
190 const WCHAR *end, *beg = deferred_data + 1;
192 end = strstrW(beg, sep);
193 msi_set_property( package->db, szCustomActionData, beg, end - beg );
194 beg = end + 3;
196 end = strstrW(beg, sep);
197 msi_set_property( package->db, szUserSID, beg, end - beg );
198 beg = end + 3;
200 end = strchrW(beg, ']');
201 msi_set_property( package->db, szProductCode, beg, end - beg );
204 WCHAR *msi_create_temp_file( MSIDATABASE *db )
206 WCHAR *ret;
208 if (!db->tempfolder)
210 WCHAR tmp[MAX_PATH];
211 UINT len = sizeof(tmp)/sizeof(tmp[0]);
213 if (msi_get_property( db, szTempFolder, tmp, &len ) ||
214 GetFileAttributesW( tmp ) != FILE_ATTRIBUTE_DIRECTORY)
216 GetTempPathW( MAX_PATH, tmp );
218 if (!(db->tempfolder = strdupW( tmp ))) return NULL;
221 if ((ret = msi_alloc( (strlenW( db->tempfolder ) + 20) * sizeof(WCHAR) )))
223 if (!GetTempFileNameW( db->tempfolder, szMsi, 0, ret ))
225 msi_free( ret );
226 return NULL;
230 return ret;
233 static MSIBINARY *create_temp_binary( MSIPACKAGE *package, LPCWSTR source, BOOL dll )
235 static const WCHAR query[] = {
236 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
237 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
238 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
239 MSIRECORD *row;
240 MSIBINARY *binary = NULL;
241 HANDLE file;
242 CHAR buffer[1024];
243 WCHAR *tmpfile;
244 DWORD sz, write;
245 UINT r;
247 if (!(tmpfile = msi_create_temp_file( package->db ))) return NULL;
249 if (!(row = MSI_QueryGetRecord( package->db, query, source ))) goto error;
250 if (!(binary = msi_alloc_zero( sizeof(MSIBINARY) ))) goto error;
252 file = CreateFileW( tmpfile, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
253 if (file == INVALID_HANDLE_VALUE) goto error;
257 sz = sizeof(buffer);
258 r = MSI_RecordReadStream( row, 2, buffer, &sz );
259 if (r != ERROR_SUCCESS)
261 ERR("Failed to get stream\n");
262 break;
264 WriteFile( file, buffer, sz, &write, NULL );
265 } while (sz == sizeof buffer);
267 CloseHandle( file );
268 if (r != ERROR_SUCCESS) goto error;
270 /* keep a reference to prevent the dll from being unloaded */
271 if (dll && !(binary->module = LoadLibraryW( tmpfile )))
273 WARN( "failed to load dll %s (%u)\n", debugstr_w( tmpfile ), GetLastError() );
275 binary->source = strdupW( source );
276 binary->tmpfile = tmpfile;
277 list_add_tail( &package->binaries, &binary->entry );
279 msiobj_release( &row->hdr );
280 return binary;
282 error:
283 if (row) msiobj_release( &row->hdr );
284 DeleteFileW( tmpfile );
285 msi_free( tmpfile );
286 msi_free( binary );
287 return NULL;
290 static MSIBINARY *get_temp_binary( MSIPACKAGE *package, LPCWSTR source, BOOL dll )
292 MSIBINARY *binary;
294 LIST_FOR_EACH_ENTRY( binary, &package->binaries, MSIBINARY, entry )
296 if (!strcmpW( binary->source, source ))
297 return binary;
300 return create_temp_binary( package, source, dll );
303 static void file_running_action(MSIPACKAGE* package, HANDLE Handle,
304 BOOL process, LPCWSTR name)
306 MSIRUNNINGACTION *action;
308 action = msi_alloc( sizeof(MSIRUNNINGACTION) );
310 action->handle = Handle;
311 action->process = process;
312 action->name = strdupW(name);
314 list_add_tail( &package->RunningActions, &action->entry );
317 static UINT custom_get_process_return( HANDLE process )
319 DWORD rc = 0;
321 GetExitCodeProcess( process, &rc );
322 TRACE("exit code is %u\n", rc);
323 if (rc != 0)
324 return ERROR_FUNCTION_FAILED;
325 return ERROR_SUCCESS;
328 static UINT custom_get_thread_return( MSIPACKAGE *package, HANDLE thread )
330 DWORD rc = 0;
332 GetExitCodeThread( thread, &rc );
334 switch (rc)
336 case ERROR_FUNCTION_NOT_CALLED:
337 case ERROR_SUCCESS:
338 case ERROR_INSTALL_USEREXIT:
339 case ERROR_INSTALL_FAILURE:
340 return rc;
341 case ERROR_NO_MORE_ITEMS:
342 return ERROR_SUCCESS;
343 case ERROR_INSTALL_SUSPEND:
344 ACTION_ForceReboot( package );
345 return ERROR_SUCCESS;
346 default:
347 ERR("Invalid Return Code %d\n",rc);
348 return ERROR_INSTALL_FAILURE;
352 static UINT wait_process_handle(MSIPACKAGE* package, UINT type,
353 HANDLE ProcessHandle, LPCWSTR name)
355 UINT rc = ERROR_SUCCESS;
357 if (!(type & msidbCustomActionTypeAsync))
359 TRACE("waiting for %s\n", debugstr_w(name));
361 msi_dialog_check_messages(ProcessHandle);
363 if (!(type & msidbCustomActionTypeContinue))
364 rc = custom_get_process_return(ProcessHandle);
366 CloseHandle(ProcessHandle);
368 else
370 TRACE("%s running in background\n", debugstr_w(name));
372 if (!(type & msidbCustomActionTypeContinue))
373 file_running_action(package, ProcessHandle, TRUE, name);
374 else
375 CloseHandle(ProcessHandle);
378 return rc;
381 typedef struct _msi_custom_action_info {
382 struct list entry;
383 LONG refs;
384 MSIPACKAGE *package;
385 LPWSTR source;
386 LPWSTR target;
387 HANDLE handle;
388 LPWSTR action;
389 INT type;
390 GUID guid;
391 } msi_custom_action_info;
393 static void release_custom_action_data( msi_custom_action_info *info )
395 EnterCriticalSection( &msi_custom_action_cs );
397 if (!--info->refs)
399 list_remove( &info->entry );
400 if (info->handle)
401 CloseHandle( info->handle );
402 msi_free( info->action );
403 msi_free( info->source );
404 msi_free( info->target );
405 msiobj_release( &info->package->hdr );
406 msi_free( info );
409 LeaveCriticalSection( &msi_custom_action_cs );
412 /* must be called inside msi_custom_action_cs if info is in the pending custom actions list */
413 static void addref_custom_action_data( msi_custom_action_info *info )
415 info->refs++;
418 static UINT wait_thread_handle( msi_custom_action_info *info )
420 UINT rc = ERROR_SUCCESS;
422 if (!(info->type & msidbCustomActionTypeAsync))
424 TRACE("waiting for %s\n", debugstr_w( info->action ));
426 msi_dialog_check_messages( info->handle );
428 if (!(info->type & msidbCustomActionTypeContinue))
429 rc = custom_get_thread_return( info->package, info->handle );
431 release_custom_action_data( info );
433 else
435 TRACE("%s running in background\n", debugstr_w( info->action ));
438 return rc;
441 static msi_custom_action_info *find_action_by_guid( const GUID *guid )
443 msi_custom_action_info *info;
444 BOOL found = FALSE;
446 EnterCriticalSection( &msi_custom_action_cs );
448 LIST_FOR_EACH_ENTRY( info, &msi_pending_custom_actions, msi_custom_action_info, entry )
450 if (IsEqualGUID( &info->guid, guid ))
452 addref_custom_action_data( info );
453 found = TRUE;
454 break;
458 LeaveCriticalSection( &msi_custom_action_cs );
460 if (!found)
461 return NULL;
463 return info;
466 static void handle_msi_break( LPCWSTR target )
468 LPWSTR msg;
469 WCHAR val[MAX_PATH];
471 static const WCHAR MsiBreak[] = { 'M','s','i','B','r','e','a','k',0 };
472 static const WCHAR WindowsInstaller[] = {
473 'W','i','n','d','o','w','s',' ','I','n','s','t','a','l','l','e','r',0
476 static const WCHAR format[] = {
477 'T','o',' ','d','e','b','u','g',' ','y','o','u','r',' ',
478 'c','u','s','t','o','m',' ','a','c','t','i','o','n',',',' ',
479 'a','t','t','a','c','h',' ','y','o','u','r',' ','d','e','b','u','g','g','e','r',' ',
480 't','o',' ','p','r','o','c','e','s','s',' ','%','i',' ','(','0','x','%','X',')',' ',
481 'a','n','d',' ','p','r','e','s','s',' ','O','K',0
484 if( !GetEnvironmentVariableW( MsiBreak, val, MAX_PATH ))
485 return;
487 if( strcmpiW( val, target ))
488 return;
490 msg = msi_alloc( (lstrlenW(format) + 10) * sizeof(WCHAR) );
491 if (!msg)
492 return;
494 wsprintfW( msg, format, GetCurrentProcessId(), GetCurrentProcessId());
495 MessageBoxW( NULL, msg, WindowsInstaller, MB_OK);
496 msi_free(msg);
497 DebugBreak();
500 static UINT get_action_info( const GUID *guid, INT *type, MSIHANDLE *handle,
501 BSTR *dll, BSTR *funcname,
502 IWineMsiRemotePackage **package )
504 IClassFactory *cf = NULL;
505 IWineMsiRemoteCustomAction *rca = NULL;
506 HRESULT r;
508 r = DllGetClassObject( &CLSID_WineMsiRemoteCustomAction,
509 &IID_IClassFactory, (LPVOID *)&cf );
510 if (FAILED(r))
512 ERR("failed to get IClassFactory interface\n");
513 return ERROR_FUNCTION_FAILED;
516 r = IClassFactory_CreateInstance( cf, NULL, &IID_IWineMsiRemoteCustomAction, (LPVOID *)&rca );
517 if (FAILED(r))
519 ERR("failed to get IWineMsiRemoteCustomAction interface\n");
520 return ERROR_FUNCTION_FAILED;
523 r = IWineMsiRemoteCustomAction_GetActionInfo( rca, guid, type, handle, dll, funcname, package );
524 IWineMsiRemoteCustomAction_Release( rca );
525 if (FAILED(r))
527 ERR("GetActionInfo failed\n");
528 return ERROR_FUNCTION_FAILED;
531 return ERROR_SUCCESS;
534 #ifdef __i386__
535 extern UINT CUSTOMPROC_wrapper( MsiCustomActionEntryPoint proc, MSIHANDLE handle );
536 __ASM_GLOBAL_FUNC( CUSTOMPROC_wrapper,
537 "pushl %ebp\n\t"
538 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
539 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
540 "movl %esp,%ebp\n\t"
541 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
542 "subl $4,%esp\n\t"
543 "pushl 12(%ebp)\n\t"
544 "movl 8(%ebp),%eax\n\t"
545 "call *%eax\n\t"
546 "leave\n\t"
547 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
548 __ASM_CFI(".cfi_same_value %ebp\n\t")
549 "ret" )
550 #else
551 static inline UINT CUSTOMPROC_wrapper( MsiCustomActionEntryPoint proc, MSIHANDLE handle )
553 return proc(handle);
555 #endif
557 static DWORD ACTION_CallDllFunction( const GUID *guid )
559 MsiCustomActionEntryPoint fn;
560 MSIHANDLE hPackage, handle;
561 HANDLE hModule;
562 LPSTR proc;
563 UINT r = ERROR_FUNCTION_FAILED;
564 BSTR dll = NULL, function = NULL;
565 INT type;
566 IWineMsiRemotePackage *remote_package = NULL;
568 TRACE("%s\n", debugstr_guid( guid ));
570 r = get_action_info( guid, &type, &handle, &dll, &function, &remote_package );
571 if (r != ERROR_SUCCESS)
572 return r;
574 hModule = LoadLibraryW( dll );
575 if (!hModule)
577 WARN( "failed to load dll %s (%u)\n", debugstr_w( dll ), GetLastError() );
578 return ERROR_SUCCESS;
581 proc = strdupWtoA( function );
582 fn = (MsiCustomActionEntryPoint) GetProcAddress( hModule, proc );
583 msi_free( proc );
584 if (fn)
586 hPackage = alloc_msi_remote_handle( (IUnknown *)remote_package );
587 if (hPackage)
589 IWineMsiRemotePackage_SetMsiHandle( remote_package, handle );
590 TRACE("calling %s\n", debugstr_w( function ) );
591 handle_msi_break( function );
593 __TRY
595 r = CUSTOMPROC_wrapper( fn, hPackage );
597 __EXCEPT_PAGE_FAULT
599 ERR("Custom action (%s:%s) caused a page fault: %08x\n",
600 debugstr_w(dll), debugstr_w(function), GetExceptionCode());
601 r = ERROR_SUCCESS;
603 __ENDTRY;
605 MsiCloseHandle( hPackage );
607 else
608 ERR("failed to create handle for %p\n", remote_package );
610 else
611 ERR("GetProcAddress(%s) failed\n", debugstr_w( function ) );
613 FreeLibrary(hModule);
615 IWineMsiRemotePackage_Release( remote_package );
616 SysFreeString( dll );
617 SysFreeString( function );
618 MsiCloseHandle( handle );
620 return r;
623 static DWORD WINAPI DllThread( LPVOID arg )
625 LPGUID guid = arg;
626 DWORD rc = 0;
628 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
630 rc = ACTION_CallDllFunction( guid );
632 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc );
634 MsiCloseAllHandles();
635 return rc;
638 static msi_custom_action_info *do_msidbCustomActionTypeDll(
639 MSIPACKAGE *package, INT type, LPCWSTR source, LPCWSTR target, LPCWSTR action )
641 msi_custom_action_info *info;
643 info = msi_alloc( sizeof *info );
644 if (!info)
645 return NULL;
647 msiobj_addref( &package->hdr );
648 info->refs = 2; /* 1 for our caller and 1 for thread we created */
649 info->package = package;
650 info->type = type;
651 info->target = strdupW( target );
652 info->source = strdupW( source );
653 info->action = strdupW( action );
654 CoCreateGuid( &info->guid );
656 EnterCriticalSection( &msi_custom_action_cs );
657 list_add_tail( &msi_pending_custom_actions, &info->entry );
658 LeaveCriticalSection( &msi_custom_action_cs );
660 info->handle = CreateThread( NULL, 0, DllThread, &info->guid, 0, NULL );
661 if (!info->handle)
663 /* release both references */
664 release_custom_action_data( info );
665 release_custom_action_data( info );
666 return NULL;
669 return info;
672 static UINT HANDLE_CustomType1( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
673 INT type, const WCHAR *action )
675 msi_custom_action_info *info;
676 MSIBINARY *binary;
678 if (!(binary = get_temp_binary( package, source, TRUE )))
679 return ERROR_FUNCTION_FAILED;
681 TRACE("Calling function %s from %s\n", debugstr_w(target), debugstr_w(binary->tmpfile));
683 info = do_msidbCustomActionTypeDll( package, type, binary->tmpfile, target, action );
684 return wait_thread_handle( info );
687 static HANDLE execute_command( const WCHAR *app, WCHAR *arg, const WCHAR *dir )
689 static const WCHAR dotexeW[] = {'.','e','x','e',0};
690 STARTUPINFOW si;
691 PROCESS_INFORMATION info;
692 WCHAR *exe = NULL, *cmd = NULL, *p;
693 BOOL ret;
695 if (app)
697 int len_arg = 0;
698 DWORD len_exe;
700 if (!(exe = msi_alloc( MAX_PATH * sizeof(WCHAR) ))) return INVALID_HANDLE_VALUE;
701 len_exe = SearchPathW( NULL, app, dotexeW, MAX_PATH, exe, NULL );
702 if (len_exe >= MAX_PATH)
704 msi_free( exe );
705 if (!(exe = msi_alloc( len_exe * sizeof(WCHAR) ))) return INVALID_HANDLE_VALUE;
706 len_exe = SearchPathW( NULL, app, dotexeW, len_exe, exe, NULL );
708 if (!len_exe)
710 WARN("can't find executable %u\n", GetLastError());
711 msi_free( exe );
712 return INVALID_HANDLE_VALUE;
715 if (arg) len_arg = strlenW( arg );
716 if (!(cmd = msi_alloc( (len_exe + len_arg + 4) * sizeof(WCHAR) )))
718 msi_free( exe );
719 return INVALID_HANDLE_VALUE;
721 p = cmd;
722 if (strchrW( exe, ' ' ))
724 *p++ = '\"';
725 memcpy( p, exe, len_exe * sizeof(WCHAR) );
726 p += len_exe;
727 *p++ = '\"';
728 *p = 0;
730 else
732 strcpyW( p, exe );
733 p += len_exe;
735 if (arg)
737 *p++ = ' ';
738 memcpy( p, arg, len_arg * sizeof(WCHAR) );
739 p[len_arg] = 0;
742 memset( &si, 0, sizeof(STARTUPINFOW) );
743 ret = CreateProcessW( exe, exe ? cmd : arg, NULL, NULL, FALSE, 0, NULL, dir, &si, &info );
744 msi_free( cmd );
745 msi_free( exe );
746 if (!ret)
748 WARN("unable to execute command %u\n", GetLastError());
749 return INVALID_HANDLE_VALUE;
751 CloseHandle( info.hThread );
752 return info.hProcess;
755 static UINT HANDLE_CustomType2( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
756 INT type, const WCHAR *action )
758 MSIBINARY *binary;
759 HANDLE handle;
760 WCHAR *arg;
762 if (!(binary = get_temp_binary( package, source, FALSE ))) return ERROR_FUNCTION_FAILED;
764 deformat_string( package, target, &arg );
765 TRACE("exe %s arg %s\n", debugstr_w(binary->tmpfile), debugstr_w(arg));
767 handle = execute_command( binary->tmpfile, arg, szCRoot );
768 msi_free( arg );
769 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
770 return wait_process_handle( package, type, handle, action );
773 static UINT HANDLE_CustomType17( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
774 INT type, const WCHAR *action )
776 msi_custom_action_info *info;
777 MSIFILE *file;
779 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
781 file = msi_get_loaded_file( package, source );
782 if (!file)
784 ERR("invalid file key %s\n", debugstr_w( source ));
785 return ERROR_FUNCTION_FAILED;
788 info = do_msidbCustomActionTypeDll( package, type, file->TargetPath, target, action );
789 return wait_thread_handle( info );
792 static UINT HANDLE_CustomType18( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
793 INT type, const WCHAR *action )
795 MSIFILE *file;
796 HANDLE handle;
797 WCHAR *arg;
799 if (!(file = msi_get_loaded_file( package, source ))) return ERROR_FUNCTION_FAILED;
801 deformat_string( package, target, &arg );
802 TRACE("exe %s arg %s\n", debugstr_w(file->TargetPath), debugstr_w(arg));
804 handle = execute_command( file->TargetPath, arg, szCRoot );
805 msi_free( arg );
806 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
807 return wait_process_handle( package, type, handle, action );
810 static UINT HANDLE_CustomType19( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
811 INT type, const WCHAR *action )
813 static const WCHAR query[] = {
814 'S','E','L','E','C','T',' ','`','M','e','s','s','a','g','e','`',' ',
815 'F','R','O','M',' ','`','E','r','r','o','r','`',' ',
816 'W','H','E','R','E',' ','`','E','r','r','o','r','`',' ','=',' ',
817 '%','s',0
819 MSIRECORD *row = 0;
820 LPWSTR deformated = NULL;
822 deformat_string( package, target, &deformated );
824 /* first try treat the error as a number */
825 row = MSI_QueryGetRecord( package->db, query, deformated );
826 if( row )
828 LPCWSTR error = MSI_RecordGetString( row, 1 );
829 if ((package->ui_level & INSTALLUILEVEL_MASK) != INSTALLUILEVEL_NONE)
830 MessageBoxW( NULL, error, NULL, MB_OK );
831 msiobj_release( &row->hdr );
833 else if ((package->ui_level & INSTALLUILEVEL_MASK) != INSTALLUILEVEL_NONE)
834 MessageBoxW( NULL, deformated, NULL, MB_OK );
836 msi_free( deformated );
838 return ERROR_INSTALL_FAILURE;
841 static UINT HANDLE_CustomType23( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
842 INT type, const WCHAR *action )
844 static const WCHAR msiexecW[] = {'m','s','i','e','x','e','c',0};
845 static const WCHAR paramsW[] = {'/','q','b',' ','/','i',' '};
846 WCHAR *dir, *arg, *p;
847 UINT len_src, len_dir, len_tgt, len = sizeof(paramsW)/sizeof(paramsW[0]);
848 HANDLE handle;
850 if (!(dir = msi_dup_property( package->db, szOriginalDatabase ))) return ERROR_OUTOFMEMORY;
851 if (!(p = strrchrW( dir, '\\' )) && !(p = strrchrW( dir, '/' )))
853 msi_free( dir );
854 return ERROR_FUNCTION_FAILED;
856 *p = 0;
857 len_dir = p - dir;
858 len_src = strlenW( source );
859 len_tgt = strlenW( target );
860 if (!(arg = msi_alloc( (len + len_dir + len_src + len_tgt + 5) * sizeof(WCHAR) )))
862 msi_free( dir );
863 return ERROR_OUTOFMEMORY;
865 memcpy( arg, paramsW, sizeof(paramsW) );
866 arg[len++] = '"';
867 memcpy( arg + len, dir, len_dir * sizeof(WCHAR) );
868 len += len_dir;
869 arg[len++] = '\\';
870 memcpy( arg + len, source, len_src * sizeof(WCHAR) );
871 len += len_src;
872 arg[len++] = '"';
873 arg[len++] = ' ';
874 strcpyW( arg + len, target );
876 TRACE("installing %s concurrently\n", debugstr_w(source));
878 handle = execute_command( msiexecW, arg, dir );
879 msi_free( dir );
880 msi_free( arg );
881 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
882 return wait_process_handle( package, type, handle, action );
885 static UINT HANDLE_CustomType50( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
886 INT type, const WCHAR *action )
888 WCHAR *exe, *arg;
889 HANDLE handle;
891 if (!(exe = msi_dup_property( package->db, source ))) return ERROR_SUCCESS;
893 deformat_string( package, target, &arg );
894 TRACE("exe %s arg %s\n", debugstr_w(exe), debugstr_w(arg));
896 handle = execute_command( exe, arg, szCRoot );
897 msi_free( exe );
898 msi_free( arg );
899 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
900 return wait_process_handle( package, type, handle, action );
903 static UINT HANDLE_CustomType34( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
904 INT type, const WCHAR *action )
906 const WCHAR *workingdir = NULL;
907 HANDLE handle;
908 WCHAR *cmd;
910 if (source)
912 workingdir = msi_get_target_folder( package, source );
913 if (!workingdir) return ERROR_FUNCTION_FAILED;
915 deformat_string( package, target, &cmd );
916 if (!cmd) return ERROR_FUNCTION_FAILED;
918 TRACE("cmd %s dir %s\n", debugstr_w(cmd), debugstr_w(workingdir));
920 handle = execute_command( NULL, cmd, workingdir );
921 msi_free( cmd );
922 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
923 return wait_process_handle( package, type, handle, action );
926 static DWORD ACTION_CallScript( const GUID *guid )
928 msi_custom_action_info *info;
929 MSIHANDLE hPackage;
930 UINT r = ERROR_FUNCTION_FAILED;
932 info = find_action_by_guid( guid );
933 if (!info)
935 ERR("failed to find action %s\n", debugstr_guid( guid) );
936 return ERROR_FUNCTION_FAILED;
939 TRACE("function %s, script %s\n", debugstr_w( info->target ), debugstr_w( info->source ) );
941 hPackage = alloc_msihandle( &info->package->hdr );
942 if (hPackage)
944 r = call_script( hPackage, info->type, info->source, info->target, info->action );
945 TRACE("script returned %u\n", r);
946 MsiCloseHandle( hPackage );
948 else
949 ERR("failed to create handle for %p\n", info->package );
951 release_custom_action_data( info );
952 return r;
955 static DWORD WINAPI ScriptThread( LPVOID arg )
957 LPGUID guid = arg;
958 DWORD rc;
960 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
962 rc = ACTION_CallScript( guid );
964 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc );
966 MsiCloseAllHandles();
967 return rc;
970 static msi_custom_action_info *do_msidbCustomActionTypeScript(
971 MSIPACKAGE *package, INT type, LPCWSTR script, LPCWSTR function, LPCWSTR action )
973 msi_custom_action_info *info;
975 info = msi_alloc( sizeof *info );
976 if (!info)
977 return NULL;
979 msiobj_addref( &package->hdr );
980 info->refs = 2; /* 1 for our caller and 1 for thread we created */
981 info->package = package;
982 info->type = type;
983 info->target = strdupW( function );
984 info->source = strdupW( script );
985 info->action = strdupW( action );
986 CoCreateGuid( &info->guid );
988 EnterCriticalSection( &msi_custom_action_cs );
989 list_add_tail( &msi_pending_custom_actions, &info->entry );
990 LeaveCriticalSection( &msi_custom_action_cs );
992 info->handle = CreateThread( NULL, 0, ScriptThread, &info->guid, 0, NULL );
993 if (!info->handle)
995 /* release both references */
996 release_custom_action_data( info );
997 release_custom_action_data( info );
998 return NULL;
1001 return info;
1004 static UINT HANDLE_CustomType37_38( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1005 INT type, const WCHAR *action )
1007 msi_custom_action_info *info;
1009 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1011 info = do_msidbCustomActionTypeScript( package, type, target, NULL, action );
1012 return wait_thread_handle( info );
1015 static UINT HANDLE_CustomType5_6( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1016 INT type, const WCHAR *action )
1018 static const WCHAR query[] = {
1019 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1020 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
1021 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
1022 MSIRECORD *row = NULL;
1023 msi_custom_action_info *info;
1024 CHAR *buffer = NULL;
1025 WCHAR *bufferw = NULL;
1026 DWORD sz = 0;
1027 UINT r;
1029 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1031 row = MSI_QueryGetRecord(package->db, query, source);
1032 if (!row)
1033 return ERROR_FUNCTION_FAILED;
1035 r = MSI_RecordReadStream(row, 2, NULL, &sz);
1036 if (r != ERROR_SUCCESS) goto done;
1038 buffer = msi_alloc( sz + 1 );
1039 if (!buffer)
1041 r = ERROR_FUNCTION_FAILED;
1042 goto done;
1045 r = MSI_RecordReadStream(row, 2, buffer, &sz);
1046 if (r != ERROR_SUCCESS)
1047 goto done;
1049 buffer[sz] = 0;
1050 bufferw = strdupAtoW(buffer);
1051 if (!bufferw)
1053 r = ERROR_FUNCTION_FAILED;
1054 goto done;
1057 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1058 r = wait_thread_handle( info );
1060 done:
1061 msi_free(bufferw);
1062 msi_free(buffer);
1063 msiobj_release(&row->hdr);
1064 return r;
1067 static UINT HANDLE_CustomType21_22( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1068 INT type, const WCHAR *action )
1070 msi_custom_action_info *info;
1071 MSIFILE *file;
1072 HANDLE hFile;
1073 DWORD sz, szHighWord = 0, read;
1074 CHAR *buffer=NULL;
1075 WCHAR *bufferw=NULL;
1076 BOOL bRet;
1077 UINT r;
1079 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1081 file = msi_get_loaded_file(package, source);
1082 if (!file)
1084 ERR("invalid file key %s\n", debugstr_w(source));
1085 return ERROR_FUNCTION_FAILED;
1088 hFile = CreateFileW(file->TargetPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
1089 if (hFile == INVALID_HANDLE_VALUE) return ERROR_FUNCTION_FAILED;
1091 sz = GetFileSize(hFile, &szHighWord);
1092 if (sz == INVALID_FILE_SIZE || szHighWord != 0)
1094 CloseHandle(hFile);
1095 return ERROR_FUNCTION_FAILED;
1097 buffer = msi_alloc( sz + 1 );
1098 if (!buffer)
1100 CloseHandle(hFile);
1101 return ERROR_FUNCTION_FAILED;
1103 bRet = ReadFile(hFile, buffer, sz, &read, NULL);
1104 CloseHandle(hFile);
1105 if (!bRet)
1107 r = ERROR_FUNCTION_FAILED;
1108 goto done;
1110 buffer[read] = 0;
1111 bufferw = strdupAtoW(buffer);
1112 if (!bufferw)
1114 r = ERROR_FUNCTION_FAILED;
1115 goto done;
1117 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1118 r = wait_thread_handle( info );
1120 done:
1121 msi_free(bufferw);
1122 msi_free(buffer);
1123 return r;
1126 static UINT HANDLE_CustomType53_54( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1127 INT type, const WCHAR *action )
1129 msi_custom_action_info *info;
1130 WCHAR *prop;
1132 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1134 prop = msi_dup_property( package->db, source );
1135 if (!prop) return ERROR_SUCCESS;
1137 info = do_msidbCustomActionTypeScript( package, type, prop, NULL, action );
1138 msi_free(prop);
1139 return wait_thread_handle( info );
1142 static BOOL action_type_matches_script( UINT type, UINT script )
1144 switch (script)
1146 case SCRIPT_NONE:
1147 case SCRIPT_INSTALL:
1148 return !(type & msidbCustomActionTypeCommit) && !(type & msidbCustomActionTypeRollback);
1149 case SCRIPT_COMMIT:
1150 return (type & msidbCustomActionTypeCommit);
1151 case SCRIPT_ROLLBACK:
1152 return (type & msidbCustomActionTypeRollback);
1153 default:
1154 ERR("unhandled script %u\n", script);
1156 return FALSE;
1159 static UINT defer_custom_action( MSIPACKAGE *package, const WCHAR *action, UINT type )
1161 WCHAR *actiondata = msi_dup_property( package->db, action );
1162 WCHAR *usersid = msi_dup_property( package->db, szUserSID );
1163 WCHAR *prodcode = msi_dup_property( package->db, szProductCode );
1164 WCHAR *deferred = msi_get_deferred_action( action, actiondata, usersid, prodcode );
1166 if (!deferred)
1168 msi_free( actiondata );
1169 msi_free( usersid );
1170 msi_free( prodcode );
1171 return ERROR_OUTOFMEMORY;
1173 if (type & msidbCustomActionTypeCommit)
1175 TRACE("deferring commit action\n");
1176 msi_schedule_action( package, SCRIPT_COMMIT, deferred );
1178 else if (type & msidbCustomActionTypeRollback)
1180 TRACE("deferring rollback action\n");
1181 msi_schedule_action( package, SCRIPT_ROLLBACK, deferred );
1183 else
1185 TRACE("deferring install action\n");
1186 msi_schedule_action( package, SCRIPT_INSTALL, deferred );
1189 msi_free( actiondata );
1190 msi_free( usersid );
1191 msi_free( prodcode );
1192 msi_free( deferred );
1193 return ERROR_SUCCESS;
1196 UINT ACTION_CustomAction( MSIPACKAGE *package, LPCWSTR action, UINT script )
1198 static const WCHAR query[] = {
1199 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1200 '`','C','u','s','t','o','m','A','c','t','i','o','n','`',' ','W','H','E','R','E',' ',
1201 '`','A','c','t','i' ,'o','n','`',' ','=',' ','\'','%','s','\'',0};
1202 UINT rc = ERROR_SUCCESS;
1203 MSIRECORD *row;
1204 UINT type;
1205 const WCHAR *source, *target, *ptr, *deferred_data = NULL;
1206 WCHAR *deformated = NULL;
1207 int len;
1209 /* deferred action: [properties]Action */
1210 if ((ptr = strrchrW(action, ']')))
1212 deferred_data = action;
1213 action = ptr + 1;
1216 row = MSI_QueryGetRecord( package->db, query, action );
1217 if (!row)
1218 return ERROR_CALL_NOT_IMPLEMENTED;
1220 type = MSI_RecordGetInteger(row,2);
1221 source = MSI_RecordGetString(row,3);
1222 target = MSI_RecordGetString(row,4);
1224 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action),type,
1225 debugstr_w(source), debugstr_w(target));
1227 /* handle some of the deferred actions */
1228 if (type & msidbCustomActionTypeTSAware)
1229 FIXME("msidbCustomActionTypeTSAware not handled\n");
1231 if (type & msidbCustomActionTypeInScript)
1233 if (type & msidbCustomActionTypeNoImpersonate)
1234 WARN("msidbCustomActionTypeNoImpersonate not handled\n");
1236 if (!action_type_matches_script( type, script ))
1238 rc = defer_custom_action( package, action, type );
1239 goto end;
1241 else
1243 LPWSTR actiondata = msi_dup_property( package->db, action );
1245 if (type & msidbCustomActionTypeInScript)
1246 package->scheduled_action_running = TRUE;
1248 if (type & msidbCustomActionTypeCommit)
1249 package->commit_action_running = TRUE;
1251 if (type & msidbCustomActionTypeRollback)
1252 package->rollback_action_running = TRUE;
1254 if (deferred_data)
1255 set_deferred_action_props(package, deferred_data);
1256 else if (actiondata)
1257 msi_set_property( package->db, szCustomActionData, actiondata, -1 );
1258 else
1259 msi_set_property( package->db, szCustomActionData, szEmpty, -1 );
1261 msi_free(actiondata);
1264 else if (!check_execution_scheduling_options(package,action,type))
1266 rc = ERROR_SUCCESS;
1267 goto end;
1270 switch (type & CUSTOM_ACTION_TYPE_MASK)
1272 case 1: /* DLL file stored in a Binary table stream */
1273 rc = HANDLE_CustomType1(package,source,target,type,action);
1274 break;
1275 case 2: /* EXE file stored in a Binary table stream */
1276 rc = HANDLE_CustomType2(package,source,target,type,action);
1277 break;
1278 case 18: /*EXE file installed with package */
1279 rc = HANDLE_CustomType18(package,source,target,type,action);
1280 break;
1281 case 19: /* Error that halts install */
1282 rc = HANDLE_CustomType19(package,source,target,type,action);
1283 break;
1284 case 17:
1285 rc = HANDLE_CustomType17(package,source,target,type,action);
1286 break;
1287 case 23: /* installs another package in the source tree */
1288 deformat_string(package,target,&deformated);
1289 rc = HANDLE_CustomType23(package,source,deformated,type,action);
1290 msi_free(deformated);
1291 break;
1292 case 50: /*EXE file specified by a property value */
1293 rc = HANDLE_CustomType50(package,source,target,type,action);
1294 break;
1295 case 34: /*EXE to be run in specified directory */
1296 rc = HANDLE_CustomType34(package,source,target,type,action);
1297 break;
1298 case 35: /* Directory set with formatted text. */
1299 deformat_string(package,target,&deformated);
1300 MSI_SetTargetPathW(package, source, deformated);
1301 msi_free(deformated);
1302 break;
1303 case 51: /* Property set with formatted text. */
1304 if (!source)
1305 break;
1307 len = deformat_string( package, target, &deformated );
1308 rc = msi_set_property( package->db, source, deformated, len );
1309 if (rc == ERROR_SUCCESS && !strcmpW( source, szSourceDir ))
1310 msi_reset_folders( package, TRUE );
1311 msi_free(deformated);
1312 break;
1313 case 37: /* JScript/VBScript text stored in target column. */
1314 case 38:
1315 rc = HANDLE_CustomType37_38(package,source,target,type,action);
1316 break;
1317 case 5:
1318 case 6: /* JScript/VBScript file stored in a Binary table stream. */
1319 rc = HANDLE_CustomType5_6(package,source,target,type,action);
1320 break;
1321 case 21: /* JScript/VBScript file installed with the product. */
1322 case 22:
1323 rc = HANDLE_CustomType21_22(package,source,target,type,action);
1324 break;
1325 case 53: /* JScript/VBScript text specified by a property value. */
1326 case 54:
1327 rc = HANDLE_CustomType53_54(package,source,target,type,action);
1328 break;
1329 default:
1330 FIXME("unhandled action type %u (%s %s)\n", type & CUSTOM_ACTION_TYPE_MASK,
1331 debugstr_w(source), debugstr_w(target));
1334 end:
1335 package->scheduled_action_running = FALSE;
1336 package->commit_action_running = FALSE;
1337 package->rollback_action_running = FALSE;
1338 msiobj_release(&row->hdr);
1339 return rc;
1342 void ACTION_FinishCustomActions(const MSIPACKAGE* package)
1344 struct list *item;
1345 HANDLE *wait_handles;
1346 unsigned int handle_count, i;
1347 msi_custom_action_info *info, *cursor;
1349 while ((item = list_head( &package->RunningActions )))
1351 MSIRUNNINGACTION *action = LIST_ENTRY( item, MSIRUNNINGACTION, entry );
1353 list_remove( &action->entry );
1355 TRACE("waiting for %s\n", debugstr_w( action->name ) );
1356 msi_dialog_check_messages( action->handle );
1358 CloseHandle( action->handle );
1359 msi_free( action->name );
1360 msi_free( action );
1363 EnterCriticalSection( &msi_custom_action_cs );
1365 handle_count = list_count( &msi_pending_custom_actions );
1366 wait_handles = msi_alloc( handle_count * sizeof(HANDLE) );
1368 handle_count = 0;
1369 LIST_FOR_EACH_ENTRY_SAFE( info, cursor, &msi_pending_custom_actions, msi_custom_action_info, entry )
1371 if (info->package == package )
1373 if (DuplicateHandle(GetCurrentProcess(), info->handle, GetCurrentProcess(), &wait_handles[handle_count], SYNCHRONIZE, FALSE, 0))
1374 handle_count++;
1378 LeaveCriticalSection( &msi_custom_action_cs );
1380 for (i = 0; i < handle_count; i++)
1382 msi_dialog_check_messages( wait_handles[i] );
1383 CloseHandle( wait_handles[i] );
1385 msi_free( wait_handles );
1387 EnterCriticalSection( &msi_custom_action_cs );
1388 LIST_FOR_EACH_ENTRY_SAFE( info, cursor, &msi_pending_custom_actions, msi_custom_action_info, entry )
1390 if (info->package == package) release_custom_action_data( info );
1392 LeaveCriticalSection( &msi_custom_action_cs );
1395 typedef struct _msi_custom_remote_impl {
1396 IWineMsiRemoteCustomAction IWineMsiRemoteCustomAction_iface;
1397 LONG refs;
1398 } msi_custom_remote_impl;
1400 static inline msi_custom_remote_impl *impl_from_IWineMsiRemoteCustomAction( IWineMsiRemoteCustomAction *iface )
1402 return CONTAINING_RECORD(iface, msi_custom_remote_impl, IWineMsiRemoteCustomAction_iface);
1405 static HRESULT WINAPI mcr_QueryInterface( IWineMsiRemoteCustomAction *iface,
1406 REFIID riid,LPVOID *ppobj)
1408 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
1409 IsEqualCLSID( riid, &IID_IWineMsiRemoteCustomAction ) )
1411 IWineMsiRemoteCustomAction_AddRef( iface );
1412 *ppobj = iface;
1413 return S_OK;
1416 return E_NOINTERFACE;
1419 static ULONG WINAPI mcr_AddRef( IWineMsiRemoteCustomAction *iface )
1421 msi_custom_remote_impl* This = impl_from_IWineMsiRemoteCustomAction( iface );
1423 return InterlockedIncrement( &This->refs );
1426 static ULONG WINAPI mcr_Release( IWineMsiRemoteCustomAction *iface )
1428 msi_custom_remote_impl* This = impl_from_IWineMsiRemoteCustomAction( iface );
1429 ULONG r;
1431 r = InterlockedDecrement( &This->refs );
1432 if (r == 0)
1433 msi_free( This );
1434 return r;
1437 static HRESULT WINAPI mcr_GetActionInfo( IWineMsiRemoteCustomAction *iface, LPCGUID custom_action_guid,
1438 INT *type, MSIHANDLE *handle, BSTR *dll, BSTR *func, IWineMsiRemotePackage **remote_package )
1440 msi_custom_action_info *info;
1442 info = find_action_by_guid( custom_action_guid );
1443 if (!info)
1444 return E_FAIL;
1446 *type = info->type;
1447 *handle = alloc_msihandle( &info->package->hdr );
1448 *dll = SysAllocString( info->source );
1449 *func = SysAllocString( info->target );
1451 release_custom_action_data( info );
1452 return create_msi_remote_package( NULL, (LPVOID *)remote_package );
1455 static const IWineMsiRemoteCustomActionVtbl msi_custom_remote_vtbl =
1457 mcr_QueryInterface,
1458 mcr_AddRef,
1459 mcr_Release,
1460 mcr_GetActionInfo,
1463 HRESULT create_msi_custom_remote( IUnknown *pOuter, LPVOID *ppObj )
1465 msi_custom_remote_impl* This;
1467 This = msi_alloc( sizeof *This );
1468 if (!This)
1469 return E_OUTOFMEMORY;
1471 This->IWineMsiRemoteCustomAction_iface.lpVtbl = &msi_custom_remote_vtbl;
1472 This->refs = 1;
1474 *ppObj = &This->IWineMsiRemoteCustomAction_iface;
1476 return S_OK;