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.

1584 lines
43 KiB

  1. #include "headers.hxx"
  2. #pragma hdrstop
  3. #include "glopres.h"
  4. const wchar_t* RUNTIME_NAME = L"opt";
  5. #define DOWNLEVEL_FILTER_BIT 0x80000000
  6. unsigned long DEFAULT_LOGGING_OPTIONS = 0;
  7. HINSTANCE hResourceModuleHandle;
  8. #define ARRAYLEN(a) (sizeof(a) / sizeof((a)[0]))
  9. #define DBG_OUT_HRESULT(hr) printf("error 0x%x at line %u\n", hr, __LINE__)
  10. #define BREAK_ON_FAIL_HRESULT(hr) \
  11. if (FAILED(hr)) \
  12. { \
  13. DBG_OUT_HRESULT(hr); \
  14. break; \
  15. }
  16. enum SCOPE_TYPE
  17. {
  18. ST_INVALID = 0,
  19. ST_TARGET_COMPUTER = DSOP_SCOPE_TYPE_TARGET_COMPUTER,
  20. ST_UPLEVEL_JOINED_DOMAIN = DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN,
  21. ST_DOWNLEVEL_JOINED_DOMAIN = DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN,
  22. ST_ENTERPRISE_DOMAIN = DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN,
  23. ST_GLOBAL_CATALOG = DSOP_SCOPE_TYPE_GLOBAL_CATALOG,
  24. ST_EXTERNAL_UPLEVEL_DOMAIN = DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN,
  25. ST_EXTERNAL_DOWNLEVEL_DOMAIN = DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN,
  26. ST_WORKGROUP = DSOP_SCOPE_TYPE_WORKGROUP,
  27. ST_USER_ENTERED_UPLEVEL_SCOPE = DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE,
  28. ST_USER_ENTERED_DOWNLEVEL_SCOPE = DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE,
  29. ST_LDAP_CONTAINER = 0x00000400
  30. };
  31. BOOL
  32. IsUplevel(
  33. SCOPE_TYPE Type)
  34. {
  35. switch (Type)
  36. {
  37. case ST_ENTERPRISE_DOMAIN:
  38. case ST_GLOBAL_CATALOG:
  39. case ST_UPLEVEL_JOINED_DOMAIN:
  40. case ST_EXTERNAL_UPLEVEL_DOMAIN:
  41. case ST_USER_ENTERED_UPLEVEL_SCOPE:
  42. case ST_LDAP_CONTAINER:
  43. return TRUE;
  44. default:
  45. return FALSE;
  46. }
  47. }
  48. PWSTR
  49. ScopeNameFromType(ULONG st)
  50. {
  51. PWSTR pwz = L"unknown";
  52. switch (st)
  53. {
  54. case DSOP_SCOPE_TYPE_TARGET_COMPUTER:
  55. pwz = L"Target Computer";
  56. break;
  57. case DSOP_SCOPE_TYPE_GLOBAL_CATALOG:
  58. pwz = L"Global Catalog";
  59. break;
  60. case DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN:
  61. pwz = L"Uplevel Joined Domain";
  62. break;
  63. case DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN:
  64. pwz = L"Enterprise Domain";
  65. break;
  66. case DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN:
  67. pwz = L"External Uplevel Domain";
  68. break;
  69. case DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN:
  70. pwz = L"External Downlevel Domain";
  71. break;
  72. case DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN:
  73. pwz = L"Downlevel Joined Domain";
  74. break;
  75. case DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE:
  76. pwz = L"User Entered Uplevel Scope";
  77. break;
  78. case DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE:
  79. pwz = L"User Entered Downlevel Scope";
  80. break;
  81. case DSOP_SCOPE_TYPE_WORKGROUP:
  82. pwz = L"Workgroup";
  83. break;
  84. }
  85. return pwz;
  86. }
  87. void
  88. NewDupStr(
  89. PWSTR *ppwzDup,
  90. PCWSTR wszSrc)
  91. {
  92. if (wszSrc)
  93. {
  94. *ppwzDup = new WCHAR[lstrlen(wszSrc) + 1];
  95. lstrcpy(*ppwzDup, wszSrc);
  96. }
  97. else
  98. {
  99. *ppwzDup = NULL;
  100. }
  101. }
  102. class CScopeInitInfo: public DSOP_SCOPE_INIT_INFO
  103. {
  104. public:
  105. CScopeInitInfo() { ZeroMemory(this, sizeof *this); cbSize = sizeof *this; }
  106. CScopeInitInfo(const CScopeInitInfo &ToCopy)
  107. {
  108. ZeroMemory(this, sizeof *this);
  109. CScopeInitInfo::operator =(ToCopy);
  110. }
  111. ~CScopeInitInfo()
  112. {
  113. delete [] const_cast<PWSTR>(pwzDcName);
  114. pwzDcName = NULL;
  115. delete [] const_cast<PWSTR>(pwzADsPath);
  116. pwzADsPath = NULL;
  117. }
  118. CScopeInitInfo &
  119. operator =(const CScopeInitInfo &rhs)
  120. {
  121. cbSize = rhs.cbSize;
  122. flType = rhs.flType;
  123. flScope = rhs.flScope;
  124. delete [] const_cast<PWSTR>(pwzDcName);
  125. NewDupStr(const_cast<PWSTR*>(&pwzDcName), rhs.pwzDcName);
  126. delete [] const_cast<PWSTR>(pwzADsPath);
  127. NewDupStr(const_cast<PWSTR*>(&pwzADsPath), rhs.pwzADsPath);
  128. hr = rhs.hr;
  129. FilterFlags.Uplevel.flBothModes = rhs.FilterFlags.Uplevel.flBothModes;
  130. FilterFlags.Uplevel.flMixedModeOnly = rhs.FilterFlags.Uplevel.flMixedModeOnly;
  131. FilterFlags.Uplevel.flNativeModeOnly = rhs.FilterFlags.Uplevel.flNativeModeOnly;
  132. FilterFlags.flDownlevel = rhs.FilterFlags.flDownlevel;
  133. return *this;
  134. }
  135. };
  136. class COpTestDlg: public CDlg
  137. {
  138. public:
  139. COpTestDlg():
  140. m_pop(NULL),
  141. m_idcLastRadioClicked(0),
  142. m_fIgnoreNotifications(FALSE)
  143. {
  144. m_wzFilename[0] = L'\0';
  145. }
  146. ~COpTestDlg()
  147. {
  148. if (m_pop)
  149. {
  150. m_pop->Release();
  151. m_pop = NULL;
  152. }
  153. }
  154. void
  155. DoModalDialog(HWND hwnd)
  156. {
  157. _DoModalDlg(hwnd, IDD_GLOP);
  158. }
  159. HRESULT
  160. Init()
  161. {
  162. HRESULT
  163. hr = CoCreateInstance(CLSID_DsObjectPicker,
  164. NULL,
  165. CLSCTX_INPROC_SERVER,
  166. IID_IDsObjectPicker,
  167. (void **) &m_pop);
  168. if (FAILED(hr))
  169. {
  170. DBG_OUT_HRESULT(hr);
  171. }
  172. return hr;
  173. }
  174. protected:
  175. virtual BOOL _OnCommand(WPARAM wParam, LPARAM lParam);
  176. virtual HRESULT _OnInit(BOOL *pfSetFocus);
  177. virtual BOOL _OnNotify(WPARAM, LPARAM);
  178. private:
  179. void
  180. _AddScope(
  181. ULONG stNew);
  182. void
  183. _SetFlagFilterUiFromInitInfo(int iItem);
  184. void
  185. _SetInitInfoFromFlagFilterUi(int iItem);
  186. void
  187. _PopulateScopeFlagList();
  188. void
  189. _PopulateFilterList(
  190. BOOL fUplevel);
  191. void
  192. _EnableScopeFlagWindows(
  193. BOOL fEnable);
  194. void
  195. _SaveAs();
  196. void
  197. _Save();
  198. void
  199. _Load();
  200. void
  201. _Clear();
  202. void
  203. _InitObjectPicker();
  204. void
  205. _PresetLocalUserManager();
  206. void
  207. _PresetAclUiFile();
  208. IDsObjectPicker *m_pop;
  209. vector<CScopeInitInfo> m_vsii;
  210. ULONG m_idcLastRadioClicked;
  211. WCHAR m_wzFilename[MAX_PATH];
  212. BOOL m_fIgnoreNotifications;
  213. };
  214. class CAddScopeDlg: public CDlg
  215. {
  216. public:
  217. CAddScopeDlg(): m_stNew(0) {}
  218. void
  219. DoModal(HWND hwndParent)
  220. {
  221. _DoModalDlg(hwndParent, IDD_ADD_SCOPE);
  222. }
  223. ULONG
  224. GetNewScopeType()
  225. {
  226. return m_stNew;
  227. }
  228. protected:
  229. virtual HRESULT
  230. _OnInit(
  231. BOOL *pfSetFocus)
  232. {
  233. CheckRadioButton(m_hwnd, FIRST_SCOPE_RADIO, LAST_SCOPE_RADIO, IDC_ADD_SCOPE_RADIO1);
  234. return S_OK;
  235. }
  236. virtual BOOL _OnCommand(WPARAM wParam, LPARAM lParam);
  237. private:
  238. ULONG m_stNew;
  239. };
  240. void
  241. COpTestDlg::_EnableScopeFlagWindows(
  242. BOOL fEnable)
  243. {
  244. EnableWindow(_hCtrl(IDC_SCOPE_FLAG_LIST), fEnable);
  245. EnableWindow(_hCtrl(IDC_SCOPE_FILTER_LIST), fEnable);
  246. EnableWindow(_hCtrl(IDC_BOTH_RADIO), fEnable);
  247. EnableWindow(_hCtrl(IDC_MIXED_RADIO), fEnable);
  248. EnableWindow(_hCtrl(IDC_NATIVE_RADIO), fEnable);
  249. EnableWindow(_hCtrl(IDC_DOWNLEVEL_RADIO), fEnable);
  250. }
  251. BOOL
  252. CAddScopeDlg::_OnCommand(WPARAM wParam, LPARAM lParam)
  253. {
  254. static ULONG s_ast[] =
  255. {
  256. DSOP_SCOPE_TYPE_TARGET_COMPUTER,
  257. DSOP_SCOPE_TYPE_GLOBAL_CATALOG,
  258. DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN,
  259. DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN,
  260. DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN,
  261. DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN,
  262. DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN,
  263. DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE,
  264. DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE,
  265. DSOP_SCOPE_TYPE_WORKGROUP
  266. };
  267. if (LOWORD(wParam) == IDCANCEL)
  268. {
  269. EndDialog(m_hwnd, 0);
  270. return FALSE;
  271. }
  272. if (LOWORD(wParam) != (WORD)IDOK)
  273. {
  274. return FALSE;
  275. }
  276. for (int i = IDC_ADD_SCOPE_RADIO1; i <= LAST_SCOPE_RADIO; i++)
  277. {
  278. if (IsDlgButtonChecked(m_hwnd, i))
  279. {
  280. m_stNew = s_ast[i - IDC_ADD_SCOPE_RADIO1];
  281. }
  282. }
  283. EndDialog(m_hwnd, 0);
  284. return FALSE;
  285. }
  286. struct SScopeFlagInfo
  287. {
  288. LPWSTR pwzName;
  289. ULONG flValue;
  290. };
  291. static SScopeFlagInfo s_ScopeFlagInfo[] =
  292. {
  293. {L"Starting scope", DSOP_SCOPE_FLAG_STARTING_SCOPE},
  294. {L"Default users", DSOP_SCOPE_FLAG_DEFAULT_FILTER_USERS},
  295. {L"Default groups", DSOP_SCOPE_FLAG_DEFAULT_FILTER_GROUPS},
  296. {L"Default computers", DSOP_SCOPE_FLAG_DEFAULT_FILTER_COMPUTERS},
  297. {L"Default contacts", DSOP_SCOPE_FLAG_DEFAULT_FILTER_CONTACTS},
  298. {L"Convert provider to WinNT", DSOP_SCOPE_FLAG_WANT_PROVIDER_WINNT},
  299. {L"Convert provider to LDAP", DSOP_SCOPE_FLAG_WANT_PROVIDER_LDAP},
  300. {L"Convert provider to GC", DSOP_SCOPE_FLAG_WANT_PROVIDER_GC},
  301. {L"Want SID path", DSOP_SCOPE_FLAG_WANT_SID_PATH},
  302. {L"Want downlevel builtins to have path", DSOP_SCOPE_FLAG_WANT_DOWNLEVEL_BUILTIN_PATH}
  303. };
  304. struct SScopeFilterInfo
  305. {
  306. LPWSTR pwzName;
  307. ULONG flValue;
  308. };
  309. static SScopeFlagInfo s_DownlevelScopeFilterInfo[] =
  310. {
  311. {L"Downlevel users", DSOP_DOWNLEVEL_FILTER_USERS},
  312. {L"Downlevel local groups", DSOP_DOWNLEVEL_FILTER_LOCAL_GROUPS},
  313. {L"Downlevel global groups", DSOP_DOWNLEVEL_FILTER_GLOBAL_GROUPS},
  314. {L"Downlevel computers", DSOP_DOWNLEVEL_FILTER_COMPUTERS},
  315. {L"Downlevel world", DSOP_DOWNLEVEL_FILTER_WORLD},
  316. {L"Downlevel authenticated user", DSOP_DOWNLEVEL_FILTER_AUTHENTICATED_USER},
  317. {L"Downlevel anonymous", DSOP_DOWNLEVEL_FILTER_ANONYMOUS},
  318. {L"Downlevel batch", DSOP_DOWNLEVEL_FILTER_BATCH},
  319. {L"Downlevel creator owner", DSOP_DOWNLEVEL_FILTER_CREATOR_OWNER},
  320. {L"Downlevel creator group", DSOP_DOWNLEVEL_FILTER_CREATOR_GROUP},
  321. {L"Downlevel dialup", DSOP_DOWNLEVEL_FILTER_DIALUP},
  322. {L"Downlevel interactive", DSOP_DOWNLEVEL_FILTER_INTERACTIVE},
  323. {L"Downlevel network", DSOP_DOWNLEVEL_FILTER_NETWORK},
  324. {L"Downlevel service", DSOP_DOWNLEVEL_FILTER_SERVICE},
  325. {L"Downlevel system", DSOP_DOWNLEVEL_FILTER_SYSTEM},
  326. {L"Downlevel exclude builtin groups", DSOP_DOWNLEVEL_FILTER_EXCLUDE_BUILTIN_GROUPS},
  327. {L"Downlevel terminal server", DSOP_DOWNLEVEL_FILTER_TERMINAL_SERVER},
  328. {L"Downlevel local service", DSOP_DOWNLEVEL_FILTER_LOCAL_SERVICE},
  329. {L"Downlevel network service", DSOP_DOWNLEVEL_FILTER_NETWORK_SERVICE},
  330. {L"Downlevel remote logon", DSOP_DOWNLEVEL_FILTER_REMOTE_LOGON},
  331. {L"Downlevel all well-known SIDs", DSOP_DOWNLEVEL_FILTER_ALL_WELLKNOWN_SIDS}
  332. };
  333. static SScopeFlagInfo s_UplevelScopeFilterInfo[] =
  334. {
  335. {L"Include advanced view", DSOP_FILTER_INCLUDE_ADVANCED_VIEW},
  336. {L"Users", DSOP_FILTER_USERS},
  337. {L"Builtin groups", DSOP_FILTER_BUILTIN_GROUPS},
  338. {L"Well-known principals", DSOP_FILTER_WELL_KNOWN_PRINCIPALS},
  339. {L"Universal groups DL", DSOP_FILTER_UNIVERSAL_GROUPS_DL},
  340. {L"Universal groups SE", DSOP_FILTER_UNIVERSAL_GROUPS_SE},
  341. {L"Global groups DL", DSOP_FILTER_GLOBAL_GROUPS_DL},
  342. {L"Global groups SE", DSOP_FILTER_GLOBAL_GROUPS_SE},
  343. {L"Domain local groups DL", DSOP_FILTER_DOMAIN_LOCAL_GROUPS_DL},
  344. {L"Domain local groups SE", DSOP_FILTER_DOMAIN_LOCAL_GROUPS_SE},
  345. {L"Contacts", DSOP_FILTER_CONTACTS},
  346. {L"Computers", DSOP_FILTER_COMPUTERS}
  347. };
  348. HRESULT
  349. COpTestDlg::_OnInit(
  350. BOOL *pfSetFocus)
  351. {
  352. LV_COLUMN lvc;
  353. RECT rcLv;
  354. HWND hwndLv;
  355. ZeroMemory(&lvc, sizeof lvc);
  356. lvc.mask = LVCF_FMT | LVCF_WIDTH;
  357. lvc.fmt = LVCFMT_LEFT;
  358. hwndLv = _hCtrl(IDC_SCOPE_LIST);
  359. GetClientRect(hwndLv, &rcLv);
  360. lvc.cx = rcLv.right - GetSystemMetrics(SM_CXVSCROLL);
  361. ListView_InsertColumn(hwndLv, 0, &lvc);
  362. hwndLv = _hCtrl(IDC_SCOPE_FLAG_LIST);
  363. GetClientRect(hwndLv, &rcLv);
  364. lvc.cx = rcLv.right - GetSystemMetrics(SM_CXVSCROLL);
  365. ListView_InsertColumn(hwndLv, 0, &lvc);
  366. hwndLv = _hCtrl(IDC_SCOPE_FILTER_LIST);
  367. GetClientRect(hwndLv, &rcLv);
  368. lvc.cx = rcLv.right - GetSystemMetrics(SM_CXVSCROLL);
  369. ListView_InsertColumn(hwndLv, 0, &lvc);
  370. ListView_SetExtendedListViewStyleEx(_hCtrl(IDC_SCOPE_LIST),
  371. LVS_EX_FULLROWSELECT,
  372. LVS_EX_FULLROWSELECT);
  373. ListView_SetExtendedListViewStyleEx(_hCtrl(IDC_SCOPE_FILTER_LIST),
  374. LVS_EX_CHECKBOXES,
  375. LVS_EX_CHECKBOXES);
  376. ListView_SetExtendedListViewStyleEx(_hCtrl(IDC_SCOPE_FLAG_LIST),
  377. LVS_EX_CHECKBOXES,
  378. LVS_EX_CHECKBOXES);
  379. _EnableScopeFlagWindows(FALSE);
  380. SetMenu(m_hwnd, LoadMenu(hResourceModuleHandle, MAKEINTRESOURCE(IDR_MENU1)));
  381. CheckRadioButton(m_hwnd, FIRST_SCOPE_RADIO, LAST_SCOPE_RADIO, IDC_BOTH_RADIO);
  382. EnableWindow(_hCtrl(IDC_COCREATE_BUTTON), FALSE);
  383. return S_OK;
  384. }
  385. BOOL
  386. COpTestDlg::_OnNotify(
  387. WPARAM wParam,
  388. LPARAM lParam)
  389. {
  390. LPNMHDR pnmh = reinterpret_cast<LPNMHDR> (lParam);
  391. BOOL fResult = TRUE;
  392. if (m_fIgnoreNotifications)
  393. {
  394. return fResult;
  395. }
  396. if (pnmh->idFrom == IDC_SCOPE_LIST)
  397. {
  398. LPNMLISTVIEW pnmlv = reinterpret_cast<LPNMLISTVIEW> (lParam);
  399. switch(pnmh->code)
  400. {
  401. case LVN_ITEMCHANGING:
  402. if (pnmlv->uOldState & LVIS_SELECTED &&
  403. !(pnmlv->uNewState & LVIS_SELECTED))
  404. {
  405. _SetInitInfoFromFlagFilterUi(pnmlv->iItem);
  406. }
  407. break;
  408. case LVN_ITEMCHANGED:
  409. if (pnmlv->uNewState & LVIS_SELECTED &&
  410. !(pnmlv->uOldState & LVIS_SELECTED))
  411. {
  412. _SetFlagFilterUiFromInitInfo(pnmlv->iItem);
  413. }
  414. break;
  415. }
  416. }
  417. return fResult;
  418. }
  419. void
  420. COpTestDlg::_SetFlagFilterUiFromInitInfo(
  421. int iItem)
  422. {
  423. if (iItem < 0)
  424. {
  425. return;
  426. }
  427. HWND hwndLv = _hCtrl(IDC_SCOPE_FLAG_LIST);
  428. for (int i = 0; i < ARRAYLEN(s_ScopeFlagInfo); i++)
  429. {
  430. if (m_vsii[iItem].flScope & s_ScopeFlagInfo[i].flValue)
  431. {
  432. ListView_SetCheckState(hwndLv, i, TRUE);
  433. }
  434. else
  435. {
  436. ListView_SetCheckState(hwndLv, i, FALSE);
  437. }
  438. }
  439. ULONG *pFilter = NULL;
  440. BOOL fShowingUplevel = TRUE;
  441. if (Button_GetCheck(_hCtrl(IDC_BOTH_RADIO)) == BST_CHECKED)
  442. {
  443. pFilter = &m_vsii[iItem].FilterFlags.Uplevel.flBothModes;
  444. }
  445. else if (Button_GetCheck(_hCtrl(IDC_MIXED_RADIO)) == BST_CHECKED)
  446. {
  447. pFilter = &m_vsii[iItem].FilterFlags.Uplevel.flMixedModeOnly;
  448. }
  449. else if (Button_GetCheck(_hCtrl(IDC_NATIVE_RADIO)) == BST_CHECKED)
  450. {
  451. pFilter = &m_vsii[iItem].FilterFlags.Uplevel.flNativeModeOnly;
  452. }
  453. else if (Button_GetCheck(_hCtrl(IDC_DOWNLEVEL_RADIO)) == BST_CHECKED)
  454. {
  455. pFilter = &m_vsii[iItem].FilterFlags.flDownlevel;
  456. fShowingUplevel = FALSE;
  457. }
  458. if (!pFilter)
  459. {
  460. return;
  461. }
  462. hwndLv = _hCtrl(IDC_SCOPE_FILTER_LIST);
  463. if (!ListView_GetItemCount(hwndLv))
  464. {
  465. return;
  466. }
  467. if (fShowingUplevel)
  468. {
  469. for (i = 0; i < ARRAYLEN(s_UplevelScopeFilterInfo); i++)
  470. {
  471. if (*pFilter & s_UplevelScopeFilterInfo[i].flValue)
  472. {
  473. ListView_SetCheckState(hwndLv, i, TRUE);
  474. }
  475. else
  476. {
  477. ListView_SetCheckState(hwndLv, i, FALSE);
  478. }
  479. }
  480. }
  481. else
  482. {
  483. for (i = 0; i < ARRAYLEN(s_DownlevelScopeFilterInfo); i++)
  484. {
  485. if ((*pFilter & s_DownlevelScopeFilterInfo[i].flValue) ==
  486. s_DownlevelScopeFilterInfo[i].flValue)
  487. {
  488. ListView_SetCheckState(hwndLv, i, TRUE);
  489. }
  490. else
  491. {
  492. ListView_SetCheckState(hwndLv, i, FALSE);
  493. }
  494. }
  495. }
  496. }
  497. void
  498. COpTestDlg::_SetInitInfoFromFlagFilterUi(int iItem)
  499. {
  500. if (iItem < 0)
  501. {
  502. return;
  503. }
  504. HWND hwndLv = _hCtrl(IDC_SCOPE_FLAG_LIST);
  505. for (int i = 0; i < ARRAYLEN(s_ScopeFlagInfo); i++)
  506. {
  507. if (ListView_GetCheckState(hwndLv, i))
  508. {
  509. m_vsii[iItem].flScope |= s_ScopeFlagInfo[i].flValue;
  510. }
  511. else
  512. {
  513. m_vsii[iItem].flScope &= ~s_ScopeFlagInfo[i].flValue;
  514. }
  515. }
  516. if (!m_idcLastRadioClicked)
  517. {
  518. return;
  519. }
  520. ULONG *pFilter = NULL;
  521. BOOL fShowingUplevel = TRUE;
  522. if (m_idcLastRadioClicked == IDC_BOTH_RADIO)
  523. {
  524. pFilter = &m_vsii[iItem].FilterFlags.Uplevel.flBothModes;
  525. }
  526. else if (m_idcLastRadioClicked == IDC_MIXED_RADIO)
  527. {
  528. pFilter = &m_vsii[iItem].FilterFlags.Uplevel.flMixedModeOnly;
  529. }
  530. else if (m_idcLastRadioClicked == IDC_NATIVE_RADIO)
  531. {
  532. pFilter = &m_vsii[iItem].FilterFlags.Uplevel.flNativeModeOnly;
  533. }
  534. else if (m_idcLastRadioClicked == IDC_DOWNLEVEL_RADIO)
  535. {
  536. pFilter = &m_vsii[iItem].FilterFlags.flDownlevel;
  537. fShowingUplevel = FALSE;
  538. }
  539. if (!pFilter)
  540. {
  541. return;
  542. }
  543. hwndLv = _hCtrl(IDC_SCOPE_FILTER_LIST);
  544. if (!ListView_GetItemCount(hwndLv))
  545. {
  546. return;
  547. }
  548. if (fShowingUplevel)
  549. {
  550. for (i = 0; i < ARRAYLEN(s_UplevelScopeFilterInfo); i++)
  551. {
  552. if (ListView_GetCheckState(hwndLv, i))
  553. {
  554. *pFilter |= s_UplevelScopeFilterInfo[i].flValue;
  555. }
  556. else
  557. {
  558. *pFilter &= ~s_UplevelScopeFilterInfo[i].flValue;
  559. }
  560. }
  561. }
  562. else
  563. {
  564. for (i = 0; i < ARRAYLEN(s_DownlevelScopeFilterInfo); i++)
  565. {
  566. if (ListView_GetCheckState(hwndLv, i))
  567. {
  568. *pFilter |= s_DownlevelScopeFilterInfo[i].flValue;
  569. }
  570. else
  571. {
  572. *pFilter &= ~s_DownlevelScopeFilterInfo[i].flValue;
  573. if (*pFilter)
  574. {
  575. *pFilter |= DOWNLEVEL_FILTER_BIT;
  576. }
  577. }
  578. }
  579. }
  580. }
  581. #define GetFirstSelected(hwndLv) ListView_GetNextItem(hwndLv, -1, LVNI_SELECTED)
  582. BOOL
  583. COpTestDlg::_OnCommand(WPARAM wParam, LPARAM lParam)
  584. {
  585. BOOL fHandled = TRUE;
  586. if (m_fIgnoreNotifications)
  587. {
  588. return FALSE;
  589. }
  590. switch (LOWORD(wParam))
  591. {
  592. case IDC_ADD:
  593. {
  594. CAddScopeDlg dlg;
  595. dlg.DoModal(m_hwnd);
  596. ULONG stNew = dlg.GetNewScopeType();
  597. if (stNew)
  598. {
  599. _AddScope(stNew);
  600. }
  601. break;
  602. }
  603. case IDC_REMOVE:
  604. {
  605. int iItem = GetFirstSelected(_hCtrl(IDC_SCOPE_LIST));
  606. if (iItem == -1)
  607. {
  608. break;
  609. }
  610. ListView_DeleteItem(_hCtrl(IDC_SCOPE_LIST), iItem);
  611. m_vsii.erase(m_vsii.begin() + iItem);
  612. if (m_vsii.empty())
  613. {
  614. _Clear();
  615. _EnableScopeFlagWindows(FALSE);
  616. }
  617. break;
  618. }
  619. case IDM_OPEN:
  620. _Clear();
  621. _Load();
  622. if (ListView_GetItemCount(_hCtrl(IDC_SCOPE_LIST)) > 0)
  623. {
  624. m_fIgnoreNotifications = TRUE;
  625. ListView_SetItemState(_hCtrl(IDC_SCOPE_LIST), 0, LVIS_SELECTED, LVIS_SELECTED);
  626. _SetFlagFilterUiFromInitInfo(0);
  627. m_fIgnoreNotifications = FALSE;
  628. }
  629. else
  630. {
  631. _EnableScopeFlagWindows(FALSE);
  632. }
  633. break;
  634. case IDM_SAVE:
  635. _SetInitInfoFromFlagFilterUi(GetFirstSelected(_hCtrl(IDC_SCOPE_LIST)));
  636. _Save();
  637. break;
  638. case IDM_SAVE_AS:
  639. _SetInitInfoFromFlagFilterUi(GetFirstSelected(_hCtrl(IDC_SCOPE_LIST)));
  640. _SaveAs();
  641. break;
  642. case IDM_LUM:
  643. _PresetLocalUserManager();
  644. break;
  645. case IDM_ACL_FILE:
  646. _PresetAclUiFile();
  647. break;
  648. case IDM_EXIT:
  649. case IDCANCEL:
  650. EndDialog(GetHwnd(), 0);
  651. break;
  652. case IDC_DOWNLEVEL_RADIO:
  653. case IDC_BOTH_RADIO:
  654. case IDC_MIXED_RADIO:
  655. case IDC_NATIVE_RADIO:
  656. if (HIWORD(wParam) == BN_CLICKED)
  657. {
  658. m_idcLastRadioClicked = LOWORD(wParam);
  659. _SetInitInfoFromFlagFilterUi(GetFirstSelected(_hCtrl(IDC_SCOPE_LIST)));
  660. _PopulateFilterList(LOWORD(wParam) != IDC_DOWNLEVEL_RADIO);
  661. _SetFlagFilterUiFromInitInfo(GetFirstSelected(_hCtrl(IDC_SCOPE_LIST)));
  662. }
  663. break;
  664. case IDC_INIT_BUTTON:
  665. _InitObjectPicker();
  666. break;
  667. case IDC_COCREATE_BUTTON:
  668. if (!m_pop)
  669. {
  670. HRESULT hr = CoCreateInstance(CLSID_DsObjectPicker,
  671. NULL,
  672. CLSCTX_INPROC_SERVER,
  673. IID_IDsObjectPicker,
  674. (void **) &m_pop);
  675. BREAK_ON_FAIL_HRESULT(hr);
  676. EnableWindow(_hCtrl(IDC_COCREATE_BUTTON), FALSE);
  677. EnableWindow(_hCtrl(IDC_RELEASE_BUTTON), TRUE);
  678. EnableWindow(_hCtrl(IDC_INIT_BUTTON), TRUE);
  679. EnableWindow(_hCtrl(IDC_INVOKE_BUTTON), TRUE);
  680. }
  681. else
  682. {
  683. MessageBeep(0);
  684. }
  685. break;
  686. case IDC_RELEASE_BUTTON:
  687. if (m_pop)
  688. {
  689. m_pop->Release();
  690. m_pop = NULL;
  691. EnableWindow(_hCtrl(IDC_RELEASE_BUTTON), FALSE);
  692. EnableWindow(_hCtrl(IDC_COCREATE_BUTTON), TRUE);
  693. EnableWindow(_hCtrl(IDC_INIT_BUTTON), FALSE);
  694. EnableWindow(_hCtrl(IDC_INVOKE_BUTTON), FALSE);
  695. }
  696. break;
  697. case IDC_INVOKE_BUTTON:
  698. {
  699. IDataObject *pdo;
  700. m_pop->InvokeDialog(m_hwnd, &pdo);
  701. if (pdo)
  702. {
  703. STGMEDIUM stgmedium =
  704. {
  705. TYMED_HGLOBAL,
  706. NULL
  707. };
  708. FORMATETC formatetc =
  709. {
  710. static_cast<CLIPFORMAT>(RegisterClipboardFormat(CFSTR_DSOP_DS_SELECTION_LIST)),
  711. NULL,
  712. DVASPECT_CONTENT,
  713. -1,
  714. TYMED_HGLOBAL
  715. };
  716. pdo->GetData(&formatetc, &stgmedium);
  717. ReleaseStgMedium(&stgmedium);
  718. pdo->Release();
  719. }
  720. break;
  721. }
  722. default:
  723. fHandled = FALSE;
  724. break;
  725. }
  726. return fHandled;
  727. }
  728. void
  729. COpTestDlg::_PresetLocalUserManager()
  730. {
  731. _Clear();
  732. m_fIgnoreNotifications = TRUE;
  733. CheckDlgButton(m_hwnd, IDC_MULTISELECT_CHECK, BST_CHECKED);
  734. Edit_SetText(_hCtrl(IDC_ATTRIBUTES_EDIT), L"groupType; ObjectSID");
  735. m_vsii.reserve(7);
  736. CScopeInitInfo sii;
  737. sii.flType = 0x1;
  738. sii.flScope = 0x21;
  739. sii.FilterFlags.Uplevel.flBothModes = 0x2;
  740. sii.FilterFlags.Uplevel.flMixedModeOnly = 0x0;
  741. sii.FilterFlags.Uplevel.flNativeModeOnly = 0x0;
  742. sii.FilterFlags.flDownlevel = 0x80020001;
  743. m_vsii.push_back(sii);
  744. sii.flType = 0x2;
  745. sii.flScope = 0x2;
  746. sii.FilterFlags.Uplevel.flBothModes = 0x0;
  747. sii.FilterFlags.Uplevel.flMixedModeOnly = 0x82;
  748. sii.FilterFlags.Uplevel.flNativeModeOnly = 0x2a2;
  749. sii.FilterFlags.flDownlevel = 0x80000005;
  750. m_vsii.push_back(sii);
  751. sii.flType = 0x4;
  752. sii.flScope = 0x2;
  753. sii.FilterFlags.Uplevel.flBothModes = 0x0;
  754. sii.FilterFlags.Uplevel.flMixedModeOnly = 0x82;
  755. sii.FilterFlags.Uplevel.flNativeModeOnly = 0x2a2;
  756. sii.FilterFlags.flDownlevel = 0x80000005;
  757. m_vsii.push_back(sii);
  758. sii.flType = 0x8;
  759. sii.flScope = 0x2;
  760. sii.FilterFlags.Uplevel.flBothModes = 0x0;
  761. sii.FilterFlags.Uplevel.flMixedModeOnly = 0x82;
  762. sii.FilterFlags.Uplevel.flNativeModeOnly = 0xa2;
  763. sii.FilterFlags.flDownlevel = 0x0;
  764. m_vsii.push_back(sii);
  765. sii.flType = 0x20;
  766. sii.flScope = 0x2;
  767. sii.FilterFlags.Uplevel.flBothModes = 0x0;
  768. sii.FilterFlags.Uplevel.flMixedModeOnly = 0x82;
  769. sii.FilterFlags.Uplevel.flNativeModeOnly = 0xa2;
  770. sii.FilterFlags.flDownlevel = 0x80000005;
  771. m_vsii.push_back(sii);
  772. sii.flType = 0x40;
  773. sii.flScope = 0x2;
  774. sii.FilterFlags.Uplevel.flBothModes = 0x0;
  775. sii.FilterFlags.Uplevel.flMixedModeOnly = 0x82;
  776. sii.FilterFlags.Uplevel.flNativeModeOnly = 0xa2;
  777. sii.FilterFlags.flDownlevel = 0x80000005;
  778. m_vsii.push_back(sii);
  779. sii.flType = 0x10;
  780. sii.flScope = 0x2;
  781. sii.FilterFlags.Uplevel.flBothModes = 0x0;
  782. sii.FilterFlags.Uplevel.flMixedModeOnly = 0x0;
  783. sii.FilterFlags.Uplevel.flNativeModeOnly = 0xa2;
  784. sii.FilterFlags.flDownlevel = 0x0;
  785. m_vsii.push_back(sii);
  786. LVITEM lvi;
  787. ZeroMemory(&lvi, sizeof lvi);
  788. lvi.mask = LVIF_TEXT;
  789. lvi.iItem = 1000;
  790. HWND hwndLv = _hCtrl(IDC_SCOPE_LIST);
  791. for (int i = 0; i < m_vsii.size(); i++)
  792. {
  793. lvi.pszText = ScopeNameFromType(m_vsii[i].flType);
  794. ListView_InsertItem(hwndLv, &lvi);
  795. }
  796. BOOL fUplevel = IsUplevel((SCOPE_TYPE)m_vsii[0].flType);
  797. _EnableScopeFlagWindows(TRUE);
  798. _PopulateScopeFlagList();
  799. _PopulateFilterList(fUplevel);
  800. ListView_SetItemState(_hCtrl(IDC_SCOPE_LIST), 0, LVIS_SELECTED, LVIS_SELECTED);
  801. m_fIgnoreNotifications = FALSE;
  802. if (fUplevel)
  803. {
  804. CheckRadioButton(m_hwnd, FIRST_MODE_RADIO, LAST_MODE_RADIO, IDC_BOTH_RADIO);
  805. }
  806. else
  807. {
  808. CheckRadioButton(m_hwnd, FIRST_MODE_RADIO, LAST_MODE_RADIO, IDC_DOWNLEVEL_RADIO);
  809. }
  810. _SetFlagFilterUiFromInitInfo(0);
  811. }
  812. void
  813. COpTestDlg::_PresetAclUiFile()
  814. {
  815. _Clear();
  816. m_fIgnoreNotifications = TRUE;
  817. CheckDlgButton(m_hwnd, IDC_MULTISELECT_CHECK, BST_CHECKED);
  818. CheckDlgButton(m_hwnd, IDC_SKIP_DC_CHECK, BST_CHECKED);
  819. Edit_SetText(_hCtrl(IDC_ATTRIBUTES_EDIT), L"ObjectSID");
  820. m_vsii.reserve(6);
  821. CScopeInitInfo sii;
  822. sii.flType = 0x2;
  823. sii.flScope = 0x1;
  824. sii.FilterFlags.Uplevel.flBothModes = 0x0;
  825. sii.FilterFlags.Uplevel.flMixedModeOnly = 0x88b;
  826. sii.FilterFlags.Uplevel.flNativeModeOnly = 0xaab;
  827. sii.FilterFlags.flDownlevel = 0x0;
  828. m_vsii.push_back(sii);
  829. sii.flType = 0x4;
  830. sii.flScope = 0x1;
  831. sii.FilterFlags.Uplevel.flBothModes = 0x0;
  832. sii.FilterFlags.Uplevel.flMixedModeOnly = 0x0;
  833. sii.FilterFlags.Uplevel.flNativeModeOnly = 0x0;
  834. sii.FilterFlags.flDownlevel = 0x80017cfd;
  835. m_vsii.push_back(sii);
  836. sii.flType = 0x1;
  837. sii.flScope = 0x0;
  838. sii.FilterFlags.Uplevel.flBothModes = 0x0;
  839. sii.FilterFlags.Uplevel.flMixedModeOnly = 0x0;
  840. sii.FilterFlags.Uplevel.flNativeModeOnly = 0x0;
  841. sii.FilterFlags.flDownlevel = 0x80017cff;
  842. m_vsii.push_back(sii);
  843. sii.flType = 0x10;
  844. sii.flScope = 0x0;
  845. sii.FilterFlags.Uplevel.flBothModes = 0x8ab;
  846. sii.FilterFlags.Uplevel.flMixedModeOnly = 0x0;
  847. sii.FilterFlags.Uplevel.flNativeModeOnly = 0x0;
  848. sii.FilterFlags.flDownlevel = 0x0;
  849. m_vsii.push_back(sii);
  850. sii.flType = 0x8;
  851. sii.flScope = 0x0;
  852. sii.FilterFlags.Uplevel.flBothModes = 0x8a3;
  853. sii.FilterFlags.Uplevel.flMixedModeOnly = 0x0;
  854. sii.FilterFlags.Uplevel.flNativeModeOnly = 0x0;
  855. sii.FilterFlags.flDownlevel = 0x0;
  856. m_vsii.push_back(sii);
  857. sii.flType = 0x20;
  858. sii.flScope = 0x0;
  859. sii.FilterFlags.Uplevel.flBothModes = 0x8a3;
  860. sii.FilterFlags.Uplevel.flMixedModeOnly = 0x0;
  861. sii.FilterFlags.Uplevel.flNativeModeOnly = 0x0;
  862. sii.FilterFlags.flDownlevel = 0x80017cf5;
  863. m_vsii.push_back(sii);
  864. sii.flType = 0x40;
  865. sii.flScope = 0x0;
  866. sii.FilterFlags.Uplevel.flBothModes = 0x8a3;
  867. sii.FilterFlags.Uplevel.flMixedModeOnly = 0x0;
  868. sii.FilterFlags.Uplevel.flNativeModeOnly = 0x0;
  869. sii.FilterFlags.flDownlevel = 0x80017cf5;
  870. m_vsii.push_back(sii);
  871. LVITEM lvi;
  872. ZeroMemory(&lvi, sizeof lvi);
  873. lvi.mask = LVIF_TEXT;
  874. lvi.iItem = 1000;
  875. HWND hwndLv = _hCtrl(IDC_SCOPE_LIST);
  876. for (int i = 0; i < m_vsii.size(); i++)
  877. {
  878. lvi.pszText = ScopeNameFromType(m_vsii[i].flType);
  879. ListView_InsertItem(hwndLv, &lvi);
  880. }
  881. BOOL fUplevel = IsUplevel((SCOPE_TYPE)m_vsii[0].flType);
  882. _EnableScopeFlagWindows(TRUE);
  883. _PopulateScopeFlagList();
  884. _PopulateFilterList(fUplevel);
  885. ListView_SetItemState(_hCtrl(IDC_SCOPE_LIST), 0, LVIS_SELECTED, LVIS_SELECTED);
  886. m_fIgnoreNotifications = FALSE;
  887. _SetFlagFilterUiFromInitInfo(0);
  888. if (fUplevel)
  889. {
  890. CheckRadioButton(m_hwnd, FIRST_MODE_RADIO, LAST_MODE_RADIO, IDC_BOTH_RADIO);
  891. }
  892. else
  893. {
  894. CheckRadioButton(m_hwnd, FIRST_MODE_RADIO, LAST_MODE_RADIO, IDC_DOWNLEVEL_RADIO);
  895. }
  896. _SetFlagFilterUiFromInitInfo(0);
  897. }
  898. void
  899. COpTestDlg::_InitObjectPicker()
  900. {
  901. DSOP_INIT_INFO ii;
  902. ZeroMemory(&ii, sizeof ii);
  903. ii.cbSize = sizeof(ii);
  904. ULONG flags = 0;
  905. if (IsDlgButtonChecked(m_hwnd, IDC_MULTISELECT_CHECK))
  906. {
  907. flags |= DSOP_FLAG_MULTISELECT;
  908. }
  909. if (IsDlgButtonChecked(m_hwnd, IDC_SKIP_DC_CHECK))
  910. {
  911. flags |= DSOP_FLAG_SKIP_TARGET_COMPUTER_DC_CHECK;
  912. }
  913. ii.flOptions = flags;
  914. WCHAR wzTarget[MAX_PATH];
  915. Edit_GetText(_hCtrl(IDC_TARGET_COMPUTER_EDIT), wzTarget, ARRAYLEN(wzTarget));
  916. ii.pwzTargetComputer = wzTarget;
  917. ULONG cchAttributes = Edit_GetTextLength(_hCtrl(IDC_ATTRIBUTES_EDIT));
  918. PWSTR pwzAttributes = new WCHAR[cchAttributes + 1];
  919. if (!pwzAttributes)
  920. {
  921. printf("out of memory\n");
  922. return;
  923. }
  924. Edit_GetText(_hCtrl(IDC_ATTRIBUTES_EDIT), pwzAttributes, cchAttributes + 1);
  925. String strAttr = pwzAttributes;
  926. delete [] pwzAttributes;
  927. list<String> tokens;
  928. strAttr.tokenize(back_inserter(tokens), L"; ");
  929. ii.cAttributesToFetch = static_cast<ULONG>(tokens.size());
  930. list<String>::iterator it;
  931. ii.apwzAttributeNames = new PCWSTR[tokens.size()];
  932. int i;
  933. for (i = 0, it = tokens.begin(); it != tokens.end(); it++, i++)
  934. {
  935. ii.apwzAttributeNames[i] = it->c_str();
  936. }
  937. ii.cDsScopeInfos = static_cast<ULONG>(m_vsii.size());
  938. ii.aDsScopeInfos = new DSOP_SCOPE_INIT_INFO[m_vsii.size()];
  939. for (i = 0; i < ii.cDsScopeInfos; i++)
  940. {
  941. CopyMemory(&ii.aDsScopeInfos[i], &m_vsii[i], sizeof DSOP_SCOPE_INIT_INFO);
  942. }
  943. HRESULT hr = m_pop->Initialize(&ii);
  944. if (FAILED(hr))
  945. {
  946. printf("init failed %#x\n", hr);
  947. }
  948. delete [] ii.aDsScopeInfos;
  949. delete [] ii.apwzAttributeNames;
  950. }
  951. void
  952. COpTestDlg::_SaveAs()
  953. {
  954. OPENFILENAME ofn;
  955. ZeroMemory(&ofn, sizeof ofn);
  956. ofn.lStructSize = sizeof ofn;
  957. ofn.hwndOwner = m_hwnd;
  958. ofn.lpstrFilter = L"Object Picker Tester (*.opt)\0*.OPT\0";
  959. ofn.lpstrDefExt = L"opt";
  960. ofn.nFilterIndex = 1;
  961. ofn.lpstrFile = m_wzFilename;
  962. ofn.nMaxFile = ARRAYLEN(m_wzFilename);
  963. ofn.Flags = OFN_PATHMUSTEXIST;
  964. BOOL fOk = GetSaveFileName(&ofn);
  965. if (!fOk)
  966. {
  967. return;
  968. }
  969. _Save();
  970. }
  971. void
  972. COpTestDlg::_Save()
  973. {
  974. String c_strCRLF(L"\r\n");
  975. String c_strQuote(L"\"");
  976. if (!*m_wzFilename)
  977. {
  978. _SaveAs();
  979. return;
  980. }
  981. // target
  982. // options
  983. // attribute string
  984. // cScopeInfos
  985. // Scopes
  986. String strBuffer;
  987. WCHAR wzTarget[MAX_PATH];
  988. Edit_GetText(_hCtrl(IDC_TARGET_COMPUTER_EDIT), wzTarget, ARRAYLEN(wzTarget));
  989. strBuffer = c_strQuote + wzTarget + c_strQuote + c_strCRLF;
  990. ULONG flags = 0;
  991. if (IsDlgButtonChecked(m_hwnd, IDC_MULTISELECT_CHECK))
  992. {
  993. flags |= DSOP_FLAG_MULTISELECT;
  994. }
  995. if (IsDlgButtonChecked(m_hwnd, IDC_SKIP_DC_CHECK))
  996. {
  997. flags |= DSOP_FLAG_SKIP_TARGET_COMPUTER_DC_CHECK;
  998. }
  999. WCHAR wzBuf[20];
  1000. wsprintf(wzBuf, L"%#x", flags);
  1001. strBuffer += wzBuf + c_strCRLF;
  1002. ULONG cchAttributes = Edit_GetTextLength(_hCtrl(IDC_ATTRIBUTES_EDIT));
  1003. PWSTR pwzAttributes = new WCHAR[cchAttributes + 1];
  1004. if (!pwzAttributes)
  1005. {
  1006. printf("out of memory\n");
  1007. return;
  1008. }
  1009. Edit_GetText(_hCtrl(IDC_ATTRIBUTES_EDIT), pwzAttributes, cchAttributes + 1);
  1010. strBuffer += c_strQuote + pwzAttributes + c_strQuote + c_strCRLF;
  1011. delete [] pwzAttributes;
  1012. wsprintf(wzBuf, L"%u", m_vsii.size());
  1013. strBuffer += wzBuf + c_strCRLF;
  1014. for (int i = 0; i < m_vsii.size(); i++)
  1015. {
  1016. wsprintf(wzBuf, L"%#x", m_vsii[i].flType);
  1017. strBuffer += wzBuf + c_strCRLF;
  1018. wsprintf(wzBuf, L"%#x", m_vsii[i].flScope);
  1019. strBuffer += wzBuf + c_strCRLF;
  1020. wsprintf(wzBuf, L"%#x", m_vsii[i].FilterFlags.Uplevel.flBothModes);
  1021. strBuffer += wzBuf + c_strCRLF;
  1022. wsprintf(wzBuf, L"%#x", m_vsii[i].FilterFlags.Uplevel.flMixedModeOnly);
  1023. strBuffer += wzBuf + c_strCRLF;
  1024. wsprintf(wzBuf, L"%#x", m_vsii[i].FilterFlags.Uplevel.flNativeModeOnly);
  1025. strBuffer += wzBuf + c_strCRLF;
  1026. wsprintf(wzBuf, L"%#x", m_vsii[i].FilterFlags.flDownlevel);
  1027. strBuffer += wzBuf + c_strCRLF;
  1028. if (m_vsii[i].pwzDcName)
  1029. {
  1030. strBuffer += c_strQuote + m_vsii[i].pwzDcName + c_strQuote + c_strCRLF;
  1031. }
  1032. else
  1033. {
  1034. strBuffer += c_strQuote + c_strQuote + c_strCRLF;
  1035. }
  1036. if (m_vsii[i].pwzADsPath)
  1037. {
  1038. strBuffer += c_strQuote + m_vsii[i].pwzADsPath + c_strQuote + c_strCRLF;
  1039. }
  1040. else
  1041. {
  1042. strBuffer += c_strQuote + c_strQuote + c_strCRLF;
  1043. }
  1044. }
  1045. HANDLE hFile = CreateFile(m_wzFilename,
  1046. GENERIC_WRITE,
  1047. FILE_SHARE_READ,
  1048. NULL,
  1049. CREATE_ALWAYS,
  1050. FILE_ATTRIBUTE_NORMAL,
  1051. NULL);
  1052. if (hFile == INVALID_HANDLE_VALUE)
  1053. {
  1054. printf("CreateFile failed %u\n", GetLastError());
  1055. return;
  1056. }
  1057. AnsiString straBuffer;
  1058. strBuffer.convert(straBuffer);
  1059. ULONG cbWritten;
  1060. WriteFile(hFile,
  1061. straBuffer.c_str(),
  1062. static_cast<ULONG>(straBuffer.length()),
  1063. &cbWritten,
  1064. NULL);
  1065. CloseHandle(hFile);
  1066. }
  1067. void
  1068. COpTestDlg::_Load()
  1069. {
  1070. OPENFILENAME ofn;
  1071. ZeroMemory(&ofn, sizeof ofn);
  1072. ofn.lStructSize = sizeof ofn;
  1073. ofn.hwndOwner = m_hwnd;
  1074. ofn.lpstrFilter = L"Object Picker Tester (*.opt)\0*.opt\0";
  1075. ofn.lpstrDefExt = L"opt";
  1076. ofn.nFilterIndex = 1;
  1077. ofn.lpstrFile = m_wzFilename;
  1078. ofn.nMaxFile = ARRAYLEN(m_wzFilename);
  1079. ofn.Flags = OFN_PATHMUSTEXIST;
  1080. BOOL fOk = GetOpenFileName(&ofn);
  1081. if (!fOk)
  1082. {
  1083. return;
  1084. }
  1085. HANDLE hFile = CreateFile(m_wzFilename,
  1086. GENERIC_READ,
  1087. FILE_SHARE_READ,
  1088. NULL,
  1089. OPEN_EXISTING,
  1090. FILE_ATTRIBUTE_NORMAL,
  1091. NULL);
  1092. if (hFile == INVALID_HANDLE_VALUE)
  1093. {
  1094. printf("CreateFile failed %u\n", GetLastError());
  1095. return;
  1096. }
  1097. ULONG cbFile = GetFileSize(hFile, NULL);
  1098. PSTR pstr = new CHAR[cbFile + 1];
  1099. if (!pstr)
  1100. {
  1101. printf("out of memory\n");
  1102. CloseHandle(hFile);
  1103. return;
  1104. }
  1105. ULONG cbRead;
  1106. ReadFile(hFile, pstr, cbFile, &cbRead, NULL);
  1107. CloseHandle(hFile);
  1108. pstr[cbRead] = '\0';
  1109. String strBuffer(pstr);
  1110. delete [] pstr;
  1111. list<String> tokens;
  1112. String c_strCRLF(L"\r\n");
  1113. strBuffer.tokenize(back_inserter(tokens), c_strCRLF);
  1114. list<String>::iterator it;
  1115. it = tokens.begin();
  1116. // target
  1117. // options
  1118. // attribute string
  1119. // cScopeInfos
  1120. // Scopes
  1121. it->strip(String::BOTH, L' ');
  1122. it->strip(String::BOTH, L'"');
  1123. Edit_SetText(_hCtrl(IDC_TARGET_COMPUTER_EDIT), it->c_str());
  1124. it++;
  1125. ULONG flags;
  1126. it->convert(flags, 16);
  1127. if (flags & DSOP_FLAG_MULTISELECT)
  1128. {
  1129. CheckDlgButton(m_hwnd, IDC_MULTISELECT_CHECK, BST_CHECKED);
  1130. }
  1131. else
  1132. {
  1133. CheckDlgButton(m_hwnd, IDC_MULTISELECT_CHECK, BST_UNCHECKED);
  1134. }
  1135. if (flags & DSOP_FLAG_SKIP_TARGET_COMPUTER_DC_CHECK)
  1136. {
  1137. CheckDlgButton(m_hwnd, IDC_SKIP_DC_CHECK, BST_CHECKED);
  1138. }
  1139. else
  1140. {
  1141. CheckDlgButton(m_hwnd, IDC_SKIP_DC_CHECK, BST_UNCHECKED);
  1142. }
  1143. it++;
  1144. it->strip(String::BOTH, L' ');
  1145. it->strip(String::BOTH, L'"');
  1146. Edit_SetText(_hCtrl(IDC_ATTRIBUTES_EDIT), it->c_str());
  1147. it++;
  1148. ULONG cInitInfos;
  1149. it->convert(cInitInfos);
  1150. HWND hwndLv = _hCtrl(IDC_SCOPE_LIST);
  1151. BOOL fFirstIsUplevel = FALSE;
  1152. for (int i = 0; i < cInitInfos; i++)
  1153. {
  1154. CScopeInitInfo sii;
  1155. it++;
  1156. it->convert(sii.flType, 16);
  1157. if (!i)
  1158. {
  1159. fFirstIsUplevel = IsUplevel((SCOPE_TYPE)sii.flType);
  1160. }
  1161. it++;
  1162. it->convert(sii.flScope, 16);
  1163. it++;
  1164. it->convert(sii.FilterFlags.Uplevel.flBothModes, 16);
  1165. it++;
  1166. it->convert(sii.FilterFlags.Uplevel.flMixedModeOnly, 16);
  1167. it++;
  1168. it->convert(sii.FilterFlags.Uplevel.flNativeModeOnly, 16);
  1169. it++;
  1170. it->convert(sii.FilterFlags.flDownlevel, 16);
  1171. it++;
  1172. it->strip(String::BOTH, L' ');
  1173. it->strip(String::BOTH, L'"');
  1174. NewDupStr(const_cast<PWSTR*>(&sii.pwzDcName),it->c_str());
  1175. it++;
  1176. it->strip(String::BOTH, L' ');
  1177. it->strip(String::BOTH, L'"');
  1178. NewDupStr(const_cast<PWSTR*>(&sii.pwzADsPath), it->c_str());
  1179. m_vsii.push_back(sii);
  1180. LVITEM lvi;
  1181. ZeroMemory(&lvi, sizeof lvi);
  1182. lvi.mask = LVIF_TEXT;
  1183. lvi.iItem = 1000;
  1184. lvi.pszText = ScopeNameFromType(sii.flType);
  1185. ListView_InsertItem(hwndLv, &lvi);
  1186. }
  1187. if (cInitInfos)
  1188. {
  1189. m_fIgnoreNotifications = TRUE;
  1190. BOOL fUplevel = IsUplevel((SCOPE_TYPE)m_vsii[0].flType);
  1191. _EnableScopeFlagWindows(TRUE);
  1192. _PopulateScopeFlagList();
  1193. _PopulateFilterList(fUplevel);
  1194. ListView_SetItemState(_hCtrl(IDC_SCOPE_LIST), 0, LVIS_SELECTED, LVIS_SELECTED);
  1195. m_fIgnoreNotifications = FALSE;
  1196. }
  1197. }
  1198. void
  1199. COpTestDlg::_PopulateFilterList(
  1200. BOOL fUplevel)
  1201. {
  1202. HWND hwndLv = _hCtrl(IDC_SCOPE_FILTER_LIST);
  1203. ListView_DeleteAllItems(hwndLv);
  1204. LVITEM lvi;
  1205. ZeroMemory(&lvi, sizeof lvi);
  1206. lvi.mask = LVIF_TEXT;
  1207. lvi.iItem = 1000;
  1208. int i=0;
  1209. if (fUplevel)
  1210. {
  1211. for (i = 0; i < ARRAYLEN(s_UplevelScopeFilterInfo); i++)
  1212. {
  1213. lvi.pszText = s_UplevelScopeFilterInfo[i].pwzName;
  1214. ListView_InsertItem(hwndLv, &lvi);
  1215. }
  1216. }
  1217. else
  1218. {
  1219. for (i = 0; i < ARRAYLEN(s_DownlevelScopeFilterInfo); i++)
  1220. {
  1221. lvi.pszText = s_DownlevelScopeFilterInfo[i].pwzName;
  1222. ListView_InsertItem(hwndLv, &lvi);
  1223. }
  1224. }
  1225. }
  1226. void
  1227. COpTestDlg::_AddScope(
  1228. ULONG stNew)
  1229. {
  1230. LVITEM lvi;
  1231. CScopeInitInfo sii;
  1232. sii.flType = stNew;
  1233. m_vsii.push_back(sii);
  1234. ZeroMemory(&lvi, sizeof lvi);
  1235. lvi.mask = LVIF_TEXT;
  1236. lvi.iItem = 1000;
  1237. lvi.pszText = ScopeNameFromType(stNew);
  1238. HWND hwndLv = _hCtrl(IDC_SCOPE_LIST);
  1239. INT iNew = ListView_InsertItem(hwndLv, &lvi);
  1240. ListView_SetItemState(_hCtrl(IDC_SCOPE_LIST), iNew, LVIS_SELECTED, LVIS_SELECTED);
  1241. hwndLv = _hCtrl(IDC_SCOPE_FLAG_LIST);
  1242. if (!ListView_GetItemCount(hwndLv))
  1243. {
  1244. _EnableScopeFlagWindows(TRUE);
  1245. _PopulateScopeFlagList();
  1246. }
  1247. if (IsUplevel((SCOPE_TYPE)stNew))
  1248. {
  1249. CheckRadioButton(m_hwnd, FIRST_SCOPE_RADIO, LAST_SCOPE_RADIO, IDC_BOTH_RADIO);
  1250. }
  1251. else
  1252. {
  1253. CheckRadioButton(m_hwnd, FIRST_SCOPE_RADIO, LAST_SCOPE_RADIO, IDC_DOWNLEVEL_RADIO);
  1254. }
  1255. _SetFlagFilterUiFromInitInfo(static_cast<ULONG>(m_vsii.size() - 1));
  1256. }
  1257. void
  1258. COpTestDlg::_PopulateScopeFlagList()
  1259. {
  1260. LVITEM lvi;
  1261. ZeroMemory(&lvi, sizeof lvi);
  1262. lvi.mask = LVIF_PARAM | LVIF_TEXT;
  1263. lvi.iItem = 1000;
  1264. HWND hwndLv = _hCtrl(IDC_SCOPE_FLAG_LIST);
  1265. for (int i = 0; i < ARRAYLEN(s_ScopeFlagInfo); i++)
  1266. {
  1267. lvi.pszText = s_ScopeFlagInfo[i].pwzName;
  1268. lvi.lParam = s_ScopeFlagInfo[i].flValue;
  1269. ListView_InsertItem(hwndLv, &lvi);
  1270. }
  1271. }
  1272. void
  1273. COpTestDlg::_Clear()
  1274. {
  1275. CheckDlgButton(m_hwnd, m_idcLastRadioClicked, BST_UNCHECKED);
  1276. CheckDlgButton(m_hwnd, IDC_MULTISELECT_CHECK, BST_UNCHECKED);
  1277. CheckDlgButton(m_hwnd, IDC_SKIP_DC_CHECK, BST_UNCHECKED);
  1278. m_idcLastRadioClicked = 0;
  1279. m_vsii.clear();
  1280. ListView_DeleteAllItems(_hCtrl(IDC_SCOPE_LIST));
  1281. ListView_DeleteAllItems(_hCtrl(IDC_SCOPE_FLAG_LIST));
  1282. ListView_DeleteAllItems(_hCtrl(IDC_SCOPE_FILTER_LIST));
  1283. Edit_SetText(_hCtrl(IDC_ATTRIBUTES_EDIT), L"");
  1284. Edit_SetText(_hCtrl(IDC_TARGET_COMPUTER_EDIT), L"");
  1285. }
  1286. void __cdecl
  1287. main(int argc, char *argv[])
  1288. {
  1289. hResourceModuleHandle = GetModuleHandle(NULL);
  1290. INITCOMMONCONTROLSEX icce;
  1291. icce.dwSize = sizeof icce;
  1292. icce.dwICC = ICC_LISTVIEW_CLASSES;
  1293. InitCommonControlsEx(&icce);
  1294. HRESULT hr;
  1295. do
  1296. {
  1297. hr = CoInitialize(NULL);
  1298. BREAK_ON_FAIL_HRESULT(hr);
  1299. COpTestDlg dlg;
  1300. hr = dlg.Init();
  1301. BREAK_ON_FAIL_HRESULT(hr);
  1302. dlg.DoModalDialog(NULL);
  1303. }
  1304. while (0);
  1305. CoUninitialize();
  1306. }