2012-09-24 06:20:13 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Alistair Leslie-Hughes
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "ole2.h"
|
|
|
|
#include "msdasc.h"
|
|
|
|
#include "oledberr.h"
|
2012-11-20 18:40:28 +01:00
|
|
|
#include "initguid.h"
|
2012-09-24 06:20:13 +02:00
|
|
|
#include "oledb_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
2018-02-03 00:17:56 +01:00
|
|
|
#include "wine/heap.h"
|
2015-06-10 09:41:28 +02:00
|
|
|
#include "wine/list.h"
|
2012-09-24 06:20:13 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(oledb);
|
|
|
|
|
2020-03-02 07:37:53 +01:00
|
|
|
DEFINE_GUID(DB_NULLGUID, 0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
|
|
|
|
DEFINE_GUID(DBGUID_SESSION, 0xc8b522f5, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
|
|
|
|
DEFINE_GUID(DBGUID_ROWSET, 0xc8b522f6, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
|
|
|
|
DEFINE_GUID(DBGUID_ROW, 0xc8b522f7, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
|
|
|
|
DEFINE_GUID(DBGUID_STREAM, 0xc8b522f9, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
|
|
|
|
|
|
|
|
DEFINE_GUID(DBPROPSET_COLUMN, 0xc8b522b9, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
|
|
|
|
DEFINE_GUID(DBPROPSET_DATASOURCE, 0xc8b522ba, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
|
|
|
|
DEFINE_GUID(DBPROPSET_DATASOURCEINFO, 0xc8b522bb, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
|
|
|
|
DEFINE_GUID(DBPROPSET_DBINIT, 0xc8b522bc, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
|
|
|
|
DEFINE_GUID(DBPROPSET_INDEX, 0xc8b522bd, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
|
|
|
|
DEFINE_GUID(DBPROPSET_ROWSET, 0xc8b522be, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
|
|
|
|
DEFINE_GUID(DBPROPSET_TABLE, 0xc8b522bf, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
|
|
|
|
DEFINE_GUID(DBPROPSET_DATASOURCEALL, 0xc8b522c0, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
|
|
|
|
DEFINE_GUID(DBPROPSET_DATASOURCEINFOALL, 0xc8b522c1, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
|
|
|
|
DEFINE_GUID(DBPROPSET_ROWSETALL, 0xc8b522c2, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
|
|
|
|
DEFINE_GUID(DBPROPSET_SESSION, 0xc8b522c6, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
|
|
|
|
DEFINE_GUID(DBPROPSET_SESSIONALL, 0xc8b522c7, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
|
|
|
|
DEFINE_GUID(DBPROPSET_DBINITALL, 0xc8b522ca, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
|
|
|
|
DEFINE_GUID(DBPROPSET_PROPERTIESINERROR, 0xc8b522d4, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
|
2012-09-24 06:20:13 +02:00
|
|
|
|
|
|
|
typedef struct datainit
|
|
|
|
{
|
|
|
|
IDataInitialize IDataInitialize_iface;
|
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
} datainit;
|
|
|
|
|
|
|
|
static inline datainit *impl_from_IDataInitialize(IDataInitialize *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, datainit, IDataInitialize_iface);
|
|
|
|
}
|
|
|
|
|
2012-09-25 04:43:58 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
IDBInitialize IDBInitialize_iface;
|
2012-10-05 06:02:51 +02:00
|
|
|
IDBProperties IDBProperties_iface;
|
2012-09-25 04:43:58 +02:00
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
} dbinit;
|
|
|
|
|
|
|
|
static inline dbinit *impl_from_IDBInitialize(IDBInitialize *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, dbinit, IDBInitialize_iface);
|
|
|
|
}
|
|
|
|
|
2012-10-05 06:02:51 +02:00
|
|
|
static inline dbinit *impl_from_IDBProperties(IDBProperties *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, dbinit, IDBProperties_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dbprops_QueryInterface(IDBProperties *iface, REFIID riid, void **ppvObject)
|
|
|
|
{
|
|
|
|
dbinit *This = impl_from_IDBProperties(iface);
|
|
|
|
|
|
|
|
return IDBInitialize_QueryInterface(&This->IDBInitialize_iface, riid, ppvObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI dbprops_AddRef(IDBProperties *iface)
|
|
|
|
{
|
|
|
|
dbinit *This = impl_from_IDBProperties(iface);
|
|
|
|
|
|
|
|
return IDBInitialize_AddRef(&This->IDBInitialize_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI dbprops_Release(IDBProperties *iface)
|
|
|
|
{
|
|
|
|
dbinit *This = impl_from_IDBProperties(iface);
|
|
|
|
|
|
|
|
return IDBInitialize_Release(&This->IDBInitialize_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dbprops_GetProperties(IDBProperties *iface, ULONG cPropertyIDSets,
|
|
|
|
const DBPROPIDSET rgPropertyIDSets[], ULONG *pcPropertySets, DBPROPSET **prgPropertySets)
|
|
|
|
{
|
|
|
|
dbinit *This = impl_from_IDBProperties(iface);
|
|
|
|
|
|
|
|
FIXME("(%p)->(%d %p %p %p)\n", This, cPropertyIDSets, rgPropertyIDSets, pcPropertySets, prgPropertySets);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dbprops_GetPropertyInfo(IDBProperties *iface, ULONG cPropertyIDSets,
|
|
|
|
const DBPROPIDSET rgPropertyIDSets[], ULONG *pcPropertyInfoSets,
|
|
|
|
DBPROPINFOSET **prgPropertyInfoSets, OLECHAR **ppDescBuffer)
|
|
|
|
{
|
|
|
|
dbinit *This = impl_from_IDBProperties(iface);
|
|
|
|
|
|
|
|
FIXME("(%p)->(%d %p %p %p %p)\n", This, cPropertyIDSets, rgPropertyIDSets, pcPropertyInfoSets,
|
|
|
|
prgPropertyInfoSets, ppDescBuffer);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dbprops_SetProperties(IDBProperties *iface, ULONG cPropertySets,
|
|
|
|
DBPROPSET rgPropertySets[])
|
|
|
|
{
|
|
|
|
dbinit *This = impl_from_IDBProperties(iface);
|
|
|
|
|
|
|
|
FIXME("(%p)->(%d %p)\n", This, cPropertySets, rgPropertySets);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct IDBPropertiesVtbl dbprops_vtbl =
|
|
|
|
{
|
|
|
|
dbprops_QueryInterface,
|
|
|
|
dbprops_AddRef,
|
|
|
|
dbprops_Release,
|
|
|
|
dbprops_GetProperties,
|
|
|
|
dbprops_GetPropertyInfo,
|
|
|
|
dbprops_SetProperties
|
|
|
|
};
|
|
|
|
|
2012-09-25 04:43:58 +02:00
|
|
|
static HRESULT WINAPI dbinit_QueryInterface(IDBInitialize *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
dbinit *This = impl_from_IDBInitialize(iface);
|
|
|
|
TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
|
|
|
|
if(IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IDBInitialize))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
}
|
2012-10-05 06:02:51 +02:00
|
|
|
else if(IsEqualIID(riid, &IID_IDBProperties))
|
|
|
|
{
|
|
|
|
*obj = &This->IDBProperties_iface;
|
|
|
|
}
|
2012-09-25 04:43:58 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("interface %s not implemented\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDBInitialize_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI dbinit_AddRef(IDBInitialize *iface)
|
|
|
|
{
|
|
|
|
dbinit *This = impl_from_IDBInitialize(iface);
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
return InterlockedIncrement(&This->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI dbinit_Release(IDBInitialize *iface)
|
|
|
|
{
|
|
|
|
dbinit *This = impl_from_IDBInitialize(iface);
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
ref = InterlockedDecrement(&This->ref);
|
|
|
|
if(ref == 0)
|
2013-08-02 07:53:58 +02:00
|
|
|
heap_free(This);
|
2012-09-25 04:43:58 +02:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dbinit_Initialize(IDBInitialize *iface)
|
|
|
|
{
|
|
|
|
dbinit *This = impl_from_IDBInitialize(iface);
|
|
|
|
|
|
|
|
FIXME("(%p) stub\n", This);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI dbinit_Uninitialize(IDBInitialize *iface)
|
|
|
|
{
|
|
|
|
dbinit *This = impl_from_IDBInitialize(iface);
|
|
|
|
|
|
|
|
FIXME("(%p) stub\n", This);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IDBInitializeVtbl dbinit_vtbl =
|
|
|
|
{
|
|
|
|
dbinit_QueryInterface,
|
|
|
|
dbinit_AddRef,
|
|
|
|
dbinit_Release,
|
|
|
|
dbinit_Initialize,
|
|
|
|
dbinit_Uninitialize
|
|
|
|
};
|
|
|
|
|
2014-05-04 18:34:09 +02:00
|
|
|
static HRESULT create_db_init(IUnknown **obj)
|
2012-09-25 04:43:58 +02:00
|
|
|
{
|
|
|
|
dbinit *This;
|
|
|
|
|
|
|
|
TRACE("()\n");
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
|
2013-08-02 07:53:58 +02:00
|
|
|
This = heap_alloc(sizeof(*This));
|
2012-09-25 04:43:58 +02:00
|
|
|
if(!This) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->IDBInitialize_iface.lpVtbl = &dbinit_vtbl;
|
2012-10-05 06:02:51 +02:00
|
|
|
This->IDBProperties_iface.lpVtbl = &dbprops_vtbl;
|
2012-09-25 04:43:58 +02:00
|
|
|
This->ref = 1;
|
|
|
|
|
2014-05-04 18:34:09 +02:00
|
|
|
*obj = (IUnknown*)&This->IDBInitialize_iface;
|
2012-09-25 04:43:58 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-24 06:20:13 +02:00
|
|
|
static HRESULT WINAPI datainit_QueryInterface(IDataInitialize *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
datainit *This = impl_from_IDataInitialize(iface);
|
|
|
|
TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
|
|
|
|
if(IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IDataInitialize))
|
|
|
|
{
|
|
|
|
*obj = &This->IDataInitialize_iface;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("interface %s not implemented\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDataInitialize_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI datainit_AddRef(IDataInitialize *iface)
|
|
|
|
{
|
|
|
|
datainit *This = impl_from_IDataInitialize(iface);
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
return InterlockedIncrement(&This->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI datainit_Release(IDataInitialize *iface)
|
|
|
|
{
|
|
|
|
datainit *This = impl_from_IDataInitialize(iface);
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
ref = InterlockedDecrement(&This->ref);
|
|
|
|
if(ref == 0)
|
2013-08-02 07:53:58 +02:00
|
|
|
heap_free(This);
|
2012-09-24 06:20:13 +02:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2012-12-26 17:53:45 +01:00
|
|
|
static void free_dbpropset(ULONG count, DBPROPSET *propset)
|
|
|
|
{
|
2013-02-23 23:48:47 +01:00
|
|
|
ULONG i;
|
2012-12-26 17:53:45 +01:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2013-02-23 23:48:47 +01:00
|
|
|
ULONG p;
|
2012-12-26 17:53:45 +01:00
|
|
|
|
|
|
|
for (p = 0; p < propset[i].cProperties; p++)
|
|
|
|
VariantClear(&propset[i].rgProperties[p].vValue);
|
|
|
|
|
|
|
|
CoTaskMemFree(propset[i].rgProperties);
|
|
|
|
}
|
|
|
|
CoTaskMemFree(propset);
|
|
|
|
}
|
|
|
|
|
2013-02-10 17:01:23 +01:00
|
|
|
struct dbproperty {
|
|
|
|
const WCHAR *name;
|
|
|
|
DBPROPID id;
|
|
|
|
DBPROPOPTIONS options;
|
|
|
|
VARTYPE type;
|
2017-04-20 12:05:32 +02:00
|
|
|
HRESULT (*convert_dbproperty)(const WCHAR *src, VARIANT *dest);
|
2013-02-10 17:01:23 +01:00
|
|
|
};
|
|
|
|
|
2017-04-20 12:05:32 +02:00
|
|
|
struct mode_propval
|
|
|
|
{
|
|
|
|
const WCHAR *name;
|
|
|
|
DWORD value;
|
|
|
|
};
|
|
|
|
|
2019-06-18 08:59:55 +02:00
|
|
|
static int __cdecl dbmodeprop_compare(const void *a, const void *b)
|
2017-04-20 12:05:32 +02:00
|
|
|
{
|
|
|
|
const WCHAR *src = a;
|
|
|
|
const struct mode_propval *propval = b;
|
2019-06-18 08:59:55 +02:00
|
|
|
return wcsicmp(src, propval->name);
|
2017-04-20 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT convert_dbproperty_mode(const WCHAR *src, VARIANT *dest)
|
|
|
|
{
|
2020-11-12 07:52:33 +01:00
|
|
|
static const struct mode_propval mode_propvals[] =
|
2017-04-20 12:05:32 +02:00
|
|
|
{
|
2020-11-12 07:52:33 +01:00
|
|
|
{ L"Read", DB_MODE_READ },
|
|
|
|
{ L"ReadWrite", DB_MODE_READWRITE },
|
|
|
|
{ L"Share Deny None", DB_MODE_SHARE_DENY_NONE },
|
|
|
|
{ L"Share Deny Read", DB_MODE_SHARE_DENY_READ },
|
|
|
|
{ L"Share Deny Write", DB_MODE_SHARE_DENY_WRITE },
|
|
|
|
{ L"Share Exclusive", DB_MODE_SHARE_EXCLUSIVE },
|
|
|
|
{ L"Write", DB_MODE_WRITE },
|
2017-04-20 12:05:32 +02:00
|
|
|
};
|
|
|
|
struct mode_propval *prop;
|
|
|
|
|
2018-07-18 23:01:31 +02:00
|
|
|
if ((prop = bsearch(src, mode_propvals, ARRAY_SIZE(mode_propvals),
|
|
|
|
sizeof(struct mode_propval), dbmodeprop_compare)))
|
2017-04-20 12:05:32 +02:00
|
|
|
{
|
|
|
|
V_VT(dest) = VT_I4;
|
|
|
|
V_I4(dest) = prop->value;
|
|
|
|
TRACE("%s = %#x\n", debugstr_w(src), prop->value);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2020-11-12 07:52:33 +01:00
|
|
|
static const struct dbproperty dbproperties[] =
|
|
|
|
{
|
|
|
|
{ L"Asynchronous Processing", DBPROP_INIT_ASYNCH, DBPROPOPTIONS_OPTIONAL, VT_I4 },
|
|
|
|
{ L"Bind Flags", DBPROP_INIT_BINDFLAGS, DBPROPOPTIONS_OPTIONAL, VT_I4 },
|
|
|
|
{ L"Cache Authentication", DBPROP_AUTH_CACHE_AUTHINFO, DBPROPOPTIONS_OPTIONAL, VT_BOOL },
|
|
|
|
{ L"Connect Timeout", DBPROP_INIT_TIMEOUT, DBPROPOPTIONS_OPTIONAL, VT_I4 },
|
|
|
|
{ L"Data Source", DBPROP_INIT_DATASOURCE, DBPROPOPTIONS_REQUIRED, VT_BSTR },
|
|
|
|
{ L"Extended Properties", DBPROP_INIT_PROVIDERSTRING, DBPROPOPTIONS_REQUIRED, VT_BSTR },
|
|
|
|
{ L"Encrypt Password", DBPROP_AUTH_ENCRYPT_PASSWORD, DBPROPOPTIONS_REQUIRED, VT_BOOL },
|
|
|
|
{ L"General Timeout", DBPROP_INIT_GENERALTIMEOUT, DBPROPOPTIONS_OPTIONAL, VT_I4 },
|
|
|
|
{ L"Impersonation Level", DBPROP_INIT_IMPERSONATION_LEVEL, DBPROPOPTIONS_OPTIONAL, VT_I4 },
|
|
|
|
{ L"Initial Catalog", DBPROP_CATALOGLOCATION, DBPROPOPTIONS_OPTIONAL, VT_BSTR },
|
|
|
|
{ L"Integrated Security", DBPROP_AUTH_INTEGRATED, DBPROPOPTIONS_OPTIONAL, VT_BSTR },
|
|
|
|
{ L"Locale Identifier", DBPROP_INIT_LCID, DBPROPOPTIONS_OPTIONAL, VT_I4 },
|
|
|
|
{ L"Location", DBPROP_INIT_LOCATION, DBPROPOPTIONS_OPTIONAL, VT_BSTR },
|
|
|
|
{ L"Lock Owner", DBPROP_INIT_LOCKOWNER, DBPROPOPTIONS_OPTIONAL, VT_BSTR },
|
|
|
|
{ L"Mask Password", DBPROP_AUTH_MASK_PASSWORD, DBPROPOPTIONS_OPTIONAL, VT_BOOL },
|
|
|
|
{ L"Mode", DBPROP_INIT_MODE, DBPROPOPTIONS_OPTIONAL, VT_I4, convert_dbproperty_mode },
|
|
|
|
{ L"OLE DB Services", DBPROP_INIT_OLEDBSERVICES, DBPROPOPTIONS_OPTIONAL, VT_I4 },
|
|
|
|
{ L"Password", DBPROP_AUTH_PASSWORD, DBPROPOPTIONS_OPTIONAL, VT_BSTR },
|
|
|
|
{ L"Persist Encrypted", DBPROP_AUTH_PERSIST_ENCRYPTED, DBPROPOPTIONS_OPTIONAL, VT_BOOL },
|
|
|
|
{ L"Persist Security Info", DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, DBPROPOPTIONS_OPTIONAL, VT_BOOL },
|
|
|
|
{ L"Prompt", DBPROP_INIT_PROMPT, DBPROPOPTIONS_OPTIONAL, VT_I2 },
|
|
|
|
{ L"Protection level", DBPROP_INIT_PROTECTION_LEVEL, DBPROPOPTIONS_OPTIONAL, VT_I4 },
|
|
|
|
{ L"User ID", DBPROP_AUTH_USERID, DBPROPOPTIONS_OPTIONAL, VT_BSTR },
|
2013-06-06 07:13:29 +02:00
|
|
|
#ifndef _WIN64
|
2020-11-12 07:52:33 +01:00
|
|
|
{ L"Window Handle", DBPROP_INIT_HWND, DBPROPOPTIONS_OPTIONAL, VT_I4 },
|
2013-06-06 07:13:29 +02:00
|
|
|
#else
|
2020-11-12 07:52:33 +01:00
|
|
|
{ L"Window Handle", DBPROP_INIT_HWND, DBPROPOPTIONS_OPTIONAL, VT_I8 },
|
2013-06-06 07:13:29 +02:00
|
|
|
#endif
|
2013-02-10 17:01:23 +01:00
|
|
|
};
|
|
|
|
|
2015-06-10 09:41:28 +02:00
|
|
|
struct dbprop_pair
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
BSTR name;
|
|
|
|
BSTR value;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct dbprops
|
|
|
|
{
|
|
|
|
struct list props;
|
|
|
|
unsigned int count;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* name/value strings are reused, so they shouldn't be freed after this call */
|
|
|
|
static HRESULT add_dbprop_to_list(struct dbprops *props, BSTR name, BSTR value)
|
|
|
|
{
|
|
|
|
struct dbprop_pair *pair;
|
|
|
|
|
|
|
|
pair = heap_alloc(sizeof(*pair));
|
|
|
|
if (!pair)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
pair->name = name;
|
|
|
|
pair->value = value;
|
|
|
|
list_add_tail(&props->props, &pair->entry);
|
|
|
|
props->count++;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2013-06-06 07:13:29 +02:00
|
|
|
|
2015-06-10 09:41:28 +02:00
|
|
|
static void free_dbprop_list(struct dbprops *props)
|
|
|
|
{
|
|
|
|
struct dbprop_pair *p, *p2;
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(p, p2, &props->props, struct dbprop_pair, entry)
|
|
|
|
{
|
|
|
|
list_remove(&p->entry);
|
|
|
|
SysFreeString(p->name);
|
|
|
|
SysFreeString(p->value);
|
|
|
|
heap_free(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT parse_init_string(const WCHAR *initstring, struct dbprops *props)
|
|
|
|
{
|
|
|
|
const WCHAR *start;
|
|
|
|
WCHAR *eq;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
list_init(&props->props);
|
|
|
|
props->count = 0;
|
|
|
|
|
|
|
|
start = initstring;
|
2019-06-18 08:59:55 +02:00
|
|
|
while (start && (eq = wcschr(start, '=')))
|
2015-06-10 09:41:28 +02:00
|
|
|
{
|
2017-02-02 00:03:20 +01:00
|
|
|
WCHAR *delim, quote;
|
2015-06-10 09:41:28 +02:00
|
|
|
BSTR value, name;
|
|
|
|
|
|
|
|
name = SysAllocStringLen(start, eq - start);
|
|
|
|
/* skip equal sign to get value */
|
|
|
|
eq++;
|
2016-08-09 09:36:22 +02:00
|
|
|
|
2017-02-02 00:03:20 +01:00
|
|
|
quote = (*eq == '"' || *eq == '\'') ? *eq : 0;
|
|
|
|
if (quote)
|
2016-08-09 09:36:22 +02:00
|
|
|
{
|
|
|
|
/* for quoted value string, skip opening mark, look for terminating one */
|
|
|
|
eq++;
|
2019-06-18 08:59:55 +02:00
|
|
|
delim = wcschr(eq, quote);
|
2016-08-09 09:36:22 +02:00
|
|
|
}
|
|
|
|
else
|
2019-06-18 08:59:55 +02:00
|
|
|
delim = wcschr(eq, ';');
|
2016-08-09 09:36:22 +02:00
|
|
|
|
2017-04-20 12:05:32 +02:00
|
|
|
if (delim)
|
|
|
|
value = SysAllocStringLen(eq, delim - eq);
|
|
|
|
else
|
|
|
|
value = SysAllocString(eq);
|
2015-06-10 09:41:28 +02:00
|
|
|
|
|
|
|
/* skip semicolon if present */
|
2016-08-09 09:36:22 +02:00
|
|
|
if (delim)
|
|
|
|
{
|
2017-02-02 00:03:20 +01:00
|
|
|
if (*delim == quote)
|
2016-08-09 09:36:22 +02:00
|
|
|
delim++;
|
|
|
|
if (*delim == ';')
|
|
|
|
delim++;
|
|
|
|
}
|
|
|
|
start = delim;
|
2015-06-10 09:41:28 +02:00
|
|
|
|
2020-11-12 07:52:33 +01:00
|
|
|
if (!wcsicmp(name, L"Provider"))
|
2015-06-10 09:41:28 +02:00
|
|
|
{
|
|
|
|
SysFreeString(name);
|
|
|
|
SysFreeString(value);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("property (name=%s, value=%s)\n", debugstr_w(name), debugstr_w(value));
|
|
|
|
|
|
|
|
hr = add_dbprop_to_list(props, name, value);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
SysFreeString(name);
|
|
|
|
SysFreeString(value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
free_dbprop_list(props);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct dbproperty *get_known_dprop_descr(BSTR name)
|
2012-12-28 11:59:23 +01:00
|
|
|
{
|
2013-02-10 17:01:23 +01:00
|
|
|
int min, max, n;
|
|
|
|
|
|
|
|
min = 0;
|
2018-07-18 23:01:31 +02:00
|
|
|
max = ARRAY_SIZE(dbproperties) - 1;
|
2012-12-28 11:59:23 +01:00
|
|
|
|
2013-02-10 17:01:23 +01:00
|
|
|
while (min <= max)
|
2012-12-28 11:59:23 +01:00
|
|
|
{
|
2013-02-10 17:01:23 +01:00
|
|
|
int r;
|
|
|
|
|
|
|
|
n = (min+max)/2;
|
|
|
|
|
2019-06-18 08:59:55 +02:00
|
|
|
r = wcsicmp(dbproperties[n].name, name);
|
2013-02-10 17:01:23 +01:00
|
|
|
if (!r)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (r < 0)
|
|
|
|
min = n+1;
|
|
|
|
else
|
|
|
|
max = n-1;
|
2012-12-28 11:59:23 +01:00
|
|
|
}
|
2013-02-10 17:01:23 +01:00
|
|
|
|
2015-06-10 09:41:28 +02:00
|
|
|
return (min <= max) ? &dbproperties[n] : NULL;
|
|
|
|
}
|
2013-02-10 17:01:23 +01:00
|
|
|
|
2015-06-10 09:41:28 +02:00
|
|
|
static HRESULT get_dbpropset_from_proplist(struct dbprops *props, DBPROPSET **propset)
|
|
|
|
{
|
|
|
|
struct dbprop_pair *pair;
|
|
|
|
int i = 0;
|
|
|
|
HRESULT hr;
|
2013-02-10 17:01:23 +01:00
|
|
|
|
|
|
|
*propset = CoTaskMemAlloc(sizeof(DBPROPSET));
|
|
|
|
if (!*propset)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2015-06-10 09:41:28 +02:00
|
|
|
(*propset)->rgProperties = CoTaskMemAlloc(props->count*sizeof(DBPROP));
|
2013-02-10 17:01:23 +01:00
|
|
|
if (!(*propset)->rgProperties)
|
|
|
|
{
|
|
|
|
CoTaskMemFree(*propset);
|
2015-06-10 09:41:28 +02:00
|
|
|
*propset = NULL;
|
2013-02-10 17:01:23 +01:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2015-06-10 09:41:28 +02:00
|
|
|
(*propset)->cProperties = 0;
|
|
|
|
LIST_FOR_EACH_ENTRY(pair, &props->props, struct dbprop_pair, entry)
|
|
|
|
{
|
|
|
|
const struct dbproperty *descr = get_known_dprop_descr(pair->name);
|
|
|
|
VARIANT dest, src;
|
|
|
|
|
|
|
|
if (!descr)
|
|
|
|
{
|
|
|
|
BSTR str;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
/* provider specific property is always VT_BSTR */
|
|
|
|
len = SysStringLen(pair->name) + SysStringLen(pair->value) + 1 /* for '=' */;
|
|
|
|
str = SysAllocStringLen(NULL, len);
|
2019-06-18 08:59:55 +02:00
|
|
|
lstrcpyW(str, pair->name);
|
2020-11-12 07:52:33 +01:00
|
|
|
lstrcatW(str, L"=");
|
2019-06-18 08:59:55 +02:00
|
|
|
lstrcatW(str, pair->value);
|
2015-06-10 09:41:28 +02:00
|
|
|
|
|
|
|
(*propset)->cProperties++;
|
|
|
|
(*propset)->guidPropertySet = DBPROPSET_DBINIT;
|
|
|
|
(*propset)->rgProperties[i].dwPropertyID = DBPROP_INIT_PROVIDERSTRING;
|
|
|
|
(*propset)->rgProperties[i].dwOptions = DBPROPOPTIONS_REQUIRED;
|
|
|
|
(*propset)->rgProperties[i].dwStatus = 0;
|
|
|
|
memset(&(*propset)->rgProperties[i].colid, 0, sizeof(DBID));
|
|
|
|
V_VT(&(*propset)->rgProperties[i].vValue) = VT_BSTR;
|
|
|
|
V_BSTR(&(*propset)->rgProperties[i].vValue) = str;
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
V_VT(&src) = VT_BSTR;
|
|
|
|
V_BSTR(&src) = pair->value;
|
|
|
|
|
|
|
|
VariantInit(&dest);
|
|
|
|
hr = VariantChangeType(&dest, &src, 0, descr->type);
|
2017-04-20 12:05:32 +02:00
|
|
|
if (FAILED(hr) && descr->convert_dbproperty)
|
|
|
|
hr = descr->convert_dbproperty(pair->value, &dest);
|
|
|
|
|
2015-06-10 09:41:28 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("failed to init property %s value as type %d\n", debugstr_w(pair->name), descr->type);
|
2015-06-13 09:21:06 +02:00
|
|
|
free_dbpropset(1, *propset);
|
|
|
|
*propset = NULL;
|
2015-06-10 09:41:28 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*propset)->cProperties++;
|
|
|
|
(*propset)->guidPropertySet = DBPROPSET_DBINIT;
|
|
|
|
(*propset)->rgProperties[i].dwPropertyID = descr->id;
|
|
|
|
(*propset)->rgProperties[i].dwOptions = descr->options;
|
|
|
|
(*propset)->rgProperties[i].dwStatus = 0;
|
|
|
|
memset(&(*propset)->rgProperties[i].colid, 0, sizeof(DBID));
|
|
|
|
(*propset)->rgProperties[i].vValue = dest;
|
|
|
|
i++;
|
|
|
|
}
|
2013-02-10 17:01:23 +01:00
|
|
|
|
|
|
|
return S_OK;
|
2012-12-28 11:59:23 +01:00
|
|
|
}
|
|
|
|
|
2012-09-24 06:20:13 +02:00
|
|
|
/*** IDataInitialize methods ***/
|
2015-06-10 09:41:28 +02:00
|
|
|
static void datasource_release(BOOL created, IUnknown **datasource)
|
|
|
|
{
|
|
|
|
if (!created)
|
|
|
|
return;
|
|
|
|
|
|
|
|
IUnknown_Release(*datasource);
|
|
|
|
*datasource = NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-03 22:27:34 +01:00
|
|
|
static inline WCHAR *strdupW(const WCHAR *src)
|
|
|
|
{
|
|
|
|
WCHAR *dest;
|
|
|
|
if (!src) return NULL;
|
2019-06-18 08:59:55 +02:00
|
|
|
dest = heap_alloc((lstrlenW(src)+1)*sizeof(WCHAR));
|
2015-11-03 22:27:34 +01:00
|
|
|
if (dest)
|
2019-06-18 08:59:55 +02:00
|
|
|
lstrcpyW(dest, src);
|
2015-11-03 22:27:34 +01:00
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
static WCHAR *strstriW(const WCHAR *str, const WCHAR *sub)
|
|
|
|
{
|
|
|
|
LPWSTR strlower, sublower, r;
|
|
|
|
strlower = CharLowerW(strdupW(str));
|
|
|
|
sublower = CharLowerW(strdupW(sub));
|
2019-06-18 08:59:55 +02:00
|
|
|
r = wcsstr(strlower, sublower);
|
2015-11-03 22:27:34 +01:00
|
|
|
if (r)
|
|
|
|
r = (LPWSTR)str + (r - strlower);
|
|
|
|
heap_free(strlower);
|
|
|
|
heap_free(sublower);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2017-02-02 00:03:19 +01:00
|
|
|
HRESULT get_data_source(IUnknown *outer, DWORD clsctx, LPWSTR initstring, REFIID riid, IUnknown **datasource)
|
2012-09-24 06:20:13 +02:00
|
|
|
{
|
2020-11-12 07:52:33 +01:00
|
|
|
static const WCHAR providerW[] = L"Provider=";
|
2015-06-06 15:09:49 +02:00
|
|
|
BOOL datasource_created = FALSE;
|
2012-12-28 11:59:23 +01:00
|
|
|
IDBProperties *dbprops;
|
|
|
|
DBPROPSET *propset;
|
2012-12-26 17:53:45 +01:00
|
|
|
WCHAR *prov = NULL;
|
|
|
|
CLSID provclsid;
|
|
|
|
HRESULT hr;
|
2012-09-24 06:20:13 +02:00
|
|
|
|
|
|
|
|
2012-12-26 17:53:45 +01:00
|
|
|
/* first get provider name */
|
|
|
|
provclsid = IID_NULL;
|
2015-11-03 22:27:34 +01:00
|
|
|
if (initstring && (prov = strstriW(initstring, providerW)))
|
2012-09-25 04:43:58 +02:00
|
|
|
{
|
2012-12-26 17:53:45 +01:00
|
|
|
WCHAR *start, *progid;
|
|
|
|
int len;
|
|
|
|
|
2018-07-18 23:01:31 +02:00
|
|
|
prov += ARRAY_SIZE(providerW)-1;
|
2012-12-26 17:53:45 +01:00
|
|
|
start = prov;
|
|
|
|
while (*prov && *prov != ';')
|
|
|
|
++prov;
|
|
|
|
TRACE("got provider %s\n", debugstr_wn(start, prov-start));
|
|
|
|
|
|
|
|
len = prov - start;
|
|
|
|
progid = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
|
|
|
|
if (!progid) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
memcpy(progid, start, len*sizeof(WCHAR));
|
|
|
|
progid[len] = 0;
|
|
|
|
|
|
|
|
hr = CLSIDFromProgID(progid, &provclsid);
|
|
|
|
CoTaskMemFree(progid);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("provider %s not registered\n", debugstr_wn(start, prov-start));
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-12 07:52:33 +01:00
|
|
|
hr = CLSIDFromProgID(L"MSDASQL", &provclsid);
|
2012-12-26 17:53:45 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
ERR("ODBC provider for OLE DB not registered\n");
|
2012-09-25 04:43:58 +02:00
|
|
|
}
|
|
|
|
|
2012-12-26 17:53:45 +01:00
|
|
|
/* check for provider mismatch if it was specified in init string */
|
|
|
|
if (*datasource && prov)
|
|
|
|
{
|
|
|
|
DBPROPIDSET propidset;
|
2022-02-01 14:05:33 +01:00
|
|
|
DWORD prop;
|
2012-12-26 17:53:45 +01:00
|
|
|
CLSID initprov;
|
|
|
|
ULONG count;
|
|
|
|
|
|
|
|
hr = IUnknown_QueryInterface(*datasource, &IID_IDBProperties, (void**)&dbprops);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("provider doesn't support IDBProperties\n");
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
prop = DBPROP_INIT_DATASOURCE;
|
|
|
|
propidset.rgPropertyIDs = ∝
|
|
|
|
propidset.cPropertyIDs = 1;
|
|
|
|
propidset.guidPropertySet = DBPROPSET_DBINIT;
|
|
|
|
count = 0;
|
|
|
|
propset = NULL;
|
|
|
|
hr = IDBProperties_GetProperties(dbprops, 1, &propidset, &count, &propset);
|
|
|
|
IDBProperties_Release(dbprops);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("GetProperties failed for datasource, 0x%08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("initial data source provider %s\n", debugstr_w(V_BSTR(&propset->rgProperties[0].vValue)));
|
|
|
|
initprov = IID_NULL;
|
2015-06-03 17:32:12 +02:00
|
|
|
hr = CLSIDFromProgID(V_BSTR(&propset->rgProperties[0].vValue), &initprov);
|
2012-12-26 17:53:45 +01:00
|
|
|
free_dbpropset(count, propset);
|
|
|
|
|
2015-06-03 17:32:12 +02:00
|
|
|
if (FAILED(hr) || !IsEqualIID(&provclsid, &initprov)) return DB_E_MISMATCHEDPROVIDER;
|
2012-12-26 17:53:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!*datasource)
|
|
|
|
{
|
|
|
|
if (!IsEqualIID(&provclsid, &IID_NULL))
|
|
|
|
hr = CoCreateInstance(&provclsid, outer, clsctx, riid, (void**)datasource);
|
|
|
|
|
|
|
|
if (FAILED(hr) && IsEqualIID(riid, &IID_IDBInitialize))
|
2014-05-04 18:34:09 +02:00
|
|
|
hr = create_db_init(datasource);
|
2015-06-06 15:09:49 +02:00
|
|
|
|
|
|
|
datasource_created = *datasource != NULL;
|
2012-12-26 17:53:45 +01:00
|
|
|
}
|
|
|
|
|
2012-12-28 11:59:23 +01:00
|
|
|
/* now set properties */
|
|
|
|
if (initstring)
|
|
|
|
{
|
2015-06-10 09:41:28 +02:00
|
|
|
struct dbprops props;
|
2012-12-28 11:59:23 +01:00
|
|
|
|
|
|
|
hr = IUnknown_QueryInterface(*datasource, &IID_IDBProperties, (void**)&dbprops);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2015-06-06 15:09:49 +02:00
|
|
|
ERR("provider doesn't support IDBProperties\n");
|
2015-06-10 09:41:28 +02:00
|
|
|
datasource_release(datasource_created, datasource);
|
2012-12-28 11:59:23 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2015-06-10 09:41:28 +02:00
|
|
|
hr = parse_init_string(initstring, &props);
|
|
|
|
if (FAILED(hr))
|
2012-12-28 11:59:23 +01:00
|
|
|
{
|
2015-06-10 09:41:28 +02:00
|
|
|
datasource_release(datasource_created, datasource);
|
|
|
|
return hr;
|
|
|
|
}
|
2012-12-28 11:59:23 +01:00
|
|
|
|
2015-06-10 09:41:28 +02:00
|
|
|
hr = get_dbpropset_from_proplist(&props, &propset);
|
|
|
|
free_dbprop_list(&props);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
datasource_release(datasource_created, datasource);
|
|
|
|
return hr;
|
2012-12-28 11:59:23 +01:00
|
|
|
}
|
|
|
|
|
2015-06-10 09:41:28 +02:00
|
|
|
hr = IDBProperties_SetProperties(dbprops, 1, propset);
|
2012-12-28 11:59:23 +01:00
|
|
|
IDBProperties_Release(dbprops);
|
2015-06-10 09:41:28 +02:00
|
|
|
free_dbpropset(1, propset);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("SetProperties failed, 0x%08x\n", hr);
|
|
|
|
datasource_release(datasource_created, datasource);
|
|
|
|
return hr;
|
|
|
|
}
|
2012-12-28 11:59:23 +01:00
|
|
|
}
|
2012-12-26 17:53:45 +01:00
|
|
|
|
|
|
|
return hr;
|
2012-09-24 06:20:13 +02:00
|
|
|
}
|
|
|
|
|
2017-02-02 00:03:19 +01:00
|
|
|
static HRESULT WINAPI datainit_GetDataSource(IDataInitialize *iface, IUnknown *outer, DWORD clsctx,
|
|
|
|
LPWSTR initstring, REFIID riid, IUnknown **datasource)
|
|
|
|
{
|
|
|
|
datainit *This = impl_from_IDataInitialize(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p 0x%x %s %s %p)\n", This, outer, clsctx, debugstr_w(initstring), debugstr_guid(riid), datasource);
|
|
|
|
|
|
|
|
return get_data_source(outer, clsctx, initstring, riid, datasource);
|
|
|
|
}
|
|
|
|
|
2012-11-20 18:40:28 +01:00
|
|
|
/* returns character length of string representation */
|
|
|
|
static int get_propvalue_length(DBPROP *prop)
|
|
|
|
{
|
|
|
|
VARIANT str;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (V_VT(&prop->vValue) == VT_BSTR) return SysStringLen(V_BSTR(&prop->vValue));
|
|
|
|
|
|
|
|
VariantInit(&str);
|
|
|
|
hr = VariantChangeType(&str, &prop->vValue, 0, VT_BSTR);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
int len = SysStringLen(V_BSTR(&str));
|
|
|
|
VariantClear(&str);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_propvalue_str(WCHAR *str, DBPROP *prop)
|
|
|
|
{
|
|
|
|
VARIANT *v = &prop->vValue;
|
|
|
|
VARIANT vstr;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (V_VT(v) == VT_BSTR)
|
|
|
|
{
|
2019-06-18 08:59:55 +02:00
|
|
|
lstrcatW(str, V_BSTR(v));
|
2012-11-20 18:40:28 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VariantInit(&vstr);
|
|
|
|
hr = VariantChangeType(&vstr, v, VARIANT_ALPHABOOL, VT_BSTR);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
2019-06-18 08:59:55 +02:00
|
|
|
lstrcatW(str, V_BSTR(&vstr));
|
2012-11-20 18:40:28 +01:00
|
|
|
VariantClear(&vstr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static WCHAR *get_propinfo_descr(DBPROP *prop, DBPROPINFOSET *propinfoset)
|
2012-09-24 06:20:13 +02:00
|
|
|
{
|
2013-02-23 23:48:47 +01:00
|
|
|
ULONG i;
|
2012-11-20 18:40:28 +01:00
|
|
|
|
|
|
|
for (i = 0; i < propinfoset->cPropertyInfos; i++)
|
|
|
|
if (propinfoset->rgPropertyInfos[i].dwPropertyID == prop->dwPropertyID)
|
|
|
|
return propinfoset->rgPropertyInfos[i].pwszDescription;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_dbpropinfoset(ULONG count, DBPROPINFOSET *propinfoset)
|
|
|
|
{
|
2013-02-23 23:48:47 +01:00
|
|
|
ULONG i;
|
2012-11-20 18:40:28 +01:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2013-02-23 23:48:47 +01:00
|
|
|
ULONG p;
|
2012-11-20 18:40:28 +01:00
|
|
|
|
|
|
|
for (p = 0; p < propinfoset[i].cPropertyInfos; p++)
|
|
|
|
VariantClear(&propinfoset[i].rgPropertyInfos[p].vValues);
|
2012-12-08 10:57:03 +01:00
|
|
|
|
|
|
|
CoTaskMemFree(propinfoset[i].rgPropertyInfos);
|
2012-11-20 18:40:28 +01:00
|
|
|
}
|
2012-11-29 14:22:55 +01:00
|
|
|
CoTaskMemFree(propinfoset);
|
2012-11-20 18:40:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI datainit_GetInitializationString(IDataInitialize *iface, IUnknown *datasource,
|
|
|
|
boolean include_pass, LPWSTR *init_string)
|
|
|
|
{
|
2020-11-12 07:52:33 +01:00
|
|
|
static const WCHAR providerW[] = L"Provider=";
|
2012-09-24 06:20:13 +02:00
|
|
|
datainit *This = impl_from_IDataInitialize(iface);
|
2012-11-20 18:40:28 +01:00
|
|
|
DBPROPINFOSET *propinfoset;
|
|
|
|
IDBProperties *props;
|
|
|
|
DBPROPIDSET propidset;
|
|
|
|
ULONG count, infocount;
|
|
|
|
WCHAR *progid, *desc;
|
|
|
|
DBPROPSET *propset;
|
|
|
|
IPersist *persist;
|
|
|
|
HRESULT hr;
|
|
|
|
CLSID clsid;
|
2013-02-23 23:48:47 +01:00
|
|
|
ULONG i, len;
|
2012-11-20 18:40:28 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p %d %p)\n", This, datasource, include_pass, init_string);
|
|
|
|
|
|
|
|
/* IPersist support is mandatory for data sources */
|
|
|
|
hr = IUnknown_QueryInterface(datasource, &IID_IPersist, (void**)&persist);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
memset(&clsid, 0, sizeof(clsid));
|
|
|
|
hr = IPersist_GetClassID(persist, &clsid);
|
|
|
|
IPersist_Release(persist);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
progid = NULL;
|
|
|
|
ProgIDFromCLSID(&clsid, &progid);
|
|
|
|
TRACE("clsid=%s, progid=%s\n", debugstr_guid(&clsid), debugstr_w(progid));
|
|
|
|
|
|
|
|
/* now get initialization properties */
|
|
|
|
hr = IUnknown_QueryInterface(datasource, &IID_IDBProperties, (void**)&props);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("IDBProperties not supported\n");
|
|
|
|
CoTaskMemFree(progid);
|
|
|
|
return hr;
|
|
|
|
}
|
2012-09-24 06:20:13 +02:00
|
|
|
|
2012-11-20 18:40:28 +01:00
|
|
|
propidset.rgPropertyIDs = NULL;
|
|
|
|
propidset.cPropertyIDs = 0;
|
|
|
|
propidset.guidPropertySet = DBPROPSET_DBINIT;
|
|
|
|
propset = NULL;
|
|
|
|
count = 0;
|
|
|
|
hr = IDBProperties_GetProperties(props, 1, &propidset, &count, &propset);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("failed to get data source properties, 0x%08x\n", hr);
|
|
|
|
CoTaskMemFree(progid);
|
|
|
|
return hr;
|
|
|
|
}
|
2012-09-24 06:20:13 +02:00
|
|
|
|
2012-11-20 18:40:28 +01:00
|
|
|
infocount = 0;
|
|
|
|
IDBProperties_GetPropertyInfo(props, 1, &propidset, &infocount, &propinfoset, &desc);
|
|
|
|
IDBProperties_Release(props);
|
|
|
|
|
|
|
|
/* check if we need to skip password */
|
2020-11-12 07:52:33 +01:00
|
|
|
len = lstrlenW(progid) + lstrlenW(providerW) + 1; /* including ';' */
|
2012-11-20 18:40:28 +01:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
WCHAR *descr = get_propinfo_descr(&propset->rgProperties[i], propinfoset);
|
|
|
|
if (descr)
|
|
|
|
{
|
|
|
|
/* include '=' and ';' */
|
2019-06-18 08:59:55 +02:00
|
|
|
len += lstrlenW(descr) + 2;
|
2012-11-20 18:40:28 +01:00
|
|
|
len += get_propvalue_length(&propset->rgProperties[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((propset->rgProperties[i].dwPropertyID == DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO) &&
|
|
|
|
(V_BOOL(&propset->rgProperties[i].vValue) == VARIANT_FALSE))
|
|
|
|
include_pass = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
len *= sizeof(WCHAR);
|
|
|
|
*init_string = CoTaskMemAlloc(len);
|
|
|
|
*init_string[0] = 0;
|
|
|
|
|
|
|
|
/* provider name */
|
2020-11-12 07:52:33 +01:00
|
|
|
lstrcatW(*init_string, providerW);
|
2019-06-18 08:59:55 +02:00
|
|
|
lstrcatW(*init_string, progid);
|
2020-11-12 07:52:33 +01:00
|
|
|
lstrcatW(*init_string, L";");
|
2012-11-20 18:40:28 +01:00
|
|
|
CoTaskMemFree(progid);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
WCHAR *descr;
|
|
|
|
|
|
|
|
if (!include_pass && propset->rgProperties[i].dwPropertyID == DBPROP_AUTH_PASSWORD) continue;
|
|
|
|
|
|
|
|
descr = get_propinfo_descr(&propset->rgProperties[i], propinfoset);
|
|
|
|
if (descr)
|
|
|
|
{
|
2019-06-18 08:59:55 +02:00
|
|
|
lstrcatW(*init_string, descr);
|
2020-11-12 07:52:33 +01:00
|
|
|
lstrcatW(*init_string, L"=");
|
2012-11-20 18:40:28 +01:00
|
|
|
write_propvalue_str(*init_string, &propset->rgProperties[i]);
|
2020-11-12 07:52:33 +01:00
|
|
|
lstrcatW(*init_string, L";");
|
2012-11-20 18:40:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free_dbpropset(count, propset);
|
|
|
|
free_dbpropinfoset(infocount, propinfoset);
|
|
|
|
CoTaskMemFree(desc);
|
|
|
|
|
|
|
|
if (!include_pass)
|
|
|
|
TRACE("%s\n", debugstr_w(*init_string));
|
|
|
|
return S_OK;
|
2012-09-24 06:20:13 +02:00
|
|
|
}
|
|
|
|
|
2012-11-20 05:27:30 +01:00
|
|
|
static HRESULT WINAPI datainit_CreateDBInstance(IDataInitialize *iface, REFCLSID provider,
|
|
|
|
IUnknown *outer, DWORD clsctx, LPWSTR reserved, REFIID riid,
|
|
|
|
IUnknown **datasource)
|
2012-09-24 06:20:13 +02:00
|
|
|
{
|
|
|
|
datainit *This = impl_from_IDataInitialize(iface);
|
|
|
|
|
2012-11-20 05:27:30 +01:00
|
|
|
TRACE("(%p)->(%s %p 0x%08x %s %s %p)\n", This, debugstr_guid(provider), outer, clsctx, debugstr_w(reserved),
|
|
|
|
debugstr_guid(riid), datasource);
|
2012-09-24 06:20:13 +02:00
|
|
|
|
2012-11-20 05:27:30 +01:00
|
|
|
return CoCreateInstance(provider, outer, clsctx, riid, (void**)datasource);
|
2012-09-24 06:20:13 +02:00
|
|
|
}
|
|
|
|
|
2017-01-29 19:30:23 +01:00
|
|
|
static HRESULT WINAPI datainit_CreateDBInstanceEx(IDataInitialize *iface, REFCLSID provider, IUnknown *outer,
|
|
|
|
DWORD clsctx, LPWSTR reserved, COSERVERINFO *server_info, DWORD cmq, MULTI_QI *results)
|
2012-09-24 06:20:13 +02:00
|
|
|
{
|
|
|
|
datainit *This = impl_from_IDataInitialize(iface);
|
|
|
|
|
2017-01-29 19:30:23 +01:00
|
|
|
FIXME("(%p)->(%s %p %#x %s %p %u %p)\n", This, debugstr_guid(provider), outer, clsctx,
|
|
|
|
debugstr_w(reserved), server_info, cmq, results);
|
2012-09-24 06:20:13 +02:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI datainit_LoadStringFromStorage(IDataInitialize *iface, LPWSTR pwszFileName,
|
|
|
|
LPWSTR *ppwszInitializationString)
|
|
|
|
{
|
|
|
|
datainit *This = impl_from_IDataInitialize(iface);
|
|
|
|
|
|
|
|
FIXME("(%p)->(%s %p)\n", This, debugstr_w(pwszFileName), ppwszInitializationString);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI datainit_WriteStringToStorage(IDataInitialize *iface, LPWSTR pwszFileName,
|
|
|
|
LPWSTR pwszInitializationString, DWORD dwCreationDisposition)
|
|
|
|
{
|
|
|
|
datainit *This = impl_from_IDataInitialize(iface);
|
|
|
|
|
|
|
|
FIXME("(%p)->(%s %s %d)\n", This, debugstr_w(pwszFileName), debugstr_w(pwszInitializationString), dwCreationDisposition);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const struct IDataInitializeVtbl datainit_vtbl =
|
|
|
|
{
|
|
|
|
datainit_QueryInterface,
|
|
|
|
datainit_AddRef,
|
|
|
|
datainit_Release,
|
|
|
|
datainit_GetDataSource,
|
|
|
|
datainit_GetInitializationString,
|
|
|
|
datainit_CreateDBInstance,
|
2017-01-29 19:30:23 +01:00
|
|
|
datainit_CreateDBInstanceEx,
|
2012-09-24 06:20:13 +02:00
|
|
|
datainit_LoadStringFromStorage,
|
|
|
|
datainit_WriteStringToStorage
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT create_data_init(IUnknown *outer, void **obj)
|
|
|
|
{
|
|
|
|
datainit *This;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", obj);
|
|
|
|
|
|
|
|
if(outer) return CLASS_E_NOAGGREGATION;
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
|
2013-08-02 07:53:58 +02:00
|
|
|
This = heap_alloc(sizeof(*This));
|
2012-09-24 06:20:13 +02:00
|
|
|
if(!This) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->IDataInitialize_iface.lpVtbl = &datainit_vtbl;
|
|
|
|
This->ref = 1;
|
|
|
|
|
|
|
|
*obj = &This->IDataInitialize_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|