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.

468 lines
12 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright (c) 1997-1999 Microsoft Corporation
  4. /**********************************************************************/
  5. #include "precomp.h"
  6. #include "NSPage.h"
  7. #include "resource.h"
  8. #include "CHString1.h"
  9. #include "wbemerror.h"
  10. #include "RootSecPage.h"
  11. #include "ErrorSecPage.h"
  12. #include "DataSrc.h"
  13. #include "WMIHelp.h"
  14. #include <cominit.h>
  15. #include <stdio.h>
  16. const static DWORD nsPageHelpIDs[] = { // Context Help IDs
  17. IDC_NS_PARA, -1,
  18. IDC_NSTREE, IDH_WMI_CTRL_SECURITY_NAMESPACE_BOX,
  19. IDC_PROPERTIES, IDH_WMI_CTRL_SECURITY_SECURITY_BUTTON,
  20. 0, 0
  21. };
  22. //-------------------------------------------------------------------------
  23. CNamespacePage::CNamespacePage(DataSource *ds, bool htmlSupport) :
  24. CUIHelpers(ds, &(ds->m_rootThread), htmlSupport),
  25. m_HWNDAlcui(0)
  26. {
  27. m_connected = false;
  28. m_hSelectedItem = 0;
  29. }
  30. //-------------------------------------------------------------------------
  31. CNamespacePage::~CNamespacePage(void)
  32. {
  33. if(m_HWNDAlcui)
  34. {
  35. FreeLibrary(m_HWNDAlcui);
  36. m_HWNDAlcui = NULL;
  37. }
  38. }
  39. //---------------------------------------------------------------------------
  40. void CNamespacePage::InitDlg(HWND hDlg)
  41. {
  42. m_hDlg = hDlg;
  43. m_DS->SetControlHandles(GetDlgItem(hDlg,IDC_ENUM_STATIC),GetDlgItem(hDlg,IDC_CANCEL_ENUM));
  44. Refresh(m_hDlg);
  45. }
  46. //---------------------------------------------------------------------------
  47. typedef HPROPSHEETPAGE (WINAPI *CREATEPAGE_PROC) (LPSECURITYINFO);
  48. HPROPSHEETPAGE CNamespacePage::CreateSecurityPage(struct NSNODE *node)
  49. /* CWbemServices &ns,
  50. _bstr_t path,
  51. _bstr_t display)
  52. */
  53. {
  54. HPROPSHEETPAGE hPage = NULL;
  55. // NOTE: (si == NULL) means the target is pre-M3 (RootSecStyle).
  56. ISecurityInformation *si = m_DS->GetSI(node);
  57. // NS_MethodStyle on NT....this is full ACL security.
  58. if(si != NULL)
  59. {
  60. // try to load aclui.
  61. if(m_HWNDAlcui == NULL)
  62. {
  63. m_HWNDAlcui = LoadLibrary(_T("aclui.dll"));
  64. }
  65. // client has a aclui
  66. if(m_HWNDAlcui != NULL)
  67. {
  68. // create aclui with full si.
  69. CREATEPAGE_PROC createPage = (CREATEPAGE_PROC)GetProcAddress(m_HWNDAlcui, "CreateSecurityPage");
  70. if(createPage)
  71. {
  72. si->AddRef();
  73. hPage = createPage(si);
  74. }
  75. else
  76. {
  77. // couldnt get the exported routines.
  78. CErrorSecurityPage *pPage = new CErrorSecurityPage(IDS_NO_CREATE_SEC);
  79. hPage = pPage->CreatePropSheetPage(MAKEINTRESOURCE(IDD_SEC_ERROR));
  80. }
  81. }
  82. else // no editor dude. Upgrade the client to atleast nt4sp4.
  83. {
  84. // cant run aclui from here.
  85. CErrorSecurityPage *pPage = NULL;
  86. if(IsNT())
  87. {
  88. pPage = new CErrorSecurityPage(IDS_NO_ACLUI);
  89. }
  90. else
  91. {
  92. pPage = new CErrorSecurityPage(IDS_NO_98TONT_SEC);
  93. }
  94. if(pPage)
  95. {
  96. hPage = pPage->CreatePropSheetPage(MAKEINTRESOURCE(IDD_SEC_ERROR));
  97. }
  98. }
  99. }
  100. /* else // not new NT
  101. {
  102. // RootSecStyle on 9x or NT (basically pre-M3 on anything)
  103. if(m_DS->IsAncient())
  104. {
  105. // must use internal editor for schema security.
  106. CRootSecurityPage *pPage = new CRootSecurityPage( ns,
  107. CPrincipal::RootSecStyle, path,
  108. m_htmlSupport,
  109. m_DS->m_OSType);
  110. hPage = pPage->CreatePropSheetPage(MAKEINTRESOURCE(IDD_9XSEC));
  111. }
  112. else // NS_MethodStyle on 9x...
  113. {
  114. // must use internal editor for schema security.
  115. CRootSecurityPage *pPage = new CRootSecurityPage(ns, CPrincipal::NS_MethodStyle, path,
  116. m_htmlSupport,
  117. m_DS->m_OSType);
  118. hPage = pPage->CreatePropSheetPage(MAKEINTRESOURCE(IDD_9XSEC));
  119. }
  120. }
  121. */
  122. return hPage;
  123. }
  124. //--------------------------------------------------------------------
  125. void CNamespacePage::OnProperties(HWND hDlg)
  126. {
  127. HPROPSHEETPAGE hPage;
  128. UINT cPages = 0;
  129. BOOL bResult = FALSE;
  130. // get the selected item.
  131. HWND treeHWND = GetDlgItem(hDlg, IDC_NSTREE);
  132. TV_ITEM item;
  133. item.mask = TVIF_PARAM;
  134. if(!m_hSelectedItem)
  135. {
  136. m_hSelectedItem = TreeView_GetRoot(treeHWND);
  137. TreeView_SelectItem(treeHWND,m_hSelectedItem);
  138. }
  139. item.hItem = m_hSelectedItem;
  140. BOOL x = TreeView_GetItem(treeHWND, &item);
  141. if ( FALSE == x )
  142. return;
  143. struct NSNODE *node = ((ITEMEXTRA *)item.lParam)->nsNode;
  144. //TreeView_SelectItem(TreeView_GetRoot(treeHWND))
  145. /* _bstr_t relName(node->fullPath);
  146. // WARNING: [5] ignores the 'root\' part cuz this call is relative to
  147. // the 'root' namespace anyway. If the root name changes length, this
  148. // assumption will break.
  149. CWbemServices ns;
  150. _bstr_t tempName = m_DS->m_whackedMachineName;
  151. if(tempName.length() > 0)
  152. {
  153. tempName += L"\\";
  154. }
  155. tempName += relName;
  156. if(m_DS->IsAncient())
  157. {
  158. ns = m_DS->RootSecNS();
  159. tempName += L"\\security";
  160. // VERY WIERD HACK: if I dont 'exercise' it here, it will hang later on
  161. // when connected to a wmi 698 build.
  162. IEnumWbemClassObject *users = NULL;
  163. HRESULT hr = ns.CreateInstanceEnum(L"__NTLMUser", 0, &users);
  164. users->Release();
  165. users = 0;
  166. }
  167. else
  168. {
  169. ns.ConnectServer(tempName, m_DS->GetCredentials());
  170. }
  171. */ // - - - - - - - - - - - - - - - -
  172. // build the sheet.
  173. // if((bool)ns)
  174. // {
  175. hPage = CreateSecurityPage(node);
  176. if(hPage)
  177. {
  178. // Build dialog title string
  179. TCHAR szTitle[MAX_PATH + 20] = {0};
  180. LoadString(_Module.GetModuleInstance(), IDS_NS_PROP_TITLE,
  181. szTitle, ARRAYSIZE(szTitle));
  182. struct NSNODE *node = ((ITEMEXTRA *)item.lParam)->nsNode;
  183. if(node)
  184. {
  185. lstrcat(szTitle, node->fullPath);
  186. }
  187. PROPSHEETHEADER psh = {0};
  188. psh.dwSize = sizeof(psh);
  189. psh.dwFlags = PSH_DEFAULT;
  190. psh.hwndParent = hDlg;
  191. psh.hInstance = _Module.GetModuleInstance();
  192. psh.pszCaption = szTitle;
  193. psh.nPages = 1;
  194. psh.nStartPage = 0;
  195. psh.phpage = &hPage;
  196. bResult = (BOOL)(PropertySheet(&psh) + 1);
  197. }
  198. // }
  199. }
  200. //---------------------------------------------------------------------------
  201. void CNamespacePage::Refresh(HWND hDlg)
  202. {
  203. if(m_DS && m_DS->IsNewConnection(&m_sessionID))
  204. {
  205. // 9x machines cant manage security on NT machines.
  206. bool is9xToNT = (IsNT() == false) && (m_DS->m_OSType == OSTYPE_WINNT);
  207. EnableWindow(GetDlgItem(hDlg, IDC_NSTREE), !is9xToNT);
  208. EnableWindow(GetDlgItem(hDlg, IDC_PROPERTIES), !is9xToNT);
  209. CHString1 para;
  210. if(is9xToNT)
  211. {
  212. para.LoadString(IDS_NO_98TONT_SEC);
  213. SetWindowText(GetDlgItem(hDlg, IDC_NS_PARA), para);
  214. return; // early.
  215. }
  216. else
  217. {
  218. para.LoadString(IDS_NS_PARA);
  219. SetWindowText(GetDlgItem(hDlg, IDC_NS_PARA), para);
  220. }
  221. CHString1 initMsg;
  222. if(m_DS->m_rootThread.m_status == WbemServiceThread::ready)
  223. {
  224. HWND hTree = GetDlgItem(hDlg, IDC_NSTREE);
  225. TreeView_DeleteAllItems(hTree);
  226. m_DS->DeleteAllNodes();
  227. // bool hideMfls = false; //TODO
  228. m_NSflag = SHOW_ALL;
  229. // old targets only use the the root node for security.
  230. if(m_DS->IsAncient())
  231. {
  232. m_NSflag = ROOT_ONLY;
  233. // TODO: hide the 'hide mfls' checkbox. Moot point on old targets.
  234. }
  235. // else if(hideMfls)
  236. // {
  237. // m_NSflag = DataSource::HIDE_SOME;
  238. // }
  239. m_DS->LoadImageList(hTree);
  240. m_DS->LoadNode(hTree, TVI_ROOT, m_NSflag);
  241. }
  242. else
  243. {
  244. ::EnableWindow(GetDlgItem(hDlg, IDC_NSTREE), FALSE);
  245. ::EnableWindow(GetDlgItem(hDlg, IDC_PROPERTIES), FALSE);
  246. } //endif ServiceIsReady()
  247. }
  248. }
  249. //------------------------------------------------------------------------
  250. void CNamespacePage::OnApply(HWND hDlg, bool bClose)
  251. {
  252. ::SendMessage(GetParent(hDlg), PSM_UNCHANGED, (WPARAM)hDlg, 0L);
  253. }
  254. //------------------------------------------------------------------------
  255. BOOL CNamespacePage::DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  256. {
  257. HWND hTree = GetDlgItem(hDlg,IDC_NSTREE);
  258. struct NSNODE *node;
  259. LPNMTREEVIEW pnm = (LPNMTREEVIEW)lParam;
  260. TCHAR strTemp[1024];
  261. switch(uMsg)
  262. {
  263. case WM_INITDIALOG:
  264. // OutputDebugString(_T("Inside InitDialog!!!!\n"));
  265. InitDlg(hDlg);
  266. break;
  267. case WM_ASYNC_CIMOM_CONNECTED:
  268. if(!m_connected)
  269. {
  270. m_connected = true;
  271. Refresh(hDlg);
  272. }
  273. break;
  274. case WM_NOTIFY:
  275. {
  276. if(pnm->hdr.code == NM_CUSTOMDRAW)
  277. {
  278. LPNMTREEVIEW pnm = (LPNMTREEVIEW)lParam;
  279. LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
  280. switch(lplvcd->nmcd.dwDrawStage)
  281. {
  282. case CDDS_PREPAINT :
  283. SetWindowLong(hDlg,DWLP_MSGRESULT,CDRF_NOTIFYITEMDRAW);
  284. return CDRF_NOTIFYITEMDRAW;
  285. break;
  286. case CDDS_ITEMPREPAINT:
  287. {
  288. if(lplvcd->nmcd.uItemState != CDIS_SELECTED)
  289. {
  290. ITEMEXTRA *pExtra = (ITEMEXTRA *)lplvcd->nmcd.lItemlParam;
  291. node = pExtra->nsNode;
  292. if(node->sType == TYPE_DYNAMIC_CLASS)
  293. {
  294. lplvcd->clrText = RGB(128,128,128);
  295. SetWindowLong(hDlg,DWLP_MSGRESULT,CDRF_NEWFONT);
  296. return CDRF_NEWFONT;
  297. }
  298. }
  299. break;
  300. }
  301. case CDDS_SUBITEM | CDDS_ITEMPREPAINT :
  302. {
  303. if(lplvcd->nmcd.uItemState != CDIS_SELECTED)
  304. {
  305. node = (struct NSNODE *)lplvcd->nmcd.lItemlParam;
  306. if(node->sType == TYPE_DYNAMIC_CLASS)
  307. {
  308. lplvcd->clrText = RGB(128,128,128);
  309. SetWindowLong(hDlg,DWLP_MSGRESULT,CDRF_NEWFONT);
  310. return CDRF_NEWFONT;
  311. }
  312. }
  313. break;
  314. }
  315. default:
  316. // _stprintf(strTemp,_T("*********************** Default : %x *****************\n"),lplvcd->nmcd.dwDrawStage);
  317. // OutputDebugString(strTemp);
  318. break;
  319. }
  320. }
  321. else
  322. {
  323. switch(((LPNMHDR)lParam)->code)
  324. {
  325. // TODO: this one's more complex.
  326. case PSN_SETACTIVE:
  327. Refresh(hDlg);
  328. break;
  329. case PSN_HELP:
  330. HTMLHelper(hDlg);
  331. break;
  332. case PSN_APPLY:
  333. OnApply(hDlg, (((LPPSHNOTIFY)lParam)->lParam == 1));
  334. break;
  335. case TVN_SELCHANGED:
  336. if(((LPNMHDR)lParam)->idFrom == IDC_NSTREE)
  337. {
  338. ITEMEXTRA *extra;
  339. // remember the selection change for OnProperties()
  340. LPNMTREEVIEW pnmtv = (LPNMTREEVIEW)lParam;
  341. m_hSelectedItem = pnmtv->itemNew.hItem;
  342. extra = (ITEMEXTRA *)pnmtv->itemNew.lParam;
  343. if((extra->nsNode->sType == TYPE_STATIC_CLASS) ||
  344. (extra->nsNode->sType == TYPE_DYNAMIC_CLASS) ||
  345. (extra->nsNode->sType == TYPE_SCOPE_CLASS))
  346. {
  347. //Disable the Security Button
  348. EnableWindow(GetDlgItem(hDlg,IDC_PROPERTIES),FALSE);
  349. }
  350. else
  351. {
  352. //In all other cases,enable the Security Button
  353. EnableWindow(GetDlgItem(hDlg,IDC_PROPERTIES),TRUE);
  354. }
  355. }
  356. break;
  357. case TVN_ITEMEXPANDING:
  358. if(((LPNMHDR)lParam)->idFrom == IDC_NSTREE)
  359. {
  360. // expand the node.
  361. LPNMTREEVIEW pnmtv = (LPNMTREEVIEW)lParam;
  362. if(pnmtv->action == TVE_EXPAND)
  363. {
  364. HWND hTree = GetDlgItem(hDlg, IDC_NSTREE);
  365. m_DS->LoadNode(hTree, pnmtv->itemNew.hItem, m_NSflag);
  366. }
  367. }
  368. break;
  369. }
  370. }
  371. }
  372. break;
  373. case WM_COMMAND:
  374. switch(LOWORD(wParam))
  375. {
  376. case IDC_PROPERTIES:
  377. if(HIWORD(wParam) == BN_CLICKED)
  378. {
  379. OnProperties(hDlg);
  380. SetFocus(GetDlgItem(hDlg, IDC_NSTREE));
  381. }
  382. break;
  383. case IDC_CANCEL_ENUM:
  384. {
  385. m_DS->CancelAllAsyncCalls();
  386. break;
  387. }
  388. default: break;
  389. };
  390. break;
  391. case WM_HELP:
  392. if (IsWindowEnabled(hDlg))
  393. {
  394. WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  395. c_HelpFile,
  396. HELP_WM_HELP,
  397. (ULONG_PTR)nsPageHelpIDs);
  398. }
  399. break;
  400. case WM_CONTEXTMENU:
  401. if (IsWindowEnabled(hDlg))
  402. {
  403. WinHelp(hDlg, c_HelpFile,
  404. HELP_CONTEXTMENU,
  405. (ULONG_PTR)nsPageHelpIDs);
  406. }
  407. break;
  408. default:
  409. return FALSE;
  410. }
  411. return TRUE;
  412. }