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.

200 lines
4.2 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. _fmemset(Credential, 0, sizeof(SSP_CREDENTIAL));
  35. Credential->References = 1;
  36. Credential->CredentialUseFlags = CredentialUseFlags;
  37. Credential->Username = NULL;
  38. Credential->Domain = NULL;
  39. SspPrint(( SSP_API_MORE, "Added Credential 0x%lx\n", Credential ));
  40. return (Credential);
  41. }
  42. PSSP_CREDENTIAL
  43. SspCredentialReferenceCredential(
  44. IN PCredHandle CredentialHandle,
  45. IN BOOLEAN RemoveCredential
  46. )
  47. /*++
  48. Routine Description:
  49. This routine checks to see if the Credential is from a currently
  50. active client, and references the Credential if it is valid.
  51. The caller may optionally request that the client's Credential be
  52. removed from the list of valid Credentials - preventing future
  53. requests from finding this Credential.
  54. For a client's Credential to be valid, the Credential value
  55. must be on our list of active Credentials.
  56. Arguments:
  57. CredentialHandle - Points to the CredentialHandle of the Credential
  58. to be referenced.
  59. RemoveCredential - This boolean value indicates whether the caller
  60. wants the logon process's Credential to be removed from the list
  61. of Credentials. TRUE indicates the Credential is to be removed.
  62. FALSE indicates the Credential is not to be removed.
  63. Return Value:
  64. NULL - the Credential was not found.
  65. Otherwise - returns a pointer to the referenced credential.
  66. --*/
  67. {
  68. PSSP_CREDENTIAL Credential;
  69. //
  70. // Sanity check
  71. //
  72. if ( CredentialHandle->dwLower != 0 ) {
  73. return NULL;
  74. }
  75. Credential = (SSP_CREDENTIAL *) CredentialHandle->dwUpper;
  76. Credential->References++;
  77. return Credential;
  78. }
  79. void
  80. SspCredentialDereferenceCredential(
  81. PSSP_CREDENTIAL Credential
  82. )
  83. /*++
  84. Routine Description:
  85. This routine decrements the specified Credential's reference count.
  86. If the reference count drops to zero, then the Credential is deleted
  87. Arguments:
  88. Credential - Points to the Credential to be dereferenced.
  89. Return Value:
  90. None.
  91. --*/
  92. {
  93. ASSERT(Credential != NULL);
  94. //
  95. // Decrement the reference count
  96. //
  97. ASSERT( Credential->References >= 1 );
  98. Credential->References--;
  99. //
  100. // If the count dropped to zero, then run-down the Credential
  101. //
  102. if ( Credential->References == 0) {
  103. SspPrint(( SSP_API_MORE, "Deleting Credential 0x%lx\n",
  104. Credential ));
  105. #ifdef BL_USE_LM_PASSWORD
  106. if (Credential->LmPassword != NULL) {
  107. SspFree(Credential->LmPassword);
  108. }
  109. #endif
  110. if (Credential->NtPassword != NULL) {
  111. _fmemset(Credential->NtPassword, 0, sizeof(NT_OWF_PASSWORD));
  112. SspFree(Credential->NtPassword);
  113. }
  114. if (Credential->Username != NULL) {
  115. _fmemset(Credential->Username, 0, _fstrlen(Credential->Username));
  116. SspFree(Credential->Username);
  117. }
  118. if (Credential->Domain != NULL) {
  119. _fmemset(Credential->Domain, 0, _fstrlen(Credential->Domain));
  120. SspFree(Credential->Domain);
  121. }
  122. if (Credential->Workstation != NULL) {
  123. _fmemset(Credential->Workstation, 0, _fstrlen(Credential->Workstation));
  124. SspFree(Credential->Workstation);
  125. }
  126. _fmemset(Credential, 0, sizeof(SSP_CREDENTIAL));
  127. SspFree( Credential );
  128. }
  129. return;
  130. }