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.

149 lines
3.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: tpwd.c
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 9-08-97 RichardW Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <windows.h>
  18. #include <rpc.h>
  19. #include <wchar.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #define SECURITY_WIN32
  23. #include <security.h>
  24. #include <pwdssp.h>
  25. VOID
  26. wgets(
  27. PWSTR s
  28. )
  29. {
  30. CHAR Buffer[MAX_PATH ];
  31. gets(Buffer);
  32. MultiByteToWideChar(
  33. CP_ACP, 0,
  34. Buffer, -1,
  35. s, MAX_PATH );
  36. }
  37. void __cdecl main (int argc, char *argv[])
  38. {
  39. SEC_WINNT_AUTH_IDENTITY_W Wide ;
  40. CredHandle Cred ;
  41. CtxtHandle Ctxt ;
  42. WCHAR Name[ MAX_PATH ];
  43. WCHAR Password[ 64 ];
  44. WCHAR Domain[ MAX_PATH ];
  45. SECURITY_STATUS scRet ;
  46. TimeStamp ts ;
  47. SecBufferDesc Input ;
  48. SecBuffer InputBuffer ;
  49. SecBufferDesc Output ;
  50. ULONG Flags ;
  51. CHAR Buffer[ MAX_PATH ];
  52. scRet = AcquireCredentialsHandleW(
  53. NULL,
  54. PWDSSP_NAME_W,
  55. SECPKG_CRED_INBOUND,
  56. NULL, NULL, NULL, NULL,
  57. &Cred, &ts );
  58. if ( scRet != 0 )
  59. {
  60. printf("AcquireCredentialsHandleW failed with %x\n", scRet );
  61. exit(0);
  62. }
  63. do
  64. {
  65. ZeroMemory(Name, sizeof(Name));
  66. ZeroMemory(Password, sizeof(Password));
  67. ZeroMemory(Domain, sizeof(Domain));
  68. printf("Enter name, or 'quit' to quit>");
  69. wgets( Name );
  70. if ( wcscmp( Name, L"quit") == 0 )
  71. {
  72. break;
  73. }
  74. printf("Enter password>" );
  75. wgets( Password );
  76. printf("Enter domain>");
  77. wgets( Domain );
  78. //
  79. // Format "blob"
  80. //
  81. ZeroMemory( &Wide, sizeof( Wide ) );
  82. Wide.User = Name ;
  83. Wide.UserLength = wcslen( Name );
  84. if ( Domain[0] )
  85. {
  86. Wide.Domain = Domain ;
  87. Wide.DomainLength = wcslen( Domain );
  88. }
  89. else
  90. {
  91. Wide.Domain = NULL ;
  92. Wide.DomainLength = 0 ;
  93. }
  94. Wide.Password = Password ;
  95. Wide.PasswordLength = wcslen( Password );
  96. Wide.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE ;
  97. InputBuffer.BufferType = SECBUFFER_TOKEN ;
  98. InputBuffer.pvBuffer = &Wide ;
  99. InputBuffer.cbBuffer = sizeof( Wide );
  100. Input.pBuffers = &InputBuffer;
  101. Input.cBuffers = 1;
  102. Input.ulVersion = 0;
  103. scRet = AcceptSecurityContext(
  104. &Cred,
  105. NULL,
  106. &Input,
  107. 0,
  108. SECURITY_NATIVE_DREP,
  109. &Ctxt,
  110. &Output,
  111. &Flags,
  112. &ts );
  113. if ( scRet != 0 )
  114. {
  115. printf(" FAILED, %x\n", scRet );
  116. }
  117. else
  118. {
  119. printf(" SUCCESS\n" );
  120. DeleteSecurityContext( &Ctxt );
  121. }
  122. } while ( 1 );
  123. }