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.

476 lines
9.4 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. repltest.c
  5. Abstract:
  6. List user objects from SAM database. Used to verify SAM
  7. replication.
  8. Author:
  9. Cliff Van Dyke (cliffv) 26-Mar-1991
  10. Environment:
  11. User mode only.
  12. Contains NT-specific code.
  13. Requires ANSI C extensions: slash-slash comments, long external names.
  14. Revision History:
  15. --*/
  16. #include <nt.h>
  17. #include <ntrtl.h>
  18. #include <nturtl.h>
  19. #include <windef.h>
  20. #include <winbase.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <lmcons.h>
  25. #include <lmapibuf.h>
  26. #include <netlib.h>
  27. #include <netdebug.h>
  28. #include <lmaccess.h>
  29. #include <lmerr.h>
  30. #include <ntsam.h>
  31. #include "accessp.h"
  32. #include "netlogon.h"
  33. #include "logonp.h"
  34. NET_API_STATUS
  35. Print_UserInfo3(
  36. LPWSTR UserName
  37. )
  38. /*++
  39. Routine Description:
  40. Prints out the user information at level 3.
  41. Arguments:
  42. UserName : Name of the user.
  43. Return Value:
  44. Net access API error code.
  45. --*/
  46. {
  47. NET_API_STATUS NetStatus;
  48. PUSER_INFO_3 UserInfo3;
  49. //
  50. // get user info
  51. //
  52. NetStatus = NetUserGetInfo(
  53. NULL,
  54. UserName,
  55. 3,
  56. (LPBYTE *)&UserInfo3
  57. );
  58. if( NetStatus != NERR_Success ) {
  59. return( NetStatus );
  60. }
  61. //
  62. // print out user info
  63. //
  64. printf( "name : %ws \n", UserInfo3->usri3_name);
  65. // printf( "password : %ws \n", UserInfo3->usri3_password);
  66. printf( "password_age : %d \n", UserInfo3->usri3_password_age);
  67. printf( "priv : %d \n", UserInfo3->usri3_priv);
  68. printf( "home_dir : %ws \n", UserInfo3->usri3_home_dir);
  69. printf( "comment : %ws \n", UserInfo3->usri3_comment);
  70. printf( "flags : %d \n", UserInfo3->usri3_flags);
  71. printf( "script_path : %ws \n", UserInfo3->usri3_script_path);
  72. printf( "auth_flags : %d \n", UserInfo3->usri3_auth_flags);
  73. printf( "full_name : %ws \n", UserInfo3->usri3_full_name);
  74. printf( "usr_comment : %ws \n", UserInfo3->usri3_usr_comment);
  75. printf( "parms : %ws \n", UserInfo3->usri3_parms);
  76. printf( "workstations : %ws \n", UserInfo3->usri3_workstations);
  77. printf( "last_logon : %d \n", UserInfo3->usri3_last_logon);
  78. printf( "last_logoff : %d \n", UserInfo3->usri3_last_logoff);
  79. printf( "acct_expires : %d \n", UserInfo3->usri3_acct_expires);
  80. printf( "max_storage : %d \n", UserInfo3->usri3_max_storage);
  81. printf( "units_per_week : %d \n", UserInfo3->usri3_units_per_week);
  82. printf( "logon_hours : %ws \n", UserInfo3->usri3_logon_hours);
  83. printf( "bad_pw_count : %d \n", UserInfo3->usri3_bad_pw_count);
  84. printf( "num_logons : %d \n", UserInfo3->usri3_num_logons);
  85. printf( "logon_server : %ws \n", UserInfo3->usri3_logon_server);
  86. printf( "country_code : %d \n", UserInfo3->usri3_country_code);
  87. printf( "code_page : %d \n", UserInfo3->usri3_code_page);
  88. printf( "user_id : %d \n", UserInfo3->usri3_user_id);
  89. printf( "primary_group_i: %d \n", UserInfo3->usri3_primary_group_id);
  90. printf( "profile : %ws \n", UserInfo3->usri3_profile);
  91. printf( "home_dir_drive : %ws \n", UserInfo3->usri3_home_dir_drive);
  92. (VOID) NetApiBufferFree( UserInfo3 );
  93. return( NetStatus );
  94. }
  95. NET_API_STATUS
  96. Print_GroupInfo2(
  97. LPWSTR GroupName
  98. )
  99. /*++
  100. Routine Description:
  101. Prints out the group information at level 2.
  102. Arguments:
  103. GroupName : Name of the group.
  104. Return Value:
  105. Net access API error code.
  106. --*/
  107. {
  108. NET_API_STATUS NetStatus;
  109. PGROUP_INFO_2 GroupInfo2;
  110. //
  111. // get group info
  112. //
  113. NetStatus = NetGroupGetInfo(
  114. NULL,
  115. GroupName,
  116. 2,
  117. (LPBYTE *)&GroupInfo2
  118. );
  119. if( NetStatus != NERR_Success ) {
  120. return( NetStatus );
  121. }
  122. printf( "name : %ws \n", GroupInfo2->grpi2_name);
  123. printf( "comment : %ws \n", GroupInfo2->grpi2_comment);
  124. printf( "group_id : %d \n", GroupInfo2->grpi2_group_id);
  125. printf( "attributes : %d \n", GroupInfo2->grpi2_attributes);
  126. (VOID) NetApiBufferFree( GroupInfo2 );
  127. return( NetStatus );
  128. }
  129. NET_API_STATUS
  130. Print_ModalsInfo(
  131. )
  132. /*++
  133. Routine Description:
  134. Prints out the modals information.
  135. Arguments:
  136. None.
  137. Return Value:
  138. Net access API error code.
  139. --*/
  140. {
  141. NET_API_STATUS NetStatus;
  142. PUSER_MODALS_INFO_0 ModalsInfo0;
  143. PUSER_MODALS_INFO_1 ModalsInfo1;
  144. PUSER_MODALS_INFO_2 ModalsInfo2;
  145. //
  146. // get modals info 0
  147. //
  148. NetStatus = NetUserModalsGet(
  149. NULL,
  150. 0,
  151. (LPBYTE *)&ModalsInfo0
  152. );
  153. if( NetStatus != NERR_Success ) {
  154. return( NetStatus );
  155. }
  156. printf( "Modals Info \n\n" );
  157. printf( "min_passwd_len : %d \n", ModalsInfo0->usrmod0_min_passwd_len);
  158. printf( "max_passwd_age : %d \n", ModalsInfo0->usrmod0_max_passwd_age);
  159. printf( "min_passwd_age : %d \n", ModalsInfo0->usrmod0_min_passwd_age);
  160. printf( "force_logoff : %d \n", ModalsInfo0->usrmod0_force_logoff);
  161. printf( "password_hist_len: %d \n", ModalsInfo0->usrmod0_password_hist_len);
  162. //
  163. // get modals info 1
  164. //
  165. NetStatus = NetUserModalsGet(
  166. NULL,
  167. 1,
  168. (LPBYTE *)&ModalsInfo1
  169. );
  170. if( NetStatus != NERR_Success ) {
  171. return( NetStatus );
  172. }
  173. printf( "role : %d \n", ModalsInfo1->usrmod1_role);
  174. printf( "primary : %ws \n", ModalsInfo1->usrmod1_primary);
  175. //
  176. // get modals info 2
  177. //
  178. NetStatus = NetUserModalsGet(
  179. NULL,
  180. 2,
  181. (LPBYTE *)&ModalsInfo2
  182. );
  183. if( NetStatus != NERR_Success ) {
  184. return( NetStatus );
  185. }
  186. printf( "domain_name : %ws \n", ModalsInfo2->usrmod2_domain_name);
  187. printf( "domain_id : %d \n", ModalsInfo2->usrmod2_domain_id);
  188. printf("--------------------------------\n\n");
  189. (VOID) NetApiBufferFree( ModalsInfo0 );
  190. (VOID) NetApiBufferFree( ModalsInfo1 );
  191. (VOID) NetApiBufferFree( ModalsInfo2 );
  192. return( NetStatus );
  193. }
  194. NET_API_STATUS
  195. Print_Users(
  196. )
  197. /*++
  198. Routine Description:
  199. Enumurates user accounts.
  200. Arguments:
  201. None.
  202. Return Value:
  203. Net access API error code.
  204. --*/
  205. {
  206. NET_API_STATUS NetStatus;
  207. PUSER_INFO_0 UserEnum0;
  208. DWORD EntriesRead;
  209. DWORD TotalEnties;
  210. DWORD ResumeHandle = 0;
  211. DWORD i;
  212. //
  213. // Enum users
  214. //
  215. NetStatus = NetUserEnum(
  216. NULL,
  217. 0,
  218. FILTER_TEMP_DUPLICATE_ACCOUNT |
  219. FILTER_NORMAL_ACCOUNT |
  220. FILTER_PROXY_ACCOUNT |
  221. FILTER_INTERDOMAIN_TRUST_ACCOUNT |
  222. FILTER_WORKSTATION_TRUST_ACCOUNT|
  223. FILTER_SERVER_TRUST_ACCOUNT,
  224. (LPBYTE *)&UserEnum0,
  225. 0x10000,
  226. &EntriesRead,
  227. &TotalEnties,
  228. &ResumeHandle );
  229. if( NetStatus != NERR_Success ) {
  230. return( NetStatus );
  231. }
  232. //
  233. // ?? implement resume
  234. //
  235. //
  236. // get info of users
  237. //
  238. for( i = 0; i < EntriesRead; i++ ) {
  239. printf("UserInfo, Count : %d \n\n", i+1 );
  240. NetStatus = Print_UserInfo3( UserEnum0[i].usri0_name );
  241. if( NetStatus != NERR_Success ) {
  242. return( NetStatus );
  243. }
  244. printf("--------------------------------\n\n");
  245. }
  246. (VOID) NetApiBufferFree( UserEnum0 );
  247. return( NetStatus );
  248. }
  249. NET_API_STATUS
  250. Print_Groups(
  251. )
  252. /*++
  253. Routine Description:
  254. Enumurates group accounts.
  255. Arguments:
  256. None.
  257. Return Value:
  258. Net access API error code.
  259. --*/
  260. {
  261. NET_API_STATUS NetStatus;
  262. PGROUP_INFO_0 GroupEnum0;
  263. DWORD EntriesRead;
  264. DWORD TotalEnties;
  265. DWORD ResumeHandle = 0;
  266. DWORD i;
  267. //
  268. // Enum groups
  269. //
  270. NetStatus = NetGroupEnum(
  271. NULL,
  272. 0,
  273. (LPBYTE *)&GroupEnum0,
  274. 0x10000,
  275. &EntriesRead,
  276. &TotalEnties,
  277. &ResumeHandle );
  278. if( NetStatus != NERR_Success ) {
  279. return( NetStatus );
  280. }
  281. //
  282. // ?? implement resume
  283. //
  284. //
  285. // get info of groups
  286. //
  287. for( i = 0; i < EntriesRead; i++ ) {
  288. printf("GroupInfo, Count : %d \n\n", i+1 );
  289. NetStatus = Print_GroupInfo2( GroupEnum0[i].grpi0_name );
  290. if( NetStatus != NERR_Success ) {
  291. return( NetStatus );
  292. }
  293. printf("--------------------------------\n\n");
  294. }
  295. (VOID) NetApiBufferFree( GroupEnum0 );
  296. return( NetStatus );
  297. }
  298. void
  299. main(
  300. DWORD argc,
  301. LPSTR *argv
  302. )
  303. /*++
  304. Routine Description:
  305. main function to dump user database.
  306. Arguments:
  307. argc : argument count.
  308. argv : argument vector.
  309. Return Value:
  310. none
  311. --*/
  312. {
  313. NET_API_STATUS NetStatus;
  314. NetStatus = Print_ModalsInfo();
  315. if( NetStatus != NERR_Success ) {
  316. goto Cleanup;
  317. }
  318. NetStatus = Print_Users();
  319. if( NetStatus != NERR_Success ) {
  320. goto Cleanup;
  321. }
  322. NetStatus = Print_Groups();
  323. if( NetStatus != NERR_Success ) {
  324. goto Cleanup;
  325. }
  326. Cleanup:
  327. if( NetStatus != NERR_Success ) {
  328. printf( "DumpDB : Unsuccessful, Error code %d \n", NetStatus );
  329. }
  330. else {
  331. printf( "DumpDB : Successful \n" );
  332. }
  333. }