ReactOS 0.4.16-dev-122-g325d74c
handle.h File Reference
#include <wincrypt.h>
Include dependency graph for handle.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  tagOBJECTHDR
 
struct  handle_table_entry
 
struct  handle_table
 

Macros

#define TABLE_SIZE_INCREMENT   32
 

Typedefs

typedef struct tagOBJECTHDR OBJECTHDR
 
typedef void(* DESTRUCTOR) (OBJECTHDR *object)
 

Functions

void init_handle_table (struct handle_table *lpTable) DECLSPEC_HIDDEN
 
void destroy_handle_table (struct handle_table *lpTable) DECLSPEC_HIDDEN
 
BOOL release_handle (struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType) DECLSPEC_HIDDEN
 
BOOL copy_handle (struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType, HCRYPTKEY *copy) DECLSPEC_HIDDEN
 
BOOL lookup_handle (struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType, OBJECTHDR **lplpObject) DECLSPEC_HIDDEN
 
BOOL is_valid_handle (struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType) DECLSPEC_HIDDEN
 
HCRYPTKEY new_object (struct handle_table *lpTable, size_t cbSize, DWORD dwType, DESTRUCTOR destructor, OBJECTHDR **ppObject) DECLSPEC_HIDDEN
 

Macro Definition Documentation

◆ TABLE_SIZE_INCREMENT

#define TABLE_SIZE_INCREMENT   32

Definition at line 33 of file handle.h.

Typedef Documentation

◆ DESTRUCTOR

typedef void(* DESTRUCTOR) (OBJECTHDR *object)

Definition at line 37 of file handle.h.

◆ OBJECTHDR

Definition at line 36 of file handle.h.

Function Documentation

◆ copy_handle()

BOOL copy_handle ( struct handle_table lpTable,
HCRYPTKEY  handle,
DWORD  dwType,
HCRYPTKEY copy 
)

Definition at line 310 of file handle.c.

311{
313 BOOL ret;
314
315 TRACE("(lpTable=%p, handle=%ld, copy=%p)\n", lpTable, handle, copy);
316
317 EnterCriticalSection(&lpTable->mutex);
318 if (!lookup_handle(lpTable, handle, dwType, &pObject))
319 {
321 LeaveCriticalSection(&lpTable->mutex);
322 return FALSE;
323 }
324
325 ret = alloc_handle(lpTable, pObject, copy);
326 LeaveCriticalSection(&lpTable->mutex);
327 return ret;
328}
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
#define FALSE
Definition: types.h:117
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL lookup_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType, OBJECTHDR **lplpObject)
Definition: handle.c:275
static BOOL alloc_handle(struct handle_table *lpTable, OBJECTHDR *lpObject, HCRYPTKEY *lpHandle)
Definition: handle.c:183
unsigned int BOOL
Definition: ntddk_ex.h:94
FxObject * pObject
#define TRACE(s)
Definition: solgame.cpp:4
CRITICAL_SECTION mutex
Definition: handle.h:56
int ret
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
ULONG_PTR HCRYPTKEY
Definition: wincrypt.h:49

Referenced by release_and_install_key(), and RSAENH_CPGetUserKey().

◆ destroy_handle_table()

void destroy_handle_table ( struct handle_table lpTable)

Definition at line 72 of file handle.c.

73{
74 TRACE("(lpTable=%p)\n", lpTable);
75
76 HeapFree(GetProcessHeap(), 0, lpTable->paEntries);
77 lpTable->mutex.DebugInfo->Spare[0] = 0;
79}
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735
DWORD_PTR Spare[8/sizeof(DWORD_PTR)]
Definition: winbase.h:887
PCRITICAL_SECTION_DEBUG DebugInfo
Definition: winbase.h:894
struct handle_table_entry * paEntries
Definition: handle.h:55
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

Referenced by DllMain().

◆ init_handle_table()

void init_handle_table ( struct handle_table lpTable)

Definition at line 53 of file handle.c.

54{
55 TRACE("(lpTable=%p)\n", lpTable);
56
57 lpTable->paEntries = NULL;
58 lpTable->iEntries = 0;
59 lpTable->iFirstFree = 0;
61 lpTable->mutex.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": HANDLETABLE.mutex");
62}
#define NULL
Definition: types.h:112
unsigned int iFirstFree
Definition: handle.h:54
unsigned int iEntries
Definition: handle.h:53
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
#define DWORD_PTR
Definition: treelist.c:76

Referenced by DllMain().

◆ is_valid_handle()

BOOL is_valid_handle ( struct handle_table lpTable,
HCRYPTKEY  handle,
DWORD  dwType 
)

Definition at line 96 of file handle.c.

97{
98 unsigned int index = HANDLE2INDEX(handle);
99 BOOL ret = FALSE;
100
101 TRACE("(lpTable=%p, handle=%ld)\n", lpTable, handle);
102
103 EnterCriticalSection(&lpTable->mutex);
104
105 /* We don't use zero handle values */
106 if (!handle) goto exit;
107
108 /* Check for index out of table bounds */
109 if (index >= lpTable->iEntries) goto exit;
110
111 /* Check if this handle is currently allocated */
112 if (!lpTable->paEntries[index].pObject) goto exit;
113
114 /* Check if this handle references an object of the correct type. */
115 if (lpTable->paEntries[index].pObject->dwType != dwType) goto exit;
116
117 ret = TRUE;
118exit:
119 LeaveCriticalSection(&lpTable->mutex);
120 return ret;
121}
#define TRUE
Definition: types.h:120
#define HANDLE2INDEX(h)
Definition: handle.c:38
GLuint index
Definition: glext.h:6031
#define exit(n)
Definition: config.h:202

Referenced by crypt_export_key(), lookup_handle(), release_handle(), RSAENH_CPDecrypt(), RSAENH_CPDeriveKey(), RSAENH_CPDestroyHash(), RSAENH_CPDestroyKey(), RSAENH_CPDuplicateHash(), RSAENH_CPDuplicateKey(), RSAENH_CPEncrypt(), RSAENH_CPExportKey(), RSAENH_CPGenRandom(), RSAENH_CPGetHashParam(), RSAENH_CPGetKeyParam(), RSAENH_CPSetHashParam(), RSAENH_CPSetKeyParam(), and RSAENH_CPVerifySignature().

◆ lookup_handle()

BOOL lookup_handle ( struct handle_table lpTable,
HCRYPTKEY  handle,
DWORD  dwType,
OBJECTHDR **  lplpObject 
)

Definition at line 275 of file handle.c.

276{
277 BOOL ret = FALSE;
278
279 TRACE("(lpTable=%p, handle=%ld, lplpObject=%p)\n", lpTable, handle, lplpObject);
280
281 EnterCriticalSection(&lpTable->mutex);
282 if (!is_valid_handle(lpTable, handle, dwType))
283 {
284 *lplpObject = NULL;
285 goto exit;
286 }
287 *lplpObject = lpTable->paEntries[HANDLE2INDEX(handle)].pObject;
288
289 ret = TRUE;
290exit:
291 LeaveCriticalSection(&lpTable->mutex);
292 return ret;
293}
BOOL is_valid_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
Definition: handle.c:96

Referenced by copy_handle(), crypt_export_key(), get_key_container(), import_symmetric_key(), read_key_container(), read_key_value(), RSAENH_CPCreateHash(), RSAENH_CPDecrypt(), RSAENH_CPDeriveKey(), RSAENH_CPDuplicateHash(), RSAENH_CPDuplicateKey(), RSAENH_CPEncrypt(), RSAENH_CPExportKey(), RSAENH_CPGetHashParam(), RSAENH_CPGetKeyParam(), RSAENH_CPHashData(), RSAENH_CPHashSessionKey(), RSAENH_CPSetHashParam(), RSAENH_CPSetKeyParam(), RSAENH_CPSignHash(), RSAENH_CPVerifySignature(), store_key_pair(), store_key_permissions(), tls1_p(), and tls1_prf().

◆ new_object()

HCRYPTKEY new_object ( struct handle_table lpTable,
size_t  cbSize,
DWORD  dwType,
DESTRUCTOR  destructor,
OBJECTHDR **  ppObject 
)

Definition at line 353 of file handle.c.

355{
357 HCRYPTKEY hObject;
358
359 if (ppObject)
360 *ppObject = NULL;
361
362 pObject = HeapAlloc(GetProcessHeap(), 0, cbSize);
363 if (!pObject)
365
366 pObject->dwType = dwType;
367 pObject->refcount = 0;
368 pObject->destructor = destructor;
369
370 if (!alloc_handle(lpTable, pObject, &hObject))
372 else
373 if (ppObject)
374 *ppObject = pObject;
375
376 return hObject;
377}
#define HeapAlloc
Definition: compat.h:733

Referenced by new_key(), new_key_container(), RSAENH_CPCreateHash(), RSAENH_CPDuplicateHash(), RSAENH_CPDuplicateKey(), and StorageImpl_Refresh().

◆ release_handle()

BOOL release_handle ( struct handle_table lpTable,
HCRYPTKEY  handle,
DWORD  dwType 
)

Definition at line 230 of file handle.c.

231{
232 unsigned int index = HANDLE2INDEX(handle);
234 BOOL ret = FALSE;
235
236 TRACE("(lpTable=%p, handle=%ld)\n", lpTable, handle);
237
238 EnterCriticalSection(&lpTable->mutex);
239
240 if (!is_valid_handle(lpTable, handle, dwType))
241 goto exit;
242
243 pObject = lpTable->paEntries[index].pObject;
244 if (InterlockedDecrement(&pObject->refcount) == 0)
245 {
246 TRACE("destroying handle %ld\n", handle);
247 if (pObject->destructor)
248 pObject->destructor(pObject);
249 }
250
251 lpTable->paEntries[index].pObject = NULL;
252 lpTable->paEntries[index].iNextFree = lpTable->iFirstFree;
253 lpTable->iFirstFree = index;
254
255 ret = TRUE;
256exit:
257 LeaveCriticalSection(&lpTable->mutex);
258 return ret;
259}
#define InterlockedDecrement
Definition: armddk.h:52
#define index(s, c)
Definition: various.h:29

Referenced by import_plaintext_key(), read_key_container(), release_key_container_keys(), RSAENH_CPAcquireContext(), RSAENH_CPDestroyHash(), RSAENH_CPDestroyKey(), RSAENH_CPReleaseContext(), and tls1_prf().