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.

127 lines
2.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: crack.c
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 9-07-97 RichardW Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "pwdsspp.h"
  18. BOOL
  19. CacheInitialize(
  20. VOID
  21. )
  22. {
  23. return TRUE ;
  24. }
  25. BOOL
  26. PwdCrackName(
  27. PWSTR DN,
  28. PWSTR FlatDomain,
  29. PWSTR FlatUser
  30. )
  31. {
  32. WCHAR FlatName[ 128 ];
  33. WCHAR DnsDomain[ 256 ];
  34. DWORD DnsSize ;
  35. DWORD Size ;
  36. NTSTATUS Status ;
  37. DWORD DsError ;
  38. PWSTR Scan ;
  39. PVOID DsContext ;
  40. Size = sizeof( FlatName ) / sizeof(WCHAR) ;
  41. DnsSize = sizeof( DnsDomain ) / sizeof( WCHAR );
  42. DsContext = THSave();
  43. __try
  44. {
  45. Status = CrackSingleName(
  46. DS_UNKNOWN_NAME,
  47. 0,
  48. DN,
  49. DS_NT4_ACCOUNT_NAME,
  50. &DnsSize,
  51. DnsDomain,
  52. &Size,
  53. FlatName,
  54. &DsError );
  55. }
  56. __except( EXCEPTION_EXECUTE_HANDLER )
  57. {
  58. Status = GetExceptionCode();
  59. }
  60. if ( !NT_SUCCESS( Status ) )
  61. {
  62. THRestore( DsContext );
  63. return FALSE ;
  64. }
  65. if ( DsError == DS_NAME_ERROR_DOMAIN_ONLY )
  66. {
  67. Size = sizeof( FlatName ) / sizeof( WCHAR ) ;
  68. DnsSize = sizeof( DnsDomain ) / sizeof( WCHAR );
  69. Status = CrackSingleName(
  70. DS_UNKNOWN_NAME,
  71. DS_NAME_FLAG_GCVERIFY,
  72. DN,
  73. DS_NT4_ACCOUNT_NAME,
  74. &DnsSize,
  75. DnsDomain,
  76. &Size,
  77. FlatName,
  78. &DsError );
  79. }
  80. THRestore( DsContext );
  81. if ( !NT_SUCCESS( Status ) )
  82. {
  83. return FALSE ;
  84. }
  85. if ( DsError == DS_NAME_NO_ERROR )
  86. {
  87. Scan = wcschr( FlatName, L'\\' );
  88. if ( Scan )
  89. {
  90. *Scan++ = L'\0' ;
  91. wcscpy(FlatDomain, FlatName );
  92. wcscpy(FlatUser, Scan );
  93. }
  94. else
  95. {
  96. wcscpy(FlatUser, FlatName );
  97. FlatDomain[0] = L'\0';
  98. }
  99. return TRUE ;
  100. }
  101. return FALSE ;
  102. }