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.

334 lines
9.4 KiB

  1. /***
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. Sample.c
  5. Abstract:
  6. Command line test tool for calling the NwlibMakeNcp function.
  7. ***/
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <nt.h>
  11. #include <ntrtl.h>
  12. #include <nturtl.h>
  13. #include <windows.h>
  14. #include <ntddnwfs.h>
  15. #include <nwapi32.h>
  16. #include <nwxchg.h>
  17. //
  18. // NCP Function Control definitions
  19. //
  20. #define CTL_NCP_E3H 0x0014105F
  21. #define CTL_NCP_E2H 0x0014105B
  22. #define CTL_NCP_E1H 0x00141057
  23. #define CTL_NCP_E0H 0x00141053
  24. //
  25. // Local structure definition
  26. //
  27. typedef struct _NWC_SERVER_INFO {
  28. HANDLE hConn ;
  29. UNICODE_STRING ServerString ;
  30. } NWC_SERVER_INFO, *PNWC_SERVER_INFO ;
  31. //
  32. // Local function definitions
  33. //
  34. NTSTATUS SendAnNCP1( NWCONN_HANDLE ConnectionHandle );
  35. NTSTATUS SendAnNCP2( NWCONN_HANDLE ConnectionHandle );
  36. NTSTATUS SendAnNCP3( NWCONN_HANDLE ConnectionHandle );
  37. //
  38. // Main program function
  39. //
  40. int
  41. _cdecl main( int argc, char **argv )
  42. {
  43. NTSTATUS ntstatus = STATUS_SUCCESS;
  44. NWCCODE nwccode = SUCCESSFUL;
  45. NWCONN_HANDLE ConnectionHandle;
  46. OEM_STRING OemArg;
  47. UNICODE_STRING ServerName;
  48. WCHAR ServerNameBuffer[256];
  49. DWORD dwE3H = FSCTL_NWR_NCP_E3H;
  50. DWORD dwE2H = FSCTL_NWR_NCP_E2H;
  51. DWORD dwE1H = FSCTL_NWR_NCP_E1H;
  52. DWORD dwE0H = FSCTL_NWR_NCP_E0H;
  53. if ( argc != 2 )
  54. {
  55. printf( "\nUsage: sample <NetWare server name>, not \\\\<server>\n" );
  56. system( "pause" );
  57. return -1;
  58. }
  59. OemArg.Length = strlen( argv[1] );
  60. OemArg.MaximumLength = OemArg.Length;
  61. OemArg.Buffer = argv[1];
  62. ServerName.Length = 0;
  63. ServerName.MaximumLength = sizeof( ServerNameBuffer );
  64. ServerName.Buffer = ServerNameBuffer;
  65. RtlOemStringToUnicodeString( &ServerName, &OemArg, FALSE );
  66. printf( "\nConnecting to NetWare server %S\n", ServerName.Buffer );
  67. nwccode = NWAttachToFileServerW( ServerName.Buffer,
  68. 0, // ScopeFlag - set to zero, not used
  69. &ConnectionHandle );
  70. if ( nwccode != SUCCESSFUL )
  71. {
  72. printf( "Error: Couldn't connect to NetWare server %S\n",
  73. ServerName.Buffer );
  74. printf( " NWAttachToFileServerW return ntstatus 0x%.8X\n\n",
  75. nwccode );
  76. return -1;
  77. }
  78. ntstatus = SendAnNCP1( ConnectionHandle ); // Your function here!
  79. if ( ntstatus != STATUS_SUCCESS )
  80. {
  81. printf( "Error: SendAnNCP1 return ntstatus 0x%.8X\n\n",
  82. ntstatus );
  83. return -1;
  84. }
  85. ntstatus = SendAnNCP2( ConnectionHandle ); // Your function here!
  86. if ( ntstatus != STATUS_SUCCESS )
  87. {
  88. printf( "Error: SendAnNCP2 return ntstatus 0x%.8X\n\n",
  89. ntstatus );
  90. return -1;
  91. }
  92. ntstatus = SendAnNCP3( ConnectionHandle ); // Your function here!
  93. if ( ntstatus != STATUS_SUCCESS )
  94. {
  95. printf( "Error: SendAnNCP3 return ntstatus 0x%.8X\n\n",
  96. ntstatus );
  97. return -1;
  98. }
  99. nwccode = NWDetachFromFileServer( ConnectionHandle );
  100. if ( nwccode != SUCCESSFUL )
  101. {
  102. printf( "Error: Couldn't disconnect from NetWare server %S\n",
  103. ServerName.Buffer );
  104. printf( " NWDetachFromFileServer return nwccode 0x%.8X\n\n",
  105. nwccode );
  106. return -1;
  107. }
  108. }
  109. NTSTATUS SendAnNCP1( NWCONN_HANDLE ConnectionHandle )
  110. /*--
  111. Routine Description:
  112. This function uses an opened handle to the preferred server to
  113. scan bindery for all file server objects.
  114. Arguments:
  115. ConnectionHandle - Supplies the handle to the server that we want to
  116. send NCP request to.
  117. Return Value:
  118. STATUS_SUCCESS - Successfully gotten a file server name.
  119. - or -
  120. A NTSTATUS code defined in ntstatus.h
  121. --*/
  122. {
  123. NTSTATUS ntstatus;
  124. BYTE year, month, day, hour, minute, second, dayofweek;
  125. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)ConnectionHandle ;
  126. //
  127. // Make and send an NCP to get file server date and time.
  128. //
  129. ntstatus = NwlibMakeNcp(
  130. pServerInfo->hConn, // Connection Handle
  131. CTL_NCP_E0H, // Server function
  132. 0, // Max request packet size
  133. 9, // Max response packet size
  134. "|bbbbbbb", // Format string
  135. // === REQUEST ================================
  136. // === REPLY ==================================
  137. &year,
  138. &month,
  139. &day,
  140. &hour,
  141. &minute,
  142. &second,
  143. &dayofweek
  144. );
  145. if ( ntstatus == STATUS_SUCCESS )
  146. {
  147. printf( "\nFile server date and time information:\n\n" );
  148. printf( "Hour: %d, Minute: %d, Second: %d\n", hour, minute, second );
  149. printf( "Day: %d, Month: %d, Year: %d\n", day, month, year );
  150. printf( "Day of the week: %d\n\n", dayofweek );
  151. }
  152. return ntstatus;
  153. }
  154. NTSTATUS SendAnNCP2( NWCONN_HANDLE ConnectionHandle )
  155. /*--
  156. Routine Description:
  157. This function uses an opened handle to the preferred server to
  158. scan bindery for all file server objects.
  159. Arguments:
  160. ConnectionHandle - Supplies the handle to the server that we want to
  161. send NCP request to.
  162. Return Value:
  163. STATUS_SUCCESS - Successfully gotten a file server name.
  164. - or -
  165. A NTSTATUS code defined in ntstatus.h
  166. --*/
  167. {
  168. NTSTATUS ntstatus;
  169. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)ConnectionHandle ;
  170. VERSION_INFO VerInfo;
  171. //
  172. // Make and send an NCP to get file server version information.
  173. //
  174. ntstatus = NwlibMakeNcp(
  175. pServerInfo->hConn, // Connection Handle
  176. CTL_NCP_E3H, // Bindery function
  177. 3, // Max request packet size
  178. 130, // Max response packet size
  179. "b|r", // Format string
  180. // === REQUEST ================================
  181. 0x11, // b Get File Server Information
  182. // === REPLY ==================================
  183. &VerInfo, // r File Version Structure
  184. sizeof(VERSION_INFO)
  185. );
  186. if ( ntstatus == STATUS_SUCCESS )
  187. {
  188. // Convert HI-LO words to LO-HI
  189. // ===========================================================
  190. VerInfo.ConnsSupported = wSWAP( VerInfo.ConnsSupported );
  191. VerInfo.connsInUse = wSWAP( VerInfo.connsInUse );
  192. VerInfo.maxVolumes = wSWAP( VerInfo.maxVolumes );
  193. VerInfo.PeakConns = wSWAP( VerInfo.PeakConns );
  194. printf( "\nFile server version information:\n\n" );
  195. printf( "Name: %s\n", VerInfo.szName );
  196. printf( "Version: %d\n", VerInfo.Version );
  197. printf( "Sub-Version: %d\n", VerInfo.SubVersion );
  198. printf( "OS Revision: %d\n", VerInfo.OSRev );
  199. printf( "SFT level: %d\n", VerInfo.SFTLevel );
  200. printf( "TTS level: %d\n", VerInfo.TTSLevel );
  201. printf( "Account version: %d\n", VerInfo.AcctVer );
  202. printf( "VAP version: %d\n", VerInfo.VAPVer );
  203. printf( "Queue version: %d\n", VerInfo.QueueVer );
  204. printf( "Printer version: %d\n", VerInfo.PrintVer );
  205. printf( "Virtual console version: %d\n", VerInfo.VirtualConsoleVer );
  206. printf( "Security restriction level: %d\n", VerInfo.SecurityResLevel );
  207. printf( "Inter-network B version: %d\n", VerInfo.InternetworkBVer );
  208. printf( "Number of connections supported: %d\n", VerInfo.ConnsSupported );
  209. printf( "Number of connections in use: %d\n", VerInfo.connsInUse );
  210. printf( "Maximum number of volumes: %d\n", VerInfo.maxVolumes );
  211. printf( "Peak number of connections: %d\n\n", VerInfo.PeakConns );
  212. }
  213. return ntstatus;
  214. }
  215. NTSTATUS SendAnNCP3( NWCONN_HANDLE ConnectionHandle )
  216. /*--
  217. Routine Description:
  218. This function uses an opened handle to the preferred server to
  219. scan bindery for all file server objects.
  220. Arguments:
  221. ConnectionHandle - Supplies the handle to the server that we want to
  222. send NCP request to.
  223. Return Value:
  224. STATUS_SUCCESS - Successfully gotten a file server name.
  225. - or -
  226. A NTSTATUS code defined in ntstatus.h
  227. --*/
  228. {
  229. NTSTATUS ntstatus;
  230. char szAnsiName[1000];
  231. WORD wFoundUserType = 0;
  232. DWORD dwObjectID = 0xFFFFFFFFL;
  233. BYTE byPropertiesFlag = 0;
  234. BYTE byObjectFlag = 0;
  235. BYTE byObjectSecurity = 0;
  236. while ( ntstatus == STATUS_SUCCESS )
  237. {
  238. //
  239. // Make and send an NCP to get file server version information.
  240. //
  241. ntstatus = NWScanObject( ConnectionHandle,
  242. "*",
  243. OT_USER_GROUP,
  244. &dwObjectID,
  245. szAnsiName,
  246. &wFoundUserType,
  247. &byPropertiesFlag,
  248. &byObjectFlag,
  249. &byObjectSecurity );
  250. if ( ntstatus == STATUS_SUCCESS )
  251. {
  252. printf( "Name: %s\n", szAnsiName );
  253. }
  254. }
  255. return ntstatus;
  256. }