2006-05-22 22:59:52 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2006 Juan Lang
|
|
|
|
*
|
|
|
|
* 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-26 12:08:32 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-05-22 22:59:52 +02:00
|
|
|
*/
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wincrypt.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "crypt32_private.h"
|
|
|
|
|
2009-11-04 01:44:44 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(context);
|
2006-05-22 22:59:52 +02:00
|
|
|
|
2013-10-21 15:58:56 +02:00
|
|
|
context_t *Context_CreateDataContext(size_t contextSize, const context_vtbl_t *vtbl, WINECRYPT_CERTSTORE *store)
|
2006-05-22 22:59:52 +02:00
|
|
|
{
|
2013-10-17 11:08:25 +02:00
|
|
|
context_t *context;
|
2006-05-22 22:59:52 +02:00
|
|
|
|
2013-10-17 11:08:25 +02:00
|
|
|
context = CryptMemAlloc(sizeof(context_t) + contextSize);
|
2013-10-08 16:23:48 +02:00
|
|
|
if (!context)
|
|
|
|
return NULL;
|
2006-05-22 22:59:52 +02:00
|
|
|
|
2013-10-14 14:46:52 +02:00
|
|
|
context->properties = ContextPropertyList_Create();
|
|
|
|
if (!context->properties)
|
2013-10-08 16:23:48 +02:00
|
|
|
{
|
|
|
|
CryptMemFree(context);
|
|
|
|
return NULL;
|
2006-05-22 22:59:52 +02:00
|
|
|
}
|
2013-10-08 16:23:48 +02:00
|
|
|
|
2013-10-18 10:50:43 +02:00
|
|
|
context->vtbl = vtbl;
|
|
|
|
context->ref = 1;
|
|
|
|
context->linked = NULL;
|
|
|
|
|
|
|
|
store->vtbl->addref(store);
|
|
|
|
context->store = store;
|
|
|
|
|
2013-10-08 16:23:48 +02:00
|
|
|
TRACE("returning %p\n", context);
|
2013-10-21 15:58:56 +02:00
|
|
|
return context;
|
2006-05-22 22:59:52 +02:00
|
|
|
}
|
|
|
|
|
2013-10-18 10:50:43 +02:00
|
|
|
context_t *Context_CreateLinkContext(unsigned int contextSize, context_t *linked, WINECRYPT_CERTSTORE *store)
|
2006-05-22 22:59:52 +02:00
|
|
|
{
|
2013-10-14 14:48:06 +02:00
|
|
|
context_t *context;
|
2006-05-22 22:59:52 +02:00
|
|
|
|
2013-10-15 16:53:26 +02:00
|
|
|
TRACE("(%d, %p)\n", contextSize, linked);
|
2006-05-22 22:59:52 +02:00
|
|
|
|
2013-10-15 16:53:26 +02:00
|
|
|
context = CryptMemAlloc(sizeof(context_t) + contextSize);
|
2013-10-08 16:23:48 +02:00
|
|
|
if (!context)
|
|
|
|
return NULL;
|
|
|
|
|
2013-10-14 14:48:06 +02:00
|
|
|
memcpy(context_ptr(context), context_ptr(linked), contextSize);
|
|
|
|
context->vtbl = linked->vtbl;
|
2013-10-08 16:23:48 +02:00
|
|
|
context->ref = 1;
|
2013-10-14 14:48:06 +02:00
|
|
|
context->linked = linked;
|
2013-10-17 11:07:24 +02:00
|
|
|
context->properties = linked->properties;
|
2013-10-14 14:48:06 +02:00
|
|
|
Context_AddRef(linked);
|
2013-10-08 16:23:48 +02:00
|
|
|
|
2013-10-18 10:50:43 +02:00
|
|
|
store->vtbl->addref(store);
|
|
|
|
context->store = store;
|
|
|
|
|
2007-08-07 23:56:26 +02:00
|
|
|
TRACE("returning %p\n", context);
|
2013-10-14 14:48:06 +02:00
|
|
|
return context;
|
2006-05-22 22:59:52 +02:00
|
|
|
}
|
|
|
|
|
2013-10-14 14:47:07 +02:00
|
|
|
void Context_AddRef(context_t *context)
|
2006-05-22 22:59:52 +02:00
|
|
|
{
|
2013-10-18 10:50:43 +02:00
|
|
|
LONG ref = InterlockedIncrement(&context->ref);
|
|
|
|
|
2013-10-14 14:47:07 +02:00
|
|
|
TRACE("(%p) ref=%d\n", context, context->ref);
|
2013-10-18 10:50:43 +02:00
|
|
|
|
|
|
|
if(ref == 1) {
|
|
|
|
/* This is the first external (non-store) reference. Increase store ref cnt. */
|
|
|
|
context->store->vtbl->addref(context->store);
|
|
|
|
}
|
2006-05-22 22:59:52 +02:00
|
|
|
}
|
|
|
|
|
2013-10-18 10:50:43 +02:00
|
|
|
void Context_Free(context_t *context)
|
2006-05-22 22:59:52 +02:00
|
|
|
{
|
2013-10-18 10:50:43 +02:00
|
|
|
TRACE("(%p)\n", context);
|
|
|
|
|
|
|
|
assert(!context->ref);
|
|
|
|
|
|
|
|
if (!context->linked) {
|
|
|
|
ContextPropertyList_Free(context->properties);
|
|
|
|
context->vtbl->free(context);
|
|
|
|
}else {
|
|
|
|
Context_Release(context->linked);
|
2009-11-04 01:46:50 +01:00
|
|
|
}
|
2013-10-18 10:50:43 +02:00
|
|
|
|
|
|
|
CryptMemFree(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Context_Release(context_t *context)
|
|
|
|
{
|
|
|
|
LONG ref = InterlockedDecrement(&context->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", context, ref);
|
|
|
|
assert(ref >= 0);
|
|
|
|
|
|
|
|
if (!ref) {
|
2013-10-22 12:29:34 +02:00
|
|
|
WINECRYPT_CERTSTORE *store = context->store;
|
|
|
|
|
2013-10-18 10:50:43 +02:00
|
|
|
/* This is the last reference, but the context still may be in a store.
|
|
|
|
* We release our store reference, but leave it up to store to free or keep the context. */
|
2013-10-22 12:29:34 +02:00
|
|
|
store->vtbl->releaseContext(store, context);
|
|
|
|
store->vtbl->release(store, 0);
|
2006-05-22 22:59:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-08 16:24:44 +02:00
|
|
|
void Context_CopyProperties(const void *to, const void *from)
|
2006-05-26 18:41:37 +02:00
|
|
|
{
|
2013-09-04 12:38:36 +02:00
|
|
|
CONTEXT_PROPERTY_LIST *toProperties, *fromProperties;
|
2006-05-26 18:41:37 +02:00
|
|
|
|
2013-10-17 11:07:24 +02:00
|
|
|
toProperties = context_from_ptr(to)->properties;
|
|
|
|
fromProperties = context_from_ptr(from)->properties;
|
2008-09-09 18:18:14 +02:00
|
|
|
assert(toProperties && fromProperties);
|
2006-05-26 18:41:37 +02:00
|
|
|
ContextPropertyList_Copy(toProperties, fromProperties);
|
|
|
|
}
|