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.

516 lines
16 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 2001.
  5. //
  6. // File: genserv.cpp
  7. //
  8. // Contents: Functions for handling the services within SCE
  9. //
  10. // History:
  11. //
  12. //---------------------------------------------------------------------------
  13. #include "stdafx.h"
  14. #include "afxdlgs.h"
  15. #include "cookie.h"
  16. #include "snapmgr.h"
  17. #include "cservice.h"
  18. #include "aservice.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // Event handlers for IFrame::Notify
  26. void CSnapin::CreateProfServiceResultList(MMC_COOKIE cookie,
  27. FOLDER_TYPES type,
  28. PEDITTEMPLATE pSceInfo,
  29. LPDATAOBJECT pDataObj
  30. )
  31. {
  32. if ( pSceInfo == NULL || pSceInfo->pTemplate == NULL ) {
  33. return;
  34. }
  35. PSCE_SERVICES pAllServices=NULL, pConfigService;
  36. DWORD rc;
  37. rc = SceEnumerateServices(
  38. &pAllServices,
  39. TRUE//FALSE
  40. );
  41. if ( rc == NO_ERROR ) {
  42. for ( PSCE_SERVICES pThisService=pAllServices;
  43. pThisService != NULL; pThisService = pThisService->Next ) {
  44. for ( pConfigService=pSceInfo->pTemplate->pServices;
  45. pConfigService != NULL; pConfigService = pConfigService->Next ) {
  46. if ( _wcsicmp(pThisService->ServiceName, pConfigService->ServiceName) == 0 ) {
  47. break;
  48. }
  49. }
  50. //
  51. // no matter if config exist for the service, add it
  52. //
  53. PWSTR DisplayName=pThisService->DisplayName;
  54. if ( DisplayName == NULL && pConfigService != NULL ) {
  55. DisplayName = pConfigService->DisplayName;
  56. }
  57. if ( DisplayName == NULL ) {
  58. DisplayName = pThisService->ServiceName;
  59. }
  60. AddResultItem(DisplayName,
  61. (LONG_PTR)pThisService,
  62. (LONG_PTR)pConfigService,
  63. ITEM_PROF_SERV,
  64. -1,
  65. cookie,
  66. FALSE,
  67. pThisService->ServiceName,
  68. (LONG_PTR)pAllServices,
  69. pSceInfo,
  70. pDataObj);
  71. }
  72. //
  73. // add the ones not exist in the current system
  74. //
  75. for ( pConfigService=pSceInfo->pTemplate->pServices;
  76. pConfigService != NULL; pConfigService = pConfigService->Next ) {
  77. for ( pThisService=pAllServices;
  78. pThisService != NULL; pThisService = pThisService->Next ) {
  79. if ( _wcsicmp(pThisService->ServiceName, pConfigService->ServiceName) == 0 )
  80. break;
  81. }
  82. if ( pThisService == NULL ) {
  83. //
  84. // the configuration does not exist on local system
  85. //
  86. PWSTR DisplayName=pConfigService->DisplayName;
  87. if ( DisplayName == NULL ) {
  88. DisplayName = pConfigService->ServiceName;
  89. }
  90. AddResultItem( DisplayName,
  91. 0,
  92. (LONG_PTR)pConfigService,
  93. ITEM_PROF_SERV,
  94. -1,
  95. cookie,
  96. FALSE,
  97. pConfigService->ServiceName,
  98. (LONG_PTR)pAllServices,
  99. pSceInfo,
  100. pDataObj);
  101. }
  102. }
  103. }
  104. }
  105. void CSnapin::DeleteServiceResultList(MMC_COOKIE cookie)
  106. {
  107. CFolder* pFolder = (CFolder *)cookie;
  108. // pFolder could be NULL for the root.
  109. if ( pFolder == NULL )
  110. return;
  111. FOLDER_TYPES type = pFolder->GetType();
  112. if ( type != AREA_SERVICE &&
  113. type != AREA_SERVICE_ANALYSIS )
  114. return;
  115. if ( m_pSelectedFolder == pFolder && m_resultItemHandle )
  116. {
  117. POSITION pos = NULL;
  118. CResult *pResult = NULL;
  119. if (m_pSelectedFolder->GetResultItem(
  120. m_resultItemHandle,
  121. pos,
  122. &pResult) != ERROR_SUCCESS)
  123. {
  124. if ( pResult != NULL )
  125. {
  126. PSCE_SERVICES pAllServices = (PSCE_SERVICES)(pResult->GetID());
  127. SceFreeMemory(pAllServices, SCE_STRUCT_SERVICES);
  128. }
  129. }
  130. }
  131. }
  132. //+--------------------------------------------------------------------------
  133. //
  134. // Method: CreateAnalysisServiceResultList
  135. //
  136. // Synopsis: Create the list of items to display in the result pane
  137. // when in the Analysis/Service section
  138. //
  139. //
  140. // Arguments: [cookie] -
  141. // [type] -
  142. // [pSceInfo] -
  143. // [pBase] -
  144. // [pDataObj] -
  145. //
  146. // Returns: none
  147. //
  148. //---------------------------------------------------------------------------
  149. void
  150. CSnapin::CreateAnalysisServiceResultList(MMC_COOKIE cookie,
  151. FOLDER_TYPES type,
  152. PEDITTEMPLATE pSceInfo,
  153. PEDITTEMPLATE pBase,
  154. LPDATAOBJECT pDataObj )
  155. {
  156. if ( pSceInfo == NULL || pBase == NULL ) {
  157. return;
  158. }
  159. PSCE_SERVICES pAllServices=NULL, pConfigService, pAnalService;
  160. DWORD rc;
  161. rc = SceEnumerateServices(
  162. &pAllServices,
  163. FALSE
  164. );
  165. if ( rc == NO_ERROR ) {
  166. for ( PSCE_SERVICES pThisService=pAllServices;
  167. pThisService != NULL; pThisService = pThisService->Next ) {
  168. //
  169. // look for base setting on this service
  170. //
  171. for ( pConfigService=pBase->pTemplate->pServices;
  172. pConfigService != NULL;
  173. pConfigService = pConfigService->Next ) {
  174. if ( _wcsicmp(pThisService->ServiceName, pConfigService->ServiceName) == 0 ) {
  175. break;
  176. }
  177. }
  178. //
  179. // look for current setting on this service
  180. //
  181. for ( pAnalService=pSceInfo->pTemplate->pServices;
  182. pAnalService != NULL;
  183. pAnalService = pAnalService->Next ) {
  184. if ( _wcsicmp(pThisService->ServiceName, pAnalService->ServiceName) == 0 ) {
  185. break;
  186. }
  187. }
  188. if ( NULL == pAnalService ) {
  189. if ( NULL != pConfigService ) {
  190. //
  191. // a matched item, use base info as the analysis info
  192. //
  193. PWSTR DisplayName=pThisService->DisplayName;
  194. if ( NULL == DisplayName )
  195. DisplayName = pConfigService->DisplayName;
  196. if ( NULL == DisplayName )
  197. DisplayName = pThisService->ServiceName;
  198. AddResultItem(DisplayName,
  199. (LONG_PTR)pConfigService, // use the same base info
  200. (LONG_PTR)pConfigService,
  201. ITEM_ANAL_SERV,
  202. 0,
  203. cookie,
  204. FALSE,
  205. pThisService->ServiceName,
  206. (LONG_PTR)pAllServices,
  207. pBase,
  208. pDataObj);
  209. } else {
  210. //
  211. // a new service
  212. //
  213. PWSTR DisplayName=pThisService->DisplayName;
  214. if ( NULL == DisplayName )
  215. DisplayName = pThisService->ServiceName;
  216. AddResultItem(DisplayName,
  217. (LONG_PTR)pConfigService, // use the same base info
  218. (LONG_PTR)pConfigService,
  219. ITEM_ANAL_SERV,
  220. SCE_STATUS_NEW_SERVICE,
  221. cookie,
  222. FALSE,
  223. pThisService->ServiceName,
  224. (LONG_PTR)pAllServices,
  225. pBase,
  226. pDataObj);
  227. }
  228. } else {
  229. if ( NULL != pConfigService ) {
  230. //
  231. // a matched or mismatched item, depending on status
  232. //
  233. PWSTR DisplayName=pThisService->DisplayName;
  234. if ( NULL == DisplayName )
  235. DisplayName = pConfigService->DisplayName;
  236. if ( NULL == DisplayName )
  237. DisplayName = pAnalService->DisplayName;
  238. if ( NULL == DisplayName )
  239. DisplayName = pThisService->ServiceName;
  240. AddResultItem(DisplayName,
  241. (LONG_PTR)pAnalService,
  242. (LONG_PTR)pConfigService,
  243. ITEM_ANAL_SERV,
  244. pAnalService->Status,
  245. cookie,
  246. FALSE,
  247. pThisService->ServiceName,
  248. (LONG_PTR)pAllServices,
  249. pBase,
  250. pDataObj);
  251. } else {
  252. //
  253. // a not configured service, use last analysis as default
  254. //
  255. PWSTR DisplayName=pThisService->DisplayName;
  256. if ( NULL == DisplayName )
  257. DisplayName = pAnalService->DisplayName;
  258. if ( NULL == DisplayName )
  259. DisplayName = pThisService->ServiceName;
  260. AddResultItem(DisplayName,
  261. (LONG_PTR)pAnalService,
  262. 0,
  263. ITEM_ANAL_SERV,
  264. SCE_STATUS_NOT_CONFIGURED,
  265. cookie,
  266. FALSE,
  267. pThisService->ServiceName,
  268. (LONG_PTR)pAllServices,
  269. pBase,
  270. pDataObj);
  271. }
  272. }
  273. }
  274. //
  275. // ignore the services not existing on the current system
  276. //
  277. /*
  278. for ( pConfigService=pSceInfo->pTemplate->pServices;
  279. pConfigService != NULL; pConfigService = pConfigService->Next ) {
  280. for ( pThisService=pAllServices;
  281. pThisService != NULL; pThisService = pThisService->Next ) {
  282. if ( _wcsicmp(pThisService->ServiceName, pConfigService->ServiceName) == 0 )
  283. break;
  284. }
  285. if ( pThisService == NULL ) {
  286. //
  287. // the configuration does not exist on local system
  288. //
  289. PWSTR DisplayName=pConfigService->DisplayName;
  290. if ( DisplayName == NULL ) {
  291. DisplayName = pConfigService->ServiceName;
  292. }
  293. AddResultItem( DisplayName, 0, (DWORD)pConfigService,
  294. ITEM_PROF_SERV, -1, cookie,false,
  295. pConfigService->ServiceName,(DWORD)pAllServices,pSceInfo);
  296. }
  297. }
  298. */
  299. }
  300. }
  301. HRESULT CSnapin::GetDisplayInfoForServiceNode(RESULTDATAITEM *pResult,
  302. CFolder *pFolder,
  303. CResult *pData)
  304. {
  305. if ( NULL == pResult || NULL == pFolder || NULL == pData ) {
  306. return E_INVALIDARG;
  307. }
  308. // get display info for columns 1,2, and 3
  309. PSCE_SERVICES pService = (PSCE_SERVICES)(pData->GetBase());
  310. PSCE_SERVICES pSetting = (PSCE_SERVICES)(pData->GetSetting());
  311. if ( pResult->nCol > 3 ) {
  312. m_strDisplay = L"";
  313. } else if ((pResult->nCol == 3) &&
  314. ((GetModeBits() & MB_RSOP) == MB_RSOP)) {
  315. m_strDisplay = pData->GetSourceGPOString();
  316. } else if ( NULL == pService ) {
  317. if ( pFolder->GetType() == AREA_SERVICE_ANALYSIS &&
  318. NULL != pSetting ) {
  319. m_strDisplay.LoadString(IDS_NOT_CONFIGURED); //(IDS_INSPECTED);
  320. } else {
  321. m_strDisplay.LoadString(IDS_NOT_CONFIGURED);
  322. }
  323. } else if ( pFolder->GetType() == AREA_SERVICE_ANALYSIS &&
  324. (NULL == pSetting ||
  325. NULL == pSetting->General.pSecurityDescriptor )) {
  326. m_strDisplay.LoadString(IDS_CONFIGURED);
  327. } else if (pResult->nCol == 1) { // both pService and pSetting exist
  328. // startup value
  329. if ( pFolder->GetType() == AREA_SERVICE ) {
  330. switch ( pService->Startup ) {
  331. case SCE_STARTUP_AUTOMATIC:
  332. m_strDisplay.LoadString(IDS_AUTOMATIC);
  333. break;
  334. case SCE_STARTUP_MANUAL:
  335. m_strDisplay.LoadString(IDS_MANUAL);
  336. break;
  337. default:
  338. m_strDisplay.LoadString(IDS_DISABLED);
  339. }
  340. } else {
  341. // analysis area
  342. if ( pService->Startup == pSetting->Startup ) {
  343. m_strDisplay.LoadString(IDS_OK);
  344. } else {
  345. m_strDisplay.LoadString(IDS_INVESTIGATE);
  346. }
  347. }
  348. } else if ( pResult->nCol == 2 ) {
  349. // column 2 - permission
  350. if ( pService->SeInfo & DACL_SECURITY_INFORMATION ) {
  351. if ( pFolder->GetType() == AREA_SERVICE ) {
  352. m_strDisplay.LoadString(IDS_CONFIGURED);
  353. } else {
  354. // analysis area
  355. if ( pService == pSetting || pSetting->Status == 0 ) {
  356. m_strDisplay.LoadString(IDS_OK);
  357. } else {
  358. m_strDisplay.LoadString(IDS_INVESTIGATE);
  359. }
  360. }
  361. } else {// permission is not configured
  362. m_strDisplay.LoadString(IDS_NOT_CONFIGURED);
  363. }
  364. }
  365. pResult->str = (LPOLESTR)(LPCTSTR)m_strDisplay;
  366. return S_OK;
  367. }
  368. //+--------------------------------------------------------------------------
  369. //
  370. // Method: SetupLinkServiceNodeToBase
  371. //
  372. // Synopsis:
  373. //
  374. //
  375. //
  376. // Arguments: [bAdd] -
  377. // [theNode] -
  378. //
  379. // Returns: none
  380. //
  381. //---------------------------------------------------------------------------
  382. void
  383. CSnapin::SetupLinkServiceNodeToBase(BOOL bAdd, LONG_PTR theNode)
  384. {
  385. PEDITTEMPLATE pet;
  386. PSCE_PROFILE_INFO pBaseInfo;
  387. //
  388. // look for the address stored in m_pData->GetBase()
  389. // if found it, delete it.
  390. //
  391. if (0 == theNode) {
  392. return;
  393. }
  394. pet = GetTemplate(GT_COMPUTER_TEMPLATE, AREA_SYSTEM_SERVICE);
  395. if (NULL == pet) {
  396. return;
  397. }
  398. pBaseInfo = pet->pTemplate;
  399. PSCE_SERVICES pServParent, pService;
  400. for ( pService=pBaseInfo->pServices, pServParent=NULL;
  401. pService != NULL; pServParent=pService, pService=pService->Next ) {
  402. if ( theNode == (LPARAM)pService ) {
  403. //
  404. // find the service node
  405. //
  406. if ( !bAdd ) {
  407. //
  408. // unlink
  409. //
  410. if ( pServParent == NULL ) {
  411. //
  412. // the first service
  413. //
  414. pBaseInfo->pServices = pService->Next;
  415. } else {
  416. pServParent->Next = pService->Next;
  417. }
  418. pService->Next = NULL;
  419. }
  420. break;
  421. }
  422. }
  423. if ( bAdd && NULL == pService ) {
  424. //
  425. // need to add this one
  426. //
  427. pService = (PSCE_SERVICES)theNode;
  428. pService->Next = pBaseInfo->pServices;
  429. pBaseInfo->pServices = pService;
  430. }
  431. return;
  432. }
  433. void CSnapin::AddServiceNodeToProfile(PSCE_SERVICES pNode)
  434. {
  435. PEDITTEMPLATE pet;
  436. PSCE_PROFILE_INFO pProfileInfo;
  437. if ( pNode ) {
  438. pet = GetTemplate(GT_LAST_INSPECTION, AREA_SYSTEM_SERVICE);
  439. if (!pet) {
  440. return;
  441. }
  442. pProfileInfo = pet->pTemplate;
  443. pNode->Next = pProfileInfo->pServices;
  444. pProfileInfo->pServices = pNode;
  445. }
  446. return;
  447. }