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.

152 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. derivecred.cxx
  5. Abstract:
  6. derivecred
  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 "derivecred.hxx"
  16. VOID
  17. Usage(
  18. IN PCWSTR pszProgramName
  19. )
  20. {
  21. DebugPrintf(SSPI_LOG, "Usage: %ws -a <account name> -p <privilege to add> -P <privilege to remove> -r <system access to set> -s <server name>\n", pszProgramName);
  22. DebugPrintf(SSPI_LOG, "example system access are SECURITY_ACCESS_INTERACTIVE_LOGON and SECURITY_ACCESS_DENY_SERVICE_LOGON\n");
  23. exit(1);
  24. }
  25. VOID __cdecl
  26. _tmain(
  27. IN INT argc,
  28. IN PTSTR argv[]
  29. )
  30. {
  31. TNtStatus Status = STATUS_SUCCESS;
  32. CHAR Data[4094] = {0};
  33. MSV1_0_DERIVECRED_REQUEST* pDeriveCred = NULL;
  34. MSV1_0_DERIVECRED_RESPONSE* pDeriveCredResponse = NULL;
  35. LUID LogonId = {0x3e4, 0};
  36. ULONG Type = MSV1_0_DERIVECRED_TYPE_SHA1;
  37. ULONG cbDataToDerive = 8;
  38. ULONG cbRequest = 0;
  39. HANDLE hLsa = NULL;
  40. ULONG PackageId = 0;
  41. NTSTATUS SubStatus = STATUS_UNSUCCESSFUL;
  42. ULONG cbResponse = 0;
  43. for (INT i = 1; i < argc; i++)
  44. {
  45. if ((*argv[i] == '-') || (*argv[i] == '/'))
  46. {
  47. switch (*(argv[i] + 1))
  48. {
  49. case 'l':
  50. LogonId.LowPart = wcstol(argv[++i], NULL, 0);
  51. break;
  52. case 'h':
  53. LogonId.HighPart = wcstol(argv[++i], NULL, 0);
  54. break;
  55. case 't':
  56. Type = wcstol(argv[++i], NULL, 0);
  57. break;
  58. case 'd':
  59. cbDataToDerive = wcstol(argv[++i], NULL, 0);
  60. break;
  61. case '?':
  62. default:
  63. Usage(argv[0]);
  64. }
  65. }
  66. else
  67. {
  68. Usage(argv[0]);
  69. }
  70. }
  71. cbRequest = sizeof(MSV1_0_DERIVECRED_REQUEST) + cbDataToDerive;
  72. pDeriveCred = (MSV1_0_DERIVECRED_REQUEST*) new CHAR[cbRequest];
  73. Status DBGCHK = pDeriveCred ? STATUS_SUCCESS : STATUS_NO_MEMORY;
  74. if (NT_SUCCESS(Status))
  75. {
  76. RtlZeroMemory(pDeriveCred, cbRequest);
  77. pDeriveCred->LogonId = LogonId;
  78. pDeriveCred->MessageType = MsV1_0DeriveCredential;
  79. pDeriveCred->DeriveCredType = Type;
  80. pDeriveCred->DeriveCredInfoLength = cbDataToDerive;
  81. RtlCopyMemory(pDeriveCred->DeriveCredSubmitBuffer, Data, cbDataToDerive);
  82. Status DBGCHK = GetLsaHandleAndPackageId(
  83. MSV1_0_PACKAGE_NAME,
  84. &hLsa,
  85. &PackageId
  86. );
  87. }
  88. if (NT_SUCCESS(Status))
  89. {
  90. SspiPrint(SSPI_LOG, TEXT("DeriveCred type %#x, LogonId %#x:%#x\n"),
  91. pDeriveCred->DeriveCredType, pDeriveCred->LogonId.HighPart, pDeriveCred->LogonId.LowPart);
  92. SspiPrintHex(SSPI_LOG, TEXT("Data to derive"), pDeriveCred->DeriveCredInfoLength, pDeriveCred->DeriveCredSubmitBuffer);
  93. Status DBGCHK = LsaCallAuthenticationPackage(
  94. hLsa,
  95. PackageId,
  96. pDeriveCred,
  97. cbRequest,
  98. (PVOID*) &pDeriveCredResponse,
  99. &cbResponse,
  100. &SubStatus
  101. );
  102. }
  103. if (NT_SUCCESS(Status))
  104. {
  105. Status DBGCHK = SubStatus;
  106. }
  107. if (NT_SUCCESS(Status))
  108. {
  109. SspiPrintHex(SSPI_LOG, TEXT("Response"), pDeriveCredResponse->DeriveCredInfoLength, pDeriveCredResponse->DeriveCredReturnBuffer);
  110. }
  111. if (pDeriveCredResponse)
  112. {
  113. LsaFreeReturnBuffer(pDeriveCredResponse);
  114. }
  115. if (pDeriveCred)
  116. {
  117. delete [] pDeriveCred;
  118. }
  119. if (hLsa)
  120. {
  121. LsaDeregisterLogonProcess(hLsa);
  122. }
  123. }