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.

885 lines
26 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 1991 - 1992
  6. //
  7. // File: ctxtapi.c
  8. //
  9. // Contents: Context APIs to the SPMgr.
  10. // - LsaInitContext
  11. // - LsaAcceptContext
  12. // - LsaFinalizeContext
  13. // - LsaMapContext
  14. //
  15. // And WLsa functions
  16. //
  17. // History: 20 May 92 RichardW Commented existing code
  18. //
  19. //------------------------------------------------------------------------
  20. #include <lsapch.hxx>
  21. //+---------------------------------------------------------------------------
  22. //
  23. // Function: WLsaInitContext
  24. //
  25. // Synopsis: Worker that maps the call to the appropriate package
  26. //
  27. // Effects:
  28. //
  29. // Arguments: [phCredential] --
  30. // [phContext] --
  31. // [pTarget] --
  32. // [fContextReq] --
  33. // [dwReserved1] --
  34. // [TargetDataRep] --
  35. // [pInput] --
  36. // [dwReserved2] --
  37. // [phNewContext] --
  38. // [pOutput] --
  39. // [pfContextAttr] --
  40. // [ptsExpiry] --
  41. // [MappedContext] --
  42. // [ContextData] --
  43. //
  44. // Requires:
  45. //
  46. // Returns:
  47. //
  48. // History: 9-24-96 RichardW Created
  49. //
  50. // Notes:
  51. //
  52. //----------------------------------------------------------------------------
  53. NTSTATUS
  54. WLsaInitContext( PCredHandle phCredential,
  55. PCtxtHandle phContext,
  56. PSECURITY_STRING pTarget,
  57. DWORD fContextReq,
  58. DWORD dwReserved1,
  59. DWORD TargetDataRep,
  60. PSecBufferDesc pInput,
  61. DWORD dwReserved2,
  62. PCtxtHandle phNewContext,
  63. PSecBufferDesc pOutput,
  64. DWORD * pfContextAttr,
  65. PTimeStamp ptsExpiry,
  66. PBOOLEAN MappedContext,
  67. PSecBuffer ContextData )
  68. {
  69. NTSTATUS scRet;
  70. PLSAP_SECURITY_PACKAGE pspPackage;
  71. PSession pSession = GetCurrentSession();
  72. PLSA_CALL_INFO CallInfo = LsapGetCurrentCall();
  73. PVOID ContextKey = NULL ;
  74. PVOID CredKey = NULL ;
  75. DebugLog((DEB_TRACE_WAPI, "[%x] WLsaInitContext(%p : %p, %p : %p, %ws)\n",
  76. pSession->dwProcessID,
  77. phCredential->dwUpper,
  78. phCredential->dwLower,
  79. phContext->dwUpper,
  80. phContext->dwLower,
  81. pTarget->Buffer));
  82. #if DBG
  83. if ( pInput && pInput->cBuffers )
  84. {
  85. DsysAssert( (ULONG_PTR) pInput->pBuffers > PORT_MAXIMUM_MESSAGE_LENGTH );
  86. }
  87. if ( pOutput && pOutput->cBuffers )
  88. {
  89. DsysAssert( (ULONG_PTR) pOutput->pBuffers > PORT_MAXIMUM_MESSAGE_LENGTH );
  90. }
  91. #endif
  92. //
  93. // Reset the new handle to a known, invalid state
  94. //
  95. phNewContext->dwLower = SPMGR_ID;
  96. phNewContext->dwUpper = 0;
  97. //
  98. // Check handles against the session to make sure they're valid. If the
  99. // context handle is valid, we use that, otherwise the credential.
  100. //
  101. if (phCredential->dwUpper)
  102. {
  103. scRet = ValidateCredHandle(
  104. pSession,
  105. phCredential,
  106. &CredKey );
  107. if ( !NT_SUCCESS( scRet ) )
  108. {
  109. DsysAssert( (pSession->fSession & SESFLAG_KERNEL) == 0 );
  110. //
  111. // null out the dwUpper since the handle is invalid, do not want to
  112. // bail it out here for app compat reasons: the credential handle
  113. // is ignored when the context handle is valid
  114. //
  115. DebugLog((DEB_WARN, "[%#x] InitContext null out invalid credential handle %#x.%#x\n",
  116. pSession->dwProcessID, phCredential->dwLower, phCredential->dwUpper));
  117. phCredential->dwUpper = NULL;
  118. }
  119. }
  120. if (phContext->dwUpper)
  121. {
  122. scRet = ValidateContextHandle(
  123. pSession,
  124. phContext,
  125. &ContextKey );
  126. if ( !NT_SUCCESS( scRet ) )
  127. {
  128. DsysAssert( (pSession->fSession & SESFLAG_KERNEL) == 0 );
  129. //
  130. // null out the dwUpper since the handle is invalid
  131. //
  132. DebugLog((DEB_WARN, "[%#x] InitContext null out invalid context handle %#x.%#x\n",
  133. pSession->dwProcessID, phContext->dwLower, phContext->dwUpper));
  134. phContext->dwUpper = NULL;
  135. }
  136. else
  137. {
  138. //
  139. // Tricky stuff: if the context handle is valid, but does not
  140. // come from the same package as the credential, null out the cred
  141. // handle:
  142. //
  143. if ( phCredential->dwLower != phContext->dwLower )
  144. {
  145. phCredential->dwLower = 0;
  146. phCredential->dwUpper = 0;
  147. }
  148. }
  149. }
  150. if ((phContext->dwUpper == NULL) && (phCredential->dwUpper == NULL))
  151. {
  152. DsysAssert( (pSession->fSession & SESFLAG_KERNEL) == 0 );
  153. scRet = SEC_E_INVALID_HANDLE;
  154. goto Cleanup;
  155. }
  156. //
  157. // log the call info using the context handle if it is valid, otherwise use
  158. // the credential handle
  159. //
  160. LsapLogCallInfo( CallInfo, pSession, phContext->dwUpper ? *phContext : *phCredential );
  161. //
  162. // if the context handle is non null and valid, use its package value, otherwise
  163. // use the package value from the credential handle
  164. //
  165. pspPackage = SpmpValidRequest( phContext->dwUpper ? phContext->dwLower : phCredential->dwLower,
  166. SP_ORDINAL_INITLSAMODECTXT );
  167. if ( !pspPackage )
  168. {
  169. scRet = SEC_E_INVALID_HANDLE;
  170. goto Cleanup;
  171. }
  172. SetCurrentPackageId( pspPackage->dwPackageID );
  173. StartCallToPackage( pspPackage );
  174. DebugLog((DEB_TRACE_VERB, "\tContext Req = 0x%08x\n", fContextReq));
  175. DebugLog((DEB_TRACE_VERB, "\tPackage = %ws\n", pspPackage->Name.Buffer));
  176. __try
  177. {
  178. scRet = pspPackage->FunctionTable.InitLsaModeContext(
  179. phCredential->dwUpper,
  180. phContext->dwUpper,
  181. pTarget,
  182. fContextReq,
  183. TargetDataRep,
  184. pInput,
  185. &phNewContext->dwUpper,
  186. pOutput,
  187. pfContextAttr,
  188. ptsExpiry,
  189. MappedContext,
  190. ContextData );
  191. }
  192. __except (SP_EXCEPTION)
  193. {
  194. scRet = GetExceptionCode();
  195. scRet = SPException(scRet, pspPackage->dwPackageID);
  196. }
  197. EndCallToPackage( pspPackage );
  198. DebugLog((DEB_TRACE_WAPI, "InitResult = %x\n", scRet));
  199. DebugLog((DEB_TRACE_VERB, "\tFlags = %08x\n", *pfContextAttr));
  200. //
  201. // Only add a new context if the old one didn't exist.
  202. // Otherwise copy the old context over the new context.
  203. //
  204. if ( NT_SUCCESS( scRet ) )
  205. {
  206. if ( (phNewContext->dwUpper != 0) &&
  207. (phNewContext->dwUpper != phContext->dwUpper) )
  208. {
  209. //
  210. // If the package ID is unchanged, set it to the current package
  211. // id. This is so that if package changes the ID through
  212. // LsapChangeHandle, we can catch it.
  213. //
  214. if ( phNewContext->dwLower == SPMGR_ID )
  215. {
  216. phNewContext->dwLower = pspPackage->dwPackageID ;
  217. if (!AddContextHandle( pSession, phNewContext, 0 ))
  218. {
  219. DebugLog(( DEB_ERROR, "Failed adding context handle %p:%p to session %p\n",
  220. phNewContext->dwUpper, phNewContext->dwLower,
  221. pSession ));
  222. pspPackage = SpmpValidRequest(
  223. phNewContext->dwLower,
  224. SP_ORDINAL_DELETECTXT
  225. );
  226. if ( pspPackage )
  227. {
  228. //
  229. // remove the handle from the underlying package.
  230. //
  231. StartCallToPackage( pspPackage );
  232. __try
  233. {
  234. pspPackage->FunctionTable.DeleteContext(
  235. phNewContext->dwUpper
  236. );
  237. }
  238. __except (SP_EXCEPTION)
  239. {
  240. NOTHING;
  241. }
  242. EndCallToPackage( pspPackage );
  243. }
  244. phNewContext->dwLower = 0;
  245. phNewContext->dwUpper = 0;
  246. scRet = SEC_E_INSUFFICIENT_MEMORY;
  247. }
  248. }
  249. }
  250. else
  251. {
  252. *phNewContext = *phContext;
  253. }
  254. }
  255. else
  256. {
  257. *phNewContext = *phContext ;
  258. }
  259. DebugLog(( DEB_TRACE_WAPI, "Init New Context = %p : %p to session %p\n",
  260. phNewContext->dwUpper , phNewContext->dwLower, pSession ));
  261. SetCurrentPackageId( SPMGR_ID );
  262. Cleanup:
  263. if ( ContextKey )
  264. {
  265. DerefContextHandle( pSession, NULL, ContextKey );
  266. }
  267. if ( CredKey )
  268. {
  269. DerefCredHandle( pSession, NULL, CredKey );
  270. }
  271. return(scRet);
  272. }
  273. //+-------------------------------------------------------------------------
  274. //
  275. // Function: WLsaAcceptContext()
  276. //
  277. // Synopsis: Worker function for AcceptSecurityContext()
  278. //
  279. // Effects: Creates a server-side security context
  280. //
  281. // Arguments: See LsaAcceptContext()
  282. //
  283. // Requires:
  284. //
  285. // Returns:
  286. //
  287. // Notes:
  288. //
  289. //--------------------------------------------------------------------------
  290. NTSTATUS
  291. WLsaAcceptContext( PCredHandle phCredential,
  292. PCtxtHandle phContext,
  293. PSecBufferDesc pInput,
  294. DWORD fContextReq,
  295. DWORD TargetDataRep,
  296. PCtxtHandle phNewContext,
  297. PSecBufferDesc pOutput,
  298. DWORD * pfContextAttr,
  299. PTimeStamp ptsExpiry,
  300. PBOOLEAN MappedContext,
  301. PSecBuffer ContextData)
  302. {
  303. NTSTATUS scRet;
  304. PLSAP_SECURITY_PACKAGE pspPackage;
  305. PSession pSession;
  306. PVOID ContextKey = NULL ;
  307. PVOID CredKey = NULL ;
  308. PLSA_CALL_INFO CallInfo = LsapGetCurrentCall();
  309. //
  310. // Clear out the handle
  311. //
  312. phNewContext->dwLower = SPMGR_ID;
  313. phNewContext->dwUpper = 0;
  314. #if DBG
  315. if ( pInput && pInput->cBuffers )
  316. {
  317. DsysAssert( (ULONG_PTR) pInput->pBuffers > PORT_MAXIMUM_MESSAGE_LENGTH );
  318. }
  319. if ( pOutput && pOutput->cBuffers )
  320. {
  321. DsysAssert( (ULONG_PTR) pOutput->pBuffers > PORT_MAXIMUM_MESSAGE_LENGTH );
  322. }
  323. #endif
  324. //
  325. // Get our session
  326. //
  327. pSession = GetCurrentSession();
  328. DebugLog((DEB_TRACE_WAPI, "[%x] WLsaAcceptContext(%p : %p)\n",
  329. pSession->dwProcessID,
  330. phCredential->dwUpper, phCredential->dwLower));
  331. //
  332. // Check handles against the session to make sure they're valid. If the
  333. // context handle is valid, we use that, otherwise the credential.
  334. //
  335. if (phCredential->dwUpper)
  336. {
  337. scRet = ValidateCredHandle(
  338. pSession,
  339. phCredential,
  340. &CredKey );
  341. if ( !NT_SUCCESS( scRet ) )
  342. {
  343. DsysAssert( (pSession->fSession & SESFLAG_KERNEL) == 0 );
  344. //
  345. // null out the dwUpper since the handle is invalid, do not want to
  346. // bail it out here for app compat reasons: the credential handle
  347. // is ignored when the context handle is valid
  348. //
  349. DebugLog((DEB_WARN, "[%#x] AcceptContext null out invalid credential handle %#x.%#x\n",
  350. pSession->dwProcessID, phCredential->dwLower, phCredential->dwUpper));
  351. phCredential->dwUpper = NULL;
  352. }
  353. }
  354. if (phContext->dwUpper)
  355. {
  356. scRet = ValidateContextHandle(
  357. pSession,
  358. phContext,
  359. &ContextKey );
  360. if ( !NT_SUCCESS( scRet ) )
  361. {
  362. DsysAssert( (pSession->fSession & SESFLAG_KERNEL) == 0 );
  363. //
  364. // null out the dwUpper since the handle is invalid
  365. //
  366. DebugLog((DEB_WARN, "[%#x] AcceptContext null out invalid context handle %#x.%#x\n",
  367. pSession->dwProcessID, phContext->dwLower, phContext->dwUpper));
  368. phContext->dwUpper = NULL;
  369. }
  370. else
  371. {
  372. //
  373. // Tricky stuff: if the context handle is valid, but does not
  374. // come from the same package as the credential, null out the cred
  375. // handle:
  376. //
  377. if ( phCredential->dwLower != phContext->dwLower )
  378. {
  379. phCredential->dwLower = 0;
  380. phCredential->dwUpper = 0;
  381. }
  382. }
  383. }
  384. if ((phContext->dwUpper == NULL) && (phCredential->dwUpper == NULL))
  385. {
  386. DsysAssert( (pSession->fSession & SESFLAG_KERNEL) == 0 );
  387. scRet = SEC_E_INVALID_HANDLE;
  388. goto Cleanup;
  389. }
  390. //
  391. // log the call info using the context handle if it is valid, otherwise use
  392. // the credential handle
  393. //
  394. LsapLogCallInfo( CallInfo, pSession, phContext->dwUpper ? *phContext : *phCredential );
  395. //
  396. // if the context handle is non null and valid, use its package value, otherwise
  397. // use the package value from the credential handle
  398. //
  399. pspPackage = SpmpValidRequest( phContext->dwUpper ? phContext->dwLower : phCredential->dwLower,
  400. SP_ORDINAL_ACCEPTLSAMODECTXT );
  401. if ( !pspPackage )
  402. {
  403. DsysAssert( (pSession->fSession & SESFLAG_KERNEL) == 0 );
  404. scRet = SEC_E_INVALID_HANDLE;
  405. goto Cleanup;
  406. }
  407. SetCurrentPackageId( pspPackage->dwPackageID );
  408. StartCallToPackage( pspPackage );
  409. __try
  410. {
  411. scRet = pspPackage->FunctionTable.AcceptLsaModeContext(
  412. phCredential->dwUpper,
  413. phContext->dwUpper,
  414. pInput,
  415. fContextReq,
  416. TargetDataRep,
  417. &phNewContext->dwUpper,
  418. pOutput,
  419. pfContextAttr,
  420. ptsExpiry,
  421. MappedContext,
  422. ContextData );
  423. }
  424. __except (SP_EXCEPTION)
  425. {
  426. scRet = GetExceptionCode();
  427. scRet = SPException(scRet, pspPackage->dwPackageID);
  428. }
  429. EndCallToPackage( pspPackage );
  430. DebugLog((DEB_TRACE_WAPI, "[%x] Result = %x\n", pSession->dwProcessID, scRet));
  431. //
  432. // Only add a new context if the old one didn't exist.
  433. // Otherwise copy the old context over the new context.
  434. //
  435. if ( NT_SUCCESS( scRet ) || ( scRet == SEC_E_INCOMPLETE_MESSAGE ) )
  436. {
  437. if ( (phNewContext->dwUpper != 0) &&
  438. (phNewContext->dwUpper != phContext->dwUpper) )
  439. {
  440. //
  441. // If the package ID is unchanged, set it to the current package
  442. // id. This is so that if package changes the ID through
  443. //
  444. if ( phNewContext->dwLower == SPMGR_ID )
  445. {
  446. phNewContext->dwLower = pspPackage->dwPackageID ;
  447. if (!AddContextHandle( pSession, phNewContext, 0 ))
  448. {
  449. DebugLog(( DEB_ERROR, "Failed adding context handle %p:%p to session %p\n",
  450. phNewContext->dwUpper, phNewContext->dwLower,
  451. pSession ));
  452. pspPackage = SpmpValidRequest(
  453. phNewContext->dwLower,
  454. SP_ORDINAL_DELETECTXT
  455. );
  456. if ( pspPackage )
  457. {
  458. //
  459. // remove the handle from the underlying package.
  460. //
  461. StartCallToPackage( pspPackage );
  462. __try
  463. {
  464. pspPackage->FunctionTable.DeleteContext(
  465. phNewContext->dwUpper
  466. );
  467. }
  468. __except (SP_EXCEPTION)
  469. {
  470. NOTHING;
  471. }
  472. EndCallToPackage( pspPackage );
  473. }
  474. phNewContext->dwLower = 0;
  475. phNewContext->dwUpper = 0;
  476. scRet = SEC_E_INSUFFICIENT_MEMORY;
  477. }
  478. }
  479. }
  480. else
  481. {
  482. *phNewContext = *phContext;
  483. }
  484. }
  485. else
  486. {
  487. *phNewContext = *phContext ;
  488. }
  489. DebugLog(( DEB_TRACE_WAPI, "Accept new context = %p : %p \n",
  490. phNewContext->dwUpper, phNewContext->dwLower ));
  491. SetCurrentPackageId( SPMGR_ID );
  492. Cleanup:
  493. if ( ContextKey )
  494. {
  495. DerefContextHandle( pSession, NULL, ContextKey );
  496. }
  497. if ( CredKey )
  498. {
  499. DerefCredHandle( pSession, NULL, CredKey );
  500. }
  501. return(scRet);
  502. }
  503. //+-------------------------------------------------------------------------
  504. //
  505. // Function: WLsaDeleteContext
  506. //
  507. // Synopsis: Worker function for deleting a context
  508. //
  509. // Effects:
  510. //
  511. // Arguments:
  512. //
  513. // Requires:
  514. //
  515. // Returns:
  516. //
  517. // Notes:
  518. //
  519. //--------------------------------------------------------------------------
  520. NTSTATUS
  521. WLsaDeleteContext( PCtxtHandle phContext)
  522. {
  523. NTSTATUS scRet;
  524. PSession pSession = GetCurrentSession();
  525. PLSA_CALL_INFO CallInfo = LsapGetCurrentCall();
  526. DebugLog((DEB_TRACE_WAPI, "[%x] WDeleteContext(%p : %p)\n",
  527. pSession->dwProcessID,
  528. phContext->dwUpper, phContext->dwLower));
  529. scRet = ValidateAndDerefContextHandle(
  530. pSession,
  531. phContext );
  532. if ( (CallInfo->Flags & CALL_FLAG_NO_HANDLE_CHK) == 0 )
  533. {
  534. if ( !NT_SUCCESS( scRet ) )
  535. {
  536. DebugLog((DEB_ERROR,"[%x] Invalid handle passed to DeleteContext: %p:%p\n",
  537. pSession->dwProcessID,
  538. phContext->dwUpper,phContext->dwLower));
  539. /// DsysAssert( (pSession->fSession & SESFLAG_KERNEL) == 0 );
  540. }
  541. }
  542. LsapLogCallInfo( CallInfo, pSession, *phContext );
  543. if (SUCCEEDED(scRet))
  544. {
  545. phContext->dwUpper = phContext->dwLower = 0xFFFFFFFF;
  546. }
  547. return(scRet);
  548. }
  549. //+-------------------------------------------------------------------------
  550. //
  551. // Function: WLsaApplyControlToken
  552. //
  553. // Synopsis: Worker function for applying a control token
  554. //
  555. // Effects:
  556. //
  557. // Arguments:
  558. //
  559. // Requires:
  560. //
  561. // Returns:
  562. //
  563. // Notes:
  564. //
  565. //--------------------------------------------------------------------------
  566. NTSTATUS
  567. WLsaApplyControlToken( PCtxtHandle phContext,
  568. PSecBufferDesc pInput)
  569. {
  570. NTSTATUS scRet;
  571. PLSAP_SECURITY_PACKAGE pspPackage;
  572. PSession pSession = GetCurrentSession();
  573. PLSA_CALL_INFO CallInfo = LsapGetCurrentCall();
  574. PVOID ContextKey ;
  575. DebugLog((DEB_TRACE_WAPI, "[%x] WApplyControlToken(%p : %p)\n",
  576. pSession->dwProcessID,
  577. phContext->dwUpper, phContext->dwLower));
  578. LsapLogCallInfo( CallInfo, pSession, *phContext );
  579. scRet = ValidateContextHandle(
  580. pSession,
  581. phContext,
  582. &ContextKey );
  583. if ( !NT_SUCCESS( scRet ) )
  584. {
  585. DsysAssert( (pSession->fSession & SESFLAG_KERNEL) == 0 );
  586. return( scRet );
  587. }
  588. pspPackage = SpmpValidRequest( phContext->dwLower,
  589. SP_ORDINAL_APPLYCONTROLTOKEN);
  590. if ( !pspPackage )
  591. {
  592. return SEC_E_INVALID_HANDLE ;
  593. }
  594. SetCurrentPackageId(phContext->dwLower);
  595. StartCallToPackage( pspPackage );
  596. __try
  597. {
  598. scRet = pspPackage->FunctionTable.ApplyControlToken(
  599. phContext->dwUpper,
  600. pInput);
  601. }
  602. __except (SP_EXCEPTION)
  603. {
  604. scRet = GetExceptionCode();
  605. scRet = SPException(scRet, pspPackage->dwPackageID);
  606. }
  607. EndCallToPackage( pspPackage );
  608. SetCurrentPackageId( SPMGR_ID );
  609. DerefContextHandle( pSession, NULL, ContextKey );
  610. return(scRet);
  611. }
  612. NTSTATUS
  613. WLsaQueryContextAttributes(
  614. PCtxtHandle phContext,
  615. ULONG ulAttribute,
  616. PVOID pvBuffer
  617. )
  618. {
  619. NTSTATUS scRet;
  620. PLSAP_SECURITY_PACKAGE pspPackage = NULL ;
  621. PSession pSession = GetCurrentSession();
  622. PLSA_CALL_INFO CallInfo = LsapGetCurrentCall();
  623. PVOID ContextKey ;
  624. DebugLog((DEB_TRACE_WAPI, "[%x] WLsaQueryContextAttributes(%p : %p)\n",
  625. pSession->dwProcessID,
  626. phContext->dwUpper, phContext->dwLower));
  627. LsapLogCallInfo( CallInfo, pSession, *phContext );
  628. scRet = ValidateContextHandle(
  629. pSession,
  630. phContext,
  631. &ContextKey );
  632. if ( NT_SUCCESS( scRet ) )
  633. {
  634. pspPackage = SpmpValidRequest( phContext->dwLower,
  635. SP_ORDINAL_QUERYCONTEXTATTRIBUTES);
  636. }
  637. if (( !pspPackage ) ||
  638. !NT_SUCCESS( scRet ) )
  639. {
  640. DsysAssert( (pSession->fSession & SESFLAG_KERNEL) == 0 );
  641. return(SEC_E_INVALID_HANDLE);
  642. }
  643. StartCallToPackage( pspPackage );
  644. SetCurrentPackageId(phContext->dwLower);
  645. __try
  646. {
  647. scRet = pspPackage->FunctionTable.QueryContextAttributes(
  648. phContext->dwUpper,
  649. ulAttribute,
  650. pvBuffer );
  651. }
  652. __except (SP_EXCEPTION)
  653. {
  654. scRet = GetExceptionCode();
  655. scRet = SPException(scRet, pspPackage->dwPackageID);
  656. }
  657. EndCallToPackage( pspPackage );
  658. SetCurrentPackageId( SPMGR_ID );
  659. DerefContextHandle( pSession, NULL, ContextKey );
  660. return(scRet);
  661. }
  662. NTSTATUS
  663. WLsaSetContextAttributes(
  664. PCtxtHandle phContext,
  665. ULONG ulAttribute,
  666. PVOID pvBuffer,
  667. ULONG cbBuffer
  668. )
  669. {
  670. NTSTATUS scRet;
  671. PLSAP_SECURITY_PACKAGE pspPackage = NULL ;
  672. PSession pSession = GetCurrentSession();
  673. PLSA_CALL_INFO CallInfo = LsapGetCurrentCall();
  674. PVOID ContextKey ;
  675. DebugLog((DEB_TRACE_WAPI, "[%x] WLsaSetContextAttributes(%p : %p)\n",
  676. pSession->dwProcessID,
  677. phContext->dwUpper, phContext->dwLower));
  678. LsapLogCallInfo( CallInfo, pSession, *phContext );
  679. scRet = ValidateContextHandle(
  680. pSession,
  681. phContext,
  682. &ContextKey );
  683. if ( NT_SUCCESS( scRet ) )
  684. {
  685. pspPackage = SpmpValidRequest( phContext->dwLower,
  686. SP_ORDINAL_SETCONTEXTATTRIBUTES);
  687. }
  688. if (( !pspPackage ) ||
  689. !NT_SUCCESS( scRet ) )
  690. {
  691. DsysAssert( (pSession->fSession & SESFLAG_KERNEL) == 0 );
  692. return(SEC_E_INVALID_HANDLE);
  693. }
  694. StartCallToPackage( pspPackage );
  695. SetCurrentPackageId(phContext->dwLower);
  696. __try
  697. {
  698. scRet = pspPackage->FunctionTable.SetContextAttributes(
  699. phContext->dwUpper,
  700. ulAttribute,
  701. pvBuffer,
  702. cbBuffer );
  703. }
  704. __except (SP_EXCEPTION)
  705. {
  706. scRet = GetExceptionCode();
  707. scRet = SPException(scRet, pspPackage->dwPackageID);
  708. }
  709. EndCallToPackage( pspPackage );
  710. SetCurrentPackageId( SPMGR_ID );
  711. DerefContextHandle( pSession, NULL, ContextKey );
  712. return(scRet);
  713. }