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.

7892 lines
284 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 2001.
  5. //
  6. // File: RSOPWizardDlg.cpp
  7. //
  8. // Contents: implementation of RSOP wizard dialog
  9. //
  10. // Classes: CRSOPWizardDlg
  11. //
  12. // Functions:
  13. //
  14. // History: 08-08-2001 rhynierm Created
  15. //
  16. //---------------------------------------------------------------------------
  17. #include "main.h"
  18. #include "RSOPWizardDlg.h"
  19. #include "RSOPWizard.h"
  20. #include "RSOPUtil.h"
  21. #include "objsel.h" // for the object picker
  22. #include "sddl.h" // for sid to string functions
  23. //---------------------------------------------------------------------------
  24. // Private global variables
  25. DWORD g_aBrowseForOUHelpIds[] =
  26. {
  27. DSBID_BANNER, IDH_RSOP_BANNER,
  28. DSBID_CONTAINERLIST, IDH_RSOP_CONTAINERLIST,
  29. 0, 0
  30. };
  31. DWORD g_aBrowseDCHelpIds[] =
  32. {
  33. IDC_LIST1, IDH_RSOP_BROWSEDC,
  34. 0, 0
  35. };
  36. //---------------------------------------------------------------------------
  37. // Private helper methods
  38. WCHAR * NameWithoutDomain(WCHAR * szName); // In RSOPWizard.cpp
  39. TCHAR* NormalizedComputerName(TCHAR * szComputerName ); // In RSOPRoot.cpp
  40. BOOL CopyString( LPTSTR szSource, LPTSTR* pszTarget ); // In RSOPQuery.cpp
  41. BOOL FreeStringList( DWORD dwCount, LPTSTR* aszStrings ); // In RSOPQuery.cpp
  42. BOOL FreeTargetData( LPRSOP_QUERY_TARGET pTarget ); // In RSOPQuery.cpp
  43. BOOL FreeTarget( LPRSOP_QUERY_TARGET pTarget ); // In RSOPQuery.cpp
  44. //---------------------------------------------------------------------------
  45. // TranslateNameXForest
  46. //
  47. // Purpose: a method to do name translations (similar to TranslateName),
  48. // but that also works with names in other forests.
  49. DWORD DsNameErrorMap[] = { ERROR_SUCCESS,
  50. ERROR_NO_SUCH_USER,
  51. ERROR_NO_SUCH_USER,
  52. ERROR_NONE_MAPPED,
  53. ERROR_NONE_MAPPED,
  54. ERROR_SOME_NOT_MAPPED,
  55. ERROR_SOME_NOT_MAPPED
  56. };
  57. #define MapDsNameError( x ) ((x < sizeof( DsNameErrorMap ) / sizeof( DWORD ) ) ? \
  58. DsNameErrorMap[ x ] : ERROR_GEN_FAILURE )
  59. BOOLEAN
  60. TranslateNameXForest (
  61. LPTSTR szDomain, // Domain where the name should be resolved
  62. LPCTSTR lpAccountName, // object name
  63. DS_NAME_FORMAT AccountNameFormat, // name format
  64. DS_NAME_FORMAT DesiredNameFormat, // new name format
  65. LPTSTR *lpTranslatedName // returned name buffer
  66. )
  67. {
  68. BOOL bRetry = FALSE;
  69. DWORD dwErr;
  70. PDOMAIN_CONTROLLER_INFO pDCInfo = NULL;
  71. HANDLE hDS = NULL;
  72. PDS_NAME_RESULT pResult = NULL;
  73. BOOLEAN bRet = FALSE;
  74. LPWSTR szTransName = NULL;
  75. DebugMsg(( DM_VERBOSE, L"TranslateNameXForest: Resolving name <%s> at Domain <%s>", lpAccountName, szDomain ? szDomain : L""));
  76. //
  77. // get a DC and bind to it. Make sure to force rediscover a DC if the bind fails
  78. //
  79. for (;;) {
  80. dwErr = DsGetDcName( NULL,
  81. szDomain ? szDomain : L"",
  82. NULL,
  83. NULL,
  84. DS_DIRECTORY_SERVICE_REQUIRED |
  85. DS_RETURN_DNS_NAME |
  86. (bRetry ? DS_FORCE_REDISCOVERY : 0) |
  87. 0,
  88. &pDCInfo );
  89. if (dwErr == NO_ERROR) {
  90. dwErr = DsBind( pDCInfo->DomainControllerName,
  91. NULL,
  92. &hDS );
  93. if (dwErr == NO_ERROR) {
  94. break;
  95. }
  96. else {
  97. DebugMsg(( DM_WARNING, L"TranslateNameXForest: Failed to bind to DC <%s> with error %d",
  98. pDCInfo->DomainControllerName, dwErr ));
  99. NetApiBufferFree(pDCInfo);
  100. pDCInfo = NULL;
  101. }
  102. }
  103. else {
  104. DebugMsg(( DM_WARNING, L"TranslateNameXForest: Failed to get DC for domain <%s> with error %d",
  105. szDomain ? szDomain : L"", dwErr ));
  106. }
  107. //
  108. // Failed to bind to a DC. bail
  109. //
  110. if (bRetry) {
  111. goto Exit;
  112. }
  113. bRetry = TRUE;
  114. }
  115. DebugMsg(( DM_VERBOSE, L"TranslateNameXForest: DC selected is <%s>", pDCInfo->DomainControllerName ));
  116. //
  117. // Now crack names with the DC that is bound
  118. //
  119. dwErr = DsCrackNames( hDS,
  120. DS_NAME_NO_FLAGS,
  121. AccountNameFormat,
  122. DesiredNameFormat,
  123. 1,
  124. &lpAccountName,
  125. &pResult);
  126. if (dwErr != DS_NAME_NO_ERROR) {
  127. DebugMsg(( DM_WARNING, L"TranslateNameXForest: Failed to crack names with error %d", dwErr ));
  128. goto Exit;
  129. }
  130. if ( pResult->cItems == 0 ) {
  131. DebugMsg(( DM_WARNING, L"TranslateNameXForest: Failed to return enough result items" ));
  132. dwErr = ERROR_INVALID_DATA;
  133. goto Exit;
  134. }
  135. if ( pResult->rItems[0].status == DS_NAME_NO_ERROR ) {
  136. //
  137. // In case of no error, return the resolved name
  138. //
  139. DWORD dwTransNameLength = 1 + lstrlen(pResult->rItems[0].pName);
  140. szTransName = (LPWSTR)LocalAlloc(LPTR, sizeof(WCHAR) * ( dwTransNameLength ));
  141. if (!szTransName) {
  142. DebugMsg(( DM_WARNING, L"TranslateNameXForest: Failed to allocate memory for domain" ));
  143. dwErr = GetLastError();
  144. goto Exit;
  145. }
  146. HRESULT hr = StringCchCopy(szTransName, dwTransNameLength, pResult->rItems[0].pName);
  147. if(FAILED(hr)) {
  148. dwErr = HRESULT_CODE(hr);
  149. goto Exit;
  150. }
  151. *lpTranslatedName = szTransName;
  152. szTransName = NULL;
  153. }
  154. else {
  155. //
  156. // remap the error code to win32 error
  157. //
  158. DebugMsg(( DM_WARNING, L"TranslateNameXForest: DsCrackNames failed with error %d", pResult->rItems[0].status ));
  159. dwErr = MapDsNameError(pResult->rItems[0].status);
  160. goto Exit;
  161. }
  162. bRet = TRUE;
  163. Exit:
  164. if ( szTransName ) {
  165. LocalFree( szTransName );
  166. }
  167. if ( pDCInfo ) {
  168. NetApiBufferFree(pDCInfo);
  169. }
  170. if (hDS) {
  171. DsUnBind( &hDS );
  172. }
  173. if (pResult) {
  174. DsFreeNameResult(pResult);
  175. }
  176. if ( !bRet )
  177. {
  178. SetLastError( dwErr );
  179. }
  180. return bRet;
  181. }
  182. //-------------------------------------------------------
  183. LPTSTR GetDomainFromSOM (LPTSTR lpSOM)
  184. {
  185. LPTSTR lpFullName, lpResult;
  186. LPOLESTR lpLdapDomain, lpDomainName;
  187. HRESULT hr;
  188. ULONG ulNoChars;
  189. ulNoChars = lstrlen(lpSOM) + 10;
  190. lpFullName = (LPTSTR) LocalAlloc (LPTR, ulNoChars * sizeof(TCHAR));
  191. if (!lpFullName)
  192. {
  193. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetDomainFromSOM: Failed to allocate memory with %d."), GetLastError()));
  194. return NULL;
  195. }
  196. hr = StringCchCopy (lpFullName, ulNoChars, TEXT("LDAP://"));
  197. if (SUCCEEDED(hr))
  198. {
  199. hr = StringCchCat (lpFullName, ulNoChars, lpSOM);
  200. }
  201. if (FAILED(hr))
  202. {
  203. LocalFree(lpFullName);
  204. return NULL;
  205. }
  206. lpLdapDomain = GetDomainFromLDAPPath(lpFullName);
  207. LocalFree (lpFullName);
  208. if (!lpLdapDomain)
  209. {
  210. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetDomainFromSOM: Failed to get ldap domain name from path.")));
  211. return NULL;
  212. }
  213. hr = ConvertToDotStyle (lpLdapDomain, &lpDomainName);
  214. delete [] lpLdapDomain;
  215. if (FAILED(hr))
  216. {
  217. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetDomainFromSOM: Failed to convert to dot style.")));
  218. return NULL;
  219. }
  220. ulNoChars = lstrlen(lpDomainName) + 1;
  221. lpResult = new TCHAR[ulNoChars];
  222. if (lpResult)
  223. {
  224. hr = StringCchCopy (lpResult, ulNoChars, lpDomainName);
  225. ASSERT(SUCCEEDED(hr));
  226. }
  227. LocalFree (lpDomainName);
  228. return lpResult;
  229. }
  230. //-------------------------------------------------------
  231. WCHAR * ExtractDomain(WCHAR * sz)
  232. {
  233. // parse through the string looking for a forward slash
  234. DWORD cch = 0;
  235. if (!sz)
  236. {
  237. return NULL;
  238. }
  239. while (sz[cch])
  240. {
  241. if (L'\\' == sz[cch] || L'/' == sz[cch])
  242. {
  243. WCHAR * szNew = new WCHAR[cch+1];
  244. if (szNew)
  245. {
  246. wcsncpy(szNew, sz, cch);
  247. szNew[cch] = TEXT('\0');
  248. }
  249. return szNew;
  250. }
  251. cch++;
  252. }
  253. // didn't find a forward slash
  254. return NULL;
  255. }
  256. //*************************************************************
  257. //
  258. // MyLookupAccountName()
  259. //
  260. // Purpose: Gets the SID of the user
  261. //
  262. // Parameters:
  263. // szSystemName: Machine where the account should be resolved
  264. // szAccName: The actual account name
  265. //
  266. // Return: lpUserName if successful
  267. // NULL if an error occurs
  268. //
  269. // Allocates and retries with the appropriate buffer size
  270. LPTSTR MyLookupAccountName(LPTSTR szSystemName, LPTSTR szAccName)
  271. {
  272. PSID pSid = NULL;
  273. DWORD cSid = 0, cbDomain = 0;
  274. SID_NAME_USE peUse;
  275. LPTSTR lpSidString = NULL, szDomain = NULL;
  276. DWORD dwErr = 0;
  277. BOOL bRet = FALSE;
  278. LookupAccountName(szSystemName, szAccName, NULL, &cSid, NULL, &cbDomain, &peUse);
  279. pSid = (PSID)LocalAlloc(LPTR, cSid);
  280. szDomain = (LPTSTR) LocalAlloc(LPTR, cbDomain*(sizeof(TCHAR)));
  281. if (!pSid || !szDomain) {
  282. return NULL;
  283. }
  284. if (!LookupAccountName(szSystemName, szAccName, pSid, &cSid, szDomain, &cbDomain, &peUse)) {
  285. DebugMsg((DM_WARNING, TEXT("MyLookupAccountName: LookupAccountName failed with %d"),
  286. GetLastError()));
  287. dwErr = GetLastError();
  288. goto Exit;
  289. }
  290. if (!ConvertSidToStringSid(pSid, &lpSidString)) {
  291. DebugMsg((DM_WARNING, TEXT("MyLookupAccountName: ConvertSidToStringSid failed with %d"),
  292. GetLastError()));
  293. dwErr = GetLastError();
  294. goto Exit;
  295. }
  296. bRet = TRUE;
  297. Exit:
  298. if (pSid) {
  299. LocalFree(pSid);
  300. }
  301. if (szDomain) {
  302. LocalFree(szDomain);
  303. }
  304. if (!bRet) {
  305. SetLastError(dwErr);
  306. return NULL;
  307. }
  308. else {
  309. return lpSidString;
  310. }
  311. }
  312. //-------------------------------------------------------
  313. void GetControlText(HWND hDlg, DWORD ctrlid, TCHAR * &szControlText, BOOL bUseLocalAlloc)
  314. {
  315. UINT nSize;
  316. if ( szControlText != NULL )
  317. {
  318. if ( bUseLocalAlloc )
  319. {
  320. LocalFree( szControlText );
  321. }
  322. else
  323. {
  324. delete [] szControlText;
  325. }
  326. szControlText = NULL;
  327. }
  328. nSize = (UINT) SendMessage(GetDlgItem(hDlg, ctrlid),
  329. WM_GETTEXTLENGTH, 0, 0);
  330. if (nSize > 0)
  331. {
  332. if ( bUseLocalAlloc )
  333. {
  334. szControlText = (TCHAR*)LocalAlloc( LPTR, (nSize+1)*sizeof(TCHAR) );
  335. }
  336. else
  337. {
  338. szControlText = new TCHAR[nSize + 1];
  339. }
  340. if (szControlText)
  341. {
  342. LPTSTR lpDest, lpSrc;
  343. GetDlgItemText(hDlg, ctrlid, szControlText, nSize + 1);
  344. if (szControlText[0] == TEXT(' '))
  345. {
  346. //
  347. // Remove leading blanks by shuffling the characters forward
  348. //
  349. lpDest = lpSrc = szControlText;
  350. while ((*lpSrc == TEXT(' ')) && *lpSrc)
  351. lpSrc++;
  352. if (*lpSrc)
  353. {
  354. while (*lpSrc)
  355. {
  356. *lpDest = *lpSrc;
  357. lpDest++;
  358. lpSrc++;
  359. }
  360. *lpDest = TEXT('\0');
  361. }
  362. }
  363. //
  364. // Remove trailing blanks
  365. //
  366. lpDest = szControlText + lstrlen(szControlText) - 1;
  367. while ((*lpDest == TEXT(' ')) && (lpDest >= szControlText))
  368. lpDest--;
  369. *(lpDest+1) = TEXT('\0');
  370. }
  371. }
  372. }
  373. //-------------------------------------------------------
  374. HRESULT ImplementBrowseButton(HWND hDlg, DWORD dwFlagsUp, DWORD dwFlagsDown,
  375. DWORD dwflScope, HWND hLB, TCHAR * &szFoundObject)
  376. {
  377. // shell the object picker to get the computer list
  378. HRESULT hr = E_FAIL;
  379. IDsObjectPicker * pDsObjectPicker = NULL;
  380. const ULONG cbNumScopes = 4; //make sure this number matches the number of scopes initialized
  381. DSOP_SCOPE_INIT_INFO ascopes [cbNumScopes];
  382. DSOP_INIT_INFO InitInfo;
  383. IDataObject * pdo = NULL;
  384. STGMEDIUM stgmedium = {
  385. TYMED_HGLOBAL,
  386. NULL
  387. };
  388. UINT cf = 0;
  389. FORMATETC formatetc = {
  390. (CLIPFORMAT)cf,
  391. NULL,
  392. DVASPECT_CONTENT,
  393. -1,
  394. TYMED_HGLOBAL
  395. };
  396. BOOL bAllocatedStgMedium = FALSE;
  397. PDS_SELECTION_LIST pDsSelList = NULL;
  398. PDS_SELECTION pDsSelection = NULL;
  399. ULONG ulSize, ulIndex, ulMax;
  400. LPWSTR lpTemp;
  401. LPTSTR szDomain = NULL;
  402. LPWSTR szUnEscapedPath = NULL;
  403. hr = CoInitialize (NULL);
  404. if (FAILED(hr))
  405. goto Browse_Cleanup;
  406. hr = CoCreateInstance (CLSID_DsObjectPicker,
  407. NULL,
  408. CLSCTX_INPROC_SERVER,
  409. IID_IDsObjectPicker,
  410. (void **) & pDsObjectPicker
  411. );
  412. if (FAILED(hr))
  413. goto Browse_Cleanup;
  414. //Initialize the scopes.
  415. ZeroMemory (ascopes, cbNumScopes * sizeof (DSOP_SCOPE_INIT_INFO));
  416. ascopes[0].cbSize = ascopes[1].cbSize = ascopes[2].cbSize = ascopes[3].cbSize
  417. = sizeof (DSOP_SCOPE_INIT_INFO);
  418. ascopes[0].flType = DSOP_SCOPE_TYPE_GLOBAL_CATALOG;
  419. ascopes[0].flScope = DSOP_SCOPE_FLAG_WANT_PROVIDER_LDAP
  420. | DSOP_SCOPE_FLAG_STARTING_SCOPE | dwflScope;
  421. ascopes[0].FilterFlags.Uplevel.flBothModes = dwFlagsUp;
  422. ascopes[1].flType = DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN;
  423. ascopes[1].FilterFlags.Uplevel.flBothModes = dwFlagsUp;
  424. ascopes[1].flScope = DSOP_SCOPE_FLAG_WANT_PROVIDER_LDAP | dwflScope;
  425. ascopes[2].flType = DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN |
  426. DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN;
  427. ascopes[2].FilterFlags.Uplevel.flBothModes = dwFlagsUp;
  428. ascopes[2].FilterFlags.flDownlevel = dwFlagsDown;
  429. ascopes[2].flScope = DSOP_SCOPE_FLAG_WANT_PROVIDER_LDAP | dwflScope;
  430. ascopes[3].flType = DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE |
  431. DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE |
  432. DSOP_SCOPE_TYPE_WORKGROUP;
  433. ascopes[3].FilterFlags.Uplevel.flBothModes = dwFlagsUp;
  434. ascopes[3].FilterFlags.flDownlevel = dwFlagsDown;
  435. ascopes[3].flScope = DSOP_SCOPE_FLAG_WANT_PROVIDER_LDAP | dwflScope;
  436. //populate the InitInfo structure that will be used to initialize the
  437. //object picker
  438. ZeroMemory (&InitInfo, sizeof (DSOP_INIT_INFO));
  439. InitInfo.cbSize = sizeof (DSOP_INIT_INFO);
  440. InitInfo.cDsScopeInfos = cbNumScopes;
  441. InitInfo.aDsScopeInfos = ascopes;
  442. InitInfo.flOptions = (hLB ? DSOP_FLAG_MULTISELECT : 0);
  443. hr = pDsObjectPicker->Initialize (&InitInfo);
  444. if (FAILED(hr))
  445. goto Browse_Cleanup;
  446. hr = pDsObjectPicker->InvokeDialog (hDlg, &pdo);
  447. //if the computer selection dialog cannot be invoked or if the user
  448. //hits cancel, bail out.
  449. if (FAILED(hr) || S_FALSE == hr)
  450. goto Browse_Cleanup;
  451. //if we are here, the user chose, OK, so find out what group was chosen
  452. cf = RegisterClipboardFormat (CFSTR_DSOP_DS_SELECTION_LIST);
  453. if (0 == cf)
  454. goto Browse_Cleanup;
  455. //set the clipboard format for the FORMATETC structure
  456. formatetc.cfFormat = (CLIPFORMAT)cf;
  457. hr = pdo->GetData (&formatetc, &stgmedium);
  458. if (FAILED (hr))
  459. goto Browse_Cleanup;
  460. bAllocatedStgMedium = TRUE;
  461. pDsSelList = (PDS_SELECTION_LIST) GlobalLock (stgmedium.hGlobal);
  462. //
  463. // Decide what the max number of items to process is
  464. //
  465. ulMax = pDsSelList->cItems;
  466. if (!hLB && (ulMax > 1))
  467. {
  468. ulMax = 1;
  469. }
  470. //
  471. // Loop through the items
  472. //
  473. for (ulIndex = 0; ulIndex < ulMax; ulIndex++)
  474. {
  475. pDsSelection = &(pDsSelList->aDsSelection[ulIndex]);
  476. //
  477. // Find the beginning of the object name after the domain name
  478. //
  479. lpTemp = pDsSelection->pwzADsPath + 7;
  480. while (*lpTemp && *lpTemp != TEXT('/'))
  481. {
  482. lpTemp++;
  483. }
  484. if (!(*lpTemp))
  485. {
  486. hr = E_FAIL;
  487. goto Browse_Cleanup;
  488. }
  489. lpTemp++;
  490. ulSize = wcslen(lpTemp);
  491. //
  492. // Convert the name from full DN to sam compatible
  493. //
  494. szDomain = GetDomainFromSOM( lpTemp );
  495. //
  496. // ADSI escapes '/' which is not liked by native ldap.
  497. // APIs like DsCrackNames/TranslateName etc.
  498. // Previous function (GetDomainFromSOM) needs it though
  499. // because it is using adsi interfaces internally
  500. //
  501. hr = UnEscapeLdapPath(lpTemp, &szUnEscapedPath);
  502. if (FAILED(hr))
  503. {
  504. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  505. ReportError (hDlg, hr, IDS_NOCOMPUTERCONTAINER);
  506. DebugMsg((DM_WARNING, TEXT("ImplementBrowseButton: UnEscapeLdapPath for %s failed with 0x%x."),
  507. lpTemp, hr));
  508. goto Browse_Cleanup;
  509. }
  510. if (TranslateNameXForest ( szDomain, szUnEscapedPath, (DS_NAME_FORMAT)NameFullyQualifiedDN,
  511. (DS_NAME_FORMAT)NameSamCompatible, &szFoundObject ))
  512. {
  513. BOOL bDollarRemoved = FALSE;
  514. if (szFoundObject[wcslen(szFoundObject)-1] == L'$')
  515. {
  516. bDollarRemoved = TRUE;
  517. szFoundObject[wcslen(szFoundObject)-1] = 0;
  518. }
  519. if (hLB)
  520. {
  521. INT iIndex;
  522. iIndex = (INT) SendMessage (hLB, LB_ADDSTRING, 0, (LPARAM) szFoundObject);
  523. SendMessage (hLB, LB_SETITEMDATA, (WPARAM) iIndex, (LPARAM) ((bDollarRemoved) ? 2: 0));
  524. SendMessage (hLB, LB_SETCURSEL, (WPARAM) iIndex, 0);
  525. LocalFree( szFoundObject );
  526. szFoundObject = NULL;
  527. }
  528. }
  529. else
  530. {
  531. hr = HRESULT_FROM_WIN32(GetLastError());
  532. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  533. ReportError (hDlg, hr, IDS_NOCOMPUTERCONTAINER);
  534. DebugMsg((DM_WARNING, TEXT("ImplementBrowseButton: TranslateName for %s to SAM style failed with %d."),
  535. lpTemp, GetLastError()));
  536. goto Browse_Cleanup;
  537. }
  538. }
  539. Browse_Cleanup:
  540. if (szUnEscapedPath)
  541. LocalFree(szUnEscapedPath);
  542. if (pDsSelList)
  543. GlobalUnlock (pDsSelList);
  544. if (bAllocatedStgMedium)
  545. ReleaseStgMedium (&stgmedium);
  546. if (pdo)
  547. pdo->Release();
  548. if (pDsObjectPicker)
  549. pDsObjectPicker->Release();
  550. if (szDomain)
  551. delete [] szDomain;
  552. return hr;
  553. }
  554. //-------------------------------------------------------
  555. HRESULT GetForestFromDC( LPTSTR szDC, LPTSTR* pszForest )
  556. {
  557. DSROLE_PRIMARY_DOMAIN_INFO_BASIC* psDomainInfo( NULL );
  558. DWORD dwResult( ERROR_SUCCESS );
  559. if ( (szDC == NULL) || (*pszForest != NULL) )
  560. {
  561. return E_INVALIDARG;
  562. }
  563. dwResult = ::DsRoleGetPrimaryDomainInformation( szDC, DsRolePrimaryDomainInfoBasic, (PBYTE*) &psDomainInfo );
  564. if ( dwResult != ERROR_SUCCESS )
  565. {
  566. return HRESULT_FROM_WIN32( dwResult );
  567. }
  568. CopyString( psDomainInfo->DomainForestName, pszForest );
  569. ::DsRoleFreeMemory( psDomainInfo );
  570. return S_OK;
  571. }
  572. //-------------------------------------------------------
  573. HRESULT GetForestFromObject( LPTSTR szDomainObject, LPTSTR* pszForest )
  574. {
  575. HRESULT hr = E_FAIL;
  576. LPTSTR szDomain = ExtractDomain( szDomainObject );
  577. if ( szDomain != NULL )
  578. {
  579. LPTSTR szDC = GetDCName( szDomain, NULL, NULL, FALSE, 0, DS_RETURN_DNS_NAME);
  580. if ( szDC != NULL )
  581. {
  582. hr = GetForestFromDC( szDC, pszForest );
  583. LocalFree( szDC );
  584. }
  585. delete [] szDomain;
  586. }
  587. return hr;
  588. }
  589. //-------------------------------------------------------
  590. HRESULT GetForestFromContainer( LPTSTR szDSContainer, LPTSTR* pszForest )
  591. {
  592. HRESULT hr = E_FAIL;
  593. LPTSTR szDomain = GetDomainFromSOM( szDSContainer );
  594. if ( szDomain != NULL )
  595. {
  596. LPTSTR szDC = GetDCName( szDomain, NULL, NULL, FALSE, 0, DS_RETURN_DNS_NAME);
  597. if ( szDC != NULL )
  598. {
  599. hr = GetForestFromDC( szDC, pszForest );
  600. LocalFree( szDC );
  601. }
  602. delete [] szDomain;
  603. }
  604. return hr;
  605. }
  606. //---------------------------------------------------------------------------
  607. // CRSOPWizardDlg class
  608. //
  609. CRSOPWizardDlg::CRSOPWizardDlg( LPRSOP_QUERY pQuery, CRSOPExtendedProcessing* pExtendedProcessing )
  610. {
  611. m_bPostXPBuild = FALSE; // Assume this is not post XP until verified as otherwise
  612. OSVERSIONINFOEX osvi;
  613. ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
  614. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  615. if ( GetVersionEx ((OSVERSIONINFO*) &osvi) )
  616. {
  617. // Windows XP was version 5.1, while .Net Server is version 5.2. So, we enable the
  618. // additional features for any version past XP, i.e. >= 5.2
  619. m_bPostXPBuild = (osvi.dwMajorVersion >= 5) && (osvi.dwMinorVersion >= 2) && (VER_NT_WORKSTATION != osvi.wProductType);
  620. }
  621. m_dwSkippedFrom = 0;
  622. m_pRSOPQuery = pQuery;
  623. m_pRSOPQueryResults = NULL;
  624. m_hrQuery = E_FAIL;
  625. m_bNoChooseQuery = FALSE;
  626. // Initialize local variables
  627. m_szDefaultUserSOM = NULL;
  628. m_szDefaultComputerSOM = NULL;
  629. m_pComputerObject = NULL;
  630. m_pUserObject = NULL;
  631. m_bDollarRemoved = FALSE;
  632. m_bNoCurrentUser = FALSE;
  633. m_dwDefaultUserSecurityGroupCount = 0;
  634. m_aszDefaultUserSecurityGroups = NULL;
  635. m_adwDefaultUserSecurityGroupsAttr = NULL;
  636. m_dwDefaultUserWQLFilterCount = 0;
  637. m_aszDefaultUserWQLFilters = NULL;
  638. m_aszDefaultUserWQLFilterNames = NULL;
  639. m_dwDefaultComputerSecurityGroupCount = 0;
  640. m_aszDefaultComputerSecurityGroups = NULL;
  641. m_adwDefaultComputerSecurityGroupsAttr = NULL;
  642. m_dwDefaultComputerWQLFilterCount = 0;
  643. m_aszDefaultComputerWQLFilters = NULL;
  644. m_aszDefaultComputerWQLFilterNames = NULL;
  645. m_bFinalNextClicked = FALSE;
  646. m_pExtendedProcessing = pExtendedProcessing;
  647. m_lPlanningFinishedPage = 0;
  648. m_lLoggingFinishedPage = 0;
  649. }
  650. //-------------------------------------------------------
  651. CRSOPWizardDlg::~CRSOPWizardDlg()
  652. {
  653. delete [] m_szDefaultUserSOM;
  654. delete [] m_szDefaultComputerSOM;
  655. if ( m_pComputerObject != NULL )
  656. {
  657. m_pComputerObject->Release();
  658. m_pComputerObject = NULL;
  659. }
  660. if ( m_pUserObject != NULL )
  661. {
  662. m_pUserObject->Release();
  663. m_pUserObject = NULL;
  664. }
  665. if ( m_dwDefaultUserSecurityGroupCount != 0 )
  666. {
  667. LocalFree( m_aszDefaultUserSecurityGroups );
  668. LocalFree( m_adwDefaultUserSecurityGroupsAttr );
  669. }
  670. if ( m_dwDefaultUserWQLFilterCount != 0 )
  671. {
  672. LocalFree( m_aszDefaultUserWQLFilters );
  673. LocalFree( m_aszDefaultUserWQLFilterNames );
  674. }
  675. if ( m_dwDefaultComputerSecurityGroupCount != 0 )
  676. {
  677. LocalFree( m_aszDefaultComputerSecurityGroups );
  678. LocalFree( m_adwDefaultComputerSecurityGroupsAttr );
  679. }
  680. if ( m_dwDefaultComputerWQLFilterCount != 0 )
  681. {
  682. LocalFree( m_aszDefaultComputerWQLFilters );
  683. LocalFree( m_aszDefaultComputerWQLFilterNames );
  684. }
  685. }
  686. //-------------------------------------------------------
  687. VOID CRSOPWizardDlg::FreeUserData ()
  688. // RSOP_PLANNING_MODE : Only called from RSOPTargetDlgProc
  689. {
  690. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  691. {
  692. FreeTargetData( m_pRSOPQuery->pUser );
  693. m_pRSOPQuery->pUser->bAssumeWQLFiltersTrue = TRUE;
  694. }
  695. else
  696. {
  697. LocalFree( m_pRSOPQuery->szUserName );
  698. m_pRSOPQuery->szUserName = NULL;
  699. LocalFree( m_pRSOPQuery->szUserSid );
  700. m_pRSOPQuery->szUserSid = NULL;
  701. }
  702. if ( m_szDefaultUserSOM != NULL )
  703. {
  704. delete [] m_szDefaultUserSOM;
  705. m_szDefaultUserSOM = NULL;
  706. }
  707. if ( m_dwDefaultUserSecurityGroupCount != 0 )
  708. {
  709. FreeStringList( m_dwDefaultUserSecurityGroupCount, m_aszDefaultUserSecurityGroups );
  710. m_aszDefaultUserSecurityGroups = NULL;
  711. LocalFree( m_adwDefaultUserSecurityGroupsAttr );
  712. m_adwDefaultUserSecurityGroupsAttr = NULL;
  713. m_dwDefaultUserSecurityGroupCount = 0;
  714. }
  715. if ( m_dwDefaultUserWQLFilterCount != 0 )
  716. {
  717. FreeStringList( m_dwDefaultUserWQLFilterCount, m_aszDefaultUserWQLFilterNames );
  718. m_aszDefaultUserWQLFilterNames = NULL;
  719. FreeStringList( m_dwDefaultUserWQLFilterCount, m_aszDefaultUserWQLFilters );
  720. m_aszDefaultUserWQLFilters = NULL;
  721. m_dwDefaultUserWQLFilterCount = 0;
  722. }
  723. if ( m_pUserObject != NULL )
  724. {
  725. m_pUserObject->Release();
  726. m_pUserObject = NULL;
  727. }
  728. }
  729. //-------------------------------------------------------
  730. VOID CRSOPWizardDlg::FreeComputerData ()
  731. // RSOP_PLANNING_MODE : Only called from RSOPTargetDlgProc
  732. {
  733. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  734. {
  735. FreeTargetData( m_pRSOPQuery->pComputer );
  736. m_pRSOPQuery->pComputer->bAssumeWQLFiltersTrue = TRUE;
  737. }
  738. else
  739. {
  740. LocalFree( m_pRSOPQuery->szComputerName );
  741. m_pRSOPQuery->szComputerName = NULL;
  742. }
  743. if ( m_szDefaultComputerSOM != NULL )
  744. {
  745. delete [] m_szDefaultComputerSOM;
  746. m_szDefaultComputerSOM = NULL;
  747. }
  748. if ( m_dwDefaultComputerSecurityGroupCount != 0 )
  749. {
  750. FreeStringList( m_dwDefaultComputerSecurityGroupCount, m_aszDefaultComputerSecurityGroups );
  751. m_aszDefaultComputerSecurityGroups = NULL;
  752. LocalFree( m_adwDefaultComputerSecurityGroupsAttr );
  753. m_adwDefaultComputerSecurityGroupsAttr = NULL;
  754. m_dwDefaultComputerSecurityGroupCount = 0;
  755. }
  756. if ( m_dwDefaultComputerWQLFilterCount != 0 )
  757. {
  758. FreeStringList( m_dwDefaultComputerWQLFilterCount, m_aszDefaultComputerWQLFilterNames );
  759. m_aszDefaultComputerWQLFilterNames = NULL;
  760. FreeStringList( m_dwDefaultComputerWQLFilterCount, m_aszDefaultComputerWQLFilters );
  761. m_aszDefaultComputerWQLFilters = NULL;
  762. m_dwDefaultComputerWQLFilterCount = 0;
  763. }
  764. if ( m_pComputerObject != NULL )
  765. {
  766. m_pComputerObject->Release();
  767. m_pComputerObject = NULL;
  768. }
  769. }
  770. //-------------------------------------------------------
  771. // Wizard interface
  772. HRESULT CRSOPWizardDlg::ShowWizard( HWND hParent )
  773. {
  774. HRESULT hr = E_FAIL;
  775. PROPSHEETPAGE psp;
  776. HPROPSHEETPAGE hPage;
  777. TCHAR szTitle[150];
  778. TCHAR szSubTitle[300];
  779. HPROPSHEETPAGE hShowNowPages[20];
  780. DWORD dwCount=0, dwDiagStartPage = 0, dwPlanStartPage = 0, dwDiagFinishPage = 0, dwPlanFinishPage = 0;
  781. hr = SetupFonts();
  782. if ( FAILED(hr) )
  783. {
  784. return hr;
  785. }
  786. // ------------------------------
  787. // Create all the wizard property pages
  788. // (1) --- Welcome ---
  789. // LoadString (g_hInstance, IDS_TITLE_WELCOME, szTitle, ARRAYSIZE(szTitle));
  790. ::memset( &psp, 0, sizeof(PROPSHEETPAGE) );
  791. psp.dwSize = sizeof(PROPSHEETPAGE);
  792. // psp.dwFlags = PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  793. psp.dwFlags = PSP_HIDEHEADER;
  794. psp.hInstance = g_hInstance;
  795. psp.pszTemplate = MAKEINTRESOURCE(IDD_RSOP_WELCOME);
  796. psp.pfnDlgProc = RSOPWelcomeDlgProc;
  797. psp.lParam = (LPARAM) this;
  798. //psp.pszHeaderTitle = szTitle;
  799. psp.pszHeaderTitle = NULL;
  800. psp.pszHeaderSubTitle = NULL;
  801. hPage = CreatePropertySheetPage(&psp);
  802. if (!hPage)
  803. {
  804. DebugMsg((DM_WARNING, TEXT("CRSOPWizardDlg::CreatePropertyPages: Failed to create property sheet page with %d."),
  805. GetLastError()));
  806. return E_FAIL;
  807. }
  808. hShowNowPages[dwCount] = hPage;
  809. dwCount++;
  810. // (2) --- Choose Mode ---
  811. LoadString (g_hInstance, IDS_TITLE_CHOOSEMODE, szTitle, ARRAYSIZE(szTitle));
  812. LoadString (g_hInstance, IDS_SUBTITLE_CHOOSEMODE, szSubTitle, ARRAYSIZE(szSubTitle));
  813. ::memset( &psp, 0, sizeof(PROPSHEETPAGE) );
  814. psp.dwSize = sizeof(PROPSHEETPAGE);
  815. psp.dwFlags = PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  816. psp.hInstance = g_hInstance;
  817. psp.pszTemplate = MAKEINTRESOURCE(IDD_RSOP_CHOOSEMODE);
  818. psp.pfnDlgProc = RSOPChooseModeDlgProc;
  819. psp.lParam = (LPARAM) this;
  820. psp.pszHeaderTitle = szTitle;
  821. psp.pszHeaderSubTitle = szSubTitle;
  822. hPage = CreatePropertySheetPage(&psp);
  823. if (!hPage)
  824. {
  825. DebugMsg((DM_WARNING, TEXT("CRSOPWizardDlg::CreatePropertyPages: Failed to create property sheet page with %d."),
  826. GetLastError()));
  827. return E_FAIL;
  828. }
  829. hShowNowPages[dwCount] = hPage;
  830. dwCount++;
  831. // (3) --- GetComp ---
  832. LoadString (g_hInstance, IDS_TITLE_GETCOMP, szTitle, ARRAYSIZE(szTitle));
  833. LoadString (g_hInstance, IDS_SUBTITLE_GETCOMP, szSubTitle, ARRAYSIZE(szSubTitle));
  834. ::memset( &psp, 0, sizeof(PROPSHEETPAGE) );
  835. psp.dwSize = sizeof(PROPSHEETPAGE);
  836. psp.dwFlags = PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  837. psp.hInstance = g_hInstance;
  838. psp.pszTemplate = MAKEINTRESOURCE(IDD_RSOP_GETCOMP);
  839. psp.pfnDlgProc = RSOPGetCompDlgProc;
  840. psp.lParam = (LPARAM) this;
  841. psp.pszHeaderTitle = szTitle;
  842. psp.pszHeaderSubTitle = szSubTitle;
  843. hPage = CreatePropertySheetPage(&psp);
  844. if (!hPage)
  845. {
  846. DebugMsg((DM_WARNING, TEXT("CRSOPWizardDlg::CreatePropertyPages: Failed to create property sheet page with %d."),
  847. GetLastError()));
  848. return E_FAIL;
  849. }
  850. hShowNowPages[dwCount] = hPage;
  851. dwDiagStartPage = dwCount;
  852. dwCount++;
  853. // (4) --- GetUser ---
  854. LoadString (g_hInstance, IDS_TITLE_GETUSER, szTitle, ARRAYSIZE(szTitle));
  855. LoadString (g_hInstance, IDS_SUBTITLE_GETUSER, szSubTitle, ARRAYSIZE(szSubTitle));
  856. ::memset( &psp, 0, sizeof(PROPSHEETPAGE) );
  857. psp.dwSize = sizeof(PROPSHEETPAGE);
  858. psp.dwFlags = PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  859. psp.hInstance = g_hInstance;
  860. psp.pszTemplate = MAKEINTRESOURCE(IDD_RSOP_GETUSER);
  861. psp.pfnDlgProc = RSOPGetUserDlgProc;
  862. psp.lParam = (LPARAM) this;
  863. psp.pszHeaderTitle = szTitle;
  864. psp.pszHeaderSubTitle = szSubTitle;
  865. hPage = CreatePropertySheetPage(&psp);
  866. if (!hPage)
  867. {
  868. DebugMsg((DM_WARNING, TEXT("CRSOPWizardDlg::CreatePropertyPages: Failed to create property sheet page with %d."),
  869. GetLastError()));
  870. return E_FAIL;
  871. }
  872. hShowNowPages[dwCount] = hPage;
  873. dwCount++;
  874. // (5) --- GetTarget ---
  875. LoadString (g_hInstance, IDS_TITLE_GETTARGET, szTitle, ARRAYSIZE(szTitle));
  876. LoadString (g_hInstance, IDS_SUBTITLE_GETTARGET, szSubTitle, ARRAYSIZE(szSubTitle));
  877. ::memset( &psp, 0, sizeof(PROPSHEETPAGE) );
  878. psp.dwSize = sizeof(PROPSHEETPAGE);
  879. psp.dwFlags = PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  880. psp.hInstance = g_hInstance;
  881. psp.pszTemplate = MAKEINTRESOURCE(IDD_RSOP_GETTARGET);
  882. psp.pfnDlgProc = RSOPGetTargetDlgProc;
  883. psp.lParam = (LPARAM) this;
  884. psp.pszHeaderTitle = szTitle;
  885. psp.pszHeaderSubTitle = szSubTitle;
  886. hPage = CreatePropertySheetPage(&psp);
  887. if (!hPage)
  888. {
  889. DebugMsg((DM_WARNING, TEXT("CRSOPWizardDlg::CreatePropertyPages: Failed to create property sheet page with %d."),
  890. GetLastError()));
  891. return E_FAIL;
  892. }
  893. hShowNowPages[dwCount] = hPage;
  894. dwPlanStartPage = dwCount;
  895. dwCount++;
  896. // (6) --- GetDC ---
  897. LoadString (g_hInstance, IDS_TITLE_GETDC, szTitle, ARRAYSIZE(szTitle));
  898. LoadString (g_hInstance, IDS_SUBTITLE_GETDC, szSubTitle, ARRAYSIZE(szSubTitle));
  899. ::memset( &psp, 0, sizeof(PROPSHEETPAGE) );
  900. psp.dwSize = sizeof(PROPSHEETPAGE);
  901. psp.dwFlags = PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  902. psp.hInstance = g_hInstance;
  903. psp.pszTemplate = MAKEINTRESOURCE(IDD_RSOP_GETDC);
  904. psp.pfnDlgProc = RSOPGetDCDlgProc;
  905. psp.lParam = (LPARAM) this;
  906. psp.pszHeaderTitle = szTitle;
  907. psp.pszHeaderSubTitle = szSubTitle;
  908. hPage = CreatePropertySheetPage(&psp);
  909. if (!hPage)
  910. {
  911. DebugMsg((DM_WARNING, TEXT("CRSOPWizardDlg::CreatePropertyPages: Failed to create property sheet page with %d."),
  912. GetLastError()));
  913. return E_FAIL;
  914. }
  915. hShowNowPages[dwCount] = hPage;
  916. dwCount++;
  917. // (7) --- AltDirs ---
  918. LoadString (g_hInstance, IDS_TITLE_ALTDIRS, szTitle, ARRAYSIZE(szTitle));
  919. LoadString (g_hInstance, IDS_SUBTITLE_ALTDIRS, szSubTitle, ARRAYSIZE(szSubTitle));
  920. ::memset( &psp, 0, sizeof(PROPSHEETPAGE) );
  921. psp.dwSize = sizeof(PROPSHEETPAGE);
  922. psp.dwFlags = PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  923. psp.hInstance = g_hInstance;
  924. psp.pszTemplate = MAKEINTRESOURCE(IDD_RSOP_ALTDIRS);
  925. psp.pfnDlgProc = RSOPAltDirsDlgProc;
  926. psp.lParam = (LPARAM) this;
  927. psp.pszHeaderTitle = szTitle;
  928. psp.pszHeaderSubTitle = szSubTitle;
  929. hPage = CreatePropertySheetPage(&psp);
  930. if (!hPage)
  931. {
  932. DebugMsg((DM_WARNING, TEXT("CRSOPWizardDlg::CreatePropertyPages: Failed to create property sheet page with %d."),
  933. GetLastError()));
  934. return E_FAIL;
  935. }
  936. hShowNowPages[dwCount] = hPage;
  937. dwCount++;
  938. // (8) --- AltUserSec ---
  939. LoadString (g_hInstance, IDS_TITLE_USERSECGRPS, szTitle, ARRAYSIZE(szTitle));
  940. LoadString (g_hInstance, IDS_SUBTITLE_USERSECGRPS, szSubTitle, ARRAYSIZE(szSubTitle));
  941. ::memset( &psp, 0, sizeof(PROPSHEETPAGE) );
  942. psp.dwSize = sizeof(PROPSHEETPAGE);
  943. psp.dwFlags = PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  944. psp.hInstance = g_hInstance;
  945. psp.pszTemplate = MAKEINTRESOURCE(IDD_RSOP_ALTUSERSEC);
  946. psp.pfnDlgProc = RSOPAltUserSecDlgProc;
  947. psp.lParam = (LPARAM) this;
  948. psp.pszHeaderTitle = szTitle;
  949. psp.pszHeaderSubTitle = szSubTitle;
  950. hPage = CreatePropertySheetPage(&psp);
  951. if (!hPage)
  952. {
  953. DebugMsg((DM_WARNING, TEXT("CRSOPWizardDlg::CreatePropertyPages: Failed to create property sheet page with %d."),
  954. GetLastError()));
  955. return E_FAIL;
  956. }
  957. hShowNowPages[dwCount] = hPage;
  958. dwCount++;
  959. // (9) --- AltCompSec ---
  960. LoadString (g_hInstance, IDS_TITLE_COMPSECGRPS, szTitle, ARRAYSIZE(szTitle));
  961. LoadString (g_hInstance, IDS_SUBTITLE_COMPSECGRPS, szSubTitle, ARRAYSIZE(szSubTitle));
  962. ::memset( &psp, 0, sizeof(PROPSHEETPAGE) );
  963. psp.dwSize = sizeof(PROPSHEETPAGE);
  964. psp.dwFlags = PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  965. psp.hInstance = g_hInstance;
  966. psp.pszTemplate = MAKEINTRESOURCE(IDD_RSOP_ALTCOMPSEC);
  967. psp.pfnDlgProc = RSOPAltCompSecDlgProc;
  968. psp.lParam = (LPARAM) this;
  969. psp.pszHeaderTitle = szTitle;
  970. psp.pszHeaderSubTitle = szSubTitle;
  971. hPage = CreatePropertySheetPage(&psp);
  972. if (!hPage)
  973. {
  974. DebugMsg((DM_WARNING, TEXT("CRSOPWizardDlg::CreatePropertyPages: Failed to create property sheet page with %d."),
  975. GetLastError()));
  976. return E_FAIL;
  977. }
  978. hShowNowPages[dwCount] = hPage;
  979. dwCount++;
  980. // (10) --- WQLUser ---
  981. LoadString (g_hInstance, IDS_TITLE_WQLUSER, szTitle, ARRAYSIZE(szTitle));
  982. LoadString (g_hInstance, IDS_SUBTITLE_WQL, szSubTitle, ARRAYSIZE(szSubTitle));
  983. ::memset( &psp, 0, sizeof(PROPSHEETPAGE) );
  984. psp.dwSize = sizeof(PROPSHEETPAGE);
  985. psp.dwFlags = PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  986. psp.hInstance = g_hInstance;
  987. psp.pszTemplate = MAKEINTRESOURCE(IDD_RSOP_WQLUSER);
  988. psp.pfnDlgProc = RSOPWQLUserDlgProc;
  989. psp.lParam = (LPARAM) this;
  990. psp.pszHeaderTitle = szTitle;
  991. psp.pszHeaderSubTitle = szSubTitle;
  992. hPage = CreatePropertySheetPage(&psp);
  993. if (!hPage)
  994. {
  995. DebugMsg((DM_WARNING, TEXT("CRSOPWizardDlg::CreatePropertyPages: Failed to create property sheet page with %d."),
  996. GetLastError()));
  997. return E_FAIL;
  998. }
  999. hShowNowPages[dwCount] = hPage;
  1000. dwCount++;
  1001. // (11) --- WQLComp ---
  1002. LoadString (g_hInstance, IDS_TITLE_WQLCOMP, szTitle, ARRAYSIZE(szTitle));
  1003. LoadString (g_hInstance, IDS_SUBTITLE_WQL, szSubTitle, ARRAYSIZE(szSubTitle));
  1004. ::memset( &psp, 0, sizeof(PROPSHEETPAGE) );
  1005. psp.dwSize = sizeof(PROPSHEETPAGE);
  1006. psp.dwFlags = PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  1007. psp.hInstance = g_hInstance;
  1008. psp.pszTemplate = MAKEINTRESOURCE(IDD_RSOP_WQLCOMP);
  1009. psp.pfnDlgProc = RSOPWQLCompDlgProc;
  1010. psp.lParam = (LPARAM) this;
  1011. psp.pszHeaderTitle = szTitle;
  1012. psp.pszHeaderSubTitle = szSubTitle;
  1013. hPage = CreatePropertySheetPage(&psp);
  1014. if (!hPage)
  1015. {
  1016. DebugMsg((DM_WARNING, TEXT("CRSOPWizardDlg::CreatePropertyPages: Failed to create property sheet page with %d."),
  1017. GetLastError()));
  1018. return E_FAIL;
  1019. }
  1020. hShowNowPages[dwCount] = hPage;
  1021. dwCount++;
  1022. // (12) --- Finished ---
  1023. LoadString (g_hInstance, IDS_TITLE_FINISHED, szTitle, ARRAYSIZE(szTitle));
  1024. LoadString (g_hInstance, IDS_SUBTITLE_FINISHED, szSubTitle, ARRAYSIZE(szSubTitle));
  1025. ::memset( &psp, 0, sizeof(PROPSHEETPAGE) );
  1026. psp.dwSize = sizeof(PROPSHEETPAGE);
  1027. psp.dwFlags = PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  1028. psp.hInstance = g_hInstance;
  1029. if ( m_pExtendedProcessing != NULL )
  1030. {
  1031. m_lLoggingFinishedPage = IDD_RSOP_FINISHED_INT;
  1032. psp.pszTemplate = MAKEINTRESOURCE(IDD_RSOP_FINISHED_INT);
  1033. }
  1034. else
  1035. {
  1036. m_lLoggingFinishedPage = IDD_RSOP_FINISHED;
  1037. psp.pszTemplate = MAKEINTRESOURCE(IDD_RSOP_FINISHED);
  1038. }
  1039. psp.pfnDlgProc = RSOPFinishedDlgProc;
  1040. psp.lParam = (LPARAM) this;
  1041. psp.pszHeaderTitle = szTitle;
  1042. psp.pszHeaderSubTitle = szSubTitle;
  1043. hPage = CreatePropertySheetPage(&psp);
  1044. if (!hPage)
  1045. {
  1046. DebugMsg((DM_WARNING, TEXT("CRSOPWizardDlg::CreatePropertyPages: Failed to create property sheet page with %d."),
  1047. GetLastError()));
  1048. return E_FAIL;
  1049. }
  1050. hShowNowPages[dwCount] = hPage;
  1051. dwDiagFinishPage = dwCount;
  1052. dwCount++;
  1053. // (13) --- Finished3 ---
  1054. LoadString (g_hInstance, IDS_TITLE_FINISHED, szTitle, ARRAYSIZE(szTitle));
  1055. LoadString (g_hInstance, IDS_SUBTITLE_FINISHED, szSubTitle, ARRAYSIZE(szSubTitle));
  1056. ::memset( &psp, 0, sizeof(PROPSHEETPAGE) );
  1057. psp.dwSize = sizeof(PROPSHEETPAGE);
  1058. psp.dwFlags = PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  1059. psp.hInstance = g_hInstance;
  1060. if ( m_pExtendedProcessing != NULL )
  1061. {
  1062. m_lPlanningFinishedPage = IDD_RSOP_FINISHED3_INT;
  1063. psp.pszTemplate = MAKEINTRESOURCE(IDD_RSOP_FINISHED3_INT);
  1064. }
  1065. else
  1066. {
  1067. m_lPlanningFinishedPage = IDD_RSOP_FINISHED3;
  1068. psp.pszTemplate = MAKEINTRESOURCE(IDD_RSOP_FINISHED3);
  1069. }
  1070. psp.pfnDlgProc = RSOPFinishedDlgProc;
  1071. psp.lParam = (LPARAM) this;
  1072. psp.pszHeaderTitle = szTitle;
  1073. psp.pszHeaderSubTitle = szSubTitle;
  1074. hPage = CreatePropertySheetPage(&psp);
  1075. if (!hPage)
  1076. {
  1077. DebugMsg((DM_WARNING, TEXT("CRSOPWizardDlg::CreatePropertyPages: Failed to create property sheet page with %d."),
  1078. GetLastError()));
  1079. return E_FAIL;
  1080. }
  1081. hShowNowPages[dwCount] = hPage;
  1082. dwPlanFinishPage = dwCount;
  1083. dwCount++;
  1084. // (14) --- Finished2 ---
  1085. ::memset( &psp, 0, sizeof(PROPSHEETPAGE) );
  1086. psp.dwSize = sizeof(PROPSHEETPAGE);
  1087. psp.dwFlags = PSP_HIDEHEADER;
  1088. psp.hInstance = g_hInstance;
  1089. psp.pszTemplate = MAKEINTRESOURCE(IDD_RSOP_FINISHED2);
  1090. psp.pfnDlgProc = RSOPFinished2DlgProc;
  1091. psp.lParam = (LPARAM) this;
  1092. psp.pszHeaderTitle = NULL;
  1093. psp.pszHeaderSubTitle = NULL;
  1094. hPage = CreatePropertySheetPage(&psp);
  1095. if (!hPage)
  1096. {
  1097. DebugMsg((DM_WARNING, TEXT("CRSOPWizardDlg::CreatePropertyPages: Failed to create property sheet page with %d."),
  1098. GetLastError()));
  1099. return E_FAIL;
  1100. }
  1101. hShowNowPages[dwCount] = hPage;
  1102. dwCount++;
  1103. if ( (m_pRSOPQuery->dwFlags & RSOP_FIX_QUERYTYPE) == RSOP_FIX_QUERYTYPE )
  1104. {
  1105. m_bNoChooseQuery = FALSE;
  1106. }
  1107. else
  1108. {
  1109. m_bNoChooseQuery = ((m_pRSOPQuery->dwFlags & RSOP_FIX_COMPUTER) == RSOP_FIX_COMPUTER)
  1110. || ((m_pRSOPQuery->dwFlags & RSOP_FIX_DC) == RSOP_FIX_DC)
  1111. || ((m_pRSOPQuery->dwFlags & RSOP_FIX_SITENAME) == RSOP_FIX_SITENAME)
  1112. || ((m_pRSOPQuery->dwFlags & RSOP_FIX_USER) == RSOP_FIX_USER);
  1113. }
  1114. // ------------------------------
  1115. // Now create the Property Sheet
  1116. INT_PTR iRet;
  1117. PROPSHEETHEADER psph;
  1118. ::memset( &psph, 0, sizeof(PROPSHEETHEADER) );
  1119. psph.dwSize = sizeof(PROPSHEETHEADER);
  1120. psph.dwFlags = PSH_WIZARD97 | PSH_HEADER | PSH_WATERMARK;
  1121. psph.hwndParent = hParent;
  1122. psph.hInstance = g_hInstance;
  1123. psph.nPages = dwCount;
  1124. psph.pszbmHeader = MAKEINTRESOURCE(IDB_HEADER);
  1125. psph.pszbmWatermark = MAKEINTRESOURCE(IDB_WIZARD);
  1126. // if (dwFlags & RSOPMSC_OVERRIDE)
  1127. if ( (m_pRSOPQuery->dwFlags & RSOP_NO_WELCOME) == RSOP_NO_WELCOME )
  1128. {
  1129. // RM: This condition translates to a case where an MSC was loaded but where parameters where passed, overriding
  1130. // the values in the MSC file.
  1131. psph.nStartPage = ( m_pRSOPQuery->QueryType == RSOP_LOGGING_MODE) ? dwDiagStartPage : dwPlanStartPage;
  1132. DebugMsg((DM_VERBOSE, TEXT("CRSOPWizardDlg::CreatePropertyPages: Showing prop sheet in override mode.")));
  1133. }
  1134. psph.phpage = hShowNowPages;
  1135. DebugMsg((DM_VERBOSE, TEXT("CRSOPWizardDlg::CreatePropertyPages: Showing prop sheet.")));
  1136. iRet = PropertySheet(&psph);
  1137. if (iRet == -1) {
  1138. DebugMsg((DM_WARNING, TEXT("CRSOPWizardDlg::CreatePropertyPages: PropertySheet failed with error %d."),
  1139. GetLastError()));
  1140. }
  1141. // user cancelled in the wizard
  1142. if (iRet != IDOK)
  1143. {
  1144. return S_FALSE;
  1145. }
  1146. return m_hrQuery;
  1147. }
  1148. //-------------------------------------------------------
  1149. HRESULT CRSOPWizardDlg::RunQuery( HWND hParent )
  1150. {
  1151. if ( DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_RSOP_STATUSMSC),
  1152. hParent, InitRsopDlgProc, (LPARAM) this ) == -1)
  1153. {
  1154. HRESULT hr = HRESULT_FROM_WIN32( GetLastError() );
  1155. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Falied to create dialog box. 0x%x"), hr));
  1156. return hr;
  1157. }
  1158. return m_hrQuery;
  1159. }
  1160. //-------------------------------------------------------
  1161. // RSOP generation dialog method
  1162. INT_PTR CALLBACK CRSOPWizardDlg::InitRsopDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  1163. {
  1164. HRESULT hr = S_OK;
  1165. TCHAR szMessage[200];
  1166. switch (message)
  1167. {
  1168. case WM_INITDIALOG:
  1169. {
  1170. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg*) lParam;
  1171. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pWizard);
  1172. if (pWizard)
  1173. {
  1174. CRSOPWizard::InitializeResultsList (GetDlgItem (hDlg, IDC_LIST1));
  1175. CRSOPWizard::FillResultsList (GetDlgItem (hDlg, IDC_LIST1), pWizard->m_pRSOPQuery, NULL);
  1176. }
  1177. PostMessage(hDlg, WM_INITRSOP, 0, 0);
  1178. return TRUE;
  1179. }
  1180. case WM_INITRSOP:
  1181. {
  1182. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg*) GetWindowLongPtr (hDlg, DWLP_USER);
  1183. // RM: InitializeRSOP used to be called here, but now we go directly to GenerateRSOPEx
  1184. pWizard->m_hrQuery = CRSOPWizard::GenerateRSOPDataEx(hDlg, pWizard->m_pRSOPQuery, &(pWizard->m_pRSOPQueryResults) );
  1185. if ( pWizard->m_hrQuery != S_OK )
  1186. {
  1187. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitRsopDlgProc: GenerateRSOPEx failed with 0x%x."), hr));
  1188. EndDialog(hDlg, 0);
  1189. return TRUE;
  1190. }
  1191. if ( pWizard->m_pExtendedProcessing != NULL )
  1192. {
  1193. pWizard->m_pExtendedProcessing->DoProcessing( pWizard->m_pRSOPQuery,
  1194. pWizard->m_pRSOPQueryResults,
  1195. pWizard->m_pExtendedProcessing->GetExtendedErrorInfo() );
  1196. }
  1197. EndDialog(hDlg, 1);
  1198. return TRUE;
  1199. }
  1200. }
  1201. return FALSE;
  1202. }
  1203. //-------------------------------------------------------
  1204. INT_PTR CALLBACK CRSOPWizardDlg::RSOPWelcomeDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  1205. {
  1206. switch (message)
  1207. {
  1208. case WM_INITDIALOG:
  1209. {
  1210. TCHAR szDefaultGPO[128];
  1211. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) (((LPPROPSHEETPAGE)lParam)->lParam);
  1212. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pWizard);
  1213. SendMessage(GetDlgItem(hDlg, IDC_RSOP_BIG_BOLD1),
  1214. WM_SETFONT, (WPARAM)pWizard->m_BigBoldFont, (LPARAM)TRUE);
  1215. /*
  1216. if (!pWizard->m_hChooseBitmap)
  1217. {
  1218. pWizard->m_hChooseBitmap = (HBITMAP) LoadImage (g_hInstance,
  1219. MAKEINTRESOURCE(IDB_WIZARD),
  1220. IMAGE_BITMAP, 0, 0,
  1221. LR_DEFAULTCOLOR);
  1222. }
  1223. if (pWizard->m_hChooseBitmap)
  1224. {
  1225. SendDlgItemMessage (hDlg, IDC_BITMAP, STM_SETIMAGE,
  1226. IMAGE_BITMAP, (LPARAM) pWizard->m_hChooseBitmap);
  1227. }
  1228. */
  1229. }
  1230. break;
  1231. case WM_COMMAND:
  1232. {
  1233. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  1234. if (!pWizard)
  1235. {
  1236. break;
  1237. }
  1238. }
  1239. break;
  1240. case WM_NOTIFY:
  1241. {
  1242. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  1243. if (!pWizard)
  1244. {
  1245. break;
  1246. }
  1247. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  1248. switch (((NMHDR FAR*)lParam)->code)
  1249. {
  1250. case PSN_SETACTIVE:
  1251. PropSheet_SetWizButtons (GetParent(hDlg),PSWIZB_NEXT);
  1252. break;
  1253. case PSN_WIZNEXT:
  1254. if ( (pQuery->dwFlags & RSOP_FIX_QUERYTYPE) == RSOP_FIX_QUERYTYPE )
  1255. {
  1256. if ( pQuery->QueryType == RSOP_PLANNING_MODE )
  1257. {
  1258. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_GETTARGET);
  1259. }
  1260. else
  1261. {
  1262. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_GETCOMP);
  1263. }
  1264. return TRUE;
  1265. }
  1266. // otherwise we fall through
  1267. case PSN_RESET:
  1268. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  1269. return TRUE;
  1270. }
  1271. break;
  1272. }
  1273. }
  1274. return FALSE;
  1275. }
  1276. //-------------------------------------------------------
  1277. INT_PTR CALLBACK CRSOPWizardDlg::RSOPChooseModeDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  1278. {
  1279. switch (message)
  1280. {
  1281. case WM_INITDIALOG:
  1282. {
  1283. CRSOPWizardDlg*pWizard = (CRSOPWizardDlg *) (((LPPROPSHEETPAGE)lParam)->lParam);
  1284. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pWizard);
  1285. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  1286. if ( IsStandaloneComputer() || !pWizard->m_bPostXPBuild )
  1287. {
  1288. EnableWindow (GetDlgItem(hDlg, IDC_RADIO1), FALSE);
  1289. CheckRadioButton( hDlg, IDC_RADIO1, IDC_RADIO2, IDC_RADIO2 );
  1290. }
  1291. else if ( pQuery->QueryType == RSOP_PLANNING_MODE )
  1292. {
  1293. CheckRadioButton( hDlg, IDC_RADIO1, IDC_RADIO2, IDC_RADIO1 );
  1294. }
  1295. else
  1296. {
  1297. CheckRadioButton( hDlg, IDC_RADIO1, IDC_RADIO2, IDC_RADIO2 );
  1298. }
  1299. break;
  1300. }
  1301. case WM_NOTIFY:
  1302. {
  1303. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  1304. if (!pWizard)
  1305. {
  1306. break;
  1307. }
  1308. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  1309. switch (((NMHDR FAR*)lParam)->code)
  1310. {
  1311. case PSN_WIZNEXT:
  1312. {
  1313. // First make sure that we do not come back to this page
  1314. pQuery->dwFlags |= RSOP_NO_WELCOME;
  1315. // Now get the right mode
  1316. RSOP_QUERY_TYPE QueryType = RSOP_LOGGING_MODE;
  1317. if (SendMessage(GetDlgItem(hDlg, IDC_RADIO1), BM_GETCHECK, 0, 0))
  1318. {
  1319. QueryType = RSOP_PLANNING_MODE;
  1320. }
  1321. if ( pQuery->QueryType != QueryType )
  1322. {
  1323. // First free any mode related information in the object
  1324. if ( pQuery->QueryType == RSOP_PLANNING_MODE )
  1325. {
  1326. pWizard->FreeUserData();
  1327. pWizard->FreeComputerData();
  1328. }
  1329. ChangeRSOPQueryType( pQuery, QueryType );
  1330. }
  1331. if ( QueryType == RSOP_PLANNING_MODE )
  1332. {
  1333. // Skip to the planning mode pages
  1334. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_GETTARGET);
  1335. return TRUE;
  1336. }
  1337. }
  1338. break;
  1339. case PSN_SETACTIVE:
  1340. PropSheet_SetWizButtons (GetParent(hDlg),PSWIZB_BACK | PSWIZB_NEXT);
  1341. break;
  1342. case PSN_WIZFINISH:
  1343. // fall through
  1344. case PSN_RESET:
  1345. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  1346. return TRUE;
  1347. }
  1348. break;
  1349. }
  1350. }
  1351. return FALSE;
  1352. }
  1353. //-------------------------------------------------------
  1354. INT_PTR CALLBACK CRSOPWizardDlg::RSOPGetCompDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  1355. // RSOP_LOGGING_MODE
  1356. {
  1357. switch (message)
  1358. {
  1359. case WM_INITDIALOG:
  1360. {
  1361. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) (((LPPROPSHEETPAGE)lParam)->lParam);
  1362. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pWizard);
  1363. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  1364. }
  1365. break;
  1366. case WM_COMMAND:
  1367. {
  1368. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  1369. if (!pWizard)
  1370. {
  1371. break;
  1372. }
  1373. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  1374. switch (LOWORD(wParam))
  1375. {
  1376. case IDC_EDIT1:
  1377. if (HIWORD(wParam) == EN_CHANGE)
  1378. {
  1379. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  1380. }
  1381. break;
  1382. case IDC_BUTTON1:
  1383. {
  1384. TCHAR * sz;
  1385. if (ImplementBrowseButton(hDlg, DSOP_FILTER_COMPUTERS,
  1386. DSOP_DOWNLEVEL_FILTER_COMPUTERS,
  1387. DSOP_SCOPE_FLAG_DEFAULT_FILTER_COMPUTERS,
  1388. NULL, sz) == S_OK)
  1389. {
  1390. SetDlgItemText (hDlg, IDC_EDIT1, sz);
  1391. LocalFree( sz );
  1392. }
  1393. }
  1394. break;
  1395. case IDC_RADIO1:
  1396. SetDlgItemText (hDlg, IDC_EDIT1, TEXT(""));
  1397. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON1), FALSE);
  1398. EnableWindow(GetDlgItem(hDlg, IDC_EDIT1), FALSE);
  1399. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  1400. break;
  1401. case IDC_RADIO2:
  1402. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON1), TRUE);
  1403. EnableWindow(GetDlgItem(hDlg, IDC_EDIT1), TRUE);
  1404. SetFocus (GetDlgItem(hDlg, IDC_EDIT1));
  1405. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  1406. break;
  1407. }
  1408. }
  1409. break;
  1410. case WM_REFRESHDISPLAY:
  1411. {
  1412. UINT n;
  1413. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  1414. if (!pWizard)
  1415. {
  1416. break;
  1417. }
  1418. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  1419. DWORD dwWizBack = PSWIZB_BACK;
  1420. if ( pWizard->m_bNoChooseQuery )
  1421. {
  1422. dwWizBack = 0;
  1423. }
  1424. if (IsDlgButtonChecked (hDlg, IDC_RADIO2) == BST_CHECKED)
  1425. {
  1426. n = (UINT) SendMessage(GetDlgItem(hDlg, IDC_EDIT1), WM_GETTEXTLENGTH, 0, 0);
  1427. if (n > 0 )
  1428. {
  1429. PropSheet_SetWizButtons(GetParent(hDlg), dwWizBack | PSWIZB_NEXT);
  1430. }
  1431. else
  1432. {
  1433. PropSheet_SetWizButtons(GetParent(hDlg), dwWizBack);
  1434. }
  1435. }
  1436. else
  1437. {
  1438. PropSheet_SetWizButtons(GetParent(hDlg), dwWizBack | PSWIZB_NEXT);
  1439. }
  1440. }
  1441. break;
  1442. case WM_NOTIFY:
  1443. {
  1444. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg*) GetWindowLongPtr (hDlg, DWLP_USER);
  1445. if (!pWizard)
  1446. {
  1447. break;
  1448. }
  1449. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  1450. switch (((NMHDR FAR*)lParam)->code)
  1451. {
  1452. case PSN_WIZBACK:
  1453. if ( (pQuery->dwFlags & RSOP_FIX_QUERYTYPE) == RSOP_FIX_QUERYTYPE )
  1454. {
  1455. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_WELCOME);
  1456. }
  1457. else
  1458. {
  1459. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_CHOOSEMODE);
  1460. }
  1461. return TRUE;
  1462. case PSN_WIZNEXT:
  1463. {
  1464. LPTSTR szNewComputerName = NULL;
  1465. if (IsDlgButtonChecked (hDlg, IDC_RADIO2) == BST_CHECKED)
  1466. {
  1467. GetControlText(hDlg, IDC_EDIT1, szNewComputerName, TRUE );
  1468. if ( szNewComputerName != NULL )
  1469. {
  1470. TCHAR* szNormalizedComputerName;
  1471. // We need to handle the case where the user enters a name
  1472. // prefixed by '\\'
  1473. szNormalizedComputerName = NormalizedComputerName( szNewComputerName );
  1474. // If we detect the '\\' prefix, we must remove it since this syntax
  1475. // is not recognized by the RSoP provider
  1476. if ( szNormalizedComputerName != szNewComputerName )
  1477. {
  1478. LPTSTR szReplaceComputerName;
  1479. HRESULT hr;
  1480. ULONG ulNoChars;
  1481. ulNoChars = lstrlen(szNormalizedComputerName)+1;
  1482. szReplaceComputerName = (TCHAR*)LocalAlloc( LPTR, ulNoChars * sizeof(TCHAR) );
  1483. if ( szReplaceComputerName != NULL )
  1484. {
  1485. hr = StringCchCopy( szReplaceComputerName, ulNoChars, szNormalizedComputerName );
  1486. ASSERT(SUCCEEDED(hr));
  1487. }
  1488. LocalFree( szNewComputerName );
  1489. szNewComputerName = szReplaceComputerName;
  1490. }
  1491. }
  1492. }
  1493. else
  1494. {
  1495. ULONG ulNoChars = 2;
  1496. HRESULT hr;
  1497. szNewComputerName = (TCHAR*)LocalAlloc( LPTR, ulNoChars * sizeof(TCHAR) );
  1498. if ( szNewComputerName != NULL )
  1499. {
  1500. hr = StringCchCopy( szNewComputerName, ulNoChars, L"." );
  1501. ASSERT(SUCCEEDED(hr));
  1502. }
  1503. }
  1504. BOOL bComputerNameChanged = FALSE;
  1505. if ( pQuery->szComputerName != NULL )
  1506. {
  1507. if ( szNewComputerName && ( lstrcmpi( pQuery->szComputerName, szNewComputerName ) != 0 ) )
  1508. {
  1509. LocalFree( pQuery->szComputerName );
  1510. pQuery->szComputerName = szNewComputerName;
  1511. bComputerNameChanged = TRUE;
  1512. }
  1513. else
  1514. {
  1515. LocalFree( szNewComputerName );
  1516. }
  1517. }
  1518. else
  1519. {
  1520. pQuery->szComputerName = szNewComputerName;
  1521. bComputerNameChanged = TRUE;
  1522. }
  1523. if ( pWizard->TestAndValidateComputer (hDlg) )
  1524. {
  1525. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  1526. if ( ((pQuery->dwFlags & RSOP_FIX_USER) != RSOP_FIX_USER)
  1527. && bComputerNameChanged )
  1528. {
  1529. if ( pQuery->szUserName != NULL )
  1530. {
  1531. LocalFree( pQuery->szUserName );
  1532. pQuery->szUserName = NULL;
  1533. }
  1534. if ( pQuery->szUserSid != NULL )
  1535. {
  1536. LocalFree( pQuery->szUserSid );
  1537. pQuery->szUserSid = NULL;
  1538. }
  1539. }
  1540. }
  1541. else
  1542. {
  1543. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  1544. }
  1545. if (IsDlgButtonChecked (hDlg, IDC_CHECK1) == BST_CHECKED)
  1546. {
  1547. pQuery->dwFlags |= RSOP_NO_COMPUTER_POLICY;
  1548. }
  1549. else
  1550. {
  1551. pQuery->dwFlags = pQuery->dwFlags & (RSOP_NO_COMPUTER_POLICY ^ 0xffffffff);
  1552. }
  1553. }
  1554. return TRUE;
  1555. case PSN_SETACTIVE:
  1556. {
  1557. if ( (pQuery->dwFlags & RSOP_FIX_COMPUTER) == RSOP_FIX_COMPUTER )
  1558. {
  1559. CheckRadioButton( hDlg, IDC_RADIO1, IDC_RADIO2, IDC_RADIO2 );
  1560. EnableWindow( GetDlgItem( hDlg, IDC_RADIO1 ), FALSE );
  1561. SetDlgItemText( hDlg, IDC_EDIT1, pQuery->szComputerName );
  1562. CheckDlgButton (hDlg, IDC_CHECK1, BST_UNCHECKED);
  1563. EnableWindow(GetDlgItem(hDlg, IDC_CHECK1), FALSE);
  1564. }
  1565. else
  1566. {
  1567. if ( (pQuery->szComputerName != NULL) && (lstrcmpi( pQuery->szComputerName, L"." ) != 0) )
  1568. {
  1569. CheckRadioButton( hDlg, IDC_RADIO1, IDC_RADIO2, IDC_RADIO2 );
  1570. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON1), TRUE);
  1571. EnableWindow(GetDlgItem(hDlg, IDC_EDIT1), TRUE);
  1572. SetDlgItemText( hDlg, IDC_EDIT1, pQuery->szComputerName );
  1573. SetFocus (GetDlgItem(hDlg, IDC_EDIT1));
  1574. }
  1575. else
  1576. {
  1577. CheckRadioButton (hDlg, IDC_RADIO1, IDC_RADIO2, IDC_RADIO1);
  1578. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON1), FALSE);
  1579. EnableWindow(GetDlgItem(hDlg, IDC_EDIT1), FALSE);
  1580. SetDlgItemText( hDlg, IDC_EDIT1, _T("") );
  1581. SetFocus (GetDlgItem(hDlg, IDC_RADIO1));
  1582. }
  1583. if ( (pQuery->dwFlags & RSOP_NO_USER_POLICY) == RSOP_NO_USER_POLICY )
  1584. {
  1585. pQuery->dwFlags = pQuery->dwFlags & (RSOP_NO_COMPUTER_POLICY ^ 0xffffffff);
  1586. CheckDlgButton (hDlg, IDC_CHECK1, BST_UNCHECKED);
  1587. EnableWindow(GetDlgItem(hDlg, IDC_CHECK1), FALSE);
  1588. }
  1589. else if ( (pQuery->dwFlags & RSOP_NO_COMPUTER_POLICY) == RSOP_NO_COMPUTER_POLICY )
  1590. {
  1591. CheckDlgButton (hDlg, IDC_CHECK1, BST_CHECKED);
  1592. EnableWindow(GetDlgItem(hDlg, IDC_CHECK1), TRUE);
  1593. }
  1594. else
  1595. {
  1596. CheckDlgButton (hDlg, IDC_CHECK1, BST_UNCHECKED);
  1597. EnableWindow(GetDlgItem(hDlg, IDC_CHECK1), TRUE);
  1598. }
  1599. }
  1600. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  1601. }
  1602. break;
  1603. case PSN_RESET:
  1604. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  1605. return TRUE;
  1606. }
  1607. break;
  1608. }
  1609. }
  1610. return FALSE;
  1611. }
  1612. //-------------------------------------------------------
  1613. INT_PTR CALLBACK CRSOPWizardDlg::RSOPGetUserDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  1614. // RSOP_LOGGING_MODE
  1615. {
  1616. switch (message)
  1617. {
  1618. case WM_INITDIALOG:
  1619. {
  1620. LVCOLUMN lvcol;
  1621. RECT rect;
  1622. HWND hLV = GetDlgItem(hDlg, IDC_LIST1);
  1623. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) (((LPPROPSHEETPAGE)lParam)->lParam);
  1624. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pWizard);
  1625. GetClientRect(hLV, &rect);
  1626. ZeroMemory(&lvcol, sizeof(lvcol));
  1627. lvcol.mask = LVCF_FMT | LVCF_WIDTH;
  1628. lvcol.fmt = LVCFMT_LEFT;
  1629. lvcol.cx = rect.right - GetSystemMetrics(SM_CYHSCROLL);
  1630. ListView_InsertColumn(hLV, 0, &lvcol);
  1631. SendMessage(hLV, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
  1632. LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP);
  1633. }
  1634. break;
  1635. case WM_NOTIFY:
  1636. {
  1637. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  1638. if (!pWizard)
  1639. {
  1640. break;
  1641. }
  1642. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  1643. switch (((NMHDR FAR*)lParam)->code)
  1644. {
  1645. case PSN_WIZNEXT:
  1646. case PSN_WIZBACK:
  1647. {
  1648. LPTSTR lpData;
  1649. HWND hList = GetDlgItem(hDlg, IDC_LIST1);
  1650. INT iSel;
  1651. if ( (pQuery->dwFlags & RSOP_FIX_USER) != RSOP_FIX_USER )
  1652. {
  1653. if ( pQuery->szUserName != NULL )
  1654. {
  1655. LocalFree( pQuery->szUserName );
  1656. pQuery->szUserName = NULL;
  1657. }
  1658. if ( pQuery->szUserSid != NULL )
  1659. {
  1660. LocalFree( pQuery->szUserSid );
  1661. pQuery->szUserSid = NULL;
  1662. }
  1663. if (IsDlgButtonChecked (hDlg, IDC_RADIO4) == BST_CHECKED)
  1664. {
  1665. pQuery->dwFlags |= RSOP_NO_USER_POLICY;
  1666. }
  1667. else
  1668. {
  1669. pQuery->dwFlags = pQuery->dwFlags & (RSOP_NO_USER_POLICY ^ 0xffffffff);
  1670. if (IsDlgButtonChecked (hDlg, IDC_RADIO1))
  1671. {
  1672. LPTSTR lpTemp;
  1673. if ( IsStandaloneComputer() )
  1674. {
  1675. pQuery->szUserName = MyGetUserName (NameUnknown);
  1676. }
  1677. else
  1678. {
  1679. pQuery->szUserName = MyGetUserName (NameSamCompatible);
  1680. }
  1681. HRESULT hr;
  1682. ULONG ulNoChars = 2;
  1683. pQuery->szUserSid = (TCHAR*)LocalAlloc( LPTR, ulNoChars * sizeof(TCHAR) );
  1684. if ( pQuery->szUserSid != NULL )
  1685. {
  1686. hr = StringCchCopy( pQuery->szUserSid, ulNoChars, TEXT(".") );
  1687. ASSERT(SUCCEEDED(hr));
  1688. }
  1689. }
  1690. else
  1691. {
  1692. iSel = (INT) SendMessage(hList, LVM_GETNEXTITEM, (WPARAM) -1, MAKELPARAM(LVNI_SELECTED, 0));
  1693. if (iSel != -1)
  1694. {
  1695. pQuery->szUserName = (TCHAR*)LocalAlloc( LPTR, 200 * sizeof(TCHAR) );
  1696. if ( pQuery->szUserName != NULL )
  1697. {
  1698. LVITEM item;
  1699. ZeroMemory (&item, sizeof(item));
  1700. item.mask = LVIF_TEXT | LVIF_PARAM;
  1701. item.iItem = iSel;
  1702. item.pszText = pQuery->szUserName;
  1703. item.cchTextMax = 200;
  1704. if (SendMessage(hList, LVM_GETITEM, 0, (LPARAM) &item))
  1705. {
  1706. lpData = (LPTSTR) item.lParam;
  1707. if (lpData)
  1708. {
  1709. ULONG ulNoChars;
  1710. HRESULT hr;
  1711. ulNoChars = lstrlen(lpData) + 1;
  1712. pQuery->szUserSid = (TCHAR*)LocalAlloc( LPTR, ulNoChars * sizeof(TCHAR) );
  1713. if ( pQuery->szUserSid != NULL )
  1714. {
  1715. hr = StringCchCopy( pQuery->szUserSid, ulNoChars, lpData );
  1716. ASSERT(SUCCEEDED(hr));
  1717. }
  1718. }
  1719. }
  1720. }
  1721. }
  1722. } // if (IsDlgButtonChecked (hDlg, IDC_RADIO1))
  1723. }
  1724. }
  1725. if ( ((NMHDR FAR*)lParam)->code == PSN_WIZNEXT )
  1726. {
  1727. // Skip to the last page in the wizard
  1728. SetWindowLong(hDlg, DWLP_MSGRESULT, pWizard->m_lLoggingFinishedPage);
  1729. return TRUE;
  1730. }
  1731. }
  1732. break;
  1733. case PSN_SETACTIVE:
  1734. {
  1735. HRESULT hr;
  1736. BOOL bFixedUserFound;
  1737. BOOL bCurrentUserFound;
  1738. HWND hList = GetDlgItem(hDlg, IDC_LIST1);
  1739. SendMessage(hList, LVM_DELETEALLITEMS, 0 ,0);
  1740. PropSheet_SetWizButtons (GetParent(hDlg),PSWIZB_BACK | PSWIZB_NEXT);
  1741. hr = pWizard->FillUserList (hList, &bCurrentUserFound, &bFixedUserFound);
  1742. if ( FAILED(hr) )
  1743. {
  1744. ReportError (hDlg, hr, IDS_ENUMUSERSFAILED);
  1745. // RsopEnumerateUsers failed. It should be safe to disable user policy setting in all cases
  1746. pQuery->dwFlags |= RSOP_NO_USER_POLICY;
  1747. EnableWindow (GetDlgItem(hDlg, IDC_RADIO1), FALSE);
  1748. EnableWindow (GetDlgItem(hDlg, IDC_RADIO2), FALSE);
  1749. CheckRadioButton(hDlg, IDC_RADIO3, IDC_RADIO4, IDC_RADIO4);
  1750. EnableWindow (GetDlgItem(hDlg, IDC_RADIO3), FALSE);
  1751. }
  1752. else if ( (pQuery->dwFlags & RSOP_FIX_USER) == RSOP_FIX_USER )
  1753. {
  1754. if ( bFixedUserFound )
  1755. {
  1756. // Disable current user radio button
  1757. CheckRadioButton (hDlg, IDC_RADIO1, IDC_RADIO2, IDC_RADIO2);
  1758. EnableWindow (GetDlgItem(hDlg, IDC_RADIO1), FALSE);
  1759. CheckRadioButton(hDlg, IDC_RADIO3, IDC_RADIO4, IDC_RADIO3);
  1760. EnableWindow (GetDlgItem(hDlg, IDC_RADIO4), FALSE);
  1761. }
  1762. else
  1763. {
  1764. EnableWindow (GetDlgItem(hDlg, IDC_RADIO1), FALSE);
  1765. EnableWindow (GetDlgItem(hDlg, IDC_RADIO2), FALSE);
  1766. CheckRadioButton(hDlg, IDC_RADIO3, IDC_RADIO4, IDC_RADIO4);
  1767. EnableWindow (GetDlgItem(hDlg, IDC_RADIO3), FALSE);
  1768. }
  1769. }
  1770. else
  1771. {
  1772. // If there is no computer policy, then we should at least have user policy, so disable
  1773. if ( (pQuery->dwFlags & RSOP_NO_COMPUTER_POLICY) == RSOP_NO_COMPUTER_POLICY )
  1774. {
  1775. pQuery->dwFlags = pQuery->dwFlags & (RSOP_NO_USER_POLICY ^ 0xffffffff);
  1776. CheckRadioButton(hDlg, IDC_RADIO3, IDC_RADIO4, IDC_RADIO3);
  1777. EnableWindow (GetDlgItem(hDlg, IDC_RADIO4), FALSE);
  1778. }
  1779. else if ( ((pQuery->dwFlags & RSOP_NO_USER_POLICY) == RSOP_NO_USER_POLICY)
  1780. || (ListView_GetItemCount (hList) == 0) )
  1781. {
  1782. CheckRadioButton(hDlg, IDC_RADIO3, IDC_RADIO4, IDC_RADIO4);
  1783. }
  1784. else
  1785. {
  1786. CheckRadioButton(hDlg, IDC_RADIO3, IDC_RADIO4, IDC_RADIO3);
  1787. }
  1788. if ( (!lstrcmpi( pQuery->szComputerName, TEXT("."))) && bCurrentUserFound )
  1789. {
  1790. pWizard->m_bNoCurrentUser = FALSE;
  1791. }
  1792. else
  1793. {
  1794. pWizard->m_bNoCurrentUser = TRUE;
  1795. }
  1796. if ( (pQuery->szUserSid != NULL)
  1797. && !lstrcmpi( pQuery->szUserSid, TEXT("."))
  1798. && !pWizard->m_bNoCurrentUser )
  1799. {
  1800. CheckRadioButton (hDlg, IDC_RADIO1, IDC_RADIO2, IDC_RADIO1);
  1801. }
  1802. else if ( (pQuery->szUserSid == NULL) && !pWizard->m_bNoCurrentUser )
  1803. {
  1804. CheckRadioButton (hDlg, IDC_RADIO1, IDC_RADIO2, IDC_RADIO1);
  1805. }
  1806. else if ( ListView_GetItemCount (hList) != 0 )
  1807. {
  1808. CheckRadioButton (hDlg, IDC_RADIO1, IDC_RADIO2, IDC_RADIO2);
  1809. if ( pQuery->szUserName != NULL )
  1810. {
  1811. LVFINDINFO FindInfo;
  1812. LVITEM item;
  1813. INT iRet;
  1814. ZeroMemory (&FindInfo, sizeof(FindInfo));
  1815. FindInfo.flags = LVFI_STRING;
  1816. FindInfo.psz = pQuery->szUserName;
  1817. iRet = (INT) SendMessage (hList, LVM_FINDITEM,
  1818. (WPARAM) -1, (LPARAM) &FindInfo);
  1819. if (iRet != -1)
  1820. {
  1821. ZeroMemory (&item, sizeof(item));
  1822. item.mask = LVIF_STATE;
  1823. item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  1824. SendMessage (hList, LVM_SETITEMSTATE, (WPARAM) -1, (LPARAM) &item);
  1825. ZeroMemory (&item, sizeof(item));
  1826. item.mask = LVIF_STATE;
  1827. item.iItem = iRet;
  1828. item.state = LVIS_SELECTED | LVIS_FOCUSED;
  1829. item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  1830. SendMessage (hList, LVM_SETITEMSTATE, (WPARAM) iRet, (LPARAM) &item);
  1831. }
  1832. }
  1833. }
  1834. else
  1835. {
  1836. EnableWindow (GetDlgItem(hDlg, IDC_RADIO1), FALSE);
  1837. EnableWindow (GetDlgItem(hDlg, IDC_RADIO2), FALSE);
  1838. CheckRadioButton(hDlg, IDC_RADIO3, IDC_RADIO4, IDC_RADIO4);
  1839. EnableWindow (GetDlgItem(hDlg, IDC_RADIO3), FALSE);
  1840. }
  1841. }
  1842. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  1843. }
  1844. break;
  1845. case PSN_RESET:
  1846. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  1847. return TRUE;
  1848. case LVN_DELETEITEM:
  1849. {
  1850. NMLISTVIEW * pNMListView = (NMLISTVIEW *) lParam;
  1851. if (pNMListView && pNMListView->lParam)
  1852. {
  1853. delete [] ((LPTSTR)pNMListView->lParam);
  1854. }
  1855. }
  1856. break;
  1857. }
  1858. }
  1859. break;
  1860. case WM_COMMAND:
  1861. {
  1862. switch (LOWORD(wParam))
  1863. {
  1864. case IDC_RADIO1:
  1865. CheckRadioButton(hDlg, IDC_RADIO3, IDC_RADIO4, IDC_RADIO3);
  1866. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  1867. break;
  1868. case IDC_RADIO2:
  1869. CheckRadioButton(hDlg, IDC_RADIO3, IDC_RADIO4, IDC_RADIO3);
  1870. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  1871. break;
  1872. case IDC_RADIO3:
  1873. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  1874. break;
  1875. case IDC_RADIO4:
  1876. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  1877. break;
  1878. }
  1879. }
  1880. break;
  1881. case WM_REFRESHDISPLAY:
  1882. {
  1883. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  1884. if (!pWizard)
  1885. {
  1886. break;
  1887. }
  1888. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  1889. if ( (pQuery->dwFlags & RSOP_FIX_USER) == RSOP_FIX_USER )
  1890. {
  1891. break;
  1892. }
  1893. int iListCount = ListView_GetItemCount(GetDlgItem(hDlg, IDC_LIST1));
  1894. if (IsDlgButtonChecked (hDlg, IDC_RADIO4) == BST_CHECKED)
  1895. {
  1896. // Disable list of users while "Do not display user policy" radio is selected
  1897. EnableWindow(GetDlgItem(hDlg, IDC_LIST1), FALSE);
  1898. EnableWindow(GetDlgItem(hDlg, IDC_RADIO1), FALSE);
  1899. EnableWindow(GetDlgItem(hDlg, IDC_RADIO2), FALSE);
  1900. if ( pWizard->m_bNoCurrentUser && (iListCount == 0)
  1901. && ( (pQuery->dwFlags & RSOP_NO_COMPUTER_POLICY) == RSOP_NO_COMPUTER_POLICY ) )
  1902. {
  1903. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK);
  1904. }
  1905. else
  1906. {
  1907. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK | PSWIZB_NEXT);
  1908. }
  1909. }
  1910. else
  1911. {
  1912. // Enable/disable inner radio buttons
  1913. EnableWindow(GetDlgItem(hDlg, IDC_RADIO1), !pWizard->m_bNoCurrentUser);
  1914. EnableWindow(GetDlgItem(hDlg, IDC_RADIO2), iListCount != 0);
  1915. if ( !pWizard->m_bNoCurrentUser || (iListCount != 0) )
  1916. {
  1917. if ( (pQuery->dwFlags & RSOP_NO_COMPUTER_POLICY) == RSOP_NO_COMPUTER_POLICY )
  1918. {
  1919. pQuery->dwFlags = pQuery->dwFlags & (RSOP_NO_USER_POLICY ^ 0xffffffff);
  1920. EnableWindow (GetDlgItem(hDlg, IDC_RADIO4), FALSE);
  1921. }
  1922. else
  1923. {
  1924. EnableWindow (GetDlgItem(hDlg, IDC_RADIO4), TRUE);
  1925. }
  1926. if (IsDlgButtonChecked (hDlg, IDC_RADIO2) == BST_CHECKED)
  1927. {
  1928. EnableWindow(GetDlgItem(hDlg, IDC_LIST1), TRUE);
  1929. if ( iListCount != 0 )
  1930. {
  1931. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK | PSWIZB_NEXT);
  1932. SetFocus (GetDlgItem(hDlg, IDC_LIST1));
  1933. }
  1934. else
  1935. {
  1936. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK);
  1937. }
  1938. }
  1939. else
  1940. {
  1941. EnableWindow(GetDlgItem(hDlg, IDC_LIST1), FALSE);
  1942. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK | PSWIZB_NEXT);
  1943. }
  1944. }
  1945. else
  1946. {
  1947. if ( (pQuery->dwFlags & RSOP_NO_COMPUTER_POLICY) == RSOP_NO_COMPUTER_POLICY )
  1948. {
  1949. // If the user said no computer data but he has access to no users,
  1950. // enable on back button and disable the checkbox
  1951. pQuery->dwFlags = pQuery->dwFlags & (RSOP_NO_USER_POLICY ^ 0xffffffff);
  1952. CheckRadioButton(hDlg, IDC_RADIO3, IDC_RADIO4, IDC_RADIO3);
  1953. EnableWindow (GetDlgItem(hDlg, IDC_RADIO4), FALSE);
  1954. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK);
  1955. }
  1956. else
  1957. {
  1958. // This is an error condition where ::FillUserList failed
  1959. EnableWindow(GetDlgItem(hDlg, IDC_LIST1), FALSE);
  1960. CheckRadioButton(hDlg, IDC_RADIO3, IDC_RADIO4, IDC_RADIO4);
  1961. EnableWindow (GetDlgItem(hDlg, IDC_RADIO3), FALSE);
  1962. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK | PSWIZB_NEXT);
  1963. }
  1964. }
  1965. }
  1966. }
  1967. break;
  1968. }
  1969. return FALSE;
  1970. }
  1971. //-------------------------------------------------------
  1972. INT_PTR CALLBACK CRSOPWizardDlg::RSOPGetTargetDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  1973. // RSOP_PLANNING_MODE
  1974. {
  1975. switch (message)
  1976. {
  1977. case WM_INITDIALOG:
  1978. {
  1979. LPTSTR lpText, lpPath;
  1980. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg*) (((LPPROPSHEETPAGE)lParam)->lParam);
  1981. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pWizard);
  1982. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  1983. if ( pWizard != NULL )
  1984. {
  1985. lpText = MyGetUserName(NameSamCompatible);
  1986. if (lpText)
  1987. {
  1988. SetDlgItemText (hDlg, IDC_EDIT6, lpText);
  1989. LocalFree (lpText);
  1990. }
  1991. lpText = MyGetUserName(NameFullyQualifiedDN);
  1992. if (lpText)
  1993. {
  1994. lpPath = pWizard->GetDefaultSOM(lpText);
  1995. if (lpPath)
  1996. {
  1997. SetDlgItemText (hDlg, IDC_EDIT5, lpPath);
  1998. delete [] lpPath;
  1999. }
  2000. LocalFree (lpText);
  2001. }
  2002. }
  2003. }
  2004. break;
  2005. case WM_COMMAND:
  2006. {
  2007. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  2008. if (!pWizard)
  2009. {
  2010. break;
  2011. }
  2012. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  2013. switch (LOWORD(wParam))
  2014. {
  2015. case IDC_RADIO1:
  2016. EnableWindow (GetDlgItem (hDlg, IDC_EDIT1), TRUE);
  2017. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE1), TRUE);
  2018. if ( pQuery->pUser->szSOM != NULL )
  2019. {
  2020. SetDlgItemText( hDlg, IDC_EDIT1, pQuery->pUser->szSOM );
  2021. }
  2022. SetDlgItemText (hDlg, IDC_EDIT2, TEXT(""));
  2023. EnableWindow (GetDlgItem (hDlg, IDC_EDIT2), FALSE);
  2024. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE2), FALSE);
  2025. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  2026. break;
  2027. case IDC_RADIO2:
  2028. EnableWindow (GetDlgItem (hDlg, IDC_EDIT2), TRUE);
  2029. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE2), TRUE);
  2030. if ( pQuery->pUser->szName != NULL )
  2031. {
  2032. SetDlgItemText( hDlg, IDC_EDIT2, pQuery->pUser->szName );
  2033. }
  2034. SetDlgItemText (hDlg, IDC_EDIT1, TEXT(""));
  2035. EnableWindow (GetDlgItem (hDlg, IDC_EDIT1), FALSE);
  2036. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE1), FALSE);
  2037. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  2038. break;
  2039. case IDC_RADIO3:
  2040. EnableWindow (GetDlgItem (hDlg, IDC_EDIT3), TRUE);
  2041. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE3), TRUE);
  2042. if ( pQuery->pComputer->szSOM != NULL )
  2043. {
  2044. SetDlgItemText( hDlg, IDC_EDIT3, pQuery->pComputer->szSOM );
  2045. }
  2046. SetDlgItemText (hDlg, IDC_EDIT4, TEXT(""));
  2047. EnableWindow (GetDlgItem (hDlg, IDC_EDIT4), FALSE);
  2048. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE4), FALSE);
  2049. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  2050. break;
  2051. case IDC_RADIO4:
  2052. EnableWindow (GetDlgItem (hDlg, IDC_EDIT4), TRUE);
  2053. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE4), TRUE);
  2054. if ( pQuery->pComputer->szName != NULL )
  2055. {
  2056. // RM: The computer name account in the DS actually has a '$' at the end. We strip it here for display
  2057. // purposes, but will add it again ...
  2058. if ( (wcslen(pQuery->pComputer->szName) >= 1)
  2059. && (pQuery->pComputer->szName[wcslen(pQuery->pComputer->szName)-1] == L'$') )
  2060. {
  2061. pWizard->m_bDollarRemoved = TRUE;
  2062. pQuery->pComputer->szName[wcslen(pQuery->pComputer->szName)-1] = L'\0';
  2063. }
  2064. SetDlgItemText(hDlg, IDC_EDIT4, pQuery->pComputer->szName );
  2065. if ( pWizard->m_bDollarRemoved )
  2066. {
  2067. pQuery->pComputer->szName[wcslen(pQuery->pComputer->szName)] = L'$';
  2068. pWizard->m_bDollarRemoved = FALSE;
  2069. }
  2070. }
  2071. SetDlgItemText (hDlg, IDC_EDIT3, TEXT(""));
  2072. EnableWindow (GetDlgItem (hDlg, IDC_EDIT3), FALSE);
  2073. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE3), FALSE);
  2074. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  2075. break;
  2076. case IDC_EDIT1:
  2077. case IDC_EDIT2:
  2078. case IDC_EDIT3:
  2079. case IDC_EDIT4:
  2080. if (HIWORD(wParam) == EN_CHANGE)
  2081. {
  2082. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  2083. }
  2084. break;
  2085. case IDC_BROWSE1:
  2086. {
  2087. DSBROWSEINFO dsbi = {0};
  2088. TCHAR *szResult;
  2089. TCHAR szTitle[256];
  2090. TCHAR szCaption[256];
  2091. dsbi.hwndOwner = hDlg;
  2092. dsbi.pszCaption = szTitle;
  2093. dsbi.pszTitle = szCaption;
  2094. dsbi.cbStruct = sizeof(dsbi);
  2095. dsbi.dwFlags = DSBI_ENTIREDIRECTORY;
  2096. dsbi.pfnCallback = DsBrowseCallback;
  2097. szResult = (LPTSTR)LocalAlloc(LPTR, sizeof(TCHAR)*4000);
  2098. if (szResult) {
  2099. dsbi.pszPath = szResult;
  2100. dsbi.cchPath = 4000;
  2101. LoadString(g_hInstance,
  2102. IDS_BROWSE_USER_OU_TITLE,
  2103. szTitle,
  2104. ARRAYSIZE(szTitle));
  2105. LoadString(g_hInstance,
  2106. IDS_BROWSE_USER_OU_CAPTION,
  2107. szCaption,
  2108. ARRAYSIZE(szCaption));
  2109. if (IDOK == DsBrowseForContainer(&dsbi))
  2110. {
  2111. LPWSTR szDN;
  2112. HRESULT hr;
  2113. // skipping 7 chars for LDAP:// in the szResult
  2114. hr = UnEscapeLdapPath(szResult+7, &szDN);
  2115. if (FAILED(hr))
  2116. {
  2117. ReportError (hDlg, hr, IDS_NOUSERCONTAINER);
  2118. }
  2119. else {
  2120. SetDlgItemText(hDlg, IDC_EDIT1, szDN);
  2121. LocalFree(szDN);
  2122. }
  2123. }
  2124. LocalFree(szResult);
  2125. }
  2126. }
  2127. break;
  2128. case IDC_BROWSE2:
  2129. {
  2130. TCHAR * sz;
  2131. if (ImplementBrowseButton(hDlg, DSOP_FILTER_USERS,
  2132. DSOP_DOWNLEVEL_FILTER_USERS,
  2133. DSOP_SCOPE_FLAG_DEFAULT_FILTER_USERS,
  2134. NULL, sz) == S_OK)
  2135. {
  2136. SetDlgItemText (hDlg, IDC_EDIT2, sz);
  2137. LocalFree( sz );
  2138. }
  2139. }
  2140. break;
  2141. case IDC_BROWSE3:
  2142. {
  2143. DSBROWSEINFO dsbi = {0};
  2144. TCHAR *szResult;
  2145. TCHAR szTitle[256];
  2146. TCHAR szCaption[256];
  2147. dsbi.hwndOwner = hDlg;
  2148. dsbi.pszCaption = szTitle;
  2149. dsbi.pszTitle = szCaption;
  2150. dsbi.cbStruct = sizeof(dsbi);
  2151. dsbi.dwFlags = DSBI_ENTIREDIRECTORY;
  2152. dsbi.pfnCallback = DsBrowseCallback;
  2153. szResult = (LPTSTR)LocalAlloc(LPTR, sizeof(TCHAR)*4000);
  2154. if (szResult) {
  2155. dsbi.pszPath = szResult;
  2156. dsbi.cchPath = 4000;
  2157. LoadString(g_hInstance,
  2158. IDS_BROWSE_COMPUTER_OU_TITLE,
  2159. szTitle,
  2160. ARRAYSIZE(szTitle));
  2161. LoadString(g_hInstance,
  2162. IDS_BROWSE_COMPUTER_OU_CAPTION,
  2163. szCaption,
  2164. ARRAYSIZE(szCaption));
  2165. if (IDOK == DsBrowseForContainer(&dsbi))
  2166. {
  2167. LPWSTR szDN;
  2168. HRESULT hr;
  2169. // skipping 7 chars for LDAP:// in the szResult
  2170. hr = UnEscapeLdapPath(szResult+7, &szDN);
  2171. if (FAILED(hr))
  2172. {
  2173. ReportError (hDlg, hr, IDS_NOCOMPUTERCONTAINER);
  2174. }
  2175. else {
  2176. SetDlgItemText(hDlg, IDC_EDIT3, szDN);
  2177. LocalFree(szDN);
  2178. }
  2179. }
  2180. LocalFree(szResult);
  2181. }
  2182. }
  2183. break;
  2184. case IDC_BROWSE4:
  2185. {
  2186. TCHAR * sz;
  2187. if (ImplementBrowseButton(hDlg, DSOP_FILTER_COMPUTERS,
  2188. DSOP_DOWNLEVEL_FILTER_COMPUTERS,
  2189. DSOP_SCOPE_FLAG_DEFAULT_FILTER_COMPUTERS,
  2190. NULL, sz) == S_OK)
  2191. {
  2192. SetDlgItemText (hDlg, IDC_EDIT4, sz);
  2193. LocalFree( sz );
  2194. }
  2195. }
  2196. break;
  2197. }
  2198. }
  2199. break;
  2200. case WM_REFRESHDISPLAY:
  2201. {
  2202. UINT n;
  2203. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg*) GetWindowLongPtr (hDlg, DWLP_USER);
  2204. if (!pWizard)
  2205. {
  2206. break;
  2207. }
  2208. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  2209. n = (UINT) SendMessage(GetDlgItem(hDlg, IDC_EDIT1), WM_GETTEXTLENGTH, 0, 0);
  2210. if (n == 0)
  2211. {
  2212. n = (UINT) SendMessage(GetDlgItem(hDlg, IDC_EDIT2), WM_GETTEXTLENGTH, 0, 0);
  2213. }
  2214. if (n == 0)
  2215. {
  2216. n = (UINT) SendMessage(GetDlgItem(hDlg, IDC_EDIT3), WM_GETTEXTLENGTH, 0, 0);
  2217. }
  2218. if (n == 0)
  2219. {
  2220. n = (UINT) SendMessage(GetDlgItem(hDlg, IDC_EDIT4), WM_GETTEXTLENGTH, 0, 0);
  2221. }
  2222. DWORD dwWizBack = PSWIZB_BACK;
  2223. if ( pWizard->m_bNoChooseQuery )
  2224. {
  2225. dwWizBack = 0;
  2226. }
  2227. if (n > 0 )
  2228. {
  2229. PropSheet_SetWizButtons(GetParent(hDlg), dwWizBack | PSWIZB_NEXT);
  2230. }
  2231. else
  2232. {
  2233. PropSheet_SetWizButtons(GetParent(hDlg), dwWizBack);
  2234. }
  2235. }
  2236. break;
  2237. case WM_NOTIFY:
  2238. {
  2239. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  2240. if (!pWizard)
  2241. {
  2242. break;
  2243. }
  2244. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  2245. switch (((NMHDR FAR*)lParam)->code)
  2246. {
  2247. case PSN_SETACTIVE:
  2248. {
  2249. // RM: Fill dialog with current user values
  2250. if ( pQuery->pUser->szName != NULL )
  2251. {
  2252. CheckDlgButton (hDlg, IDC_RADIO2, BST_CHECKED);
  2253. SetDlgItemText(hDlg, IDC_EDIT2, pQuery->pUser->szName);
  2254. EnableWindow (GetDlgItem (hDlg, IDC_EDIT2), TRUE);
  2255. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE2), TRUE);
  2256. CheckDlgButton (hDlg, IDC_RADIO1, BST_UNCHECKED);
  2257. SetDlgItemText(hDlg, IDC_EDIT1, _T(""));
  2258. EnableWindow (GetDlgItem (hDlg, IDC_EDIT1), FALSE);
  2259. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE1), FALSE);
  2260. }
  2261. else if ( pQuery->pUser->szSOM != NULL )
  2262. {
  2263. CheckDlgButton (hDlg, IDC_RADIO1, BST_CHECKED);
  2264. SetDlgItemText(hDlg, IDC_EDIT1, pQuery->pUser->szSOM);
  2265. EnableWindow (GetDlgItem (hDlg, IDC_EDIT1), TRUE);
  2266. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE1), TRUE);
  2267. CheckDlgButton (hDlg, IDC_RADIO2, BST_UNCHECKED);
  2268. SetDlgItemText(hDlg, IDC_EDIT2, _T(""));
  2269. EnableWindow (GetDlgItem (hDlg, IDC_EDIT2), FALSE);
  2270. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE2), FALSE);
  2271. }
  2272. else
  2273. {
  2274. CheckDlgButton (hDlg, IDC_RADIO1, BST_CHECKED);
  2275. SetDlgItemText(hDlg, IDC_EDIT1, _T(""));
  2276. EnableWindow (GetDlgItem (hDlg, IDC_EDIT1), TRUE);
  2277. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE1), TRUE);
  2278. CheckDlgButton (hDlg, IDC_RADIO2, BST_UNCHECKED);
  2279. SetDlgItemText(hDlg, IDC_EDIT2, _T(""));
  2280. EnableWindow (GetDlgItem (hDlg, IDC_EDIT2), FALSE);
  2281. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE2), FALSE);
  2282. }
  2283. // Disable certain items if the user must remain fixed
  2284. if ( (pQuery->dwFlags & RSOP_FIX_USER) == RSOP_FIX_USER )
  2285. {
  2286. EnableWindow (GetDlgItem (hDlg, IDC_RADIO1), FALSE);
  2287. EnableWindow (GetDlgItem (hDlg, IDC_RADIO2), FALSE);
  2288. if ( pQuery->pUser->szName != NULL )
  2289. {
  2290. EnableWindow (GetDlgItem (hDlg, IDC_EDIT2), FALSE);
  2291. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE2), FALSE);
  2292. }
  2293. else if ( pQuery->pUser->szSOM != NULL )
  2294. {
  2295. EnableWindow (GetDlgItem (hDlg, IDC_EDIT1), FALSE);
  2296. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE1), FALSE);
  2297. }
  2298. }
  2299. // RM: Fill dialog with current computer values
  2300. if ( pQuery->pComputer->szName != NULL )
  2301. {
  2302. CheckDlgButton (hDlg, IDC_RADIO4, BST_CHECKED);
  2303. // RM: The computer name account in the DS actually has a '$' at the end. We strip it here for display
  2304. // purposes, but will add it again ...
  2305. if ( (wcslen(pQuery->pComputer->szName) >= 1)
  2306. && (pQuery->pComputer->szName[wcslen(pQuery->pComputer->szName)-1] == L'$') )
  2307. {
  2308. pWizard->m_bDollarRemoved = TRUE;
  2309. pQuery->pComputer->szName[wcslen(pQuery->pComputer->szName)-1] = L'\0';
  2310. }
  2311. SetDlgItemText(hDlg, IDC_EDIT4, pQuery->pComputer->szName );
  2312. if ( pWizard->m_bDollarRemoved )
  2313. {
  2314. pQuery->pComputer->szName[wcslen(pQuery->pComputer->szName)] = L'$';
  2315. pWizard->m_bDollarRemoved = FALSE;
  2316. }
  2317. EnableWindow (GetDlgItem (hDlg, IDC_EDIT4), TRUE);
  2318. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE4), TRUE);
  2319. CheckDlgButton (hDlg, IDC_RADIO3, BST_UNCHECKED);
  2320. SetDlgItemText(hDlg, IDC_EDIT3, _T(""));
  2321. EnableWindow (GetDlgItem (hDlg, IDC_EDIT3), FALSE);
  2322. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE3), FALSE);
  2323. }
  2324. else if ( pQuery->pComputer->szSOM != NULL )
  2325. {
  2326. CheckDlgButton (hDlg, IDC_RADIO3, BST_CHECKED);
  2327. SetDlgItemText(hDlg, IDC_EDIT3, pQuery->pComputer->szSOM);
  2328. EnableWindow (GetDlgItem (hDlg, IDC_EDIT3), TRUE);
  2329. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE3), TRUE);
  2330. CheckDlgButton (hDlg, IDC_RADIO4, BST_UNCHECKED);
  2331. SetDlgItemText(hDlg, IDC_EDIT4, _T(""));
  2332. EnableWindow (GetDlgItem (hDlg, IDC_EDIT4), FALSE);
  2333. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE4), FALSE);
  2334. }
  2335. else
  2336. {
  2337. CheckDlgButton (hDlg, IDC_RADIO3, BST_CHECKED);
  2338. SetDlgItemText(hDlg, IDC_EDIT3, _T(""));
  2339. EnableWindow (GetDlgItem (hDlg, IDC_EDIT3), TRUE);
  2340. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE3), TRUE);
  2341. CheckDlgButton (hDlg, IDC_RADIO4, BST_UNCHECKED);
  2342. SetDlgItemText(hDlg, IDC_EDIT4, _T(""));
  2343. EnableWindow (GetDlgItem (hDlg, IDC_EDIT4), FALSE);
  2344. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE4), FALSE);
  2345. }
  2346. // Disable certain items if the computer must remain fixed
  2347. if ( (pQuery->dwFlags & RSOP_FIX_COMPUTER) == RSOP_FIX_COMPUTER )
  2348. {
  2349. EnableWindow (GetDlgItem (hDlg, IDC_RADIO3), FALSE);
  2350. EnableWindow (GetDlgItem (hDlg, IDC_RADIO4), FALSE);
  2351. if ( pQuery->pComputer->szName != NULL )
  2352. {
  2353. EnableWindow (GetDlgItem (hDlg, IDC_EDIT4), FALSE);
  2354. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE4), FALSE);
  2355. }
  2356. else if ( pQuery->pComputer->szSOM != NULL )
  2357. {
  2358. EnableWindow (GetDlgItem (hDlg, IDC_EDIT3), FALSE);
  2359. EnableWindow (GetDlgItem (hDlg, IDC_BROWSE3), FALSE);
  2360. }
  2361. }
  2362. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  2363. }
  2364. break;
  2365. case PSN_WIZBACK:
  2366. if ( (pQuery->dwFlags & RSOP_FIX_QUERYTYPE) == RSOP_FIX_QUERYTYPE )
  2367. {
  2368. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_WELCOME);
  2369. }
  2370. else
  2371. {
  2372. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_CHOOSEMODE);
  2373. }
  2374. return TRUE;
  2375. case PSN_WIZNEXT:
  2376. {
  2377. HRESULT hr;
  2378. IDirectoryObject * pUserObject = NULL;
  2379. IDirectoryObject * pComputerObject = NULL;
  2380. LPTSTR lpUserName = NULL, lpUserSOM = NULL;
  2381. LPTSTR lpComputerName = NULL, lpComputerSOM = NULL;
  2382. LPTSTR lpFullName;
  2383. BOOL bUserChanged = TRUE;
  2384. BOOL bComputerChanged = TRUE;
  2385. SetWaitCursor();
  2386. // Get the user and dn name
  2387. if (IsDlgButtonChecked(hDlg, IDC_RADIO1) == BST_CHECKED)
  2388. {
  2389. GetControlText(hDlg, IDC_EDIT1, lpUserSOM, FALSE);
  2390. if (lpUserSOM)
  2391. {
  2392. pWizard->EscapeString (&lpUserSOM);
  2393. hr = pWizard->TestSOM (lpUserSOM, hDlg);
  2394. if (FAILED(hr))
  2395. {
  2396. if (hr != E_INVALIDARG)
  2397. {
  2398. ReportError (hDlg, hr, IDS_NOUSERCONTAINER);
  2399. }
  2400. delete [] lpUserSOM;
  2401. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  2402. return TRUE;
  2403. }
  2404. }
  2405. }
  2406. else
  2407. {
  2408. GetControlText(hDlg, IDC_EDIT2, lpUserName, FALSE);
  2409. if ( lpUserName )
  2410. {
  2411. lpUserSOM = ConvertName(lpUserName);
  2412. if (lpUserName && !lpUserSOM)
  2413. {
  2414. DebugMsg((DM_WARNING, TEXT("CRSOPWizardDlg::RSOPGetTargetDlgProc: Failed to convert username %s to DN name with %d."), lpUserName, GetLastError()));
  2415. if (GetLastError() == ERROR_FILE_NOT_FOUND)
  2416. {
  2417. ReportError (hDlg, 0, IDS_NOUSER2);
  2418. }
  2419. else
  2420. {
  2421. ReportError (hDlg, GetLastError(), IDS_NOUSER);
  2422. }
  2423. delete [] lpUserName;
  2424. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  2425. return TRUE;
  2426. }
  2427. pWizard->EscapeString (&lpUserSOM);
  2428. }
  2429. }
  2430. if (lpUserSOM)
  2431. {
  2432. ULONG ulNoChars;
  2433. ulNoChars = lstrlen(lpUserSOM) + 10;
  2434. lpFullName = (LPTSTR) LocalAlloc (LPTR, ulNoChars * sizeof(TCHAR));
  2435. if (lpFullName)
  2436. {
  2437. hr = StringCchCopy (lpFullName, ulNoChars, TEXT("LDAP://"));
  2438. if (SUCCEEDED(hr))
  2439. {
  2440. hr = StringCchCat (lpFullName, ulNoChars, lpUserSOM);
  2441. }
  2442. if (SUCCEEDED(hr))
  2443. {
  2444. hr = OpenDSObject(lpFullName, IID_IDirectoryObject, (void**)&pUserObject);
  2445. if (FAILED(hr))
  2446. {
  2447. DebugMsg((DM_WARNING, TEXT("CRSOPWizardDlg::RSOPGetTargetDlgProc: Failed to bind to user object %s with %d."), lpFullName, hr));
  2448. ReportError (hDlg, hr, IDS_NOUSERCONTAINER);
  2449. if (lpUserName)
  2450. {
  2451. delete [] lpUserName;
  2452. }
  2453. LocalFree (lpFullName);
  2454. delete [] lpUserSOM;
  2455. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  2456. return TRUE;
  2457. }
  2458. }
  2459. LocalFree (lpFullName);
  2460. }
  2461. }
  2462. // Get the computer and dn name
  2463. if (IsDlgButtonChecked(hDlg, IDC_RADIO3) == BST_CHECKED)
  2464. {
  2465. GetControlText(hDlg, IDC_EDIT3, lpComputerSOM, FALSE);
  2466. if (lpComputerSOM)
  2467. {
  2468. pWizard->EscapeString (&lpComputerSOM);
  2469. hr = pWizard->TestSOM (lpComputerSOM, hDlg);
  2470. if (FAILED(hr))
  2471. {
  2472. if (hr != E_INVALIDARG)
  2473. {
  2474. ReportError (hDlg, hr, IDS_NOCOMPUTERCONTAINER);
  2475. }
  2476. delete [] lpComputerSOM;
  2477. if (lpUserName)
  2478. {
  2479. delete [] lpUserName;
  2480. }
  2481. if (lpUserSOM)
  2482. {
  2483. delete [] lpUserSOM;
  2484. }
  2485. if (pUserObject)
  2486. {
  2487. pUserObject->Release();
  2488. pUserObject = NULL;
  2489. }
  2490. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  2491. return TRUE;
  2492. }
  2493. }
  2494. }
  2495. else
  2496. {
  2497. GetControlText(hDlg, IDC_EDIT4, lpComputerName, FALSE );
  2498. if (lpComputerName)
  2499. {
  2500. ULONG ulNoChars;
  2501. ulNoChars = lstrlen(lpComputerName) + 2;
  2502. LPTSTR lpTempName = new TCHAR [ulNoChars];
  2503. if (lpTempName)
  2504. {
  2505. hr = StringCchCopy (lpTempName, ulNoChars, lpComputerName);
  2506. if (SUCCEEDED(hr))
  2507. {
  2508. hr = StringCchCat (lpTempName, ulNoChars, TEXT("$"));
  2509. }
  2510. if (SUCCEEDED(hr))
  2511. {
  2512. lpComputerSOM = ConvertName(lpTempName);
  2513. delete [] lpComputerName;
  2514. lpComputerName = lpTempName;
  2515. }
  2516. }
  2517. }
  2518. if (lpComputerName && !lpComputerSOM)
  2519. {
  2520. DebugMsg((DM_WARNING, TEXT("CRSOPWizardDlg::RSOPGetTargetDlgProc: Failed to convert computername %s to DN name with %d."), lpComputerName, GetLastError()));
  2521. if (GetLastError() == ERROR_FILE_NOT_FOUND)
  2522. {
  2523. ReportError (hDlg, 0, IDS_NOCOMPUTER2);
  2524. }
  2525. else
  2526. {
  2527. ReportError (hDlg, GetLastError(), IDS_NOCOMPUTER);
  2528. }
  2529. delete [] lpComputerName;
  2530. if (lpUserName)
  2531. {
  2532. delete [] lpUserName;
  2533. }
  2534. if (lpUserSOM)
  2535. {
  2536. delete [] lpUserSOM;
  2537. }
  2538. if (pUserObject)
  2539. {
  2540. pUserObject->Release();
  2541. pUserObject = NULL;
  2542. }
  2543. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  2544. return TRUE;
  2545. }
  2546. pWizard->EscapeString (&lpComputerSOM);
  2547. }
  2548. if (lpComputerSOM)
  2549. {
  2550. ULONG ulNoChars;
  2551. ulNoChars = lstrlen(lpComputerSOM) + 10;
  2552. lpFullName = (LPTSTR) LocalAlloc (LPTR, ulNoChars * sizeof(TCHAR));
  2553. if (lpFullName)
  2554. {
  2555. hr = StringCchCopy (lpFullName, ulNoChars, TEXT("LDAP://"));
  2556. if (SUCCEEDED(hr))
  2557. {
  2558. hr = StringCchCat (lpFullName, ulNoChars, lpComputerSOM);
  2559. }
  2560. if (SUCCEEDED(hr))
  2561. {
  2562. hr = OpenDSObject(lpFullName, IID_IDirectoryObject, (void**)&pComputerObject);
  2563. if (FAILED(hr))
  2564. {
  2565. DebugMsg((DM_WARNING, TEXT("CRSOPWizardDlg::RSOPGetTargetDlgProc: Failed to bind to computer object %s with %d."), lpFullName, hr));
  2566. ReportError (hDlg, hr, IDS_NOCOMPUTERCONTAINER);
  2567. if (lpComputerName)
  2568. {
  2569. delete [] lpComputerName;
  2570. }
  2571. LocalFree (lpFullName);
  2572. delete [] lpComputerSOM;
  2573. if (lpUserName)
  2574. {
  2575. delete [] lpUserName;
  2576. }
  2577. if (lpUserSOM)
  2578. {
  2579. delete [] lpUserSOM;
  2580. }
  2581. if (pUserObject)
  2582. {
  2583. pUserObject->Release();
  2584. pUserObject = NULL;
  2585. }
  2586. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  2587. return TRUE;
  2588. }
  2589. LocalFree (lpFullName);
  2590. }
  2591. }
  2592. }
  2593. // Now check that both user and computer are in the same forest
  2594. if ( (lpUserSOM != NULL) && (lpComputerSOM != NULL) )
  2595. {
  2596. LPTSTR szComputerForest( NULL );
  2597. LPTSTR szUserForest( NULL );
  2598. BOOL bDifferentForests( FALSE );
  2599. hr = GetForestFromContainer( lpUserSOM, &szUserForest );
  2600. if ( SUCCEEDED(hr) )
  2601. {
  2602. hr = GetForestFromContainer( lpComputerSOM, &szComputerForest );
  2603. if ( SUCCEEDED(hr) )
  2604. {
  2605. if ( CompareString( LOCALE_USER_DEFAULT, NORM_IGNORECASE, szComputerForest, -1,
  2606. szUserForest, -1 ) != CSTR_EQUAL )
  2607. {
  2608. bDifferentForests = TRUE;
  2609. hr = E_INVALIDARG;
  2610. }
  2611. LocalFree( szComputerForest );
  2612. }
  2613. LocalFree( szUserForest );
  2614. }
  2615. if ( FAILED(hr) )
  2616. {
  2617. if ( bDifferentForests )
  2618. {
  2619. ReportError (hDlg, hr, IDS_NOCROSSFORESTALLOWED);
  2620. }
  2621. else
  2622. {
  2623. ReportError (hDlg, hr, IDS_CROSSFORESTFAILED);
  2624. }
  2625. if (lpComputerName)
  2626. {
  2627. delete [] lpComputerName;
  2628. }
  2629. delete [] lpComputerSOM;
  2630. if (lpUserName)
  2631. {
  2632. delete [] lpUserName;
  2633. }
  2634. delete [] lpUserSOM;
  2635. if (pUserObject)
  2636. {
  2637. pUserObject->Release();
  2638. pUserObject = NULL;
  2639. }
  2640. if (pComputerObject)
  2641. {
  2642. pComputerObject->Release();
  2643. pComputerObject = NULL;
  2644. }
  2645. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  2646. return TRUE;
  2647. }
  2648. }
  2649. // Store the user information
  2650. if ( (pQuery->pUser->szName != NULL) && (lpUserName != NULL) && (!lstrcmpi(pQuery->pUser->szName, lpUserName)))
  2651. {
  2652. bUserChanged = FALSE;
  2653. // Just reinitialize and reuse what we might need
  2654. if ( pWizard->m_szDefaultUserSOM == NULL )
  2655. {
  2656. pWizard->m_szDefaultUserSOM = pWizard->GetDefaultSOM (lpUserSOM);
  2657. }
  2658. if ( pWizard->m_pUserObject == NULL )
  2659. {
  2660. pWizard->m_pUserObject = pUserObject;
  2661. pUserObject = NULL;
  2662. }
  2663. // Now delete the unneeded stuff
  2664. delete [] lpUserName;
  2665. if (lpUserSOM)
  2666. {
  2667. delete [] lpUserSOM;
  2668. }
  2669. if (pUserObject)
  2670. {
  2671. pUserObject->Release();
  2672. pUserObject = NULL;
  2673. }
  2674. }
  2675. else if ( (pQuery->pUser->szName == NULL) && (lpUserName == NULL)
  2676. && (pQuery->pUser->szSOM != NULL) && (lpUserSOM != NULL)
  2677. && (!lstrcmpi( pQuery->pUser->szSOM, lpUserSOM)))
  2678. {
  2679. bUserChanged = FALSE;
  2680. // Just reinitialize and reuse what we might need
  2681. if ( pWizard->m_szDefaultUserSOM == NULL )
  2682. {
  2683. pWizard->m_szDefaultUserSOM = pWizard->GetDefaultSOM (lpUserSOM);
  2684. }
  2685. if ( pWizard->m_pUserObject == NULL )
  2686. {
  2687. pWizard->m_pUserObject = pUserObject;
  2688. pUserObject = NULL;
  2689. }
  2690. // Now delete the unneeded stuff
  2691. delete [] lpUserSOM;
  2692. if (pUserObject)
  2693. {
  2694. pUserObject->Release();
  2695. }
  2696. }
  2697. else if ( (pQuery->pUser->szName == NULL) && (lpUserName == NULL)
  2698. && (pQuery->pUser->szSOM == NULL) && (lpUserSOM == NULL) )
  2699. {
  2700. bUserChanged = FALSE;
  2701. // No stuff to delete!
  2702. }
  2703. else
  2704. {
  2705. pWizard->FreeUserData();
  2706. if ( lpUserName != NULL )
  2707. {
  2708. ULONG ulNoChars;
  2709. ulNoChars = lstrlen(lpUserName)+1;
  2710. pQuery->pUser->szName = (TCHAR*)LocalAlloc( LPTR, ulNoChars * sizeof(TCHAR) );
  2711. if ( pQuery->pUser->szName != NULL )
  2712. {
  2713. hr = StringCchCopy( pQuery->pUser->szName, ulNoChars, lpUserName );
  2714. ASSERT(SUCCEEDED(hr));
  2715. }
  2716. delete [] lpUserName;
  2717. pWizard->m_szDefaultUserSOM = pWizard->GetDefaultSOM (lpUserSOM);
  2718. delete [] lpUserSOM;
  2719. }
  2720. else if ( lpUserSOM != NULL )
  2721. {
  2722. pQuery->pUser->szSOM = NULL;
  2723. (void)UnEscapeLdapPath(lpUserSOM, &(pQuery->pUser->szSOM));
  2724. delete [] lpUserSOM;
  2725. }
  2726. pWizard->m_pUserObject = pUserObject;
  2727. }
  2728. // Store the computer information
  2729. if ( (pQuery->pComputer->szName != NULL) && (lpComputerName != NULL) && !lstrcmpi(pQuery->pComputer->szName, lpComputerName) )
  2730. {
  2731. bComputerChanged = FALSE;
  2732. // Just reinitialize and reuse what we might need
  2733. if ( pWizard->m_szDefaultComputerSOM == NULL )
  2734. {
  2735. pWizard->m_szDefaultComputerSOM = pWizard->GetDefaultSOM (lpComputerSOM);
  2736. }
  2737. if ( pWizard->m_pComputerObject== NULL )
  2738. {
  2739. pWizard->m_pComputerObject = pComputerObject;
  2740. pComputerObject = NULL;
  2741. }
  2742. // Now delete the unneeded stuff
  2743. delete [] lpComputerName;
  2744. if (lpComputerSOM)
  2745. {
  2746. delete [] lpComputerSOM;
  2747. }
  2748. if (pComputerObject)
  2749. {
  2750. pComputerObject->Release();
  2751. pComputerObject = NULL;
  2752. }
  2753. }
  2754. else if ( (pQuery->pComputer->szName == NULL) && (lpComputerName == NULL)
  2755. && (pQuery->pComputer->szSOM != NULL) && (lpComputerSOM != NULL)
  2756. && !lstrcmpi(pQuery->pComputer->szSOM, lpComputerSOM) )
  2757. {
  2758. bComputerChanged = FALSE;
  2759. // Just reinitialize and reuse what we might need
  2760. if ( pWizard->m_szDefaultComputerSOM == NULL )
  2761. {
  2762. pWizard->m_szDefaultComputerSOM = pWizard->GetDefaultSOM (lpComputerSOM);
  2763. }
  2764. if ( pWizard->m_pComputerObject== NULL )
  2765. {
  2766. pWizard->m_pComputerObject = pComputerObject;
  2767. pComputerObject = NULL;
  2768. }
  2769. // Now delete the unneeded stuff
  2770. delete [] lpComputerSOM;
  2771. if (pComputerObject)
  2772. {
  2773. pComputerObject->Release();
  2774. pComputerObject = NULL;
  2775. }
  2776. }
  2777. else if ( (pQuery->pComputer->szName == NULL) && (lpComputerName == NULL)
  2778. && (pQuery->pComputer->szSOM == NULL) && (lpComputerSOM == NULL) )
  2779. {
  2780. bComputerChanged = FALSE;
  2781. // No stuff to delete!
  2782. }
  2783. else
  2784. {
  2785. pWizard->FreeComputerData ();
  2786. if ( lpComputerName != NULL )
  2787. {
  2788. ULONG ulNoChars;
  2789. ulNoChars = lstrlen(lpComputerName)+1;
  2790. pQuery->pComputer->szName = (TCHAR*)LocalAlloc( LPTR, ulNoChars * sizeof(TCHAR) );
  2791. if ( pQuery->pComputer->szName != NULL )
  2792. {
  2793. hr = StringCchCopy( pQuery->pComputer->szName, ulNoChars, lpComputerName );
  2794. ASSERT(SUCCEEDED(hr));
  2795. }
  2796. delete [] lpComputerName;
  2797. pWizard->m_szDefaultComputerSOM = pWizard->GetDefaultSOM (lpComputerSOM);
  2798. delete [] lpComputerSOM;
  2799. }
  2800. else if ( lpComputerSOM != NULL )
  2801. {
  2802. pQuery->pComputer->szSOM = NULL;
  2803. (void)UnEscapeLdapPath(lpComputerSOM, &(pQuery->pComputer->szSOM));
  2804. delete [] lpComputerSOM;
  2805. }
  2806. pWizard->m_pComputerObject = pComputerObject;
  2807. }
  2808. if ( (pQuery->dwFlags & RSOP_FIX_SITENAME) == RSOP_FIX_SITENAME )
  2809. {
  2810. LPTSTR szSiteFriendly = NULL;
  2811. if ( GetSiteFriendlyName( pQuery->szSite, &szSiteFriendly ) )
  2812. {
  2813. ULONG ulNoChars;
  2814. ulNoChars = lstrlen(szSiteFriendly)+1;
  2815. LocalFree( pQuery->szSite );
  2816. pQuery->szSite = (TCHAR*)LocalAlloc( LPTR, ulNoChars * sizeof(TCHAR) );
  2817. if ( pQuery->szSite != NULL )
  2818. {
  2819. hr = StringCchCopy( pQuery->szSite, ulNoChars, szSiteFriendly );
  2820. ASSERT(SUCCEEDED(hr));
  2821. }
  2822. delete [] szSiteFriendly;
  2823. }
  2824. }
  2825. // RM-TODO: Do not delete site name if it is already set and ? didn't change. First find out what ? is!
  2826. else if ( (bComputerChanged || bUserChanged) && (pQuery->szSite != NULL) )
  2827. {
  2828. LocalFree( pQuery->szSite );
  2829. pQuery->szSite = NULL;
  2830. }
  2831. if ( bUserChanged || bComputerChanged || (pQuery->szDomainController == NULL) )
  2832. {
  2833. // Set pQuery->szDomainController to the primary DC
  2834. LPTSTR szDomain = NULL;
  2835. // Determine the focused domain so we can focus on the correct DC.
  2836. if ( pQuery->pComputer->szName != NULL )
  2837. {
  2838. // Try and get the computer's domain
  2839. szDomain = ExtractDomain( pQuery->pComputer->szName );
  2840. }
  2841. if ( (szDomain == NULL) && (pQuery->pComputer->szSOM != NULL) )
  2842. {
  2843. // Try and get the computer's domain from the SOM
  2844. szDomain = GetDomainFromSOM( pQuery->pComputer->szSOM );
  2845. }
  2846. if ( (szDomain == NULL) && (pQuery->pUser->szName != NULL) )
  2847. {
  2848. // Try and get the user's domain
  2849. szDomain = ExtractDomain( pQuery->pUser->szName );
  2850. }
  2851. if ( (szDomain == NULL) && (pQuery->pUser->szSOM != NULL) )
  2852. {
  2853. // Try and get the user's domain from the SOM
  2854. szDomain = GetDomainFromSOM( pQuery->pUser->szSOM );
  2855. }
  2856. if ( szDomain == NULL )
  2857. {
  2858. // Use the local domain
  2859. LPTSTR szName;
  2860. szName = MyGetUserName(NameSamCompatible);
  2861. if ( szName != NULL )
  2862. {
  2863. szDomain = ExtractDomain(szName);
  2864. LocalFree( szName );
  2865. }
  2866. }
  2867. // RM: This is a hack! The command line parameter passed as the preferred DC is being used lower down
  2868. // in this method as a parameter to GetDCName - this is the only known place where it is used.
  2869. LPTSTR szInheritServer = NULL;
  2870. if ( (pQuery->dwFlags & RSOP_FIX_DC) == RSOP_FIX_DC )
  2871. {
  2872. szInheritServer = pQuery->szDomainController;
  2873. pQuery->szDomainController = NULL;
  2874. }
  2875. if ( pQuery->szDomainController != NULL )
  2876. {
  2877. LocalFree( pQuery->szDomainController );
  2878. pQuery->szDomainController = NULL;
  2879. }
  2880. LPTSTR lpDCName;
  2881. lpDCName = GetDCName (szDomain, szInheritServer, NULL, FALSE, 0, DS_RETURN_DNS_NAME);
  2882. if ( lpDCName != NULL )
  2883. {
  2884. pQuery->szDomainController = lpDCName;
  2885. lpDCName = NULL;
  2886. }
  2887. if ( szDomain != NULL )
  2888. {
  2889. delete [] szDomain;
  2890. }
  2891. }
  2892. // Reset the loopback mode if the computer or user is now empty
  2893. if ( (pQuery->LoopbackMode != RSOP_LOOPBACK_NONE) && (bComputerChanged || bUserChanged) )
  2894. {
  2895. if ( ((pQuery->pComputer->szName == NULL) && (pQuery->pComputer->szSOM == NULL))
  2896. || ((pQuery->pUser->szName == NULL) && (pQuery->pUser->szSOM == NULL)) )
  2897. pQuery->LoopbackMode = RSOP_LOOPBACK_NONE;
  2898. }
  2899. ClearWaitCursor();
  2900. }
  2901. if (SendMessage(GetDlgItem(hDlg, IDC_BUTTON1), BM_GETCHECK, 0, 0))
  2902. {
  2903. pWizard->m_dwSkippedFrom = IDD_RSOP_GETTARGET;
  2904. // skip to the final pages
  2905. SetWindowLong(hDlg, DWLP_MSGRESULT, pWizard->m_lPlanningFinishedPage);
  2906. return TRUE;
  2907. }
  2908. pWizard->m_dwSkippedFrom = 0;
  2909. break;
  2910. case PSN_WIZFINISH:
  2911. case PSN_RESET:
  2912. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  2913. return TRUE;
  2914. }
  2915. }
  2916. break;
  2917. }
  2918. return FALSE;
  2919. }
  2920. //-------------------------------------------------------
  2921. INT_PTR CALLBACK CRSOPWizardDlg::RSOPGetDCDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  2922. // RSOP_PLANNING_MODE
  2923. {
  2924. BOOL bEnable;
  2925. switch (message)
  2926. {
  2927. case WM_INITDIALOG:
  2928. {
  2929. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) (((LPPROPSHEETPAGE)lParam)->lParam);
  2930. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pWizard);
  2931. }
  2932. break;
  2933. case WM_COMMAND:
  2934. {
  2935. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  2936. if (!pWizard)
  2937. {
  2938. break;
  2939. }
  2940. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  2941. switch (LOWORD(wParam))
  2942. {
  2943. case IDC_CHECK2:
  2944. if (SendMessage (GetDlgItem(hDlg, IDC_CHECK2), BM_GETCHECK, 0, 0))
  2945. {
  2946. pQuery->LoopbackMode = RSOP_LOOPBACK_REPLACE;
  2947. SendMessage (GetDlgItem(hDlg, IDC_RADIO2), BM_SETCHECK, BST_CHECKED, 0);
  2948. SendMessage (GetDlgItem(hDlg, IDC_RADIO3), BM_SETCHECK, BST_UNCHECKED, 0);
  2949. bEnable = TRUE;
  2950. if ( (NULL == pQuery->pUser->szName) && (NULL == pQuery->pUser->szSOM) )
  2951. {
  2952. bEnable = FALSE;
  2953. }
  2954. EnableWindow (GetDlgItem(hDlg, IDC_RADIO2), bEnable);
  2955. EnableWindow (GetDlgItem(hDlg, IDC_RADIO3), bEnable);
  2956. }
  2957. else
  2958. {
  2959. pQuery->LoopbackMode = RSOP_LOOPBACK_NONE;
  2960. SendMessage (GetDlgItem(hDlg, IDC_RADIO2), BM_SETCHECK, BST_UNCHECKED, 0);
  2961. SendMessage (GetDlgItem(hDlg, IDC_RADIO3), BM_SETCHECK, BST_UNCHECKED, 0);
  2962. EnableWindow (GetDlgItem(hDlg, IDC_RADIO2), FALSE);
  2963. EnableWindow (GetDlgItem(hDlg, IDC_RADIO3), FALSE);
  2964. }
  2965. break;
  2966. case IDC_RADIO2:
  2967. pQuery->LoopbackMode = RSOP_LOOPBACK_REPLACE;
  2968. break;
  2969. case IDC_RADIO3:
  2970. pQuery->LoopbackMode = RSOP_LOOPBACK_MERGE;
  2971. break;
  2972. }
  2973. }
  2974. break;
  2975. case WM_NOTIFY:
  2976. {
  2977. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg*) GetWindowLongPtr (hDlg, DWLP_USER);
  2978. if (!pWizard)
  2979. {
  2980. break;
  2981. }
  2982. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  2983. switch (((NMHDR FAR*)lParam)->code)
  2984. {
  2985. case PSN_SETACTIVE:
  2986. {
  2987. PropSheet_SetWizButtons (GetParent(hDlg),PSWIZB_BACK | PSWIZB_NEXT);
  2988. SetWaitCursor();
  2989. if ( pQuery->bSlowNetworkConnection )
  2990. {
  2991. CheckDlgButton(hDlg, IDC_CHECK1, BST_CHECKED);
  2992. }
  2993. else
  2994. {
  2995. CheckDlgButton(hDlg, IDC_CHECK1, BST_UNCHECKED);
  2996. }
  2997. pWizard->InitializeSitesInfo (hDlg);
  2998. if ( (RSOP_LOOPBACK_NONE == pQuery->LoopbackMode)
  2999. || ( (RSOP_LOOPBACK_MERGE == pQuery->LoopbackMode)
  3000. && ( ((NULL == pQuery->pUser->szName) && (NULL == pQuery->pUser->szSOM))
  3001. || ((NULL == pQuery->pComputer->szName) && (NULL == pQuery->pComputer->szSOM)) ) )
  3002. || ( (RSOP_LOOPBACK_REPLACE == pQuery->LoopbackMode)
  3003. && (NULL == pQuery->pComputer->szName) && (NULL == pQuery->pComputer->szSOM) ) )
  3004. {
  3005. pQuery->LoopbackMode = RSOP_LOOPBACK_NONE;
  3006. SendMessage (GetDlgItem(hDlg, IDC_CHECK2), BM_SETCHECK, BST_UNCHECKED, 0);
  3007. SendMessage (GetDlgItem(hDlg, IDC_RADIO2), BM_SETCHECK, BST_UNCHECKED, 0);
  3008. SendMessage (GetDlgItem(hDlg, IDC_RADIO3), BM_SETCHECK, BST_UNCHECKED, 0);
  3009. if ( (NULL == pQuery->pComputer->szName) && (NULL == pQuery->pComputer->szSOM) )
  3010. {
  3011. EnableWindow (GetDlgItem(hDlg, IDC_CHECK2), FALSE);
  3012. }
  3013. else
  3014. {
  3015. EnableWindow (GetDlgItem(hDlg, IDC_CHECK2), TRUE);
  3016. }
  3017. EnableWindow (GetDlgItem(hDlg, IDC_RADIO2), FALSE);
  3018. EnableWindow (GetDlgItem(hDlg, IDC_RADIO3), FALSE);
  3019. }
  3020. else
  3021. {
  3022. CheckDlgButton( hDlg, IDC_CHECK2, BST_CHECKED );
  3023. if ( RSOP_LOOPBACK_REPLACE == pQuery->LoopbackMode )
  3024. {
  3025. SendMessage (GetDlgItem(hDlg, IDC_RADIO2), BM_SETCHECK, BST_CHECKED, 0);
  3026. SendMessage (GetDlgItem(hDlg, IDC_RADIO3), BM_SETCHECK, BST_UNCHECKED, 0);
  3027. }
  3028. else
  3029. {
  3030. SendMessage (GetDlgItem(hDlg, IDC_RADIO2), BM_SETCHECK, BST_UNCHECKED, 0);
  3031. SendMessage (GetDlgItem(hDlg, IDC_RADIO3), BM_SETCHECK, BST_CHECKED, 0);
  3032. }
  3033. bEnable = TRUE;
  3034. if ( (NULL == pQuery->pUser->szName) && (NULL == pQuery->pUser->szSOM) )
  3035. {
  3036. bEnable = FALSE;
  3037. }
  3038. EnableWindow (GetDlgItem(hDlg, IDC_RADIO2), bEnable);
  3039. EnableWindow (GetDlgItem(hDlg, IDC_RADIO3), bEnable);
  3040. }
  3041. ClearWaitCursor();
  3042. }
  3043. break;
  3044. case PSN_WIZBACK:
  3045. case PSN_WIZNEXT:
  3046. {
  3047. SetWaitCursor();
  3048. GetControlText(hDlg, IDC_COMBO1, pQuery->szSite, TRUE);
  3049. if ( pQuery->szSite != NULL )
  3050. {
  3051. TCHAR szName[30];
  3052. LoadString (g_hInstance, IDS_NONE, szName, ARRAYSIZE(szName));
  3053. if ( !lstrcmpi( pQuery->szSite, szName ) )
  3054. {
  3055. LocalFree( pQuery->szSite );
  3056. pQuery->szSite = NULL;
  3057. }
  3058. }
  3059. if (SendMessage(GetDlgItem(hDlg, IDC_CHECK1), BM_GETCHECK, 0, 0))
  3060. {
  3061. pQuery->bSlowNetworkConnection= TRUE;
  3062. }
  3063. else
  3064. {
  3065. pQuery->bSlowNetworkConnection = FALSE;
  3066. }
  3067. ClearWaitCursor();
  3068. if ( ((NMHDR FAR*)lParam)->code == PSN_WIZNEXT )
  3069. {
  3070. if (SendMessage(GetDlgItem(hDlg, IDC_RADIO1), BM_GETCHECK, 0, 0))
  3071. {
  3072. pWizard->m_dwSkippedFrom = IDD_RSOP_GETDC;
  3073. SetWindowLong(hDlg, DWLP_MSGRESULT, pWizard->m_lPlanningFinishedPage);
  3074. return TRUE;
  3075. }
  3076. if ( (NULL == pQuery->pUser->szName) && (NULL == pQuery->pComputer->szName) )
  3077. {
  3078. pWizard->m_dwSkippedFrom = IDD_RSOP_GETDC;
  3079. if ( (pQuery->pUser->szSOM != NULL) || (RSOP_LOOPBACK_NONE!= pQuery->LoopbackMode) )
  3080. {
  3081. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_ALTUSERSEC);
  3082. }
  3083. else if ( pQuery->pComputer->szSOM != NULL )
  3084. {
  3085. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_ALTCOMPSEC);
  3086. }
  3087. else
  3088. {
  3089. SetWindowLong(hDlg, DWLP_MSGRESULT, pWizard->m_lPlanningFinishedPage);
  3090. }
  3091. return TRUE;
  3092. }
  3093. pWizard->m_dwSkippedFrom = 0;
  3094. }
  3095. }
  3096. break;
  3097. case PSN_WIZFINISH:
  3098. // fall through
  3099. case PSN_RESET:
  3100. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  3101. return TRUE;
  3102. }
  3103. break;
  3104. }
  3105. }
  3106. return FALSE;
  3107. }
  3108. //-------------------------------------------------------
  3109. INT_PTR CALLBACK CRSOPWizardDlg::RSOPAltDirsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  3110. // RSOP_PLANNING_MODE
  3111. {
  3112. switch (message)
  3113. {
  3114. case WM_INITDIALOG:
  3115. {
  3116. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) (((LPPROPSHEETPAGE)lParam)->lParam);
  3117. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pWizard);
  3118. }
  3119. break;
  3120. case WM_COMMAND:
  3121. {
  3122. DSBROWSEINFO dsbi = {0};
  3123. TCHAR szTitle[256];
  3124. TCHAR szCaption[256];
  3125. TCHAR* szResult;
  3126. dsbi.hwndOwner = hDlg;
  3127. dsbi.pszCaption = szTitle;
  3128. dsbi.pszTitle = szCaption;
  3129. dsbi.cbStruct = sizeof(dsbi);
  3130. dsbi.pszPath = NULL;
  3131. dsbi.cchPath = 0;
  3132. dsbi.dwFlags = DSBI_ENTIREDIRECTORY;
  3133. dsbi.pfnCallback = DsBrowseCallback;
  3134. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  3135. if (!pWizard)
  3136. {
  3137. break;
  3138. }
  3139. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  3140. switch (LOWORD(wParam))
  3141. {
  3142. case IDC_BUTTON1:
  3143. // browse for user's OU
  3144. szResult = (LPTSTR)LocalAlloc(LPTR, sizeof(TCHAR)*4000);
  3145. if ( szResult )
  3146. {
  3147. dsbi.pszPath = szResult;
  3148. dsbi.cchPath = 4000;
  3149. LoadString(g_hInstance,
  3150. IDS_BROWSE_USER_OU_TITLE,
  3151. szTitle,
  3152. ARRAYSIZE(szTitle));
  3153. LoadString(g_hInstance,
  3154. IDS_BROWSE_USER_OU_CAPTION,
  3155. szCaption,
  3156. ARRAYSIZE(szCaption));
  3157. if (IDOK == DsBrowseForContainer(&dsbi))
  3158. {
  3159. LPWSTR szDN;
  3160. HRESULT hr;
  3161. // skipping 7 chars for LDAP:// in the szResult
  3162. hr = UnEscapeLdapPath(szResult+7, &szDN);
  3163. if (FAILED(hr))
  3164. {
  3165. ReportError (hDlg, hr, IDS_NOUSERCONTAINER);
  3166. }
  3167. else {
  3168. SetDlgItemText(hDlg, IDC_EDIT1, szDN);
  3169. LocalFree(szDN);
  3170. }
  3171. }
  3172. LocalFree(szResult);
  3173. }
  3174. break;
  3175. case IDC_BUTTON2:
  3176. // browse for computer's OU
  3177. szResult = (LPTSTR)LocalAlloc(LPTR, sizeof(TCHAR)*4000);
  3178. if ( szResult )
  3179. {
  3180. dsbi.pszPath = szResult;
  3181. dsbi.cchPath = 4000;
  3182. LoadString(g_hInstance,
  3183. IDS_BROWSE_COMPUTER_OU_TITLE,
  3184. szTitle,
  3185. ARRAYSIZE(szTitle));
  3186. LoadString(g_hInstance,
  3187. IDS_BROWSE_COMPUTER_OU_CAPTION,
  3188. szCaption,
  3189. ARRAYSIZE(szCaption));
  3190. if (IDOK == DsBrowseForContainer(&dsbi))
  3191. {
  3192. LPWSTR szDN;
  3193. HRESULT hr;
  3194. // skipping 7 chars for LDAP:// in the szResult
  3195. hr = UnEscapeLdapPath(szResult+7, &szDN);
  3196. if (FAILED(hr))
  3197. {
  3198. ReportError (hDlg, hr, IDS_NOUSERCONTAINER);
  3199. }
  3200. else {
  3201. SetDlgItemText(hDlg, IDC_EDIT2, szDN);
  3202. LocalFree(szDN);
  3203. }
  3204. }
  3205. LocalFree(szResult);
  3206. }
  3207. break;
  3208. case IDC_BUTTON3:
  3209. if (IsWindowEnabled (GetDlgItem(hDlg, IDC_EDIT1)))
  3210. {
  3211. if ( pWizard->m_szDefaultUserSOM != NULL )
  3212. {
  3213. SetDlgItemText (hDlg, IDC_EDIT1, pWizard->m_szDefaultUserSOM);
  3214. }
  3215. }
  3216. if (IsWindowEnabled (GetDlgItem(hDlg, IDC_EDIT2)))
  3217. {
  3218. if ( pWizard->m_szDefaultComputerSOM != NULL )
  3219. {
  3220. SetDlgItemText (hDlg, IDC_EDIT2, pWizard->m_szDefaultComputerSOM);
  3221. }
  3222. }
  3223. break;
  3224. }
  3225. }
  3226. break;
  3227. case WM_NOTIFY:
  3228. {
  3229. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  3230. if (!pWizard)
  3231. {
  3232. break;
  3233. }
  3234. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  3235. switch (((NMHDR FAR*)lParam)->code)
  3236. {
  3237. case PSN_SETACTIVE:
  3238. PropSheet_SetWizButtons (GetParent(hDlg),PSWIZB_BACK | PSWIZB_NEXT);
  3239. EnableWindow(GetDlgItem(hDlg, IDC_EDIT1), TRUE);
  3240. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON1), TRUE);
  3241. SetDlgItemText (hDlg, IDC_EDIT1, TEXT(""));
  3242. if ( pQuery->pUser->szSOM != NULL )
  3243. {
  3244. SetDlgItemText (hDlg, IDC_EDIT1, pQuery->pUser->szSOM );
  3245. if ( pQuery->pUser->szName == NULL )
  3246. {
  3247. EnableWindow(GetDlgItem(hDlg, IDC_EDIT1), FALSE);
  3248. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON1), FALSE);
  3249. }
  3250. }
  3251. else if ( pWizard->m_szDefaultUserSOM != NULL )
  3252. {
  3253. SetDlgItemText (hDlg, IDC_EDIT1, pWizard->m_szDefaultUserSOM);
  3254. }
  3255. else if ( pQuery->pUser->szName == NULL )
  3256. {
  3257. EnableWindow(GetDlgItem(hDlg, IDC_EDIT1), FALSE);
  3258. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON1), FALSE);
  3259. }
  3260. EnableWindow(GetDlgItem(hDlg, IDC_EDIT2), TRUE);
  3261. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON2), TRUE);
  3262. SetDlgItemText (hDlg, IDC_EDIT2, TEXT(""));
  3263. if ( pQuery->pComputer->szSOM != NULL )
  3264. {
  3265. SetDlgItemText (hDlg, IDC_EDIT2, pQuery->pComputer->szSOM);
  3266. if ( pQuery->pComputer->szName == NULL )
  3267. {
  3268. EnableWindow(GetDlgItem(hDlg, IDC_EDIT2), FALSE);
  3269. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON2), FALSE);
  3270. }
  3271. }
  3272. else if ( pWizard->m_szDefaultComputerSOM != NULL )
  3273. {
  3274. SetDlgItemText (hDlg, IDC_EDIT2, pWizard->m_szDefaultComputerSOM);
  3275. }
  3276. else if ( pQuery->pComputer->szName == NULL )
  3277. {
  3278. EnableWindow(GetDlgItem(hDlg, IDC_EDIT2), FALSE);
  3279. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON2), FALSE);
  3280. }
  3281. if (IsWindowEnabled (GetDlgItem(hDlg, IDC_EDIT1))
  3282. || IsWindowEnabled (GetDlgItem(hDlg, IDC_EDIT2)))
  3283. {
  3284. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON3), TRUE);
  3285. }
  3286. else
  3287. {
  3288. EnableWindow(GetDlgItem(hDlg, IDC_BUTTON3), FALSE);
  3289. }
  3290. break;
  3291. case PSN_WIZBACK:
  3292. case PSN_WIZNEXT:
  3293. {
  3294. LPTSTR lpUserSOM = NULL, lpComputerSOM = NULL;
  3295. HRESULT hr;
  3296. GetControlText(hDlg, IDC_EDIT1, lpUserSOM, FALSE);
  3297. GetControlText(hDlg, IDC_EDIT2, lpComputerSOM, FALSE);
  3298. if (lpUserSOM)
  3299. {
  3300. pWizard->EscapeString(&lpUserSOM);
  3301. if (lpUserSOM)
  3302. {
  3303. hr = pWizard->TestSOM (lpUserSOM, hDlg);
  3304. }
  3305. else {
  3306. hr = E_FAIL;
  3307. }
  3308. if (FAILED(hr))
  3309. {
  3310. if (hr != E_INVALIDARG)
  3311. {
  3312. ReportError (hDlg, hr, IDS_NOUSERCONTAINER);
  3313. }
  3314. if (lpUserSOM)
  3315. {
  3316. delete [] lpUserSOM;
  3317. }
  3318. if (lpComputerSOM)
  3319. {
  3320. delete [] lpComputerSOM;
  3321. }
  3322. if ( ((NMHDR FAR*)lParam)->code == PSN_WIZNEXT )
  3323. {
  3324. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  3325. return TRUE;
  3326. }
  3327. else
  3328. {
  3329. return FALSE;
  3330. }
  3331. }
  3332. }
  3333. if (lpComputerSOM)
  3334. {
  3335. pWizard->EscapeString(&lpComputerSOM);
  3336. if (lpComputerSOM)
  3337. {
  3338. hr = pWizard->TestSOM (lpComputerSOM, hDlg);
  3339. }
  3340. else {
  3341. hr = E_FAIL;
  3342. }
  3343. if (FAILED(hr))
  3344. {
  3345. if (hr != E_INVALIDARG)
  3346. {
  3347. ReportError (hDlg, hr, IDS_NOCOMPUTERCONTAINER);
  3348. }
  3349. if (lpUserSOM)
  3350. {
  3351. delete [] lpUserSOM;
  3352. }
  3353. if (lpComputerSOM)
  3354. {
  3355. delete [] lpComputerSOM;
  3356. }
  3357. if ( ((NMHDR FAR*)lParam)->code == PSN_WIZNEXT )
  3358. {
  3359. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  3360. return TRUE;
  3361. }
  3362. else
  3363. {
  3364. return FALSE;
  3365. }
  3366. }
  3367. }
  3368. if (lpUserSOM)
  3369. {
  3370. hr = UnEscapeLdapPath(lpUserSOM, &pQuery->pUser->szSOM);
  3371. delete [] lpUserSOM;
  3372. lpUserSOM = NULL;
  3373. }
  3374. else {
  3375. pQuery->pUser->szSOM = NULL;
  3376. }
  3377. if (lpComputerSOM)
  3378. {
  3379. hr = UnEscapeLdapPath(lpComputerSOM, &pQuery->pComputer->szSOM);
  3380. delete [] lpComputerSOM;
  3381. lpComputerSOM = NULL;
  3382. }
  3383. else {
  3384. pQuery->pComputer->szSOM = NULL;
  3385. }
  3386. if ( (pWizard->m_szDefaultUserSOM != NULL) && (pQuery->pUser->szSOM != NULL) )
  3387. {
  3388. if (!lstrcmpi(pWizard->m_szDefaultUserSOM, pQuery->pUser->szSOM))
  3389. {
  3390. LocalFree( pQuery->pUser->szSOM );
  3391. pQuery->pUser->szSOM = NULL;
  3392. }
  3393. }
  3394. if ( (pWizard->m_szDefaultComputerSOM != NULL) && (pQuery->pComputer->szSOM != NULL) )
  3395. {
  3396. if (!lstrcmpi(pWizard->m_szDefaultComputerSOM, pQuery->pComputer->szSOM))
  3397. {
  3398. LocalFree( pQuery->pComputer->szSOM );
  3399. pQuery->pComputer->szSOM = NULL;
  3400. }
  3401. }
  3402. if ( ((NMHDR FAR*)lParam)->code == PSN_WIZNEXT )
  3403. {
  3404. if (SendMessage(GetDlgItem(hDlg, IDC_RADIO1), BM_GETCHECK, 0, 0))
  3405. {
  3406. pWizard->m_dwSkippedFrom = IDD_RSOP_ALTDIRS;
  3407. SetWindowLong(hDlg, DWLP_MSGRESULT, pWizard->m_lPlanningFinishedPage);
  3408. return TRUE;
  3409. }
  3410. if ( (NULL == pQuery->pUser->szName) && (NULL == pQuery->pUser->szSOM) )
  3411. {
  3412. pWizard->m_dwSkippedFrom = IDD_RSOP_ALTDIRS;
  3413. if ( (pQuery->pComputer->szName != NULL) || (pQuery->pComputer->szSOM != NULL) )
  3414. {
  3415. if ( RSOP_LOOPBACK_NONE == pQuery->LoopbackMode)
  3416. {
  3417. // skip to the alternate computer security page
  3418. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_ALTCOMPSEC);
  3419. }
  3420. else
  3421. {
  3422. // Skip to the alternate user security page if simulating loopback mode
  3423. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_ALTUSERSEC);
  3424. }
  3425. }
  3426. else
  3427. {
  3428. // skip to the finish page
  3429. SetWindowLong(hDlg, DWLP_MSGRESULT, pWizard->m_lPlanningFinishedPage);
  3430. }
  3431. return TRUE;
  3432. }
  3433. pWizard->m_dwSkippedFrom = 0;
  3434. }
  3435. }
  3436. break;
  3437. case PSN_WIZFINISH:
  3438. // fall through
  3439. case PSN_RESET:
  3440. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  3441. return TRUE;
  3442. }
  3443. }
  3444. break;
  3445. }
  3446. return FALSE;
  3447. }
  3448. //-------------------------------------------------------
  3449. INT_PTR CALLBACK CRSOPWizardDlg::RSOPAltUserSecDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  3450. // RSOP_PLANNING_MODE
  3451. {
  3452. switch (message)
  3453. {
  3454. case WM_INITDIALOG:
  3455. {
  3456. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) (((LPPROPSHEETPAGE)lParam)->lParam);
  3457. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pWizard);
  3458. }
  3459. break;
  3460. case WM_COMMAND:
  3461. {
  3462. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  3463. if (!pWizard)
  3464. {
  3465. break;
  3466. }
  3467. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  3468. switch (LOWORD(wParam))
  3469. {
  3470. case IDC_BUTTON1:
  3471. {
  3472. TCHAR * sz;
  3473. if ( ImplementBrowseButton(hDlg,
  3474. (DSOP_FILTER_UNIVERSAL_GROUPS_SE | DSOP_FILTER_GLOBAL_GROUPS_SE | DSOP_FILTER_DOMAIN_LOCAL_GROUPS_SE),
  3475. (DSOP_DOWNLEVEL_FILTER_GLOBAL_GROUPS),
  3476. (DSOP_SCOPE_FLAG_DEFAULT_FILTER_GROUPS),
  3477. GetDlgItem(hDlg, IDC_LIST1), sz) == S_OK )
  3478. {
  3479. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON3), TRUE);
  3480. }
  3481. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  3482. }
  3483. break;
  3484. case IDC_BUTTON2:
  3485. {
  3486. INT iIndex;
  3487. iIndex = (INT) SendDlgItemMessage (hDlg, IDC_LIST1, LB_GETCURSEL, 0, 0);
  3488. if (iIndex != LB_ERR)
  3489. {
  3490. if ((SendDlgItemMessage (hDlg, IDC_LIST1, LB_GETITEMDATA, (WPARAM) iIndex, 0) & 1) == 0)
  3491. {
  3492. SendDlgItemMessage (hDlg, IDC_LIST1, LB_DELETESTRING, (WPARAM) iIndex, 0);
  3493. SendDlgItemMessage (hDlg, IDC_LIST1, LB_SETCURSEL, (WPARAM) iIndex, 0);
  3494. }
  3495. }
  3496. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON3), TRUE);
  3497. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  3498. }
  3499. break;
  3500. case IDC_BUTTON3:
  3501. {
  3502. if ( pQuery->pUser->dwSecurityGroupCount != 0 )
  3503. {
  3504. FreeStringList( pQuery->pUser->dwSecurityGroupCount, pQuery->pUser->aszSecurityGroups );
  3505. pQuery->pUser->dwSecurityGroupCount = 0;
  3506. pQuery->pUser->aszSecurityGroups = NULL;
  3507. LocalFree( pQuery->pUser->adwSecurityGroupsAttr );
  3508. pQuery->pUser->adwSecurityGroupsAttr = NULL;
  3509. }
  3510. if ( pWizard->m_dwDefaultUserSecurityGroupCount != 0 )
  3511. {
  3512. pWizard->FillListFromSecurityGroups( GetDlgItem(hDlg, IDC_LIST1),
  3513. pWizard->m_dwDefaultUserSecurityGroupCount,
  3514. pWizard->m_aszDefaultUserSecurityGroups,
  3515. pWizard->m_adwDefaultUserSecurityGroupsAttr );
  3516. }
  3517. else
  3518. {
  3519. pWizard->BuildMembershipList( GetDlgItem(hDlg, IDC_LIST1),
  3520. pWizard->m_pUserObject,
  3521. &(pWizard->m_dwDefaultUserSecurityGroupCount),
  3522. &(pWizard->m_aszDefaultUserSecurityGroups),
  3523. &(pWizard->m_adwDefaultUserSecurityGroupsAttr) );
  3524. }
  3525. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON3), FALSE);
  3526. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  3527. }
  3528. break;
  3529. case IDC_LIST1:
  3530. if (HIWORD(wParam) == LBN_SELCHANGE)
  3531. {
  3532. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  3533. }
  3534. break;
  3535. }
  3536. }
  3537. break;
  3538. case WM_REFRESHDISPLAY:
  3539. if (SendDlgItemMessage (hDlg, IDC_LIST1, LB_GETCOUNT, 0, 0) > 0)
  3540. {
  3541. INT iIndex;
  3542. iIndex = (INT) SendDlgItemMessage (hDlg, IDC_LIST1, LB_GETCURSEL, 0, 0);
  3543. if (iIndex != LB_ERR)
  3544. {
  3545. if ((SendDlgItemMessage (hDlg, IDC_LIST1, LB_GETITEMDATA, (WPARAM) iIndex, 0) & 1) == 0)
  3546. {
  3547. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON2), TRUE);
  3548. }
  3549. else
  3550. {
  3551. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON2), FALSE);
  3552. }
  3553. }
  3554. } else {
  3555. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON2), FALSE);
  3556. }
  3557. break;
  3558. case WM_NOTIFY:
  3559. {
  3560. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg*) GetWindowLongPtr (hDlg, DWLP_USER);
  3561. if (!pWizard)
  3562. {
  3563. break;
  3564. }
  3565. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  3566. switch (((NMHDR FAR*)lParam)->code)
  3567. {
  3568. case PSN_SETACTIVE:
  3569. PropSheet_SetWizButtons (GetParent(hDlg),PSWIZB_BACK | PSWIZB_NEXT);
  3570. if ( pQuery->pUser->dwSecurityGroupCount != 0 )
  3571. {
  3572. pWizard->FillListFromSecurityGroups( GetDlgItem(hDlg, IDC_LIST1),
  3573. pQuery->pUser->dwSecurityGroupCount,
  3574. pQuery->pUser->aszSecurityGroups,
  3575. pQuery->pUser->adwSecurityGroupsAttr );
  3576. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON3), TRUE);
  3577. }
  3578. else if ( pWizard->m_dwDefaultUserSecurityGroupCount != 0 )
  3579. {
  3580. pWizard->FillListFromSecurityGroups( GetDlgItem(hDlg, IDC_LIST1),
  3581. pWizard->m_dwDefaultUserSecurityGroupCount,
  3582. pWizard->m_aszDefaultUserSecurityGroups,
  3583. pWizard->m_adwDefaultUserSecurityGroupsAttr );
  3584. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON3), FALSE);
  3585. }
  3586. else
  3587. {
  3588. pWizard->BuildMembershipList( GetDlgItem(hDlg, IDC_LIST1),
  3589. pWizard->m_pUserObject,
  3590. &(pWizard->m_dwDefaultUserSecurityGroupCount),
  3591. &(pWizard->m_aszDefaultUserSecurityGroups),
  3592. &(pWizard->m_adwDefaultUserSecurityGroupsAttr) );
  3593. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON3), FALSE);
  3594. }
  3595. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  3596. break;
  3597. case PSN_WIZNEXT:
  3598. {
  3599. // Free the previous list of security groups
  3600. if ( pQuery->pUser->dwSecurityGroupCount != 0 )
  3601. {
  3602. FreeStringList( pQuery->pUser->dwSecurityGroupCount, pQuery->pUser->aszSecurityGroups );
  3603. pQuery->pUser->dwSecurityGroupCount = 0;
  3604. pQuery->pUser->aszSecurityGroups = NULL;
  3605. LocalFree( pQuery->pUser->adwSecurityGroupsAttr );
  3606. pQuery->pUser->adwSecurityGroupsAttr = NULL;
  3607. }
  3608. // Save the current list
  3609. pWizard->SaveSecurityGroups( GetDlgItem(hDlg, IDC_LIST1),
  3610. &(pQuery->pUser->dwSecurityGroupCount),
  3611. &(pQuery->pUser->aszSecurityGroups),
  3612. &(pQuery->pUser->adwSecurityGroupsAttr) );
  3613. // Compare the current list with the default list. If the default list
  3614. // matches the current list, then delete the current list and just use
  3615. // the defaults
  3616. if ( pWizard->CompareStringLists( pWizard->m_dwDefaultUserSecurityGroupCount,
  3617. pWizard->m_aszDefaultUserSecurityGroups,
  3618. pQuery->pUser->dwSecurityGroupCount,
  3619. pQuery->pUser->aszSecurityGroups ) )
  3620. {
  3621. if ( pQuery->pUser->dwSecurityGroupCount != 0 )
  3622. {
  3623. FreeStringList( pQuery->pUser->dwSecurityGroupCount, pQuery->pUser->aszSecurityGroups );
  3624. pQuery->pUser->dwSecurityGroupCount = 0;
  3625. pQuery->pUser->aszSecurityGroups = NULL;
  3626. LocalFree( pQuery->pUser->adwSecurityGroupsAttr );
  3627. pQuery->pUser->adwSecurityGroupsAttr = NULL;
  3628. }
  3629. }
  3630. // Now check where we should go
  3631. if (SendMessage(GetDlgItem(hDlg, IDC_RADIO1), BM_GETCHECK, 0, 0))
  3632. {
  3633. pWizard->m_dwSkippedFrom = IDD_RSOP_ALTUSERSEC;
  3634. // skip to the diagnostic pages
  3635. SetWindowLong(hDlg, DWLP_MSGRESULT, pWizard->m_lPlanningFinishedPage);
  3636. return TRUE;
  3637. }
  3638. if ( (NULL == pQuery->pComputer->szName) && (NULL == pQuery->pComputer->szSOM) )
  3639. {
  3640. // skip to the finish page
  3641. pWizard->m_dwSkippedFrom = IDD_RSOP_ALTUSERSEC;
  3642. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_WQLUSER);
  3643. return TRUE;
  3644. }
  3645. pWizard->m_dwSkippedFrom = 0;
  3646. }
  3647. break;
  3648. case PSN_WIZBACK:
  3649. {
  3650. // Free the previous list of security groups
  3651. if ( pQuery->pUser->dwSecurityGroupCount != 0 )
  3652. {
  3653. FreeStringList( pQuery->pUser->dwSecurityGroupCount, pQuery->pUser->aszSecurityGroups );
  3654. pQuery->pUser->dwSecurityGroupCount = 0;
  3655. pQuery->pUser->aszSecurityGroups = NULL;
  3656. LocalFree( pQuery->pUser->adwSecurityGroupsAttr );
  3657. pQuery->pUser->adwSecurityGroupsAttr = NULL;
  3658. }
  3659. // Save the current list
  3660. pWizard->SaveSecurityGroups( GetDlgItem(hDlg, IDC_LIST1),
  3661. &(pQuery->pUser->dwSecurityGroupCount),
  3662. &(pQuery->pUser->aszSecurityGroups),
  3663. &(pQuery->pUser->adwSecurityGroupsAttr) );
  3664. // Compare the current list with the default list. If the default list
  3665. // matches the current list, then delete the current list and just use
  3666. // the defaults
  3667. if ( pWizard->CompareStringLists( pWizard->m_dwDefaultUserSecurityGroupCount,
  3668. pWizard->m_aszDefaultUserSecurityGroups,
  3669. pQuery->pUser->dwSecurityGroupCount,
  3670. pQuery->pUser->aszSecurityGroups ) )
  3671. {
  3672. if ( pQuery->pUser->dwSecurityGroupCount != 0 )
  3673. {
  3674. FreeStringList( pQuery->pUser->dwSecurityGroupCount, pQuery->pUser->aszSecurityGroups );
  3675. pQuery->pUser->dwSecurityGroupCount = 0;
  3676. pQuery->pUser->aszSecurityGroups = NULL;
  3677. LocalFree( pQuery->pUser->adwSecurityGroupsAttr );
  3678. pQuery->pUser->adwSecurityGroupsAttr = NULL;
  3679. }
  3680. }
  3681. // Now check where we should go
  3682. if ( (pQuery->pUser->szName == NULL) && (pQuery->pComputer->szName == NULL) )
  3683. {
  3684. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_GETDC);
  3685. return TRUE;
  3686. }
  3687. }
  3688. break;
  3689. case PSN_WIZFINISH:
  3690. // fall through
  3691. case PSN_RESET:
  3692. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  3693. return TRUE;
  3694. }
  3695. }
  3696. break;
  3697. }
  3698. return FALSE;
  3699. }
  3700. //-------------------------------------------------------
  3701. INT_PTR CALLBACK CRSOPWizardDlg::RSOPAltCompSecDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  3702. // RSOP_PLANNING_MODE
  3703. {
  3704. switch (message)
  3705. {
  3706. case WM_INITDIALOG:
  3707. {
  3708. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) (((LPPROPSHEETPAGE)lParam)->lParam);
  3709. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pWizard);
  3710. }
  3711. break;
  3712. case WM_COMMAND:
  3713. {
  3714. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  3715. if (!pWizard)
  3716. {
  3717. break;
  3718. }
  3719. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  3720. switch (LOWORD(wParam))
  3721. {
  3722. case IDC_BUTTON1:
  3723. {
  3724. TCHAR * sz;
  3725. if ( ImplementBrowseButton(hDlg,
  3726. (DSOP_FILTER_UNIVERSAL_GROUPS_SE | DSOP_FILTER_GLOBAL_GROUPS_SE | DSOP_FILTER_DOMAIN_LOCAL_GROUPS_SE),
  3727. (DSOP_DOWNLEVEL_FILTER_GLOBAL_GROUPS),
  3728. (DSOP_SCOPE_FLAG_DEFAULT_FILTER_GROUPS),
  3729. GetDlgItem(hDlg, IDC_LIST1), sz) == S_OK )
  3730. {
  3731. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON3), TRUE);
  3732. }
  3733. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  3734. }
  3735. break;
  3736. case IDC_BUTTON2:
  3737. {
  3738. INT iIndex;
  3739. iIndex = (INT) SendDlgItemMessage (hDlg, IDC_LIST1, LB_GETCURSEL, 0, 0);
  3740. if (iIndex != LB_ERR)
  3741. {
  3742. if ((SendDlgItemMessage (hDlg, IDC_LIST1, LB_GETITEMDATA, (WPARAM) iIndex, 0) & 1) == 0)
  3743. {
  3744. SendDlgItemMessage (hDlg, IDC_LIST1, LB_DELETESTRING, (WPARAM) iIndex, 0);
  3745. SendDlgItemMessage (hDlg, IDC_LIST1, LB_SETCURSEL, (WPARAM) iIndex, 0);
  3746. }
  3747. }
  3748. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON3), TRUE);
  3749. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  3750. }
  3751. break;
  3752. case IDC_BUTTON3:
  3753. {
  3754. if ( pQuery->pComputer->dwSecurityGroupCount != 0 )
  3755. {
  3756. FreeStringList( pQuery->pComputer->dwSecurityGroupCount, pQuery->pComputer->aszSecurityGroups );
  3757. pQuery->pComputer->dwSecurityGroupCount = 0;
  3758. pQuery->pComputer->aszSecurityGroups = NULL;
  3759. LocalFree( pQuery->pComputer->adwSecurityGroupsAttr );
  3760. pQuery->pComputer->adwSecurityGroupsAttr = NULL;
  3761. }
  3762. if ( pWizard->m_dwDefaultComputerSecurityGroupCount != 0 )
  3763. {
  3764. pWizard->FillListFromSecurityGroups( GetDlgItem(hDlg, IDC_LIST1),
  3765. pWizard->m_dwDefaultComputerSecurityGroupCount,
  3766. pWizard->m_aszDefaultComputerSecurityGroups,
  3767. pWizard->m_adwDefaultComputerSecurityGroupsAttr );
  3768. }
  3769. else
  3770. {
  3771. pWizard->BuildMembershipList( GetDlgItem(hDlg, IDC_LIST1),
  3772. pWizard->m_pComputerObject,
  3773. &(pWizard->m_dwDefaultComputerSecurityGroupCount),
  3774. &(pWizard->m_aszDefaultComputerSecurityGroups),
  3775. &(pWizard->m_adwDefaultComputerSecurityGroupsAttr) );
  3776. }
  3777. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON3), FALSE);
  3778. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  3779. }
  3780. break;
  3781. case IDC_LIST1:
  3782. if (HIWORD(wParam) == LBN_SELCHANGE)
  3783. {
  3784. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  3785. }
  3786. break;
  3787. }
  3788. }
  3789. break;
  3790. case WM_REFRESHDISPLAY:
  3791. if (SendDlgItemMessage (hDlg, IDC_LIST1, LB_GETCOUNT, 0, 0) > 0)
  3792. {
  3793. INT iIndex;
  3794. iIndex = (INT) SendDlgItemMessage (hDlg, IDC_LIST1, LB_GETCURSEL, 0, 0);
  3795. if (iIndex != LB_ERR)
  3796. {
  3797. if ((SendDlgItemMessage (hDlg, IDC_LIST1, LB_GETITEMDATA, (WPARAM) iIndex, 0) & 1) == 0)
  3798. {
  3799. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON2), TRUE);
  3800. }
  3801. else
  3802. {
  3803. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON2), FALSE);
  3804. }
  3805. }
  3806. } else {
  3807. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON2), FALSE);
  3808. }
  3809. break;
  3810. case WM_NOTIFY:
  3811. {
  3812. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  3813. if (!pWizard)
  3814. {
  3815. break;
  3816. }
  3817. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  3818. switch (((NMHDR FAR*)lParam)->code)
  3819. {
  3820. case PSN_SETACTIVE:
  3821. PropSheet_SetWizButtons (GetParent(hDlg),PSWIZB_BACK | PSWIZB_NEXT);
  3822. if ( pQuery->pComputer->dwSecurityGroupCount != 0 )
  3823. {
  3824. pWizard->FillListFromSecurityGroups( GetDlgItem(hDlg, IDC_LIST1),
  3825. pQuery->pComputer->dwSecurityGroupCount,
  3826. pQuery->pComputer->aszSecurityGroups,
  3827. pQuery->pComputer->adwSecurityGroupsAttr );
  3828. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON3), TRUE);
  3829. }
  3830. else if ( pWizard->m_dwDefaultComputerSecurityGroupCount != 0 )
  3831. {
  3832. pWizard->FillListFromSecurityGroups( GetDlgItem(hDlg, IDC_LIST1),
  3833. pWizard->m_dwDefaultComputerSecurityGroupCount,
  3834. pWizard->m_aszDefaultComputerSecurityGroups,
  3835. pWizard->m_adwDefaultComputerSecurityGroupsAttr );
  3836. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON3), FALSE);
  3837. }
  3838. else
  3839. {
  3840. pWizard->BuildMembershipList( GetDlgItem(hDlg, IDC_LIST1),
  3841. pWizard->m_pComputerObject,
  3842. &(pWizard->m_dwDefaultComputerSecurityGroupCount),
  3843. &(pWizard->m_aszDefaultComputerSecurityGroups),
  3844. &(pWizard->m_adwDefaultComputerSecurityGroupsAttr) );
  3845. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON3), FALSE);
  3846. }
  3847. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  3848. break;
  3849. case PSN_WIZNEXT:
  3850. {
  3851. // Free the previous list of security groups
  3852. if ( pQuery->pComputer->dwSecurityGroupCount != 0 )
  3853. {
  3854. FreeStringList( pQuery->pComputer->dwSecurityGroupCount, pQuery->pComputer->aszSecurityGroups );
  3855. pQuery->pComputer->dwSecurityGroupCount = 0;
  3856. pQuery->pComputer->aszSecurityGroups = NULL;
  3857. LocalFree( pQuery->pComputer->adwSecurityGroupsAttr );
  3858. pQuery->pComputer->adwSecurityGroupsAttr = NULL;
  3859. }
  3860. // Save the current list
  3861. pWizard->SaveSecurityGroups( GetDlgItem(hDlg, IDC_LIST1),
  3862. &(pQuery->pComputer->dwSecurityGroupCount),
  3863. &(pQuery->pComputer->aszSecurityGroups),
  3864. &(pQuery->pComputer->adwSecurityGroupsAttr) );
  3865. // Compare the current list with the default list. If the default list
  3866. // matches the current list, then delete the current list and just use
  3867. // the defaults
  3868. if ( pWizard->CompareStringLists( pWizard->m_dwDefaultComputerSecurityGroupCount,
  3869. pWizard->m_aszDefaultComputerSecurityGroups,
  3870. pQuery->pComputer->dwSecurityGroupCount,
  3871. pQuery->pComputer->aszSecurityGroups ) )
  3872. {
  3873. if ( pQuery->pComputer->dwSecurityGroupCount != 0 )
  3874. {
  3875. FreeStringList( pQuery->pComputer->dwSecurityGroupCount, pQuery->pComputer->aszSecurityGroups );
  3876. pQuery->pComputer->dwSecurityGroupCount = 0;
  3877. pQuery->pComputer->aszSecurityGroups = NULL;
  3878. LocalFree( pQuery->pComputer->adwSecurityGroupsAttr );
  3879. pQuery->pComputer->adwSecurityGroupsAttr = NULL;
  3880. }
  3881. }
  3882. // Now check where to go
  3883. if (SendMessage(GetDlgItem(hDlg, IDC_RADIO1), BM_GETCHECK, 0, 0))
  3884. {
  3885. pWizard->m_dwSkippedFrom = IDD_RSOP_ALTCOMPSEC;
  3886. SetWindowLong(hDlg, DWLP_MSGRESULT, pWizard->m_lPlanningFinishedPage);
  3887. return TRUE;
  3888. }
  3889. if ( (NULL == pQuery->pUser->szName) && (NULL == pQuery->pUser->szSOM) && (RSOP_LOOPBACK_NONE == pQuery->LoopbackMode) )
  3890. {
  3891. pWizard->m_dwSkippedFrom = IDD_RSOP_ALTCOMPSEC;
  3892. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_WQLCOMP);
  3893. return TRUE;
  3894. }
  3895. pWizard->m_dwSkippedFrom = 0;
  3896. }
  3897. break;
  3898. case PSN_WIZBACK:
  3899. {
  3900. // Free the previous list of security groups
  3901. if ( pQuery->pComputer->dwSecurityGroupCount != 0 )
  3902. {
  3903. FreeStringList( pQuery->pComputer->dwSecurityGroupCount, pQuery->pComputer->aszSecurityGroups );
  3904. pQuery->pComputer->dwSecurityGroupCount = 0;
  3905. pQuery->pComputer->aszSecurityGroups = NULL;
  3906. LocalFree( pQuery->pComputer->adwSecurityGroupsAttr );
  3907. pQuery->pComputer->adwSecurityGroupsAttr = NULL;
  3908. }
  3909. // Save the current list
  3910. pWizard->SaveSecurityGroups( GetDlgItem(hDlg, IDC_LIST1),
  3911. &(pQuery->pComputer->dwSecurityGroupCount),
  3912. &(pQuery->pComputer->aszSecurityGroups),
  3913. &(pQuery->pComputer->adwSecurityGroupsAttr) );
  3914. // Compare the current list with the default list. If the default list
  3915. // matches the current list, then delete the current list and just use
  3916. // the defaults
  3917. if ( pWizard->CompareStringLists( pWizard->m_dwDefaultComputerSecurityGroupCount,
  3918. pWizard->m_aszDefaultComputerSecurityGroups,
  3919. pQuery->pComputer->dwSecurityGroupCount,
  3920. pQuery->pComputer->aszSecurityGroups ) )
  3921. {
  3922. if ( pQuery->pComputer->dwSecurityGroupCount != 0 )
  3923. {
  3924. FreeStringList( pQuery->pComputer->dwSecurityGroupCount, pQuery->pComputer->aszSecurityGroups );
  3925. pQuery->pComputer->dwSecurityGroupCount = 0;
  3926. pQuery->pComputer->aszSecurityGroups = NULL;
  3927. LocalFree( pQuery->pComputer->adwSecurityGroupsAttr );
  3928. pQuery->pComputer->adwSecurityGroupsAttr = NULL;
  3929. }
  3930. }
  3931. if ( (pQuery->pUser->szName == NULL) && (pQuery->pUser->szSOM == NULL) )
  3932. {
  3933. if ( pQuery->pComputer->szName != NULL )
  3934. {
  3935. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_ALTDIRS);
  3936. }
  3937. else
  3938. {
  3939. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_GETDC);
  3940. }
  3941. return TRUE;
  3942. }
  3943. }
  3944. break;
  3945. case PSN_WIZFINISH:
  3946. // fall through
  3947. case PSN_RESET:
  3948. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  3949. return TRUE;
  3950. }
  3951. }
  3952. break;
  3953. }
  3954. return FALSE;
  3955. }
  3956. //-------------------------------------------------------
  3957. INT_PTR CALLBACK CRSOPWizardDlg::RSOPWQLUserDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  3958. // RSOP_PLANNING_MODE
  3959. {
  3960. switch (message)
  3961. {
  3962. case WM_INITDIALOG:
  3963. {
  3964. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) (((LPPROPSHEETPAGE)lParam)->lParam);
  3965. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pWizard);
  3966. SetFocus(GetDlgItem(hDlg, IDC_RADIO2));
  3967. }
  3968. break;
  3969. case WM_COMMAND:
  3970. {
  3971. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  3972. if (!pWizard)
  3973. {
  3974. break;
  3975. }
  3976. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  3977. switch (LOWORD(wParam))
  3978. {
  3979. case IDC_BUTTON2:
  3980. {
  3981. INT iIndex;
  3982. iIndex = (INT) SendDlgItemMessage (hDlg, IDC_LIST1, LB_GETCURSEL, 0, 0);
  3983. if (iIndex != LB_ERR)
  3984. {
  3985. SendDlgItemMessage (hDlg, IDC_LIST1, LB_DELETESTRING, (WPARAM) iIndex, 0);
  3986. SendDlgItemMessage (hDlg, IDC_LIST1, LB_SETCURSEL, (WPARAM) iIndex, 0);
  3987. }
  3988. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  3989. }
  3990. break;
  3991. case IDC_BUTTON1:
  3992. {
  3993. if ( pQuery->pUser->dwWQLFilterCount != 0 )
  3994. {
  3995. FreeStringList( pQuery->pUser->dwWQLFilterCount, pQuery->pUser->aszWQLFilters );
  3996. FreeStringList( pQuery->pUser->dwWQLFilterCount, pQuery->pUser->aszWQLFilterNames );
  3997. pQuery->pUser->dwWQLFilterCount = 0;
  3998. pQuery->pUser->aszWQLFilters = NULL;
  3999. pQuery->pUser->aszWQLFilterNames = NULL;
  4000. }
  4001. pQuery->pUser->bAssumeWQLFiltersTrue = FALSE;
  4002. if ( pWizard->m_dwDefaultUserWQLFilterCount != 0 )
  4003. {
  4004. pWizard->FillListFromWQLFilters(GetDlgItem(hDlg, IDC_LIST1),
  4005. pWizard->m_dwDefaultUserWQLFilterCount,
  4006. pWizard->m_aszDefaultUserWQLFilterNames,
  4007. pWizard->m_aszDefaultUserWQLFilters );
  4008. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  4009. }
  4010. else {
  4011. PostMessage (hDlg, WM_BUILDWQLLIST, 0, 0);
  4012. }
  4013. }
  4014. break;
  4015. case IDC_RADIO2:
  4016. {
  4017. if ( IsDlgButtonChecked( hDlg, IDC_RADIO2 ) )
  4018. {
  4019. if ( pQuery->pUser->dwWQLFilterCount != 0 )
  4020. {
  4021. FreeStringList( pQuery->pUser->dwWQLFilterCount, pQuery->pUser->aszWQLFilters );
  4022. FreeStringList( pQuery->pUser->dwWQLFilterCount, pQuery->pUser->aszWQLFilterNames );
  4023. pQuery->pUser->dwWQLFilterCount = 0;
  4024. pQuery->pUser->aszWQLFilters = NULL;
  4025. pQuery->pUser->aszWQLFilterNames = NULL;
  4026. }
  4027. pQuery->pUser->bAssumeWQLFiltersTrue = TRUE;
  4028. }
  4029. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  4030. }
  4031. break;
  4032. case IDC_RADIO3:
  4033. {
  4034. if ( IsDlgButtonChecked( hDlg, IDC_RADIO3 ) )
  4035. {
  4036. pQuery->pUser->bAssumeWQLFiltersTrue = FALSE;
  4037. }
  4038. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  4039. }
  4040. break;
  4041. }
  4042. }
  4043. break;
  4044. case WM_BUILDWQLLIST:
  4045. {
  4046. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg*) GetWindowLongPtr (hDlg, DWLP_USER);
  4047. if (!pWizard)
  4048. {
  4049. break;
  4050. }
  4051. pWizard->BuildWQLFilterList (hDlg, TRUE, &(pWizard->m_dwDefaultUserWQLFilterCount),
  4052. &(pWizard->m_aszDefaultUserWQLFilterNames),
  4053. &(pWizard->m_aszDefaultUserWQLFilters) );
  4054. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  4055. }
  4056. break;
  4057. case WM_REFRESHDISPLAY:
  4058. {
  4059. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  4060. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  4061. if ( pQuery->pUser->bAssumeWQLFiltersTrue )
  4062. {
  4063. // set the listbox to null
  4064. pWizard->FillListFromWQLFilters(GetDlgItem(hDlg, IDC_LIST1), 0, NULL, NULL);
  4065. CheckDlgButton (hDlg, IDC_RADIO2, BST_CHECKED);
  4066. CheckDlgButton (hDlg, IDC_RADIO3, BST_UNCHECKED);
  4067. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON2), FALSE);
  4068. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON1), FALSE);
  4069. EnableWindow (GetDlgItem(hDlg, IDC_LIST1), FALSE);
  4070. ShowWindow(GetDlgItem(hDlg, IDC_LIST2), SW_SHOW);
  4071. ShowWindow(GetDlgItem(hDlg, IDC_LIST1), SW_HIDE);
  4072. }
  4073. else
  4074. {
  4075. CheckDlgButton (hDlg, IDC_RADIO2, BST_UNCHECKED);
  4076. CheckDlgButton (hDlg, IDC_RADIO3, BST_CHECKED);
  4077. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON1), TRUE);
  4078. EnableWindow (GetDlgItem(hDlg, IDC_LIST1), TRUE);
  4079. ShowWindow(GetDlgItem(hDlg, IDC_LIST1), SW_SHOW);
  4080. ShowWindow(GetDlgItem(hDlg, IDC_LIST2), SW_HIDE);
  4081. if (SendDlgItemMessage (hDlg, IDC_LIST1, LB_GETCOUNT, 0, 0) > 0)
  4082. {
  4083. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON2), TRUE);
  4084. }
  4085. else
  4086. {
  4087. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON2), FALSE);
  4088. }
  4089. }
  4090. }
  4091. break;
  4092. case WM_NOTIFY:
  4093. {
  4094. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg*) GetWindowLongPtr (hDlg, DWLP_USER);
  4095. if (!pWizard)
  4096. {
  4097. break;
  4098. }
  4099. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  4100. switch (((NMHDR FAR*)lParam)->code)
  4101. {
  4102. case PSN_SETACTIVE:
  4103. PropSheet_SetWizButtons (GetParent(hDlg),PSWIZB_BACK | PSWIZB_NEXT);
  4104. if ( !pQuery->pUser->bAssumeWQLFiltersTrue )
  4105. {
  4106. pWizard->FillListFromWQLFilters(GetDlgItem(hDlg, IDC_LIST1),
  4107. pQuery->pUser->dwWQLFilterCount,
  4108. pQuery->pUser->aszWQLFilterNames,
  4109. pQuery->pUser->aszWQLFilters );
  4110. }
  4111. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  4112. break;
  4113. case PSN_WIZNEXT:
  4114. {
  4115. // Free the previous list of WQL Filters
  4116. if ( pQuery->pUser->dwWQLFilterCount != 0 )
  4117. {
  4118. FreeStringList( pQuery->pUser->dwWQLFilterCount, pQuery->pUser->aszWQLFilters );
  4119. FreeStringList( pQuery->pUser->dwWQLFilterCount, pQuery->pUser->aszWQLFilterNames );
  4120. pQuery->pUser->dwWQLFilterCount = 0;
  4121. pQuery->pUser->aszWQLFilters = NULL;
  4122. pQuery->pUser->aszWQLFilterNames = NULL;
  4123. }
  4124. // Save the current list
  4125. if ( !pQuery->pUser->bAssumeWQLFiltersTrue )
  4126. {
  4127. pWizard->SaveWQLFilters(GetDlgItem(hDlg, IDC_LIST1), &(pQuery->pUser->dwWQLFilterCount),
  4128. &(pQuery->pUser->aszWQLFilterNames),
  4129. &(pQuery->pUser->aszWQLFilters) );
  4130. }
  4131. // Move to the next page
  4132. if (SendMessage(GetDlgItem(hDlg, IDC_RADIO1), BM_GETCHECK, 0, 0))
  4133. {
  4134. pWizard->m_dwSkippedFrom = IDD_RSOP_WQLUSER;
  4135. SetWindowLong(hDlg, DWLP_MSGRESULT, pWizard->m_lPlanningFinishedPage);
  4136. return TRUE;
  4137. }
  4138. if ( (NULL == pQuery->pComputer->szName) && (NULL == pQuery->pComputer->szSOM) )
  4139. {
  4140. // skip to the finish page
  4141. pWizard->m_dwSkippedFrom = IDD_RSOP_WQLUSER;
  4142. SetWindowLong(hDlg, DWLP_MSGRESULT, pWizard->m_lPlanningFinishedPage);
  4143. return TRUE;
  4144. }
  4145. pWizard->m_dwSkippedFrom = 0;
  4146. }
  4147. break;
  4148. case PSN_WIZBACK:
  4149. {
  4150. // Free the previous list of WQL Filters
  4151. if ( pQuery->pUser->dwWQLFilterCount != 0 )
  4152. {
  4153. FreeStringList( pQuery->pUser->dwWQLFilterCount, pQuery->pUser->aszWQLFilters );
  4154. FreeStringList( pQuery->pUser->dwWQLFilterCount, pQuery->pUser->aszWQLFilterNames );
  4155. pQuery->pUser->dwWQLFilterCount = 0;
  4156. pQuery->pUser->aszWQLFilters = NULL;
  4157. pQuery->pUser->aszWQLFilterNames = NULL;
  4158. }
  4159. // Save the current list
  4160. if ( !pQuery->pUser->bAssumeWQLFiltersTrue )
  4161. {
  4162. pWizard->SaveWQLFilters(GetDlgItem(hDlg, IDC_LIST1), &(pQuery->pUser->dwWQLFilterCount),
  4163. &(pQuery->pUser->aszWQLFilterNames),
  4164. &(pQuery->pUser->aszWQLFilters) );
  4165. }
  4166. // Check which page to go back to
  4167. if ( (pQuery->pComputer->szName == NULL) && (pQuery->pComputer->szSOM == NULL) )
  4168. {
  4169. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_ALTUSERSEC);
  4170. return TRUE;
  4171. }
  4172. }
  4173. break;
  4174. case PSN_WIZFINISH:
  4175. // fall through
  4176. case PSN_RESET:
  4177. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  4178. return TRUE;
  4179. }
  4180. }
  4181. break;
  4182. }
  4183. return FALSE;
  4184. }
  4185. //-------------------------------------------------------
  4186. INT_PTR CALLBACK CRSOPWizardDlg::RSOPWQLCompDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  4187. // RSOP_PLANNING_MODE
  4188. {
  4189. switch (message)
  4190. {
  4191. case WM_INITDIALOG:
  4192. {
  4193. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) (((LPPROPSHEETPAGE)lParam)->lParam);
  4194. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pWizard);
  4195. SetFocus(GetDlgItem(hDlg, IDC_RADIO2));
  4196. }
  4197. break;
  4198. case WM_COMMAND:
  4199. {
  4200. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  4201. if (!pWizard)
  4202. {
  4203. break;
  4204. }
  4205. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  4206. switch (LOWORD(wParam))
  4207. {
  4208. case IDC_BUTTON2:
  4209. {
  4210. INT iIndex;
  4211. iIndex = (INT) SendDlgItemMessage (hDlg, IDC_LIST1, LB_GETCURSEL, 0, 0);
  4212. if (iIndex != LB_ERR)
  4213. {
  4214. SendDlgItemMessage (hDlg, IDC_LIST1, LB_DELETESTRING, (WPARAM) iIndex, 0);
  4215. SendDlgItemMessage (hDlg, IDC_LIST1, LB_SETCURSEL, (WPARAM) iIndex, 0);
  4216. }
  4217. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  4218. }
  4219. break;
  4220. case IDC_BUTTON1:
  4221. {
  4222. if ( pQuery->pComputer->dwWQLFilterCount != 0 )
  4223. {
  4224. FreeStringList( pQuery->pComputer->dwWQLFilterCount, pQuery->pComputer->aszWQLFilters );
  4225. FreeStringList( pQuery->pComputer->dwWQLFilterCount, pQuery->pComputer->aszWQLFilterNames );
  4226. pQuery->pComputer->dwWQLFilterCount = 0;
  4227. pQuery->pComputer->aszWQLFilters = NULL;
  4228. pQuery->pComputer->aszWQLFilterNames = NULL;
  4229. }
  4230. pQuery->pComputer->bAssumeWQLFiltersTrue = FALSE;
  4231. if ( pWizard->m_dwDefaultComputerWQLFilterCount != 0 )
  4232. {
  4233. pWizard->FillListFromWQLFilters(GetDlgItem(hDlg, IDC_LIST1),
  4234. pWizard->m_dwDefaultComputerWQLFilterCount,
  4235. pWizard->m_aszDefaultComputerWQLFilterNames,
  4236. pWizard->m_aszDefaultComputerWQLFilters );
  4237. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  4238. }
  4239. else
  4240. {
  4241. PostMessage (hDlg, WM_BUILDWQLLIST, 0, 0);
  4242. }
  4243. }
  4244. break;
  4245. case IDC_RADIO2:
  4246. {
  4247. if ( IsDlgButtonChecked( hDlg, IDC_RADIO2 ) )
  4248. {
  4249. if ( pQuery->pComputer->dwWQLFilterCount != 0 )
  4250. {
  4251. FreeStringList( pQuery->pComputer->dwWQLFilterCount, pQuery->pComputer->aszWQLFilters );
  4252. FreeStringList( pQuery->pComputer->dwWQLFilterCount, pQuery->pComputer->aszWQLFilterNames );
  4253. pQuery->pComputer->dwWQLFilterCount = 0;
  4254. pQuery->pComputer->aszWQLFilters = NULL;
  4255. pQuery->pComputer->aszWQLFilterNames = NULL;
  4256. }
  4257. pQuery->pComputer->bAssumeWQLFiltersTrue = TRUE;
  4258. }
  4259. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  4260. }
  4261. break;
  4262. case IDC_RADIO3:
  4263. {
  4264. if ( IsDlgButtonChecked( hDlg, IDC_RADIO3 ) )
  4265. {
  4266. pQuery->pComputer->bAssumeWQLFiltersTrue = FALSE;
  4267. }
  4268. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  4269. }
  4270. break;
  4271. }
  4272. }
  4273. break;
  4274. case WM_BUILDWQLLIST:
  4275. {
  4276. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg*) GetWindowLongPtr (hDlg, DWLP_USER);
  4277. if (!pWizard)
  4278. {
  4279. break;
  4280. }
  4281. pWizard->BuildWQLFilterList (hDlg, FALSE, &(pWizard->m_dwDefaultComputerWQLFilterCount),
  4282. &(pWizard->m_aszDefaultComputerWQLFilterNames),
  4283. &(pWizard->m_aszDefaultComputerWQLFilters) );
  4284. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  4285. }
  4286. break;
  4287. case WM_REFRESHDISPLAY:
  4288. {
  4289. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  4290. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  4291. if ( pQuery->pComputer->bAssumeWQLFiltersTrue )
  4292. {
  4293. // set the listbox to null
  4294. CheckDlgButton (hDlg, IDC_RADIO2, BST_CHECKED);
  4295. CheckDlgButton (hDlg, IDC_RADIO3, BST_UNCHECKED);
  4296. pWizard->FillListFromWQLFilters(GetDlgItem(hDlg, IDC_LIST1), 0, NULL, NULL);
  4297. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON2), FALSE);
  4298. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON1), FALSE);
  4299. EnableWindow (GetDlgItem(hDlg, IDC_LIST1), FALSE);
  4300. ShowWindow(GetDlgItem(hDlg, IDC_LIST2), SW_SHOW);
  4301. ShowWindow(GetDlgItem(hDlg, IDC_LIST1), SW_HIDE);
  4302. }
  4303. else
  4304. {
  4305. CheckDlgButton (hDlg, IDC_RADIO2, BST_UNCHECKED);
  4306. CheckDlgButton (hDlg, IDC_RADIO3, BST_CHECKED);
  4307. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON1), TRUE);
  4308. EnableWindow (GetDlgItem(hDlg, IDC_LIST1), TRUE);
  4309. ShowWindow(GetDlgItem(hDlg, IDC_LIST1), SW_SHOW);
  4310. ShowWindow(GetDlgItem(hDlg, IDC_LIST2), SW_HIDE);
  4311. if (SendDlgItemMessage (hDlg, IDC_LIST1, LB_GETCOUNT, 0, 0) > 0)
  4312. {
  4313. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON2), TRUE);
  4314. }
  4315. else
  4316. {
  4317. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON2), FALSE);
  4318. }
  4319. }
  4320. }
  4321. break;
  4322. case WM_NOTIFY:
  4323. {
  4324. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  4325. if (!pWizard)
  4326. {
  4327. break;
  4328. }
  4329. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  4330. switch (((NMHDR FAR*)lParam)->code)
  4331. {
  4332. case PSN_SETACTIVE:
  4333. PropSheet_SetWizButtons (GetParent(hDlg),PSWIZB_BACK | PSWIZB_NEXT);
  4334. if ( !pQuery->pComputer->bAssumeWQLFiltersTrue )
  4335. {
  4336. pWizard->FillListFromWQLFilters(GetDlgItem(hDlg, IDC_LIST1),
  4337. pQuery->pComputer->dwWQLFilterCount,
  4338. pQuery->pComputer->aszWQLFilterNames,
  4339. pQuery->pComputer->aszWQLFilters );
  4340. }
  4341. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  4342. break;
  4343. case PSN_WIZNEXT:
  4344. {
  4345. // Free the previous list of WQL Filters
  4346. if ( pQuery->pComputer->dwWQLFilterCount != 0 )
  4347. {
  4348. FreeStringList( pQuery->pComputer->dwWQLFilterCount, pQuery->pComputer->aszWQLFilters );
  4349. FreeStringList( pQuery->pComputer->dwWQLFilterCount, pQuery->pComputer->aszWQLFilterNames );
  4350. pQuery->pComputer->dwWQLFilterCount = 0;
  4351. pQuery->pComputer->aszWQLFilters = NULL;
  4352. pQuery->pComputer->aszWQLFilterNames = NULL;
  4353. }
  4354. // Save the current list
  4355. if ( !pQuery->pComputer->bAssumeWQLFiltersTrue )
  4356. {
  4357. pWizard->SaveWQLFilters (GetDlgItem(hDlg, IDC_LIST1), &(pQuery->pComputer->dwWQLFilterCount),
  4358. &(pQuery->pComputer->aszWQLFilterNames),
  4359. &(pQuery->pComputer->aszWQLFilters) );
  4360. }
  4361. pWizard->m_dwSkippedFrom = 0;
  4362. // Skip to the last page in the wizard
  4363. SetWindowLong(hDlg, DWLP_MSGRESULT, pWizard->m_lPlanningFinishedPage);
  4364. return TRUE;
  4365. }
  4366. case PSN_WIZBACK:
  4367. {
  4368. // Free the previous list of WQL Filters
  4369. if ( pQuery->pComputer->dwWQLFilterCount != 0 )
  4370. {
  4371. FreeStringList( pQuery->pComputer->dwWQLFilterCount, pQuery->pComputer->aszWQLFilters );
  4372. FreeStringList( pQuery->pComputer->dwWQLFilterCount, pQuery->pComputer->aszWQLFilterNames );
  4373. pQuery->pComputer->dwWQLFilterCount = 0;
  4374. pQuery->pComputer->aszWQLFilters = NULL;
  4375. pQuery->pComputer->aszWQLFilterNames = NULL;
  4376. }
  4377. // Save the current list
  4378. if ( !pQuery->pComputer->bAssumeWQLFiltersTrue )
  4379. {
  4380. pWizard->SaveWQLFilters (GetDlgItem(hDlg, IDC_LIST1), &(pQuery->pComputer->dwWQLFilterCount),
  4381. &(pQuery->pComputer->aszWQLFilterNames),
  4382. &(pQuery->pComputer->aszWQLFilters) );
  4383. }
  4384. // Check which page to go back to
  4385. if ( (pQuery->pUser->szName == NULL) && (pQuery->pUser->szSOM == NULL) )
  4386. {
  4387. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_ALTCOMPSEC);
  4388. return TRUE;
  4389. }
  4390. }
  4391. break;
  4392. case PSN_WIZFINISH:
  4393. // fall through
  4394. case PSN_RESET:
  4395. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  4396. return TRUE;
  4397. }
  4398. }
  4399. break;
  4400. }
  4401. return FALSE;
  4402. }
  4403. //-------------------------------------------------------
  4404. INT_PTR CALLBACK CRSOPWizardDlg::RSOPFinishedDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  4405. // RSOP_LOGGING_MODE (IDD_RSOP_FINISHED)
  4406. // RSOP_PLANNING_MODE (IDD_RSOP_FINISHED3)
  4407. {
  4408. switch (message)
  4409. {
  4410. case WM_INITDIALOG:
  4411. {
  4412. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg*) (((LPPROPSHEETPAGE)lParam)->lParam);
  4413. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pWizard);
  4414. if (pWizard)
  4415. {
  4416. CRSOPWizard::InitializeResultsList (GetDlgItem (hDlg, IDC_LIST1));
  4417. }
  4418. }
  4419. break;
  4420. case WM_REFRESHDISPLAY:
  4421. {
  4422. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg*) GetWindowLongPtr (hDlg, DWLP_USER);
  4423. if (!pWizard)
  4424. {
  4425. break;
  4426. }
  4427. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  4428. if ( pQuery->QueryType == RSOP_PLANNING_MODE )
  4429. {
  4430. UINT n;
  4431. n = (UINT) SendMessage(GetDlgItem(hDlg, IDC_EDIT1), WM_GETTEXTLENGTH, 0, 0);
  4432. if (n > 0 )
  4433. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK | PSWIZB_NEXT);
  4434. else
  4435. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK);
  4436. }
  4437. }
  4438. break;
  4439. case WM_COMMAND:
  4440. {
  4441. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg*) GetWindowLongPtr (hDlg, DWLP_USER);
  4442. if (!pWizard)
  4443. {
  4444. break;
  4445. }
  4446. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  4447. if ( pQuery->QueryType == RSOP_PLANNING_MODE )
  4448. {
  4449. switch (LOWORD(wParam))
  4450. {
  4451. case IDC_BUTTON1:
  4452. if (DialogBoxParam (g_hInstance, MAKEINTRESOURCE(IDD_RSOP_BROWSEDC), hDlg,
  4453. BrowseDCDlgProc, (LPARAM) pWizard))
  4454. {
  4455. SetDlgItemText (hDlg, IDC_EDIT1, pQuery->szDomainController);
  4456. }
  4457. break;
  4458. case IDC_EDIT1:
  4459. if (HIWORD(wParam) == EN_CHANGE)
  4460. {
  4461. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  4462. }
  4463. break;
  4464. }
  4465. }
  4466. }
  4467. break;
  4468. case WM_NOTIFY:
  4469. {
  4470. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  4471. if (!pWizard)
  4472. {
  4473. break;
  4474. }
  4475. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  4476. switch (((NMHDR FAR*)lParam)->code)
  4477. {
  4478. case PSN_WIZBACK:
  4479. if ( pQuery->QueryType == RSOP_PLANNING_MODE )
  4480. {
  4481. if ( pWizard->m_dwSkippedFrom != 0 )
  4482. {
  4483. SetWindowLong(hDlg, DWLP_MSGRESULT, pWizard->m_dwSkippedFrom);
  4484. return TRUE;
  4485. }
  4486. else if ( (pQuery->pComputer->szName == NULL) && (pQuery->pComputer->szSOM == NULL) )
  4487. {
  4488. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_WQLUSER);
  4489. return TRUE;
  4490. }
  4491. else
  4492. {
  4493. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_WQLCOMP);
  4494. return TRUE;
  4495. }
  4496. }
  4497. else // RSOP_LOGGING_MODE
  4498. {
  4499. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_GETUSER);
  4500. return TRUE;
  4501. }
  4502. break;
  4503. case PSN_SETACTIVE:
  4504. PropSheet_SetWizButtons (GetParent(hDlg), PSWIZB_BACK | PSWIZB_NEXT);
  4505. if ( pQuery->QueryType == RSOP_PLANNING_MODE )
  4506. {
  4507. if ( pQuery->szDomainController != NULL )
  4508. {
  4509. if ( !pWizard->IsComputerRSoPEnabled(pQuery->szDomainController))
  4510. {
  4511. LocalFree( pQuery->szDomainController );
  4512. pQuery->szDomainController = NULL;
  4513. }
  4514. }
  4515. if ( pQuery->szDomainController != NULL )
  4516. {
  4517. SetDlgItemText (hDlg, IDC_EDIT1, pQuery->szDomainController);
  4518. }
  4519. else
  4520. {
  4521. SetDlgItemText (hDlg, IDC_EDIT1, TEXT(""));
  4522. }
  4523. }
  4524. CRSOPWizard::FillResultsList (GetDlgItem (hDlg, IDC_LIST1), pQuery, NULL );
  4525. if ( pWizard->m_pExtendedProcessing != NULL )
  4526. {
  4527. CheckDlgButton(hDlg, IDC_RADIO1, pWizard->m_pExtendedProcessing->GetExtendedErrorInfo() ? BST_CHECKED : BST_UNCHECKED );
  4528. }
  4529. break;
  4530. case PSN_WIZNEXT:
  4531. {
  4532. pWizard->m_bFinalNextClicked = TRUE;
  4533. if ( pQuery->QueryType == RSOP_PLANNING_MODE )
  4534. {
  4535. SetWaitCursor();
  4536. GetControlText(hDlg, IDC_EDIT1, pQuery->szDomainController, TRUE );
  4537. if ( ! pQuery->szDomainController || !pWizard->IsComputerRSoPEnabled( pQuery->szDomainController ) )
  4538. {
  4539. ClearWaitCursor();
  4540. ReportError(hDlg, GetLastError(), IDS_DCMISSINGRSOP);
  4541. pWizard->m_bFinalNextClicked = FALSE;
  4542. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  4543. return TRUE;
  4544. }
  4545. ClearWaitCursor();
  4546. }
  4547. //PropSheet_SetWizButtons (GetParent(hDlg),PSWIZB_DISABLEDFINISH);
  4548. PropSheet_SetWizButtons (GetParent(hDlg), 0);
  4549. EnableWindow (GetDlgItem(GetParent(hDlg), IDCANCEL), FALSE);
  4550. if ( pQuery->QueryType == RSOP_PLANNING_MODE )
  4551. {
  4552. EnableWindow( GetDlgItem(hDlg, IDC_BUTTON1), FALSE );
  4553. SendMessage( GetDlgItem(hDlg, IDC_EDIT1), EM_SETREADONLY, TRUE, 0 );
  4554. }
  4555. BOOL bGetExtendedInfo = FALSE;
  4556. if ( pWizard->m_pExtendedProcessing != NULL )
  4557. {
  4558. bGetExtendedInfo = (BOOL)SendMessage(GetDlgItem(hDlg, IDC_RADIO1), BM_GETCHECK, 0, 0);
  4559. EnableWindow( GetDlgItem(hDlg, IDC_RADIO1), FALSE );
  4560. }
  4561. if ( bGetExtendedInfo )
  4562. {
  4563. pWizard->m_pRSOPQuery->dwFlags |= RSOP_90P_ONLY;
  4564. }
  4565. else
  4566. {
  4567. pWizard->m_pRSOPQuery->dwFlags = pWizard->m_pRSOPQuery->dwFlags & (RSOP_90P_ONLY ^ 0xffffffff);
  4568. }
  4569. // RM: InitializeRSOP used to be called here, but now we go directly to GenerateRSOPEx
  4570. {
  4571. pWizard->m_hrQuery = CRSOPWizard::GenerateRSOPDataEx(hDlg, pWizard->m_pRSOPQuery, &(pWizard->m_pRSOPQueryResults) );
  4572. if ( pWizard->m_hrQuery != S_OK )
  4573. {
  4574. PropSheet_SetWizButtons (GetParent(hDlg),PSWIZB_BACK);
  4575. pWizard->m_bFinalNextClicked = FALSE;
  4576. EnableWindow (GetDlgItem(GetParent(hDlg), IDCANCEL), TRUE);
  4577. if ( pQuery->QueryType == RSOP_PLANNING_MODE )
  4578. {
  4579. EnableWindow( GetDlgItem(hDlg, IDC_BUTTON1), TRUE );
  4580. SendMessage( GetDlgItem(hDlg, IDC_EDIT1), EM_SETREADONLY, FALSE, 0 );
  4581. }
  4582. if ( pWizard->m_pExtendedProcessing != NULL )
  4583. {
  4584. EnableWindow( GetDlgItem(hDlg, IDC_RADIO1), TRUE );
  4585. }
  4586. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_INVALID);
  4587. return TRUE;
  4588. }
  4589. }
  4590. if ( pWizard->m_pExtendedProcessing != NULL )
  4591. {
  4592. pWizard->m_pExtendedProcessing->DoProcessing( pWizard->m_pRSOPQuery,
  4593. pWizard->m_pRSOPQueryResults,
  4594. bGetExtendedInfo );
  4595. SendMessage( GetDlgItem(hDlg, IDC_PROGRESS1), PBM_SETRANGE32, 0, (LPARAM) 100);
  4596. SendMessage( GetDlgItem(hDlg, IDC_PROGRESS1), PBM_SETPOS, (WPARAM) 100, 0);
  4597. EnableWindow( GetDlgItem(hDlg, IDC_RADIO1), TRUE );
  4598. }
  4599. // skip to the VERY last page in the wizard
  4600. if ( pQuery->QueryType == RSOP_PLANNING_MODE )
  4601. {
  4602. EnableWindow( GetDlgItem(hDlg, IDC_BUTTON1), TRUE );
  4603. SendMessage( GetDlgItem(hDlg, IDC_EDIT1), EM_SETREADONLY, FALSE, 0 );
  4604. }
  4605. SetWindowLong(hDlg, DWLP_MSGRESULT, IDD_RSOP_FINISHED2);
  4606. pWizard->m_bFinalNextClicked = FALSE;
  4607. return TRUE;
  4608. }
  4609. case PSN_RESET:
  4610. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  4611. return TRUE;
  4612. case PSN_QUERYCANCEL:
  4613. {
  4614. if (pWizard->m_bFinalNextClicked)
  4615. {
  4616. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, TRUE);
  4617. return TRUE;
  4618. }
  4619. return FALSE;
  4620. }
  4621. }
  4622. }
  4623. break;
  4624. }
  4625. return FALSE;
  4626. }
  4627. //-------------------------------------------------------
  4628. INT_PTR CALLBACK CRSOPWizardDlg::RSOPFinished2DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  4629. // Both modes
  4630. {
  4631. static BOOL iCancelQuery = FALSE;
  4632. switch (message)
  4633. {
  4634. case WM_INITDIALOG:
  4635. {
  4636. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) (((LPPROPSHEETPAGE)lParam)->lParam);
  4637. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pWizard);
  4638. SendMessage(GetDlgItem(hDlg, IDC_RSOP_BIG_BOLD1),
  4639. WM_SETFONT, (WPARAM)pWizard->m_BigBoldFont, (LPARAM)TRUE);
  4640. /*
  4641. if (!pWizard->m_hChooseBitmap)
  4642. {
  4643. pWizard->m_hChooseBitmap = (HBITMAP) LoadImage (g_hInstance,
  4644. MAKEINTRESOURCE(IDB_WIZARD),
  4645. IMAGE_BITMAP, 0, 0,
  4646. LR_DEFAULTCOLOR);
  4647. }
  4648. if (pWizard->m_hChooseBitmap)
  4649. {
  4650. SendDlgItemMessage (hDlg, IDC_BITMAP, STM_SETIMAGE,
  4651. IMAGE_BITMAP, (LPARAM) pWizard->m_hChooseBitmap);
  4652. }
  4653. */
  4654. }
  4655. break;
  4656. case WM_NOTIFY:
  4657. {
  4658. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  4659. if (!pWizard)
  4660. {
  4661. break;
  4662. }
  4663. switch (((NMHDR FAR*)lParam)->code)
  4664. {
  4665. case PSN_SETACTIVE:
  4666. PropSheet_SetWizButtons (GetParent(hDlg), PSWIZB_FINISH);
  4667. break;
  4668. case PSN_WIZFINISH:
  4669. // fall through
  4670. case PSN_RESET:
  4671. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  4672. return TRUE;
  4673. // Ignore the 'X' button on the upper right corner
  4674. case PSN_QUERYCANCEL:
  4675. {
  4676. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, TRUE);
  4677. return TRUE;
  4678. }
  4679. }
  4680. }
  4681. break;
  4682. }
  4683. return FALSE;
  4684. }
  4685. //-------------------------------------------------------
  4686. HRESULT CRSOPWizardDlg::SetupFonts()
  4687. {
  4688. HRESULT hr;
  4689. LOGFONT BigBoldLogFont;
  4690. LOGFONT BoldLogFont;
  4691. HDC pdc = NULL;
  4692. WCHAR largeFontSizeString[128];
  4693. INT largeFontSize;
  4694. WCHAR smallFontSizeString[128];
  4695. INT smallFontSize;
  4696. //
  4697. // Create the fonts we need based on the dialog font
  4698. //
  4699. NONCLIENTMETRICS ncm = {0};
  4700. ncm.cbSize = sizeof (ncm);
  4701. if (SystemParametersInfo (SPI_GETNONCLIENTMETRICS, 0, &ncm, 0) == FALSE) {
  4702. hr = HRESULT_FROM_WIN32(GetLastError());
  4703. goto end;
  4704. }
  4705. BigBoldLogFont = ncm.lfMessageFont;
  4706. BoldLogFont = ncm.lfMessageFont;
  4707. //
  4708. // Create Big Bold Font and Bold Font
  4709. //
  4710. BigBoldLogFont.lfWeight = FW_BOLD;
  4711. BoldLogFont.lfWeight = FW_BOLD;
  4712. //
  4713. // Load size and name from resources, since these may change
  4714. // from locale to locale based on the size of the system font, etc.
  4715. //
  4716. if ( !LoadString (g_hInstance, IDS_LARGEFONTNAME, BigBoldLogFont.lfFaceName, LF_FACESIZE) )
  4717. {
  4718. ASSERT (0);
  4719. hr = StringCchCopy (BigBoldLogFont.lfFaceName, LF_FACESIZE, L"Verdana");
  4720. if (FAILED(hr))
  4721. {
  4722. goto end;
  4723. }
  4724. }
  4725. if ( LoadString (g_hInstance, IDS_LARGEFONTSIZE, largeFontSizeString, ARRAYSIZE(largeFontSizeString)) )
  4726. {
  4727. largeFontSize = wcstoul ((LPCWSTR) largeFontSizeString, NULL, 10);
  4728. }
  4729. else
  4730. {
  4731. ASSERT (0);
  4732. largeFontSize = 12;
  4733. }
  4734. if ( !LoadString (g_hInstance, IDS_SMALLFONTNAME, BoldLogFont.lfFaceName, LF_FACESIZE) )
  4735. {
  4736. ASSERT (0);
  4737. hr = StringCchCopy (BoldLogFont.lfFaceName, LF_FACESIZE, L"Verdana");
  4738. if (FAILED(hr))
  4739. {
  4740. goto end;
  4741. }
  4742. }
  4743. if ( LoadString (g_hInstance, IDS_SMALLFONTSIZE, smallFontSizeString, ARRAYSIZE(smallFontSizeString)) )
  4744. {
  4745. smallFontSize = wcstoul ((LPCWSTR) smallFontSizeString, NULL, 10);
  4746. }
  4747. else
  4748. {
  4749. ASSERT (0);
  4750. smallFontSize = 8;
  4751. }
  4752. pdc = GetDC (NULL);
  4753. if (pdc == NULL) {
  4754. hr = HRESULT_FROM_WIN32(GetLastError());
  4755. goto end;
  4756. }
  4757. BigBoldLogFont.lfHeight = 0 - (GetDeviceCaps (pdc, LOGPIXELSY) * largeFontSize / 72);
  4758. BoldLogFont.lfHeight = 0 - (GetDeviceCaps (pdc, LOGPIXELSY) * smallFontSize / 72);
  4759. m_BigBoldFont = CreateFontIndirect (&BigBoldLogFont);
  4760. if (m_BigBoldFont == NULL) {
  4761. hr = HRESULT_FROM_WIN32(GetLastError());
  4762. goto end;
  4763. }
  4764. m_BoldFont = CreateFontIndirect (&BoldLogFont);
  4765. if (m_BoldFont == NULL) {
  4766. hr = HRESULT_FROM_WIN32(GetLastError());
  4767. goto end;
  4768. }
  4769. hr = S_OK;
  4770. end:
  4771. if (pdc != NULL) {
  4772. ReleaseDC (NULL, pdc);
  4773. pdc = NULL;
  4774. }
  4775. return hr;
  4776. }
  4777. //-------------------------------------------------------
  4778. HRESULT CRSOPWizardDlg::FillUserList (HWND hList, BOOL* pbFoundCurrentUser, BOOL* pbFoundFixedUser)
  4779. {
  4780. HRESULT hr, hrSuccess;
  4781. IWbemServices * pNamespace = NULL;
  4782. IWbemClassObject * pOutInst = NULL;
  4783. BSTR bstrParam = NULL;
  4784. BSTR bstrClassPath = NULL;
  4785. BSTR bstrMethodName = NULL;
  4786. VARIANT var;
  4787. TCHAR szBuffer[MAX_PATH];
  4788. IWbemLocator * pLocator = NULL;
  4789. SAFEARRAY * psa;
  4790. LONG lMax, lIndex;
  4791. BSTR bstrSid;
  4792. PSID pSid;
  4793. TCHAR szName[125];
  4794. TCHAR szDomain[125];
  4795. TCHAR szFullName[MAX_PATH];
  4796. DWORD dwNameSize, dwDomainSize;
  4797. SID_NAME_USE NameUse;
  4798. LPTSTR lpData, szUserSidPref = NULL;
  4799. INT iRet;
  4800. LVITEM item;
  4801. LPTSTR lpCurrentUserSid = NULL;
  4802. HANDLE hToken;
  4803. LPTSTR lpSystemName = NULL;
  4804. BOOL bFixUser = FALSE;
  4805. *pbFoundFixedUser = FALSE;
  4806. // This method only gets called from RSOPGetUserDlgProc, which means that it must be logging mode!
  4807. if ( m_pRSOPQuery->QueryType != RSOP_LOGGING_MODE )
  4808. {
  4809. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::FillUserList: Not called in planning mode.") ));
  4810. return E_FAIL;
  4811. }
  4812. if ( m_pRSOPQuery->szComputerName == NULL )
  4813. {
  4814. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::FillUserList: Called without computer name set.") ));
  4815. return E_FAIL;
  4816. }
  4817. bFixUser = (m_pRSOPQuery->dwFlags & RSOP_FIX_USER) == RSOP_FIX_USER;
  4818. // Get the "selected" user's Sid
  4819. if ( (m_pRSOPQuery->szUserName != NULL) && bFixUser )
  4820. {
  4821. szUserSidPref = MyLookupAccountName(
  4822. (lstrcmpi( m_pRSOPQuery->szComputerName, TEXT(".")) == 0) ? NULL : NameWithoutDomain(m_pRSOPQuery->szComputerName),
  4823. m_pRSOPQuery->szUserName );
  4824. if ( szUserSidPref == NULL )
  4825. {
  4826. hr = HRESULT_FROM_WIN32(GetLastError());
  4827. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::FillUserList: MyLookupAccountName failed with %d"), hr));
  4828. }
  4829. }
  4830. if ( lstrcmpi(m_pRSOPQuery->szComputerName, TEXT(".")) )
  4831. {
  4832. lpSystemName = m_pRSOPQuery->szComputerName;
  4833. }
  4834. *pbFoundCurrentUser = FALSE;
  4835. if (OpenProcessToken (GetCurrentProcess(), TOKEN_READ, &hToken))
  4836. {
  4837. lpCurrentUserSid = GetSidString(hToken);
  4838. CloseHandle (hToken);
  4839. }
  4840. hr = CoCreateInstance(CLSID_WbemLocator,
  4841. 0,
  4842. CLSCTX_INPROC_SERVER,
  4843. IID_IWbemLocator,
  4844. (LPVOID *) &pLocator);
  4845. if (FAILED(hr))
  4846. {
  4847. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::FillUserList: CoCreateInstance failed with 0x%x"), hr));
  4848. goto Cleanup;
  4849. }
  4850. // Set up diagnostic mode
  4851. // Build a path to the target: "\\\\computer\\root\\rsop"
  4852. hr = StringCchPrintf (szBuffer, ARRAYSIZE(szBuffer), TEXT("\\\\%s\\root\\rsop"), NameWithoutDomain(m_pRSOPQuery->szComputerName));
  4853. if (FAILED(hr))
  4854. {
  4855. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::FillUserList: Could not copy Name without domain with 0x%x"), hr));
  4856. goto Cleanup;
  4857. }
  4858. bstrParam = SysAllocString(szBuffer);
  4859. hr = pLocator->ConnectServer(bstrParam,
  4860. NULL,
  4861. NULL,
  4862. NULL,
  4863. 0,
  4864. NULL,
  4865. NULL,
  4866. &pNamespace);
  4867. if (FAILED(hr))
  4868. {
  4869. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::FillUserList: ConnectServer to %s failed with 0x%x"), szBuffer, hr));
  4870. goto Cleanup;
  4871. }
  4872. // Set the proper security to prevent the ExecMethod call from failing and to enable encryption
  4873. hr = CoSetProxyBlanket(pNamespace,
  4874. RPC_C_AUTHN_DEFAULT,
  4875. RPC_C_AUTHZ_DEFAULT,
  4876. COLE_DEFAULT_PRINCIPAL,
  4877. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  4878. RPC_C_IMP_LEVEL_IMPERSONATE,
  4879. NULL,
  4880. 0);
  4881. if (FAILED(hr))
  4882. {
  4883. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::FillUserList: CoSetProxyBlanket failed with 0x%x"), hr));
  4884. goto Cleanup;
  4885. }
  4886. bstrClassPath = SysAllocString(TEXT("RsopLoggingModeProvider"));
  4887. bstrMethodName = SysAllocString(TEXT("RsopEnumerateUsers"));
  4888. hr = pNamespace->ExecMethod(bstrClassPath,
  4889. bstrMethodName,
  4890. 0,
  4891. NULL,
  4892. NULL,
  4893. &pOutInst,
  4894. NULL);
  4895. if (FAILED(hr))
  4896. {
  4897. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::FillUserList: ExecMethod failed with 0x%x"), hr));
  4898. goto Cleanup;
  4899. }
  4900. hr = GetParameter(pOutInst, TEXT("hResult"), hrSuccess);
  4901. if (SUCCEEDED(hr) && SUCCEEDED(hrSuccess))
  4902. {
  4903. VariantInit(&var);
  4904. hr = pOutInst->Get(TEXT("userSids"), 0, &var, 0, 0);
  4905. if (SUCCEEDED(hr))
  4906. {
  4907. if (var.vt & VT_ARRAY)
  4908. {
  4909. psa = var.parray;
  4910. if (SUCCEEDED( SafeArrayGetUBound(psa, 1, &lMax)))
  4911. {
  4912. for (lIndex = 0; lIndex <= lMax; lIndex++)
  4913. {
  4914. if (SUCCEEDED(SafeArrayGetElement (psa, &lIndex, &bstrSid)))
  4915. {
  4916. ULONG ulNoChars = lstrlen(bstrSid) + 1;
  4917. lpData = new WCHAR[ulNoChars];
  4918. if (lpData)
  4919. {
  4920. hr = StringCchCopy (lpData, ulNoChars, bstrSid);
  4921. ASSERT(SUCCEEDED(hr));
  4922. if (lpCurrentUserSid)
  4923. {
  4924. if (!lstrcmpi(lpCurrentUserSid, lpData))
  4925. {
  4926. *pbFoundCurrentUser = TRUE;
  4927. }
  4928. }
  4929. if (NT_SUCCESS(AllocateAndInitSidFromString (bstrSid, &pSid)))
  4930. {
  4931. dwNameSize = ARRAYSIZE(szName);
  4932. dwDomainSize = ARRAYSIZE(szDomain);
  4933. if (LookupAccountSid (NameWithoutDomain(lpSystemName), pSid, szName, &dwNameSize,
  4934. szDomain, &dwDomainSize, &NameUse))
  4935. {
  4936. BOOL bAddUser;
  4937. bAddUser = (!bFixUser || (lstrcmpi(szUserSidPref, lpData) == 0));
  4938. if ( bFixUser && (lstrcmpi(szUserSidPref, lpData) == 0))
  4939. {
  4940. *pbFoundFixedUser = TRUE;
  4941. m_pRSOPQuery->szUserSid = szUserSidPref;
  4942. }
  4943. if (bAddUser)
  4944. {
  4945. hr = StringCchPrintf (szFullName, ARRAYSIZE(szFullName), TEXT("%s\\%s"), szDomain, szName);
  4946. if (SUCCEEDED(hr))
  4947. {
  4948. ZeroMemory (&item, sizeof(item));
  4949. item.mask = LVIF_TEXT | LVIF_PARAM;
  4950. item.pszText = szFullName;
  4951. item.lParam = (LPARAM) lpData;
  4952. iRet = ListView_InsertItem(hList, &item);
  4953. if (iRet == -1)
  4954. {
  4955. delete [] lpData;
  4956. }
  4957. else if ( (szUserSidPref != NULL) && !lstrcmpi(szUserSidPref, lpData) )
  4958. {
  4959. ListView_SetItemState( hList, iRet, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  4960. }
  4961. }
  4962. }
  4963. }
  4964. else
  4965. {
  4966. delete [] lpData;
  4967. }
  4968. RtlFreeSid(pSid);
  4969. }
  4970. else
  4971. {
  4972. delete [] lpData;
  4973. }
  4974. }
  4975. }
  4976. }
  4977. }
  4978. }
  4979. }
  4980. VariantClear(&var);
  4981. item.mask = LVIF_STATE;
  4982. item.iItem = 0;
  4983. item.iSubItem = 0;
  4984. item.state = LVIS_SELECTED | LVIS_FOCUSED;
  4985. item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  4986. SendMessage (hList, LVM_SETITEMSTATE, 0, (LPARAM) &item);
  4987. }
  4988. else
  4989. {
  4990. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::FillUserList: Either GetParameter or the return value failed. hr = 0x%x, hrSuccess = 0x%x"), hr, hrSuccess));
  4991. }
  4992. if ( bFixUser && !(*pbFoundFixedUser) )
  4993. {
  4994. hr = HRESULT_FROM_WIN32(ERROR_NO_SUCH_USER);
  4995. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::FillUserList: User not found on the machine")));
  4996. }
  4997. Cleanup:
  4998. SysFreeString(bstrParam);
  4999. SysFreeString(bstrClassPath);
  5000. SysFreeString(bstrMethodName);
  5001. if (pOutInst)
  5002. {
  5003. pOutInst->Release();
  5004. }
  5005. if (pNamespace)
  5006. {
  5007. pNamespace->Release();
  5008. }
  5009. if (pLocator)
  5010. {
  5011. pLocator->Release();
  5012. }
  5013. if (lpCurrentUserSid)
  5014. {
  5015. DeleteSidString(lpCurrentUserSid);
  5016. }
  5017. if ( !(*pbFoundFixedUser))
  5018. {
  5019. LocalFree(szUserSidPref);
  5020. }
  5021. return hr;
  5022. }
  5023. //-------------------------------------------------------
  5024. VOID CRSOPWizardDlg::EscapeString (LPTSTR *lpString)
  5025. {
  5026. IADsPathname * pADsPathnameDest = NULL;
  5027. IADsPathname * pADsPathnameSrc = NULL;
  5028. HRESULT hr;
  5029. BSTR bstr = NULL, bstrResult;
  5030. LPTSTR lpTemp;
  5031. LONG lIndex, lCount;
  5032. //
  5033. // Create a pathname object to put the source string into so we
  5034. // can take it apart one element at a time.
  5035. //
  5036. hr = CoCreateInstance(CLSID_Pathname, NULL, CLSCTX_INPROC_SERVER,
  5037. IID_IADsPathname, (LPVOID*)&pADsPathnameSrc);
  5038. if (FAILED(hr))
  5039. {
  5040. goto Exit;
  5041. }
  5042. hr = pADsPathnameSrc->put_EscapedMode (ADS_ESCAPEDMODE_OFF_EX);
  5043. if (FAILED(hr))
  5044. {
  5045. goto Exit;
  5046. }
  5047. //
  5048. // Set the provider to LDAP and set the source string
  5049. //
  5050. BSTR bstrLDAP = SysAllocString(TEXT("LDAP"));
  5051. if ( bstrLDAP == NULL )
  5052. {
  5053. hr = E_OUTOFMEMORY;
  5054. goto Exit;
  5055. }
  5056. hr = pADsPathnameSrc->Set (bstrLDAP, ADS_SETTYPE_PROVIDER);
  5057. SysFreeString( bstrLDAP );
  5058. if (FAILED(hr))
  5059. {
  5060. goto Exit;
  5061. }
  5062. BSTR bstrTmpString = SysAllocString( *lpString );
  5063. if ( bstrTmpString == NULL )
  5064. {
  5065. hr = E_OUTOFMEMORY;
  5066. goto Exit;
  5067. }
  5068. hr = pADsPathnameSrc->Set (bstrTmpString, ADS_SETTYPE_DN);
  5069. SysFreeString( bstrTmpString );
  5070. if (FAILED(hr))
  5071. {
  5072. goto Exit;
  5073. }
  5074. //
  5075. // Query for the number of elements
  5076. //
  5077. hr = pADsPathnameSrc->GetNumElements (&lCount);
  5078. if (FAILED(hr))
  5079. {
  5080. goto Exit;
  5081. }
  5082. //
  5083. // Create a pathname object to put the freshly escaped string into
  5084. //
  5085. hr = CoCreateInstance(CLSID_Pathname, NULL, CLSCTX_INPROC_SERVER,
  5086. IID_IADsPathname, (LPVOID*)&pADsPathnameDest);
  5087. if (FAILED(hr))
  5088. {
  5089. goto Exit;
  5090. }
  5091. hr = pADsPathnameDest->put_EscapedMode(ADS_ESCAPEDMODE_ON );
  5092. if (FAILED(hr))
  5093. {
  5094. goto Exit;
  5095. }
  5096. //
  5097. // Loop through the string one element at at time escaping the RDN
  5098. //
  5099. for (lIndex = lCount; lIndex > 0; lIndex--)
  5100. {
  5101. //
  5102. // Get this element
  5103. //
  5104. hr = pADsPathnameSrc->GetElement ((lIndex - 1), &bstr);
  5105. if (FAILED(hr))
  5106. {
  5107. goto Exit;
  5108. }
  5109. //
  5110. // Check for escape characters
  5111. //
  5112. hr = pADsPathnameDest->GetEscapedElement (0, bstr, &bstrResult);
  5113. if (FAILED(hr))
  5114. {
  5115. goto Exit;
  5116. }
  5117. //
  5118. // Add the new element to the destination pathname object
  5119. //
  5120. hr = pADsPathnameDest->AddLeafElement (bstrResult);
  5121. SysFreeString (bstrResult);
  5122. if (FAILED(hr))
  5123. {
  5124. goto Exit;
  5125. }
  5126. SysFreeString (bstr);
  5127. bstr = NULL;
  5128. }
  5129. //
  5130. // Get the final path
  5131. //
  5132. hr = pADsPathnameDest->Retrieve (ADS_FORMAT_X500_DN, &bstr);
  5133. if (FAILED(hr))
  5134. {
  5135. goto Exit;
  5136. }
  5137. //
  5138. // Allocate a new buffer to hold the string
  5139. //
  5140. ULONG ulNoChars = lstrlen(bstr) + 1;
  5141. lpTemp = new TCHAR [ulNoChars];
  5142. if (lpTemp)
  5143. {
  5144. hr = StringCchCopy (lpTemp, ulNoChars, bstr);
  5145. ASSERT(SUCCEEDED(hr));
  5146. delete [] *lpString;
  5147. *lpString = lpTemp;
  5148. }
  5149. Exit:
  5150. if (bstr)
  5151. {
  5152. SysFreeString (bstr);
  5153. }
  5154. if (pADsPathnameDest)
  5155. {
  5156. pADsPathnameDest->Release();
  5157. }
  5158. if (pADsPathnameSrc)
  5159. {
  5160. pADsPathnameSrc->Release();
  5161. }
  5162. }
  5163. //-------------------------------------------------------
  5164. INT CALLBACK CRSOPWizardDlg::DsBrowseCallback (HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
  5165. {
  5166. if (uMsg == DSBM_HELP)
  5167. {
  5168. WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_FILE, HELP_WM_HELP,
  5169. (ULONG_PTR) (LPSTR) g_aBrowseForOUHelpIds);
  5170. }
  5171. else if (uMsg == DSBM_CONTEXTMENU)
  5172. {
  5173. WinHelp((HWND) lParam, HELP_FILE, HELP_CONTEXTMENU,
  5174. (ULONG_PTR) (LPSTR) g_aBrowseForOUHelpIds);
  5175. }
  5176. return 0;
  5177. }
  5178. //-------------------------------------------------------
  5179. INT_PTR CALLBACK CRSOPWizardDlg::BrowseDCDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  5180. // Only called in RSOPFinishedDlgProc where QueryType == RSOP_PLANNING_MODE
  5181. {
  5182. switch (message)
  5183. {
  5184. case WM_INITDIALOG:
  5185. {
  5186. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) lParam;
  5187. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pWizard);
  5188. pWizard->InitializeDCInfo(hDlg);
  5189. return TRUE;
  5190. }
  5191. case WM_COMMAND:
  5192. {
  5193. CRSOPWizardDlg* pWizard = (CRSOPWizardDlg *) GetWindowLongPtr (hDlg, DWLP_USER);
  5194. if (!pWizard)
  5195. {
  5196. break;
  5197. }
  5198. LPRSOP_QUERY pQuery = pWizard->m_pRSOPQuery;
  5199. if (LOWORD(wParam) == IDOK)
  5200. {
  5201. INT iSel, iStrLen;
  5202. iSel = (INT) SendDlgItemMessage (hDlg, IDC_LIST1, LB_GETCURSEL, 0, 0);
  5203. if (iSel == LB_ERR)
  5204. {
  5205. break;
  5206. }
  5207. iStrLen = (INT) SendDlgItemMessage (hDlg, IDC_LIST1, LB_GETTEXTLEN, (WPARAM) iSel, 0);
  5208. if (iStrLen == LB_ERR)
  5209. {
  5210. break;
  5211. }
  5212. if ( pQuery->QueryType == RSOP_PLANNING_MODE )
  5213. {
  5214. LocalFree( pQuery->szDomainController );
  5215. pQuery->szDomainController = (TCHAR*)LocalAlloc( LPTR, (iStrLen+1) * sizeof(TCHAR) );
  5216. if ( pQuery->szDomainController == NULL )
  5217. {
  5218. break;
  5219. }
  5220. SendDlgItemMessage (hDlg, IDC_LIST1, LB_GETTEXT, (WPARAM) iSel, (LPARAM) pQuery->szDomainController );
  5221. }
  5222. EndDialog(hDlg, 1);
  5223. return TRUE;
  5224. }
  5225. if (LOWORD(wParam) == IDCANCEL)
  5226. {
  5227. EndDialog(hDlg, 0);
  5228. return TRUE;
  5229. }
  5230. }
  5231. break;
  5232. case WM_HELP: // F1
  5233. WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_FILE, HELP_WM_HELP,
  5234. (ULONG_PTR) (LPSTR) g_aBrowseDCHelpIds);
  5235. break;
  5236. case WM_CONTEXTMENU: // right mouse click
  5237. WinHelp((HWND) wParam, HELP_FILE, HELP_CONTEXTMENU,
  5238. (ULONG_PTR) (LPSTR) g_aBrowseDCHelpIds);
  5239. return (TRUE);
  5240. }
  5241. return FALSE;
  5242. }
  5243. //-------------------------------------------------------
  5244. VOID CRSOPWizardDlg::InitializeSitesInfo (HWND hDlg)
  5245. // RSOP_PLANNING_MODE - only called from RSOPGetDCDlgProc
  5246. {
  5247. LPTSTR szDomain = NULL;
  5248. PDS_NAME_RESULTW pSites;
  5249. int iInitialSite = 0;
  5250. int iIndex, iDefault = CB_ERR;
  5251. HANDLE hDs;
  5252. DWORD dw, n;
  5253. SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_RESETCONTENT, 0, 0);
  5254. // Determine the focused domain.
  5255. if ( m_pRSOPQuery->pComputer->szName != NULL )
  5256. {
  5257. // Try and get the computer's domain
  5258. szDomain = ExtractDomain( m_pRSOPQuery->pComputer->szName );
  5259. }
  5260. if ( (szDomain == NULL) && (m_pRSOPQuery->pComputer->szSOM != NULL) )
  5261. {
  5262. // Try and get the computer's domain from the SOM
  5263. szDomain = GetDomainFromSOM( m_pRSOPQuery->pComputer->szSOM );
  5264. }
  5265. if ( (szDomain == NULL) && (m_pRSOPQuery->pUser->szName != NULL) )
  5266. {
  5267. // Try and get the user's domain
  5268. szDomain = ExtractDomain( m_pRSOPQuery->pUser->szName );
  5269. }
  5270. if ( (szDomain == NULL) && (m_pRSOPQuery->pUser->szSOM != NULL) )
  5271. {
  5272. // Try and get the user's domain from the SOM
  5273. szDomain = GetDomainFromSOM( m_pRSOPQuery->pUser->szSOM );
  5274. }
  5275. if ( szDomain == NULL )
  5276. {
  5277. // Use the local domain
  5278. LPTSTR szName;
  5279. szName = MyGetUserName(NameSamCompatible);
  5280. if ( szName != NULL )
  5281. {
  5282. szDomain = ExtractDomain(szName);
  5283. LocalFree( szName );
  5284. }
  5285. }
  5286. // Bind to the domain
  5287. dw = DsBindW(NULL, szDomain, &hDs);
  5288. if (dw == ERROR_SUCCESS)
  5289. {
  5290. // If we have a site pref, show only that..
  5291. if ( (m_pRSOPQuery->dwFlags & RSOP_FIX_SITENAME) == RSOP_FIX_SITENAME )
  5292. {
  5293. LPWSTR szSiteFriendlyName=NULL;
  5294. // Get the friendly name
  5295. if ( GetSiteFriendlyName(m_pRSOPQuery->szSite, &szSiteFriendlyName) )
  5296. {
  5297. SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_ADDSTRING,
  5298. (WPARAM) 0, (LPARAM) (LPCTSTR) szSiteFriendlyName);
  5299. delete [] szSiteFriendlyName;
  5300. }
  5301. }
  5302. else
  5303. {
  5304. // Query for the list of sites
  5305. dw = DsListSitesW(hDs, &pSites);
  5306. if (dw == ERROR_SUCCESS)
  5307. {
  5308. for (n = 0; n < pSites->cItems; n++)
  5309. {
  5310. // Add the site name (if it has a name)
  5311. if (pSites->rItems[n].pName)
  5312. {
  5313. LPWSTR szSiteFriendlyName=NULL;
  5314. if (GetSiteFriendlyName(pSites->rItems[n].pName, &szSiteFriendlyName))
  5315. {
  5316. SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_ADDSTRING,
  5317. (WPARAM) 0, (LPARAM) (LPCTSTR) szSiteFriendlyName);
  5318. delete [] szSiteFriendlyName;
  5319. }
  5320. }
  5321. }
  5322. DsFreeNameResultW(pSites);
  5323. }
  5324. else
  5325. {
  5326. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeSitesInfo: DsListSites failed with 0x%x"), dw));
  5327. }
  5328. }
  5329. DsUnBindW(&hDs);
  5330. }
  5331. else
  5332. {
  5333. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeSitesInfo: DsBindW failed with 0x%x"), dw));
  5334. }
  5335. if ( (m_pRSOPQuery->dwFlags & RSOP_FIX_SITENAME) == 0 )
  5336. {
  5337. TCHAR szString[1024];
  5338. LoadString (g_hInstance, IDS_NONE, szString, ARRAYSIZE(szString));
  5339. iIndex = (int) SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_ADDSTRING,
  5340. (WPARAM) 0, (LPARAM) (LPCTSTR) szString);
  5341. }
  5342. // Set the initial selection
  5343. if ( (m_pRSOPQuery->dwFlags & RSOP_FIX_SITENAME) == RSOP_FIX_SITENAME )
  5344. {
  5345. iDefault = (INT) SendMessage (GetDlgItem(hDlg, IDC_COMBO1), CB_FINDSTRINGEXACT,
  5346. (WPARAM) -1, (LPARAM) m_pRSOPQuery->szSite );
  5347. }
  5348. else if ( m_pRSOPQuery->szSite != NULL )
  5349. {
  5350. iDefault = (INT) SendMessage (GetDlgItem(hDlg, IDC_COMBO1), CB_FINDSTRINGEXACT,
  5351. (WPARAM) -1, (LPARAM) m_pRSOPQuery->szSite);
  5352. }
  5353. SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_SETCURSEL,
  5354. (WPARAM) (iDefault == CB_ERR) ? iIndex : iDefault, NULL);
  5355. if ( szDomain != NULL )
  5356. {
  5357. delete [] szDomain;
  5358. }
  5359. }
  5360. //-------------------------------------------------------
  5361. BOOL CRSOPWizardDlg::IsComputerRSoPEnabled(LPTSTR lpComputerName)
  5362. {
  5363. LPSTR lpComputerNameA;
  5364. LPTSTR lpName, lpWMIPath;
  5365. HRESULT hr;
  5366. BOOL bRetVal = FALSE;
  5367. struct hostent *hostp;
  5368. DWORD dwResult, dwSize = (lstrlen(lpComputerName) + 1) * 2;
  5369. ULONG inaddr, ulSpeed;
  5370. IWbemLocator * pLocator = 0;
  5371. IWbemServices * pNamespace = 0;
  5372. BSTR bstrPath;
  5373. SetLastError(ERROR_SUCCESS);
  5374. //
  5375. // Allocate memory for a ANSI computer name
  5376. //
  5377. lpComputerNameA = new CHAR[dwSize];
  5378. if (lpComputerNameA)
  5379. {
  5380. //
  5381. // Skip the leading \\ if present
  5382. //
  5383. if ((*lpComputerName == TEXT('\\')) && (*(lpComputerName+1) == TEXT('\\')))
  5384. {
  5385. lpName = lpComputerName + 2;
  5386. }
  5387. else
  5388. {
  5389. lpName = lpComputerName;
  5390. }
  5391. //
  5392. // Convert the computer name to ANSI
  5393. //
  5394. if (WideCharToMultiByte (CP_ACP, 0, lpName, -1, lpComputerNameA, dwSize, NULL, NULL))
  5395. {
  5396. //
  5397. // Get the host information for the computer
  5398. //
  5399. hostp = gethostbyname(lpComputerNameA);
  5400. if (hostp)
  5401. {
  5402. //
  5403. // Get the ip address of the computer
  5404. //
  5405. inaddr = *(long *)hostp->h_addr;
  5406. //
  5407. // Create an instance of the WMI locator
  5408. //
  5409. hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER,
  5410. IID_IWbemLocator, (LPVOID *) &pLocator);
  5411. if (SUCCEEDED(hr))
  5412. {
  5413. //
  5414. // Try to connect to the rsop namespace
  5415. //
  5416. dwSize = lstrlen(lpName) + 20;
  5417. lpWMIPath = new TCHAR[dwSize];
  5418. if (lpWMIPath)
  5419. {
  5420. hr = StringCchPrintf (lpWMIPath, dwSize, TEXT("\\\\%s\\root\\rsop"), lpName);
  5421. if (SUCCEEDED(hr))
  5422. {
  5423. bstrPath = SysAllocString(lpWMIPath);
  5424. if (bstrPath)
  5425. {
  5426. hr = pLocator->ConnectServer(bstrPath,
  5427. NULL,
  5428. NULL,
  5429. NULL,
  5430. 0,
  5431. NULL,
  5432. NULL,
  5433. &pNamespace);
  5434. if (SUCCEEDED(hr))
  5435. {
  5436. //
  5437. // Success. This computer has RSOP support
  5438. //
  5439. pNamespace->Release();
  5440. bRetVal = TRUE;
  5441. }
  5442. else
  5443. {
  5444. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::IsComputerRSoPEnabled: ConnectServer for %s failed with 0x%x"), bstrPath, hr));
  5445. }
  5446. SysFreeString (bstrPath);
  5447. //
  5448. // Set hr into the last error code. Note, this has to happen after
  5449. // the call to SysFreeString since it changes the last error code
  5450. // to success
  5451. //
  5452. if (hr != S_OK)
  5453. {
  5454. SetLastError(hr);
  5455. }
  5456. }
  5457. else
  5458. {
  5459. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::IsComputerRSoPEnabled: SysAllocString failed")));
  5460. SetLastError(ERROR_OUTOFMEMORY);
  5461. }
  5462. }
  5463. else
  5464. {
  5465. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::IsComputerRSoPEnabled: Could not copy WMI path")));
  5466. SetLastError(HRESULT_CODE(hr));
  5467. }
  5468. delete [] lpWMIPath;
  5469. }
  5470. else
  5471. {
  5472. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::IsComputerRSoPEnabled: Failed to alloc memory for wmi path.")));
  5473. SetLastError(ERROR_OUTOFMEMORY);
  5474. }
  5475. pLocator->Release();
  5476. }
  5477. else
  5478. {
  5479. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::IsComputerRSoPEnabled: CoCreateInstance failed with 0x%x."), hr));
  5480. SetLastError((DWORD)hr);
  5481. }
  5482. }
  5483. else
  5484. {
  5485. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::IsComputerRSoPEnabled: gethostbyname failed with %d."), WSAGetLastError()));
  5486. SetLastError(WSAGetLastError());
  5487. }
  5488. }
  5489. else
  5490. {
  5491. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::IsComputerRSoPEnabled: WideCharToMultiByte failed with %d"), GetLastError()));
  5492. }
  5493. delete [] lpComputerNameA;
  5494. }
  5495. else
  5496. {
  5497. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::IsComputerRSoPEnabled: Failed to allocate memory for ansi dc name")));
  5498. SetLastError(ERROR_OUTOFMEMORY);
  5499. }
  5500. return bRetVal;
  5501. }
  5502. //-------------------------------------------------------
  5503. BOOL CRSOPWizardDlg::TestAndValidateComputer(HWND hDlg)
  5504. // RSOP_LOGGING_MODE - only called in RSOPGetCompDlgProc
  5505. {
  5506. LPTSTR lpMachineName = NULL;
  5507. BOOL bOk = TRUE;
  5508. HKEY hKeyRoot = 0, hKey = 0;
  5509. DWORD dwType, dwSize, dwValue = 1;
  5510. INT iRet;
  5511. TCHAR szMessage[200];
  5512. TCHAR szCaption[100];
  5513. LONG lResult;
  5514. HRESULT hr;
  5515. ULONG ulNoChars;
  5516. if ( (m_pRSOPQuery->szComputerName != NULL) && lstrcmpi(m_pRSOPQuery->szComputerName, TEXT(".")) )
  5517. {
  5518. ulNoChars = lstrlen(m_pRSOPQuery->szComputerName) + 3;
  5519. lpMachineName = new TCHAR[ulNoChars];
  5520. if ( lpMachineName == NULL )
  5521. {
  5522. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::TestAndValidateComputer: Failed to allocate memory with %d"), GetLastError()));
  5523. goto Exit;
  5524. }
  5525. hr = StringCchCopy (lpMachineName, ulNoChars, TEXT("\\\\"));
  5526. if (SUCCEEDED(hr))
  5527. {
  5528. if ((lstrlen (m_pRSOPQuery->szComputerName) > 2) && (m_pRSOPQuery->szComputerName[0] == TEXT('\\')) &&
  5529. (m_pRSOPQuery->szComputerName[1] == TEXT('\\')))
  5530. {
  5531. hr = StringCchCat (lpMachineName, ulNoChars, m_pRSOPQuery->szComputerName + 2);
  5532. }
  5533. else
  5534. {
  5535. hr = StringCchCat (lpMachineName, ulNoChars, NameWithoutDomain(m_pRSOPQuery->szComputerName) );
  5536. }
  5537. }
  5538. if (FAILED(hr))
  5539. {
  5540. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::TestAndValidateComputer: Could not copy machine name with 0x%x"), hr));
  5541. goto Exit;
  5542. }
  5543. }
  5544. SetWaitCursor();
  5545. //
  5546. // If we are testing a remote machine, test if the machine is alive and has
  5547. // the rsop namespace
  5548. //
  5549. if ( lpMachineName != NULL )
  5550. {
  5551. if (!IsComputerRSoPEnabled (lpMachineName))
  5552. {
  5553. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::TestAndValidateComputer: IsComputerRSoPEnabled failed on machine <%s>"), lpMachineName));
  5554. if (GetLastError() == WBEM_E_INVALID_NAMESPACE)
  5555. {
  5556. ReportError (hDlg, 0, IDS_DOWNLEVELCOMPUTER, m_pRSOPQuery->szComputerName);
  5557. }
  5558. else
  5559. {
  5560. ReportError (hDlg, GetLastError(), IDS_CONNECTSERVERFAILED, m_pRSOPQuery->szComputerName);
  5561. }
  5562. bOk = FALSE;
  5563. goto Exit;
  5564. }
  5565. }
  5566. //
  5567. // Check if the machine has rsop logging enabled or disabled
  5568. //
  5569. lResult = RegConnectRegistry (lpMachineName, HKEY_LOCAL_MACHINE, &hKeyRoot);
  5570. ClearWaitCursor();
  5571. if (lResult != ERROR_SUCCESS)
  5572. {
  5573. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::TestAndValidateComputer: Failed to connect to %s with %d"),
  5574. lpMachineName, lResult));
  5575. bOk = TRUE;
  5576. dwValue = 1; // Ignore errors at this point and assume that rsop is enabled on the machine
  5577. goto Exit;
  5578. }
  5579. lResult = RegOpenKeyEx (hKeyRoot, TEXT("Software\\Policies\\Microsoft\\Windows\\System"),
  5580. 0, KEY_READ, &hKey);
  5581. if (lResult == ERROR_SUCCESS)
  5582. {
  5583. dwSize = sizeof (dwValue);
  5584. lResult = RegQueryValueEx (hKey, TEXT("RsopLogging"), NULL, &dwType, (LPBYTE) &dwValue,
  5585. &dwSize);
  5586. RegCloseKey (hKey);
  5587. if (lResult == ERROR_SUCCESS)
  5588. {
  5589. RegCloseKey (hKeyRoot);
  5590. goto Exit;
  5591. }
  5592. }
  5593. lResult = RegOpenKeyEx (hKeyRoot, TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"),
  5594. 0, KEY_READ, &hKey);
  5595. if (lResult != ERROR_SUCCESS)
  5596. {
  5597. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::TestAndValidateComputer: Failed to open winlogon key with %d"),
  5598. lResult));
  5599. RegCloseKey (hKeyRoot);
  5600. goto Exit;
  5601. }
  5602. dwSize = sizeof (dwValue);
  5603. RegQueryValueEx (hKey, TEXT("RsopLogging"), NULL, &dwType, (LPBYTE) &dwValue, &dwSize);
  5604. RegCloseKey (hKey);
  5605. RegCloseKey (hKeyRoot);
  5606. Exit:
  5607. if (bOk && (dwValue == 0))
  5608. {
  5609. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::TestAndValidateComputer: RSOP Logging is not enabled on %s"),
  5610. lpMachineName));
  5611. LoadString(g_hInstance, IDS_RSOPLOGGINGDISABLED, szMessage, ARRAYSIZE(szMessage));
  5612. LoadString(g_hInstance, IDS_RSOPLOGGINGTITLE, szCaption, ARRAYSIZE(szCaption));
  5613. iRet = MessageBox (hDlg, szMessage, szCaption, MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2);
  5614. if (iRet == IDNO)
  5615. {
  5616. bOk = FALSE;
  5617. }
  5618. }
  5619. if (lpMachineName)
  5620. {
  5621. delete [] lpMachineName;
  5622. }
  5623. return bOk;
  5624. }
  5625. //-------------------------------------------------------
  5626. VOID CRSOPWizardDlg::InitializeDCInfo (HWND hDlg)
  5627. // RSOP_PLANNING_MODE - ...
  5628. {
  5629. LPTSTR szDomain = NULL;
  5630. DWORD dwError = ERROR_SUCCESS;
  5631. INT iDefault = LB_ERR, nPDC = LB_ERR, nCount = 0;
  5632. if ( m_pRSOPQuery->QueryType != RSOP_PLANNING_MODE )
  5633. {
  5634. return;
  5635. }
  5636. // Determine the focused domain so we can focus on the correct DC.
  5637. // Determine the focused domain.
  5638. if ( m_pRSOPQuery->pComputer->szName != NULL )
  5639. {
  5640. // Try and get the computer's domain
  5641. szDomain = ExtractDomain( m_pRSOPQuery->pComputer->szName );
  5642. }
  5643. if ( (szDomain == NULL) && (m_pRSOPQuery->pComputer->szSOM != NULL) )
  5644. {
  5645. // Try and get the computer's domain from the SOM
  5646. szDomain = GetDomainFromSOM( m_pRSOPQuery->pComputer->szSOM );
  5647. }
  5648. if ( (szDomain == NULL) && (m_pRSOPQuery->pUser->szName != NULL) )
  5649. {
  5650. // Try and get the user's domain
  5651. szDomain = ExtractDomain( m_pRSOPQuery->pUser->szName );
  5652. }
  5653. if ( (szDomain == NULL) && (m_pRSOPQuery->pUser->szSOM != NULL) )
  5654. {
  5655. // Try and get the user's domain from the SOM
  5656. szDomain = GetDomainFromSOM( m_pRSOPQuery->pUser->szSOM );
  5657. }
  5658. if ( szDomain == NULL )
  5659. {
  5660. // Use the local domain
  5661. LPTSTR szName;
  5662. szName = MyGetUserName(NameSamCompatible);
  5663. if ( szName != NULL )
  5664. {
  5665. szDomain = ExtractDomain(szName);
  5666. LocalFree( szName );
  5667. }
  5668. }
  5669. if ( szDomain != NULL )
  5670. {
  5671. DWORD cInfo;
  5672. INT n;
  5673. PDS_DOMAIN_CONTROLLER_INFO_1 pInfo = NULL;
  5674. HANDLE hDs;
  5675. DWORD result;
  5676. ULONG uDCCount = 0;
  5677. result = DsBind(NULL, szDomain, &hDs);
  5678. if (ERROR_SUCCESS == result)
  5679. {
  5680. result = DsGetDomainControllerInfo(hDs,
  5681. szDomain,
  5682. 1,
  5683. &cInfo,
  5684. (void **)&pInfo);
  5685. if (ERROR_SUCCESS == result)
  5686. {
  5687. // Enumerate the list
  5688. for (n = 0; (DWORD)n < cInfo; n++)
  5689. {
  5690. if (pInfo[n].DnsHostName != NULL)
  5691. {
  5692. uDCCount ++;
  5693. }
  5694. else
  5695. {
  5696. continue;
  5697. }
  5698. if (IsComputerRSoPEnabled(pInfo[n].DnsHostName))
  5699. {
  5700. SendMessage(GetDlgItem(hDlg, IDC_LIST1), LB_ADDSTRING, 0, (LPARAM)pInfo[n].DnsHostName);
  5701. if (pInfo[n].fIsPdc)
  5702. {
  5703. nPDC = n;
  5704. }
  5705. nCount++;
  5706. }
  5707. else
  5708. {
  5709. dwError = GetLastError();
  5710. }
  5711. }
  5712. if (nCount)
  5713. {
  5714. // Set the initial selection
  5715. if ( m_pRSOPQuery->szDomainController != NULL )
  5716. {
  5717. iDefault = (INT) SendMessage (GetDlgItem(hDlg, IDC_LIST1), LB_FINDSTRING,
  5718. (WPARAM) -1, (LPARAM) m_pRSOPQuery->szDomainController);
  5719. }
  5720. else if (nPDC != LB_ERR)
  5721. {
  5722. iDefault = (INT) SendMessage(GetDlgItem(hDlg, IDC_LIST1), LB_FINDSTRINGEXACT,
  5723. (WPARAM) -1, (LPARAM) pInfo[nPDC].DnsHostName);
  5724. }
  5725. SendMessage(GetDlgItem(hDlg, IDC_LIST1), LB_SETCURSEL,
  5726. (WPARAM) (iDefault == LB_ERR) ? 0 : iDefault, NULL);
  5727. }
  5728. else
  5729. {
  5730. ReportError (hDlg, dwError, IDS_NORSOPDC, szDomain);
  5731. }
  5732. DsFreeDomainControllerInfo(1, cInfo, pInfo);
  5733. }
  5734. else
  5735. {
  5736. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeDCInfo: DsGetDomainControllerInfo to %s failed with %d."), szDomain, result));
  5737. }
  5738. if (0 == uDCCount)
  5739. {
  5740. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeDCInfo: DsGetDomainControllerInfo to %s returned DCs with no DNS host name"), szDomain));
  5741. }
  5742. DsUnBind(&hDs);
  5743. }
  5744. else
  5745. {
  5746. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeDCInfo: DsBind to %s failed with %d."), szDomain, result));
  5747. ReportError(hDlg, result, IDS_DSBINDFAILED);
  5748. }
  5749. delete [] szDomain;
  5750. }
  5751. }
  5752. //-------------------------------------------------------
  5753. DWORD CRSOPWizardDlg::GetDefaultGroupCount()
  5754. {
  5755. return 2;
  5756. }
  5757. VOID CRSOPWizardDlg::AddDefaultGroups (HWND hLB)
  5758. {
  5759. SID_IDENTIFIER_AUTHORITY authNT = SECURITY_NT_AUTHORITY;
  5760. SID_IDENTIFIER_AUTHORITY authWORLD = SECURITY_WORLD_SID_AUTHORITY;
  5761. PSID psidUser, psidEveryone;
  5762. DWORD dwNameSize, dwDomainSize;
  5763. TCHAR szName[200];
  5764. TCHAR szDomain[65];
  5765. SID_NAME_USE SidName;
  5766. INT iIndex;
  5767. //
  5768. // Get the authenticated users sid
  5769. //
  5770. if (AllocateAndInitializeSid(&authNT, 1, SECURITY_AUTHENTICATED_USER_RID,
  5771. 0, 0, 0, 0, 0, 0, 0, &psidUser))
  5772. {
  5773. //
  5774. // Get the friendly display name and add it to the list
  5775. //
  5776. dwNameSize = ARRAYSIZE(szName);
  5777. dwDomainSize = ARRAYSIZE(szDomain);
  5778. if (LookupAccountSid (NULL, psidUser, szName, &dwNameSize,
  5779. szDomain, &dwDomainSize, &SidName))
  5780. {
  5781. iIndex = (INT) SendMessage (hLB, LB_ADDSTRING, 0, (LPARAM) szName);
  5782. SendMessage (hLB, LB_SETITEMDATA, (WPARAM) iIndex, (LPARAM) 1);
  5783. }
  5784. FreeSid(psidUser);
  5785. }
  5786. //
  5787. // Get the everyone sid
  5788. //
  5789. if (AllocateAndInitializeSid(&authWORLD, 1, SECURITY_WORLD_RID,
  5790. 0, 0, 0, 0, 0, 0, 0, &psidEveryone))
  5791. {
  5792. //
  5793. // Get the friendly display name and add it to the list
  5794. //
  5795. dwNameSize = ARRAYSIZE(szName);
  5796. dwDomainSize = ARRAYSIZE(szDomain);
  5797. if (LookupAccountSid (NULL, psidEveryone, szName, &dwNameSize,
  5798. szDomain, &dwDomainSize, &SidName))
  5799. {
  5800. iIndex = (INT) SendMessage (hLB, LB_ADDSTRING, 0, (LPARAM) szName);
  5801. SendMessage (hLB, LB_SETITEMDATA, (WPARAM) iIndex, (LPARAM) 1);
  5802. }
  5803. FreeSid(psidEveryone);
  5804. }
  5805. }
  5806. //-------------------------------------------------------
  5807. HRESULT CRSOPWizardDlg::BuildMembershipList (HWND hLB, IDirectoryObject * pDSObj, DWORD* pdwCount, LPTSTR** paszSecGrps, DWORD** padwSecGrpAttr)
  5808. {
  5809. HRESULT hr;
  5810. PADS_ATTR_INFO spAttrs;
  5811. DWORD i, j, cAttrs = 0;
  5812. WCHAR wzMembershipAttr[MAX_PATH] = L"memberOf;range=0-*";
  5813. const WCHAR wcSep = L'-';
  5814. const WCHAR wcEnd = L'*';
  5815. const WCHAR wzFormat[] = L"memberOf;range=%ld-*";
  5816. BOOL fMoreRemain = FALSE;
  5817. PWSTR rgpwzAttrNames[] = {wzMembershipAttr};
  5818. TCHAR szDisplayName[MAX_PATH];
  5819. ULONG ulSize;
  5820. LPTSTR lpFullName, lpTemp;
  5821. IADs * pGroup;
  5822. VARIANT varType;
  5823. BSTR bstrGroupType = NULL;
  5824. SetWaitCursor();
  5825. SendMessage (hLB, WM_SETREDRAW, FALSE, 0);
  5826. SendMessage (hLB, LB_RESETCONTENT, 0, 0);
  5827. AddDefaultGroups (hLB);
  5828. if (!pDSObj)
  5829. goto BuildMembershipListEnd;
  5830. GetPrimaryGroup (hLB, pDSObj);
  5831. bstrGroupType = SysAllocString( TEXT("groupType") );
  5832. if ( bstrGroupType == NULL )
  5833. {
  5834. goto BuildMembershipListEnd;
  5835. }
  5836. //
  5837. // Read the membership list from the object. First read the attribute off
  5838. // of the actual object which will give all memberships in the object's
  5839. // domain (including local groups which are not replicated to the GC).
  5840. //
  5841. do
  5842. {
  5843. hr = pDSObj->GetObjectAttributes(rgpwzAttrNames, 1, &spAttrs, &cAttrs);
  5844. if (SUCCEEDED(hr))
  5845. {
  5846. if (cAttrs > 0 && spAttrs != NULL)
  5847. {
  5848. for (i = 0; i < spAttrs->dwNumValues; i++)
  5849. {
  5850. ulSize = (lstrlen(spAttrs->pADsValues[i].CaseIgnoreString) + 10);
  5851. lpFullName = (LPTSTR) LocalAlloc (LPTR, ulSize * sizeof(TCHAR));
  5852. if (lpFullName)
  5853. {
  5854. hr = StringCchCopy (lpFullName, ulSize, TEXT("LDAP://"));
  5855. if (SUCCEEDED(hr))
  5856. {
  5857. hr = StringCchCat (lpFullName, ulSize, spAttrs->pADsValues[i].CaseIgnoreString);
  5858. }
  5859. if (SUCCEEDED(hr))
  5860. {
  5861. hr = OpenDSObject(lpFullName, IID_IADs, (void**)&pGroup);
  5862. if (SUCCEEDED(hr))
  5863. {
  5864. if (SUCCEEDED(pGroup->Get(bstrGroupType, &varType)))
  5865. {
  5866. if ( varType.lVal & 0x80000000)
  5867. {
  5868. if ( varType.lVal & 0x5)
  5869. {
  5870. lpTemp = lpFullName;
  5871. while (*lpTemp && (*lpTemp != TEXT(',')))
  5872. {
  5873. lpTemp++;
  5874. }
  5875. if (*lpTemp)
  5876. {
  5877. *lpTemp = TEXT('\0');
  5878. SendMessage (hLB, LB_ADDSTRING, 0, (LPARAM) (lpFullName+10));
  5879. }
  5880. }
  5881. else
  5882. {
  5883. if (TranslateName (spAttrs->pADsValues[i].CaseIgnoreString, NameFullyQualifiedDN,
  5884. NameSamCompatible, lpFullName, &ulSize))
  5885. {
  5886. SendMessage (hLB, LB_ADDSTRING, 0, (LPARAM) lpFullName);
  5887. }
  5888. }
  5889. }
  5890. VariantClear (&varType);
  5891. }
  5892. pGroup->Release();
  5893. }
  5894. }
  5895. LocalFree (lpFullName);
  5896. }
  5897. }
  5898. //
  5899. // Check to see if there is more data. If the last char of the
  5900. // attribute name string is an asterisk, then we have everything.
  5901. //
  5902. int cchEnd = wcslen(spAttrs->pszAttrName);
  5903. fMoreRemain = spAttrs->pszAttrName[cchEnd - 1] != wcEnd;
  5904. if (fMoreRemain)
  5905. {
  5906. PWSTR pwz = wcsrchr(spAttrs->pszAttrName, wcSep);
  5907. if (!pwz)
  5908. {
  5909. fMoreRemain = FALSE;
  5910. }
  5911. else
  5912. {
  5913. pwz++; // move past the hyphen to the range end value.
  5914. long lEnd = _wtol(pwz);
  5915. lEnd++; // start with the next value.
  5916. hr = StringCchPrintf (wzMembershipAttr, ARRAYSIZE(wzMembershipAttr), wzFormat, lEnd);
  5917. if (SUCCEEDED(hr))
  5918. {
  5919. DebugMsg((DM_VERBOSE, TEXT("Range returned is %s, now asking for %s"),
  5920. spAttrs->pszAttrName, wzMembershipAttr));
  5921. }
  5922. else
  5923. {
  5924. DebugMsg((DM_WARNING, TEXT("Could not copy membership attributes with 0x%x"),hr));
  5925. break;
  5926. }
  5927. }
  5928. }
  5929. }
  5930. FreeADsMem (spAttrs);
  5931. }
  5932. else
  5933. {
  5934. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildMembershipList: GetObjectAttributes failed with 0x%s"), hr));
  5935. }
  5936. } while (fMoreRemain);
  5937. BuildMembershipListEnd:
  5938. SendMessage (hLB, LB_SETCURSEL, 0, 0);
  5939. SendMessage (hLB, WM_SETREDRAW, TRUE, 0);
  5940. UpdateWindow (hLB);
  5941. SaveSecurityGroups (hLB, pdwCount, paszSecGrps, padwSecGrpAttr);
  5942. if ( bstrGroupType != NULL )
  5943. {
  5944. SysFreeString( bstrGroupType );
  5945. }
  5946. ClearWaitCursor();
  5947. return S_OK;
  5948. }
  5949. //-------------------------------------------------------
  5950. VOID CRSOPWizardDlg::GetPrimaryGroup (HWND hLB, IDirectoryObject * pDSObj)
  5951. {
  5952. HRESULT hr;
  5953. PADS_ATTR_INFO spAttrs;
  5954. WCHAR wzObjectSID[] = L"objectSid";
  5955. WCHAR wzPrimaryGroup[] = L"primaryGroupID";
  5956. PWSTR rgpwzAttrNames[] = {wzObjectSID, wzPrimaryGroup};
  5957. DWORD cAttrs = 2, i;
  5958. DWORD dwOriginalPriGroup = 0;
  5959. LPBYTE pObjSID = NULL;
  5960. UCHAR * psaCount, iIndex;
  5961. PSID pSID = NULL;
  5962. PSID_IDENTIFIER_AUTHORITY psia;
  5963. DWORD rgRid[8];
  5964. TCHAR szName[200];
  5965. TCHAR szDomain[300];
  5966. TCHAR *szFullName;
  5967. DWORD dwNameSize, dwDomainSize;
  5968. SID_NAME_USE SidName;
  5969. //
  5970. // Get the SID and perhaps the Primary Group attribute values.
  5971. //
  5972. hr = pDSObj->GetObjectAttributes(rgpwzAttrNames, cAttrs, &spAttrs, &cAttrs);
  5973. if (FAILED(hr))
  5974. {
  5975. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetPrimaryGroup: GetObjectAttributes failed with 0x%x"), hr));
  5976. return;
  5977. }
  5978. for (i = 0; i < cAttrs; i++)
  5979. {
  5980. if (_wcsicmp(spAttrs[i].pszAttrName, wzPrimaryGroup) == 0)
  5981. {
  5982. dwOriginalPriGroup = spAttrs[i].pADsValues->Integer;
  5983. continue;
  5984. }
  5985. if (_wcsicmp(spAttrs[i].pszAttrName, wzObjectSID) == 0)
  5986. {
  5987. pObjSID = new BYTE[spAttrs[i].pADsValues->OctetString.dwLength];
  5988. if (!pObjSID)
  5989. {
  5990. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetPrimaryGroup: Failed to allocate memory for sid with %d"), GetLastError()));
  5991. goto Exit;
  5992. }
  5993. memcpy(pObjSID, spAttrs[i].pADsValues->OctetString.lpValue,
  5994. spAttrs[i].pADsValues->OctetString.dwLength);
  5995. }
  5996. }
  5997. if (!IsValidSid (pObjSID))
  5998. {
  5999. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetPrimaryGroup: SID is not valid.")));
  6000. goto Exit;
  6001. }
  6002. psaCount = GetSidSubAuthorityCount(pObjSID);
  6003. if (psaCount == NULL)
  6004. {
  6005. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetPrimaryGroup: GetSidSubAuthorityCount failed with %d"), GetLastError()));
  6006. goto Exit;
  6007. }
  6008. if (*psaCount > 8)
  6009. {
  6010. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetPrimaryGroup: psaCount is greater than 8")));
  6011. goto Exit;
  6012. }
  6013. for (iIndex = 0; iIndex < (*psaCount - 1); iIndex++)
  6014. {
  6015. PDWORD pRid = GetSidSubAuthority(pObjSID, (DWORD)iIndex);
  6016. if (pRid == NULL)
  6017. {
  6018. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetPrimaryGroup: GetSidSubAuthority failed with %d"), GetLastError()));
  6019. goto Exit;
  6020. }
  6021. rgRid[iIndex] = *pRid;
  6022. }
  6023. rgRid[*psaCount - 1] = dwOriginalPriGroup;
  6024. for (iIndex = *psaCount; iIndex < 8; iIndex++)
  6025. {
  6026. rgRid[iIndex] = 0;
  6027. }
  6028. psia = GetSidIdentifierAuthority(pObjSID);
  6029. if (psia == NULL)
  6030. {
  6031. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetPrimaryGroup: GetSidIdentifierAuthorityCount failed with %d"), GetLastError()));
  6032. goto Exit;
  6033. }
  6034. if (!AllocateAndInitializeSid(psia, *psaCount, rgRid[0], rgRid[1],
  6035. rgRid[2], rgRid[3], rgRid[4],
  6036. rgRid[5], rgRid[6], rgRid[7], &pSID))
  6037. {
  6038. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetPrimaryGroup: AllocateAndInitializeSid failed with %d"), GetLastError()));
  6039. goto Exit;
  6040. }
  6041. dwNameSize = ARRAYSIZE(szName);
  6042. dwDomainSize = ARRAYSIZE(szDomain);
  6043. if (LookupAccountSid (NULL, pSID, szName, &dwNameSize, szDomain, &dwDomainSize,
  6044. &SidName))
  6045. {
  6046. ULONG ulNoChars = lstrlen(szDomain) + lstrlen(szName) + 1 + 1;
  6047. szFullName = (WCHAR *) LocalAlloc(LPTR, ulNoChars * sizeof(WCHAR));
  6048. if (szFullName != NULL)
  6049. {
  6050. hr = StringCchPrintf (szFullName, ulNoChars, TEXT("%s\\%s"), szDomain, szName);
  6051. ASSERT(SUCCEEDED(hr));
  6052. SendMessage (hLB, LB_ADDSTRING, 0, (LPARAM) szFullName);
  6053. LocalFree(szFullName);
  6054. }
  6055. }
  6056. else
  6057. {
  6058. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetPrimaryGroup: LookupAccountSid failed with %d"), GetLastError()));
  6059. }
  6060. FreeSid (pSID);
  6061. Exit:
  6062. FreeADsMem (spAttrs);
  6063. if (pObjSID)
  6064. {
  6065. delete [] pObjSID;
  6066. }
  6067. }
  6068. //-------------------------------------------------------
  6069. HRESULT CRSOPWizardDlg::SaveSecurityGroups (HWND hLB, DWORD* pdwCount, LPTSTR** paszSecGrps, DWORD** padwSecGrpAttr)
  6070. {
  6071. LONG i, lCount = 0;
  6072. DWORD dwLen;
  6073. LPTSTR lpText;
  6074. BSTR bstrText;
  6075. HRESULT hr;
  6076. if ( (*paszSecGrps != NULL) || (*padwSecGrpAttr != NULL) )
  6077. {
  6078. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::SaveSecurityGroups: Arrays passed in are not NULL!")) );
  6079. return E_FAIL;
  6080. }
  6081. // Get number of items from list box
  6082. lCount = (LONG) SendMessage (hLB, LB_GETCOUNT, 0, 0);
  6083. if ( lCount == 0 )
  6084. {
  6085. *pdwCount = 0;
  6086. return S_OK;
  6087. }
  6088. *paszSecGrps = (LPTSTR*)LocalAlloc( LPTR, sizeof(LPTSTR) * lCount );
  6089. if ( *paszSecGrps == NULL )
  6090. {
  6091. return E_OUTOFMEMORY;
  6092. }
  6093. *padwSecGrpAttr = (DWORD*)LocalAlloc( LPTR, sizeof(DWORD) * lCount );
  6094. if ( *padwSecGrpAttr == NULL )
  6095. {
  6096. LocalFree( *paszSecGrps );
  6097. *paszSecGrps = NULL;
  6098. return E_OUTOFMEMORY;
  6099. }
  6100. *pdwCount = lCount;
  6101. for ( i = 0; i < lCount; i++ )
  6102. {
  6103. dwLen = (DWORD) SendMessage (hLB, LB_GETTEXTLEN, (WPARAM) i, 0);
  6104. if (dwLen != LB_ERR)
  6105. {
  6106. lpText = (LPTSTR)LocalAlloc( LPTR, (dwLen+2) * sizeof(TCHAR) );
  6107. // RM: Should actually do something here if memory allocation fails!
  6108. if ( lpText != NULL )
  6109. {
  6110. if (SendMessage (hLB, LB_GETTEXT, (WPARAM) i, (LPARAM) lpText) != LB_ERR)
  6111. {
  6112. LONG lFlags;
  6113. BOOL bDollarRemoved;
  6114. lFlags = (LONG) SendMessage (hLB, LB_GETITEMDATA, (WPARAM) i, 0);
  6115. bDollarRemoved = (lFlags & 2);
  6116. if (bDollarRemoved)
  6117. {
  6118. lpText[wcslen(lpText)] = L'$';
  6119. }
  6120. if (lFlags & 1)
  6121. { // default grps
  6122. (*padwSecGrpAttr)[i] = 1;
  6123. }
  6124. (*paszSecGrps)[i] = lpText;
  6125. }
  6126. }
  6127. }
  6128. }
  6129. return S_OK;
  6130. }
  6131. //-------------------------------------------------------
  6132. VOID CRSOPWizardDlg::FillListFromSecurityGroups(HWND hLB, DWORD dwCount, LPTSTR* aszSecurityGroups, DWORD* adwSecGrpAttr)
  6133. {
  6134. DWORD dwIndex;
  6135. LPTSTR lpText;
  6136. SetWaitCursor();
  6137. SendMessage (hLB, WM_SETREDRAW, FALSE, 0);
  6138. SendMessage (hLB, LB_RESETCONTENT, 0, 0);
  6139. if ( (dwCount != 0) && (aszSecurityGroups != NULL) )
  6140. {
  6141. for ( dwIndex = 0; dwIndex < dwCount; dwIndex++ )
  6142. {
  6143. BOOL bDollarRemoved = FALSE;
  6144. lpText = aszSecurityGroups[dwIndex];
  6145. if (lpText[wcslen(lpText)-1] == L'$')
  6146. {
  6147. bDollarRemoved = TRUE;
  6148. lpText[wcslen(lpText)-1] = 0;
  6149. }
  6150. INT iIndex;
  6151. iIndex = (INT) SendMessage (hLB, LB_ADDSTRING, 0, (LPARAM) lpText);
  6152. if ( (adwSecGrpAttr != NULL) && (adwSecGrpAttr[dwIndex] & 1) )
  6153. {
  6154. SendMessage (hLB, LB_SETITEMDATA, (WPARAM) iIndex, (LPARAM) 1);
  6155. }
  6156. else
  6157. {
  6158. SendMessage (hLB, LB_SETITEMDATA, (WPARAM) iIndex, (LPARAM) (bDollarRemoved) ? 2 : 0);
  6159. }
  6160. // we just modified it, set it back
  6161. if (bDollarRemoved)
  6162. {
  6163. lpText[wcslen(lpText)] = L'$';
  6164. }
  6165. }
  6166. }
  6167. SendMessage (hLB, LB_SETCURSEL, 0, 0);
  6168. SendMessage (hLB, WM_SETREDRAW, TRUE, 0);
  6169. UpdateWindow (hLB);
  6170. ClearWaitCursor();
  6171. }
  6172. //-------------------------------------------------------
  6173. VOID CRSOPWizardDlg::FillListFromWQLFilters( HWND hLB, DWORD dwCount, LPTSTR* aszNames, LPTSTR* aszFilters )
  6174. {
  6175. INT iIndex;
  6176. DWORD dwIndex;
  6177. SetWaitCursor();
  6178. SendMessage (hLB, WM_SETREDRAW, FALSE, 0);
  6179. SendMessage (hLB, LB_RESETCONTENT, 0, 0);
  6180. if ( dwCount != 0 )
  6181. {
  6182. for ( dwIndex = 0; dwIndex < dwCount; dwIndex++ )
  6183. {
  6184. iIndex = (INT) SendMessage (hLB, LB_ADDSTRING, 0, (LPARAM) aszNames[dwIndex] );
  6185. DebugMsg((DM_VERBOSE, TEXT("CRSOPComponentData::FillListFromSafeArrays: Added WQL filter %s"), aszNames[dwIndex]));
  6186. if (iIndex != LB_ERR)
  6187. {
  6188. SendMessage (hLB, LB_SETITEMDATA, (WPARAM) iIndex, (LPARAM) aszFilters[dwIndex] );
  6189. }
  6190. }
  6191. }
  6192. SendMessage (hLB, LB_SETCURSEL, 0, 0);
  6193. SendMessage (hLB, WM_SETREDRAW, TRUE, 0);
  6194. UpdateWindow (hLB);
  6195. ClearWaitCursor();
  6196. }
  6197. VOID CRSOPWizardDlg::BuildWQLFilterList (HWND hDlg, BOOL bUser, DWORD* pdwCount, LPTSTR** paszNames, LPTSTR** paszFilters )
  6198. {
  6199. HRESULT hr;
  6200. LPTSTR szNameSpace = NULL;
  6201. LPTSTR lpFullNameSpace, lpEnd;
  6202. TCHAR szBuffer[150];
  6203. HWND hLB = GetDlgItem (hDlg, IDC_LIST1);
  6204. ULONG ulErrorInfo;
  6205. //
  6206. // Prepare to generate the rsop data. Give the user a message in the listbox
  6207. // and disable the controls on the page
  6208. //
  6209. SetWaitCursor();
  6210. SendMessage (hLB, LB_RESETCONTENT, 0, 0);
  6211. LoadString(g_hInstance, IDS_PLEASEWAIT, szBuffer, ARRAYSIZE(szBuffer));
  6212. SendMessage (hLB, LB_ADDSTRING, 0, (LPARAM) szBuffer);
  6213. PropSheet_SetWizButtons (GetParent(hDlg), 0);
  6214. EnableWindow (GetDlgItem(GetParent(hDlg), IDCANCEL), FALSE);
  6215. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON1), FALSE);
  6216. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON2), FALSE);
  6217. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON3), FALSE);
  6218. EnableWindow (GetDlgItem(hDlg, IDC_RADIO1), FALSE);
  6219. //
  6220. // Generate the rsop data using the info we have already
  6221. //
  6222. hr = CRSOPWizard::GenerateRSOPData(NULL, m_pRSOPQuery, &szNameSpace, TRUE, TRUE, bUser, FALSE, &ulErrorInfo);
  6223. SendMessage (hLB, LB_RESETCONTENT, 0, 0);
  6224. if (FAILED (hr))
  6225. {
  6226. ReportError (hDlg, hr, IDS_EXECFAILED);
  6227. goto Exit;
  6228. }
  6229. ULONG ulNoChars;
  6230. ulNoChars = lstrlen(szNameSpace) + 20;
  6231. lpFullNameSpace = (LPTSTR) LocalAlloc (LPTR, ulNoChars * sizeof(TCHAR));
  6232. if (lpFullNameSpace)
  6233. {
  6234. hr = StringCchCopy (lpFullNameSpace, ulNoChars, szNameSpace);
  6235. if (SUCCEEDED(hr))
  6236. {
  6237. lpEnd = CheckSlash(lpFullNameSpace);
  6238. if (bUser)
  6239. {
  6240. hr = StringCchCopy (lpEnd, ulNoChars - lstrlen(lpFullNameSpace), TEXT("User"));
  6241. }
  6242. else
  6243. {
  6244. hr = StringCchCopy (lpEnd, ulNoChars - lstrlen(lpFullNameSpace), TEXT("Computer"));
  6245. }
  6246. }
  6247. if (SUCCEEDED(hr))
  6248. {
  6249. if (SUCCEEDED(ExtractWQLFilters (lpFullNameSpace, pdwCount, paszNames, paszFilters) ))
  6250. {
  6251. FillListFromWQLFilters( hLB, *pdwCount, *paszNames, *paszFilters );
  6252. }
  6253. }
  6254. LocalFree (lpFullNameSpace);
  6255. }
  6256. CRSOPWizard:: DeleteRSOPData( szNameSpace, m_pRSOPQuery );
  6257. LocalFree( szNameSpace );
  6258. Exit:
  6259. PropSheet_SetWizButtons (GetParent(hDlg), PSWIZB_BACK | PSWIZB_NEXT);
  6260. EnableWindow (GetDlgItem(GetParent(hDlg), IDCANCEL), TRUE);
  6261. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON1), TRUE);
  6262. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON2), TRUE);
  6263. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON3), TRUE);
  6264. EnableWindow (GetDlgItem(hDlg, IDC_RADIO1), TRUE);
  6265. ClearWaitCursor();
  6266. }
  6267. //-------------------------------------------------------
  6268. HRESULT CRSOPWizardDlg::SaveWQLFilters (HWND hLB, DWORD* pdwCount, LPTSTR** paszNames, LPTSTR**paszFilters )
  6269. {
  6270. LONG i, lLength, lCount = 0;
  6271. LPTSTR lpText, lpName;
  6272. BSTR bstrText;
  6273. HRESULT hr;
  6274. if ( (*paszNames != NULL) || (*paszFilters != NULL) )
  6275. {
  6276. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::SaveWQLFilters: Arrays passed in are not NULL!")) );
  6277. return E_FAIL;
  6278. }
  6279. // Getting the number of items
  6280. lCount = (LONG) SendMessage (hLB, LB_GETCOUNT, 0, 0);
  6281. if ( lCount == 0 )
  6282. {
  6283. *pdwCount = 0;
  6284. return S_OK;
  6285. }
  6286. *paszNames = (LPTSTR*)LocalAlloc( LPTR, sizeof(LPTSTR) * lCount );
  6287. if ( *paszNames == NULL )
  6288. {
  6289. return E_OUTOFMEMORY;
  6290. }
  6291. *paszFilters = (LPTSTR*)LocalAlloc( LPTR, sizeof(LPTSTR) * lCount );
  6292. if ( *paszFilters == NULL )
  6293. {
  6294. LocalFree( *paszNames );
  6295. *paszNames = NULL;
  6296. return E_OUTOFMEMORY;
  6297. }
  6298. *pdwCount = lCount;
  6299. for ( i = 0; i < lCount; i++ )
  6300. {
  6301. lLength = (LONG) SendMessage (hLB, LB_GETTEXTLEN, (WPARAM) i, 0);
  6302. lpName = (LPTSTR)LocalAlloc( LPTR, sizeof(TCHAR) * (lLength + 1) );
  6303. if ( lpName != NULL )
  6304. {
  6305. if (SendMessage (hLB, LB_GETTEXT, (WPARAM) i, (LPARAM) lpName) != LB_ERR)
  6306. {
  6307. (*paszNames)[i] = lpName;
  6308. lpText = (LPTSTR) SendMessage (hLB, LB_GETITEMDATA, (WPARAM) i, 0);
  6309. if (lpText)
  6310. {
  6311. ULONG ulNoChars = wcslen(lpText) + 1;
  6312. (*paszFilters)[i] = (LPTSTR)LocalAlloc( LPTR, sizeof(TCHAR) * ulNoChars );
  6313. if ( (*paszFilters)[i] != NULL )
  6314. {
  6315. hr = StringCchCopy( (*paszFilters)[i], ulNoChars, lpText );
  6316. ASSERT(SUCCEEDED(hr));
  6317. }
  6318. }
  6319. }
  6320. else
  6321. {
  6322. LocalFree( lpName );
  6323. }
  6324. }
  6325. }
  6326. return S_OK;
  6327. }
  6328. //-------------------------------------------------------
  6329. BOOL CRSOPWizardDlg::CompareStringLists( DWORD dwCountA, LPTSTR* aszListA, DWORD dwCountB, LPTSTR* aszListB )
  6330. {
  6331. BOOL bFound;
  6332. DWORD dwA, dwB;
  6333. //
  6334. // Parameter checks
  6335. //
  6336. if ( dwCountA != dwCountB )
  6337. {
  6338. return FALSE;
  6339. }
  6340. if ( (dwCountA == 0) && (dwCountB == 0) )
  6341. {
  6342. return TRUE;
  6343. }
  6344. if ( dwCountA == 0 )
  6345. {
  6346. return FALSE;
  6347. }
  6348. if ( dwCountB == 0 )
  6349. {
  6350. return FALSE;
  6351. }
  6352. if ( (aszListA == NULL) || (aszListB == NULL) )
  6353. {
  6354. return FALSE;
  6355. }
  6356. //
  6357. // Loop through comparing item by item
  6358. //
  6359. for ( dwA = 0; dwA < dwCountA; dwA++ )
  6360. {
  6361. bFound = FALSE;
  6362. for ( dwB = 0; dwB < dwCountB; dwB++ )
  6363. {
  6364. if ( !lstrcmpi( aszListA[dwA], aszListB[dwB] ) )
  6365. {
  6366. bFound = TRUE;
  6367. }
  6368. }
  6369. if (!bFound)
  6370. {
  6371. return FALSE;
  6372. }
  6373. }
  6374. return TRUE;
  6375. }
  6376. //-------------------------------------------------------
  6377. LPTSTR CRSOPWizardDlg::GetDefaultSOM (LPTSTR lpDNName)
  6378. {
  6379. HRESULT hr;
  6380. LPTSTR lpPath = NULL;
  6381. IADsPathname * pADsPathname = NULL;
  6382. BSTR bstrContainer = NULL;
  6383. //
  6384. // Create a pathname object we can work with
  6385. //
  6386. hr = CoCreateInstance(CLSID_Pathname, NULL, CLSCTX_INPROC_SERVER,
  6387. IID_IADsPathname, (LPVOID*)&pADsPathname);
  6388. if (FAILED(hr))
  6389. {
  6390. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildAltDirPath: Failed to create adspathname instance with 0x%x"), hr));
  6391. goto Exit;
  6392. }
  6393. //
  6394. // Add the DN name
  6395. //
  6396. BSTR bstrDNName = SysAllocString( lpDNName );
  6397. if ( bstrDNName == NULL )
  6398. {
  6399. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildAltDirPath: Failed to allocate BSTR memory.")));
  6400. hr = E_OUTOFMEMORY;
  6401. goto Exit;
  6402. }
  6403. hr = pADsPathname->Set (bstrDNName, ADS_SETTYPE_DN);
  6404. SysFreeString( bstrDNName );
  6405. if (FAILED(hr))
  6406. {
  6407. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildAltDirPath: Failed to set pathname with 0x%x"), hr));
  6408. goto Exit;
  6409. }
  6410. //
  6411. // Remove the user / computer name
  6412. //
  6413. hr = pADsPathname->RemoveLeafElement ();
  6414. if (FAILED(hr))
  6415. {
  6416. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildAltDirPath: Failed to retreive GPO name with 0x%x"), hr));
  6417. goto Exit;
  6418. }
  6419. //
  6420. // Get the new path
  6421. //
  6422. hr = pADsPathname->Retrieve (ADS_FORMAT_X500_DN, &bstrContainer);
  6423. if (FAILED(hr))
  6424. {
  6425. DebugMsg((DM_WARNING, TEXT("CGroupPolicyObject::New: Failed to retreive container path with 0x%x"), hr));
  6426. goto Exit;
  6427. }
  6428. //
  6429. // Allocate a new buffer for the path
  6430. //
  6431. ULONG ulNoChars = lstrlen(bstrContainer)+ 1;
  6432. lpPath = new TCHAR [ulNoChars];
  6433. if (!lpPath)
  6434. {
  6435. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildAltDirPath: Failed to allocate memory with %d"), GetLastError()));
  6436. goto Exit;
  6437. }
  6438. //
  6439. // Build the path
  6440. //
  6441. hr = StringCchCopy (lpPath, ulNoChars, bstrContainer);
  6442. ASSERT(SUCCEEDED(hr));
  6443. Exit:
  6444. if (bstrContainer)
  6445. {
  6446. SysFreeString (bstrContainer);
  6447. }
  6448. if (pADsPathname)
  6449. {
  6450. pADsPathname->Release();
  6451. }
  6452. return lpPath;
  6453. }
  6454. //-------------------------------------------------------
  6455. HRESULT CRSOPWizardDlg::TestSOM (LPTSTR lpSOM, HWND hDlg)
  6456. {
  6457. HRESULT hr = E_OUTOFMEMORY;
  6458. LPTSTR lpFullName;
  6459. IDirectoryObject * pObject;
  6460. ADS_OBJECT_INFO *pInfo;
  6461. if (!lpSOM)
  6462. {
  6463. return E_INVALIDARG;
  6464. }
  6465. ULONG ulNoChars = lstrlen(lpSOM) + 10;
  6466. lpFullName = (LPTSTR) LocalAlloc (LPTR, ulNoChars * sizeof(TCHAR));
  6467. if (lpFullName)
  6468. {
  6469. hr = StringCchCopy (lpFullName, ulNoChars, TEXT("LDAP://"));
  6470. if (SUCCEEDED(hr))
  6471. {
  6472. hr = StringCchCat (lpFullName, ulNoChars, lpSOM);
  6473. }
  6474. if (FAILED(hr))
  6475. {
  6476. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::TestSOM: Could not copy SOM name with 0x%x"), hr));
  6477. LocalFree(lpFullName);
  6478. return hr;
  6479. }
  6480. hr = OpenDSObject(lpFullName, IID_IDirectoryObject, (void**)&pObject);
  6481. if (SUCCEEDED(hr))
  6482. {
  6483. hr = pObject->GetObjectInformation (&pInfo);
  6484. if (SUCCEEDED(hr))
  6485. {
  6486. if (CompareString (LOCALE_INVARIANT, NORM_IGNORECASE, pInfo->pszClassName, -1, TEXT("user"), -1) == CSTR_EQUAL)
  6487. {
  6488. hr = E_INVALIDARG;
  6489. ReportError (hDlg, hr, IDS_BADUSERSOM);
  6490. }
  6491. else if (CompareString (LOCALE_INVARIANT, NORM_IGNORECASE, pInfo->pszClassName, -1, TEXT("computer"), -1) == CSTR_EQUAL)
  6492. {
  6493. hr = E_INVALIDARG;
  6494. ReportError (hDlg, hr, IDS_BADCOMPUTERSOM);
  6495. }
  6496. FreeADsMem (pInfo);
  6497. }
  6498. pObject->Release();
  6499. }
  6500. else
  6501. {
  6502. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::TestSOM: OpenDSObject to %s failed with 0x%x"), lpFullName, hr));
  6503. }
  6504. LocalFree (lpFullName);
  6505. }
  6506. return hr;
  6507. }