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.

1118 lines
29 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. credapi.c
  5. Abstract:
  6. Credential Manager RPC API Interfaces
  7. Author:
  8. Cliff Van Dyke (CliffV)
  9. Environment:
  10. Revision History:
  11. --*/
  12. #include <lsapch2.h>
  13. #include <credp.hxx>
  14. #include <windns.h>
  15. NTSTATUS
  16. CrediGetLogonId(
  17. OUT PLUID LogonId
  18. )
  19. /*++
  20. Routine Description:
  21. This routine impersonates the client then gets the logon id from the impersonated token.
  22. This routine also checks to ensure the user sid isn't restricted.
  23. On successful return, we are still imperonating the client. The caller should call
  24. RpcRevertToSelf();
  25. Arguments:
  26. LogonId - Returns the logon ID.
  27. Return Value:
  28. Status of the operation.
  29. --*/
  30. {
  31. NTSTATUS Status;
  32. //
  33. // Impersonate
  34. //
  35. Status = I_RpcMapWin32Status( RpcImpersonateClient( 0 ) );
  36. if ( NT_SUCCESS(Status) ) {
  37. HANDLE ClientToken;
  38. //
  39. // Open the token
  40. //
  41. Status = NtOpenThreadToken( NtCurrentThread(),
  42. TOKEN_QUERY,
  43. TRUE,
  44. &ClientToken );
  45. if ( NT_SUCCESS( Status ) ) {
  46. TOKEN_STATISTICS TokenStats;
  47. ULONG ReturnedSize;
  48. //
  49. // Get the LogonId
  50. //
  51. Status = NtQueryInformationToken( ClientToken,
  52. TokenStatistics,
  53. &TokenStats,
  54. sizeof( TokenStats ),
  55. &ReturnedSize );
  56. if ( NT_SUCCESS( Status ) ) {
  57. //
  58. // Save the logon id
  59. //
  60. *LogonId = TokenStats.AuthenticationId;
  61. //
  62. // Get the user sid
  63. //
  64. Status = NtQueryInformationToken (
  65. ClientToken,
  66. TokenUser,
  67. NULL,
  68. 0,
  69. &ReturnedSize );
  70. if ( Status == STATUS_BUFFER_TOO_SMALL ) {
  71. PTOKEN_USER UserSid;
  72. UserSid = LsapAllocateLsaHeap( ReturnedSize );
  73. if ( UserSid == NULL ) {
  74. Status = STATUS_NO_MEMORY;
  75. } else {
  76. Status = NtQueryInformationToken (
  77. ClientToken,
  78. TokenUser,
  79. UserSid,
  80. ReturnedSize,
  81. &ReturnedSize );
  82. if ( NT_SUCCESS( Status )) {
  83. BOOL IsMember;
  84. //
  85. // Ensure the user sid isn't restricted.
  86. //
  87. if ( !CheckTokenMembership( ClientToken,
  88. UserSid->User.Sid,
  89. &IsMember ) ) {
  90. Status = I_RpcMapWin32Status( GetLastError() );
  91. } else {
  92. //
  93. // If not, fail
  94. //
  95. if ( !IsMember ) {
  96. Status = STATUS_ACCESS_DENIED;
  97. } else {
  98. BOOLEAN IsNetworkClient;
  99. //
  100. // Don't allow the caller to have come in from the network.
  101. //
  102. Status = LsapDbIsRpcClientNetworkClient( &IsNetworkClient );
  103. if ( NT_SUCCESS(Status ) ) {
  104. if ( IsNetworkClient ) {
  105. Status = STATUS_ACCESS_DENIED;
  106. } else {
  107. Status = STATUS_SUCCESS;
  108. }
  109. }
  110. }
  111. }
  112. }
  113. LsapFreeLsaHeap( UserSid );
  114. }
  115. }
  116. }
  117. NtClose( ClientToken );
  118. }
  119. if ( !NT_SUCCESS(Status) ) {
  120. RpcRevertToSelf();
  121. }
  122. }
  123. return Status;
  124. }
  125. NTSTATUS
  126. CredrWrite(
  127. IN LPWSTR ServerName,
  128. IN PENCRYPTED_CREDENTIALW Credential,
  129. IN ULONG Flags
  130. )
  131. /*++
  132. Routine Description:
  133. The CredWrite API creates a new credential or modifies an existing
  134. credential in the user's credential set. The new credential is
  135. associated with the logon session of the current token. The token
  136. must not have the user's SID disabled.
  137. The CredWrite API creates a credential if none already exists by the
  138. specified TargetName. If the specified TargetName already exists, the
  139. specified credential replaces the existing one.
  140. Arguments:
  141. ServerName - Name of server this APi was remoted to.
  142. Must be NULL.
  143. Credential - Specifies the credential to be written.
  144. Flags - Specifies flags to control the operation of the API.
  145. The following flags are defined:
  146. CRED_PRESERVE_CREDENTIAL_BLOB: The credential blob should be preserved from the
  147. already existing credential with the same credential name and credential type.
  148. Return Values:
  149. The following status codes may be returned:
  150. STATUS_NO_SUCH_LOGON_SESSION - The logon session does not exist or
  151. there is no credential set associated with this logon session.
  152. Network logon sessions do not have an associated credential set.
  153. STATUS_INVALID_PARAMETER - Certain fields may not be changed in an
  154. existing credential. If such a field does not match the value
  155. specified in the existing credential, this error is returned.
  156. STATUS_NOT_FOUND - There is no credential with the specified TargetName.
  157. Returned only if CRED_PRESERVE_CREDENTIAL_BLOB was specified.
  158. --*/
  159. {
  160. NTSTATUS Status;
  161. LUID LogonId;
  162. //
  163. // Ensure this is a local call.
  164. //
  165. if ( ServerName != NULL ) {
  166. Status = STATUS_INVALID_COMPUTER_NAME;
  167. goto Cleanup;
  168. }
  169. //
  170. // Get the LogonId for the caller.
  171. //
  172. Status = CrediGetLogonId( &LogonId );
  173. if ( !NT_SUCCESS(Status) ) {
  174. goto Cleanup;
  175. }
  176. //
  177. // Call the internal routine
  178. //
  179. Status = CrediWrite( &LogonId,
  180. CREDP_FLAGS_USER_ENCRYPTED_PASSWORD,
  181. Credential,
  182. Flags );
  183. RpcRevertToSelf();
  184. //
  185. // Cleanup
  186. //
  187. Cleanup:
  188. return Status;
  189. }
  190. NTSTATUS
  191. CredrRead (
  192. IN LPWSTR ServerName,
  193. IN LPWSTR TargetName,
  194. IN ULONG Type,
  195. IN ULONG Flags,
  196. OUT PENCRYPTED_CREDENTIALW *Credential
  197. )
  198. /*++
  199. Routine Description:
  200. The CredRead API reads a credential from the user's credential set.
  201. The credential set used is the one associated with the logon session
  202. of the current token. The token must not have the user's SID disabled.
  203. Arguments:
  204. ServerName - Name of server this APi was remoted to.
  205. Must be NULL.
  206. TargetName - Specifies the name of the credential to read.
  207. Type - Specifies the Type of the credential to find.
  208. One of the CRED_TYPE_* values should be specified.
  209. Flags - Specifies flags to control the operation of the API.
  210. Reserved. Must be zero.
  211. Credential - Returns a pointer to the credential. The returned buffer
  212. must be freed by calling CredFree.
  213. Return Values:
  214. The following status codes may be returned:
  215. STATUS_NOT_FOUND - There is no credential with the specified TargetName.
  216. STATUS_NO_SUCH_LOGON_SESSION - The logon session does not exist or
  217. there is no credential set associated with this logon session.
  218. Network logon sessions do not have an associated credential set.
  219. --*/
  220. {
  221. NTSTATUS Status;
  222. LUID LogonId;
  223. //
  224. // Ensure this is a local call.
  225. //
  226. if ( ServerName != NULL ) {
  227. Status = STATUS_INVALID_COMPUTER_NAME;
  228. goto Cleanup;
  229. }
  230. //
  231. // Get the LogonId for the caller.
  232. //
  233. Status = CrediGetLogonId( &LogonId );
  234. if ( !NT_SUCCESS(Status) ) {
  235. goto Cleanup;
  236. }
  237. //
  238. // Call the internal routine
  239. //
  240. Status = CrediRead( &LogonId,
  241. CREDP_FLAGS_USE_MIDL_HEAP, // Use MIDL_user_allocate
  242. TargetName,
  243. Type,
  244. Flags,
  245. Credential );
  246. RpcRevertToSelf();
  247. //
  248. // Cleanup
  249. //
  250. Cleanup:
  251. return Status;
  252. }
  253. NTSTATUS
  254. CredrEnumerate (
  255. IN LPWSTR ServerName,
  256. IN LPWSTR Filter,
  257. IN ULONG Flags,
  258. OUT PCREDENTIAL_ARRAY CredentialArray
  259. )
  260. /*++
  261. Routine Description:
  262. The CredEnumerate API enumerates the credentials from the user's credential set.
  263. The credential set used is the one associated with the logon session
  264. of the current token. The token must not have the user's SID disabled.
  265. Arguments:
  266. ServerName - Name of server this APi was remoted to.
  267. Must be NULL.
  268. Filter - Specifies a filter for the returned credentials. Only credentials
  269. with a TargetName matching the filter will be returned. The filter specifies
  270. a name prefix followed by an asterisk. For instance, the filter "FRED*" will
  271. return all credentials with a TargetName beginning with the string "FRED".
  272. If NULL is specified, all credentials will be returned.
  273. Flags - Specifies flags to control the operation of the API.
  274. Reserved. Must be zero.
  275. Count - Returns a count of the number of credentials returned in Credentials.
  276. Credentials - Returns a pointer to an array of pointers to credentials.
  277. The returned buffer must be freed by calling CredFree.
  278. Return Values:
  279. On success, TRUE is returned. On failure, FALSE is returned.
  280. GetLastError() may be called to get a more specific status code.
  281. The following status codes may be returned:
  282. STATUS_NOT_FOUND - There is no credentials matching the specified Filter.
  283. STATUS_NO_SUCH_LOGON_SESSION - The logon session does not exist or
  284. there is no credential set associated with this logon session.
  285. Network logon sessions do not have an associated credential set.
  286. --*/
  287. {
  288. NTSTATUS Status;
  289. LUID LogonId;
  290. //
  291. // Ensure this is a local call.
  292. //
  293. if ( ServerName != NULL ) {
  294. Status = STATUS_INVALID_COMPUTER_NAME;
  295. goto Cleanup;
  296. }
  297. //
  298. // Validate the credential array.
  299. //
  300. if ( CredentialArray == NULL ||
  301. CredentialArray->CredentialCount != 0 ||
  302. CredentialArray->Credentials != NULL ) {
  303. Status = STATUS_INVALID_PARAMETER;
  304. goto Cleanup;
  305. }
  306. //
  307. // Get the LogonId for the caller.
  308. //
  309. Status = CrediGetLogonId( &LogonId );
  310. if ( !NT_SUCCESS(Status) ) {
  311. goto Cleanup;
  312. }
  313. //
  314. // Call the internal routine
  315. //
  316. Status = CrediEnumerate( &LogonId,
  317. 0,
  318. Filter,
  319. Flags,
  320. &CredentialArray->CredentialCount,
  321. &CredentialArray->Credentials );
  322. RpcRevertToSelf();
  323. //
  324. // Cleanup
  325. //
  326. Cleanup:
  327. return Status;
  328. }
  329. NTSTATUS
  330. CredrWriteDomainCredentials (
  331. IN LPWSTR ServerName,
  332. IN PCREDENTIAL_TARGET_INFORMATIONW TargetInfo,
  333. IN PENCRYPTED_CREDENTIALW Credential,
  334. IN ULONG Flags
  335. )
  336. /*++
  337. Routine Description:
  338. The CredWriteDomainCredentials API writes a new domain
  339. credential to the user's credential set. The new credential is
  340. associated with the logon session of the current token. The token
  341. must not have the user's SID disabled.
  342. CredWriteDomainCredentials differs from CredWrite in that it handles
  343. the idiosyncrasies of domain (CRED_TYPE_DOMAIN_PASSWORD or CRED_TYPE_DOMAIN_CERTIFICATE)
  344. credentials. Domain credentials contain more than one target field.
  345. At least one of the naming parameters must be specified: NetbiosServerName,
  346. DnsServerName, NetbiosDomainName, DnsDomainName or DnsForestName.
  347. Arguments:
  348. ServerName - Name of server this APi was remoted to.
  349. Must be NULL.
  350. TargetInfo - Specifies the target information identifying the target server.
  351. Credential - Specifies the credential to be written.
  352. Flags - Specifies flags to control the operation of the API.
  353. Reserved. Must be zero.
  354. Return Values:
  355. The following status codes may be returned:
  356. STATUS_NO_SUCH_LOGON_SESSION - The logon session does not exist or
  357. there is no credential set associated with this logon session.
  358. Network logon sessions do not have an associated credential set.
  359. STATUS_INVALID_PARAMETER - Certain fields may not be changed in an
  360. existing credential. If such a field does not match the value
  361. specified in the existing credential, this error is returned.
  362. STATUS_INVALID_PARAMETER - None of the naming parameters were specified
  363. or the credential specified did not have the Type field set to
  364. CRED_TYPE_DOMAIN_PASSWORD or CRED_TYPE_DOMAIN_CERTIFICATE.
  365. --*/
  366. {
  367. NTSTATUS Status;
  368. LUID LogonId;
  369. //
  370. // Ensure this is a local call.
  371. //
  372. if ( ServerName != NULL ) {
  373. Status = STATUS_INVALID_COMPUTER_NAME;
  374. goto Cleanup;
  375. }
  376. //
  377. // Get the LogonId for the caller.
  378. //
  379. Status = CrediGetLogonId( &LogonId );
  380. if ( !NT_SUCCESS(Status) ) {
  381. goto Cleanup;
  382. }
  383. //
  384. // Call the internal routine
  385. //
  386. Status = CrediWriteDomainCredentials( &LogonId,
  387. CREDP_FLAGS_USER_ENCRYPTED_PASSWORD,
  388. TargetInfo,
  389. Credential,
  390. Flags );
  391. RpcRevertToSelf();
  392. //
  393. // Cleanup
  394. //
  395. Cleanup:
  396. return Status;
  397. }
  398. NTSTATUS
  399. CredrReadDomainCredentials (
  400. IN LPWSTR ServerName,
  401. IN PCREDENTIAL_TARGET_INFORMATIONW TargetInfo,
  402. IN ULONG Flags,
  403. OUT PCREDENTIAL_ARRAY CredentialArray
  404. )
  405. /*++
  406. Routine Description:
  407. The CredReadDomainCredentials API reads the domain credentials from the user's credential set.
  408. The credential set used is the one associated with the logon session
  409. of the current token. The token must not have the user's SID disabled.
  410. CredReadDomainCredentials differs from CredRead in that it handles the
  411. idiosyncrasies of domain (CRED_TYPE_DOMAIN_PASSWORD or CRED_TYPE_DOMAIN_CERTIFICATE)
  412. credentials. Domain credentials contain more than one target field.
  413. At least one of the naming parameters must be specified: NetbiosServerName,
  414. DnsServerName, NetbiosDomainName, DnsDomainName or DnsForestName. This API returns
  415. the most specific credentials that match the naming parameters. That is, if there
  416. is a credential that matches the target server name and a credential that matches
  417. the target domain name, only the server specific credential is returned. This is
  418. the credential that would be used.
  419. Arguments:
  420. ServerName - Name of server this APi was remoted to.
  421. Must be NULL.
  422. TargetInfo - Specifies the target information identifying the target ser
  423. Flags - Specifies flags to control the operation of the API.
  424. The following flags are defined:
  425. CRED_CACHE_TARGET_INFORMATION: The TargetInfo should be cached for a subsequent read via
  426. CredGetTargetInfo.
  427. Count - Returns a count of the number of credentials returned in Credentials.
  428. Credentials - Returns a pointer to an array of pointers to credentials.
  429. The most specific existing credential matching the TargetInfo is returned.
  430. If there is both a CRED_TYPE_DOMAIN_PASSWORD and CRED_TYPE_DOMAIN_CERTIFICATE
  431. credential, both are returned. If a connection were to be made to the named
  432. target, this most-specific credential would be used.
  433. The returned buffer must be freed by calling CredFree.
  434. Return Values:
  435. The following status codes may be returned:
  436. STATUS_INVALID_PARAMETER - None of the naming parameters were specified.
  437. STATUS_NOT_FOUND - There are no credentials matching the specified naming parameters.
  438. STATUS_NO_SUCH_LOGON_SESSION - The logon session does not exist or
  439. there is no credential set associated with this logon session.
  440. Network logon sessions do not have an associated credential set.
  441. --*/
  442. {
  443. NTSTATUS Status;
  444. LUID LogonId;
  445. ULONG CredFlags = 0;
  446. //
  447. // Ensure this is a local call.
  448. //
  449. if ( ServerName != NULL ) {
  450. Status = STATUS_INVALID_COMPUTER_NAME;
  451. goto Cleanup;
  452. }
  453. //
  454. // Validate the credential array.
  455. //
  456. if ( CredentialArray == NULL ||
  457. CredentialArray->CredentialCount != 0 ||
  458. CredentialArray->Credentials != NULL ) {
  459. Status = STATUS_INVALID_PARAMETER;
  460. goto Cleanup;
  461. }
  462. //
  463. // Get the LogonId for the caller.
  464. //
  465. Status = CrediGetLogonId( &LogonId );
  466. if ( !NT_SUCCESS(Status) ) {
  467. goto Cleanup;
  468. }
  469. //
  470. // Handle caching target info.
  471. //
  472. // The Credi* routine caches by default and has to be asked to not cache.
  473. // Whereas the public API doesn't cache by default.
  474. //
  475. if ( Flags & CRED_CACHE_TARGET_INFORMATION ) {
  476. Flags &= ~CRED_CACHE_TARGET_INFORMATION;
  477. } else {
  478. CredFlags |= CREDP_FLAGS_DONT_CACHE_TI;
  479. }
  480. //
  481. // Call the internal routine
  482. //
  483. Status = CrediReadDomainCredentials(
  484. &LogonId,
  485. CredFlags,
  486. TargetInfo,
  487. Flags,
  488. &CredentialArray->CredentialCount,
  489. &CredentialArray->Credentials );
  490. RpcRevertToSelf();
  491. //
  492. // Cleanup
  493. //
  494. Cleanup:
  495. return Status;
  496. }
  497. NTSTATUS
  498. CredrDelete (
  499. IN LPWSTR ServerName,
  500. IN LPWSTR TargetName,
  501. IN ULONG Type,
  502. IN ULONG Flags
  503. )
  504. /*++
  505. Routine Description:
  506. The CredDelete API deletes a credential from the user's credential set.
  507. The credential set used is the one associated with the logon session
  508. of the current token. The token must not have the user's SID disabled.
  509. Arguments:
  510. ServerName - Name of server this APi was remoted to.
  511. Must be NULL.
  512. TargetName - Specifies the name of the credential to delete.
  513. Type - Specifies the Type of the credential to find.
  514. One of the CRED_TYPE_* values should be specified.
  515. Flags - Specifies flags to control the operation of the API.
  516. Reserved. Must be zero.
  517. Return Values:
  518. The following status codes may be returned:
  519. STATUS_NOT_FOUND - There is no credential with the specified TargetName.
  520. STATUS_NO_SUCH_LOGON_SESSION - The logon session does not exist or
  521. there is no credential set associated with this logon session.
  522. Network logon sessions do not have an associated credential set.
  523. --*/
  524. {
  525. NTSTATUS Status;
  526. LUID LogonId;
  527. //
  528. // Ensure this is a local call.
  529. //
  530. if ( ServerName != NULL ) {
  531. Status = STATUS_INVALID_COMPUTER_NAME;
  532. goto Cleanup;
  533. }
  534. //
  535. // Get the LogonId for the caller.
  536. //
  537. Status = CrediGetLogonId( &LogonId );
  538. if ( !NT_SUCCESS(Status) ) {
  539. goto Cleanup;
  540. }
  541. //
  542. // Call the internal routine
  543. //
  544. Status = CrediDelete( &LogonId,
  545. 0,
  546. TargetName,
  547. Type,
  548. Flags );
  549. RpcRevertToSelf();
  550. //
  551. // Cleanup
  552. //
  553. Cleanup:
  554. return Status;
  555. }
  556. NTSTATUS
  557. CredrRename (
  558. IN LPWSTR ServerName,
  559. IN LPWSTR OldTargetName,
  560. IN LPWSTR NewTargetName,
  561. IN ULONG Type,
  562. IN ULONG Flags
  563. )
  564. /*++
  565. Routine Description:
  566. The CredRename API renames a credential in the user's credential set.
  567. The credential set used is the one associated with the logon session
  568. of the current token. The token must not have the user's SID disabled.
  569. Arguments:
  570. ServerName - Name of server this APi was remoted to.
  571. Must be NULL.
  572. OldTargetName - Specifies the current name of the credential to rename.
  573. NewTargetName - Specifies the new name of the credential.
  574. Type - Specifies the Type of the credential to rename
  575. One of the CRED_TYPE_* values should be specified.
  576. Flags - Specifies flags to control the operation of the API.
  577. Reserved. Must be zero.
  578. Return Values:
  579. The following status codes may be returned:
  580. STATUS_NOT_FOUND - There is no credential with the specified OldTargetName.
  581. STATUS_OBJECT_NAME_COLLISION - There is already a credential named NewTargetName.
  582. STATUS_NO_SUCH_LOGON_SESSION - The logon session does not exist or
  583. there is no credential set associated with this logon session.
  584. Network logon sessions do not have an associated credential set.
  585. --*/
  586. {
  587. NTSTATUS Status;
  588. LUID LogonId;
  589. //
  590. // Ensure this is a local call.
  591. //
  592. if ( ServerName != NULL ) {
  593. Status = STATUS_INVALID_COMPUTER_NAME;
  594. goto Cleanup;
  595. }
  596. //
  597. // Get the LogonId for the caller.
  598. //
  599. Status = CrediGetLogonId( &LogonId );
  600. if ( !NT_SUCCESS(Status) ) {
  601. goto Cleanup;
  602. }
  603. //
  604. // Call the internal routine
  605. //
  606. Status = CrediRename( &LogonId,
  607. OldTargetName,
  608. NewTargetName,
  609. Type,
  610. Flags );
  611. RpcRevertToSelf();
  612. //
  613. // Cleanup
  614. //
  615. Cleanup:
  616. return Status;
  617. }
  618. NTSTATUS
  619. CredrGetTargetInfo (
  620. IN LPWSTR ServerName,
  621. IN LPWSTR TargetServerName,
  622. IN ULONG Flags,
  623. OUT PCREDENTIAL_TARGET_INFORMATIONW *TargetInfo
  624. )
  625. /*++
  626. Routine Description:
  627. The CredGetTargetInfo API gets all of the known target name information
  628. for the named target machine. This executed locally
  629. and does not need any particular privilege. The information returned is expected
  630. to be passed to the CredReadDomainCredentials and CredWriteDomainCredentials APIs.
  631. The information should not be used for any other purpose.
  632. Authentication packages compute TargetInfo when attempting to authenticate to
  633. ServerName. The authentication packages cache this target information to make it
  634. available to CredGetTargetInfo. Therefore, the target information will only be
  635. available if we've recently attempted to authenticate to ServerName.
  636. Arguments:
  637. ServerName - Name of server this APi was remoted to.
  638. Must be NULL.
  639. TargetServerName - This parameter specifies the name of the machine to get the information
  640. for.
  641. Flags - Specifies flags to control the operation of the API.
  642. CRED_ALLOW_NAME_RESOLUTION - Specifies that if no target info can be found for
  643. TargetName, then name resolution should be done on TargetName to convert it
  644. to other forms. If target info exists for any of those other forms, that
  645. target info is returned. Currently only DNS name resolution is done.
  646. This bit is useful if the application doesn't call the authentication package
  647. directly. The application might pass the TargetName to another layer of software
  648. to authenticate to the server. That layer of software might resolve the name and
  649. pass the resolved name to the authentication package. As such, there will be no
  650. target info for the original TargetName.
  651. TargetInfo - Returns a pointer to the target information.
  652. At least one of the returned fields of TargetInfo will be non-NULL.
  653. Return Values:
  654. The following status codes may be returned:
  655. STATUS_NO_MEMORY - There isn't enough memory to complete the operation.
  656. STATUS_NOT_FOUND - There is no credential with the specified TargetName.
  657. --*/
  658. {
  659. NTSTATUS Status;
  660. LUID LogonId;
  661. //
  662. // Ensure this is a local call.
  663. //
  664. if ( ServerName != NULL ) {
  665. return STATUS_INVALID_COMPUTER_NAME;
  666. }
  667. //
  668. // Get the LogonId for the caller.
  669. //
  670. Status = CrediGetLogonId( &LogonId );
  671. if ( !NT_SUCCESS(Status) ) {
  672. goto Cleanup;
  673. }
  674. //
  675. // Call the internal routine
  676. //
  677. Status = CrediGetTargetInfo( &LogonId, TargetServerName, Flags, TargetInfo );
  678. RpcRevertToSelf();
  679. //
  680. // Cleanup
  681. //
  682. Cleanup:
  683. return Status;
  684. }
  685. NTSTATUS
  686. CredrGetSessionTypes (
  687. IN LPWSTR ServerName,
  688. IN DWORD MaximumPersistCount,
  689. OUT LPDWORD MaximumPersist
  690. )
  691. /*++
  692. Routine Description:
  693. CredGetSessionTypes returns the maximum persistence supported by the current logon
  694. session.
  695. For whistler, CRED_PERSIST_LOCAL_MACHINE and CRED_PERSIST_ENTERPRISE credentials can not
  696. be stored for sessions where the profile is not loaded. If future releases, credentials
  697. might not be associated with the user's profile.
  698. Arguments:
  699. ServerName - Name of server this APi was remoted to.
  700. Must be NULL.
  701. MaximumPersistCount - Specifies the number of elements in the MaximumPersist array.
  702. The caller should specify CRED_TYPE_MAXIMUM for this parameter.
  703. MaximumPersist - Returns the maximum persistance supported by the current logon session for
  704. each credential type. Index into the array with one of the CRED_TYPE_* defines.
  705. Returns CRED_PERSIST_NONE if no credential of this type can be stored.
  706. Returns CRED_PERSIST_SESSION if only session specific credential may be stored.
  707. Returns CRED_PERSIST_LOCAL_MACHINE if session specific and machine specific credentials
  708. may be stored.
  709. Returns CRED_PERSIST_ENTERPRISE if any credential may be stored.
  710. Return Values:
  711. STATUS_NO_SUCH_LOGON_SESSION - The logon session does not exist or
  712. there is no credential set associated with this logon session.
  713. Network logon sessions do not have an associated credential set.
  714. --*/
  715. {
  716. NTSTATUS Status;
  717. LUID LogonId;
  718. //
  719. // Ensure this is a local call.
  720. //
  721. if ( ServerName != NULL ) {
  722. Status = STATUS_INVALID_COMPUTER_NAME;
  723. goto Cleanup;
  724. }
  725. //
  726. // Get the LogonId for the caller.
  727. //
  728. Status = CrediGetLogonId( &LogonId );
  729. if ( !NT_SUCCESS(Status) ) {
  730. goto Cleanup;
  731. }
  732. //
  733. // Call the internal routine
  734. //
  735. Status = CrediGetSessionTypes( &LogonId, MaximumPersistCount, MaximumPersist );
  736. RpcRevertToSelf();
  737. //
  738. // Cleanup
  739. //
  740. Cleanup:
  741. return Status;
  742. }
  743. NTSTATUS
  744. CredrProfileLoaded (
  745. IN LPWSTR ServerName
  746. )
  747. /*++
  748. Routine Description:
  749. The CredProfileLoaded API is a private API used by LoadUserProfile to notify the
  750. credential manager that the profile for the current user has been loaded.
  751. The caller must be impersonating the logged on user.
  752. Arguments:
  753. ServerName - Name of server this APi was remoted to.
  754. Must be NULL.
  755. Return Values:
  756. The following status codes may be returned:
  757. STATUS_NO_SUCH_LOGON_SESSION - The logon session does not exist or
  758. there is no credential set associated with this logon session.
  759. Network logon sessions do not have an associated credential set.
  760. --*/
  761. {
  762. NTSTATUS Status;
  763. LUID LogonId;
  764. //
  765. // Ensure this is a local call.
  766. //
  767. if ( ServerName != NULL ) {
  768. Status = STATUS_INVALID_COMPUTER_NAME;
  769. goto Cleanup;
  770. }
  771. //
  772. // Get the LogonId for the caller.
  773. //
  774. Status = CrediGetLogonId( &LogonId );
  775. if ( !NT_SUCCESS(Status) ) {
  776. //
  777. // This is a notification API. Don't bother the caller with trivia.
  778. // This might be a network token. Network tokens don't have credentials.
  779. //
  780. if ( Status == STATUS_ACCESS_DENIED ) {
  781. Status = STATUS_SUCCESS;
  782. }
  783. goto Cleanup;
  784. }
  785. //
  786. // Call the internal routine
  787. //
  788. Status = CrediProfileLoaded( &LogonId );
  789. RpcRevertToSelf();
  790. //
  791. // Cleanup
  792. //
  793. Cleanup:
  794. return Status;
  795. }