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.

298 lines
8.3 KiB

  1. // ChooseIPDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "resource.h"
  5. #include "KeyObjs.h"
  6. #include "CmnKey.h"
  7. #include "W3Key.h"
  8. #include "W3Serv.h"
  9. #include "iiscnfg.h"
  10. #include "wrapmb.h"
  11. #include "mdkey.h"
  12. #include "mdserv.h"
  13. #include "IPDlg.h"
  14. #include "inetinfo.h"
  15. #include "inetcom.h"
  16. #include <lmapibuf.h>
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. extern BOOL g_fUsingMetabase;
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CChooseIPDlg dialog
  25. CChooseIPDlg::CChooseIPDlg(CWnd* pParent /*=NULL*/)
  26. : CDialog(CChooseIPDlg::IDD, pParent),
  27. m_pKey( NULL )
  28. {
  29. //{{AFX_DATA_INIT(CChooseIPDlg)
  30. //}}AFX_DATA_INIT
  31. }
  32. void CChooseIPDlg::DoDataExchange(CDataExchange* pDX)
  33. {
  34. CDialog::DoDataExchange(pDX);
  35. //{{AFX_DATA_MAP(CChooseIPDlg)
  36. DDX_Control(pDX, IDC_LIST_IPADDRESSES, m_ctrlList);
  37. //}}AFX_DATA_MAP
  38. }
  39. BEGIN_MESSAGE_MAP(CChooseIPDlg, CDialog)
  40. //{{AFX_MSG_MAP(CChooseIPDlg)
  41. //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CChooseIPDlg message handlers
  45. //----------------------------------------------------------------
  46. // override virtual oninitdialog
  47. BOOL CChooseIPDlg::OnInitDialog( )
  48. {
  49. // call the base oninit
  50. CDialog::OnInitDialog();
  51. // because we are querying the WWW server here, put up the wait cursor
  52. CWaitCursor waitcursor;
  53. // build the list of ip addresses
  54. if ( !BuildIPAddressList() )
  55. EndDialog( 3 );
  56. // if the item passed in through m_szIPAddress is in the list, select it
  57. LV_FINDINFO findInfo;
  58. findInfo.flags = LVFI_STRING; // search for a string
  59. findInfo.psz = m_szIPAddress; // string to search for
  60. findInfo.lParam = 0; // not used
  61. int iFound = m_ctrlList.FindItem( &findInfo );
  62. // if we found something, select it
  63. if ( iFound >= 0 )
  64. {
  65. m_ctrlList.SetItemState( iFound, LVIS_SELECTED, LVIS_SELECTED );
  66. }
  67. // return 0 to say we set the default item
  68. // return 1 to just select the default default item
  69. return 1;
  70. }
  71. //----------------------------------------------------------------
  72. // override the on OK routine
  73. void CChooseIPDlg::OnOK()
  74. {
  75. // get the selected item
  76. int iSelected = m_ctrlList.GetNextItem( -1, LVNI_SELECTED );
  77. // if nothing is selected, bail
  78. if ( iSelected < 0 )
  79. {
  80. CDialog::OnCancel();
  81. return;
  82. }
  83. // put the text of the selected item in the right place
  84. m_szIPAddress = m_ctrlList.GetItemText( iSelected, 0 );
  85. // call the inherited OnOK
  86. CDialog::OnOK();
  87. }
  88. //----------------------------------------------------------------
  89. // This routine queries the target server and gets the virtual servers
  90. BOOL CChooseIPDlg::BuildIPAddressList( void )
  91. {
  92. // if we are using the new metabase stuff, load it that way
  93. if ( g_fUsingMetabase )
  94. return BuildMetaIPAddressList();
  95. // for now - the downlevel admin is turned off because the infoadmn.lib disappeared on me
  96. return FALSE;
  97. /*
  98. // $(BASEDIR)\public\sdk\lib\*\infoadmn.lib \
  99. // $(BASEDIR)\public\sdk\lib\*\infocomm.lib \
  100. // start by getting the host machine. This is the object that
  101. // owns the service that owns this key.
  102. ASSERT( m_pKey->HGetTreeItem() );
  103. // get the parental service object
  104. CW3KeyService *pServ = (CW3KeyService*)m_pKey->PGetParent();
  105. ASSERT( pServ );
  106. // get the service parent, which is the machine
  107. CMachine *pMachine = (CMachine*)pServ->PGetParent();
  108. ASSERT( pMachine );
  109. if ( !pMachine ) return FALSE;
  110. LPINET_INFO_CONFIG_INFO pConfig = NULL;
  111. NET_API_STATUS apiStatus;
  112. DWORD cbNameBuff;
  113. PWCHAR szwName = NULL;
  114. // build the server name afresh instead of reusing the m_pszwMachineName
  115. // because that variable is only filled out for remote machines. Unlock the LSA
  116. // package which assumes you mean the local machine if you don't give it a name,
  117. // the inetinfo routine wants the name in either case.
  118. // create the unicode name that will be used to access the server
  119. // first allocate space for it
  120. cbNameBuff = sizeof(WCHAR) * (MAX_COMPUTERNAME_LENGTH + 1);
  121. szwName = (WCHAR*)GlobalAlloc( GPTR, cbNameBuff );
  122. // if the allocation didn't work, return FALSE
  123. if ( !szwName ) return FALSE;
  124. // if it is a remote machine, just copy over the m_pszwMachineName
  125. if ( !pMachine->FLocal() )
  126. {
  127. wcscpy(szwName, pServ->m_pszwMachineName);
  128. }
  129. else
  130. // a local machine, we need to fill in the correct name of the machine
  131. {
  132. char smallerbuff[MAX_COMPUTERNAME_LENGTH + 1];
  133. DWORD cbSmallerBuff = MAX_COMPUTERNAME_LENGTH + 1;
  134. // get the computer name
  135. GetComputerName( smallerbuff, &cbSmallerBuff );
  136. // unicodize the name into the buffer
  137. MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, smallerbuff, -1,
  138. szwName, cbNameBuff/sizeof(WCHAR) );
  139. }
  140. #ifdef _DEBUG
  141. CString szTest = szwName;
  142. #endif
  143. // get the config info of the target server
  144. apiStatus = InetInfoGetAdminInformation( szwName, INET_HTTP, &pConfig );
  145. // we don't need the wide name any more, so get rid of it
  146. GlobalFree( szwName );
  147. szwName = NULL;
  148. // check if an error ocurred
  149. if ( apiStatus || !pConfig || !pConfig->VirtualRoots )
  150. {
  151. AfxMessageBox( IDS_NO_HTTP );
  152. return FALSE;
  153. }
  154. // check that there are some virtual roots
  155. if ( !pConfig->VirtualRoots->cEntries )
  156. {
  157. NetApiBufferFree( pConfig );
  158. AfxMessageBox( IDS_NO_VIRT_ROOTS );
  159. return FALSE;
  160. }
  161. // loop through the itmes in the virutal root list
  162. for ( DWORD i = 0; i < pConfig->VirtualRoots->cEntries; i++ )
  163. {
  164. // make life easier and get a pointer to the virtual root entry
  165. LPINET_INFO_VIRTUAL_ROOT_ENTRY pVirtualRoot = &pConfig->VirtualRoots->aVirtRootEntry[i];
  166. // get the string
  167. CString szAddress = pVirtualRoot->pszAddress;
  168. // if there is an ip address there, add it to the list
  169. if ( !szAddress.IsEmpty() )
  170. m_ctrlList.InsertItem(0, szAddress);
  171. }
  172. // clean up the info pointer
  173. if ( pConfig )
  174. NetApiBufferFree( pConfig );
  175. // return success
  176. return TRUE;
  177. */
  178. }
  179. //----------------------------------------------------------------
  180. BOOL CChooseIPDlg::BuildMetaIPAddressList( void )
  181. {
  182. CString sz;
  183. // create the metabase wrapper object
  184. CWrapMetaBase mbWrap;
  185. if ( !mbWrap.FInit() )
  186. {
  187. ASSERT( FALSE );
  188. return FALSE; // can't get to metabase
  189. }
  190. // scan the available virtual servers and populate the drop down with
  191. // their secure port numbers
  192. for ( DWORD i = 1; TRUE; i++ )
  193. {
  194. // build the object name
  195. sz.Format( "%s%d", MD_W3BASE, i );
  196. // attempt to open the object in the metabase
  197. if ( !mbWrap.Open( sz, METADATA_PERMISSION_READ ) )
  198. break; // can't open - leave the loop
  199. // load the string representing the bindings
  200. DWORD cbData;
  201. PVOID pData;
  202. pData = mbWrap.GetData( "", MD_SECURE_BINDINGS, IIS_MD_UT_SERVER, MULTISZ_METADATA, &cbData );
  203. if ( pData )
  204. {
  205. PTCHAR pBinding = (PTCHAR)pData;
  206. LV_FINDINFO findinfo;
  207. findinfo.flags = LVFI_STRING;
  208. findinfo.lParam = 0;
  209. // walk the bindings in the list
  210. while ( TRUE )
  211. {
  212. sz = (PCHAR)pBinding;
  213. if ( sz.IsEmpty() )
  214. break;
  215. // get the IP address
  216. sz = sz.Left( sz.Find(':') );
  217. if ( !sz.IsEmpty() )
  218. {
  219. // add the string to the list
  220. // but only if it isn't already there
  221. findinfo.psz = sz;
  222. if ( m_ctrlList.FindItem( &findinfo ) < 0 )
  223. m_ctrlList.InsertItem(0, sz);
  224. }
  225. // advance the binding pointer
  226. pBinding += strlen(pBinding)+1;
  227. }
  228. // free the buffer
  229. mbWrap.FreeWrapData( pData );
  230. }
  231. // close the object
  232. mbWrap.Close();
  233. }
  234. // if nothing is in the IP box, tell the user
  235. if ( m_ctrlList.GetItemCount() == 0 )
  236. AfxMessageBox( IDS_NO_SECURE_BINDINGS );
  237. return TRUE;
  238. }