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.

1404 lines
40 KiB

  1. // sfm.cpp : SFM shares, sessions and open resources
  2. /*
  3. History:
  4. 1/24/97 JonN
  5. I have looked over the enumeration API usage in SFMMGR.CPL:
  6. The Users dialog uses AfpAdminSessionEnum for the upper LB and
  7. AfpAdminConnectionEnum for the lower LB.
  8. The Volumesdialog uses AfpAdminVolumeEnum for the upper LB and
  9. AfpAdminConnectionEnum for the lower LB.
  10. The Files dialog uses AfpAdminFileEnum for single LB.
  11. 8/20/97 EricDav
  12. Added code to support the SFM property sheet. The following
  13. functions were added:
  14. DisplaySfmProperties()
  15. CleanupSfmProperties();
  16. UserHasAccess();
  17. SetSfmPropSheet();
  18. The SFM prop sheet is a modeless prop sheet and is global for
  19. a machine running SFM.
  20. 4/16/98 EricDav
  21. Added code to properly check if SFM is installed and running.
  22. Able to start the service as necessary.
  23. */
  24. #include "stdafx.h"
  25. #include "cmponent.h"
  26. #include "safetemp.h"
  27. #include "FileSvc.h"
  28. #include "DynamLnk.h" // DynamicDLL
  29. #include "ShrPgSFM.h" // Share Properties Page
  30. #include "compdata.h"
  31. #include "progress.h" // service control progress dialog
  32. #include "dataobj.h"
  33. #include "sfm.h"
  34. #include "sfmutil.h" // Support for the SFM config prop sheet
  35. #define DONT_WANT_SHELLDEBUG
  36. #include "shlobjp.h" // LPITEMIDLIST
  37. #include "wraps.h" // Wrap_ILCreateFromPath
  38. #include "macros.h"
  39. USE_HANDLE_MACROS("FILEMGMT(sfm.cpp)")
  40. #ifdef _DEBUG
  41. #define new DEBUG_NEW
  42. #undef THIS_FILE
  43. static char THIS_FILE[] = __FILE__;
  44. #endif
  45. DynamicDLL g_SfmDLL( _T("SFMAPI.DLL"), g_apchFunctionNames );
  46. SfmFileServiceProvider::SfmFileServiceProvider( CFileMgmtComponentData* pFileMgmtData )
  47. : m_ulSFMServerConnection( NULL ),
  48. m_pSfmPropSheet(NULL),
  49. // not subject to localization
  50. FileServiceProvider( pFileMgmtData )
  51. {
  52. VERIFY( m_strTransportSFM.LoadString( IDS_TRANSPORT_SFM ) );
  53. }
  54. SfmFileServiceProvider::~SfmFileServiceProvider()
  55. {
  56. CleanupSfmProperties();
  57. SFMDisconnect();
  58. }
  59. typedef DWORD (*CONNECTPROC) (LPWSTR,PAFP_SERVER_HANDLE);
  60. typedef DWORD (*DISCONNECTPROC) (AFP_SERVER_HANDLE);
  61. BOOL SfmFileServiceProvider::SFMConnect(LPCWSTR pwchServerName, BOOL fDisplayError)
  62. {
  63. if (NULL != m_ulSFMServerConnection)
  64. {
  65. if (NULL == pwchServerName)
  66. {
  67. if (0 == m_ulSFMServerConnectionMachine.GetLength() )
  68. return TRUE; // already connected to local machine
  69. }
  70. else
  71. {
  72. if (0 == lstrcmpi(m_ulSFMServerConnectionMachine, pwchServerName))
  73. return TRUE; // already connected to this machine
  74. }
  75. SFMDisconnect();
  76. ASSERT (NULL == m_ulSFMServerConnection);
  77. }
  78. if ( !g_SfmDLL.LoadFunctionPointers() )
  79. return S_OK;
  80. DWORD retval = ((CONNECTPROC)g_SfmDLL[AFP_CONNECT])(
  81. const_cast<LPWSTR>(pwchServerName),
  82. &m_ulSFMServerConnection );
  83. if ( 0 != retval )
  84. {
  85. ASSERT( NULL == m_ulSFMServerConnection );
  86. m_ulSFMServerConnection = NULL;
  87. m_ulSFMServerConnectionMachine = _T("");
  88. if (fDisplayError)
  89. {
  90. (void) DoErrMsgBox(GetActiveWindow(), MB_OK | MB_ICONSTOP, retval, IDS_POPUP_SFM_CONNECT, pwchServerName );
  91. }
  92. return FALSE;
  93. } else
  94. {
  95. m_ulSFMServerConnectionMachine =
  96. (pwchServerName ? pwchServerName : _T(""));
  97. }
  98. return TRUE;
  99. }
  100. void SfmFileServiceProvider::SFMDisconnect()
  101. {
  102. if (NULL == m_ulSFMServerConnection)
  103. return;
  104. if ( !g_SfmDLL.LoadFunctionPointers() )
  105. return;
  106. ((DISCONNECTPROC)g_SfmDLL[AFP_DISCONNECT])(
  107. m_ulSFMServerConnection );
  108. m_ulSFMServerConnection = NULL;
  109. }
  110. /*
  111. DWORD
  112. AfpAdminVolumeEnum(
  113. IN AFP_SERVER_HANDLE hAfpServer,
  114. OUT LPBYTE * lpbBuffer,
  115. IN DWORD dwPrefMaxLen,
  116. OUT LPDWORD lpdwEntriesRead,
  117. OUT LPDWORD lpdwTotalEntries,
  118. IN LPDWORD lpdwResumeHandle
  119. );
  120. */
  121. typedef DWORD (*VOLUMEENUMPROC) (AFP_SERVER_HANDLE,LPBYTE*,DWORD,LPDWORD,LPDWORD,LPDWORD);
  122. HRESULT SfmFileServiceProvider::PopulateShares(
  123. IResultData* pResultData,
  124. CFileMgmtCookie* pcookie)
  125. {
  126. TEST_NONNULL_PTR_PARAM(pcookie);
  127. if ( !g_SfmDLL.LoadFunctionPointers() )
  128. return S_OK;
  129. if ( !SFMConnect(pcookie->QueryTargetServer()) )
  130. return S_OK;
  131. AFP_VOLUME_INFO* pvolumeinfo = NULL;
  132. DWORD dwEntriesRead = 0;
  133. DWORD dwTotalEntries = 0;
  134. DWORD hEnumHandle = 0;
  135. HRESULT hr = S_OK;
  136. NET_API_STATUS retval = NERR_Success;
  137. do {
  138. retval = ((VOLUMEENUMPROC)g_SfmDLL[AFP_VOLUME_ENUM])(
  139. m_ulSFMServerConnection,
  140. (PBYTE*)&pvolumeinfo,
  141. (DWORD)-1L,
  142. &dwEntriesRead,
  143. &dwTotalEntries,
  144. &hEnumHandle );
  145. if (NERR_Success == retval)
  146. {
  147. hr = AddSFMShareItems( pResultData, pcookie, pvolumeinfo, dwEntriesRead );
  148. pvolumeinfo = NULL;
  149. break;
  150. } else if (ERROR_MORE_DATA == retval) {
  151. ASSERT( NULL != hEnumHandle );
  152. hr = AddSFMShareItems( pResultData, pcookie, pvolumeinfo, dwEntriesRead );
  153. pvolumeinfo = NULL;
  154. continue;
  155. } else if (RPC_S_SERVER_UNAVAILABLE == retval && 0 == hEnumHandle) {
  156. // SFM just isn't installed, don't worry about it
  157. retval = NERR_Success;
  158. break;
  159. } else {
  160. (void) DoErrMsgBox(GetActiveWindow(), MB_OK | MB_ICONSTOP, retval, IDS_POPUP_SFM_SHARES, pcookie->QueryNonNULLMachineName() );
  161. break;
  162. }
  163. } while (S_OK == hr);
  164. return HRESULT_FROM_WIN32(retval);
  165. }
  166. /*
  167. typedef enum _COLNUM_SHARES {
  168. COLNUM_SHARES_SHARED_FOLDER = 0,
  169. COLNUM_SHARES_SHARED_PATH,
  170. COLNUM_SHARES_TRANSPORT,
  171. COLNUM_SHARES_NUM_SESSIONS,
  172. COLNUM_SHARES_COMMENT
  173. } COLNUM_SHARES;
  174. typedef struct _AFP_VOLUME_INFO
  175. {
  176. LPWSTR afpvol_name; // Name of the volume max.
  177. DWORD afpvol_id; // id of this volume. generated by sever
  178. LPWSTR afpvol_password; // Volume password, max. AFP_VOLPASS_LEN
  179. DWORD afpvol_max_uses; // Max opens allowed
  180. DWORD afpvol_props_mask; // Mask of volume properties
  181. DWORD afpvol_curr_uses; // Number of curr open connections.
  182. LPWSTR afpvol_path; // The actual path
  183. // Ignored for VolumeSetInfo
  184. } AFP_VOLUME_INFO, *PAFP_VOLUME_INFO;
  185. */
  186. HRESULT SfmFileServiceProvider::AddSFMShareItems(
  187. IResultData* pResultData,
  188. CFileMgmtCookie* pParentCookie,
  189. PVOID pinfo,
  190. DWORD nItems)
  191. {
  192. TEST_NONNULL_PTR_PARAM(pParentCookie);
  193. TEST_NONNULL_PTR_PARAM(pinfo);
  194. if (0 >= nItems)
  195. return S_OK;
  196. RESULTDATAITEM tRDItem;
  197. ::ZeroMemory( &tRDItem, sizeof(tRDItem) );
  198. // CODEWORK should use MMC_ICON_CALLBACK
  199. tRDItem.nImage = iIconSFMShare;
  200. tRDItem.nCol = COLNUM_SHARES_SHARED_FOLDER;
  201. tRDItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  202. tRDItem.str = MMC_CALLBACK;
  203. AFP_VOLUME_INFO* pvolumeinfo = (AFP_VOLUME_INFO*)pinfo;
  204. DWORD nItemsToAdd = 0;
  205. for (DWORD i = 0; i < nItems; i++ )
  206. {
  207. if (!IsInvalidSharename(pvolumeinfo[i].afpvol_name))
  208. nItemsToAdd++;
  209. }
  210. CSfmShareCookie* pcookiearray = new CSfmShareCookie[nItemsToAdd];
  211. CSfmCookieBlock* pCookieBlock = new CSfmCookieBlock(
  212. pcookiearray,nItemsToAdd,pParentCookie->QueryTargetServer(),pinfo );
  213. pParentCookie->m_listResultCookieBlocks.AddHead( pCookieBlock );
  214. CString str;
  215. for ( ; nItems > 0; nItems--, pvolumeinfo++, pcookiearray++ )
  216. {
  217. if (IsInvalidSharename(pvolumeinfo->afpvol_name))
  218. continue;
  219. pcookiearray->m_pobject = pvolumeinfo;
  220. // WARNING cookie cast
  221. tRDItem.lParam = reinterpret_cast<LPARAM>((CCookie*)pcookiearray);
  222. HRESULT hr = pResultData->InsertItem(&tRDItem);
  223. ASSERT(SUCCEEDED(hr));
  224. }
  225. return S_OK;
  226. }
  227. /*
  228. DWORD
  229. AfpAdminSessionEnum(
  230. IN AFP_SERVER_HANDLE hAfpServer,
  231. OUT LPBYTE * lpbBuffer,
  232. IN DWORD dwPrefMaxLen,
  233. OUT LPDWORD lpdwEntriesRead,
  234. OUT LPDWORD lpdwTotalEntries,
  235. IN LPDWORD lpdwResumeHandle
  236. );
  237. */
  238. typedef DWORD (*SESSIONENUMPROC) (AFP_SERVER_HANDLE,LPBYTE*,DWORD,LPDWORD,LPDWORD,LPDWORD);
  239. // if pResultData is not NULL, add sessions/resources to the listbox
  240. // if pResultData is NULL, delete all sessions/resources
  241. // if pResultData is NULL, return SUCCEEDED(hr) to continue or
  242. // FAILED(hr) to abort
  243. HRESULT SfmFileServiceProvider::EnumerateSessions(
  244. IResultData* pResultData,
  245. CFileMgmtCookie* pcookie,
  246. bool bAddToResultPane)
  247. {
  248. TEST_NONNULL_PTR_PARAM(pcookie);
  249. if ( !g_SfmDLL.LoadFunctionPointers() )
  250. return S_OK;
  251. if ( !SFMConnect(pcookie->QueryTargetServer()) )
  252. return S_OK;
  253. AFP_SESSION_INFO* psessioninfo = NULL;
  254. DWORD dwEntriesRead = 0;
  255. DWORD dwTotalEntries = 0;
  256. DWORD hEnumHandle = 0;
  257. HRESULT hr = S_OK;
  258. NET_API_STATUS retval = NERR_Success;
  259. do {
  260. retval = ((SESSIONENUMPROC)g_SfmDLL[AFP_SESSION_ENUM])(
  261. m_ulSFMServerConnection,
  262. (PBYTE*)&psessioninfo,
  263. (DWORD)-1L,
  264. &dwEntriesRead,
  265. &dwTotalEntries,
  266. &hEnumHandle );
  267. if (NERR_Success == retval)
  268. {
  269. hr = HandleSFMSessionItems( pResultData, pcookie, psessioninfo, dwEntriesRead,
  270. bAddToResultPane);
  271. psessioninfo = NULL;
  272. break;
  273. } else if (ERROR_MORE_DATA == retval) {
  274. ASSERT( NULL != hEnumHandle );
  275. hr = HandleSFMSessionItems( pResultData, pcookie, psessioninfo, dwEntriesRead,
  276. bAddToResultPane);
  277. psessioninfo = NULL;
  278. continue;
  279. } else if (RPC_S_SERVER_UNAVAILABLE == retval && 0 == hEnumHandle) {
  280. // SFM just isn't installed, don't worry about it
  281. retval = NERR_Success;
  282. break;
  283. } else {
  284. (void) DoErrMsgBox(GetActiveWindow(), MB_OK | MB_ICONSTOP, retval, IDS_POPUP_SFM_SESSIONS, pcookie->QueryNonNULLMachineName() );
  285. break;
  286. }
  287. } while (S_OK == hr);
  288. return HRESULT_FROM_WIN32(retval);
  289. }
  290. /*
  291. typedef enum _COLNUM_SESSIONS {
  292. COLNUM_SESSIONS_USERNAME = 0,
  293. COLNUM_SESSIONS_COMPUTERNAME,
  294. COLNUM_SESSIONS_NUM_FILES,
  295. COLNUM_SESSIONS_CONNECTED_TIME,
  296. COLNUM_SESSIONS_IDLE_TIME,
  297. COLNUM_SESSIONS_IS_GUEST
  298. } COLNUM_SESSIONS;
  299. typedef struct _AFP_SESSION_INFO
  300. {
  301. DWORD afpsess_id; // Id of the session
  302. LPWSTR afpsess_ws_name; // Workstation Name,
  303. LPWSTR afpsess_username; // User Name, max. UNLEN
  304. DWORD afpsess_num_cons; // Number of open volumes
  305. DWORD afpsess_num_opens; // Number of open files
  306. LONG afpsess_time; // Time session established
  307. DWORD afpsess_logon_type; // How the user logged on
  308. } AFP_SESSION_INFO, *PAFP_SESSION_INFO;
  309. ShirishK 1/24/97:
  310. afpsess_logon_type: tells you how the user is logged on:
  311. 0 -> Guest, 2 -> the standard MS way, 3 -> Admin
  312. */
  313. HRESULT SfmFileServiceProvider::HandleSFMSessionItems(
  314. IResultData* pResultData,
  315. CFileMgmtCookie* pParentCookie,
  316. PVOID pinfo,
  317. DWORD nItems,
  318. BOOL bAddToResultPane)
  319. {
  320. TEST_NONNULL_PTR_PARAM(pParentCookie);
  321. TEST_NONNULL_PTR_PARAM(pinfo);
  322. if (0 >= nItems)
  323. return S_OK;
  324. BOOL fDeleteAllItems = (NULL == pResultData);
  325. RESULTDATAITEM tRDItem;
  326. ::ZeroMemory( &tRDItem, sizeof(tRDItem) );
  327. // CODEWORK should use MMC_ICON_CALLBACK
  328. tRDItem.nImage = iIconSFMSession;
  329. tRDItem.nCol = COLNUM_SESSIONS_USERNAME;
  330. tRDItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  331. tRDItem.str = MMC_CALLBACK;
  332. AFP_SESSION_INFO* psessioninfo = (AFP_SESSION_INFO*)pinfo;
  333. CSfmSessionCookie* pcookiearray = new CSfmSessionCookie[nItems];
  334. CSfmCookieBlock* pCookieBlock = new CSfmCookieBlock(
  335. pcookiearray,nItems,pParentCookie->QueryTargetServer(),pinfo );
  336. bool bAdded = false;
  337. if ( !fDeleteAllItems || !bAddToResultPane )
  338. {
  339. pParentCookie->m_listResultCookieBlocks.AddHead( pCookieBlock );
  340. bAdded = true;
  341. }
  342. for ( ; nItems > 0; nItems--, psessioninfo++, pcookiearray++ )
  343. {
  344. pcookiearray->m_pobject = psessioninfo;
  345. if ( bAddToResultPane )
  346. {
  347. if (fDeleteAllItems)
  348. {
  349. DWORD dwApiResult = CloseSession( pcookiearray );
  350. if (0L != dwApiResult)
  351. {
  352. CString strName;
  353. TranslateIPToComputerName(psessioninfo->afpsess_ws_name, strName);
  354. (void) DoErrMsgBox(GetActiveWindow(), MB_OK | MB_ICONSTOP, dwApiResult,
  355. IDS_POPUP_SFM_DISCONNECTALLSESSION_ERROR,
  356. strName );
  357. //return S_FALSE;
  358. }
  359. continue;
  360. }
  361. // WARNING cookie cast
  362. tRDItem.lParam = reinterpret_cast<LPARAM>((CCookie*)pcookiearray);
  363. HRESULT hr = pResultData->InsertItem(&tRDItem);
  364. ASSERT(SUCCEEDED(hr));
  365. }
  366. }
  367. if ( !bAdded ) // they were not added to the parent cookie's list
  368. delete pCookieBlock;
  369. return S_OK;
  370. }
  371. /*
  372. DWORD
  373. AfpAdminFileEnum(
  374. IN AFP_SERVER_HANDLE hAfpServer,
  375. OUT LPBYTE * lpbBuffer,
  376. IN DWORD dwPrefMaxLen,
  377. OUT LPDWORD lpdwEntriesRead,
  378. OUT LPDWORD lpdwTotalEntries,
  379. IN LPDWORD lpdwResumeHandle
  380. );
  381. */
  382. typedef DWORD (*FILEENUMPROC) (AFP_SERVER_HANDLE,LPBYTE*,DWORD,LPDWORD,LPDWORD,LPDWORD);
  383. // if pResultData is not NULL, add sessions/resources to the listbox
  384. // if pResultData is NULL, delete all sessions/resources
  385. // if pResultData is NULL, return SUCCEEDED(hr) to continue or
  386. // FAILED(hr) to abort
  387. HRESULT SfmFileServiceProvider::EnumerateResources(
  388. IResultData* pResultData,
  389. CFileMgmtCookie* pcookie)
  390. {
  391. TEST_NONNULL_PTR_PARAM(pcookie);
  392. if ( !g_SfmDLL.LoadFunctionPointers() )
  393. return S_OK;
  394. if ( !SFMConnect(pcookie->QueryTargetServer()) )
  395. return S_OK;
  396. AFP_FILE_INFO* pfileinfo = NULL;
  397. DWORD dwEntriesRead = 0;
  398. DWORD dwTotalEntries = 0;
  399. DWORD hEnumHandle = 0;
  400. HRESULT hr = S_OK;
  401. NET_API_STATUS retval = NERR_Success;
  402. do {
  403. retval = ((FILEENUMPROC)g_SfmDLL[AFP_FILE_ENUM])(
  404. m_ulSFMServerConnection,
  405. (PBYTE*)&pfileinfo,
  406. (DWORD)-1L,
  407. &dwEntriesRead,
  408. &dwTotalEntries,
  409. &hEnumHandle );
  410. if (NERR_Success == retval)
  411. {
  412. hr = HandleSFMResourceItems( pResultData, pcookie, pfileinfo, dwEntriesRead );
  413. pfileinfo = NULL;
  414. break;
  415. } else if (ERROR_MORE_DATA == retval) {
  416. ASSERT( NULL != hEnumHandle );
  417. hr = HandleSFMResourceItems( pResultData, pcookie, pfileinfo, dwEntriesRead );
  418. pfileinfo = NULL;
  419. continue;
  420. } else if (RPC_S_SERVER_UNAVAILABLE == retval && 0 == hEnumHandle) {
  421. // SFM just isn't installed, don't worry about it
  422. retval = NERR_Success;
  423. break;
  424. } else {
  425. (void) DoErrMsgBox(GetActiveWindow(), MB_OK | MB_ICONSTOP, retval, IDS_POPUP_SFM_RESOURCES, pcookie->QueryNonNULLMachineName() );
  426. break;
  427. }
  428. } while (S_OK == hr);
  429. return HRESULT_FROM_WIN32(retval);
  430. }
  431. #if 0
  432. typedef enum _COLNUM_RESOURCES {
  433. COLNUM_RESOURCES_FILENAME = 0,
  434. COLNUM_RESOURCES_USERNAME,
  435. COLNUM_RESOURCES_NUM_LOCKS, // we don't try to display sharename for now, since
  436. // only SFM has this information
  437. COLNUM_RESOURCES_OPEN_MODE
  438. } COLNUM_RESOURCES;
  439. typedef struct _AFP_FILE_INFO
  440. {
  441. DWORD afpfile_id; // Id of the open file fork
  442. DWORD afpfile_open_mode; // Mode in which file is opened
  443. DWORD afpfile_num_locks; // Number of locks on the file
  444. DWORD afpfile_fork_type; // Fork type
  445. LPWSTR afpfile_username; // File opened by this user. max UNLEN
  446. LPWSTR afpfile_path; // Absolute canonical path to the file
  447. } AFP_FILE_INFO, *PAFP_FILE_INFO;
  448. #endif
  449. HRESULT SfmFileServiceProvider::HandleSFMResourceItems(
  450. IResultData* pResultData,
  451. CFileMgmtCookie* pParentCookie,
  452. PVOID pinfo,
  453. DWORD nItems)
  454. {
  455. TEST_NONNULL_PTR_PARAM(pParentCookie);
  456. TEST_NONNULL_PTR_PARAM(pinfo);
  457. if (0 >= nItems)
  458. return S_OK;
  459. BOOL fDeleteAllItems = (NULL == pResultData);
  460. RESULTDATAITEM tRDItem;
  461. ::ZeroMemory( &tRDItem, sizeof(tRDItem) );
  462. // CODEWORK should use MMC_ICON_CALLBACK
  463. tRDItem.nImage = iIconSFMResource;
  464. tRDItem.nCol = COLNUM_RESOURCES_FILENAME;
  465. tRDItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  466. tRDItem.str = MMC_CALLBACK;
  467. AFP_FILE_INFO* pfileinfo = (AFP_FILE_INFO*)pinfo;
  468. CSfmResourceCookie* pcookiearray = new CSfmResourceCookie[nItems];
  469. CSfmCookieBlock* pCookieBlock = new CSfmCookieBlock(
  470. pcookiearray,nItems,pParentCookie->QueryTargetServer(),pinfo );
  471. if (!fDeleteAllItems)
  472. {
  473. pParentCookie->m_listResultCookieBlocks.AddHead( pCookieBlock );
  474. }
  475. CString str;
  476. for ( ; nItems > 0; nItems--, pfileinfo++, pcookiearray++ )
  477. {
  478. pcookiearray->m_pobject = pfileinfo;
  479. if (fDeleteAllItems)
  480. {
  481. DWORD dwApiResult = CloseResource( pcookiearray );
  482. if (0L != dwApiResult)
  483. {
  484. (void) DoErrMsgBox(GetActiveWindow(), MB_OK | MB_ICONSTOP, dwApiResult,
  485. IDS_POPUP_SFM_DISCONNECTALLRESOURCE_ERROR,
  486. pfileinfo->afpfile_path );
  487. return S_FALSE;
  488. }
  489. continue;
  490. }
  491. // WARNING cookie cast
  492. tRDItem.lParam = reinterpret_cast<LPARAM>((CCookie*)pcookiearray);
  493. HRESULT hr = pResultData->InsertItem(&tRDItem);
  494. ASSERT(SUCCEEDED(hr));
  495. }
  496. if (fDeleteAllItems) // they were not added to the parent cookie's list
  497. delete pCookieBlock;
  498. return S_OK;
  499. }
  500. /*
  501. DWORD
  502. AfpAdminFileClose(
  503. IN AFP_SERVER_HANDLE hAfpServer,
  504. IN DWORD dwConnectionId
  505. );
  506. DWORD
  507. AfpAdminConnectionEnum(
  508. IN AFP_SERVER_HANDLE hAfpServer,
  509. OUT LPBYTE *ppbBuffer,
  510. IN DWORD dwFilter,
  511. IN DWORD dwId,
  512. IN DWORD dwPrefMaxLen,
  513. OUT LPDWORD lpdwEntriesRead,
  514. OUT LPDWORD lpdwTotalEntries,
  515. IN LPDWORD lpdwResumeHandle
  516. );
  517. DWORD
  518. AfpAdminConnectionClose(
  519. IN AFP_SERVER_HANDLE hAfpServer,
  520. IN DWORD dwConnectionId
  521. );
  522. DWORD
  523. AfpAdminVolumeGetInfo (
  524. IN AFP_SERVER_HANDLE hAfpServer,
  525. IN LPWSTR lpwsVolumeName,
  526. OUT LPBYTE * lpbBuffer
  527. );
  528. typedef struct _AFP_VOLUME_INFO
  529. {
  530. LPWSTR afpvol_name; // Name of the volume max.
  531. DWORD afpvol_id; // id of this volume. generated by sever
  532. LPWSTR afpvol_password; // Volume password, max. AFP_VOLPASS_LEN
  533. DWORD afpvol_max_uses; // Max opens allowed
  534. DWORD afpvol_props_mask; // Mask of volume properties
  535. DWORD afpvol_curr_uses; // Number of curr open connections.
  536. LPWSTR afpvol_path; // The actual path
  537. // Ignored for VolumeSetInfo
  538. } AFP_VOLUME_INFO, *PAFP_VOLUME_INFO;
  539. DWORD
  540. AfpAdminVolumeDelete(
  541. IN AFP_SERVER_HANDLE hAfpServer,
  542. IN LPWSTR lpwsVolumeName
  543. );
  544. */
  545. typedef DWORD (*VOLUMEGETINFOPROC) (AFP_SERVER_HANDLE,LPWSTR,LPBYTE*);
  546. typedef DWORD (*FILECLOSEPROC) (AFP_SERVER_HANDLE,DWORD);
  547. typedef DWORD (*AFPCONNECTIONENUMPROC) (AFP_SERVER_HANDLE,LPBYTE*,DWORD,
  548. DWORD,DWORD,LPDWORD,LPDWORD,LPDWORD);
  549. typedef DWORD (*AFPCONNECTIONCLOSEPROC) (AFP_SERVER_HANDLE,DWORD);
  550. typedef DWORD (*VOLUMEDELPROC) (AFP_SERVER_HANDLE,LPWSTR);
  551. typedef DWORD (*BUFFERFREEPROC) (LPVOID);
  552. DWORD SfmFileServiceProvider::DeleteShare( LPCWSTR pwchServerName, LPCWSTR pwchShareName )
  553. {
  554. if ( !g_SfmDLL.LoadFunctionPointers() )
  555. return S_OK;
  556. if ( !SFMConnect(pwchServerName, TRUE) )
  557. return S_OK;
  558. PAFP_VOLUME_INFO pAfpVolumeInfo = NULL;
  559. DWORD dwRetCode = ((VOLUMEGETINFOPROC)g_SfmDLL[AFP_VOLUME_GET_INFO])(
  560. m_ulSFMServerConnection,
  561. const_cast<LPTSTR>(pwchShareName),
  562. (LPBYTE*)&pAfpVolumeInfo);
  563. if (AFPERR_VolumeNonExist == dwRetCode)
  564. return NERR_Success;
  565. if (NO_ERROR == dwRetCode)
  566. {
  567. ASSERT( NULL != pAfpVolumeInfo);
  568. //
  569. // Check if there are any open resources on the volume
  570. //
  571. PAFP_FILE_INFO pAfpFileInfos = NULL;
  572. DWORD dwEntriesRead = 0;
  573. DWORD dwTotalEntries = 0;
  574. dwRetCode = ((FILEENUMPROC)g_SfmDLL[AFP_FILE_ENUM])(
  575. m_ulSFMServerConnection,
  576. (PBYTE*)&pAfpFileInfos,
  577. (DWORD)-1L,
  578. &dwEntriesRead,
  579. &dwTotalEntries,
  580. NULL );
  581. if (NO_ERROR == dwRetCode)
  582. {
  583. PAFP_FILE_INFO pAfpFileInfoIter = pAfpFileInfos;
  584. for ( DWORD dwIndex = 0;
  585. dwIndex < dwEntriesRead;
  586. dwIndex++, pAfpFileInfoIter++ )
  587. {
  588. if (_tcsnicmp(pAfpVolumeInfo->afpvol_path,
  589. pAfpFileInfoIter->afpfile_path,
  590. _tcslen(pAfpVolumeInfo->afpvol_path)) == 0)
  591. {
  592. ((FILECLOSEPROC)g_SfmDLL[AFP_FILE_CLOSE])(
  593. m_ulSFMServerConnection,
  594. pAfpFileInfoIter->afpfile_id );
  595. }
  596. }
  597. ((BUFFERFREEPROC) g_SfmDLL[AFP_BUFFER_FREE])(pAfpFileInfos);
  598. }
  599. //
  600. // Check if there are any users connected to the volume
  601. // by enumerating the connections to this volume.
  602. //
  603. PAFP_CONNECTION_INFO pAfpConnections = NULL;
  604. dwRetCode = ((AFPCONNECTIONENUMPROC)g_SfmDLL[AFP_CONNECTION_ENUM])(
  605. m_ulSFMServerConnection,
  606. (LPBYTE*)&pAfpConnections,
  607. AFP_FILTER_ON_VOLUME_ID,
  608. pAfpVolumeInfo->afpvol_id,
  609. (DWORD)-1, // Get all conenctions
  610. &dwEntriesRead,
  611. &dwTotalEntries,
  612. NULL );
  613. ((BUFFERFREEPROC) g_SfmDLL[AFP_BUFFER_FREE])(pAfpVolumeInfo);
  614. if (NO_ERROR == dwRetCode)
  615. {
  616. PAFP_CONNECTION_INFO pAfpConnInfoIter = pAfpConnections;
  617. for ( DWORD dwIndex = 0;
  618. dwIndex < dwEntriesRead;
  619. dwIndex++, pAfpConnInfoIter++ )
  620. {
  621. ((AFPCONNECTIONCLOSEPROC)g_SfmDLL[AFP_CONNECTION_CLOSE])(
  622. m_ulSFMServerConnection,
  623. pAfpConnInfoIter->afpconn_id );
  624. }
  625. ((BUFFERFREEPROC) g_SfmDLL[AFP_BUFFER_FREE])(pAfpConnections);
  626. }
  627. dwRetCode = ((VOLUMEDELPROC)g_SfmDLL[AFP_VOLUME_DEL])(
  628. m_ulSFMServerConnection,
  629. const_cast<LPTSTR>(pwchShareName) );
  630. if (AFPERR_VolumeNonExist == dwRetCode)
  631. dwRetCode = NERR_Success;
  632. }
  633. return dwRetCode;
  634. }
  635. /*
  636. DWORD
  637. AfpAdminSessionClose(
  638. IN AFP_SERVER_HANDLE hAfpServer,
  639. IN DWORD dwSessionId
  640. );
  641. */
  642. typedef DWORD (*SESSIONCLOSEPROC) (AFP_SERVER_HANDLE,DWORD);
  643. DWORD SfmFileServiceProvider::CloseSession(CFileMgmtResultCookie* pcookie)
  644. {
  645. if ( !g_SfmDLL.LoadFunctionPointers() )
  646. return S_OK;
  647. USES_CONVERSION;
  648. if ( !SFMConnect(T2OLE(const_cast<LPTSTR>(pcookie->QueryTargetServer()))) )
  649. return S_OK;
  650. ASSERT( FILEMGMT_SESSION == pcookie->QueryObjectType() );
  651. AFP_SESSION_INFO* psessioninfo = (AFP_SESSION_INFO*)pcookie->m_pobject;
  652. ASSERT( NULL != psessioninfo );
  653. DWORD dwRet = ((SESSIONCLOSEPROC)g_SfmDLL[AFP_SESSION_CLOSE])(
  654. m_ulSFMServerConnection,
  655. psessioninfo->afpsess_id );
  656. return (AFPERR_InvalidId == dwRet ? NERR_Success : dwRet);
  657. }
  658. DWORD SfmFileServiceProvider::CloseResource(CFileMgmtResultCookie* pcookie)
  659. {
  660. if ( !g_SfmDLL.LoadFunctionPointers() )
  661. return S_OK;
  662. if ( !SFMConnect(T2OLE(const_cast<LPTSTR>(pcookie->QueryTargetServer()))) )
  663. return S_OK;
  664. ASSERT( FILEMGMT_RESOURCE == pcookie->QueryObjectType() );
  665. AFP_FILE_INFO* pfileinfo = (AFP_FILE_INFO*)pcookie->m_pobject;
  666. ASSERT( NULL != pfileinfo );
  667. DWORD dwRet = ((FILECLOSEPROC)g_SfmDLL[AFP_FILE_CLOSE])(
  668. m_ulSFMServerConnection,
  669. pfileinfo->afpfile_id );
  670. return (AFPERR_InvalidId == dwRet ? NERR_Success : dwRet);
  671. }
  672. /*
  673. DWORD
  674. AfpAdminDirectoryGetInfo(
  675. IN AFP_SERVER_HANDLE hAfpServer,
  676. IN LPWSTR lpwsPath,
  677. OUT LPBYTE *ppAfpDirectoryInfo
  678. );
  679. DWORD
  680. AfpAdminDirectorySetInfo(
  681. IN AFP_SERVER_HANDLE hAfpServer,
  682. IN LPBYTE pAfpDirectoryInfo,
  683. IN DWORD dwParmNum
  684. );
  685. */
  686. typedef DWORD (*DIRECTORYGETINFOPROC) (AFP_SERVER_HANDLE,LPWSTR,LPBYTE*);
  687. typedef DWORD (*DIRECTORYSETINFOPROC) (AFP_SERVER_HANDLE,LPBYTE,DWORD);
  688. DWORD SfmFileServiceProvider::GetDirectoryInfo(
  689. LPCTSTR ptchServerName,
  690. LPCWSTR pszPath,
  691. DWORD* pdwPerms,
  692. CString& strOwner,
  693. CString& strGroup )
  694. {
  695. if ( !g_SfmDLL.LoadFunctionPointers() )
  696. return S_OK;
  697. if ( !SFMConnect(ptchServerName, TRUE) )
  698. return S_OK;
  699. AFP_DIRECTORY_INFO* pdirinfo = NULL;
  700. DWORD retval = ((DIRECTORYGETINFOPROC)g_SfmDLL[AFP_DIRECTORY_GET_INFO])(
  701. m_ulSFMServerConnection,
  702. const_cast<LPWSTR>(pszPath),
  703. (LPBYTE*)&pdirinfo );
  704. if (0L != retval)
  705. {
  706. return retval;
  707. }
  708. ASSERT( NULL != pdirinfo );
  709. *pdwPerms = pdirinfo->afpdir_perms;
  710. strOwner = pdirinfo->afpdir_owner;
  711. strGroup = pdirinfo->afpdir_group;
  712. FreeData( pdirinfo );
  713. return 0L;
  714. }
  715. DWORD SfmFileServiceProvider::SetDirectoryInfo(
  716. LPCTSTR ptchServerName,
  717. LPCWSTR pszPath,
  718. DWORD dwPerms,
  719. LPCWSTR pszOwner,
  720. LPCWSTR pszGroup )
  721. {
  722. if ( !g_SfmDLL.LoadFunctionPointers() )
  723. return S_OK;
  724. if ( !SFMConnect(ptchServerName, TRUE) )
  725. return S_OK;
  726. AFP_DIRECTORY_INFO dirinfo;
  727. ::memset( &dirinfo, 0, sizeof(dirinfo) );
  728. dirinfo.afpdir_path = const_cast<LPWSTR>(pszPath);
  729. dirinfo.afpdir_perms = dwPerms;
  730. dirinfo.afpdir_owner = const_cast<LPWSTR>(pszOwner);
  731. dirinfo.afpdir_group = const_cast<LPWSTR>(pszGroup);
  732. dirinfo.afpdir_in_volume = FALSE;
  733. return ((DIRECTORYSETINFOPROC)g_SfmDLL[AFP_DIRECTORY_SET_INFO])(
  734. m_ulSFMServerConnection,
  735. (LPBYTE)&dirinfo,
  736. AFP_DIR_PARMNUM_ALL );
  737. }
  738. /*
  739. DWORD
  740. AfpAdminVolumeSetInfo (
  741. IN AFP_SERVER_HANDLE hAfpServer,
  742. IN LPBYTE pBuffer,
  743. IN DWORD dwParmNum
  744. );
  745. */
  746. typedef DWORD (*VOLUMESETINFOPROC) (AFP_SERVER_HANDLE,LPBYTE,DWORD);
  747. VOID SfmFileServiceProvider::DisplayShareProperties(
  748. LPPROPERTYSHEETCALLBACK pCallBack,
  749. LPDATAOBJECT pDataObject,
  750. LONG_PTR handle)
  751. {
  752. /*
  753. add General page
  754. */
  755. CSharePageGeneralSFM * pPage = new CSharePageGeneralSFM();
  756. if ( !pPage->Load( m_pFileMgmtData, pDataObject ) )
  757. return;
  758. // This mechanism deletes the CSharePageGeneral when the property sheet is finished
  759. pPage->m_pfnOriginalPropSheetPageProc = pPage->m_psp.pfnCallback;
  760. pPage->m_psp.lParam = reinterpret_cast<LPARAM>(pPage);
  761. pPage->m_psp.pfnCallback = &CSharePageGeneralSFM::PropSheetPageProc;
  762. pPage->m_handle = handle;
  763. HPROPSHEETPAGE hPage=MyCreatePropertySheetPage(&pPage->m_psp);
  764. pCallBack->AddPage(hPage);
  765. CreateFolderSecurityPropPage(pCallBack, pDataObject);
  766. }
  767. DWORD SfmFileServiceProvider::ReadShareProperties(
  768. LPCTSTR ptchServerName,
  769. LPCTSTR ptchShareName,
  770. OUT PVOID* ppvPropertyBlock,
  771. OUT CString& /*strDescription*/,
  772. OUT CString& strPath,
  773. OUT BOOL* pfEditDescription,
  774. OUT BOOL* pfEditPath,
  775. OUT DWORD* pdwShareType)
  776. {
  777. if ( !g_SfmDLL.LoadFunctionPointers() )
  778. {
  779. ASSERT(FALSE);
  780. return S_OK;
  781. }
  782. if (ppvPropertyBlock) *ppvPropertyBlock = NULL;
  783. if (pdwShareType) *pdwShareType = 0;
  784. if (pfEditDescription) *pfEditDescription = FALSE;
  785. if (pfEditPath) *pfEditPath = FALSE;
  786. USES_CONVERSION;
  787. if ( !SFMConnect(T2OLE(const_cast<LPTSTR>(ptchServerName))) )
  788. return S_OK;
  789. AFP_VOLUME_INFO* pvolumeinfo = NULL;
  790. NET_API_STATUS retval = ((VOLUMEGETINFOPROC)g_SfmDLL[AFP_VOLUME_GET_INFO])(
  791. m_ulSFMServerConnection,
  792. T2OLE(const_cast<LPTSTR>(ptchShareName)),
  793. (LPBYTE*)&pvolumeinfo);
  794. if (NERR_Success == retval)
  795. {
  796. strPath = pvolumeinfo->afpvol_path;
  797. if (ppvPropertyBlock)
  798. {
  799. *ppvPropertyBlock = pvolumeinfo; // will be freed by the caller
  800. } else
  801. {
  802. FreeData(pvolumeinfo);
  803. }
  804. }
  805. return retval;
  806. }
  807. // the changed values have already been loaded into pvPropertyBlock
  808. DWORD SfmFileServiceProvider::WriteShareProperties(LPCTSTR ptchServerName, LPCTSTR /*ptchShareName*/,
  809. PVOID pvPropertyBlock, LPCTSTR /*ptchDescription*/, LPCTSTR /*ptchPath*/)
  810. {
  811. if ( !g_SfmDLL.LoadFunctionPointers() )
  812. return S_OK;
  813. USES_CONVERSION;
  814. if ( !SFMConnect(T2OLE(const_cast<LPTSTR>(ptchServerName))) )
  815. return S_OK;
  816. ASSERT( NULL != pvPropertyBlock );
  817. AFP_VOLUME_INFO* pvolumeinfo = (AFP_VOLUME_INFO*)pvPropertyBlock;
  818. DWORD retval = ((VOLUMESETINFOPROC)g_SfmDLL[AFP_VOLUME_SET_INFO])(
  819. m_ulSFMServerConnection,
  820. (LPBYTE)pvolumeinfo,
  821. AFP_VOL_PARMNUM_ALL);
  822. pvolumeinfo->afpvol_path = NULL;
  823. return retval;
  824. }
  825. VOID SfmFileServiceProvider::FreeShareProperties(PVOID pvPropertyBlock)
  826. {
  827. FreeData( pvPropertyBlock );
  828. }
  829. DWORD SfmFileServiceProvider::QueryMaxUsers(PVOID pvPropertyBlock)
  830. {
  831. AFP_VOLUME_INFO* pvolumeinfo = (AFP_VOLUME_INFO*)pvPropertyBlock;
  832. ASSERT( NULL != pvolumeinfo );
  833. return pvolumeinfo->afpvol_max_uses;
  834. }
  835. VOID SfmFileServiceProvider::SetMaxUsers(PVOID pvPropertyBlock, DWORD dwMaxUsers)
  836. {
  837. AFP_VOLUME_INFO* pvolumeinfo = (AFP_VOLUME_INFO*)pvPropertyBlock;
  838. ASSERT( NULL != pvolumeinfo );
  839. pvolumeinfo->afpvol_max_uses = dwMaxUsers;
  840. }
  841. VOID SfmFileServiceProvider::FreeData(PVOID pv)
  842. {
  843. if (pv != NULL)
  844. {
  845. ASSERT( NULL != g_SfmDLL[AFP_BUFFER_FREE] );
  846. (void) ((BUFFERFREEPROC)g_SfmDLL[AFP_BUFFER_FREE])( pv );
  847. }
  848. }
  849. LPCTSTR SfmFileServiceProvider::QueryTransportString()
  850. {
  851. return m_strTransportSFM;
  852. }
  853. BOOL SfmFileServiceProvider::DisplaySfmProperties(LPDATAOBJECT pDataObject, CFileMgmtCookie* pcookie)
  854. {
  855. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  856. if ( !g_SfmDLL.LoadFunctionPointers() )
  857. return S_OK;
  858. CString strServerName;
  859. HRESULT hr = ExtractString( pDataObject, CFileMgmtDataObject::m_CFMachineName, &strServerName, MAX_PATH );
  860. if ( !SFMConnect(strServerName) )
  861. return S_OK;
  862. CString strTitle;
  863. // check to see if we have a sheet up, if so make it active.
  864. if (m_pSfmPropSheet)
  865. {
  866. m_pSfmPropSheet->SetActiveWindow();
  867. return TRUE;
  868. }
  869. // nothing up, create a new sheet
  870. strTitle.LoadString(IDS_PROP_SHEET_TITLE);
  871. SetSfmPropSheet(new CSFMPropertySheet);
  872. if (!m_pSfmPropSheet->FInit(NULL, m_ulSFMServerConnection, strTitle, this, pcookie->QueryTargetServer()))
  873. {
  874. delete m_pSfmPropSheet;
  875. SetSfmPropSheet(NULL);
  876. return FALSE;
  877. }
  878. return m_pSfmPropSheet->DoModelessSheet(pDataObject);
  879. }
  880. void SfmFileServiceProvider::CleanupSfmProperties()
  881. {
  882. if (m_pSfmPropSheet)
  883. {
  884. // we're going away, so set the pointer to NULL
  885. // so the property sheet won't try to call back into us.
  886. m_pSfmPropSheet->SetProvider(NULL);
  887. m_pSfmPropSheet->CancelSheet();
  888. m_pSfmPropSheet->Release();
  889. SetSfmPropSheet(NULL);
  890. }
  891. }
  892. void SfmFileServiceProvider::SetSfmPropSheet(CSFMPropertySheet * pSfmPropSheet)
  893. {
  894. if (m_pSfmPropSheet)
  895. m_pSfmPropSheet->Release();
  896. m_pSfmPropSheet = pSfmPropSheet;
  897. }
  898. DWORD SfmFileServiceProvider::UserHasAccess(LPCWSTR pwchServerName)
  899. {
  900. PAFP_SERVER_INFO pAfpServerInfo;
  901. DWORD err;
  902. if ( !g_SfmDLL.LoadFunctionPointers() )
  903. return FALSE;
  904. if ( !SFMConnect(pwchServerName) )
  905. return FALSE;
  906. err = ((SERVERGETINFOPROC) g_SfmDLL[AFP_SERVER_GET_INFO])(m_ulSFMServerConnection,
  907. (LPBYTE*) &pAfpServerInfo);
  908. if (err == NO_ERROR)
  909. {
  910. ((BUFFERFREEPROC) g_SfmDLL[AFP_BUFFER_FREE])(pAfpServerInfo);
  911. }
  912. return err;
  913. }
  914. BOOL SfmFileServiceProvider::FSFMInstalled(LPCWSTR pwchServerName)
  915. {
  916. BOOL bInstalled = FALSE;
  917. if ( !g_SfmDLL.LoadFunctionPointers() )
  918. return FALSE;
  919. if ( !SFMConnect(pwchServerName) )
  920. return FALSE;
  921. // check to make sure the service is there
  922. SC_HANDLE hScManager = ::OpenSCManager(pwchServerName, NULL, SC_MANAGER_CONNECT);
  923. if (hScManager)
  924. {
  925. SC_HANDLE hService = ::OpenService(hScManager, AFP_SERVICE_NAME, GENERIC_READ);
  926. if (hService != NULL)
  927. {
  928. // the service is there. May or may not be started.
  929. bInstalled = TRUE;
  930. ::CloseServiceHandle(hService);
  931. }
  932. ::CloseServiceHandle(hScManager);
  933. }
  934. return bInstalled;
  935. }
  936. // ensures that SFM is started
  937. BOOL SfmFileServiceProvider::StartSFM(HWND hwndParent, SC_HANDLE hScManager, LPCWSTR pwchServerName)
  938. {
  939. BOOL bStarted = FALSE;
  940. if ( !g_SfmDLL.LoadFunctionPointers() )
  941. return FALSE;
  942. if ( !SFMConnect(pwchServerName) )
  943. return FALSE;
  944. // open the service
  945. SC_HANDLE hService = ::OpenService(hScManager, AFP_SERVICE_NAME, GENERIC_READ);
  946. if (hService != NULL)
  947. {
  948. SERVICE_STATUS ss;
  949. // get the service status
  950. if (::QueryServiceStatus(hService, &ss))
  951. {
  952. APIERR err = NO_ERROR;
  953. if (ss.dwCurrentState != SERVICE_RUNNING)
  954. {
  955. // try to start the service
  956. CString strSvcDisplayName, strMessageBox;
  957. strSvcDisplayName.LoadString(IDS_PROP_SHEET_TITLE);
  958. AfxFormatString1(strMessageBox, IDS_START_SERVICE, strSvcDisplayName);
  959. if (AfxMessageBox(strMessageBox, MB_YESNO) == IDYES)
  960. {
  961. TCHAR szName[MAX_COMPUTERNAME_LENGTH + 1] = {0};
  962. DWORD dwSize = sizeof(szName);
  963. if (pwchServerName == NULL)
  964. {
  965. GetComputerName(szName, &dwSize);
  966. pwchServerName = szName;
  967. }
  968. // the service control progress handles displaying the error
  969. err = CServiceControlProgress::S_EStartService(hwndParent,
  970. hScManager,
  971. pwchServerName,
  972. AFP_SERVICE_NAME,
  973. strSvcDisplayName,
  974. 0,
  975. NULL);
  976. }
  977. else
  978. {
  979. // user chose not to start the service.
  980. err = 1;
  981. }
  982. }
  983. if (err == NO_ERROR)
  984. {
  985. bStarted = TRUE;
  986. }
  987. }
  988. ::CloseServiceHandle(hService);
  989. }
  990. return bStarted;
  991. }
  992. CSfmCookieBlock::~CSfmCookieBlock()
  993. {
  994. if (NULL != m_pvCookieData)
  995. {
  996. (void) ((BUFFERFREEPROC)g_SfmDLL[AFP_BUFFER_FREE])( m_pvCookieData );
  997. m_pvCookieData = NULL;
  998. }
  999. }
  1000. DEFINE_COOKIE_BLOCK(CSfmCookie)
  1001. DEFINE_FORWARDS_MACHINE_NAME( CSfmCookie, m_pCookieBlock )
  1002. void CSfmCookie::AddRefCookie() { m_pCookieBlock->AddRef(); }
  1003. void CSfmCookie::ReleaseCookie() { m_pCookieBlock->Release(); }
  1004. HRESULT CSfmCookie::GetTransport( FILEMGMT_TRANSPORT* pTransport )
  1005. {
  1006. *pTransport = FILEMGMT_SFM;
  1007. return S_OK;
  1008. }
  1009. HRESULT CSfmShareCookie::GetShareName( CString& strShareName )
  1010. {
  1011. AFP_VOLUME_INFO* pvolumeinfo = (AFP_VOLUME_INFO*)m_pobject;
  1012. ASSERT( NULL != pvolumeinfo );
  1013. USES_CONVERSION;
  1014. strShareName = OLE2T(pvolumeinfo->afpvol_name);
  1015. return S_OK;
  1016. }
  1017. HRESULT CSfmShareCookie::GetSharePIDList( OUT LPITEMIDLIST *ppidl )
  1018. {
  1019. ASSERT(ppidl);
  1020. ASSERT(NULL == *ppidl); // prevent memory leak
  1021. *ppidl = NULL;
  1022. AFP_VOLUME_INFO* pvolumeinfo = (AFP_VOLUME_INFO*)m_pobject;
  1023. ASSERT( NULL != pvolumeinfo );
  1024. ASSERT( _tcslen(pvolumeinfo->afpvol_path) >= 3 &&
  1025. _T(':') == *(pvolumeinfo->afpvol_path + 1) );
  1026. USES_CONVERSION;
  1027. PCTSTR pszTargetServer = m_pCookieBlock->QueryTargetServer();
  1028. CString csPath;
  1029. if (pszTargetServer)
  1030. {
  1031. //
  1032. // since MS Windows user cannot see shares created for MAC or Netware users,
  1033. // we have to use $ share to retrieve the pidl here.
  1034. //
  1035. CString csTemp = OLE2T(pvolumeinfo->afpvol_path);
  1036. csTemp.SetAt(1, _T('$'));
  1037. if ( _tcslen(pszTargetServer) >= 2 &&
  1038. _T('\\') == *pszTargetServer &&
  1039. _T('\\') == *(pszTargetServer + 1) )
  1040. {
  1041. csPath = pszTargetServer;
  1042. } else
  1043. {
  1044. csPath = _T("\\\\");
  1045. csPath += pszTargetServer;
  1046. }
  1047. csPath += _T("\\");
  1048. csPath += csTemp;
  1049. } else
  1050. {
  1051. csPath = OLE2T(pvolumeinfo->afpvol_path);
  1052. }
  1053. if (FALSE == csPath.IsEmpty())
  1054. *ppidl = ILCreateFromPath(csPath);
  1055. return ((*ppidl) ? S_OK : E_FAIL);
  1056. }
  1057. HRESULT CSfmSessionCookie::GetSessionID( DWORD* pdwSessionID )
  1058. {
  1059. AFP_SESSION_INFO* psessioninfo = (AFP_SESSION_INFO*)m_pobject;
  1060. ASSERT( NULL != pdwSessionID && NULL != psessioninfo );
  1061. *pdwSessionID = psessioninfo->afpsess_id;
  1062. return S_OK;
  1063. }
  1064. HRESULT CSfmResourceCookie::GetFileID( DWORD* pdwFileID )
  1065. {
  1066. AFP_FILE_INFO* pfileinfo = (AFP_FILE_INFO*)m_pobject;
  1067. ASSERT( NULL != pdwFileID && NULL != pfileinfo );
  1068. *pdwFileID = pfileinfo->afpfile_id;
  1069. return S_OK;
  1070. }
  1071. BSTR CSfmShareCookie::GetColumnText( int nCol )
  1072. {
  1073. switch (nCol)
  1074. {
  1075. case COLNUM_SHARES_SHARED_FOLDER:
  1076. return GetShareInfo()->afpvol_name;
  1077. case COLNUM_SHARES_SHARED_PATH:
  1078. return GetShareInfo()->afpvol_path;
  1079. case COLNUM_SHARES_TRANSPORT:
  1080. return const_cast<BSTR>((LPCTSTR)g_strTransportSFM);
  1081. case COLNUM_SHARES_COMMENT:
  1082. break; // not known for SFM
  1083. default:
  1084. ASSERT(FALSE);
  1085. break;
  1086. }
  1087. return L"";
  1088. }
  1089. BSTR CSfmShareCookie::QueryResultColumnText( int nCol, CFileMgmtComponentData& /*refcdata*/ )
  1090. {
  1091. if (COLNUM_SHARES_NUM_SESSIONS == nCol)
  1092. return MakeDwordResult( GetNumOfCurrentUses() );
  1093. return GetColumnText(nCol);
  1094. }
  1095. extern CString g_cstrClientName;
  1096. extern CString g_cstrGuest;
  1097. extern CString g_cstrYes;
  1098. extern CString g_cstrNo;
  1099. BSTR CSfmSessionCookie::GetColumnText( int nCol )
  1100. {
  1101. switch (nCol)
  1102. {
  1103. case COLNUM_SESSIONS_USERNAME:
  1104. if (0 == GetSessionInfo()->afpsess_logon_type &&
  1105. ( !(GetSessionInfo()->afpsess_username) ||
  1106. _T('\0') == *(GetSessionInfo()->afpsess_username) ) )
  1107. {
  1108. return const_cast<BSTR>(((LPCTSTR)g_cstrGuest));
  1109. } else
  1110. {
  1111. return GetSessionInfo()->afpsess_username;
  1112. }
  1113. case COLNUM_SESSIONS_COMPUTERNAME:
  1114. {
  1115. TranslateIPToComputerName(GetSessionInfo()->afpsess_ws_name, g_cstrClientName);
  1116. return const_cast<BSTR>(((LPCTSTR)g_cstrClientName));
  1117. }
  1118. case COLNUM_SESSIONS_TRANSPORT:
  1119. return const_cast<BSTR>((LPCTSTR)g_strTransportSFM);
  1120. case COLNUM_SESSIONS_IS_GUEST:
  1121. if (0 == GetSessionInfo()->afpsess_logon_type)
  1122. return const_cast<BSTR>(((LPCTSTR)g_cstrYes));
  1123. else
  1124. return const_cast<BSTR>(((LPCTSTR)g_cstrNo));
  1125. default:
  1126. ASSERT(FALSE);
  1127. break;
  1128. }
  1129. return L"";
  1130. }
  1131. BSTR CSfmSessionCookie::QueryResultColumnText( int nCol, CFileMgmtComponentData& /*refcdata*/ )
  1132. {
  1133. switch (nCol)
  1134. {
  1135. case COLNUM_SESSIONS_NUM_FILES:
  1136. return MakeDwordResult( GetNumOfOpenFiles() );
  1137. case COLNUM_SESSIONS_CONNECTED_TIME:
  1138. return MakeElapsedTimeResult( GetConnectedTime() );
  1139. case COLNUM_SESSIONS_IDLE_TIME:
  1140. return L""; // not known for SFM sessions
  1141. default:
  1142. break;
  1143. }
  1144. return GetColumnText(nCol);
  1145. }
  1146. BSTR CSfmResourceCookie::GetColumnText( int nCol )
  1147. {
  1148. switch (nCol)
  1149. {
  1150. case COLNUM_RESOURCES_FILENAME:
  1151. return GetFileInfo()->afpfile_path;
  1152. case COLNUM_RESOURCES_USERNAME:
  1153. return GetFileInfo()->afpfile_username;
  1154. case COLNUM_RESOURCES_TRANSPORT:
  1155. return const_cast<BSTR>((LPCTSTR)g_strTransportSFM);
  1156. case COLNUM_RESOURCES_OPEN_MODE:
  1157. {
  1158. return ( MakePermissionsResult(
  1159. ((AFP_OPEN_MODE_WRITE & GetFileInfo()->afpfile_open_mode)
  1160. ? PERM_FILE_WRITE : 0) |
  1161. ((AFP_OPEN_MODE_READ & GetFileInfo()->afpfile_open_mode)
  1162. ? PERM_FILE_READ : 0) ) );
  1163. }
  1164. default:
  1165. ASSERT(FALSE);
  1166. break;
  1167. }
  1168. return L"";
  1169. }
  1170. BSTR CSfmResourceCookie::QueryResultColumnText( int nCol, CFileMgmtComponentData& /*refcdata*/ )
  1171. {
  1172. if (COLNUM_RESOURCES_NUM_LOCKS == nCol)
  1173. return MakeDwordResult( GetNumOfLocks() );
  1174. return GetColumnText(nCol);
  1175. }
  1176. void CSharePageGeneralSFM::ReadSfmSettings()
  1177. {
  1178. AFP_VOLUME_INFO* pvolumeinfo = (AFP_VOLUME_INFO*)m_pvPropertyBlock;
  1179. ASSERT( NULL != pvolumeinfo );
  1180. // CODEWORK I may want to use a string of eight spaces rather than
  1181. // putting the actual password on screen. I may also want to
  1182. // use a confirmation password field.
  1183. // See \\kernel\razzle2\src\sfm\afp\ui\afpmgr\volprop.cxx
  1184. m_strSfmPassword = pvolumeinfo->afpvol_password;
  1185. m_bSfmReadonly = !!(pvolumeinfo->afpvol_props_mask & AFP_VOLUME_READONLY);
  1186. m_bSfmGuests = !!(pvolumeinfo->afpvol_props_mask & AFP_VOLUME_GUESTACCESS);
  1187. }
  1188. void CSharePageGeneralSFM::WriteSfmSettings()
  1189. {
  1190. AFP_VOLUME_INFO* pvolumeinfo = (AFP_VOLUME_INFO*)m_pvPropertyBlock;
  1191. ASSERT( NULL != pvolumeinfo );
  1192. pvolumeinfo->afpvol_password = const_cast<LPWSTR>((LPCWSTR)m_strSfmPassword);
  1193. pvolumeinfo->afpvol_props_mask &=
  1194. ~(AFP_VOLUME_READONLY|AFP_VOLUME_GUESTACCESS);
  1195. if (m_bSfmReadonly)
  1196. pvolumeinfo->afpvol_props_mask |= AFP_VOLUME_READONLY;
  1197. if (m_bSfmGuests)
  1198. pvolumeinfo->afpvol_props_mask |= AFP_VOLUME_GUESTACCESS;
  1199. }