Leaked source code of windows server 2003
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.

303 lines
6.3 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 1992 - 1997
  6. //
  7. // File: support.cxx
  8. //
  9. // Contents: support routines for ksecdd.sys
  10. //
  11. //
  12. // History: 3-7-94 Created MikeSw
  13. // 12-15-97 Modified from private\lsa\client\ssp AdamBa
  14. //
  15. //------------------------------------------------------------------------
  16. #include <rdrssp.h>
  17. //+-------------------------------------------------------------------------
  18. //
  19. // Function: SecAllocate
  20. //
  21. // Synopsis:
  22. //
  23. // Effects:
  24. //
  25. // Arguments:
  26. //
  27. // Requires:
  28. //
  29. // Returns:
  30. //
  31. // Notes:
  32. //
  33. //
  34. //--------------------------------------------------------------------------
  35. VOID * SEC_ENTRY
  36. SecAllocate(ULONG cbMemory)
  37. {
  38. return(ExAllocatePool(NonPagedPool, cbMemory));
  39. }
  40. //+-------------------------------------------------------------------------
  41. //
  42. // Function: SecFree
  43. //
  44. // Synopsis:
  45. //
  46. // Effects:
  47. //
  48. // Arguments:
  49. //
  50. // Requires:
  51. //
  52. // Returns:
  53. //
  54. // Notes:
  55. //
  56. //
  57. //--------------------------------------------------------------------------
  58. void SEC_ENTRY
  59. SecFree(PVOID pvMemory)
  60. {
  61. ExFreePool(pvMemory);
  62. }
  63. //+-------------------------------------------------------------------------
  64. //
  65. // Function: MapSecurityErrorK
  66. //
  67. // Synopsis: maps a HRESULT from the security interface to a NTSTATUS
  68. //
  69. // Effects:
  70. //
  71. // Arguments:
  72. //
  73. // Requires:
  74. //
  75. // Returns:
  76. //
  77. // Notes:
  78. //
  79. //
  80. //--------------------------------------------------------------------------
  81. NTSTATUS SEC_ENTRY
  82. MapSecurityErrorK(HRESULT Error)
  83. {
  84. return((NTSTATUS) Error);
  85. }
  86. //+-------------------------------------------------------------------------
  87. //
  88. // Function: GetTokenBuffer
  89. //
  90. // Synopsis:
  91. //
  92. // This routine parses a Token Descriptor and pulls out the useful
  93. // information.
  94. //
  95. // Effects:
  96. //
  97. // Arguments:
  98. //
  99. // TokenDescriptor - Descriptor of the buffer containing (or to contain) the
  100. // token. If not specified, TokenBuffer and TokenSize will be returned
  101. // as NULL.
  102. //
  103. // BufferIndex - Index of the token buffer to find (0 for first, 1 for
  104. // second).
  105. //
  106. // TokenBuffer - Returns a pointer to the buffer for the token.
  107. //
  108. // TokenSize - Returns a pointer to the location of the size of the buffer.
  109. //
  110. // ReadonlyOK - TRUE if the token buffer may be readonly.
  111. //
  112. // Requires:
  113. //
  114. // Returns:
  115. //
  116. // TRUE - If token buffer was properly found.
  117. //
  118. // Notes:
  119. //
  120. //
  121. //--------------------------------------------------------------------------
  122. BOOLEAN
  123. GetTokenBuffer(
  124. IN PSecBufferDesc TokenDescriptor OPTIONAL,
  125. IN ULONG BufferIndex,
  126. OUT PVOID * TokenBuffer,
  127. OUT PULONG TokenSize,
  128. IN BOOLEAN ReadonlyOK
  129. )
  130. {
  131. ULONG i, Index = 0;
  132. //
  133. // If there is no TokenDescriptor passed in,
  134. // just pass out NULL to our caller.
  135. //
  136. if ( !ARGUMENT_PRESENT( TokenDescriptor) ) {
  137. *TokenBuffer = NULL;
  138. *TokenSize = 0;
  139. return TRUE;
  140. }
  141. //
  142. // Check the version of the descriptor.
  143. //
  144. if ( TokenDescriptor->ulVersion != SECBUFFER_VERSION ) {
  145. return FALSE;
  146. }
  147. //
  148. // Loop through each described buffer.
  149. //
  150. for ( i=0; i<TokenDescriptor->cBuffers ; i++ ) {
  151. PSecBuffer Buffer = &TokenDescriptor->pBuffers[i];
  152. if ( (Buffer->BufferType & (~SECBUFFER_ATTRMASK)) == SECBUFFER_TOKEN ) {
  153. //
  154. // If the buffer is readonly and readonly isn't OK,
  155. // reject the buffer.
  156. //
  157. if ( !ReadonlyOK && (Buffer->BufferType & SECBUFFER_READONLY) ) {
  158. return FALSE;
  159. }
  160. if (Index != BufferIndex)
  161. {
  162. Index++;
  163. continue;
  164. }
  165. //
  166. // Return the requested information
  167. //
  168. *TokenBuffer = Buffer->pvBuffer;
  169. *TokenSize = Buffer->cbBuffer;
  170. return TRUE;
  171. }
  172. }
  173. return FALSE;
  174. }
  175. //+-------------------------------------------------------------------------
  176. //
  177. // Function: GetSecurityToken
  178. //
  179. // Synopsis:
  180. // This routine parses a Token Descriptor and pulls out the useful
  181. // information.
  182. //
  183. // Effects:
  184. //
  185. // Arguments:
  186. // TokenDescriptor - Descriptor of the buffer containing (or to contain) the
  187. // token. If not specified, TokenBuffer and TokenSize will be returned
  188. // as NULL.
  189. //
  190. // BufferIndex - Index of the token buffer to find (0 for first, 1 for
  191. // second).
  192. //
  193. // TokenBuffer - Returns a pointer to the buffer for the token.
  194. //
  195. // Requires:
  196. //
  197. // Returns:
  198. //
  199. // TRUE - If token buffer was properly found.
  200. //
  201. // Notes:
  202. //
  203. //
  204. //--------------------------------------------------------------------------
  205. BOOLEAN
  206. GetSecurityToken(
  207. IN PSecBufferDesc TokenDescriptor OPTIONAL,
  208. IN ULONG BufferIndex,
  209. OUT PSecBuffer * TokenBuffer
  210. )
  211. {
  212. ULONG i;
  213. ULONG Index = 0;
  214. PAGED_CODE();
  215. //
  216. // If there is no TokenDescriptor passed in,
  217. // just pass out NULL to our caller.
  218. //
  219. if ( !ARGUMENT_PRESENT( TokenDescriptor) ) {
  220. *TokenBuffer = NULL;
  221. return TRUE;
  222. }
  223. //
  224. // Check the version of the descriptor.
  225. //
  226. if ( TokenDescriptor->ulVersion != SECBUFFER_VERSION ) {
  227. return FALSE;
  228. }
  229. //
  230. // Loop through each described buffer.
  231. //
  232. for ( i=0; i<TokenDescriptor->cBuffers ; i++ ) {
  233. PSecBuffer Buffer = &TokenDescriptor->pBuffers[i];
  234. if ( (Buffer->BufferType & (~SECBUFFER_ATTRMASK)) == SECBUFFER_TOKEN ) {
  235. //
  236. // If the buffer is readonly and readonly isn't OK,
  237. // reject the buffer.
  238. //
  239. if ( Buffer->BufferType & SECBUFFER_READONLY ) {
  240. return FALSE;
  241. }
  242. if (Index != BufferIndex)
  243. {
  244. Index++;
  245. continue;
  246. }
  247. //
  248. // Return the requested information
  249. //
  250. *TokenBuffer = Buffer;
  251. return TRUE;
  252. }
  253. }
  254. return FALSE;
  255. }