2003-08-13 03:27:48 +02:00
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
2004-07-10 00:25:34 +02:00
|
|
|
* Copyright 2002-2004 Mike McCormack for CodeWeavers
|
2003-08-13 03:27:48 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-08-13 03:27:48 +02:00
|
|
|
*/
|
|
|
|
|
2007-06-27 02:02:06 +02:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "shlwapi.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "msi.h"
|
|
|
|
#include "msiquery.h"
|
2018-04-16 03:52:10 +02:00
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
#include "msipriv.h"
|
2018-04-16 03:52:10 +02:00
|
|
|
#include "winemsi.h"
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msi);
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
static CRITICAL_SECTION MSI_handle_cs;
|
|
|
|
static CRITICAL_SECTION_DEBUG MSI_handle_cs_debug =
|
|
|
|
{
|
|
|
|
0, 0, &MSI_handle_cs,
|
|
|
|
{ &MSI_handle_cs_debug.ProcessLocksList,
|
|
|
|
&MSI_handle_cs_debug.ProcessLocksList },
|
2005-09-09 12:19:44 +02:00
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": MSI_handle_cs") }
|
2004-07-10 00:25:34 +02:00
|
|
|
};
|
|
|
|
static CRITICAL_SECTION MSI_handle_cs = { &MSI_handle_cs_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
2004-12-27 20:29:33 +01:00
|
|
|
static CRITICAL_SECTION MSI_object_cs;
|
|
|
|
static CRITICAL_SECTION_DEBUG MSI_object_cs_debug =
|
|
|
|
{
|
|
|
|
0, 0, &MSI_object_cs,
|
|
|
|
{ &MSI_object_cs_debug.ProcessLocksList,
|
|
|
|
&MSI_object_cs_debug.ProcessLocksList },
|
2005-09-09 12:19:44 +02:00
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": MSI_object_cs") }
|
2004-12-27 20:29:33 +01:00
|
|
|
};
|
|
|
|
static CRITICAL_SECTION MSI_object_cs = { &MSI_object_cs_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
2005-01-06 21:43:04 +01:00
|
|
|
typedef struct msi_handle_info_t
|
|
|
|
{
|
2007-06-27 02:02:06 +02:00
|
|
|
BOOL remote;
|
|
|
|
union {
|
|
|
|
MSIOBJECTHDR *obj;
|
2018-04-16 03:52:10 +02:00
|
|
|
MSIHANDLE rem;
|
2007-06-27 02:02:06 +02:00
|
|
|
} u;
|
2005-01-06 21:43:04 +01:00
|
|
|
DWORD dwThreadId;
|
|
|
|
} msi_handle_info;
|
|
|
|
|
2006-08-28 16:51:30 +02:00
|
|
|
static msi_handle_info *msihandletable = NULL;
|
2007-06-27 14:14:49 +02:00
|
|
|
static unsigned int msihandletable_size = 0;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2006-08-29 10:08:01 +02:00
|
|
|
void msi_free_handle_table(void)
|
|
|
|
{
|
|
|
|
msi_free( msihandletable );
|
|
|
|
msihandletable = NULL;
|
|
|
|
msihandletable_size = 0;
|
2011-11-17 09:52:38 +01:00
|
|
|
DeleteCriticalSection(&MSI_handle_cs);
|
|
|
|
DeleteCriticalSection(&MSI_object_cs);
|
2006-08-29 10:08:01 +02:00
|
|
|
}
|
|
|
|
|
2007-06-27 02:02:06 +02:00
|
|
|
static MSIHANDLE alloc_handle_table_entry(void)
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
/* find a slot */
|
2006-08-28 16:51:30 +02:00
|
|
|
for(i=0; i<msihandletable_size; i++)
|
2018-04-16 03:52:10 +02:00
|
|
|
if( !msihandletable[i].u.obj && !msihandletable[i].u.rem )
|
2003-08-13 03:27:48 +02:00
|
|
|
break;
|
2006-08-28 16:51:30 +02:00
|
|
|
if( i==msihandletable_size )
|
|
|
|
{
|
|
|
|
msi_handle_info *p;
|
|
|
|
int newsize;
|
|
|
|
if (msihandletable_size == 0)
|
|
|
|
{
|
|
|
|
newsize = 256;
|
|
|
|
p = msi_alloc_zero(newsize*sizeof(msi_handle_info));
|
|
|
|
}
|
2006-08-29 10:08:01 +02:00
|
|
|
else
|
|
|
|
{
|
2006-08-28 16:51:30 +02:00
|
|
|
newsize = msihandletable_size * 2;
|
|
|
|
p = msi_realloc_zero(msihandletable,
|
|
|
|
newsize*sizeof(msi_handle_info));
|
2006-08-29 10:08:01 +02:00
|
|
|
}
|
2006-08-28 16:51:30 +02:00
|
|
|
if (!p)
|
2007-06-27 02:02:06 +02:00
|
|
|
return 0;
|
2006-08-28 16:51:30 +02:00
|
|
|
msihandletable = p;
|
|
|
|
msihandletable_size = newsize;
|
|
|
|
}
|
2007-06-27 02:02:06 +02:00
|
|
|
return i + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
MSIHANDLE alloc_msihandle( MSIOBJECTHDR *obj )
|
|
|
|
{
|
|
|
|
msi_handle_info *entry;
|
|
|
|
MSIHANDLE ret;
|
|
|
|
|
|
|
|
EnterCriticalSection( &MSI_handle_cs );
|
|
|
|
|
|
|
|
ret = alloc_handle_table_entry();
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
entry = &msihandletable[ ret - 1 ];
|
|
|
|
msiobj_addref( obj );
|
|
|
|
entry->u.obj = obj;
|
|
|
|
entry->dwThreadId = GetCurrentThreadId();
|
|
|
|
entry->remote = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection( &MSI_handle_cs );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%p -> %d\n", obj, ret );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2007-06-27 02:02:06 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-04-16 03:52:10 +02:00
|
|
|
MSIHANDLE alloc_msi_remote_handle(MSIHANDLE remote)
|
2007-06-27 02:02:06 +02:00
|
|
|
{
|
|
|
|
msi_handle_info *entry;
|
|
|
|
MSIHANDLE ret;
|
|
|
|
|
|
|
|
EnterCriticalSection( &MSI_handle_cs );
|
|
|
|
|
|
|
|
ret = alloc_handle_table_entry();
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
entry = &msihandletable[ ret - 1 ];
|
2018-04-16 03:52:10 +02:00
|
|
|
entry->u.rem = remote;
|
2007-06-27 02:02:06 +02:00
|
|
|
entry->dwThreadId = GetCurrentThreadId();
|
|
|
|
entry->remote = TRUE;
|
|
|
|
}
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
LeaveCriticalSection( &MSI_handle_cs );
|
2007-06-27 02:02:06 +02:00
|
|
|
|
2018-04-16 03:52:10 +02:00
|
|
|
TRACE("%d -> %d\n", remote, ret);
|
2007-06-27 02:02:06 +02:00
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
return ret;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void *msihandle2msiinfo(MSIHANDLE handle, UINT type)
|
|
|
|
{
|
2004-07-10 00:25:34 +02:00
|
|
|
MSIOBJECTHDR *ret = NULL;
|
|
|
|
|
|
|
|
EnterCriticalSection( &MSI_handle_cs );
|
2003-08-13 03:27:48 +02:00
|
|
|
handle--;
|
2007-06-27 02:02:06 +02:00
|
|
|
if( handle >= msihandletable_size )
|
2004-07-10 00:25:34 +02:00
|
|
|
goto out;
|
2007-06-27 02:02:06 +02:00
|
|
|
if( msihandletable[handle].remote)
|
2004-07-10 00:25:34 +02:00
|
|
|
goto out;
|
2007-06-27 02:02:06 +02:00
|
|
|
if( !msihandletable[handle].u.obj )
|
2004-07-10 00:25:34 +02:00
|
|
|
goto out;
|
2007-06-27 02:02:06 +02:00
|
|
|
if( msihandletable[handle].u.obj->magic != MSIHANDLE_MAGIC )
|
2004-07-10 00:25:34 +02:00
|
|
|
goto out;
|
2007-06-27 02:02:06 +02:00
|
|
|
if( type && (msihandletable[handle].u.obj->type != type) )
|
|
|
|
goto out;
|
|
|
|
ret = msihandletable[handle].u.obj;
|
2004-07-10 00:25:34 +02:00
|
|
|
msiobj_addref( ret );
|
2006-11-01 07:09:02 +01:00
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
out:
|
|
|
|
LeaveCriticalSection( &MSI_handle_cs );
|
|
|
|
|
2009-01-15 09:46:57 +01:00
|
|
|
return ret;
|
2004-07-10 00:25:34 +02:00
|
|
|
}
|
|
|
|
|
2018-04-16 03:52:10 +02:00
|
|
|
MSIHANDLE msi_get_remote( MSIHANDLE handle )
|
2007-06-27 02:02:06 +02:00
|
|
|
{
|
2018-04-16 03:52:10 +02:00
|
|
|
MSIHANDLE ret = 0;
|
2007-06-27 02:02:06 +02:00
|
|
|
|
|
|
|
EnterCriticalSection( &MSI_handle_cs );
|
|
|
|
handle--;
|
|
|
|
if( handle>=msihandletable_size )
|
|
|
|
goto out;
|
|
|
|
if( !msihandletable[handle].remote)
|
|
|
|
goto out;
|
2018-04-16 03:52:10 +02:00
|
|
|
ret = msihandletable[handle].u.rem;
|
2007-06-27 02:02:06 +02:00
|
|
|
|
|
|
|
out:
|
|
|
|
LeaveCriticalSection( &MSI_handle_cs );
|
|
|
|
|
2018-04-16 03:52:10 +02:00
|
|
|
return ret;
|
2007-06-27 02:02:06 +02:00
|
|
|
}
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
void *alloc_msiobject(UINT type, UINT size, msihandledestructor destroy )
|
2004-06-28 22:34:35 +02:00
|
|
|
{
|
2004-07-10 00:25:34 +02:00
|
|
|
MSIOBJECTHDR *info;
|
2004-06-28 22:34:35 +02:00
|
|
|
|
2005-09-20 13:57:19 +02:00
|
|
|
info = msi_alloc_zero( size );
|
2004-07-10 00:25:34 +02:00
|
|
|
if( info )
|
|
|
|
{
|
|
|
|
info->magic = MSIHANDLE_MAGIC;
|
|
|
|
info->type = type;
|
|
|
|
info->refcount = 1;
|
|
|
|
info->destructor = destroy;
|
|
|
|
}
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
void msiobj_addref( MSIOBJECTHDR *info )
|
|
|
|
{
|
2004-06-28 22:34:35 +02:00
|
|
|
if( !info )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( info->magic != MSIHANDLE_MAGIC )
|
|
|
|
{
|
|
|
|
ERR("Invalid handle!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-01-20 21:34:29 +01:00
|
|
|
InterlockedIncrement(&info->refcount);
|
2004-06-28 22:34:35 +02:00
|
|
|
}
|
|
|
|
|
2004-12-27 20:29:33 +01:00
|
|
|
void msiobj_lock( MSIOBJECTHDR *info )
|
|
|
|
{
|
|
|
|
EnterCriticalSection( &MSI_object_cs );
|
|
|
|
}
|
|
|
|
|
|
|
|
void msiobj_unlock( MSIOBJECTHDR *info )
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &MSI_object_cs );
|
|
|
|
}
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
int msiobj_release( MSIOBJECTHDR *info )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2004-07-10 00:25:34 +02:00
|
|
|
int ret;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
if( !info )
|
2004-07-10 00:25:34 +02:00
|
|
|
return -1;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
if( info->magic != MSIHANDLE_MAGIC )
|
|
|
|
{
|
|
|
|
ERR("Invalid handle!\n");
|
2004-07-10 00:25:34 +02:00
|
|
|
return -1;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
2005-01-20 21:34:29 +01:00
|
|
|
ret = InterlockedDecrement( &info->refcount );
|
|
|
|
if( ret==0 )
|
2004-07-10 00:25:34 +02:00
|
|
|
{
|
2005-01-20 21:34:29 +01:00
|
|
|
if( info->destructor )
|
2004-07-10 00:25:34 +02:00
|
|
|
info->destructor( info );
|
2005-09-20 13:57:19 +02:00
|
|
|
msi_free( info );
|
2004-07-10 00:25:34 +02:00
|
|
|
TRACE("object %p destroyed\n", info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-01-06 21:43:04 +01:00
|
|
|
/***********************************************************
|
|
|
|
* MsiCloseHandle [MSI.@]
|
|
|
|
*/
|
2004-07-10 00:25:34 +02:00
|
|
|
UINT WINAPI MsiCloseHandle(MSIHANDLE handle)
|
|
|
|
{
|
2007-06-27 02:02:06 +02:00
|
|
|
MSIOBJECTHDR *info = NULL;
|
2004-07-10 00:25:34 +02:00
|
|
|
UINT ret = ERROR_INVALID_HANDLE;
|
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%x\n",handle);
|
2004-07-10 00:25:34 +02:00
|
|
|
|
2006-06-11 02:51:42 +02:00
|
|
|
if (!handle)
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
EnterCriticalSection( &MSI_handle_cs );
|
|
|
|
|
2007-06-27 14:14:49 +02:00
|
|
|
handle--;
|
|
|
|
if (handle >= msihandletable_size)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (msihandletable[handle].remote)
|
2004-07-10 00:25:34 +02:00
|
|
|
{
|
2018-04-16 03:52:10 +02:00
|
|
|
remote_CloseHandle( msihandletable[handle].u.rem );
|
2004-07-10 00:25:34 +02:00
|
|
|
}
|
2007-06-27 02:02:06 +02:00
|
|
|
else
|
|
|
|
{
|
2007-06-27 14:14:49 +02:00
|
|
|
info = msihandletable[handle].u.obj;
|
2007-06-27 02:02:06 +02:00
|
|
|
if( !info )
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if( info->magic != MSIHANDLE_MAGIC )
|
|
|
|
{
|
|
|
|
ERR("Invalid handle!\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-27 14:14:49 +02:00
|
|
|
msihandletable[handle].u.obj = NULL;
|
|
|
|
msihandletable[handle].remote = 0;
|
|
|
|
msihandletable[handle].dwThreadId = 0;
|
2004-07-10 00:25:34 +02:00
|
|
|
|
|
|
|
ret = ERROR_SUCCESS;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("handle %x destroyed\n", handle+1);
|
2004-07-10 00:25:34 +02:00
|
|
|
out:
|
|
|
|
LeaveCriticalSection( &MSI_handle_cs );
|
|
|
|
if( info )
|
|
|
|
msiobj_release( info );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
return ret;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
2005-01-06 21:43:04 +01:00
|
|
|
/***********************************************************
|
|
|
|
* MsiCloseAllHandles [MSI.@]
|
|
|
|
*
|
|
|
|
* Closes all handles owned by the current thread
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* The number of handles closed
|
|
|
|
*/
|
2003-08-13 03:27:48 +02:00
|
|
|
UINT WINAPI MsiCloseAllHandles(void)
|
|
|
|
{
|
2005-01-06 21:43:04 +01:00
|
|
|
UINT i, n=0;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2006-08-28 16:51:30 +02:00
|
|
|
EnterCriticalSection( &MSI_handle_cs );
|
|
|
|
for(i=0; i<msihandletable_size; i++)
|
2005-01-06 21:43:04 +01:00
|
|
|
{
|
|
|
|
if(msihandletable[i].dwThreadId == GetCurrentThreadId())
|
|
|
|
{
|
2006-08-28 16:51:30 +02:00
|
|
|
LeaveCriticalSection( &MSI_handle_cs );
|
2005-01-06 21:43:04 +01:00
|
|
|
MsiCloseHandle( i+1 );
|
2006-08-28 16:51:30 +02:00
|
|
|
EnterCriticalSection( &MSI_handle_cs );
|
2005-01-06 21:43:04 +01:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
2006-08-28 16:51:30 +02:00
|
|
|
LeaveCriticalSection( &MSI_handle_cs );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-01-06 21:43:04 +01:00
|
|
|
return n;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
2018-04-16 03:52:10 +02:00
|
|
|
|
2018-04-26 03:54:40 +02:00
|
|
|
UINT __cdecl s_remote_CloseHandle(MSIHANDLE handle)
|
2018-04-16 03:52:10 +02:00
|
|
|
{
|
|
|
|
return MsiCloseHandle(handle);
|
|
|
|
}
|