Source code of Windows XP (NT5)
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.

1875 lines
48 KiB

  1. // conndlg.cpp : implementation file
  2. //
  3. // Commenting #define out - causing compiler error - not sure if needed, compiles
  4. // okay without it.
  5. //#define WINVER 0x0400
  6. #include "precomp.h"
  7. #include "afxtempl.h"
  8. #include <comdef.h> //for _bstr_t
  9. #include "resource.h"
  10. #include "wbemidl.h"
  11. #include <comdef.h>
  12. //smart pointer
  13. _COM_SMARTPTR_TYPEDEF(IWbemServices, IID_IWbemServices);
  14. _COM_SMARTPTR_TYPEDEF(IEnumWbemClassObject, IID_IEnumWbemClassObject);
  15. //_COM_SMARTPTR_TYPEDEF(IWbemContext, IID_IWbemContext );
  16. _COM_SMARTPTR_TYPEDEF(IWbemLocator, IID_IWbemLocator);
  17. #include "drdbdr.h"
  18. #include "Browse.h"
  19. #include "dlgcback.h"
  20. #include "cominit.h" //for Dcom blanket
  21. #include "htmlhelp.h" //for HELP
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CConnectionDialog dialog
  29. HTREEITEM CConnectionDialog :: InsertItem (CTreeCtrl &treeCtrl,
  30. HTREEITEM hParentTreeItem,
  31. const char *namespaceName)
  32. {
  33. TV_INSERTSTRUCT newItem;
  34. newItem.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
  35. newItem.hParent = hParentTreeItem;
  36. char *name = new char [strlen (namespaceName) + 1];
  37. name[0] = 0;
  38. lstrcpy (name, namespaceName);
  39. newItem.item.pszText = name;
  40. // newItem.item.cchTextMax = strlen (namespaceName) + 1;
  41. //get parent name and prepend to name to generate absolute name
  42. char *absName = NULL;
  43. if (hParentTreeItem == TVI_ROOT)
  44. {
  45. absName = new char [strlen (namespaceName) + 1];
  46. absName[0] = 0;
  47. lstrcpy (absName, namespaceName);
  48. }
  49. else
  50. {
  51. ISAMTreeItemData* parentData =
  52. (ISAMTreeItemData*)treeCtrl.GetItemData (hParentTreeItem);
  53. absName = new char [strlen (namespaceName) + strlen (parentData->absName) + 2 + 1];
  54. absName[0] = 0;
  55. strcpy (absName, parentData->absName);
  56. strcat (absName, "\\");
  57. strcat (absName, namespaceName);
  58. }
  59. newItem.item.iImage = newItem.item.iSelectedImage = m_idxMode1Image;
  60. ISAMTreeItemData *itemData = new ISAMTreeItemData;
  61. itemData->absName = absName;
  62. itemData->pszText = name; //this copy will be deleted
  63. itemData->included = FALSE;
  64. itemData->childInclude = 0;
  65. itemData->childChildInclude = 0;
  66. //Add to list for quick cleanup
  67. if (pCurrentSelectionList)
  68. {
  69. pCurrentItem->pNext = itemData;
  70. pCurrentItem = itemData;
  71. }
  72. else
  73. {
  74. pCurrentSelectionList = itemData;
  75. pCurrentItem = itemData;
  76. }
  77. newItem.item.lParam = (DWORD)itemData;
  78. return treeCtrl.InsertItem (&newItem);
  79. }
  80. int CConnectionDialog :: FindAbsName (char *name,
  81. HTREEITEM hStartAt,
  82. HTREEITEM& hFoundItem)
  83. {
  84. if (!name)
  85. return FALSE;
  86. {
  87. ISAMTreeItemData *pItemData = (ISAMTreeItemData*)m_tree1.GetItemData (hStartAt);
  88. if (pItemData && pItemData->absName &&
  89. !_stricmp (name, pItemData->absName))
  90. {
  91. hFoundItem = hStartAt;
  92. return TRUE;
  93. }
  94. else
  95. {
  96. HTREEITEM firstChild = NULL;
  97. if (firstChild = m_tree1.GetChildItem (hStartAt))
  98. {
  99. if (FindAbsName (name, firstChild, hFoundItem))
  100. return TRUE;
  101. HTREEITEM nextSibling = firstChild;
  102. while (nextSibling = m_tree1.GetNextItem (nextSibling, TVGN_NEXT))
  103. {
  104. if (FindAbsName (name, nextSibling, hFoundItem))
  105. return TRUE;
  106. }
  107. }
  108. return FALSE;
  109. }
  110. }
  111. }
  112. int CConnectionDialog :: CreateNamespace (char *name,
  113. HTREEITEM hStartAt,
  114. HTREEITEM& hFoundItem)
  115. {
  116. hFoundItem = NULL;
  117. //If we are to create the namespace in the tree control
  118. //we need to do it relative to its parent namespace
  119. //The first step therefore is to get a handle to its parent
  120. //We work out the name of the parent namespace
  121. //Start at the end of the string and work your way
  122. //back until you reach a backslash character or
  123. //you run out of string
  124. long len = lstrlen(name);
  125. //Note: a namespace cannot end with a backslash
  126. //so we check for this error condition
  127. long index = len - 1;
  128. if (name[index] == '\\')
  129. return FALSE;
  130. while (index && (name[index] != '\\'))
  131. index--;
  132. //We have either run out of string or found a backslash
  133. if (!index)
  134. {
  135. //We have run out of string
  136. return FALSE;
  137. }
  138. else
  139. {
  140. name[index] = 0;
  141. char* parent = name;
  142. char* child = parent + index + 1;
  143. //Get Parent
  144. HTREEITEM hParent;
  145. if (! FindAbsName(parent, hStartAt, hParent))
  146. {
  147. // Could not get parent, so create it
  148. CreateNamespace (parent, hStartAt, hParent);
  149. }
  150. if (hParent)
  151. {
  152. //Found parent, so now create child
  153. hFoundItem = InsertItem(m_tree1,hParent, (const char*)child);
  154. }
  155. }
  156. return TRUE;
  157. }
  158. int CConnectionDialog :: UnincludedChild (HTREEITEM hStartAt, int checkSelf)
  159. {
  160. if (checkSelf && !(((ISAMTreeItemData*)m_tree1.GetItemData (hStartAt))->included))
  161. {
  162. return TRUE;
  163. }
  164. else
  165. {
  166. HTREEITEM firstChild = NULL;
  167. if (firstChild = m_tree1.GetChildItem (hStartAt))
  168. {
  169. if (UnincludedChild (firstChild, TRUE))
  170. return TRUE;
  171. HTREEITEM nextSibling = firstChild;
  172. while (nextSibling = m_tree1.GetNextItem (nextSibling, TVGN_NEXT))
  173. {
  174. if (UnincludedChild (nextSibling, TRUE))
  175. return TRUE;;
  176. }
  177. }
  178. return FALSE;
  179. }
  180. }
  181. void CConnectionDialog :: GenerateOutMap (HTREEITEM hStartAt)
  182. {
  183. ISAMTreeItemData *itemData = (ISAMTreeItemData*)m_tree1.GetItemData (hStartAt);
  184. if (itemData->included)
  185. {
  186. // if there's an unincluded child add this individually and recurse
  187. // else add deep and no need to recurse
  188. if (UnincludedChild (hStartAt, FALSE))
  189. {
  190. // get name and add it shallow and recurse
  191. pMapStringToObOut->SetAt (itemData->absName,
  192. new CNamespace (itemData->absName));
  193. HTREEITEM firstChild = NULL;
  194. if (firstChild = m_tree1.GetChildItem (hStartAt))
  195. {
  196. GenerateOutMap (firstChild);
  197. HTREEITEM nextSibling = firstChild;
  198. while (nextSibling = m_tree1.GetNextItem (nextSibling, TVGN_NEXT))
  199. {
  200. GenerateOutMap (nextSibling);
  201. }
  202. }
  203. }
  204. else
  205. {
  206. // get name and add with deep flag (no recurse)
  207. // for now do same as above ie don't use deep flag
  208. pMapStringToObOut->SetAt (itemData->absName,
  209. new CNamespace (itemData->absName));
  210. HTREEITEM firstChild = NULL;
  211. if (firstChild = m_tree1.GetChildItem (hStartAt))
  212. {
  213. GenerateOutMap (firstChild);
  214. HTREEITEM nextSibling = firstChild;
  215. while (nextSibling = m_tree1.GetNextItem (nextSibling, TVGN_NEXT))
  216. {
  217. GenerateOutMap (nextSibling);
  218. }
  219. }
  220. }
  221. }
  222. else
  223. {
  224. // just recurse
  225. HTREEITEM firstChild = NULL;
  226. if (firstChild = m_tree1.GetChildItem (hStartAt))
  227. {
  228. GenerateOutMap (firstChild);
  229. HTREEITEM nextSibling = firstChild;
  230. while (nextSibling = m_tree1.GetNextItem (nextSibling, TVGN_NEXT))
  231. {
  232. GenerateOutMap (nextSibling);
  233. }
  234. }
  235. }
  236. }
  237. void CConnectionDialog :: GenerateOutString (HTREEITEM hStartAt)
  238. {
  239. ISAMTreeItemData *itemData = (ISAMTreeItemData*)m_tree1.GetItemData (hStartAt);
  240. if (itemData->included)
  241. {
  242. // if there's an unincluded child add this individually and recurse
  243. // else add deep and no need to recurse
  244. if (UnincludedChild (hStartAt, FALSE))
  245. {
  246. // get name and add it shallow and recurse
  247. char *temp = *lpszNamespacesOut;
  248. if (temp)
  249. {
  250. *lpszNamespacesOut = new char [strlen (temp) + 1 + 4 /* for punctuation */
  251. + strlen (itemData->absName) +
  252. strlen ("shallow")];
  253. (*lpszNamespacesOut)[0] = 0;
  254. strcpy (*lpszNamespacesOut, temp);
  255. strcat (*lpszNamespacesOut, ",");
  256. strcat (*lpszNamespacesOut, "{");
  257. strcat (*lpszNamespacesOut, itemData->absName);
  258. strcat (*lpszNamespacesOut, ",shallow}");
  259. delete temp;
  260. }
  261. else
  262. {
  263. *lpszNamespacesOut = new char [strlen (itemData->absName) + 1 + 4 +
  264. strlen ("shallow")];
  265. (*lpszNamespacesOut)[0] = 0;
  266. strcpy (*lpszNamespacesOut, "{");
  267. strcat (*lpszNamespacesOut, itemData->absName);
  268. strcat (*lpszNamespacesOut, ",shallow}");
  269. }
  270. HTREEITEM firstChild = NULL;
  271. if (firstChild = m_tree1.GetChildItem (hStartAt))
  272. {
  273. GenerateOutString (firstChild);
  274. HTREEITEM nextSibling = firstChild;
  275. while (nextSibling = m_tree1.GetNextItem (nextSibling, TVGN_NEXT))
  276. {
  277. GenerateOutString (nextSibling);
  278. }
  279. }
  280. }
  281. else
  282. {
  283. // get name and add with deep flag (no recurse)
  284. // for now do same as above ie don't use deep flag
  285. char *temp = *lpszNamespacesOut;
  286. if (temp)
  287. {
  288. *lpszNamespacesOut = new char [strlen (temp) + 1 + 4 /* for punctuation */
  289. + strlen (itemData->absName) +
  290. strlen ("deep")];
  291. (*lpszNamespacesOut)[0] = 0;
  292. strcpy (*lpszNamespacesOut, temp);
  293. strcat (*lpszNamespacesOut, ",");
  294. strcat (*lpszNamespacesOut, "{");
  295. strcat (*lpszNamespacesOut, itemData->absName);
  296. strcat (*lpszNamespacesOut, ",deep}");
  297. delete temp;
  298. }
  299. else
  300. {
  301. *lpszNamespacesOut = new char [strlen (itemData->absName) + 1 + 4
  302. + strlen("deep")];
  303. (*lpszNamespacesOut)[0] = 0;
  304. strcpy (*lpszNamespacesOut, "{");
  305. strcat (*lpszNamespacesOut, itemData->absName);
  306. strcat (*lpszNamespacesOut, ",deep}");
  307. }
  308. }
  309. }
  310. else
  311. {
  312. // just recurse
  313. HTREEITEM firstChild = NULL;
  314. if (firstChild = m_tree1.GetChildItem (hStartAt))
  315. {
  316. GenerateOutString (firstChild);
  317. HTREEITEM nextSibling = firstChild;
  318. while (nextSibling = m_tree1.GetNextItem (nextSibling, TVGN_NEXT))
  319. {
  320. GenerateOutString (nextSibling);
  321. }
  322. }
  323. }
  324. }
  325. void CConnectionDialog :: UpdateChildChildInclude (HTREEITEM hNode, BOOL fIncrement)
  326. {
  327. //Get the parent node, so that you can flag that a non-immediate child
  328. //has been selected
  329. HTREEITEM hParentNode = m_tree1.GetParentItem(hNode);
  330. if (hParentNode)
  331. {
  332. TV_ITEM tvItem;
  333. tvItem.hItem = hParentNode;
  334. tvItem.mask = TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  335. if (m_tree1.GetItem (&tvItem))
  336. {
  337. ISAMTreeItemData* temp = (ISAMTreeItemData*)tvItem.lParam;
  338. if (fIncrement)
  339. {
  340. ++(temp->childChildInclude);
  341. //update state of parent if no immediate children
  342. if (0 == temp->childInclude)
  343. {
  344. //I can find out the state via the iImage field
  345. if ( tvItem.iImage == m_idxMode1Image)
  346. {
  347. //In state 1, move to state 2
  348. tvItem.iSelectedImage = tvItem.iImage = m_idxMode2Image;
  349. m_tree1.SetItem (&tvItem);
  350. }
  351. else if ( tvItem.iImage == m_idxMode3Image)
  352. {
  353. //In state 3, move to state 4
  354. tvItem.iSelectedImage = tvItem.iImage = m_idxMode4Image;
  355. m_tree1.SetItem (&tvItem);
  356. }
  357. }
  358. }
  359. else
  360. {
  361. --(temp->childChildInclude);
  362. //update state of parent if no immediate children
  363. if ((0 == temp->childInclude) && (0 == temp->childChildInclude))
  364. {
  365. //I can find out the state via the iImage field
  366. if ( tvItem.iImage == m_idxMode2Image)
  367. {
  368. //In state 2, move to state 1
  369. tvItem.iSelectedImage = tvItem.iImage = m_idxMode1Image;
  370. m_tree1.SetItem (&tvItem);
  371. }
  372. else if ( tvItem.iImage == m_idxMode4Image)
  373. {
  374. //In state 4, move to state 3
  375. tvItem.iSelectedImage = tvItem.iImage = m_idxMode3Image;
  376. m_tree1.SetItem (&tvItem);
  377. }
  378. }
  379. }
  380. }
  381. //Recursive call up the chain of parents
  382. UpdateChildChildInclude(hParentNode, fIncrement);
  383. }
  384. }
  385. void CConnectionDialog :: AddNamespaces (HTREEITEM hParent,
  386. int deep)
  387. {
  388. TV_ITEM tvItem;
  389. tvItem.hItem = hParent;
  390. tvItem.mask = TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN;
  391. if (m_tree1.GetItem (&tvItem))
  392. {
  393. //If cel not already selected, then select
  394. if (! ((ISAMTreeItemData*)tvItem.lParam)->included )
  395. {
  396. cSelectedCels++;
  397. //Update count in parent node
  398. HTREEITEM hParentNode = m_tree1.GetParentItem(hParent);
  399. if (hParentNode)
  400. {
  401. TV_ITEM tvItem2;
  402. tvItem2.hItem = hParentNode;
  403. tvItem2.mask = TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  404. if (m_tree1.GetItem (&tvItem2))
  405. {
  406. ++(((ISAMTreeItemData*)tvItem2.lParam)->childInclude);
  407. //Parent node must be in either state 1, 2 or 3
  408. //I can find out the state via the iImage field
  409. if ( tvItem2.iImage == m_idxMode1Image)
  410. {
  411. //In state 1, move to state 2
  412. //tvItem2.iSelectedImage = tvItem2.iImage = m_idxMode2Image;
  413. m_tree1.SetItemImage (hParentNode, m_idxMode2Image, m_idxMode2Image);
  414. }
  415. else if ( tvItem2.iImage == m_idxMode3Image)
  416. {
  417. //In state 3, move to state 4
  418. //tvItem2.iSelectedImage = tvItem2.iImage = m_idxMode4Image;
  419. m_tree1.SetItemImage (hParentNode, m_idxMode4Image, m_idxMode4Image);
  420. }
  421. //Now indicate to parents parent that a non-immediate child
  422. //has been selected
  423. UpdateChildChildInclude(hParentNode, TRUE);
  424. }
  425. }
  426. }
  427. if (deep) //recurse
  428. {
  429. HTREEITEM firstChild = NULL;
  430. if (firstChild = m_tree1.GetChildItem (hParent))
  431. {
  432. AddNamespaces (firstChild, deep);
  433. HTREEITEM nextSibling = firstChild;
  434. while (nextSibling = m_tree1.GetNextItem (nextSibling, TVGN_NEXT))
  435. AddNamespaces (nextSibling, deep);
  436. }
  437. }
  438. m_tree1.GetItem (&tvItem);
  439. ((ISAMTreeItemData*)tvItem.lParam)->included = TRUE;
  440. //Check if this node has 'included' children
  441. int children = tvItem.cChildren;
  442. ISAMTreeItemData* temp = (ISAMTreeItemData*)tvItem.lParam;
  443. if (children && (temp->childInclude || temp->childChildInclude))
  444. {
  445. // tvItem.iSelectedImage = tvItem.iImage = m_idxMode4Image;
  446. m_tree1.SetItemImage (hParent, m_idxMode4Image, m_idxMode4Image);
  447. }
  448. else
  449. {
  450. // tvItem.iSelectedImage = tvItem.iImage = m_idxMode3Image;
  451. m_tree1.SetItemImage (hParent, m_idxMode3Image, m_idxMode3Image);
  452. }
  453. // m_tree1.SetItem (&tvItem);
  454. }
  455. //Update state of OK and Cancel pushbutton depending on
  456. //number of cels selected
  457. m_okButton.EnableWindow(cSelectedCels ? TRUE : FALSE);
  458. }
  459. void CConnectionDialog :: RemoveNamespaces (HTREEITEM hParent,
  460. int deep)
  461. {
  462. TV_ITEM tvItem;
  463. tvItem.hItem = hParent;
  464. tvItem.mask = TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN;
  465. if (m_tree1.GetItem (&tvItem))
  466. {
  467. //If cel not unselected, then unselect
  468. if ( ((ISAMTreeItemData*)tvItem.lParam)->included )
  469. {
  470. cSelectedCels--;
  471. //update state of parent
  472. HTREEITEM hParentNode = m_tree1.GetParentItem(hParent);
  473. if (hParentNode)
  474. {
  475. TV_ITEM tvItem2;
  476. tvItem2.hItem = hParentNode;
  477. tvItem2.mask = TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  478. if (m_tree1.GetItem (&tvItem2))
  479. {
  480. --(((ISAMTreeItemData*)tvItem2.lParam)->childInclude);
  481. //Parent node must be in either state 2 or 4
  482. //I can find out the state via the iImage field
  483. if ( tvItem2.iImage == m_idxMode4Image)
  484. {
  485. //In state 4
  486. if (!((ISAMTreeItemData*)tvItem2.lParam)->childInclude)
  487. {
  488. //Check non-immediate children
  489. if (!((ISAMTreeItemData*)tvItem2.lParam)->childChildInclude)
  490. {
  491. //If no more children move to state 3
  492. // tvItem2.iSelectedImage = tvItem2.iImage = m_idxMode3Image;
  493. //// m_tree1.SetItem (&tvItem2);
  494. m_tree1.SetItemImage (hParentNode, m_idxMode3Image, m_idxMode3Image);
  495. }
  496. }
  497. }
  498. else
  499. {
  500. //In state 2
  501. if (!((ISAMTreeItemData*)tvItem2.lParam)->childInclude)
  502. {
  503. //Check non-immediate children
  504. if (!((ISAMTreeItemData*)tvItem2.lParam)->childChildInclude)
  505. {
  506. //If no more children move to state 1
  507. // tvItem2.iSelectedImage = tvItem2.iImage = m_idxMode1Image;
  508. //// m_tree1.SetItem (&tvItem2);
  509. m_tree1.SetItemImage (hParentNode, m_idxMode1Image, m_idxMode1Image);
  510. }
  511. }
  512. }
  513. //Now indicate to parents parent that a non-immediate child
  514. //has been de-selected
  515. UpdateChildChildInclude(hParentNode, FALSE);
  516. }
  517. }
  518. }
  519. if (deep) //recurse
  520. {
  521. HTREEITEM firstChild = NULL;
  522. if (firstChild = m_tree1.GetChildItem (hParent))
  523. {
  524. RemoveNamespaces (firstChild, deep);
  525. HTREEITEM nextSibling = firstChild;
  526. while (nextSibling = m_tree1.GetNextItem (nextSibling, TVGN_NEXT))
  527. RemoveNamespaces (nextSibling, deep);
  528. }
  529. }
  530. m_tree1.GetItem (&tvItem);
  531. ((ISAMTreeItemData*)tvItem.lParam)->included = FALSE;
  532. //Check if this node has 'included' children
  533. int children = tvItem.cChildren;
  534. ISAMTreeItemData* temp = (ISAMTreeItemData*)tvItem.lParam;
  535. if (children && (temp->childInclude || temp->childChildInclude))
  536. {
  537. // tvItem.iSelectedImage = tvItem.iImage = m_idxMode2Image;
  538. m_tree1.SetItemImage (hParent, m_idxMode2Image, m_idxMode2Image);
  539. }
  540. else
  541. {
  542. // tvItem.iSelectedImage = tvItem.iImage = m_idxMode1Image;
  543. m_tree1.SetItemImage (hParent, m_idxMode1Image, m_idxMode1Image);
  544. }
  545. //// m_tree1.SetItem (&tvItem);
  546. }
  547. //Update state of OK and Cancel pushbutton depending on
  548. //number of cels selected
  549. m_okButton.EnableWindow(cSelectedCels ? TRUE : FALSE);
  550. }
  551. CConnectionDialog::CConnectionDialog(CWnd* pParent, char *pszServer,
  552. // WBEM_LOGIN_AUTHENTICATION loginMethod,
  553. char *pszUsername, char *pszPassword,
  554. char **pszLocale, char** pszAuthority,
  555. BOOL FAR* fSysProp, BOOL fConnParmSpec,
  556. CMapStringToOb *pNamespaceMap,
  557. CMapStringToOb *pNamespaceMapOut,
  558. BOOL enableDefaultDatabase, char **connectionString, BOOL FAR* fImpersonate, BOOL FAR* fPassthrghOnly, BOOL FAR* fItprtEmptPwdAsBlk)
  559. : CDialog(CConnectionDialog::IDD, pParent)
  560. {
  561. ODBCTRACE(_T("\nWBEM ODBC Driver : CConnectionDialog::CConnectionDialog\n"));
  562. //{{AFX_DATA_INIT(CConnectionDialog)
  563. //}}AFX_DATA_INIT
  564. pMapStringToObOut = pNamespaceMapOut;
  565. pMapStringToObIn = pNamespaceMap;
  566. // pServerIn = NULL;
  567. // pUsernameIn = NULL;
  568. // pPasswordIn = NULL;
  569. lpszNamespacesOut = connectionString;
  570. fDoubleClicked = FALSE;
  571. fConnParmSpecified = fConnParmSpec;
  572. //Make copy of Server, UserName and Password memory addresses
  573. lpszServer = pszServer;
  574. lpszUserName = pszUsername;
  575. lpszPassword = pszPassword;
  576. lpszAuthority = NULL;
  577. lpszLocale = NULL;
  578. lpszAuthorityOut = pszAuthority;
  579. lpszLocaleOut = pszLocale;
  580. if (pszLocale && *pszLocale)
  581. {
  582. int localeLen = lstrlen(*pszLocale);
  583. lpszLocale = new char [localeLen + 1];
  584. lpszLocale[0] = 0;
  585. lstrcpy(lpszLocale, *pszLocale);
  586. }
  587. if (pszAuthority && *pszAuthority)
  588. {
  589. int authLen = lstrlen(*pszAuthority);
  590. lpszAuthority = new char [authLen + 1];
  591. lpszAuthority[0] = 0;
  592. lstrcpy(lpszAuthority, *pszAuthority);
  593. ODBCTRACE(_T("\nWBEM ODBC Driver : Authority :"));
  594. ODBCTRACE(_T(lpszAuthority));
  595. ODBCTRACE(_T("\n"));
  596. }
  597. // m_loginMethod = loginMethod;
  598. //A counter to indicated number of selected namespace cels
  599. cSelectedCels = 0;
  600. *connectionString = NULL;
  601. //Setup System Properties
  602. fSystemProperties = fSysProp;
  603. // if (pszUsername)
  604. // {
  605. // pUsernameIn = new char [strlen (pszUsername) + 1];
  606. // pUsernameIn[0] = 0;
  607. // strcpy (pUsernameIn, pszUsername);
  608. // }
  609. // if (pszPassword)
  610. // {
  611. // pPasswordIn = new char [strlen (pszPassword) + 1];
  612. // pPasswordIn[0] = 0;
  613. // strcpy (pPasswordIn, pszPassword);
  614. // }
  615. fImpersonation = fImpersonate;
  616. fPassthroughOnly = fPassthrghOnly;
  617. fIntpretEmptPwdAsBlank = fItprtEmptPwdAsBlk;
  618. impersonateMgr = NULL;
  619. if (*fImpersonation)
  620. {
  621. //Now check if impersonation is necessary
  622. //only if connecting locally
  623. if (IsLocalServer(lpszServer))
  624. {
  625. impersonateMgr = new ImpersonationManager(lpszUserName, lpszPassword, lpszAuthority);
  626. }
  627. else
  628. {
  629. ODBCTRACE("\nWBEM ODBC Driver : Server not detected as local, not impersonating\n");
  630. }
  631. }
  632. }
  633. CConnectionDialog :: ~CConnectionDialog()
  634. {
  635. ODBCTRACE ("\nWBEM ODBC Driver : CConnectionDialog :: ~CConnectionDialog\n");
  636. //Tidy Up
  637. // if (pUsernameIn)
  638. // delete pUsernameIn;
  639. // if (pPasswordIn)
  640. // delete pPasswordIn;
  641. delete impersonateMgr;
  642. ODBCTRACE ("\nWBEM ODBC Driver : CConnectionDialog :: ~CConnectionDialog exit point\n");
  643. }
  644. void CConnectionDialog::DoDataExchange(CDataExchange* pDX)
  645. {
  646. CDialog::DoDataExchange(pDX);
  647. //{{AFX_DATA_MAP(CConnectionDialog)
  648. //}}AFX_DATA_MAP
  649. }
  650. BEGIN_MESSAGE_MAP(CConnectionDialog, CDialog)
  651. //{{AFX_MSG_MAP(CConnectionDialog)
  652. ON_NOTIFY(NM_CLICK, IDC_TREE1, OnClickTree1)
  653. ON_NOTIFY(TVN_KEYDOWN, IDC_TREE1, OnKeyDown)
  654. ON_NOTIFY(TVN_ITEMEXPANDING, IDC_TREE1, OnTreeExpand)
  655. ON_NOTIFY(TVN_DELETEITEM, IDC_TREE1, OnDeleteitemTree1)
  656. ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
  657. ON_BN_CLICKED(IDC_CHECK1, OnButtonSysProp)
  658. ON_BN_CLICKED(IDC_CHECK_IMPERSONATE, OnButtonImpersonation)
  659. ON_BN_CLICKED(IDC_CHECK_PASSTHROUGHONLY, OnButtonPassthroughOnly)
  660. ON_NOTIFY(NM_DBLCLK, IDC_TREE1, OnDblclkTree1)
  661. ON_EN_KILLFOCUS(IDC_BROWSE_EDIT, OnKillfocusBrowseEdit)
  662. ON_EN_CHANGE(IDC_EDIT_USER_NAME, OnUserNameChange)
  663. ON_EN_CHANGE(IDC_EDIT_PSWD, OnPasswordChange)
  664. ON_EN_CHANGE(IDC_EDIT_AUTH, OnAuthorityChange)
  665. ON_EN_CHANGE(IDC_EDIT_LOCALE, OnLocaleChange)
  666. ON_EN_CHANGE(IDC_BROWSE_EDIT, OnServerChange)
  667. ON_BN_CLICKED(IDC_REFRESH_BUTTON, OnButtonRefresh)
  668. ON_BN_CLICKED(IDC_HELP_BUTTON, OnHelp)
  669. ON_BN_CLICKED(IDC_RADIO_BLANK, OnButtonInterpretEmpty)
  670. ON_BN_CLICKED(IDC_RADIO_NULL, OnButtonInterpretEmpty)
  671. ON_WM_NCDESTROY()
  672. //}}AFX_MSG_MAP
  673. END_MESSAGE_MAP()
  674. /////////////////////////////////////////////////////////////////////////////
  675. // CConnectionDialog message handlers
  676. void CConnectionDialog::OnKeyDown(NMHDR* pNMHDR, LRESULT* pResult)
  677. {
  678. TV_KEYDOWN* lParam = (TV_KEYDOWN*)pNMHDR;
  679. // TODO: Add your control notification handler code here
  680. *pResult = 0;
  681. //Check if SPACE BAR is pressed
  682. if (lParam->wVKey == VK_SPACE)
  683. {
  684. HTREEITEM item = m_tree1.GetSelectedItem();
  685. //Grab the WM_CHAR message from the message queue
  686. MSG myMessage;
  687. BOOL status = GetMessage(&myMessage, lParam->hdr.hwndFrom, WM_CHAR, WM_CHAR);
  688. if (item)
  689. {
  690. //Get the item
  691. TV_ITEM tvItem;
  692. tvItem.hItem = item;
  693. tvItem.mask = TVIF_STATE | TVIF_PARAM;
  694. if (m_tree1.GetItem (&tvItem))
  695. {
  696. //Check if item is expanded, if not we add/remove in 'deep' mode
  697. BOOL fDeepMode = (tvItem.state & TVIS_EXPANDED) ? FALSE : TRUE;
  698. //If the item is 'included' we remove
  699. //If the item is not 'included' we add
  700. if ( ((ISAMTreeItemData*)tvItem.lParam)->included )
  701. {
  702. RemoveNamespaces(item, fDeepMode);
  703. }
  704. else
  705. {
  706. BeginWaitCursor();
  707. BOOL itemSelected = ((ISAMTreeItemData*)tvItem.lParam)->included;
  708. BOOL fChildrenChecked = FALSE;
  709. //Get immediate child items and expand them to 1 level only
  710. //Note: Remember to check if it has already been expanded
  711. HTREEITEM firstChild = NULL;
  712. if (firstChild = m_tree1.GetChildItem (item))
  713. {
  714. //Get absolute name for this item
  715. TV_ITEM tvItem2;
  716. tvItem2.hItem = firstChild;
  717. tvItem2.mask = TVIF_PARAM;
  718. if (m_tree1.GetItem (&tvItem2))
  719. {
  720. //Check if this node has already been checked for children
  721. fChildrenChecked = ((ISAMTreeItemData*)tvItem2.lParam)->fExpanded;
  722. if (!fChildrenChecked)
  723. {
  724. char* txt = ((ISAMTreeItemData*)tvItem2.lParam)->absName;
  725. ISAMBuildTreeChildren (firstChild,
  726. txt,
  727. m_tree1,
  728. *this,
  729. lpszServer,
  730. // m_loginMethod,
  731. lpszUserName,
  732. lpszPassword,
  733. *fIntpretEmptPwdAsBlank,
  734. lpszLocale,
  735. lpszAuthority,
  736. ! itemSelected);
  737. }
  738. }
  739. HTREEITEM nextSibling = firstChild;
  740. while (nextSibling = m_tree1.GetNextItem (nextSibling, TVGN_NEXT))
  741. {
  742. TV_ITEM tvItem3;
  743. tvItem3.hItem = nextSibling;
  744. tvItem3.mask = TVIF_PARAM;
  745. if (m_tree1.GetItem (&tvItem3))
  746. {
  747. //Check if this node has already been checked for children
  748. fChildrenChecked = ((ISAMTreeItemData*)tvItem3.lParam)->fExpanded;
  749. if (!fChildrenChecked)
  750. {
  751. char* txt = ((ISAMTreeItemData*)tvItem3.lParam)->absName;
  752. ISAMBuildTreeChildren (nextSibling,
  753. txt,
  754. m_tree1,
  755. *this,
  756. lpszServer,
  757. // m_loginMethod,
  758. lpszUserName,
  759. lpszPassword,
  760. *fIntpretEmptPwdAsBlank,
  761. lpszLocale,
  762. lpszAuthority,
  763. ! itemSelected);
  764. }
  765. }
  766. }
  767. }
  768. AddNamespaces (item, fDeepMode);
  769. EndWaitCursor();
  770. }
  771. }
  772. }
  773. }
  774. }
  775. void CConnectionDialog::OnTreeExpand(NMHDR* pNMHDR, LRESULT* pResult)
  776. {
  777. NM_TREEVIEW* lParam = (NM_TREEVIEW*)pNMHDR;
  778. // TODO: Add your control notification handler code here
  779. *pResult = 0;
  780. TV_ITEM tvItem = lParam->itemNew;
  781. UINT action = lParam->action;
  782. HTREEITEM item = tvItem.hItem;
  783. //Check if item is expanded, if not we add/remove in 'deep' mode
  784. BOOL fExpanding = (action == TVE_EXPAND) ? TRUE : FALSE;
  785. if (!fExpanding)
  786. return;
  787. BeginWaitCursor();
  788. char* txt = ((ISAMTreeItemData*)tvItem.lParam)->pszText;
  789. BOOL fChildrenChecked = FALSE;
  790. //Get immediate child items and expand them to 1 level only
  791. //Note: Remember to check if it has already been expanded
  792. HTREEITEM firstChild = NULL;
  793. if (firstChild = m_tree1.GetChildItem (item))
  794. {
  795. //Get absolute name for this item
  796. TV_ITEM tvItem2;
  797. tvItem2.hItem = firstChild;
  798. tvItem2.mask = TVIF_PARAM;
  799. if (m_tree1.GetItem (&tvItem2))
  800. {
  801. //Check if this node has already been checked for children
  802. fChildrenChecked = ((ISAMTreeItemData*)tvItem2.lParam)->fExpanded;
  803. if (!fChildrenChecked)
  804. {
  805. txt = ((ISAMTreeItemData*)tvItem2.lParam)->absName;
  806. ISAMBuildTreeChildren (firstChild,
  807. txt,
  808. m_tree1,
  809. *this,
  810. lpszServer,
  811. // m_loginMethod,
  812. lpszUserName,
  813. lpszPassword,
  814. *fIntpretEmptPwdAsBlank,
  815. lpszLocale,
  816. lpszAuthority,
  817. FALSE);
  818. }
  819. }
  820. HTREEITEM nextSibling = firstChild;
  821. while (nextSibling = m_tree1.GetNextItem (nextSibling, TVGN_NEXT))
  822. {
  823. TV_ITEM tvItem3;
  824. tvItem3.hItem = nextSibling;
  825. tvItem3.mask = TVIF_PARAM;
  826. if (m_tree1.GetItem (&tvItem3))
  827. {
  828. //Check if this node has already been checked for children
  829. fChildrenChecked = ((ISAMTreeItemData*)tvItem3.lParam)->fExpanded;
  830. if (!fChildrenChecked)
  831. {
  832. txt = ((ISAMTreeItemData*)tvItem3.lParam)->absName;
  833. ISAMBuildTreeChildren (nextSibling,
  834. txt,
  835. m_tree1,
  836. *this,
  837. lpszServer,
  838. // m_loginMethod,
  839. lpszUserName,
  840. lpszPassword,
  841. *fIntpretEmptPwdAsBlank,
  842. lpszLocale,
  843. lpszAuthority,
  844. FALSE);
  845. }
  846. }
  847. }
  848. }
  849. EndWaitCursor();
  850. }
  851. void CConnectionDialog::OnClickTree1(NMHDR* pNMHDR, LRESULT* pResult)
  852. {
  853. // TODO: Add your control notification handler code here
  854. *pResult = 0;
  855. //Check if you double-clicked
  856. // if (fDoubleClicked)
  857. // {
  858. // fDoubleClicked = FALSE;
  859. // return;
  860. // }
  861. fDoubleClicked = FALSE;
  862. //Get current position of mouse cursor and perform
  863. //a hit test on the tree control
  864. POINT cursorPos;
  865. GetCursorPos(&cursorPos);
  866. m_tree1.ScreenToClient(&cursorPos);
  867. UINT fFlags = 0;
  868. HTREEITEM item = m_tree1.HitTest(cursorPos, &fFlags);
  869. if (fFlags & TVHT_ONITEMICON)
  870. {
  871. //Support for mouse operation to 'check' the node checkbox
  872. if (item)
  873. {
  874. //Get the item
  875. TV_ITEM tvItem;
  876. tvItem.hItem = item;
  877. tvItem.mask = TVIF_STATE | TVIF_PARAM;
  878. if (m_tree1.GetItem (&tvItem))
  879. {
  880. //Check if item is expanded, if not we add/remove in 'deep' mode
  881. BOOL fDeepMode = (tvItem.state & TVIS_EXPANDED) ? FALSE : TRUE;
  882. //If the item is 'included' we remove
  883. //If the item is not 'included' we add
  884. if ( ((ISAMTreeItemData*)tvItem.lParam)->included )
  885. {
  886. RemoveNamespaces(item, fDeepMode);
  887. }
  888. else
  889. {
  890. BeginWaitCursor();
  891. BOOL itemSelected = ((ISAMTreeItemData*)tvItem.lParam)->included;
  892. BOOL fChildrenChecked = FALSE;
  893. //Get immediate child items and expand them to 1 level only
  894. //Note: Remember to check if it has already been expanded
  895. HTREEITEM firstChild = NULL;
  896. if (firstChild = m_tree1.GetChildItem (item))
  897. {
  898. //Get absolute name for this item
  899. TV_ITEM tvItem2;
  900. tvItem2.hItem = firstChild;
  901. tvItem2.mask = TVIF_PARAM;
  902. if (m_tree1.GetItem (&tvItem2))
  903. {
  904. //Check if this node has already been checked for children
  905. fChildrenChecked = ((ISAMTreeItemData*)tvItem2.lParam)->fExpanded;
  906. if (!fChildrenChecked)
  907. {
  908. char* txt = ((ISAMTreeItemData*)tvItem2.lParam)->absName;
  909. ISAMBuildTreeChildren (firstChild,
  910. txt,
  911. m_tree1,
  912. *this,
  913. lpszServer,
  914. // m_loginMethod,
  915. lpszUserName,
  916. lpszPassword,
  917. *fIntpretEmptPwdAsBlank,
  918. lpszLocale,
  919. lpszAuthority,
  920. ! itemSelected);
  921. }
  922. }
  923. HTREEITEM nextSibling = firstChild;
  924. while (nextSibling = m_tree1.GetNextItem (nextSibling, TVGN_NEXT))
  925. {
  926. TV_ITEM tvItem3;
  927. tvItem3.hItem = nextSibling;
  928. tvItem3.mask = TVIF_PARAM;
  929. if (m_tree1.GetItem (&tvItem3))
  930. {
  931. //Check if this node has already been checked for children
  932. fChildrenChecked = ((ISAMTreeItemData*)tvItem3.lParam)->fExpanded;
  933. if (!fChildrenChecked)
  934. {
  935. char* txt = ((ISAMTreeItemData*)tvItem3.lParam)->absName;
  936. ISAMBuildTreeChildren (nextSibling,
  937. txt,
  938. m_tree1,
  939. *this,
  940. lpszServer,
  941. // m_loginMethod,
  942. lpszUserName,
  943. lpszPassword,
  944. *fIntpretEmptPwdAsBlank,
  945. lpszLocale,
  946. lpszAuthority,
  947. ! itemSelected);
  948. }
  949. }
  950. }
  951. }
  952. AddNamespaces (item, fDeepMode);
  953. EndWaitCursor();
  954. }
  955. }
  956. }
  957. }
  958. }
  959. void CConnectionDialog::OnDeleteitemTree1(NMHDR* pNMHDR, LRESULT* pResult)
  960. {
  961. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  962. // TODO: Add your control notification handler code here
  963. *pResult = 0;
  964. }
  965. // Window Procedure to circumvent bug(?) in mfc
  966. CMap<SHORT, SHORT, CWindowInfo*, CWindowInfo*> windowMap;
  967. LRESULT CALLBACK
  968. MySubClassProc (HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
  969. {
  970. CWindowInfo *pwindowInfo = NULL;
  971. VERIFY (windowMap.Lookup ((SHORT) ((DWORD)hWnd & 0xffff), pwindowInfo) && pwindowInfo);
  972. return :: CallWindowProc (pwindowInfo->m_oldWindowProc,
  973. pwindowInfo->m_hWnd,
  974. nMsg, wParam, lParam);
  975. }
  976. BOOL CConnectionDialog::OnInitDialog()
  977. {
  978. ODBCTRACE ("\nWBEM ODBC Driver : CConnectionDialog::OnInitDialog\n");
  979. CDialog::OnInitDialog();
  980. // subclass the window to circumvent a bug (?) in mfc
  981. WNDPROC oldWindowProc = (WNDPROC):: SetWindowLong (m_hWnd, GWL_WNDPROC, (DWORD) MySubClassProc);
  982. CWindowInfo *pwindowInfo = new CWindowInfo (m_hWnd, oldWindowProc);
  983. windowMap.SetAt ((SHORT)((DWORD)m_hWnd & 0xffff), pwindowInfo);
  984. // hook up the controls
  985. m_browseEdit.Attach (::GetDlgItem (m_hWnd, IDC_BROWSE_EDIT));
  986. m_browse.Attach (::GetDlgItem (m_hWnd, IDC_BUTTON_BROWSE));
  987. m_cancelButton.Attach(::GetDlgItem (m_hWnd, IDCANCEL));
  988. m_okButton.Attach (::GetDlgItem (m_hWnd, IDOK));
  989. m_UserName.Attach(::GetDlgItem (m_hWnd, IDC_EDIT_USER_NAME));
  990. m_Password.Attach(::GetDlgItem (m_hWnd, IDC_EDIT_PSWD));
  991. m_Authority.Attach(::GetDlgItem (m_hWnd, IDC_EDIT_AUTH));
  992. m_Locale.Attach(::GetDlgItem (m_hWnd, IDC_EDIT_LOCALE));
  993. m_tree1.Attach(::GetDlgItem (m_hWnd, IDC_TREE1));
  994. m_sysPropCheck.Attach(::GetDlgItem (m_hWnd, IDC_CHECK1));
  995. m_impersonateCheck.Attach(::GetDlgItem (m_hWnd, IDC_CHECK_IMPERSONATE));
  996. m_PassthroughOnlyCheck.Attach(::GetDlgItem (m_hWnd, IDC_CHECK_PASSTHROUGHONLY));
  997. m_messageEdit.Attach (::GetDlgItem (m_hWnd, IDC_MESSAGE));
  998. m_RefreshButton.Attach (::GetDlgItem (m_hWnd, IDC_REFRESH_BUTTON));
  999. m_PwdAsNull.Attach (::GetDlgItem (m_hWnd, IDC_RADIO_NULL));
  1000. m_PwdAsBlank.Attach (::GetDlgItem (m_hWnd, IDC_RADIO_BLANK));
  1001. // TODO: Add extra initialization here
  1002. pCurrentSelectionList = NULL;
  1003. pCurrentItem = NULL;
  1004. m_browseEdit.LimitText(MAX_SERVER_NAME_LENGTH);
  1005. m_UserName.LimitText(MAX_USER_NAME_LENGTH);
  1006. m_Password.LimitText(MAX_PASSWORD_LENGTH);
  1007. m_Password.SetPasswordChar('*');
  1008. m_browseEdit.SetWindowText((lpszServer ? lpszServer : ""));
  1009. m_browseEdit.SetModify(FALSE);
  1010. m_UserName.SetWindowText((lpszUserName ? lpszUserName : ""));
  1011. m_UserName.SetModify(FALSE);
  1012. m_Password.SetWindowText((lpszPassword ? lpszPassword : ""));
  1013. m_Password.SetModify(FALSE);
  1014. //Set Authority
  1015. m_Authority.SetWindowText((lpszAuthority ? lpszAuthority : ""));
  1016. m_Authority.SetModify(FALSE);
  1017. //Set Locale
  1018. m_Locale.SetWindowText((lpszLocale ? lpszLocale : ""));
  1019. m_Locale.SetModify(FALSE);
  1020. //Set System Properties checkbox
  1021. m_sysPropCheck.SetCheck(*fSystemProperties ? 1 : 0);
  1022. //Set Impersonation checkbox
  1023. m_impersonateCheck.SetCheck(impersonateMgr ? 1 : 0);
  1024. //Set Passthrough only checkbox
  1025. m_PassthroughOnlyCheck.SetCheck(*fPassthroughOnly ? 1 : 0);
  1026. //Set the Interpret an empty password as
  1027. m_PwdAsNull.SetCheck(*fIntpretEmptPwdAsBlank ? 0 : 1);
  1028. m_PwdAsBlank.SetCheck(*fIntpretEmptPwdAsBlank ? 1 : 0);
  1029. m_messageEdit.FmtLines(TRUE);
  1030. m_messageEdit.ShowWindow(SW_HIDE);
  1031. m_tree1.EnableWindow(TRUE);
  1032. m_tree1.ShowWindow(SW_SHOWNA);
  1033. char buffer [129];
  1034. buffer[0] = 0;
  1035. LoadString(s_hModule, STR_CONNECT, (char*)buffer, 128);
  1036. m_RefreshButton.SetWindowText(buffer);
  1037. m_RefreshButton.EnableWindow(FALSE);
  1038. // Fill in the first tree with all the namespace information
  1039. // The second tree is empty for now. In future this will depend on the
  1040. // connection string
  1041. //Each node in the CTreeCtrl will be in one of the following 4 states
  1042. // 1) node not selected, child nodes not selected
  1043. // 2) node not selected, some or all child nodes selected
  1044. // 3) node selected, no child nodes selected
  1045. // 4) node selected, some or all child nodes selected
  1046. m_imageList.Create (32, 16, TRUE, 25, 0);
  1047. bmap1.LoadBitmap(IDB_BITMAP1);
  1048. bmap2.LoadBitmap(IDB_BITMAP2);
  1049. bmap3.LoadBitmap(IDB_BITMAP3);
  1050. bmap4.LoadBitmap(IDB_BITMAP4);
  1051. bmask.LoadBitmap(IDB_MASK);
  1052. m_idxMode1Image = m_imageList.Add (&bmap1, &bmask);
  1053. m_idxMode2Image = m_imageList.Add (&bmap2, &bmask);
  1054. m_idxMode3Image = m_imageList.Add (&bmap3, &bmask);
  1055. m_idxMode4Image = m_imageList.Add (&bmap4, &bmask);
  1056. m_tree1.SetImageList (&m_imageList, TVSIL_NORMAL);
  1057. //Tidy Up
  1058. bmap1.DeleteObject();
  1059. bmap2.DeleteObject();
  1060. bmap3.DeleteObject();
  1061. bmap4.DeleteObject();
  1062. bmask.DeleteObject();
  1063. LONG oldStyle = :: GetWindowLong(m_tree1.m_hWnd, GWL_STYLE);
  1064. :: SetWindowLong (m_tree1.m_hWnd,
  1065. GWL_STYLE,
  1066. oldStyle | TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT);
  1067. BOOL fStatusOK = TRUE;
  1068. //We may or may not be using impersonation
  1069. //but if we do, has it worked ?
  1070. if (*fImpersonation && impersonateMgr)
  1071. {
  1072. //Check if impersonation request has worked
  1073. if (! impersonateMgr->CanWeImpersonate() )
  1074. {
  1075. fStatusOK = FALSE;
  1076. }
  1077. }
  1078. if (fStatusOK)
  1079. {
  1080. BeginWaitCursor();
  1081. HTREEITEM hDummy;
  1082. SWORD treeStatus = ISAMBuildTree (TVI_ROOT, "root", /*"root\\default",*/
  1083. m_tree1, *this,
  1084. lpszServer ? lpszServer : NULL, // server
  1085. // m_loginMethod,
  1086. lpszUserName ? lpszUserName : NULL, // username
  1087. lpszPassword ? lpszPassword : NULL, // password
  1088. *fIntpretEmptPwdAsBlank,
  1089. lpszLocale,
  1090. lpszAuthority,
  1091. TRUE, FALSE, hDummy);
  1092. EndWaitCursor();
  1093. // enumerate elements in list and set the namespaces passed in in the
  1094. // connection string to be included
  1095. POSITION pos;
  1096. CString key;
  1097. CNamespace *pNamespace;
  1098. for (pos = pMapStringToObIn->GetStartPosition ();pos != NULL;)
  1099. {
  1100. pMapStringToObIn->GetNextAssoc (pos, key, (CObject*&)pNamespace);
  1101. HTREEITEM hFoundItem;
  1102. int len = (pNamespace->GetName ()).GetLength ();
  1103. LPTSTR str = (pNamespace->GetName ()).GetBuffer (len);
  1104. if (FindAbsName (str, m_tree1.GetRootItem (), hFoundItem))
  1105. {
  1106. //include it
  1107. AddNamespaces (hFoundItem, FALSE /* shallow */);
  1108. }
  1109. else
  1110. {
  1111. // attempt to create namespace
  1112. if (CreateNamespace (str, m_tree1.GetRootItem (), hFoundItem))
  1113. {
  1114. //include it
  1115. AddNamespaces (hFoundItem, FALSE /* shallow */);
  1116. }
  1117. }
  1118. }
  1119. //Update state of OK pushbutton depending on
  1120. //number of cels selected
  1121. m_okButton.EnableWindow(cSelectedCels ? TRUE : FALSE);
  1122. }
  1123. else
  1124. {
  1125. //Impersonation failed
  1126. m_tree1.EnableWindow(FALSE);
  1127. m_tree1.ShowWindow(SW_HIDE);
  1128. char buffer [128 + 1];
  1129. buffer[0] = 0;
  1130. LoadString(s_hModule, STR_FAILED_WBEM_CONN,
  1131. (char*)buffer, 128);
  1132. m_messageEdit.SetWindowText(buffer);
  1133. m_messageEdit.ShowWindow(SW_SHOWNA);
  1134. }
  1135. //Final check to see if proper connection parameters were entered
  1136. if (!fConnParmSpecified)
  1137. {
  1138. ConnectionParameterChange();
  1139. //Give the user name edit box focus
  1140. m_UserName.SetFocus();
  1141. }
  1142. return TRUE; // return TRUE unless you set the focus to a control
  1143. // EXCEPTION: OCX Property Pages should return FALSE
  1144. }
  1145. void CConnectionDialog::OnNcDestroy()
  1146. {
  1147. CWindowInfo *pwindowInfo = NULL;
  1148. BOOL found = windowMap.Lookup ((SHORT) ((DWORD)m_hWnd & 0xffff), pwindowInfo);
  1149. ASSERT (found);
  1150. if (found)
  1151. {
  1152. // unsubclass the window
  1153. :: SetWindowLong (m_hWnd, GWL_WNDPROC, (DWORD) pwindowInfo->m_oldWindowProc);
  1154. delete pwindowInfo;
  1155. windowMap.RemoveKey ((SHORT) ((DWORD)m_hWnd & 0xffff));
  1156. }
  1157. m_browseEdit.Detach ();
  1158. m_browse.Detach ();
  1159. m_cancelButton.Detach();
  1160. m_okButton.Detach ();
  1161. m_UserName.Detach();
  1162. m_Password.Detach();
  1163. m_Authority.Detach();
  1164. m_Locale.Detach();
  1165. m_tree1.Detach();
  1166. m_sysPropCheck.Detach();
  1167. m_impersonateCheck.Detach();
  1168. m_PassthroughOnlyCheck.Detach();
  1169. m_messageEdit.Detach();
  1170. m_RefreshButton.Detach();
  1171. m_PwdAsNull.Detach();
  1172. m_PwdAsBlank.Detach();
  1173. CDialog :: OnNcDestroy ();
  1174. }
  1175. void CConnectionDialog::OnOK()
  1176. {
  1177. // TODO: Add extra validation here
  1178. GenerateOutMap (m_tree1.GetRootItem ());
  1179. GenerateOutString (m_tree1.GetRootItem ());
  1180. //Copy back new Username and Password
  1181. lpszUserName[0] = 0;
  1182. lpszPassword[0] = 0;
  1183. m_UserName.GetWindowText(lpszUserName, MAX_USER_NAME_LENGTH);
  1184. m_Password.GetWindowText(lpszPassword, MAX_PASSWORD_LENGTH);
  1185. //Copy Authority & Locale
  1186. if (lpszAuthority)
  1187. delete lpszAuthority;
  1188. *lpszAuthorityOut = NULL;
  1189. int AuthLen = m_Authority.GetWindowTextLength();
  1190. if (AuthLen)
  1191. {
  1192. *lpszAuthorityOut = new char [AuthLen + 1];
  1193. (*lpszAuthorityOut)[0] = 0;
  1194. m_Authority.GetWindowText(*lpszAuthorityOut, AuthLen + 1);
  1195. (*lpszAuthorityOut)[AuthLen] = 0;
  1196. }
  1197. if (lpszLocale)
  1198. delete lpszLocale;
  1199. *lpszLocaleOut = NULL;
  1200. int LocaleLen = m_Locale.GetWindowTextLength();
  1201. if (LocaleLen)
  1202. {
  1203. *lpszLocaleOut = new char [LocaleLen + 1];
  1204. (*lpszLocaleOut)[0] = 0;
  1205. m_Locale.GetWindowText(*lpszLocaleOut, LocaleLen + 1);
  1206. (*lpszLocaleOut)[LocaleLen] = 0;
  1207. }
  1208. HTREEITEM hTreeItem = m_tree1.GetRootItem();
  1209. CleanUpTreeCtrl(hTreeItem);
  1210. CDialog::OnOK();
  1211. }
  1212. void CConnectionDialog :: CleanUpTreeCtrl(HTREEITEM& hTreeItem)
  1213. {
  1214. if (pCurrentSelectionList)
  1215. {
  1216. ISAMTreeItemData* theNext = NULL;
  1217. do
  1218. {
  1219. theNext = pCurrentSelectionList->pNext;
  1220. delete pCurrentSelectionList;
  1221. pCurrentSelectionList = theNext;
  1222. } while (pCurrentSelectionList);
  1223. }
  1224. pCurrentSelectionList = NULL;
  1225. pCurrentItem = NULL;
  1226. }
  1227. void CConnectionDialog::OnButtonSysProp()
  1228. {
  1229. //Clicked on the System Properties checkbox
  1230. *fSystemProperties = m_sysPropCheck.GetCheck() ? TRUE : FALSE;
  1231. }
  1232. void CConnectionDialog::OnButtonInterpretEmpty()
  1233. {
  1234. //Clicked on one of the Interpret empty password as radio buttons
  1235. *fIntpretEmptPwdAsBlank = m_PwdAsBlank.GetCheck() ? TRUE : FALSE;
  1236. ConnectionParameterChange();
  1237. }
  1238. void CConnectionDialog::OnButtonImpersonation()
  1239. {
  1240. //Clicked on the Impersonation checkbox
  1241. *fImpersonation = m_impersonateCheck.GetCheck() ? TRUE : FALSE;
  1242. ConnectionParameterChange();
  1243. }
  1244. void CConnectionDialog::OnButtonPassthroughOnly()
  1245. {
  1246. //Clicked on the Passthrough only checkbox
  1247. *fPassthroughOnly = m_PassthroughOnlyCheck.GetCheck() ? TRUE : FALSE;
  1248. }
  1249. void CConnectionDialog::OnButtonBrowse()
  1250. {
  1251. // TODO: Add your control notification handler code here
  1252. m_browse.EnableWindow(FALSE);
  1253. BeginWaitCursor();
  1254. //Show dialog box
  1255. CBrowseDialog d;
  1256. int result = d.DoModal();
  1257. m_browse.EnableWindow(TRUE);
  1258. EndWaitCursor();
  1259. //abort if OK pushbutton was not pressed
  1260. if (result != IDOK)
  1261. return;
  1262. m_browseEdit.SetWindowText( d.GetServerName() );
  1263. m_browseEdit.SetModify(FALSE);
  1264. //update tree
  1265. RefreshTree();
  1266. }
  1267. void CConnectionDialog::OnCancel()
  1268. {
  1269. // TODO: Add extra cleanup here
  1270. HTREEITEM hTreeItem = m_tree1.GetRootItem();
  1271. CleanUpTreeCtrl(hTreeItem);
  1272. CDialog::OnCancel();
  1273. }
  1274. BOOL GetWbemDirectory(_bstr_t& wbemDir)
  1275. {
  1276. HKEY keyHandle = (HKEY)1;
  1277. TCHAR buff [1001];
  1278. DWORD sizebuff = 1000;
  1279. long fStatus = 0;
  1280. _bstr_t location("Software\\ODBC\\ODBCINST.INI\\WBEM ODBC Driver");
  1281. buff[0] = 0;
  1282. fStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  1283. (LPCTSTR)location, 0, KEY_READ, &keyHandle);
  1284. if (fStatus == ERROR_SUCCESS)
  1285. {
  1286. DWORD typeValue;
  1287. _bstr_t subkey("Help");
  1288. fStatus = RegQueryValueEx(keyHandle, (LPCTSTR)subkey, NULL,
  1289. &typeValue, (LPBYTE)buff, &sizebuff);
  1290. if (fStatus == ERROR_SUCCESS)
  1291. {
  1292. wbemDir = buff;
  1293. return TRUE;
  1294. }
  1295. }
  1296. return FALSE;
  1297. }
  1298. void CConnectionDialog::OnHelp()
  1299. {
  1300. _bstr_t sName = ">Main";
  1301. //Get the WBEM directory
  1302. _bstr_t wbemDir;
  1303. if ( !GetWbemDirectory(wbemDir) )
  1304. return;
  1305. _bstr_t sPrefix = "mk:@MSITStore:" + wbemDir + "\\WBEMDR32.CHM";
  1306. _bstr_t sIndex = sPrefix + "::" + "/_hmm_connecting_to_an_odbc_data_source.htm";
  1307. HtmlHelp
  1308. (
  1309. NULL, // HWND - this is where WM_TCARD messages will be sent
  1310. sName, // Use "Main" window name
  1311. HH_DISPLAY_TOPIC, // We want to display a topic please
  1312. (DWORD)(TCHAR*)sIndex // Full path of topic to display
  1313. );
  1314. }
  1315. void CConnectionDialog::OnDblclkTree1(NMHDR* pNMHDR, LRESULT* pResult)
  1316. {
  1317. // TODO: Add your control notification handler code here
  1318. fDoubleClicked = TRUE;
  1319. *pResult = 0;
  1320. }
  1321. void CConnectionDialog::ConnectionParameterChange()
  1322. {
  1323. m_tree1.EnableWindow(FALSE);
  1324. m_tree1.ShowWindow(SW_HIDE);
  1325. char buffer [128 + 1];
  1326. buffer[0] = 0;
  1327. LoadString(s_hModule, STR_PLEASE_REFRESH,
  1328. (char*)buffer, 128);
  1329. m_messageEdit.SetWindowText(buffer);
  1330. m_messageEdit.ShowWindow(SW_SHOWNA);
  1331. LoadString(s_hModule, STR_CONNECT, (char*)buffer, 128);
  1332. m_RefreshButton.SetWindowText(buffer);
  1333. m_RefreshButton.EnableWindow(TRUE);
  1334. m_okButton.EnableWindow(FALSE);
  1335. }
  1336. void CConnectionDialog::OnLocaleChange()
  1337. {
  1338. ConnectionParameterChange();
  1339. }
  1340. void CConnectionDialog::OnAuthorityChange()
  1341. {
  1342. ConnectionParameterChange();
  1343. }
  1344. void CConnectionDialog::OnUserNameChange()
  1345. {
  1346. ConnectionParameterChange();
  1347. }
  1348. void CConnectionDialog::OnPasswordChange()
  1349. {
  1350. ConnectionParameterChange();
  1351. }
  1352. void CConnectionDialog::OnServerChange()
  1353. {
  1354. ConnectionParameterChange();
  1355. }
  1356. void CConnectionDialog::OnButtonRefresh()
  1357. {
  1358. char buffer [129];
  1359. buffer[0] = 0;
  1360. m_tree1.EnableWindow(TRUE);
  1361. m_tree1.ShowWindow(SW_SHOWNA);
  1362. m_messageEdit.ShowWindow(SW_HIDE);
  1363. //Disable button and rename to CONNECT
  1364. LoadString(s_hModule, STR_CONNECT, (char*)buffer, 128);
  1365. m_RefreshButton.SetWindowText(buffer);
  1366. m_RefreshButton.EnableWindow(FALSE);
  1367. BOOL status = RefreshTree();
  1368. if (status)
  1369. {
  1370. //If refresh was successful
  1371. //enable button and rename to REFRESH
  1372. LoadString(s_hModule, STR_REFRESH, (char*)buffer, 128);
  1373. m_RefreshButton.SetWindowText(buffer);
  1374. m_RefreshButton.EnableWindow(TRUE);
  1375. }
  1376. //Give the tree control or message text focus
  1377. if ( m_tree1.IsWindowEnabled() )
  1378. m_tree1.SetFocus();
  1379. else
  1380. m_messageEdit.SetFocus();
  1381. }
  1382. void CConnectionDialog::OnKillfocusBrowseEdit()
  1383. {
  1384. /*
  1385. // TODO: Add your control notification handler code here
  1386. //Check if server, user name or password have been changed
  1387. //If so, refresh tree
  1388. if ( m_browseEdit.GetModify() || m_UserName.GetModify() || m_Password.GetModify() )
  1389. {
  1390. //reset flags
  1391. m_browseEdit.SetModify(FALSE);
  1392. m_UserName.SetModify(FALSE);
  1393. m_Password.SetModify(FALSE);
  1394. //refresh tree view
  1395. RefreshTree();
  1396. }
  1397. */
  1398. }
  1399. BOOL CConnectionDialog::RefreshTree()
  1400. {
  1401. ODBCTRACE ("\nWBEM ODBC Driver : CConnectionDialog::RefreshTree\n");
  1402. BOOL status = FALSE;
  1403. //Update tree view with namespaces associated with new server
  1404. HTREEITEM hTreeItem = m_tree1.GetRootItem();
  1405. CleanUpTreeCtrl(hTreeItem);
  1406. m_tree1.DeleteAllItems();
  1407. cSelectedCels = 0;
  1408. //Refresh Window
  1409. UpdateWindow();
  1410. lpszServer[0] = 0;
  1411. lpszUserName[0] = 0;
  1412. lpszPassword[0] = 0;
  1413. m_browseEdit.GetWindowText(lpszServer, MAX_SERVER_NAME_LENGTH);
  1414. m_UserName.GetWindowText(lpszUserName, MAX_USER_NAME_LENGTH);
  1415. m_Password.GetWindowText(lpszPassword, MAX_PASSWORD_LENGTH);
  1416. //Copy Authority & Locale
  1417. if (lpszAuthority)
  1418. delete lpszAuthority;
  1419. lpszAuthority = NULL;
  1420. int AuthLen = m_Authority.GetWindowTextLength();
  1421. if (AuthLen)
  1422. {
  1423. lpszAuthority = new char [AuthLen + 1];
  1424. lpszAuthority[0] = 0;
  1425. m_Authority.GetWindowText(lpszAuthority, AuthLen + 1);
  1426. lpszAuthority[AuthLen] = 0;
  1427. ODBCTRACE(_T("\nWBEM ODBC Driver : CConnectionDialog::RefreshTree\n"));
  1428. ODBCTRACE(_T(" Authority :"));
  1429. ODBCTRACE(_T(lpszAuthority));
  1430. ODBCTRACE(_T("\n"));
  1431. }
  1432. if (lpszLocale)
  1433. delete lpszLocale;
  1434. lpszLocale = NULL;
  1435. int LocaleLen = m_Locale.GetWindowTextLength();
  1436. if (LocaleLen)
  1437. {
  1438. lpszLocale = new char [LocaleLen + 1];
  1439. lpszLocale[0] = 0;
  1440. m_Locale.GetWindowText(lpszLocale, LocaleLen + 1);
  1441. lpszLocale[LocaleLen] = 0;
  1442. }
  1443. //Update impersonation if applicable
  1444. BOOL fImpersonateStatusOK = TRUE;
  1445. if (*fImpersonation)
  1446. {
  1447. ODBCTRACE ("\nWBEM ODBC Driver : Impersonation checkbox ON\n");
  1448. delete impersonateMgr;
  1449. impersonateMgr = NULL;
  1450. //Now check if impersonation is necessary
  1451. //only if connecting locally
  1452. if (IsLocalServer(lpszServer))
  1453. {
  1454. impersonateMgr = new ImpersonationManager(lpszUserName, lpszPassword, lpszAuthority);
  1455. //Check if impersonation request has worked
  1456. if (! impersonateMgr->CanWeImpersonate() )
  1457. {
  1458. ODBCTRACE ("\nWBEM ODBC Driver : We cannot impersonate\n");
  1459. fImpersonateStatusOK = FALSE;
  1460. }
  1461. else
  1462. {
  1463. ODBCTRACE ("\nWBEM ODBC Driver : We can impersonate\n");
  1464. //Do the actual impersonation so cloaking will work
  1465. if ( ! impersonateMgr->ImpersonatingNow() )
  1466. impersonateMgr->Impersonate("CConnectionDialog");
  1467. }
  1468. }
  1469. else
  1470. {
  1471. ODBCTRACE("\nWBEM ODBC Driver : Server not detected as local, not impersonating\n");
  1472. }
  1473. }
  1474. else
  1475. {
  1476. ODBCTRACE ("\nWBEM ODBC Driver : Impersonation checkbox OFF\n");
  1477. }
  1478. BeginWaitCursor();
  1479. //Disable OK pushbutton when updating
  1480. m_okButton.EnableWindow(FALSE);
  1481. //Check if you can connect using specified authentication information
  1482. char* lpRootNamespace = "root";
  1483. DWORD dwAuthLevel = 0;
  1484. DWORD dwImpLevel = 0;
  1485. COAUTHIDENTITY* pAuthIdent = NULL;
  1486. IWbemServicesPtr pGateway = NULL;
  1487. ISAMGetGatewayServer (pGateway,
  1488. lpszServer ? (LPUSTR)lpszServer : NULL, //server
  1489. // m_loginMethod,
  1490. (LPUSTR)lpRootNamespace,
  1491. lpszUserName ? (LPUSTR)lpszUserName : NULL, // username
  1492. lpszPassword ? (LPUSTR)lpszPassword : NULL, // password
  1493. (LPUSTR)lpszLocale, //locale
  1494. (LPUSTR)lpszAuthority,//authority
  1495. dwAuthLevel,
  1496. dwImpLevel,
  1497. *fIntpretEmptPwdAsBlank,
  1498. &pAuthIdent
  1499. );
  1500. if ( pAuthIdent )
  1501. {
  1502. WbemFreeAuthIdentity( pAuthIdent );
  1503. pAuthIdent = NULL;
  1504. }
  1505. if (fImpersonateStatusOK && (pGateway != NULL))
  1506. {
  1507. ODBCTRACE ("\nWBEM ODBC Driver : fImpersonateStatusOK && pGateway\n");
  1508. BOOL fIsLocalConnection = IsLocalServer((LPSTR) lpszServer);
  1509. //cloaking
  1510. if ( fIsLocalConnection && IsW2KOrMore() )
  1511. {
  1512. WbemSetDynamicCloaking(pGateway, dwAuthLevel, dwImpLevel);
  1513. }
  1514. status = TRUE;
  1515. HTREEITEM hDummy;
  1516. ISAMBuildTree (TVI_ROOT, "root", /*"root\\default",*/
  1517. m_tree1, *this,
  1518. lpszServer ? lpszServer : NULL, //server
  1519. // m_loginMethod,
  1520. lpszUserName ? lpszUserName : NULL, // username
  1521. lpszPassword ? lpszPassword : NULL, // password
  1522. *fIntpretEmptPwdAsBlank,
  1523. lpszLocale,
  1524. lpszAuthority,
  1525. TRUE, FALSE, hDummy);
  1526. //finished impersonating
  1527. // if ( (*fImpersonation) && (impersonateMgr) )
  1528. // impersonateMgr->RevertToYourself("ConnectionDialog");
  1529. }
  1530. else
  1531. {
  1532. ODBCTRACE ("\nWBEM ODBC Driver : Failed Connection\n");
  1533. status = FALSE;
  1534. m_tree1.EnableWindow(FALSE);
  1535. m_tree1.ShowWindow(SW_HIDE);
  1536. char buffer [128 + 1];
  1537. buffer[0] = 0;
  1538. LoadString(s_hModule, STR_FAILED_WBEM_CONN,
  1539. (char*)buffer, 128);
  1540. m_messageEdit.SetWindowText(buffer);
  1541. m_messageEdit.ShowWindow(SW_SHOWNA);
  1542. }
  1543. EndWaitCursor();
  1544. if (status)
  1545. ODBCTRACE ("\nWBEM ODBC Driver : CConnectionDialog::RefreshTree returns TRUE\n");
  1546. else
  1547. ODBCTRACE ("\nWBEM ODBC Driver : CConnectionDialog::RefreshTree returns FALSE\n");
  1548. return status;
  1549. }