wined3d: Validate (2D) texture dimensions in texture_init().
[wine.git] / dlls / msi / custom.c
blob4e934bdce04cd8f6127d4b1978d679f534db10fc
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 "pushl 12(%ebp)\n\t"
543 "movl 8(%ebp),%eax\n\t"
544 "call *%eax\n\t"
545 "leave\n\t"
546 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
547 __ASM_CFI(".cfi_same_value %ebp\n\t")
548 "ret" )
549 #else
550 static inline UINT CUSTOMPROC_wrapper( MsiCustomActionEntryPoint proc, MSIHANDLE handle )
552 return proc(handle);
554 #endif
556 static DWORD ACTION_CallDllFunction( const GUID *guid )
558 MsiCustomActionEntryPoint fn;
559 MSIHANDLE hPackage, handle;
560 HANDLE hModule;
561 LPSTR proc;
562 UINT r = ERROR_FUNCTION_FAILED;
563 BSTR dll = NULL, function = NULL;
564 INT type;
565 IWineMsiRemotePackage *remote_package = NULL;
567 TRACE("%s\n", debugstr_guid( guid ));
569 r = get_action_info( guid, &type, &handle, &dll, &function, &remote_package );
570 if (r != ERROR_SUCCESS)
571 return r;
573 hModule = LoadLibraryW( dll );
574 if (!hModule)
576 WARN( "failed to load dll %s (%u)\n", debugstr_w( dll ), GetLastError() );
577 return ERROR_SUCCESS;
580 proc = strdupWtoA( function );
581 fn = (MsiCustomActionEntryPoint) GetProcAddress( hModule, proc );
582 msi_free( proc );
583 if (fn)
585 hPackage = alloc_msi_remote_handle( (IUnknown *)remote_package );
586 if (hPackage)
588 IWineMsiRemotePackage_SetMsiHandle( remote_package, handle );
589 TRACE("calling %s\n", debugstr_w( function ) );
590 handle_msi_break( function );
592 __TRY
594 r = CUSTOMPROC_wrapper( fn, hPackage );
596 __EXCEPT_PAGE_FAULT
598 ERR("Custom action (%s:%s) caused a page fault: %08x\n",
599 debugstr_w(dll), debugstr_w(function), GetExceptionCode());
600 r = ERROR_SUCCESS;
602 __ENDTRY;
604 MsiCloseHandle( hPackage );
606 else
607 ERR("failed to create handle for %p\n", remote_package );
609 else
610 ERR("GetProcAddress(%s) failed\n", debugstr_w( function ) );
612 FreeLibrary(hModule);
614 IWineMsiRemotePackage_Release( remote_package );
615 SysFreeString( dll );
616 SysFreeString( function );
617 MsiCloseHandle( handle );
619 return r;
622 static DWORD WINAPI DllThread( LPVOID arg )
624 LPGUID guid = arg;
625 DWORD rc = 0;
627 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
629 rc = ACTION_CallDllFunction( guid );
631 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc );
633 MsiCloseAllHandles();
634 return rc;
637 static msi_custom_action_info *do_msidbCustomActionTypeDll(
638 MSIPACKAGE *package, INT type, LPCWSTR source, LPCWSTR target, LPCWSTR action )
640 msi_custom_action_info *info;
642 info = msi_alloc( sizeof *info );
643 if (!info)
644 return NULL;
646 msiobj_addref( &package->hdr );
647 info->refs = 2; /* 1 for our caller and 1 for thread we created */
648 info->package = package;
649 info->type = type;
650 info->target = strdupW( target );
651 info->source = strdupW( source );
652 info->action = strdupW( action );
653 CoCreateGuid( &info->guid );
655 EnterCriticalSection( &msi_custom_action_cs );
656 list_add_tail( &msi_pending_custom_actions, &info->entry );
657 LeaveCriticalSection( &msi_custom_action_cs );
659 info->handle = CreateThread( NULL, 0, DllThread, &info->guid, 0, NULL );
660 if (!info->handle)
662 /* release both references */
663 release_custom_action_data( info );
664 release_custom_action_data( info );
665 return NULL;
668 return info;
671 static UINT HANDLE_CustomType1( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
672 INT type, const WCHAR *action )
674 msi_custom_action_info *info;
675 MSIBINARY *binary;
677 if (!(binary = get_temp_binary( package, source, TRUE )))
678 return ERROR_FUNCTION_FAILED;
680 TRACE("Calling function %s from %s\n", debugstr_w(target), debugstr_w(binary->tmpfile));
682 info = do_msidbCustomActionTypeDll( package, type, binary->tmpfile, target, action );
683 return wait_thread_handle( info );
686 static HANDLE execute_command( const WCHAR *app, WCHAR *arg, const WCHAR *dir )
688 static const WCHAR dotexeW[] = {'.','e','x','e',0};
689 STARTUPINFOW si;
690 PROCESS_INFORMATION info;
691 WCHAR *exe = NULL, *cmd = NULL, *p;
692 BOOL ret;
694 if (app)
696 int len_arg = 0;
697 DWORD len_exe;
699 if (!(exe = msi_alloc( MAX_PATH * sizeof(WCHAR) ))) return INVALID_HANDLE_VALUE;
700 len_exe = SearchPathW( NULL, app, dotexeW, MAX_PATH, exe, NULL );
701 if (len_exe >= MAX_PATH)
703 msi_free( exe );
704 if (!(exe = msi_alloc( len_exe * sizeof(WCHAR) ))) return INVALID_HANDLE_VALUE;
705 len_exe = SearchPathW( NULL, app, dotexeW, len_exe, exe, NULL );
707 if (!len_exe)
709 WARN("can't find executable %u\n", GetLastError());
710 msi_free( exe );
711 return INVALID_HANDLE_VALUE;
714 if (arg) len_arg = strlenW( arg );
715 if (!(cmd = msi_alloc( (len_exe + len_arg + 4) * sizeof(WCHAR) )))
717 msi_free( exe );
718 return INVALID_HANDLE_VALUE;
720 p = cmd;
721 if (strchrW( exe, ' ' ))
723 *p++ = '\"';
724 memcpy( p, exe, len_exe * sizeof(WCHAR) );
725 p += len_exe;
726 *p++ = '\"';
727 *p = 0;
729 else
731 strcpyW( p, exe );
732 p += len_exe;
734 if (arg)
736 *p++ = ' ';
737 memcpy( p, arg, len_arg * sizeof(WCHAR) );
738 p[len_arg] = 0;
741 memset( &si, 0, sizeof(STARTUPINFOW) );
742 ret = CreateProcessW( exe, exe ? cmd : arg, NULL, NULL, FALSE, 0, NULL, dir, &si, &info );
743 msi_free( cmd );
744 msi_free( exe );
745 if (!ret)
747 WARN("unable to execute command %u\n", GetLastError());
748 return INVALID_HANDLE_VALUE;
750 CloseHandle( info.hThread );
751 return info.hProcess;
754 static UINT HANDLE_CustomType2( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
755 INT type, const WCHAR *action )
757 MSIBINARY *binary;
758 HANDLE handle;
759 WCHAR *arg;
761 if (!(binary = get_temp_binary( package, source, FALSE ))) return ERROR_FUNCTION_FAILED;
763 deformat_string( package, target, &arg );
764 TRACE("exe %s arg %s\n", debugstr_w(binary->tmpfile), debugstr_w(arg));
766 handle = execute_command( binary->tmpfile, arg, szCRoot );
767 msi_free( arg );
768 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
769 return wait_process_handle( package, type, handle, action );
772 static UINT HANDLE_CustomType17( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
773 INT type, const WCHAR *action )
775 msi_custom_action_info *info;
776 MSIFILE *file;
778 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
780 file = msi_get_loaded_file( package, source );
781 if (!file)
783 ERR("invalid file key %s\n", debugstr_w( source ));
784 return ERROR_FUNCTION_FAILED;
787 info = do_msidbCustomActionTypeDll( package, type, file->TargetPath, target, action );
788 return wait_thread_handle( info );
791 static UINT HANDLE_CustomType18( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
792 INT type, const WCHAR *action )
794 MSIFILE *file;
795 HANDLE handle;
796 WCHAR *arg;
798 if (!(file = msi_get_loaded_file( package, source ))) return ERROR_FUNCTION_FAILED;
800 deformat_string( package, target, &arg );
801 TRACE("exe %s arg %s\n", debugstr_w(file->TargetPath), debugstr_w(arg));
803 handle = execute_command( file->TargetPath, arg, szCRoot );
804 msi_free( arg );
805 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
806 return wait_process_handle( package, type, handle, action );
809 static UINT HANDLE_CustomType19( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
810 INT type, const WCHAR *action )
812 static const WCHAR query[] = {
813 'S','E','L','E','C','T',' ','`','M','e','s','s','a','g','e','`',' ',
814 'F','R','O','M',' ','`','E','r','r','o','r','`',' ',
815 'W','H','E','R','E',' ','`','E','r','r','o','r','`',' ','=',' ',
816 '%','s',0
818 MSIRECORD *row = 0;
819 LPWSTR deformated = NULL;
821 deformat_string( package, target, &deformated );
823 /* first try treat the error as a number */
824 row = MSI_QueryGetRecord( package->db, query, deformated );
825 if( row )
827 LPCWSTR error = MSI_RecordGetString( row, 1 );
828 if ((package->ui_level & INSTALLUILEVEL_MASK) != INSTALLUILEVEL_NONE)
829 MessageBoxW( NULL, error, NULL, MB_OK );
830 msiobj_release( &row->hdr );
832 else if ((package->ui_level & INSTALLUILEVEL_MASK) != INSTALLUILEVEL_NONE)
833 MessageBoxW( NULL, deformated, NULL, MB_OK );
835 msi_free( deformated );
837 return ERROR_INSTALL_FAILURE;
840 static UINT HANDLE_CustomType23( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
841 INT type, const WCHAR *action )
843 static const WCHAR msiexecW[] = {'m','s','i','e','x','e','c',0};
844 static const WCHAR paramsW[] = {'/','q','b',' ','/','i',' '};
845 WCHAR *dir, *arg, *p;
846 UINT len_src, len_dir, len_tgt, len = sizeof(paramsW)/sizeof(paramsW[0]);
847 HANDLE handle;
849 if (!(dir = msi_dup_property( package->db, szOriginalDatabase ))) return ERROR_OUTOFMEMORY;
850 if (!(p = strrchrW( dir, '\\' )) && !(p = strrchrW( dir, '/' )))
852 msi_free( dir );
853 return ERROR_FUNCTION_FAILED;
855 *p = 0;
856 len_dir = p - dir;
857 len_src = strlenW( source );
858 len_tgt = strlenW( target );
859 if (!(arg = msi_alloc( (len + len_dir + len_src + len_tgt + 5) * sizeof(WCHAR) )))
861 msi_free( dir );
862 return ERROR_OUTOFMEMORY;
864 memcpy( arg, paramsW, sizeof(paramsW) );
865 arg[len++] = '"';
866 memcpy( arg + len, dir, len_dir * sizeof(WCHAR) );
867 len += len_dir;
868 arg[len++] = '\\';
869 memcpy( arg + len, source, len_src * sizeof(WCHAR) );
870 len += len_src;
871 arg[len++] = '"';
872 arg[len++] = ' ';
873 strcpyW( arg + len, target );
875 TRACE("installing %s concurrently\n", debugstr_w(source));
877 handle = execute_command( msiexecW, arg, dir );
878 msi_free( dir );
879 msi_free( arg );
880 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
881 return wait_process_handle( package, type, handle, action );
884 static UINT HANDLE_CustomType50( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
885 INT type, const WCHAR *action )
887 WCHAR *exe, *arg;
888 HANDLE handle;
890 if (!(exe = msi_dup_property( package->db, source ))) return ERROR_SUCCESS;
892 deformat_string( package, target, &arg );
893 TRACE("exe %s arg %s\n", debugstr_w(exe), debugstr_w(arg));
895 handle = execute_command( exe, arg, szCRoot );
896 msi_free( exe );
897 msi_free( arg );
898 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
899 return wait_process_handle( package, type, handle, action );
902 static UINT HANDLE_CustomType34( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
903 INT type, const WCHAR *action )
905 const WCHAR *workingdir = NULL;
906 HANDLE handle;
907 WCHAR *cmd;
909 if (source)
911 workingdir = msi_get_target_folder( package, source );
912 if (!workingdir) return ERROR_FUNCTION_FAILED;
914 deformat_string( package, target, &cmd );
915 if (!cmd) return ERROR_FUNCTION_FAILED;
917 TRACE("cmd %s dir %s\n", debugstr_w(cmd), debugstr_w(workingdir));
919 handle = execute_command( NULL, cmd, workingdir );
920 msi_free( cmd );
921 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
922 return wait_process_handle( package, type, handle, action );
925 static DWORD ACTION_CallScript( const GUID *guid )
927 msi_custom_action_info *info;
928 MSIHANDLE hPackage;
929 UINT r = ERROR_FUNCTION_FAILED;
931 info = find_action_by_guid( guid );
932 if (!info)
934 ERR("failed to find action %s\n", debugstr_guid( guid) );
935 return ERROR_FUNCTION_FAILED;
938 TRACE("function %s, script %s\n", debugstr_w( info->target ), debugstr_w( info->source ) );
940 hPackage = alloc_msihandle( &info->package->hdr );
941 if (hPackage)
943 r = call_script( hPackage, info->type, info->source, info->target, info->action );
944 TRACE("script returned %u\n", r);
945 MsiCloseHandle( hPackage );
947 else
948 ERR("failed to create handle for %p\n", info->package );
950 release_custom_action_data( info );
951 return r;
954 static DWORD WINAPI ScriptThread( LPVOID arg )
956 LPGUID guid = arg;
957 DWORD rc;
959 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
961 rc = ACTION_CallScript( guid );
963 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc );
965 MsiCloseAllHandles();
966 return rc;
969 static msi_custom_action_info *do_msidbCustomActionTypeScript(
970 MSIPACKAGE *package, INT type, LPCWSTR script, LPCWSTR function, LPCWSTR action )
972 msi_custom_action_info *info;
974 info = msi_alloc( sizeof *info );
975 if (!info)
976 return NULL;
978 msiobj_addref( &package->hdr );
979 info->refs = 2; /* 1 for our caller and 1 for thread we created */
980 info->package = package;
981 info->type = type;
982 info->target = strdupW( function );
983 info->source = strdupW( script );
984 info->action = strdupW( action );
985 CoCreateGuid( &info->guid );
987 EnterCriticalSection( &msi_custom_action_cs );
988 list_add_tail( &msi_pending_custom_actions, &info->entry );
989 LeaveCriticalSection( &msi_custom_action_cs );
991 info->handle = CreateThread( NULL, 0, ScriptThread, &info->guid, 0, NULL );
992 if (!info->handle)
994 /* release both references */
995 release_custom_action_data( info );
996 release_custom_action_data( info );
997 return NULL;
1000 return info;
1003 static UINT HANDLE_CustomType37_38( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1004 INT type, const WCHAR *action )
1006 msi_custom_action_info *info;
1008 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1010 info = do_msidbCustomActionTypeScript( package, type, target, NULL, action );
1011 return wait_thread_handle( info );
1014 static UINT HANDLE_CustomType5_6( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1015 INT type, const WCHAR *action )
1017 static const WCHAR query[] = {
1018 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1019 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
1020 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
1021 MSIRECORD *row = NULL;
1022 msi_custom_action_info *info;
1023 CHAR *buffer = NULL;
1024 WCHAR *bufferw = NULL;
1025 DWORD sz = 0;
1026 UINT r;
1028 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1030 row = MSI_QueryGetRecord(package->db, query, source);
1031 if (!row)
1032 return ERROR_FUNCTION_FAILED;
1034 r = MSI_RecordReadStream(row, 2, NULL, &sz);
1035 if (r != ERROR_SUCCESS) goto done;
1037 buffer = msi_alloc( sz + 1 );
1038 if (!buffer)
1040 r = ERROR_FUNCTION_FAILED;
1041 goto done;
1044 r = MSI_RecordReadStream(row, 2, buffer, &sz);
1045 if (r != ERROR_SUCCESS)
1046 goto done;
1048 buffer[sz] = 0;
1049 bufferw = strdupAtoW(buffer);
1050 if (!bufferw)
1052 r = ERROR_FUNCTION_FAILED;
1053 goto done;
1056 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1057 r = wait_thread_handle( info );
1059 done:
1060 msi_free(bufferw);
1061 msi_free(buffer);
1062 msiobj_release(&row->hdr);
1063 return r;
1066 static UINT HANDLE_CustomType21_22( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1067 INT type, const WCHAR *action )
1069 msi_custom_action_info *info;
1070 MSIFILE *file;
1071 HANDLE hFile;
1072 DWORD sz, szHighWord = 0, read;
1073 CHAR *buffer=NULL;
1074 WCHAR *bufferw=NULL;
1075 BOOL bRet;
1076 UINT r;
1078 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1080 file = msi_get_loaded_file(package, source);
1081 if (!file)
1083 ERR("invalid file key %s\n", debugstr_w(source));
1084 return ERROR_FUNCTION_FAILED;
1087 hFile = CreateFileW(file->TargetPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
1088 if (hFile == INVALID_HANDLE_VALUE) return ERROR_FUNCTION_FAILED;
1090 sz = GetFileSize(hFile, &szHighWord);
1091 if (sz == INVALID_FILE_SIZE || szHighWord != 0)
1093 CloseHandle(hFile);
1094 return ERROR_FUNCTION_FAILED;
1096 buffer = msi_alloc( sz + 1 );
1097 if (!buffer)
1099 CloseHandle(hFile);
1100 return ERROR_FUNCTION_FAILED;
1102 bRet = ReadFile(hFile, buffer, sz, &read, NULL);
1103 CloseHandle(hFile);
1104 if (!bRet)
1106 r = ERROR_FUNCTION_FAILED;
1107 goto done;
1109 buffer[read] = 0;
1110 bufferw = strdupAtoW(buffer);
1111 if (!bufferw)
1113 r = ERROR_FUNCTION_FAILED;
1114 goto done;
1116 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1117 r = wait_thread_handle( info );
1119 done:
1120 msi_free(bufferw);
1121 msi_free(buffer);
1122 return r;
1125 static UINT HANDLE_CustomType53_54( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1126 INT type, const WCHAR *action )
1128 msi_custom_action_info *info;
1129 WCHAR *prop;
1131 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1133 prop = msi_dup_property( package->db, source );
1134 if (!prop) return ERROR_SUCCESS;
1136 info = do_msidbCustomActionTypeScript( package, type, prop, NULL, action );
1137 msi_free(prop);
1138 return wait_thread_handle( info );
1141 static BOOL action_type_matches_script( UINT type, UINT script )
1143 switch (script)
1145 case SCRIPT_NONE:
1146 case SCRIPT_INSTALL:
1147 return !(type & msidbCustomActionTypeCommit) && !(type & msidbCustomActionTypeRollback);
1148 case SCRIPT_COMMIT:
1149 return (type & msidbCustomActionTypeCommit);
1150 case SCRIPT_ROLLBACK:
1151 return (type & msidbCustomActionTypeRollback);
1152 default:
1153 ERR("unhandled script %u\n", script);
1155 return FALSE;
1158 static UINT defer_custom_action( MSIPACKAGE *package, const WCHAR *action, UINT type )
1160 WCHAR *actiondata = msi_dup_property( package->db, action );
1161 WCHAR *usersid = msi_dup_property( package->db, szUserSID );
1162 WCHAR *prodcode = msi_dup_property( package->db, szProductCode );
1163 WCHAR *deferred = msi_get_deferred_action( action, actiondata, usersid, prodcode );
1165 if (!deferred)
1167 msi_free( actiondata );
1168 msi_free( usersid );
1169 msi_free( prodcode );
1170 return ERROR_OUTOFMEMORY;
1172 if (type & msidbCustomActionTypeCommit)
1174 TRACE("deferring commit action\n");
1175 msi_schedule_action( package, SCRIPT_COMMIT, deferred );
1177 else if (type & msidbCustomActionTypeRollback)
1179 TRACE("deferring rollback action\n");
1180 msi_schedule_action( package, SCRIPT_ROLLBACK, deferred );
1182 else
1184 TRACE("deferring install action\n");
1185 msi_schedule_action( package, SCRIPT_INSTALL, deferred );
1188 msi_free( actiondata );
1189 msi_free( usersid );
1190 msi_free( prodcode );
1191 msi_free( deferred );
1192 return ERROR_SUCCESS;
1195 UINT ACTION_CustomAction( MSIPACKAGE *package, LPCWSTR action, UINT script )
1197 static const WCHAR query[] = {
1198 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1199 '`','C','u','s','t','o','m','A','c','t','i','o','n','`',' ','W','H','E','R','E',' ',
1200 '`','A','c','t','i' ,'o','n','`',' ','=',' ','\'','%','s','\'',0};
1201 UINT rc = ERROR_SUCCESS;
1202 MSIRECORD *row;
1203 UINT type;
1204 const WCHAR *source, *target, *ptr, *deferred_data = NULL;
1205 WCHAR *deformated = NULL;
1206 int len;
1208 /* deferred action: [properties]Action */
1209 if ((ptr = strrchrW(action, ']')))
1211 deferred_data = action;
1212 action = ptr + 1;
1215 row = MSI_QueryGetRecord( package->db, query, action );
1216 if (!row)
1217 return ERROR_CALL_NOT_IMPLEMENTED;
1219 type = MSI_RecordGetInteger(row,2);
1220 source = MSI_RecordGetString(row,3);
1221 target = MSI_RecordGetString(row,4);
1223 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action),type,
1224 debugstr_w(source), debugstr_w(target));
1226 /* handle some of the deferred actions */
1227 if (type & msidbCustomActionTypeTSAware)
1228 FIXME("msidbCustomActionTypeTSAware not handled\n");
1230 if (type & msidbCustomActionTypeInScript)
1232 if (type & msidbCustomActionTypeNoImpersonate)
1233 WARN("msidbCustomActionTypeNoImpersonate not handled\n");
1235 if (!action_type_matches_script( type, script ))
1237 rc = defer_custom_action( package, action, type );
1238 goto end;
1240 else
1242 LPWSTR actiondata = msi_dup_property( package->db, action );
1244 if (type & msidbCustomActionTypeInScript)
1245 package->scheduled_action_running = TRUE;
1247 if (type & msidbCustomActionTypeCommit)
1248 package->commit_action_running = TRUE;
1250 if (type & msidbCustomActionTypeRollback)
1251 package->rollback_action_running = TRUE;
1253 if (deferred_data)
1254 set_deferred_action_props(package, deferred_data);
1255 else if (actiondata)
1256 msi_set_property( package->db, szCustomActionData, actiondata, -1 );
1257 else
1258 msi_set_property( package->db, szCustomActionData, szEmpty, -1 );
1260 msi_free(actiondata);
1263 else if (!check_execution_scheduling_options(package,action,type))
1265 rc = ERROR_SUCCESS;
1266 goto end;
1269 switch (type & CUSTOM_ACTION_TYPE_MASK)
1271 case 1: /* DLL file stored in a Binary table stream */
1272 rc = HANDLE_CustomType1(package,source,target,type,action);
1273 break;
1274 case 2: /* EXE file stored in a Binary table stream */
1275 rc = HANDLE_CustomType2(package,source,target,type,action);
1276 break;
1277 case 18: /*EXE file installed with package */
1278 rc = HANDLE_CustomType18(package,source,target,type,action);
1279 break;
1280 case 19: /* Error that halts install */
1281 rc = HANDLE_CustomType19(package,source,target,type,action);
1282 break;
1283 case 17:
1284 rc = HANDLE_CustomType17(package,source,target,type,action);
1285 break;
1286 case 23: /* installs another package in the source tree */
1287 deformat_string(package,target,&deformated);
1288 rc = HANDLE_CustomType23(package,source,deformated,type,action);
1289 msi_free(deformated);
1290 break;
1291 case 50: /*EXE file specified by a property value */
1292 rc = HANDLE_CustomType50(package,source,target,type,action);
1293 break;
1294 case 34: /*EXE to be run in specified directory */
1295 rc = HANDLE_CustomType34(package,source,target,type,action);
1296 break;
1297 case 35: /* Directory set with formatted text. */
1298 deformat_string(package,target,&deformated);
1299 MSI_SetTargetPathW(package, source, deformated);
1300 msi_free(deformated);
1301 break;
1302 case 51: /* Property set with formatted text. */
1303 if (!source)
1304 break;
1306 len = deformat_string( package, target, &deformated );
1307 rc = msi_set_property( package->db, source, deformated, len );
1308 if (rc == ERROR_SUCCESS && !strcmpW( source, szSourceDir ))
1309 msi_reset_folders( package, TRUE );
1310 msi_free(deformated);
1311 break;
1312 case 37: /* JScript/VBScript text stored in target column. */
1313 case 38:
1314 rc = HANDLE_CustomType37_38(package,source,target,type,action);
1315 break;
1316 case 5:
1317 case 6: /* JScript/VBScript file stored in a Binary table stream. */
1318 rc = HANDLE_CustomType5_6(package,source,target,type,action);
1319 break;
1320 case 21: /* JScript/VBScript file installed with the product. */
1321 case 22:
1322 rc = HANDLE_CustomType21_22(package,source,target,type,action);
1323 break;
1324 case 53: /* JScript/VBScript text specified by a property value. */
1325 case 54:
1326 rc = HANDLE_CustomType53_54(package,source,target,type,action);
1327 break;
1328 default:
1329 FIXME("unhandled action type %u (%s %s)\n", type & CUSTOM_ACTION_TYPE_MASK,
1330 debugstr_w(source), debugstr_w(target));
1333 end:
1334 package->scheduled_action_running = FALSE;
1335 package->commit_action_running = FALSE;
1336 package->rollback_action_running = FALSE;
1337 msiobj_release(&row->hdr);
1338 return rc;
1341 void ACTION_FinishCustomActions(const MSIPACKAGE* package)
1343 struct list *item;
1344 HANDLE *wait_handles;
1345 unsigned int handle_count, i;
1346 msi_custom_action_info *info, *cursor;
1348 while ((item = list_head( &package->RunningActions )))
1350 MSIRUNNINGACTION *action = LIST_ENTRY( item, MSIRUNNINGACTION, entry );
1352 list_remove( &action->entry );
1354 TRACE("waiting for %s\n", debugstr_w( action->name ) );
1355 msi_dialog_check_messages( action->handle );
1357 CloseHandle( action->handle );
1358 msi_free( action->name );
1359 msi_free( action );
1362 EnterCriticalSection( &msi_custom_action_cs );
1364 handle_count = list_count( &msi_pending_custom_actions );
1365 wait_handles = msi_alloc( handle_count * sizeof(HANDLE) );
1367 handle_count = 0;
1368 LIST_FOR_EACH_ENTRY_SAFE( info, cursor, &msi_pending_custom_actions, msi_custom_action_info, entry )
1370 if (info->package == package )
1372 if (DuplicateHandle(GetCurrentProcess(), info->handle, GetCurrentProcess(), &wait_handles[handle_count], SYNCHRONIZE, FALSE, 0))
1373 handle_count++;
1377 LeaveCriticalSection( &msi_custom_action_cs );
1379 for (i = 0; i < handle_count; i++)
1381 msi_dialog_check_messages( wait_handles[i] );
1382 CloseHandle( wait_handles[i] );
1384 msi_free( wait_handles );
1386 EnterCriticalSection( &msi_custom_action_cs );
1387 LIST_FOR_EACH_ENTRY_SAFE( info, cursor, &msi_pending_custom_actions, msi_custom_action_info, entry )
1389 if (info->package == package) release_custom_action_data( info );
1391 LeaveCriticalSection( &msi_custom_action_cs );
1394 typedef struct _msi_custom_remote_impl {
1395 IWineMsiRemoteCustomAction IWineMsiRemoteCustomAction_iface;
1396 LONG refs;
1397 } msi_custom_remote_impl;
1399 static inline msi_custom_remote_impl *impl_from_IWineMsiRemoteCustomAction( IWineMsiRemoteCustomAction *iface )
1401 return CONTAINING_RECORD(iface, msi_custom_remote_impl, IWineMsiRemoteCustomAction_iface);
1404 static HRESULT WINAPI mcr_QueryInterface( IWineMsiRemoteCustomAction *iface,
1405 REFIID riid,LPVOID *ppobj)
1407 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
1408 IsEqualCLSID( riid, &IID_IWineMsiRemoteCustomAction ) )
1410 IWineMsiRemoteCustomAction_AddRef( iface );
1411 *ppobj = iface;
1412 return S_OK;
1415 return E_NOINTERFACE;
1418 static ULONG WINAPI mcr_AddRef( IWineMsiRemoteCustomAction *iface )
1420 msi_custom_remote_impl* This = impl_from_IWineMsiRemoteCustomAction( iface );
1422 return InterlockedIncrement( &This->refs );
1425 static ULONG WINAPI mcr_Release( IWineMsiRemoteCustomAction *iface )
1427 msi_custom_remote_impl* This = impl_from_IWineMsiRemoteCustomAction( iface );
1428 ULONG r;
1430 r = InterlockedDecrement( &This->refs );
1431 if (r == 0)
1432 msi_free( This );
1433 return r;
1436 static HRESULT WINAPI mcr_GetActionInfo( IWineMsiRemoteCustomAction *iface, LPCGUID custom_action_guid,
1437 INT *type, MSIHANDLE *handle, BSTR *dll, BSTR *func, IWineMsiRemotePackage **remote_package )
1439 msi_custom_action_info *info;
1441 info = find_action_by_guid( custom_action_guid );
1442 if (!info)
1443 return E_FAIL;
1445 *type = info->type;
1446 *handle = alloc_msihandle( &info->package->hdr );
1447 *dll = SysAllocString( info->source );
1448 *func = SysAllocString( info->target );
1450 release_custom_action_data( info );
1451 return create_msi_remote_package( NULL, (LPVOID *)remote_package );
1454 static const IWineMsiRemoteCustomActionVtbl msi_custom_remote_vtbl =
1456 mcr_QueryInterface,
1457 mcr_AddRef,
1458 mcr_Release,
1459 mcr_GetActionInfo,
1462 HRESULT create_msi_custom_remote( IUnknown *pOuter, LPVOID *ppObj )
1464 msi_custom_remote_impl* This;
1466 This = msi_alloc( sizeof *This );
1467 if (!This)
1468 return E_OUTOFMEMORY;
1470 This->IWineMsiRemoteCustomAction_iface.lpVtbl = &msi_custom_remote_vtbl;
1471 This->refs = 1;
1473 *ppObj = &This->IWineMsiRemoteCustomAction_iface;
1475 return S_OK;