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.

778 lines
22 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: rrasqry.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // rrasqry.cpp : implementation file
  11. //
  12. #include "stdafx.h"
  13. #include "qryfrm.h"
  14. #include "rrasqry.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. static UINT g_cfDsObjectNames = 0;
  21. static UINT g_cfDsQueryParams = 0;
  22. static UINT g_cfDsQueryScope = 0;
  23. #define DIR_SEARCH_PAGE_SIZE 256
  24. #define DIR_SEARCH_PAGE_TIME_LIMIT 30
  25. #define CFSTR_DSQUERYSCOPE TEXT("DsQueryScope")
  26. HRESULT RRASDelRouterIdObj(
  27. /*[in]*/LPCWSTR pwszMachineName // DN of the computer object in DS
  28. )
  29. {
  30. HRESULT hr = S_OK;
  31. CComPtr<IADsContainer> spContainer;
  32. CString machineName;
  33. if(!pwszMachineName || *pwszMachineName == 0) // this machine
  34. machineName = GetLocalMachineName();
  35. else
  36. machineName = pwszMachineName;
  37. ASSERT(machineName.GetLength());
  38. if(machineName.GetLength() == 0) return S_FALSE;
  39. // prepare fileter,
  40. // in format
  41. // (&(objectClass=RRASAdministrationConnectionPoint)(distinguishedName=CN=RouterIdentity,CN=*)
  42. CString filter = FILTER_PREFIX;
  43. filter += _T("&");
  44. filter += FILTER_PREFIX;
  45. #if 1 /// use computer to query
  46. filter += ATTR_NAME_OBJECTCLASS;
  47. filter += _T("=");
  48. filter += ATTR_CLASS_COMPUTER;
  49. filter += FILTER_POSTFIX;
  50. filter += FILTER_PREFIX;
  51. filter += ATTR_NAME_CN;
  52. filter += _T("=");
  53. filter += machineName;
  54. #else // user router id of the computer object for query, not found
  55. filter += ATTR_NAME_OBJECTCLASS;
  56. filter += _T("=");
  57. filter += ATTR_CLASS_RRASID;
  58. filter += FILTER_POSTFIX;
  59. filter += FILTER_PREFIX;
  60. filter += ATTR_NAME_DN;
  61. filter += _T("=");
  62. filter += DNPREFIX_ROUTERID;
  63. filter += machineName;
  64. filter += _T(",*");
  65. #endif
  66. filter += FILTER_POSTFIX;
  67. filter += FILTER_POSTFIX;
  68. // end of filter
  69. // Query the routerId Object
  70. // Search Routers under configuration
  71. CComPtr<IADs> spIADs;
  72. CComPtr<IDirectorySearch> spISearch;
  73. CString RIdPath;
  74. BSTR RRASPath = NULL;
  75. CString RRASDNSName;
  76. CComPtr<IADs> spIADsRId;
  77. CComPtr<IADsContainer> spIADsContainerRRAS;
  78. VARIANT var;
  79. CString strSearchScope;
  80. ADS_SEARCH_HANDLE hSrch = NULL;
  81. ADS_SEARCH_COLUMN colDN;
  82. VariantInit(&var);
  83. // retieve the list of EAPTypes in the DS
  84. // get ROOTDSE
  85. // if no scope is specified, search the entire enterprise
  86. CHECK_HR(hr = ADsGetObject(L"LDAP://RootDSE", IID_IADs, (void**)&spIADs));
  87. ASSERT(spIADs.p);
  88. CHECK_HR(hr = spIADs->Get(L"rootDomainNamingContext", &var));
  89. ASSERT(V_BSTR(&var));
  90. strSearchScope = _T("LDAP://");
  91. strSearchScope += V_BSTR(&var);
  92. spIADs.Release();
  93. // Get the scope object
  94. CHECK_HR(hr = ADsGetObject(T2W((LPTSTR)(LPCTSTR)strSearchScope), IID_IDirectorySearch, (void**)&spISearch));
  95. ASSERT(spISearch.p);
  96. {
  97. ADS_SEARCHPREF_INFO s_aSearchPrefs[3];
  98. s_aSearchPrefs[0].dwSearchPref = ADS_SEARCHPREF_PAGED_TIME_LIMIT;
  99. s_aSearchPrefs[0].vValue.dwType = ADSTYPE_INTEGER;
  100. s_aSearchPrefs[0].vValue.Integer = DIR_SEARCH_PAGE_TIME_LIMIT;
  101. s_aSearchPrefs[0].dwStatus = ADS_STATUS_S_OK;
  102. s_aSearchPrefs[1].dwSearchPref = ADS_SEARCHPREF_SEARCH_SCOPE;
  103. s_aSearchPrefs[1].vValue.dwType = ADSTYPE_INTEGER;
  104. s_aSearchPrefs[1].vValue.Integer = ADS_SCOPE_SUBTREE;
  105. s_aSearchPrefs[1].dwStatus = ADS_STATUS_S_OK;
  106. s_aSearchPrefs[2].dwSearchPref = ADS_SEARCHPREF_CHASE_REFERRALS;
  107. s_aSearchPrefs[2].vValue.dwType = ADSTYPE_BOOLEAN;
  108. s_aSearchPrefs[2].vValue.Boolean = (ADS_BOOLEAN) -1;
  109. s_aSearchPrefs[2].dwStatus = ADS_STATUS_S_OK;
  110. PWSTR s_apwzAttrs[] = { L"distinguishedName" };
  111. CHECK_HR(hr = spISearch->SetSearchPreference(s_aSearchPrefs, ARRAYSIZE(s_aSearchPrefs)));
  112. // do the search
  113. CHECK_HR(hr = spISearch->ExecuteSearch(T2W((LPTSTR)(LPCTSTR)filter),
  114. s_apwzAttrs, ARRAYSIZE(s_apwzAttrs), &hSrch));
  115. ASSERT(hSrch);
  116. do
  117. {
  118. //
  119. // Get the columns for each of the properties we are interested in, if
  120. // we failed to get any of the base properties for the object then lets
  121. // just skip this entry as we cannot build a valid IDLIST for it. The
  122. // properties that we request should be present on all objects.
  123. //
  124. CHECK_HR(hr = spISearch->GetNextRow(hSrch));
  125. if(hr == S_OK) // it might equal to S_ADS_NOMORE_ROWS otherwise
  126. {
  127. CHECK_HR(hr = spISearch->GetColumn(hSrch, s_apwzAttrs[0], &colDN));
  128. RIdPath = _T("LDAP://");
  129. RIdPath += colDN.pADsValues->CaseIgnoreString;
  130. #if 1 //uses computer to query
  131. spIADsContainerRRAS.Release();
  132. CHECK_HR(hr = ADsGetObject(T2W((LPTSTR)(LPCTSTR)RIdPath), IID_IADsContainer, (void**)&spIADsContainerRRAS));
  133. ASSERT(spIADsContainerRRAS.p);
  134. #else // uses routerID to query -- this mothed can not find the object, so changed
  135. spIADsRId.Release();
  136. CHECK_HR(hr = ADsGetObject(T2W((LPTSTR)(LPCTSTR)RIdPath), IID_IADs, (void**)&spIADsRId));
  137. ASSERT(spIADsRId.p);
  138. CHECK_HR(hr = spIADsRId->get_Parent(&RRASPath));
  139. spIADsContainerRRAS.Release();
  140. CHECK_HR(hr = ADsGetObject(RRASPath, IID_IADsContainer, (void**)&spIADsContainerRRAS));
  141. ASSERT(spIADsContainerRRAS.p);
  142. SysFreeString(RRASPath);
  143. RRASPath = NULL;
  144. #endif
  145. VariantClear(&var);
  146. CHECK_HR(hr = spIADsContainerRRAS->Delete(ATTR_CLASS_RRASID, CN_ROUTERID));
  147. }
  148. } while( !FAILED(hr) && hr != S_ADS_NOMORE_ROWS);
  149. }
  150. //
  151. // If there is more than one computer found, ( should not ) and give use a chance to delete one.
  152. L_ERR:
  153. return S_OK;
  154. }
  155. HRESULT RRASOpenQryDlg(
  156. /*[in]*/ CWnd* pParent,
  157. /*[in, out]*/ RRASQryData& QryData
  158. )
  159. {
  160. CDlgSvr dlg(QryData, pParent);
  161. HRESULT hr = S_OK;
  162. if(dlg.DoModal() == IDOK)
  163. {
  164. if(QryData.dwCatFlag == RRAS_QRY_CAT_NT5LDAP)
  165. hr = RRASDSQueryDlg(pParent, QryData);
  166. }
  167. else
  168. hr = S_FALSE;
  169. return hr;
  170. }
  171. HRESULT RRASDSQueryDlg(
  172. /*[in]*/ CWnd* pParent,
  173. /*[in, out]*/ RRASQryData& QryData
  174. )
  175. {
  176. HRESULT hr = S_OK;
  177. CComPtr<ICommonQuery> spCommonQuery;
  178. CComPtr<IDataObject> spDataObject;
  179. FORMATETC fmte = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  180. STGMEDIUM medium = { TYMED_NULL, NULL, NULL };
  181. DSQUERYINITPARAMS dqip;
  182. OPENQUERYWINDOW oqw;
  183. CHECK_HR(hr = CoInitialize(NULL));
  184. CHECK_HR(hr = CoCreateInstance(CLSID_CommonQuery, NULL, CLSCTX_INPROC_SERVER, IID_ICommonQuery, (LPVOID*)&spCommonQuery));
  185. dqip.cbStruct = sizeof(dqip);
  186. dqip.dwFlags = 0;
  187. dqip.pDefaultScope = NULL;
  188. oqw.cbStruct = sizeof(oqw);
  189. oqw.dwFlags = 0;
  190. oqw.clsidHandler = CLSID_DsQuery;
  191. oqw.pHandlerParameters = &dqip;
  192. oqw.clsidDefaultForm = CLSID_RRASQueryForm;
  193. oqw.dwFlags |= OQWF_OKCANCEL;
  194. dqip.dwFlags |= DSQPF_NOSAVE;
  195. oqw.dwFlags |= OQWF_REMOVEFORMS;
  196. oqw.dwFlags |= OQWF_DEFAULTFORM;
  197. oqw.dwFlags |= OQWF_HIDEMENUS;
  198. oqw.dwFlags |= OQWF_HIDESEARCHUI;
  199. // Now display the dialog, and if we succeeded and get an IDataObject then
  200. // slurp the results into our list view.
  201. hr = spCommonQuery->OpenQueryWindow(NULL, &oqw, &spDataObject);
  202. if ( SUCCEEDED(hr) && spDataObject.p )
  203. {
  204. // now get the DSQUERYPARAMS and lets get the filter string
  205. if ( !g_cfDsQueryScope )
  206. g_cfDsQueryScope = RegisterClipboardFormat(CFSTR_DSQUERYSCOPE);
  207. fmte.cfFormat = (CLIPFORMAT) g_cfDsQueryScope;
  208. if ( SUCCEEDED(spDataObject->GetData(&fmte, &medium)) )
  209. {
  210. LPWSTR pScopeStr = (LPWSTR)medium.hGlobal;
  211. QryData.strScope = pScopeStr;
  212. ReleaseStgMedium(&medium);
  213. }
  214. else
  215. QryData.strScope = _T("");
  216. if ( !g_cfDsQueryParams )
  217. g_cfDsQueryParams = RegisterClipboardFormat(CFSTR_DSQUERYPARAMS);
  218. fmte.cfFormat = (CLIPFORMAT) g_cfDsQueryParams;
  219. if ( SUCCEEDED(spDataObject->GetData(&fmte, &medium)) )
  220. {
  221. LPDSQUERYPARAMS pDsQueryParams = (LPDSQUERYPARAMS)medium.hGlobal;
  222. LPWSTR pFilter = (LPTSTR)ByteOffset(pDsQueryParams, pDsQueryParams->offsetQuery);
  223. QryData.strFilter = pFilter;
  224. ReleaseStgMedium(&medium);
  225. }
  226. else
  227. QryData.strFilter = _T("");
  228. }
  229. L_ERR:
  230. CoUninitialize();
  231. return hr;
  232. }
  233. //
  234. // S_OK -- User select OK
  235. // S_FALSE -- User select Cancel
  236. // ERROR:
  237. // DS error, search activeDs.dll
  238. // Win32 erroe
  239. // LDAP error
  240. // General error -- memory, invalid argument ...
  241. HRESULT RRASExecQry(
  242. /*[in]*/ RRASQryData& QryData,
  243. /*[out]*/ DWORD& dwFlags,
  244. /*[out]*/ CStringArray& RRASs
  245. )
  246. {
  247. USES_CONVERSION;
  248. HRESULT hr = S_OK;
  249. switch(QryData.dwCatFlag)
  250. {
  251. case RRAS_QRY_CAT_THIS:
  252. {
  253. CString machine;
  254. RRASs.Add(machine);
  255. break;
  256. }
  257. case RRAS_QRY_CAT_MACHINE:
  258. RRASs.Add(QryData.strFilter);
  259. break;
  260. // NT4 Domain
  261. case RRAS_QRY_CAT_NT4DOMAIN:
  262. {
  263. LPWSTR pDomainName;
  264. SERVER_INFO_100* pServerInfo100 = NULL;
  265. SERVER_INFO_101* pServerInfo101 = NULL;
  266. DWORD dwRead;
  267. DWORD dwTotal;
  268. DWORD index;
  269. BYTE flag;
  270. NET_API_STATUS netret;
  271. dwFlags = RRAS_QRY_RESULT_HOSTNAME;
  272. if(QryData.strScope.IsEmpty())
  273. return E_INVALIDARG;
  274. // Although the API excepts TCHAR it is exclusively UNICODE
  275. if (QryData.strScope.Left(2) != _T("\\\\"))
  276. pDomainName = T2W((LPTSTR)(LPCTSTR)QryData.strScope);
  277. else
  278. pDomainName = T2W((LPTSTR)(LPCTSTR)QryData.strScope + 2);
  279. // Check for dot. (FQDNs are not accepted)
  280. index = 0;
  281. while(pDomainName[index] != L'\0'){
  282. if(pDomainName[index] == L'.'){
  283. // Error out
  284. AfxMessageBox(IDS_ERR_DOMAIN_FORMAT);
  285. return E_INVALIDARG;
  286. }
  287. index++;
  288. }
  289. do
  290. {
  291. CWaitCursor wCursor;
  292. netret = ::NetServerEnum(NULL, 101, (LPBYTE*)&pServerInfo101,
  293. 0xffffffff, &dwRead, &dwTotal, SV_TYPE_DIALIN_SERVER,
  294. pDomainName, NULL);
  295. if(pServerInfo101 && netret == NERR_Success || netret == ERROR_MORE_DATA)
  296. {
  297. PSERVER_INFO_101 pSvInfo101_t = pServerInfo101;
  298. CString serverName;
  299. for (;dwRead > 0; dwRead--, pSvInfo101_t++)
  300. {
  301. // this option should addin all the server in the NT4 domain, not the NT4 servers in the domain
  302. // if(pSvInfo101_t->sv101_version_major == 4)
  303. {
  304. serverName = (LPWSTR)pSvInfo101_t->sv101_name;
  305. RRASs.Add(serverName);
  306. }
  307. }
  308. NetApiBufferFree(pServerInfo101);
  309. }
  310. } while (netret == ERROR_MORE_DATA);
  311. if(netret == NERR_Success)
  312. hr = S_OK;
  313. else if (netret != ERROR_ACCESS_DENIED) {
  314. // Error out
  315. AfxMessageBox(IDS_ERR_DOMAIN_NAME);
  316. return E_INVALIDARG;
  317. }
  318. else
  319. hr = HRESULT_FROM_WIN32(netret);
  320. }
  321. break;
  322. // NT5 LADP Query
  323. case RRAS_QRY_CAT_NT5LDAP:
  324. {
  325. // Search Routers under configuration
  326. CComPtr<IADs> spIADs;
  327. CComPtr<IDirectorySearch> spISearch;
  328. CString RIdPath;
  329. BSTR RRASPath = NULL;
  330. CString RRASDNSName;
  331. CComPtr<IADs> spIADsRId;
  332. CComPtr<IADs> spIADsRRAS;
  333. VARIANT var;
  334. CString strSearchScope;
  335. ADS_SEARCH_HANDLE hSrch = NULL;
  336. ADS_SEARCH_COLUMN colDN;
  337. CWaitCursor cw;
  338. // dwFlags = RRAS_QRY_RESULT_DNSNAME;
  339. dwFlags = RRAS_QRY_RESULT_HOSTNAME;
  340. VariantInit(&var);
  341. // retieve the list of EAPTypes in the DS
  342. // get ROOTDSE
  343. // if no scope is specified, search the entire enterprise
  344. if(QryData.strScope.IsEmpty())
  345. {
  346. CHECK_HR(hr = ADsGetObject(L"LDAP://RootDSE", IID_IADs, (void**)&spIADs));
  347. ASSERT(spIADs.p);
  348. CHECK_HR(hr = spIADs->Get(L"rootDomainNamingContext", &var));
  349. ASSERT(V_BSTR(&var));
  350. strSearchScope = _T("LDAP://");
  351. strSearchScope += V_BSTR(&var);
  352. spIADs.Release();
  353. }
  354. else
  355. strSearchScope = QryData.strScope;
  356. // Get the scope object
  357. CHECK_HR(hr = ADsGetObject(T2W((LPTSTR)(LPCTSTR)strSearchScope), IID_IDirectorySearch, (void**)&spISearch));
  358. ASSERT(spISearch.p);
  359. {
  360. ADS_SEARCHPREF_INFO s_aSearchPrefs[3];
  361. s_aSearchPrefs[0].dwSearchPref = ADS_SEARCHPREF_PAGED_TIME_LIMIT;
  362. s_aSearchPrefs[0].vValue.dwType = ADSTYPE_INTEGER;
  363. s_aSearchPrefs[0].vValue.Integer = DIR_SEARCH_PAGE_TIME_LIMIT;
  364. s_aSearchPrefs[0].dwStatus = ADS_STATUS_S_OK;
  365. s_aSearchPrefs[1].dwSearchPref = ADS_SEARCHPREF_SEARCH_SCOPE;
  366. s_aSearchPrefs[1].vValue.dwType = ADSTYPE_INTEGER;
  367. s_aSearchPrefs[1].vValue.Integer = ADS_SCOPE_SUBTREE;
  368. s_aSearchPrefs[1].dwStatus = ADS_STATUS_S_OK;
  369. s_aSearchPrefs[2].dwSearchPref = ADS_SEARCHPREF_CHASE_REFERRALS;
  370. s_aSearchPrefs[2].vValue.dwType = ADSTYPE_BOOLEAN;
  371. s_aSearchPrefs[2].vValue.Boolean = (ADS_BOOLEAN) -1;
  372. s_aSearchPrefs[2].dwStatus = ADS_STATUS_S_OK;
  373. PWSTR s_apwzAttrs[] = { L"distinguishedName" };
  374. CHECK_HR(hr = spISearch->SetSearchPreference(s_aSearchPrefs, ARRAYSIZE(s_aSearchPrefs)));
  375. // do the search
  376. CHECK_HR(hr = spISearch->ExecuteSearch(T2W((LPTSTR)(LPCTSTR)QryData.strFilter),
  377. s_apwzAttrs, ARRAYSIZE(s_apwzAttrs), &hSrch));
  378. ASSERT(hSrch);
  379. do
  380. {
  381. //
  382. // Get the columns for each of the properties we are interested in, if
  383. // we failed to get any of the base properties for the object then lets
  384. // just skip this entry as we cannot build a valid IDLIST for it. The
  385. // properties that we request should be present on all objects.
  386. //
  387. CHECK_HR(hr = spISearch->GetNextRow(hSrch));
  388. if(hr == S_OK) // it might equal to S_ADS_NOMORE_ROWS otherwise
  389. {
  390. CHECK_HR(hr = spISearch->GetColumn(hSrch, s_apwzAttrs[0], &colDN));
  391. RIdPath = _T("LDAP://");
  392. RIdPath += colDN.pADsValues->CaseIgnoreString;
  393. spIADsRId.Release();
  394. CHECK_HR(hr = ADsGetObject(T2W((LPTSTR)(LPCTSTR)RIdPath), IID_IADs, (void**)&spIADsRId));
  395. ASSERT(spIADsRId.p);
  396. CHECK_HR(hr = spIADsRId->get_Parent(&RRASPath));
  397. spIADsRRAS.Release();
  398. CHECK_HR(hr = ADsGetObject(RRASPath, IID_IADs, (void**)&spIADsRRAS));
  399. ASSERT(spIADsRRAS.p);
  400. SysFreeString(RRASPath);
  401. RRASPath = NULL;
  402. VariantClear(&var);
  403. // build 1750, this is empty, changed to "name"
  404. // CHECK_HR(hr = spIADsRRAS->Get(L"dNSHostName", &var));
  405. CHECK_HR(hr = spIADsRRAS->Get(L"name", &var));
  406. RRASDNSName = V_BSTR(&var);
  407. if(!RRASDNSName.IsEmpty())
  408. RRASs.Add(RRASDNSName);
  409. }
  410. } while( !FAILED(hr) && hr != S_ADS_NOMORE_ROWS);
  411. }
  412. L_ERR:
  413. if(hSrch)
  414. CHECK_HR(hr = spISearch->CloseSearchHandle(hSrch));
  415. VariantClear(&var);
  416. SysFreeString(RRASPath);
  417. }
  418. break;
  419. default:
  420. hr = E_INVALIDARG;
  421. }
  422. if (FAILED(hr))
  423. DisplayErrorMessage(NULL, hr);
  424. return hr;
  425. }
  426. // S_OK -- User select OK
  427. // ERROR:
  428. // DS error, search activeDs.dll
  429. // Win32 erroe
  430. // LDAP error
  431. // General error -- memory, invalid argument ...
  432. /////////////////////////////////////////////////////////////////////////////
  433. // CDlgSvr dialog
  434. RRASQryData __staticQueryData;
  435. CDlgSvr::CDlgSvr(CWnd* pParent /*=NULL*/)
  436. : m_QueryData(__staticQueryData), CBaseDialog(CDlgSvr::IDD, pParent)
  437. {
  438. Init();
  439. }
  440. CDlgSvr::CDlgSvr(RRASQryData& QueryData, CWnd* pParent /*=NULL*/)
  441. : m_QueryData(QueryData), CBaseDialog(CDlgSvr::IDD, pParent)
  442. {
  443. Init();
  444. }
  445. void CDlgSvr::Init()
  446. {
  447. //{{AFX_DATA_INIT(CDlgSvr)
  448. // NOTE: the ClassWizard will add member initialization here
  449. //}}AFX_DATA_INIT
  450. }
  451. void CDlgSvr::DoDataExchange(CDataExchange* pDX)
  452. {
  453. CBaseDialog::DoDataExchange(pDX);
  454. //{{AFX_DATA_MAP(CDlgSvr)
  455. DDX_Control(pDX, IDC_QRY_EDIT_MACHINE, m_editMachine);
  456. DDX_Control(pDX, IDC_QRY_EDIT_DOMAIN, m_editDomain);
  457. DDX_Control(pDX, IDOK, m_btnOk);
  458. DDX_Control(pDX, IDNEXT, m_btnNext);
  459. DDX_Radio(pDX, IDC_QRY_RADIO_THIS, m_nRadio);
  460. DDX_Text(pDX, IDC_QRY_EDIT_DOMAIN, m_strDomain);
  461. DDV_MaxChars(pDX, m_strDomain, 253);
  462. if(m_nRadio == 2)
  463. {
  464. DDV_MinChars(pDX, m_strDomain, 1);
  465. }
  466. DDX_Text(pDX, IDC_QRY_EDIT_MACHINE, m_strMachine);
  467. DDV_MaxChars(pDX, m_strMachine, 253);
  468. if(m_nRadio == 1)
  469. {
  470. DDV_MinChars(pDX, m_strMachine, 1);
  471. }
  472. //}}AFX_DATA_MAP
  473. }
  474. BEGIN_MESSAGE_MAP(CDlgSvr, CBaseDialog)
  475. //{{AFX_MSG_MAP(CDlgSvr)
  476. ON_BN_CLICKED(IDC_QRY_RADIO_ANOTHER, OnRadioAnother)
  477. ON_BN_CLICKED(IDC_QRY_RADIO_NT4, OnRadioNt4)
  478. ON_BN_CLICKED(IDC_QRY_RADIO_NT5, OnRadioNt5)
  479. ON_BN_CLICKED(IDC_QRY_RADIO_THIS, OnRadioThis)
  480. ON_BN_CLICKED(IDOK, OnButtonNext)
  481. ON_BN_CLICKED(IDNEXT, OnButtonNext)
  482. //}}AFX_MSG_MAP
  483. END_MESSAGE_MAP()
  484. /////////////////////////////////////////////////////////////////////////////
  485. // CDlgSvr message handlers
  486. void CDlgSvr::OnRadioAnother()
  487. {
  488. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  489. CString str;
  490. str.LoadString(IDS_OK);
  491. m_editMachine.EnableWindow(TRUE);
  492. m_editDomain.EnableWindow(FALSE);
  493. // m_btnNext.SetWindowText(str);
  494. //Enable the OK button, hide the NEXT button
  495. m_btnOk.EnableWindow(TRUE);
  496. m_btnOk.ShowWindow(SW_SHOW);
  497. m_btnNext.EnableWindow(FALSE);
  498. m_btnNext.ShowWindow(SW_HIDE);
  499. }
  500. void CDlgSvr::OnRadioNt4()
  501. {
  502. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  503. CString str;
  504. str.LoadString(IDS_OK);
  505. m_editMachine.EnableWindow(FALSE);
  506. m_editDomain.EnableWindow(TRUE);
  507. // m_btnNext.SetWindowText(str);
  508. //Enable the OK button, hide the NEXT button
  509. m_btnOk.EnableWindow(TRUE);
  510. m_btnOk.ShowWindow(SW_SHOW);
  511. m_btnNext.EnableWindow(FALSE);
  512. m_btnNext.ShowWindow(SW_HIDE);
  513. }
  514. void CDlgSvr::OnRadioNt5()
  515. {
  516. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  517. CString str;
  518. str.LoadString(IDS_NEXT);
  519. m_editMachine.EnableWindow(FALSE);
  520. m_editDomain.EnableWindow(FALSE);
  521. // m_btnNext.SetWindowText(str);
  522. //Enable the NEXT button, hide the OK button
  523. m_btnNext.EnableWindow(TRUE);
  524. m_btnNext.ShowWindow(SW_SHOW);
  525. m_btnOk.EnableWindow(FALSE);
  526. m_btnOk.ShowWindow(SW_HIDE);
  527. }
  528. void CDlgSvr::OnRadioThis()
  529. {
  530. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  531. CString str;
  532. str.LoadString(IDS_OK);
  533. m_editMachine.EnableWindow(FALSE);
  534. m_editDomain.EnableWindow(FALSE);
  535. // m_btnNext.SetWindowText(str);
  536. //Enable the OK button, hide the NEXT button
  537. m_btnOk.EnableWindow(TRUE);
  538. m_btnOk.ShowWindow(SW_SHOW);
  539. m_btnNext.EnableWindow(FALSE);
  540. m_btnNext.ShowWindow(SW_HIDE);
  541. }
  542. void CDlgSvr::OnButtonNext()
  543. {
  544. if(UpdateData(TRUE) == 0) return;
  545. switch(m_nRadio)
  546. {
  547. case 0:
  548. m_QueryData.dwCatFlag = RRAS_QRY_CAT_THIS;
  549. break;
  550. case 1:
  551. m_QueryData.dwCatFlag = RRAS_QRY_CAT_MACHINE;
  552. m_QueryData.strFilter = m_strMachine;
  553. break;
  554. case 2:
  555. m_QueryData.dwCatFlag = RRAS_QRY_CAT_NT4DOMAIN;
  556. m_QueryData.strScope = m_strDomain;
  557. break;
  558. case 3:
  559. m_QueryData.dwCatFlag = RRAS_QRY_CAT_NT5LDAP;
  560. break;
  561. default:
  562. ASSERT(0); // this should not happen
  563. break;
  564. }
  565. EndDialog(IDOK);
  566. }
  567. /////////////////////////////////////////////////////////////////////////////
  568. // CDlgSrv message handlers
  569. /////////////////////////////////////////////////////////////////////////////
  570. // CDlgSvr1 message handlers
  571. BOOL CDlgSvr::OnInitDialog()
  572. {
  573. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  574. BOOL bEnableMachine = FALSE, bEnableDomain = FALSE;
  575. UINT okIDS = IDS_OK;
  576. switch(m_QueryData.dwCatFlag)
  577. {
  578. case RRAS_QRY_CAT_THIS:
  579. m_nRadio = 0;
  580. break;
  581. case RRAS_QRY_CAT_MACHINE:
  582. bEnableMachine = TRUE;
  583. m_strMachine = m_QueryData.strFilter;
  584. m_nRadio = 1;
  585. break;
  586. case RRAS_QRY_CAT_NT4DOMAIN:
  587. bEnableDomain = TRUE;
  588. m_strDomain = m_QueryData.strScope;
  589. m_nRadio = 2;
  590. break;
  591. case RRAS_QRY_CAT_NT5LDAP:
  592. m_nRadio = 3;
  593. okIDS = IDS_NEXT;
  594. break;
  595. default:
  596. m_nRadio = 0;
  597. break;
  598. }
  599. CBaseDialog::OnInitDialog();
  600. if(okIDS == IDS_OK){
  601. //Enable the OK button and disable the NEXT button
  602. m_btnOk.EnableWindow(TRUE);
  603. m_btnOk.ShowWindow(SW_SHOW);
  604. m_btnNext.EnableWindow(FALSE);
  605. m_btnNext.ShowWindow(SW_HIDE);
  606. }
  607. else if(okIDS == IDS_NEXT){
  608. //Enable the NEXT button and disable the OK button
  609. m_btnNext.EnableWindow(TRUE);
  610. m_btnNext.ShowWindow(SW_SHOW);
  611. m_btnOk.EnableWindow(FALSE);
  612. m_btnOk.ShowWindow(SW_HIDE);
  613. }
  614. m_editMachine.EnableWindow(bEnableMachine);
  615. m_editDomain.EnableWindow(bEnableDomain);
  616. /*
  617. CString str;
  618. str.LoadString(IDS_OK);
  619. m_btnOk.SetWindowText(str);
  620. str.LoadString(IDS_NEXT);
  621. m_btnNext.SetWindowText(str);
  622. */
  623. return TRUE; // return TRUE unless you set the focus to a control
  624. // EXCEPTION: OCX Property Pages should return FALSE
  625. }