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.

599 lines
16 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1995 **/
  4. /**********************************************************************/
  5. /*
  6. dlg1.cxx
  7. WNetConnectionDialog1* and WNetDisconnectDialog1* source
  8. FILE HISTORY:
  9. BruceFo 19-May-95 Created
  10. */
  11. #define INCL_NETCONS
  12. #define INCL_NETCONFIG
  13. #define INCL_NETSERVICE
  14. #define INCL_NETLIB
  15. #define INCL_WINDOWS
  16. #define INCL_NETERRORS
  17. #define INCL_DOSERRORS
  18. #include <lmui.hxx>
  19. #define INCL_BLT_CONTROL
  20. #define INCL_BLT_CLIENT
  21. #define INCL_BLT_MSGPOPUP
  22. #include <blt.hxx>
  23. #include <mprconn.h>
  24. //
  25. // Export these using C-style syntax
  26. //
  27. extern "C"
  28. {
  29. #include <mpr.h>
  30. }
  31. #include <shlobj.h>
  32. #include <shlobjp.h> // netplwiz.h stuff
  33. //
  34. // Null strings are quite often taken to be either a NULL pointer or a zero
  35. //
  36. #define IS_EMPTY_STRING(pch) ( !(pch) || !*(pch) )
  37. #define MAX_NET_PATH MAX_PATH
  38. DWORD
  39. MPRUI_WNetConnectionDialog1Help(
  40. LPCONNECTDLGSTRUCTW lpConnDlgStruct
  41. );
  42. DWORD
  43. MPRUI_WNetDisconnectDialog1Help(
  44. HWND hwndOwner,
  45. LPWSTR lpLocalName,
  46. LPWSTR lpRemoteName,
  47. DWORD dwFlags
  48. );
  49. /*******************************************************************
  50. NAME: MPRUI_WNetDisconnectDialog1W
  51. SYNOPSIS:
  52. ENTRY: lpDiscDlgStruct -
  53. EXIT:
  54. RETURNS:
  55. NOTES:
  56. HISTORY:
  57. BruceFo 19-May-1995 Created
  58. ********************************************************************/
  59. DWORD
  60. MPRUI_WNetDisconnectDialog1W(
  61. LPDISCDLGSTRUCTW lpDiscDlgStruct
  62. )
  63. {
  64. DWORD status = WN_SUCCESS;
  65. __try
  66. {
  67. if (NULL == lpDiscDlgStruct)
  68. {
  69. status = WN_BAD_POINTER;
  70. }
  71. else if ((lpDiscDlgStruct->cbStructure < sizeof(DISCDLGSTRUCTW))
  72. || ((lpDiscDlgStruct->lpLocalName == NULL) && (lpDiscDlgStruct->lpRemoteName == NULL))
  73. )
  74. {
  75. status = ERROR_INVALID_PARAMETER;
  76. }
  77. else
  78. {
  79. status = MPRUI_WNetDisconnectDialog1Help(
  80. lpDiscDlgStruct->hwndOwner,
  81. lpDiscDlgStruct->lpLocalName,
  82. lpDiscDlgStruct->lpRemoteName,
  83. lpDiscDlgStruct->dwFlags);
  84. }
  85. }
  86. __except(EXCEPTION_EXECUTE_HANDLER)
  87. {
  88. status = WN_BAD_POINTER;
  89. }
  90. if (status != WN_SUCCESS)
  91. {
  92. SetLastError(status);
  93. }
  94. return status;
  95. }
  96. /*******************************************************************
  97. NAME: MPRUI_WNetDisconnectDialog1A
  98. SYNOPSIS:
  99. ENTRY: lpDiscDlgStruct -
  100. EXIT:
  101. RETURNS:
  102. NOTES:
  103. HISTORY:
  104. BruceFo 19-May-1995 Created
  105. ********************************************************************/
  106. DWORD
  107. MPRUI_WNetDisconnectDialog1A(
  108. LPDISCDLGSTRUCTA lpDiscDlgStruct
  109. )
  110. {
  111. APIERR err;
  112. __try
  113. {
  114. if (NULL == lpDiscDlgStruct)
  115. {
  116. err = WN_BAD_POINTER;
  117. }
  118. else if ((lpDiscDlgStruct->cbStructure < sizeof(DISCDLGSTRUCTA))
  119. || ((lpDiscDlgStruct->lpLocalName == NULL) && (lpDiscDlgStruct->lpRemoteName == NULL))
  120. )
  121. {
  122. err = ERROR_INVALID_PARAMETER;
  123. }
  124. else
  125. {
  126. DISCDLGSTRUCTW discDlgStructW;
  127. NLS_STR nlsLocalName;
  128. NLS_STR nlsRemoteName;
  129. if ( (err = nlsRemoteName.MapCopyFrom(lpDiscDlgStruct->lpRemoteName))
  130. || (err = nlsLocalName.MapCopyFrom(lpDiscDlgStruct->lpLocalName))
  131. )
  132. {
  133. // do nothing
  134. }
  135. if ( 0 == err )
  136. {
  137. discDlgStructW.cbStructure = sizeof(DISCDLGSTRUCTW);
  138. discDlgStructW.hwndOwner = lpDiscDlgStruct->hwndOwner;
  139. discDlgStructW.lpLocalName = (LPWSTR)nlsLocalName.QueryPch();
  140. discDlgStructW.lpRemoteName = (LPWSTR)nlsRemoteName.QueryPch();
  141. discDlgStructW.dwFlags = lpDiscDlgStruct->dwFlags;
  142. err = MPRUI_WNetDisconnectDialog1W(&discDlgStructW);
  143. }
  144. }
  145. }
  146. __except(EXCEPTION_EXECUTE_HANDLER)
  147. {
  148. err = WN_BAD_POINTER;
  149. }
  150. return err;
  151. }
  152. /*******************************************************************
  153. NAME: MPRUI_WNetConnectionDialog1A
  154. SYNOPSIS:
  155. ENTRY: lpConnDlgStruct -
  156. EXIT:
  157. RETURNS:
  158. NOTES:
  159. HISTORY:
  160. BruceFo 19-May-1995 Created
  161. ********************************************************************/
  162. DWORD
  163. MPRUI_WNetConnectionDialog1A(
  164. LPCONNECTDLGSTRUCTA lpConnDlgStruct
  165. )
  166. {
  167. APIERR err = WN_SUCCESS;
  168. __try
  169. {
  170. if ((NULL == lpConnDlgStruct) || (NULL == lpConnDlgStruct->lpConnRes))
  171. {
  172. err = WN_BAD_POINTER;
  173. }
  174. else
  175. {
  176. if ((lpConnDlgStruct->dwFlags & CONNDLG_RO_PATH) &&
  177. ((lpConnDlgStruct->dwFlags & CONNDLG_USE_MRU)
  178. || (IS_EMPTY_STRING(lpConnDlgStruct->lpConnRes->lpRemoteName)))
  179. )
  180. {
  181. // A read only remote path has been requested with
  182. // a drop down MRU list or no remote path specified.
  183. // Neither of these options are valid.
  184. err = WN_BAD_VALUE;
  185. }
  186. else if ((lpConnDlgStruct->dwFlags & CONNDLG_PERSIST) &&
  187. (lpConnDlgStruct->dwFlags & CONNDLG_NOT_PERSIST))
  188. {
  189. // Caller has specified inconsistent values.
  190. err = WN_BAD_VALUE;
  191. }
  192. if (lpConnDlgStruct->lpConnRes->dwType != RESOURCETYPE_DISK)
  193. {
  194. // Only disk dialog is supported
  195. err = WN_BAD_DEV_TYPE;
  196. }
  197. }
  198. if (WN_SUCCESS == err)
  199. {
  200. NLS_STR nlsLocalName;
  201. NLS_STR nlsRemoteName;
  202. NLS_STR nlsComment;
  203. NLS_STR nlsProvider;
  204. if ( (err = nlsRemoteName.MapCopyFrom(lpConnDlgStruct->lpConnRes->lpRemoteName))
  205. || (err = nlsLocalName.MapCopyFrom(lpConnDlgStruct->lpConnRes->lpLocalName))
  206. || (err = nlsComment.MapCopyFrom(lpConnDlgStruct->lpConnRes->lpComment))
  207. || (err = nlsProvider.MapCopyFrom(lpConnDlgStruct->lpConnRes->lpProvider))
  208. )
  209. {
  210. // do nothing
  211. }
  212. if ( 0 == err )
  213. {
  214. NETRESOURCEW netResourceW;
  215. CONNECTDLGSTRUCTW connDlgStructW;
  216. connDlgStructW.cbStructure = sizeof(CONNECTDLGSTRUCTW);
  217. connDlgStructW.hwndOwner = lpConnDlgStruct->hwndOwner;
  218. connDlgStructW.lpConnRes = &netResourceW;
  219. connDlgStructW.dwFlags = lpConnDlgStruct->dwFlags;
  220. connDlgStructW.dwDevNum = lpConnDlgStruct->dwDevNum;
  221. netResourceW.dwScope = lpConnDlgStruct->lpConnRes->dwScope;
  222. netResourceW.dwType = lpConnDlgStruct->lpConnRes->dwType;
  223. netResourceW.dwDisplayType = lpConnDlgStruct->lpConnRes->dwDisplayType;
  224. netResourceW.dwUsage = lpConnDlgStruct->lpConnRes->dwUsage;
  225. netResourceW.lpLocalName = (LPWSTR)nlsLocalName.QueryPch();
  226. netResourceW.lpRemoteName = (LPWSTR)nlsRemoteName.QueryPch();
  227. netResourceW.lpComment = (LPWSTR)nlsComment.QueryPch();
  228. netResourceW.lpProvider = (LPWSTR)nlsProvider.QueryPch();
  229. err = MPRUI_WNetConnectionDialog1Help(&connDlgStructW);
  230. if (err == WN_SUCCESS)
  231. {
  232. // Now copy back the one thing that is an "out" paramter
  233. lpConnDlgStruct->dwDevNum = connDlgStructW.dwDevNum;
  234. }
  235. }
  236. }
  237. }
  238. __except(EXCEPTION_EXECUTE_HANDLER)
  239. {
  240. err = WN_BAD_POINTER;
  241. }
  242. return err;
  243. }
  244. /*******************************************************************
  245. NAME: MPRUI_WNetConnectionDialog1W
  246. SYNOPSIS:
  247. ENTRY: lpConnDlgStruct -
  248. EXIT:
  249. RETURNS:
  250. NOTES:
  251. HISTORY:
  252. BruceFo 19-May-1995 Created
  253. ********************************************************************/
  254. DWORD
  255. MPRUI_WNetConnectionDialog1W(
  256. LPCONNECTDLGSTRUCTW lpConnDlgStruct
  257. )
  258. {
  259. APIERR err = WN_SUCCESS;
  260. __try
  261. {
  262. if ((NULL == lpConnDlgStruct) || (NULL == lpConnDlgStruct->lpConnRes))
  263. {
  264. err = WN_BAD_POINTER;
  265. }
  266. else
  267. {
  268. if ((lpConnDlgStruct->dwFlags & CONNDLG_RO_PATH) &&
  269. ((lpConnDlgStruct->dwFlags & CONNDLG_USE_MRU)
  270. || (IS_EMPTY_STRING(lpConnDlgStruct->lpConnRes->lpRemoteName)))
  271. )
  272. {
  273. // A read only remote path has been requested with
  274. // a drop down MRU list or no remote path specified.
  275. // Neither of these options are valid.
  276. err = WN_BAD_VALUE;
  277. }
  278. else if ((lpConnDlgStruct->dwFlags & CONNDLG_PERSIST) &&
  279. (lpConnDlgStruct->dwFlags & CONNDLG_NOT_PERSIST))
  280. {
  281. // Caller has specified inconsistent values.
  282. err = WN_BAD_VALUE;
  283. }
  284. if (lpConnDlgStruct->lpConnRes->dwType != RESOURCETYPE_DISK)
  285. {
  286. // Only disk dialog is supported
  287. err = WN_BAD_DEV_TYPE;
  288. }
  289. }
  290. if (WN_SUCCESS == err)
  291. {
  292. err = MPRUI_WNetConnectionDialog1Help(lpConnDlgStruct);
  293. }
  294. }
  295. __except(EXCEPTION_EXECUTE_HANDLER)
  296. {
  297. err = WN_BAD_POINTER;
  298. }
  299. return err;
  300. }
  301. /*******************************************************************
  302. NAME: MPRUI_WNetConnectionDialog
  303. SYNOPSIS: Entrypoint for the MPRUI_WNetConnectionDialog API
  304. ENTRY: hwnd - Parent window handle suitable for hosting a dialog
  305. dwType - one of RESOURCETYPE_DISK or RESOURCETYPE_PRINT
  306. EXIT:
  307. RETURNS:
  308. NOTES:
  309. HISTORY:
  310. Johnl 22-Jan-1992 Commented, fixed
  311. beng 31-Mar-1992 Unicode mumble
  312. ********************************************************************/
  313. DWORD MPRUI_WNetConnectionDialog( HWND hwnd,
  314. DWORD dwType )
  315. {
  316. NETRESOURCE netResource;
  317. CONNECTDLGSTRUCT connDlgStruct;
  318. if (dwType != RESOURCETYPE_DISK)
  319. {
  320. // Only disk dialog is supported
  321. return WN_BAD_DEV_TYPE;
  322. }
  323. connDlgStruct.hwndOwner = hwnd;
  324. connDlgStruct.lpConnRes = &netResource;
  325. connDlgStruct.dwFlags = CONNDLG_USE_MRU;
  326. ::memsetf((LPSTR)&netResource,0,sizeof(netResource));
  327. netResource.dwType = dwType;
  328. return MPRUI_WNetConnectionDialog1Help(&connDlgStruct);
  329. }
  330. /*******************************************************************
  331. NAME: MPRUI_WNetConnectionDialog1Help
  332. SYNOPSIS: Helper function for MPRUI_WNetConnectionDialog1{A,W}.
  333. Assumes parameters have been validated.
  334. ENTRY: lpConnDlgStruct -
  335. EXIT:
  336. RETURNS:
  337. NOTES:
  338. HISTORY:
  339. BruceFo 19-May-1995 Created
  340. ********************************************************************/
  341. DWORD
  342. MPRUI_WNetConnectionDialog1Help(
  343. LPCONNECTDLGSTRUCTW lpConnDlgStruct
  344. )
  345. {
  346. APIERR err;
  347. HMODULE hModule;
  348. ASSERT(lpConnDlgStruct->lpConnRes->dwType == RESOURCETYPE_DISK);
  349. if ((lpConnDlgStruct->dwFlags &
  350. (CONNDLG_RO_PATH | CONNDLG_USE_MRU)) == 0)
  351. {
  352. // If read-only or drop down MRU list not explicitly
  353. // requested, then pick a default based upon whether
  354. // or not the remote name was specified.
  355. lpConnDlgStruct->dwFlags |=
  356. (IS_EMPTY_STRING(lpConnDlgStruct->lpConnRes->lpRemoteName))
  357. ? CONNDLG_USE_MRU : CONNDLG_RO_PATH;
  358. }
  359. //
  360. // Create the wizard. The third parameter indicates whether or not
  361. // the user specified a read-only path in lpConnDlgStruct.
  362. //
  363. err = NetPlacesWizardDoModal(lpConnDlgStruct,
  364. NETPLACES_WIZARD_MAPDRIVE,
  365. lpConnDlgStruct->dwFlags & CONNDLG_RO_PATH);
  366. //
  367. // this should never happen, but just in case, we
  368. // make sure we never pass internal errors out
  369. //
  370. if ( err >= IDS_UI_BASE )
  371. {
  372. err = ERROR_UNEXP_NET_ERR ;
  373. }
  374. return err;
  375. }
  376. /*******************************************************************
  377. NAME: MPRUI_WNetDisconnectDialog1Help
  378. SYNOPSIS:
  379. ENTRY: lpDiscDlgStruct -
  380. EXIT:
  381. RETURNS:
  382. NOTES:
  383. HISTORY:
  384. BruceFo 19-May-1995 Created
  385. ********************************************************************/
  386. DWORD
  387. MPRUI_WNetDisconnectDialog1Help(
  388. HWND hwndOwner,
  389. LPWSTR lpLocalName,
  390. LPWSTR lpRemoteName,
  391. DWORD dwFlags
  392. )
  393. {
  394. AUTO_CURSOR cursHourGlass ;
  395. OWNINGWND wndOwner( hwndOwner ) ;
  396. DWORD dwCancelFlags = ((dwFlags & DISC_UPDATE_PROFILE) != 0) ? CONNECT_UPDATE_PROFILE : 0;
  397. WCHAR* pszName = IS_EMPTY_STRING(lpLocalName) ? lpRemoteName : lpLocalName;
  398. DWORD status = WNetCancelConnection2(pszName, dwCancelFlags, FALSE);
  399. if (status != WN_SUCCESS)
  400. {
  401. // If the caller did not provide the remote name, go and get it.
  402. // This enables the best error message to be produced (assuming
  403. // that it is not the case that both the connection to the server
  404. // has gone down and the provider does not keep the remote name
  405. // locally).
  406. WCHAR szRemoteName[MAX_NET_PATH] ;
  407. ALIAS_STR nlsRemoteName(lpRemoteName ? lpRemoteName : L"");
  408. ALIAS_STR nlsLocalName(lpLocalName ? lpLocalName : L"");
  409. DWORD err = WN_SUCCESS;
  410. if (!IS_EMPTY_STRING(lpLocalName) &&
  411. IS_EMPTY_STRING(lpRemoteName)
  412. )
  413. {
  414. DWORD dwBufferSize = MAX_NET_PATH;
  415. err = WNetGetConnection(lpLocalName, szRemoteName, &dwBufferSize);
  416. if ( (err != WN_SUCCESS) && (err != WN_CONNECTION_CLOSED) )
  417. {
  418. // error!
  419. }
  420. else
  421. {
  422. nlsRemoteName = szRemoteName;
  423. }
  424. }
  425. if ( (err == WN_SUCCESS) || (err == WN_CONNECTION_CLOSED) )
  426. {
  427. if ( (status == WN_OPEN_FILES) ||
  428. (status == WN_DEVICE_IN_USE) )
  429. {
  430. if ((dwFlags & DISC_NO_FORCE ) == 0)
  431. {
  432. // There are open files on this connection - ask user whether
  433. // he REALLY wants to destroy it - then apply force.
  434. switch ( MsgPopup(
  435. wndOwner,
  436. IDS_OPENFILES_WITH_NAME_WARNING,
  437. MPSEV_WARNING,
  438. MP_YESNO,
  439. nlsLocalName,
  440. nlsRemoteName ))
  441. {
  442. case IDYES:
  443. status = WNetCancelConnection2(pszName, dwCancelFlags, TRUE);
  444. break ;
  445. case IDNO:
  446. status = WN_CANCEL;
  447. break ;
  448. }
  449. }
  450. }
  451. }
  452. }
  453. if ( (status != WN_SUCCESS) && (status != WN_CANCEL) )
  454. {
  455. MsgPopup( wndOwner, (MSGID) status );
  456. }
  457. return status;
  458. }