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.

157 lines
3.1 KiB

  1. /* Copyright (c) 1993, Microsoft Corporation, all rights reserved
  2. **
  3. ** slsa.c
  4. ** Server-side LSA Authentication Utilities
  5. **
  6. ** 11/10/93 MikeSa Pulled from NT 3.1 RAS authentication.
  7. ** 11/12/93 SteveC Do clear-text authentication when Challenge is NULL
  8. */
  9. #define UNICODE
  10. #include <nt.h>
  11. #include <ntrtl.h>
  12. #include <nturtl.h>
  13. #include <ntlsa.h>
  14. #include <ntmsv1_0.h>
  15. #include <ntsamp.h>
  16. #include <crypt.h>
  17. #include <windows.h>
  18. #include <lmcons.h>
  19. #include <lmapibuf.h>
  20. #include <lmaccess.h>
  21. #include <rasfmsub.h>
  22. #include <stdlib.h>
  23. #include <rtutils.h>
  24. #include <lmcons.h>
  25. #include <lmaccess.h>
  26. #include <lmapibuf.h>
  27. #include <mprapi.h>
  28. #include <rasman.h>
  29. #include <rasauth.h>
  30. #include <pppcp.h>
  31. #include <raserror.h>
  32. #include <stdio.h>
  33. #include <md5.h>
  34. #define INCL_MISC
  35. #include <ppputil.h>
  36. #include "raschap.h"
  37. static DWORD g_dwAuthPkgId;
  38. //**
  39. //
  40. // Call:
  41. //
  42. // Returns: NO_ERROR - Success
  43. // Non-zero returns - Failure
  44. //
  45. // Description:
  46. //
  47. DWORD
  48. InitLSA(
  49. VOID
  50. )
  51. {
  52. NTSTATUS ntstatus;
  53. STRING PackageName;
  54. //
  55. // To be able to call into NTLM, we need a handle to the LSA.
  56. //
  57. ntstatus = LsaConnectUntrusted(&g_hLsa);
  58. if ( ntstatus != STATUS_SUCCESS )
  59. {
  60. return( RtlNtStatusToDosError( ntstatus ) );
  61. }
  62. //
  63. // We use the MSV1_0 authentication package for LM2.x logons. We get
  64. // to MSV1_0 via the Lsa. So we call Lsa to get MSV1_0's package id,
  65. // which we'll use in later calls to Lsa.
  66. //
  67. RtlInitString(&PackageName, MSV1_0_PACKAGE_NAME);
  68. ntstatus = LsaLookupAuthenticationPackage(g_hLsa, &PackageName, &g_dwAuthPkgId);
  69. return( RtlNtStatusToDosError( ntstatus ) );
  70. }
  71. //**
  72. //
  73. // Call:
  74. //
  75. // Returns: NO_ERROR - Success
  76. // Non-zero returns - Failure
  77. //
  78. // Description:
  79. //
  80. VOID
  81. EndLSA(
  82. VOID
  83. )
  84. {
  85. LsaDeregisterLogonProcess( g_hLsa );
  86. }
  87. //** -GetChallenge
  88. //
  89. // Function:
  90. // Calls Lsa to get LM 2.0 challenge to send client during
  91. // authentication
  92. //
  93. // Returns:
  94. // 0 - success
  95. // 1 - Lsa error
  96. //
  97. // History:
  98. // 05/18/92 - Michael Salamone (MikeSa) - Original Version 1.0
  99. //**
  100. DWORD GetChallenge(
  101. OUT PBYTE pChallenge
  102. )
  103. {
  104. MSV1_0_LM20_CHALLENGE_REQUEST ChallengeRequest;
  105. PMSV1_0_LM20_CHALLENGE_RESPONSE pChallengeResponse;
  106. DWORD dwChallengeResponseLength;
  107. NTSTATUS Status;
  108. NTSTATUS PStatus;
  109. ChallengeRequest.MessageType = MsV1_0Lm20ChallengeRequest;
  110. Status = LsaCallAuthenticationPackage(
  111. g_hLsa,
  112. g_dwAuthPkgId,
  113. &ChallengeRequest,
  114. sizeof(MSV1_0_LM20_CHALLENGE_REQUEST),
  115. (PVOID) &pChallengeResponse,
  116. &dwChallengeResponseLength,
  117. &PStatus
  118. );
  119. if ( Status != STATUS_SUCCESS )
  120. {
  121. return( RtlNtStatusToDosError( Status ) );
  122. }
  123. else if ( PStatus != STATUS_SUCCESS )
  124. {
  125. return( RtlNtStatusToDosError( PStatus ) );
  126. }
  127. else
  128. {
  129. RtlMoveMemory(pChallenge, pChallengeResponse->ChallengeToClient,
  130. MSV1_0_CHALLENGE_LENGTH);
  131. LsaFreeReturnBuffer(pChallengeResponse);
  132. return (0);
  133. }
  134. }