Leaked source code of windows server 2003
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.

817 lines
23 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name :
  4. RwpFunctions.cxx
  5. Abstract:
  6. Implements the behaviors of the "Rogue Worker Process" --
  7. to test Application Manager
  8. Author:
  9. David Wang ( t-dwang ) 14-Jun-1999 Initial
  10. Project:
  11. Duct-Tape
  12. --*/
  13. /*********************************************************
  14. * Include Headers
  15. *********************************************************/
  16. #include "precomp.hxx"
  17. #include "RwpFunctions.hxx"
  18. /*********************************************************
  19. * local functions
  20. *********************************************************/
  21. BOOL DoGetPidTest(HRESULT* phr, IPM_MESSAGE_PIPE* pPipe);
  22. BOOL DoPingReplyTest(HRESULT* phr, IPM_MESSAGE_PIPE* pPipe);
  23. BOOL DoSendCountersTest(HRESULT* phr, IPM_MESSAGE_PIPE* pPipe);
  24. BOOL DoHResultTest(HRESULT* phr, IPM_MESSAGE_PIPE* pPipe);
  25. BOOL DoWorkerRequestShutdownTest(HRESULT* phr, IPM_MESSAGE_PIPE* pPipe);
  26. BOOL DoInvalidOpcodeTest(HRESULT* phr, IPM_MESSAGE_PIPE* pPipe);
  27. void RWP_Write_LONG_to_Registry(const WCHAR* szSubKey, LONG lValue);
  28. // These are for the new RWP tests
  29. LONG OpCodeToTest;
  30. LONG DataLength;
  31. LONG UseDataLength;
  32. LONG DataPointerType;
  33. LONG NumberOfCalls;
  34. LONG AttackDuration;
  35. LONG TestStarted;
  36. LONG TestCompleted;
  37. // These are for old RWP tests
  38. LONG RwpBehaviorExhibited;
  39. LONG PingBehavior, PingCount;
  40. LONG ShutdownBehavior, ShutdownCount;
  41. LONG RotationBehavior, RotationCount;
  42. LONG StartupBehavior, StartupCount;
  43. LONG HealthBehavior, HealthCount;
  44. LONG RecycleBehavior, RecycleCount;
  45. LONG AppPoolBehavior;
  46. LONG RWP_EXTRA_DEBUG;
  47. LONG RWP_AppPoolTest(void)
  48. {
  49. return AppPoolBehavior == RWP_APPPOOL_BOGUS ? TRUE : FALSE;
  50. }
  51. LONG RWP_IPM_BadParamTest(LONG OpCode, HRESULT* phr, IPM_MESSAGE_PIPE* pPipe)
  52. {
  53. BOOL bRet = FALSE;
  54. DBGPRINTF((DBG_CONTEXT, "In RWP_IPM_BadParamTest()\n"));
  55. if(OpCode != OpCodeToTest)
  56. return FALSE;
  57. bRet = TRUE;
  58. // we need to indicate we have actually gotten to the
  59. // code in w3wp that calls our test
  60. if(OpCodeToTest != RWP_IPM_OP_NONE)
  61. RWP_Write_LONG_to_Registry(RWP_CONFIG_TEST_STARTED, 1);
  62. switch(OpCodeToTest)
  63. {
  64. case RWP_IPM_OP_NONE:
  65. bRet = FALSE;
  66. break;
  67. case RWP_IPM_OP_GETPID:
  68. bRet = DoGetPidTest(phr, pPipe);
  69. break;
  70. case RWP_IPM_OP_PING_REPLY:
  71. bRet = DoPingReplyTest(phr, pPipe);
  72. break;
  73. case RWP_IPM_OP_SEND_COUNTERS:
  74. bRet = DoSendCountersTest(phr, pPipe);
  75. break;
  76. case RWP_IPM_OP_HRESULT:
  77. bRet = DoHResultTest(phr, pPipe);
  78. break;
  79. case RWP_IPM_OP_WORKER_REQUESTS_SHUTDOWN:
  80. bRet = DoWorkerRequestShutdownTest(phr, pPipe);
  81. break;
  82. case RWP_IPM_OP_INVALID:
  83. bRet = DoInvalidOpcodeTest(phr, pPipe);
  84. break;
  85. default:
  86. bRet = FALSE;
  87. break;
  88. }
  89. if(bRet)
  90. RWP_Write_LONG_to_Registry(RWP_CONFIG_TEST_COMPLETION_STATUS, RWP_TEST_STATUS_COMPLETE);
  91. else
  92. RWP_Write_LONG_to_Registry(RWP_CONFIG_TEST_COMPLETION_STATUS, RWP_TEST_STATUS_ERROR);
  93. return bRet;
  94. }
  95. BOOL DoGetPidTest(HRESULT* phr, IPM_MESSAGE_PIPE* pPipe)
  96. {
  97. DWORD dwDataLength;
  98. DWORD * pData = NULL;
  99. DBGPRINTF((DBG_CONTEXT, "In DoGetPidTest()\n"));
  100. DWORD dwId = GetCurrentProcessId();
  101. dwDataLength = UseDataLength ? DataLength : sizeof(dwId);
  102. switch(DataPointerType)
  103. {
  104. default:
  105. case RWP_DATA_POINTER_TYPE_VALID:
  106. pData = &dwId;
  107. break;
  108. case RWP_DATA_POINTER_TYPE_NULL:
  109. pData = NULL;
  110. break;
  111. case RWP_DATA_POINTER_TYPE_INVALID:
  112. pData = (DWORD*) 1;
  113. break;
  114. }
  115. *phr = pPipe->WriteMessage(IPM_OP_GETPID,
  116. dwDataLength,
  117. pData);
  118. return TRUE;
  119. }
  120. BOOL DoPingReplyTest(HRESULT* phr, IPM_MESSAGE_PIPE* pPipe)
  121. {
  122. DWORD dwDataLength;
  123. DWORD * pData = NULL;
  124. DWORD dwData = 42; // just some random data
  125. DBGPRINTF((DBG_CONTEXT, "In DoPingReplyTest()\n"));
  126. dwDataLength = UseDataLength ? DataLength : 0;
  127. switch(DataPointerType)
  128. {
  129. default:
  130. case RWP_DATA_POINTER_TYPE_VALID:
  131. pData = &dwData;
  132. break;
  133. case RWP_DATA_POINTER_TYPE_NULL:
  134. pData = NULL;
  135. break;
  136. case RWP_DATA_POINTER_TYPE_INVALID:
  137. pData = (DWORD*) 1;
  138. break;
  139. }
  140. *phr = pPipe->WriteMessage(
  141. IPM_OP_PING_REPLY, // ping reply opcode
  142. dwDataLength,
  143. pData
  144. );
  145. return TRUE;
  146. }
  147. BOOL DoSendCountersTest(HRESULT* phr, IPM_MESSAGE_PIPE* pPipe)
  148. {
  149. DWORD dwDataLength;
  150. DWORD * pData = NULL;
  151. DWORD dwData = 42; // just some random data
  152. DBGPRINTF((DBG_CONTEXT, "In DoSendCountersTest()\n"));
  153. dwDataLength = UseDataLength ? DataLength : sizeof(dwData);
  154. BYTE* pBuffer = NULL;
  155. switch(DataPointerType)
  156. {
  157. default:
  158. case RWP_DATA_POINTER_TYPE_VALID:
  159. if((UseDataLength) && (DataLength > 0))
  160. {
  161. pBuffer = new BYTE[DataLength];
  162. pData = (DWORD*) pBuffer;
  163. }
  164. else
  165. {
  166. pData = &dwData;
  167. }
  168. break;
  169. case RWP_DATA_POINTER_TYPE_NULL:
  170. pData = NULL;
  171. break;
  172. case RWP_DATA_POINTER_TYPE_INVALID:
  173. pData = (DWORD*) 1;
  174. break;
  175. }
  176. for(int i = 0; i < NumberOfCalls; i++)
  177. {
  178. *phr = pPipe->WriteMessage(
  179. IPM_OP_SEND_COUNTERS, // ping reply opcode
  180. dwDataLength,
  181. pData
  182. );
  183. }
  184. if(pBuffer)
  185. delete [] pBuffer;
  186. return TRUE;
  187. }
  188. BOOL DoHResultTest(HRESULT* phr, IPM_MESSAGE_PIPE* pPipe)
  189. {
  190. // Test 67034 needs special processing
  191. DWORD dwDataLength;
  192. HRESULT * pData = NULL;
  193. DWORD dwTickCount;
  194. DWORD dwStopTickCount;
  195. DWORD dwAttackDurationMsec;
  196. HRESULT hrToSend = S_OK;
  197. DBGPRINTF((DBG_CONTEXT, "In DoHResultTest()\n"));
  198. dwDataLength = UseDataLength ? DataLength : sizeof(hrToSend);
  199. switch(DataPointerType)
  200. {
  201. default:
  202. case RWP_DATA_POINTER_TYPE_VALID:
  203. pData = &hrToSend;
  204. break;
  205. case RWP_DATA_POINTER_TYPE_NULL:
  206. pData = NULL;
  207. break;
  208. case RWP_DATA_POINTER_TYPE_INVALID:
  209. pData = (HRESULT*) 1;
  210. break;
  211. }
  212. if(AttackDuration == 0)
  213. {
  214. *phr = pPipe->WriteMessage(
  215. IPM_OP_HRESULT, // ping reply opcode
  216. dwDataLength,
  217. pData
  218. );
  219. }
  220. else
  221. {
  222. // we're doing a DoS attack for some amount of time
  223. dwTickCount = GetTickCount();
  224. // convert duration to msec
  225. dwAttackDurationMsec = AttackDuration * 60 * 1000;
  226. dwStopTickCount = dwTickCount + dwAttackDurationMsec;
  227. while(dwTickCount < dwStopTickCount)
  228. {
  229. *phr = pPipe->WriteMessage(
  230. IPM_OP_HRESULT, // ping reply opcode
  231. dwDataLength,
  232. pData
  233. );
  234. dwTickCount = GetTickCount();
  235. }
  236. }
  237. return TRUE;
  238. }
  239. BOOL DoWorkerRequestShutdownTest(HRESULT* phr, IPM_MESSAGE_PIPE* pPipe)
  240. {
  241. DWORD dwDataLength;
  242. IPM_WP_SHUTDOWN_MSG * pData = NULL;
  243. IPM_WP_SHUTDOWN_MSG reason = IPM_WP_RESTART_COUNT_REACHED;
  244. DBGPRINTF((DBG_CONTEXT, "In DoWorkerRequestShutdownTest()\n"));
  245. dwDataLength = UseDataLength ? DataLength : sizeof(reason);
  246. switch(DataPointerType)
  247. {
  248. default:
  249. case RWP_DATA_POINTER_TYPE_VALID:
  250. pData = &reason;
  251. break;
  252. case RWP_DATA_POINTER_TYPE_NULL:
  253. pData = NULL;
  254. break;
  255. case RWP_DATA_POINTER_TYPE_INVALID:
  256. pData = (IPM_WP_SHUTDOWN_MSG *) 1;
  257. break;
  258. case RWP_DATA_POINTER_TYPE_INVALID_REASON:
  259. reason = (IPM_WP_SHUTDOWN_MSG) ((IPM_WP_SHUTDOWN_MSG)2*IPM_WP_MAXIMUM);
  260. pData = &reason;
  261. break;
  262. }
  263. *phr = pPipe->WriteMessage(
  264. IPM_OP_WORKER_REQUESTS_SHUTDOWN, // ping reply opcode
  265. dwDataLength,
  266. pData
  267. );
  268. return TRUE;
  269. }
  270. BOOL DoInvalidOpcodeTest(HRESULT* phr, IPM_MESSAGE_PIPE* pPipe)
  271. {
  272. // Just use params for a shutdown reply
  273. DWORD dwDataLength;
  274. IPM_WP_SHUTDOWN_MSG * pData = NULL;
  275. DBGPRINTF((DBG_CONTEXT, "In DoInvalidOpcodeTest()\n"));
  276. IPM_WP_SHUTDOWN_MSG reason = IPM_WP_RESTART_COUNT_REACHED;
  277. pData = &reason;
  278. dwDataLength = sizeof(reason);
  279. *phr = pPipe->WriteMessage(
  280. (IPM_OPCODE) 50,
  281. dwDataLength,
  282. pData
  283. );
  284. return TRUE;
  285. }
  286. LONG RWP_Ping_Behavior(HRESULT* hr, IPM_MESSAGE_PIPE* pPipe)
  287. {
  288. *hr = S_OK;
  289. int i = 0;
  290. switch (PingBehavior)
  291. {
  292. //
  293. //Don't respond to pings
  294. //
  295. case RWP_PING_NO_ANSWER:
  296. DBGPRINTF((DBG_CONTEXT, "Rogue: Not responding to Ping\n"));
  297. break;
  298. //
  299. //Responding with n pings
  300. //
  301. case RWP_PING_MULTI_ANSWER:
  302. DBGPRINTF((DBG_CONTEXT, "Rogue: Responding to Ping %d times", PingCount));
  303. for (i = 0; i < PingCount; i++)
  304. {
  305. *hr = pPipe->WriteMessage(
  306. IPM_OP_PING_REPLY, // ping reply opcode
  307. 0, // no data to send
  308. NULL // pointer to no data
  309. );
  310. }
  311. break;
  312. //
  313. //Respond after n seconds
  314. //
  315. case RWP_PING_DELAY_ANSWER:
  316. DBGPRINTF((DBG_CONTEXT, "Rogue: Delay responding to Ping for %d seconds", PingCount));
  317. RWP_Sleep_For(PingCount);
  318. //return 0 so that we'll keep going (this is a delay, not fail)
  319. return (RWP_NO_MISBEHAVE);
  320. break;
  321. default:
  322. DBGPRINTF((DBG_CONTEXT, "Rogue: Unknown Ping Behavior = %d\n", PingBehavior));
  323. break;
  324. }
  325. return (PingBehavior);
  326. } // RWP_Ping_Behavior
  327. LONG RWP_Shutdown_Behavior(HRESULT* hr)
  328. {
  329. *hr = S_OK;
  330. switch (ShutdownBehavior)
  331. {
  332. case RWP_SHUTDOWN_NOT_OBEY:
  333. //
  334. //Not shutting down, period
  335. //
  336. DBGPRINTF((DBG_CONTEXT, "Rogue: Not shutting down\n"));
  337. break;
  338. case RWP_SHUTDOWN_DELAY:
  339. //
  340. //Sleeping for n seconds before continuing on
  341. //
  342. DBGPRINTF((DBG_CONTEXT, "Rogue: Sleeping for %d seconds before shutdown\n", ShutdownCount));
  343. RWP_Sleep_For(ShutdownCount);
  344. //return 0 so that we'll keep going (this is a delay, not fail)
  345. return (RWP_NO_MISBEHAVE);
  346. break;
  347. default:
  348. DBGPRINTF((DBG_CONTEXT, "Rogue: Unknown Shutdown Behavior\n"));
  349. break;
  350. }
  351. return (ShutdownBehavior);
  352. } // RWP_Shutdown_Behavior
  353. LONG RWP_Rotation_Behavior(HRESULT* pHr, IPM_MESSAGE_PIPE* pPipe)
  354. {
  355. *pHr = S_OK;
  356. IPM_WP_SHUTDOWN_MSG reason;
  357. switch (RotationBehavior)
  358. {
  359. case RWP_ROTATION_INVALID_REASON:
  360. DBGPRINTF((DBG_CONTEXT, "Rogue: Sending Invalid shut-down reason\n"));
  361. reason = IPM_WP_MINIMUM;
  362. *pHr = pPipe->WriteMessage(
  363. IPM_OP_WORKER_REQUESTS_SHUTDOWN, // sends shut-down message
  364. sizeof(reason), // data to send
  365. (BYTE *)&reason // pointer to data
  366. );
  367. break;
  368. default:
  369. DBGPRINTF((DBG_CONTEXT, "Rogue: Unknown Rotation Behavior\n"));
  370. break;
  371. }
  372. return (RotationBehavior);
  373. }
  374. LONG RWP_Startup_Behavior(HRESULT* rc)
  375. {
  376. //
  377. //modify rc accordingly
  378. //
  379. *rc = NO_ERROR;
  380. switch (StartupBehavior)
  381. {
  382. case RWP_STARTUP_NOT_OBEY:
  383. //
  384. //Don't register with WAS
  385. //
  386. DBGPRINTF((DBG_CONTEXT, "Rogue: Not registering with WAS\n"));
  387. break;
  388. case RWP_STARTUP_DELAY:
  389. //
  390. //Delay starting up the thread message loop
  391. //
  392. DBGPRINTF((DBG_CONTEXT, "Rogue: Delay starting up for %d\n", StartupCount));
  393. RWP_Sleep_For(StartupCount);
  394. //return 0 so that we'll keep going (this is a delay, not fail)
  395. return (RWP_NO_MISBEHAVE);
  396. case RWP_STARTUP_NOT_REGISTER_FAIL:
  397. //
  398. //Quit before registering with UL
  399. //
  400. DBGPRINTF((DBG_CONTEXT, "Rogue: Not starting up (unregistered)... shutting down\n"));
  401. // BUGBUG - what is this?
  402. //wpContext->IndicateShutdown(SHUTDOWN_REASON_ADMIN);
  403. //return 0 so that it enters (and subsequently exits) the thread loop
  404. return (RWP_NO_MISBEHAVE);
  405. //
  406. //It looks like the place to modify is in wpcontext.cxx,
  407. //when it tries to initialize IPM if requested
  408. //
  409. default:
  410. break;
  411. }
  412. return (StartupBehavior);
  413. }
  414. LONG RWP_Health_Behavior()
  415. {
  416. return 0;
  417. }
  418. /*
  419. LONG RWP_Recycle_Behavior() {
  420. }
  421. */
  422. void RWP_Sleep_For(LONG lTime) {
  423. SleepEx(
  424. (DWORD)lTime * 1000, //sleep for lTimeToSleep * 1000 milliseconds (4 second increments)
  425. FALSE); // not alertable
  426. DBGPRINTF((DBG_CONTEXT, "Done sleeping \n"));
  427. }
  428. void RWP_Display_Behavior()
  429. {
  430. DBGPRINTF((DBG_CONTEXT, "Rogue Behavior Status\n"));
  431. switch(PingBehavior)
  432. {
  433. case RWP_NO_MISBEHAVE:
  434. DBGPRINTF((DBG_CONTEXT, RWP_NO_PING_MISBEHAVE_MSG));
  435. break;
  436. case RWP_PING_NO_ANSWER:
  437. DBGPRINTF((DBG_CONTEXT, RWP_PING_NO_ANSWER_MSG));
  438. break;
  439. case RWP_PING_MULTI_ANSWER:
  440. DBGPRINTF((DBG_CONTEXT, "%s %d\n", RWP_PING_MULTI_ANSWER_MSG, PingCount));
  441. break;
  442. case RWP_PING_DELAY_ANSWER:
  443. DBGPRINTF((DBG_CONTEXT, "%s %d\n", RWP_PING_DELAY_ANSWER_MSG, PingCount));
  444. break;
  445. default:
  446. DBGPRINTF((DBG_CONTEXT, "Ping behavior set to unknown value"));
  447. break;
  448. }
  449. switch(StartupBehavior)
  450. {
  451. case RWP_NO_MISBEHAVE:
  452. DBGPRINTF((DBG_CONTEXT, RWP_NO_STARTUP_MISBEHAVE_MSG));
  453. break;
  454. case RWP_STARTUP_NOT_OBEY:
  455. DBGPRINTF((DBG_CONTEXT, RWP_STARTUP_NOT_OBEY_MSG));
  456. break;
  457. case RWP_STARTUP_DELAY:
  458. DBGPRINTF((DBG_CONTEXT, "%s %d\n", RWP_STARTUP_DELAY_MSG, StartupCount));
  459. break;
  460. case RWP_STARTUP_NOT_REGISTER_FAIL:
  461. DBGPRINTF((DBG_CONTEXT, RWP_STARTUP_NOT_REGISTER_FAIL_MSG));
  462. break;
  463. default:
  464. DBGPRINTF((DBG_CONTEXT, "Startup behavior set to unknown value"));
  465. break;
  466. }
  467. switch(ShutdownBehavior)
  468. {
  469. case RWP_NO_MISBEHAVE:
  470. DBGPRINTF((DBG_CONTEXT, RWP_NO_SHUTDOWN_MISBEHAVE_MSG));
  471. break;
  472. case RWP_SHUTDOWN_NOT_OBEY:
  473. DBGPRINTF((DBG_CONTEXT, RWP_SHUTDOWN_NOT_OBEY_MSG));
  474. break;
  475. case RWP_SHUTDOWN_DELAY:
  476. DBGPRINTF((DBG_CONTEXT, RWP_SHUTDOWN_DELAY_MSG, ShutdownCount));
  477. break;
  478. default:
  479. DBGPRINTF((DBG_CONTEXT, "Shutdown behavior set to unknown value"));
  480. break;
  481. }
  482. switch(RotationBehavior)
  483. {
  484. case RWP_NO_MISBEHAVE:
  485. DBGPRINTF((DBG_CONTEXT, RWP_NO_ROTATION_MISBEHAVE_MSG));
  486. break;
  487. case RWP_ROTATION_INVALID_REASON:
  488. DBGPRINTF((DBG_CONTEXT, RWP_ROTATION_INVALID_REASON_MSG));
  489. break;
  490. default:
  491. DBGPRINTF((DBG_CONTEXT, "Rotation behavior set to unknown value"));
  492. break;
  493. }
  494. switch(RecycleBehavior)
  495. {
  496. case RWP_NO_MISBEHAVE:
  497. DBGPRINTF((DBG_CONTEXT, RWP_NO_RECYCLE_MISBEHAVE_MSG));
  498. break;
  499. case RWP_RECYCLE_NOT_OBEY:
  500. DBGPRINTF((DBG_CONTEXT, RWP_RECYCLE_NOT_OBEY_MSG));
  501. break;
  502. case RWP_RECYCLE_DELAY:
  503. DBGPRINTF((DBG_CONTEXT, "%s %d\n", RWP_RECYCLE_DELAY_MSG, RecycleCount));
  504. break;
  505. default:
  506. DBGPRINTF((DBG_CONTEXT, "Shutdown behavior set to unknown value"));
  507. break;
  508. }
  509. switch(HealthBehavior)
  510. {
  511. case RWP_NO_MISBEHAVE:
  512. DBGPRINTF((DBG_CONTEXT, RWP_NO_HEALTH_MISBEHAVE_MSG));
  513. break;
  514. case RWP_HEALTH_OK:
  515. DBGPRINTF((DBG_CONTEXT, RWP_HEALTH_OK_MSG));
  516. break;
  517. case RWP_HEALTH_NOT_OK:
  518. DBGPRINTF((DBG_CONTEXT, RWP_HEALTH_NOT_OK_MSG));
  519. break;
  520. case RWP_HEALTH_TERMINALLY_ILL:
  521. DBGPRINTF((DBG_CONTEXT, RWP_HEALTH_TERMINALLY_ILL_MSG));
  522. break;
  523. default:
  524. break;
  525. }
  526. }
  527. void RWP_Read_LONG_from_Registry(HKEY hkey, const WCHAR* szSubKey, LONG* lValue)
  528. {
  529. LONG lResult;
  530. DWORD dwType;
  531. DWORD len = sizeof(lValue);
  532. HKEY myKey;
  533. lResult = RegQueryValueEx(
  534. hkey,
  535. szSubKey,
  536. 0,
  537. &dwType,
  538. (LPBYTE)lValue,
  539. &len);
  540. if (lResult != ERROR_SUCCESS)
  541. {
  542. //sets default = 0 (no misbehave)
  543. *lValue = RWP_NO_MISBEHAVE;
  544. /*
  545. //key does not exist -- try to create it
  546. lResult = RegCreateKeyEx(
  547. hkey,
  548. szSubKey,
  549. 0,
  550. NULL,
  551. REG_OPTION_NON_VOLATILE,
  552. KEY_ALL_ACCESS,
  553. NULL,
  554. &myKey,
  555. &dwType);
  556. */
  557. }
  558. }
  559. void RWP_Write_LONG_to_Registry(const WCHAR* szSubKey, LONG lValue)
  560. {
  561. LONG lResult;
  562. HKEY hkMyKey;
  563. lResult = RegOpenKeyEx(
  564. HKEY_LOCAL_MACHINE, //root key
  565. RWP_CONFIG_LOCATION, //sub key
  566. 0, //reserved - must be 0
  567. KEY_ALL_ACCESS, //SAM
  568. &hkMyKey); //my pointer to HKEY
  569. if (lResult != ERROR_SUCCESS)
  570. {
  571. DBGPRINTF((DBG_CONTEXT, "Unable to open configuration key. RegOpenKeyEx returned %d\n", lResult));
  572. return;
  573. }
  574. lResult = RegSetValueEx(
  575. hkMyKey,
  576. szSubKey,
  577. 0,
  578. REG_DWORD,
  579. (LPBYTE)&lValue,
  580. sizeof(lValue));
  581. RegCloseKey(hkMyKey);
  582. ASSERT(lResult == ERROR_SUCCESS);
  583. return;
  584. }
  585. BOOL RWP_Read_Config(const WCHAR* szRegKey)
  586. {
  587. BOOL bSuccess = FALSE;
  588. HKEY hkMyKey;
  589. LONG lResult;
  590. DWORD dwDisp;
  591. DWORD dwLastError = 0;
  592. //
  593. // Initialize to default values
  594. //
  595. // New behavior
  596. OpCodeToTest = RWP_IPM_OP_NONE;
  597. DataLength = 0; // 0 means set it to the actual data length
  598. UseDataLength = FALSE; // by default we'll use the valid data length
  599. DataPointerType = RWP_DATA_POINTER_TYPE_VALID;
  600. NumberOfCalls = 1;
  601. AttackDuration = 0;
  602. PingBehavior = RWP_NO_MISBEHAVE;
  603. ShutdownBehavior = RWP_NO_MISBEHAVE;
  604. StartupBehavior = RWP_NO_MISBEHAVE;
  605. HealthBehavior = RWP_NO_MISBEHAVE;
  606. RecycleBehavior = RWP_NO_MISBEHAVE;
  607. AppPoolBehavior = RWP_NO_MISBEHAVE;
  608. RWP_EXTRA_DEBUG = RWP_DEBUG_OFF;
  609. lResult = RegOpenKeyEx(
  610. HKEY_LOCAL_MACHINE, //root key
  611. szRegKey, //sub key
  612. 0, //reserved - must be 0
  613. KEY_ALL_ACCESS, //SAM
  614. &hkMyKey); //my pointer to HKEY
  615. if (lResult != ERROR_SUCCESS)
  616. {
  617. DBGPRINTF((DBG_CONTEXT, "Unable to open configuration key. RegOpenKeyEx returned %d\n", lResult));
  618. }
  619. else
  620. { //my key exists. Read in config info and validate
  621. DBGPRINTF((DBG_CONTEXT, "Key exists\n"));
  622. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_OPCODE_TO_TEST, &OpCodeToTest);
  623. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_IPM_DATA_LENGTH, &DataLength);
  624. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_IPM_USE_DATA_LENGTH, &UseDataLength);
  625. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_IPM_POINTER_TYPE, &DataPointerType);
  626. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_NUMBER_OF_CALLS, &NumberOfCalls);
  627. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_ATTACK_DURATION, &AttackDuration);
  628. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_PING_BEHAVIOR, &PingBehavior);
  629. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_SHUTDOWN_BEHAVIOR, &ShutdownBehavior);
  630. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_ROTATION_BEHAVIOR, &RotationBehavior);
  631. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_STARTUP_BEHAVIOR, &StartupBehavior);
  632. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_HEALTH_BEHAVIOR, &HealthBehavior);
  633. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_RECYCLE_BEHAVIOR, &RecycleBehavior);
  634. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_APP_POOL_BEHAVIOR, &AppPoolBehavior);
  635. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_PING_COUNT, &PingCount);
  636. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_SHUTDOWN_COUNT, &ShutdownCount);
  637. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_ROTATION_COUNT, &RotationCount);
  638. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_STARTUP_COUNT, &StartupCount);
  639. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_HEALTH_COUNT, &HealthCount);
  640. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_RECYCLE_COUNT, &RecycleCount);
  641. RWP_Read_LONG_from_Registry(hkMyKey, RWP_CONFIG_EXTRA_DEBUG, &RWP_EXTRA_DEBUG);
  642. }
  643. bSuccess = TRUE;
  644. RegCloseKey(hkMyKey);
  645. //
  646. //Declare our intentions
  647. //
  648. RWP_Display_Behavior();
  649. DBGPRINTF((DBG_CONTEXT, "Finished Configurations\n"));
  650. //TODO: Display PID and command line info...
  651. return (bSuccess);
  652. }
  653. /*
  654. Methods modified:
  655. iiswp.cxx
  656. wpipm.cxx (3 places - handleping, handleshutdown, pipedisconnected)
  657. */