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.

208 lines
5.6 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. asrequest.cxx
  5. Abstract:
  6. enumusers
  7. Author:
  8. Larry Zhu (LZhu) December 1, 2001 Created
  9. Environment:
  10. User Mode
  11. Revision History:
  12. --*/
  13. #include "precomp.hxx"
  14. #pragma hdrstop
  15. #include <kerberos.h>
  16. #include "asrequest.hxx"
  17. void
  18. Usage(
  19. IN PCSTR pszApp
  20. )
  21. {
  22. DebugPrintf(SSPI_ERROR, "\n\nUsage: %s -c<client name> -C<client realm> "
  23. "-s<server name> -S<server realm> -t<server name type> -p<client password>\n\n", pszApp);
  24. exit(-1);
  25. }
  26. #if 0
  27. typedef struct _KERB_TICKET_AS_REQUEST {
  28. KERB_PROTOCOL_MESSAGE_TYPE MessageType;
  29. ULONG Flags;
  30. ULONG NameType;
  31. UNICODE_STRING ClientName;
  32. UNICODE_STRING ClientRealm;
  33. UNICODE_STRING ClientPassword;
  34. UNICODE_STRING ServerName; // optional, default to krbtgt
  35. UNICODE_STRING ServerRealm; // optinal, default to local realm
  36. } KERB_TICKET_AS_REQUEST, *PKERB_TICKET_AS_REQUEST;
  37. #endif
  38. VOID __cdecl
  39. main(
  40. IN INT argc,
  41. IN PSTR argv[]
  42. )
  43. {
  44. TNtStatus Status = STATUS_SUCCESS;
  45. NTSTATUS AuthPackageStatus = STATUS_UNSUCCESSFUL;
  46. HANDLE LogonHandle = NULL;
  47. ULONG PackageId = -1;
  48. KERB_TICKET_AS_REQUEST AsReq;
  49. KERB_TICKET_AS_REQUEST* pAsRequest = NULL;
  50. ULONG cbAsQuest = sizeof(KERB_TICKET_AS_REQUEST);
  51. KERB_TICKET_AS_REQUEST* pAsResp = NULL;
  52. ULONG AsResponseLength = 0;
  53. CHAR* pWhere = NULL;
  54. RtlZeroMemory(&AsReq, sizeof(AsReq));
  55. AsReq.MessageType = (KERB_PROTOCOL_MESSAGE_TYPE) KerbTicketAsRequestMessage;
  56. /* allow the user to override settings with command line switches */
  57. for (int i = 1; NT_SUCCESS(Status) && (i < argc); i++)
  58. {
  59. if ((*argv[i] == '-') || (*argv[i] == '/'))
  60. {
  61. switch (argv[i][1])
  62. {
  63. case 'c':
  64. Status DBGCHK = CreateUnicodeStringFromAsciiz(argv[i] + 2, &AsReq.ClientName);
  65. cbAsQuest += AsReq.ClientName.MaximumLength;
  66. break;
  67. case 'C':
  68. Status DBGCHK = CreateUnicodeStringFromAsciiz(argv[i] + 2, &AsReq.ClientRealm);
  69. cbAsQuest += AsReq.ClientRealm.MaximumLength;
  70. break;
  71. case 's':
  72. Status DBGCHK = CreateUnicodeStringFromAsciiz(argv[i] + 2, &AsReq.ServerName);
  73. cbAsQuest += AsReq.ServerName.MaximumLength;
  74. break;
  75. case 'S':
  76. Status DBGCHK = CreateUnicodeStringFromAsciiz(argv[i] + 2, &AsReq.ServerRealm);
  77. cbAsQuest += AsReq.ServerRealm.MaximumLength;
  78. break;
  79. case 'p':
  80. Status DBGCHK = CreateUnicodeStringFromAsciiz(argv[i] + 2, &AsReq.ClientPassword);
  81. cbAsQuest += AsReq.ClientPassword.MaximumLength;
  82. break;
  83. case 't':
  84. AsReq.NameType = strtol(argv[i] + 2, NULL, 0);
  85. break;
  86. case 'h':
  87. case '?':
  88. default:
  89. Usage(argv[0]);
  90. break;
  91. }
  92. }
  93. else
  94. {
  95. Usage(argv[0]);
  96. }
  97. }
  98. if (NT_SUCCESS(Status) && (AsReq.NameType == KRB_NT_UNKNOWN))
  99. {
  100. DebugPrintf(SSPI_ERROR, "server name type required\n");
  101. Status DBGCHK = STATUS_INVALID_PARAMETER;
  102. }
  103. if (NT_SUCCESS(Status))
  104. {
  105. Status DBGCHK = GetLsaHandleAndPackageId(
  106. MICROSOFT_KERBEROS_NAME_A,
  107. &LogonHandle,
  108. &PackageId
  109. );
  110. }
  111. if (NT_SUCCESS(Status))
  112. {
  113. pAsRequest = (KERB_TICKET_AS_REQUEST*) new UCHAR[cbAsQuest];
  114. Status DBGCHK = pAsRequest ? S_OK : STATUS_NO_MEMORY;
  115. }
  116. if (NT_SUCCESS(Status))
  117. {
  118. pWhere = ((CHAR*) pAsRequest) + sizeof(KERB_TICKET_AS_REQUEST);
  119. *pAsRequest = AsReq;
  120. RelocatePackUnicodeString(&pAsRequest->ClientRealm, &pWhere);
  121. RelocatePackUnicodeString(&pAsRequest->ClientName, &pWhere);
  122. RelocatePackUnicodeString(&pAsRequest->ClientPassword, &pWhere);
  123. RelocatePackUnicodeString(&pAsRequest->ServerRealm, &pWhere);
  124. RelocatePackUnicodeString(&pAsRequest->ServerName, &pWhere);
  125. DebugPrintf(SSPI_LOG,
  126. "pAsRequest %p, ClientRealm (%wZ), ClientName (%wZ), "
  127. "ClientPassword (%wZ), ServerRealm (%wZ), "
  128. "ServerName (%wZ), SererNameType %d(%#x), pWhere %p\n",
  129. pAsRequest,
  130. &pAsRequest->ClientRealm,
  131. &pAsRequest->ClientName,
  132. &pAsRequest->ClientPassword,
  133. &pAsRequest->ServerRealm,
  134. &pAsRequest->ServerName,
  135. pAsRequest->NameType,
  136. pAsRequest->NameType,
  137. pWhere);
  138. Status DBGCHK = LsaCallAuthenticationPackage(
  139. LogonHandle,
  140. PackageId,
  141. pAsRequest,
  142. cbAsQuest,
  143. (PVOID*) &pAsResp,
  144. &AsResponseLength,
  145. &AuthPackageStatus
  146. );
  147. }
  148. if (LogonHandle != NULL)
  149. {
  150. LsaDeregisterLogonProcess(LogonHandle);
  151. }
  152. RtlFreeUnicodeString(&AsReq.ClientName);
  153. RtlFreeUnicodeString(&AsReq.ClientRealm);
  154. RtlFreeUnicodeString(&AsReq.ServerName);
  155. RtlFreeUnicodeString(&AsReq.ServerRealm);
  156. RtlFreeUnicodeString(&AsReq.ClientPassword);
  157. if (pAsRequest)
  158. {
  159. delete [] pAsRequest;
  160. }
  161. if (pAsResp)
  162. {
  163. LsaFreeReturnBuffer(pAsResp);
  164. }
  165. }