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.

356 lines
11 KiB

  1. /*************************************************************************
  2. *
  3. * NCP.C
  4. *
  5. * All routines doing direct NCPs or filecontrol operations
  6. *
  7. * Copyright (c) 1995 Microsoft Corporation
  8. *
  9. * $Log: N:\NT\PRIVATE\NW4\NWSCRIPT\VCS\NCP.C $
  10. *
  11. * Rev 1.2 10 Apr 1996 14:22:50 terryt
  12. * Hotfix for 21181hq
  13. *
  14. * Rev 1.2 12 Mar 1996 19:54:06 terryt
  15. * Relative NDS names and merge
  16. *
  17. * Rev 1.1 22 Dec 1995 14:24:56 terryt
  18. * Add Microsoft headers
  19. *
  20. * Rev 1.0 15 Nov 1995 18:07:10 terryt
  21. * Initial revision.
  22. *
  23. *************************************************************************/
  24. #include <stdio.h>
  25. #include <direct.h>
  26. #include <time.h>
  27. #include <stdlib.h>
  28. #include <nt.h>
  29. #include <ntrtl.h>
  30. #include <nturtl.h>
  31. #include <windows.h>
  32. #include <nwapi32.h>
  33. #include <ntddnwfs.h>
  34. #include "nwscript.h"
  35. #include "ntnw.h"
  36. #include "inc/nwlibs.h"
  37. /********************************************************************
  38. NTGetUserID
  39. Routine Description:
  40. Given a connection handle, return the user ID
  41. Arguments:
  42. ConnectionHandle - Connection Handle
  43. UserID - returned User ID
  44. Return Value:
  45. 0 = success
  46. else NT error
  47. *******************************************************************/
  48. unsigned int
  49. NTGetUserID(
  50. unsigned int ConnectionHandle,
  51. unsigned long *pUserID
  52. )
  53. {
  54. NTSTATUS NtStatus ;
  55. unsigned int ObjectType;
  56. unsigned char LoginTime[7];
  57. unsigned char UserName[48];
  58. VERSION_INFO VerInfo;
  59. unsigned int Version;
  60. unsigned int ConnectionNum;
  61. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)ConnectionHandle ;
  62. NtStatus = GetConnectionNumber( ConnectionHandle, &ConnectionNum );
  63. if (!NT_SUCCESS(NtStatus))
  64. return NtStatus;
  65. NtStatus = NWGetFileServerVersionInfo( (NWCONN_HANDLE)ConnectionHandle,
  66. &VerInfo );
  67. if (!NT_SUCCESS(NtStatus))
  68. return NtStatus;
  69. Version = VerInfo.Version * 1000 + VerInfo.SubVersion * 10;
  70. if ( ( Version >= 3110 ) || ( Version < 2000 ) ) {
  71. NtStatus = NwlibMakeNcp(
  72. pServerInfo->hConn, // Connection Handle
  73. FSCTL_NWR_NCP_E3H, // Bindery function
  74. 8, // Max request packet size
  75. 63, // Max response packet size
  76. "br|rrrr", // Format string
  77. // === REQUEST ================================
  78. 0x1c, // b Get Connection Information
  79. &ConnectionNum, 4, // r Connection Number
  80. // === REPLY ==================================
  81. pUserID, 4, // r Object ID
  82. &ObjectType, 2, // r Object Type
  83. UserName, 48, // r UserName
  84. LoginTime, 7 // r Login Time
  85. );
  86. }
  87. else {
  88. NtStatus = NwlibMakeNcp(
  89. pServerInfo->hConn, // Connection Handle
  90. FSCTL_NWR_NCP_E3H, // Bindery function
  91. 4, // Max request packet size
  92. 63, // Max response packet size
  93. "bb|rrrr", // Format string
  94. // === REQUEST ================================
  95. 0x16, // b Get Connection Information
  96. ConnectionNum, // b Connection Number
  97. // === REPLY ==================================
  98. pUserID, 4, // r Object ID
  99. &ObjectType, 2, // r Object Type
  100. UserName, 48, // r UserName
  101. LoginTime, 7 // r Login Time
  102. );
  103. }
  104. return NtStatus;
  105. }
  106. /********************************************************************
  107. GetConnectionNumber
  108. Routine Description:
  109. Given a ConnectionHandle, return the NetWare Connection number
  110. Arguments:
  111. ConnectionHandle - Connection Handle
  112. pConnectionNumber - pointer to returned connection number
  113. Return Value:
  114. 0 = success
  115. else NT error
  116. *******************************************************************/
  117. unsigned int
  118. GetConnectionNumber(
  119. unsigned int ConnectionHandle,
  120. unsigned int * pConnectionNumber )
  121. {
  122. NTSTATUS Status;
  123. IO_STATUS_BLOCK IoStatusBlock;
  124. NWR_GET_CONNECTION_DETAILS Details;
  125. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)ConnectionHandle ;
  126. Status = NtFsControlFile(
  127. pServerInfo->hConn, // Connection Handle
  128. NULL,
  129. NULL,
  130. NULL,
  131. &IoStatusBlock,
  132. FSCTL_NWR_GET_CONN_DETAILS,
  133. NULL,
  134. 0,
  135. (PVOID) &Details,
  136. sizeof(Details));
  137. if (Status == STATUS_SUCCESS) {
  138. Status = IoStatusBlock.Status;
  139. }
  140. if (NT_SUCCESS(Status)) {
  141. *pConnectionNumber = 256 * Details.ConnectionNumberHi +
  142. Details.ConnectionNumberLo;
  143. }
  144. return Status;
  145. }
  146. /********************************************************************
  147. GetInternetAddress
  148. Routine Description:
  149. Return the address of the current system
  150. Arguments:
  151. ConnectionHandle - Connection Handle
  152. ConnectionNum - Connection Number
  153. pAddress - returned address
  154. Return Value:
  155. 0 = success
  156. else NT error
  157. *******************************************************************/
  158. unsigned int
  159. GetInternetAddress(
  160. unsigned int ConnectionHandle,
  161. unsigned int ConnectionNum,
  162. unsigned char *pAddress
  163. )
  164. {
  165. NTSTATUS NtStatus ;
  166. VERSION_INFO VerInfo;
  167. unsigned int Version;
  168. unsigned char Address[12];
  169. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)ConnectionHandle ;
  170. NtStatus = NWGetFileServerVersionInfo( (NWCONN_HANDLE)ConnectionHandle,
  171. &VerInfo );
  172. if (!NT_SUCCESS(NtStatus))
  173. return NtStatus;
  174. Version = VerInfo.Version * 1000 + VerInfo.SubVersion * 10;
  175. if ( ( Version >= 3110 ) || ( Version < 2000 ) ) {
  176. NtStatus = NwlibMakeNcp(
  177. pServerInfo->hConn, // Connection Handle
  178. FSCTL_NWR_NCP_E3H, // Bindery function
  179. 7, // Max request packet size
  180. 14, // Max response packet size
  181. "br|r", // Format string
  182. // === REQUEST ================================
  183. 0x1a, // b Get Connection Information
  184. &ConnectionNum, 4, // r Connection Number
  185. // === REPLY ==================================
  186. Address, 12 // r Login Time
  187. );
  188. }
  189. else {
  190. NtStatus = NwlibMakeNcp(
  191. pServerInfo->hConn, // Connection Handle
  192. FSCTL_NWR_NCP_E3H, // Bindery function
  193. 4, // Max request packet size
  194. 14, // Max response packet size
  195. "bb|r", // Format string
  196. // === REQUEST ================================
  197. 0x13, // b Get Connection Information
  198. (unsigned char)ConnectionNum, // b Connection Number
  199. // === REPLY ==================================
  200. Address, 12 // r Login Time
  201. );
  202. }
  203. memcpy( pAddress, Address, 10 );
  204. return NtStatus;
  205. }
  206. /********************************************************************
  207. GetBinderyObjectID
  208. Routine Description:
  209. Get the object ID of a named object in the bindery
  210. Arguments:
  211. ConnectionHandle - Server connection handle
  212. pObjectName - Name of object
  213. ObjectType - Object type
  214. pObjectId - returned object ID
  215. Return Value:
  216. 0 = success
  217. else NT error
  218. *******************************************************************/
  219. unsigned int
  220. GetBinderyObjectID(
  221. unsigned int ConnectionHandle,
  222. char *pObjectName,
  223. unsigned short ObjectType,
  224. unsigned long *pObjectId )
  225. {
  226. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)ConnectionHandle ;
  227. unsigned int reply;
  228. reply = NwlibMakeNcp(
  229. pServerInfo->hConn, // Connection Handle
  230. FSCTL_NWR_NCP_E3H, // Directory function
  231. 54, // Max request packet size
  232. 56, // Max response packet size
  233. "brp|r", // Format string
  234. // === REQUEST ================================
  235. 0x35, // b Get object ID
  236. &ObjectType, W_SIZE, // r Object type HI-LO
  237. pObjectName, // p UserName
  238. // === REPLY ==================================
  239. pObjectId, 4 // 4 bytes of raw data
  240. );
  241. return reply;
  242. }
  243. /********************************************************************
  244. GetDefaultPrinterQueue
  245. Routine Description:
  246. Get the default printer queue.
  247. Arguments:
  248. ConnectionHandle - IN
  249. Handle to server
  250. pServerName - IN
  251. File server name
  252. pQueueName - OUT
  253. Default printer queue name
  254. Return Value:
  255. *******************************************************************/
  256. unsigned int
  257. GetDefaultPrinterQueue (
  258. unsigned int ConnectionHandle,
  259. unsigned char *pServerName,
  260. unsigned char *pQueueName
  261. )
  262. {
  263. unsigned long ObjectID;
  264. NTSTATUS NtStatus ;
  265. PNWC_SERVER_INFO pServerInfo = (PNWC_SERVER_INFO)ConnectionHandle ;
  266. NWOBJ_TYPE ObjectType;
  267. NWCCODE Nwcode;
  268. NtStatus = NwlibMakeNcp(
  269. pServerInfo->hConn, // Connection Handle
  270. NWR_ANY_F2_NCP(0x11), // F2 Function function
  271. 4, // Max request packet size
  272. 4, // Max response packet size
  273. "wbb|d", // Format string
  274. // === REQUEST ================================
  275. 0x2, // w Length
  276. 0xA, // b Subfunction
  277. 0, // b printer number
  278. // === REPLY ==================================
  279. &ObjectID // d Object ID of Queue
  280. );
  281. if ( !NT_SUCCESS( NtStatus ) )
  282. return ( NtStatus & 0xFF );
  283. Nwcode = NWGetObjectName( (NWCONN_HANDLE) ConnectionHandle,
  284. ObjectID,
  285. pQueueName,
  286. &ObjectType );
  287. return Nwcode;
  288. }