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.

285 lines
6.9 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 1992 - 1992
  6. //
  7. // File: passprop.cxx
  8. //
  9. // Contents: utility program to set domain password properties
  10. //
  11. //
  12. // History: 3-May-96 Created MikeSw
  13. //
  14. //------------------------------------------------------------------------
  15. extern "C"
  16. {
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <ntsam.h>
  21. #include <ntlsa.h>
  22. #include <windows.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <stdlib.h>
  26. #include <lmcons.h>
  27. #include <lmaccess.h>
  28. #include "passp.h"
  29. }
  30. void _cdecl
  31. main(int argc, char *argv[])
  32. {
  33. NTSTATUS Status;
  34. PDOMAIN_PASSWORD_INFORMATION PasswordInfo = NULL;
  35. SAM_HANDLE ServerHandle = NULL;
  36. SAM_HANDLE DomainHandle = NULL;
  37. SAM_HANDLE UserHandle = NULL;
  38. LSA_HANDLE PolicyHandle = NULL;
  39. OBJECT_ATTRIBUTES ObjectAttributes;
  40. SECURITY_QUALITY_OF_SERVICE SecurityQualityOfService;
  41. PPOLICY_ACCOUNT_DOMAIN_INFO AccountDomainInfo = NULL;
  42. PULONG UserId = NULL;
  43. PSID_NAME_USE NameUse = NULL;
  44. ULONG TurnOffFlags = 0;
  45. ULONG TurnOnFlags = 0;
  46. int Index;
  47. CHAR MessageBuff[1000];
  48. CHAR ComplexArg[20];
  49. CHAR SimpleArg[20];
  50. CHAR AdminArg[20];
  51. CHAR NoAdminArg[20];
  52. InitializeObjectAttributes(
  53. &ObjectAttributes,
  54. NULL,
  55. 0,
  56. NULL,
  57. NULL
  58. );
  59. FormatMessageA(
  60. FORMAT_MESSAGE_FROM_HMODULE,
  61. NULL,
  62. MSG_PASSPROP_SWITCH_COMPLEX,
  63. 0,
  64. ComplexArg,
  65. 20,
  66. NULL
  67. );
  68. FormatMessageA(
  69. FORMAT_MESSAGE_FROM_HMODULE,
  70. NULL,
  71. MSG_PASSPROP_SWITCH_SIMPLE,
  72. 0,
  73. SimpleArg,
  74. 20,
  75. NULL
  76. );
  77. FormatMessageA(
  78. FORMAT_MESSAGE_FROM_HMODULE,
  79. NULL,
  80. MSG_PASSPROP_SWITCH_ADMIN_LOCKOUT,
  81. 0,
  82. AdminArg,
  83. 20,
  84. NULL
  85. );
  86. FormatMessageA(
  87. FORMAT_MESSAGE_FROM_HMODULE,
  88. NULL,
  89. MSG_PASSPROP_SWITCH_NO_ADMIN_LOCKOUT,
  90. 0,
  91. NoAdminArg,
  92. 20,
  93. NULL
  94. );
  95. for (Index = 1; Index < argc ; Index++)
  96. {
  97. if (_stricmp(argv[Index],ComplexArg) == 0)
  98. {
  99. TurnOnFlags |= DOMAIN_PASSWORD_COMPLEX;
  100. } else if (_stricmp(argv[Index],SimpleArg) == 0)
  101. {
  102. TurnOffFlags |= DOMAIN_PASSWORD_COMPLEX;
  103. } else if (_stricmp(argv[Index],AdminArg) == 0)
  104. {
  105. TurnOnFlags |= DOMAIN_LOCKOUT_ADMINS;
  106. } else if (_stricmp(argv[Index],NoAdminArg) == 0)
  107. {
  108. TurnOffFlags |= DOMAIN_LOCKOUT_ADMINS;
  109. } else
  110. {
  111. goto Usage;
  112. }
  113. }
  114. //
  115. // The InitializeObjectAttributes call doesn't initialize the
  116. // quality of serivce, so do that separately.
  117. //
  118. SecurityQualityOfService.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
  119. SecurityQualityOfService.ImpersonationLevel = SecurityImpersonation;
  120. SecurityQualityOfService.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
  121. SecurityQualityOfService.EffectiveOnly = FALSE;
  122. ObjectAttributes.SecurityQualityOfService = &SecurityQualityOfService;
  123. Status = LsaOpenPolicy(
  124. NULL,
  125. &ObjectAttributes,
  126. POLICY_VIEW_LOCAL_INFORMATION,
  127. &PolicyHandle
  128. );
  129. if (!NT_SUCCESS(Status)) {
  130. printf("Failed to open local policy: 0x%x\n",Status);
  131. return;
  132. }
  133. Status = LsaQueryInformationPolicy(
  134. PolicyHandle,
  135. PolicyAccountDomainInformation,
  136. (PVOID *) &AccountDomainInfo
  137. );
  138. LsaClose(PolicyHandle);
  139. if (!NT_SUCCESS(Status)) {
  140. printf("Failed to query info policy: 0x%x\n",Status);
  141. return;
  142. }
  143. Status = SamConnect(
  144. NULL,
  145. &ServerHandle,
  146. SAM_SERVER_LOOKUP_DOMAIN,
  147. &ObjectAttributes
  148. );
  149. if (!NT_SUCCESS(Status)) {
  150. printf("Failed to sam connect: 0x%x\n",Status);
  151. return;
  152. }
  153. Status = SamOpenDomain(
  154. ServerHandle,
  155. MAXIMUM_ALLOWED,
  156. AccountDomainInfo->DomainSid,
  157. &DomainHandle
  158. );
  159. if (!NT_SUCCESS(Status)) {
  160. printf("Failed to open domain: 0x%x\n",Status);
  161. SamCloseHandle(ServerHandle);
  162. return;
  163. }
  164. Status = SamQueryInformationDomain(
  165. DomainHandle,
  166. DomainPasswordInformation,
  167. (PVOID *) &PasswordInfo
  168. );
  169. if (!NT_SUCCESS(Status))
  170. {
  171. printf("Failed to query domain pasword info: 0x%x\n",Status);
  172. SamCloseHandle(ServerHandle);
  173. SamCloseHandle(DomainHandle);
  174. return;
  175. }
  176. PasswordInfo->PasswordProperties = (PasswordInfo->PasswordProperties | TurnOnFlags) & (~TurnOffFlags);
  177. if ((TurnOnFlags != 0) || (TurnOffFlags != 0))
  178. {
  179. Status = SamSetInformationDomain(
  180. DomainHandle,
  181. DomainPasswordInformation,
  182. PasswordInfo
  183. );
  184. if (!NT_SUCCESS(Status))
  185. {
  186. printf("Failed to query domain pasword info: 0x%x\n",Status);
  187. return;
  188. }
  189. }
  190. if ((PasswordInfo->PasswordProperties & DOMAIN_PASSWORD_COMPLEX) != 0)
  191. {
  192. FormatMessageA(
  193. FORMAT_MESSAGE_FROM_HMODULE,
  194. NULL,
  195. MSG_PASSPROP_COMPLEX,
  196. 0,
  197. MessageBuff,
  198. 1000,
  199. NULL
  200. );
  201. }
  202. else
  203. {
  204. FormatMessageA(
  205. FORMAT_MESSAGE_FROM_HMODULE,
  206. NULL,
  207. MSG_PASSPROP_SIMPLE,
  208. 0,
  209. MessageBuff,
  210. 1000,
  211. NULL
  212. );
  213. }
  214. printf("%s",MessageBuff);
  215. if ((PasswordInfo->PasswordProperties & DOMAIN_LOCKOUT_ADMINS) != 0)
  216. {
  217. FormatMessageA(
  218. FORMAT_MESSAGE_FROM_HMODULE,
  219. NULL,
  220. MSG_PASSPROP_ADMIN_LOCKOUT,
  221. 0,
  222. MessageBuff,
  223. 1000,
  224. NULL
  225. );
  226. }
  227. else
  228. {
  229. FormatMessageA(
  230. FORMAT_MESSAGE_FROM_HMODULE,
  231. NULL,
  232. MSG_PASSPROP_NO_ADMIN_LOCKOUT,
  233. 0,
  234. MessageBuff,
  235. 1000,
  236. NULL
  237. );
  238. }
  239. printf("%s",MessageBuff);
  240. SamCloseHandle(ServerHandle);
  241. SamCloseHandle(DomainHandle);
  242. SamFreeMemory(PasswordInfo);
  243. return;
  244. Usage:
  245. FormatMessageA(
  246. FORMAT_MESSAGE_FROM_HMODULE,
  247. NULL,
  248. MSG_PASSPROP_USAGE,
  249. 0,
  250. MessageBuff,
  251. 1000,
  252. NULL
  253. );
  254. printf("%s",MessageBuff);
  255. }