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.

418 lines
9.6 KiB

  1. /*--
  2. Copyright (c) 1987-1993 Microsoft Corporation
  3. Module Name:
  4. pwdtest.c
  5. Abstract:
  6. Test program for the changing passwords.
  7. Author:
  8. 30-Apr-1993 (cliffv)
  9. Environment:
  10. User mode only.
  11. Contains NT-specific code.
  12. Requires ANSI C extensions: slash-slash comments, long external names.
  13. Revision History:
  14. Chandana Surlu 21-Jul-96 Stolen from \\kernel\razzle3\src\security\msv1_0\pwdtest.c
  15. --*/
  16. //
  17. // Common include files.
  18. //
  19. #include <msp.h>
  20. #define NLP_ALLOCATE
  21. #include <nlp.h>
  22. #include <lsarpc.h> // Lsar routines
  23. #include <lsaisrv.h> // LsaIFree and Trusted Client Routines
  24. #include <stdio.h>
  25. //
  26. // Dummy routines from LSA
  27. //
  28. NTSTATUS
  29. LsapAllocateClientBuffer (
  30. IN PLSA_CLIENT_REQUEST ClientRequest,
  31. IN ULONG LengthRequired,
  32. OUT PVOID *ClientBaseAddress
  33. )
  34. {
  35. UNREFERENCED_PARAMETER (ClientRequest);
  36. *ClientBaseAddress = RtlAllocateHeap( MspHeap, 0, LengthRequired );
  37. if ( *ClientBaseAddress == NULL ) {
  38. return(STATUS_QUOTA_EXCEEDED);
  39. }
  40. return(STATUS_SUCCESS);
  41. }
  42. NTSTATUS
  43. LsapFreeClientBuffer (
  44. IN PLSA_CLIENT_REQUEST ClientRequest,
  45. IN PVOID ClientBaseAddress OPTIONAL
  46. )
  47. {
  48. UNREFERENCED_PARAMETER (ClientRequest);
  49. UNREFERENCED_PARAMETER (ClientBaseAddress);
  50. return(STATUS_SUCCESS);
  51. }
  52. NTSTATUS
  53. LsapCopyToClientBuffer (
  54. IN PLSA_CLIENT_REQUEST ClientRequest,
  55. IN ULONG Length,
  56. IN PVOID ClientBaseAddress,
  57. IN PVOID BufferToCopy
  58. )
  59. {
  60. UNREFERENCED_PARAMETER (ClientRequest);
  61. RtlMoveMemory( ClientBaseAddress, BufferToCopy, Length );
  62. return(STATUS_SUCCESS);
  63. }
  64. int __cdecl
  65. main(
  66. IN int argc,
  67. IN char ** argv
  68. )
  69. /*++
  70. Routine Description:
  71. Drive the password changing.
  72. Arguments:
  73. argc - the number of command-line arguments.
  74. argv - an array of pointers to the arguments.
  75. Return Value:
  76. Exit status
  77. --*/
  78. {
  79. NTSTATUS Status;
  80. MSV1_0_CHANGEPASSWORD_REQUEST Request;
  81. PMSV1_0_CHANGEPASSWORD_RESPONSE ReturnBuffer;
  82. ULONG ReturnBufferSize;
  83. NTSTATUS ProtocolStatus;
  84. OBJECT_ATTRIBUTES LSAObjectAttributes;
  85. UNICODE_STRING LocalComputerName = { 0, 0, NULL };
  86. PPOLICY_PRIMARY_DOMAIN_INFO PrimaryDomainInfo = NULL;
  87. if ( argc < 5 ) {
  88. fprintf( stderr,
  89. "Usage: pwdtest DomainName UserName OldPassword NewPassword\n" );
  90. return(1);
  91. }
  92. //
  93. // Set up MSV1_0.dll environment.
  94. //
  95. MspHeap = RtlProcessHeap();
  96. Status = NlInitialize();
  97. if ( !NT_SUCCESS( Status ) ) {
  98. printf("pwdtest: NlInitialize failed, status %x\n", Status);
  99. return(1);
  100. }
  101. Lsa.AllocateClientBuffer = LsapAllocateClientBuffer;
  102. Lsa.FreeClientBuffer = LsapFreeClientBuffer;
  103. Lsa.CopyToClientBuffer = LsapCopyToClientBuffer;
  104. //
  105. // Open the LSA policy database in case change password needs it
  106. //
  107. InitializeObjectAttributes( &LSAObjectAttributes,
  108. NULL, // Name
  109. 0, // Attributes
  110. NULL, // Root
  111. NULL ); // Security Descriptor
  112. Status = LsaOpenPolicy( &LocalComputerName,
  113. &LSAObjectAttributes,
  114. POLICY_VIEW_LOCAL_INFORMATION,
  115. &NlpPolicyHandle );
  116. if( !NT_SUCCESS(Status) ) {
  117. printf("pwdtest: LsaOpenPolicy failed, status %x\n", Status);
  118. return(1);
  119. }
  120. //
  121. // Get the name of our domain.
  122. //
  123. Status = LsaQueryInformationPolicy(
  124. NlpPolicyHandle,
  125. PolicyPrimaryDomainInformation,
  126. (PVOID *) &PrimaryDomainInfo );
  127. if( !NT_SUCCESS(Status) ) {
  128. KdPrint(("pwdtest: LsaQueryInformationPolicy failed, status %x\n",
  129. Status));
  130. return(1);
  131. }
  132. NlpSamDomainName = PrimaryDomainInfo->Name;
  133. //
  134. // Build the request message
  135. //
  136. Request.MessageType = MsV1_0ChangePassword;
  137. RtlCreateUnicodeStringFromAsciiz( &Request.DomainName, argv[1] );
  138. RtlCreateUnicodeStringFromAsciiz( &Request.AccountName, argv[2] );
  139. RtlCreateUnicodeStringFromAsciiz( &Request.OldPassword, argv[3] );
  140. RtlCreateUnicodeStringFromAsciiz( &Request.NewPassword, argv[4] );
  141. Status = MspLm20ChangePassword( NULL,
  142. &Request,
  143. &Request,
  144. 0x7FFFFFFF,
  145. (PVOID *) &ReturnBuffer,
  146. &ReturnBufferSize,
  147. &ProtocolStatus );
  148. printf( "Status = 0x%lx 0x%lx\n", Status, ProtocolStatus );
  149. if ( ProtocolStatus == STATUS_CANT_DISABLE_MANDATORY ) {
  150. printf( "Are you running as SYSTEM?\n" );
  151. }
  152. if ( ReturnBufferSize != 0 ) {
  153. printf( "PasswordInfoValid %ld\n", ReturnBuffer->PasswordInfoValid );
  154. if ( ReturnBuffer->PasswordInfoValid ) {
  155. printf( "Min length: %ld PasswordHistory: %ld Prop 0x%lx\n",
  156. ReturnBuffer->DomainPasswordInfo.MinPasswordLength,
  157. ReturnBuffer->DomainPasswordInfo.PasswordHistoryLength,
  158. ReturnBuffer->DomainPasswordInfo.PasswordProperties );
  159. }
  160. }
  161. return 0;
  162. }
  163. //
  164. // Stub routines needed by msvpaswd.c
  165. //
  166. NTSTATUS
  167. LsarQueryInformationPolicy(
  168. IN LSAPR_HANDLE PolicyHandle,
  169. IN POLICY_INFORMATION_CLASS InfoClass,
  170. OUT PLSAPR_POLICY_INFORMATION *Buffer
  171. )
  172. {
  173. return( LsaQueryInformationPolicy( PolicyHandle,
  174. InfoClass,
  175. Buffer ) );
  176. }
  177. VOID
  178. LsaIFree_LSAPR_POLICY_INFORMATION (
  179. POLICY_INFORMATION_CLASS InfoClass,
  180. PLSAPR_POLICY_INFORMATION Buffer
  181. )
  182. {
  183. UNREFERENCED_PARAMETER (InfoClass);
  184. UNREFERENCED_PARAMETER (Buffer);
  185. }
  186. NTSTATUS
  187. NlpChangePassword(
  188. IN PUNICODE_STRING DomainName,
  189. IN PUNICODE_STRING UserName,
  190. IN PLM_OWF_PASSWORD LmOwfPassword,
  191. IN PNT_OWF_PASSWORD NtOwfPassword
  192. )
  193. {
  194. UNREFERENCED_PARAMETER (DomainName);
  195. UNREFERENCED_PARAMETER (UserName);
  196. UNREFERENCED_PARAMETER (LmOwfPassword);
  197. UNREFERENCED_PARAMETER (NtOwfPassword);
  198. return(STATUS_SUCCESS);
  199. }
  200. NTSTATUS
  201. NlInitialize(
  202. VOID
  203. )
  204. /*++
  205. Routine Description:
  206. Initialize NETLOGON portion of msv1_0 authentication package.
  207. Arguments:
  208. None.
  209. Return Status:
  210. STATUS_SUCCESS - Indicates NETLOGON successfully initialized.
  211. --*/
  212. {
  213. NTSTATUS Status;
  214. LPWSTR ComputerName;
  215. DWORD ComputerNameLength = MAX_COMPUTERNAME_LENGTH + 1;
  216. NT_PRODUCT_TYPE NtProductType;
  217. UNICODE_STRING TempUnicodeString;
  218. //
  219. // Initialize global data
  220. //
  221. NlpEnumerationHandle = 0;
  222. NlpSessionCount = 0;
  223. NlpComputerName.Buffer = NULL;
  224. NlpSamDomainName.Buffer = NULL;
  225. NlpSamDomainId = NULL;
  226. NlpSamDomainHandle = NULL;
  227. //
  228. // Get the name of this machine.
  229. //
  230. ComputerName = RtlAllocateHeap(
  231. MspHeap, 0,
  232. ComputerNameLength * sizeof(WCHAR) );
  233. if (ComputerName == NULL ||
  234. !GetComputerNameW( ComputerName, &ComputerNameLength )) {
  235. KdPrint(( "MsV1_0: Cannot get computername %lX\n", GetLastError() ));
  236. NlpLanmanInstalled = FALSE;
  237. RtlFreeHeap( MspHeap, 0, ComputerName );
  238. ComputerName = NULL;
  239. } else {
  240. NlpLanmanInstalled = TRUE;
  241. }
  242. RtlInitUnicodeString( &NlpComputerName, ComputerName );
  243. //
  244. // Determine if this machine is running Windows NT or Lanman NT.
  245. // LanMan NT runs on a domain controller.
  246. //
  247. if ( !RtlGetNtProductType( &NtProductType ) ) {
  248. KdPrint(( "MsV1_0: Nt Product Type undefined (WinNt assumed)\n" ));
  249. NtProductType = NtProductWinNt;
  250. }
  251. NlpWorkstation = (BOOLEAN)(NtProductType != NtProductLanManNt);
  252. #ifdef notdef
  253. //
  254. // Initialize any locks.
  255. //
  256. __try
  257. {
  258. RtlInitializeResource(&NlpActiveLogonLock);
  259. }
  260. __except(EXCEPTION_EXECUTE_HANDLER)
  261. {
  262. Status = STATUS_INSUFFICIENT_RESOURCES;
  263. }
  264. ASSERT( NT_SUCCESS(Status) );
  265. InitializeListHead(&NlpActiveLogonListAnchor);
  266. RtlInitializeCriticalSection(&NlpSessionCountLock);
  267. //
  268. // initialize the cache - creates a critical section is all
  269. //
  270. NlpCacheInitialize();
  271. #endif // notdef
  272. //
  273. // Attempt to load Netapi.dll
  274. //
  275. NlpLoadNetapiDll();
  276. #ifdef COMPILED_BY_DEVELOPER
  277. KdPrint(("msv1_0: COMPILED_BY_DEVELOPER breakpoint.\n"));
  278. DbgBreakPoint();
  279. #endif // COMPILED_BY_DEVELOPER
  280. //
  281. // Initialize useful encryption constants
  282. //
  283. Status = RtlCalculateLmOwfPassword( "", &NlpNullLmOwfPassword );
  284. ASSERT( NT_SUCCESS(Status) );
  285. RtlInitUnicodeString(&TempUnicodeString, NULL);
  286. Status = RtlCalculateNtOwfPassword(&TempUnicodeString,
  287. &NlpNullNtOwfPassword);
  288. ASSERT( NT_SUCCESS(Status) );
  289. #ifdef notdef
  290. //
  291. // If we weren't successful,
  292. // Clean up global resources we intended to initialize.
  293. //
  294. if ( !NT_SUCCESS(Status) ) {
  295. if ( NlpComputerName.Buffer != NULL ) {
  296. MIDL_user_free( NlpComputerName.Buffer );
  297. }
  298. }
  299. #endif // notdef
  300. return STATUS_SUCCESS;
  301. }