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.

273 lines
5.7 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. disptest.c
  5. Abstract:
  6. Test program for NetQueryDisplayInformation and
  7. NetGetDisplayInformationIndex API functions
  8. Author:
  9. Cliff Van Dyke (cliffv) 15-Dec-1994
  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. #undef DOMAIN_ALL_ACCESS // defined in both ntsam.h and ntwinapi.h
  20. // #include <ntsam.h>
  21. // #include <ntlsa.h>
  22. #include <windef.h>
  23. #include <winbase.h>
  24. #include <lmcons.h>
  25. // #include <accessp.h>
  26. // #include <align.h>
  27. #include <lmapibuf.h>
  28. #include <lmaccess.h>
  29. #include <lmerr.h>
  30. // #include <limits.h>
  31. #include <netdebug.h>
  32. #include <netlib.h>
  33. #include <netlibnt.h>
  34. #include <rpcutil.h>
  35. #include <stdlib.h>
  36. #include <stdio.h>
  37. #include <tstring.h>
  38. // #include <secobj.h>
  39. // #include <stddef.h>
  40. ///#include <uasp.h>
  41. DWORD
  42. DisplayStruct(
  43. IN DWORD Level,
  44. IN PVOID Buffer
  45. )
  46. /*++
  47. Routine Description:
  48. Display the appropriate structure.
  49. Arguments:
  50. Level - Info level of structure
  51. Buffer - structure to display
  52. Return Value:
  53. Index of next entry
  54. --*/
  55. {
  56. DWORD Index;
  57. switch (Level) {
  58. case 1: {
  59. PNET_DISPLAY_USER NetDisplayUser = (PNET_DISPLAY_USER) Buffer;
  60. printf("%4.4ld %-20.20ws comm:%ws flg:%lx full:%ws rid:%lx\n",
  61. NetDisplayUser->usri1_next_index,
  62. NetDisplayUser->usri1_name,
  63. NetDisplayUser->usri1_comment,
  64. NetDisplayUser->usri1_flags,
  65. NetDisplayUser->usri1_full_name,
  66. NetDisplayUser->usri1_user_id );
  67. Index = NetDisplayUser->usri1_next_index;
  68. break;
  69. }
  70. case 2: {
  71. PNET_DISPLAY_MACHINE NetDisplayMachine = (PNET_DISPLAY_MACHINE) Buffer;
  72. printf("%4.4ld %-20.20ws comm:%ws flg:%lx rid:%lx\n",
  73. NetDisplayMachine->usri2_next_index,
  74. NetDisplayMachine->usri2_name,
  75. NetDisplayMachine->usri2_comment,
  76. NetDisplayMachine->usri2_flags,
  77. NetDisplayMachine->usri2_user_id );
  78. Index = NetDisplayMachine->usri2_next_index;
  79. break;
  80. }
  81. case 3: {
  82. PNET_DISPLAY_GROUP NetDisplayGroup = (PNET_DISPLAY_GROUP) Buffer;
  83. printf("%4.4ld %-20.20ws comm:%ws attr:%lx rid:%lx\n",
  84. NetDisplayGroup->grpi3_next_index,
  85. NetDisplayGroup->grpi3_name,
  86. NetDisplayGroup->grpi3_comment,
  87. NetDisplayGroup->grpi3_attributes,
  88. NetDisplayGroup->grpi3_group_id );
  89. Index = NetDisplayGroup->grpi3_next_index;
  90. break;
  91. }
  92. }
  93. return Index;
  94. }
  95. int __cdecl
  96. main(
  97. IN int argc,
  98. IN char ** argv
  99. )
  100. /*++
  101. Routine Description:
  102. Test program for NetQueryDisplayInformation and
  103. NetGetDisplayInformationIndex API functions
  104. Arguments:
  105. argc - the number of command-line arguments.
  106. argv - an array of pointers to the arguments.
  107. Return Value:
  108. Exit status
  109. --*/
  110. {
  111. NET_API_STATUS NetStatus;
  112. char *end;
  113. DWORD i;
  114. DWORD FixedSize;
  115. LPWSTR ServerName = NULL;
  116. DWORD Level = 1;
  117. DWORD Index = 0;
  118. DWORD EntriesRequested = 0xFFFFFFFF;
  119. DWORD PreferredMaximumLength = 0xFFFFFFFF;
  120. LPWSTR Prefix = NULL;
  121. DWORD ReturnedEntryCount;
  122. PVOID SortedBuffer;
  123. if ( argc > 1 ) {
  124. ServerName = NetpAllocWStrFromStr( argv[1] );
  125. }
  126. if ( argc > 2 ) {
  127. Level = strtoul( argv[2], &end, 10 );
  128. }
  129. if ( argc > 3 ) {
  130. Index = strtoul( argv[3], &end, 10 );
  131. }
  132. if ( argc > 4 ) {
  133. EntriesRequested = strtoul( argv[4], &end, 10 );
  134. }
  135. if ( argc > 5 ) {
  136. PreferredMaximumLength = strtoul( argv[5], &end, 10 );
  137. }
  138. if ( argc > 6 ) {
  139. Prefix = NetpAllocWStrFromStr( argv[6] );
  140. }
  141. //
  142. // Size of each entry.
  143. //
  144. switch (Level) {
  145. case 1:
  146. FixedSize = sizeof(NET_DISPLAY_USER);
  147. break;
  148. case 2:
  149. FixedSize = sizeof(NET_DISPLAY_MACHINE);
  150. break;
  151. case 3:
  152. FixedSize = sizeof(NET_DISPLAY_GROUP);
  153. break;
  154. default:
  155. FixedSize = 0;
  156. break;
  157. }
  158. printf( "Server: %ws Level: %ld Index: %ld EntriesRequested: %ld PrefMax: %ld\n",
  159. ServerName,
  160. Level,
  161. Index,
  162. EntriesRequested,
  163. PreferredMaximumLength );
  164. if ( Prefix != NULL) {
  165. printf( "Prefix: %ws\n", Prefix );
  166. NetStatus = NetGetDisplayInformationIndex(
  167. ServerName,
  168. Level,
  169. Prefix,
  170. &Index );
  171. printf( "Status from NetGetDisplayInformationIndex: %ld\n", NetStatus );
  172. if ( NetStatus != NERR_Success ) {
  173. return 0;
  174. }
  175. printf( "NewIndex: %ld\n", Index );
  176. }
  177. do {
  178. NetStatus = NetQueryDisplayInformation(
  179. ServerName,
  180. Level,
  181. Index,
  182. EntriesRequested,
  183. PreferredMaximumLength,
  184. &ReturnedEntryCount,
  185. &SortedBuffer );
  186. printf( "Count: %ld Status: %ld\n",
  187. ReturnedEntryCount,
  188. NetStatus );
  189. if ( NetStatus != NERR_Success && NetStatus != ERROR_MORE_DATA ) {
  190. break;
  191. }
  192. for ( i=0; i<ReturnedEntryCount; i++ ) {
  193. Index = DisplayStruct( Level,
  194. ((LPBYTE) SortedBuffer) + FixedSize * i );
  195. }
  196. //
  197. // Free the returned buffer.
  198. //
  199. NetApiBufferFree( SortedBuffer );
  200. } while ( NetStatus == ERROR_MORE_DATA );
  201. return 0;
  202. }