msi: Unlock msi_custom_action_c on the error paths.
[wine.git] / dlls / msi / custom.c
blobcd37a56d93138b6a3b8441cdb92b1787e8eae95e
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 <stdio.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winerror.h"
31 #include "msidefs.h"
32 #include "winuser.h"
33 #include "objbase.h"
34 #include "oleauto.h"
36 #include "msipriv.h"
37 #include "winemsi.h"
38 #include "wine/heap.h"
39 #include "wine/debug.h"
40 #include "wine/unicode.h"
41 #include "wine/exception.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msi);
45 #define CUSTOM_ACTION_TYPE_MASK 0x3F
47 typedef struct tagMSIRUNNINGACTION
49 struct list entry;
50 HANDLE handle;
51 BOOL process;
52 LPWSTR name;
53 } MSIRUNNINGACTION;
55 typedef UINT (WINAPI *MsiCustomActionEntryPoint)( MSIHANDLE );
57 static CRITICAL_SECTION msi_custom_action_cs;
58 static CRITICAL_SECTION_DEBUG msi_custom_action_cs_debug =
60 0, 0, &msi_custom_action_cs,
61 { &msi_custom_action_cs_debug.ProcessLocksList,
62 &msi_custom_action_cs_debug.ProcessLocksList },
63 0, 0, { (DWORD_PTR)(__FILE__ ": msi_custom_action_cs") }
65 static CRITICAL_SECTION msi_custom_action_cs = { &msi_custom_action_cs_debug, -1, 0, 0, 0, 0 };
67 static struct list msi_pending_custom_actions = LIST_INIT( msi_pending_custom_actions );
69 void __RPC_FAR * __RPC_USER MIDL_user_allocate(SIZE_T len)
71 return heap_alloc(len);
74 void __RPC_USER MIDL_user_free(void __RPC_FAR * ptr)
76 heap_free(ptr);
79 UINT msi_schedule_action( MSIPACKAGE *package, UINT script, const WCHAR *action )
81 UINT count;
82 WCHAR **newbuf = NULL;
84 if (script >= SCRIPT_MAX)
86 FIXME("Unknown script requested %u\n", script);
87 return ERROR_FUNCTION_FAILED;
89 TRACE("Scheduling action %s in script %u\n", debugstr_w(action), script);
91 count = package->script_actions_count[script];
92 package->script_actions_count[script]++;
93 if (count != 0) newbuf = msi_realloc( package->script_actions[script],
94 package->script_actions_count[script] * sizeof(WCHAR *) );
95 else newbuf = msi_alloc( sizeof(WCHAR *) );
97 newbuf[count] = strdupW( action );
98 package->script_actions[script] = newbuf;
99 return ERROR_SUCCESS;
102 UINT msi_register_unique_action( MSIPACKAGE *package, const WCHAR *action )
104 UINT count;
105 WCHAR **newbuf = NULL;
107 TRACE("Registering %s as unique action\n", debugstr_w(action));
109 count = package->unique_actions_count;
110 package->unique_actions_count++;
111 if (count != 0) newbuf = msi_realloc( package->unique_actions,
112 package->unique_actions_count * sizeof(WCHAR *) );
113 else newbuf = msi_alloc( sizeof(WCHAR *) );
115 newbuf[count] = strdupW( action );
116 package->unique_actions = newbuf;
117 return ERROR_SUCCESS;
120 BOOL msi_action_is_unique( const MSIPACKAGE *package, const WCHAR *action )
122 UINT i;
124 for (i = 0; i < package->unique_actions_count; i++)
126 if (!strcmpW( package->unique_actions[i], action )) return TRUE;
128 return FALSE;
131 static BOOL check_execution_scheduling_options(MSIPACKAGE *package, LPCWSTR action, UINT options)
133 if ((options & msidbCustomActionTypeClientRepeat) ==
134 msidbCustomActionTypeClientRepeat)
136 if (!(package->InWhatSequence & SEQUENCE_UI &&
137 package->InWhatSequence & SEQUENCE_EXEC))
139 TRACE("Skipping action due to dbCustomActionTypeClientRepeat option.\n");
140 return FALSE;
143 else if (options & msidbCustomActionTypeFirstSequence)
145 if (package->InWhatSequence & SEQUENCE_UI &&
146 package->InWhatSequence & SEQUENCE_EXEC )
148 TRACE("Skipping action due to msidbCustomActionTypeFirstSequence option.\n");
149 return FALSE;
152 else if (options & msidbCustomActionTypeOncePerProcess)
154 if (msi_action_is_unique(package, action))
156 TRACE("Skipping action due to msidbCustomActionTypeOncePerProcess option.\n");
157 return FALSE;
159 else
160 msi_register_unique_action(package, action);
163 return TRUE;
166 /* stores the following properties before the action:
168 * [CustomActionData<=>UserSID<=>ProductCode]Action
170 static LPWSTR msi_get_deferred_action(LPCWSTR action, LPCWSTR actiondata,
171 LPCWSTR usersid, LPCWSTR prodcode)
173 LPWSTR deferred;
174 DWORD len;
176 static const WCHAR format[] = {
177 '[','%','s','<','=','>','%','s','<','=','>','%','s',']','%','s',0
180 if (!actiondata)
181 return strdupW(action);
183 len = lstrlenW(action) + lstrlenW(actiondata) +
184 lstrlenW(usersid) + lstrlenW(prodcode) +
185 lstrlenW(format) - 7;
186 deferred = msi_alloc(len * sizeof(WCHAR));
188 sprintfW(deferred, format, actiondata, usersid, prodcode, action);
189 return deferred;
192 static void set_deferred_action_props( MSIPACKAGE *package, const WCHAR *deferred_data )
194 static const WCHAR sep[] = {'<','=','>',0};
195 const WCHAR *end, *beg = deferred_data + 1;
197 end = strstrW(beg, sep);
198 msi_set_property( package->db, szCustomActionData, beg, end - beg );
199 beg = end + 3;
201 end = strstrW(beg, sep);
202 msi_set_property( package->db, szUserSID, beg, end - beg );
203 beg = end + 3;
205 end = strchrW(beg, ']');
206 msi_set_property( package->db, szProductCode, beg, end - beg );
209 WCHAR *msi_create_temp_file( MSIDATABASE *db )
211 WCHAR *ret;
213 if (!db->tempfolder)
215 WCHAR tmp[MAX_PATH];
216 UINT len = sizeof(tmp)/sizeof(tmp[0]);
218 if (msi_get_property( db, szTempFolder, tmp, &len ) ||
219 GetFileAttributesW( tmp ) != FILE_ATTRIBUTE_DIRECTORY)
221 GetTempPathW( MAX_PATH, tmp );
223 if (!(db->tempfolder = strdupW( tmp ))) return NULL;
226 if ((ret = msi_alloc( (strlenW( db->tempfolder ) + 20) * sizeof(WCHAR) )))
228 if (!GetTempFileNameW( db->tempfolder, szMsi, 0, ret ))
230 msi_free( ret );
231 return NULL;
235 return ret;
238 static MSIBINARY *create_temp_binary(MSIPACKAGE *package, LPCWSTR source)
240 static const WCHAR query[] = {
241 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
242 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
243 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
244 MSIRECORD *row;
245 MSIBINARY *binary = NULL;
246 HANDLE file;
247 CHAR buffer[1024];
248 WCHAR *tmpfile;
249 DWORD sz, write;
250 UINT r;
252 if (!(tmpfile = msi_create_temp_file( package->db ))) return NULL;
254 if (!(row = MSI_QueryGetRecord( package->db, query, source ))) goto error;
255 if (!(binary = msi_alloc_zero( sizeof(MSIBINARY) ))) goto error;
257 file = CreateFileW( tmpfile, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
258 if (file == INVALID_HANDLE_VALUE) goto error;
262 sz = sizeof(buffer);
263 r = MSI_RecordReadStream( row, 2, buffer, &sz );
264 if (r != ERROR_SUCCESS)
266 ERR("Failed to get stream\n");
267 break;
269 WriteFile( file, buffer, sz, &write, NULL );
270 } while (sz == sizeof buffer);
272 CloseHandle( file );
273 if (r != ERROR_SUCCESS) goto error;
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)
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);
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 MSIPACKAGE *package;
384 LPWSTR source;
385 LPWSTR target;
386 HANDLE handle;
387 LPWSTR action;
388 INT type;
389 GUID guid;
390 DWORD arch;
391 } msi_custom_action_info;
393 static void free_custom_action_data( msi_custom_action_info *info )
395 EnterCriticalSection( &msi_custom_action_cs );
397 list_remove( &info->entry );
398 if (info->handle)
399 CloseHandle( info->handle );
400 msi_free( info->action );
401 msi_free( info->source );
402 msi_free( info->target );
403 msiobj_release( &info->package->hdr );
404 msi_free( info );
406 LeaveCriticalSection( &msi_custom_action_cs );
409 static UINT wait_thread_handle( msi_custom_action_info *info )
411 UINT rc = ERROR_SUCCESS;
413 if (!(info->type & msidbCustomActionTypeAsync))
415 TRACE("waiting for %s\n", debugstr_w( info->action ));
417 msi_dialog_check_messages( info->handle );
419 if (!(info->type & msidbCustomActionTypeContinue))
420 rc = custom_get_thread_return( info->package, info->handle );
422 free_custom_action_data( info );
424 else
426 TRACE("%s running in background\n", debugstr_w( info->action ));
429 return rc;
432 static msi_custom_action_info *find_action_by_guid( const GUID *guid )
434 msi_custom_action_info *info;
435 BOOL found = FALSE;
437 EnterCriticalSection( &msi_custom_action_cs );
439 LIST_FOR_EACH_ENTRY( info, &msi_pending_custom_actions, msi_custom_action_info, entry )
441 if (IsEqualGUID( &info->guid, guid ))
443 found = TRUE;
444 break;
448 LeaveCriticalSection( &msi_custom_action_cs );
450 if (!found)
451 return NULL;
453 return info;
456 static void handle_msi_break(LPCSTR target)
458 char format[] = "To debug your custom action, attach your debugger to "
459 "process %i (0x%X) and press OK";
460 char val[MAX_PATH];
461 char msg[100];
463 if (!GetEnvironmentVariableA("MsiBreak", val, MAX_PATH))
464 return;
466 if (strcasecmp(val, target))
467 return;
469 sprintf(msg, format, GetCurrentProcessId(), GetCurrentProcessId());
470 MessageBoxA(NULL, msg, "Windows Installer", MB_OK);
471 DebugBreak();
474 static WCHAR ncalrpcW[] = {'n','c','a','l','r','p','c',0};
475 static WCHAR endpoint_lrpcW[] = {'m','s','i',0};
477 #ifdef __i386__
478 /* wrapper for apps that don't declare the thread function correctly */
479 extern UINT custom_proc_wrapper( MsiCustomActionEntryPoint entry, MSIHANDLE hinst );
480 __ASM_GLOBAL_FUNC(custom_proc_wrapper,
481 "pushl %ebp\n\t"
482 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
483 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
484 "movl %esp,%ebp\n\t"
485 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
486 "subl $4,%esp\n\t"
487 "pushl 12(%ebp)\n\t"
488 "call *8(%ebp)\n\t"
489 "leave\n\t"
490 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
491 __ASM_CFI(".cfi_same_value %ebp\n\t")
492 "ret" )
493 #else
494 static UINT custom_proc_wrapper( MsiCustomActionEntryPoint entry, MSIHANDLE hinst )
496 return entry(hinst);
498 #endif
500 UINT CDECL __wine_msi_call_dll_function(const GUID *guid)
502 MsiCustomActionEntryPoint fn;
503 MSIHANDLE remote_package = 0;
504 RPC_WSTR binding_str;
505 MSIHANDLE hPackage;
506 RPC_STATUS status;
507 LPWSTR dll = NULL;
508 LPSTR proc = NULL;
509 HANDLE hModule;
510 INT type;
511 UINT r;
513 TRACE("%s\n", debugstr_guid( guid ));
515 if (!rpc_handle)
517 status = RpcStringBindingComposeW(NULL, ncalrpcW, NULL, endpoint_lrpcW, NULL, &binding_str);
518 if (status != RPC_S_OK)
520 ERR("RpcStringBindingCompose failed: %#x\n", status);
521 return status;
523 status = RpcBindingFromStringBindingW(binding_str, &rpc_handle);
524 if (status != RPC_S_OK)
526 ERR("RpcBindingFromStringBinding failed: %#x\n", status);
527 return status;
529 RpcStringFreeW(&binding_str);
532 r = remote_GetActionInfo(guid, &type, &dll, &proc, &remote_package);
533 if (r != ERROR_SUCCESS)
534 return r;
536 hModule = LoadLibraryW( dll );
537 if (!hModule)
539 ERR( "failed to load dll %s (%u)\n", debugstr_w( dll ), GetLastError() );
540 return ERROR_SUCCESS;
543 fn = (MsiCustomActionEntryPoint) GetProcAddress( hModule, proc );
544 if (fn)
546 hPackage = alloc_msi_remote_handle( remote_package );
547 if (hPackage)
549 TRACE("calling %s\n", debugstr_a(proc));
550 handle_msi_break(proc);
552 __TRY
554 r = custom_proc_wrapper(fn, hPackage);
556 __EXCEPT_PAGE_FAULT
558 ERR("Custom action (%s:%s) caused a page fault: %08x\n",
559 debugstr_w(dll), debugstr_a(proc), GetExceptionCode());
560 r = ERROR_SUCCESS;
562 __ENDTRY;
564 MsiCloseHandle( hPackage );
566 else
567 ERR("failed to create handle for %x\n", remote_package );
569 else
570 ERR("GetProcAddress(%s) failed\n", debugstr_a(proc));
572 FreeLibrary(hModule);
574 midl_user_free(dll);
575 midl_user_free(proc);
577 return r;
580 static DWORD custom_start_server(MSIPACKAGE *package, DWORD arch)
582 static const WCHAR pipe_name[] = {'\\','\\','.','\\','p','i','p','e','\\','m','s','i','c','a','_','%','x','_','%','d',0};
583 static const WCHAR msiexecW[] = {'\\','m','s','i','e','x','e','c','.','e','x','e',0};
584 static const WCHAR argsW[] = {'%','s',' ','-','E','m','b','e','d','d','i','n','g',' ','%','d',0};
586 WCHAR path[MAX_PATH], cmdline[MAX_PATH + 23];
587 PROCESS_INFORMATION pi = {0};
588 STARTUPINFOW si = {0};
589 WCHAR buffer[24];
590 void *cookie;
591 HANDLE pipe;
592 BOOL wow64;
594 if ((arch == SCS_32BIT_BINARY && package->custom_server_32_process) ||
595 (arch == SCS_64BIT_BINARY && package->custom_server_64_process))
596 return ERROR_SUCCESS;
598 sprintfW(buffer, pipe_name, GetCurrentProcessId(), arch == SCS_32BIT_BINARY ? 32 : 64);
599 pipe = CreateNamedPipeW(buffer, PIPE_ACCESS_DUPLEX, 0, 1, sizeof(DWORD64),
600 sizeof(GUID), 0, NULL);
601 if (pipe == INVALID_HANDLE_VALUE)
602 ERR("Failed to create custom action client pipe: %u\n", GetLastError());
604 if (sizeof(void *) == 8 && arch == SCS_32BIT_BINARY)
605 GetSystemWow64DirectoryW(path, MAX_PATH - sizeof(msiexecW)/sizeof(WCHAR));
606 else
607 GetSystemDirectoryW(path, MAX_PATH - sizeof(msiexecW)/sizeof(WCHAR));
608 strcatW(path, msiexecW);
609 sprintfW(cmdline, argsW, path, GetCurrentProcessId());
611 if (IsWow64Process(GetCurrentProcess(), &wow64) && wow64 && arch == SCS_64BIT_BINARY)
613 Wow64DisableWow64FsRedirection(&cookie);
614 CreateProcessW(path, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
615 Wow64RevertWow64FsRedirection(cookie);
617 else
618 CreateProcessW(path, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
620 CloseHandle(pi.hThread);
622 if (arch == SCS_32BIT_BINARY)
624 package->custom_server_32_process = pi.hProcess;
625 package->custom_server_32_pipe = pipe;
627 else
629 package->custom_server_64_process = pi.hProcess;
630 package->custom_server_64_pipe = pipe;
633 if (!ConnectNamedPipe(pipe, NULL))
635 ERR("Failed to connect to custom action server: %u\n", GetLastError());
636 return GetLastError();
639 return ERROR_SUCCESS;
642 void custom_stop_server(HANDLE process, HANDLE pipe)
644 DWORD size;
646 WriteFile(pipe, &GUID_NULL, sizeof(GUID_NULL), &size, NULL);
647 WaitForSingleObject(process, INFINITE);
648 CloseHandle(process);
649 CloseHandle(pipe);
652 static DWORD WINAPI custom_client_thread(void *arg)
654 msi_custom_action_info *info = arg;
655 DWORD64 thread64;
656 HANDLE process;
657 HANDLE thread;
658 HANDLE pipe;
659 DWORD size;
660 UINT rc;
662 CoInitializeEx(NULL, COINIT_MULTITHREADED); /* needed to marshal streams */
664 if (info->arch == SCS_32BIT_BINARY)
666 process = info->package->custom_server_32_process;
667 pipe = info->package->custom_server_32_pipe;
669 else
671 process = info->package->custom_server_64_process;
672 pipe = info->package->custom_server_64_pipe;
675 EnterCriticalSection(&msi_custom_action_cs);
677 if (!WriteFile(pipe, &info->guid, sizeof(info->guid), &size, NULL) ||
678 size != sizeof(info->guid))
680 ERR("Failed to write to custom action client pipe: %u\n", GetLastError());
681 LeaveCriticalSection(&msi_custom_action_cs);
682 return GetLastError();
684 if (!ReadFile(pipe, &thread64, sizeof(thread64), &size, NULL) || size != sizeof(thread64))
686 ERR("Failed to read from custom action client pipe: %u\n", GetLastError());
687 LeaveCriticalSection(&msi_custom_action_cs);
688 return GetLastError();
691 LeaveCriticalSection(&msi_custom_action_cs);
693 if (DuplicateHandle(process, (HANDLE)(DWORD_PTR)thread64, GetCurrentProcess(),
694 &thread, 0, FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
696 WaitForSingleObject(thread, INFINITE);
697 GetExitCodeThread(thread, &rc);
698 CloseHandle(thread);
700 else
701 rc = GetLastError();
703 CoUninitialize();
704 return rc;
707 static msi_custom_action_info *do_msidbCustomActionTypeDll(
708 MSIPACKAGE *package, INT type, LPCWSTR source, LPCWSTR target, LPCWSTR action )
710 msi_custom_action_info *info;
711 RPC_STATUS status;
712 BOOL ret;
714 info = msi_alloc( sizeof *info );
715 if (!info)
716 return NULL;
718 msiobj_addref( &package->hdr );
719 info->package = package;
720 info->type = type;
721 info->target = strdupW( target );
722 info->source = strdupW( source );
723 info->action = strdupW( action );
724 CoCreateGuid( &info->guid );
726 EnterCriticalSection( &msi_custom_action_cs );
727 list_add_tail( &msi_pending_custom_actions, &info->entry );
728 LeaveCriticalSection( &msi_custom_action_cs );
730 if (!package->rpc_server_started)
732 status = RpcServerUseProtseqEpW(ncalrpcW, RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
733 endpoint_lrpcW, NULL);
734 if (status != RPC_S_OK)
736 ERR("RpcServerUseProtseqEp failed: %#x\n", status);
737 return NULL;
740 status = RpcServerRegisterIfEx(s_IWineMsiRemote_v0_0_s_ifspec, NULL, NULL,
741 RPC_IF_AUTOLISTEN, RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL);
742 if (status != RPC_S_OK)
744 ERR("RpcServerRegisterIfEx failed: %#x\n", status);
745 return NULL;
748 info->package->rpc_server_started = 1;
751 ret = GetBinaryTypeW(source, &info->arch);
752 if (!ret)
753 info->arch = (sizeof(void *) == 8 ? SCS_64BIT_BINARY : SCS_32BIT_BINARY);
755 custom_start_server(package, info->arch);
757 info->handle = CreateThread(NULL, 0, custom_client_thread, info, 0, NULL);
758 if (!info->handle)
760 free_custom_action_data( info );
761 return NULL;
764 return info;
767 static UINT HANDLE_CustomType1( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
768 INT type, const WCHAR *action )
770 msi_custom_action_info *info;
771 MSIBINARY *binary;
773 if (!(binary = get_temp_binary(package, source)))
774 return ERROR_FUNCTION_FAILED;
776 TRACE("Calling function %s from %s\n", debugstr_w(target), debugstr_w(binary->tmpfile));
778 info = do_msidbCustomActionTypeDll( package, type, binary->tmpfile, target, action );
779 return wait_thread_handle( info );
782 static HANDLE execute_command( const WCHAR *app, WCHAR *arg, const WCHAR *dir )
784 static const WCHAR dotexeW[] = {'.','e','x','e',0};
785 STARTUPINFOW si;
786 PROCESS_INFORMATION info;
787 WCHAR *exe = NULL, *cmd = NULL, *p;
788 BOOL ret;
790 if (app)
792 int len_arg = 0;
793 DWORD len_exe;
795 if (!(exe = msi_alloc( MAX_PATH * sizeof(WCHAR) ))) return INVALID_HANDLE_VALUE;
796 len_exe = SearchPathW( NULL, app, dotexeW, MAX_PATH, exe, NULL );
797 if (len_exe >= MAX_PATH)
799 msi_free( exe );
800 if (!(exe = msi_alloc( len_exe * sizeof(WCHAR) ))) return INVALID_HANDLE_VALUE;
801 len_exe = SearchPathW( NULL, app, dotexeW, len_exe, exe, NULL );
803 if (!len_exe)
805 ERR("can't find executable %u\n", GetLastError());
806 msi_free( exe );
807 return INVALID_HANDLE_VALUE;
810 if (arg) len_arg = strlenW( arg );
811 if (!(cmd = msi_alloc( (len_exe + len_arg + 4) * sizeof(WCHAR) )))
813 msi_free( exe );
814 return INVALID_HANDLE_VALUE;
816 p = cmd;
817 if (strchrW( exe, ' ' ))
819 *p++ = '\"';
820 memcpy( p, exe, len_exe * sizeof(WCHAR) );
821 p += len_exe;
822 *p++ = '\"';
823 *p = 0;
825 else
827 strcpyW( p, exe );
828 p += len_exe;
830 if (arg)
832 *p++ = ' ';
833 memcpy( p, arg, len_arg * sizeof(WCHAR) );
834 p[len_arg] = 0;
837 memset( &si, 0, sizeof(STARTUPINFOW) );
838 ret = CreateProcessW( exe, exe ? cmd : arg, NULL, NULL, FALSE, 0, NULL, dir, &si, &info );
839 msi_free( cmd );
840 msi_free( exe );
841 if (!ret)
843 ERR("unable to execute command %u\n", GetLastError());
844 return INVALID_HANDLE_VALUE;
846 CloseHandle( info.hThread );
847 return info.hProcess;
850 static UINT HANDLE_CustomType2( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
851 INT type, const WCHAR *action )
853 MSIBINARY *binary;
854 HANDLE handle;
855 WCHAR *arg;
857 if (!(binary = get_temp_binary(package, source)))
858 return ERROR_FUNCTION_FAILED;
860 deformat_string( package, target, &arg );
861 TRACE("exe %s arg %s\n", debugstr_w(binary->tmpfile), debugstr_w(arg));
863 handle = execute_command( binary->tmpfile, arg, szCRoot );
864 msi_free( arg );
865 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
866 return wait_process_handle( package, type, handle, action );
869 static UINT HANDLE_CustomType17( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
870 INT type, const WCHAR *action )
872 msi_custom_action_info *info;
873 MSIFILE *file;
875 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
877 file = msi_get_loaded_file( package, source );
878 if (!file)
880 ERR("invalid file key %s\n", debugstr_w( source ));
881 return ERROR_FUNCTION_FAILED;
884 info = do_msidbCustomActionTypeDll( package, type, file->TargetPath, target, action );
885 return wait_thread_handle( info );
888 static UINT HANDLE_CustomType18( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
889 INT type, const WCHAR *action )
891 MSIFILE *file;
892 HANDLE handle;
893 WCHAR *arg;
895 if (!(file = msi_get_loaded_file( package, source ))) return ERROR_FUNCTION_FAILED;
897 deformat_string( package, target, &arg );
898 TRACE("exe %s arg %s\n", debugstr_w(file->TargetPath), debugstr_w(arg));
900 handle = execute_command( file->TargetPath, arg, szCRoot );
901 msi_free( arg );
902 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
903 return wait_process_handle( package, type, handle, action );
906 static UINT HANDLE_CustomType19( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
907 INT type, const WCHAR *action )
909 static const WCHAR query[] = {
910 'S','E','L','E','C','T',' ','`','M','e','s','s','a','g','e','`',' ',
911 'F','R','O','M',' ','`','E','r','r','o','r','`',' ',
912 'W','H','E','R','E',' ','`','E','r','r','o','r','`',' ','=',' ',
913 '%','s',0
915 MSIRECORD *row = 0;
916 LPWSTR deformated = NULL;
918 deformat_string( package, target, &deformated );
920 /* first try treat the error as a number */
921 row = MSI_QueryGetRecord( package->db, query, deformated );
922 if( row )
924 LPCWSTR error = MSI_RecordGetString( row, 1 );
925 if ((package->ui_level & INSTALLUILEVEL_MASK) != INSTALLUILEVEL_NONE)
926 MessageBoxW( NULL, error, NULL, MB_OK );
927 msiobj_release( &row->hdr );
929 else if ((package->ui_level & INSTALLUILEVEL_MASK) != INSTALLUILEVEL_NONE)
930 MessageBoxW( NULL, deformated, NULL, MB_OK );
932 msi_free( deformated );
934 return ERROR_INSTALL_FAILURE;
937 static UINT HANDLE_CustomType23( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
938 INT type, const WCHAR *action )
940 static const WCHAR msiexecW[] = {'m','s','i','e','x','e','c',0};
941 static const WCHAR paramsW[] = {'/','q','b',' ','/','i',' '};
942 WCHAR *dir, *arg, *p;
943 UINT len_src, len_dir, len_tgt, len = sizeof(paramsW)/sizeof(paramsW[0]);
944 HANDLE handle;
946 if (!(dir = msi_dup_property( package->db, szOriginalDatabase ))) return ERROR_OUTOFMEMORY;
947 if (!(p = strrchrW( dir, '\\' )) && !(p = strrchrW( dir, '/' )))
949 msi_free( dir );
950 return ERROR_FUNCTION_FAILED;
952 *p = 0;
953 len_dir = p - dir;
954 len_src = strlenW( source );
955 len_tgt = strlenW( target );
956 if (!(arg = msi_alloc( (len + len_dir + len_src + len_tgt + 5) * sizeof(WCHAR) )))
958 msi_free( dir );
959 return ERROR_OUTOFMEMORY;
961 memcpy( arg, paramsW, sizeof(paramsW) );
962 arg[len++] = '"';
963 memcpy( arg + len, dir, len_dir * sizeof(WCHAR) );
964 len += len_dir;
965 arg[len++] = '\\';
966 memcpy( arg + len, source, len_src * sizeof(WCHAR) );
967 len += len_src;
968 arg[len++] = '"';
969 arg[len++] = ' ';
970 strcpyW( arg + len, target );
972 TRACE("installing %s concurrently\n", debugstr_w(source));
974 handle = execute_command( msiexecW, arg, dir );
975 msi_free( dir );
976 msi_free( arg );
977 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
978 return wait_process_handle( package, type, handle, action );
981 static UINT HANDLE_CustomType50( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
982 INT type, const WCHAR *action )
984 WCHAR *exe, *arg;
985 HANDLE handle;
987 if (!(exe = msi_dup_property( package->db, source ))) return ERROR_SUCCESS;
989 deformat_string( package, target, &arg );
990 TRACE("exe %s arg %s\n", debugstr_w(exe), debugstr_w(arg));
992 handle = execute_command( exe, arg, szCRoot );
993 msi_free( exe );
994 msi_free( arg );
995 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
996 return wait_process_handle( package, type, handle, action );
999 static UINT HANDLE_CustomType34( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1000 INT type, const WCHAR *action )
1002 const WCHAR *workingdir = NULL;
1003 HANDLE handle;
1004 WCHAR *cmd;
1006 if (source)
1008 workingdir = msi_get_target_folder( package, source );
1009 if (!workingdir) return ERROR_FUNCTION_FAILED;
1011 deformat_string( package, target, &cmd );
1012 if (!cmd) return ERROR_FUNCTION_FAILED;
1014 TRACE("cmd %s dir %s\n", debugstr_w(cmd), debugstr_w(workingdir));
1016 handle = execute_command( NULL, cmd, workingdir );
1017 msi_free( cmd );
1018 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
1019 return wait_process_handle( package, type, handle, action );
1022 static DWORD ACTION_CallScript( const GUID *guid )
1024 msi_custom_action_info *info;
1025 MSIHANDLE hPackage;
1026 UINT r = ERROR_FUNCTION_FAILED;
1028 info = find_action_by_guid( guid );
1029 if (!info)
1031 ERR("failed to find action %s\n", debugstr_guid( guid) );
1032 return ERROR_FUNCTION_FAILED;
1035 TRACE("function %s, script %s\n", debugstr_w( info->target ), debugstr_w( info->source ) );
1037 hPackage = alloc_msihandle( &info->package->hdr );
1038 if (hPackage)
1040 r = call_script( hPackage, info->type, info->source, info->target, info->action );
1041 TRACE("script returned %u\n", r);
1042 MsiCloseHandle( hPackage );
1044 else
1045 ERR("failed to create handle for %p\n", info->package );
1047 return r;
1050 static DWORD WINAPI ScriptThread( LPVOID arg )
1052 LPGUID guid = arg;
1053 DWORD rc;
1055 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
1057 rc = ACTION_CallScript( guid );
1059 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc );
1061 MsiCloseAllHandles();
1062 return rc;
1065 static msi_custom_action_info *do_msidbCustomActionTypeScript(
1066 MSIPACKAGE *package, INT type, LPCWSTR script, LPCWSTR function, LPCWSTR action )
1068 msi_custom_action_info *info;
1070 info = msi_alloc( sizeof *info );
1071 if (!info)
1072 return NULL;
1074 msiobj_addref( &package->hdr );
1075 info->package = package;
1076 info->type = type;
1077 info->target = strdupW( function );
1078 info->source = strdupW( script );
1079 info->action = strdupW( action );
1080 CoCreateGuid( &info->guid );
1082 EnterCriticalSection( &msi_custom_action_cs );
1083 list_add_tail( &msi_pending_custom_actions, &info->entry );
1084 LeaveCriticalSection( &msi_custom_action_cs );
1086 info->handle = CreateThread( NULL, 0, ScriptThread, &info->guid, 0, NULL );
1087 if (!info->handle)
1089 free_custom_action_data( info );
1090 return NULL;
1093 return info;
1096 static UINT HANDLE_CustomType37_38( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1097 INT type, const WCHAR *action )
1099 msi_custom_action_info *info;
1101 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1103 info = do_msidbCustomActionTypeScript( package, type, target, NULL, action );
1104 return wait_thread_handle( info );
1107 static UINT HANDLE_CustomType5_6( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1108 INT type, const WCHAR *action )
1110 static const WCHAR query[] = {
1111 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1112 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
1113 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
1114 MSIRECORD *row = NULL;
1115 msi_custom_action_info *info;
1116 CHAR *buffer = NULL;
1117 WCHAR *bufferw = NULL;
1118 DWORD sz = 0;
1119 UINT r;
1121 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1123 row = MSI_QueryGetRecord(package->db, query, source);
1124 if (!row)
1125 return ERROR_FUNCTION_FAILED;
1127 r = MSI_RecordReadStream(row, 2, NULL, &sz);
1128 if (r != ERROR_SUCCESS) goto done;
1130 buffer = msi_alloc( sz + 1 );
1131 if (!buffer)
1133 r = ERROR_FUNCTION_FAILED;
1134 goto done;
1137 r = MSI_RecordReadStream(row, 2, buffer, &sz);
1138 if (r != ERROR_SUCCESS)
1139 goto done;
1141 buffer[sz] = 0;
1142 bufferw = strdupAtoW(buffer);
1143 if (!bufferw)
1145 r = ERROR_FUNCTION_FAILED;
1146 goto done;
1149 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1150 r = wait_thread_handle( info );
1152 done:
1153 msi_free(bufferw);
1154 msi_free(buffer);
1155 msiobj_release(&row->hdr);
1156 return r;
1159 static UINT HANDLE_CustomType21_22( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1160 INT type, const WCHAR *action )
1162 msi_custom_action_info *info;
1163 MSIFILE *file;
1164 HANDLE hFile;
1165 DWORD sz, szHighWord = 0, read;
1166 CHAR *buffer=NULL;
1167 WCHAR *bufferw=NULL;
1168 BOOL bRet;
1169 UINT r;
1171 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1173 file = msi_get_loaded_file(package, source);
1174 if (!file)
1176 ERR("invalid file key %s\n", debugstr_w(source));
1177 return ERROR_FUNCTION_FAILED;
1180 hFile = CreateFileW(file->TargetPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
1181 if (hFile == INVALID_HANDLE_VALUE) return ERROR_FUNCTION_FAILED;
1183 sz = GetFileSize(hFile, &szHighWord);
1184 if (sz == INVALID_FILE_SIZE || szHighWord != 0)
1186 CloseHandle(hFile);
1187 return ERROR_FUNCTION_FAILED;
1189 buffer = msi_alloc( sz + 1 );
1190 if (!buffer)
1192 CloseHandle(hFile);
1193 return ERROR_FUNCTION_FAILED;
1195 bRet = ReadFile(hFile, buffer, sz, &read, NULL);
1196 CloseHandle(hFile);
1197 if (!bRet)
1199 r = ERROR_FUNCTION_FAILED;
1200 goto done;
1202 buffer[read] = 0;
1203 bufferw = strdupAtoW(buffer);
1204 if (!bufferw)
1206 r = ERROR_FUNCTION_FAILED;
1207 goto done;
1209 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1210 r = wait_thread_handle( info );
1212 done:
1213 msi_free(bufferw);
1214 msi_free(buffer);
1215 return r;
1218 static UINT HANDLE_CustomType53_54( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1219 INT type, const WCHAR *action )
1221 msi_custom_action_info *info;
1222 WCHAR *prop;
1224 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1226 prop = msi_dup_property( package->db, source );
1227 if (!prop) return ERROR_SUCCESS;
1229 info = do_msidbCustomActionTypeScript( package, type, prop, NULL, action );
1230 msi_free(prop);
1231 return wait_thread_handle( info );
1234 static BOOL action_type_matches_script( UINT type, UINT script )
1236 switch (script)
1238 case SCRIPT_NONE:
1239 return FALSE;
1240 case SCRIPT_INSTALL:
1241 return !(type & msidbCustomActionTypeCommit) && !(type & msidbCustomActionTypeRollback);
1242 case SCRIPT_COMMIT:
1243 return (type & msidbCustomActionTypeCommit);
1244 case SCRIPT_ROLLBACK:
1245 return (type & msidbCustomActionTypeRollback);
1246 default:
1247 ERR("unhandled script %u\n", script);
1249 return FALSE;
1252 static UINT defer_custom_action( MSIPACKAGE *package, const WCHAR *action, UINT type )
1254 WCHAR *actiondata = msi_dup_property( package->db, action );
1255 WCHAR *usersid = msi_dup_property( package->db, szUserSID );
1256 WCHAR *prodcode = msi_dup_property( package->db, szProductCode );
1257 WCHAR *deferred = msi_get_deferred_action( action, actiondata, usersid, prodcode );
1259 if (!deferred)
1261 msi_free( actiondata );
1262 msi_free( usersid );
1263 msi_free( prodcode );
1264 return ERROR_OUTOFMEMORY;
1266 if (type & msidbCustomActionTypeCommit)
1268 TRACE("deferring commit action\n");
1269 msi_schedule_action( package, SCRIPT_COMMIT, deferred );
1271 else if (type & msidbCustomActionTypeRollback)
1273 TRACE("deferring rollback action\n");
1274 msi_schedule_action( package, SCRIPT_ROLLBACK, deferred );
1276 else
1278 TRACE("deferring install action\n");
1279 msi_schedule_action( package, SCRIPT_INSTALL, deferred );
1282 msi_free( actiondata );
1283 msi_free( usersid );
1284 msi_free( prodcode );
1285 msi_free( deferred );
1286 return ERROR_SUCCESS;
1289 UINT ACTION_CustomAction(MSIPACKAGE *package, const WCHAR *action)
1291 static const WCHAR query[] = {
1292 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1293 '`','C','u','s','t','o','m','A','c','t','i','o','n','`',' ','W','H','E','R','E',' ',
1294 '`','A','c','t','i' ,'o','n','`',' ','=',' ','\'','%','s','\'',0};
1295 UINT rc = ERROR_SUCCESS;
1296 MSIRECORD *row;
1297 UINT type;
1298 const WCHAR *source, *target, *ptr, *deferred_data = NULL;
1299 WCHAR *deformated = NULL;
1300 int len;
1302 /* deferred action: [properties]Action */
1303 if ((ptr = strrchrW(action, ']')))
1305 deferred_data = action;
1306 action = ptr + 1;
1309 row = MSI_QueryGetRecord( package->db, query, action );
1310 if (!row)
1311 return ERROR_FUNCTION_NOT_CALLED;
1313 type = MSI_RecordGetInteger(row,2);
1314 source = MSI_RecordGetString(row,3);
1315 target = MSI_RecordGetString(row,4);
1317 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action),type,
1318 debugstr_w(source), debugstr_w(target));
1320 /* handle some of the deferred actions */
1321 if (type & msidbCustomActionTypeTSAware)
1322 FIXME("msidbCustomActionTypeTSAware not handled\n");
1324 if (type & msidbCustomActionTypeInScript)
1326 if (type & msidbCustomActionTypeNoImpersonate)
1327 WARN("msidbCustomActionTypeNoImpersonate not handled\n");
1329 if (!action_type_matches_script(type, package->script))
1331 rc = defer_custom_action( package, action, type );
1332 goto end;
1334 else
1336 LPWSTR actiondata = msi_dup_property( package->db, action );
1338 if (type & msidbCustomActionTypeInScript)
1339 package->scheduled_action_running = TRUE;
1341 if (type & msidbCustomActionTypeCommit)
1342 package->commit_action_running = TRUE;
1344 if (type & msidbCustomActionTypeRollback)
1345 package->rollback_action_running = TRUE;
1347 if (deferred_data)
1348 set_deferred_action_props(package, deferred_data);
1349 else if (actiondata)
1350 msi_set_property( package->db, szCustomActionData, actiondata, -1 );
1351 else
1352 msi_set_property( package->db, szCustomActionData, szEmpty, -1 );
1354 msi_free(actiondata);
1357 else if (!check_execution_scheduling_options(package,action,type))
1359 rc = ERROR_SUCCESS;
1360 goto end;
1363 switch (type & CUSTOM_ACTION_TYPE_MASK)
1365 case 1: /* DLL file stored in a Binary table stream */
1366 rc = HANDLE_CustomType1(package,source,target,type,action);
1367 break;
1368 case 2: /* EXE file stored in a Binary table stream */
1369 rc = HANDLE_CustomType2(package,source,target,type,action);
1370 break;
1371 case 18: /*EXE file installed with package */
1372 rc = HANDLE_CustomType18(package,source,target,type,action);
1373 break;
1374 case 19: /* Error that halts install */
1375 rc = HANDLE_CustomType19(package,source,target,type,action);
1376 break;
1377 case 17:
1378 rc = HANDLE_CustomType17(package,source,target,type,action);
1379 break;
1380 case 23: /* installs another package in the source tree */
1381 deformat_string(package,target,&deformated);
1382 rc = HANDLE_CustomType23(package,source,deformated,type,action);
1383 msi_free(deformated);
1384 break;
1385 case 50: /*EXE file specified by a property value */
1386 rc = HANDLE_CustomType50(package,source,target,type,action);
1387 break;
1388 case 34: /*EXE to be run in specified directory */
1389 rc = HANDLE_CustomType34(package,source,target,type,action);
1390 break;
1391 case 35: /* Directory set with formatted text. */
1392 deformat_string(package,target,&deformated);
1393 MSI_SetTargetPathW(package, source, deformated);
1394 msi_free(deformated);
1395 break;
1396 case 51: /* Property set with formatted text. */
1397 if (!source)
1398 break;
1400 len = deformat_string( package, target, &deformated );
1401 rc = msi_set_property( package->db, source, deformated, len );
1402 if (rc == ERROR_SUCCESS && !strcmpW( source, szSourceDir ))
1403 msi_reset_folders( package, TRUE );
1404 msi_free(deformated);
1405 break;
1406 case 37: /* JScript/VBScript text stored in target column. */
1407 case 38:
1408 rc = HANDLE_CustomType37_38(package,source,target,type,action);
1409 break;
1410 case 5:
1411 case 6: /* JScript/VBScript file stored in a Binary table stream. */
1412 rc = HANDLE_CustomType5_6(package,source,target,type,action);
1413 break;
1414 case 21: /* JScript/VBScript file installed with the product. */
1415 case 22:
1416 rc = HANDLE_CustomType21_22(package,source,target,type,action);
1417 break;
1418 case 53: /* JScript/VBScript text specified by a property value. */
1419 case 54:
1420 rc = HANDLE_CustomType53_54(package,source,target,type,action);
1421 break;
1422 default:
1423 FIXME("unhandled action type %u (%s %s)\n", type & CUSTOM_ACTION_TYPE_MASK,
1424 debugstr_w(source), debugstr_w(target));
1427 end:
1428 package->scheduled_action_running = FALSE;
1429 package->commit_action_running = FALSE;
1430 package->rollback_action_running = FALSE;
1431 msiobj_release(&row->hdr);
1432 return rc;
1435 void ACTION_FinishCustomActions(const MSIPACKAGE* package)
1437 struct list *item;
1438 HANDLE *wait_handles;
1439 unsigned int handle_count, i;
1440 msi_custom_action_info *info, *cursor;
1442 while ((item = list_head( &package->RunningActions )))
1444 MSIRUNNINGACTION *action = LIST_ENTRY( item, MSIRUNNINGACTION, entry );
1446 list_remove( &action->entry );
1448 TRACE("waiting for %s\n", debugstr_w( action->name ) );
1449 msi_dialog_check_messages( action->handle );
1451 CloseHandle( action->handle );
1452 msi_free( action->name );
1453 msi_free( action );
1456 EnterCriticalSection( &msi_custom_action_cs );
1458 handle_count = list_count( &msi_pending_custom_actions );
1459 wait_handles = msi_alloc( handle_count * sizeof(HANDLE) );
1461 handle_count = 0;
1462 LIST_FOR_EACH_ENTRY_SAFE( info, cursor, &msi_pending_custom_actions, msi_custom_action_info, entry )
1464 if (info->package == package )
1466 if (DuplicateHandle(GetCurrentProcess(), info->handle, GetCurrentProcess(), &wait_handles[handle_count], SYNCHRONIZE, FALSE, 0))
1467 handle_count++;
1471 LeaveCriticalSection( &msi_custom_action_cs );
1473 for (i = 0; i < handle_count; i++)
1475 msi_dialog_check_messages( wait_handles[i] );
1476 CloseHandle( wait_handles[i] );
1478 msi_free( wait_handles );
1480 EnterCriticalSection( &msi_custom_action_cs );
1481 LIST_FOR_EACH_ENTRY_SAFE( info, cursor, &msi_pending_custom_actions, msi_custom_action_info, entry )
1483 if (info->package == package)
1484 free_custom_action_data( info );
1486 LeaveCriticalSection( &msi_custom_action_cs );
1489 UINT __cdecl s_remote_GetActionInfo(const GUID *guid, int *type, LPWSTR *dll, LPSTR *func, MSIHANDLE *hinst)
1491 msi_custom_action_info *info;
1493 info = find_action_by_guid(guid);
1494 if (!info)
1495 return ERROR_INVALID_DATA;
1497 *type = info->type;
1498 *hinst = alloc_msihandle(&info->package->hdr);
1499 *dll = strdupW(info->source);
1500 *func = strdupWtoA(info->target);
1502 return ERROR_SUCCESS;