/dlls/secur32/wrapper.c

https://github.com/YokoZar/wine · C · 1126 lines · 909 code · 107 blank · 110 comment · 164 complexity · cd89b398abaf6ec54decb4480f590a4d MD5 · raw file

  1. /* Copyright (C) 2004 Juan Lang
  2. *
  3. * Implements secur32 functions that forward to (wrap) an SSP's implementation.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  18. */
  19. #include <stdarg.h>
  20. #include "windef.h"
  21. #include "winbase.h"
  22. #include "winnls.h"
  23. #include "sspi.h"
  24. #include "secur32_priv.h"
  25. #include "wine/debug.h"
  26. WINE_DEFAULT_DEBUG_CHANNEL(secur32);
  27. /* Tries to allocate a new SecHandle, into which it stores package (in
  28. * phSec->dwUpper) and a copy of realHandle (allocated with SECUR32_ALLOC,
  29. * and stored in phSec->dwLower). SecHandle is equivalent to both a
  30. * CredHandle and a CtxtHandle.
  31. */
  32. static SECURITY_STATUS SECUR32_makeSecHandle(PSecHandle phSec,
  33. SecurePackage *package, PSecHandle realHandle)
  34. {
  35. SECURITY_STATUS ret;
  36. TRACE("%p %p %p\n", phSec, package, realHandle);
  37. if (phSec && package && realHandle)
  38. {
  39. PSecHandle newSec = HeapAlloc(GetProcessHeap(), 0, sizeof(SecHandle));
  40. if (newSec)
  41. {
  42. *newSec = *realHandle;
  43. phSec->dwUpper = (ULONG_PTR)package;
  44. phSec->dwLower = (ULONG_PTR)newSec;
  45. ret = SEC_E_OK;
  46. }
  47. else
  48. ret = SEC_E_INSUFFICIENT_MEMORY;
  49. }
  50. else
  51. ret = SEC_E_INVALID_HANDLE;
  52. return ret;
  53. }
  54. /***********************************************************************
  55. * AcquireCredentialsHandleA (SECUR32.@)
  56. */
  57. SECURITY_STATUS WINAPI AcquireCredentialsHandleA(
  58. SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialsUse,
  59. PLUID pvLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
  60. PVOID pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
  61. {
  62. SECURITY_STATUS ret;
  63. TRACE("%s %s %d %p %p %p %p %p %p\n", debugstr_a(pszPrincipal),
  64. debugstr_a(pszPackage), fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn,
  65. pvGetKeyArgument, phCredential, ptsExpiry);
  66. if (pszPackage)
  67. {
  68. SecurePackage *package = SECUR32_findPackageA(pszPackage);
  69. if (package && package->provider)
  70. {
  71. if (package->provider->fnTableA.AcquireCredentialsHandleA)
  72. {
  73. CredHandle myCred;
  74. ret = package->provider->fnTableA.AcquireCredentialsHandleA(
  75. pszPrincipal, pszPackage, fCredentialsUse, pvLogonID,
  76. pAuthData, pGetKeyFn, pvGetKeyArgument, &myCred,
  77. ptsExpiry);
  78. if (ret == SEC_E_OK)
  79. {
  80. ret = SECUR32_makeSecHandle(phCredential, package, &myCred);
  81. if (ret != SEC_E_OK)
  82. package->provider->fnTableW.FreeCredentialsHandle(
  83. &myCred);
  84. }
  85. }
  86. else
  87. ret = SEC_E_UNSUPPORTED_FUNCTION;
  88. }
  89. else
  90. ret = SEC_E_SECPKG_NOT_FOUND;
  91. }
  92. else
  93. ret = SEC_E_SECPKG_NOT_FOUND;
  94. return ret;
  95. }
  96. /***********************************************************************
  97. * AcquireCredentialsHandleW (SECUR32.@)
  98. */
  99. SECURITY_STATUS WINAPI AcquireCredentialsHandleW(
  100. SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialsUse,
  101. PLUID pvLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
  102. PVOID pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
  103. {
  104. SECURITY_STATUS ret;
  105. TRACE("%s %s %d %p %p %p %p %p %p\n", debugstr_w(pszPrincipal),
  106. debugstr_w(pszPackage), fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn,
  107. pvGetKeyArgument, phCredential, ptsExpiry);
  108. if (pszPackage)
  109. {
  110. SecurePackage *package = SECUR32_findPackageW(pszPackage);
  111. if (package && package->provider)
  112. {
  113. if (package->provider->fnTableW.AcquireCredentialsHandleW)
  114. {
  115. CredHandle myCred;
  116. ret = package->provider->fnTableW.AcquireCredentialsHandleW(
  117. pszPrincipal, pszPackage, fCredentialsUse, pvLogonID,
  118. pAuthData, pGetKeyFn, pvGetKeyArgument, &myCred,
  119. ptsExpiry);
  120. if (ret == SEC_E_OK)
  121. {
  122. ret = SECUR32_makeSecHandle(phCredential, package, &myCred);
  123. if (ret != SEC_E_OK)
  124. package->provider->fnTableW.FreeCredentialsHandle(
  125. &myCred);
  126. }
  127. }
  128. else
  129. ret = SEC_E_UNSUPPORTED_FUNCTION;
  130. }
  131. else
  132. ret = SEC_E_SECPKG_NOT_FOUND;
  133. }
  134. else
  135. ret = SEC_E_SECPKG_NOT_FOUND;
  136. return ret;
  137. }
  138. /***********************************************************************
  139. * FreeCredentialsHandle (SECUR32.@)
  140. */
  141. SECURITY_STATUS WINAPI FreeCredentialsHandle(
  142. PCredHandle phCredential)
  143. {
  144. SECURITY_STATUS ret;
  145. TRACE("%p\n", phCredential);
  146. if (phCredential)
  147. {
  148. SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
  149. PCredHandle cred = (PCredHandle)phCredential->dwLower;
  150. if (package && package->provider &&
  151. package->provider->fnTableW.FreeCredentialsHandle)
  152. ret = package->provider->fnTableW.FreeCredentialsHandle(cred);
  153. else
  154. ret = SEC_E_INVALID_HANDLE;
  155. HeapFree(GetProcessHeap(), 0, cred);
  156. }
  157. else
  158. ret = SEC_E_INVALID_HANDLE;
  159. return ret;
  160. }
  161. /***********************************************************************
  162. * QueryCredentialsAttributesA (SECUR32.@)
  163. */
  164. SECURITY_STATUS WINAPI QueryCredentialsAttributesA(
  165. PCredHandle phCredential, ULONG ulAttribute, void *pBuffer)
  166. {
  167. SECURITY_STATUS ret;
  168. TRACE("%p %d %p\n", phCredential, ulAttribute, pBuffer);
  169. if (phCredential)
  170. {
  171. SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
  172. PCredHandle cred = (PCredHandle)phCredential->dwLower;
  173. if (package && package->provider)
  174. {
  175. if (package->provider->fnTableA.QueryCredentialsAttributesA)
  176. ret = package->provider->fnTableA.QueryCredentialsAttributesA(
  177. cred, ulAttribute, pBuffer);
  178. else
  179. ret = SEC_E_UNSUPPORTED_FUNCTION;
  180. }
  181. else
  182. ret = SEC_E_INVALID_HANDLE;
  183. }
  184. else
  185. ret = SEC_E_INVALID_HANDLE;
  186. return ret;
  187. }
  188. /***********************************************************************
  189. * QueryCredentialsAttributesW (SECUR32.@)
  190. */
  191. SECURITY_STATUS WINAPI QueryCredentialsAttributesW(
  192. PCredHandle phCredential, ULONG ulAttribute, void *pBuffer)
  193. {
  194. SECURITY_STATUS ret;
  195. TRACE("%p %d %p\n", phCredential, ulAttribute, pBuffer);
  196. if (phCredential)
  197. {
  198. SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
  199. PCredHandle cred = (PCredHandle)phCredential->dwLower;
  200. if (package && package->provider)
  201. {
  202. if (package->provider->fnTableW.QueryCredentialsAttributesW)
  203. ret = package->provider->fnTableW.QueryCredentialsAttributesW(
  204. cred, ulAttribute, pBuffer);
  205. else
  206. ret = SEC_E_UNSUPPORTED_FUNCTION;
  207. }
  208. else
  209. ret = SEC_E_INVALID_HANDLE;
  210. }
  211. else
  212. ret = SEC_E_INVALID_HANDLE;
  213. return ret;
  214. }
  215. /***********************************************************************
  216. * InitializeSecurityContextA (SECUR32.@)
  217. */
  218. SECURITY_STATUS WINAPI InitializeSecurityContextA(
  219. PCredHandle phCredential, PCtxtHandle phContext,
  220. SEC_CHAR *pszTargetName, ULONG fContextReq,
  221. ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput,
  222. ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
  223. ULONG *pfContextAttr, PTimeStamp ptsExpiry)
  224. {
  225. SECURITY_STATUS ret;
  226. SecurePackage *package = NULL;
  227. PCredHandle cred = NULL;
  228. PCredHandle ctxt = NULL;
  229. TRACE("%p %p %s 0x%08x %d %d %p %d %p %p %p %p\n", phCredential, phContext,
  230. debugstr_a(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
  231. Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
  232. if (phContext)
  233. {
  234. package = (SecurePackage *)phContext->dwUpper;
  235. ctxt = (PCtxtHandle)phContext->dwLower;
  236. }
  237. if (phCredential)
  238. {
  239. package = (SecurePackage *)phCredential->dwUpper;
  240. cred = (PCredHandle)phCredential->dwLower;
  241. }
  242. if (package && package->provider)
  243. {
  244. if (package->provider->fnTableA.InitializeSecurityContextA)
  245. {
  246. CtxtHandle myCtxt;
  247. if (phContext)
  248. {
  249. PCtxtHandle realCtxt = (PCtxtHandle)phContext->dwLower;
  250. myCtxt.dwUpper = realCtxt->dwUpper;
  251. myCtxt.dwLower = realCtxt->dwLower;
  252. }
  253. ret = package->provider->fnTableA.InitializeSecurityContextA(
  254. cred, ctxt, pszTargetName, fContextReq,
  255. Reserved1, TargetDataRep, pInput, Reserved2, phNewContext ? &myCtxt : NULL,
  256. pOutput, pfContextAttr, ptsExpiry);
  257. if ((ret == SEC_E_OK || ret == SEC_I_CONTINUE_NEEDED) &&
  258. phNewContext && phNewContext != phContext)
  259. {
  260. SECURITY_STATUS ret2;
  261. ret2 = SECUR32_makeSecHandle(phNewContext, package, &myCtxt);
  262. if (ret2 != SEC_E_OK)
  263. package->provider->fnTableA.DeleteSecurityContext(&myCtxt);
  264. }
  265. }
  266. else
  267. ret = SEC_E_UNSUPPORTED_FUNCTION;
  268. }
  269. else
  270. ret = SEC_E_INVALID_HANDLE;
  271. return ret;
  272. }
  273. /***********************************************************************
  274. * InitializeSecurityContextW (SECUR32.@)
  275. */
  276. SECURITY_STATUS WINAPI InitializeSecurityContextW(
  277. PCredHandle phCredential, PCtxtHandle phContext,
  278. SEC_WCHAR *pszTargetName, ULONG fContextReq,
  279. ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput,
  280. ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
  281. ULONG *pfContextAttr, PTimeStamp ptsExpiry)
  282. {
  283. SECURITY_STATUS ret;
  284. SecurePackage *package = NULL;
  285. PCredHandle cred = NULL;
  286. PCredHandle ctxt = NULL;
  287. TRACE("%p %p %s %d %d %d %p %d %p %p %p %p\n", phCredential, phContext,
  288. debugstr_w(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
  289. Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
  290. if (phContext)
  291. {
  292. package = (SecurePackage *)phContext->dwUpper;
  293. ctxt = (PCtxtHandle)phContext->dwLower;
  294. }
  295. if (phCredential)
  296. {
  297. package = (SecurePackage *)phCredential->dwUpper;
  298. cred = (PCredHandle)phCredential->dwLower;
  299. }
  300. if (package && package->provider)
  301. {
  302. if (package->provider->fnTableW.InitializeSecurityContextW)
  303. {
  304. CtxtHandle myCtxt;
  305. if (phContext)
  306. {
  307. PCtxtHandle realCtxt = (PCtxtHandle)phContext->dwLower;
  308. myCtxt.dwUpper = realCtxt->dwUpper;
  309. myCtxt.dwLower = realCtxt->dwLower;
  310. }
  311. ret = package->provider->fnTableW.InitializeSecurityContextW(
  312. cred, ctxt, pszTargetName, fContextReq,
  313. Reserved1, TargetDataRep, pInput, Reserved2, phNewContext ? &myCtxt : NULL,
  314. pOutput, pfContextAttr, ptsExpiry);
  315. if ((ret == SEC_E_OK || ret == SEC_I_CONTINUE_NEEDED) &&
  316. phNewContext && phNewContext != phContext)
  317. {
  318. SECURITY_STATUS ret2;
  319. ret2 = SECUR32_makeSecHandle(phNewContext, package, &myCtxt);
  320. if (ret2 != SEC_E_OK)
  321. package->provider->fnTableW.DeleteSecurityContext(&myCtxt);
  322. }
  323. }
  324. else
  325. ret = SEC_E_UNSUPPORTED_FUNCTION;
  326. }
  327. else
  328. ret = SEC_E_INVALID_HANDLE;
  329. return ret;
  330. }
  331. /***********************************************************************
  332. * AcceptSecurityContext (SECUR32.@)
  333. */
  334. SECURITY_STATUS WINAPI AcceptSecurityContext(
  335. PCredHandle phCredential, PCtxtHandle phContext, PSecBufferDesc pInput,
  336. ULONG fContextReq, ULONG TargetDataRep, PCtxtHandle phNewContext,
  337. PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry)
  338. {
  339. SECURITY_STATUS ret;
  340. TRACE("%p %p %p %d %d %p %p %p %p\n", phCredential, phContext, pInput,
  341. fContextReq, TargetDataRep, phNewContext, pOutput, pfContextAttr,
  342. ptsExpiry);
  343. if (phCredential)
  344. {
  345. SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
  346. PCredHandle cred = (PCredHandle)phCredential->dwLower;
  347. if (package && package->provider)
  348. {
  349. if (package->provider->fnTableW.AcceptSecurityContext)
  350. {
  351. CtxtHandle myCtxt;
  352. if(phContext)
  353. {
  354. PCtxtHandle realCtxt = (PCtxtHandle)phContext->dwLower;
  355. TRACE("realCtx: %p\n", realCtxt);
  356. myCtxt.dwUpper = realCtxt->dwUpper;
  357. myCtxt.dwLower = realCtxt->dwLower;
  358. }
  359. ret = package->provider->fnTableW.AcceptSecurityContext(
  360. cred, phContext ? &myCtxt : NULL, pInput, fContextReq,
  361. TargetDataRep, &myCtxt, pOutput, pfContextAttr, ptsExpiry);
  362. if (ret == SEC_E_OK || ret == SEC_I_CONTINUE_NEEDED)
  363. {
  364. SECURITY_STATUS ret2;
  365. ret2 = SECUR32_makeSecHandle(phNewContext, package, &myCtxt);
  366. if (ret2 != SEC_E_OK)
  367. package->provider->fnTableW.DeleteSecurityContext(
  368. &myCtxt);
  369. }
  370. }
  371. else
  372. ret = SEC_E_UNSUPPORTED_FUNCTION;
  373. }
  374. else
  375. ret = SEC_E_INVALID_HANDLE;
  376. }
  377. else
  378. ret = SEC_E_INVALID_HANDLE;
  379. return ret;
  380. }
  381. /***********************************************************************
  382. * CompleteAuthToken (SECUR32.@)
  383. */
  384. SECURITY_STATUS WINAPI CompleteAuthToken(PCtxtHandle phContext,
  385. PSecBufferDesc pToken)
  386. {
  387. SECURITY_STATUS ret;
  388. TRACE("%p %p\n", phContext, pToken);
  389. if (phContext)
  390. {
  391. SecurePackage *package = (SecurePackage *)phContext->dwUpper;
  392. PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
  393. if (package && package->provider)
  394. {
  395. if (package->provider->fnTableW.CompleteAuthToken)
  396. ret = package->provider->fnTableW.CompleteAuthToken(ctxt,
  397. pToken);
  398. else
  399. ret = SEC_E_UNSUPPORTED_FUNCTION;
  400. }
  401. else
  402. ret = SEC_E_INVALID_HANDLE;
  403. }
  404. else
  405. ret = SEC_E_INVALID_HANDLE;
  406. return ret;
  407. }
  408. /***********************************************************************
  409. * DeleteSecurityContext (SECUR32.@)
  410. */
  411. SECURITY_STATUS WINAPI DeleteSecurityContext(PCtxtHandle phContext)
  412. {
  413. SECURITY_STATUS ret;
  414. TRACE("%p\n", phContext);
  415. if (phContext)
  416. {
  417. SecurePackage *package = (SecurePackage *)phContext->dwUpper;
  418. PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
  419. if (package && package->provider &&
  420. package->provider->fnTableW.DeleteSecurityContext)
  421. ret = package->provider->fnTableW.DeleteSecurityContext(ctxt);
  422. else
  423. ret = SEC_E_INVALID_HANDLE;
  424. HeapFree(GetProcessHeap(), 0, ctxt);
  425. }
  426. else
  427. ret = SEC_E_INVALID_HANDLE;
  428. return ret;
  429. }
  430. /***********************************************************************
  431. * ApplyControlToken (SECUR32.@)
  432. */
  433. SECURITY_STATUS WINAPI ApplyControlToken(PCtxtHandle phContext,
  434. PSecBufferDesc pInput)
  435. {
  436. SECURITY_STATUS ret;
  437. TRACE("%p %p\n", phContext, pInput);
  438. if (phContext)
  439. {
  440. SecurePackage *package = (SecurePackage *)phContext->dwUpper;
  441. PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
  442. if (package && package->provider)
  443. {
  444. if (package->provider->fnTableW.ApplyControlToken)
  445. ret = package->provider->fnTableW.ApplyControlToken(
  446. ctxt, pInput);
  447. else
  448. ret = SEC_E_UNSUPPORTED_FUNCTION;
  449. }
  450. else
  451. ret = SEC_E_INVALID_HANDLE;
  452. }
  453. else
  454. ret = SEC_E_INVALID_HANDLE;
  455. return ret;
  456. }
  457. /***********************************************************************
  458. * QueryContextAttributesA (SECUR32.@)
  459. */
  460. SECURITY_STATUS WINAPI QueryContextAttributesA(PCtxtHandle phContext,
  461. ULONG ulAttribute, void *pBuffer)
  462. {
  463. SECURITY_STATUS ret;
  464. TRACE("%p %d %p\n", phContext, ulAttribute, pBuffer);
  465. if (phContext)
  466. {
  467. SecurePackage *package = (SecurePackage *)phContext->dwUpper;
  468. PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
  469. if (package && package->provider)
  470. {
  471. if (package->provider->fnTableA.QueryContextAttributesA)
  472. ret = package->provider->fnTableA.QueryContextAttributesA(
  473. ctxt, ulAttribute, pBuffer);
  474. else
  475. ret = SEC_E_UNSUPPORTED_FUNCTION;
  476. }
  477. else
  478. ret = SEC_E_INVALID_HANDLE;
  479. }
  480. else
  481. ret = SEC_E_INVALID_HANDLE;
  482. return ret;
  483. }
  484. /***********************************************************************
  485. * QueryContextAttributesW (SECUR32.@)
  486. */
  487. SECURITY_STATUS WINAPI QueryContextAttributesW(PCtxtHandle phContext,
  488. ULONG ulAttribute, void *pBuffer)
  489. {
  490. SECURITY_STATUS ret;
  491. TRACE("%p %d %p\n", phContext, ulAttribute, pBuffer);
  492. if (phContext)
  493. {
  494. SecurePackage *package = (SecurePackage *)phContext->dwUpper;
  495. PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
  496. if (package && package->provider)
  497. {
  498. if (package->provider->fnTableW.QueryContextAttributesW)
  499. ret = package->provider->fnTableW.QueryContextAttributesW(
  500. ctxt, ulAttribute, pBuffer);
  501. else
  502. ret = SEC_E_UNSUPPORTED_FUNCTION;
  503. }
  504. else
  505. ret = SEC_E_INVALID_HANDLE;
  506. }
  507. else
  508. ret = SEC_E_INVALID_HANDLE;
  509. return ret;
  510. }
  511. /***********************************************************************
  512. * ImpersonateSecurityContext (SECUR32.@)
  513. */
  514. SECURITY_STATUS WINAPI ImpersonateSecurityContext(PCtxtHandle phContext)
  515. {
  516. SECURITY_STATUS ret;
  517. TRACE("%p\n", phContext);
  518. if (phContext)
  519. {
  520. SecurePackage *package = (SecurePackage *)phContext->dwUpper;
  521. PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
  522. if (package && package->provider)
  523. {
  524. if (package->provider->fnTableW.ImpersonateSecurityContext)
  525. ret = package->provider->fnTableW.ImpersonateSecurityContext(
  526. ctxt);
  527. else
  528. ret = SEC_E_UNSUPPORTED_FUNCTION;
  529. }
  530. else
  531. ret = SEC_E_INVALID_HANDLE;
  532. }
  533. else
  534. ret = SEC_E_INVALID_HANDLE;
  535. return ret;
  536. }
  537. /***********************************************************************
  538. * RevertSecurityContext (SECUR32.@)
  539. */
  540. SECURITY_STATUS WINAPI RevertSecurityContext(PCtxtHandle phContext)
  541. {
  542. SECURITY_STATUS ret;
  543. TRACE("%p\n", phContext);
  544. if (phContext)
  545. {
  546. SecurePackage *package = (SecurePackage *)phContext->dwUpper;
  547. PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
  548. if (package && package->provider)
  549. {
  550. if (package->provider->fnTableW.RevertSecurityContext)
  551. ret = package->provider->fnTableW.RevertSecurityContext(
  552. ctxt);
  553. else
  554. ret = SEC_E_UNSUPPORTED_FUNCTION;
  555. }
  556. else
  557. ret = SEC_E_INVALID_HANDLE;
  558. }
  559. else
  560. ret = SEC_E_INVALID_HANDLE;
  561. return ret;
  562. }
  563. /***********************************************************************
  564. * MakeSignature (SECUR32.@)
  565. */
  566. SECURITY_STATUS WINAPI MakeSignature(PCtxtHandle phContext, ULONG fQOP,
  567. PSecBufferDesc pMessage, ULONG MessageSeqNo)
  568. {
  569. SECURITY_STATUS ret;
  570. TRACE("%p %d %p %d\n", phContext, fQOP, pMessage, MessageSeqNo);
  571. if (phContext)
  572. {
  573. SecurePackage *package = (SecurePackage *)phContext->dwUpper;
  574. PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
  575. if (package && package->provider)
  576. {
  577. if (package->provider->fnTableW.MakeSignature)
  578. ret = package->provider->fnTableW.MakeSignature(
  579. ctxt, fQOP, pMessage, MessageSeqNo);
  580. else
  581. ret = SEC_E_UNSUPPORTED_FUNCTION;
  582. }
  583. else
  584. ret = SEC_E_INVALID_HANDLE;
  585. }
  586. else
  587. ret = SEC_E_INVALID_HANDLE;
  588. return ret;
  589. }
  590. /***********************************************************************
  591. * VerifySignature (SECUR32.@)
  592. */
  593. SECURITY_STATUS WINAPI VerifySignature(PCtxtHandle phContext,
  594. PSecBufferDesc pMessage, ULONG MessageSeqNo, PULONG pfQOP)
  595. {
  596. SECURITY_STATUS ret;
  597. TRACE("%p %p %d %p\n", phContext, pMessage, MessageSeqNo, pfQOP);
  598. if (phContext)
  599. {
  600. SecurePackage *package = (SecurePackage *)phContext->dwUpper;
  601. PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
  602. if (package && package->provider)
  603. {
  604. if (package->provider->fnTableW.VerifySignature)
  605. ret = package->provider->fnTableW.VerifySignature(
  606. ctxt, pMessage, MessageSeqNo, pfQOP);
  607. else
  608. ret = SEC_E_UNSUPPORTED_FUNCTION;
  609. }
  610. else
  611. ret = SEC_E_INVALID_HANDLE;
  612. }
  613. else
  614. ret = SEC_E_INVALID_HANDLE;
  615. return ret;
  616. }
  617. /***********************************************************************
  618. * QuerySecurityPackageInfoA (SECUR32.@)
  619. */
  620. SECURITY_STATUS WINAPI QuerySecurityPackageInfoA(SEC_CHAR *pszPackageName,
  621. PSecPkgInfoA *ppPackageInfo)
  622. {
  623. SECURITY_STATUS ret;
  624. TRACE("%s %p\n", debugstr_a(pszPackageName), ppPackageInfo);
  625. if (pszPackageName)
  626. {
  627. SecurePackage *package = SECUR32_findPackageA(pszPackageName);
  628. if (package)
  629. {
  630. size_t bytesNeeded = sizeof(SecPkgInfoA);
  631. int nameLen = 0, commentLen = 0;
  632. if (package->infoW.Name)
  633. {
  634. nameLen = WideCharToMultiByte(CP_ACP, 0,
  635. package->infoW.Name, -1, NULL, 0, NULL, NULL);
  636. bytesNeeded += nameLen;
  637. }
  638. if (package->infoW.Comment)
  639. {
  640. commentLen = WideCharToMultiByte(CP_ACP, 0,
  641. package->infoW.Comment, -1, NULL, 0, NULL, NULL);
  642. bytesNeeded += commentLen;
  643. }
  644. *ppPackageInfo = HeapAlloc(GetProcessHeap(), 0, bytesNeeded);
  645. if (*ppPackageInfo)
  646. {
  647. PSTR nextString = (PSTR)((PBYTE)*ppPackageInfo +
  648. sizeof(SecPkgInfoA));
  649. memcpy(*ppPackageInfo, &package->infoW, sizeof(package->infoW));
  650. if (package->infoW.Name)
  651. {
  652. (*ppPackageInfo)->Name = nextString;
  653. nextString += WideCharToMultiByte(CP_ACP, 0,
  654. package->infoW.Name, -1, nextString, nameLen, NULL, NULL);
  655. }
  656. else
  657. (*ppPackageInfo)->Name = NULL;
  658. if (package->infoW.Comment)
  659. {
  660. (*ppPackageInfo)->Comment = nextString;
  661. nextString += WideCharToMultiByte(CP_ACP, 0,
  662. package->infoW.Comment, -1, nextString, commentLen, NULL,
  663. NULL);
  664. }
  665. else
  666. (*ppPackageInfo)->Comment = NULL;
  667. ret = SEC_E_OK;
  668. }
  669. else
  670. ret = SEC_E_INSUFFICIENT_MEMORY;
  671. }
  672. else
  673. ret = SEC_E_SECPKG_NOT_FOUND;
  674. }
  675. else
  676. ret = SEC_E_SECPKG_NOT_FOUND;
  677. return ret;
  678. }
  679. /***********************************************************************
  680. * QuerySecurityPackageInfoW (SECUR32.@)
  681. */
  682. SECURITY_STATUS WINAPI QuerySecurityPackageInfoW(SEC_WCHAR *pszPackageName,
  683. PSecPkgInfoW *ppPackageInfo)
  684. {
  685. SECURITY_STATUS ret;
  686. SecurePackage *package = SECUR32_findPackageW(pszPackageName);
  687. TRACE("%s %p\n", debugstr_w(pszPackageName), ppPackageInfo);
  688. if (package)
  689. {
  690. size_t bytesNeeded = sizeof(SecPkgInfoW);
  691. int nameLen = 0, commentLen = 0;
  692. if (package->infoW.Name)
  693. {
  694. nameLen = lstrlenW(package->infoW.Name) + 1;
  695. bytesNeeded += nameLen * sizeof(WCHAR);
  696. }
  697. if (package->infoW.Comment)
  698. {
  699. commentLen = lstrlenW(package->infoW.Comment) + 1;
  700. bytesNeeded += commentLen * sizeof(WCHAR);
  701. }
  702. *ppPackageInfo = HeapAlloc(GetProcessHeap(), 0, bytesNeeded);
  703. if (*ppPackageInfo)
  704. {
  705. PWSTR nextString = (PWSTR)((PBYTE)*ppPackageInfo +
  706. sizeof(SecPkgInfoW));
  707. **ppPackageInfo = package->infoW;
  708. if (package->infoW.Name)
  709. {
  710. (*ppPackageInfo)->Name = nextString;
  711. lstrcpynW(nextString, package->infoW.Name, nameLen);
  712. nextString += nameLen;
  713. }
  714. else
  715. (*ppPackageInfo)->Name = NULL;
  716. if (package->infoW.Comment)
  717. {
  718. (*ppPackageInfo)->Comment = nextString;
  719. lstrcpynW(nextString, package->infoW.Comment, commentLen);
  720. }
  721. else
  722. (*ppPackageInfo)->Comment = NULL;
  723. ret = SEC_E_OK;
  724. }
  725. else
  726. ret = SEC_E_INSUFFICIENT_MEMORY;
  727. }
  728. else
  729. ret = SEC_E_SECPKG_NOT_FOUND;
  730. return ret;
  731. }
  732. /***********************************************************************
  733. * ExportSecurityContext (SECUR32.@)
  734. */
  735. SECURITY_STATUS WINAPI ExportSecurityContext(PCtxtHandle phContext,
  736. ULONG fFlags, PSecBuffer pPackedContext, void **pToken)
  737. {
  738. SECURITY_STATUS ret;
  739. TRACE("%p %d %p %p\n", phContext, fFlags, pPackedContext, pToken);
  740. if (phContext)
  741. {
  742. SecurePackage *package = (SecurePackage *)phContext->dwUpper;
  743. PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
  744. if (package && package->provider)
  745. {
  746. if (package->provider->fnTableW.ExportSecurityContext)
  747. ret = package->provider->fnTableW.ExportSecurityContext(
  748. ctxt, fFlags, pPackedContext, pToken);
  749. else
  750. ret = SEC_E_UNSUPPORTED_FUNCTION;
  751. }
  752. else
  753. ret = SEC_E_INVALID_HANDLE;
  754. }
  755. else
  756. ret = SEC_E_INVALID_HANDLE;
  757. return ret;
  758. }
  759. /***********************************************************************
  760. * ImportSecurityContextA (SECUR32.@)
  761. */
  762. SECURITY_STATUS WINAPI ImportSecurityContextA(SEC_CHAR *pszPackage,
  763. PSecBuffer pPackedContext, void *Token, PCtxtHandle phContext)
  764. {
  765. SECURITY_STATUS ret;
  766. SecurePackage *package = SECUR32_findPackageA(pszPackage);
  767. TRACE("%s %p %p %p\n", debugstr_a(pszPackage), pPackedContext, Token,
  768. phContext);
  769. if (package && package->provider)
  770. {
  771. if (package->provider->fnTableA.ImportSecurityContextA)
  772. {
  773. CtxtHandle myCtxt;
  774. ret = package->provider->fnTableA.ImportSecurityContextA(
  775. pszPackage, pPackedContext, Token, &myCtxt);
  776. if (ret == SEC_E_OK)
  777. {
  778. ret = SECUR32_makeSecHandle(phContext, package, &myCtxt);
  779. if (ret != SEC_E_OK)
  780. package->provider->fnTableW.DeleteSecurityContext(&myCtxt);
  781. }
  782. }
  783. else
  784. ret = SEC_E_UNSUPPORTED_FUNCTION;
  785. }
  786. else
  787. ret = SEC_E_SECPKG_NOT_FOUND;
  788. return ret;
  789. }
  790. /***********************************************************************
  791. * ImportSecurityContextW (SECUR32.@)
  792. */
  793. SECURITY_STATUS WINAPI ImportSecurityContextW(SEC_WCHAR *pszPackage,
  794. PSecBuffer pPackedContext, void *Token, PCtxtHandle phContext)
  795. {
  796. SECURITY_STATUS ret;
  797. SecurePackage *package = SECUR32_findPackageW(pszPackage);
  798. TRACE("%s %p %p %p\n", debugstr_w(pszPackage), pPackedContext, Token,
  799. phContext);
  800. if (package && package->provider)
  801. {
  802. if (package->provider->fnTableW.ImportSecurityContextW)
  803. {
  804. CtxtHandle myCtxt;
  805. ret = package->provider->fnTableW.ImportSecurityContextW(
  806. pszPackage, pPackedContext, Token, &myCtxt);
  807. if (ret == SEC_E_OK)
  808. {
  809. ret = SECUR32_makeSecHandle(phContext, package, &myCtxt);
  810. if (ret != SEC_E_OK)
  811. package->provider->fnTableW.DeleteSecurityContext(&myCtxt);
  812. }
  813. }
  814. else
  815. ret = SEC_E_UNSUPPORTED_FUNCTION;
  816. }
  817. else
  818. ret = SEC_E_SECPKG_NOT_FOUND;
  819. return ret;
  820. }
  821. /***********************************************************************
  822. * AddCredentialsA (SECUR32.@)
  823. */
  824. SECURITY_STATUS WINAPI AddCredentialsA(PCredHandle hCredentials,
  825. SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialUse,
  826. void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
  827. PTimeStamp ptsExpiry)
  828. {
  829. SECURITY_STATUS ret;
  830. TRACE("%p %s %s %d %p %p %p %p\n", hCredentials, debugstr_a(pszPrincipal),
  831. debugstr_a(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
  832. pvGetKeyArgument, ptsExpiry);
  833. if (hCredentials)
  834. {
  835. SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
  836. PCredHandle cred = (PCtxtHandle)hCredentials->dwLower;
  837. if (package && package->provider)
  838. {
  839. if (package->provider->fnTableA.AddCredentialsA)
  840. ret = package->provider->fnTableA.AddCredentialsA(
  841. cred, pszPrincipal, pszPackage, fCredentialUse, pAuthData,
  842. pGetKeyFn, pvGetKeyArgument, ptsExpiry);
  843. else
  844. ret = SEC_E_UNSUPPORTED_FUNCTION;
  845. }
  846. else
  847. ret = SEC_E_INVALID_HANDLE;
  848. }
  849. else
  850. ret = SEC_E_INVALID_HANDLE;
  851. return ret;
  852. }
  853. /***********************************************************************
  854. * AddCredentialsW (SECUR32.@)
  855. */
  856. SECURITY_STATUS WINAPI AddCredentialsW(PCredHandle hCredentials,
  857. SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialUse,
  858. void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
  859. PTimeStamp ptsExpiry)
  860. {
  861. SECURITY_STATUS ret;
  862. TRACE("%p %s %s %d %p %p %p %p\n", hCredentials, debugstr_w(pszPrincipal),
  863. debugstr_w(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
  864. pvGetKeyArgument, ptsExpiry);
  865. if (hCredentials)
  866. {
  867. SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
  868. PCredHandle cred = (PCtxtHandle)hCredentials->dwLower;
  869. if (package && package->provider)
  870. {
  871. if (package->provider->fnTableW.AddCredentialsW)
  872. ret = package->provider->fnTableW.AddCredentialsW(
  873. cred, pszPrincipal, pszPackage, fCredentialUse, pAuthData,
  874. pGetKeyFn, pvGetKeyArgument, ptsExpiry);
  875. else
  876. ret = SEC_E_UNSUPPORTED_FUNCTION;
  877. }
  878. else
  879. ret = SEC_E_INVALID_HANDLE;
  880. }
  881. else
  882. ret = SEC_E_INVALID_HANDLE;
  883. return ret;
  884. }
  885. /***********************************************************************
  886. * QuerySecurityContextToken (SECUR32.@)
  887. */
  888. SECURITY_STATUS WINAPI QuerySecurityContextToken(PCtxtHandle phContext,
  889. HANDLE *phToken)
  890. {
  891. SECURITY_STATUS ret;
  892. TRACE("%p %p\n", phContext, phToken);
  893. if (phContext)
  894. {
  895. SecurePackage *package = (SecurePackage *)phContext->dwUpper;
  896. PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
  897. if (package && package->provider)
  898. {
  899. if (package->provider->fnTableW.QuerySecurityContextToken)
  900. ret = package->provider->fnTableW.QuerySecurityContextToken(
  901. ctxt, phToken);
  902. else
  903. ret = SEC_E_UNSUPPORTED_FUNCTION;
  904. }
  905. else
  906. ret = SEC_E_INVALID_HANDLE;
  907. }
  908. else
  909. ret = SEC_E_INVALID_HANDLE;
  910. return ret;
  911. }
  912. /***********************************************************************
  913. * EncryptMessage (SECUR32.@)
  914. */
  915. SECURITY_STATUS WINAPI EncryptMessage(PCtxtHandle phContext, ULONG fQOP,
  916. PSecBufferDesc pMessage, ULONG MessageSeqNo)
  917. {
  918. SECURITY_STATUS ret;
  919. TRACE("%p %d %p %d\n", phContext, fQOP, pMessage, MessageSeqNo);
  920. if (phContext)
  921. {
  922. SecurePackage *package = (SecurePackage *)phContext->dwUpper;
  923. PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
  924. if (package && package->provider)
  925. {
  926. if (package->provider->fnTableW.EncryptMessage)
  927. ret = package->provider->fnTableW.EncryptMessage(
  928. ctxt, fQOP, pMessage, MessageSeqNo);
  929. else
  930. ret = SEC_E_UNSUPPORTED_FUNCTION;
  931. }
  932. else
  933. ret = SEC_E_INVALID_HANDLE;
  934. }
  935. else
  936. ret = SEC_E_INVALID_HANDLE;
  937. return ret;
  938. }
  939. /***********************************************************************
  940. * DecryptMessage (SECUR32.@)
  941. */
  942. SECURITY_STATUS WINAPI DecryptMessage(PCtxtHandle phContext,
  943. PSecBufferDesc pMessage, ULONG MessageSeqNo, PULONG pfQOP)
  944. {
  945. SECURITY_STATUS ret;
  946. TRACE("%p %p %d %p\n", phContext, pMessage, MessageSeqNo, pfQOP);
  947. if (phContext)
  948. {
  949. SecurePackage *package = (SecurePackage *)phContext->dwUpper;
  950. PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
  951. if (package && package->provider)
  952. {
  953. if (package->provider->fnTableW.DecryptMessage)
  954. ret = package->provider->fnTableW.DecryptMessage(
  955. ctxt, pMessage, MessageSeqNo, pfQOP);
  956. else
  957. ret = SEC_E_UNSUPPORTED_FUNCTION;
  958. }
  959. else
  960. ret = SEC_E_INVALID_HANDLE;
  961. }
  962. else
  963. ret = SEC_E_INVALID_HANDLE;
  964. return ret;
  965. }
  966. /***********************************************************************
  967. * SetContextAttributesA (SECUR32.@)
  968. */
  969. SECURITY_STATUS WINAPI SetContextAttributesA(PCtxtHandle phContext,
  970. ULONG ulAttribute, void *pBuffer, ULONG cbBuffer)
  971. {
  972. SECURITY_STATUS ret;
  973. TRACE("%p %d %p %d\n", phContext, ulAttribute, pBuffer, cbBuffer);
  974. if (phContext)
  975. {
  976. SecurePackage *package = (SecurePackage *)phContext->dwUpper;
  977. PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
  978. if (package && package->provider)
  979. {
  980. if (package->provider->fnTableA.SetContextAttributesA)
  981. ret = package->provider->fnTableA.SetContextAttributesA(
  982. ctxt, ulAttribute, pBuffer, cbBuffer);
  983. else
  984. ret = SEC_E_UNSUPPORTED_FUNCTION;
  985. }
  986. else
  987. ret = SEC_E_INVALID_HANDLE;
  988. }
  989. else
  990. ret = SEC_E_INVALID_HANDLE;
  991. return ret;
  992. }
  993. /***********************************************************************
  994. * SetContextAttributesW (SECUR32.@)
  995. */
  996. SECURITY_STATUS WINAPI SetContextAttributesW(PCtxtHandle phContext,
  997. ULONG ulAttribute, void *pBuffer, ULONG cbBuffer)
  998. {
  999. SECURITY_STATUS ret;
  1000. TRACE("%p %d %p %d\n", phContext, ulAttribute, pBuffer, cbBuffer);
  1001. if (phContext)
  1002. {
  1003. SecurePackage *package = (SecurePackage *)phContext->dwUpper;
  1004. PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
  1005. if (package && package->provider)
  1006. {
  1007. if (package->provider->fnTableW.SetContextAttributesW)
  1008. ret = package->provider->fnTableW.SetContextAttributesW(
  1009. ctxt, ulAttribute, pBuffer, cbBuffer);
  1010. else
  1011. ret = SEC_E_UNSUPPORTED_FUNCTION;
  1012. }
  1013. else
  1014. ret = SEC_E_INVALID_HANDLE;
  1015. }
  1016. else
  1017. ret = SEC_E_INVALID_HANDLE;
  1018. return ret;
  1019. }