Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

251 lines
4.0 KiB

  1. /*
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. secutil.h
  5. Abstract:
  6. Author:
  7. Narendra Gidwani (microsoft!NarenG)
  8. Revision History:
  9. 8 Sept. 1992 Initial Version
  10. Notes: Tab stop: 4
  11. --*/
  12. #ifndef _SECUTIL_
  13. #define _SECUTIL_
  14. typedef struct _AFP_SID_NAME
  15. {
  16. AFPTIME LastAccessedTime;
  17. UNICODE_STRING Name;
  18. struct _AFP_SID_NAME * SidLink;
  19. BYTE Sid[1];
  20. } AFP_SID_NAME, *PAFP_SID_NAME;
  21. typedef struct _AFP_SID_MACID
  22. {
  23. struct _AFP_SID_MACID *Next;
  24. DWORD MacId;
  25. BYTE Sid[1];
  26. } AFP_SID_MACID, *PAFP_SID_MACID;
  27. extern
  28. NTSTATUS
  29. AfpSecUtilInit(
  30. VOID
  31. );
  32. extern
  33. VOID
  34. AfpSecUtilDeInit(
  35. VOID
  36. );
  37. extern
  38. NTSTATUS
  39. AfpSecurityUtilityWorker(
  40. IN PIRP pIrp,
  41. IN PIO_STACK_LOCATION pIrpSp
  42. );
  43. extern
  44. NTSTATUS FASTCALL
  45. AfpNameToSid(
  46. IN PSDA pSda,
  47. IN PUNICODE_STRING Name
  48. );
  49. extern
  50. NTSTATUS
  51. AfpSidToName(
  52. IN PSDA pSda,
  53. IN PSID Sid,
  54. OUT PAFP_SID_NAME * ppTranslatedSid
  55. );
  56. extern
  57. NTSTATUS FASTCALL
  58. AfpSidToMacId(
  59. IN PSID Sid,
  60. OUT PULONG pMacId
  61. );
  62. extern
  63. NTSTATUS FASTCALL
  64. AfpMacIdToSid(
  65. IN ULONG MacId,
  66. OUT PSID * ppSid
  67. );
  68. extern
  69. NTSTATUS FASTCALL
  70. AfpChangePassword(
  71. IN PSDA pSda,
  72. IN PAFP_PASSWORD_DESC pPassword
  73. );
  74. extern
  75. AFPSTATUS FASTCALL
  76. AfpInitSidOffsets(
  77. IN ULONG SidOffstPairs,
  78. IN PAFP_SID_OFFSET pSidOff
  79. );
  80. extern
  81. VOID
  82. AfpTerminateSecurityUtility(
  83. VOID
  84. );
  85. #ifdef _SECUTIL_LOCALS
  86. #define SIZE_SID_LOOKUP_TABLE 51
  87. #define SID_HASH_RADIX 11
  88. #define SID_NAME_AGE 300 // In seconds
  89. #define MAX_SECWORKITEM_QLEN 5000
  90. typedef VOID (*SEC_COMPLETION_ROUTINE)(IN ULONG, IN PVOID);
  91. typedef struct _SEC_WORK_ITEM
  92. {
  93. LIST_ENTRY Links;
  94. PVOID pOutput;
  95. LONG OutputBufSize;
  96. SEC_COMPLETION_ROUTINE pCompletionRoutine;
  97. PKEVENT pCompletionEvent;
  98. PSDA pSda;
  99. } SEC_WORK_ITEM, *PSEC_WORK_ITEM;
  100. typedef enum _SECURITY_THREAD_STATE
  101. {
  102. IDLE=1,
  103. BUSY,
  104. NOT_AVAILABLE
  105. } SECURITY_THREAD_STATE;
  106. typedef struct _AFP_SECURITY_THREAD
  107. {
  108. SECURITY_THREAD_STATE State;
  109. PIRP pIrp;
  110. PSEC_WORK_ITEM pSecWorkItem;
  111. } AFP_SECURITY_THREAD, *PAFP_SECURITY_THREAD;
  112. // Array of utiity threads
  113. LOCAL AFP_SECURITY_THREAD afpSecurityThread[NUM_SECURITY_UTILITY_THREADS] = { 0 };
  114. // Hash table for SID/Name cache
  115. LOCAL PAFP_SID_NAME * afpSidLookupTable = (PAFP_SID_NAME*)NULL;
  116. LOCAL PAFP_SID_MACID * afpSidToMacIdTable = (PAFP_SID_MACID*)NULL;
  117. LOCAL PAFP_SID_MACID afpLastCachedSid = (PAFP_SID_MACID)NULL;
  118. LOCAL DWORD afpNextMacIdToUse = 1;
  119. // Queue of work items for the SecurityThreads
  120. LOCAL LIST_ENTRY afpSecWorkItemQ = { 0 };
  121. LOCAL DWORD afpSecWorkItemQLength = { 0 };
  122. // Single Writer Multi Reader for the SID/Name cache
  123. LOCAL SWMR afpSWMRForSidNameCache = { 0 };
  124. // Spinlock protects the array of worker threads, the work queue and the
  125. // 'in progress' count/event
  126. LOCAL AFP_SPIN_LOCK afpSecUtilLock = { 0 };
  127. // Signalled when no work is in progress.
  128. LOCAL KEVENT afpUtilWorkInProgressEvent = { 0 };
  129. LOCAL LONG afpUtilWorkInProgress = 0;
  130. LOCAL
  131. NTSTATUS
  132. afpQueueSecWorkItem(
  133. IN AFP_FSD_CMD_ID FsdCommand,
  134. IN PSDA pSda,
  135. IN PKEVENT pCompletionEvent,
  136. IN PAFP_FSD_CMD_PKT pAfpFsdCmdPkt,
  137. IN LONG BufSize,
  138. IN SEC_COMPLETION_ROUTINE pCompletionRoutine
  139. );
  140. #define ALLOC_SWI() (PSEC_WORK_ITEM)AfpAllocNonPagedMemory(sizeof(SEC_WORK_ITEM))
  141. LOCAL VOID
  142. afpCompleteNameToSid(
  143. IN ULONG Index,
  144. IN PVOID pInBuf
  145. );
  146. LOCAL VOID
  147. afpCompleteSidToName(
  148. IN ULONG Index,
  149. IN PVOID pInBuf
  150. );
  151. LOCAL VOID
  152. afpCompleteMacIdToSid(
  153. IN ULONG Index,
  154. IN PVOID pInBuf
  155. );
  156. LOCAL VOID
  157. afpCompleteChangePassword(
  158. IN ULONG Index,
  159. IN PVOID pInBuf
  160. );
  161. LOCAL VOID
  162. afpCompleteLogEvent(
  163. IN ULONG Index,
  164. IN PVOID pInBuf
  165. );
  166. LOCAL NTSTATUS FASTCALL
  167. afpUpdateNameSidCache(
  168. IN WCHAR * Name,
  169. IN PSID Sid
  170. );
  171. LOCAL PAFP_SID_NAME FASTCALL
  172. afpLookupSid(
  173. IN PSID Sid
  174. );
  175. LOCAL ULONG FASTCALL
  176. afpHashSid(
  177. IN PSID Sid
  178. );
  179. LOCAL VOID
  180. afpDeInitializeSecurityUtility(
  181. VOID
  182. );
  183. AFPSTATUS FASTCALL
  184. afpAgeSidNameCache(
  185. IN PVOID pContext
  186. );
  187. #endif // _SECUTIL_LOCALS
  188. #endif // _SECUTIL_
  189.