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.

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