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.

173 lines
3.8 KiB

  1. /***
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. NdsChPw.c
  5. Abstract:
  6. This is the command line NDS utility for changing a
  7. user's NDS password.
  8. Author:
  9. Cory West [corywest] 12-Jan-96
  10. ***/
  11. #include <ndsapi32.h>
  12. #include <nds.h>
  13. int
  14. _cdecl main(
  15. int argc,
  16. char **argv
  17. ) {
  18. NTSTATUS ntstatus;
  19. IO_STATUS_BLOCK IoStatusBlock;
  20. OBJECT_ATTRIBUTES ObjectAttributes;
  21. ACCESS_MASK DesiredAccess = SYNCHRONIZE | FILE_LIST_DIRECTORY;
  22. HANDLE hRdr;
  23. WCHAR DevicePreamble[] = L"\\Device\\Nwrdr\\";
  24. UINT PreambleLength = 14;
  25. UNICODE_STRING OpenName;
  26. WCHAR NameStr[64];
  27. UINT i;
  28. OEM_STRING OemArg;
  29. UNICODE_STRING NdsTree;
  30. WCHAR TreeBuffer[MAX_NDS_TREE_NAME_LEN];
  31. UNICODE_STRING UserName;
  32. WCHAR UserBuffer[MAX_NDS_NAME_CHARS];
  33. UNICODE_STRING CurrPass;
  34. WCHAR CurrPassBuffer[64];
  35. UNICODE_STRING NewPass;
  36. WCHAR NewPassBuffer[64];
  37. //
  38. // Check the arguments.
  39. //
  40. if ( argc != 5 ) {
  41. printf( "Usage: ndschpw tree user current_pw new_pw\n" );
  42. return -1;
  43. }
  44. //
  45. // Copy over the preamble.
  46. //
  47. OpenName.MaximumLength = sizeof( NameStr );
  48. for ( i = 0; i < PreambleLength ; i++ )
  49. NameStr[i] = DevicePreamble[i];
  50. //
  51. // Convert the argument name to unicode.
  52. //
  53. OemArg.Length = strlen( argv[1] );
  54. OemArg.MaximumLength = OemArg.Length;
  55. OemArg.Buffer = argv[1];
  56. NdsTree.Length = 0;
  57. NdsTree.MaximumLength = sizeof( TreeBuffer );
  58. NdsTree.Buffer = TreeBuffer;
  59. RtlOemStringToUnicodeString( &NdsTree, &OemArg, FALSE );
  60. //
  61. // Copy the server or tree name.
  62. //
  63. for ( i = 0 ; i < ( NdsTree.Length / sizeof( WCHAR ) ) ; i++ ) {
  64. NameStr[i + PreambleLength] = NdsTree.Buffer[i];
  65. }
  66. OpenName.Length = ( i * sizeof( WCHAR ) ) +
  67. ( PreambleLength * sizeof( WCHAR ) );
  68. OpenName.Buffer = NameStr;
  69. //
  70. // Set up the object attributes.
  71. //
  72. InitializeObjectAttributes( &ObjectAttributes,
  73. &OpenName,
  74. OBJ_CASE_INSENSITIVE,
  75. NULL,
  76. NULL );
  77. ntstatus = NtOpenFile( &hRdr,
  78. DesiredAccess,
  79. &ObjectAttributes,
  80. &IoStatusBlock,
  81. FILE_SHARE_VALID_FLAGS,
  82. FILE_SYNCHRONOUS_IO_NONALERT );
  83. if ( !NT_SUCCESS(ntstatus) )
  84. return ntstatus;
  85. //
  86. // Convert the other args to unicode.
  87. //
  88. OemArg.Length = strlen( argv[2] );
  89. OemArg.MaximumLength = OemArg.Length;
  90. OemArg.Buffer = argv[2];
  91. UserName.Length = 0;
  92. UserName.MaximumLength = sizeof( UserBuffer );
  93. UserName.Buffer = UserBuffer;
  94. RtlOemStringToUnicodeString( &UserName, &OemArg, FALSE );
  95. OemArg.Length = strlen( argv[3] );
  96. OemArg.MaximumLength = OemArg.Length;
  97. OemArg.Buffer = argv[3];
  98. CurrPass.Length = 0;
  99. CurrPass.MaximumLength = sizeof( CurrPassBuffer );
  100. CurrPass.Buffer = CurrPassBuffer;
  101. RtlOemStringToUnicodeString( &CurrPass, &OemArg, FALSE );
  102. OemArg.Length = strlen( argv[4] );
  103. OemArg.MaximumLength = OemArg.Length;
  104. OemArg.Buffer = argv[4];
  105. NewPass.Length = 0;
  106. NewPass.MaximumLength = sizeof( NewPassBuffer );
  107. NewPass.Buffer = NewPassBuffer;
  108. RtlOemStringToUnicodeString( &NewPass, &OemArg, FALSE );
  109. //
  110. // Submit the request.
  111. //
  112. ntstatus = NwNdsChangePassword( hRdr,
  113. &NdsTree,
  114. &UserName,
  115. &CurrPass,
  116. &NewPass );
  117. if ( NT_SUCCESS( ntstatus )) {
  118. printf( "Password changed.\n" );
  119. } else {
  120. printf( "Password change failed!\n" );
  121. }
  122. NtClose( hRdr );
  123. return ntstatus;
  124. }