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.

390 lines
10 KiB

  1. ///**************************************************************
  2. /// Microsoft LAN Manager *
  3. /// Copyright(c) Microsoft Corp., 1990-1992 *
  4. ///**************************************************************
  5. //
  6. // This program is designed to do functional testing on the following
  7. // APIs:
  8. // NetUserModalsGet
  9. // NetUserModalsSet
  10. //
  11. // This test can be run independently of other tests.
  12. //
  13. //
  14. #include <nt.h> // TIME definition
  15. #include <ntrtl.h> // TIME definition
  16. #include <nturtl.h> // TIME definition
  17. #define NOMINMAX // Avoid redefinition of min and max in stdlib.h
  18. #include <windef.h>
  19. #include <winbase.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <lmcons.h>
  24. #include <lmapibuf.h>
  25. #include <netlib.h>
  26. #include <netdebug.h>
  27. #include <lmaccess.h>
  28. #include <lmerr.h>
  29. #include <ntsam.h>
  30. #include "uastest.h"
  31. #include "accessp.h"
  32. #include "netlogon.h"
  33. #include "logonp.h"
  34. #define TEST_MIN_PWLEN 2
  35. #define TEST_MAX_PWAGE 0xDDDDDDDD
  36. #define TEST_MIN_PWAGE 0x00000222
  37. #define TEST_FORCE_LOGOFF 0xEEEEEEEE
  38. #define TEST_MAX_PWHIST 7
  39. #define COMPUTERNAME "STAND_ALONE"
  40. #define DEF_COMPNAME "COMPNAME"
  41. char rbuf[1024];
  42. char ibuf[1024];
  43. char obuf[1024];
  44. char ibuf2[1024];
  45. char obuf2[1024];
  46. void
  47. test_init_modals()
  48. {
  49. PUSER_MODALS_INFO_0 um0p;
  50. //
  51. // test with invalid level
  52. //
  53. if (err = NetUserModalsGet(server, 3, (LPBYTE *) &um0p)) {
  54. if (err != ERROR_INVALID_LEVEL) {
  55. error_exit( FAIL, "UserModalsGet invalid level wrong", NULL);
  56. } else {
  57. error_exit( PASS, "UserModalsGet invalid level OK", NULL);
  58. }
  59. } else {
  60. error_exit( FAIL, "UserModalsGet with invalid level succeeded", NULL);
  61. NetApiBufferFree( um0p );
  62. }
  63. //
  64. // get valid level
  65. //
  66. if (err = NetUserModalsGet(server, 0, (LPBYTE *) &um0p))
  67. error_exit( FAIL, "First UserModalsGet failed", NULL);
  68. else {
  69. error_exit( PASS, "First UserModalsGet successful", NULL);
  70. //
  71. // verify initial settings
  72. //
  73. TestDiffDword( "Min password default mismatch", NULL,
  74. um0p->usrmod0_min_passwd_len, DEF_MIN_PWLEN );
  75. TestDiffDword( "Max password age default mismatch", NULL,
  76. um0p->usrmod0_max_passwd_age, DEF_MAX_PWAGE );
  77. TestDiffDword( "Min password age default mismatch", NULL,
  78. um0p->usrmod0_min_passwd_age, DEF_MIN_PWAGE );
  79. TestDiffDword( "Force logooff default mismatch", NULL,
  80. um0p->usrmod0_force_logoff, DEF_FORCE_LOGOFF );
  81. TestDiffDword( "Password history length default mismatch", NULL,
  82. um0p->usrmod0_password_hist_len, DEF_MAX_PWHIST );
  83. NetApiBufferFree( um0p );
  84. }
  85. }
  86. VOID
  87. restore_original_modals( VOID )
  88. {
  89. PUSER_MODALS_INFO_0 um0p;
  90. USER_MODALS_INFO_0 um0;
  91. //
  92. // attempt to restore original (default) settings
  93. //
  94. um0.usrmod0_min_passwd_len = DEF_MIN_PWLEN;
  95. um0.usrmod0_max_passwd_age = DEF_MAX_PWAGE;
  96. um0.usrmod0_min_passwd_age = DEF_MIN_PWAGE;
  97. um0.usrmod0_force_logoff = DEF_FORCE_LOGOFF;
  98. um0.usrmod0_password_hist_len = DEF_MAX_PWHIST;
  99. if (err = NetUserModalsSet(server, 0, (LPBYTE) &um0, &ParmError ))
  100. error_exit( FAIL, "UserModalsSet (restore) Failed", NULL);
  101. //
  102. // verify reset
  103. //
  104. if (err = NetUserModalsGet(server, 0, (LPBYTE *) &um0p)) {
  105. error_exit( FAIL, "Verify UserModalsGet failed", NULL);
  106. } else {
  107. TestDiffDword( "Min password default mismatch", NULL,
  108. um0p->usrmod0_min_passwd_len, DEF_MIN_PWLEN );
  109. TestDiffDword( "Max password age default mismatch", NULL,
  110. um0p->usrmod0_max_passwd_age, DEF_MAX_PWAGE );
  111. TestDiffDword( "Min password age default mismatch", NULL,
  112. um0p->usrmod0_min_passwd_age, DEF_MIN_PWAGE );
  113. TestDiffDword( "Force logooff default mismatch", NULL,
  114. um0p->usrmod0_force_logoff, DEF_FORCE_LOGOFF );
  115. TestDiffDword( "Password history length default mismatch", NULL,
  116. um0p->usrmod0_password_hist_len, DEF_MAX_PWHIST );
  117. NetApiBufferFree( um0p );
  118. }
  119. }
  120. void
  121. test_set_modals()
  122. {
  123. PUSER_MODALS_INFO_0 um0p = (PUSER_MODALS_INFO_0 ) ibuf;
  124. USER_MODALS_INFO_0 um0;
  125. //
  126. // set with invalid level
  127. //
  128. if (err = NetUserModalsSet(server, 3, (LPBYTE) &um0, &ParmError )) {
  129. if (err != ERROR_INVALID_LEVEL)
  130. error_exit(FAIL, "UserModalsSet invalid level wrong", NULL);
  131. } else
  132. error_exit(FAIL, "UserModalsSet with invalid level succeeded", NULL);
  133. //
  134. // setup data for update
  135. //
  136. um0.usrmod0_min_passwd_len = TEST_MIN_PWLEN;
  137. um0.usrmod0_max_passwd_age = TEST_MAX_PWAGE;
  138. um0.usrmod0_min_passwd_age = TEST_MIN_PWAGE;
  139. um0.usrmod0_force_logoff = TEST_FORCE_LOGOFF;
  140. um0.usrmod0_password_hist_len = TEST_MAX_PWHIST;
  141. //
  142. // set with valid level
  143. //
  144. if (err = NetUserModalsSet(server, 0, (LPBYTE) &um0, &ParmError ))
  145. error_exit(FAIL, "UserModalsSet invalid", NULL);
  146. else {
  147. error_exit( PASS, "NetUserModalsSet level 0 OK", NULL);
  148. //
  149. // verify set data
  150. //
  151. if (err = NetUserModalsGet(server, 0, (LPBYTE *) &um0p)) {
  152. error_exit(FAIL, "Verify UserModalsGet failed", NULL);
  153. } else {
  154. //
  155. // verify initial settings
  156. //
  157. TestDiffDword( "Min password test mismatch", NULL,
  158. um0p->usrmod0_min_passwd_len, TEST_MIN_PWLEN );
  159. TestDiffDword( "Max password age test mismatch", NULL,
  160. um0p->usrmod0_max_passwd_age, TEST_MAX_PWAGE );
  161. TestDiffDword( "Min password age test mismatch", NULL,
  162. um0p->usrmod0_min_passwd_age, TEST_MIN_PWAGE );
  163. TestDiffDword( "Force logooff test mismatch", NULL,
  164. um0p->usrmod0_force_logoff, TEST_FORCE_LOGOFF );
  165. TestDiffDword( "Password history length test mismatch", NULL,
  166. um0p->usrmod0_password_hist_len, TEST_MAX_PWHIST );
  167. NetApiBufferFree( um0p );
  168. }
  169. }
  170. //
  171. // attempt to restore original (default) settings
  172. //
  173. restore_original_modals( );
  174. }
  175. //
  176. // test_set_modals_1(parmnum)
  177. //
  178. void
  179. test_set_modals_1(parmnum)
  180. short parmnum;
  181. {
  182. PUSER_MODALS_INFO_0 um0p;
  183. USER_MODALS_INFO_1001 um1001;
  184. USER_MODALS_INFO_1002 um1002;
  185. USER_MODALS_INFO_1003 um1003;
  186. USER_MODALS_INFO_1004 um1004;
  187. USER_MODALS_INFO_1005 um1005;
  188. LPBYTE Parameter;
  189. LPWSTR LevelText;
  190. //
  191. // setup data for update
  192. //
  193. switch (parmnum) {
  194. case 1001:
  195. um1001.usrmod1001_min_passwd_len = TEST_MIN_PWLEN;
  196. LevelText = L"Parmnum 1001";
  197. Parameter = (LPBYTE) &um1001;
  198. break;
  199. case 1002:
  200. um1002.usrmod1002_max_passwd_age = TEST_MAX_PWAGE;
  201. LevelText = L"Parmnum 1002";
  202. Parameter = (LPBYTE) &um1002;
  203. break;
  204. case 1003:
  205. um1003.usrmod1003_min_passwd_age = TEST_MIN_PWAGE;
  206. LevelText = L"Parmnum 1003";
  207. Parameter = (LPBYTE) &um1003;
  208. break;
  209. case 1004:
  210. um1004.usrmod1004_force_logoff = TEST_FORCE_LOGOFF;
  211. LevelText = L"Parmnum 1004";
  212. Parameter = (LPBYTE) &um1004;
  213. break;
  214. case 1005:
  215. um1005.usrmod1005_password_hist_len = TEST_MAX_PWHIST;
  216. LevelText = L"Parmnum 1005";
  217. Parameter = (LPBYTE) &um1005;
  218. break;
  219. default:
  220. error_exit(FAIL, "Invalid parmnum internal error", NULL);
  221. return;
  222. }
  223. if (err = NetUserModalsSet(server, parmnum, Parameter, &ParmError)) {
  224. error_exit(FAIL, "UserModalsSet invalid", LevelText);
  225. } else {
  226. error_exit(PASS, "UserModalsSet successful", LevelText);
  227. //
  228. // verify set data
  229. //
  230. if (err = NetUserModalsGet(server, 0, (LPBYTE *) &um0p)) {
  231. error_exit(FAIL, "Verify UserModalsGet failed", NULL);
  232. } else {
  233. //
  234. // verify initial settings
  235. //
  236. switch (parmnum) {
  237. case 1001:
  238. TestDiffDword( "Min password test mismatch", LevelText,
  239. um0p->usrmod0_min_passwd_len, TEST_MIN_PWLEN );
  240. break;
  241. case 1002:
  242. TestDiffDword( "Max password age test mismatch", LevelText,
  243. um0p->usrmod0_max_passwd_age, TEST_MAX_PWAGE );
  244. break;
  245. case 1003:
  246. TestDiffDword( "Min password age test mismatch", LevelText,
  247. um0p->usrmod0_min_passwd_age, TEST_MIN_PWAGE );
  248. break;
  249. case 1004:
  250. TestDiffDword( "Force logooff test mismatch", LevelText,
  251. um0p->usrmod0_force_logoff, TEST_FORCE_LOGOFF );
  252. break;
  253. case 1005:
  254. TestDiffDword( "Password history length test mismatch", LevelText,
  255. um0p->usrmod0_password_hist_len, TEST_MAX_PWHIST );
  256. break;
  257. default:
  258. printf("uastest1:Invalid Parmnum %d\n", parmnum);
  259. }
  260. NetApiBufferFree( um0p );
  261. }
  262. }
  263. //
  264. // attempt to restore original (default) settings
  265. //
  266. restore_original_modals( );
  267. }
  268. void
  269. main(argc, argv)
  270. int argc;
  271. char **argv;
  272. {
  273. short i;
  274. testname = "UASTEST3";
  275. if (argv[1] != NULL)
  276. server = NetpLogonOemToUnicode(argv[1]);
  277. if (argc > 1)
  278. exit_flag = 1;
  279. #ifdef UASP_LIBRARY
  280. printf( "Calling UaspInitialize\n");
  281. if (err = UaspInitialize()) {
  282. error_exit(FAIL, "UaspInitiailize failed", NULL );
  283. }
  284. #endif // UASP_LIBRARY
  285. error_exit(ACTION, "test_init_modals()", NULL );
  286. test_init_modals();
  287. error_exit(ACTION, "test_set_modals()", NULL );
  288. test_set_modals();
  289. error_exit(ACTION, "test_set_modals_1()", NULL );
  290. for (i = 1001; i < 1005; i++) {
  291. test_set_modals_1(i);
  292. }
  293. }