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.

571 lines
13 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. utils.c
  5. Abstract:
  6. Common utility routines for clusters resources
  7. Author:
  8. John Vert (jvert) 12/15/1996
  9. Revision History:
  10. --*/
  11. #include "clusres.h"
  12. #include "clusrtl.h"
  13. #include "clusudef.h"
  14. DWORD
  15. ClusResOpenDriver(
  16. HANDLE *Handle,
  17. LPWSTR DriverName
  18. )
  19. /*++
  20. Routine Description:
  21. This function opens a specified IO drivers.
  22. Arguments:
  23. Handle - pointer to location where the opened drivers handle is
  24. returned.
  25. DriverName - name of the driver to be opened.
  26. Return Value:
  27. Windows Error Code.
  28. --*/
  29. {
  30. OBJECT_ATTRIBUTES objectAttributes;
  31. IO_STATUS_BLOCK ioStatusBlock;
  32. UNICODE_STRING nameString;
  33. NTSTATUS status;
  34. *Handle = NULL;
  35. //
  36. // Open a Handle to the IP driver.
  37. //
  38. RtlInitUnicodeString(&nameString, DriverName);
  39. InitializeObjectAttributes(
  40. &objectAttributes,
  41. &nameString,
  42. OBJ_CASE_INSENSITIVE,
  43. (HANDLE) NULL,
  44. (PSECURITY_DESCRIPTOR) NULL
  45. );
  46. status = NtCreateFile(
  47. Handle,
  48. SYNCHRONIZE | FILE_READ_DATA | FILE_WRITE_DATA,
  49. &objectAttributes,
  50. &ioStatusBlock,
  51. NULL,
  52. FILE_ATTRIBUTE_NORMAL,
  53. FILE_SHARE_READ | FILE_SHARE_WRITE,
  54. FILE_OPEN_IF,
  55. 0,
  56. NULL,
  57. 0
  58. );
  59. return( RtlNtStatusToDosError( status ) );
  60. } // ClusResOpenDriver
  61. NTSTATUS
  62. ClusResDoIoctl(
  63. HANDLE Handle,
  64. DWORD IoctlCode,
  65. PVOID Request,
  66. DWORD RequestSize,
  67. PVOID Response,
  68. PDWORD ResponseSize
  69. )
  70. /*++
  71. Routine Description:
  72. Utility routine used to issue a filtering ioctl to the tcpip driver.
  73. Arguments:
  74. Handle - An open file handle on which to issue the request.
  75. IoctlCode - The IOCTL opcode.
  76. Request - A pointer to the input buffer.
  77. RequestSize - Size of the input buffer.
  78. Response - A pointer to the output buffer.
  79. ResponseSize - On input, the size in bytes of the output buffer.
  80. On output, the number of bytes returned in the output buffer.
  81. Return Value:
  82. NT Status Code.
  83. --*/
  84. {
  85. IO_STATUS_BLOCK ioStatusBlock;
  86. NTSTATUS status;
  87. ioStatusBlock.Information = 0;
  88. status = NtDeviceIoControlFile(
  89. Handle, // Driver handle
  90. NULL, // Event
  91. NULL, // APC Routine
  92. NULL, // APC context
  93. &ioStatusBlock, // Status block
  94. IoctlCode, // Control code
  95. Request, // Input buffer
  96. RequestSize, // Input buffer size
  97. Response, // Output buffer
  98. *ResponseSize // Output buffer size
  99. );
  100. if (status == STATUS_PENDING) {
  101. status = NtWaitForSingleObject(
  102. Handle,
  103. TRUE,
  104. NULL
  105. );
  106. }
  107. if (status == STATUS_SUCCESS) {
  108. status = ioStatusBlock.Status;
  109. *ResponseSize = (DWORD)ioStatusBlock.Information;
  110. }
  111. else {
  112. *ResponseSize = 0;
  113. }
  114. return(status);
  115. } // ClusResDoIoctl
  116. VOID
  117. ClusResLogEventWithName0(
  118. IN HKEY hResourceKey,
  119. IN DWORD LogLevel,
  120. IN DWORD LogModule,
  121. IN LPSTR FileName,
  122. IN DWORD LineNumber,
  123. IN DWORD MessageId,
  124. IN DWORD dwByteCount,
  125. IN PVOID lpBytes
  126. )
  127. /*++
  128. Routine Description:
  129. Logs an event to the eventlog. The display name of the resource is retrieved
  130. and passed as the first insertion string.
  131. Arguments:
  132. hResourceKey - Supplies the cluster resource key.
  133. LogLevel - Supplies the logging level, one of
  134. LOG_CRITICAL 1
  135. LOG_UNUSUAL 2
  136. LOG_NOISE 3
  137. LogModule - Supplies the module ID.
  138. FileName - Supplies the filename of the caller
  139. LineNumber - Supplies the line number of the caller
  140. MessageId - Supplies the message ID to be logged.
  141. dwByteCount - Supplies the number of error-specific bytes to log. If this
  142. is zero, lpBytes is ignored.
  143. lpBytes - Supplies the error-specific bytes to log.
  144. Return Value:
  145. ERROR_SUCCESS if successful
  146. Win32 error code otherwise
  147. --*/
  148. {
  149. DWORD BufSize;
  150. DWORD Status;
  151. WCHAR ResourceName[80];
  152. PWCHAR resName = ResourceName;
  153. DWORD dwType;
  154. //
  155. // Get the display name for this resource.
  156. //
  157. BufSize = sizeof( ResourceName );
  158. again:
  159. Status = ClusterRegQueryValue( hResourceKey,
  160. CLUSREG_NAME_RES_NAME,
  161. &dwType,
  162. (LPBYTE)resName,
  163. &BufSize );
  164. if ( Status == ERROR_MORE_DATA ) {
  165. resName = LocalAlloc( LMEM_FIXED, BufSize );
  166. if ( resName != NULL ) {
  167. goto again;
  168. }
  169. resName = ResourceName;
  170. ResourceName[0] = UNICODE_NULL;
  171. } else if ( Status != ERROR_SUCCESS ) {
  172. ResourceName[0] = '\0';
  173. }
  174. ClusterLogEvent1(LogLevel,
  175. LogModule,
  176. FileName,
  177. LineNumber,
  178. MessageId,
  179. dwByteCount,
  180. lpBytes,
  181. resName);
  182. if ( resName != ResourceName ) {
  183. LocalFree( resName );
  184. }
  185. return;
  186. } // ClusResLogEventWithName0
  187. VOID
  188. ClusResLogEventWithName1(
  189. IN HKEY hResourceKey,
  190. IN DWORD LogLevel,
  191. IN DWORD LogModule,
  192. IN LPSTR FileName,
  193. IN DWORD LineNumber,
  194. IN DWORD MessageId,
  195. IN DWORD dwByteCount,
  196. IN PVOID lpBytes,
  197. IN LPCWSTR Arg1
  198. )
  199. /*++
  200. Routine Description:
  201. Logs an event to the eventlog. The display name of the resource is retrieved
  202. and passed as the first insertion string.
  203. Arguments:
  204. hResourceKey - Supplies the cluster resource key.
  205. LogLevel - Supplies the logging level, one of
  206. LOG_CRITICAL 1
  207. LOG_UNUSUAL 2
  208. LOG_NOISE 3
  209. LogModule - Supplies the module ID.
  210. FileName - Supplies the filename of the caller
  211. LineNumber - Supplies the line number of the caller
  212. MessageId - Supplies the message ID to be logged.
  213. dwByteCount - Supplies the number of error-specific bytes to log. If this
  214. is zero, lpBytes is ignored.
  215. lpBytes - Supplies the error-specific bytes to log.
  216. Arg1 - Supplies an insertion string
  217. Return Value:
  218. ERROR_SUCCESS if successful
  219. Win32 error code otherwise
  220. --*/
  221. {
  222. DWORD BufSize;
  223. DWORD Status;
  224. WCHAR ResourceName[80];
  225. PWCHAR resName = ResourceName;
  226. DWORD dwType;
  227. //
  228. // Get the display name for this resource.
  229. //
  230. BufSize = sizeof( ResourceName );
  231. again:
  232. Status = ClusterRegQueryValue( hResourceKey,
  233. CLUSREG_NAME_RES_NAME,
  234. &dwType,
  235. (LPBYTE)resName,
  236. &BufSize );
  237. if ( Status == ERROR_MORE_DATA ) {
  238. resName = LocalAlloc( LMEM_FIXED, BufSize );
  239. if ( resName != NULL ) {
  240. goto again;
  241. }
  242. resName = ResourceName;
  243. ResourceName[0] = UNICODE_NULL;
  244. } else if ( Status != ERROR_SUCCESS ) {
  245. ResourceName[0] = '\0';
  246. }
  247. ClusterLogEvent2(LogLevel,
  248. LogModule,
  249. FileName,
  250. LineNumber,
  251. MessageId,
  252. dwByteCount,
  253. lpBytes,
  254. resName,
  255. Arg1);
  256. if ( resName != ResourceName ) {
  257. LocalFree( resName );
  258. }
  259. return;
  260. } // ClusResLogEventWithName1
  261. VOID
  262. ClusResLogEventWithName2(
  263. IN HKEY hResourceKey,
  264. IN DWORD LogLevel,
  265. IN DWORD LogModule,
  266. IN LPSTR FileName,
  267. IN DWORD LineNumber,
  268. IN DWORD MessageId,
  269. IN DWORD dwByteCount,
  270. IN PVOID lpBytes,
  271. IN LPCWSTR Arg1,
  272. IN LPCWSTR Arg2
  273. )
  274. /*++
  275. Routine Description:
  276. Logs an event to the eventlog. The display name of the resource is retrieved
  277. and passed as the first insertion string.
  278. Arguments:
  279. hResourceKey - Supplies the cluster resource key.
  280. LogLevel - Supplies the logging level, one of
  281. LOG_CRITICAL 1
  282. LOG_UNUSUAL 2
  283. LOG_NOISE 3
  284. LogModule - Supplies the module ID.
  285. FileName - Supplies the filename of the caller
  286. LineNumber - Supplies the line number of the caller
  287. MessageId - Supplies the message ID to be logged.
  288. dwByteCount - Supplies the number of error-specific bytes to log. If this
  289. is zero, lpBytes is ignored.
  290. lpBytes - Supplies the error-specific bytes to log.
  291. Arg1 - Supplies an insertion string
  292. Arg2 - Supplies the second insertion string
  293. Return Value:
  294. ERROR_SUCCESS if successful
  295. Win32 error code otherwise
  296. --*/
  297. {
  298. DWORD BufSize;
  299. DWORD Status;
  300. WCHAR ResourceName[80];
  301. PWCHAR resName = ResourceName;
  302. DWORD dwType;
  303. //
  304. // Get the display name for this resource.
  305. //
  306. BufSize = sizeof( ResourceName );
  307. again:
  308. Status = ClusterRegQueryValue( hResourceKey,
  309. CLUSREG_NAME_RES_NAME,
  310. &dwType,
  311. (LPBYTE)resName,
  312. &BufSize );
  313. if ( Status == ERROR_MORE_DATA ) {
  314. resName = LocalAlloc( LMEM_FIXED, BufSize );
  315. if ( resName != NULL ) {
  316. goto again;
  317. }
  318. resName = ResourceName;
  319. ResourceName[0] = UNICODE_NULL;
  320. } else if ( Status != ERROR_SUCCESS ) {
  321. ResourceName[0] = '\0';
  322. }
  323. ClusterLogEvent3(LogLevel,
  324. LogModule,
  325. FileName,
  326. LineNumber,
  327. MessageId,
  328. dwByteCount,
  329. lpBytes,
  330. resName,
  331. Arg1,
  332. Arg2);
  333. if ( resName != ResourceName ) {
  334. LocalFree( resName );
  335. }
  336. return;
  337. } // ClusResLogEventWithName2
  338. VOID
  339. ClusResLogEventWithName3(
  340. IN HKEY hResourceKey,
  341. IN DWORD LogLevel,
  342. IN DWORD LogModule,
  343. IN LPSTR FileName,
  344. IN DWORD LineNumber,
  345. IN DWORD MessageId,
  346. IN DWORD dwByteCount,
  347. IN PVOID lpBytes,
  348. IN LPCWSTR Arg1,
  349. IN LPCWSTR Arg2,
  350. IN LPCWSTR Arg3
  351. )
  352. /*++
  353. Routine Description:
  354. Logs an event to the eventlog. The display name of the resource is retrieved
  355. and passed as the first insertion string.
  356. Arguments:
  357. hResourceKey - Supplies the cluster resource key.
  358. LogLevel - Supplies the logging level, one of
  359. LOG_CRITICAL 1
  360. LOG_UNUSUAL 2
  361. LOG_NOISE 3
  362. LogModule - Supplies the module ID.
  363. FileName - Supplies the filename of the caller
  364. LineNumber - Supplies the line number of the caller
  365. MessageId - Supplies the message ID to be logged.
  366. dwByteCount - Supplies the number of error-specific bytes to log. If this
  367. is zero, lpBytes is ignored.
  368. lpBytes - Supplies the error-specific bytes to log.
  369. Arg1 - Supplies an insertion string
  370. Arg2 - Supplies the second insertion string
  371. Arg3 - Supplies the third insertion string
  372. Return Value:
  373. ERROR_SUCCESS if successful
  374. Win32 error code otherwise
  375. --*/
  376. {
  377. DWORD BufSize;
  378. DWORD Status;
  379. WCHAR ResourceName[80];
  380. PWCHAR resName = ResourceName;
  381. DWORD dwType;
  382. //
  383. // Get the display name for this resource.
  384. //
  385. BufSize = sizeof( ResourceName );
  386. again:
  387. Status = ClusterRegQueryValue( hResourceKey,
  388. CLUSREG_NAME_RES_NAME,
  389. &dwType,
  390. (LPBYTE)resName,
  391. &BufSize );
  392. if ( Status == ERROR_MORE_DATA ) {
  393. resName = LocalAlloc( LMEM_FIXED, BufSize );
  394. if ( resName != NULL ) {
  395. goto again;
  396. }
  397. resName = ResourceName;
  398. ResourceName[0] = UNICODE_NULL;
  399. } else if ( Status != ERROR_SUCCESS ) {
  400. ResourceName[0] = '\0';
  401. }
  402. ClusterLogEvent4(LogLevel,
  403. LogModule,
  404. FileName,
  405. LineNumber,
  406. MessageId,
  407. dwByteCount,
  408. lpBytes,
  409. resName,
  410. Arg1,
  411. Arg2,
  412. Arg3);
  413. if ( resName != ResourceName ) {
  414. LocalFree( resName );
  415. }
  416. return;
  417. }