ReactOS  0.4.14-dev-376-gaedba84
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 {
312  OBJECTHDR *pObject;
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 }
static BOOL alloc_handle(struct handle_table *lpTable, OBJECTHDR *lpObject, HCRYPTKEY *lpHandle)
Definition: handle.c:183
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
CRITICAL_SECTION mutex
Definition: handle.h:56
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
unsigned int BOOL
Definition: ntddk_ex.h:94
#define TRACE(s)
Definition: solgame.cpp:4
int ret
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
ULONG_PTR HCRYPTKEY
Definition: wincrypt.h:49
BOOL lookup_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType, OBJECTHDR **lplpObject)
Definition: handle.c:275
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

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;
78  DeleteCriticalSection(&lpTable->mutex);
79 }
CRITICAL_SECTION mutex
Definition: handle.h:56
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:403
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
PCRITICAL_SECTION_DEBUG DebugInfo
Definition: winbase.h:866
struct handle_table_entry * paEntries
Definition: handle.h:55
#define HeapFree(x, y, z)
Definition: compat.h:402
DWORD_PTR Spare[8/sizeof(DWORD_PTR)]
Definition: winbase.h:859

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 DWORD_PTR
Definition: treelist.c:76
CRITICAL_SECTION mutex
Definition: handle.h:56
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
PCRITICAL_SECTION_DEBUG DebugInfo
Definition: winbase.h:866
struct handle_table_entry * paEntries
Definition: handle.h:55
unsigned int iEntries
Definition: handle.h:53
unsigned int iFirstFree
Definition: handle.h:54
DWORD_PTR Spare[8/sizeof(DWORD_PTR)]
Definition: winbase.h:859

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;
118 exit:
119  LeaveCriticalSection(&lpTable->mutex);
120  return ret;
121 }
#define TRUE
Definition: types.h:120
#define HANDLE2INDEX(h)
Definition: handle.c:38
CRITICAL_SECTION mutex
Definition: handle.h:56
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint index
Definition: glext.h:6031
#define TRACE(s)
Definition: solgame.cpp:4
int ret
struct handle_table_entry * paEntries
Definition: handle.h:55
unsigned int iEntries
Definition: handle.h:53
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void exit(int exitcode)
Definition: _exit.c:33

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;
290 exit:
291  LeaveCriticalSection(&lpTable->mutex);
292  return ret;
293 }
#define TRUE
Definition: types.h:120
#define HANDLE2INDEX(h)
Definition: handle.c:38
CRITICAL_SECTION mutex
Definition: handle.h:56
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
BOOL is_valid_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
Definition: handle.c:96
int ret
struct handle_table_entry * paEntries
Definition: handle.h:55
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void exit(int exitcode)
Definition: _exit.c:33

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 {
356  OBJECTHDR *pObject;
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))
371  HeapFree(GetProcessHeap(), 0, pObject);
372  else
373  if (ppObject)
374  *ppObject = pObject;
375 
376  return hObject;
377 }
LONG refcount
Definition: handle.h:41
static BOOL alloc_handle(struct handle_table *lpTable, OBJECTHDR *lpObject, HCRYPTKEY *lpHandle)
Definition: handle.c:183
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
DESTRUCTOR destructor
Definition: handle.h:42
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
ULONG_PTR HCRYPTKEY
Definition: wincrypt.h:49
DWORD dwType
Definition: handle.h:40
#define HeapFree(x, y, z)
Definition: compat.h:402

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);
233  OBJECTHDR *pObject;
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;
256 exit:
257  LeaveCriticalSection(&lpTable->mutex);
258  return ret;
259 }
LONG refcount
Definition: handle.h:41
#define TRUE
Definition: types.h:120
#define HANDLE2INDEX(h)
Definition: handle.c:38
CRITICAL_SECTION mutex
Definition: handle.h:56
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
DESTRUCTOR destructor
Definition: handle.h:42
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
GLuint index
Definition: glext.h:6031
#define TRACE(s)
Definition: solgame.cpp:4
BOOL is_valid_handle(struct handle_table *lpTable, HCRYPTKEY handle, DWORD dwType)
Definition: handle.c:96
int ret
#define index(s, c)
Definition: various.h:29
#define InterlockedDecrement
Definition: armddk.h:52
struct handle_table_entry * paEntries
Definition: handle.h:55
unsigned int iFirstFree
Definition: handle.h:54
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void exit(int exitcode)
Definition: _exit.c:33

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