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.

366 lines
10 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. digestw.cxx
  5. Abstract:
  6. sspi wide char interface for digest package.
  7. Author:
  8. Adriaan Canter (adriaanc) 01-Aug-1998
  9. --*/
  10. #include "include.hxx"
  11. static SecurityFunctionTableW
  12. SecTableW =
  13. {
  14. SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION,
  15. EnumerateSecurityPackagesW,
  16. NULL, // QueryCredentialsAttributesA
  17. AcquireCredentialsHandleW,
  18. FreeCredentialsHandle,
  19. NULL, // SspiLogonUserA
  20. InitializeSecurityContextW,
  21. AcceptSecurityContext,
  22. CompleteAuthToken,
  23. DeleteSecurityContext,
  24. ApplyControlToken,
  25. QueryContextAttributesW,
  26. ImpersonateSecurityContext,
  27. RevertSecurityContext,
  28. MakeSignature,
  29. VerifySignature,
  30. FreeContextBuffer,
  31. QuerySecurityPackageInfoW,
  32. NULL, // Reserved3
  33. NULL, // Reserved4
  34. NULL, // ExportSecurityContext
  35. NULL, // ImportSecurityContextA
  36. NULL, // Reserved7
  37. NULL, // Reserved8
  38. NULL, // QuerySecurityContextToken
  39. NULL, // EncryptMessage
  40. NULL // DecryptMessage
  41. };
  42. //--------------------------------------------------------------------------
  43. //
  44. // Function: InitSecurityInterfaceW
  45. //
  46. // Synopsis:
  47. //
  48. // Effects:
  49. //
  50. // Arguments:
  51. //
  52. // Requires:
  53. //
  54. // Returns:
  55. //
  56. // Notes:
  57. //
  58. //
  59. //--------------------------------------------------------------------------
  60. extern "C" PSecurityFunctionTableW SEC_ENTRY
  61. InitSecurityInterfaceW(VOID)
  62. {
  63. PSecurityFunctionTableW pSecTableW = &SecTableW;
  64. return pSecTableW;
  65. }
  66. //--------------------------------------------------------------------------
  67. //
  68. // Function: AcquireCredentialsHandleW
  69. //
  70. // Synopsis:
  71. //
  72. // Effects:
  73. //
  74. // Arguments:
  75. //
  76. // Requires:
  77. //
  78. // Returns:
  79. //
  80. // Notes:
  81. //
  82. // HEINOUS SSPI HACK here: AcquireCredentialsHandle is called with the package
  83. // name ("Digest") as the package identifier. When AcquireCredentialsHandle returns
  84. // to the caller PCredHandle->dwLower is set by security.dll to be the index of
  85. // the package returned. EnumerateSecurityPackages. This is how SSPI resolves the
  86. // correct provider dll when subsequent calls are made through the dispatch table
  87. // (PSecurityFunctionTale). Any credential *or* context handle handed out by the
  88. // package must have the dwLower member set to this index so that subsequent calls
  89. // can resolve the dll from the handle.
  90. //
  91. //--------------------------------------------------------------------------
  92. extern "C" SECURITY_STATUS SEC_ENTRY
  93. AcquireCredentialsHandleW(
  94. LPWSTR wszPrincipal, // Name of principal
  95. LPWSTR wszPackageName, // Name of package
  96. DWORD dwCredentialUse, // Flags indicating use
  97. VOID SEC_FAR * pvLogonId, // Pointer to logon ID
  98. VOID SEC_FAR * pAuthData, // Package specific data
  99. SEC_GET_KEY_FN pGetKeyFn, // Pointer to GetKey() func
  100. VOID SEC_FAR * pvGetKeyArgument, // Value to pass to GetKey()
  101. PCredHandle phCredential, // (out) Cred Handle
  102. PTimeStamp ptsExpiry // (out) Lifetime (optional)
  103. )
  104. {
  105. return SEC_E_UNSUPPORTED_FUNCTION;
  106. #if 0
  107. SECURITY_STATUS ssResult;
  108. DWORD wcbPrincipal, cbPrincipal, wcbPackageName, cbPackageName;
  109. wcbPrincipal = wszPrincipal ? wcslen(wszPrincipal) : 0;
  110. cbPrincipal = wcbPrincipal / sizeof(WCHAR);
  111. wcbPackageName = wszPackageName ? wcslen(wszPackageName) : 0;
  112. cbPackageName = wcbPackageName / sizeof(WCHAR);
  113. LPSTR szPrincipal;
  114. LPSTR szPackageName;
  115. szPrincipal = new CHAR[cbPrincipal];
  116. szPackageName = new CHAR[cbPackageName];
  117. WideCharToMultiByte(CP_ACP,0, wszPrincipal, wcbPrincipal,
  118. szPrincipal, cbPrincipal, NULL,NULL);
  119. WideCharToMultiByte(CP_ACP,0, wszPackageName, wcbPackageName,
  120. szPackageName, cbPackageName, NULL,NULL);
  121. ssResult = AcquireCredentialsHandleA(
  122. szPrincipal, // Name of principal
  123. szPackageName, // Name of package
  124. dwCredentialUse, // Flags indicating use
  125. pvLogonId, // Pointer to logon ID
  126. pAuthData, // Package specific data
  127. pGetKeyFn, // Pointer to GetKey() func
  128. pvGetKeyArgument, // Value to pass to GetKey()
  129. phCredential, // (out) Cred Handle
  130. ptsExpiry // (out) Lifetime (optional)
  131. );
  132. delete szPrincipal;
  133. delete szPackageName;
  134. return ssResult;
  135. #endif // 0
  136. }
  137. //--------------------------------------------------------------------------
  138. //
  139. // Function: InitializeSecurityContextA
  140. //
  141. // Synopsis:
  142. //
  143. // Effects:
  144. //
  145. // Arguments:
  146. //
  147. // Requires:
  148. //
  149. // Returns:
  150. //
  151. // Notes:
  152. //
  153. //--------------------------------------------------------------------------
  154. extern "C" SECURITY_STATUS SEC_ENTRY
  155. InitializeSecurityContextW(
  156. PCredHandle phCredential, // Cred to base context
  157. PCtxtHandle phContext, // Existing context (OPT)
  158. LPWSTR wszTargetName, // Name of target
  159. DWORD fContextReq, // Context Requirements
  160. DWORD Reserved1, // Reserved, MBZ
  161. DWORD TargetDataRep, // Data rep of target
  162. PSecBufferDesc pInput, // Input Buffers
  163. DWORD Reserved2, // Reserved, MBZ
  164. PCtxtHandle phNewContext, // (out) New Context handle
  165. PSecBufferDesc pOutput, // (inout) Output Buffers
  166. DWORD SEC_FAR * pfContextAttr, // (out) Context attrs
  167. PTimeStamp ptsExpiry // (out) Life span (OPT)
  168. )
  169. {
  170. return SEC_E_UNSUPPORTED_FUNCTION;
  171. #if 0
  172. SECURITY_STATUS ssResult;
  173. DWORD wcbTargetName, cbTargetName;
  174. wcbTargetName = wszTargetName ? wcslen(wszTargetName) : 0;
  175. cbTargetName = wcbTargetName / sizeof(WCHAR);
  176. LPSTR szTargetName;
  177. szTargetName = new CHAR[cbTargetName];
  178. WideCharToMultiByte(CP_ACP,0, wszTargetName, wcbTargetName,
  179. szTargetName, cbTargetName, NULL,NULL);
  180. ssResult = InitializeSecurityContextA(
  181. phCredential, // Cred to base context
  182. phContext, // Existing context (OPT)
  183. szTargetName, // Name of target
  184. fContextReq, // Context Requirements
  185. Reserved1, // Reserved, MBZ
  186. TargetDataRep, // Data rep of target
  187. pInput, // Input Buffers
  188. Reserved2, // Reserved, MBZ
  189. phNewContext, // (out) New Context handle
  190. pOutput, // (inout) Output Buffers
  191. pfContextAttr, // (out) Context attrs
  192. ptsExpiry // (out) Life span (OPT)
  193. );
  194. delete szTargetName;
  195. return ssResult;
  196. #endif // 0
  197. }
  198. //--------------------------------------------------------------------------
  199. //
  200. // Function: EnumerateSecurityPackagesW
  201. //
  202. // Synopsis:
  203. //
  204. // Effects:
  205. //
  206. // Arguments:
  207. //
  208. // Requires:
  209. //
  210. // Returns:
  211. //
  212. // Notes:
  213. //
  214. //
  215. //--------------------------------------------------------------------------
  216. SECURITY_STATUS SEC_ENTRY
  217. EnumerateSecurityPackagesW(DWORD SEC_FAR *pcPackages,
  218. PSecPkgInfoW SEC_FAR *ppSecPkgInfo)
  219. {
  220. SECURITY_STATUS ssResult;
  221. ssResult = QuerySecurityPackageInfoW(PACKAGE_NAMEW, ppSecPkgInfo);
  222. if (ssResult == SEC_E_OK)
  223. {
  224. *pcPackages = 1;
  225. }
  226. return ssResult;
  227. }
  228. //--------------------------------------------------------------------------
  229. //
  230. // Function: QuerySecurityPackageInfoW
  231. //
  232. // Synopsis:
  233. //
  234. // Effects:
  235. //
  236. // Arguments:
  237. //
  238. // Requires:
  239. //
  240. // Returns:
  241. //
  242. // Notes:
  243. //
  244. //
  245. //--------------------------------------------------------------------------
  246. SECURITY_STATUS SEC_ENTRY
  247. QuerySecurityPackageInfoW(LPWSTR wszPackageName,
  248. PSecPkgInfoW SEC_FAR *ppSecPkgInfo)
  249. {
  250. PSecPkgInfoW pSecPkgInfo;
  251. SECURITY_STATUS ssResult;
  252. LPWSTR pwCur;
  253. if (wcscmp(wszPackageName, PACKAGE_NAMEW))
  254. {
  255. ssResult = SEC_E_SECPKG_NOT_FOUND;
  256. goto exit;
  257. }
  258. DWORD wcbSecPkgInfo, wcbstruct, wcbname, wcbcomment;
  259. wcbstruct = sizeof(SecPkgInfoW);
  260. wcbname = sizeof(PACKAGE_NAMEW);
  261. wcbcomment = sizeof(PACKAGE_COMMENTW);
  262. wcbSecPkgInfo = wcbstruct + wcbname + wcbcomment;
  263. pSecPkgInfo = (PSecPkgInfoW) LocalAlloc(0,wcbSecPkgInfo);
  264. if (!pSecPkgInfo)
  265. {
  266. ssResult = SEC_E_INSUFFICIENT_MEMORY;
  267. goto exit;
  268. }
  269. pSecPkgInfo->fCapabilities = PACKAGE_CAPABILITIES;
  270. pSecPkgInfo->wVersion = PACKAGE_VERSION;
  271. pSecPkgInfo->wRPCID = PACKAGE_RPCID;
  272. pSecPkgInfo->cbMaxToken = PACKAGE_MAXTOKEN;
  273. pwCur = (LPWSTR) ((LPBYTE) (pSecPkgInfo) + sizeof(SecPkgInfoW));
  274. pSecPkgInfo->Name = pwCur;
  275. memcpy(pSecPkgInfo->Name, PACKAGE_NAMEW, sizeof(PACKAGE_NAMEW));
  276. pwCur = (LPWSTR) ((LPBYTE) (pwCur) + sizeof(PACKAGE_NAMEW));
  277. pSecPkgInfo->Comment = pwCur;
  278. memcpy(pSecPkgInfo->Comment, PACKAGE_COMMENTW, sizeof(PACKAGE_COMMENTW));
  279. *ppSecPkgInfo = pSecPkgInfo;
  280. ssResult = SEC_E_OK;
  281. exit:
  282. return ssResult;
  283. }
  284. //--------------------------------------------------------------------------
  285. //
  286. // Function: QueryContextAttributesW
  287. //
  288. // Synopsis:
  289. //
  290. // Effects:
  291. //
  292. // Arguments:
  293. //
  294. // Requires:
  295. //
  296. // Returns:
  297. //
  298. // Notes:
  299. //
  300. //
  301. //--------------------------------------------------------------------------
  302. extern "C" SECURITY_STATUS SEC_ENTRY
  303. QueryContextAttributesW(
  304. PCtxtHandle phContext, // Context to query
  305. unsigned long ulAttribute, // Attribute to query
  306. void SEC_FAR * pBuffer // Buffer for attributes
  307. )
  308. {
  309. return SEC_E_UNSUPPORTED_FUNCTION;
  310. }