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.

615 lines
11 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. RACPLSettings.cpp
  5. Abstract:
  6. Author:
  7. Rajesh Soy 10/00
  8. Revision History:
  9. Rajesh Soy - created 10/26/2000
  10. --*/
  11. #include "stdafx.h"
  12. #include "RACPLSettings.h"
  13. CRACPLSettings *g_pcRASettings = NULL;
  14. BOOL APIENTRY DllMain( HANDLE hModule,
  15. DWORD ul_reason_for_call,
  16. LPVOID lpReserved
  17. )
  18. {
  19. switch (ul_reason_for_call)
  20. {
  21. case DLL_PROCESS_ATTACH:
  22. case DLL_THREAD_ATTACH:
  23. case DLL_THREAD_DETACH:
  24. case DLL_PROCESS_DETACH:
  25. break;
  26. }
  27. return TRUE;
  28. }
  29. /*++
  30. Function Name:
  31. CRACPLSettings::OnInitDialog
  32. Routine Description:
  33. Invoked on WM_INITDIALOG
  34. Arguments:
  35. none
  36. Return Value:
  37. always returns TRUE
  38. --*/
  39. BOOL CRACPLSettingsDialog::OnInitDialog()
  40. {
  41. //
  42. // Call CDialog::OnInitDialog();
  43. //
  44. CDialog::OnInitDialog();
  45. //
  46. // Open the RA Settings
  47. //
  48. if(S_OK != OpenRACPLSettings())
  49. {
  50. //
  51. // Error condition
  52. //
  53. goto ExitOnInitDialog;
  54. }
  55. //
  56. // Get the settings
  57. //
  58. if( S_OK != GetRACPLSettings( &m_RACPLSettings ) )
  59. {
  60. //
  61. // Error condition
  62. //
  63. goto ExitOnInitDialog;
  64. }
  65. //
  66. // TODO: Set current values in UI
  67. //
  68. ExitOnInitDialog:
  69. return TRUE;
  70. }
  71. /*++
  72. Function Name:
  73. CRACPLSettings::CRACPLSettings
  74. Routine Description:
  75. Constructor for the CRACPLSettings class
  76. Arguments:
  77. none
  78. Return Value:
  79. S_OK on success. Otherwise, an error code is returned.
  80. --*/
  81. CRACPLSettings::CRACPLSettings()
  82. {
  83. //
  84. // Initialize member variables
  85. //
  86. m_RACPLSettings.dwMode = REG_DWORD_RA_DEFAULTMODE; // Remote Assistance Mode
  87. m_RACPLSettings.dwUnsolicited = REG_DWORD_RA_UNSOLICITED_DEFAULT; // Allow Unsolicited Remote Assistance
  88. m_RACPLSettings.dwMaxTimeout = REG_DWORD_RA_DEFAULT_TIMEOUT; // Maximum Ticket Timeout
  89. m_pcRegKey = NULL;
  90. return;
  91. }
  92. /*++
  93. Function Name:
  94. CRACPLSettings::OpenRACPLSettings
  95. Routine Description:
  96. Member function of the CRACPLSettings class that initializes the RACPLSettings API
  97. Arguments:
  98. none
  99. Return Value:
  100. S_OK on success. Otherwise, an error code is returned.
  101. --*/
  102. DWORD CRACPLSettings::OpenRACPLSettings()
  103. {
  104. DWORD dwRetVal = S_OK;
  105. //
  106. // Instantiate the registry access class
  107. //
  108. if( NULL == m_pcRegKey )
  109. {
  110. m_pcRegKey = new CRegKey;
  111. if( NULL == m_pcRegKey )
  112. {
  113. //
  114. // Error
  115. //
  116. dwRetVal = GetLastError();
  117. goto ExitOpenRACPLSettings;
  118. }
  119. }
  120. else
  121. {
  122. m_pcRegKey->Close();
  123. }
  124. //
  125. // Create the Remote Assistance Settings registry key. Open it if existing
  126. //
  127. if(ERROR_SUCCESS != m_pcRegKey->Create(HKEY_LOCAL_MACHINE, REG_KEY_REMOTEASSISTANCE))
  128. {
  129. //
  130. // Error condition, exit
  131. //
  132. dwRetVal = GetLastError();
  133. goto ExitOpenRACPLSettings;
  134. }
  135. //
  136. // Initialize member variables
  137. //
  138. dwRetVal = GetRACPLSettings( NULL );
  139. ExitOpenRACPLSettings:
  140. return dwRetVal;
  141. }
  142. /*++
  143. Function Name:
  144. CRACPLSettings::CloseRACPLSettings
  145. Routine Description:
  146. Member function of the CRACPLSettings class that closes the RACPLSettings API
  147. Arguments:
  148. none
  149. Return Value:
  150. S_OK on success. Otherwise, an error code is returned.
  151. --*/
  152. DWORD CRACPLSettings::CloseRACPLSettings()
  153. {
  154. DWORD dwRetVal = S_OK;
  155. if( NULL != m_pcRegKey )
  156. {
  157. m_pcRegKey->Close();
  158. m_pcRegKey = NULL;
  159. }
  160. return dwRetVal;
  161. }
  162. /*++
  163. Function Name:
  164. CRACPLSettings::GetRACPLSettings
  165. Routine Description:
  166. Member function of the CRACPLSettings class that reads the Remote Assistance
  167. settings from registry and returns it in the buffer passed
  168. Arguments:
  169. pRACPLSettings - pointer to RACPLSETTINGS structure
  170. Return Value:
  171. S_OK on success. Otherwise, an error code is returned.
  172. --*/
  173. DWORD CRACPLSettings::GetRACPLSettings(
  174. PRACPLSETTINGS pRACPLSettings
  175. )
  176. {
  177. DWORD dwRetVal = S_OK;
  178. if(NULL != m_pcRegKey)
  179. {
  180. //
  181. // Remote Assistance Mode
  182. //
  183. if(ERROR_SUCCESS != m_pcRegKey->QueryValue( m_RACPLSettings.dwMode, REG_VALUE_MODE ))
  184. {
  185. m_RACPLSettings.dwMode = REG_DWORD_RA_DEFAULTMODE;
  186. }
  187. //
  188. // Allow Unsolicited Remote Assistance
  189. //
  190. if(ERROR_SUCCESS != m_pcRegKey->QueryValue( m_RACPLSettings.dwUnsolicited, REG_VALUE_UNSOLICITED ))
  191. {
  192. m_RACPLSettings.dwUnsolicited = REG_DWORD_RA_UNSOLICITED_DEFAULT;
  193. }
  194. //
  195. // Maximum Ticket Timeout
  196. //
  197. if(ERROR_SUCCESS != m_pcRegKey->QueryValue( m_RACPLSettings.dwMaxTimeout, REG_VALUE_MAX_TICKET ))
  198. {
  199. m_RACPLSettings.dwMaxTimeout = REG_DWORD_RA_DEFAULT_TIMEOUT;
  200. }
  201. //
  202. // Copy the settings to the buffer passed if necessary
  203. //
  204. if(NULL != pRACPLSettings)
  205. {
  206. memcpy((void *)pRACPLSettings, (void *)&m_RACPLSettings, sizeof(RACPLSETTINGS));
  207. }
  208. }
  209. else
  210. {
  211. //
  212. // RACPLSettings API has not been initialized
  213. //
  214. dwRetVal = ERROR_BADKEY;
  215. goto ExitGetRACPLSettings;
  216. }
  217. ExitGetRACPLSettings:
  218. return dwRetVal;
  219. }
  220. /*++
  221. Function Name:
  222. CRACPLSettings::SetRACPLSettings
  223. Routine Description:
  224. Member function of the CRACPLSettings class that sets the Remote Assistance
  225. settings in registry from the values passed in the input buffer
  226. Arguments:
  227. pRACPLSettings - pointer to RACPLSETTINGS structure containing the values
  228. to be set
  229. Return Value:
  230. S_OK on success. Otherwise, an error code is returned.
  231. --*/
  232. DWORD CRACPLSettings::SetRACPLSettings(PRACPLSETTINGS pRACPLSettings)
  233. {
  234. DWORD dwRetVal = S_OK;
  235. //
  236. // Sanity Check
  237. //
  238. if(NULL == pRACPLSettings)
  239. {
  240. dwRetVal = ERROR_INVALID_BLOCK;
  241. goto ExitSetRACPLSettings;
  242. }
  243. if(NULL != m_pcRegKey)
  244. {
  245. //
  246. // Remote Assistance Mode
  247. //
  248. switch( pRACPLSettings->dwMode ) {
  249. case REG_DWORD_RA_ENABLED:
  250. case REG_DWORD_RA_DISABLED:
  251. case REG_DWORD_RA_SHADOWONLY:
  252. //
  253. // These are the only valid values
  254. //
  255. if(ERROR_SUCCESS != m_pcRegKey->SetValue( pRACPLSettings->dwMode, REG_VALUE_MODE ))
  256. {
  257. dwRetVal = GetLastError();
  258. goto ExitSetRACPLSettings;
  259. }
  260. m_RACPLSettings.dwMode = pRACPLSettings->dwMode;
  261. break;
  262. default:
  263. //
  264. // Invalid value. Ignore
  265. //
  266. break;
  267. }
  268. //
  269. // Allow Unsolicited Remote Assistance
  270. //
  271. switch( pRACPLSettings->dwUnsolicited ) {
  272. case REG_DWORD_RA_ALLOW:
  273. case REG_DWORD_RA_DISALLOW:
  274. //
  275. // These are the only valid values
  276. //
  277. if(ERROR_SUCCESS != m_pcRegKey->SetValue( pRACPLSettings->dwUnsolicited, REG_VALUE_UNSOLICITED ))
  278. {
  279. dwRetVal = GetLastError();
  280. goto ExitSetRACPLSettings;
  281. }
  282. m_RACPLSettings.dwUnsolicited = pRACPLSettings->dwUnsolicited;
  283. break;
  284. default:
  285. //
  286. // Invalid value. Ignore
  287. //
  288. break;
  289. }
  290. //
  291. // Maximum Ticket Timeout
  292. //
  293. if( (REG_DWORD_RA_TIMEOUT_MIN <= pRACPLSettings->dwMaxTimeout) &&
  294. (REG_DWORD_RA_TIMEOUT_MAX >= pRACPLSettings->dwMaxTimeout))
  295. {
  296. if(ERROR_SUCCESS != m_pcRegKey->SetValue( pRACPLSettings->dwMaxTimeout, REG_VALUE_MAX_TICKET ))
  297. {
  298. dwRetVal = GetLastError();
  299. goto ExitSetRACPLSettings;
  300. }
  301. m_RACPLSettings.dwMaxTimeout = pRACPLSettings->dwMaxTimeout;
  302. }
  303. }
  304. else
  305. {
  306. //
  307. // RACPLSettings API has not been initialized
  308. //
  309. dwRetVal = ERROR_BADKEY;
  310. goto ExitSetRACPLSettings;
  311. }
  312. ExitSetRACPLSettings:
  313. return dwRetVal;
  314. }
  315. /*++
  316. *********************** RACPLSettings API ***************************
  317. --*/
  318. /*++
  319. Function Name:
  320. OpenRACPLSettings
  321. Routine Description:
  322. Initializes the RACPLSettings API
  323. Arguments:
  324. none
  325. Return Value:
  326. S_OK on success. Otherwise, an error code is returned.
  327. --*/
  328. RACPLSETTINGS_API DWORD OpenRACPLSettings(void)
  329. {
  330. DWORD dwRetVal = S_OK;
  331. //
  332. // Allocate the global variable
  333. //
  334. if(NULL == g_pcRASettings)
  335. {
  336. g_pcRASettings = new CRACPLSettings;
  337. if(NULL == g_pcRASettings)
  338. {
  339. //
  340. // Fatal Error
  341. //
  342. dwRetVal = GetLastError();
  343. goto ExitOpenRACPLSettings;
  344. }
  345. }
  346. //
  347. // Call the initialization routine
  348. //
  349. dwRetVal = g_pcRASettings->OpenRACPLSettings();
  350. ExitOpenRACPLSettings:
  351. return dwRetVal;
  352. }
  353. /*++
  354. Function Name:
  355. CloseRACPLSettings
  356. Routine Description:
  357. Closes the RACPLSettings API
  358. Arguments:
  359. none
  360. Return Value:
  361. S_OK on success. Otherwise, an error code is returned.
  362. --*/
  363. RACPLSETTINGS_API DWORD CloseRACPLSettings(void)
  364. {
  365. DWORD dwRetVal = S_OK;
  366. if(NULL != g_pcRASettings)
  367. {
  368. dwRetVal = g_pcRASettings->CloseRACPLSettings();
  369. }
  370. else
  371. {
  372. //
  373. // The registry key for RACPLSettings is not open
  374. //
  375. dwRetVal = ERROR_BADKEY;
  376. }
  377. return dwRetVal;
  378. }
  379. /*++
  380. Function Name:
  381. GetRACPLSettings
  382. Routine Description:
  383. Function that reads the Remote Assistance Settings
  384. from the system registry and returns it in the buffer passed
  385. Arguments:
  386. pRACPLSettings - void pointer that gets the RACPLSETTINGS structure
  387. Return Value:
  388. S_OK on success. Otherwise, an error code is returned.
  389. --*/
  390. RACPLSETTINGS_API DWORD GetRACPLSettings(
  391. PRACPLSETTINGS pRACPLSettings
  392. )
  393. {
  394. DWORD dwRetVal = S_OK;
  395. //
  396. // Sanity check
  397. //
  398. if(NULL == pRACPLSettings)
  399. {
  400. dwRetVal = ERROR_INVALID_BLOCK;
  401. goto ExitGetRACPLSettings;
  402. }
  403. if(NULL != g_pcRASettings)
  404. {
  405. dwRetVal = g_pcRASettings->GetRACPLSettings( pRACPLSettings );
  406. }
  407. else
  408. {
  409. //
  410. // The registry key for RACPLSettings is not open
  411. //
  412. dwRetVal = ERROR_BADKEY;
  413. }
  414. ExitGetRACPLSettings:
  415. return dwRetVal;
  416. }
  417. /*++
  418. Function Name:
  419. SetRACPLSettings
  420. Routine Description:
  421. Function that reads the Remote Assistance Settings
  422. from the buffer passed and writes them to the system registry
  423. Arguments:
  424. pRACPLSettings - pointer to RACPLSETTINGS structure containing the values
  425. to be set
  426. Return Value:
  427. S_OK on success. Otherwise, an error code is returned.
  428. --*/
  429. RACPLSETTINGS_API DWORD SetRACPLSettings(
  430. PRACPLSETTINGS pRACPLSettings
  431. )
  432. {
  433. DWORD dwRetVal = S_OK;
  434. //
  435. // Sanity check
  436. //
  437. if(NULL == pRACPLSettings)
  438. {
  439. dwRetVal = ERROR_INVALID_BLOCK;
  440. goto ExitSetRACPLSettings;
  441. }
  442. if(NULL != g_pcRASettings)
  443. {
  444. dwRetVal = g_pcRASettings->SetRACPLSettings( pRACPLSettings );
  445. }
  446. else
  447. {
  448. //
  449. // The registry key for RACPLSettings is not open
  450. //
  451. dwRetVal = ERROR_BADKEY;
  452. }
  453. ExitSetRACPLSettings:
  454. return dwRetVal;
  455. }