Source code of Windows XP (NT5)
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.

193 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. stub.c
  5. Abstract:
  6. NT LM Security Support Provider client stubs.
  7. Author:
  8. Cliff Van Dyke (CliffV) 29-Jun-1993
  9. Environment: User Mode
  10. Revision History:
  11. --*/
  12. #ifdef BLDR_KERNEL_RUNTIME
  13. #include <bootdefs.h>
  14. #endif
  15. #include <stddef.h>
  16. #include <security.h>
  17. #include <ntlmsspi.h>
  18. #include <crypt.h>
  19. #include <cred.h>
  20. #include <debug.h>
  21. PSSP_CREDENTIAL
  22. SspCredentialAllocateCredential(
  23. IN ULONG CredentialUseFlags
  24. )
  25. {
  26. PSSP_CREDENTIAL Credential;
  27. //
  28. // Allocate a credential block and initialize it.
  29. //
  30. Credential = (PSSP_CREDENTIAL) SspAlloc (sizeof(SSP_CREDENTIAL));
  31. if ( Credential == NULL ) {
  32. return (NULL);
  33. }
  34. Credential->References = 1;
  35. Credential->CredentialUseFlags = CredentialUseFlags;
  36. Credential->Username = NULL;
  37. Credential->Domain = NULL;
  38. SspPrint(( SSP_API_MORE, "Added Credential 0x%lx\n", Credential ));
  39. return (Credential);
  40. }
  41. PSSP_CREDENTIAL
  42. SspCredentialReferenceCredential(
  43. IN PCredHandle CredentialHandle,
  44. IN BOOLEAN RemoveCredential
  45. )
  46. /*++
  47. Routine Description:
  48. This routine checks to see if the Credential is from a currently
  49. active client, and references the Credential if it is valid.
  50. The caller may optionally request that the client's Credential be
  51. removed from the list of valid Credentials - preventing future
  52. requests from finding this Credential.
  53. For a client's Credential to be valid, the Credential value
  54. must be on our list of active Credentials.
  55. Arguments:
  56. CredentialHandle - Points to the CredentialHandle of the Credential
  57. to be referenced.
  58. RemoveCredential - This boolean value indicates whether the caller
  59. wants the logon process's Credential to be removed from the list
  60. of Credentials. TRUE indicates the Credential is to be removed.
  61. FALSE indicates the Credential is not to be removed.
  62. Return Value:
  63. NULL - the Credential was not found.
  64. Otherwise - returns a pointer to the referenced credential.
  65. --*/
  66. {
  67. PSSP_CREDENTIAL Credential;
  68. //
  69. // Sanity check
  70. //
  71. if ( CredentialHandle->dwLower != 0 ) {
  72. return NULL;
  73. }
  74. Credential = (SSP_CREDENTIAL *) CredentialHandle->dwUpper;
  75. Credential->References++;
  76. return Credential;
  77. }
  78. void
  79. SspCredentialDereferenceCredential(
  80. PSSP_CREDENTIAL Credential
  81. )
  82. /*++
  83. Routine Description:
  84. This routine decrements the specified Credential's reference count.
  85. If the reference count drops to zero, then the Credential is deleted
  86. Arguments:
  87. Credential - Points to the Credential to be dereferenced.
  88. Return Value:
  89. None.
  90. --*/
  91. {
  92. ASSERT(Credential != NULL);
  93. //
  94. // Decrement the reference count
  95. //
  96. ASSERT( Credential->References >= 1 );
  97. Credential->References--;
  98. //
  99. // If the count dropped to zero, then run-down the Credential
  100. //
  101. if ( Credential->References == 0) {
  102. SspPrint(( SSP_API_MORE, "Deleting Credential 0x%lx\n",
  103. Credential ));
  104. #ifdef BL_USE_LM_PASSWORD
  105. if (Credential->LmPassword != NULL) {
  106. SspFree(Credential->LmPassword);
  107. }
  108. #endif
  109. if (Credential->NtPassword != NULL) {
  110. SspFree(Credential->NtPassword);
  111. }
  112. if (Credential->Username != NULL) {
  113. SspFree(Credential->Username);
  114. }
  115. if (Credential->Domain != NULL) {
  116. SspFree(Credential->Domain);
  117. }
  118. if (Credential->Workstation != NULL) {
  119. SspFree(Credential->Workstation);
  120. }
  121. SspFree( Credential );
  122. }
  123. return;
  124. }