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.

3982 lines
114 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Windows NT Directory Service Property Pages
  4. //
  5. // Microsoft Windows
  6. // Copyright (C) Microsoft Corporation, 1992 - 1999
  7. //
  8. // File: group.cxx
  9. //
  10. // Contents: CDsGroupGenObjPage, the class that implements the group object
  11. // general property page, CDsGrpMembersPage for the group
  12. // membership page, and CDsGrpShlGenPage for the shell group
  13. // general page.
  14. //
  15. // History: 10-April-97 EricB created
  16. //
  17. //-----------------------------------------------------------------------------
  18. #include "pch.h"
  19. #include "proppage.h"
  20. #include "group.h"
  21. #include "qrybase.h"
  22. #define BULK_ADD 1
  23. #ifdef DSADMIN
  24. #define DESCR_IDX 0
  25. #define SAMNAME_IDX 1
  26. #define EMAIL_IDX 2
  27. #define COMMENT_IDX 3
  28. //+----------------------------------------------------------------------------
  29. //
  30. // Member: CDsGroupGenObjPage::CDsGroupGenObjPage
  31. //
  32. //-----------------------------------------------------------------------------
  33. CDsGroupGenObjPage::CDsGroupGenObjPage(PDSPAGE pDsPage, LPDATAOBJECT pDataObj,
  34. HWND hNotifyObj, DWORD dwFlags) :
  35. m_pCIcon(NULL),
  36. m_fMixed(TRUE),
  37. m_dwType(0),
  38. m_fTypeWritable(FALSE),
  39. m_fDescrWritable(FALSE),
  40. m_fSamNameWritable(FALSE),
  41. m_fEmailWritable(FALSE),
  42. m_fCommentWritable(FALSE),
  43. m_fTypeDirty(FALSE),
  44. m_fDescrDirty(FALSE),
  45. m_fSamNameDirty(FALSE),
  46. m_fEmailDirty(FALSE),
  47. m_fCommentDirty(FALSE),
  48. CDsPropPageBase(pDsPage, pDataObj, hNotifyObj, dwFlags)
  49. {
  50. TRACE(CDsGroupGenObjPage,CDsGroupGenObjPage);
  51. #ifdef _DEBUG
  52. strcpy(szClass, "CDsGroupGenObjPage");
  53. #endif
  54. }
  55. //+----------------------------------------------------------------------------
  56. //
  57. // Member: CDsGroupGenObjPage::~CDsGroupGenObjPage
  58. //
  59. //-----------------------------------------------------------------------------
  60. CDsGroupGenObjPage::~CDsGroupGenObjPage()
  61. {
  62. TRACE(CDsGroupGenObjPage,~CDsGroupGenObjPage);
  63. }
  64. //+----------------------------------------------------------------------------
  65. //
  66. // Function: CreateGroupGenObjPage
  67. //
  68. // Synopsis: Creates an instance of a page window.
  69. //
  70. //-----------------------------------------------------------------------------
  71. HRESULT
  72. CreateGroupGenObjPage(PDSPAGE pDsPage, LPDATAOBJECT pDataObj,
  73. PWSTR pwzADsPath, PWSTR pwzClass, HWND hNotifyObj,
  74. DWORD dwFlags, const CDSSmartBasePathsInfo& basePathsInfo,
  75. HPROPSHEETPAGE * phPage)
  76. {
  77. TRACE_FUNCTION(CreateGroupGenObjPage);
  78. CDsGroupGenObjPage * pPageObj = new CDsGroupGenObjPage(pDsPage, pDataObj,
  79. hNotifyObj, dwFlags);
  80. CHECK_NULL(pPageObj, return E_OUTOFMEMORY);
  81. pPageObj->Init(pwzADsPath, pwzClass, basePathsInfo);
  82. return pPageObj->CreatePage(phPage);
  83. }
  84. //+----------------------------------------------------------------------------
  85. //
  86. // Method: CDsPropPageBase::DlgProc
  87. //
  88. // Synopsis: per-instance dialog proc
  89. //
  90. //-----------------------------------------------------------------------------
  91. INT_PTR CALLBACK
  92. CDsGroupGenObjPage::DlgProc(HWND, UINT uMsg, WPARAM wParam, LPARAM lParam)
  93. {
  94. if (uMsg == g_uChangeMsg)
  95. {
  96. OnAttrChanged(wParam);
  97. return TRUE;
  98. }
  99. switch (uMsg)
  100. {
  101. case WM_INITDIALOG:
  102. return InitDlg(lParam);
  103. case WM_NOTIFY:
  104. return OnNotify(wParam, lParam);
  105. case PSM_QUERYSIBLINGS:
  106. OnQuerySiblings(wParam, lParam);
  107. break;
  108. case WM_SHOWWINDOW:
  109. return OnShowWindow();
  110. case WM_SETFOCUS:
  111. return OnSetFocus((HWND)wParam);
  112. case WM_HELP:
  113. return OnHelp((LPHELPINFO)lParam);
  114. case WM_COMMAND:
  115. if (m_fInInit)
  116. {
  117. return TRUE;
  118. }
  119. return(OnCommand(GET_WM_COMMAND_ID(wParam, lParam),
  120. GET_WM_COMMAND_HWND(wParam, lParam),
  121. GET_WM_COMMAND_CMD(wParam, lParam)));
  122. case WM_DESTROY:
  123. return OnDestroy();
  124. default:
  125. return FALSE;
  126. }
  127. return TRUE;
  128. }
  129. //+----------------------------------------------------------------------------
  130. //
  131. // Method: CDsGroupGenObjPage::OnInitDialog
  132. //
  133. // Synopsis: Set the initial control values from the corresponding DS
  134. // attributes.
  135. //
  136. //-----------------------------------------------------------------------------
  137. HRESULT CDsGroupGenObjPage::OnInitDialog(LPARAM)
  138. {
  139. TRACE(CDsGroupGenObjPage,OnInitDialog);
  140. HRESULT hr;
  141. PADS_ATTR_INFO pAttrs = NULL;
  142. DWORD cAttrs = 0;
  143. CWaitCursor Wait;
  144. if (!ADsPropSetHwnd(m_hNotifyObj, m_hPage))
  145. {
  146. m_pWritableAttrs = NULL;
  147. }
  148. PTSTR ptzRDN;
  149. if (!UnicodeToTchar(m_pwszRDName, &ptzRDN))
  150. {
  151. REPORT_ERROR(E_OUTOFMEMORY, m_hPage);
  152. return S_OK;
  153. }
  154. SetDlgItemText(m_hPage, IDC_CN, ptzRDN);
  155. delete [] ptzRDN;
  156. //
  157. // Get the icon from the DS and put it on the page.
  158. //
  159. ATTR_DATA ad = {0, 0};
  160. hr = GeneralPageIcon(this, &GenIcon, NULL, 0, &ad, fInit);
  161. CHECK_HRESULT_REPORT(hr, m_hPage, return S_OK);
  162. m_pCIcon = (CDsIconCtrl *)ad.pVoid;
  163. m_fTypeWritable = CheckIfWritable(g_wzGroupType);
  164. m_fDescrWritable = CheckIfWritable(m_rgpAttrMap[DESCR_IDX]->AttrInfo.pszAttrName);
  165. m_fSamNameWritable = CheckIfWritable(m_rgpAttrMap[SAMNAME_IDX]->AttrInfo.pszAttrName);
  166. m_fEmailWritable = CheckIfWritable(m_rgpAttrMap[EMAIL_IDX]->AttrInfo.pszAttrName);
  167. m_fCommentWritable = CheckIfWritable(m_rgpAttrMap[COMMENT_IDX]->AttrInfo.pszAttrName);
  168. //
  169. // Get description, SAM name, email address, and comment attributes.
  170. //
  171. SendDlgItemMessage(m_hPage, m_rgpAttrMap[DESCR_IDX]->nCtrlID, EM_LIMITTEXT,
  172. m_rgpAttrMap[DESCR_IDX]->nSizeLimit, 0);
  173. SendDlgItemMessage(m_hPage, m_rgpAttrMap[SAMNAME_IDX]->nCtrlID, EM_LIMITTEXT,
  174. m_rgpAttrMap[SAMNAME_IDX]->nSizeLimit, 0);
  175. SendDlgItemMessage(m_hPage, m_rgpAttrMap[EMAIL_IDX]->nCtrlID, EM_LIMITTEXT,
  176. m_rgpAttrMap[EMAIL_IDX]->nSizeLimit, 0);
  177. SendDlgItemMessage(m_hPage, m_rgpAttrMap[COMMENT_IDX]->nCtrlID, EM_LIMITTEXT,
  178. m_rgpAttrMap[COMMENT_IDX]->nSizeLimit, 0);
  179. PWSTR rgpwzAttrNames[] = {m_rgpAttrMap[DESCR_IDX]->AttrInfo.pszAttrName,
  180. m_rgpAttrMap[SAMNAME_IDX]->AttrInfo.pszAttrName,
  181. m_rgpAttrMap[EMAIL_IDX]->AttrInfo.pszAttrName,
  182. m_rgpAttrMap[COMMENT_IDX]->AttrInfo.pszAttrName,
  183. g_wzGroupType};
  184. hr = m_pDsObj->GetObjectAttributes(rgpwzAttrNames, 5, &pAttrs, &cAttrs);
  185. if (!CHECK_ADS_HR_IGNORE_UNFOUND_ATTR(&hr, m_hPage))
  186. {
  187. return S_OK;
  188. }
  189. for (DWORD i = 0; i < cAttrs; i++)
  190. {
  191. dspAssert(pAttrs);
  192. dspAssert(pAttrs[i].pADsValues);
  193. PTSTR ptz;
  194. if (_wcsicmp(pAttrs[i].pszAttrName, m_rgpAttrMap[DESCR_IDX]->AttrInfo.pszAttrName) == 0)
  195. {
  196. // description.
  197. //
  198. if (!UnicodeToTchar(pAttrs[i].pADsValues->CaseIgnoreString, &ptz))
  199. {
  200. REPORT_ERROR(E_OUTOFMEMORY, m_hPage);
  201. FreeADsMem(pAttrs);
  202. return S_OK;
  203. }
  204. SetDlgItemText(m_hPage, m_rgpAttrMap[DESCR_IDX]->nCtrlID, ptz);
  205. delete [] ptz;
  206. }
  207. if (_wcsicmp(pAttrs[i].pszAttrName, m_rgpAttrMap[SAMNAME_IDX]->AttrInfo.pszAttrName) == 0)
  208. {
  209. // SAM name.
  210. //
  211. if (!UnicodeToTchar(pAttrs[i].pADsValues->CaseIgnoreString, &ptz))
  212. {
  213. REPORT_ERROR(E_OUTOFMEMORY, m_hPage);
  214. FreeADsMem(pAttrs);
  215. return S_OK;
  216. }
  217. SetDlgItemText(m_hPage, m_rgpAttrMap[SAMNAME_IDX]->nCtrlID, ptz);
  218. delete [] ptz;
  219. }
  220. if (_wcsicmp(pAttrs[i].pszAttrName, m_rgpAttrMap[EMAIL_IDX]->AttrInfo.pszAttrName) == 0)
  221. {
  222. // email address.
  223. //
  224. if (!UnicodeToTchar(pAttrs[i].pADsValues->CaseIgnoreString, &ptz))
  225. {
  226. REPORT_ERROR(E_OUTOFMEMORY, m_hPage);
  227. FreeADsMem(pAttrs);
  228. return S_OK;
  229. }
  230. SetDlgItemText(m_hPage, m_rgpAttrMap[EMAIL_IDX]->nCtrlID, ptz);
  231. delete [] ptz;
  232. }
  233. if (_wcsicmp(pAttrs[i].pszAttrName, m_rgpAttrMap[COMMENT_IDX]->AttrInfo.pszAttrName) == 0)
  234. {
  235. // comment.
  236. //
  237. if (!UnicodeToTchar(pAttrs[i].pADsValues->CaseIgnoreString, &ptz))
  238. {
  239. REPORT_ERROR(E_OUTOFMEMORY, m_hPage);
  240. FreeADsMem(pAttrs);
  241. return S_OK;
  242. }
  243. SetDlgItemText(m_hPage, m_rgpAttrMap[COMMENT_IDX]->nCtrlID, ptz);
  244. delete [] ptz;
  245. }
  246. if (_wcsicmp(pAttrs[i].pszAttrName, g_wzGroupType) == 0)
  247. {
  248. // group type.
  249. //
  250. m_dwType = pAttrs[i].pADsValues->Integer;
  251. }
  252. }
  253. if (pAttrs)
  254. {
  255. FreeADsMem(pAttrs);
  256. }
  257. //
  258. // Get the domain type and set the buttons accordingly.
  259. //
  260. GetDomainMode(this, &m_fMixed);
  261. SetGroupTypeButtons();
  262. if (!m_fDescrWritable)
  263. {
  264. SendDlgItemMessage(m_hPage, m_rgpAttrMap[DESCR_IDX]->nCtrlID, EM_SETREADONLY, (WPARAM)TRUE, 0);
  265. }
  266. if (!m_fSamNameWritable)
  267. {
  268. SendDlgItemMessage(m_hPage, m_rgpAttrMap[SAMNAME_IDX]->nCtrlID, EM_SETREADONLY, (WPARAM)TRUE, 0);
  269. }
  270. if (!m_fEmailWritable)
  271. {
  272. SendDlgItemMessage(m_hPage, m_rgpAttrMap[EMAIL_IDX]->nCtrlID, EM_SETREADONLY, (WPARAM)TRUE, 0);
  273. }
  274. if (!m_fCommentWritable)
  275. {
  276. SendDlgItemMessage(m_hPage, m_rgpAttrMap[COMMENT_IDX]->nCtrlID, EM_SETREADONLY, (WPARAM)TRUE, 0);
  277. }
  278. return S_OK;
  279. }
  280. //+----------------------------------------------------------------------------
  281. //
  282. // Method: CDsGroupGenObjPage::SetGroupTypeButtons
  283. //
  284. // Synopsis: Enables/Disables and checks the appropriate group type radio
  285. // buttons based on the domain mode, and groupType attribute
  286. //
  287. //-----------------------------------------------------------------------------
  288. void CDsGroupGenObjPage::SetGroupTypeButtons()
  289. {
  290. BOOL Sec = m_dwType & GROUP_TYPE_SECURITY_ENABLED;
  291. CheckDlgButton(m_hPage,
  292. (Sec) ? IDC_RADIO_SEC_ENABLED :
  293. IDC_RADIO_SEC_DISABLED,
  294. BST_CHECKED);
  295. if (m_fMixed)
  296. {
  297. EnableWindow(GetDlgItem(m_hPage, (Sec) ? IDC_RADIO_SEC_DISABLED :
  298. IDC_RADIO_SEC_ENABLED), FALSE);
  299. EnableWindow(GetDlgItem(m_hPage, IDC_RADIO_UNIVERSAL), FALSE);
  300. }
  301. UINT id;
  302. if (m_dwType & GROUP_TYPE_ACCOUNT_GROUP)
  303. {
  304. id = IDC_RADIO_ACCOUNT;
  305. EnableWindow(GetDlgItem(m_hPage, IDC_RADIO_RESOURCE), FALSE);
  306. }
  307. else
  308. if (m_dwType & GROUP_TYPE_RESOURCE_GROUP)
  309. {
  310. id = IDC_RADIO_RESOURCE;
  311. EnableWindow(GetDlgItem(m_hPage, IDC_RADIO_ACCOUNT), FALSE);
  312. if (m_dwType & GROUP_TYPE_BUILTIN_LOCAL_GROUP)
  313. {
  314. TCHAR szLabel[100];
  315. if (LoadStringReport(IDS_BUILTIN_GROUP, szLabel, 100, m_hPage))
  316. {
  317. SetWindowText(GetDlgItem(m_hPage, IDC_RADIO_RESOURCE), szLabel);
  318. }
  319. }
  320. }
  321. else
  322. if (m_dwType & GROUP_TYPE_UNIVERSAL_GROUP)
  323. {
  324. id = IDC_RADIO_UNIVERSAL;
  325. EnableWindow(GetDlgItem(m_hPage, IDC_RADIO_ACCOUNT), m_fMixed ? FALSE : TRUE);
  326. EnableWindow(GetDlgItem(m_hPage, IDC_RADIO_RESOURCE), m_fMixed ? FALSE : TRUE);
  327. EnableWindow(GetDlgItem(m_hPage, IDC_RADIO_UNIVERSAL), TRUE);
  328. }
  329. else
  330. {
  331. //
  332. // Probably a default but we should never get here anyway
  333. //
  334. id = IDC_RADIO_ACCOUNT;
  335. #if DBG == 1
  336. dspAssert(FALSE && "Unknown group type!");
  337. #endif
  338. }
  339. CheckDlgButton(m_hPage, id, BST_CHECKED);
  340. bool fIsSpecialAccount = false;
  341. IsSpecialAccount (fIsSpecialAccount);
  342. if (!m_fTypeWritable ||
  343. (m_dwType & GROUP_TYPE_BUILTIN_LOCAL_GROUP) ||
  344. fIsSpecialAccount)
  345. {
  346. EnableWindow(GetDlgItem(m_hPage, IDC_RADIO_ACCOUNT), FALSE);
  347. EnableWindow(GetDlgItem(m_hPage, IDC_RADIO_RESOURCE), FALSE);
  348. EnableWindow(GetDlgItem(m_hPage, IDC_RADIO_UNIVERSAL), FALSE);
  349. EnableWindow(GetDlgItem(m_hPage, IDC_RADIO_SEC_ENABLED), FALSE);
  350. EnableWindow(GetDlgItem(m_hPage, IDC_RADIO_SEC_DISABLED), FALSE);
  351. }
  352. }
  353. //+----------------------------------------------------------------------------
  354. //
  355. // Method: CDsGroupGenObjPage::IsSpecialAccount
  356. //
  357. // Synopsis: Returns true if group RID indicates a special account
  358. //
  359. //-----------------------------------------------------------------------------
  360. HRESULT CDsGroupGenObjPage::IsSpecialAccount(bool& fIsSpecialAccount)
  361. {
  362. //
  363. // Get the group SID. This is a required attribute so bail if not found.
  364. //
  365. PWSTR rgpwzAttrNames[] = {g_wzObjectSID};
  366. PADS_ATTR_INFO pAttrs = NULL;
  367. DWORD cAttrs = 0;
  368. CWaitCursor Wait;
  369. HRESULT hr = m_pDsObj->GetObjectAttributes(rgpwzAttrNames, 1, &pAttrs, &cAttrs);
  370. if (!CHECK_ADS_HR(&hr, m_hPage))
  371. {
  372. return hr;
  373. }
  374. dspAssert(cAttrs);
  375. if (cAttrs != 1)
  376. {
  377. return E_FAIL;
  378. }
  379. dspAssert(pAttrs);
  380. PUCHAR saCount = GetSidSubAuthorityCount(pAttrs->pADsValues->OctetString.lpValue);
  381. DWORD dwGroupRID = *GetSidSubAuthority(pAttrs->pADsValues->OctetString.lpValue, (ULONG)*saCount - 1);
  382. dspDebugOut((DEB_ITRACE, "Group RID = %d\n", dwGroupRID));
  383. // This is the highest special account RID or alias in ntseapi.h
  384. if ( dwGroupRID <= DOMAIN_ALIAS_RID_RAS_SERVERS )
  385. fIsSpecialAccount = true;
  386. FreeADsMem(pAttrs);
  387. return hr;
  388. }
  389. //+----------------------------------------------------------------------------
  390. //
  391. // Method: CDsGroupGenObjPage::OnApply
  392. //
  393. // Synopsis: Handles the Apply notification.
  394. //
  395. //-----------------------------------------------------------------------------
  396. LRESULT
  397. CDsGroupGenObjPage::OnApply(void)
  398. {
  399. TRACE(CDsGroupGenObjPage,OnApply);
  400. HRESULT hr = S_OK;
  401. ADSVALUE ADsValueType = {ADSTYPE_INTEGER, 0};
  402. ADS_ATTR_INFO AttrInfoDesc = m_rgpAttrMap[DESCR_IDX]->AttrInfo;
  403. ADS_ATTR_INFO AttrInfoSAMn = m_rgpAttrMap[SAMNAME_IDX]->AttrInfo;
  404. ADS_ATTR_INFO AttrInfoMail = m_rgpAttrMap[EMAIL_IDX]->AttrInfo;
  405. ADS_ATTR_INFO AttrInfoComm = m_rgpAttrMap[COMMENT_IDX]->AttrInfo;
  406. ADS_ATTR_INFO AttrInfoType = {g_wzGroupType, ADS_ATTR_UPDATE,
  407. ADSTYPE_INTEGER, &ADsValueType, 1};
  408. ADS_ATTR_INFO rgAttrs[5];
  409. DWORD cAttrs = 0;
  410. ADSVALUE ADsValueDesc = {m_rgpAttrMap[DESCR_IDX]->AttrInfo.dwADsType, NULL};
  411. ADSVALUE ADsValueSAMname = {m_rgpAttrMap[SAMNAME_IDX]->AttrInfo.dwADsType, NULL};
  412. ADSVALUE ADsValueComm = {m_rgpAttrMap[COMMENT_IDX]->AttrInfo.dwADsType, NULL};
  413. ADSVALUE ADsValueMail = {m_rgpAttrMap[EMAIL_IDX]->AttrInfo.dwADsType, NULL};
  414. //
  415. // Description.
  416. //
  417. AttrInfoDesc.pADsValues = &ADsValueDesc;
  418. AttrInfoDesc.dwNumValues = 1;
  419. LPTSTR ptsz;
  420. if (m_fDescrDirty)
  421. {
  422. dspAssert(m_fDescrWritable);
  423. ptsz = new TCHAR[m_rgpAttrMap[DESCR_IDX]->nSizeLimit + 1];
  424. CHECK_NULL(ptsz, return -1);
  425. if (GetDlgItemText(m_hPage, m_rgpAttrMap[DESCR_IDX]->nCtrlID,
  426. ptsz, m_rgpAttrMap[DESCR_IDX]->nSizeLimit + 1) == 0)
  427. {
  428. // An empty control means remove the attribute value from the
  429. // object.
  430. //
  431. AttrInfoDesc.dwNumValues = 0;
  432. AttrInfoDesc.pADsValues = NULL;
  433. AttrInfoDesc.dwControlCode = ADS_ATTR_CLEAR;
  434. }
  435. else
  436. {
  437. if (!TcharToUnicode(ptsz, &ADsValueDesc.CaseIgnoreString))
  438. {
  439. delete[] ptsz;
  440. return -1;
  441. }
  442. }
  443. delete[] ptsz;
  444. rgAttrs[cAttrs++] = AttrInfoDesc;
  445. }
  446. //
  447. // SAM name.
  448. //
  449. AttrInfoSAMn.pADsValues = &ADsValueSAMname;
  450. AttrInfoSAMn.dwNumValues = 1;
  451. if (m_fSamNameDirty)
  452. {
  453. dspAssert(m_fSamNameWritable);
  454. ptsz = new TCHAR[m_rgpAttrMap[SAMNAME_IDX]->nSizeLimit + 1];
  455. if (ptsz == NULL)
  456. {
  457. DO_DEL(ADsValueDesc.CaseExactString)
  458. return -1;
  459. }
  460. if (GetDlgItemText(m_hPage, m_rgpAttrMap[SAMNAME_IDX]->nCtrlID,
  461. ptsz, m_rgpAttrMap[SAMNAME_IDX]->nSizeLimit + 1) == 0)
  462. {
  463. ErrMsg (IDS_ERR_DNLEVELNAME_MISSING, m_hPage);
  464. delete[] ptsz;
  465. hr = E_FAIL;
  466. goto Cleanup;
  467. }
  468. else
  469. {
  470. CStr csSAMName = ptsz;
  471. //
  472. // Now check for illegal characters
  473. //
  474. bool bSAMNameChanged = false;
  475. int iFind = csSAMName.FindOneOf(INVALID_ACCOUNT_NAME_CHARS);
  476. if (iFind != -1 && !csSAMName.IsEmpty())
  477. {
  478. PVOID apv[1] = {(LPWSTR)(LPCWSTR)csSAMName};
  479. if (IDYES == SuperMsgBox(m_hPage,
  480. IDS_GROUP_SAMNAME_ILLEGAL,
  481. 0,
  482. MB_YESNO | MB_ICONWARNING,
  483. S_OK,
  484. apv,
  485. 1,
  486. FALSE,
  487. __FILE__,
  488. __LINE__))
  489. {
  490. while (iFind != -1)
  491. {
  492. csSAMName.SetAt(iFind, L'_');
  493. iFind = csSAMName.FindOneOf(INVALID_ACCOUNT_NAME_CHARS);
  494. bSAMNameChanged = true;
  495. }
  496. }
  497. else
  498. {
  499. //
  500. // Set the focus to the edit box and select the text
  501. //
  502. SetFocus(GetDlgItem(m_hPage, m_rgpAttrMap[SAMNAME_IDX]->nCtrlID));
  503. SendDlgItemMessage(m_hPage, m_rgpAttrMap[SAMNAME_IDX]->nCtrlID, EM_SETSEL, 0, -1);
  504. delete[] ptsz;
  505. hr = E_FAIL;
  506. goto Cleanup;
  507. }
  508. }
  509. if (bSAMNameChanged)
  510. {
  511. //
  512. // Write the change back to the control
  513. //
  514. SetDlgItemText(m_hPage, m_rgpAttrMap[SAMNAME_IDX]->nCtrlID, const_cast<PWSTR>((LPCWSTR)csSAMName));
  515. }
  516. if (!AllocWStr((PWSTR)(PCWSTR)csSAMName, &ADsValueSAMname.CaseIgnoreString))
  517. {
  518. delete[] ptsz;
  519. DO_DEL(ADsValueDesc.CaseExactString)
  520. return -1;
  521. }
  522. }
  523. delete[] ptsz;
  524. rgAttrs[cAttrs++] = AttrInfoSAMn;
  525. }
  526. //
  527. // Email Address.
  528. //
  529. AttrInfoMail.pADsValues = &ADsValueMail;
  530. AttrInfoMail.dwNumValues = 1;
  531. if (m_fEmailWritable)
  532. {
  533. if (!m_fEmailDirty)
  534. {
  535. SendMessage(GetParent(GetHWnd()), PSM_QUERYSIBLINGS,
  536. (WPARAM)m_rgpAttrMap[EMAIL_IDX]->AttrInfo.pszAttrName,
  537. (LPARAM)GetHWnd());
  538. }
  539. // SendMessage is syncronous. If the sibling page has an updated email
  540. // attribute value, it will get written to this page's edit control
  541. // and the dirty state member will be set. So, check it now rather than
  542. // use a 'else' clause after the above 'if' clause.
  543. //
  544. if (m_fEmailDirty)
  545. {
  546. ptsz = new TCHAR[m_rgpAttrMap[EMAIL_IDX]->nSizeLimit + 1];
  547. if (ptsz == NULL)
  548. {
  549. DO_DEL(ADsValueDesc.CaseExactString)
  550. DO_DEL(ADsValueSAMname.CaseIgnoreString);
  551. return -1;
  552. }
  553. if (GetDlgItemText(m_hPage, m_rgpAttrMap[EMAIL_IDX]->nCtrlID,
  554. ptsz, m_rgpAttrMap[EMAIL_IDX]->nSizeLimit + 1) == 0)
  555. {
  556. AttrInfoMail.dwNumValues = 0;
  557. AttrInfoMail.pADsValues = NULL;
  558. AttrInfoMail.dwControlCode = ADS_ATTR_CLEAR;
  559. }
  560. else
  561. {
  562. if (!TcharToUnicode(ptsz, &ADsValueMail.CaseIgnoreString))
  563. {
  564. delete[] ptsz;
  565. hr = E_OUTOFMEMORY;
  566. goto Cleanup;
  567. }
  568. if (!FValidSMTPAddress(ADsValueMail.CaseIgnoreString))
  569. {
  570. ErrMsg(IDS_INVALID_MAIL_ADDR, GetHWnd());
  571. delete [] ptsz;
  572. hr = E_FAIL;
  573. goto Cleanup;
  574. }
  575. }
  576. delete[] ptsz;
  577. rgAttrs[cAttrs++] = AttrInfoMail;
  578. }
  579. }
  580. //
  581. // Comment.
  582. //
  583. AttrInfoComm.pADsValues = &ADsValueComm;
  584. AttrInfoComm.dwNumValues = 1;
  585. if (m_fCommentDirty)
  586. {
  587. dspAssert(m_fCommentWritable);
  588. ptsz = new TCHAR[m_rgpAttrMap[COMMENT_IDX]->nSizeLimit + 1];
  589. if (ptsz == NULL)
  590. {
  591. DO_DEL(ADsValueDesc.CaseExactString)
  592. DO_DEL(ADsValueSAMname.CaseIgnoreString);
  593. DO_DEL(ADsValueMail.CaseExactString)
  594. return -1;
  595. }
  596. if (GetDlgItemText(m_hPage, m_rgpAttrMap[COMMENT_IDX]->nCtrlID,
  597. ptsz, m_rgpAttrMap[COMMENT_IDX]->nSizeLimit + 1) == 0)
  598. {
  599. AttrInfoComm.dwNumValues = 0;
  600. AttrInfoComm.pADsValues = NULL;
  601. AttrInfoComm.dwControlCode = ADS_ATTR_CLEAR;
  602. }
  603. else
  604. {
  605. if (!TcharToUnicode(ptsz, &ADsValueComm.CaseIgnoreString))
  606. {
  607. delete[] ptsz;
  608. DO_DEL(ADsValueDesc.CaseExactString)
  609. DO_DEL(ADsValueSAMname.CaseIgnoreString);
  610. DO_DEL(ADsValueMail.CaseExactString)
  611. return -1;
  612. }
  613. }
  614. delete[] ptsz;
  615. rgAttrs[cAttrs++] = AttrInfoComm;
  616. }
  617. //
  618. // set the group type flags
  619. //
  620. if (m_fTypeDirty)
  621. {
  622. dspAssert(m_fTypeWritable);
  623. BOOL Account = (IsDlgButtonChecked (m_hPage,IDC_RADIO_ACCOUNT)
  624. == BST_CHECKED);
  625. BOOL Resource = (IsDlgButtonChecked (m_hPage,IDC_RADIO_RESOURCE)
  626. == BST_CHECKED);
  627. BOOL Security = (IsDlgButtonChecked (m_hPage, IDC_RADIO_SEC_ENABLED)
  628. == BST_CHECKED);
  629. if (Security)
  630. {
  631. ADsValueType.Integer = GROUP_TYPE_SECURITY_ENABLED;
  632. }
  633. else
  634. {
  635. if (m_dwType & GROUP_TYPE_SECURITY_ENABLED)
  636. {
  637. TCHAR szTitle[80], szMessage[512];
  638. if (!LoadStringReport(IDS_MSG_TITLE, szTitle, 80, m_hPage))
  639. {
  640. hr = E_OUTOFMEMORY;
  641. goto Cleanup;
  642. }
  643. if (!LoadStringReport(IDS_MSG_DISABLING_SECURITY, szMessage, 512, m_hPage))
  644. {
  645. hr = E_OUTOFMEMORY;
  646. goto Cleanup;
  647. }
  648. LONG iRet = MessageBox(m_hPage, szMessage, szTitle, MB_YESNO |
  649. MB_ICONWARNING);
  650. if (iRet == IDNO)
  651. {
  652. //
  653. // The user declined, so go back to prop sheet.
  654. //
  655. hr = S_FALSE;
  656. goto Cleanup;
  657. }
  658. }
  659. ADsValueType.Integer = 0;
  660. }
  661. if (Resource)
  662. {
  663. ADsValueType.Integer |= GROUP_TYPE_RESOURCE_GROUP;
  664. }
  665. else
  666. {
  667. if (Account)
  668. {
  669. ADsValueType.Integer |= GROUP_TYPE_ACCOUNT_GROUP;
  670. }
  671. else
  672. {
  673. ADsValueType.Integer |= GROUP_TYPE_UNIVERSAL_GROUP;
  674. }
  675. }
  676. rgAttrs[cAttrs++] = AttrInfoType;
  677. }
  678. //
  679. // Write the description, and group type.
  680. //
  681. DWORD cModified;
  682. hr = m_pDsObj->SetObjectAttributes(rgAttrs, cAttrs, &cModified);
  683. if (!CHECK_ADS_HR(&hr, m_hPage))
  684. {
  685. goto Cleanup;
  686. }
  687. // Store the new group type and change the group type buttons
  688. m_dwType = ADsValueType.Integer;
  689. SetGroupTypeButtons();
  690. m_fTypeDirty = m_fDescrDirty = m_fSamNameDirty = m_fEmailDirty =
  691. m_fCommentDirty = FALSE;
  692. Cleanup:
  693. DO_DEL(ADsValueDesc.CaseExactString)
  694. DO_DEL(ADsValueSAMname.CaseIgnoreString);
  695. DO_DEL(ADsValueMail.CaseExactString)
  696. DO_DEL(ADsValueComm.CaseExactString)
  697. if (hr == S_FALSE)
  698. return PSNRET_INVALID_NOCHANGEPAGE;
  699. else
  700. return (SUCCEEDED(hr)) ? PSNRET_NOERROR : PSNRET_INVALID_NOCHANGEPAGE;
  701. }
  702. //+----------------------------------------------------------------------------
  703. //
  704. // Method: CDsGroupGenObjPage::OnCommand
  705. //
  706. // Synopsis: Handle control notifications.
  707. //
  708. //-----------------------------------------------------------------------------
  709. LRESULT
  710. CDsGroupGenObjPage::OnCommand(int id, HWND hwndCtl, UINT codeNotify)
  711. {
  712. if (m_fInInit)
  713. {
  714. return 0;
  715. }
  716. switch (codeNotify)
  717. {
  718. case BN_CLICKED:
  719. if ((id == IDC_RADIO_UNIVERSAL) ||
  720. (id == IDC_RADIO_RESOURCE) ||
  721. (id == IDC_RADIO_ACCOUNT))
  722. {
  723. int iCheck1, iCheck2;
  724. switch (id)
  725. {
  726. case IDC_RADIO_UNIVERSAL:
  727. iCheck1 = IDC_RADIO_RESOURCE;
  728. iCheck2 = IDC_RADIO_ACCOUNT;
  729. break;
  730. case IDC_RADIO_RESOURCE:
  731. iCheck1 = IDC_RADIO_UNIVERSAL;
  732. iCheck2 = IDC_RADIO_ACCOUNT;
  733. break;
  734. case IDC_RADIO_ACCOUNT:
  735. iCheck1 = IDC_RADIO_UNIVERSAL;
  736. iCheck2 = IDC_RADIO_RESOURCE;
  737. break;
  738. default:
  739. dspAssert(FALSE);
  740. iCheck1 = IDC_RADIO_RESOURCE;
  741. iCheck2 = IDC_RADIO_ACCOUNT;
  742. break;
  743. }
  744. CheckDlgButton(m_hPage, iCheck1, BST_UNCHECKED);
  745. CheckDlgButton(m_hPage, iCheck2, BST_UNCHECKED);
  746. m_fTypeDirty = TRUE;
  747. SetDirty();
  748. }
  749. if ((id == IDC_RADIO_SEC_ENABLED) ||
  750. (id == IDC_RADIO_SEC_DISABLED))
  751. {
  752. CheckDlgButton(m_hPage,
  753. (id == IDC_RADIO_SEC_ENABLED) ?
  754. IDC_RADIO_SEC_DISABLED : IDC_RADIO_SEC_ENABLED,
  755. BST_UNCHECKED);
  756. m_fTypeDirty = TRUE;
  757. SetDirty();
  758. }
  759. break;
  760. case EN_CHANGE:
  761. switch (id)
  762. {
  763. case IDC_EMAIL_EDIT:
  764. m_fEmailDirty = TRUE;
  765. break;
  766. case IDC_DESCRIPTION_EDIT:
  767. m_fDescrDirty = TRUE;
  768. break;
  769. case IDC_SAM_NAME_EDIT:
  770. m_fSamNameDirty = TRUE;
  771. break;
  772. case IDC_EDIT_COMMENT:
  773. m_fCommentDirty = TRUE;
  774. break;
  775. }
  776. break;
  777. }
  778. return CDsPropPageBase::OnCommand(id, hwndCtl, codeNotify);
  779. }
  780. //+----------------------------------------------------------------------------
  781. //
  782. // Method: CDsGroupGenObjPage::OnNotify
  783. //
  784. // Synopsis: Handles list notification messages
  785. //
  786. //-----------------------------------------------------------------------------
  787. LRESULT
  788. CDsGroupGenObjPage::OnNotify(WPARAM wParam, LPARAM lParam)
  789. {
  790. if (m_fInInit)
  791. {
  792. return 0;
  793. }
  794. if (((LPNMHDR)lParam)->code == PSN_SETACTIVE)
  795. {
  796. dspDebugOut((DEB_ITRACE,
  797. "(HWND: %08x) got PSN_SETACTIVE, sending PSM_QUERYSIBLINGS.\n",
  798. GetHWnd()));
  799. SendMessage(GetParent(GetHWnd()), PSM_QUERYSIBLINGS,
  800. (WPARAM)m_rgpAttrMap[EMAIL_IDX]->AttrInfo.pszAttrName,
  801. (LPARAM)GetHWnd());
  802. }
  803. return CDsPropPageBase::OnNotify(wParam, lParam);
  804. }
  805. //+----------------------------------------------------------------------------
  806. //
  807. // Method: CDsGroupGenObjPage::OnQuerySiblings
  808. //
  809. // Synopsis: Inter-page communications for shared attributes.
  810. //
  811. // lParam == the HWND of the sending window.
  812. // wParam == the name of the attribute whose status is sought.
  813. //
  814. //-----------------------------------------------------------------------------
  815. void
  816. CDsGroupGenObjPage::OnQuerySiblings(WPARAM wParam, LPARAM lParam)
  817. {
  818. PWSTR pwz = NULL;
  819. int cch;
  820. #if DBG == 1
  821. char szBuf[100];
  822. strcpy(szBuf, "(HWND: %08x) got PSM_QUERYSIBLINGS for '%ws'");
  823. #endif
  824. if ((HWND)lParam != GetHWnd())
  825. {
  826. if (m_fEmailDirty && wParam &&
  827. _wcsicmp((PWSTR)wParam,
  828. m_rgpAttrMap[EMAIL_IDX]->AttrInfo.pszAttrName) == 0)
  829. {
  830. #if DBG == 1
  831. strcat(szBuf, " sending DSPROP_ATTRCHANGED_MSG");
  832. #endif
  833. ADS_ATTR_INFO Attr;
  834. ADSVALUE ADsValue;
  835. cch = (int)SendDlgItemMessage(GetHWnd(),
  836. m_rgpAttrMap[EMAIL_IDX]->nCtrlID,
  837. WM_GETTEXTLENGTH, 0, 0);
  838. pwz = new WCHAR[++cch];
  839. CHECK_NULL_REPORT(pwz, GetHWnd(), return);
  840. Attr.dwNumValues = 1;
  841. Attr.pszAttrName = m_rgpAttrMap[EMAIL_IDX]->AttrInfo.pszAttrName;
  842. Attr.pADsValues = &ADsValue;
  843. Attr.pADsValues->dwType = m_rgpAttrMap[EMAIL_IDX]->AttrInfo.dwADsType;
  844. Attr.pADsValues->CaseIgnoreString = pwz;
  845. GetDlgItemText(GetHWnd(), m_rgpAttrMap[EMAIL_IDX]->nCtrlID,
  846. Attr.pADsValues->CaseIgnoreString, cch);
  847. SendMessage((HWND)lParam, g_uChangeMsg, (WPARAM)&Attr, 0);
  848. delete [] pwz;
  849. }
  850. }
  851. #if DBG == 1
  852. else
  853. {
  854. strcat(szBuf, " (it was sent by this page!)");
  855. }
  856. strcat(szBuf, "\n");
  857. dspDebugOut((DEB_ITRACE, szBuf, GetHWnd(), wParam));
  858. #endif
  859. }
  860. //+----------------------------------------------------------------------------
  861. //
  862. // Method: CDsGroupGenObjPage::OnAttrChanged
  863. //
  864. // Synopsis: Inter-page communications for shared attributes.
  865. //
  866. // wParam == the PADS_ATTR_INFO struct for the changed attribute.
  867. //
  868. //-----------------------------------------------------------------------------
  869. void
  870. CDsGroupGenObjPage::OnAttrChanged(WPARAM wParam)
  871. {
  872. PADS_ATTR_INFO pAttrInfo = (PADS_ATTR_INFO)wParam;
  873. dspAssert(pAttrInfo && pAttrInfo->pszAttrName && pAttrInfo->pADsValues &&
  874. pAttrInfo->pADsValues->CaseIgnoreString);
  875. dspDebugOut((DEB_ITRACE,
  876. "(HWND: %08x) got DSPROP_ATTRCHANGED_MSG for '%ws'.\n",
  877. GetHWnd(), pAttrInfo->pszAttrName));
  878. if (_wcsicmp(pAttrInfo->pszAttrName, m_rgpAttrMap[EMAIL_IDX]->AttrInfo.pszAttrName) == 0)
  879. {
  880. SetDlgItemText(GetHWnd(), m_rgpAttrMap[EMAIL_IDX]->nCtrlID,
  881. pAttrInfo->pADsValues->CaseIgnoreString);
  882. }
  883. }
  884. //+----------------------------------------------------------------------------
  885. //
  886. // Method: CDsGroupGenObjPage::OnDestroy
  887. //
  888. // Synopsis: Exit cleanup
  889. //
  890. //-----------------------------------------------------------------------------
  891. LRESULT
  892. CDsGroupGenObjPage::OnDestroy(void)
  893. {
  894. ATTR_DATA ad = {0, (LPARAM)m_pCIcon};
  895. GeneralPageIcon(this, &GenIcon, NULL, 0, &ad, fOnDestroy);
  896. CDsPropPageBase::OnDestroy();
  897. // If an application processes this message, it should return zero.
  898. return 0;
  899. }
  900. #endif // DSADMIN
  901. //+----------------------------------------------------------------------------
  902. //
  903. // Member: CDsGrpMembersPage::CDsGrpMembersPage
  904. //
  905. //-----------------------------------------------------------------------------
  906. CDsGrpMembersPage::CDsGrpMembersPage(PDSPAGE pDsPage, LPDATAOBJECT pDataObj,
  907. HWND hNotifyObj, DWORD dwFlags) :
  908. m_pList(NULL),
  909. m_fMixed(TRUE),
  910. m_dwType(0),
  911. m_fMemberWritable(FALSE),
  912. m_dwGroupRID(0),
  913. m_fShowIcons(FALSE),
  914. m_pszSecurityGroupExtraClasses(NULL),
  915. m_dwSecurityGroupExtraClassesCount(0),
  916. m_pszNonSecurityGroupExtraClasses(NULL),
  917. m_dwNonSecurityGroupExtraClassesCount(0),
  918. m_hwndObjPicker(NULL),
  919. m_pInitInfo(NULL),
  920. CDsPropPageBase(pDsPage, pDataObj, hNotifyObj, dwFlags)
  921. {
  922. TRACE(CDsGrpMembersPage,CDsGrpMembersPage);
  923. #ifdef _DEBUG
  924. strcpy(szClass, "CDsGrpMembersPage");
  925. #endif
  926. }
  927. //+----------------------------------------------------------------------------
  928. //
  929. // Member: CDsGrpMembersPage::~CDsGrpMembersPage
  930. //
  931. //-----------------------------------------------------------------------------
  932. CDsGrpMembersPage::~CDsGrpMembersPage()
  933. {
  934. TRACE(CDsGrpMembersPage,~CDsGrpMembersPage);
  935. DO_DEL(m_pList);
  936. if (m_pszSecurityGroupExtraClasses != NULL)
  937. {
  938. for (DWORD idx = 0; idx < m_dwSecurityGroupExtraClassesCount; idx++)
  939. {
  940. if (m_pszSecurityGroupExtraClasses[idx] != NULL)
  941. {
  942. delete[] m_pszSecurityGroupExtraClasses[idx];
  943. m_pszSecurityGroupExtraClasses[idx] = NULL;
  944. }
  945. }
  946. delete[] m_pszSecurityGroupExtraClasses;
  947. }
  948. if (m_pszNonSecurityGroupExtraClasses != NULL)
  949. {
  950. for (DWORD idx = 0; idx < m_dwNonSecurityGroupExtraClassesCount; idx++)
  951. {
  952. if (m_pszNonSecurityGroupExtraClasses[idx] != NULL)
  953. {
  954. delete[] m_pszNonSecurityGroupExtraClasses[idx];
  955. m_pszNonSecurityGroupExtraClasses[idx] = NULL;
  956. }
  957. }
  958. delete[] m_pszNonSecurityGroupExtraClasses;
  959. }
  960. }
  961. //+----------------------------------------------------------------------------
  962. //
  963. // Member: CDsGrpMembersPage::IUnknown::QueryInterface
  964. //
  965. // Synopsis: Returns requested interface pointer
  966. //
  967. //-----------------------------------------------------------------------------
  968. STDMETHODIMP
  969. CDsGrpMembersPage::QueryInterface(REFIID riid, void ** ppvObject)
  970. {
  971. TRACE2(CDsGrpMembersPage,QueryInterface);
  972. if (IID_ICustomizeDsBrowser == riid)
  973. {
  974. *ppvObject = (ICustomizeDsBrowser*)this;
  975. }
  976. else
  977. {
  978. return CDsPropPageBase::QueryInterface(riid, ppvObject);
  979. }
  980. AddRef();
  981. return S_OK;
  982. }
  983. //+----------------------------------------------------------------------------
  984. //
  985. // Member: CDsGrpMembersPage::IUnknown::AddRef
  986. //
  987. // Synopsis: increments reference count
  988. //
  989. // Returns: the reference count
  990. //
  991. //-----------------------------------------------------------------------------
  992. STDMETHODIMP_(ULONG)
  993. CDsGrpMembersPage::AddRef(void)
  994. {
  995. dspDebugOut((DEB_USER2, "CDsGrpMembersPage::AddRef refcount going in %d\n", m_uRefs));
  996. return CDsPropPageBase::AddRef();
  997. }
  998. //+----------------------------------------------------------------------------
  999. //
  1000. // Member: CDsGrpMembersPage::IUnknown::Release
  1001. //
  1002. // Synopsis: Decrements the object's reference count and frees it when
  1003. // no longer referenced.
  1004. //
  1005. // Returns: zero if the reference count is zero or non-zero otherwise
  1006. //
  1007. //-----------------------------------------------------------------------------
  1008. STDMETHODIMP_(ULONG)
  1009. CDsGrpMembersPage::Release(void)
  1010. {
  1011. dspDebugOut((DEB_USER2, "CDsGrpMembersPage::Release ref count going in %d\n", m_uRefs));
  1012. return CDsPropPageBase::Release();
  1013. }
  1014. //+----------------------------------------------------------------------------
  1015. //
  1016. // Method: CDsGrpMembersPage::Initialize
  1017. //
  1018. // Synopsis: Initializes the ICustomizeDsBrowser interface
  1019. //
  1020. //-----------------------------------------------------------------------------
  1021. HRESULT CDsGrpMembersPage::Initialize(HWND hwnd,
  1022. PCDSOP_INIT_INFO pInitInfo,
  1023. IBindHelper *pBindHelper)
  1024. {
  1025. HRESULT hr = S_OK;
  1026. dspAssert(IsWindow(hwnd));
  1027. dspAssert(pBindHelper);
  1028. m_hwndObjPicker = hwnd;
  1029. m_pInitInfo = pInitInfo;
  1030. m_pBinder = pBindHelper;
  1031. return hr;
  1032. }
  1033. //+----------------------------------------------------------------------------
  1034. //
  1035. // Method: CDsGrpMembersPage::BuildQueryString
  1036. //
  1037. // Synopsis: Used to build the query string from the securityGroupExtraClasses
  1038. // and nonSecurityGroupExtraClasses in the DisplaySpecifiers
  1039. //
  1040. //-----------------------------------------------------------------------------
  1041. HRESULT CDsGrpMembersPage::BuildQueryString(PWSTR* ppszFilterString)
  1042. {
  1043. CStrW szFilterString = L"(|";
  1044. BOOL bSecurityGroup = (m_dwType & GROUP_TYPE_SECURITY_ENABLED) ? TRUE : FALSE;
  1045. if (bSecurityGroup)
  1046. {
  1047. if (m_dwSecurityGroupExtraClassesCount == 0)
  1048. {
  1049. return S_FALSE;
  1050. }
  1051. for (DWORD idx = 0; idx < m_dwSecurityGroupExtraClassesCount; idx++)
  1052. {
  1053. if (m_pszSecurityGroupExtraClasses[idx] != NULL)
  1054. {
  1055. szFilterString += L"(objectClass=";
  1056. szFilterString += m_pszSecurityGroupExtraClasses[idx];
  1057. szFilterString += L")";
  1058. }
  1059. }
  1060. }
  1061. else
  1062. {
  1063. if (m_dwNonSecurityGroupExtraClassesCount == 0)
  1064. {
  1065. return S_FALSE;
  1066. }
  1067. for (DWORD idx = 0; idx < m_dwNonSecurityGroupExtraClassesCount; idx++)
  1068. {
  1069. if (m_pszNonSecurityGroupExtraClasses[idx] != NULL)
  1070. {
  1071. szFilterString += L"(objectClass=";
  1072. if(_wcsicmp(m_pszNonSecurityGroupExtraClasses[idx],L"MSMQ-Queue")==0)
  1073. {
  1074. szFilterString +=L"MSMQQueue";
  1075. }
  1076. else
  1077. {
  1078. szFilterString += m_pszNonSecurityGroupExtraClasses[idx];
  1079. }
  1080. szFilterString += L")";
  1081. }
  1082. }
  1083. }
  1084. szFilterString += L")";
  1085. *ppszFilterString = new WCHAR[szFilterString.GetLength() + 1];
  1086. CHECK_NULL_REPORT(*ppszFilterString, GetHWnd(), return E_OUTOFMEMORY);
  1087. wcscpy(*ppszFilterString, szFilterString);
  1088. return S_OK;
  1089. }
  1090. //+----------------------------------------------------------------------------
  1091. //
  1092. // Method: CDsSelectionListWrapper::CreateSelectionList
  1093. //
  1094. // Synopsis: Used to convert a CDsSelectionListWrapper to a PDS_SELECTION_LIST
  1095. //
  1096. //-----------------------------------------------------------------------------
  1097. PDS_SELECTION_LIST CDsSelectionListWrapper::CreateSelectionList(CDsSelectionListWrapper* pHead)
  1098. {
  1099. if (pHead == NULL)
  1100. {
  1101. return NULL;
  1102. }
  1103. PDS_SELECTION_LIST pSelectionList = NULL;
  1104. UINT nCount = CDsSelectionListWrapper::GetCount(pHead);
  1105. if (nCount > 0)
  1106. {
  1107. pSelectionList = (PDS_SELECTION_LIST)malloc(sizeof(DS_SELECTION_LIST) +
  1108. (sizeof(DS_SELECTION) * (nCount - 1)));
  1109. if (pSelectionList != NULL)
  1110. {
  1111. memset(pSelectionList, 0, sizeof(DS_SELECTION_LIST) + (sizeof(DS_SELECTION) * (nCount - 1)));
  1112. pSelectionList->cItems = nCount;
  1113. pSelectionList->cFetchedAttributes = 0;
  1114. //
  1115. // Now fill in the selection list by walking the wrapper list
  1116. //
  1117. UINT idx = 0;
  1118. CDsSelectionListWrapper* pCurrentItem = pHead;
  1119. while (pCurrentItem != NULL)
  1120. {
  1121. memcpy(&(pSelectionList->aDsSelection[idx]), pCurrentItem->m_pSelection, sizeof(DS_SELECTION));
  1122. pCurrentItem = pCurrentItem->m_pNext;
  1123. idx++;
  1124. }
  1125. }
  1126. }
  1127. return pSelectionList;
  1128. }
  1129. //+----------------------------------------------------------------------------
  1130. //
  1131. // Method: CDsSelectionListWrapper::CreateSelectionList
  1132. //
  1133. // Synopsis: Counts the number of items in the CDsSelectionListWrapper
  1134. //
  1135. //-----------------------------------------------------------------------------
  1136. UINT CDsSelectionListWrapper::GetCount(CDsSelectionListWrapper* pHead)
  1137. {
  1138. CDsSelectionListWrapper* pCurrentItem = pHead;
  1139. UINT nCount = 0;
  1140. while (pCurrentItem != NULL)
  1141. {
  1142. nCount++;
  1143. pCurrentItem = pCurrentItem->m_pNext;
  1144. }
  1145. return nCount;
  1146. }
  1147. //+----------------------------------------------------------------------------
  1148. //
  1149. // Method: CDsSelectionListWrapper::DetachItemsAndDeleteList
  1150. //
  1151. // Synopsis: Counts the number of items in the CDsSelectionListWrapper
  1152. //
  1153. //-----------------------------------------------------------------------------
  1154. void CDsSelectionListWrapper::DetachItemsAndDeleteList(CDsSelectionListWrapper* pHead)
  1155. {
  1156. CDsSelectionListWrapper* pNextItem = pHead;
  1157. CDsSelectionListWrapper* pDeleteItem = NULL;
  1158. while (pNextItem != NULL)
  1159. {
  1160. pDeleteItem = pNextItem;
  1161. pNextItem = pNextItem->m_pNext;
  1162. delete pDeleteItem->m_pSelection;
  1163. delete pDeleteItem;
  1164. }
  1165. }
  1166. //+----------------------------------------------------------------------------
  1167. //
  1168. // Method: CDsGrpMembersPage::CollectDsObjects
  1169. //
  1170. // Synopsis: Used by AddObjects and PrefixSearch to retrieve the dataobject
  1171. // of the additional objects
  1172. //
  1173. //-----------------------------------------------------------------------------
  1174. HRESULT CDsGrpMembersPage::CollectDsObjects(PWSTR pszFilter,
  1175. IDsObjectPickerScope *pDsScope,
  1176. CDsPropDataObj *pdo)
  1177. {
  1178. HRESULT hr = S_OK;
  1179. dspAssert(pdo != NULL);
  1180. if (pdo == NULL)
  1181. {
  1182. return E_POINTER;
  1183. }
  1184. //
  1185. // Prepare the search object
  1186. //
  1187. PWSTR pszScopePath = NULL;
  1188. hr = pDsScope->GetADsPath(&pszScopePath);
  1189. CHECK_HRESULT(hr, return hr;);
  1190. CDSSearch searchObj;
  1191. hr = searchObj.Init(pszScopePath);
  1192. CHECK_HRESULT(hr, return hr;);
  1193. PWSTR pszAttributes[] = { g_wzADsPath };
  1194. hr = searchObj.SetAttributeList(pszAttributes, 1);
  1195. CHECK_HRESULT(hr, return hr);
  1196. dspAssert(pszFilter != NULL);
  1197. if (pszFilter == NULL)
  1198. {
  1199. return E_INVALIDARG;
  1200. }
  1201. hr = searchObj.SetFilterString(pszFilter);
  1202. CHECK_HRESULT(hr, return hr);
  1203. hr = searchObj.SetSearchScope(ADS_SCOPE_SUBTREE);
  1204. CHECK_HRESULT(hr, return hr);
  1205. //
  1206. // Prepare the linked list for temporary storage of DS_SELECTION items
  1207. //
  1208. CDsSelectionListWrapper* pListHead = NULL;
  1209. CDsSelectionListWrapper* pCurrentListItem = NULL;
  1210. //
  1211. // Get the path cracker
  1212. //
  1213. CComPtr<IADsPathname> spPathCracker;
  1214. hr = GetADsPathname(spPathCracker);
  1215. CHECK_HRESULT(hr, return hr);
  1216. //
  1217. // Execute the query
  1218. //
  1219. hr = searchObj.DoQuery();
  1220. while (SUCCEEDED(hr))
  1221. {
  1222. hr = searchObj.GetNextRow();
  1223. if (S_ADS_NOMORE_ROWS == hr)
  1224. {
  1225. hr = S_OK;
  1226. break;
  1227. }
  1228. if (SUCCEEDED(hr))
  1229. {
  1230. ADS_SEARCH_COLUMN PathColumn, ClassColumn;
  1231. ::ZeroMemory( &PathColumn, sizeof(PathColumn) );
  1232. ::ZeroMemory(&ClassColumn, sizeof(ClassColumn));
  1233. //
  1234. // Get the ADsPath
  1235. //
  1236. hr = searchObj.GetColumn(pszAttributes[0], &PathColumn);
  1237. CHECK_HRESULT(hr, continue);
  1238. dspAssert(PathColumn.pADsValues->dwType == ADSTYPE_CASE_IGNORE_STRING);
  1239. //
  1240. // Get the objectClass
  1241. //
  1242. CComPtr<IDirectoryObject> spDirObject;
  1243. hr = DSAdminOpenObject(PathColumn.pADsValues->CaseIgnoreString,
  1244. IID_IDirectoryObject,
  1245. (PVOID*)&spDirObject);
  1246. CHECK_HRESULT(hr, continue);
  1247. //
  1248. // Get the object info
  1249. //
  1250. ADS_OBJECT_INFO* pADsObjectInfo = NULL;
  1251. hr = spDirObject->GetObjectInformation(&pADsObjectInfo);
  1252. CHECK_HRESULT(hr, continue);
  1253. dspAssert(pADsObjectInfo != NULL);
  1254. PDS_SELECTION pSelection = new DS_SELECTION;
  1255. CHECK_NULL(pSelection, return E_OUTOFMEMORY);
  1256. ::ZeroMemory(pSelection, sizeof(DS_SELECTION));
  1257. if (!AllocWStr(PathColumn.pADsValues->CaseIgnoreString, &(pSelection->pwzADsPath)))
  1258. {
  1259. CHECK_HRESULT(E_OUTOFMEMORY, return E_OUTOFMEMORY);
  1260. }
  1261. //
  1262. // Assume that the class we are interested in is the first in the multivalued attribute
  1263. //
  1264. if (!AllocWStr(pADsObjectInfo->pszClassName, &(pSelection->pwzClass)))
  1265. {
  1266. CHECK_HRESULT(E_OUTOFMEMORY, return E_OUTOFMEMORY);
  1267. }
  1268. hr = spPathCracker->Set(CComBSTR(PathColumn.pADsValues->CaseIgnoreString), ADS_SETTYPE_FULL);
  1269. CHECK_HRESULT(hr, continue);
  1270. hr = spPathCracker->SetDisplayType(ADS_DISPLAY_VALUE_ONLY);
  1271. CHECK_HRESULT(hr, continue);
  1272. hr = spPathCracker->put_EscapedMode(ADS_ESCAPEDMODE_OFF_EX);
  1273. CHECK_HRESULT(hr, continue);
  1274. CComBSTR bstrName;
  1275. hr = spPathCracker->Retrieve(ADS_FORMAT_LEAF, &bstrName);
  1276. CHECK_HRESULT(hr, continue);
  1277. //
  1278. // Return the display to full
  1279. //
  1280. hr = spPathCracker->SetDisplayType(ADS_DISPLAY_FULL);
  1281. dspAssert(SUCCEEDED(hr));
  1282. hr = spPathCracker->put_EscapedMode(ADS_ESCAPEDMODE_ON);
  1283. dspAssert(SUCCEEDED(hr));
  1284. if (!AllocWStr(bstrName, &(pSelection->pwzName)))
  1285. {
  1286. CHECK_HRESULT(E_OUTOFMEMORY, return E_OUTOFMEMORY);
  1287. }
  1288. CDsSelectionListWrapper* pNewItem = new CDsSelectionListWrapper;
  1289. CHECK_NULL(pNewItem, return E_OUTOFMEMORY);
  1290. pNewItem->m_pSelection = pSelection;
  1291. //
  1292. // Add selection item to list
  1293. //
  1294. if (pListHead == NULL)
  1295. {
  1296. pListHead = pNewItem;
  1297. pCurrentListItem = pNewItem;
  1298. }
  1299. else
  1300. {
  1301. pCurrentListItem->m_pNext = pNewItem;
  1302. pCurrentListItem = pNewItem;
  1303. }
  1304. searchObj.FreeColumn(&PathColumn);
  1305. searchObj.FreeColumn(&ClassColumn);
  1306. }
  1307. }
  1308. if (pListHead != NULL)
  1309. {
  1310. PDS_SELECTION_LIST pSelectionList = CDsSelectionListWrapper::CreateSelectionList(pListHead);
  1311. if (pSelectionList != NULL)
  1312. {
  1313. hr = pdo->Init(pSelectionList);
  1314. CHECK_HRESULT(hr, return hr);
  1315. }
  1316. CDsSelectionListWrapper::DetachItemsAndDeleteList(pListHead);
  1317. }
  1318. else
  1319. {
  1320. hr = S_FALSE;
  1321. }
  1322. return hr;
  1323. }
  1324. //+----------------------------------------------------------------------------
  1325. //
  1326. // Method: CDsGrpMembersPage::AddObjects
  1327. //
  1328. // Synopsis: Called by the Object Picker UI to add additional objects to the UI
  1329. //
  1330. //-----------------------------------------------------------------------------
  1331. HRESULT CDsGrpMembersPage::AddObjects(IDsObjectPickerScope *pDsScope,
  1332. IDataObject **ppdo)
  1333. {
  1334. HRESULT hr = S_OK;
  1335. //
  1336. // Prepare the data object
  1337. //
  1338. CDsPropDataObj* pDataObj = new CDsPropDataObj(GetHWnd(), m_fReadOnly);
  1339. CHECK_NULL(pDataObj, return E_OUTOFMEMORY);
  1340. *ppdo = pDataObj;
  1341. PWSTR pszFilter = NULL;
  1342. hr = BuildQueryString(&pszFilter);
  1343. if (FAILED(hr) ||
  1344. !pszFilter ||
  1345. hr == S_FALSE)
  1346. {
  1347. delete pDataObj;
  1348. pDataObj = NULL;
  1349. *ppdo = NULL;
  1350. hr = S_FALSE;
  1351. }
  1352. else
  1353. {
  1354. hr = CollectDsObjects(pszFilter, pDsScope, pDataObj);
  1355. }
  1356. if (pszFilter != NULL)
  1357. {
  1358. delete[] pszFilter;
  1359. pszFilter = NULL;
  1360. }
  1361. return hr;
  1362. }
  1363. //+----------------------------------------------------------------------------
  1364. //
  1365. // Method: CDsGrpMembersPage::GetQueryInfoByScope
  1366. //
  1367. // Synopsis: Called by the Object Picker UI
  1368. //
  1369. //-----------------------------------------------------------------------------
  1370. HRESULT CDsGrpMembersPage::GetQueryInfoByScope(IDsObjectPickerScope*,
  1371. PDSQUERYINFO *ppdsqi)
  1372. {
  1373. return E_NOTIMPL;
  1374. }
  1375. //+----------------------------------------------------------------------------
  1376. //
  1377. // Method: CDsGrpMembersPage::PrefixSearch
  1378. //
  1379. // Synopsis: Called by the Object Picker UI to get additional objects starting
  1380. // with a specific string
  1381. //
  1382. //-----------------------------------------------------------------------------
  1383. HRESULT CDsGrpMembersPage::PrefixSearch(IDsObjectPickerScope *pDsScope,
  1384. PCWSTR pwzSearchFor,
  1385. IDataObject **ppdo)
  1386. {
  1387. HRESULT hr = S_OK;
  1388. //
  1389. // Prepare the data object
  1390. //
  1391. CDsPropDataObj* pDataObj = new CDsPropDataObj(GetHWnd(), m_fReadOnly);
  1392. CHECK_NULL(pDataObj, return E_OUTOFMEMORY);
  1393. *ppdo = pDataObj;
  1394. CStrW szFilter;
  1395. PWSTR pszFilter = NULL;
  1396. hr = BuildQueryString(&pszFilter);
  1397. if (FAILED(hr) ||
  1398. hr == S_FALSE ||
  1399. pszFilter == NULL)
  1400. {
  1401. delete pDataObj;
  1402. pDataObj = NULL;
  1403. *ppdo = NULL;
  1404. if (pszFilter)
  1405. {
  1406. delete[] pszFilter;
  1407. pszFilter = NULL;
  1408. }
  1409. hr = S_FALSE;
  1410. }
  1411. else
  1412. {
  1413. szFilter = pszFilter;
  1414. CStrW szEscapedSearchFor;
  1415. GetFilterEscapedValue(pwzSearchFor, szEscapedSearchFor);
  1416. CStrW szPrefix;
  1417. szPrefix = L"(&(name=";
  1418. szPrefix += szEscapedSearchFor;
  1419. szPrefix += L"*)";
  1420. szFilter = szPrefix + szFilter + L")";
  1421. hr = CollectDsObjects(szFilter.GetBuffer(szFilter.GetLength() + 1), pDsScope, pDataObj);
  1422. }
  1423. return hr;
  1424. }
  1425. //+----------------------------------------------------------------------------
  1426. //
  1427. // Function: CreateGroupMembersPage
  1428. //
  1429. // Synopsis: Creates an instance of the group membership page window.
  1430. //
  1431. //-----------------------------------------------------------------------------
  1432. HRESULT
  1433. CreateGroupMembersPage(PDSPAGE pDsPage, LPDATAOBJECT pDataObj,
  1434. PWSTR pwzADsPath, PWSTR pwzClass, HWND hNotifyObj,
  1435. DWORD dwFlags, const CDSSmartBasePathsInfo& basePathsInfo,
  1436. HPROPSHEETPAGE * phPage)
  1437. {
  1438. TRACE_FUNCTION(CreateGroupMembersPage);
  1439. CDsGrpMembersPage * pPageObj = new CDsGrpMembersPage(pDsPage, pDataObj,
  1440. hNotifyObj, dwFlags);
  1441. CHECK_NULL(pPageObj, return E_OUTOFMEMORY);
  1442. pPageObj->Init(pwzADsPath, pwzClass, basePathsInfo);
  1443. return pPageObj->CreatePage(phPage);
  1444. }
  1445. //+----------------------------------------------------------------------------
  1446. //
  1447. // Method: CDsGrpMembersPage::DlgProc
  1448. //
  1449. // Synopsis: per-instance dialog proc
  1450. //
  1451. //-----------------------------------------------------------------------------
  1452. INT_PTR CALLBACK
  1453. CDsGrpMembersPage::DlgProc(HWND, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1454. {
  1455. switch (uMsg)
  1456. {
  1457. case WM_INITDIALOG:
  1458. return InitDlg(lParam);
  1459. case WM_NOTIFY:
  1460. return OnNotify(wParam, lParam);
  1461. case WM_SHOWWINDOW:
  1462. return OnShowWindow();
  1463. case WM_SETFOCUS:
  1464. return OnSetFocus((HWND)wParam);
  1465. case WM_HELP:
  1466. return OnHelp((LPHELPINFO)lParam);
  1467. case WM_COMMAND:
  1468. if (m_fInInit)
  1469. {
  1470. return TRUE;
  1471. }
  1472. return(OnCommand(GET_WM_COMMAND_ID(wParam, lParam),
  1473. GET_WM_COMMAND_HWND(wParam, lParam),
  1474. GET_WM_COMMAND_CMD(wParam, lParam)));
  1475. case WM_DESTROY:
  1476. return OnDestroy();
  1477. default:
  1478. return(FALSE);
  1479. }
  1480. return(TRUE);
  1481. }
  1482. //+----------------------------------------------------------------------------
  1483. //
  1484. // Method: CDsGrpMembersPage::OnInitDialog
  1485. //
  1486. // Synopsis: Set the initial control values from the corresponding DS
  1487. // attributes.
  1488. //
  1489. //-----------------------------------------------------------------------------
  1490. HRESULT
  1491. CDsGrpMembersPage::OnInitDialog(LPARAM lParam)
  1492. {
  1493. return OnInitDialog(lParam, TRUE);
  1494. }
  1495. HRESULT CDsGrpMembersPage::OnInitDialog(LPARAM, BOOL fShowIcons)
  1496. {
  1497. TRACE(CDsGrpMembersPage,OnInitDialog);
  1498. HRESULT hr;
  1499. PADS_ATTR_INFO pAttrs = NULL;
  1500. DWORD cAttrs = 0;
  1501. m_fShowIcons = (0 != g_ulMemberFilterCount) ? fShowIcons : FALSE;
  1502. CWaitCursor Wait;
  1503. if (!ADsPropSetHwnd(m_hNotifyObj, m_hPage))
  1504. {
  1505. m_pWritableAttrs = NULL;
  1506. }
  1507. PTSTR ptzRDN;
  1508. if (!UnicodeToTchar(m_pwszRDName, &ptzRDN))
  1509. {
  1510. REPORT_ERROR(E_OUTOFMEMORY, m_hPage);
  1511. return S_OK;
  1512. }
  1513. SetDlgItemText(m_hPage, IDC_CN, ptzRDN);
  1514. delete [] ptzRDN;
  1515. GetDomainMode(this, &m_fMixed);
  1516. //
  1517. // Get the group RID.
  1518. //
  1519. PWSTR rgpwzAttrNames[] = {L"primaryGroupToken"};
  1520. hr = m_pDsObj->GetObjectAttributes(rgpwzAttrNames, 1, &pAttrs, &cAttrs);
  1521. if (!CHECK_ADS_HR(&hr, m_hPage))
  1522. {
  1523. return S_OK;
  1524. }
  1525. dspAssert(cAttrs);
  1526. if (cAttrs == 1)
  1527. {
  1528. dspAssert(pAttrs);
  1529. m_dwGroupRID = pAttrs->pADsValues->Integer;
  1530. FreeADsMem(pAttrs);
  1531. }
  1532. GetGroupType(this, &m_dwType);
  1533. dspDebugOut((DEB_ITRACE, "Group Type = 0x%x\n", m_dwType));
  1534. //
  1535. // Get the membership list and fill the listview control.
  1536. //
  1537. m_pList = new CDsMembershipList(m_hPage, IDC_MEMBER_LIST);
  1538. CHECK_NULL_REPORT(m_pList, m_hPage, return S_OK);
  1539. hr = m_pList->Init(m_fShowIcons);
  1540. CHECK_HRESULT(hr, return S_OK);
  1541. hr = FillGroupList();
  1542. CHECK_HRESULT(hr, return S_OK);
  1543. m_fMemberWritable = CheckIfWritable(g_wzMemberAttr);
  1544. if (!m_fMemberWritable)
  1545. {
  1546. EnableWindow(GetDlgItem(m_hPage, IDC_ADD_BTN), FALSE);
  1547. EnableWindow(GetDlgItem(m_hPage, IDC_REMOVE_BTN), FALSE);
  1548. }
  1549. //Set the focus and selection on first item in the list
  1550. ListView_SetItemState(GetDlgItem(m_hPage, IDC_MEMBER_LIST), 0,
  1551. LVIS_SELECTED, LVIS_SELECTED);
  1552. ListView_SetItemState(GetDlgItem(m_hPage, IDC_MEMBER_LIST), 0,
  1553. LVIS_FOCUSED, LVIS_FOCUSED);
  1554. BOOL bSecurityGroup = (m_dwType & GROUP_TYPE_SECURITY_ENABLED) ? TRUE : FALSE;
  1555. hr = LoadGroupExtraClasses(bSecurityGroup);
  1556. return S_OK;
  1557. }
  1558. //+----------------------------------------------------------------------------
  1559. //
  1560. // Method: CDsGrpMembersPage::OnApply
  1561. //
  1562. // Synopsis: Handles the Apply notification.
  1563. //
  1564. //-----------------------------------------------------------------------------
  1565. LRESULT
  1566. CDsGrpMembersPage::OnApply(void)
  1567. {
  1568. TRACE(CDsGrpMembersPage,OnApply);
  1569. HRESULT hr = S_OK;
  1570. ADS_ATTR_INFO AttrInfo;
  1571. PADS_ATTR_INFO pAttrs = &AttrInfo;
  1572. AttrInfo.pszAttrName = g_wzMemberAttr;
  1573. AttrInfo.dwADsType = ADSTYPE_DN_STRING;
  1574. //
  1575. // Read the list of members and do additions.
  1576. //
  1577. DWORD cModified;
  1578. int i, cMembers = m_pList->GetCount();
  1579. if (cMembers > 0)
  1580. {
  1581. AttrInfo.dwControlCode = ADS_ATTR_APPEND;
  1582. PADSVALUE rgADsValues;
  1583. rgADsValues = new ADSVALUE[cMembers];
  1584. CHECK_NULL(rgADsValues, return PSNRET_INVALID_NOCHANGEPAGE);
  1585. memset(rgADsValues, 0, cMembers * sizeof(ADSVALUE));
  1586. pAttrs->pADsValues = rgADsValues;
  1587. pAttrs->dwNumValues = 0;
  1588. CMemberListItem * pItem;
  1589. for (i = 0; i < cMembers; i++)
  1590. {
  1591. if (FAILED(m_pList->GetItem(i, &pItem)))
  1592. {
  1593. dspAssert(FALSE && "List Error");
  1594. return PSNRET_INVALID_NOCHANGEPAGE;
  1595. }
  1596. if (!pItem)
  1597. {
  1598. dspAssert(pItem);
  1599. return PSNRET_INVALID_NOCHANGEPAGE;
  1600. }
  1601. if (pItem->m_fIsAlreadyMember)
  1602. {
  1603. continue;
  1604. }
  1605. dspAssert(pItem->m_pwzDN);
  1606. rgADsValues[pAttrs->dwNumValues].DNString = pItem->m_pwzDN;
  1607. rgADsValues[pAttrs->dwNumValues].dwType = ADSTYPE_DN_STRING;
  1608. pAttrs->dwNumValues++;
  1609. }
  1610. if (pAttrs->dwNumValues)
  1611. {
  1612. hr = m_pDsObj->SetObjectAttributes(pAttrs, 1, &cModified);
  1613. if (!CheckGroupUpdate(hr, m_hPage))
  1614. {
  1615. delete [] rgADsValues;
  1616. return PSNRET_INVALID_NOCHANGEPAGE;
  1617. }
  1618. }
  1619. delete [] rgADsValues;
  1620. // Now mark all entries as members
  1621. for (i = 0; i < cMembers; i++)
  1622. {
  1623. if (FAILED(m_pList->GetItem(i, &pItem)))
  1624. {
  1625. dspAssert(FALSE && "List Error");
  1626. return PSNRET_INVALID_NOCHANGEPAGE;
  1627. }
  1628. if (!pItem)
  1629. {
  1630. dspAssert(pItem);
  1631. return PSNRET_INVALID_NOCHANGEPAGE;
  1632. }
  1633. pItem->m_fIsAlreadyMember = TRUE;
  1634. }
  1635. }
  1636. //
  1637. // Do removals.
  1638. //
  1639. DWORD cDelItems = m_DelList.GetItemCount();
  1640. if (cDelItems)
  1641. {
  1642. AttrInfo.dwControlCode = ADS_ATTR_DELETE;
  1643. PADSVALUE rgADsValues;
  1644. rgADsValues = new ADSVALUE[cDelItems];
  1645. CHECK_NULL(rgADsValues, return PSNRET_INVALID_NOCHANGEPAGE);
  1646. memset(rgADsValues, 0, cDelItems * sizeof(ADSVALUE));
  1647. pAttrs->pADsValues = rgADsValues;
  1648. pAttrs->dwNumValues = 0;
  1649. CMemberListItem * pDelItem = m_DelList.RemoveFirstItem();
  1650. while (pDelItem)
  1651. {
  1652. if (pDelItem->m_fIsExternal)
  1653. {
  1654. hr = GetRealDN(pDelItem);
  1655. CHECK_HRESULT_REPORT(hr, m_hPage, continue);
  1656. }
  1657. dspAssert(pDelItem->m_pwzDN);
  1658. rgADsValues[pAttrs->dwNumValues].DNString = pDelItem->m_pwzDN;
  1659. rgADsValues[pAttrs->dwNumValues].dwType = ADSTYPE_DN_STRING;
  1660. pAttrs->dwNumValues++;
  1661. pDelItem = m_DelList.RemoveFirstItem();
  1662. }
  1663. if (pAttrs->dwNumValues)
  1664. {
  1665. hr = m_pDsObj->SetObjectAttributes(pAttrs, 1, &cModified);
  1666. if (!CheckGroupUpdate(hr, m_hPage, FALSE))
  1667. {
  1668. delete [] rgADsValues;
  1669. return PSNRET_INVALID_NOCHANGEPAGE;
  1670. }
  1671. }
  1672. delete [] rgADsValues;
  1673. }
  1674. return (SUCCEEDED(hr)) ? PSNRET_NOERROR : PSNRET_INVALID_NOCHANGEPAGE;
  1675. }
  1676. //+----------------------------------------------------------------------------
  1677. //
  1678. // Method: CDsGrpMembersPage::OnCommand
  1679. //
  1680. // Synopsis: Handle control notifications.
  1681. //
  1682. //-----------------------------------------------------------------------------
  1683. LRESULT
  1684. CDsGrpMembersPage::OnCommand(int id, HWND hwndCtl, UINT codeNotify)
  1685. {
  1686. if (m_fInInit)
  1687. {
  1688. return 0;
  1689. }
  1690. switch (codeNotify)
  1691. {
  1692. case BN_CLICKED:
  1693. TRACE(CDsGrpMembersPage,OnCommand);
  1694. if (id == IDC_ADD_BTN)
  1695. {
  1696. InvokeUserQuery();
  1697. }
  1698. if (id == IDC_REMOVE_BTN)
  1699. {
  1700. RemoveMember();
  1701. }
  1702. break;
  1703. }
  1704. return CDsPropPageBase::OnCommand(id, hwndCtl, codeNotify);
  1705. }
  1706. //+----------------------------------------------------------------------------
  1707. //
  1708. // Method: CDsGrpMembersPage::OnNotify
  1709. //
  1710. // Synopsis: Handles list notification messages
  1711. //
  1712. //-----------------------------------------------------------------------------
  1713. LRESULT
  1714. CDsGrpMembersPage::OnNotify(WPARAM wParam, LPARAM lParam)
  1715. {
  1716. if (m_fInInit)
  1717. {
  1718. return 0;
  1719. }
  1720. switch (((LPNMHDR)lParam)->code)
  1721. {
  1722. case LVN_ITEMCHANGED:
  1723. if (m_fMemberWritable)
  1724. {
  1725. LRESULT selected = SendDlgItemMessage(m_hPage, IDC_MEMBER_LIST, LVM_GETSELECTEDCOUNT, 0, 0);
  1726. if (selected > 0)
  1727. {
  1728. EnableWindow(GetDlgItem(m_hPage, IDC_REMOVE_BTN), TRUE);
  1729. }
  1730. else
  1731. {
  1732. EnableWindow(GetDlgItem(m_hPage, IDC_REMOVE_BTN), FALSE);
  1733. }
  1734. }
  1735. break;
  1736. case NM_DBLCLK:
  1737. //
  1738. // Display properties for the selected item. First, find out
  1739. // which item is selected.
  1740. //
  1741. CMemberListItem * pItem;
  1742. if (!m_pList->GetCurListItem(NULL, NULL, &pItem))
  1743. {
  1744. break;
  1745. }
  1746. dspAssert(pItem);
  1747. if (pItem->m_fIsExternal)
  1748. {
  1749. HRESULT hr = GetRealDN(pItem);
  1750. if (hr == HRESULT_FROM_WIN32(ERROR_DS_OBJ_NOT_FOUND))
  1751. {
  1752. MsgBox(IDS_CANT_VIEW_EXTERNAL, m_hPage);
  1753. break;
  1754. }
  1755. CHECK_HRESULT_REPORT(hr, m_hPage, break);
  1756. }
  1757. if (pItem->m_ulScopeType & DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN)
  1758. {
  1759. //
  1760. // We cannot show the properties for downlevel users
  1761. //
  1762. // Put a useful message up
  1763. PTSTR ptzTitle, ptzMsg;
  1764. if (!LoadStringToTchar(IDS_MSG_NO_DOWNLEVEL_PROPERTIES, &ptzMsg))
  1765. {
  1766. break;
  1767. }
  1768. if (!LoadStringToTchar(IDS_MSG_TITLE, &ptzTitle))
  1769. {
  1770. break;
  1771. }
  1772. MessageBox(m_hPage, ptzMsg, ptzTitle, MB_OK | MB_ICONEXCLAMATION);
  1773. delete[] ptzTitle;
  1774. delete[] ptzMsg;
  1775. break;
  1776. }
  1777. PostPropSheet(pItem->m_pwzDN, this);
  1778. break;
  1779. }
  1780. return CDsPropPageBase::OnNotify(wParam, lParam);
  1781. }
  1782. // NTRAID#NTBUG9-651756-2002/07/15-artm
  1783. //
  1784. // Helper function to copy LsaStrings to string objects.
  1785. //
  1786. #ifdef DSADMIN
  1787. HRESULT
  1788. CopyLsaString(const LSA_UNICODE_STRING& lsaString, CStrW& dest)
  1789. {
  1790. TRACE_FUNCTION(CopyLsaString);
  1791. dest.Empty();
  1792. // Get string length in characters (+1 for NULL).
  1793. int buffsize = (lsaString.Length / sizeof(WCHAR)) + 1;
  1794. WCHAR* buffer = dest.GetBuffer(buffsize);
  1795. if (!buffer)
  1796. {
  1797. return E_OUTOFMEMORY;
  1798. }
  1799. HRESULT hr = StringCchCopyN(
  1800. buffer,
  1801. buffsize,
  1802. lsaString.Buffer,
  1803. buffsize - 1);
  1804. buffer = NULL;
  1805. dest.ReleaseBuffer();
  1806. // We don't expect that the copy should ever fail.
  1807. dspAssert(SUCCEEDED(hr));
  1808. return hr;
  1809. }
  1810. //
  1811. // Get the localized name and domain for a SID.
  1812. //
  1813. HRESULT
  1814. LocalizeSid(PSID psid, CStrW& localizedName, CStrW& localizedDomain)
  1815. {
  1816. TRACE_FUNCTION(LocalizeSid);
  1817. PLSA_TRANSLATED_NAME pTranslatedName = NULL;
  1818. PLSA_REFERENCED_DOMAIN_LIST pReferencedDomains = NULL;
  1819. HRESULT hr = S_OK;
  1820. NTSTATUS nts = STATUS_SUCCESS;
  1821. LSA_HANDLE hLsa = NULL;
  1822. LSA_OBJECT_ATTRIBUTES lsaAttr;
  1823. ::ZeroMemory(&lsaAttr, sizeof(lsaAttr));
  1824. do
  1825. {
  1826. if (!psid || !IsValidSid(psid))
  1827. {
  1828. hr = E_INVALIDARG;
  1829. break;
  1830. }
  1831. // Acquire the LSA resource.
  1832. // We call this in the same way as object picker.
  1833. nts = LsaOpenPolicy(NULL, &lsaAttr, POLICY_LOOKUP_NAMES, &hLsa);
  1834. if (nts != STATUS_SUCCESS)
  1835. {
  1836. hr = HRESULT_FROM_NT(nts);
  1837. break;
  1838. }
  1839. // Convert the SID to a localized name.
  1840. nts = LsaLookupSids(hLsa,
  1841. 1,
  1842. &psid,
  1843. &pReferencedDomains,
  1844. &pTranslatedName);
  1845. if (nts != STATUS_SUCCESS)
  1846. {
  1847. hr = HRESULT_FROM_NT(nts);
  1848. break;
  1849. }
  1850. // Verify assumption that the SID we had was valid.
  1851. if (pTranslatedName->Use == SidTypeInvalid ||
  1852. pTranslatedName->Use == SidTypeUnknown ||
  1853. pTranslatedName->Use == SidTypeDomain)
  1854. {
  1855. dspAssert(pTranslatedName->Use != SidTypeInvalid);
  1856. dspAssert(pTranslatedName->Use != SidTypeUnknown);
  1857. dspAssert(pTranslatedName->Use != SidTypeDomain);
  1858. hr = E_FAIL;
  1859. break;
  1860. }
  1861. hr = CopyLsaString(pTranslatedName->Name, localizedName);
  1862. CHECK_HRESULT(hr, break);
  1863. // If there are no referenced domains for the localized name we
  1864. // don't need to do any more work.
  1865. if (pTranslatedName->DomainIndex < 0L)
  1866. {
  1867. break;
  1868. }
  1869. ULONG domainIndex = pTranslatedName->DomainIndex;
  1870. // Should _never_ happen. Implies a bug either in Lsa functions
  1871. // or in their documentation.
  1872. dspAssert(pReferencedDomains->Entries >= domainIndex);
  1873. hr = CopyLsaString(
  1874. pReferencedDomains->Domains[domainIndex].Name,
  1875. localizedDomain);
  1876. CHECK_HRESULT(hr, break);
  1877. } while (0);
  1878. // Clean up any resources we've accumulated.
  1879. if (pTranslatedName)
  1880. {
  1881. LsaFreeMemory(static_cast<PVOID>(pTranslatedName));
  1882. }
  1883. if (pReferencedDomains)
  1884. {
  1885. LsaFreeMemory(static_cast<PVOID>(pReferencedDomains));
  1886. }
  1887. if (hLsa)
  1888. {
  1889. nts = LsaClose(hLsa);
  1890. hLsa = NULL;
  1891. // No conceivable reason why this should fail.
  1892. dspAssert(nts == STATUS_SUCCESS);
  1893. }
  1894. return hr;
  1895. }
  1896. #endif // DSADMIN
  1897. //+----------------------------------------------------------------------------
  1898. //
  1899. // Method: CDsGrpMembersPage::InvokeUserQuery
  1900. //
  1901. // Synopsis: Bring up the query dialog to search for users and groups.
  1902. //
  1903. //-----------------------------------------------------------------------------
  1904. void
  1905. CDsGrpMembersPage::InvokeUserQuery(void)
  1906. {
  1907. TRACE(CDsGrpMembersPage,InvokeUserQuery);
  1908. HRESULT hr;
  1909. UINT i;
  1910. CWaitCursor WaitCursor;
  1911. CSmartWStr cstrCleanDN;
  1912. IDsObjectPicker * pObjSel;
  1913. BOOL fIsObjSelInited, fNativeModeUSG = FALSE;
  1914. CStr strExternMemberList;
  1915. hr = GetObjSel(&pObjSel, &fIsObjSelInited);
  1916. CHECK_HRESULT(hr, return);
  1917. if (!fIsObjSelInited)
  1918. {
  1919. CStrW cstrDC;
  1920. hr = GetLdapServerName(m_pDsObj, cstrDC);
  1921. CHECK_HRESULT_REPORT(hr, m_hPage, return);
  1922. dspDebugOut((DEB_ITRACE, "ObjSel targetted to %ws\n", (LPCWSTR)cstrDC));
  1923. DSOP_SCOPE_INIT_INFO rgScopes[5];
  1924. DSOP_INIT_INFO InitInfo;
  1925. ZeroMemory(rgScopes, sizeof(rgScopes));
  1926. ZeroMemory(&InitInfo, sizeof(InitInfo));
  1927. // The first scope is the local domain. All group types can contain
  1928. // users, computers, and contacts from the local domain.
  1929. //
  1930. rgScopes[0].cbSize = sizeof(DSOP_SCOPE_INIT_INFO);
  1931. rgScopes[0].flType = DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN;
  1932. rgScopes[0].flScope = DSOP_SCOPE_FLAG_STARTING_SCOPE |
  1933. DSOP_SCOPE_FLAG_DEFAULT_FILTER_USERS |
  1934. DSOP_SCOPE_FLAG_DEFAULT_FILTER_GROUPS;
  1935. rgScopes[0].pwzDcName = cstrDC;
  1936. rgScopes[0].FilterFlags.Uplevel.flBothModes =
  1937. DSOP_FILTER_USERS | DSOP_FILTER_CONTACTS | DSOP_FILTER_COMPUTERS;
  1938. // The second scope is the local forest.
  1939. //
  1940. rgScopes[1].cbSize = sizeof(DSOP_SCOPE_INIT_INFO);
  1941. rgScopes[1].flType = DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN;
  1942. rgScopes[1].flScope = DSOP_SCOPE_FLAG_DEFAULT_FILTER_USERS |
  1943. DSOP_SCOPE_FLAG_DEFAULT_FILTER_GROUPS;
  1944. // The third scope is the GC.
  1945. //
  1946. rgScopes[2].cbSize = sizeof(DSOP_SCOPE_INIT_INFO);
  1947. rgScopes[2].flType = DSOP_SCOPE_TYPE_GLOBAL_CATALOG;
  1948. rgScopes[2].flScope = DSOP_SCOPE_FLAG_DEFAULT_FILTER_USERS |
  1949. DSOP_SCOPE_FLAG_DEFAULT_FILTER_GROUPS;
  1950. // The fourth scope is uplevel external trusted domains.
  1951. //
  1952. rgScopes[3].cbSize = sizeof(DSOP_SCOPE_INIT_INFO);
  1953. rgScopes[3].flType = DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN;
  1954. rgScopes[3].flScope = DSOP_SCOPE_FLAG_DEFAULT_FILTER_USERS |
  1955. DSOP_SCOPE_FLAG_DEFAULT_FILTER_GROUPS |
  1956. DSOP_SCOPE_FLAG_WANT_PROVIDER_LDAP;
  1957. // The fifth scope is downlevel external trusted domains.
  1958. //
  1959. rgScopes[4].cbSize = sizeof(DSOP_SCOPE_INIT_INFO);
  1960. rgScopes[4].flType = DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN;
  1961. rgScopes[4].flScope = DSOP_SCOPE_FLAG_DEFAULT_FILTER_USERS |
  1962. DSOP_SCOPE_FLAG_DEFAULT_FILTER_GROUPS;
  1963. if (m_dwType & GROUP_TYPE_ACCOUNT_GROUP) // Global group
  1964. {
  1965. if (!(m_fMixed && (m_dwType & GROUP_TYPE_SECURITY_ENABLED)))
  1966. {
  1967. // if it is not mixed-mode, security-enabled, add global.
  1968. //
  1969. rgScopes[0].FilterFlags.Uplevel.flBothModes |=
  1970. DSOP_FILTER_GLOBAL_GROUPS_DL |
  1971. DSOP_FILTER_GLOBAL_GROUPS_SE;
  1972. }
  1973. rgScopes[1].FilterFlags.Uplevel.flBothModes =
  1974. rgScopes[2].FilterFlags.Uplevel.flBothModes =
  1975. DSOP_FILTER_CONTACTS;
  1976. InitInfo.cDsScopeInfos = 3; // Enterprise scope.
  1977. }
  1978. else if (m_dwType & GROUP_TYPE_RESOURCE_GROUP) // Local group.
  1979. {
  1980. rgScopes[0].FilterFlags.Uplevel.flBothModes |=
  1981. DSOP_FILTER_UNIVERSAL_GROUPS_DL |
  1982. DSOP_FILTER_UNIVERSAL_GROUPS_SE |
  1983. DSOP_FILTER_GLOBAL_GROUPS_DL |
  1984. DSOP_FILTER_GLOBAL_GROUPS_SE;
  1985. if (!(m_fMixed && (m_dwType & GROUP_TYPE_SECURITY_ENABLED)) &&
  1986. !(m_dwType & GROUP_TYPE_BUILTIN_LOCAL_GROUP))
  1987. {
  1988. // If this is not a mixed-mode security-enabled local group
  1989. // or a builtin group, then add local groups.
  1990. //
  1991. rgScopes[0].FilterFlags.Uplevel.flBothModes |=
  1992. DSOP_FILTER_DOMAIN_LOCAL_GROUPS_DL |
  1993. DSOP_FILTER_DOMAIN_LOCAL_GROUPS_SE;
  1994. }
  1995. rgScopes[1].FilterFlags.Uplevel.flBothModes =
  1996. rgScopes[2].FilterFlags.Uplevel.flBothModes =
  1997. DSOP_FILTER_USERS | DSOP_FILTER_CONTACTS |
  1998. DSOP_FILTER_COMPUTERS |
  1999. DSOP_FILTER_UNIVERSAL_GROUPS_DL |
  2000. DSOP_FILTER_UNIVERSAL_GROUPS_SE |
  2001. DSOP_FILTER_GLOBAL_GROUPS_DL |
  2002. DSOP_FILTER_GLOBAL_GROUPS_SE;
  2003. //bug 37724
  2004. if( m_dwType & GROUP_TYPE_BUILTIN_LOCAL_GROUP )
  2005. {
  2006. rgScopes[0].FilterFlags.Uplevel.flBothModes |=
  2007. DSOP_FILTER_WELL_KNOWN_PRINCIPALS;
  2008. rgScopes[1].FilterFlags.Uplevel.flBothModes |=
  2009. DSOP_FILTER_WELL_KNOWN_PRINCIPALS;
  2010. rgScopes[2].FilterFlags.Uplevel.flBothModes |=
  2011. DSOP_FILTER_WELL_KNOWN_PRINCIPALS;
  2012. }
  2013. //
  2014. // Uplevel external domains:
  2015. //
  2016. rgScopes[3].FilterFlags.Uplevel.flBothModes =
  2017. DSOP_FILTER_USERS | DSOP_FILTER_COMPUTERS |
  2018. DSOP_FILTER_UNIVERSAL_GROUPS_DL |
  2019. DSOP_FILTER_UNIVERSAL_GROUPS_SE |
  2020. DSOP_FILTER_GLOBAL_GROUPS_DL |
  2021. DSOP_FILTER_GLOBAL_GROUPS_SE;
  2022. //
  2023. // Downlevel external domains:
  2024. //
  2025. rgScopes[4].FilterFlags.flDownlevel =
  2026. DSOP_DOWNLEVEL_FILTER_USERS |
  2027. DSOP_DOWNLEVEL_FILTER_GLOBAL_GROUPS;
  2028. InitInfo.cDsScopeInfos = 5; // Any trusted domain.
  2029. }
  2030. else if (m_dwType & GROUP_TYPE_UNIVERSAL_GROUP)
  2031. {
  2032. rgScopes[0].FilterFlags.Uplevel.flBothModes =
  2033. rgScopes[1].FilterFlags.Uplevel.flBothModes =
  2034. rgScopes[2].FilterFlags.Uplevel.flBothModes =
  2035. DSOP_FILTER_USERS | DSOP_FILTER_CONTACTS |
  2036. DSOP_FILTER_COMPUTERS |
  2037. DSOP_FILTER_UNIVERSAL_GROUPS_DL |
  2038. DSOP_FILTER_UNIVERSAL_GROUPS_SE |
  2039. DSOP_FILTER_GLOBAL_GROUPS_DL |
  2040. DSOP_FILTER_GLOBAL_GROUPS_SE;
  2041. InitInfo.cDsScopeInfos = 3; // Enterprise scope.
  2042. }
  2043. InitInfo.cbSize = sizeof(DSOP_INIT_INFO);
  2044. InitInfo.aDsScopeInfos = rgScopes;
  2045. InitInfo.pwzTargetComputer = cstrDC;
  2046. InitInfo.flOptions = DSOP_FLAG_MULTISELECT;
  2047. InitInfo.cAttributesToFetch = 2;
  2048. LPCWSTR rgAttrNames[] = {g_wzObjectSID,
  2049. g_wzUserAccountControl};
  2050. InitInfo.apwzAttributeNames = rgAttrNames;
  2051. hr = pObjSel->Initialize(&InitInfo);
  2052. CHECK_HRESULT_REPORT(hr, m_hPage, return);
  2053. ObjSelInited();
  2054. }
  2055. IDataObject * pdoSelections = NULL;
  2056. CComPtr<IDsObjectPickerEx> spObjPickerEx;
  2057. hr = pObjSel->QueryInterface(IID_IDsObjectPickerEx, (void**)&spObjPickerEx);
  2058. CHECK_HRESULT_REPORT(hr, m_hPage, return);
  2059. hr = spObjPickerEx->InvokeDialogEx(m_hPage, this, &pdoSelections);
  2060. // hr = pObjSel->InvokeDialog(m_hPage, &pdoSelections);
  2061. CHECK_HRESULT_REPORT(hr, m_hPage, return);
  2062. if (hr == S_FALSE || !pdoSelections)
  2063. {
  2064. return;
  2065. }
  2066. // Security enabled universal groups shouldn't contain members
  2067. // from mixed-mode domains BUT, we have to allow it for Exchange's
  2068. // non-standard public folder security model.
  2069. //
  2070. if (!m_fMixed && (m_dwType & GROUP_TYPE_UNIVERSAL_GROUP) &&
  2071. (m_dwType & GROUP_TYPE_SECURITY_ENABLED))
  2072. {
  2073. fNativeModeUSG = TRUE;
  2074. }
  2075. m_MixedModeMembers.Init(this);
  2076. CSmartWStr cstrCleanGroup;
  2077. FORMATETC fmte = {g_cfDsSelList, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  2078. STGMEDIUM medium = {TYMED_NULL, NULL, NULL};
  2079. hr = pdoSelections->GetData(&fmte, &medium);
  2080. CHECK_HRESULT_REPORT(hr, m_hPage, return);
  2081. PDS_SELECTION_LIST pSelList = (PDS_SELECTION_LIST)GlobalLock(medium.hGlobal);
  2082. if (!pSelList)
  2083. {
  2084. goto ExitCleanup;
  2085. }
  2086. WaitCursor.SetWait();
  2087. // Clean the group name so it can be compared with those returned by the
  2088. // user's selection.
  2089. //
  2090. hr = SkipPrefix(m_pwszObjPathName, &cstrCleanGroup);
  2091. CHECK_HRESULT_REPORT(hr, m_hPage, goto ExitCleanup);
  2092. //
  2093. // Insert the returned items into the group.
  2094. //
  2095. for (i = 0; i < pSelList->cItems; i++)
  2096. {
  2097. CMemberListItem * pItemInDelList = NULL;
  2098. PSID pSid = NULL;
  2099. if (!pSelList->aDsSelection[i].pwzADsPath) continue;
  2100. // Check for an object from an external trusted domain. These objects
  2101. // have a path of the form "LDAP://<SID=01050xxxx>". SAM will create
  2102. // an FSPO for this member and will then store that DN rather than the
  2103. // above path. We won't know this DN until after the member is added,
  2104. // so use its object-SID to identify it.
  2105. //
  2106. #ifdef DSADMIN
  2107. // NTRAID#NTBUG9-651756-2002/07/03-artm Need to use SID for well known security principals.
  2108. PCWSTR objectClass = pSelList->aDsSelection[i].pwzClass;
  2109. bool isWellKnownSecurityPrincipal = false;
  2110. if (objectClass && (_wcsicmp(objectClass, g_wzFPO) == 0) )
  2111. {
  2112. isWellKnownSecurityPrincipal = true;
  2113. }
  2114. #endif //DSADMIN
  2115. if ((pSelList->aDsSelection[i].flScopeType == DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN) ||
  2116. (pSelList->aDsSelection[i].flScopeType == DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN)
  2117. #ifdef DSADMIN
  2118. || isWellKnownSecurityPrincipal
  2119. #endif //DSADMIN
  2120. )
  2121. {
  2122. dspAssert(pSelList->aDsSelection[i].pvarFetchedAttributes);
  2123. if (pSelList->aDsSelection[i].pvarFetchedAttributes[0].vt != (VT_ARRAY | VT_UI1))
  2124. {
  2125. REPORT_ERROR(ERROR_DATATYPE_MISMATCH, m_hPage);
  2126. continue;
  2127. }
  2128. pSid = pSelList->aDsSelection[i].pvarFetchedAttributes[0].parray->pvData;
  2129. dspAssert(IsValidSid(pSid));
  2130. //
  2131. // Check if the item is in the delete list, if so remove it.
  2132. //
  2133. pItemInDelList = m_DelList.FindItemRemove(pSid);
  2134. }
  2135. else
  2136. {
  2137. hr = SkipPrefix(pSelList->aDsSelection[i].pwzADsPath, &cstrCleanDN);
  2138. CHECK_HRESULT_REPORT(hr, m_hPage, goto ExitCleanup);
  2139. // See if the user is trying to add the group to itself.
  2140. //
  2141. if (_wcsicmp(cstrCleanDN, cstrCleanGroup) == 0)
  2142. {
  2143. if (pSelList->cItems == 1)
  2144. {
  2145. ErrMsg(IDS_ERROR_GRP_SELF, m_hPage);
  2146. goto ExitCleanup;
  2147. }
  2148. continue;
  2149. }
  2150. // Check if the item is in the delete list, if so remove it.
  2151. //
  2152. pItemInDelList = m_DelList.FindItemRemove(cstrCleanDN);
  2153. }
  2154. if (pItemInDelList)
  2155. {
  2156. hr = m_pList->InsertIntoList(pItemInDelList);
  2157. }
  2158. else
  2159. {
  2160. // NTRAID#NTBUG9-651756-2002/07/03-artm
  2161. #ifdef DSADMIN
  2162. if (isWellKnownSecurityPrincipal)
  2163. {
  2164. dspAssert(pSid);
  2165. CStrW localizedName, domainName;
  2166. hr = LocalizeSid(pSid, localizedName, domainName);
  2167. CHECK_HRESULT_REPORT(hr, m_hPage, goto ExitCleanup);
  2168. // Dummy up the canonical version of the localized name.
  2169. CStrW canonicalNameEx = domainName + L"\n" + localizedName;
  2170. hr = m_pList->InsertIntoList(pSid, canonicalNameEx);
  2171. }
  2172. else if (pSid)
  2173. #else
  2174. if (pSid)
  2175. #endif // DSADMIN
  2176. {
  2177. CComPtr<IADsPathname> spPathCracker;
  2178. hr = GetADsPathname(spPathCracker);
  2179. CHECK_HRESULT_REPORT(hr, m_hPage, goto ExitCleanup);
  2180. hr = spPathCracker->Set(CComBSTR(pSelList->aDsSelection[i].pwzADsPath),
  2181. ADS_SETTYPE_FULL);
  2182. CHECK_HRESULT_REPORT(hr, m_hPage, goto ExitCleanup);
  2183. PWSTR pwzName;
  2184. BSTR bstr;
  2185. hr = spPathCracker->Retrieve(ADS_FORMAT_PROVIDER, &bstr);
  2186. CHECK_HRESULT_REPORT(hr, m_hPage, goto ExitCleanup);
  2187. if (_wcsicmp(bstr, L"LDAP") == 0)
  2188. {
  2189. SysFreeString(bstr);
  2190. hr = SkipPrefix(pSelList->aDsSelection[i].pwzADsPath, &cstrCleanDN);
  2191. CHECK_HRESULT_REPORT(hr, m_hPage, goto ExitCleanup);
  2192. hr = CrackName(cstrCleanDN, &pwzName, GET_OBJ_CAN_NAME_EX, m_hPage);
  2193. CHECK_HRESULT_REPORT(hr, m_hPage, goto ExitCleanup);
  2194. hr = m_pList->InsertIntoList(pSid, pwzName);
  2195. LocalFreeStringW(&pwzName);
  2196. }
  2197. else
  2198. {
  2199. SysFreeString(bstr);
  2200. hr = spPathCracker->Retrieve(ADS_FORMAT_WINDOWS_DN, &bstr);
  2201. CHECK_HRESULT_REPORT(hr, m_hPage, goto ExitCleanup);
  2202. hr = m_pList->InsertIntoList(pSid, bstr);
  2203. SysFreeString(bstr);
  2204. }
  2205. }
  2206. else
  2207. {
  2208. int iIcon = -1;
  2209. if (m_fShowIcons)
  2210. {
  2211. BOOL fDisabled = FALSE;
  2212. if (pSelList->aDsSelection[i].pvarFetchedAttributes[1].vt == VT_I4)
  2213. {
  2214. fDisabled = pSelList->aDsSelection[i].pvarFetchedAttributes[1].lVal & UF_ACCOUNTDISABLE;
  2215. }
  2216. iIcon = g_ClassIconCache.GetClassIconIndex(pSelList->aDsSelection[i].pwzClass,
  2217. fDisabled);
  2218. if (iIcon == -1)
  2219. {
  2220. iIcon = g_ClassIconCache.AddClassIcon(pSelList->aDsSelection[i].pwzClass,
  2221. fDisabled);
  2222. }
  2223. }
  2224. if (fNativeModeUSG &&
  2225. ((DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN == pSelList->aDsSelection[i].flScopeType) ||
  2226. (DSOP_SCOPE_TYPE_GLOBAL_CATALOG == pSelList->aDsSelection[i].flScopeType)))
  2227. {
  2228. // member from domain in forest is DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN
  2229. // member from the same domain is DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN
  2230. //
  2231. m_MixedModeMembers.CheckMember(cstrCleanDN);
  2232. }
  2233. dspDebugOut((DEB_ITRACE, "New member scope is 0x%x\n", pSelList->aDsSelection[i].flScopeType));
  2234. hr = m_pList->InsertIntoList(cstrCleanDN, iIcon);
  2235. }
  2236. }
  2237. if (hr == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS))
  2238. {
  2239. continue;
  2240. }
  2241. CHECK_HRESULT(hr, goto ExitCleanup);
  2242. }
  2243. m_MixedModeMembers.ListExternalMembers(strExternMemberList);
  2244. if (!strExternMemberList.IsEmpty())
  2245. {
  2246. CStr strMessage, strFormat;
  2247. strFormat.LoadString(g_hInstance, IDS_USG_MIXED_WARNING);
  2248. strMessage.Format(strFormat, strExternMemberList);
  2249. ReportErrorWorker(m_hPage, (LPTSTR)(LPCTSTR)strMessage);
  2250. }
  2251. SetDirty();
  2252. ExitCleanup:
  2253. GlobalUnlock(medium.hGlobal);
  2254. ReleaseStgMedium(&medium);
  2255. pdoSelections->Release();
  2256. }
  2257. //+----------------------------------------------------------------------------
  2258. //
  2259. // Method: CDsGrpMembersPage::FillGroupList
  2260. //
  2261. // Synopsis: Fill the list box with the names of the group members.
  2262. //
  2263. //-----------------------------------------------------------------------------
  2264. HRESULT
  2265. CDsGrpMembersPage::FillGroupList(void)
  2266. {
  2267. TRACE(CDsGrpMembersPage,FillGroupList);
  2268. return ::FillGroupList(this, m_pList, m_dwGroupRID);
  2269. }
  2270. //+----------------------------------------------------------------------------
  2271. //
  2272. // Method: CDsGrpMembersPage::RemoveMember
  2273. //
  2274. // Synopsis: Removes the selected users.
  2275. //
  2276. //-----------------------------------------------------------------------------
  2277. void
  2278. CDsGrpMembersPage::RemoveMember(void)
  2279. {
  2280. TRACE(CDsGrpMembersPage,RemoveMember);
  2281. if (!m_pList)
  2282. {
  2283. return;
  2284. }
  2285. int* pIndex = NULL;
  2286. CMemberListItem ** ppItem;
  2287. int nNumSelected = 0;
  2288. //
  2289. // Compose the confirmation message and post it.
  2290. //
  2291. TCHAR szMsg[160];
  2292. if (!LoadStringReport(IDS_RM_MBR_MSG, szMsg, 160, m_hPage))
  2293. {
  2294. return;
  2295. }
  2296. TCHAR szTitle[80];
  2297. if (!LoadStringReport(IDS_MSG_TITLE, szTitle, 80, m_hPage))
  2298. {
  2299. return;
  2300. }
  2301. LONG iRet = MessageBox(m_hPage, szMsg, szTitle, MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2);
  2302. if (iRet == IDNO)
  2303. {
  2304. // The user declined, so go home.
  2305. //
  2306. return;
  2307. }
  2308. CWaitCursor cWait;
  2309. if (!m_pList->GetCurListItems(&pIndex, NULL, &ppItem, &nNumSelected))
  2310. {
  2311. return;
  2312. }
  2313. for (int idx = 0; idx < nNumSelected; idx++)
  2314. {
  2315. if (!ppItem[idx])
  2316. {
  2317. if (pIndex != NULL)
  2318. {
  2319. delete[] pIndex;
  2320. pIndex = 0;
  2321. }
  2322. delete[] ppItem;
  2323. return;
  2324. }
  2325. if (ppItem[idx]->m_fIsPrimary)
  2326. {
  2327. ErrMsg(IDS_RM_USR_PRI_GRP, m_hPage);
  2328. continue;
  2329. }
  2330. //
  2331. // Put the item into the delete list and remove it from the list box.
  2332. //
  2333. if (!m_DelList.AddItem(ppItem[idx]))
  2334. {
  2335. REPORT_ERROR(E_OUTOFMEMORY, m_hPage);
  2336. if (pIndex != NULL)
  2337. {
  2338. delete[] pIndex;
  2339. pIndex = 0;
  2340. }
  2341. delete[] ppItem;
  2342. return;
  2343. }
  2344. m_pList->RemoveListItem(pIndex[idx]);
  2345. for (int idx2 = idx; idx2 < nNumSelected; idx2++)
  2346. {
  2347. if (pIndex[idx2] > pIndex[idx])
  2348. {
  2349. pIndex[idx2]--;
  2350. }
  2351. }
  2352. SetDirty();
  2353. }
  2354. //
  2355. // Disable the Remove button, since nothing in the list box should have
  2356. // the selection at this point.
  2357. //
  2358. //Since Remove Button has focus now, set focus to add button
  2359. //before disabling
  2360. SetFocus(GetDlgItem(m_hPage,IDC_ADD_BTN));
  2361. PostMessage(GetDlgItem(m_hPage, IDC_ADD_BTN), BM_SETSTYLE, BS_DEFPUSHBUTTON, MAKELPARAM(TRUE, 0));
  2362. PostMessage(GetDlgItem(m_hPage, IDC_REMOVE_BTN), BM_SETSTYLE, BS_PUSHBUTTON, MAKELPARAM(TRUE, 0));
  2363. EnableWindow(GetDlgItem(m_hPage, IDC_REMOVE_BTN), FALSE);
  2364. if (pIndex != NULL)
  2365. {
  2366. delete[] pIndex;
  2367. pIndex = 0;
  2368. }
  2369. delete[] ppItem;
  2370. return;
  2371. }
  2372. //+----------------------------------------------------------------------------
  2373. //
  2374. // Method: CDsGrpMembersPage::GetRealDN
  2375. //
  2376. // Synopsis: If a member from an external domain that was added to the
  2377. // group during this instance of the page, we won't yet have the
  2378. // path to the FPO as the DN. So, search for the FPO using the
  2379. // object-SID.
  2380. //
  2381. //-----------------------------------------------------------------------------
  2382. HRESULT
  2383. CDsGrpMembersPage::GetRealDN(CMemberListItem * pItem)
  2384. {
  2385. return ::GetRealDN(this, pItem);
  2386. }
  2387. //+----------------------------------------------------------------------------
  2388. //
  2389. // Method: CDsGrpMembersPage::OnDestroy
  2390. //
  2391. // Synopsis: Exit cleanup
  2392. //
  2393. //-----------------------------------------------------------------------------
  2394. LRESULT
  2395. CDsGrpMembersPage::OnDestroy(void)
  2396. {
  2397. if (m_pList)
  2398. {
  2399. m_pList->ClearList();
  2400. }
  2401. CDsPropPageBase::OnDestroy();
  2402. // If an application processes this message, it should return zero.
  2403. return 0;
  2404. }
  2405. HRESULT HrVariantToStringArray(const CComVariant& refvar, PWSTR** pppszStringArray, DWORD* pdwCount)
  2406. {
  2407. HRESULT hr = S_OK;
  2408. long start, end, current;
  2409. *pdwCount = 0;
  2410. *pppszStringArray = NULL;
  2411. if (V_VT(&refvar) == VT_BSTR)
  2412. {
  2413. CComBSTR bstrVal = V_BSTR(&refvar);
  2414. *pppszStringArray = new PWSTR[1];
  2415. if (*pppszStringArray != NULL)
  2416. {
  2417. size_t length = wcslen(bstrVal);
  2418. PWSTR pszVal = new WCHAR[length + 1];
  2419. if (pszVal != NULL)
  2420. {
  2421. wcscpy(pszVal, bstrVal);
  2422. (*pppszStringArray)[0] = pszVal;
  2423. }
  2424. else
  2425. {
  2426. delete[] *pppszStringArray;
  2427. *pppszStringArray = NULL;
  2428. *pdwCount = 0;
  2429. return E_OUTOFMEMORY;
  2430. }
  2431. }
  2432. *pdwCount = 1;
  2433. return S_OK;
  2434. }
  2435. //
  2436. // Check the VARIANT to make sure we have
  2437. // an array of variants.
  2438. //
  2439. if ( V_VT(&refvar) != ( VT_ARRAY | VT_VARIANT ) )
  2440. {
  2441. dspAssert(FALSE);
  2442. return E_UNEXPECTED;
  2443. }
  2444. SAFEARRAY *saAttributes = V_ARRAY( &refvar );
  2445. //
  2446. // Figure out the dimensions of the array.
  2447. //
  2448. hr = SafeArrayGetLBound( saAttributes, 1, &start );
  2449. if( FAILED(hr) )
  2450. return hr;
  2451. hr = SafeArrayGetUBound( saAttributes, 1, &end );
  2452. if( FAILED(hr) )
  2453. return hr;
  2454. CComVariant SingleResult;
  2455. //
  2456. // Process the array elements.
  2457. //
  2458. *pppszStringArray = new PWSTR[(end - start) + 1];
  2459. if (*pppszStringArray != NULL)
  2460. {
  2461. for ( current = start; current <= end; current++)
  2462. {
  2463. hr = SafeArrayGetElement( saAttributes, &current, &SingleResult );
  2464. if( FAILED(hr) )
  2465. return hr;
  2466. if ( V_VT(&SingleResult) != VT_BSTR )
  2467. return E_UNEXPECTED;
  2468. CComBSTR bstrVal = V_BSTR(&SingleResult);
  2469. size_t length = wcslen(bstrVal);
  2470. PWSTR pszVal = new WCHAR[length + 1];
  2471. if (pszVal != NULL)
  2472. {
  2473. wcscpy(pszVal, bstrVal);
  2474. long lCount = static_cast<long>(*pdwCount);
  2475. if (lCount < (end - start) + 1)
  2476. {
  2477. (*pppszStringArray)[(*pdwCount)++] = pszVal;
  2478. }
  2479. }
  2480. else
  2481. {
  2482. return E_OUTOFMEMORY;
  2483. }
  2484. }
  2485. }
  2486. else
  2487. {
  2488. hr = E_OUTOFMEMORY;
  2489. *pdwCount = 0;
  2490. }
  2491. return hr;
  2492. }
  2493. //+----------------------------------------------------------------------------
  2494. //
  2495. // Method: CDsGrpMembersPage::LoadGroupExtraClasses
  2496. //
  2497. // Synopsis: Read the extra classes that need to be displayed from the
  2498. // DisplaySpecifiers
  2499. //
  2500. //-----------------------------------------------------------------------------
  2501. HRESULT CDsGrpMembersPage::LoadGroupExtraClasses(BOOL bSecurity)
  2502. {
  2503. HRESULT hr = S_OK;
  2504. dspAssert(m_pDsObj != NULL);
  2505. if (m_pDsObj == NULL)
  2506. {
  2507. return E_INVALIDARG;
  2508. }
  2509. static LPCWSTR lpszSettingsObjectClass = L"dsUISettings";
  2510. static LPCWSTR lpszSettingsObject = L"cn=DS-UI-Default-Settings";
  2511. static LPCWSTR lpszSecurityGroupProperty = L"msDS-Security-Group-Extra-Classes";
  2512. static LPCWSTR lpszNonSecurityGroupProperty = L"msDS-Non-Security-Group-Extra-Classes";
  2513. //
  2514. // Not AddRef'd so don't use a smart pointer
  2515. //
  2516. IDsDisplaySpecifier* pDispSpec;
  2517. hr = GetIDispSpec(&pDispSpec);
  2518. CHECK_HRESULT_REPORT(hr, GetHWnd(), return hr);
  2519. //
  2520. // get the display specifiers locale container (e.g. 409)
  2521. //
  2522. CComPtr<IADsContainer> spLocaleContainer;
  2523. hr = pDispSpec->GetDisplaySpecifier(NULL, IID_IADsContainer, (void**)&spLocaleContainer);
  2524. if (FAILED(hr))
  2525. {
  2526. return hr;
  2527. }
  2528. //
  2529. // bind to the settings object
  2530. //
  2531. CComPtr<IDispatch> spIDispatchObject;
  2532. hr = spLocaleContainer->GetObject(CComBSTR(lpszSettingsObjectClass),
  2533. CComBSTR(lpszSettingsObject),
  2534. &spIDispatchObject);
  2535. if (FAILED(hr))
  2536. {
  2537. return hr;
  2538. }
  2539. CComPtr<IADs> spSettingsObject;
  2540. hr = spIDispatchObject->QueryInterface(IID_IADs, (void**)&spSettingsObject);
  2541. if (FAILED(hr))
  2542. {
  2543. return hr;
  2544. }
  2545. if (bSecurity)
  2546. {
  2547. //
  2548. // get the security group extra classes as a CStringList
  2549. //
  2550. CComVariant var;
  2551. hr = spSettingsObject->Get(CComBSTR(lpszSecurityGroupProperty), &var);
  2552. if (SUCCEEDED(hr))
  2553. {
  2554. hr = HrVariantToStringArray(var, &m_pszSecurityGroupExtraClasses, &m_dwSecurityGroupExtraClassesCount);
  2555. }
  2556. }
  2557. else
  2558. {
  2559. //
  2560. // get the non-security group extra classes as a CStringList
  2561. //
  2562. CComVariant var;
  2563. hr = spSettingsObject->Get(CComBSTR(lpszNonSecurityGroupProperty), &var);
  2564. if (SUCCEEDED(hr))
  2565. {
  2566. hr = HrVariantToStringArray(var, &m_pszNonSecurityGroupExtraClasses, &m_dwNonSecurityGroupExtraClassesCount);
  2567. }
  2568. }
  2569. return hr;
  2570. }
  2571. //+----------------------------------------------------------------------------
  2572. //
  2573. // Function: GetDomainMode
  2574. //
  2575. // Synopsis: Is the domain to which the indicated object belongs in mixed
  2576. // or native mode?
  2577. //
  2578. //-----------------------------------------------------------------------------
  2579. HRESULT
  2580. GetDomainMode(CDsPropPageBase * pObj, PBOOL pfMixed)
  2581. {
  2582. HRESULT hr;
  2583. CComBSTR cbstrDomain;
  2584. hr = GetDomainScope(pObj, &cbstrDomain);
  2585. CHECK_HRESULT_REPORT(hr, pObj->GetHWnd(), return hr);
  2586. return GetDomainMode(cbstrDomain, pObj->GetHWnd(), pfMixed);
  2587. }
  2588. HRESULT
  2589. GetDomainMode(PWSTR pwzDomain, HWND hWnd, PBOOL pfMixed)
  2590. {
  2591. HRESULT hr;
  2592. WCHAR wzMixedAttr[] = L"nTMixedDomain";
  2593. PWSTR rgpwzAttrNames[] = {wzMixedAttr};
  2594. CComPtr <IDirectoryObject> pDomObj;
  2595. PADS_ATTR_INFO pAttrs = NULL;
  2596. DWORD cAttrs = 0;
  2597. dspDebugOut((DEB_ITRACE, "GetDomainMode targetted to %ws\n", pwzDomain));
  2598. hr = DSAdminOpenObject(pwzDomain,
  2599. IID_IDirectoryObject,
  2600. (void **)&pDomObj);
  2601. CHECK_HRESULT_REPORT(hr, hWnd, return hr);
  2602. hr = pDomObj->GetObjectAttributes(rgpwzAttrNames, 1, &pAttrs, &cAttrs);
  2603. CHECK_HRESULT_REPORT(hr, hWnd, return hr);
  2604. if (cAttrs && pAttrs && (_wcsicmp(pAttrs->pszAttrName, wzMixedAttr) == 0))
  2605. {
  2606. *pfMixed = (BOOL)pAttrs->pADsValues->Integer;
  2607. FreeADsMem(pAttrs);
  2608. }
  2609. else
  2610. {
  2611. *pfMixed = 0;
  2612. }
  2613. return hr;
  2614. }
  2615. //+----------------------------------------------------------------------------
  2616. //
  2617. // Function: GetGroupType
  2618. //
  2619. //-----------------------------------------------------------------------------
  2620. HRESULT
  2621. GetGroupType(CDsPropPageBase * pObj, DWORD * pdwType)
  2622. {
  2623. HRESULT hr;
  2624. PWSTR rgpwzAttrNames[] = {g_wzGroupType};
  2625. PADS_ATTR_INFO pAttrs = NULL;
  2626. DWORD cAttrs = 0;
  2627. hr = pObj->m_pDsObj->GetObjectAttributes(rgpwzAttrNames, 1, &pAttrs, &cAttrs);
  2628. CHECK_HRESULT_REPORT(hr, pObj->GetHWnd(), return hr);
  2629. if (cAttrs && pAttrs && (_wcsicmp(pAttrs->pszAttrName, g_wzGroupType) == 0))
  2630. {
  2631. *pdwType = pAttrs->pADsValues->Integer;
  2632. FreeADsMem(pAttrs);
  2633. }
  2634. else
  2635. {
  2636. *pdwType = 0;
  2637. }
  2638. return hr;
  2639. }
  2640. //+----------------------------------------------------------------------------
  2641. //
  2642. // Function: FillGroupList
  2643. //
  2644. // Synopsis: Fill the list box with the names of the group members.
  2645. //
  2646. //-----------------------------------------------------------------------------
  2647. HRESULT
  2648. FillGroupList(CDsPropPageBase * pPage, CDsMembershipList * pList,
  2649. DWORD dwGroupRID)
  2650. {
  2651. TRACE_FUNCTION(FillGroupList);
  2652. HRESULT hr = S_OK;
  2653. Smart_PADS_ATTR_INFO spAttrs;
  2654. DWORD i, cAttrs = 0;
  2655. WCHAR wzMemberAttr[MAX_PATH] = L"member;range=0-*";
  2656. const WCHAR wcSep = L'-';
  2657. const WCHAR wcEnd = L'*';
  2658. const WCHAR wzFormat[] = L"member;range=%ld-*";
  2659. PWSTR pwzAttrName[] = {wzMemberAttr}, pwzPath;
  2660. BOOL fMoreRemain = FALSE, fNameNotMapped = FALSE;
  2661. CComPtr <IDirectorySearch> spDsSearch;
  2662. //
  2663. // Read the membership list from the object using range (incremental)
  2664. // retrieval.
  2665. //
  2666. do
  2667. {
  2668. hr = pPage->m_pDsObj->GetObjectAttributes(pwzAttrName, 1, &spAttrs, &cAttrs);
  2669. if (!CHECK_ADS_HR_IGNORE_UNFOUND_ATTR(&hr, pPage->GetHWnd()))
  2670. {
  2671. return hr;
  2672. }
  2673. if (cAttrs > 0 && spAttrs != NULL)
  2674. {
  2675. for (i = 0; i < spAttrs->dwNumValues; i++)
  2676. {
  2677. hr = pList->InsertIntoNewList(spAttrs->pADsValues[i].CaseIgnoreString);
  2678. if (DS_NAME_ERROR_NO_MAPPING == HRESULT_CODE(hr))
  2679. {
  2680. fNameNotMapped = TRUE;
  2681. hr = S_OK;
  2682. }
  2683. else
  2684. {
  2685. CHECK_HRESULT(hr, return hr);
  2686. }
  2687. }
  2688. //
  2689. // Check to see if there is more data. If the last char of the
  2690. // attribute name string is an asterisk, then we have everything.
  2691. //
  2692. size_t cchEnd = wcslen(spAttrs->pszAttrName);
  2693. fMoreRemain = spAttrs->pszAttrName[cchEnd - 1] != wcEnd;
  2694. if (fMoreRemain)
  2695. {
  2696. PWSTR pwz = wcsrchr(spAttrs->pszAttrName, wcSep);
  2697. if (!pwz)
  2698. {
  2699. dspAssert(FALSE && spAttrs->pszAttrName);
  2700. fMoreRemain = FALSE;
  2701. }
  2702. else
  2703. {
  2704. pwz++; // move past the hyphen to the range end value.
  2705. dspAssert(*pwz);
  2706. long lEnd = _wtol(pwz);
  2707. lEnd++; // start with the next value.
  2708. wsprintfW(wzMemberAttr, wzFormat, lEnd);
  2709. dspDebugOut((DEB_ITRACE,
  2710. "Range returned is %ws, now asking for %ws\n",
  2711. spAttrs->pszAttrName, wzMemberAttr));
  2712. }
  2713. }
  2714. }
  2715. } while (fMoreRemain);
  2716. //
  2717. // Query for all users/computers who have this as their primary group.
  2718. //
  2719. // Filter out interdomain-trust accounts (0x30000002).
  2720. // This value is defined in ds\src\dsamain\include\mappings.h
  2721. //
  2722. WCHAR wzSearchFormat[] = L"(&(primaryGroupID=%u)(sAMAccountType<=805306369))";
  2723. CStrW strSearchFilter;
  2724. strSearchFilter.Format(wzSearchFormat, dwGroupRID);
  2725. BSTR bstrDomain;
  2726. hr = GetDomainScope(pPage, &bstrDomain);
  2727. CHECK_HRESULT(hr, return hr);
  2728. pwzAttrName[0] = g_wzADsPath;
  2729. CDSSearch Search;
  2730. hr = Search.Init((LPCWSTR)bstrDomain);
  2731. SysFreeString(bstrDomain);
  2732. CHECK_HRESULT_REPORT(hr, pPage->GetHWnd(), return hr);
  2733. Search.SetFilterString(const_cast<LPWSTR>((LPCWSTR)strSearchFilter));
  2734. Search.SetAttributeList(pwzAttrName, 1);
  2735. Search.SetSearchScope(ADS_SCOPE_SUBTREE);
  2736. hr = Search.DoQuery();
  2737. while (SUCCEEDED(hr))
  2738. {
  2739. hr = Search.GetNextRow();
  2740. if (hr == S_ADS_NOMORE_ROWS)
  2741. {
  2742. hr = S_OK;
  2743. break;
  2744. }
  2745. CHECK_HRESULT_REPORT(hr, pPage->GetHWnd(), return hr);
  2746. ADS_SEARCH_COLUMN Column = {0};
  2747. hr = Search.GetColumn(g_wzADsPath, &Column);
  2748. CHECK_HRESULT_REPORT(hr, pPage->GetHWnd(), return hr);
  2749. hr = pPage->SkipPrefix(Column.pADsValues->CaseIgnoreString, &pwzPath);
  2750. Search.FreeColumn(&Column);
  2751. CHECK_HRESULT_REPORT(hr, pPage->GetHWnd(), return hr);
  2752. hr = pList->InsertIntoNewList(pwzPath, TRUE);
  2753. delete [] pwzPath;
  2754. CHECK_HRESULT(hr, return hr);
  2755. }
  2756. if (pList->GetCount() < 1)
  2757. {
  2758. EnableWindow(GetDlgItem(pPage->GetHWnd(), IDC_REMOVE_BTN), FALSE);
  2759. }
  2760. else if (((CDsGrpMembersPage *)pPage)->m_fShowIcons)
  2761. {
  2762. // Get class and userAccountControl for the group members and use
  2763. // those values to select icons.
  2764. //
  2765. pList->SetMemberIcons(pPage);
  2766. }
  2767. if (fNameNotMapped)
  2768. {
  2769. MsgBox(IDS_GRP_NO_NAME_MAPPING, pPage->GetHWnd());
  2770. }
  2771. return hr;
  2772. }
  2773. //+----------------------------------------------------------------------------
  2774. //
  2775. // Function: GetRealDN
  2776. //
  2777. // Synopsis: If a member from an external domain that was added to the
  2778. // group during this instance of the page, we won't yet have the
  2779. // path to the FPO as the DN. So, search for the FPO using the
  2780. // object-SID.
  2781. //
  2782. //-----------------------------------------------------------------------------
  2783. HRESULT
  2784. GetRealDN(CDsPropPageBase * pPage, CMemberListItem * pItem)
  2785. {
  2786. HRESULT hr = S_OK;
  2787. if (!pItem->GetSid())
  2788. {
  2789. return E_FAIL;
  2790. }
  2791. CComBSTR cbstrDomain;
  2792. hr = GetDomainScope(pPage, &cbstrDomain);
  2793. CHECK_HRESULT(hr, return hr);
  2794. CStrW strDN;
  2795. hr = FindFPO(pItem->GetSid(), cbstrDomain, strDN);
  2796. //Don't show this eror here
  2797. if(FAILED(hr))
  2798. return hr;
  2799. PWSTR pwzOldDN = pItem->m_pwzDN;
  2800. if (!AllocWStr(const_cast<PWSTR>((LPCWSTR)strDN), &pItem->m_pwzDN))
  2801. {
  2802. REPORT_ERROR(E_OUTOFMEMORY, pPage->GetHWnd());
  2803. return E_OUTOFMEMORY;
  2804. }
  2805. DO_DEL(pwzOldDN);
  2806. pItem->m_fIsExternal = FALSE;
  2807. return S_OK;
  2808. }
  2809. //+----------------------------------------------------------------------------
  2810. //
  2811. // Member: CDsGrpShlGenPage::CDsGrpShlGenPage
  2812. //
  2813. //-----------------------------------------------------------------------------
  2814. CDsGrpShlGenPage::CDsGrpShlGenPage(PDSPAGE pDsPage, LPDATAOBJECT pDataObj,
  2815. HWND hNotifyObj, DWORD dwFlags) :
  2816. m_pCIcon(NULL),
  2817. m_fDescrWritable(FALSE),
  2818. m_fDescrDirty(FALSE),
  2819. CDsGrpMembersPage(pDsPage, pDataObj, hNotifyObj, dwFlags)
  2820. {
  2821. TRACE(CDsGrpShlGenPage,CDsGrpShlGenPage);
  2822. #ifdef _DEBUG
  2823. strcpy(szClass, "CDsGrpShlGenPage");
  2824. #endif
  2825. }
  2826. //+----------------------------------------------------------------------------
  2827. //
  2828. // Member: CDsGrpShlGenPage::~CDsGrpShlGenPage
  2829. //
  2830. //-----------------------------------------------------------------------------
  2831. CDsGrpShlGenPage::~CDsGrpShlGenPage()
  2832. {
  2833. TRACE(CDsGrpShlGenPage,~CDsGrpShlGenPage);
  2834. }
  2835. //+----------------------------------------------------------------------------
  2836. //
  2837. // Function: CreateGrpShlGenPage
  2838. //
  2839. // Synopsis: Creates an instance of the group shell general page window.
  2840. //
  2841. //-----------------------------------------------------------------------------
  2842. HRESULT
  2843. CreateGrpShlGenPage(PDSPAGE pDsPage, LPDATAOBJECT pDataObj,
  2844. PWSTR pwzADsPath, PWSTR pwzClass, HWND hNotifyObj,
  2845. DWORD dwFlags, const CDSSmartBasePathsInfo& basePathsInfo,
  2846. HPROPSHEETPAGE * phPage)
  2847. {
  2848. TRACE_FUNCTION(CreateGroupMembersPage);
  2849. CDsGrpShlGenPage * pPageObj = new CDsGrpShlGenPage(pDsPage, pDataObj,
  2850. hNotifyObj, dwFlags);
  2851. CHECK_NULL(pPageObj, return E_OUTOFMEMORY);
  2852. pPageObj->Init(pwzADsPath, pwzClass, basePathsInfo);
  2853. return pPageObj->CreatePage(phPage);
  2854. }
  2855. //+----------------------------------------------------------------------------
  2856. //
  2857. // Method: CDsGrpShlGenPage::OnInitDialog
  2858. //
  2859. // Synopsis: Set the initial control values from the corresponding DS
  2860. // attributes.
  2861. //
  2862. //-----------------------------------------------------------------------------
  2863. HRESULT CDsGrpShlGenPage::OnInitDialog(LPARAM lParam)
  2864. {
  2865. TRACE(CDsGrpShlGenPage,OnInitDialog);
  2866. HRESULT hr;
  2867. Smart_PADS_ATTR_INFO spAttrs;
  2868. DWORD cAttrs = 0;
  2869. CWaitCursor Wait;
  2870. //
  2871. // Get the icon from the DS and put it on the page.
  2872. //
  2873. ATTR_DATA ad = {0, 0};
  2874. hr = GeneralPageIcon(this, &GenIcon, NULL, 0, &ad, fInit);
  2875. CHECK_HRESULT_REPORT(hr, m_hPage, return S_OK);
  2876. m_pCIcon = (CDsIconCtrl *)ad.pVoid;
  2877. //
  2878. // Get the name.
  2879. //
  2880. LPTSTR ptz;
  2881. if (!UnicodeToTchar(m_pwszRDName, &ptz))
  2882. {
  2883. REPORT_ERROR(E_OUTOFMEMORY, m_hPage);
  2884. return S_OK;
  2885. }
  2886. SetDlgItemText(m_hPage, IDC_CN, ptz);
  2887. delete [] ptz;
  2888. m_fDescrWritable = CheckIfWritable(g_wzDescription);
  2889. //
  2890. // Get the description
  2891. //
  2892. PWSTR rgpwzAttrNames[] = {g_wzDescription};
  2893. hr = m_pDsObj->GetObjectAttributes(rgpwzAttrNames, 1, &spAttrs, &cAttrs);
  2894. if (!CHECK_ADS_HR_IGNORE_UNFOUND_ATTR(&hr, m_hPage))
  2895. {
  2896. return S_OK;
  2897. }
  2898. if (1 == cAttrs)
  2899. {
  2900. dspAssert(spAttrs);
  2901. if (!UnicodeToTchar(spAttrs->pADsValues->CaseIgnoreString, &ptz))
  2902. {
  2903. REPORT_ERROR(E_OUTOFMEMORY, m_hPage);
  2904. return S_OK;
  2905. }
  2906. SetDlgItemText(m_hPage, IDC_DESCRIPTION_EDIT, ptz);
  2907. delete [] ptz;
  2908. }
  2909. if (m_fDescrWritable)
  2910. {
  2911. SendDlgItemMessage(m_hPage, IDC_DESCRIPTION_EDIT, EM_LIMITTEXT, DSPROP_DESCRIPTION_RANGE_UPPER, 0);
  2912. }
  2913. else
  2914. {
  2915. SendDlgItemMessage(m_hPage, IDC_DESCRIPTION_EDIT, EM_SETREADONLY, (WPARAM)TRUE, 0);
  2916. }
  2917. HRESULT hRes = CDsGrpMembersPage::OnInitDialog(lParam, FALSE);
  2918. #if !defined(DSADMIN)
  2919. // in the Win95 shell, we do not want to have the buttons
  2920. // because we do not have object picker
  2921. MakeNotWritable();
  2922. EnableWindow(GetDlgItem(m_hPage, IDC_ADD_BTN), FALSE);
  2923. #endif
  2924. EnableWindow(GetDlgItem(m_hPage, IDC_REMOVE_BTN), FALSE);
  2925. return hRes;
  2926. }
  2927. //+----------------------------------------------------------------------------
  2928. //
  2929. // Method: CDsGrpShlGenPage::OnCommand
  2930. //
  2931. // Synopsis: Handle control notifications.
  2932. //
  2933. //-----------------------------------------------------------------------------
  2934. LRESULT
  2935. CDsGrpShlGenPage::OnCommand(int id, HWND hwndCtl, UINT codeNotify)
  2936. {
  2937. if (m_fInInit)
  2938. {
  2939. return 0;
  2940. }
  2941. if (EN_CHANGE == codeNotify && IDC_DESCRIPTION_EDIT == id)
  2942. {
  2943. m_fDescrDirty = TRUE;
  2944. }
  2945. TRACE(CDsGrpShlGenPage,OnCommand);
  2946. return CDsGrpMembersPage::OnCommand(id, hwndCtl, codeNotify);
  2947. }
  2948. //+----------------------------------------------------------------------------
  2949. //
  2950. // Method: CDsGrpShlGenPage::OnApply
  2951. //
  2952. // Synopsis: Write changes
  2953. //
  2954. //-----------------------------------------------------------------------------
  2955. LRESULT CDsGrpShlGenPage::OnApply(void)
  2956. {
  2957. TRACE(CDsGrpShlGenPage,OnApply);
  2958. ADS_ATTR_INFO AttrInfoDesc = {g_wzDescription, ADS_ATTR_UPDATE,
  2959. ADSTYPE_CASE_IGNORE_STRING, NULL, 0};
  2960. ADSVALUE ADsValueDesc = {ADSTYPE_CASE_IGNORE_STRING, NULL};
  2961. AttrInfoDesc.pADsValues = &ADsValueDesc;
  2962. AttrInfoDesc.dwNumValues = 1;
  2963. LPTSTR ptsz;
  2964. if (m_fDescrDirty)
  2965. {
  2966. dspAssert(m_fDescrWritable);
  2967. ptsz = new TCHAR[DSPROP_DESCRIPTION_RANGE_UPPER + 1];
  2968. CHECK_NULL_REPORT(ptsz, m_hPage, return -1);
  2969. if (GetDlgItemText(m_hPage, IDC_DESCRIPTION_EDIT, ptsz, DSPROP_DESCRIPTION_RANGE_UPPER + 1) == 0)
  2970. {
  2971. // An empty control means remove the attribute value from the
  2972. // object.
  2973. //
  2974. AttrInfoDesc.dwNumValues = 0;
  2975. AttrInfoDesc.pADsValues = NULL;
  2976. AttrInfoDesc.dwControlCode = ADS_ATTR_CLEAR;
  2977. }
  2978. else
  2979. {
  2980. if (!TcharToUnicode(ptsz, &ADsValueDesc.CaseIgnoreString))
  2981. {
  2982. REPORT_ERROR(E_OUTOFMEMORY, m_hPage);
  2983. delete [] ptsz;
  2984. return -1;
  2985. }
  2986. }
  2987. delete [] ptsz;
  2988. DWORD cModified;
  2989. HRESULT hr = m_pDsObj->SetObjectAttributes(&AttrInfoDesc, 1, &cModified);
  2990. if (!CHECK_ADS_HR(&hr, m_hPage))
  2991. {
  2992. goto Cleanup;
  2993. }
  2994. m_fDescrDirty = FALSE;
  2995. }
  2996. Cleanup:
  2997. DO_DEL(ADsValueDesc.CaseExactString);
  2998. return CDsGrpMembersPage::OnApply();
  2999. }
  3000. //+----------------------------------------------------------------------------
  3001. //
  3002. // Method: CDsGrpShlGenPage::OnDestroy
  3003. //
  3004. // Synopsis: Exit cleanup
  3005. //
  3006. //-----------------------------------------------------------------------------
  3007. LRESULT
  3008. CDsGrpShlGenPage::OnDestroy(void)
  3009. {
  3010. ATTR_DATA ad = {0, (LPARAM)m_pCIcon};
  3011. GeneralPageIcon(this, &GenIcon, NULL, 0, &ad, fOnDestroy);
  3012. CDsGrpMembersPage::OnDestroy();
  3013. // If an application processes this message, it should return zero.
  3014. return 0;
  3015. }
  3016. //+----------------------------------------------------------------------------
  3017. //
  3018. // Function: CheckGroupUpdate
  3019. //
  3020. // Synopsis: Checks the result code to see if a group-specific error has
  3021. // occured.
  3022. //
  3023. //-----------------------------------------------------------------------------
  3024. BOOL
  3025. CheckGroupUpdate(HRESULT hr, HWND hPage, BOOL fAdd, PWSTR pwzDN)
  3026. {
  3027. if (SUCCEEDED(hr))
  3028. {
  3029. return TRUE;
  3030. }
  3031. if (hPage == NULL)
  3032. {
  3033. hPage = GetDesktopWindow();
  3034. }
  3035. DWORD dwErr = 0;
  3036. WCHAR wszErrBuf[MAX_PATH+1];
  3037. WCHAR wszNameBuf[MAX_PATH+1];
  3038. ADsGetLastError(&dwErr, wszErrBuf, MAX_PATH, wszNameBuf, MAX_PATH);
  3039. //
  3040. // ERROR_DS_CONSTRAINT_VIOLATION is the error returned for
  3041. // duplicate name.
  3042. //
  3043. if ((LDAP_RETCODE)dwErr == LDAP_CONSTRAINT_VIOLATION ||
  3044. hr == HRESULT_FROM_WIN32(ERROR_DS_CONSTRAINT_VIOLATION))
  3045. {
  3046. PTSTR ptzTitle, ptzMsg;
  3047. if (!LoadStringToTchar(IDS_MSG_TITLE, &ptzTitle))
  3048. {
  3049. goto FatalError;
  3050. }
  3051. if (!LoadStringToTchar((fAdd) ? IDS_ERRMSG_GROUP_CONSTRAINT :
  3052. IDS_ERRMSG_GROUP_DELETE, &ptzMsg))
  3053. {
  3054. delete [] ptzTitle;
  3055. goto FatalError;
  3056. }
  3057. MessageBox(hPage, ptzMsg, ptzTitle, MB_OK | MB_ICONEXCLAMATION);
  3058. delete [] ptzTitle;
  3059. delete [] ptzMsg;
  3060. }
  3061. else if (HRESULT_CODE(hr) == ERROR_DS_NO_SUCH_OBJECT && fAdd)
  3062. {
  3063. // Put a useful message up
  3064. PTSTR ptzTitle = 0, ptzMsg = 0;
  3065. if (!LoadStringToTchar(IDS_MSG_USER_NOT_PRESENT, &ptzMsg))
  3066. {
  3067. goto FatalError;
  3068. }
  3069. if (!LoadStringToTchar(IDS_MSG_TITLE, &ptzTitle))
  3070. {
  3071. goto FatalError;
  3072. }
  3073. MessageBox(hPage, ptzMsg, ptzTitle, MB_OK | MB_ICONEXCLAMATION);
  3074. delete[] ptzTitle;
  3075. delete[] ptzMsg;
  3076. }
  3077. else if (HRESULT_CODE(dwErr) == ERROR_DS_NO_ATTRIBUTE_OR_VALUE && !fAdd)
  3078. {
  3079. // No message needed
  3080. return FALSE;
  3081. }
  3082. else if (HRESULT_CODE(dwErr) == ERROR_MEMBER_NOT_IN_ALIAS && !fAdd)
  3083. {
  3084. // Put a useful message up
  3085. bool bShowGenericMessage = true;
  3086. if (pwzDN)
  3087. {
  3088. //
  3089. // Crack the DN into the name
  3090. //
  3091. CComPtr<IADsPathname> spPathcracker;
  3092. hr = CoCreateInstance(CLSID_Pathname,
  3093. NULL,
  3094. CLSCTX_INPROC_SERVER,
  3095. IID_IADsPathname,
  3096. (PVOID *)&spPathcracker);
  3097. if (SUCCEEDED(hr))
  3098. {
  3099. hr = spPathcracker->Set(CComBSTR(pwzDN), ADS_SETTYPE_DN);
  3100. if (SUCCEEDED(hr))
  3101. {
  3102. hr = spPathcracker->SetDisplayType(ADS_DISPLAY_VALUE_ONLY);
  3103. if (SUCCEEDED(hr))
  3104. {
  3105. CComBSTR sbstrName;
  3106. hr = spPathcracker->Retrieve(ADS_FORMAT_LEAF, &sbstrName);
  3107. if (SUCCEEDED(hr))
  3108. {
  3109. ErrMsgParam(IDS_MSG_MEMBER_ALREADY_GONE, (LPARAM)(PWSTR)sbstrName, hPage);
  3110. bShowGenericMessage = false;
  3111. }
  3112. }
  3113. }
  3114. }
  3115. }
  3116. if (bShowGenericMessage)
  3117. {
  3118. PTSTR ptzTitle = 0, ptzMsg = 0;
  3119. if (!LoadStringToTchar(IDS_MSG_MEMBER_ALREADY_GONE2, &ptzMsg))
  3120. {
  3121. goto FatalError;
  3122. }
  3123. if (!LoadStringToTchar(IDS_MSG_TITLE, &ptzTitle))
  3124. {
  3125. goto FatalError;
  3126. }
  3127. MessageBox(hPage, ptzMsg, ptzTitle, MB_OK | MB_ICONEXCLAMATION);
  3128. delete[] ptzTitle;
  3129. delete[] ptzMsg;
  3130. }
  3131. }
  3132. else
  3133. {
  3134. if (dwErr)
  3135. {
  3136. dspDebugOut((DEB_ERROR,
  3137. "Extended Error 0x%x: %ws %ws.\n", dwErr,
  3138. wszErrBuf, wszNameBuf));
  3139. ReportError(dwErr, IDS_ADS_ERROR_FORMAT, hPage);
  3140. }
  3141. else
  3142. {
  3143. dspDebugOut((DEB_ERROR, "Error %08lx\n", hr));
  3144. ReportError(hr, IDS_ADS_ERROR_FORMAT, hPage);
  3145. }
  3146. }
  3147. return FALSE;
  3148. FatalError:
  3149. MessageBoxA(hPage, "A Fatal Error has occured!", "Active Directory Service",
  3150. MB_OK | MB_ICONEXCLAMATION);
  3151. return FALSE;
  3152. }
  3153. //+----------------------------------------------------------------------------
  3154. //
  3155. // Function: FindFPO
  3156. //
  3157. // Synopsis: Given a SID, look for a corresponding FPO.
  3158. //
  3159. //-----------------------------------------------------------------------------
  3160. HRESULT
  3161. FindFPO(PSID pSid, PWSTR pwzDomain, CStrW & strFPODN)
  3162. {
  3163. HRESULT hr;
  3164. CDSSearch Srch;
  3165. hr = Srch.Init(pwzDomain);
  3166. CHECK_HRESULT(hr, return hr);
  3167. PWSTR rgpwzAttrNames[] = {g_wzDN};
  3168. hr = Srch.SetAttributeList(rgpwzAttrNames, 1);
  3169. CHECK_HRESULT(hr, return hr);
  3170. Srch.SetSearchScope(ADS_SCOPE_SUBTREE);
  3171. WCHAR wzSearchFormat[] = L"(&(objectCategory=foreignSecurityPrincipal)(objectSid=%s))";
  3172. PWSTR pwzSID;
  3173. CStrW strSearchFilter;
  3174. hr = ADsEncodeBinaryData((PBYTE)pSid,
  3175. GetLengthSid(pSid),
  3176. &pwzSID);
  3177. CHECK_HRESULT(hr, return hr);
  3178. strSearchFilter.Format(wzSearchFormat, pwzSID);
  3179. FreeADsMem(pwzSID);
  3180. Srch.SetFilterString(const_cast<LPWSTR>((LPCWSTR)strSearchFilter));
  3181. hr = Srch.DoQuery();
  3182. CHECK_HRESULT(hr, return hr);
  3183. hr = Srch.GetNextRow();
  3184. if (hr == S_ADS_NOMORE_ROWS)
  3185. {
  3186. // No object has a matching SID, the FPO must have been deleted.
  3187. //
  3188. return HRESULT_FROM_WIN32(ERROR_DS_OBJ_NOT_FOUND);
  3189. }
  3190. CHECK_HRESULT(hr, return hr);
  3191. ADS_SEARCH_COLUMN Column;
  3192. hr = Srch.GetColumn(g_wzDN, &Column);
  3193. CHECK_HRESULT(hr, return hr);
  3194. strFPODN = Column.pADsValues->CaseIgnoreString;
  3195. if (strFPODN.IsEmpty())
  3196. {
  3197. Srch.FreeColumn(&Column);
  3198. return E_OUTOFMEMORY;
  3199. }
  3200. Srch.FreeColumn(&Column);
  3201. return S_OK;
  3202. }
  3203. //+----------------------------------------------------------------------------
  3204. //
  3205. // Class: CMemberDomainMode
  3206. //
  3207. // Purpose: Maintains a list of all domains in the enterprise from which
  3208. // members have been added along with those domains' mode. Keeps
  3209. // a second list of members who have been added from mixed-mode
  3210. // domains.
  3211. //
  3212. //-----------------------------------------------------------------------------
  3213. void
  3214. CMemberDomainMode::Init(CDsPropPageBase * pPage)
  3215. {
  3216. m_pPage = pPage;
  3217. m_MemberList.Clear();
  3218. }
  3219. HRESULT
  3220. CMemberDomainMode::CheckMember(PWSTR pwzMemberDN)
  3221. {
  3222. HRESULT hr;
  3223. CComBSTR cbstrDomain;
  3224. BOOL fMixed = FALSE;
  3225. hr = GetObjectsDomain(m_pPage, pwzMemberDN, &cbstrDomain);
  3226. if (SUCCEEDED(hr) && cbstrDomain)
  3227. {
  3228. if (!m_DomainList.Find(cbstrDomain, &fMixed))
  3229. {
  3230. // The member's domain is not already in the list. Read the domain
  3231. // mode and then add it.
  3232. //
  3233. hr = GetDomainMode(cbstrDomain, m_pPage->GetHWnd(), &fMixed);
  3234. CHECK_HRESULT(hr, return hr);
  3235. hr = m_DomainList.Insert(cbstrDomain, fMixed);
  3236. CHECK_HRESULT_REPORT(hr, m_pPage->GetHWnd(), return hr);
  3237. }
  3238. }
  3239. if (fMixed)
  3240. {
  3241. PWSTR pwzCanEx;
  3242. PTSTR ptzCanEx;
  3243. CStr strName;
  3244. hr = CrackName(pwzMemberDN, &pwzCanEx, GET_OBJ_CAN_NAME_EX, m_pPage->GetHWnd());
  3245. CHECK_HRESULT(hr, return hr);
  3246. if (!UnicodeToTchar(pwzCanEx, &ptzCanEx))
  3247. {
  3248. LocalFreeStringW(&pwzCanEx);
  3249. REPORT_ERROR(E_OUTOFMEMORY, m_pPage->GetHWnd());
  3250. return E_OUTOFMEMORY;
  3251. }
  3252. LocalFreeStringW(&pwzCanEx);
  3253. CStr cstrFolder;
  3254. GetNameParts(ptzCanEx, cstrFolder, strName);
  3255. DO_DEL(ptzCanEx);
  3256. hr = m_MemberList.Insert(strName);
  3257. CHECK_HRESULT_REPORT(hr, m_pPage->GetHWnd(), return hr);
  3258. }
  3259. return S_OK;
  3260. }
  3261. HRESULT
  3262. CMemberDomainMode::ListExternalMembers(CStr & strList)
  3263. {
  3264. m_MemberList.GetList(strList);
  3265. return S_OK;
  3266. }
  3267. //+----------------------------------------------------------------------------
  3268. //
  3269. // CMemberDomainMode helper classes
  3270. //
  3271. //-----------------------------------------------------------------------------
  3272. HRESULT
  3273. CMMMemberList::Insert(LPCTSTR ptzName)
  3274. {
  3275. CMMMemberListItem * pItem = new CMMMemberListItem;
  3276. if (!pItem)
  3277. {
  3278. return E_OUTOFMEMORY;
  3279. }
  3280. pItem->m_strName = ptzName;
  3281. if (m_pListHead == NULL)
  3282. {
  3283. m_pListHead = pItem;
  3284. }
  3285. else
  3286. {
  3287. pItem->LinkAfter(m_pListHead);
  3288. }
  3289. return S_OK;
  3290. }
  3291. #define MAX_MMMLISTING 25
  3292. void
  3293. CMMMemberList::GetList(CStr & strList)
  3294. {
  3295. int nCount = 0;
  3296. strList.Empty();
  3297. CMMMemberListItem * pItem = m_pListHead;
  3298. while (pItem)
  3299. {
  3300. strList += pItem->m_strName;
  3301. nCount++;
  3302. pItem = pItem->Next();
  3303. if (pItem)
  3304. {
  3305. if (nCount > MAX_MMMLISTING)
  3306. {
  3307. strList += TEXT("...");
  3308. return;
  3309. }
  3310. else
  3311. {
  3312. strList += TEXT(", ");
  3313. }
  3314. }
  3315. }
  3316. }
  3317. void
  3318. CMMMemberList::Clear(void)
  3319. {
  3320. CMMMemberListItem * pItem = m_pListHead, * pNext;
  3321. while (pItem)
  3322. {
  3323. pNext = pItem->Next();
  3324. delete pItem;
  3325. pItem = pNext;
  3326. }
  3327. m_pListHead = NULL;
  3328. }
  3329. CDomainModeList::~CDomainModeList(void)
  3330. {
  3331. CDomainModeListItem * pItem = m_pListHead, * pNext;
  3332. while (pItem)
  3333. {
  3334. pNext = pItem->Next();
  3335. delete pItem;
  3336. pItem = pNext;
  3337. }
  3338. }
  3339. HRESULT
  3340. CDomainModeList::Insert(PWSTR pwzDomain, BOOL fMixed)
  3341. {
  3342. CDomainModeListItem * pItem = new CDomainModeListItem;
  3343. if (!pItem)
  3344. {
  3345. return E_OUTOFMEMORY;
  3346. }
  3347. pItem->m_strName = pwzDomain;
  3348. pItem->m_fMixed = fMixed;
  3349. if (m_pListHead == NULL)
  3350. {
  3351. m_pListHead = pItem;
  3352. }
  3353. else
  3354. {
  3355. pItem->LinkAfter(m_pListHead);
  3356. }
  3357. return S_OK;
  3358. }
  3359. BOOL
  3360. CDomainModeList::Find(LPCWSTR pwzDomain, PBOOL pfMixed)
  3361. {
  3362. CDomainModeListItem * pItem = m_pListHead;
  3363. while (pItem)
  3364. {
  3365. if (_wcsicmp(pwzDomain, pItem->m_strName) == 0)
  3366. {
  3367. *pfMixed = pItem->m_fMixed;
  3368. return TRUE;
  3369. }
  3370. pItem = pItem->Next();
  3371. }
  3372. return FALSE;
  3373. }