ReactOS 0.4.17-dev-1190-g4c812f4
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)
 
void destroy_handle_table (struct handle_table *lpTable)
 
BOOL release_handle (struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
 
BOOL copy_handle (struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType, HCRYPTKEY *copy)
 
BOOL lookup_handle (struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType, OBJECTHDR **lplpObject)
 
BOOL is_valid_handle (struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
 
HCRYPTKEY new_object (struct handle_table *lpTable, size_t cbSize, DWORD dwType, DESTRUCTOR destructor, OBJECTHDR **ppObject)
 

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 308 of file handle.c.

309{
311 BOOL ret;
312
313 TRACE("(lpTable=%p, handle=%Id, copy=%p)\n", lpTable, handle, copy);
314
315 EnterCriticalSection(&lpTable->mutex);
316 if (!lookup_handle(lpTable, handle, dwType, &pObject))
317 {
319 LeaveCriticalSection(&lpTable->mutex);
320 return FALSE;
321 }
322
323 ret = alloc_handle(lpTable, pObject, copy);
324 LeaveCriticalSection(&lpTable->mutex);
325 return ret;
326}
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:273
static BOOL alloc_handle(struct handle_table *lpTable, OBJECTHDR *lpObject, HCRYPTKEY *lpHandle)
Definition: handle.c:181
return ret
Definition: mutex.c:147
unsigned int BOOL
Definition: ntddk_ex.h:94
FxObject * pObject
#define TRACE(s)
Definition: solgame.cpp:4
CRITICAL_SECTION mutex
Definition: handle.h:56
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
ULONG_PTR HCRYPTKEY
Definition: wincrypt.h:58

Referenced by release_and_install_key(), and RSAENH_CPGetUserKey().

◆ destroy_handle_table()

void destroy_handle_table ( struct handle_table *  lpTable)

Definition at line 70 of file handle.c.

71{
72 TRACE("(lpTable=%p)\n", lpTable);
73
74 free(lpTable->paEntries);
75 lpTable->mutex.DebugInfo->Spare[0] = 0;
77}
#define free
Definition: debug_ros.c:5
PRTL_CRITICAL_SECTION_DEBUG DebugInfo
Definition: rtltypes.h:1478
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 51 of file handle.c.

52{
53 TRACE("(lpTable=%p)\n", lpTable);
54
55 lpTable->paEntries = NULL;
56 lpTable->iEntries = 0;
57 lpTable->iFirstFree = 0;
59 lpTable->mutex.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": HANDLETABLE.mutex");
60}
#define NULL
Definition: types.h:112
BOOL WINAPI InitializeCriticalSectionEx(OUT LPCRITICAL_SECTION lpCriticalSection, IN DWORD dwSpinCount, IN DWORD flags)
Definition: sync.c:107
unsigned int iFirstFree
Definition: handle.h:54
unsigned int iEntries
Definition: handle.h:53
#define DWORD_PTR
Definition: treelist.c:76
#define RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO
Definition: winnt_old.h:1160

Referenced by DllMain().

◆ is_valid_handle()

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

Definition at line 94 of file handle.c.

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

Referenced by crypt_export_key(), initialize_stdio_handles_nolock(), 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 273 of file handle.c.

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

Referenced by copy_handle(), crypt_export_key(), finalize_hash(), 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(), tls1_prf(), and update_hash().

◆ new_object()

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

Definition at line 351 of file handle.c.

353{
355 HCRYPTKEY hObject;
356
357 if (ppObject)
358 *ppObject = NULL;
359
361 if (!pObject)
363
364 pObject->dwType = dwType;
365 pObject->refcount = 0;
366 pObject->destructor = destructor;
367
368 if (!alloc_handle(lpTable, pObject, &hObject))
369 free(pObject);
370 else
371 if (ppObject)
372 *ppObject = pObject;
373
374 return hObject;
375}
#define malloc
Definition: debug_ros.c:4
UINT32 cbSize

Referenced by alloc_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 228 of file handle.c.

229{
230 unsigned int index = HANDLE2INDEX(handle);
232 BOOL ret = FALSE;
233
234 TRACE("(lpTable=%p, handle=%Id)\n", lpTable, handle);
235
236 EnterCriticalSection(&lpTable->mutex);
237
238 if (!is_valid_handle(lpTable, handle, dwType))
239 goto exit;
240
241 pObject = lpTable->paEntries[index].pObject;
242 if (InterlockedDecrement(&pObject->refcount) == 0)
243 {
244 TRACE("destroying handle %Id\n", handle);
245 if (pObject->destructor)
246 pObject->destructor(pObject);
247 }
248
249 lpTable->paEntries[index].pObject = NULL;
250 lpTable->paEntries[index].iNextFree = lpTable->iFirstFree;
251 lpTable->iFirstFree = index;
252
253 ret = TRUE;
254exit:
255 LeaveCriticalSection(&lpTable->mutex);
256 return ret;
257}
#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().