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.

197 lines
5.5 KiB

  1. /**************************************************************************
  2. Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  3. MODULE: PMNET.CPP
  4. PURPOSE: Source module for Passport Manager config tool, remote
  5. machine access
  6. FUNCTIONS:
  7. COMMENTS: Borrowed from Regedit
  8. **************************************************************************/
  9. #include "pmcfg.h"
  10. const DWORD s_PMAdminConnectHelpIDs[] =
  11. {
  12. IDC_REMOTENAME, IDH_PMADMIN_CONNECT,
  13. IDC_BROWSE, IDH_PMADMIN_CONNECT_BROWSE,
  14. 0, 0
  15. };
  16. VOID PASCAL PMAdmin_Connect_OnCommandBrowse(HWND hWnd);
  17. INT_PTR CALLBACK PMAdmin_ConnectDlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
  18. /*******************************************************************************
  19. *
  20. * PMAdmin_OnCommandConnect
  21. *
  22. * DESCRIPTION:
  23. *
  24. * PARAMETERS:
  25. *
  26. *******************************************************************************/
  27. BOOL PMAdmin_OnCommandConnect
  28. (
  29. HWND hWnd,
  30. LPTSTR lpszRemoteName
  31. )
  32. {
  33. TCHAR RemoteName[MAX_PATH];
  34. LPTSTR lpUnslashedRemoteName;
  35. TCHAR ComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  36. DWORD cbComputerName;
  37. // Pre-populate the remote name if we already have one
  38. lstrcpyn(RemoteName, lpszRemoteName, DIMENSION(RemoteName));
  39. //
  40. // Query the user for the name of the remote computer to connect to.
  41. //
  42. if (DialogBoxParam(g_hInst,
  43. MAKEINTRESOURCE(IDD_PMADMINCONNECT),
  44. hWnd,
  45. PMAdmin_ConnectDlgProc,
  46. (LPARAM) (LPTSTR) RemoteName) != IDOK)
  47. return FALSE;
  48. lpUnslashedRemoteName = (RemoteName[0] == TEXT('\\') &&
  49. RemoteName[1] == TEXT('\\')) ? &RemoteName[2] : &RemoteName[0];
  50. CharLower(lpUnslashedRemoteName);
  51. CharUpperBuff(lpUnslashedRemoteName, 1);
  52. //
  53. // Check if the user is trying to connect to the local computer and prevent
  54. // this.
  55. //
  56. cbComputerName = sizeof(ComputerName)/sizeof(TCHAR);
  57. if (GetComputerName(ComputerName, &cbComputerName))
  58. {
  59. if (lstrcmpi(lpUnslashedRemoteName, ComputerName) == 0)
  60. {
  61. ReportError(hWnd, IDS_CONNECTNOTLOCAL);
  62. }
  63. else
  64. {
  65. lstrcpy(lpszRemoteName, lpUnslashedRemoteName);
  66. }
  67. }
  68. return TRUE;
  69. }
  70. /*******************************************************************************
  71. *
  72. * PMAdmin_ConnectDlgProc
  73. *
  74. * DESCRIPTION:
  75. *
  76. * PARAMETERS:
  77. *
  78. *******************************************************************************/
  79. INT_PTR CALLBACK PMAdmin_ConnectDlgProc
  80. (
  81. HWND hWnd,
  82. UINT Message,
  83. WPARAM wParam,
  84. LPARAM lParam
  85. )
  86. {
  87. LPTSTR lpRemoteName;
  88. switch (Message)
  89. {
  90. case WM_INITDIALOG:
  91. SetWindowLongPtr(hWnd, DWLP_USER, (LONG_PTR) lParam);
  92. SendDlgItemMessage(hWnd, IDC_REMOTENAME, EM_SETLIMITTEXT, MAX_PATH, 0);
  93. SetDlgItemText(hWnd, IDC_REMOTENAME, (LPTSTR) lParam);
  94. break;
  95. case WM_COMMAND:
  96. switch (GET_WM_COMMAND_ID(wParam, lParam))
  97. {
  98. case IDC_BROWSE:
  99. PMAdmin_Connect_OnCommandBrowse(hWnd);
  100. break;
  101. case IDOK:
  102. lpRemoteName = (LPTSTR) GetWindowLongPtr(hWnd, DWLP_USER);
  103. GetDlgItemText(hWnd, IDC_REMOTENAME, lpRemoteName, MAX_PATH);
  104. // FALL THROUGH
  105. case IDCANCEL:
  106. EndDialog(hWnd, GET_WM_COMMAND_ID(wParam, lParam));
  107. break;
  108. }
  109. break;
  110. case WM_HELP:
  111. WinHelp( (HWND)((LPHELPINFO) lParam)->hItemHandle, g_szHelpFileName,
  112. HELP_WM_HELP, (ULONG_PTR) s_PMAdminConnectHelpIDs);
  113. break;
  114. case WM_CONTEXTMENU:
  115. WinHelp((HWND) wParam, g_szHelpFileName, HELP_CONTEXTMENU,
  116. (ULONG_PTR) s_PMAdminConnectHelpIDs);
  117. break;
  118. default:
  119. return FALSE;
  120. }
  121. return TRUE;
  122. }
  123. /*******************************************************************************
  124. *
  125. * PMAdmin_Connect_OnCommandBrowse
  126. *
  127. * DESCRIPTION:
  128. *
  129. * PARAMETERS:
  130. *
  131. *******************************************************************************/
  132. VOID PASCAL PMAdmin_Connect_OnCommandBrowse
  133. (
  134. HWND hWnd
  135. )
  136. {
  137. BROWSEINFO BrowseInfo;
  138. LPITEMIDLIST pidlComputer;
  139. TCHAR RemoteName[MAX_PATH];
  140. TCHAR szTitle[MAX_TITLE];
  141. LPMALLOC lpMalloc; // Pointer to shell allocator interface
  142. BrowseInfo.hwndOwner = hWnd;
  143. BrowseInfo.pidlRoot = (LPITEMIDLIST) MAKEINTRESOURCE(CSIDL_NETWORK);
  144. BrowseInfo.pszDisplayName = RemoteName;
  145. LoadString(g_hInst, IDS_COMPUTERBROWSETITLE, szTitle, DIMENSION(szTitle));
  146. BrowseInfo.lpszTitle = szTitle;
  147. BrowseInfo.ulFlags = BIF_BROWSEFORCOMPUTER;
  148. BrowseInfo.lpfn = NULL;
  149. if ((pidlComputer = SHBrowseForFolder(&BrowseInfo)) != NULL)
  150. {
  151. // Free the pidl allocated by the BrowserForFolder call
  152. if ((NOERROR == SHGetMalloc(&lpMalloc)) && (NULL != lpMalloc))
  153. {
  154. lpMalloc->Free(pidlComputer);
  155. lpMalloc->Release();
  156. }
  157. SetDlgItemText(hWnd, IDC_REMOTENAME, RemoteName);
  158. EnableWindow(GetDlgItem(hWnd, IDOK), TRUE);
  159. }
  160. }