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.

1585 lines
43 KiB

  1. ///**************************************************************
  2. /// Microsoft LAN Manager *
  3. /// Copyright(c) Microsoft Corp., 1990-92 *
  4. ///**************************************************************
  5. //
  6. // This program is designed to do functional testing on the following
  7. // APIs:
  8. // NetGroupAdd
  9. // NetGroupDel
  10. // NetGroupGetInfo
  11. // NetGroupSetInfo
  12. // NetGroupEnum
  13. // NetGroupAddUser
  14. // NetGroupDelUsers
  15. // NetGroupGetUsers
  16. // NetUserGetGroups
  17. // NetUserSetGroups
  18. //
  19. // Note: This assumes UASTEST1 was run previously which
  20. // leaves two users, User1 & User2, defined on the NET.ACC.
  21. //
  22. //
  23. #include <nt.h> // TIME definition
  24. #include <ntrtl.h> // TIME definition
  25. #include <nturtl.h> // TIME definition
  26. #define NOMINMAX // Avoid redefinition of min and max in stdlib.h
  27. #include <windef.h>
  28. #include <winbase.h>
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32. #include <lmcons.h>
  33. #include <lmapibuf.h>
  34. #include <netlib.h>
  35. #include <netdebug.h>
  36. #include <lmaccess.h>
  37. #include <lmerr.h>
  38. #include <ntsam.h>
  39. #include "uastest.h"
  40. #include "accessp.h"
  41. #include "netlogon.h"
  42. #include "logonp.h"
  43. #define GROUP1 L"GROUP1"
  44. #define GROUP2 L"GROUP2"
  45. #define GROUP3 L"GROUP3"
  46. #define GROUP4 L"GROUP4"
  47. #define GROUP_COMMENT L"This Group is added for demo"
  48. #define PARM_COMMENT L"This comment was added by SetInfo (level 1002)"
  49. #define DEFAULT_GROUP_ATTR ( SE_GROUP_MANDATORY | \
  50. SE_GROUP_ENABLED_BY_DEFAULT )
  51. #define GROUP_ATTR DEFAULT_GROUP_ATTR
  52. LPWSTR group[] = {
  53. GROUP1, GROUP2, GROUP3, GROUP4 };
  54. DWORD group_count;
  55. LPWSTR DefaultGroup;
  56. void
  57. clean_up()
  58. {
  59. PUSER_INFO_0 UserInfo0;
  60. PGROUP_INFO_0 GroupInfo0;
  61. int Failed = 0;
  62. //
  63. // Expects Only four groups to be present Group1 thru Group4
  64. //
  65. err = 0;
  66. if (err = NetGroupDel(server, GROUP1))
  67. if (err != NERR_GroupNotFound) {
  68. error_exit(
  69. FAIL, "Cleanup GroupDel wrong status",
  70. GROUP1 );
  71. Failed = 1;
  72. }
  73. err = 0;
  74. if (err = NetGroupDel(server, GROUP2))
  75. if (err != NERR_GroupNotFound) {
  76. error_exit(
  77. FAIL, "Cleanup GroupDel wrong status",
  78. GROUP2 );
  79. Failed = 1;
  80. }
  81. err = 0;
  82. if (err = NetGroupDel(server, GROUP3))
  83. if (err != NERR_GroupNotFound) {
  84. error_exit(
  85. FAIL, "Cleanup GroupDel wrong status",
  86. GROUP3 );
  87. Failed = 1;
  88. }
  89. err = 0;
  90. if (err = NetGroupDel(server, GROUP4))
  91. if (err != NERR_GroupNotFound) {
  92. error_exit(
  93. FAIL, "Cleanup GroupDel wrong status",
  94. GROUP4 );
  95. Failed = 1;
  96. }
  97. if (!Failed) {
  98. error_exit(PASS, "Successful clean up of groups", NULL );
  99. }
  100. //
  101. // count the existing number of Groups in the database
  102. //
  103. err = NetGroupEnum(server, 0, (LPBYTE *)&GroupInfo0, 0xffffffff,
  104. &nread, &total, NULL);
  105. if (err)
  106. error_exit(FAIL, "Initial Enumeration Failed", NULL);
  107. else
  108. group_count = total;
  109. (VOID)NetApiBufferFree( GroupInfo0 );
  110. //
  111. // also verify that USER1 and USER2 exist in database
  112. //
  113. if (err = NetUserGetInfo(server, USER1, 0, (LPBYTE *)&UserInfo0)) {
  114. exit_flag = 1;
  115. error_exit( FAIL, "Test aborted. user not in database",
  116. USER1 );
  117. } else {
  118. (VOID)NetApiBufferFree( UserInfo0 );
  119. }
  120. if (err = NetUserGetInfo(server, USER2, 0, (LPBYTE *)&UserInfo0)) {
  121. exit_flag = 1;
  122. error_exit( FAIL, "Test aborted. user not in database",
  123. USER2 );
  124. } else {
  125. (VOID)NetApiBufferFree( UserInfo0 );
  126. }
  127. }
  128. void
  129. add_group_l1(namep)
  130. LPWSTR namep;
  131. {
  132. GROUP_INFO_1 GroupInfo1;
  133. GroupInfo1.grpi1_name = namep;
  134. GroupInfo1.grpi1_comment = GROUP_COMMENT;
  135. if (err = NetGroupAdd(server, 1, (char * ) &GroupInfo1, NULL )) {
  136. error_exit(FAIL, "GroupAdd (level 1) failed", namep );
  137. } else {
  138. error_exit(PASS, "Group added successfully", namep);
  139. }
  140. }
  141. void
  142. add_group_l2(namep)
  143. LPWSTR namep;
  144. {
  145. GROUP_INFO_2 GroupInfo2;
  146. GroupInfo2.grpi2_name = namep;
  147. GroupInfo2.grpi2_comment = GROUP_COMMENT;
  148. GroupInfo2.grpi2_attributes = GROUP_ATTR;
  149. if (err = NetGroupAdd(server, 2, (char * ) &GroupInfo2, NULL )) {
  150. error_exit(FAIL, "GroupAdd (level 2) failed", namep );
  151. } else {
  152. error_exit(PASS, "Group added successfully", namep);
  153. }
  154. }
  155. void
  156. test_add_del()
  157. {
  158. GROUP_INFO_0 GroupInfo0;
  159. //
  160. // delete a non-existent group
  161. //
  162. if (err = NetGroupDel(server, GROUP1)) {
  163. if (err != NERR_GroupNotFound)
  164. error_exit(FAIL, "Delete of non-existent group wrong status",
  165. GROUP1 );
  166. else
  167. error_exit(PASS, "Delete of non-existent group denied",
  168. GROUP1 );
  169. err = 0;
  170. } else
  171. error_exit(FAIL, "Delete of non-existent group succeeded",
  172. GROUP1 );
  173. //
  174. // add group level 0
  175. //
  176. GroupInfo0.grpi0_name = GROUP1;
  177. if (err = NetGroupAdd(server, 0, (LPBYTE)&GroupInfo0, NULL))
  178. error_exit(FAIL, "Add of group (Level 0) failed", GROUP1 );
  179. else
  180. error_exit(PASS, "Group added successfully (level 0)", GROUP1);
  181. //
  182. // delete group added level 0
  183. //
  184. if (err = NetGroupDel(server, GROUP1))
  185. error_exit(FAIL, "Delete of group failed", GROUP1 );
  186. else
  187. error_exit(PASS, "Group deleted successfully", GROUP1 );
  188. //
  189. // add group level 1
  190. //
  191. error_exit(ACTION, "Try to Add group at Level 1", GROUP1 );
  192. add_group_l1(GROUP1);
  193. //
  194. // delete group added level 1
  195. //
  196. if (err = NetGroupDel(server, GROUP1))
  197. error_exit(FAIL, "Delete of group failed", GROUP1 );
  198. else
  199. error_exit(PASS, "group deleted successfully", GROUP1 );
  200. //
  201. // add group level 2
  202. //
  203. error_exit(ACTION, "Try to Add group at Level 2", GROUP1 );
  204. add_group_l2(GROUP1);
  205. //
  206. // delete group added level 2
  207. //
  208. if (err = NetGroupDel(server, GROUP1))
  209. error_exit(FAIL, "Delete of group failed", GROUP1 );
  210. else
  211. error_exit(PASS, "group deleted successfully", GROUP1 );
  212. //
  213. // add group 1 l0
  214. //
  215. GroupInfo0.grpi0_name = GROUP1;
  216. if (err = NetGroupAdd(server, 0, (LPBYTE)&GroupInfo0, NULL))
  217. error_exit(FAIL, "Second Add of group (level 0) failed", GROUP1 );
  218. else
  219. error_exit(PASS, "Group added successfully (level 0)", GROUP1 );
  220. //
  221. // add duplicate
  222. //
  223. if (err = NetGroupAdd(server, 0, (LPBYTE)&GroupInfo0, NULL)) {
  224. if (err != NERR_GroupExists)
  225. error_exit(FAIL, "Adding of duplicate group Wrong", GROUP1 );
  226. else {
  227. err = 0;
  228. error_exit(PASS, "Adding of Duplicate Group denied", GROUP1);
  229. }
  230. } else
  231. error_exit(FAIL, "Add of duplicate group succeeded", GROUP1 );
  232. //
  233. // add group 2 l0
  234. //
  235. GroupInfo0.grpi0_name = GROUP2;
  236. if (err = NetGroupAdd(server, 0, (LPBYTE)&GroupInfo0, NULL))
  237. error_exit(FAIL, "Second Add of group (level 0) failed", GROUP2);
  238. else
  239. error_exit(PASS, "Group added successfully (level 0)", GROUP2 );
  240. //
  241. // add group 3 l1
  242. //
  243. error_exit(ACTION, "Try to Add group at Level 1", GROUP3);
  244. add_group_l1(GROUP3);
  245. //
  246. // add group 4 l1
  247. //
  248. error_exit(ACTION, "Try to Add group at Level 1", GROUP4);
  249. add_group_l1(GROUP4);
  250. }
  251. //
  252. // set_info_l1 NetGroupSetInfo call on named group. First a
  253. // call is issued to a bogus group and then to
  254. // the requested group
  255. //
  256. void
  257. set_info_l1(namep)
  258. LPWSTR namep;
  259. {
  260. GROUP_INFO_1 GroupInfo1;
  261. GroupInfo1.grpi1_name = namep;
  262. GroupInfo1.grpi1_comment = namep;
  263. //
  264. // first attempt on an invalid group
  265. //
  266. err = NetGroupSetInfo(server, NOTTHERE, 1, (LPBYTE)&GroupInfo1, NULL );
  267. if (err == 0) {
  268. error_exit(FAIL, "SetInfo (Level 1) succeed on non-existent group",
  269. NULL );
  270. } else if (err != NERR_GroupNotFound) {
  271. error_exit(FAIL, "SetInfo (Level 1) on non-existent group wrong",
  272. NULL);
  273. } else {
  274. error_exit(PASS, "SetInfo (Level 1) denied on non-existent group",
  275. NULL );
  276. }
  277. if (_wcsicmp(NOTTHERE, namep) == 0)
  278. return;
  279. //
  280. // now attempt on a valid group
  281. //
  282. if (err = NetGroupSetInfo(server, namep, 1, (LPBYTE)&GroupInfo1, NULL )){
  283. error_exit(FAIL, "SetInfo (Level 1) failed", namep);
  284. } else
  285. error_exit(PASS, "SetInfo (Level 1) succeeded", namep);
  286. }
  287. //
  288. // set_info_l2 NetGroupSetInfo call on named group. First a
  289. // call is issued to a bogus group and then to
  290. // the requested group
  291. //
  292. void
  293. set_info_l2(namep)
  294. LPWSTR namep;
  295. {
  296. GROUP_INFO_2 GroupInfo2;
  297. GroupInfo2.grpi2_name = namep;
  298. GroupInfo2.grpi2_comment = namep;
  299. GroupInfo2.grpi2_attributes = GROUP_ATTR;
  300. //
  301. // first attempt on an invalid group
  302. //
  303. err = NetGroupSetInfo(server, NOTTHERE, 2, (LPBYTE)&GroupInfo2, NULL );
  304. if (err == 0) {
  305. error_exit(FAIL, "SetInfo (Level 2) succeed on non-existent group",
  306. NULL );
  307. } else if (err != NERR_GroupNotFound) {
  308. error_exit(FAIL, "SetInfo (Level 2) on non-existent group wrong",
  309. NULL);
  310. } else {
  311. error_exit(PASS, "SetInfo (Level 2) denied on non-existent group",
  312. NULL );
  313. }
  314. if (_wcsicmp(NOTTHERE, namep) == 0)
  315. return;
  316. //
  317. // now attempt on a valid group
  318. //
  319. if (err = NetGroupSetInfo(server, namep, 2, (LPBYTE)&GroupInfo2, NULL )){
  320. error_exit(FAIL, "SetInfo (Level 2) failed", namep);
  321. } else
  322. error_exit(PASS, "SetInfo (Level 2) succeeded", namep);
  323. }
  324. void
  325. set_group_comment(namep, buf)
  326. LPWSTR namep;
  327. LPWSTR buf;
  328. {
  329. GROUP_INFO_1002 GroupComment;
  330. GroupComment.grpi1002_comment = buf;
  331. if (err = NetGroupSetInfo(server, namep, 1002, (LPBYTE)&GroupComment,NULL)){
  332. error_exit(FAIL, "SetInfo (Level 1002) failed\n", namep);
  333. } else
  334. error_exit(PASS, "SetInfo (Level 1002) succeeded\n", namep);
  335. }
  336. void
  337. set_group_attributes(namep)
  338. LPWSTR namep;
  339. {
  340. GROUP_INFO_1005 GroupComment;
  341. GroupComment.grpi1005_attributes = GROUP_ATTR;
  342. if (err = NetGroupSetInfo(server, namep, 1005, (LPBYTE)&GroupComment,NULL)){
  343. error_exit(FAIL, "SetInfo (Level 1005) failed\n", namep);
  344. } else
  345. error_exit(PASS, "SetInfo (Level 1005) succeeded\n", namep);
  346. }
  347. //
  348. // verify_enum ACTION - Verify that NetGroupEnum (level 0/1) returned all
  349. // the special groups (USERS, ADMINS, GUESTS) and the
  350. // groups added for this test (GROUP1 - GROUP4).
  351. //
  352. void
  353. verify_enum(level, GroupEnum)
  354. short level;
  355. LPBYTE GroupEnum;
  356. {
  357. GROUP_INFO_0 *GroupInfo0;
  358. GROUP_INFO_1 *GroupInfo1;
  359. GROUP_INFO_2 *GroupInfo2;
  360. LPWSTR name;
  361. unsigned short found = 0;
  362. //
  363. // number of groups read should be group_count + 4 (added for this test)
  364. //
  365. if (nread != group_count + 4) {
  366. error_exit(FAIL, "Number of Groups read Incorrect", NULL );
  367. printf("UASTEST2: Read = %u Expected = %u\n", nread, group_count + 4);
  368. }
  369. if (total != group_count + 4) {
  370. error_exit(FAIL, "Total Number of Groups returned Incorrect",NULL);
  371. printf("UASTEST2: Total = %u Expected = %u\n", total, group_count + 4);
  372. }
  373. if ((nread == total) & (err == 0)) {
  374. if (level == 0)
  375. GroupInfo0 = (GROUP_INFO_0 * ) GroupEnum;
  376. else if (level == 1)
  377. GroupInfo1 = (GROUP_INFO_1 * ) GroupEnum;
  378. else
  379. GroupInfo2 = (GROUP_INFO_2 * ) GroupEnum;
  380. while (nread--) {
  381. if (level == 0)
  382. name = GroupInfo0->grpi0_name;
  383. else if (level == 1)
  384. name = GroupInfo1->grpi1_name;
  385. else
  386. name = GroupInfo2->grpi2_name;
  387. if ( (_wcsicmp(name, GROUP1) == 0) ||
  388. (_wcsicmp(name, GROUP2) == 0) ||
  389. (_wcsicmp(name, GROUP3) == 0) ||
  390. (_wcsicmp(name, GROUP4) == 0) ) {
  391. found++;
  392. error_exit(PASS, "Found group added for this test", name);
  393. }
  394. if (level == 0)
  395. GroupInfo0++;
  396. else if (level == 1)
  397. GroupInfo1++;
  398. else
  399. GroupInfo2++;
  400. }
  401. }
  402. if (found != 4)
  403. error_exit(FAIL, "Unable to find ALL 4 groups", NULL);
  404. else
  405. printf("UASTEST2: PASS - Found %u groups\n", found);
  406. }
  407. //
  408. // validate_enum_l0 NetGroupEnum at level 0
  409. //
  410. void
  411. validate_enum_l0()
  412. {
  413. PGROUP_INFO_0 GroupInfo0;
  414. if (err = NetGroupEnum(server, 0, (LPBYTE *)&GroupInfo0, 0xffffffff, &nread, &total, NULL ))
  415. error_exit(FAIL, "NetGroupEnum (Level 0) failed", NULL );
  416. else
  417. error_exit(PASS, "Successful enumeration (level 0) of groups",
  418. NULL);
  419. verify_enum(0, (LPBYTE)GroupInfo0);
  420. (VOID)NetApiBufferFree( GroupInfo0 );
  421. }
  422. //
  423. // validate_enum_l1 NetGroupEnum at level 1
  424. //
  425. void
  426. validate_enum_l1()
  427. {
  428. PGROUP_INFO_1 GroupInfo1;
  429. if (err = NetGroupEnum(server, 1, (LPBYTE *)&GroupInfo1, 0xffffffff, &nread, &total, NULL ))
  430. error_exit(FAIL, "NetGroupEnum (Level 1) failed", NULL);
  431. else
  432. error_exit(PASS, "NetGroupEnum (Level 1) succeeded", NULL);
  433. verify_enum(1, (LPBYTE)GroupInfo1);
  434. (VOID)NetApiBufferFree( GroupInfo1 );
  435. }
  436. //
  437. // validate_enum_l2 NetGroupEnum at level 2
  438. //
  439. void
  440. validate_enum_l2()
  441. {
  442. PGROUP_INFO_2 GroupInfo2;
  443. if (err = NetGroupEnum(server, 2, (LPBYTE *)&GroupInfo2, 0xffffffff, &nread, &total, NULL ))
  444. error_exit(FAIL, "NetGroupEnum (Level 2) failed", NULL);
  445. else
  446. error_exit(PASS, "NetGroupEnum (Level 2) succeeded", NULL);
  447. verify_enum(2, (LPBYTE)GroupInfo2);
  448. (VOID)NetApiBufferFree( GroupInfo2 );
  449. }
  450. void
  451. test_get_set_enum_info()
  452. {
  453. int i;
  454. PGROUP_INFO_0 GroupInfo0;
  455. PGROUP_INFO_1 GroupInfo1;
  456. PGROUP_INFO_2 GroupInfo2;
  457. //
  458. // get info for non-existent group
  459. //
  460. error_exit(ACTION, "Try GetInfo (Level 0) on Non-Existent Group", NULL);
  461. if (err = NetGroupGetInfo(server, NOTTHERE, 0, (LPBYTE *) &GroupInfo0)) {
  462. if (err != NERR_GroupNotFound)
  463. error_exit(FAIL, "GetInfo (Level 0) on non-existent group",
  464. NULL );
  465. else {
  466. err = 0;
  467. error_exit(
  468. PASS, "GetInfo (Level 0) on non-existent group denied",
  469. NULL );
  470. }
  471. } else {
  472. error_exit(FAIL, "GetInfo (Level 0) succeed on non-existent group",
  473. NULL );
  474. (VOID)NetApiBufferFree( GroupInfo0 );
  475. }
  476. //
  477. // get info group1 Level 0
  478. //
  479. error_exit(ACTION, "Try GetInfo (Level 0)", GROUP1);
  480. if (err = NetGroupGetInfo(server, GROUP1, 0, (LPBYTE * ) & GroupInfo0))
  481. error_exit(FAIL, "GroupGetInfo (Level 0) failed", GROUP1);
  482. else {
  483. error_exit(PASS, "GroupGetInfo (Level 0) succeeded", GROUP1);
  484. //
  485. // verify data from GetInfo
  486. //
  487. if (_wcsicmp(GROUP1, GroupInfo0->grpi0_name) != 0)
  488. error_exit(FAIL, "GroupGetInfo (Level 0) returned wrong name", GROUP1 );
  489. else
  490. error_exit(PASS, "Group name matched correctly", GROUP1);
  491. (VOID)NetApiBufferFree( GroupInfo0 );
  492. }
  493. //
  494. // get info group1 Level 1
  495. //
  496. error_exit(ACTION, "Try GetInfo (Level 1)", GROUP1);
  497. if (err = NetGroupGetInfo(server, GROUP1, 1, (LPBYTE *)&GroupInfo1))
  498. error_exit(FAIL, "GroupGetInfo (Level 1) failed", GROUP1);
  499. else {
  500. error_exit(PASS, "GroupGetInfo (Level 1) succeeded", GROUP1);
  501. //
  502. // verify data from GetInfo
  503. //
  504. if (_wcsicmp(GROUP1, GroupInfo1->grpi1_name) != 0)
  505. error_exit(FAIL, "GroupGetInfo (Level 1) returned wrong name",
  506. GROUP1);
  507. else
  508. error_exit(PASS, "Group name matched correctly", GROUP1);
  509. //
  510. // verify devault values
  511. //
  512. if (_wcsicmp(GroupInfo1->grpi1_comment, L"") != 0)
  513. error_exit(
  514. FAIL, "GroupGetInfo (Level 1) wrong default comment",
  515. GROUP1 );
  516. else
  517. error_exit(PASS, "Default Comment (\"\") matched correctly",
  518. GROUP1);
  519. (VOID)NetApiBufferFree( GroupInfo1 );
  520. }
  521. //
  522. // get info group1 Level 2
  523. //
  524. error_exit(ACTION, "Try GetInfo (Level 2)", GROUP1);
  525. if (err = NetGroupGetInfo(server, GROUP1, 2, (LPBYTE *)&GroupInfo2))
  526. error_exit(FAIL, "GroupGetInfo (Level 2) failed", GROUP1);
  527. else {
  528. error_exit(PASS, "GroupGetInfo (Level 2) succeeded", GROUP1);
  529. //
  530. // verify data from GetInfo
  531. //
  532. if (_wcsicmp(GROUP1, GroupInfo2->grpi2_name) != 0)
  533. error_exit(FAIL, "GroupGetInfo (Level 2) returned wrong name",
  534. GROUP1);
  535. else
  536. error_exit(PASS, "Group name matched correctly", GROUP1);
  537. //
  538. // verify default values
  539. //
  540. if (_wcsicmp(GroupInfo2->grpi2_comment, L"") != 0)
  541. error_exit(
  542. FAIL, "GroupGetInfo (Level 1) wrong default comment",
  543. GROUP1 );
  544. else
  545. error_exit(PASS, "Default Comment (\"\") matched correctly",
  546. GROUP1);
  547. if (GroupInfo2->grpi2_attributes != DEFAULT_GROUP_ATTR) {
  548. error_exit(
  549. FAIL, "GroupGetInfo (Level 2) wrong default attributes",
  550. GROUP1 );
  551. printf( "UASTEST2: FAIL - %ld should be %ld \n",
  552. GroupInfo2->grpi2_attributes, DEFAULT_GROUP_ATTR );
  553. } else {
  554. error_exit(PASS, "Default attributes matched correctly",
  555. GROUP1);
  556. }
  557. (VOID)NetApiBufferFree( GroupInfo2 );
  558. }
  559. //
  560. // get info group3 Level 1
  561. //
  562. error_exit(ACTION, "Try GetInfo (Level 1)", GROUP3);
  563. if (err = NetGroupGetInfo(server, GROUP3, 1, (LPBYTE *)&GroupInfo1))
  564. error_exit(FAIL, "GroupGetInfo (Level 1) failed", GROUP3);
  565. else {
  566. error_exit(PASS, "GroupGetInfo (Level 1) succeeded", GROUP3);
  567. //
  568. // verify set values
  569. //
  570. if (_wcsicmp(GroupInfo1->grpi1_name, GROUP3) != 0)
  571. error_exit(
  572. FAIL, "GroupGetInfo (Level 1) name mismatch",
  573. GROUP3);
  574. else {
  575. error_exit(PASS, "Group name matched correctly", GROUP3);
  576. }
  577. if (_wcsicmp(GroupInfo1->grpi1_comment, GROUP_COMMENT) != 0) {
  578. error_exit(FAIL, "GroupGetInfo (Level 1) comment mismatch",
  579. GROUP3);
  580. printf( "UASTEST2: FAIL - '" );
  581. PrintUnicode( GroupInfo1->grpi1_comment );
  582. printf("' should be '" );
  583. PrintUnicode( GROUP_COMMENT );
  584. printf( "'\n");
  585. } else
  586. error_exit(PASS, "Comment matched correctly", GROUP3);
  587. (VOID)NetApiBufferFree( GroupInfo1 );
  588. }
  589. //
  590. // set info on nonexistent
  591. //
  592. error_exit(ACTION, "Try SetInfo (Level 1) on Non-Existent Group",
  593. NULL);
  594. set_info_l1(NOTTHERE);
  595. //
  596. // set info group1
  597. //
  598. error_exit(ACTION, "Try SetInfo (Level 1)", GROUP1);
  599. set_info_l1(GROUP1);
  600. //
  601. // verify group1 setinfo
  602. //
  603. error_exit(ACTION, "Verify SetInfo results", GROUP1 );
  604. if (err = NetGroupGetInfo(server, GROUP1, 1, (LPBYTE *)&GroupInfo1))
  605. error_exit(FAIL, "Second GroupGetInfo (Level 1) failed", GROUP1);
  606. else {
  607. error_exit(PASS, "Second GroupGetInfo (Level 1) succeeded",GROUP1);
  608. //
  609. // verify devault values
  610. //
  611. if (_wcsicmp(GroupInfo1->grpi1_comment, GROUP1) != 0) {
  612. error_exit(FAIL, "comment mismatch", GROUP1);
  613. printf( "UASTEST2: FAIL - '" );
  614. PrintUnicode( GroupInfo1->grpi1_comment );
  615. printf("' should be '" );
  616. PrintUnicode( GROUP1 );
  617. printf( "'\n");
  618. } else
  619. error_exit(PASS, "Comment matched correctly", GROUP1);
  620. (VOID)NetApiBufferFree( GroupInfo1 );
  621. }
  622. //
  623. // set info group2 level 1
  624. //
  625. error_exit(ACTION, "Try SetInfo (Level 1)", GROUP2);
  626. set_info_l1(GROUP2);
  627. error_exit(ACTION, "Verify SetInfo results", GROUP2);
  628. //
  629. // verify group2 setinfo
  630. //
  631. if (err = NetGroupGetInfo(server, GROUP2, 1, (LPBYTE *)&GroupInfo1))
  632. error_exit(FAIL, "Second GroupGetInfo (Level 1) failed", GROUP2);
  633. else {
  634. error_exit(PASS, "Second GroupGetInfo (Level 1) succeeded",GROUP2);
  635. //
  636. // verify devault values
  637. //
  638. if (_wcsicmp(GroupInfo1->grpi1_comment, GROUP2) != 0) {
  639. error_exit(FAIL, "comment mismatch", GROUP2);
  640. printf( "UASTEST2: FAIL - '" );
  641. PrintUnicode( GroupInfo1->grpi1_comment );
  642. printf("' should be '" );
  643. PrintUnicode( GROUP2 );
  644. printf( "'\n");
  645. } else
  646. error_exit(PASS, "Comment matched correctly", GROUP2);
  647. (VOID)NetApiBufferFree( GroupInfo1 );
  648. }
  649. //
  650. // set info group2 level 2
  651. //
  652. error_exit(ACTION, "Try SetInfo (Level 2)", GROUP2);
  653. set_info_l2(GROUP2);
  654. error_exit(ACTION, "Verify SetInfo results", GROUP2);
  655. //
  656. // verify group2 setinfo level 2
  657. //
  658. if (err = NetGroupGetInfo(server, GROUP2, 2, (LPBYTE *)&GroupInfo2))
  659. error_exit(FAIL, "Second GroupGetInfo (Level 2) failed", GROUP2);
  660. else {
  661. error_exit(PASS, "Second GroupGetInfo (Level 2) succeeded",GROUP2);
  662. //
  663. // verify devault values
  664. //
  665. if (_wcsicmp(GroupInfo2->grpi2_comment, GROUP2) != 0) {
  666. error_exit(FAIL, "comment mismatch", GROUP2);
  667. printf( "UASTEST2: FAIL - '" );
  668. PrintUnicode( GroupInfo2->grpi2_comment );
  669. printf("' should be '" );
  670. PrintUnicode( GROUP2 );
  671. printf( "'\n");
  672. } else
  673. error_exit(PASS, "Comment matched correctly", GROUP2);
  674. if (GroupInfo2->grpi2_attributes != GROUP_ATTR)
  675. error_exit(
  676. FAIL, "GroupGetInfo (Level 2) wrong default attributes",
  677. GROUP2 );
  678. else
  679. error_exit(PASS, "Default attributes (\"\") matched correctly",
  680. GROUP2);
  681. (VOID)NetApiBufferFree( GroupInfo2 );
  682. }
  683. //
  684. // set comment using level 1002
  685. //
  686. set_group_comment(GROUP2, PARM_COMMENT);
  687. if (err = NetGroupGetInfo(server, GROUP2, 1, (LPBYTE *)&GroupInfo1))
  688. error_exit(FAIL, "Second GroupGetInfo (Level 1) failed", GROUP2);
  689. else {
  690. error_exit(PASS, "Second GroupGetInfo (Level 1) succeeded",GROUP2);
  691. //
  692. // verify devault values
  693. //
  694. if (_wcsicmp(GroupInfo1->grpi1_comment, PARM_COMMENT) != 0) {
  695. error_exit(FAIL, "comment mismatch", GROUP2);
  696. printf( "UASTEST2: FAIL - '" );
  697. PrintUnicode( GroupInfo1->grpi1_comment );
  698. printf("' should be '" );
  699. PrintUnicode( PARM_COMMENT );
  700. printf( "'\n");
  701. } else
  702. error_exit(PASS, "Second Comment matched correctly",GROUP2);
  703. (VOID)NetApiBufferFree( GroupInfo1 );
  704. }
  705. error_exit(ACTION, "Try SetInfo (Level 1002) on GROUP1 - GROUP4",NULL);
  706. for (i = 0; i < 4; i++)
  707. set_group_comment(group[i], group[i]);
  708. //
  709. // set group attributes using level 1005
  710. //
  711. set_group_attributes(GROUP2);
  712. if (err = NetGroupGetInfo(server, GROUP2, 2, (LPBYTE *)&GroupInfo2))
  713. error_exit(FAIL, "Second GroupGetInfo (Level 2) failed", GROUP2);
  714. else {
  715. error_exit(PASS, "Second GroupGetInfo (Level 2) succeeded",GROUP2);
  716. //
  717. // verify default values
  718. //
  719. if (GroupInfo2->grpi2_attributes != GROUP_ATTR) {
  720. error_exit(FAIL, "attributes mismatch", GROUP2);
  721. printf( "UASTEST2: FAIL - %ld should be %ld \n",
  722. GroupInfo2->grpi2_attributes, GROUP_ATTR );
  723. } else
  724. error_exit(PASS, "group attributes matched correctly",GROUP2);
  725. (VOID)NetApiBufferFree( GroupInfo2 );
  726. }
  727. error_exit(ACTION, "Try SetInfo (Level 1005) on GROUP1 - GROUP4",NULL);
  728. for (i = 0; i < 4; i++)
  729. set_group_attributes(group[i]);
  730. //
  731. // enum all level 0
  732. //
  733. error_exit(
  734. ACTION,
  735. "Enumerate Groups (Level 0) and find those added for test",
  736. NULL);
  737. validate_enum_l0();
  738. //
  739. // enum all level 1
  740. //
  741. error_exit(
  742. ACTION,
  743. "Enumerate Groups (Level 1) and find those added for test",
  744. NULL);
  745. validate_enum_l1();
  746. //
  747. // enum all level 2
  748. //
  749. error_exit(
  750. ACTION,
  751. "Enumerate Groups (Level 2) and find those added for test",
  752. NULL);
  753. validate_enum_l2();
  754. }
  755. //
  756. // test_group_users Test NetGroupSetUsers & NetGroupGetUsers
  757. //
  758. void
  759. test_group_users()
  760. {
  761. register int i;
  762. GROUP_USERS_INFO_0 gu0;
  763. GROUP_USERS_INFO_0 gu0Array[2];
  764. PGROUP_USERS_INFO_0 GroupUser0;
  765. PGROUP_USERS_INFO_1 GroupUser1;
  766. //
  767. // add non-exist user to group
  768. //
  769. gu0.grui0_name = NOTTHERE;
  770. if (err = NetGroupSetUsers(server, GROUP1, 0, (char * ) & gu0, 1)) {
  771. if (err != NERR_UserNotFound)
  772. error_exit(FAIL, "NetGroupSetUsers on non-existent user wrong",
  773. GROUP1 );
  774. else
  775. error_exit(PASS,
  776. "NetGroupSetUsers on non-existent user denied",
  777. GROUP1 );
  778. } else
  779. error_exit(FAIL, "NetGroupSetUsers on non-existent user succeded",
  780. GROUP1 );
  781. //
  782. // add user to non-exist group
  783. //
  784. gu0.grui0_name = USER1;
  785. if (err = NetGroupSetUsers(server, NOTTHERE, 0, (char * ) & gu0, 1)) {
  786. if (err != NERR_GroupNotFound)
  787. error_exit(FAIL, "NetGroupSetUsers on non-existent group wrong",
  788. NULL );
  789. else
  790. error_exit(PASS, "NetGroupSetUsers on non-existent group denied",
  791. NULL );
  792. } else
  793. error_exit(FAIL, "NetGroupSetUsers on non-existent group succeded",
  794. NULL );
  795. //
  796. // add user to group1
  797. //
  798. gu0.grui0_name = USER1;
  799. if (err = NetGroupSetUsers(server, GROUP1, 0, (char * ) & gu0, 1))
  800. error_exit(FAIL, "NetGroupSetUsers unable to add USER1 to GROUP1", NULL );
  801. else
  802. error_exit(PASS, "NetGroupSetUsers added USER1 to GROUP1 successfully", NULL );
  803. //
  804. // getuser non-exist group
  805. //
  806. if (err = NetGroupGetUsers(server, NOTTHERE, 0, (LPBYTE *)&GroupUser0,
  807. 0xffffffff, &nread, &total, NULL)) {
  808. if (err != NERR_GroupNotFound)
  809. error_exit(FAIL, "NetGroupGetUsers on non-existent group wrong", NULL );
  810. else
  811. error_exit(PASS, "NetGroupGetUsers on non-existent group denied", NULL );
  812. } else {
  813. error_exit(FAIL, "NetGroupGetUsers on non-existent group succeded", NULL );
  814. (VOID)NetApiBufferFree( GroupUser0 );
  815. }
  816. //
  817. // getuser on group2 with no user
  818. //
  819. if (err = NetGroupGetUsers(server, GROUP2, 0, (LPBYTE *)&GroupUser0,
  820. 0xffffffff, &nread, &total, NULL))
  821. error_exit(FAIL, "NetGroupGetUsers on group with no users failed",
  822. GROUP2 );
  823. else {
  824. error_exit(PASS, "NetGroupGetUsers on group with no users succeded",
  825. GROUP2 );
  826. if ((nread != total) || (nread != 0))
  827. error_exit(
  828. FAIL, "NetGroupGetUsers returned non-zero number of users",
  829. GROUP2);
  830. else
  831. error_exit(
  832. PASS, "NetGroupGetUsers returned zero number of users",
  833. GROUP2);
  834. (VOID)NetApiBufferFree( GroupUser0 );
  835. }
  836. //
  837. // getuser on group1 with user
  838. //
  839. if (err = NetGroupGetUsers(server, GROUP1, 0, (LPBYTE *)&GroupUser0,
  840. 0xffffffff, &nread, &total, NULL ))
  841. error_exit(FAIL, "NetGroupGetUsers on group with users failed",
  842. GROUP1);
  843. else {
  844. error_exit(PASS, "NetGroupGetUsers on group with users succeded",
  845. GROUP1);
  846. if ((nread != total) || (nread != 1)) {
  847. printf( "nread: %ld total: %ld\n", nread, total );
  848. error_exit(
  849. FAIL, "NetGroupGetUsers returned wrong number of users",
  850. GROUP1);
  851. } else
  852. error_exit(
  853. PASS, "NetGroupGetUsers returned correct number of users",
  854. GROUP1);
  855. if ( nread > 0 ) {
  856. if (_wcsicmp( GroupUser0->grui0_name, USER1) != 0)
  857. error_exit(FAIL, "NetGroupGetUsers returned wrong user",
  858. GROUP1);
  859. else
  860. error_exit(
  861. PASS, "NetGroupGetUsers returned USER1 (correct user)",
  862. GROUP1);
  863. }
  864. (VOID)NetApiBufferFree( GroupUser0 );
  865. }
  866. //
  867. // getuser on group1 with user level 1
  868. //
  869. if (err = NetGroupGetUsers(server, GROUP1, 1, (LPBYTE *)&GroupUser1,
  870. 0xffffffff, &nread, &total, NULL ))
  871. error_exit(FAIL, "NetGroupGetUsers on group with users failed",
  872. GROUP1);
  873. else {
  874. error_exit(PASS, "NetGroupGetUsers on group with users succeded",
  875. GROUP1);
  876. if ((nread != total) || (nread != 1)) {
  877. printf( "nread: %ld total: %ld\n", nread, total );
  878. error_exit(
  879. FAIL, "NetGroupGetUsers returned wrong number of users",
  880. GROUP1);
  881. } else
  882. error_exit(
  883. PASS, "NetGroupGetUsers returned correct number of users",
  884. GROUP1);
  885. if ( nread > 0 ) {
  886. if (_wcsicmp( GroupUser1->grui1_name, USER1) != 0)
  887. error_exit(FAIL, "NetGroupGetUsers returned wrong user",
  888. GROUP1);
  889. else
  890. error_exit(
  891. PASS, "NetGroupGetUsers returned USER1 (correct user)",
  892. GROUP1);
  893. }
  894. (VOID)NetApiBufferFree( GroupUser1 );
  895. }
  896. //
  897. // delete user from group
  898. //
  899. if (err = NetGroupDelUser(server, GROUP1, USER1))
  900. error_exit(FAIL, "NetGroupDelUser (USER1, GROUP1) failed", NULL);
  901. else
  902. error_exit(
  903. PASS, "NetGroupDelUser deleted USER1 from GROUP1 successfully",
  904. NULL);
  905. //
  906. // verify delete of user
  907. //
  908. if (err = NetGroupGetUsers(server, GROUP1, 0, (LPBYTE *)&GroupUser0,
  909. 0xffffffff, &nread, &total, NULL ))
  910. error_exit(FAIL, "NetGroupGetUsers failed", GROUP1 );
  911. else {
  912. if ((nread != total) && (nread != 0))
  913. error_exit(FAIL, "NetGroupGetUsers returned non-zero",GROUP1);
  914. (VOID)NetApiBufferFree( GroupUser0 );
  915. }
  916. //
  917. // add all users (USER1 and USER2) to all groups
  918. //
  919. for (i = 0; i < 4; i++) {
  920. gu0Array[0].grui0_name = USER1;
  921. gu0Array[1].grui0_name = USER2;
  922. if (err = NetGroupSetUsers(server, group[i], 0, (char * ) gu0Array, 2))
  923. error_exit(FAIL, "Adding of USER1 and USER2 as member", group[i]);
  924. else
  925. error_exit(PASS, "USER1 and USER2 added to as member successfully",
  926. group[i]);
  927. }
  928. //
  929. // verify for one group
  930. //
  931. if (err = NetGroupGetUsers(server, GROUP1, 0, (LPBYTE *)&GroupUser0,
  932. 0xffffffff, &nread, &total, NULL))
  933. error_exit(FAIL, "NetGroupGetUsers after mass add failed", GROUP1);
  934. else {
  935. PGROUP_USERS_INFO_0 TempGroupUser0;
  936. error_exit(PASS, "NetGroupGetUsers after mass add succeeded",
  937. GROUP1);
  938. if ((nread != total) || (nread != 2)) {
  939. printf( "nread: %ld total: %ld\n", nread, total );
  940. error_exit(
  941. FAIL, "NetGroupGetUsers after mass add wrong # of users",
  942. GROUP1 );
  943. }
  944. TempGroupUser0 = GroupUser0;
  945. if (_wcsicmp(TempGroupUser0->grui0_name, USER1) == 0) {
  946. TempGroupUser0++;
  947. if (nread < 2 || _wcsicmp(TempGroupUser0->grui0_name, USER2) != 0)
  948. error_exit(
  949. FAIL, "NetGroupGetUsers after mass add missing USER2",
  950. GROUP1);
  951. else
  952. error_exit(PASS, "Found both USER1 and USER2", GROUP1);
  953. } else if (_wcsicmp(TempGroupUser0->grui0_name, USER2) == 0) {
  954. TempGroupUser0++;
  955. if (nread < 2 || _wcsicmp(TempGroupUser0->grui0_name, USER1) != 0)
  956. error_exit(
  957. FAIL, "NetGroupGetUsers after mass add missing USER1",
  958. GROUP1 );
  959. else
  960. error_exit(PASS, "Found both USER1 and USER2",
  961. GROUP1);
  962. } else {
  963. error_exit(
  964. FAIL, "NetGroupGetUsers after mass add incorrect users returned",
  965. GROUP1);
  966. }
  967. (VOID)NetApiBufferFree( GroupUser0 );
  968. }
  969. }
  970. //
  971. // verfiy_ul0 verify the information returned by NetUserGetGroups
  972. //
  973. void
  974. verify_ul0(
  975. PGROUP_INFO_0 GroupInfo0
  976. )
  977. {
  978. LPWSTR name;
  979. unsigned short found = 0;
  980. if (nread != 5) {
  981. printf("UASTEST2: FAIL - Incorrect number of users read %ld s.b. 5\n",
  982. nread );
  983. TEXIT;
  984. }
  985. if (total != 5) {
  986. printf("UASTEST2: FAIL - Incorrect total number of users returned %ld s.b. 5\n", total );
  987. TEXIT;
  988. }
  989. //
  990. // note that USER1 must have been added with USER privs hence
  991. // it will be member of USER group as well as GROUP1 thru GROUP4
  992. // since that was done in previous test
  993. //
  994. // Note: "Users" is spelled "None" on a workstation.
  995. //
  996. if ((nread == total) && (err == 0)) {
  997. while (nread--) {
  998. if (_wcsicmp(GroupInfo0->grpi0_name, DefaultGroup ) == 0 ) {
  999. printf("UASTEST2: Found membership in automatic group %ws\n",
  1000. DefaultGroup );
  1001. found++;
  1002. } else {
  1003. name = GroupInfo0->grpi0_name;
  1004. if ( (_wcsicmp(name, GROUP1) == 0) ||
  1005. (_wcsicmp(name, GROUP2) == 0) ||
  1006. (_wcsicmp(name, GROUP3) == 0) ||
  1007. (_wcsicmp(name, GROUP4) == 0) ) {
  1008. found++;
  1009. error_exit(PASS, "Found group added for this test", name);
  1010. }
  1011. }
  1012. GroupInfo0++;
  1013. }
  1014. }
  1015. if (found != 5)
  1016. error_exit(FAIL, "Unable to find ALL 5 Groups", NULL );
  1017. else
  1018. printf("UASTEST2: PASS - Found %u groups\n", found);
  1019. }
  1020. //
  1021. // verfiy_ul1 verify the information returned by NetUserGetGroups
  1022. //
  1023. void
  1024. verify_ul1(
  1025. PGROUP_INFO_1 GroupInfo1
  1026. )
  1027. {
  1028. LPWSTR name;
  1029. unsigned short found = 0;
  1030. if (nread != 5) {
  1031. printf("UASTEST2: FAIL - Incorrect number of users read\n");
  1032. TEXIT;
  1033. }
  1034. if (total != 5) {
  1035. printf("UASTEST2: FAIL - Incorrect total number of users returned\n");
  1036. TEXIT;
  1037. }
  1038. //
  1039. // note that USER1 must have been added with USERS privs hence
  1040. // it will be member of USERS group as well as GROUP1 thru GROUP4
  1041. // since that was done in previous test
  1042. //
  1043. if ((nread == total) && (err == 0)) {
  1044. while (nread--) {
  1045. if (_wcsicmp(GroupInfo1->grpi1_name, DefaultGroup) == 0) {
  1046. printf("UASTEST2: Found membership in automatic group %ws\n",
  1047. DefaultGroup );
  1048. found++;
  1049. } else {
  1050. name = GroupInfo1->grpi1_name;
  1051. if ( (_wcsicmp(name, GROUP1) == 0) ||
  1052. (_wcsicmp(name, GROUP2) == 0) ||
  1053. (_wcsicmp(name, GROUP3) == 0) ||
  1054. (_wcsicmp(name, GROUP4) == 0) ) {
  1055. found++;
  1056. error_exit(PASS, "Found group added for this test", name);
  1057. }
  1058. }
  1059. GroupInfo1++;
  1060. }
  1061. }
  1062. if (found != 5)
  1063. error_exit(FAIL, "Unable to find ALL 5 Groups", NULL );
  1064. else
  1065. printf("UASTEST2: PASS - Found %u groups\n", found);
  1066. }
  1067. //
  1068. // verify_del_user verifies the buffer returned by NetUserGetGroups
  1069. // after NetGroupDelUser calls
  1070. //
  1071. void
  1072. verify_del_l0(
  1073. PGROUP_INFO_0 GroupInfo0
  1074. )
  1075. {
  1076. if (nread != 1) {
  1077. printf("UASTEST2: Incorrect number of users read\n");
  1078. TEXIT;
  1079. }
  1080. if (total != 1) {
  1081. printf("UASTEST2: Incorrect total number of users returned\n");
  1082. TEXIT;
  1083. }
  1084. if ((nread == 1) && (total == 1) && (err == 0)) {
  1085. if (_wcsicmp(GroupInfo0->grpi0_name, DefaultGroup ) == 0) {
  1086. printf(
  1087. "UASTEST2: PASS - Automatic membership in %ws confirmed\n",
  1088. DefaultGroup );
  1089. } else {
  1090. error_exit(FAIL, "Invalid membership in group\n",
  1091. GroupInfo0->grpi0_name);
  1092. }
  1093. }
  1094. }
  1095. //
  1096. // test_user_group Test NetUserGetGroups & NetUserSetGroups
  1097. //
  1098. void
  1099. test_user_group()
  1100. {
  1101. GROUP_INFO_0 GroupInfo0[5];
  1102. PGROUP_INFO_0 GroupInfo0Ret;
  1103. PGROUP_INFO_1 GroupInfo1Ret;
  1104. //
  1105. // get groups on invalid user
  1106. //
  1107. if (err = NetUserGetGroups(server, NOTTHERE, 0, (LPBYTE *)&GroupInfo0Ret,
  1108. 0xffffffff, &nread, &total)) {
  1109. if (err != NERR_UserNotFound)
  1110. error_exit(
  1111. FAIL, "NetUserGetGroups for non-existent user wrong",
  1112. NULL );
  1113. else
  1114. error_exit(
  1115. PASS, "NetUserGetGroups for non-existent user denied",
  1116. NULL );
  1117. } else {
  1118. error_exit(
  1119. FAIL, "NetUserGetGroups succeeded for non-existent user",
  1120. NULL );
  1121. (VOID)NetApiBufferFree( GroupInfo0Ret );
  1122. }
  1123. //
  1124. // get groups for user1 level 0
  1125. //
  1126. if (err = NetUserGetGroups(server, USER1, 0, (LPBYTE *)&GroupInfo0Ret,
  1127. 0xffffffff, &nread, &total))
  1128. error_exit(FAIL, "NetUserGetGroups failed (level 0)", USER1 );
  1129. else {
  1130. error_exit(PASS, "NetUserGetGroups succeeded (level 0)", USER1 );
  1131. error_exit(ACTION, "Verify results of NetUserGetGroups (level 0)", USER1);
  1132. verify_ul0( GroupInfo0Ret );
  1133. (VOID)NetApiBufferFree( GroupInfo0Ret );
  1134. }
  1135. //
  1136. // get groups for user1 level 1
  1137. //
  1138. if (err = NetUserGetGroups(server, USER1, 1, (LPBYTE *)&GroupInfo1Ret,
  1139. 0xffffffff, &nread, &total))
  1140. error_exit(FAIL, "NetUserGetGroups failed (level 1)", USER1 );
  1141. else {
  1142. error_exit(PASS, "NetUserGetGroups succeeded (level 1)", USER1 );
  1143. error_exit(ACTION, "Verify results of NetUserGetGroups (level 1)", USER1);
  1144. verify_ul1( GroupInfo1Ret );
  1145. (VOID)NetApiBufferFree( GroupInfo1Ret );
  1146. }
  1147. //
  1148. // delete user from groups
  1149. //
  1150. if (err = NetGroupDelUser(server, GROUP1, USER1))
  1151. error_exit(
  1152. FAIL, "NetGroupDelUser unable to delete USER1 from GROUP1",
  1153. GROUP1 );
  1154. else
  1155. error_exit(
  1156. PASS, "NetGroupDelUser successfully deleted USER1 from GROUP1",
  1157. GROUP1);
  1158. if (err = NetGroupDelUser(server, GROUP2, USER1))
  1159. error_exit(
  1160. FAIL, "NetGroupDelUser unable to delete USER1 from GROUP2",
  1161. GROUP2 );
  1162. else
  1163. error_exit(
  1164. PASS, "NetGroupDelUser successfully deleted USER1 from GROUP2",
  1165. GROUP2 );
  1166. if (err = NetGroupDelUser(server, GROUP3, USER1))
  1167. error_exit(
  1168. FAIL, "NetGroupDelUser unable to delete USER1 from GROUP3",
  1169. GROUP3 );
  1170. else
  1171. error_exit(
  1172. PASS, "NetGroupDelUser successfully deleted USER1 from GROUP3",
  1173. GROUP3 );
  1174. if (err = NetGroupDelUser(server, GROUP4, USER1))
  1175. error_exit(
  1176. FAIL, "NetGroupDelUser unable to delete USER1 from GROUP4",
  1177. GROUP4 );
  1178. else
  1179. error_exit(
  1180. PASS, "NetGroupDelUser successfully deleted USER1 from GROUP4",
  1181. GROUP4 );
  1182. //
  1183. // get groups for user1
  1184. //
  1185. if (err = NetUserGetGroups(server, USER1, 0, (LPBYTE *)&GroupInfo0Ret,
  1186. 0xffffffff, &nread, &total))
  1187. error_exit(
  1188. FAIL, "NetUserGetGroups for USER1 failed", USER1 );
  1189. else {
  1190. error_exit(PASS, "NetUserGetGroups for USER1 succeeded", USER1 );
  1191. error_exit(ACTION, "Verify results after NetGroupDelUser", USER1);
  1192. verify_del_l0( GroupInfo0Ret );
  1193. (VOID)NetApiBufferFree( GroupInfo0Ret );
  1194. }
  1195. //
  1196. // set groups for invalid user
  1197. //
  1198. GroupInfo0[0].grpi0_name = GROUP1;
  1199. GroupInfo0[1].grpi0_name = GROUP2;
  1200. GroupInfo0[2].grpi0_name = GROUP3;
  1201. GroupInfo0[3].grpi0_name = GROUP4;
  1202. if (err = NetUserSetGroups(server, NOTTHERE, 0, (LPBYTE)&GroupInfo0, 4 )) {
  1203. if (err != NERR_UserNotFound)
  1204. error_exit(
  1205. FAIL, "NetUserSetGroups for non-existent user wrong",
  1206. NULL );
  1207. else
  1208. error_exit(
  1209. PASS, "NetUserSetGroups for non-existent user denied",
  1210. NULL );
  1211. } else
  1212. error_exit(
  1213. FAIL, "NetUserSetGroups for non-existent user succeeded",
  1214. NULL );
  1215. //
  1216. // set groups for valid user
  1217. //
  1218. GroupInfo0[0].grpi0_name = GROUP1;
  1219. GroupInfo0[1].grpi0_name = GROUP2;
  1220. GroupInfo0[2].grpi0_name = GROUP3;
  1221. GroupInfo0[3].grpi0_name = GROUP4;
  1222. GroupInfo0[4].grpi0_name = DefaultGroup;
  1223. if (err = NetUserSetGroups(server, USER1, 0, (LPBYTE)&GroupInfo0, 5 )) {
  1224. error_exit(FAIL, "NetUserSetGroups for USER1 failed", NULL );
  1225. } else
  1226. error_exit(PASS, "NetUserSetGroups for USER1 succeeded", NULL );
  1227. //
  1228. // verify set of groups
  1229. //
  1230. if (err = NetUserGetGroups(server, USER1, 0, (LPBYTE *)&GroupInfo0Ret,
  1231. 0xffffffff, &nread, &total))
  1232. error_exit(FAIL, "NetUserGetGroups for USER1 failed", NULL );
  1233. else {
  1234. error_exit(PASS, "NetUserGetGroups for USER1 succeeded", NULL );
  1235. printf("UASTEST2: Verify results of NetUserSetGroups on USER1\n");
  1236. verify_ul0( GroupInfo0Ret );
  1237. (VOID)NetApiBufferFree( GroupInfo0Ret );
  1238. }
  1239. }
  1240. void
  1241. main(argc, argv)
  1242. int argc;
  1243. char **argv;
  1244. {
  1245. NT_PRODUCT_TYPE NtProductType;
  1246. testname = "UASTEST2";
  1247. if (argv[1] != NULL)
  1248. server = NetpLogonOemToUnicode(argv[1]);
  1249. if (argc > 1)
  1250. exit_flag = 1;
  1251. //
  1252. // On WinNt, a user is added to group "None" by default.
  1253. // On LanManNt, a user is added to group "Users" by default.
  1254. //
  1255. if ( RtlGetNtProductType( &NtProductType ) ) {
  1256. if ( NtProductType == NtProductLanManNt ) {
  1257. DefaultGroup = L"Users";
  1258. } else {
  1259. DefaultGroup = L"None";
  1260. }
  1261. } else {
  1262. printf("UASTEST2: FAIL: cannot determine product type\n");
  1263. DefaultGroup = L"None";
  1264. }
  1265. #ifdef UASP_LIBRARY
  1266. printf( "Calling UaspInitialize\n");
  1267. if (err = UaspInitialize()) {
  1268. error_exit( FAIL, "UaspInitiailize failed", NULL );
  1269. }
  1270. #endif // UASP_LIBRARY
  1271. printf("\n");
  1272. printf("******** Starting UASTEST2: NetGroup API tests ********\n");
  1273. clean_up();
  1274. printf("UASTEST2: test_add_del() ... started\n");
  1275. test_add_del();
  1276. printf("UASTEST2: test_get_set_enum_info() ... started\n");
  1277. test_get_set_enum_info();
  1278. printf("UASTEST2: test_group_users() ... started\n");
  1279. test_group_users();
  1280. printf("UASTEST2: test_user_group() ... started\n");
  1281. test_user_group();
  1282. printf("******** Completed UASTEST2: NetGroup API tests ********\n");
  1283. printf("\n");
  1284. }